@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.
- package/README.md +104 -0
- package/dist/bundle.cjs.js +18 -30
- package/dist/bundle.cjs.js.map +1 -1
- package/dist/bundle.es.js +3506 -7033
- package/dist/bundle.es.js.map +1 -1
- package/dist/bundle.iife.js +18 -30
- package/dist/bundle.iife.js.map +1 -1
- package/dist/bundle.umd.js +17 -29
- package/dist/bundle.umd.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/messages.d.ts +2 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/protocol/webrtc.d.ts.map +1 -1
- package/dist/protocol/websocket.d.ts.map +1 -1
- package/dist/runtime/context.d.ts +34 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/handlers.d.ts +21 -0
- package/dist/runtime/handlers.d.ts.map +1 -0
- package/dist/runtime/listeners.d.ts +6 -0
- package/dist/runtime/listeners.d.ts.map +1 -0
- package/dist/runtime/protocols.d.ts +17 -0
- package/dist/runtime/protocols.d.ts.map +1 -0
- package/dist/runtime/threads.d.ts +35 -0
- package/dist/runtime/threads.d.ts.map +1 -0
- package/dist/runtime/utils.d.ts +10 -0
- package/dist/runtime/utils.d.ts.map +1 -0
- package/dist/runtime.d.ts +4 -22
- package/dist/runtime.d.ts.map +1 -1
- package/dist/storage/base.d.ts +19 -0
- package/dist/storage/base.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/persona.d.ts +30 -0
- package/dist/storage/persona.d.ts.map +1 -0
- package/dist/types.d.ts +51 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -10
- package/playground/src/chat.tsx +51 -66
- package/playground/src/components/assistant-ui/thread-list.tsx +45 -12
- package/playground/src/components/assistant-ui/thread.tsx +34 -96
- package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +59 -0
- package/playground/src/components/chat/logging.tsx +53 -0
- package/playground/src/components/ui/input.tsx +21 -0
- package/playground/src/components/ui/separator.tsx +26 -0
- package/playground/src/components/ui/sheet.tsx +139 -0
- package/playground/src/components/ui/sidebar.tsx +619 -0
- package/playground/src/components/ui/skeleton.tsx +13 -0
- package/playground/src/components/ui/tooltip.tsx +0 -2
- package/playground/src/hooks/theme.ts +70 -0
- package/playground/src/hooks/use-mobile.ts +19 -0
- package/src/index.ts +1 -0
- package/src/messages.ts +98 -8
- package/src/protocol/webrtc.ts +1 -0
- package/src/protocol/websocket.ts +5 -2
- package/src/runtime/context.ts +88 -0
- package/src/runtime/handlers.ts +276 -0
- package/src/runtime/index.ts +6 -0
- package/src/runtime/listeners.ts +79 -0
- package/src/runtime/protocols.ts +169 -0
- package/src/runtime/threads.ts +120 -0
- package/src/runtime/utils.ts +46 -0
- package/src/runtime.tsx +226 -326
- package/src/storage/base.ts +21 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/persona.ts +132 -0
- package/src/types.ts +64 -2
- package/vite.config.ts +11 -1
package/dist/bundle.cjs.js
CHANGED
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
"use strict";var sb=Object.defineProperty;var ib=(n,i,r)=>i in n?sb(n,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[i]=r;var S=(n,i,r)=>ib(n,typeof i!="symbol"?i+"":i,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("react");var $n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Lu(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Bu={exports:{}},qn={};/**
|
|
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 mu;function ob(){if(mu)return qn;mu=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 qn.Fragment=i,qn.jsx=r,qn.jsxs=r,qn}Bu.exports=ob();var Pe=Bu.exports,ab=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},{}),ku=class{constructor(){S(this,"_providers",new Set);S(this,"_subscribers",new Set)}getModelContext(){return ab(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)}},ub=class{constructor(){S(this,"_contextProvider",new ku)}registerModelContextProvider(n){return this._contextProvider.registerModelContextProvider(n)}getModelContextProvider(){return this._contextProvider}},cb=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)}},hb=n=>n.status.type==="complete",Du=class extends cb{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=>hb(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)}}},lb=class extends Du{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()}};let fb=(n,i=21)=>(r=i)=>{let a="",h=r|0;for(;h--;)a+=n[Math.random()*n.length|0];return a};var Li=fb("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7),db="__optimistic__",pb=()=>`${db}${Li()}`,bn=Symbol("autoStatus"),gb=Object.freeze(Object.assign({type:"running"},{[bn]:!0})),_b=Object.freeze(Object.assign({type:"complete",reason:"unknown"},{[bn]:!0}));Object.freeze(Object.assign({type:"requires-action",reason:"tool-calls"},{[bn]:!0}));Object.freeze(Object.assign({type:"requires-action",reason:"interrupt"},{[bn]:!0}));var bb=n=>n[bn]===!0,Nu=(n,i,r,a,h)=>n&&h?Object.assign({type:"incomplete",reason:"error",error:h},{[bn]:!0}):n&&i?gb:_b,mn={exports:{}};const mb=typeof Buffer<"u",vu=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,wu=/"(?: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 Fu(n,i,r){r==null&&i!==null&&typeof i=="object"&&(r=i,i=void 0),mb&&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(vu.test(n)===!1&&wu.test(n)===!1)return a}else if(h!=="ignore"&&f==="ignore"){if(vu.test(n)===!1)return a}else if(wu.test(n)===!1)return a;return Uu(a,{protoAction:h,constructorAction:f,safe:r&&r.safe})}function Uu(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 Bi(n,i,r){const{stackTraceLimit:a}=Error;Error.stackTraceLimit=0;try{return Fu(n,i,r)}finally{Error.stackTraceLimit=a}}function vb(n,i){const{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return Fu(n,i,{safe:!0})}catch{return}finally{Error.stackTraceLimit=r}}mn.exports=Bi;mn.exports.default=Bi;mn.exports.parse=Bi;mn.exports.safeParse=vb;mn.exports.scan=Uu;var wb=mn.exports;const yu=Lu(wb);function yb(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 yi=Symbol("aui.parse-partial-json-object.meta"),Sb=n=>{if(n.length===0)return{[yi]:{state:"partial",partialPath:[]}};try{const i=yu.parse(n);if(typeof i!="object"||i===null)throw new Error("argsText is expected to be an object");return i[yi]={state:"complete",partialPath:[]},i}catch{try{const[i,r]=yb(n),a=yu.parse(i);if(typeof a!="object"||a===null)throw new Error("argsText is expected to be an object");return a[yi]={state:"partial",partialPath:r},a}catch{return}}},ki=(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:Tt,...pt}=A,ut={...pt,toolCallId:A.toolCallId??`tool-${Li()}`,...K!==void 0&&{parentId:K},...Tt!==void 0&&{messages:Tt}};return A.args?{...ut,args:A.args,argsText:A.argsText??JSON.stringify(A.args)}:{...ut,args:Sb(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}`)}}},Di={fromArray:n=>{const i=n.map(r=>ki(r,Li(),Nu(!1,!1,!1,!1,void 0)));return{messages:i.map((r,a)=>({parentId:a>0?i[a-1].id:null,message:r}))}}},Kr=n=>n.next?Kr(n.next):"current"in n?n:null,xb=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}},Wu=class{constructor(){S(this,"messages",new Map);S(this,"head",null);S(this,"root",{children:[],next:null});S(this,"_messages",new xb(()=>{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],(Kr(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=pb();while(this.messages.has(r));return this.addOrUpdateMessage(n,ki(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=Kr(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=Kr(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)}},Xr=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()}}},re=Symbol("skip-update"),Ni=class extends Xr{constructor(i){super();S(this,"_previousStateDirty",!0);S(this,"_previousState");S(this,"getState",()=>{if(!this.isConnected||this._previousStateDirty){const i=this.binding.getState();i!==re&&(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)}},Hr=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 Eb(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 ne=class extends Xr{constructor(i){super();S(this,"_previousState");S(this,"getState",()=>(this.isConnected||this._syncState(),this._previousState));this.binding=i;const r=i.getState();if(r===re)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===re||Eb(i,this._previousState)?!1:(this._previousState=i,!0)}_connect(){const i=()=>{this._syncState()&&this.notifySubscribers()};return this.binding.subscribe(i)}},_n=Symbol("innerMessage"),Tb=n=>n[_n],Jn=n=>n.content.filter(r=>r.type==="text").map(r=>r.text).join(`
|
|
12
|
-
|
|
13
|
-
`),$u=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)}},qu=class extends $u{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)}},Ab=class extends qu{get source(){return"thread-composer"}},Cb=class extends qu{get source(){return"edit-composer"}},Ib=class extends $u{get source(){return"message"}constructor(n){super(n)}remove(){throw new Error("Message attachments cannot be removed")}},zu=class extends Xr{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()}}},Hu=Object.freeze([]),Ju=Object.freeze({}),Rb=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)??Hu,text:(n==null?void 0:n.text)??"",role:(n==null?void 0:n.role)??"user",runConfig:(n==null?void 0:n.runConfig)??Ju,attachmentAccept:(n==null?void 0:n.attachmentAccept)??"",value:(n==null?void 0:n.text)??""}),Mb=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)??Hu,runConfig:(n==null?void 0:n.runConfig)??Ju,attachmentAccept:(n==null?void 0:n.attachmentAccept)??"",value:(n==null?void 0:n.text)??""}),Gu=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 zu({event:n,binding:this._core}),this._eventSubscriptionSubjects.set(n,r)),r.subscribe(i)}},Pb=class extends Gu{constructor(i){const r=new Ni({path:i.path,getState:()=>Rb(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 Ab(new ne({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"}:re},subscribe:r=>this._core.subscribe(r)}),this._core)}},Ob=class extends Gu{constructor(i,r){const a=new Ni({path:i.path,getState:()=>Mb(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 Cb(new ne({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"}:re},subscribe:r=>this._core.subscribe(r)}),this._core)}},Su=Symbol.for("aui.tool-response"),Lb=class Ci{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[Su](){return!0}static[Symbol.hasInstance](i){return typeof i=="object"&&i!==null&&Su in i}static toResponse(i){return i instanceof Ci?i:new Ci({result:i===void 0?"<no result>":i})}},xu=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=Lb.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)}},Yr=class extends Xr{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()}}},Jr=Object.freeze({type:"complete"}),Bb=(n,i,r)=>{if(n.role!=="assistant")return Jr;if(r.type==="tool-call")return r.result?Jr:n.status;const a=i===Math.max(0,n.content.length-1);return n.status.type==="requires-action"?Jr:a?n.status:Jr},Eu=(n,i)=>{const r=n.content[i];if(!r)return re;const a=Bb(n,i,r);return Object.freeze({...r,[_n]:r[_n],status:a})},kb=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 Ob(new Yr({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 Jn(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 xu(new ne({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${n}]`,messagePartSelector:{type:"index",index:n}},getState:()=>Eu(this.getState(),n),subscribe:i=>this._core.subscribe(i)}),this._core,this._threadBinding)}getMessagePartByToolCallId(n){return new xu(new ne({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?re:Eu(i,r)},subscribe:i=>this._core.subscribe(i)}),this._core,this._threadBinding)}getAttachmentByIndex(n){return new Ib(new ne({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"}:re},subscribe:i=>this._core.subscribe(i)}))}},Db=n=>({parentId:n.parentId??null,sourceId:n.sourceId??null,runConfig:n.runConfig??{},...n.stream?{stream:n.stream}:{}}),Nb=n=>({parentId:n.parentId??null,sourceId:n.sourceId??null,runConfig:n.runConfig??{}}),Fb=(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}},Ub=(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})},Wb=class{constructor(n,i){S(this,"_threadBinding");S(this,"composer");S(this,"_eventSubscriptionSubjects",new Map);const r=new ne({path:n.path,getState:()=>Ub(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 Pb(new Yr({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(Fb(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(Nb(i))}unstable_resumeRun(n){return this._threadBinding.getState().resumeRun(Db(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 kb(new ne({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 re;const w=this._threadBinding.getState().getBranches(r.id),I=r.metadata.submittedFeedback;return{...r,[_n]:r[_n],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 zu({event:n,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(n,r)),r.subscribe(i)}},$b=n=>({mainThreadId:n.mainThreadId,newThread:n.newThreadId,threads:n.threadIds,archivedThreads:n.archivedThreadIds,isLoading:n.isLoading,threadItems:n.threadData}),Gr=(n,i)=>{if(i===void 0)return re;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}:re},qb=class{constructor(n,i=Wb){S(this,"_getState");S(this,"_mainThreadListItemRuntime");S(this,"main");this._core=n,this._runtimeFactory=i;const r=new Ni({path:{},getState:()=>$b(n),subscribe:a=>n.subscribe(a)});this._getState=r.getState.bind(r),this._mainThreadListItemRuntime=new Hr(new ne({path:{ref:"threadItems[main]",threadSelector:{type:"main"}},getState:()=>Gr(this._core,this._core.mainThreadId),subscribe:a=>this._core.subscribe(a)}),this._core),this.main=new i(new Yr({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 Yr({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 Hr(new ne({path:{ref:`threadItems[${n}]`,threadSelector:{type:"index",index:n}},getState:()=>Gr(this._core,this._core.threadIds[n]),subscribe:i=>this._core.subscribe(i)}),this._core)}getArchivedItemByIndex(n){return new Hr(new ne({path:{ref:`archivedThreadItems[${n}]`,threadSelector:{type:"archiveIndex",index:n}},getState:()=>Gr(this._core,this._core.archivedThreadIds[n]),subscribe:i=>this._core.subscribe(i)}),this._core)}getItemById(n){return new Hr(new ne({path:{ref:`threadItems[threadId=${n}]`,threadSelector:{type:"threadId",threadId:n}},getState:()=>Gr(this._core,n),subscribe:i=>this._core.subscribe(i)}),this._core)}},zb=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 Hb(n.file)}]}}async remove(){}},Hb=n=>new Promise((i,r)=>{const a=new FileReader;a.onload=()=>i(a.result),a.onerror=h=>r(h),a.readAsDataURL(n)});function Si(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 Jb=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(Si(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(Si(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(Si({name:n.name,type:n.contentType},r.accept))return r.remove(n);throw new Error("No matching adapter found for attachment")}},Gb=U.createContext(null),Kb=()=>U.useContext(Gb),Je=Object.freeze([]),Ge="DEFAULT_THREAD_ID",Yb=Object.freeze([Ge]),Ku=Object.freeze({id:Ge,remoteId:void 0,externalId:void 0,status:"regular"}),Vb=Promise.resolve(),Tu=Object.freeze({[Ge]:Ku}),Zb=class{constructor(n={},i){S(this,"_mainThreadId",Ge);S(this,"_threads",Yb);S(this,"_archivedThreads",Je);S(this,"_threadData",Tu);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 Vb}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===Ge)return Ku}__internal_setAdapter(n,i=!1){var I,P,C,A;const r=this.adapter;this.adapter=n;const a=n.threadId??Ge,h=n.threads??Je,f=n.archivedThreads??Je,p=r.threadId??Ge,m=r.threads??Je,w=r.archivedThreads??Je;!i&&p===a&&m===h&&w===f||(this._threadData={...Tu,...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))??Je),w!==f&&(this._archivedThreads=((A=this.adapter.archivedThreads)==null?void 0:A.map(R=>R.id))??Je),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()}},Au=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})}},Xb=class extends Du{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=Jn(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){Jn(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()}},Qb=class{constructor(n){S(this,"_subscriptions",new Set);S(this,"_isInitialized",!1);S(this,"repository",new Wu);S(this,"composer",new lb(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 Xb(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(Jn(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(Di.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)}}},jb=Object.freeze([]),tm=(n,i)=>{var r;return n&&((r=i[i.length-1])==null?void 0:r.role)!=="assistant"},em=class extends Qb{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 Au);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(Tb).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??jb,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 Au;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,Tt=Nu(K,r,!1,!1,void 0);if(C&&(C.role!=="assistant"||!bb(C.status)||C.status===Tt))return C;const pt=i.convertMessage(A,R),ut=ki(pt,R.toString(),Tt);return ut[_n]=A,ut}):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),tm(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(Jn(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 Wu;r.import(Di.fromArray(i??[])),this.updateMessages(r.getMessages())}import(i){this._assistantOptimisticId=null,super.import(i),this._store.onImport&&this._store.onImport(this.repository.getMessages())}},Cu=n=>{var i;return((i=n.adapters)==null?void 0:i.threadList)??{}},nm=class extends ub{constructor(i){super();S(this,"threads");this.threads=new Zb(Cu(i),()=>new em(this._contextProvider,i))}setAdapter(i){this.threads.__internal_setAdapter(Cu(i)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(i)}},rm=n=>{const[i]=U.useState(()=>new nm(n));U.useEffect(()=>{i.setAdapter(n)});const{modelContext:r}=Kb()??{};return U.useEffect(()=>{if(r)return i.registerModelContextProvider(r)},[r,i]),U.useMemo(()=>new av(i),[i])};function sm(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 im(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 zn=null;function om(n,i){n.currentIndex=0;const r=zn;zn=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{zn=r}}function Fi(){if(!zn)throw new Error("No resource fiber available");return zn}function Yu(n,i){const r=n[Vu];if(!r)throw new Error("ResourceElement.type is not a valid Resource");return r(i)}var Vu=Symbol("fnSymbol");function Qr(n,i){return{resource:n,scheduleRerender:i,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function pn(n){n.isMounted=!1,im(n)}function Gn(n,i){const r={commitTasks:[],props:i,state:void 0};return om(n,()=>{n.renderContext=r;try{r.state=Yu(n.resource,i)}finally{n.renderContext=void 0}}),r}function gn(n,i){n.isMounted=!0,n.isNeverMounted=!1,sm(i,n)}var am=globalThis.__ASSISTANT_UI_DISABLE_LAYOUT_EFFECT__===!0,Iu=am?U.useEffect:U.useLayoutEffect;function um(n){const[,i]=U.useState({}),r=U.useMemo(()=>Qr(n.type,()=>i({})),[n.type,i]),a=Gn(r,n.props);return Iu(()=>()=>pn(r),[]),Iu(()=>{gn(r,a)}),a.state}var Zu=n=>typeof n=="string"?{scope:n.split(".")[0],event:n}:{scope:n.scope,event:n.event},xi=(n,i,r)=>i===n,dn,Ei=()=>{if(dn)return dn;const n=()=>({apis:new Map,nextId:0,listeners:new Set});if(typeof window>"u")return dn=n(),dn;const i=window.__ASSISTANT_UI_DEVTOOLS_HOOK__;if(i)return dn=i,i;const r=n();return window.__ASSISTANT_UI_DEVTOOLS_HOOK__=r,dn=r,r},ee,cm=(ee=class{static register(i){var m,w;const r=Ei();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>ee.MAX_EVENT_LOGS_PER_API&&(P.logs=P.logs.slice(-200)),ee.notifyListeners(a))}),p=(w=i.subscribe)==null?void 0:w.call(i,()=>{ee.notifyListeners(a)});return r.apis.set(a,h),ee.notifyListeners(a),()=>{const I=Ei();I.apis.get(a)&&(f==null||f(),p==null||p(),I.apis.delete(a),ee.notifyListeners(a))}}static notifyListeners(i){Ei().listeners.forEach(a=>a(i))}},S(ee,"MAX_EVENT_LOGS_PER_API",200),ee);function dt(n){const i=(r,a)=>({type:i,props:r,...(a==null?void 0:a.key)!==void 0&&{key:a.key}});return i[Vu]=n,i}var hm=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 lm(n){const i=Fi(),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,hm(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 ce(n){const i=lm(n);return[i.value,i.set]}function fm(){const n=Fi(),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 Dt(n,i){const r=Fi(),a=fm();r.renderContext.commitTasks.push({effect:n,deps:i,cellIndex:a})}function Vr(n){const[i]=ce(()=>({current:n}));return i}var dm=(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=Vr();return r.current||(r.current={value:n(),deps:i}),dm(r.current.deps,i)||(r.current.value=n(),r.current.deps=i),r.current.value};function Ti(n,i){const[r,a]=ce({}),h=rt(()=>Qr(n.type,()=>a({})),[n.type]),f=i?rt(()=>n.props,i):n.props,p=rt(()=>Gn(h,f),[h,f,r]);return Dt(()=>()=>pn(h),[h]),Dt(()=>{gn(h,p)},[h,p]),p.state}function se(n){return Yu(n.type,n.props)}function pm(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]=ce({}),h=rt(()=>new Map(n.map(m=>[m.key,m])),[n]),[f]=ce(()=>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&&pn(C),C=Qr(I.type,()=>a({})),f.set(P,C));const A=Gn(C,I.props);m.set(P,A)}),f.forEach((I,P)=>{w.has(P)||(pn(I),f.delete(P))}),m},[h,r]);return Dt(()=>{p.forEach((m,w)=>{const I=f.get(w);I&&gn(I,m)})},[p,f]),Dt(()=>()=>{f.forEach(m=>{pn(m)}),f.clear()},[f]),rt(()=>n.map(m=>{var w;return(w=p.get(m.key))==null?void 0:w.state}),[n,p])}var Ii=[],Ri=!1;function gm(){Ri=!1;const n=Ii;Ii=[];for(const i of n)try{i()}catch(r){console.error("Error in scheduled task:",r)}}function _m(n){Ii.push(n),Ri||(Ri=!0,queueMicrotask(gm))}var Ke,bm=(Ke=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,_m(()=>{this._hasScheduledTask=!1,this.flushSync()}))}flushSync(){if(this._isFlushing)return;this._isFlushing=!0;let i=0;try{for(;this._isDirty;){if(i++,i>Ke.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(Ke,"MAX_FLUSH_DEPTH",50),Ke),mm=dt(({element:n,onUpdateInput:i,onFlushSync:r,onDispose:a})=>{const[h,f]=ce(n.props),p=se({type:n.type,props:h}),m=Vr(new Set).current,w=Vr(p);return Dt(()=>{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}),[])}),vm=(n,i=!1)=>{let r=!i;const a={element:n,onUpdateInput:()=>{r||(r=!0,gn(f,p))},onFlushSync:()=>{h.flushSync()},onDispose:()=>pn(f)},h=new bm(()=>{p=Gn(f,a),r&&gn(f,p)}),f=Qr(mm,()=>h.markDirty());let p=Gn(f,a);return r&&gn(f,p),p.state},Hn=Symbol("tap.Context"),Xu=n=>({[Hn]:n}),Qu=(n,i,r)=>{const a=n[Hn];n[Hn]=i;try{return r()}finally{n[Hn]=a}},ju=n=>n[Hn];const Ru=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},wm=n=>n?Ru(n):Ru,ym=n=>n;function Sm(n,i=ym){const r=U.useSyncExternalStore(n.subscribe,U.useCallback(()=>i(n.getState()),[n,i]),U.useCallback(()=>i(n.getInitialState()),[n,i]));return U.useDebugValue(r),r}const Mu=n=>{const i=wm(n),r=a=>Sm(i,a);return Object.assign(r,i),r},xm=n=>n?Mu(n):Mu;var Em=dt(n=>{const i=rt(()=>vm(n,!0),[n.type]);return Dt(()=>{i.updateInput(n.props)}),i}),Tm=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}},he=(n,i)=>{const r=Vr(n);Dt(()=>{r.current=n});const a=rt(()=>new Proxy({},new Tm(()=>r.current)),[]),h=i==null?void 0:i.key,f=n.getState();return rt(()=>({key:h,state:f,api:a}),[f,h])},tc=Xu(null),Am=(n,i)=>Qu(tc,n,i),ec=()=>{const n=ju(tc);if(!n)throw new Error("Model context is not available in this context");return n},Cm=dt(({toolkit:n})=>{const[i,r]=ce(()=>({tools:{}})),a=ec();Dt(()=>{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 he({getState:()=>i,setToolUI:h})}),Im=dt(()=>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})})}}},[])),nc=Xu(null),Rm=(n,i)=>Qu(nc,n,i),Ui=()=>{const n=ju(nc);if(!n)throw new Error("Events context is not available");return n},Mm=dt(()=>{const[n]=ce(()=>({})),i=new ku;return he({getState:()=>n,getModelContext:()=>i.getModelContext(),subscribe:r=>i.subscribe(r),register:r=>i.registerModelContextProvider(r)})}),Pm=dt(({threads:n,modelContext:i,tools:r})=>{const a=se(Im()),{threads:h,tools:f,modelContext:p}=Rm(a,()=>{const w=Ti(i??Mm(),[i]);return Am(w.api,()=>({modelContext:w,tools:Ti(r??Cm({}),[r]),threads:Ti(n,[n])}))}),m=rt(()=>({threads:h.state,tools:f.state,modelContext:p.state}),[h.state,f.state,p.state]);return he({getState:()=>m,threads:h.api,tools:f.api,modelContext:p.api,on:a.on})}),Om=n=>{const i=()=>n.getState().api.threads.item("main");return{threads:Et({source:"root",query:{},get:()=>n.getState().api.threads}),tools:Et({source:"root",query:{},get:()=>n.getState().api.tools}),modelContext:Et({source:"root",query:{},get:()=>n.getState().api.modelContext}),thread:Et({source:"threads",query:{type:"main"},get:()=>n.getState().api.threads.thread("main")}),threadListItem:Et({source:"threads",query:{type:"main"},get:()=>i()}),composer:Et({source:"thread",query:{},get:()=>n.getState().api.threads.thread("main").composer}),on(r,a){const{event:h,scope:f}=Zu(r);if(f==="*")return n.getState().api.on(h,a);if(xi("thread",f)||xi("thread-list-item",f)||xi("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}},Lm=n=>{const i=sc(),r=um(Em(Pm(n))),a=U.useMemo(()=>Om(r),[r]);return U.useMemo(()=>Fm(i,a),[i,a])},Et=n=>{const i=n.get;return i.source=n.source,i.query=n.query,i},Oe=()=>()=>{},rc=U.createContext({threads:Et({source:null,query:{},get:()=>{throw new Error("Threads is only available inside <AssistantProvider />")}}),tools:Et({source:null,query:{},get:()=>{throw new Error("Tools is only available inside <AssistantProvider />")}}),modelContext:Et({source:null,query:{},get:()=>{throw new Error("ModelContext is only available inside <AssistantProvider />")}}),threadListItem:Et({source:null,query:{},get:()=>{throw new Error("ThreadListItem is only available inside <AssistantProvider />")}}),thread:Et({source:null,query:{},get:()=>{throw new Error("Thread is only available inside <AssistantProvider />")}}),composer:Et({source:null,query:{},get:()=>{throw new Error("Composer is only available inside <AssistantProvider />")}}),message:Et({source:null,query:{},get:()=>{throw new Error("Message is only available inside <ThreadPrimitive.Messages />")}}),part:Et({source:null,query:{},get:()=>{throw new Error("Part is only available inside <MessagePrimitive.Parts />")}}),attachment:Et({source:null,query:{},get:()=>{throw new Error("Attachment is only available inside <MessagePrimitive.Attachments /> or <ComposerPrimitive.Attachments />")}}),subscribe:Oe,flushSync:Oe,on:n=>{const{scope:i}=Zu(n);throw new Error(`Event scope is not available in this component: ${i}`)}}),sc=()=>U.useContext(rc),Bm=n=>Lm(n);function km(n){return n?Bm(n):sc()}var Dm=(n,i)=>n===Oe?i:i===Oe?n:(...r)=>{n(...r),i(...r)},Nm=(n,i)=>n===Oe?i:i===Oe?n:(...r)=>{const a=n(...r),h=i(...r);return()=>{a(),h()}},Fm=(n,i)=>{const r=i.subscribe,a=i.flushSync;return{...n,...i,subscribe:Nm(n.subscribe,r??Oe),flushSync:Dm(n.flushSync,a??Oe)}},Um=({api:n,children:i,devToolsVisible:r=!0})=>(U.useEffect(()=>{if(!(!r||!n.subscribe))return cm.register(n)},[n,r]),Pe.jsx(rc.Provider,{value:n,children:i}));function Wm(n,i){function r(a){const h=U.useContext(n);if(!(a!=null&&a.optional)&&!h)throw new Error(`This component must be used within ${i}.`);return h}return r}function $m(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 ic=U.createContext(null),qm=Wm(ic,"ThreadPrimitive.Viewport"),{useThreadViewportStore:zm}=$m(qm,"useThreadViewport"),Ve=n=>{const[,i]=ce(n.getState);return Dt(()=>(i(n.getState()),n.subscribe(()=>{i(n.getState())})),[n]),n.getState()},Hm=dt(({runtime:n})=>{const i=Ve(n),r=Ui();return Dt(()=>{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]),he({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})}),Kn=n=>{const i=pm(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}}},oc=dt(({runtime:n})=>{const i=Ve(n);return he({getState:()=>i,remove:n.remove,__internal_getRuntime:()=>n},{key:i.id})}),Jm=dt(({runtime:n,index:i})=>{const r=rt(()=>n.getAttachmentByIndex(i),[n,i]);return se(oc({runtime:r}))}),ac=dt(({threadIdRef:n,messageIdRef:i,runtime:r})=>{const a=Ve(r),h=Ui();Dt(()=>{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=Kn(a.attachments.map((m,w)=>Jm({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 he({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})}),Gm=dt(({runtime:n})=>{const i=Ve(n);return he({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})}),Km=dt(({runtime:n,index:i})=>{const r=rt(()=>n.getAttachmentByIndex(i),[n,i]);return se(oc({runtime:r}))}),Ym=dt(({runtime:n,index:i})=>{const r=rt(()=>n.getMessagePartByIndex(i),[n,i]);return se(Gm({runtime:r}))}),Vm=dt(({runtime:n,threadIdRef:i})=>{var A;const r=Ve(n),[a,h]=ce(!1),[f,p]=ce(!1),m=rt(()=>({get current(){return n.getState().id}}),[n]),w=se(ac({runtime:n.composer,threadIdRef:i,messageIdRef:m})),I=Kn(r.content.map((R,K)=>Ym({runtime:n,index:K},{key:K}))),P=Kn(((A=r.attachments)==null?void 0:A.map((R,K)=>Km({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 he({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})}),Zm=dt(({runtime:n,id:i,threadIdRef:r})=>{const a=rt(()=>n.getMessageById(i),[n,i]);return se(Vm({runtime:a,threadIdRef:r}))}),Xm=dt(({runtime:n})=>{const i=Ve(n),r=Ui();Dt(()=>{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=se(ac({runtime:n.composer,threadIdRef:a})),f=Kn(i.messages.map(m=>Zm({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 he({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})}),Qm=dt(({runtime:n,id:i})=>{const r=rt(()=>n.getItemById(i),[n,i]);return se(Hm({runtime:r}))}),jm=dt(({runtime:n,__internal_assistantRuntime:i})=>{const r=Ve(n),a=se(Xm({runtime:n.main})),h=Kn(Object.keys(r.threadItems).map(p=>Qm({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 he({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})}),tv=dt(n=>{const i=ec();return Dt(()=>n.registerModelContextProvider(i),[n,i]),se(jm({runtime:n.threads,__internal_assistantRuntime:n}))}),Ai=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()}}}}},ev=(n={})=>{const i=new Set,r=Ai(p=>{f.setState({height:{...f.getState().height,viewport:p}})}),a=Ai(p=>{f.setState({height:{...f.getState().height,inset:p}})}),h=Ai(p=>{f.setState({height:{...f.getState().height,userMessage:p}})}),f=xm(()=>({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},Pu=n=>n,nv=n=>{const i=zm({optional:!0}),[r]=U.useState(()=>ev(n));return U.useEffect(()=>i==null?void 0:i.getState().onScrollToBottom(()=>{r.getState().scrollToBottom()}),[i,r]),U.useEffect(()=>{if(i)return r.subscribe(a=>{i.getState().isAtBottom!==a.isAtBottom&&Pu(i).setState({isAtBottom:a.isAtBottom})})},[r,i]),U.useEffect(()=>{const a={turnAnchor:n.turnAnchor??"bottom"};r.getState().turnAnchor!==a.turnAnchor&&Pu(r).setState(a)},[r,n.turnAnchor]),r},rv=({children:n,options:i={}})=>{const r=nv(i),[a]=U.useState(()=>({useThreadViewport:r}));return Pe.jsx(ic.Provider,{value:a,children:n})},sv=n=>{var i;return(i=n._core)==null?void 0:i.RenderComponent},iv=({children:n,runtime:i})=>{const r=km({threads:tv(i)}),a=sv(i);return Pe.jsxs(Um,{api:r,children:[a&&Pe.jsx(a,{}),Pe.jsx(rv,{children:n})]})},ov=U.memo(iv),av=class{constructor(n){S(this,"threads");S(this,"_thread");this._core=n,this.threads=new qb(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(Di.fromArray(n??[]))}};function uv(n){return n.filter(i=>i.finishReason==="stop"?i.text!==null&&i.text.trim()!=="":!0)}function Ou(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),uv(i)}function cv(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 Yn{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 Mi extends Yn{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(Tt=>({type:"message",payload:Tt})))}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 Pi extends Yn{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 hv{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 Oi extends Yn{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 hv(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 Zr={exports:{}};/**
|
|
1
|
+
"use strict";var mg=Object.defineProperty;var xg=(h,f,i)=>f in h?mg(h,f,{enumerable:!0,configurable:!0,writable:!0,value:i}):h[f]=i;var D=(h,f,i)=>xg(h,typeof f!="symbol"?f+"":f,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Zi=require("react/jsx-runtime"),j=require("react"),xr=require("@assistant-ui/react");let Sg=0;function Ag(){return`msg_${Date.now()}_${Sg++}`}function bg(h){return h.thought&&(h={...h,type:"reasoning"}),h.id?h.createdAt?h:{...h,createdAt:new Date}:{...h,id:Ag(),createdAt:h.createdAt||new Date}}function Cg(h){return h.filter(f=>f.finishReason==="stop"?f.text!==null&&f.text.trim()!=="":!0)}function ee(h){const f=[];let i=null;for(let _ of h)if(_=bg(_),_.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),Cg(f)}function Pg(h){var _,v,S;const f=h.file?[{type:"file",data:h.file.url,mimeType:h.file.contentType}]:[];let i;if((h.role==="assistant"||h.role==="function")&&(h.status?i=h.status:h.finishReason==="stop"?i={type:"complete",reason:"stop"}:h.finishReason==="function_call"?i={type:"complete",reason:"stop"}:h.finishReason||(i=void 0)),h.role==="function"){const E={id:h.id,role:"assistant",createdAt:h.createdAt,content:((_=h.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=h.functionResponse)==null?void 0:M.result}}))??[],metadata:{...h.metadata,custom:{protocol:h.protocol,sessionId:h.sessionId,sources:h.sources,...(v=h.metadata)==null?void 0:v.custom}}};return i?{...E,status:i}:E}const p={id:h.id,role:h.role,createdAt:h.createdAt,content:h.type==="reasoning"?[{type:"reasoning",text:h.text},...f]:[{type:"text",text:h.text},...f],metadata:{...h.metadata,custom:{protocol:h.protocol,sessionId:h.sessionId,sources:h.sources,type:h.type,...(S=h.metadata)==null?void 0:S.custom}}};return h.role==="assistant"&&i?{...p,status:i}:p}class Ce{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 Yi extends Ce{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,I,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"&&((I=i==null?void 0:i.payload)==null?void 0:I.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 J=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(J.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 Xi extends Ce{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 I=JSON.parse(M.data);this.notifyPacket(I)}),this.webSocket.addEventListener("close",M=>{var I;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."}}),(I=this.config.logger)==null||I.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 Rg{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 Qi extends Ce{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 Rg(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 be=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ig(h){return h&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")?h.default:h}var Sr={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
|
-
*/Zr.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,Tt=2,pt=1,ut=2,Zn=4,Kt=8,Le=16,Yt=32,Be=64,q=128,ct=256,X=512,Nt=30,ht="...",Ft=800,st=16,wt=1,fc=2,dc=3,ke=1/0,ye=9007199254740991,pc=17976931348623157e292,Xn=NaN,ie=4294967295,gc=ie-1,_c=ie>>>1,bc=[["ary",q],["bind",pt],["bindKey",ut],["curry",Kt],["curryRight",Le],["flip",X],["partial",Yt],["partialRight",Be],["rearg",ct]],Ze="[object Arguments]",Qn="[object Array]",mc="[object AsyncFunction]",vn="[object Boolean]",wn="[object Date]",vc="[object DOMException]",jn="[object Error]",tr="[object Function]",Wi="[object GeneratorFunction]",Vt="[object Map]",yn="[object Number]",wc="[object Null]",le="[object Object]",$i="[object Promise]",yc="[object Proxy]",Sn="[object RegExp]",Zt="[object Set]",xn="[object String]",er="[object Symbol]",Sc="[object Undefined]",En="[object WeakMap]",xc="[object WeakSet]",Tn="[object ArrayBuffer]",Xe="[object DataView]",ts="[object Float32Array]",es="[object Float64Array]",ns="[object Int8Array]",rs="[object Int16Array]",ss="[object Int32Array]",is="[object Uint8Array]",os="[object Uint8ClampedArray]",as="[object Uint16Array]",us="[object Uint32Array]",Ec=/\b__p \+= '';/g,Tc=/\b(__p \+=) '' \+/g,Ac=/(__e\(.*?\)|\b__t\)) \+\n'';/g,qi=/&(?:amp|lt|gt|quot|#39);/g,zi=/[&<>"']/g,Cc=RegExp(qi.source),Ic=RegExp(zi.source),Rc=/<%-([\s\S]+?)%>/g,Mc=/<%([\s\S]+?)%>/g,Hi=/<%=([\s\S]+?)%>/g,Pc=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Oc=/^\w*$/,Lc=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cs=/[\\^$.*+?()[\]{}|]/g,Bc=RegExp(cs.source),hs=/^\s+/,kc=/\s/,Dc=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Nc=/\{\n\/\* \[wrapped with (.+)\] \*/,Fc=/,? & /,Uc=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Wc=/[()=,{}\[\]\/\s]/,$c=/\\(\\)?/g,qc=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Ji=/\w*$/,zc=/^[-+]0x[0-9a-f]+$/i,Hc=/^0b[01]+$/i,Jc=/^\[object .+?Constructor\]$/,Gc=/^0o[0-7]+$/i,Kc=/^(?:0|[1-9]\d*)$/,Yc=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,nr=/($^)/,Vc=/['\n\r\u2028\u2029\\]/g,rr="\\ud800-\\udfff",Zc="\\u0300-\\u036f",Xc="\\ufe20-\\ufe2f",Qc="\\u20d0-\\u20ff",Gi=Zc+Xc+Qc,Ki="\\u2700-\\u27bf",Yi="a-z\\xdf-\\xf6\\xf8-\\xff",jc="\\xac\\xb1\\xd7\\xf7",th="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",eh="\\u2000-\\u206f",nh=" \\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",Vi="A-Z\\xc0-\\xd6\\xd8-\\xde",Zi="\\ufe0e\\ufe0f",Xi=jc+th+eh+nh,ls="['’]",rh="["+rr+"]",Qi="["+Xi+"]",sr="["+Gi+"]",ji="\\d+",sh="["+Ki+"]",to="["+Yi+"]",eo="[^"+rr+Xi+ji+Ki+Yi+Vi+"]",fs="\\ud83c[\\udffb-\\udfff]",ih="(?:"+sr+"|"+fs+")",no="[^"+rr+"]",ds="(?:\\ud83c[\\udde6-\\uddff]){2}",ps="[\\ud800-\\udbff][\\udc00-\\udfff]",Qe="["+Vi+"]",ro="\\u200d",so="(?:"+to+"|"+eo+")",oh="(?:"+Qe+"|"+eo+")",io="(?:"+ls+"(?:d|ll|m|re|s|t|ve))?",oo="(?:"+ls+"(?:D|LL|M|RE|S|T|VE))?",ao=ih+"?",uo="["+Zi+"]?",ah="(?:"+ro+"(?:"+[no,ds,ps].join("|")+")"+uo+ao+")*",uh="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",ch="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",co=uo+ao+ah,hh="(?:"+[sh,ds,ps].join("|")+")"+co,lh="(?:"+[no+sr+"?",sr,ds,ps,rh].join("|")+")",fh=RegExp(ls,"g"),dh=RegExp(sr,"g"),gs=RegExp(fs+"(?="+fs+")|"+lh+co,"g"),ph=RegExp([Qe+"?"+to+"+"+io+"(?="+[Qi,Qe,"$"].join("|")+")",oh+"+"+oo+"(?="+[Qi,Qe+so,"$"].join("|")+")",Qe+"?"+so+"+"+io,Qe+"+"+oo,ch,uh,ji,hh].join("|"),"g"),gh=RegExp("["+ro+rr+Gi+Zi+"]"),_h=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,bh=["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"],mh=-1,tt={};tt[ts]=tt[es]=tt[ns]=tt[rs]=tt[ss]=tt[is]=tt[os]=tt[as]=tt[us]=!0,tt[Ze]=tt[Qn]=tt[Tn]=tt[vn]=tt[Xe]=tt[wn]=tt[jn]=tt[tr]=tt[Vt]=tt[yn]=tt[le]=tt[Sn]=tt[Zt]=tt[xn]=tt[En]=!1;var j={};j[Ze]=j[Qn]=j[Tn]=j[Xe]=j[vn]=j[wn]=j[ts]=j[es]=j[ns]=j[rs]=j[ss]=j[Vt]=j[yn]=j[le]=j[Sn]=j[Zt]=j[xn]=j[er]=j[is]=j[os]=j[as]=j[us]=!0,j[jn]=j[tr]=j[En]=!1;var vh={À:"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"},wh={"&":"&","<":"<",">":">",'"':""","'":"'"},yh={"&":"&","<":"<",">":">",""":'"',"'":"'"},Sh={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},xh=parseFloat,Eh=parseInt,ho=typeof $n=="object"&&$n&&$n.Object===Object&&$n,Th=typeof self=="object"&&self&&self.Object===Object&&self,_t=ho||Th||Function("return this")(),_s=i&&!i.nodeType&&i,De=_s&&!0&&n&&!n.nodeType&&n,lo=De&&De.exports===_s,bs=lo&&ho.process,Ut=function(){try{var _=De&&De.require&&De.require("util").types;return _||bs&&bs.binding&&bs.binding("util")}catch{}}(),fo=Ut&&Ut.isArrayBuffer,po=Ut&&Ut.isDate,go=Ut&&Ut.isMap,_o=Ut&&Ut.isRegExp,bo=Ut&&Ut.isSet,mo=Ut&&Ut.isTypedArray;function Mt(_,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 Ah(_,y,v,O){for(var N=-1,Y=_==null?0:_.length;++N<Y;){var lt=_[N];y(O,lt,v(lt),_)}return O}function Wt(_,y){for(var v=-1,O=_==null?0:_.length;++v<O&&y(_[v],v,_)!==!1;);return _}function Ch(_,y){for(var v=_==null?0:_.length;v--&&y(_[v],v,_)!==!1;);return _}function vo(_,y){for(var v=-1,O=_==null?0:_.length;++v<O;)if(!y(_[v],v,_))return!1;return!0}function Se(_,y){for(var v=-1,O=_==null?0:_.length,N=0,Y=[];++v<O;){var lt=_[v];y(lt,v,_)&&(Y[N++]=lt)}return Y}function ir(_,y){var v=_==null?0:_.length;return!!v&&je(_,y,0)>-1}function ms(_,y,v){for(var O=-1,N=_==null?0:_.length;++O<N;)if(v(y,_[O]))return!0;return!1}function et(_,y){for(var v=-1,O=_==null?0:_.length,N=Array(O);++v<O;)N[v]=y(_[v],v,_);return N}function xe(_,y){for(var v=-1,O=y.length,N=_.length;++v<O;)_[N+v]=y[v];return _}function vs(_,y,v,O){var N=-1,Y=_==null?0:_.length;for(O&&Y&&(v=_[++N]);++N<Y;)v=y(v,_[N],N,_);return v}function Ih(_,y,v,O){var N=_==null?0:_.length;for(O&&N&&(v=_[--N]);N--;)v=y(v,_[N],N,_);return v}function ws(_,y){for(var v=-1,O=_==null?0:_.length;++v<O;)if(y(_[v],v,_))return!0;return!1}var Rh=ys("length");function Mh(_){return _.split("")}function Ph(_){return _.match(Uc)||[]}function wo(_,y,v){var O;return v(_,function(N,Y,lt){if(y(N,Y,lt))return O=Y,!1}),O}function or(_,y,v,O){for(var N=_.length,Y=v+(O?1:-1);O?Y--:++Y<N;)if(y(_[Y],Y,_))return Y;return-1}function je(_,y,v){return y===y?zh(_,y,v):or(_,yo,v)}function Oh(_,y,v,O){for(var N=v-1,Y=_.length;++N<Y;)if(O(_[N],y))return N;return-1}function yo(_){return _!==_}function So(_,y){var v=_==null?0:_.length;return v?xs(_,y)/v:Xn}function ys(_){return function(y){return y==null?r:y[_]}}function Ss(_){return function(y){return _==null?r:_[y]}}function xo(_,y,v,O,N){return N(_,function(Y,lt,Q){v=O?(O=!1,Y):y(v,Y,lt,Q)}),v}function Lh(_,y){var v=_.length;for(_.sort(y);v--;)_[v]=_[v].value;return _}function xs(_,y){for(var v,O=-1,N=_.length;++O<N;){var Y=y(_[O]);Y!==r&&(v=v===r?Y:v+Y)}return v}function Es(_,y){for(var v=-1,O=Array(_);++v<_;)O[v]=y(v);return O}function Bh(_,y){return et(y,function(v){return[v,_[v]]})}function Eo(_){return _&&_.slice(0,Io(_)+1).replace(hs,"")}function Pt(_){return function(y){return _(y)}}function Ts(_,y){return et(y,function(v){return _[v]})}function An(_,y){return _.has(y)}function To(_,y){for(var v=-1,O=_.length;++v<O&&je(y,_[v],0)>-1;);return v}function Ao(_,y){for(var v=_.length;v--&&je(y,_[v],0)>-1;);return v}function kh(_,y){for(var v=_.length,O=0;v--;)_[v]===y&&++O;return O}var Dh=Ss(vh),Nh=Ss(wh);function Fh(_){return"\\"+Sh[_]}function Uh(_,y){return _==null?r:_[y]}function tn(_){return gh.test(_)}function Wh(_){return _h.test(_)}function $h(_){for(var y,v=[];!(y=_.next()).done;)v.push(y.value);return v}function As(_){var y=-1,v=Array(_.size);return _.forEach(function(O,N){v[++y]=[N,O]}),v}function Co(_,y){return function(v){return _(y(v))}}function Ee(_,y){for(var v=-1,O=_.length,N=0,Y=[];++v<O;){var lt=_[v];(lt===y||lt===P)&&(_[v]=P,Y[N++]=v)}return Y}function ar(_){var y=-1,v=Array(_.size);return _.forEach(function(O){v[++y]=O}),v}function qh(_){var y=-1,v=Array(_.size);return _.forEach(function(O){v[++y]=[O,O]}),v}function zh(_,y,v){for(var O=v-1,N=_.length;++O<N;)if(_[O]===y)return O;return-1}function Hh(_,y,v){for(var O=v+1;O--;)if(_[O]===y)return O;return O}function en(_){return tn(_)?Gh(_):Rh(_)}function Xt(_){return tn(_)?Kh(_):Mh(_)}function Io(_){for(var y=_.length;y--&&kc.test(_.charAt(y)););return y}var Jh=Ss(yh);function Gh(_){for(var y=gs.lastIndex=0;gs.test(_);)++y;return y}function Kh(_){return _.match(gs)||[]}function Yh(_){return _.match(ph)||[]}var Vh=function _(y){y=y==null?_t:nn.defaults(_t.Object(),y,nn.pick(_t,bh));var v=y.Array,O=y.Date,N=y.Error,Y=y.Function,lt=y.Math,Q=y.Object,Cs=y.RegExp,Zh=y.String,$t=y.TypeError,ur=v.prototype,Xh=Y.prototype,rn=Q.prototype,cr=y["__core-js_shared__"],hr=Xh.toString,Z=rn.hasOwnProperty,Qh=0,Ro=function(){var t=/[^.]+$/.exec(cr&&cr.keys&&cr.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),lr=rn.toString,jh=hr.call(Q),tl=_t._,el=Cs("^"+hr.call(Z).replace(cs,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),fr=lo?y.Buffer:r,Te=y.Symbol,dr=y.Uint8Array,Mo=fr?fr.allocUnsafe:r,pr=Co(Q.getPrototypeOf,Q),Po=Q.create,Oo=rn.propertyIsEnumerable,gr=ur.splice,Lo=Te?Te.isConcatSpreadable:r,Cn=Te?Te.iterator:r,Ne=Te?Te.toStringTag:r,_r=function(){try{var t=qe(Q,"defineProperty");return t({},"",{}),t}catch{}}(),nl=y.clearTimeout!==_t.clearTimeout&&y.clearTimeout,rl=O&&O.now!==_t.Date.now&&O.now,sl=y.setTimeout!==_t.setTimeout&&y.setTimeout,br=lt.ceil,mr=lt.floor,Is=Q.getOwnPropertySymbols,il=fr?fr.isBuffer:r,Bo=y.isFinite,ol=ur.join,al=Co(Q.keys,Q),ft=lt.max,mt=lt.min,ul=O.now,cl=y.parseInt,ko=lt.random,hl=ur.reverse,Rs=qe(y,"DataView"),In=qe(y,"Map"),Ms=qe(y,"Promise"),sn=qe(y,"Set"),Rn=qe(y,"WeakMap"),Mn=qe(Q,"create"),vr=Rn&&new Rn,on={},ll=ze(Rs),fl=ze(In),dl=ze(Ms),pl=ze(sn),gl=ze(Rn),wr=Te?Te.prototype:r,Pn=wr?wr.valueOf:r,Do=wr?wr.toString:r;function c(t){if(it(t)&&!F(t)&&!(t instanceof J)){if(t instanceof qt)return t;if(Z.call(t,"__wrapped__"))return Na(t)}return new qt(t)}var an=function(){function t(){}return function(e){if(!nt(e))return{};if(Po)return Po(e);t.prototype=e;var s=new t;return t.prototype=r,s}}();function yr(){}function qt(t,e){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=r}c.templateSettings={escape:Rc,evaluate:Mc,interpolate:Hi,variable:"",imports:{_:c}},c.prototype=yr.prototype,c.prototype.constructor=c,qt.prototype=an(yr.prototype),qt.prototype.constructor=qt;function J(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=ie,this.__views__=[]}function _l(){var t=new J(this.__wrapped__);return t.__actions__=At(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=At(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=At(this.__views__),t}function bl(){if(this.__filtered__){var t=new J(this);t.__dir__=-1,t.__filtered__=!0}else t=this.clone(),t.__dir__*=-1;return t}function ml(){var t=this.__wrapped__.value(),e=this.__dir__,s=F(t),o=e<0,u=s?t.length:0,l=Pf(0,u,this.__views__),d=l.start,g=l.end,b=g-d,x=o?g:d-1,E=this.__iteratees__,T=E.length,M=0,L=mt(b,this.__takeCount__);if(!s||!o&&u==b&&L==b)return oa(t,this.__actions__);var k=[];t:for(;b--&&M<L;){x+=e;for(var $=-1,D=t[x];++$<T;){var H=E[$],G=H.iteratee,Bt=H.type,xt=G(D);if(Bt==fc)D=xt;else if(!xt){if(Bt==wt)continue t;break t}}k[M++]=D}return k}J.prototype=an(yr.prototype),J.prototype.constructor=J;function Fe(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 vl(){this.__data__=Mn?Mn(null):{},this.size=0}function wl(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}function yl(t){var e=this.__data__;if(Mn){var s=e[t];return s===w?r:s}return Z.call(e,t)?e[t]:r}function Sl(t){var e=this.__data__;return Mn?e[t]!==r:Z.call(e,t)}function xl(t,e){var s=this.__data__;return this.size+=this.has(t)?0:1,s[t]=Mn&&e===r?w:e,this}Fe.prototype.clear=vl,Fe.prototype.delete=wl,Fe.prototype.get=yl,Fe.prototype.has=Sl,Fe.prototype.set=xl;function fe(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 El(){this.__data__=[],this.size=0}function Tl(t){var e=this.__data__,s=Sr(e,t);if(s<0)return!1;var o=e.length-1;return s==o?e.pop():gr.call(e,s,1),--this.size,!0}function Al(t){var e=this.__data__,s=Sr(e,t);return s<0?r:e[s][1]}function Cl(t){return Sr(this.__data__,t)>-1}function Il(t,e){var s=this.__data__,o=Sr(s,t);return o<0?(++this.size,s.push([t,e])):s[o][1]=e,this}fe.prototype.clear=El,fe.prototype.delete=Tl,fe.prototype.get=Al,fe.prototype.has=Cl,fe.prototype.set=Il;function de(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 Rl(){this.size=0,this.__data__={hash:new Fe,map:new(In||fe),string:new Fe}}function Ml(t){var e=Br(this,t).delete(t);return this.size-=e?1:0,e}function Pl(t){return Br(this,t).get(t)}function Ol(t){return Br(this,t).has(t)}function Ll(t,e){var s=Br(this,t),o=s.size;return s.set(t,e),this.size+=s.size==o?0:1,this}de.prototype.clear=Rl,de.prototype.delete=Ml,de.prototype.get=Pl,de.prototype.has=Ol,de.prototype.set=Ll;function Ue(t){var e=-1,s=t==null?0:t.length;for(this.__data__=new de;++e<s;)this.add(t[e])}function Bl(t){return this.__data__.set(t,w),this}function kl(t){return this.__data__.has(t)}Ue.prototype.add=Ue.prototype.push=Bl,Ue.prototype.has=kl;function Qt(t){var e=this.__data__=new fe(t);this.size=e.size}function Dl(){this.__data__=new fe,this.size=0}function Nl(t){var e=this.__data__,s=e.delete(t);return this.size=e.size,s}function Fl(t){return this.__data__.get(t)}function Ul(t){return this.__data__.has(t)}function Wl(t,e){var s=this.__data__;if(s instanceof fe){var o=s.__data__;if(!In||o.length<h-1)return o.push([t,e]),this.size=++s.size,this;s=this.__data__=new de(o)}return s.set(t,e),this.size=s.size,this}Qt.prototype.clear=Dl,Qt.prototype.delete=Nl,Qt.prototype.get=Fl,Qt.prototype.has=Ul,Qt.prototype.set=Wl;function No(t,e){var s=F(t),o=!s&&He(t),u=!s&&!o&&Me(t),l=!s&&!o&&!u&&ln(t),d=s||o||u||l,g=d?Es(t.length,Zh):[],b=g.length;for(var x in t)(e||Z.call(t,x))&&!(d&&(x=="length"||u&&(x=="offset"||x=="parent")||l&&(x=="buffer"||x=="byteLength"||x=="byteOffset")||be(x,b)))&&g.push(x);return g}function Fo(t){var e=t.length;return e?t[$s(0,e-1)]:r}function $l(t,e){return kr(At(t),We(e,0,t.length))}function ql(t){return kr(At(t))}function Ps(t,e,s){(s!==r&&!jt(t[e],s)||s===r&&!(e in t))&&pe(t,e,s)}function On(t,e,s){var o=t[e];(!(Z.call(t,e)&&jt(o,s))||s===r&&!(e in t))&&pe(t,e,s)}function Sr(t,e){for(var s=t.length;s--;)if(jt(t[s][0],e))return s;return-1}function zl(t,e,s,o){return Ae(t,function(u,l,d){e(o,u,s(u),d)}),o}function Uo(t,e){return t&&ae(e,gt(e),t)}function Hl(t,e){return t&&ae(e,It(e),t)}function pe(t,e,s){e=="__proto__"&&_r?_r(t,e,{configurable:!0,enumerable:!0,value:s,writable:!0}):t[e]=s}function Os(t,e){for(var s=-1,o=e.length,u=v(o),l=t==null;++s<o;)u[s]=l?r:fi(t,e[s]);return u}function We(t,e,s){return t===t&&(s!==r&&(t=t<=s?t:s),e!==r&&(t=t>=e?t:e)),t}function zt(t,e,s,o,u,l){var d,g=e&C,b=e&A,x=e&R;if(s&&(d=u?s(t,o,u,l):s(t)),d!==r)return d;if(!nt(t))return t;var E=F(t);if(E){if(d=Lf(t),!g)return At(t,d)}else{var T=vt(t),M=T==tr||T==Wi;if(Me(t))return ca(t,g);if(T==le||T==Ze||M&&!u){if(d=b||M?{}:Ia(t),!g)return b?Sf(t,Hl(d,t)):yf(t,Uo(d,t))}else{if(!j[T])return u?t:{};d=Bf(t,T,g)}}l||(l=new Qt);var L=l.get(t);if(L)return L;l.set(t,d),ru(t)?t.forEach(function(D){d.add(zt(D,e,s,D,t,l))}):eu(t)&&t.forEach(function(D,H){d.set(H,zt(D,e,s,H,t,l))});var k=x?b?Qs:Xs:b?It:gt,$=E?r:k(t);return Wt($||t,function(D,H){$&&(H=D,D=t[H]),On(d,H,zt(D,e,s,H,t,l))}),d}function Jl(t){var e=gt(t);return function(s){return Wo(s,t,e)}}function Wo(t,e,s){var o=s.length;if(t==null)return!o;for(t=Q(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 $o(t,e,s){if(typeof t!="function")throw new $t(p);return Un(function(){t.apply(r,s)},e)}function Ln(t,e,s,o){var u=-1,l=ir,d=!0,g=t.length,b=[],x=e.length;if(!g)return b;s&&(e=et(e,Pt(s))),o?(l=ms,d=!1):e.length>=h&&(l=An,d=!1,e=new Ue(e));t:for(;++u<g;){var E=t[u],T=s==null?E:s(E);if(E=o||E!==0?E:0,d&&T===T){for(var M=x;M--;)if(e[M]===T)continue t;b.push(E)}else l(e,T,o)||b.push(E)}return b}var Ae=pa(oe),qo=pa(Bs,!0);function Gl(t,e){var s=!0;return Ae(t,function(o,u,l){return s=!!e(o,u,l),s}),s}function xr(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&&!Lt(d):s(d,g)))var g=d,b=l}return b}function Kl(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:iu(o);s<o;)t[s++]=e;return t}function zo(t,e){var s=[];return Ae(t,function(o,u,l){e(o,u,l)&&s.push(o)}),s}function bt(t,e,s,o,u){var l=-1,d=t.length;for(s||(s=Df),u||(u=[]);++l<d;){var g=t[l];e>0&&s(g)?e>1?bt(g,e-1,s,o,u):xe(u,g):o||(u[u.length]=g)}return u}var Ls=ga(),Ho=ga(!0);function oe(t,e){return t&&Ls(t,e,gt)}function Bs(t,e){return t&&Ho(t,e,gt)}function Er(t,e){return Se(e,function(s){return me(t[s])})}function $e(t,e){e=Ie(e,t);for(var s=0,o=e.length;t!=null&&s<o;)t=t[ue(e[s++])];return s&&s==o?t:r}function Jo(t,e,s){var o=e(t);return F(t)?o:xe(o,s(t))}function yt(t){return t==null?t===r?Sc:wc:Ne&&Ne in Q(t)?Mf(t):zf(t)}function ks(t,e){return t>e}function Yl(t,e){return t!=null&&Z.call(t,e)}function Vl(t,e){return t!=null&&e in Q(t)}function Zl(t,e,s){return t>=mt(e,s)&&t<ft(e,s)}function Ds(t,e,s){for(var o=s?ms:ir,u=t[0].length,l=t.length,d=l,g=v(l),b=1/0,x=[];d--;){var E=t[d];d&&e&&(E=et(E,Pt(e))),b=mt(E.length,b),g[d]=!s&&(e||u>=120&&E.length>=120)?new Ue(d&&E):r}E=t[0];var T=-1,M=g[0];t:for(;++T<u&&x.length<b;){var L=E[T],k=e?e(L):L;if(L=s||L!==0?L:0,!(M?An(M,k):o(x,k,s))){for(d=l;--d;){var $=g[d];if(!($?An($,k):o(t[d],k,s)))continue t}M&&M.push(k),x.push(L)}}return x}function Xl(t,e,s,o){return oe(t,function(u,l,d){e(o,s(u),l,d)}),o}function Bn(t,e,s){e=Ie(e,t),t=Oa(t,e);var o=t==null?t:t[ue(Jt(e))];return o==null?r:Mt(o,t,s)}function Go(t){return it(t)&&yt(t)==Ze}function Ql(t){return it(t)&&yt(t)==Tn}function jl(t){return it(t)&&yt(t)==wn}function kn(t,e,s,o,u){return t===e?!0:t==null||e==null||!it(t)&&!it(e)?t!==t&&e!==e:tf(t,e,s,o,kn,u)}function tf(t,e,s,o,u,l){var d=F(t),g=F(e),b=d?Qn:vt(t),x=g?Qn:vt(e);b=b==Ze?le:b,x=x==Ze?le:x;var E=b==le,T=x==le,M=b==x;if(M&&Me(t)){if(!Me(e))return!1;d=!0,E=!1}if(M&&!E)return l||(l=new Qt),d||ln(t)?Ta(t,e,s,o,u,l):If(t,e,b,s,o,u,l);if(!(s&K)){var L=E&&Z.call(t,"__wrapped__"),k=T&&Z.call(e,"__wrapped__");if(L||k){var $=L?t.value():t,D=k?e.value():e;return l||(l=new Qt),u($,D,s,o,l)}}return M?(l||(l=new Qt),Rf(t,e,s,o,u,l)):!1}function ef(t){return it(t)&&vt(t)==Vt}function Ns(t,e,s,o){var u=s.length,l=u,d=!o;if(t==null)return!l;for(t=Q(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],x=t[b],E=g[1];if(d&&g[2]){if(x===r&&!(b in t))return!1}else{var T=new Qt;if(o)var M=o(x,E,b,t,e,T);if(!(M===r?kn(E,x,K|Tt,o,T):M))return!1}}return!0}function Ko(t){if(!nt(t)||Ff(t))return!1;var e=me(t)?el:Jc;return e.test(ze(t))}function nf(t){return it(t)&&yt(t)==Sn}function rf(t){return it(t)&&vt(t)==Zt}function sf(t){return it(t)&&$r(t.length)&&!!tt[yt(t)]}function Yo(t){return typeof t=="function"?t:t==null?Rt:typeof t=="object"?F(t)?Xo(t[0],t[1]):Zo(t):_u(t)}function Fs(t){if(!Fn(t))return al(t);var e=[];for(var s in Q(t))Z.call(t,s)&&s!="constructor"&&e.push(s);return e}function of(t){if(!nt(t))return qf(t);var e=Fn(t),s=[];for(var o in t)o=="constructor"&&(e||!Z.call(t,o))||s.push(o);return s}function Us(t,e){return t<e}function Vo(t,e){var s=-1,o=Ct(t)?v(t.length):[];return Ae(t,function(u,l,d){o[++s]=e(u,l,d)}),o}function Zo(t){var e=ti(t);return e.length==1&&e[0][2]?Ma(e[0][0],e[0][1]):function(s){return s===t||Ns(s,t,e)}}function Xo(t,e){return ni(t)&&Ra(e)?Ma(ue(t),e):function(s){var o=fi(s,t);return o===r&&o===e?di(s,t):kn(e,o,K|Tt)}}function Tr(t,e,s,o,u){t!==e&&Ls(e,function(l,d){if(u||(u=new Qt),nt(l))af(t,e,d,s,Tr,o,u);else{var g=o?o(si(t,d),l,d+"",t,e,u):r;g===r&&(g=l),Ps(t,d,g)}},It)}function af(t,e,s,o,u,l,d){var g=si(t,s),b=si(e,s),x=d.get(b);if(x){Ps(t,s,x);return}var E=l?l(g,b,s+"",t,e,d):r,T=E===r;if(T){var M=F(b),L=!M&&Me(b),k=!M&&!L&&ln(b);E=b,M||L||k?F(g)?E=g:ot(g)?E=At(g):L?(T=!1,E=ca(b,!0)):k?(T=!1,E=ha(b,!0)):E=[]:Wn(b)||He(b)?(E=g,He(g)?E=ou(g):(!nt(g)||me(g))&&(E=Ia(b))):T=!1}T&&(d.set(b,E),u(E,b,o,l,d),d.delete(b)),Ps(t,s,E)}function Qo(t,e){var s=t.length;if(s)return e+=e<0?s:0,be(e,s)?t[e]:r}function jo(t,e,s){e.length?e=et(e,function(l){return F(l)?function(d){return $e(d,l.length===1?l[0]:l)}:l}):e=[Rt];var o=-1;e=et(e,Pt(B()));var u=Vo(t,function(l,d,g){var b=et(e,function(x){return x(l)});return{criteria:b,index:++o,value:l}});return Lh(u,function(l,d){return wf(l,d,s)})}function uf(t,e){return ta(t,e,function(s,o){return di(t,o)})}function ta(t,e,s){for(var o=-1,u=e.length,l={};++o<u;){var d=e[o],g=$e(t,d);s(g,d)&&Dn(l,Ie(d,t),g)}return l}function cf(t){return function(e){return $e(e,t)}}function Ws(t,e,s,o){var u=o?Oh:je,l=-1,d=e.length,g=t;for(t===e&&(e=At(e)),s&&(g=et(t,Pt(s)));++l<d;)for(var b=0,x=e[l],E=s?s(x):x;(b=u(g,E,b,o))>-1;)g!==t&&gr.call(g,b,1),gr.call(t,b,1);return t}function ea(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;be(u)?gr.call(t,u,1):Hs(t,u)}}return t}function $s(t,e){return t+mr(ko()*(e-t+1))}function hf(t,e,s,o){for(var u=-1,l=ft(br((e-t)/(s||1)),0),d=v(l);l--;)d[o?l:++u]=t,t+=s;return d}function qs(t,e){var s="";if(!t||e<1||e>ye)return s;do e%2&&(s+=t),e=mr(e/2),e&&(t+=t);while(e);return s}function z(t,e){return ii(Pa(t,e,Rt),t+"")}function lf(t){return Fo(fn(t))}function ff(t,e){var s=fn(t);return kr(s,We(e,0,s.length))}function Dn(t,e,s,o){if(!nt(t))return t;e=Ie(e,t);for(var u=-1,l=e.length,d=l-1,g=t;g!=null&&++u<l;){var b=ue(e[u]),x=s;if(b==="__proto__"||b==="constructor"||b==="prototype")return t;if(u!=d){var E=g[b];x=o?o(E,b,g):r,x===r&&(x=nt(E)?E:be(e[u+1])?[]:{})}On(g,b,x),g=g[b]}return t}var na=vr?function(t,e){return vr.set(t,e),t}:Rt,df=_r?function(t,e){return _r(t,"toString",{configurable:!0,enumerable:!1,value:gi(e),writable:!0})}:Rt;function pf(t){return kr(fn(t))}function Ht(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 gf(t,e){var s;return Ae(t,function(o,u,l){return s=e(o,u,l),!s}),!!s}function Ar(t,e,s){var o=0,u=t==null?o:t.length;if(typeof e=="number"&&e===e&&u<=_c){for(;o<u;){var l=o+u>>>1,d=t[l];d!==null&&!Lt(d)&&(s?d<=e:d<e)?o=l+1:u=l}return u}return zs(t,e,Rt,s)}function zs(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=Lt(e),x=e===r;u<l;){var E=mr((u+l)/2),T=s(t[E]),M=T!==r,L=T===null,k=T===T,$=Lt(T);if(d)var D=o||k;else x?D=k&&(o||M):g?D=k&&M&&(o||!L):b?D=k&&M&&!L&&(o||!$):L||$?D=!1:D=o?T<=e:T<e;D?u=E+1:l=E}return mt(l,gc)}function ra(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||!jt(g,b)){var b=g;l[u++]=d===0?0:d}}return l}function sa(t){return typeof t=="number"?t:Lt(t)?Xn:+t}function Ot(t){if(typeof t=="string")return t;if(F(t))return et(t,Ot)+"";if(Lt(t))return Do?Do.call(t):"";var e=t+"";return e=="0"&&1/t==-ke?"-0":e}function Ce(t,e,s){var o=-1,u=ir,l=t.length,d=!0,g=[],b=g;if(s)d=!1,u=ms;else if(l>=h){var x=e?null:Af(t);if(x)return ar(x);d=!1,u=An,b=new Ue}else b=e?[]:g;t:for(;++o<l;){var E=t[o],T=e?e(E):E;if(E=s||E!==0?E:0,d&&T===T){for(var M=b.length;M--;)if(b[M]===T)continue t;e&&b.push(T),g.push(E)}else u(b,T,s)||(b!==g&&b.push(T),g.push(E))}return g}function Hs(t,e){return e=Ie(e,t),t=Oa(t,e),t==null||delete t[ue(Jt(e))]}function ia(t,e,s,o){return Dn(t,e,s($e(t,e)),o)}function Cr(t,e,s,o){for(var u=t.length,l=o?u:-1;(o?l--:++l<u)&&e(t[l],l,t););return s?Ht(t,o?0:l,o?l+1:u):Ht(t,o?l+1:0,o?u:l)}function oa(t,e){var s=t;return s instanceof J&&(s=s.value()),vs(e,function(o,u){return u.func.apply(u.thisArg,xe([o],u.args))},s)}function Js(t,e,s){var o=t.length;if(o<2)return o?Ce(t[0]):[];for(var u=-1,l=v(o);++u<o;)for(var d=t[u],g=-1;++g<o;)g!=u&&(l[u]=Ln(l[u]||d,t[g],e,s));return Ce(bt(l,1),e,s)}function aa(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 Gs(t){return ot(t)?t:[]}function Ks(t){return typeof t=="function"?t:Rt}function Ie(t,e){return F(t)?t:ni(t,e)?[t]:Da(V(t))}var _f=z;function Re(t,e,s){var o=t.length;return s=s===r?o:s,!e&&s>=o?t:Ht(t,e,s)}var ua=nl||function(t){return _t.clearTimeout(t)};function ca(t,e){if(e)return t.slice();var s=t.length,o=Mo?Mo(s):new t.constructor(s);return t.copy(o),o}function Ys(t){var e=new t.constructor(t.byteLength);return new dr(e).set(new dr(t)),e}function bf(t,e){var s=e?Ys(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.byteLength)}function mf(t){var e=new t.constructor(t.source,Ji.exec(t));return e.lastIndex=t.lastIndex,e}function vf(t){return Pn?Q(Pn.call(t)):{}}function ha(t,e){var s=e?Ys(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.length)}function la(t,e){if(t!==e){var s=t!==r,o=t===null,u=t===t,l=Lt(t),d=e!==r,g=e===null,b=e===e,x=Lt(e);if(!g&&!x&&!l&&t>e||l&&d&&b&&!g&&!x||o&&d&&b||!s&&b||!u)return 1;if(!o&&!l&&!x&&t<e||x&&s&&u&&!o&&!l||g&&s&&u||!d&&u||!b)return-1}return 0}function wf(t,e,s){for(var o=-1,u=t.criteria,l=e.criteria,d=u.length,g=s.length;++o<d;){var b=la(u[o],l[o]);if(b){if(o>=g)return b;var x=s[o];return b*(x=="desc"?-1:1)}}return t.index-e.index}function fa(t,e,s,o){for(var u=-1,l=t.length,d=s.length,g=-1,b=e.length,x=ft(l-d,0),E=v(b+x),T=!o;++g<b;)E[g]=e[g];for(;++u<d;)(T||u<l)&&(E[s[u]]=t[u]);for(;x--;)E[g++]=t[u++];return E}function da(t,e,s,o){for(var u=-1,l=t.length,d=-1,g=s.length,b=-1,x=e.length,E=ft(l-g,0),T=v(E+x),M=!o;++u<E;)T[u]=t[u];for(var L=u;++b<x;)T[L+b]=e[b];for(;++d<g;)(M||u<l)&&(T[L+s[d]]=t[u++]);return T}function At(t,e){var s=-1,o=t.length;for(e||(e=v(o));++s<o;)e[s]=t[s];return e}function ae(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?pe(s,g,b):On(s,g,b)}return s}function yf(t,e){return ae(t,ei(t),e)}function Sf(t,e){return ae(t,Aa(t),e)}function Ir(t,e){return function(s,o){var u=F(s)?Ah:zl,l=e?e():{};return u(s,t,B(o,2),l)}}function un(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&&St(s[0],s[1],d)&&(l=u<3?r:l,u=1),e=Q(e);++o<u;){var g=s[o];g&&t(e,g,o,l)}return e})}function pa(t,e){return function(s,o){if(s==null)return s;if(!Ct(s))return t(s,o);for(var u=s.length,l=e?u:-1,d=Q(s);(e?l--:++l<u)&&o(d[l],l,d)!==!1;);return s}}function ga(t){return function(e,s,o){for(var u=-1,l=Q(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 xf(t,e,s){var o=e&pt,u=Nn(t);function l(){var d=this&&this!==_t&&this instanceof l?u:t;return d.apply(o?s:this,arguments)}return l}function _a(t){return function(e){e=V(e);var s=tn(e)?Xt(e):r,o=s?s[0]:e.charAt(0),u=s?Re(s,1).join(""):e.slice(1);return o[t]()+u}}function cn(t){return function(e){return vs(pu(du(e).replace(fh,"")),t,"")}}function Nn(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=an(t.prototype),o=t.apply(s,e);return nt(o)?o:s}}function Ef(t,e,s){var o=Nn(t);function u(){for(var l=arguments.length,d=v(l),g=l,b=hn(u);g--;)d[g]=arguments[g];var x=l<3&&d[0]!==b&&d[l-1]!==b?[]:Ee(d,b);if(l-=x.length,l<s)return ya(t,e,Rr,u.placeholder,r,d,x,r,r,s-l);var E=this&&this!==_t&&this instanceof u?o:t;return Mt(E,this,d)}return u}function ba(t){return function(e,s,o){var u=Q(e);if(!Ct(e)){var l=B(s,3);e=gt(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 ma(t){return _e(function(e){var s=e.length,o=s,u=qt.prototype.thru;for(t&&e.reverse();o--;){var l=e[o];if(typeof l!="function")throw new $t(p);if(u&&!d&&Lr(l)=="wrapper")var d=new qt([],!0)}for(o=d?o:s;++o<s;){l=e[o];var g=Lr(l),b=g=="wrapper"?js(l):r;b&&ri(b[0])&&b[1]==(q|Kt|Yt|ct)&&!b[4].length&&b[9]==1?d=d[Lr(b[0])].apply(d,b[3]):d=l.length==1&&ri(l)?d[g]():d.thru(l)}return function(){var x=arguments,E=x[0];if(d&&x.length==1&&F(E))return d.plant(E).value();for(var T=0,M=s?e[T].apply(this,x):E;++T<s;)M=e[T].call(this,M);return M}})}function Rr(t,e,s,o,u,l,d,g,b,x){var E=e&q,T=e&pt,M=e&ut,L=e&(Kt|Le),k=e&X,$=M?r:Nn(t);function D(){for(var H=arguments.length,G=v(H),Bt=H;Bt--;)G[Bt]=arguments[Bt];if(L)var xt=hn(D),kt=kh(G,xt);if(o&&(G=fa(G,o,u,L)),l&&(G=da(G,l,d,L)),H-=kt,L&&H<x){var at=Ee(G,xt);return ya(t,e,Rr,D.placeholder,s,G,at,g,b,x-H)}var te=T?s:this,we=M?te[t]:t;return H=G.length,g?G=Hf(G,g):k&&H>1&&G.reverse(),E&&b<H&&(G.length=b),this&&this!==_t&&this instanceof D&&(we=$||Nn(we)),we.apply(te,G)}return D}function va(t,e){return function(s,o){return Xl(s,t,e(o),{})}}function Mr(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=Ot(s),o=Ot(o)):(s=sa(s),o=sa(o)),u=t(s,o)}return u}}function Vs(t){return _e(function(e){return e=et(e,Pt(B())),z(function(s){var o=this;return t(e,function(u){return Mt(u,o,s)})})})}function Pr(t,e){e=e===r?" ":Ot(e);var s=e.length;if(s<2)return s?qs(e,t):e;var o=qs(e,br(t/en(e)));return tn(e)?Re(Xt(o),0,t).join(""):o.slice(0,t)}function Tf(t,e,s,o){var u=e&pt,l=Nn(t);function d(){for(var g=-1,b=arguments.length,x=-1,E=o.length,T=v(E+b),M=this&&this!==_t&&this instanceof d?l:t;++x<E;)T[x]=o[x];for(;b--;)T[x++]=arguments[++g];return Mt(M,u?s:this,T)}return d}function wa(t){return function(e,s,o){return o&&typeof o!="number"&&St(e,s,o)&&(s=o=r),e=ve(e),s===r?(s=e,e=0):s=ve(s),o=o===r?e<s?1:-1:ve(o),hf(e,s,o,t)}}function Or(t){return function(e,s){return typeof e=="string"&&typeof s=="string"||(e=Gt(e),s=Gt(s)),t(e,s)}}function ya(t,e,s,o,u,l,d,g,b,x){var E=e&Kt,T=E?d:r,M=E?r:d,L=E?l:r,k=E?r:l;e|=E?Yt:Be,e&=~(E?Be:Yt),e&Zn||(e&=-4);var $=[t,e,u,L,T,k,M,g,b,x],D=s.apply(r,$);return ri(t)&&La(D,$),D.placeholder=o,Ba(D,t,e)}function Zs(t){var e=lt[t];return function(s,o){if(s=Gt(s),o=o==null?0:mt(W(o),292),o&&Bo(s)){var u=(V(s)+"e").split("e"),l=e(u[0]+"e"+(+u[1]+o));return u=(V(l)+"e").split("e"),+(u[0]+"e"+(+u[1]-o))}return e(s)}}var Af=sn&&1/ar(new sn([,-0]))[1]==ke?function(t){return new sn(t)}:mi;function Sa(t){return function(e){var s=vt(e);return s==Vt?As(e):s==Zt?qh(e):Bh(e,t(e))}}function ge(t,e,s,o,u,l,d,g){var b=e&ut;if(!b&&typeof t!="function")throw new $t(p);var x=o?o.length:0;if(x||(e&=-97,o=u=r),d=d===r?d:ft(W(d),0),g=g===r?g:W(g),x-=u?u.length:0,e&Be){var E=o,T=u;o=u=r}var M=b?r:js(t),L=[t,e,s,o,u,E,T,l,d,g];if(M&&$f(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:ft(L[9]-x,0),!g&&e&(Kt|Le)&&(e&=-25),!e||e==pt)var k=xf(t,e,s);else e==Kt||e==Le?k=Ef(t,e,g):(e==Yt||e==(pt|Yt))&&!u.length?k=Tf(t,e,s,o):k=Rr.apply(r,L);var $=M?na:La;return Ba($(k,L),t,e)}function xa(t,e,s,o){return t===r||jt(t,rn[s])&&!Z.call(o,s)?e:t}function Ea(t,e,s,o,u,l){return nt(t)&&nt(e)&&(l.set(e,t),Tr(t,e,r,Ea,l),l.delete(e)),t}function Cf(t){return Wn(t)?r:t}function Ta(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 x=l.get(t),E=l.get(e);if(x&&E)return x==e&&E==t;var T=-1,M=!0,L=s&Tt?new Ue:r;for(l.set(t,e),l.set(e,t);++T<g;){var k=t[T],$=e[T];if(o)var D=d?o($,k,T,e,t,l):o(k,$,T,t,e,l);if(D!==r){if(D)continue;M=!1;break}if(L){if(!ws(e,function(H,G){if(!An(L,G)&&(k===H||u(k,H,s,o,l)))return L.push(G)})){M=!1;break}}else if(!(k===$||u(k,$,s,o,l))){M=!1;break}}return l.delete(t),l.delete(e),M}function If(t,e,s,o,u,l,d){switch(s){case Xe:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Tn:return!(t.byteLength!=e.byteLength||!l(new dr(t),new dr(e)));case vn:case wn:case yn:return jt(+t,+e);case jn:return t.name==e.name&&t.message==e.message;case Sn:case xn:return t==e+"";case Vt:var g=As;case Zt:var b=o&K;if(g||(g=ar),t.size!=e.size&&!b)return!1;var x=d.get(t);if(x)return x==e;o|=Tt,d.set(t,e);var E=Ta(g(t),g(e),o,u,l,d);return d.delete(t),E;case er:if(Pn)return Pn.call(t)==Pn.call(e)}return!1}function Rf(t,e,s,o,u,l){var d=s&K,g=Xs(t),b=g.length,x=Xs(e),E=x.length;if(b!=E&&!d)return!1;for(var T=b;T--;){var M=g[T];if(!(d?M in e:Z.call(e,M)))return!1}var L=l.get(t),k=l.get(e);if(L&&k)return L==e&&k==t;var $=!0;l.set(t,e),l.set(e,t);for(var D=d;++T<b;){M=g[T];var H=t[M],G=e[M];if(o)var Bt=d?o(G,H,M,e,t,l):o(H,G,M,t,e,l);if(!(Bt===r?H===G||u(H,G,s,o,l):Bt)){$=!1;break}D||(D=M=="constructor")}if($&&!D){var xt=t.constructor,kt=e.constructor;xt!=kt&&"constructor"in t&&"constructor"in e&&!(typeof xt=="function"&&xt instanceof xt&&typeof kt=="function"&&kt instanceof kt)&&($=!1)}return l.delete(t),l.delete(e),$}function _e(t){return ii(Pa(t,r,Wa),t+"")}function Xs(t){return Jo(t,gt,ei)}function Qs(t){return Jo(t,It,Aa)}var js=vr?function(t){return vr.get(t)}:mi;function Lr(t){for(var e=t.name+"",s=on[e],o=Z.call(on,e)?s.length:0;o--;){var u=s[o],l=u.func;if(l==null||l==t)return u.name}return e}function hn(t){var e=Z.call(c,"placeholder")?c:t;return e.placeholder}function B(){var t=c.iteratee||_i;return t=t===_i?Yo:t,arguments.length?t(arguments[0],arguments[1]):t}function Br(t,e){var s=t.__data__;return Nf(e)?s[typeof e=="string"?"string":"hash"]:s.map}function ti(t){for(var e=gt(t),s=e.length;s--;){var o=e[s],u=t[o];e[s]=[o,u,Ra(u)]}return e}function qe(t,e){var s=Uh(t,e);return Ko(s)?s:r}function Mf(t){var e=Z.call(t,Ne),s=t[Ne];try{t[Ne]=r;var o=!0}catch{}var u=lr.call(t);return o&&(e?t[Ne]=s:delete t[Ne]),u}var ei=Is?function(t){return t==null?[]:(t=Q(t),Se(Is(t),function(e){return Oo.call(t,e)}))}:vi,Aa=Is?function(t){for(var e=[];t;)xe(e,ei(t)),t=pr(t);return e}:vi,vt=yt;(Rs&&vt(new Rs(new ArrayBuffer(1)))!=Xe||In&&vt(new In)!=Vt||Ms&&vt(Ms.resolve())!=$i||sn&&vt(new sn)!=Zt||Rn&&vt(new Rn)!=En)&&(vt=function(t){var e=yt(t),s=e==le?t.constructor:r,o=s?ze(s):"";if(o)switch(o){case ll:return Xe;case fl:return Vt;case dl:return $i;case pl:return Zt;case gl:return En}return e});function Pf(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=mt(e,t+d);break;case"takeRight":t=ft(t,e-d);break}}return{start:t,end:e}}function Of(t){var e=t.match(Nc);return e?e[1].split(Fc):[]}function Ca(t,e,s){e=Ie(e,t);for(var o=-1,u=e.length,l=!1;++o<u;){var d=ue(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&&$r(u)&&be(d,u)&&(F(t)||He(t)))}function Lf(t){var e=t.length,s=new t.constructor(e);return e&&typeof t[0]=="string"&&Z.call(t,"index")&&(s.index=t.index,s.input=t.input),s}function Ia(t){return typeof t.constructor=="function"&&!Fn(t)?an(pr(t)):{}}function Bf(t,e,s){var o=t.constructor;switch(e){case Tn:return Ys(t);case vn:case wn:return new o(+t);case Xe:return bf(t,s);case ts:case es:case ns:case rs:case ss:case is:case os:case as:case us:return ha(t,s);case Vt:return new o;case yn:case xn:return new o(t);case Sn:return mf(t);case Zt:return new o;case er:return vf(t)}}function kf(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(Dc,`{
|
|
21
|
-
/* [wrapped with `+
|
|
22
|
-
`)}function Df(t){return F(t)||He(t)||!!(Lo&&t&&t[Lo])}function be(t,e){var s=typeof t;return e=e??ye,!!e&&(s=="number"||s!="symbol"&&Kc.test(t))&&t>-1&&t%1==0&&t<e}function St(t,e,s){if(!nt(s))return!1;var o=typeof e;return(o=="number"?Ct(s)&&be(e,s.length):o=="string"&&e in s)?jt(s[e],t):!1}function ni(t,e){if(F(t))return!1;var s=typeof t;return s=="number"||s=="symbol"||s=="boolean"||t==null||Lt(t)?!0:Oc.test(t)||!Pc.test(t)||e!=null&&t in Q(e)}function Nf(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function ri(t){var e=Lr(t),s=c[e];if(typeof s!="function"||!(e in J.prototype))return!1;if(t===s)return!0;var o=js(s);return!!o&&t===o[0]}function Ff(t){return!!Ro&&Ro in t}var Uf=cr?me:wi;function Fn(t){var e=t&&t.constructor,s=typeof e=="function"&&e.prototype||rn;return t===s}function Ra(t){return t===t&&!nt(t)}function Ma(t,e){return function(s){return s==null?!1:s[t]===e&&(e!==r||t in Q(s))}}function Wf(t){var e=Ur(t,function(o){return s.size===I&&s.clear(),o}),s=e.cache;return e}function $f(t,e){var s=t[1],o=e[1],u=s|o,l=u<(pt|ut|q),d=o==q&&s==Kt||o==q&&s==ct&&t[7].length<=e[8]||o==(q|ct)&&e[7].length<=e[8]&&s==Kt;if(!(l||d))return t;o&pt&&(t[2]=e[2],u|=s&pt?0:Zn);var g=e[3];if(g){var b=t[3];t[3]=b?fa(b,g,e[4]):g,t[4]=b?Ee(t[3],P):e[4]}return g=e[5],g&&(b=t[5],t[5]=b?da(b,g,e[6]):g,t[6]=b?Ee(t[5],P):e[6]),g=e[7],g&&(t[7]=g),o&q&&(t[8]=t[8]==null?e[8]:mt(t[8],e[8])),t[9]==null&&(t[9]=e[9]),t[0]=e[0],t[1]=u,t}function qf(t){var e=[];if(t!=null)for(var s in Q(t))e.push(s);return e}function zf(t){return lr.call(t)}function Pa(t,e,s){return e=ft(e===r?t.length-1:e,0),function(){for(var o=arguments,u=-1,l=ft(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),Mt(t,this,g)}}function Oa(t,e){return e.length<2?t:$e(t,Ht(e,0,-1))}function Hf(t,e){for(var s=t.length,o=mt(e.length,s),u=At(t);o--;){var l=e[o];t[o]=be(l,s)?u[l]:r}return t}function si(t,e){if(!(e==="constructor"&&typeof t[e]=="function")&&e!="__proto__")return t[e]}var La=ka(na),Un=sl||function(t,e){return _t.setTimeout(t,e)},ii=ka(df);function Ba(t,e,s){var o=e+"";return ii(t,kf(o,Jf(Of(o),s)))}function ka(t){var e=0,s=0;return function(){var o=ul(),u=st-(o-s);if(s=o,u>0){if(++e>=Ft)return arguments[0]}else e=0;return t.apply(r,arguments)}}function kr(t,e){var s=-1,o=t.length,u=o-1;for(e=e===r?o:e;++s<e;){var l=$s(s,u),d=t[l];t[l]=t[s],t[s]=d}return t.length=e,t}var Da=Wf(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(Lc,function(s,o,u,l){e.push(u?l.replace($c,"$1"):o||s)}),e});function ue(t){if(typeof t=="string"||Lt(t))return t;var e=t+"";return e=="0"&&1/t==-ke?"-0":e}function ze(t){if(t!=null){try{return hr.call(t)}catch{}try{return t+""}catch{}}return""}function Jf(t,e){return Wt(bc,function(s){var o="_."+s[0];e&s[1]&&!ir(t,o)&&t.push(o)}),t.sort()}function Na(t){if(t instanceof J)return t.clone();var e=new qt(t.__wrapped__,t.__chain__);return e.__actions__=At(t.__actions__),e.__index__=t.__index__,e.__values__=t.__values__,e}function Gf(t,e,s){(s?St(t,e,s):e===r)?e=1:e=ft(W(e),0);var o=t==null?0:t.length;if(!o||e<1)return[];for(var u=0,l=0,d=v(br(o/e));u<o;)d[l++]=Ht(t,u,u+=e);return d}function Kf(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 Yf(){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 xe(F(s)?At(s):[s],bt(e,1))}var Vf=z(function(t,e){return ot(t)?Ln(t,bt(e,1,ot,!0)):[]}),Zf=z(function(t,e){var s=Jt(e);return ot(s)&&(s=r),ot(t)?Ln(t,bt(e,1,ot,!0),B(s,2)):[]}),Xf=z(function(t,e){var s=Jt(e);return ot(s)&&(s=r),ot(t)?Ln(t,bt(e,1,ot,!0),r,s):[]});function Qf(t,e,s){var o=t==null?0:t.length;return o?(e=s||e===r?1:W(e),Ht(t,e<0?0:e,o)):[]}function jf(t,e,s){var o=t==null?0:t.length;return o?(e=s||e===r?1:W(e),e=o-e,Ht(t,0,e<0?0:e)):[]}function td(t,e){return t&&t.length?Cr(t,B(e,3),!0,!0):[]}function ed(t,e){return t&&t.length?Cr(t,B(e,3),!0):[]}function nd(t,e,s,o){var u=t==null?0:t.length;return u?(s&&typeof s!="number"&&St(t,e,s)&&(s=0,o=u),Kl(t,e,s,o)):[]}function Fa(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=ft(o+u,0)),or(t,B(e,3),u)}function Ua(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?ft(o+u,0):mt(u,o-1)),or(t,B(e,3),u,!0)}function Wa(t){var e=t==null?0:t.length;return e?bt(t,1):[]}function rd(t){var e=t==null?0:t.length;return e?bt(t,ke):[]}function sd(t,e){var s=t==null?0:t.length;return s?(e=e===r?1:W(e),bt(t,e)):[]}function id(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 $a(t){return t&&t.length?t[0]:r}function od(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=ft(o+u,0)),je(t,e,u)}function ad(t){var e=t==null?0:t.length;return e?Ht(t,0,-1):[]}var ud=z(function(t){var e=et(t,Gs);return e.length&&e[0]===t[0]?Ds(e):[]}),cd=z(function(t){var e=Jt(t),s=et(t,Gs);return e===Jt(s)?e=r:s.pop(),s.length&&s[0]===t[0]?Ds(s,B(e,2)):[]}),hd=z(function(t){var e=Jt(t),s=et(t,Gs);return e=typeof e=="function"?e:r,e&&s.pop(),s.length&&s[0]===t[0]?Ds(s,r,e):[]});function ld(t,e){return t==null?"":ol.call(t,e)}function Jt(t){var e=t==null?0:t.length;return e?t[e-1]:r}function fd(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?ft(o+u,0):mt(u,o-1)),e===e?Hh(t,e,u):or(t,yo,u,!0)}function dd(t,e){return t&&t.length?Qo(t,W(e)):r}var pd=z(qa);function qa(t,e){return t&&t.length&&e&&e.length?Ws(t,e):t}function gd(t,e,s){return t&&t.length&&e&&e.length?Ws(t,e,B(s,2)):t}function _d(t,e,s){return t&&t.length&&e&&e.length?Ws(t,e,r,s):t}var bd=_e(function(t,e){var s=t==null?0:t.length,o=Os(t,e);return ea(t,et(e,function(u){return be(u,s)?+u:u}).sort(la)),o});function md(t,e){var s=[];if(!(t&&t.length))return s;var o=-1,u=[],l=t.length;for(e=B(e,3);++o<l;){var d=t[o];e(d,o,t)&&(s.push(d),u.push(o))}return ea(t,u),s}function oi(t){return t==null?t:hl.call(t)}function vd(t,e,s){var o=t==null?0:t.length;return o?(s&&typeof s!="number"&&St(t,e,s)?(e=0,s=o):(e=e==null?0:W(e),s=s===r?o:W(s)),Ht(t,e,s)):[]}function wd(t,e){return Ar(t,e)}function yd(t,e,s){return zs(t,e,B(s,2))}function Sd(t,e){var s=t==null?0:t.length;if(s){var o=Ar(t,e);if(o<s&&jt(t[o],e))return o}return-1}function xd(t,e){return Ar(t,e,!0)}function Ed(t,e,s){return zs(t,e,B(s,2),!0)}function Td(t,e){var s=t==null?0:t.length;if(s){var o=Ar(t,e,!0)-1;if(jt(t[o],e))return o}return-1}function Ad(t){return t&&t.length?ra(t):[]}function Cd(t,e){return t&&t.length?ra(t,B(e,2)):[]}function Id(t){var e=t==null?0:t.length;return e?Ht(t,1,e):[]}function Rd(t,e,s){return t&&t.length?(e=s||e===r?1:W(e),Ht(t,0,e<0?0:e)):[]}function Md(t,e,s){var o=t==null?0:t.length;return o?(e=s||e===r?1:W(e),e=o-e,Ht(t,e<0?0:e,o)):[]}function Pd(t,e){return t&&t.length?Cr(t,B(e,3),!1,!0):[]}function Od(t,e){return t&&t.length?Cr(t,B(e,3)):[]}var Ld=z(function(t){return Ce(bt(t,1,ot,!0))}),Bd=z(function(t){var e=Jt(t);return ot(e)&&(e=r),Ce(bt(t,1,ot,!0),B(e,2))}),kd=z(function(t){var e=Jt(t);return e=typeof e=="function"?e:r,Ce(bt(t,1,ot,!0),r,e)});function Dd(t){return t&&t.length?Ce(t):[]}function Nd(t,e){return t&&t.length?Ce(t,B(e,2)):[]}function Fd(t,e){return e=typeof e=="function"?e:r,t&&t.length?Ce(t,r,e):[]}function ai(t){if(!(t&&t.length))return[];var e=0;return t=Se(t,function(s){if(ot(s))return e=ft(s.length,e),!0}),Es(e,function(s){return et(t,ys(s))})}function za(t,e){if(!(t&&t.length))return[];var s=ai(t);return e==null?s:et(s,function(o){return Mt(e,r,o)})}var Ud=z(function(t,e){return ot(t)?Ln(t,e):[]}),Wd=z(function(t){return Js(Se(t,ot))}),$d=z(function(t){var e=Jt(t);return ot(e)&&(e=r),Js(Se(t,ot),B(e,2))}),qd=z(function(t){var e=Jt(t);return e=typeof e=="function"?e:r,Js(Se(t,ot),r,e)}),zd=z(ai);function Hd(t,e){return aa(t||[],e||[],On)}function Jd(t,e){return aa(t||[],e||[],Dn)}var Gd=z(function(t){var e=t.length,s=e>1?t[e-1]:r;return s=typeof s=="function"?(t.pop(),s):r,za(t,s)});function Ha(t){var e=c(t);return e.__chain__=!0,e}function Kd(t,e){return e(t),t}function Dr(t,e){return e(t)}var Yd=_e(function(t){var e=t.length,s=e?t[0]:0,o=this.__wrapped__,u=function(l){return Os(l,t)};return e>1||this.__actions__.length||!(o instanceof J)||!be(s)?this.thru(u):(o=o.slice(s,+s+(e?1:0)),o.__actions__.push({func:Dr,args:[u],thisArg:r}),new qt(o,this.__chain__).thru(function(l){return e&&!l.length&&l.push(r),l}))});function Vd(){return Ha(this)}function Zd(){return new qt(this.value(),this.__chain__)}function Xd(){this.__values__===r&&(this.__values__=su(this.value()));var t=this.__index__>=this.__values__.length,e=t?r:this.__values__[this.__index__++];return{done:t,value:e}}function Qd(){return this}function jd(t){for(var e,s=this;s instanceof yr;){var o=Na(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 tp(){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:Dr,args:[oi],thisArg:r}),new qt(e,this.__chain__)}return this.thru(oi)}function ep(){return oa(this.__wrapped__,this.__actions__)}var np=Ir(function(t,e,s){Z.call(t,s)?++t[s]:pe(t,s,1)});function rp(t,e,s){var o=F(t)?vo:Gl;return s&&St(t,e,s)&&(e=r),o(t,B(e,3))}function sp(t,e){var s=F(t)?Se:zo;return s(t,B(e,3))}var ip=ba(Fa),op=ba(Ua);function ap(t,e){return bt(Nr(t,e),1)}function up(t,e){return bt(Nr(t,e),ke)}function cp(t,e,s){return s=s===r?1:W(s),bt(Nr(t,e),s)}function Ja(t,e){var s=F(t)?Wt:Ae;return s(t,B(e,3))}function Ga(t,e){var s=F(t)?Ch:qo;return s(t,B(e,3))}var hp=Ir(function(t,e,s){Z.call(t,s)?t[s].push(e):pe(t,s,[e])});function lp(t,e,s,o){t=Ct(t)?t:fn(t),s=s&&!o?W(s):0;var u=t.length;return s<0&&(s=ft(u+s,0)),qr(t)?s<=u&&t.indexOf(e,s)>-1:!!u&&je(t,e,s)>-1}var fp=z(function(t,e,s){var o=-1,u=typeof e=="function",l=Ct(t)?v(t.length):[];return Ae(t,function(d){l[++o]=u?Mt(e,d,s):Bn(d,e,s)}),l}),dp=Ir(function(t,e,s){pe(t,s,e)});function Nr(t,e){var s=F(t)?et:Vo;return s(t,B(e,3))}function pp(t,e,s,o){return t==null?[]:(F(e)||(e=e==null?[]:[e]),s=o?r:s,F(s)||(s=s==null?[]:[s]),jo(t,e,s))}var gp=Ir(function(t,e,s){t[s?0:1].push(e)},function(){return[[],[]]});function _p(t,e,s){var o=F(t)?vs:xo,u=arguments.length<3;return o(t,B(e,4),s,u,Ae)}function bp(t,e,s){var o=F(t)?Ih:xo,u=arguments.length<3;return o(t,B(e,4),s,u,qo)}function mp(t,e){var s=F(t)?Se:zo;return s(t,Wr(B(e,3)))}function vp(t){var e=F(t)?Fo:lf;return e(t)}function wp(t,e,s){(s?St(t,e,s):e===r)?e=1:e=W(e);var o=F(t)?$l:ff;return o(t,e)}function yp(t){var e=F(t)?ql:pf;return e(t)}function Sp(t){if(t==null)return 0;if(Ct(t))return qr(t)?en(t):t.length;var e=vt(t);return e==Vt||e==Zt?t.size:Fs(t).length}function xp(t,e,s){var o=F(t)?ws:gf;return s&&St(t,e,s)&&(e=r),o(t,B(e,3))}var Ep=z(function(t,e){if(t==null)return[];var s=e.length;return s>1&&St(t,e[0],e[1])?e=[]:s>2&&St(e[0],e[1],e[2])&&(e=[e[0]]),jo(t,bt(e,1),[])}),Fr=rl||function(){return _t.Date.now()};function Tp(t,e){if(typeof e!="function")throw new $t(p);return t=W(t),function(){if(--t<1)return e.apply(this,arguments)}}function Ka(t,e,s){return e=s?r:e,e=t&&e==null?t.length:e,ge(t,q,r,r,r,r,e)}function Ya(t,e){var s;if(typeof e!="function")throw new $t(p);return t=W(t),function(){return--t>0&&(s=e.apply(this,arguments)),t<=1&&(e=r),s}}var ui=z(function(t,e,s){var o=pt;if(s.length){var u=Ee(s,hn(ui));o|=Yt}return ge(t,o,e,s,u)}),Va=z(function(t,e,s){var o=pt|ut;if(s.length){var u=Ee(s,hn(Va));o|=Yt}return ge(e,o,t,s,u)});function Za(t,e,s){e=s?r:e;var o=ge(t,Kt,r,r,r,r,r,e);return o.placeholder=Za.placeholder,o}function Xa(t,e,s){e=s?r:e;var o=ge(t,Le,r,r,r,r,r,e);return o.placeholder=Xa.placeholder,o}function Qa(t,e,s){var o,u,l,d,g,b,x=0,E=!1,T=!1,M=!0;if(typeof t!="function")throw new $t(p);e=Gt(e)||0,nt(s)&&(E=!!s.leading,T="maxWait"in s,l=T?ft(Gt(s.maxWait)||0,e):l,M="trailing"in s?!!s.trailing:M);function L(at){var te=o,we=u;return o=u=r,x=at,d=t.apply(we,te),d}function k(at){return x=at,g=Un(H,e),E?L(at):d}function $(at){var te=at-b,we=at-x,bu=e-te;return T?mt(bu,l-we):bu}function D(at){var te=at-b,we=at-x;return b===r||te>=e||te<0||T&&we>=l}function H(){var at=Fr();if(D(at))return G(at);g=Un(H,$(at))}function G(at){return g=r,M&&o?L(at):(o=u=r,d)}function Bt(){g!==r&&ua(g),x=0,o=b=u=g=r}function xt(){return g===r?d:G(Fr())}function kt(){var at=Fr(),te=D(at);if(o=arguments,u=this,b=at,te){if(g===r)return k(b);if(T)return ua(g),g=Un(H,e),L(b)}return g===r&&(g=Un(H,e)),d}return kt.cancel=Bt,kt.flush=xt,kt}var Ap=z(function(t,e){return $o(t,1,e)}),Cp=z(function(t,e,s){return $o(t,Gt(e)||0,s)});function Ip(t){return ge(t,X)}function Ur(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new $t(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(Ur.Cache||de),s}Ur.Cache=de;function Wr(t){if(typeof t!="function")throw new $t(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 Rp(t){return Ya(2,t)}var Mp=_f(function(t,e){e=e.length==1&&F(e[0])?et(e[0],Pt(B())):et(bt(e,1),Pt(B()));var s=e.length;return z(function(o){for(var u=-1,l=mt(o.length,s);++u<l;)o[u]=e[u].call(this,o[u]);return Mt(t,this,o)})}),ci=z(function(t,e){var s=Ee(e,hn(ci));return ge(t,Yt,r,e,s)}),ja=z(function(t,e){var s=Ee(e,hn(ja));return ge(t,Be,r,e,s)}),Pp=_e(function(t,e){return ge(t,ct,r,r,r,e)});function Op(t,e){if(typeof t!="function")throw new $t(p);return e=e===r?e:W(e),z(t,e)}function Lp(t,e){if(typeof t!="function")throw new $t(p);return e=e==null?0:ft(W(e),0),z(function(s){var o=s[e],u=Re(s,0,e);return o&&xe(u,o),Mt(t,this,u)})}function Bp(t,e,s){var o=!0,u=!0;if(typeof t!="function")throw new $t(p);return nt(s)&&(o="leading"in s?!!s.leading:o,u="trailing"in s?!!s.trailing:u),Qa(t,e,{leading:o,maxWait:e,trailing:u})}function kp(t){return Ka(t,1)}function Dp(t,e){return ci(Ks(e),t)}function Np(){if(!arguments.length)return[];var t=arguments[0];return F(t)?t:[t]}function Fp(t){return zt(t,R)}function Up(t,e){return e=typeof e=="function"?e:r,zt(t,R,e)}function Wp(t){return zt(t,C|R)}function $p(t,e){return e=typeof e=="function"?e:r,zt(t,C|R,e)}function qp(t,e){return e==null||Wo(t,e,gt(e))}function jt(t,e){return t===e||t!==t&&e!==e}var zp=Or(ks),Hp=Or(function(t,e){return t>=e}),He=Go(function(){return arguments}())?Go:function(t){return it(t)&&Z.call(t,"callee")&&!Oo.call(t,"callee")},F=v.isArray,Jp=fo?Pt(fo):Ql;function Ct(t){return t!=null&&$r(t.length)&&!me(t)}function ot(t){return it(t)&&Ct(t)}function Gp(t){return t===!0||t===!1||it(t)&&yt(t)==vn}var Me=il||wi,Kp=po?Pt(po):jl;function Yp(t){return it(t)&&t.nodeType===1&&!Wn(t)}function Vp(t){if(t==null)return!0;if(Ct(t)&&(F(t)||typeof t=="string"||typeof t.splice=="function"||Me(t)||ln(t)||He(t)))return!t.length;var e=vt(t);if(e==Vt||e==Zt)return!t.size;if(Fn(t))return!Fs(t).length;for(var s in t)if(Z.call(t,s))return!1;return!0}function Zp(t,e){return kn(t,e)}function Xp(t,e,s){s=typeof s=="function"?s:r;var o=s?s(t,e):r;return o===r?kn(t,e,r,s):!!o}function hi(t){if(!it(t))return!1;var e=yt(t);return e==jn||e==vc||typeof t.message=="string"&&typeof t.name=="string"&&!Wn(t)}function Qp(t){return typeof t=="number"&&Bo(t)}function me(t){if(!nt(t))return!1;var e=yt(t);return e==tr||e==Wi||e==mc||e==yc}function tu(t){return typeof t=="number"&&t==W(t)}function $r(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=ye}function nt(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}function it(t){return t!=null&&typeof t=="object"}var eu=go?Pt(go):ef;function jp(t,e){return t===e||Ns(t,e,ti(e))}function tg(t,e,s){return s=typeof s=="function"?s:r,Ns(t,e,ti(e),s)}function eg(t){return nu(t)&&t!=+t}function ng(t){if(Uf(t))throw new N(f);return Ko(t)}function rg(t){return t===null}function sg(t){return t==null}function nu(t){return typeof t=="number"||it(t)&&yt(t)==yn}function Wn(t){if(!it(t)||yt(t)!=le)return!1;var e=pr(t);if(e===null)return!0;var s=Z.call(e,"constructor")&&e.constructor;return typeof s=="function"&&s instanceof s&&hr.call(s)==jh}var li=_o?Pt(_o):nf;function ig(t){return tu(t)&&t>=-ye&&t<=ye}var ru=bo?Pt(bo):rf;function qr(t){return typeof t=="string"||!F(t)&&it(t)&&yt(t)==xn}function Lt(t){return typeof t=="symbol"||it(t)&&yt(t)==er}var ln=mo?Pt(mo):sf;function og(t){return t===r}function ag(t){return it(t)&&vt(t)==En}function ug(t){return it(t)&&yt(t)==xc}var cg=Or(Us),hg=Or(function(t,e){return t<=e});function su(t){if(!t)return[];if(Ct(t))return qr(t)?Xt(t):At(t);if(Cn&&t[Cn])return $h(t[Cn]());var e=vt(t),s=e==Vt?As:e==Zt?ar:fn;return s(t)}function ve(t){if(!t)return t===0?t:0;if(t=Gt(t),t===ke||t===-ke){var e=t<0?-1:1;return e*pc}return t===t?t:0}function W(t){var e=ve(t),s=e%1;return e===e?s?e-s:e:0}function iu(t){return t?We(W(t),0,ie):0}function Gt(t){if(typeof t=="number")return t;if(Lt(t))return Xn;if(nt(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=nt(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=Eo(t);var s=Hc.test(t);return s||Gc.test(t)?Eh(t.slice(2),s?2:8):zc.test(t)?Xn:+t}function ou(t){return ae(t,It(t))}function lg(t){return t?We(W(t),-ye,ye):t===0?t:0}function V(t){return t==null?"":Ot(t)}var fg=un(function(t,e){if(Fn(e)||Ct(e)){ae(e,gt(e),t);return}for(var s in e)Z.call(e,s)&&On(t,s,e[s])}),au=un(function(t,e){ae(e,It(e),t)}),zr=un(function(t,e,s,o){ae(e,It(e),t,o)}),dg=un(function(t,e,s,o){ae(e,gt(e),t,o)}),pg=_e(Os);function gg(t,e){var s=an(t);return e==null?s:Uo(s,e)}var _g=z(function(t,e){t=Q(t);var s=-1,o=e.length,u=o>2?e[2]:r;for(u&&St(e[0],e[1],u)&&(o=1);++s<o;)for(var l=e[s],d=It(l),g=-1,b=d.length;++g<b;){var x=d[g],E=t[x];(E===r||jt(E,rn[x])&&!Z.call(t,x))&&(t[x]=l[x])}return t}),bg=z(function(t){return t.push(r,Ea),Mt(uu,r,t)});function mg(t,e){return wo(t,B(e,3),oe)}function vg(t,e){return wo(t,B(e,3),Bs)}function wg(t,e){return t==null?t:Ls(t,B(e,3),It)}function yg(t,e){return t==null?t:Ho(t,B(e,3),It)}function Sg(t,e){return t&&oe(t,B(e,3))}function xg(t,e){return t&&Bs(t,B(e,3))}function Eg(t){return t==null?[]:Er(t,gt(t))}function Tg(t){return t==null?[]:Er(t,It(t))}function fi(t,e,s){var o=t==null?r:$e(t,e);return o===r?s:o}function Ag(t,e){return t!=null&&Ca(t,e,Yl)}function di(t,e){return t!=null&&Ca(t,e,Vl)}var Cg=va(function(t,e,s){e!=null&&typeof e.toString!="function"&&(e=lr.call(e)),t[e]=s},gi(Rt)),Ig=va(function(t,e,s){e!=null&&typeof e.toString!="function"&&(e=lr.call(e)),Z.call(t,e)?t[e].push(s):t[e]=[s]},B),Rg=z(Bn);function gt(t){return Ct(t)?No(t):Fs(t)}function It(t){return Ct(t)?No(t,!0):of(t)}function Mg(t,e){var s={};return e=B(e,3),oe(t,function(o,u,l){pe(s,e(o,u,l),o)}),s}function Pg(t,e){var s={};return e=B(e,3),oe(t,function(o,u,l){pe(s,u,e(o,u,l))}),s}var Og=un(function(t,e,s){Tr(t,e,s)}),uu=un(function(t,e,s,o){Tr(t,e,s,o)}),Lg=_e(function(t,e){var s={};if(t==null)return s;var o=!1;e=et(e,function(l){return l=Ie(l,t),o||(o=l.length>1),l}),ae(t,Qs(t),s),o&&(s=zt(s,C|A|R,Cf));for(var u=e.length;u--;)Hs(s,e[u]);return s});function Bg(t,e){return cu(t,Wr(B(e)))}var kg=_e(function(t,e){return t==null?{}:uf(t,e)});function cu(t,e){if(t==null)return{};var s=et(Qs(t),function(o){return[o]});return e=B(e),ta(t,s,function(o,u){return e(o,u[0])})}function Dg(t,e,s){e=Ie(e,t);var o=-1,u=e.length;for(u||(u=1,t=r);++o<u;){var l=t==null?r:t[ue(e[o])];l===r&&(o=u,l=s),t=me(l)?l.call(t):l}return t}function Ng(t,e,s){return t==null?t:Dn(t,e,s)}function Fg(t,e,s,o){return o=typeof o=="function"?o:r,t==null?t:Dn(t,e,s,o)}var hu=Sa(gt),lu=Sa(It);function Ug(t,e,s){var o=F(t),u=o||Me(t)||ln(t);if(e=B(e,4),s==null){var l=t&&t.constructor;u?s=o?new l:[]:nt(t)?s=me(l)?an(pr(t)):{}:s={}}return(u?Wt:oe)(t,function(d,g,b){return e(s,d,g,b)}),s}function Wg(t,e){return t==null?!0:Hs(t,e)}function $g(t,e,s){return t==null?t:ia(t,e,Ks(s))}function qg(t,e,s,o){return o=typeof o=="function"?o:r,t==null?t:ia(t,e,Ks(s),o)}function fn(t){return t==null?[]:Ts(t,gt(t))}function zg(t){return t==null?[]:Ts(t,It(t))}function Hg(t,e,s){return s===r&&(s=e,e=r),s!==r&&(s=Gt(s),s=s===s?s:0),e!==r&&(e=Gt(e),e=e===e?e:0),We(Gt(t),e,s)}function Jg(t,e,s){return e=ve(e),s===r?(s=e,e=0):s=ve(s),t=Gt(t),Zl(t,e,s)}function Gg(t,e,s){if(s&&typeof s!="boolean"&&St(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=ve(t),e===r?(e=t,t=0):e=ve(e)),t>e){var o=t;t=e,e=o}if(s||t%1||e%1){var u=ko();return mt(t+u*(e-t+xh("1e-"+((u+"").length-1))),e)}return $s(t,e)}var Kg=cn(function(t,e,s){return e=e.toLowerCase(),t+(s?fu(e):e)});function fu(t){return pi(V(t).toLowerCase())}function du(t){return t=V(t),t&&t.replace(Yc,Dh).replace(dh,"")}function Yg(t,e,s){t=V(t),e=Ot(e);var o=t.length;s=s===r?o:We(W(s),0,o);var u=s;return s-=e.length,s>=0&&t.slice(s,u)==e}function Vg(t){return t=V(t),t&&Ic.test(t)?t.replace(zi,Nh):t}function Zg(t){return t=V(t),t&&Bc.test(t)?t.replace(cs,"\\$&"):t}var Xg=cn(function(t,e,s){return t+(s?"-":"")+e.toLowerCase()}),Qg=cn(function(t,e,s){return t+(s?" ":"")+e.toLowerCase()}),jg=_a("toLowerCase");function t_(t,e,s){t=V(t),e=W(e);var o=e?en(t):0;if(!e||o>=e)return t;var u=(e-o)/2;return Pr(mr(u),s)+t+Pr(br(u),s)}function e_(t,e,s){t=V(t),e=W(e);var o=e?en(t):0;return e&&o<e?t+Pr(e-o,s):t}function n_(t,e,s){t=V(t),e=W(e);var o=e?en(t):0;return e&&o<e?Pr(e-o,s)+t:t}function r_(t,e,s){return s||e==null?e=0:e&&(e=+e),cl(V(t).replace(hs,""),e||0)}function s_(t,e,s){return(s?St(t,e,s):e===r)?e=1:e=W(e),qs(V(t),e)}function i_(){var t=arguments,e=V(t[0]);return t.length<3?e:e.replace(t[1],t[2])}var o_=cn(function(t,e,s){return t+(s?"_":"")+e.toLowerCase()});function a_(t,e,s){return s&&typeof s!="number"&&St(t,e,s)&&(e=s=r),s=s===r?ie:s>>>0,s?(t=V(t),t&&(typeof e=="string"||e!=null&&!li(e))&&(e=Ot(e),!e&&tn(t))?Re(Xt(t),0,s):t.split(e,s)):[]}var u_=cn(function(t,e,s){return t+(s?" ":"")+pi(e)});function c_(t,e,s){return t=V(t),s=s==null?0:We(W(s),0,t.length),e=Ot(e),t.slice(s,s+e.length)==e}function h_(t,e,s){var o=c.templateSettings;s&&St(t,e,s)&&(e=r),t=V(t),e=zr({},e,o,xa);var u=zr({},e.imports,o.imports,xa),l=gt(u),d=Ts(u,l),g,b,x=0,E=e.interpolate||nr,T="__p += '",M=Cs((e.escape||nr).source+"|"+E.source+"|"+(E===Hi?qc:nr).source+"|"+(e.evaluate||nr).source+"|$","g"),L="//# sourceURL="+(Z.call(e,"sourceURL")?(e.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++mh+"]")+`
|
|
23
|
-
`;t.replace(
|
|
24
|
-
__e(`+
|
|
25
|
-
'`),
|
|
26
|
-
`+
|
|
27
|
-
__p += '`),
|
|
28
|
-
((__t = (`+
|
|
29
|
-
'`),
|
|
30
|
-
`;var
|
|
31
|
-
`+
|
|
8
|
+
*/Sr.exports;(function(h,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,I="__lodash_placeholder__",P=1,T=2,F=4,J=1,q=2,_t=1,Pt=2,Vt=4,st=8,Pn=16,zt=32,gn=64,xt=128,Dt=256,Bn=512,Re=30,Rt="...",Ie=800,Mn=16,re=1,ft=2,br=3,rn=1/0,jt=9007199254740991,Cr=17976931348623157e292,$n=NaN,Ft=4294967295,Ee=Ft-1,Pr=Ft>>>1,X=[["ary",xt],["bind",_t],["bindKey",Pt],["curry",st],["curryRight",Pn],["flip",Bn],["partial",zt],["partialRight",gn],["rearg",Dt]],ct="[object Arguments]",Ht="[object Array]",Rn="[object AsyncFunction]",_n="[object Boolean]",vt="[object Date]",Fo="[object DOMException]",Te="[object Error]",Le="[object Function]",Vi="[object GeneratorFunction]",Gt="[object Map]",ie="[object Number]",No="[object Null]",un="[object Object]",ji="[object Promise]",Uo="[object Proxy]",ue="[object RegExp]",Jt="[object Set]",se="[object String]",Oe="[object Symbol]",Bo="[object Undefined]",oe="[object WeakMap]",Mo="[object WeakSet]",ae="[object ArrayBuffer]",Kn="[object DataView]",Rr="[object Float32Array]",Ir="[object Float64Array]",Er="[object Int8Array]",Tr="[object Int16Array]",Lr="[object Int32Array]",Or="[object Uint8Array]",Wr="[object Uint8ClampedArray]",Dr="[object Uint16Array]",Fr="[object Uint32Array]",$o=/\b__p \+= '';/g,Ko=/\b(__p \+=) '' \+/g,qo=/(__e\(.*?\)|\b__t\)) \+\n'';/g,tu=/&(?:amp|lt|gt|quot|#39);/g,nu=/[&<>"']/g,ko=RegExp(tu.source),zo=RegExp(nu.source),Ho=/<%-([\s\S]+?)%>/g,Go=/<%([\s\S]+?)%>/g,eu=/<%=([\s\S]+?)%>/g,Jo=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Zo=/^\w*$/,Yo=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Nr=/[\\^$.*+?()[\]{}|]/g,Xo=RegExp(Nr.source),Ur=/^\s+/,Qo=/\s/,Vo=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,jo=/\{\n\/\* \[wrapped with (.+)\] \*/,ta=/,? & /,na=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ea=/[()=,{}\[\]\/\s]/,ra=/\\(\\)?/g,ia=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ru=/\w*$/,ua=/^[-+]0x[0-9a-f]+$/i,sa=/^0b[01]+$/i,oa=/^\[object .+?Constructor\]$/,aa=/^0o[0-7]+$/i,fa=/^(?:0|[1-9]\d*)$/,ca=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,We=/($^)/,la=/['\n\r\u2028\u2029\\]/g,De="\\ud800-\\udfff",ha="\\u0300-\\u036f",da="\\ufe20-\\ufe2f",pa="\\u20d0-\\u20ff",iu=ha+da+pa,uu="\\u2700-\\u27bf",su="a-z\\xdf-\\xf6\\xf8-\\xff",ga="\\xac\\xb1\\xd7\\xf7",_a="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",va="\\u2000-\\u206f",wa=" \\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",ou="A-Z\\xc0-\\xd6\\xd8-\\xde",au="\\ufe0e\\ufe0f",fu=ga+_a+va+wa,Br="['’]",ya="["+De+"]",cu="["+fu+"]",Fe="["+iu+"]",lu="\\d+",ma="["+uu+"]",hu="["+su+"]",du="[^"+De+fu+lu+uu+su+ou+"]",Mr="\\ud83c[\\udffb-\\udfff]",xa="(?:"+Fe+"|"+Mr+")",pu="[^"+De+"]",$r="(?:\\ud83c[\\udde6-\\uddff]){2}",Kr="[\\ud800-\\udbff][\\udc00-\\udfff]",qn="["+ou+"]",gu="\\u200d",_u="(?:"+hu+"|"+du+")",Sa="(?:"+qn+"|"+du+")",vu="(?:"+Br+"(?:d|ll|m|re|s|t|ve))?",wu="(?:"+Br+"(?:D|LL|M|RE|S|T|VE))?",yu=xa+"?",mu="["+au+"]?",Aa="(?:"+gu+"(?:"+[pu,$r,Kr].join("|")+")"+mu+yu+")*",ba="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ca="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",xu=mu+yu+Aa,Pa="(?:"+[ma,$r,Kr].join("|")+")"+xu,Ra="(?:"+[pu+Fe+"?",Fe,$r,Kr,ya].join("|")+")",Ia=RegExp(Br,"g"),Ea=RegExp(Fe,"g"),qr=RegExp(Mr+"(?="+Mr+")|"+Ra+xu,"g"),Ta=RegExp([qn+"?"+hu+"+"+vu+"(?="+[cu,qn,"$"].join("|")+")",Sa+"+"+wu+"(?="+[cu,qn+_u,"$"].join("|")+")",qn+"?"+_u+"+"+vu,qn+"+"+wu,Ca,ba,lu,Pa].join("|"),"g"),La=RegExp("["+gu+De+iu+au+"]"),Oa=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Wa=["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"],Da=-1,tt={};tt[Rr]=tt[Ir]=tt[Er]=tt[Tr]=tt[Lr]=tt[Or]=tt[Wr]=tt[Dr]=tt[Fr]=!0,tt[ct]=tt[Ht]=tt[ae]=tt[_n]=tt[Kn]=tt[vt]=tt[Te]=tt[Le]=tt[Gt]=tt[ie]=tt[un]=tt[ue]=tt[Jt]=tt[se]=tt[oe]=!1;var V={};V[ct]=V[Ht]=V[ae]=V[Kn]=V[_n]=V[vt]=V[Rr]=V[Ir]=V[Er]=V[Tr]=V[Lr]=V[Gt]=V[ie]=V[un]=V[ue]=V[Jt]=V[se]=V[Oe]=V[Or]=V[Wr]=V[Dr]=V[Fr]=!0,V[Te]=V[Le]=V[oe]=!1;var Fa={À:"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"},Na={"&":"&","<":"<",">":">",'"':""","'":"'"},Ua={"&":"&","<":"<",">":">",""":'"',"'":"'"},Ba={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Ma=parseFloat,$a=parseInt,Su=typeof be=="object"&&be&&be.Object===Object&&be,Ka=typeof self=="object"&&self&&self.Object===Object&&self,ht=Su||Ka||Function("return this")(),kr=f&&!f.nodeType&&f,In=kr&&!0&&h&&!h.nodeType&&h,Au=In&&In.exports===kr,zr=Au&&Su.process,Nt=function(){try{var l=In&&In.require&&In.require("util").types;return l||zr&&zr.binding&&zr.binding("util")}catch{}}(),bu=Nt&&Nt.isArrayBuffer,Cu=Nt&&Nt.isDate,Pu=Nt&&Nt.isMap,Ru=Nt&&Nt.isRegExp,Iu=Nt&&Nt.isSet,Eu=Nt&&Nt.isTypedArray;function It(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 qa(l,w,g,b){for(var N=-1,G=l==null?0:l.length;++N<G;){var ot=l[N];w(b,ot,g(ot),l)}return b}function Ut(l,w){for(var g=-1,b=l==null?0:l.length;++g<b&&w(l[g],g,l)!==!1;);return l}function ka(l,w){for(var g=l==null?0:l.length;g--&&w(l[g],g,l)!==!1;);return l}function Tu(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 vn(l,w){for(var g=-1,b=l==null?0:l.length,N=0,G=[];++g<b;){var ot=l[g];w(ot,g,l)&&(G[N++]=ot)}return G}function Ne(l,w){var g=l==null?0:l.length;return!!g&&kn(l,w,0)>-1}function Hr(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 nt(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 wn(l,w){for(var g=-1,b=w.length,N=l.length;++g<b;)l[N+g]=w[g];return l}function Gr(l,w,g,b){var N=-1,G=l==null?0:l.length;for(b&&G&&(g=l[++N]);++N<G;)g=w(g,l[N],N,l);return g}function za(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 Jr(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 Ha=Zr("length");function Ga(l){return l.split("")}function Ja(l){return l.match(na)||[]}function Lu(l,w,g){var b;return g(l,function(N,G,ot){if(w(N,G,ot))return b=G,!1}),b}function Ue(l,w,g,b){for(var N=l.length,G=g+(b?1:-1);b?G--:++G<N;)if(w(l[G],G,l))return G;return-1}function kn(l,w,g){return w===w?sf(l,w,g):Ue(l,Ou,g)}function Za(l,w,g,b){for(var N=g-1,G=l.length;++N<G;)if(b(l[N],w))return N;return-1}function Ou(l){return l!==l}function Wu(l,w){var g=l==null?0:l.length;return g?Xr(l,w)/g:$n}function Zr(l){return function(w){return w==null?i:w[l]}}function Yr(l){return function(w){return l==null?i:l[w]}}function Du(l,w,g,b,N){return N(l,function(G,ot,Q){g=b?(b=!1,G):w(g,G,ot,Q)}),g}function Ya(l,w){var g=l.length;for(l.sort(w);g--;)l[g]=l[g].value;return l}function Xr(l,w){for(var g,b=-1,N=l.length;++b<N;){var G=w(l[b]);G!==i&&(g=g===i?G:g+G)}return g}function Qr(l,w){for(var g=-1,b=Array(l);++g<l;)b[g]=w(g);return b}function Xa(l,w){return nt(w,function(g){return[g,l[g]]})}function Fu(l){return l&&l.slice(0,Mu(l)+1).replace(Ur,"")}function Et(l){return function(w){return l(w)}}function Vr(l,w){return nt(w,function(g){return l[g]})}function fe(l,w){return l.has(w)}function Nu(l,w){for(var g=-1,b=l.length;++g<b&&kn(w,l[g],0)>-1;);return g}function Uu(l,w){for(var g=l.length;g--&&kn(w,l[g],0)>-1;);return g}function Qa(l,w){for(var g=l.length,b=0;g--;)l[g]===w&&++b;return b}var Va=Yr(Fa),ja=Yr(Na);function tf(l){return"\\"+Ba[l]}function nf(l,w){return l==null?i:l[w]}function zn(l){return La.test(l)}function ef(l){return Oa.test(l)}function rf(l){for(var w,g=[];!(w=l.next()).done;)g.push(w.value);return g}function jr(l){var w=-1,g=Array(l.size);return l.forEach(function(b,N){g[++w]=[N,b]}),g}function Bu(l,w){return function(g){return l(w(g))}}function yn(l,w){for(var g=-1,b=l.length,N=0,G=[];++g<b;){var ot=l[g];(ot===w||ot===I)&&(l[g]=I,G[N++]=g)}return G}function Be(l){var w=-1,g=Array(l.size);return l.forEach(function(b){g[++w]=b}),g}function uf(l){var w=-1,g=Array(l.size);return l.forEach(function(b){g[++w]=[b,b]}),g}function sf(l,w,g){for(var b=g-1,N=l.length;++b<N;)if(l[b]===w)return b;return-1}function of(l,w,g){for(var b=g+1;b--;)if(l[b]===w)return b;return b}function Hn(l){return zn(l)?ff(l):Ha(l)}function Zt(l){return zn(l)?cf(l):Ga(l)}function Mu(l){for(var w=l.length;w--&&Qo.test(l.charAt(w)););return w}var af=Yr(Ua);function ff(l){for(var w=qr.lastIndex=0;qr.test(l);)++w;return w}function cf(l){return l.match(qr)||[]}function lf(l){return l.match(Ta)||[]}var hf=function l(w){w=w==null?ht:Gn.defaults(ht.Object(),w,Gn.pick(ht,Wa));var g=w.Array,b=w.Date,N=w.Error,G=w.Function,ot=w.Math,Q=w.Object,ti=w.RegExp,df=w.String,Bt=w.TypeError,Me=g.prototype,pf=G.prototype,Jn=Q.prototype,$e=w["__core-js_shared__"],Ke=pf.toString,Y=Jn.hasOwnProperty,gf=0,$u=function(){var t=/[^.]+$/.exec($e&&$e.keys&&$e.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),qe=Jn.toString,_f=Ke.call(Q),vf=ht._,wf=ti("^"+Ke.call(Y).replace(Nr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ke=Au?w.Buffer:i,mn=w.Symbol,ze=w.Uint8Array,Ku=ke?ke.allocUnsafe:i,He=Bu(Q.getPrototypeOf,Q),qu=Q.create,ku=Jn.propertyIsEnumerable,Ge=Me.splice,zu=mn?mn.isConcatSpreadable:i,ce=mn?mn.iterator:i,En=mn?mn.toStringTag:i,Je=function(){try{var t=Dn(Q,"defineProperty");return t({},"",{}),t}catch{}}(),yf=w.clearTimeout!==ht.clearTimeout&&w.clearTimeout,mf=b&&b.now!==ht.Date.now&&b.now,xf=w.setTimeout!==ht.setTimeout&&w.setTimeout,Ze=ot.ceil,Ye=ot.floor,ni=Q.getOwnPropertySymbols,Sf=ke?ke.isBuffer:i,Hu=w.isFinite,Af=Me.join,bf=Bu(Q.keys,Q),at=ot.max,pt=ot.min,Cf=b.now,Pf=w.parseInt,Gu=ot.random,Rf=Me.reverse,ei=Dn(w,"DataView"),le=Dn(w,"Map"),ri=Dn(w,"Promise"),Zn=Dn(w,"Set"),he=Dn(w,"WeakMap"),de=Dn(Q,"create"),Xe=he&&new he,Yn={},If=Fn(ei),Ef=Fn(le),Tf=Fn(ri),Lf=Fn(Zn),Of=Fn(he),Qe=mn?mn.prototype:i,pe=Qe?Qe.valueOf:i,Ju=Qe?Qe.toString:i;function s(t){if(rt(t)&&!U(t)&&!(t instanceof z)){if(t instanceof Mt)return t;if(Y.call(t,"__wrapped__"))return Zs(t)}return new Mt(t)}var Xn=function(){function t(){}return function(n){if(!et(n))return{};if(qu)return qu(n);t.prototype=n;var e=new t;return t.prototype=i,e}}();function Ve(){}function Mt(t,n){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!n,this.__index__=0,this.__values__=i}s.templateSettings={escape:Ho,evaluate:Go,interpolate:eu,variable:"",imports:{_:s}},s.prototype=Ve.prototype,s.prototype.constructor=s,Mt.prototype=Xn(Ve.prototype),Mt.prototype.constructor=Mt;function z(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=Ft,this.__views__=[]}function Wf(){var t=new z(this.__wrapped__);return t.__actions__=St(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=St(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=St(this.__views__),t}function Df(){if(this.__filtered__){var t=new z(this);t.__dir__=-1,t.__filtered__=!0}else t=this.clone(),t.__dir__*=-1;return t}function Ff(){var t=this.__wrapped__.value(),n=this.__dir__,e=U(t),r=n<0,u=e?t.length:0,o=Jc(0,u,this.__views__),a=o.start,c=o.end,d=c-a,y=r?c:a-1,m=this.__iteratees__,x=m.length,A=0,R=pt(d,this.__takeCount__);if(!e||!r&&u==d&&R==d)return vs(t,this.__actions__);var O=[];t:for(;d--&&A<R;){y+=n;for(var $=-1,W=t[y];++$<x;){var k=m[$],H=k.iteratee,Ot=k.type,mt=H(W);if(Ot==ft)W=mt;else if(!mt){if(Ot==re)continue t;break t}}O[A++]=W}return O}z.prototype=Xn(Ve.prototype),z.prototype.constructor=z;function Tn(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 Nf(){this.__data__=de?de(null):{},this.size=0}function Uf(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}function Bf(t){var n=this.__data__;if(de){var e=n[t];return e===C?i:e}return Y.call(n,t)?n[t]:i}function Mf(t){var n=this.__data__;return de?n[t]!==i:Y.call(n,t)}function $f(t,n){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=de&&n===i?C:n,this}Tn.prototype.clear=Nf,Tn.prototype.delete=Uf,Tn.prototype.get=Bf,Tn.prototype.has=Mf,Tn.prototype.set=$f;function sn(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 Kf(){this.__data__=[],this.size=0}function qf(t){var n=this.__data__,e=je(n,t);if(e<0)return!1;var r=n.length-1;return e==r?n.pop():Ge.call(n,e,1),--this.size,!0}function kf(t){var n=this.__data__,e=je(n,t);return e<0?i:n[e][1]}function zf(t){return je(this.__data__,t)>-1}function Hf(t,n){var e=this.__data__,r=je(e,t);return r<0?(++this.size,e.push([t,n])):e[r][1]=n,this}sn.prototype.clear=Kf,sn.prototype.delete=qf,sn.prototype.get=kf,sn.prototype.has=zf,sn.prototype.set=Hf;function on(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 Gf(){this.size=0,this.__data__={hash:new Tn,map:new(le||sn),string:new Tn}}function Jf(t){var n=lr(this,t).delete(t);return this.size-=n?1:0,n}function Zf(t){return lr(this,t).get(t)}function Yf(t){return lr(this,t).has(t)}function Xf(t,n){var e=lr(this,t),r=e.size;return e.set(t,n),this.size+=e.size==r?0:1,this}on.prototype.clear=Gf,on.prototype.delete=Jf,on.prototype.get=Zf,on.prototype.has=Yf,on.prototype.set=Xf;function Ln(t){var n=-1,e=t==null?0:t.length;for(this.__data__=new on;++n<e;)this.add(t[n])}function Qf(t){return this.__data__.set(t,C),this}function Vf(t){return this.__data__.has(t)}Ln.prototype.add=Ln.prototype.push=Qf,Ln.prototype.has=Vf;function Yt(t){var n=this.__data__=new sn(t);this.size=n.size}function jf(){this.__data__=new sn,this.size=0}function tc(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e}function nc(t){return this.__data__.get(t)}function ec(t){return this.__data__.has(t)}function rc(t,n){var e=this.__data__;if(e instanceof sn){var r=e.__data__;if(!le||r.length<_-1)return r.push([t,n]),this.size=++e.size,this;e=this.__data__=new on(r)}return e.set(t,n),this.size=e.size,this}Yt.prototype.clear=jf,Yt.prototype.delete=tc,Yt.prototype.get=nc,Yt.prototype.has=ec,Yt.prototype.set=rc;function Zu(t,n){var e=U(t),r=!e&&Nn(t),u=!e&&!r&&Cn(t),o=!e&&!r&&!u&&te(t),a=e||r||u||o,c=a?Qr(t.length,df):[],d=c.length;for(var y in t)(n||Y.call(t,y))&&!(a&&(y=="length"||u&&(y=="offset"||y=="parent")||o&&(y=="buffer"||y=="byteLength"||y=="byteOffset")||ln(y,d)))&&c.push(y);return c}function Yu(t){var n=t.length;return n?t[pi(0,n-1)]:i}function ic(t,n){return hr(St(t),On(n,0,t.length))}function uc(t){return hr(St(t))}function ii(t,n,e){(e!==i&&!Xt(t[n],e)||e===i&&!(n in t))&&an(t,n,e)}function ge(t,n,e){var r=t[n];(!(Y.call(t,n)&&Xt(r,e))||e===i&&!(n in t))&&an(t,n,e)}function je(t,n){for(var e=t.length;e--;)if(Xt(t[e][0],n))return e;return-1}function sc(t,n,e,r){return xn(t,function(u,o,a){n(r,u,e(u),a)}),r}function Xu(t,n){return t&&nn(n,lt(n),t)}function oc(t,n){return t&&nn(n,bt(n),t)}function an(t,n,e){n=="__proto__"&&Je?Je(t,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[n]=e}function ui(t,n){for(var e=-1,r=n.length,u=g(r),o=t==null;++e<r;)u[e]=o?i:Mi(t,n[e]);return u}function On(t,n,e){return t===t&&(e!==i&&(t=t<=e?t:e),n!==i&&(t=t>=n?t:n)),t}function $t(t,n,e,r,u,o){var a,c=n&P,d=n&T,y=n&F;if(e&&(a=u?e(t,r,u,o):e(t)),a!==i)return a;if(!et(t))return t;var m=U(t);if(m){if(a=Yc(t),!c)return St(t,a)}else{var x=gt(t),A=x==Le||x==Vi;if(Cn(t))return ms(t,c);if(x==un||x==ct||A&&!u){if(a=d||A?{}:Ms(t),!c)return d?Bc(t,oc(a,t)):Uc(t,Xu(a,t))}else{if(!V[x])return u?t:{};a=Xc(t,x,c)}}o||(o=new Yt);var R=o.get(t);if(R)return R;o.set(t,a),go(t)?t.forEach(function(W){a.add($t(W,n,e,W,t,o))}):ho(t)&&t.forEach(function(W,k){a.set(k,$t(W,n,e,k,t,o))});var O=y?d?Ci:bi:d?bt:lt,$=m?i:O(t);return Ut($||t,function(W,k){$&&(k=W,W=t[k]),ge(a,k,$t(W,n,e,k,t,o))}),a}function ac(t){var n=lt(t);return function(e){return Qu(e,t,n)}}function Qu(t,n,e){var r=e.length;if(t==null)return!r;for(t=Q(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 Vu(t,n,e){if(typeof t!="function")throw new Bt(S);return Se(function(){t.apply(i,e)},n)}function _e(t,n,e,r){var u=-1,o=Ne,a=!0,c=t.length,d=[],y=n.length;if(!c)return d;e&&(n=nt(n,Et(e))),r?(o=Hr,a=!1):n.length>=_&&(o=fe,a=!1,n=new Ln(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;d.push(m)}else o(n,x,r)||d.push(m)}return d}var xn=Cs(tn),ju=Cs(oi,!0);function fc(t,n){var e=!0;return xn(t,function(r,u,o){return e=!!n(r,u,o),e}),e}function tr(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&&!Lt(a):e(a,c)))var c=a,d=o}return d}function cc(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:vo(r);e<r;)t[e++]=n;return t}function ts(t,n){var e=[];return xn(t,function(r,u,o){n(r,u,o)&&e.push(r)}),e}function dt(t,n,e,r,u){var o=-1,a=t.length;for(e||(e=Vc),u||(u=[]);++o<a;){var c=t[o];n>0&&e(c)?n>1?dt(c,n-1,e,r,u):wn(u,c):r||(u[u.length]=c)}return u}var si=Ps(),ns=Ps(!0);function tn(t,n){return t&&si(t,n,lt)}function oi(t,n){return t&&ns(t,n,lt)}function nr(t,n){return vn(n,function(e){return hn(t[e])})}function Wn(t,n){n=An(n,t);for(var e=0,r=n.length;t!=null&&e<r;)t=t[en(n[e++])];return e&&e==r?t:i}function es(t,n,e){var r=n(t);return U(t)?r:wn(r,e(t))}function wt(t){return t==null?t===i?Bo:No:En&&En in Q(t)?Gc(t):ul(t)}function ai(t,n){return t>n}function lc(t,n){return t!=null&&Y.call(t,n)}function hc(t,n){return t!=null&&n in Q(t)}function dc(t,n,e){return t>=pt(n,e)&&t<at(n,e)}function fi(t,n,e){for(var r=e?Hr:Ne,u=t[0].length,o=t.length,a=o,c=g(o),d=1/0,y=[];a--;){var m=t[a];a&&n&&(m=nt(m,Et(n))),d=pt(m.length,d),c[a]=!e&&(n||u>=120&&m.length>=120)?new Ln(a&&m):i}m=t[0];var x=-1,A=c[0];t:for(;++x<u&&y.length<d;){var R=m[x],O=n?n(R):R;if(R=e||R!==0?R:0,!(A?fe(A,O):r(y,O,e))){for(a=o;--a;){var $=c[a];if(!($?fe($,O):r(t[a],O,e)))continue t}A&&A.push(O),y.push(R)}}return y}function pc(t,n,e,r){return tn(t,function(u,o,a){n(r,e(u),o,a)}),r}function ve(t,n,e){n=An(n,t),t=ks(t,n);var r=t==null?t:t[en(qt(n))];return r==null?i:It(r,t,e)}function rs(t){return rt(t)&&wt(t)==ct}function gc(t){return rt(t)&&wt(t)==ae}function _c(t){return rt(t)&&wt(t)==vt}function we(t,n,e,r,u){return t===n?!0:t==null||n==null||!rt(t)&&!rt(n)?t!==t&&n!==n:vc(t,n,e,r,we,u)}function vc(t,n,e,r,u,o){var a=U(t),c=U(n),d=a?Ht:gt(t),y=c?Ht:gt(n);d=d==ct?un:d,y=y==ct?un:y;var m=d==un,x=y==un,A=d==y;if(A&&Cn(t)){if(!Cn(n))return!1;a=!0,m=!1}if(A&&!m)return o||(o=new Yt),a||te(t)?Ns(t,n,e,r,u,o):zc(t,n,d,e,r,u,o);if(!(e&J)){var R=m&&Y.call(t,"__wrapped__"),O=x&&Y.call(n,"__wrapped__");if(R||O){var $=R?t.value():t,W=O?n.value():n;return o||(o=new Yt),u($,W,e,r,o)}}return A?(o||(o=new Yt),Hc(t,n,e,r,u,o)):!1}function wc(t){return rt(t)&>(t)==Gt}function ci(t,n,e,r){var u=e.length,o=u,a=!r;if(t==null)return!o;for(t=Q(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 d=c[0],y=t[d],m=c[1];if(a&&c[2]){if(y===i&&!(d in t))return!1}else{var x=new Yt;if(r)var A=r(y,m,d,t,n,x);if(!(A===i?we(m,y,J|q,r,x):A))return!1}}return!0}function is(t){if(!et(t)||tl(t))return!1;var n=hn(t)?wf:oa;return n.test(Fn(t))}function yc(t){return rt(t)&&wt(t)==ue}function mc(t){return rt(t)&>(t)==Jt}function xc(t){return rt(t)&&wr(t.length)&&!!tt[wt(t)]}function us(t){return typeof t=="function"?t:t==null?Ct:typeof t=="object"?U(t)?as(t[0],t[1]):os(t):Io(t)}function li(t){if(!xe(t))return bf(t);var n=[];for(var e in Q(t))Y.call(t,e)&&e!="constructor"&&n.push(e);return n}function Sc(t){if(!et(t))return il(t);var n=xe(t),e=[];for(var r in t)r=="constructor"&&(n||!Y.call(t,r))||e.push(r);return e}function hi(t,n){return t<n}function ss(t,n){var e=-1,r=At(t)?g(t.length):[];return xn(t,function(u,o,a){r[++e]=n(u,o,a)}),r}function os(t){var n=Ri(t);return n.length==1&&n[0][2]?Ks(n[0][0],n[0][1]):function(e){return e===t||ci(e,t,n)}}function as(t,n){return Ei(t)&&$s(n)?Ks(en(t),n):function(e){var r=Mi(e,t);return r===i&&r===n?$i(e,t):we(n,r,J|q)}}function er(t,n,e,r,u){t!==n&&si(n,function(o,a){if(u||(u=new Yt),et(o))Ac(t,n,a,e,er,r,u);else{var c=r?r(Li(t,a),o,a+"",t,n,u):i;c===i&&(c=o),ii(t,a,c)}},bt)}function Ac(t,n,e,r,u,o,a){var c=Li(t,e),d=Li(n,e),y=a.get(d);if(y){ii(t,e,y);return}var m=o?o(c,d,e+"",t,n,a):i,x=m===i;if(x){var A=U(d),R=!A&&Cn(d),O=!A&&!R&&te(d);m=d,A||R||O?U(c)?m=c:it(c)?m=St(c):R?(x=!1,m=ms(d,!0)):O?(x=!1,m=xs(d,!0)):m=[]:Ae(d)||Nn(d)?(m=c,Nn(c)?m=wo(c):(!et(c)||hn(c))&&(m=Ms(d))):x=!1}x&&(a.set(d,m),u(m,d,r,o,a),a.delete(d)),ii(t,e,m)}function fs(t,n){var e=t.length;if(e)return n+=n<0?e:0,ln(n,e)?t[n]:i}function cs(t,n,e){n.length?n=nt(n,function(o){return U(o)?function(a){return Wn(a,o.length===1?o[0]:o)}:o}):n=[Ct];var r=-1;n=nt(n,Et(L()));var u=ss(t,function(o,a,c){var d=nt(n,function(y){return y(o)});return{criteria:d,index:++r,value:o}});return Ya(u,function(o,a){return Nc(o,a,e)})}function bc(t,n){return ls(t,n,function(e,r){return $i(t,r)})}function ls(t,n,e){for(var r=-1,u=n.length,o={};++r<u;){var a=n[r],c=Wn(t,a);e(c,a)&&ye(o,An(a,t),c)}return o}function Cc(t){return function(n){return Wn(n,t)}}function di(t,n,e,r){var u=r?Za:kn,o=-1,a=n.length,c=t;for(t===n&&(n=St(n)),e&&(c=nt(t,Et(e)));++o<a;)for(var d=0,y=n[o],m=e?e(y):y;(d=u(c,m,d,r))>-1;)c!==t&&Ge.call(c,d,1),Ge.call(t,d,1);return t}function hs(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;ln(u)?Ge.call(t,u,1):vi(t,u)}}return t}function pi(t,n){return t+Ye(Gu()*(n-t+1))}function Pc(t,n,e,r){for(var u=-1,o=at(Ze((n-t)/(e||1)),0),a=g(o);o--;)a[r?o:++u]=t,t+=e;return a}function gi(t,n){var e="";if(!t||n<1||n>jt)return e;do n%2&&(e+=t),n=Ye(n/2),n&&(t+=t);while(n);return e}function K(t,n){return Oi(qs(t,n,Ct),t+"")}function Rc(t){return Yu(ne(t))}function Ic(t,n){var e=ne(t);return hr(e,On(n,0,e.length))}function ye(t,n,e,r){if(!et(t))return t;n=An(n,t);for(var u=-1,o=n.length,a=o-1,c=t;c!=null&&++u<o;){var d=en(n[u]),y=e;if(d==="__proto__"||d==="constructor"||d==="prototype")return t;if(u!=a){var m=c[d];y=r?r(m,d,c):i,y===i&&(y=et(m)?m:ln(n[u+1])?[]:{})}ge(c,d,y),c=c[d]}return t}var ds=Xe?function(t,n){return Xe.set(t,n),t}:Ct,Ec=Je?function(t,n){return Je(t,"toString",{configurable:!0,enumerable:!1,value:qi(n),writable:!0})}:Ct;function Tc(t){return hr(ne(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 Lc(t,n){var e;return xn(t,function(r,u,o){return e=n(r,u,o),!e}),!!e}function rr(t,n,e){var r=0,u=t==null?r:t.length;if(typeof n=="number"&&n===n&&u<=Pr){for(;r<u;){var o=r+u>>>1,a=t[o];a!==null&&!Lt(a)&&(e?a<=n:a<n)?r=o+1:u=o}return u}return _i(t,n,Ct,e)}function _i(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,d=Lt(n),y=n===i;u<o;){var m=Ye((u+o)/2),x=e(t[m]),A=x!==i,R=x===null,O=x===x,$=Lt(x);if(a)var W=r||O;else y?W=O&&(r||A):c?W=O&&A&&(r||!R):d?W=O&&A&&!R&&(r||!$):R||$?W=!1:W=r?x<=n:x<n;W?u=m+1:o=m}return pt(o,Ee)}function ps(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||!Xt(c,d)){var d=c;o[u++]=a===0?0:a}}return o}function gs(t){return typeof t=="number"?t:Lt(t)?$n:+t}function Tt(t){if(typeof t=="string")return t;if(U(t))return nt(t,Tt)+"";if(Lt(t))return Ju?Ju.call(t):"";var n=t+"";return n=="0"&&1/t==-rn?"-0":n}function Sn(t,n,e){var r=-1,u=Ne,o=t.length,a=!0,c=[],d=c;if(e)a=!1,u=Hr;else if(o>=_){var y=n?null:qc(t);if(y)return Be(y);a=!1,u=fe,d=new Ln}else d=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=d.length;A--;)if(d[A]===x)continue t;n&&d.push(x),c.push(m)}else u(d,x,e)||(d!==c&&d.push(x),c.push(m))}return c}function vi(t,n){return n=An(n,t),t=ks(t,n),t==null||delete t[en(qt(n))]}function _s(t,n,e,r){return ye(t,n,e(Wn(t,n)),r)}function ir(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 vs(t,n){var e=t;return e instanceof z&&(e=e.value()),Gr(n,function(r,u){return u.func.apply(u.thisArg,wn([r],u.args))},e)}function wi(t,n,e){var r=t.length;if(r<2)return r?Sn(t[0]):[];for(var u=-1,o=g(r);++u<r;)for(var a=t[u],c=-1;++c<r;)c!=u&&(o[u]=_e(o[u]||a,t[c],n,e));return Sn(dt(o,1),n,e)}function ws(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 yi(t){return it(t)?t:[]}function mi(t){return typeof t=="function"?t:Ct}function An(t,n){return U(t)?t:Ei(t,n)?[t]:Js(Z(t))}var Oc=K;function bn(t,n,e){var r=t.length;return e=e===i?r:e,!n&&e>=r?t:Kt(t,n,e)}var ys=yf||function(t){return ht.clearTimeout(t)};function ms(t,n){if(n)return t.slice();var e=t.length,r=Ku?Ku(e):new t.constructor(e);return t.copy(r),r}function xi(t){var n=new t.constructor(t.byteLength);return new ze(n).set(new ze(t)),n}function Wc(t,n){var e=n?xi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.byteLength)}function Dc(t){var n=new t.constructor(t.source,ru.exec(t));return n.lastIndex=t.lastIndex,n}function Fc(t){return pe?Q(pe.call(t)):{}}function xs(t,n){var e=n?xi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function Ss(t,n){if(t!==n){var e=t!==i,r=t===null,u=t===t,o=Lt(t),a=n!==i,c=n===null,d=n===n,y=Lt(n);if(!c&&!y&&!o&&t>n||o&&a&&d&&!c&&!y||r&&a&&d||!e&&d||!u)return 1;if(!r&&!o&&!y&&t<n||y&&e&&u&&!r&&!o||c&&e&&u||!a&&u||!d)return-1}return 0}function Nc(t,n,e){for(var r=-1,u=t.criteria,o=n.criteria,a=u.length,c=e.length;++r<a;){var d=Ss(u[r],o[r]);if(d){if(r>=c)return d;var y=e[r];return d*(y=="desc"?-1:1)}}return t.index-n.index}function As(t,n,e,r){for(var u=-1,o=t.length,a=e.length,c=-1,d=n.length,y=at(o-a,0),m=g(d+y),x=!r;++c<d;)m[c]=n[c];for(;++u<a;)(x||u<o)&&(m[e[u]]=t[u]);for(;y--;)m[c++]=t[u++];return m}function bs(t,n,e,r){for(var u=-1,o=t.length,a=-1,c=e.length,d=-1,y=n.length,m=at(o-c,0),x=g(m+y),A=!r;++u<m;)x[u]=t[u];for(var R=u;++d<y;)x[R+d]=n[d];for(;++a<c;)(A||u<o)&&(x[R+e[a]]=t[u++]);return x}function St(t,n){var e=-1,r=t.length;for(n||(n=g(r));++e<r;)n[e]=t[e];return n}function nn(t,n,e,r){var u=!e;e||(e={});for(var o=-1,a=n.length;++o<a;){var c=n[o],d=r?r(e[c],t[c],c,e,t):i;d===i&&(d=t[c]),u?an(e,c,d):ge(e,c,d)}return e}function Uc(t,n){return nn(t,Ii(t),n)}function Bc(t,n){return nn(t,Us(t),n)}function ur(t,n){return function(e,r){var u=U(e)?qa:sc,o=n?n():{};return u(e,t,L(r,2),o)}}function Qn(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&&yt(e[0],e[1],a)&&(o=u<3?i:o,u=1),n=Q(n);++r<u;){var c=e[r];c&&t(n,c,r,o)}return n})}function Cs(t,n){return function(e,r){if(e==null)return e;if(!At(e))return t(e,r);for(var u=e.length,o=n?u:-1,a=Q(e);(n?o--:++o<u)&&r(a[o],o,a)!==!1;);return e}}function Ps(t){return function(n,e,r){for(var u=-1,o=Q(n),a=r(n),c=a.length;c--;){var d=a[t?c:++u];if(e(o[d],d,o)===!1)break}return n}}function Mc(t,n,e){var r=n&_t,u=me(t);function o(){var a=this&&this!==ht&&this instanceof o?u:t;return a.apply(r?e:this,arguments)}return o}function Rs(t){return function(n){n=Z(n);var e=zn(n)?Zt(n):i,r=e?e[0]:n.charAt(0),u=e?bn(e,1).join(""):n.slice(1);return r[t]()+u}}function Vn(t){return function(n){return Gr(Po(Co(n).replace(Ia,"")),t,"")}}function me(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=Xn(t.prototype),r=t.apply(e,n);return et(r)?r:e}}function $c(t,n,e){var r=me(t);function u(){for(var o=arguments.length,a=g(o),c=o,d=jn(u);c--;)a[c]=arguments[c];var y=o<3&&a[0]!==d&&a[o-1]!==d?[]:yn(a,d);if(o-=y.length,o<e)return Os(t,n,sr,u.placeholder,i,a,y,i,i,e-o);var m=this&&this!==ht&&this instanceof u?r:t;return It(m,this,a)}return u}function Is(t){return function(n,e,r){var u=Q(n);if(!At(n)){var o=L(e,3);n=lt(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 Es(t){return cn(function(n){var e=n.length,r=e,u=Mt.prototype.thru;for(t&&n.reverse();r--;){var o=n[r];if(typeof o!="function")throw new Bt(S);if(u&&!a&&cr(o)=="wrapper")var a=new Mt([],!0)}for(r=a?r:e;++r<e;){o=n[r];var c=cr(o),d=c=="wrapper"?Pi(o):i;d&&Ti(d[0])&&d[1]==(xt|st|zt|Dt)&&!d[4].length&&d[9]==1?a=a[cr(d[0])].apply(a,d[3]):a=o.length==1&&Ti(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 sr(t,n,e,r,u,o,a,c,d,y){var m=n&xt,x=n&_t,A=n&Pt,R=n&(st|Pn),O=n&Bn,$=A?i:me(t);function W(){for(var k=arguments.length,H=g(k),Ot=k;Ot--;)H[Ot]=arguments[Ot];if(R)var mt=jn(W),Wt=Qa(H,mt);if(r&&(H=As(H,r,u,R)),o&&(H=bs(H,o,a,R)),k-=Wt,R&&k<y){var ut=yn(H,mt);return Os(t,n,sr,W.placeholder,e,H,ut,c,d,y-k)}var Qt=x?e:this,pn=A?Qt[t]:t;return k=H.length,c?H=sl(H,c):O&&k>1&&H.reverse(),m&&d<k&&(H.length=d),this&&this!==ht&&this instanceof W&&(pn=$||me(pn)),pn.apply(Qt,H)}return W}function Ts(t,n){return function(e,r){return pc(e,t,n(r),{})}}function or(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=Tt(e),r=Tt(r)):(e=gs(e),r=gs(r)),u=t(e,r)}return u}}function Si(t){return cn(function(n){return n=nt(n,Et(L())),K(function(e){var r=this;return t(n,function(u){return It(u,r,e)})})})}function ar(t,n){n=n===i?" ":Tt(n);var e=n.length;if(e<2)return e?gi(n,t):n;var r=gi(n,Ze(t/Hn(n)));return zn(n)?bn(Zt(r),0,t).join(""):r.slice(0,t)}function Kc(t,n,e,r){var u=n&_t,o=me(t);function a(){for(var c=-1,d=arguments.length,y=-1,m=r.length,x=g(m+d),A=this&&this!==ht&&this instanceof a?o:t;++y<m;)x[y]=r[y];for(;d--;)x[y++]=arguments[++c];return It(A,u?e:this,x)}return a}function Ls(t){return function(n,e,r){return r&&typeof r!="number"&&yt(n,e,r)&&(e=r=i),n=dn(n),e===i?(e=n,n=0):e=dn(e),r=r===i?n<e?1:-1:dn(r),Pc(n,e,r,t)}}function fr(t){return function(n,e){return typeof n=="string"&&typeof e=="string"||(n=kt(n),e=kt(e)),t(n,e)}}function Os(t,n,e,r,u,o,a,c,d,y){var m=n&st,x=m?a:i,A=m?i:a,R=m?o:i,O=m?i:o;n|=m?zt:gn,n&=~(m?gn:zt),n&Vt||(n&=-4);var $=[t,n,u,R,x,O,A,c,d,y],W=e.apply(i,$);return Ti(t)&&zs(W,$),W.placeholder=r,Hs(W,t,n)}function Ai(t){var n=ot[t];return function(e,r){if(e=kt(e),r=r==null?0:pt(B(r),292),r&&Hu(e)){var u=(Z(e)+"e").split("e"),o=n(u[0]+"e"+(+u[1]+r));return u=(Z(o)+"e").split("e"),+(u[0]+"e"+(+u[1]-r))}return n(e)}}var qc=Zn&&1/Be(new Zn([,-0]))[1]==rn?function(t){return new Zn(t)}:Hi;function Ws(t){return function(n){var e=gt(n);return e==Gt?jr(n):e==Jt?uf(n):Xa(n,t(n))}}function fn(t,n,e,r,u,o,a,c){var d=n&Pt;if(!d&&typeof t!="function")throw new Bt(S);var y=r?r.length:0;if(y||(n&=-97,r=u=i),a=a===i?a:at(B(a),0),c=c===i?c:B(c),y-=u?u.length:0,n&gn){var m=r,x=u;r=u=i}var A=d?i:Pi(t),R=[t,n,e,r,u,m,x,o,a,c];if(A&&rl(R,A),t=R[0],n=R[1],e=R[2],r=R[3],u=R[4],c=R[9]=R[9]===i?d?0:t.length:at(R[9]-y,0),!c&&n&(st|Pn)&&(n&=-25),!n||n==_t)var O=Mc(t,n,e);else n==st||n==Pn?O=$c(t,n,c):(n==zt||n==(_t|zt))&&!u.length?O=Kc(t,n,e,r):O=sr.apply(i,R);var $=A?ds:zs;return Hs($(O,R),t,n)}function Ds(t,n,e,r){return t===i||Xt(t,Jn[e])&&!Y.call(r,e)?n:t}function Fs(t,n,e,r,u,o){return et(t)&&et(n)&&(o.set(n,t),er(t,n,i,Fs,o),o.delete(n)),t}function kc(t){return Ae(t)?i:t}function Ns(t,n,e,r,u,o){var a=e&J,c=t.length,d=n.length;if(c!=d&&!(a&&d>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,R=e&q?new Ln: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(R){if(!Jr(n,function(k,H){if(!fe(R,H)&&(O===k||u(O,k,e,r,o)))return R.push(H)})){A=!1;break}}else if(!(O===$||u(O,$,e,r,o))){A=!1;break}}return o.delete(t),o.delete(n),A}function zc(t,n,e,r,u,o,a){switch(e){case Kn:if(t.byteLength!=n.byteLength||t.byteOffset!=n.byteOffset)return!1;t=t.buffer,n=n.buffer;case ae:return!(t.byteLength!=n.byteLength||!o(new ze(t),new ze(n)));case _n:case vt:case ie:return Xt(+t,+n);case Te:return t.name==n.name&&t.message==n.message;case ue:case se:return t==n+"";case Gt:var c=jr;case Jt:var d=r&J;if(c||(c=Be),t.size!=n.size&&!d)return!1;var y=a.get(t);if(y)return y==n;r|=q,a.set(t,n);var m=Ns(c(t),c(n),r,u,o,a);return a.delete(t),m;case Oe:if(pe)return pe.call(t)==pe.call(n)}return!1}function Hc(t,n,e,r,u,o){var a=e&J,c=bi(t),d=c.length,y=bi(n),m=y.length;if(d!=m&&!a)return!1;for(var x=d;x--;){var A=c[x];if(!(a?A in n:Y.call(n,A)))return!1}var R=o.get(t),O=o.get(n);if(R&&O)return R==n&&O==t;var $=!0;o.set(t,n),o.set(n,t);for(var W=a;++x<d;){A=c[x];var k=t[A],H=n[A];if(r)var Ot=a?r(H,k,A,n,t,o):r(k,H,A,t,n,o);if(!(Ot===i?k===H||u(k,H,e,r,o):Ot)){$=!1;break}W||(W=A=="constructor")}if($&&!W){var mt=t.constructor,Wt=n.constructor;mt!=Wt&&"constructor"in t&&"constructor"in n&&!(typeof mt=="function"&&mt instanceof mt&&typeof Wt=="function"&&Wt instanceof Wt)&&($=!1)}return o.delete(t),o.delete(n),$}function cn(t){return Oi(qs(t,i,Qs),t+"")}function bi(t){return es(t,lt,Ii)}function Ci(t){return es(t,bt,Us)}var Pi=Xe?function(t){return Xe.get(t)}:Hi;function cr(t){for(var n=t.name+"",e=Yn[n],r=Y.call(Yn,n)?e.length:0;r--;){var u=e[r],o=u.func;if(o==null||o==t)return u.name}return n}function jn(t){var n=Y.call(s,"placeholder")?s:t;return n.placeholder}function L(){var t=s.iteratee||ki;return t=t===ki?us:t,arguments.length?t(arguments[0],arguments[1]):t}function lr(t,n){var e=t.__data__;return jc(n)?e[typeof n=="string"?"string":"hash"]:e.map}function Ri(t){for(var n=lt(t),e=n.length;e--;){var r=n[e],u=t[r];n[e]=[r,u,$s(u)]}return n}function Dn(t,n){var e=nf(t,n);return is(e)?e:i}function Gc(t){var n=Y.call(t,En),e=t[En];try{t[En]=i;var r=!0}catch{}var u=qe.call(t);return r&&(n?t[En]=e:delete t[En]),u}var Ii=ni?function(t){return t==null?[]:(t=Q(t),vn(ni(t),function(n){return ku.call(t,n)}))}:Gi,Us=ni?function(t){for(var n=[];t;)wn(n,Ii(t)),t=He(t);return n}:Gi,gt=wt;(ei&>(new ei(new ArrayBuffer(1)))!=Kn||le&>(new le)!=Gt||ri&>(ri.resolve())!=ji||Zn&>(new Zn)!=Jt||he&>(new he)!=oe)&&(gt=function(t){var n=wt(t),e=n==un?t.constructor:i,r=e?Fn(e):"";if(r)switch(r){case If:return Kn;case Ef:return Gt;case Tf:return ji;case Lf:return Jt;case Of:return oe}return n});function Jc(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=pt(n,t+a);break;case"takeRight":t=at(t,n-a);break}}return{start:t,end:n}}function Zc(t){var n=t.match(jo);return n?n[1].split(ta):[]}function Bs(t,n,e){n=An(n,t);for(var r=-1,u=n.length,o=!1;++r<u;){var a=en(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&&wr(u)&&ln(a,u)&&(U(t)||Nn(t)))}function Yc(t){var n=t.length,e=new t.constructor(n);return n&&typeof t[0]=="string"&&Y.call(t,"index")&&(e.index=t.index,e.input=t.input),e}function Ms(t){return typeof t.constructor=="function"&&!xe(t)?Xn(He(t)):{}}function Xc(t,n,e){var r=t.constructor;switch(n){case ae:return xi(t);case _n:case vt:return new r(+t);case Kn:return Wc(t,e);case Rr:case Ir:case Er:case Tr:case Lr:case Or:case Wr:case Dr:case Fr:return xs(t,e);case Gt:return new r;case ie:case se:return new r(t);case ue:return Dc(t);case Jt:return new r;case Oe:return Fc(t)}}function Qc(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(Vo,`{
|
|
9
|
+
/* [wrapped with `+n+`] */
|
|
10
|
+
`)}function Vc(t){return U(t)||Nn(t)||!!(zu&&t&&t[zu])}function ln(t,n){var e=typeof t;return n=n??jt,!!n&&(e=="number"||e!="symbol"&&fa.test(t))&&t>-1&&t%1==0&&t<n}function yt(t,n,e){if(!et(e))return!1;var r=typeof n;return(r=="number"?At(e)&&ln(n,e.length):r=="string"&&n in e)?Xt(e[n],t):!1}function Ei(t,n){if(U(t))return!1;var e=typeof t;return e=="number"||e=="symbol"||e=="boolean"||t==null||Lt(t)?!0:Zo.test(t)||!Jo.test(t)||n!=null&&t in Q(n)}function jc(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}function Ti(t){var n=cr(t),e=s[n];if(typeof e!="function"||!(n in z.prototype))return!1;if(t===e)return!0;var r=Pi(e);return!!r&&t===r[0]}function tl(t){return!!$u&&$u in t}var nl=$e?hn:Ji;function xe(t){var n=t&&t.constructor,e=typeof n=="function"&&n.prototype||Jn;return t===e}function $s(t){return t===t&&!et(t)}function Ks(t,n){return function(e){return e==null?!1:e[t]===n&&(n!==i||t in Q(e))}}function el(t){var n=_r(t,function(r){return e.size===M&&e.clear(),r}),e=n.cache;return n}function rl(t,n){var e=t[1],r=n[1],u=e|r,o=u<(_t|Pt|xt),a=r==xt&&e==st||r==xt&&e==Dt&&t[7].length<=n[8]||r==(xt|Dt)&&n[7].length<=n[8]&&e==st;if(!(o||a))return t;r&_t&&(t[2]=n[2],u|=e&_t?0:Vt);var c=n[3];if(c){var d=t[3];t[3]=d?As(d,c,n[4]):c,t[4]=d?yn(t[3],I):n[4]}return c=n[5],c&&(d=t[5],t[5]=d?bs(d,c,n[6]):c,t[6]=d?yn(t[5],I):n[6]),c=n[7],c&&(t[7]=c),r&xt&&(t[8]=t[8]==null?n[8]:pt(t[8],n[8])),t[9]==null&&(t[9]=n[9]),t[0]=n[0],t[1]=u,t}function il(t){var n=[];if(t!=null)for(var e in Q(t))n.push(e);return n}function ul(t){return qe.call(t)}function qs(t,n,e){return n=at(n===i?t.length-1:n,0),function(){for(var r=arguments,u=-1,o=at(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),It(t,this,c)}}function ks(t,n){return n.length<2?t:Wn(t,Kt(n,0,-1))}function sl(t,n){for(var e=t.length,r=pt(n.length,e),u=St(t);r--;){var o=n[r];t[r]=ln(o,e)?u[o]:i}return t}function Li(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}var zs=Gs(ds),Se=xf||function(t,n){return ht.setTimeout(t,n)},Oi=Gs(Ec);function Hs(t,n,e){var r=n+"";return Oi(t,Qc(r,ol(Zc(r),e)))}function Gs(t){var n=0,e=0;return function(){var r=Cf(),u=Mn-(r-e);if(e=r,u>0){if(++n>=Ie)return arguments[0]}else n=0;return t.apply(i,arguments)}}function hr(t,n){var e=-1,r=t.length,u=r-1;for(n=n===i?r:n;++e<n;){var o=pi(e,u),a=t[o];t[o]=t[e],t[e]=a}return t.length=n,t}var Js=el(function(t){var n=[];return t.charCodeAt(0)===46&&n.push(""),t.replace(Yo,function(e,r,u,o){n.push(u?o.replace(ra,"$1"):r||e)}),n});function en(t){if(typeof t=="string"||Lt(t))return t;var n=t+"";return n=="0"&&1/t==-rn?"-0":n}function Fn(t){if(t!=null){try{return Ke.call(t)}catch{}try{return t+""}catch{}}return""}function ol(t,n){return Ut(X,function(e){var r="_."+e[0];n&e[1]&&!Ne(t,r)&&t.push(r)}),t.sort()}function Zs(t){if(t instanceof z)return t.clone();var n=new Mt(t.__wrapped__,t.__chain__);return n.__actions__=St(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}function al(t,n,e){(e?yt(t,n,e):n===i)?n=1:n=at(B(n),0);var r=t==null?0:t.length;if(!r||n<1)return[];for(var u=0,o=0,a=g(Ze(r/n));u<r;)a[o++]=Kt(t,u,u+=n);return a}function fl(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 cl(){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 wn(U(e)?St(e):[e],dt(n,1))}var ll=K(function(t,n){return it(t)?_e(t,dt(n,1,it,!0)):[]}),hl=K(function(t,n){var e=qt(n);return it(e)&&(e=i),it(t)?_e(t,dt(n,1,it,!0),L(e,2)):[]}),dl=K(function(t,n){var e=qt(n);return it(e)&&(e=i),it(t)?_e(t,dt(n,1,it,!0),i,e):[]});function pl(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 gl(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 _l(t,n){return t&&t.length?ir(t,L(n,3),!0,!0):[]}function vl(t,n){return t&&t.length?ir(t,L(n,3),!0):[]}function wl(t,n,e,r){var u=t==null?0:t.length;return u?(e&&typeof e!="number"&&yt(t,n,e)&&(e=0,r=u),cc(t,n,e,r)):[]}function Ys(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=at(r+u,0)),Ue(t,L(n,3),u)}function Xs(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?at(r+u,0):pt(u,r-1)),Ue(t,L(n,3),u,!0)}function Qs(t){var n=t==null?0:t.length;return n?dt(t,1):[]}function yl(t){var n=t==null?0:t.length;return n?dt(t,rn):[]}function ml(t,n){var e=t==null?0:t.length;return e?(n=n===i?1:B(n),dt(t,n)):[]}function xl(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 Vs(t){return t&&t.length?t[0]:i}function Sl(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=at(r+u,0)),kn(t,n,u)}function Al(t){var n=t==null?0:t.length;return n?Kt(t,0,-1):[]}var bl=K(function(t){var n=nt(t,yi);return n.length&&n[0]===t[0]?fi(n):[]}),Cl=K(function(t){var n=qt(t),e=nt(t,yi);return n===qt(e)?n=i:e.pop(),e.length&&e[0]===t[0]?fi(e,L(n,2)):[]}),Pl=K(function(t){var n=qt(t),e=nt(t,yi);return n=typeof n=="function"?n:i,n&&e.pop(),e.length&&e[0]===t[0]?fi(e,i,n):[]});function Rl(t,n){return t==null?"":Af.call(t,n)}function qt(t){var n=t==null?0:t.length;return n?t[n-1]:i}function Il(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?at(r+u,0):pt(u,r-1)),n===n?of(t,n,u):Ue(t,Ou,u,!0)}function El(t,n){return t&&t.length?fs(t,B(n)):i}var Tl=K(js);function js(t,n){return t&&t.length&&n&&n.length?di(t,n):t}function Ll(t,n,e){return t&&t.length&&n&&n.length?di(t,n,L(e,2)):t}function Ol(t,n,e){return t&&t.length&&n&&n.length?di(t,n,i,e):t}var Wl=cn(function(t,n){var e=t==null?0:t.length,r=ui(t,n);return hs(t,nt(n,function(u){return ln(u,e)?+u:u}).sort(Ss)),r});function Dl(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 hs(t,u),e}function Wi(t){return t==null?t:Rf.call(t)}function Fl(t,n,e){var r=t==null?0:t.length;return r?(e&&typeof e!="number"&&yt(t,n,e)?(n=0,e=r):(n=n==null?0:B(n),e=e===i?r:B(e)),Kt(t,n,e)):[]}function Nl(t,n){return rr(t,n)}function Ul(t,n,e){return _i(t,n,L(e,2))}function Bl(t,n){var e=t==null?0:t.length;if(e){var r=rr(t,n);if(r<e&&Xt(t[r],n))return r}return-1}function Ml(t,n){return rr(t,n,!0)}function $l(t,n,e){return _i(t,n,L(e,2),!0)}function Kl(t,n){var e=t==null?0:t.length;if(e){var r=rr(t,n,!0)-1;if(Xt(t[r],n))return r}return-1}function ql(t){return t&&t.length?ps(t):[]}function kl(t,n){return t&&t.length?ps(t,L(n,2)):[]}function zl(t){var n=t==null?0:t.length;return n?Kt(t,1,n):[]}function Hl(t,n,e){return t&&t.length?(n=e||n===i?1:B(n),Kt(t,0,n<0?0:n)):[]}function Gl(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 Jl(t,n){return t&&t.length?ir(t,L(n,3),!1,!0):[]}function Zl(t,n){return t&&t.length?ir(t,L(n,3)):[]}var Yl=K(function(t){return Sn(dt(t,1,it,!0))}),Xl=K(function(t){var n=qt(t);return it(n)&&(n=i),Sn(dt(t,1,it,!0),L(n,2))}),Ql=K(function(t){var n=qt(t);return n=typeof n=="function"?n:i,Sn(dt(t,1,it,!0),i,n)});function Vl(t){return t&&t.length?Sn(t):[]}function jl(t,n){return t&&t.length?Sn(t,L(n,2)):[]}function th(t,n){return n=typeof n=="function"?n:i,t&&t.length?Sn(t,i,n):[]}function Di(t){if(!(t&&t.length))return[];var n=0;return t=vn(t,function(e){if(it(e))return n=at(e.length,n),!0}),Qr(n,function(e){return nt(t,Zr(e))})}function to(t,n){if(!(t&&t.length))return[];var e=Di(t);return n==null?e:nt(e,function(r){return It(n,i,r)})}var nh=K(function(t,n){return it(t)?_e(t,n):[]}),eh=K(function(t){return wi(vn(t,it))}),rh=K(function(t){var n=qt(t);return it(n)&&(n=i),wi(vn(t,it),L(n,2))}),ih=K(function(t){var n=qt(t);return n=typeof n=="function"?n:i,wi(vn(t,it),i,n)}),uh=K(Di);function sh(t,n){return ws(t||[],n||[],ge)}function oh(t,n){return ws(t||[],n||[],ye)}var ah=K(function(t){var n=t.length,e=n>1?t[n-1]:i;return e=typeof e=="function"?(t.pop(),e):i,to(t,e)});function no(t){var n=s(t);return n.__chain__=!0,n}function fh(t,n){return n(t),t}function dr(t,n){return n(t)}var ch=cn(function(t){var n=t.length,e=n?t[0]:0,r=this.__wrapped__,u=function(o){return ui(o,t)};return n>1||this.__actions__.length||!(r instanceof z)||!ln(e)?this.thru(u):(r=r.slice(e,+e+(n?1:0)),r.__actions__.push({func:dr,args:[u],thisArg:i}),new Mt(r,this.__chain__).thru(function(o){return n&&!o.length&&o.push(i),o}))});function lh(){return no(this)}function hh(){return new Mt(this.value(),this.__chain__)}function dh(){this.__values__===i&&(this.__values__=_o(this.value()));var t=this.__index__>=this.__values__.length,n=t?i:this.__values__[this.__index__++];return{done:t,value:n}}function ph(){return this}function gh(t){for(var n,e=this;e instanceof Ve;){var r=Zs(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 _h(){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:dr,args:[Wi],thisArg:i}),new Mt(n,this.__chain__)}return this.thru(Wi)}function vh(){return vs(this.__wrapped__,this.__actions__)}var wh=ur(function(t,n,e){Y.call(t,e)?++t[e]:an(t,e,1)});function yh(t,n,e){var r=U(t)?Tu:fc;return e&&yt(t,n,e)&&(n=i),r(t,L(n,3))}function mh(t,n){var e=U(t)?vn:ts;return e(t,L(n,3))}var xh=Is(Ys),Sh=Is(Xs);function Ah(t,n){return dt(pr(t,n),1)}function bh(t,n){return dt(pr(t,n),rn)}function Ch(t,n,e){return e=e===i?1:B(e),dt(pr(t,n),e)}function eo(t,n){var e=U(t)?Ut:xn;return e(t,L(n,3))}function ro(t,n){var e=U(t)?ka:ju;return e(t,L(n,3))}var Ph=ur(function(t,n,e){Y.call(t,e)?t[e].push(n):an(t,e,[n])});function Rh(t,n,e,r){t=At(t)?t:ne(t),e=e&&!r?B(e):0;var u=t.length;return e<0&&(e=at(u+e,0)),yr(t)?e<=u&&t.indexOf(n,e)>-1:!!u&&kn(t,n,e)>-1}var Ih=K(function(t,n,e){var r=-1,u=typeof n=="function",o=At(t)?g(t.length):[];return xn(t,function(a){o[++r]=u?It(n,a,e):ve(a,n,e)}),o}),Eh=ur(function(t,n,e){an(t,e,n)});function pr(t,n){var e=U(t)?nt:ss;return e(t,L(n,3))}function Th(t,n,e,r){return t==null?[]:(U(n)||(n=n==null?[]:[n]),e=r?i:e,U(e)||(e=e==null?[]:[e]),cs(t,n,e))}var Lh=ur(function(t,n,e){t[e?0:1].push(n)},function(){return[[],[]]});function Oh(t,n,e){var r=U(t)?Gr:Du,u=arguments.length<3;return r(t,L(n,4),e,u,xn)}function Wh(t,n,e){var r=U(t)?za:Du,u=arguments.length<3;return r(t,L(n,4),e,u,ju)}function Dh(t,n){var e=U(t)?vn:ts;return e(t,vr(L(n,3)))}function Fh(t){var n=U(t)?Yu:Rc;return n(t)}function Nh(t,n,e){(e?yt(t,n,e):n===i)?n=1:n=B(n);var r=U(t)?ic:Ic;return r(t,n)}function Uh(t){var n=U(t)?uc:Tc;return n(t)}function Bh(t){if(t==null)return 0;if(At(t))return yr(t)?Hn(t):t.length;var n=gt(t);return n==Gt||n==Jt?t.size:li(t).length}function Mh(t,n,e){var r=U(t)?Jr:Lc;return e&&yt(t,n,e)&&(n=i),r(t,L(n,3))}var $h=K(function(t,n){if(t==null)return[];var e=n.length;return e>1&&yt(t,n[0],n[1])?n=[]:e>2&&yt(n[0],n[1],n[2])&&(n=[n[0]]),cs(t,dt(n,1),[])}),gr=mf||function(){return ht.Date.now()};function Kh(t,n){if(typeof n!="function")throw new Bt(S);return t=B(t),function(){if(--t<1)return n.apply(this,arguments)}}function io(t,n,e){return n=e?i:n,n=t&&n==null?t.length:n,fn(t,xt,i,i,i,i,n)}function uo(t,n){var e;if(typeof n!="function")throw new Bt(S);return t=B(t),function(){return--t>0&&(e=n.apply(this,arguments)),t<=1&&(n=i),e}}var Fi=K(function(t,n,e){var r=_t;if(e.length){var u=yn(e,jn(Fi));r|=zt}return fn(t,r,n,e,u)}),so=K(function(t,n,e){var r=_t|Pt;if(e.length){var u=yn(e,jn(so));r|=zt}return fn(n,r,t,e,u)});function oo(t,n,e){n=e?i:n;var r=fn(t,st,i,i,i,i,i,n);return r.placeholder=oo.placeholder,r}function ao(t,n,e){n=e?i:n;var r=fn(t,Pn,i,i,i,i,i,n);return r.placeholder=ao.placeholder,r}function fo(t,n,e){var r,u,o,a,c,d,y=0,m=!1,x=!1,A=!0;if(typeof t!="function")throw new Bt(S);n=kt(n)||0,et(e)&&(m=!!e.leading,x="maxWait"in e,o=x?at(kt(e.maxWait)||0,n):o,A="trailing"in e?!!e.trailing:A);function R(ut){var Qt=r,pn=u;return r=u=i,y=ut,a=t.apply(pn,Qt),a}function O(ut){return y=ut,c=Se(k,n),m?R(ut):a}function $(ut){var Qt=ut-d,pn=ut-y,Eo=n-Qt;return x?pt(Eo,o-pn):Eo}function W(ut){var Qt=ut-d,pn=ut-y;return d===i||Qt>=n||Qt<0||x&&pn>=o}function k(){var ut=gr();if(W(ut))return H(ut);c=Se(k,$(ut))}function H(ut){return c=i,A&&r?R(ut):(r=u=i,a)}function Ot(){c!==i&&ys(c),y=0,r=d=u=c=i}function mt(){return c===i?a:H(gr())}function Wt(){var ut=gr(),Qt=W(ut);if(r=arguments,u=this,d=ut,Qt){if(c===i)return O(d);if(x)return ys(c),c=Se(k,n),R(d)}return c===i&&(c=Se(k,n)),a}return Wt.cancel=Ot,Wt.flush=mt,Wt}var qh=K(function(t,n){return Vu(t,1,n)}),kh=K(function(t,n,e){return Vu(t,kt(n)||0,e)});function zh(t){return fn(t,Bn)}function _r(t,n){if(typeof t!="function"||n!=null&&typeof n!="function")throw new Bt(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(_r.Cache||on),e}_r.Cache=on;function vr(t){if(typeof t!="function")throw new Bt(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 Hh(t){return uo(2,t)}var Gh=Oc(function(t,n){n=n.length==1&&U(n[0])?nt(n[0],Et(L())):nt(dt(n,1),Et(L()));var e=n.length;return K(function(r){for(var u=-1,o=pt(r.length,e);++u<o;)r[u]=n[u].call(this,r[u]);return It(t,this,r)})}),Ni=K(function(t,n){var e=yn(n,jn(Ni));return fn(t,zt,i,n,e)}),co=K(function(t,n){var e=yn(n,jn(co));return fn(t,gn,i,n,e)}),Jh=cn(function(t,n){return fn(t,Dt,i,i,i,n)});function Zh(t,n){if(typeof t!="function")throw new Bt(S);return n=n===i?n:B(n),K(t,n)}function Yh(t,n){if(typeof t!="function")throw new Bt(S);return n=n==null?0:at(B(n),0),K(function(e){var r=e[n],u=bn(e,0,n);return r&&wn(u,r),It(t,this,u)})}function Xh(t,n,e){var r=!0,u=!0;if(typeof t!="function")throw new Bt(S);return et(e)&&(r="leading"in e?!!e.leading:r,u="trailing"in e?!!e.trailing:u),fo(t,n,{leading:r,maxWait:n,trailing:u})}function Qh(t){return io(t,1)}function Vh(t,n){return Ni(mi(n),t)}function jh(){if(!arguments.length)return[];var t=arguments[0];return U(t)?t:[t]}function td(t){return $t(t,F)}function nd(t,n){return n=typeof n=="function"?n:i,$t(t,F,n)}function ed(t){return $t(t,P|F)}function rd(t,n){return n=typeof n=="function"?n:i,$t(t,P|F,n)}function id(t,n){return n==null||Qu(t,n,lt(n))}function Xt(t,n){return t===n||t!==t&&n!==n}var ud=fr(ai),sd=fr(function(t,n){return t>=n}),Nn=rs(function(){return arguments}())?rs:function(t){return rt(t)&&Y.call(t,"callee")&&!ku.call(t,"callee")},U=g.isArray,od=bu?Et(bu):gc;function At(t){return t!=null&&wr(t.length)&&!hn(t)}function it(t){return rt(t)&&At(t)}function ad(t){return t===!0||t===!1||rt(t)&&wt(t)==_n}var Cn=Sf||Ji,fd=Cu?Et(Cu):_c;function cd(t){return rt(t)&&t.nodeType===1&&!Ae(t)}function ld(t){if(t==null)return!0;if(At(t)&&(U(t)||typeof t=="string"||typeof t.splice=="function"||Cn(t)||te(t)||Nn(t)))return!t.length;var n=gt(t);if(n==Gt||n==Jt)return!t.size;if(xe(t))return!li(t).length;for(var e in t)if(Y.call(t,e))return!1;return!0}function hd(t,n){return we(t,n)}function dd(t,n,e){e=typeof e=="function"?e:i;var r=e?e(t,n):i;return r===i?we(t,n,i,e):!!r}function Ui(t){if(!rt(t))return!1;var n=wt(t);return n==Te||n==Fo||typeof t.message=="string"&&typeof t.name=="string"&&!Ae(t)}function pd(t){return typeof t=="number"&&Hu(t)}function hn(t){if(!et(t))return!1;var n=wt(t);return n==Le||n==Vi||n==Rn||n==Uo}function lo(t){return typeof t=="number"&&t==B(t)}function wr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=jt}function et(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}function rt(t){return t!=null&&typeof t=="object"}var ho=Pu?Et(Pu):wc;function gd(t,n){return t===n||ci(t,n,Ri(n))}function _d(t,n,e){return e=typeof e=="function"?e:i,ci(t,n,Ri(n),e)}function vd(t){return po(t)&&t!=+t}function wd(t){if(nl(t))throw new N(v);return is(t)}function yd(t){return t===null}function md(t){return t==null}function po(t){return typeof t=="number"||rt(t)&&wt(t)==ie}function Ae(t){if(!rt(t)||wt(t)!=un)return!1;var n=He(t);if(n===null)return!0;var e=Y.call(n,"constructor")&&n.constructor;return typeof e=="function"&&e instanceof e&&Ke.call(e)==_f}var Bi=Ru?Et(Ru):yc;function xd(t){return lo(t)&&t>=-jt&&t<=jt}var go=Iu?Et(Iu):mc;function yr(t){return typeof t=="string"||!U(t)&&rt(t)&&wt(t)==se}function Lt(t){return typeof t=="symbol"||rt(t)&&wt(t)==Oe}var te=Eu?Et(Eu):xc;function Sd(t){return t===i}function Ad(t){return rt(t)&>(t)==oe}function bd(t){return rt(t)&&wt(t)==Mo}var Cd=fr(hi),Pd=fr(function(t,n){return t<=n});function _o(t){if(!t)return[];if(At(t))return yr(t)?Zt(t):St(t);if(ce&&t[ce])return rf(t[ce]());var n=gt(t),e=n==Gt?jr:n==Jt?Be:ne;return e(t)}function dn(t){if(!t)return t===0?t:0;if(t=kt(t),t===rn||t===-rn){var n=t<0?-1:1;return n*Cr}return t===t?t:0}function B(t){var n=dn(t),e=n%1;return n===n?e?n-e:n:0}function vo(t){return t?On(B(t),0,Ft):0}function kt(t){if(typeof t=="number")return t;if(Lt(t))return $n;if(et(t)){var n=typeof t.valueOf=="function"?t.valueOf():t;t=et(n)?n+"":n}if(typeof t!="string")return t===0?t:+t;t=Fu(t);var e=sa.test(t);return e||aa.test(t)?$a(t.slice(2),e?2:8):ua.test(t)?$n:+t}function wo(t){return nn(t,bt(t))}function Rd(t){return t?On(B(t),-jt,jt):t===0?t:0}function Z(t){return t==null?"":Tt(t)}var Id=Qn(function(t,n){if(xe(n)||At(n)){nn(n,lt(n),t);return}for(var e in n)Y.call(n,e)&&ge(t,e,n[e])}),yo=Qn(function(t,n){nn(n,bt(n),t)}),mr=Qn(function(t,n,e,r){nn(n,bt(n),t,r)}),Ed=Qn(function(t,n,e,r){nn(n,lt(n),t,r)}),Td=cn(ui);function Ld(t,n){var e=Xn(t);return n==null?e:Xu(e,n)}var Od=K(function(t,n){t=Q(t);var e=-1,r=n.length,u=r>2?n[2]:i;for(u&&yt(n[0],n[1],u)&&(r=1);++e<r;)for(var o=n[e],a=bt(o),c=-1,d=a.length;++c<d;){var y=a[c],m=t[y];(m===i||Xt(m,Jn[y])&&!Y.call(t,y))&&(t[y]=o[y])}return t}),Wd=K(function(t){return t.push(i,Fs),It(mo,i,t)});function Dd(t,n){return Lu(t,L(n,3),tn)}function Fd(t,n){return Lu(t,L(n,3),oi)}function Nd(t,n){return t==null?t:si(t,L(n,3),bt)}function Ud(t,n){return t==null?t:ns(t,L(n,3),bt)}function Bd(t,n){return t&&tn(t,L(n,3))}function Md(t,n){return t&&oi(t,L(n,3))}function $d(t){return t==null?[]:nr(t,lt(t))}function Kd(t){return t==null?[]:nr(t,bt(t))}function Mi(t,n,e){var r=t==null?i:Wn(t,n);return r===i?e:r}function qd(t,n){return t!=null&&Bs(t,n,lc)}function $i(t,n){return t!=null&&Bs(t,n,hc)}var kd=Ts(function(t,n,e){n!=null&&typeof n.toString!="function"&&(n=qe.call(n)),t[n]=e},qi(Ct)),zd=Ts(function(t,n,e){n!=null&&typeof n.toString!="function"&&(n=qe.call(n)),Y.call(t,n)?t[n].push(e):t[n]=[e]},L),Hd=K(ve);function lt(t){return At(t)?Zu(t):li(t)}function bt(t){return At(t)?Zu(t,!0):Sc(t)}function Gd(t,n){var e={};return n=L(n,3),tn(t,function(r,u,o){an(e,n(r,u,o),r)}),e}function Jd(t,n){var e={};return n=L(n,3),tn(t,function(r,u,o){an(e,u,n(r,u,o))}),e}var Zd=Qn(function(t,n,e){er(t,n,e)}),mo=Qn(function(t,n,e,r){er(t,n,e,r)}),Yd=cn(function(t,n){var e={};if(t==null)return e;var r=!1;n=nt(n,function(o){return o=An(o,t),r||(r=o.length>1),o}),nn(t,Ci(t),e),r&&(e=$t(e,P|T|F,kc));for(var u=n.length;u--;)vi(e,n[u]);return e});function Xd(t,n){return xo(t,vr(L(n)))}var Qd=cn(function(t,n){return t==null?{}:bc(t,n)});function xo(t,n){if(t==null)return{};var e=nt(Ci(t),function(r){return[r]});return n=L(n),ls(t,e,function(r,u){return n(r,u[0])})}function Vd(t,n,e){n=An(n,t);var r=-1,u=n.length;for(u||(u=1,t=i);++r<u;){var o=t==null?i:t[en(n[r])];o===i&&(r=u,o=e),t=hn(o)?o.call(t):o}return t}function jd(t,n,e){return t==null?t:ye(t,n,e)}function tp(t,n,e,r){return r=typeof r=="function"?r:i,t==null?t:ye(t,n,e,r)}var So=Ws(lt),Ao=Ws(bt);function np(t,n,e){var r=U(t),u=r||Cn(t)||te(t);if(n=L(n,4),e==null){var o=t&&t.constructor;u?e=r?new o:[]:et(t)?e=hn(o)?Xn(He(t)):{}:e={}}return(u?Ut:tn)(t,function(a,c,d){return n(e,a,c,d)}),e}function ep(t,n){return t==null?!0:vi(t,n)}function rp(t,n,e){return t==null?t:_s(t,n,mi(e))}function ip(t,n,e,r){return r=typeof r=="function"?r:i,t==null?t:_s(t,n,mi(e),r)}function ne(t){return t==null?[]:Vr(t,lt(t))}function up(t){return t==null?[]:Vr(t,bt(t))}function sp(t,n,e){return e===i&&(e=n,n=i),e!==i&&(e=kt(e),e=e===e?e:0),n!==i&&(n=kt(n),n=n===n?n:0),On(kt(t),n,e)}function op(t,n,e){return n=dn(n),e===i?(e=n,n=0):e=dn(e),t=kt(t),dc(t,n,e)}function ap(t,n,e){if(e&&typeof e!="boolean"&&yt(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=dn(t),n===i?(n=t,t=0):n=dn(n)),t>n){var r=t;t=n,n=r}if(e||t%1||n%1){var u=Gu();return pt(t+u*(n-t+Ma("1e-"+((u+"").length-1))),n)}return pi(t,n)}var fp=Vn(function(t,n,e){return n=n.toLowerCase(),t+(e?bo(n):n)});function bo(t){return Ki(Z(t).toLowerCase())}function Co(t){return t=Z(t),t&&t.replace(ca,Va).replace(Ea,"")}function cp(t,n,e){t=Z(t),n=Tt(n);var r=t.length;e=e===i?r:On(B(e),0,r);var u=e;return e-=n.length,e>=0&&t.slice(e,u)==n}function lp(t){return t=Z(t),t&&zo.test(t)?t.replace(nu,ja):t}function hp(t){return t=Z(t),t&&Xo.test(t)?t.replace(Nr,"\\$&"):t}var dp=Vn(function(t,n,e){return t+(e?"-":"")+n.toLowerCase()}),pp=Vn(function(t,n,e){return t+(e?" ":"")+n.toLowerCase()}),gp=Rs("toLowerCase");function _p(t,n,e){t=Z(t),n=B(n);var r=n?Hn(t):0;if(!n||r>=n)return t;var u=(n-r)/2;return ar(Ye(u),e)+t+ar(Ze(u),e)}function vp(t,n,e){t=Z(t),n=B(n);var r=n?Hn(t):0;return n&&r<n?t+ar(n-r,e):t}function wp(t,n,e){t=Z(t),n=B(n);var r=n?Hn(t):0;return n&&r<n?ar(n-r,e)+t:t}function yp(t,n,e){return e||n==null?n=0:n&&(n=+n),Pf(Z(t).replace(Ur,""),n||0)}function mp(t,n,e){return(e?yt(t,n,e):n===i)?n=1:n=B(n),gi(Z(t),n)}function xp(){var t=arguments,n=Z(t[0]);return t.length<3?n:n.replace(t[1],t[2])}var Sp=Vn(function(t,n,e){return t+(e?"_":"")+n.toLowerCase()});function Ap(t,n,e){return e&&typeof e!="number"&&yt(t,n,e)&&(n=e=i),e=e===i?Ft:e>>>0,e?(t=Z(t),t&&(typeof n=="string"||n!=null&&!Bi(n))&&(n=Tt(n),!n&&zn(t))?bn(Zt(t),0,e):t.split(n,e)):[]}var bp=Vn(function(t,n,e){return t+(e?" ":"")+Ki(n)});function Cp(t,n,e){return t=Z(t),e=e==null?0:On(B(e),0,t.length),n=Tt(n),t.slice(e,e+n.length)==n}function Pp(t,n,e){var r=s.templateSettings;e&&yt(t,n,e)&&(n=i),t=Z(t),n=mr({},n,r,Ds);var u=mr({},n.imports,r.imports,Ds),o=lt(u),a=Vr(u,o),c,d,y=0,m=n.interpolate||We,x="__p += '",A=ti((n.escape||We).source+"|"+m.source+"|"+(m===eu?ia:We).source+"|"+(n.evaluate||We).source+"|$","g"),R="//# sourceURL="+(Y.call(n,"sourceURL")?(n.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++Da+"]")+`
|
|
11
|
+
`;t.replace(A,function(W,k,H,Ot,mt,Wt){return H||(H=Ot),x+=t.slice(y,Wt).replace(la,tf),k&&(c=!0,x+=`' +
|
|
12
|
+
__e(`+k+`) +
|
|
13
|
+
'`),mt&&(d=!0,x+=`';
|
|
14
|
+
`+mt+`;
|
|
15
|
+
__p += '`),H&&(x+=`' +
|
|
16
|
+
((__t = (`+H+`)) == null ? '' : __t) +
|
|
17
|
+
'`),y=Wt+W.length,W}),x+=`';
|
|
18
|
+
`;var O=Y.call(n,"variable")&&n.variable;if(!O)x=`with (obj) {
|
|
19
|
+
`+x+`
|
|
32
20
|
}
|
|
33
|
-
`;else if(
|
|
34
|
-
`+(
|
|
35
|
-
`)+"var __t, __p = ''"+(
|
|
21
|
+
`;else if(ea.test(O))throw new N(E);x=(d?x.replace($o,""):x).replace(Ko,"$1").replace(qo,"$1;"),x="function("+(O||"obj")+`) {
|
|
22
|
+
`+(O?"":`obj || (obj = {});
|
|
23
|
+
`)+"var __t, __p = ''"+(c?", __e = _.escape":"")+(d?`, __j = Array.prototype.join;
|
|
36
24
|
function print() { __p += __j.call(arguments, '') }
|
|
37
25
|
`:`;
|
|
38
|
-
`)+
|
|
39
|
-
}`;var $=gu(function(){return Y(l,L+"return "+T).apply(r,d)});if($.source=T,hi($))throw $;return $}function l_(t){return V(t).toLowerCase()}function f_(t){return V(t).toUpperCase()}function d_(t,e,s){if(t=V(t),t&&(s||e===r))return Eo(t);if(!t||!(e=Ot(e)))return t;var o=Xt(t),u=Xt(e),l=To(o,u),d=Ao(o,u)+1;return Re(o,l,d).join("")}function p_(t,e,s){if(t=V(t),t&&(s||e===r))return t.slice(0,Io(t)+1);if(!t||!(e=Ot(e)))return t;var o=Xt(t),u=Ao(o,Xt(e))+1;return Re(o,0,u).join("")}function g_(t,e,s){if(t=V(t),t&&(s||e===r))return t.replace(hs,"");if(!t||!(e=Ot(e)))return t;var o=Xt(t),u=To(o,Xt(e));return Re(o,u).join("")}function __(t,e){var s=Nt,o=ht;if(nt(e)){var u="separator"in e?e.separator:u;s="length"in e?W(e.length):s,o="omission"in e?Ot(e.omission):o}t=V(t);var l=t.length;if(tn(t)){var d=Xt(t);l=d.length}if(s>=l)return t;var g=s-en(o);if(g<1)return o;var b=d?Re(d,0,g).join(""):t.slice(0,g);if(u===r)return b+o;if(d&&(g+=b.length-g),li(u)){if(t.slice(g).search(u)){var x,E=b;for(u.global||(u=Cs(u.source,V(Ji.exec(u))+"g")),u.lastIndex=0;x=u.exec(E);)var T=x.index;b=b.slice(0,T===r?g:T)}}else if(t.indexOf(Ot(u),g)!=g){var M=b.lastIndexOf(u);M>-1&&(b=b.slice(0,M))}return b+o}function b_(t){return t=V(t),t&&Cc.test(t)?t.replace(qi,Jh):t}var m_=cn(function(t,e,s){return t+(s?" ":"")+e.toUpperCase()}),pi=_a("toUpperCase");function pu(t,e,s){return t=V(t),e=s?r:e,e===r?Wh(t)?Yh(t):Ph(t):t.match(e)||[]}var gu=z(function(t,e){try{return Mt(t,r,e)}catch(s){return hi(s)?s:new N(s)}}),v_=_e(function(t,e){return Wt(e,function(s){s=ue(s),pe(t,s,ui(t[s],t))}),t});function w_(t){var e=t==null?0:t.length,s=B();return t=e?et(t,function(o){if(typeof o[1]!="function")throw new $t(p);return[s(o[0]),o[1]]}):[],z(function(o){for(var u=-1;++u<e;){var l=t[u];if(Mt(l[0],this,o))return Mt(l[1],this,o)}})}function y_(t){return Jl(zt(t,C))}function gi(t){return function(){return t}}function S_(t,e){return t==null||t!==t?e:t}var x_=ma(),E_=ma(!0);function Rt(t){return t}function _i(t){return Yo(typeof t=="function"?t:zt(t,C))}function T_(t){return Zo(zt(t,C))}function A_(t,e){return Xo(t,zt(e,C))}var C_=z(function(t,e){return function(s){return Bn(s,t,e)}}),I_=z(function(t,e){return function(s){return Bn(t,s,e)}});function bi(t,e,s){var o=gt(e),u=Er(e,o);s==null&&!(nt(e)&&(u.length||!o.length))&&(s=e,e=t,t=this,u=Er(e,gt(e)));var l=!(nt(s)&&"chain"in s)||!!s.chain,d=me(t);return Wt(u,function(g){var b=e[g];t[g]=b,d&&(t.prototype[g]=function(){var x=this.__chain__;if(l||x){var E=t(this.__wrapped__),T=E.__actions__=At(this.__actions__);return T.push({func:b,args:arguments,thisArg:t}),E.__chain__=x,E}return b.apply(t,xe([this.value()],arguments))})}),t}function R_(){return _t._===this&&(_t._=tl),this}function mi(){}function M_(t){return t=W(t),z(function(e){return Qo(e,t)})}var P_=Vs(et),O_=Vs(vo),L_=Vs(ws);function _u(t){return ni(t)?ys(ue(t)):cf(t)}function B_(t){return function(e){return t==null?r:$e(t,e)}}var k_=wa(),D_=wa(!0);function vi(){return[]}function wi(){return!1}function N_(){return{}}function F_(){return""}function U_(){return!0}function W_(t,e){if(t=W(t),t<1||t>ye)return[];var s=ie,o=mt(t,ie);e=B(e),t-=ie;for(var u=Es(o,e);++s<t;)e(s);return u}function $_(t){return F(t)?et(t,ue):Lt(t)?[t]:At(Da(V(t)))}function q_(t){var e=++Qh;return V(t)+e}var z_=Mr(function(t,e){return t+e},0),H_=Zs("ceil"),J_=Mr(function(t,e){return t/e},1),G_=Zs("floor");function K_(t){return t&&t.length?xr(t,Rt,ks):r}function Y_(t,e){return t&&t.length?xr(t,B(e,2),ks):r}function V_(t){return So(t,Rt)}function Z_(t,e){return So(t,B(e,2))}function X_(t){return t&&t.length?xr(t,Rt,Us):r}function Q_(t,e){return t&&t.length?xr(t,B(e,2),Us):r}var j_=Mr(function(t,e){return t*e},1),tb=Zs("round"),eb=Mr(function(t,e){return t-e},0);function nb(t){return t&&t.length?xs(t,Rt):0}function rb(t,e){return t&&t.length?xs(t,B(e,2)):0}return c.after=Tp,c.ary=Ka,c.assign=fg,c.assignIn=au,c.assignInWith=zr,c.assignWith=dg,c.at=pg,c.before=Ya,c.bind=ui,c.bindAll=v_,c.bindKey=Va,c.castArray=Np,c.chain=Ha,c.chunk=Gf,c.compact=Kf,c.concat=Yf,c.cond=w_,c.conforms=y_,c.constant=gi,c.countBy=np,c.create=gg,c.curry=Za,c.curryRight=Xa,c.debounce=Qa,c.defaults=_g,c.defaultsDeep=bg,c.defer=Ap,c.delay=Cp,c.difference=Vf,c.differenceBy=Zf,c.differenceWith=Xf,c.drop=Qf,c.dropRight=jf,c.dropRightWhile=td,c.dropWhile=ed,c.fill=nd,c.filter=sp,c.flatMap=ap,c.flatMapDeep=up,c.flatMapDepth=cp,c.flatten=Wa,c.flattenDeep=rd,c.flattenDepth=sd,c.flip=Ip,c.flow=x_,c.flowRight=E_,c.fromPairs=id,c.functions=Eg,c.functionsIn=Tg,c.groupBy=hp,c.initial=ad,c.intersection=ud,c.intersectionBy=cd,c.intersectionWith=hd,c.invert=Cg,c.invertBy=Ig,c.invokeMap=fp,c.iteratee=_i,c.keyBy=dp,c.keys=gt,c.keysIn=It,c.map=Nr,c.mapKeys=Mg,c.mapValues=Pg,c.matches=T_,c.matchesProperty=A_,c.memoize=Ur,c.merge=Og,c.mergeWith=uu,c.method=C_,c.methodOf=I_,c.mixin=bi,c.negate=Wr,c.nthArg=M_,c.omit=Lg,c.omitBy=Bg,c.once=Rp,c.orderBy=pp,c.over=P_,c.overArgs=Mp,c.overEvery=O_,c.overSome=L_,c.partial=ci,c.partialRight=ja,c.partition=gp,c.pick=kg,c.pickBy=cu,c.property=_u,c.propertyOf=B_,c.pull=pd,c.pullAll=qa,c.pullAllBy=gd,c.pullAllWith=_d,c.pullAt=bd,c.range=k_,c.rangeRight=D_,c.rearg=Pp,c.reject=mp,c.remove=md,c.rest=Op,c.reverse=oi,c.sampleSize=wp,c.set=Ng,c.setWith=Fg,c.shuffle=yp,c.slice=vd,c.sortBy=Ep,c.sortedUniq=Ad,c.sortedUniqBy=Cd,c.split=a_,c.spread=Lp,c.tail=Id,c.take=Rd,c.takeRight=Md,c.takeRightWhile=Pd,c.takeWhile=Od,c.tap=Kd,c.throttle=Bp,c.thru=Dr,c.toArray=su,c.toPairs=hu,c.toPairsIn=lu,c.toPath=$_,c.toPlainObject=ou,c.transform=Ug,c.unary=kp,c.union=Ld,c.unionBy=Bd,c.unionWith=kd,c.uniq=Dd,c.uniqBy=Nd,c.uniqWith=Fd,c.unset=Wg,c.unzip=ai,c.unzipWith=za,c.update=$g,c.updateWith=qg,c.values=fn,c.valuesIn=zg,c.without=Ud,c.words=pu,c.wrap=Dp,c.xor=Wd,c.xorBy=$d,c.xorWith=qd,c.zip=zd,c.zipObject=Hd,c.zipObjectDeep=Jd,c.zipWith=Gd,c.entries=hu,c.entriesIn=lu,c.extend=au,c.extendWith=zr,bi(c,c),c.add=z_,c.attempt=gu,c.camelCase=Kg,c.capitalize=fu,c.ceil=H_,c.clamp=Hg,c.clone=Fp,c.cloneDeep=Wp,c.cloneDeepWith=$p,c.cloneWith=Up,c.conformsTo=qp,c.deburr=du,c.defaultTo=S_,c.divide=J_,c.endsWith=Yg,c.eq=jt,c.escape=Vg,c.escapeRegExp=Zg,c.every=rp,c.find=ip,c.findIndex=Fa,c.findKey=mg,c.findLast=op,c.findLastIndex=Ua,c.findLastKey=vg,c.floor=G_,c.forEach=Ja,c.forEachRight=Ga,c.forIn=wg,c.forInRight=yg,c.forOwn=Sg,c.forOwnRight=xg,c.get=fi,c.gt=zp,c.gte=Hp,c.has=Ag,c.hasIn=di,c.head=$a,c.identity=Rt,c.includes=lp,c.indexOf=od,c.inRange=Jg,c.invoke=Rg,c.isArguments=He,c.isArray=F,c.isArrayBuffer=Jp,c.isArrayLike=Ct,c.isArrayLikeObject=ot,c.isBoolean=Gp,c.isBuffer=Me,c.isDate=Kp,c.isElement=Yp,c.isEmpty=Vp,c.isEqual=Zp,c.isEqualWith=Xp,c.isError=hi,c.isFinite=Qp,c.isFunction=me,c.isInteger=tu,c.isLength=$r,c.isMap=eu,c.isMatch=jp,c.isMatchWith=tg,c.isNaN=eg,c.isNative=ng,c.isNil=sg,c.isNull=rg,c.isNumber=nu,c.isObject=nt,c.isObjectLike=it,c.isPlainObject=Wn,c.isRegExp=li,c.isSafeInteger=ig,c.isSet=ru,c.isString=qr,c.isSymbol=Lt,c.isTypedArray=ln,c.isUndefined=og,c.isWeakMap=ag,c.isWeakSet=ug,c.join=ld,c.kebabCase=Xg,c.last=Jt,c.lastIndexOf=fd,c.lowerCase=Qg,c.lowerFirst=jg,c.lt=cg,c.lte=hg,c.max=K_,c.maxBy=Y_,c.mean=V_,c.meanBy=Z_,c.min=X_,c.minBy=Q_,c.stubArray=vi,c.stubFalse=wi,c.stubObject=N_,c.stubString=F_,c.stubTrue=U_,c.multiply=j_,c.nth=dd,c.noConflict=R_,c.noop=mi,c.now=Fr,c.pad=t_,c.padEnd=e_,c.padStart=n_,c.parseInt=r_,c.random=Gg,c.reduce=_p,c.reduceRight=bp,c.repeat=s_,c.replace=i_,c.result=Dg,c.round=tb,c.runInContext=_,c.sample=vp,c.size=Sp,c.snakeCase=o_,c.some=xp,c.sortedIndex=wd,c.sortedIndexBy=yd,c.sortedIndexOf=Sd,c.sortedLastIndex=xd,c.sortedLastIndexBy=Ed,c.sortedLastIndexOf=Td,c.startCase=u_,c.startsWith=c_,c.subtract=eb,c.sum=nb,c.sumBy=rb,c.template=h_,c.times=W_,c.toFinite=ve,c.toInteger=W,c.toLength=iu,c.toLower=l_,c.toNumber=Gt,c.toSafeInteger=lg,c.toString=V,c.toUpper=f_,c.trim=d_,c.trimEnd=p_,c.trimStart=g_,c.truncate=__,c.unescape=b_,c.uniqueId=q_,c.upperCase=m_,c.upperFirst=pi,c.each=Ja,c.eachRight=Ga,c.first=$a,bi(c,function(){var t={};return oe(c,function(e,s){Z.call(c.prototype,s)||(t[s]=e)}),t}(),{chain:!1}),c.VERSION=a,Wt(["bind","bindKey","curry","curryRight","partial","partialRight"],function(t){c[t].placeholder=c}),Wt(["drop","take"],function(t,e){J.prototype[t]=function(s){s=s===r?1:ft(W(s),0);var o=this.__filtered__&&!e?new J(this):this.clone();return o.__filtered__?o.__takeCount__=mt(s,o.__takeCount__):o.__views__.push({size:mt(s,ie),type:t+(o.__dir__<0?"Right":"")}),o},J.prototype[t+"Right"]=function(s){return this.reverse()[t](s).reverse()}}),Wt(["filter","map","takeWhile"],function(t,e){var s=e+1,o=s==wt||s==dc;J.prototype[t]=function(u){var l=this.clone();return l.__iteratees__.push({iteratee:B(u,3),type:s}),l.__filtered__=l.__filtered__||o,l}}),Wt(["head","last"],function(t,e){var s="take"+(e?"Right":"");J.prototype[t]=function(){return this[s](1).value()[0]}}),Wt(["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(Rt)},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 Bn(s,t,e)})}),J.prototype.reject=function(t){return this.filter(Wr(B(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(ie)},oe(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,x=g[0],E=b||F(d),T=function(H){var G=u.apply(c,xe([H],g));return o&&M?G[0]:G};E&&s&&typeof x=="function"&&x.length!=1&&(b=E=!1);var M=this.__chain__,L=!!this.__actions__.length,k=l&&!M,$=b&&!L;if(!l&&E){d=$?d:new J(this);var D=t.apply(d,g);return D.__actions__.push({func:Dr,args:[T],thisArg:r}),new qt(D,M)}return k&&$?t.apply(this,g):(D=this.thru(T),k?o?D.value()[0]:D.value():D)})}),Wt(["pop","push","shift","sort","splice","unshift"],function(t){var e=ur[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(F(l)?l:[],u)}return this[s](function(d){return e.apply(F(d)?d:[],u)})}}),oe(J.prototype,function(t,e){var s=c[e];if(s){var o=s.name+"";Z.call(on,o)||(on[o]=[]),on[o].push({name:e,func:s})}}),on[Rr(r,ut).name]=[{name:"wrapper",func:r}],J.prototype.clone=_l,J.prototype.reverse=bl,J.prototype.value=ml,c.prototype.at=Yd,c.prototype.chain=Vd,c.prototype.commit=Zd,c.prototype.next=Xd,c.prototype.plant=jd,c.prototype.reverse=tp,c.prototype.toJSON=c.prototype.valueOf=c.prototype.value=ep,c.prototype.first=c.prototype.head,Cn&&(c.prototype[Cn]=Qd),c},nn=Vh();De?((De.exports=nn)._=nn,_s._=nn):_t._=nn}).call($n)})(Zr,Zr.exports);var lv=Zr.exports;const fv=Lu(lv);class dv{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 pv{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=fv.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 uc extends Yn{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 dv(this.config),h=new pv(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 Vn=U.createContext(void 0);function gv(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 _v(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 bv({dev:n=!1,baseUrl:i,protocols:r,logger:a,children:h,session:f="new",transformMessages:p,...m}){const[w,I]=U.useState(!1),[P,C]=U.useState([]),[A,R]=U.useState(f),[K,Tt]=U.useState(new Map),pt=U.useRef(!1),ut=U.useMemo(()=>{if(Array.isArray(r))return r;if(typeof r=="object"&&r!==null){const q=n?"localhost:8000":i||"persona.applica.guru/api",ct=n?"http":"https",X=n?"ws":"wss";let Nt=Object.keys(r).map(ht=>{switch(ht){case"rest":const Ft=r[ht];return Ft===!0?new Mi({apiUrl:`${ct}://${q}`,apiKey:m.apiKey,agentId:m.agentId,logger:a}):typeof Ft=="object"&&Ft!==null?new Mi(Ft):null;case"webrtc":const st=r[ht];return st===!0?new Oi({webrtcUrl:`${X}://${q}/webrtc`,apiKey:m.apiKey,agentId:m.agentId,logger:a}):typeof st=="object"&&st!==null?new Oi(st):null;case"websocket":const wt=r[ht];return wt===!0?new Pi({webSocketUrl:`${X}://${q}/websocket`,apiKey:m.apiKey,agentId:m.agentId,logger:a}):typeof wt=="object"&&wt!==null?new Pi(wt):null;default:throw new Error(`Unknown protocol: ${ht}`)}}).filter(ht=>ht!==null);return m.tools&&Nt.push(new uc({apiUrl:`${ct}://${q}`,apiKey:m.apiKey,agentId:m.agentId,tools:m.tools,logger:a})),Nt}throw new Error("Invalid protocols configuration")},[]);U.useEffect(()=>{pt.current||(pt.current=!0,a==null||a.debug("Initializing protocols: ",ut.map(q=>q.getName())),ut.forEach(q=>{q.setSession(A),q.clearListeners(),q.addStatusChangeListener(ct=>{a==null||a.debug(`${q.getName()} has notified new status: ${ct}`),K.set(q.getName(),ct),ct==="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(X=>X.schema)}}})),Tt(new Map(K))}),q.addPacketListener(ct=>{if(ct.type==="message"){const X=ct.payload;(X==null?void 0:X.finishReason)==="stop"&&!(X!=null&&X.functionResponse)&&!(X!=null&&X.thought)&&I(!1),X.thought&&(X.type="reasoning"),C(Nt=>{const ht=Ou([...Nt,{...X,protocol:q.getName()}]);return p?p(ht):ht})}else if(ct.type==="reasoning"){const Nt={type:"reasoning",text:ct.payload.thought,role:"assistant",finishReason:"stop"};C(ht=>{const Ft=Ou([...ht,{...Nt,protocol:q.getName()}]);return p?p(Ft):Ft})}else ct.type==="transaction"&&ut.filter(X=>X!==q).forEach(X=>X.onTransaction(ct.payload))}),q.autostart&&q.status==="disconnected"&&(a==null||a.debug(`Connecting to protocol: ${q.getName()}`),q.connect(A),I(!1))}))},[A,ut,a,K,p]);const Zn=async q=>{var Ft;if(((Ft=q.content[0])==null?void 0:Ft.type)!=="text")throw new Error("Only text messages are supported");if(!ut.some(st=>st.getName()!=="transaction"&&st.status==="connected")){C(st=>{const wt=[...st,{role:"assistant",type:"text",text:"No protocol is connected."}];return p?p(wt):wt});return}const X=q.content[0].text;C(st=>{const wt=[...st,{role:"user",type:"text",text:X}];return p?p(wt):wt}),I(!0);const Nt=ut.sort((st,wt)=>wt.getPriority()-st.getPriority()).find(st=>st.status==="connected"),ht=[];if(q.attachments)for(const st of q.attachments)st.contentType.startsWith("image/")&&st.file&&ht.push({role:"user",image:{contentType:st.contentType,content:await gv(st.file)},text:"",type:"text"});q.content&&ht.push({role:"user",text:q.content[0].text,type:"text"}),a==null||a.debug("Sending message:",ht),await(Nt==null?void 0:Nt.sendPacket({type:"request",payload:ht}))},Kt=U.useCallback(()=>(I(!1),C([]),R("new"),Promise.resolve()),[]),Le=U.useCallback(()=>Promise.resolve(),[]),Yt=U.useCallback(()=>P,[P]),Be=rm({isRunning:w,messages:P,convertMessage:cv,onNew:Zn,onCancel:Kt,onReload:Le,adapters:{attachments:new Jb([new zb])}});return Pe.jsx(Vn.Provider,{value:{protocols:ut,protocolsStatus:K,getMessages:Yt},children:Pe.jsx(ov,{runtime:Be,children:h})})}function mv({children:n,...i}){return Pe.jsx(bv,{...i,children:n})}function vv(){const n=U.useContext(Vn);if(!n)throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");return n}function cc(n){const i=U.useContext(Vn);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 wv(){const n=U.useContext(Vn);if(!n)throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");return _v(n.protocols)}function yv(){return cc("webrtc")}function Sv(){const n=U.useContext(Vn);if(!n)throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");return n.getMessages()}class xv{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 Ye(n,i,r){return{type:n,description:i,...r}}function hc(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 jr(n){return{schema:hc(n),implementation:n.implementation}}function lc(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 jr(p)}const Ev=lc("sum","Sum two numbers",function(i,r){return{result:i+r}},{a:Ye("number","First number to sum",{required:!0}),b:Ye("number","Second number to sum",{required:!0})},{result:Ye("number","Sum of two numbers")}),Tv=jr({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:Ye("number","First number to sum"),b:Ye("number","Seconth number to sum")},output:{result:Ye("number","Sum of two numbers")},implementation:function(i,r){return{result:i+r}}});function Av(n){const i=[],r={};return n.forEach(a=>{const{schema:h,implementation:f}=jr(a);i.push(h),r[a.name]=f}),{schemas:i,implementations:r}}function Cv(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}exports.PersonaConsoleLogger=xv;exports.PersonaProtocolBase=Yn;exports.PersonaRESTProtocol=Mi;exports.PersonaRuntimeProvider=mv;exports.PersonaTransactionProtocol=uc;exports.PersonaWebRTCProtocol=Oi;exports.PersonaWebSocketProtocol=Pi;exports.createParameter=Ye;exports.createTool=jr;exports.createToolFromFunction=lc;exports.createToolRegistry=Av;exports.generateToolSchema=hc;exports.navigateToToolExample=Tv;exports.sumTool=Ev;exports.usePersonaRuntime=vv;exports.usePersonaRuntimeEndpoint=wv;exports.usePersonaRuntimeMessages=Sv;exports.usePersonaRuntimeProtocol=cc;exports.usePersonaRuntimeWebRTCProtocol=yv;exports.validateToolParameters=Cv;
|
|
26
|
+
`)+x+`return __p
|
|
27
|
+
}`;var $=Ro(function(){return G(o,R+"return "+x).apply(i,a)});if($.source=x,Ui($))throw $;return $}function Rp(t){return Z(t).toLowerCase()}function Ip(t){return Z(t).toUpperCase()}function Ep(t,n,e){if(t=Z(t),t&&(e||n===i))return Fu(t);if(!t||!(n=Tt(n)))return t;var r=Zt(t),u=Zt(n),o=Nu(r,u),a=Uu(r,u)+1;return bn(r,o,a).join("")}function Tp(t,n,e){if(t=Z(t),t&&(e||n===i))return t.slice(0,Mu(t)+1);if(!t||!(n=Tt(n)))return t;var r=Zt(t),u=Uu(r,Zt(n))+1;return bn(r,0,u).join("")}function Lp(t,n,e){if(t=Z(t),t&&(e||n===i))return t.replace(Ur,"");if(!t||!(n=Tt(n)))return t;var r=Zt(t),u=Nu(r,Zt(n));return bn(r,u).join("")}function Op(t,n){var e=Re,r=Rt;if(et(n)){var u="separator"in n?n.separator:u;e="length"in n?B(n.length):e,r="omission"in n?Tt(n.omission):r}t=Z(t);var o=t.length;if(zn(t)){var a=Zt(t);o=a.length}if(e>=o)return t;var c=e-Hn(r);if(c<1)return r;var d=a?bn(a,0,c).join(""):t.slice(0,c);if(u===i)return d+r;if(a&&(c+=d.length-c),Bi(u)){if(t.slice(c).search(u)){var y,m=d;for(u.global||(u=ti(u.source,Z(ru.exec(u))+"g")),u.lastIndex=0;y=u.exec(m);)var x=y.index;d=d.slice(0,x===i?c:x)}}else if(t.indexOf(Tt(u),c)!=c){var A=d.lastIndexOf(u);A>-1&&(d=d.slice(0,A))}return d+r}function Wp(t){return t=Z(t),t&&ko.test(t)?t.replace(tu,af):t}var Dp=Vn(function(t,n,e){return t+(e?" ":"")+n.toUpperCase()}),Ki=Rs("toUpperCase");function Po(t,n,e){return t=Z(t),n=e?i:n,n===i?ef(t)?lf(t):Ja(t):t.match(n)||[]}var Ro=K(function(t,n){try{return It(t,i,n)}catch(e){return Ui(e)?e:new N(e)}}),Fp=cn(function(t,n){return Ut(n,function(e){e=en(e),an(t,e,Fi(t[e],t))}),t});function Np(t){var n=t==null?0:t.length,e=L();return t=n?nt(t,function(r){if(typeof r[1]!="function")throw new Bt(S);return[e(r[0]),r[1]]}):[],K(function(r){for(var u=-1;++u<n;){var o=t[u];if(It(o[0],this,r))return It(o[1],this,r)}})}function Up(t){return ac($t(t,P))}function qi(t){return function(){return t}}function Bp(t,n){return t==null||t!==t?n:t}var Mp=Es(),$p=Es(!0);function Ct(t){return t}function ki(t){return us(typeof t=="function"?t:$t(t,P))}function Kp(t){return os($t(t,P))}function qp(t,n){return as(t,$t(n,P))}var kp=K(function(t,n){return function(e){return ve(e,t,n)}}),zp=K(function(t,n){return function(e){return ve(t,e,n)}});function zi(t,n,e){var r=lt(n),u=nr(n,r);e==null&&!(et(n)&&(u.length||!r.length))&&(e=n,n=t,t=this,u=nr(n,lt(n)));var o=!(et(e)&&"chain"in e)||!!e.chain,a=hn(t);return Ut(u,function(c){var d=n[c];t[c]=d,a&&(t.prototype[c]=function(){var y=this.__chain__;if(o||y){var m=t(this.__wrapped__),x=m.__actions__=St(this.__actions__);return x.push({func:d,args:arguments,thisArg:t}),m.__chain__=y,m}return d.apply(t,wn([this.value()],arguments))})}),t}function Hp(){return ht._===this&&(ht._=vf),this}function Hi(){}function Gp(t){return t=B(t),K(function(n){return fs(n,t)})}var Jp=Si(nt),Zp=Si(Tu),Yp=Si(Jr);function Io(t){return Ei(t)?Zr(en(t)):Cc(t)}function Xp(t){return function(n){return t==null?i:Wn(t,n)}}var Qp=Ls(),Vp=Ls(!0);function Gi(){return[]}function Ji(){return!1}function jp(){return{}}function tg(){return""}function ng(){return!0}function eg(t,n){if(t=B(t),t<1||t>jt)return[];var e=Ft,r=pt(t,Ft);n=L(n),t-=Ft;for(var u=Qr(r,n);++e<t;)n(e);return u}function rg(t){return U(t)?nt(t,en):Lt(t)?[t]:St(Js(Z(t)))}function ig(t){var n=++gf;return Z(t)+n}var ug=or(function(t,n){return t+n},0),sg=Ai("ceil"),og=or(function(t,n){return t/n},1),ag=Ai("floor");function fg(t){return t&&t.length?tr(t,Ct,ai):i}function cg(t,n){return t&&t.length?tr(t,L(n,2),ai):i}function lg(t){return Wu(t,Ct)}function hg(t,n){return Wu(t,L(n,2))}function dg(t){return t&&t.length?tr(t,Ct,hi):i}function pg(t,n){return t&&t.length?tr(t,L(n,2),hi):i}var gg=or(function(t,n){return t*n},1),_g=Ai("round"),vg=or(function(t,n){return t-n},0);function wg(t){return t&&t.length?Xr(t,Ct):0}function yg(t,n){return t&&t.length?Xr(t,L(n,2)):0}return s.after=Kh,s.ary=io,s.assign=Id,s.assignIn=yo,s.assignInWith=mr,s.assignWith=Ed,s.at=Td,s.before=uo,s.bind=Fi,s.bindAll=Fp,s.bindKey=so,s.castArray=jh,s.chain=no,s.chunk=al,s.compact=fl,s.concat=cl,s.cond=Np,s.conforms=Up,s.constant=qi,s.countBy=wh,s.create=Ld,s.curry=oo,s.curryRight=ao,s.debounce=fo,s.defaults=Od,s.defaultsDeep=Wd,s.defer=qh,s.delay=kh,s.difference=ll,s.differenceBy=hl,s.differenceWith=dl,s.drop=pl,s.dropRight=gl,s.dropRightWhile=_l,s.dropWhile=vl,s.fill=wl,s.filter=mh,s.flatMap=Ah,s.flatMapDeep=bh,s.flatMapDepth=Ch,s.flatten=Qs,s.flattenDeep=yl,s.flattenDepth=ml,s.flip=zh,s.flow=Mp,s.flowRight=$p,s.fromPairs=xl,s.functions=$d,s.functionsIn=Kd,s.groupBy=Ph,s.initial=Al,s.intersection=bl,s.intersectionBy=Cl,s.intersectionWith=Pl,s.invert=kd,s.invertBy=zd,s.invokeMap=Ih,s.iteratee=ki,s.keyBy=Eh,s.keys=lt,s.keysIn=bt,s.map=pr,s.mapKeys=Gd,s.mapValues=Jd,s.matches=Kp,s.matchesProperty=qp,s.memoize=_r,s.merge=Zd,s.mergeWith=mo,s.method=kp,s.methodOf=zp,s.mixin=zi,s.negate=vr,s.nthArg=Gp,s.omit=Yd,s.omitBy=Xd,s.once=Hh,s.orderBy=Th,s.over=Jp,s.overArgs=Gh,s.overEvery=Zp,s.overSome=Yp,s.partial=Ni,s.partialRight=co,s.partition=Lh,s.pick=Qd,s.pickBy=xo,s.property=Io,s.propertyOf=Xp,s.pull=Tl,s.pullAll=js,s.pullAllBy=Ll,s.pullAllWith=Ol,s.pullAt=Wl,s.range=Qp,s.rangeRight=Vp,s.rearg=Jh,s.reject=Dh,s.remove=Dl,s.rest=Zh,s.reverse=Wi,s.sampleSize=Nh,s.set=jd,s.setWith=tp,s.shuffle=Uh,s.slice=Fl,s.sortBy=$h,s.sortedUniq=ql,s.sortedUniqBy=kl,s.split=Ap,s.spread=Yh,s.tail=zl,s.take=Hl,s.takeRight=Gl,s.takeRightWhile=Jl,s.takeWhile=Zl,s.tap=fh,s.throttle=Xh,s.thru=dr,s.toArray=_o,s.toPairs=So,s.toPairsIn=Ao,s.toPath=rg,s.toPlainObject=wo,s.transform=np,s.unary=Qh,s.union=Yl,s.unionBy=Xl,s.unionWith=Ql,s.uniq=Vl,s.uniqBy=jl,s.uniqWith=th,s.unset=ep,s.unzip=Di,s.unzipWith=to,s.update=rp,s.updateWith=ip,s.values=ne,s.valuesIn=up,s.without=nh,s.words=Po,s.wrap=Vh,s.xor=eh,s.xorBy=rh,s.xorWith=ih,s.zip=uh,s.zipObject=sh,s.zipObjectDeep=oh,s.zipWith=ah,s.entries=So,s.entriesIn=Ao,s.extend=yo,s.extendWith=mr,zi(s,s),s.add=ug,s.attempt=Ro,s.camelCase=fp,s.capitalize=bo,s.ceil=sg,s.clamp=sp,s.clone=td,s.cloneDeep=ed,s.cloneDeepWith=rd,s.cloneWith=nd,s.conformsTo=id,s.deburr=Co,s.defaultTo=Bp,s.divide=og,s.endsWith=cp,s.eq=Xt,s.escape=lp,s.escapeRegExp=hp,s.every=yh,s.find=xh,s.findIndex=Ys,s.findKey=Dd,s.findLast=Sh,s.findLastIndex=Xs,s.findLastKey=Fd,s.floor=ag,s.forEach=eo,s.forEachRight=ro,s.forIn=Nd,s.forInRight=Ud,s.forOwn=Bd,s.forOwnRight=Md,s.get=Mi,s.gt=ud,s.gte=sd,s.has=qd,s.hasIn=$i,s.head=Vs,s.identity=Ct,s.includes=Rh,s.indexOf=Sl,s.inRange=op,s.invoke=Hd,s.isArguments=Nn,s.isArray=U,s.isArrayBuffer=od,s.isArrayLike=At,s.isArrayLikeObject=it,s.isBoolean=ad,s.isBuffer=Cn,s.isDate=fd,s.isElement=cd,s.isEmpty=ld,s.isEqual=hd,s.isEqualWith=dd,s.isError=Ui,s.isFinite=pd,s.isFunction=hn,s.isInteger=lo,s.isLength=wr,s.isMap=ho,s.isMatch=gd,s.isMatchWith=_d,s.isNaN=vd,s.isNative=wd,s.isNil=md,s.isNull=yd,s.isNumber=po,s.isObject=et,s.isObjectLike=rt,s.isPlainObject=Ae,s.isRegExp=Bi,s.isSafeInteger=xd,s.isSet=go,s.isString=yr,s.isSymbol=Lt,s.isTypedArray=te,s.isUndefined=Sd,s.isWeakMap=Ad,s.isWeakSet=bd,s.join=Rl,s.kebabCase=dp,s.last=qt,s.lastIndexOf=Il,s.lowerCase=pp,s.lowerFirst=gp,s.lt=Cd,s.lte=Pd,s.max=fg,s.maxBy=cg,s.mean=lg,s.meanBy=hg,s.min=dg,s.minBy=pg,s.stubArray=Gi,s.stubFalse=Ji,s.stubObject=jp,s.stubString=tg,s.stubTrue=ng,s.multiply=gg,s.nth=El,s.noConflict=Hp,s.noop=Hi,s.now=gr,s.pad=_p,s.padEnd=vp,s.padStart=wp,s.parseInt=yp,s.random=ap,s.reduce=Oh,s.reduceRight=Wh,s.repeat=mp,s.replace=xp,s.result=Vd,s.round=_g,s.runInContext=l,s.sample=Fh,s.size=Bh,s.snakeCase=Sp,s.some=Mh,s.sortedIndex=Nl,s.sortedIndexBy=Ul,s.sortedIndexOf=Bl,s.sortedLastIndex=Ml,s.sortedLastIndexBy=$l,s.sortedLastIndexOf=Kl,s.startCase=bp,s.startsWith=Cp,s.subtract=vg,s.sum=wg,s.sumBy=yg,s.template=Pp,s.times=eg,s.toFinite=dn,s.toInteger=B,s.toLength=vo,s.toLower=Rp,s.toNumber=kt,s.toSafeInteger=Rd,s.toString=Z,s.toUpper=Ip,s.trim=Ep,s.trimEnd=Tp,s.trimStart=Lp,s.truncate=Op,s.unescape=Wp,s.uniqueId=ig,s.upperCase=Dp,s.upperFirst=Ki,s.each=eo,s.eachRight=ro,s.first=Vs,zi(s,function(){var t={};return tn(s,function(n,e){Y.call(s.prototype,e)||(t[e]=n)}),t}(),{chain:!1}),s.VERSION=p,Ut(["bind","bindKey","curry","curryRight","partial","partialRight"],function(t){s[t].placeholder=s}),Ut(["drop","take"],function(t,n){z.prototype[t]=function(e){e=e===i?1:at(B(e),0);var r=this.__filtered__&&!n?new z(this):this.clone();return r.__filtered__?r.__takeCount__=pt(e,r.__takeCount__):r.__views__.push({size:pt(e,Ft),type:t+(r.__dir__<0?"Right":"")}),r},z.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}}),Ut(["filter","map","takeWhile"],function(t,n){var e=n+1,r=e==re||e==br;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}}),Ut(["head","last"],function(t,n){var e="take"+(n?"Right":"");z.prototype[t]=function(){return this[e](1).value()[0]}}),Ut(["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(Ct)},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 ve(e,t,n)})}),z.prototype.reject=function(t){return this.filter(vr(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(Ft)},tn(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,d=a instanceof z,y=c[0],m=d||U(a),x=function(k){var H=u.apply(s,wn([k],c));return r&&A?H[0]:H};m&&e&&typeof y=="function"&&y.length!=1&&(d=m=!1);var A=this.__chain__,R=!!this.__actions__.length,O=o&&!A,$=d&&!R;if(!o&&m){a=$?a:new z(this);var W=t.apply(a,c);return W.__actions__.push({func:dr,args:[x],thisArg:i}),new Mt(W,A)}return O&&$?t.apply(this,c):(W=this.thru(x),O?r?W.value()[0]:W.value():W)})}),Ut(["pop","push","shift","sort","splice","unshift"],function(t){var n=Me[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)})}}),tn(z.prototype,function(t,n){var e=s[n];if(e){var r=e.name+"";Y.call(Yn,r)||(Yn[r]=[]),Yn[r].push({name:n,func:e})}}),Yn[sr(i,Pt).name]=[{name:"wrapper",func:i}],z.prototype.clone=Wf,z.prototype.reverse=Df,z.prototype.value=Ff,s.prototype.at=ch,s.prototype.chain=lh,s.prototype.commit=hh,s.prototype.next=dh,s.prototype.plant=gh,s.prototype.reverse=_h,s.prototype.toJSON=s.prototype.valueOf=s.prototype.value=vh,s.prototype.first=s.prototype.head,ce&&(s.prototype[ce]=ph),s},Gn=hf();In?((In.exports=Gn)._=Gn,kr._=Gn):ht._=Gn}).call(be)})(Sr,Sr.exports);var Eg=Sr.exports;const Tg=Ig(Eg);class Lg{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 Og{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=Tg.get(i,"schema.config.parameters.properties",{}),I=(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,I);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 To extends Ce{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 Lg(this.config),_=new Og(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 Wg(h,f){if(Array.isArray(h))return h;if(typeof h=="object"&&h!==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(h).map(S=>{switch(S){case"rest":return Dg(h[S],{baseEndpointProtocol:p,baseEndpoint:i,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger});case"webrtc":return Fg(h[S],{baseWebSocketProtocol:_,baseEndpoint:i,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger});case"websocket":return Ng(h[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 To({apiUrl:`${p}://${i}`,apiKey:f.apiKey,agentId:f.agentId,tools:f.tools,logger:f.logger})),v}throw new Error("Invalid protocols configuration")}function Dg(h,f){return h===!0?new Yi({apiUrl:`${f.baseEndpointProtocol}://${f.baseEndpoint}`,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger}):typeof h=="object"&&h!==null?new Yi(h):null}function Fg(h,f){return h===!0?new Qi({webrtcUrl:`${f.baseWebSocketProtocol}://${f.baseEndpoint}/webrtc`,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger}):typeof h=="object"&&h!==null?new Qi(h):null}function Ng(h,f){return h===!0?new Xi({webSocketUrl:`${f.baseWebSocketProtocol}://${f.baseEndpoint}/websocket`,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger}):typeof h=="object"&&h!==null?new Xi(h):null}function Ug(h,f,i,p,_){return v=>{v.type==="message"?Bg(v.payload,h,f,i,_):v.type==="reasoning"?Mg(v.payload,h,f,_):v.type==="transaction"&&$g(v.payload,h,p)}}function Bg(h,f,i,p,_){h.createdAt||(h.createdAt=new Date),(h==null?void 0:h.finishReason)==="stop"&&!(h!=null&&h.functionResponse)&&!(h!=null&&h.thought)&&p(!1),h.thought&&(h.type="reasoning"),h.protocol=f.getName(),i(v=>{const S=ee([...v,h]);return _?_(S):S})}function Mg(h,f,i,p){const _={type:"reasoning",text:h.thought,role:"assistant",finishReason:"stop",protocol:f.getName(),createdAt:new Date};i(v=>{const S=ee([...v,_]);return p?p(S):S})}function $g(h,f,i){i.filter(p=>p!==f).forEach(p=>p.onTransaction(h))}function Kg(h){return new Promise((f,i)=>{const p=new FileReader;p.readAsDataURL(h),p.onload=()=>{const v=p.result.split(";base64,")[1];f(v)},p.onerror=_=>{i(_)}})}function qg(h){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 h){const p=f[i.getName()];if(p)return p(i)}return null}function kg(h,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(!h.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"},J=[...T,F];return p?p(J):J});return}const C={role:"user",type:"text",text:v.content[0].text,createdAt:new Date};f(T=>{const F=ee([...T,C]);return p?p(F):F}),i(!0);const M=h.sort((T,F)=>F.getPriority()-T.getPriority()).find(T=>T.status==="connected"),I=[];if(v.attachments)for(const T of v.attachments)T.contentType.startsWith("image/")&&T.file&&I.push({role:"user",image:{contentType:T.contentType,content:await Kg(T.file)},text:"",type:"text",createdAt:new Date});v.content&&I.push({role:"user",text:v.content[0].text,type:"text",createdAt:new Date}),_==null||_.debug("Sending message:",I),await(M==null?void 0:M.sendPacket({type:"request",payload:I}))}}function zg(h,f,i,p,_,v){return async S=>{var J;if(((J=S.content[0])==null?void 0:J.type)!=="text")throw new Error("Only text messages are supported");const E=h.sort((q,_t)=>_t.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 I=f.slice(0,M+1),P={role:"user",text:S.content[0].text,type:"text",createdAt:new Date},T=ee([...I,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 Hg(h,f,i,p,_,v){return async(S,E)=>{const C=h.sort((J,q)=>q.getPriority()-J.getPriority()).find(J=>J.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 I=f.findIndex(J=>J.id===M);if(I===-1){v==null||v.debug("Parent message not found:",M);return}const P=f[I];i(J=>{const q=J.slice(0,I+1);return _?_(q):q});let T;if(P.role==="assistant"||P.role==="function"){for(let J=I-1;J>=0;J--)if(f[J].role==="user"){T=f[J];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 Gg(h,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 _}),h.forEach(_=>{_.status==="connected"&&_.sendPacket({type:"command",payload:{command:"set_initial_context",arguments:{cancel:!0}}}).catch(()=>{})}),Promise.resolve())}const Pe=j.createContext(void 0);function Jg(){const h=j.useContext(Pe);if(!h)throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");return h}function Lo(h){const f=j.useContext(Pe);if(!f)throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");const i=f.protocols.find(_=>_.getName()===h);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 Zg(){const h=j.useContext(Pe);if(!h)throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");return qg(h.protocols)}function Yg(){return Lo("webrtc")}function Xg(){const h=j.useContext(Pe);if(!h)throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");return h.getMessages()}function Qg(){const h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let f="";for(let i=0;i<16;i++)f+=h.charAt(Math.floor(Math.random()*h.length));return f}function Vg(h,f,i,p,_,v,S,E,C,M,I){return{threadId:h,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=Qg();I==null||I.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=>{I==null||I.debug("Switching to thread:",P),i(P),S==null||S(P)},onArchive:P=>{I==null||I.debug("Archiving thread:",P),p(T=>T.map(F=>F.threadId===P?{...F,status:"archived"}:F)),E==null||E(P)},onUnarchive:P=>{I==null||I.debug("Unarchiving thread:",P),p(T=>T.map(F=>F.threadId===P?{...F,status:"regular"}:F)),C==null||C(P)},onDelete:async P=>{if(I==null||I.debug("Deleting thread:",P),p(T=>T.filter(F=>F.threadId!==P)),h===P){const T=f.filter(F=>F.threadId!==P&&F.status==="regular");T.length>0&&i(T[0].threadId)}_.remove(P).then(()=>I==null?void 0:I.debug("Thread deleted from backend")).catch(T=>I==null?void 0:I.error("Failed to delete thread:",T)),M==null||M(P)}}}class Oo{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(I=>({threadId:I.code||I.id,title:I.title||`Session ${I.code||I.id}`,status:I.status==="archived"?"archived":"regular"})):[]}catch(E){return(S=this.logger)==null||S.warn("PersonaSessionStorage: error listing sessions",E),[]}}}function jg({dev:h=!1,baseUrl:f,protocols:i,logger:p,children:_,session:v="new",transformMessages:S,enableThreads:E=!1,sessionStorage:C,onThreadCreate:M,onThreadSwitch:I,onThreadRename:P,onThreadArchive:T,onThreadUnarchive:F,onThreadDelete:J,...q}){const[_t,Pt]=j.useState(!1),[Vt,st]=j.useState([]),[Pn,zt]=j.useState(new Map),gn=j.useRef(!1),xt=j.useRef(!1),Dt=j.useMemo(()=>C||new Oo({apiKey:q.apiKey,endpoint:f||"https://persona.applica.guru/api"}),[C,f,q.apiKey]),[Bn,Re]=j.useState([]),[Rt,Ie]=j.useState(""),Mn=j.useRef(typeof v=="string"?v:"new"),re=j.useRef(!1);j.useEffect(()=>{!E||re.current||(re.current=!0,Dt.list(q.agentId,q.userId).then(X=>{(X==null?void 0:X.length)>0&&(Re(X),Ie(X[0].threadId))}).catch(X=>p==null?void 0:p.error("Failed to load threads:",X)))},[E,Dt,q.agentId,q.userId,p]);const ft=j.useMemo(()=>Wg(i,{dev:h||!1,baseUrl:f,apiKey:q.apiKey,agentId:q.agentId,userId:q.userId,tools:q.tools,logger:p}),[i,h,f,q.apiKey,q.agentId,q.userId,q.tools,p]);j.useEffect(()=>{gn.current||(gn.current=!0,p==null||p.debug("Setting up protocols:",ft.map(X=>X.getName())),ft.forEach(X=>{X.setSession(Mn.current),X.clearListeners(),X.addStatusChangeListener(ct=>{p==null||p.debug(`${X.getName()} status: ${ct}`),zt(Ht=>{const Rn=new Map(Ht);return Rn.set(X.getName(),ct),Rn}),ct==="connected"&&!xt.current&&(q.context&&X.sendPacket({type:"command",payload:{command:"set_initial_context",arguments:q.context}}).catch(()=>{}),q.tools&&Array.isArray(q.tools)&&X.sendPacket({type:"command",payload:{command:"set_local_tools",arguments:{tools:q.tools.map(Ht=>Ht.schema)}}}).catch(()=>{}))}),X.addPacketListener(Ug(X,st,Pt,ft,S)),X.autostart&&X.status==="disconnected"&&(p==null||p.debug(`Auto-connecting protocol: ${X.getName()}`),X.connect(Mn.current).catch(()=>{}),Pt(!1))}))},[]),j.useEffect(()=>{if(!E||!Rt){st([]);return}if(xt.current||Rt===Mn.current)return;xt.current=!0,p==null||p.info("Switching to thread:",Rt),(async()=>{try{const ct=ft.filter(vt=>vt.status==="connected");ct.length>0&&await Promise.allSettled(ct.map(vt=>vt.disconnect())),Mn.current=Rt,await Promise.allSettled(ft.map(vt=>vt.setSession(Rt)));const Ht=await Dt.sync(Rt),Rn=ee(Ht);st(S?S(Rn):Rn),p==null||p.debug(`Loaded ${Ht.length} messages for thread ${Rt}`);const _n=ft.filter(vt=>vt.autostart);_n.length>0&&await Promise.allSettled(_n.map(vt=>vt.connect(Rt)))}catch(ct){p==null||p.error("Failed to switch thread:",ct),st([])}finally{xt.current=!1}})()},[Rt,E,ft,Dt,S,p]);const br=j.useCallback(kg(ft,st,Pt,S,p),[ft,S,p]),rn=j.useCallback(zg(ft,Vt,st,Pt,S,p),[ft,Vt,S,p]),jt=j.useCallback(Hg(ft,Vt,st,Pt,S,p),[ft,Vt,S,p]),Cr=j.useCallback(Gg(ft,st,Pt,S),[ft,S]),$n=j.useCallback(X=>{const ct=ee([...X]);st(S?S(ct):ct)},[S]),Ft=j.useCallback(()=>Vt,[Vt]),Ee=j.useMemo(()=>{if(E)return Vg(Rt,Bn,Ie,Re,Dt,M,I,T,F,J,p)},[E,Rt,Bn,Dt,M,I,T,F,J,p]),Pr=xr.useExternalStoreRuntime({isRunning:_t,messages:Vt,convertMessage:Pg,setMessages:$n,onNew:br,onEdit:rn,onCancel:Cr,onReload:jt,adapters:{attachments:new xr.CompositeAttachmentAdapter([new xr.SimpleImageAttachmentAdapter]),...Ee?{threadList:Ee}:{}}});return Zi.jsx(Pe.Provider,{value:{protocols:ft,protocolsStatus:Pn,getMessages:Ft},children:Zi.jsx(xr.AssistantRuntimeProvider,{runtime:Pr,children:_})})}function t_({children:h,...f}){return Zi.jsx(jg,{...f,children:h})}class n_{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 Un(h,f,i){return{type:h,description:f,...i}}function Wo(h){const f=Object.entries(h.parameters).filter(([i,p])=>p.required).map(([i])=>i);return{type:"local",name:h.name,description:h.description,config:{timeout:h.timeout||60,parameters:{type:"object",title:h.title||`${h.name} parameters`,required:f,properties:h.parameters},output:{type:"object",title:`${h.name} output`,properties:h.output}}}}function Ar(h){return{schema:Wo(h),implementation:h.implementation}}function Do(h,f,i,p,_,v){const S={name:h,description:f,title:v==null?void 0:v.title,timeout:v==null?void 0:v.timeout,parameters:p,output:_,implementation:i};return Ar(S)}const e_=Do("sum","Sum two numbers",function(f,i){return{result:f+i}},{a:Un("number","First number to sum",{required:!0}),b:Un("number","Second number to sum",{required:!0})},{result:Un("number","Sum of two numbers")}),r_=Ar({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:Un("number","First number to sum"),b:Un("number","Seconth number to sum")},output:{result:Un("number","Sum of two numbers")},implementation:function(f,i){return{result:f+i}}});function i_(h){const f=[],i={};return h.forEach(p=>{const{schema:_,implementation:v}=Ar(p);f.push(_),i[p.name]=v}),{schemas:f,implementations:i}}function u_(h,f){const{required:i,properties:p}=f.config.parameters;for(const _ of i)if(!(_ in h))throw new Error(`Missing required parameter: ${_}`);for(const[_,v]of Object.entries(h)){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}exports.PersonaConsoleLogger=n_;exports.PersonaProtocolBase=Ce;exports.PersonaRESTProtocol=Yi;exports.PersonaRuntimeProvider=t_;exports.PersonaSessionStorage=Oo;exports.PersonaTransactionProtocol=To;exports.PersonaWebRTCProtocol=Qi;exports.PersonaWebSocketProtocol=Xi;exports.createParameter=Un;exports.createTool=Ar;exports.createToolFromFunction=Do;exports.createToolRegistry=i_;exports.generateToolSchema=Wo;exports.navigateToToolExample=r_;exports.sumTool=e_;exports.usePersonaRuntime=Jg;exports.usePersonaRuntimeEndpoint=Zg;exports.usePersonaRuntimeMessages=Xg;exports.usePersonaRuntimeProtocol=Lo;exports.usePersonaRuntimeWebRTCProtocol=Yg;exports.validateToolParameters=u_;
|
|
40
28
|
//# sourceMappingURL=bundle.cjs.js.map
|