UNPKG

starchild-widget

Version:

Starchild Widget

1 lines 642 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom/client"),require("react/jsx-runtime"),require("styled-components"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom/client","react/jsx-runtime","styled-components","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).StarChildWidget={},e.React,e.ReactDOM,e.jsxRuntime,e.styled,e.ReactDOM)}(this,function(e,t,n,r,i,o){"use strict";var s=Object.defineProperty,a=(e,t,n)=>((e,t,n)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);function l(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const c=l(t),u=l(o);var d=(e=>(e.EN_US="en-US",e.ZH_CN="zh-CN",e))(d||{}),h=(e=>(e.LIGHT="light",e.DARK="dark",e))(h||{}),p=(e=>(e.SEARCH="SEARCH",e.TEXT="TEXT",e))(p||{}),f=(e=>(e.LINE="line",e.BG="bg",e))(f||{}),g=(e=>(e[e.CLICK=0]="CLICK",e[e.HOVER=1]="HOVER",e))(g||{}),m=(e=>(e.COMMON="COMMON",e.AUTH="AUTH",e.CHAT="CHAT",e.SEARCH="SEARCH",e.POSITION_CACHE="POSITION_CACHE",e.TRADE="TRADE",e.RESET_ALL="RESET_ALL",e.CHAT_CACHE="CHAT_CACHE",e))(m||{});class x extends Error{constructor(e,t,n){super(e),a(this,"status"),a(this,"statusText"),this.name="ApiError",this.status=t,this.statusText=n}}var y=(e=>(e.CHAT="CHAT",e.SEARCH="SEARCH",e))(y||{});const b=e=>{const t=window.innerWidth||document.documentElement.clientWidth||1200,n=window.innerHeight||document.documentElement.clientHeight||800;if(e===y.CHAT)return{x:t-12,y:n-12};if(e===y.SEARCH){const e=640;return{x:Math.max(12,(t-e)/2),y:80}}return{x:12,y:12}},v=(e,t)=>{const n=Math.max(0,window.innerWidth-t.width-12),r=Math.max(0,window.innerHeight-t.height-12);return{x:Math.max(12,Math.min(e.x,n)),y:Math.max(12,Math.min(e.y,r))}},w=e=>{const t=(()=>{const e=window.innerWidth||document.documentElement.clientWidth||1200,t=window.innerHeight||document.documentElement.clientHeight||800;return{minWidth:420,minHeight:228,maxWidth:Math.min(980,e-40),maxHeight:t-160}})();return{width:Math.max(t.minWidth,Math.min(e.width,t.maxWidth)),height:Math.max(t.minHeight,Math.min(e.height,t.maxHeight))}},k={"zh-CN":"zh","en-US":"en"};class C{constructor(e){a(this,"config"),this.config={retries:3,retryDelay:1e3,timeout:1e4,headers:{},...e}}async get(e,t={}){return this.request(e,"GET",void 0,t)}async post(e,t,n={}){return this.request(e,"POST",t,n)}async delete(e,t,n={}){return this.request(e,"DELETE",t,n)}async put(e,t,n={}){return this.request(e,"PUT",t,n)}setAccountId(e){this.config.headers["account-id"]=e}setAiChatKey(e){this.config.headers["account-api-key"]=e}setLanguage(e){this.config.headers.language=e}clearAccountId(){delete this.config.headers["account-id"]}clearAiChatKey(){delete this.config.headers["account-api-key"]}async request(e,t,n,r={}){const i=this.buildUrl(e),o={...this.config.headers,...r.headers},s={method:t,headers:o};"POST"!==t&&"PUT"!==t&&"DELETE"!==t||void 0===n||(n instanceof FormData?(s.body=n,delete o["Content-Type"]):n instanceof URLSearchParams?(s.body=n.toString(),o["Content-Type"]="application/x-www-form-urlencoded"):(s.body=JSON.stringify(n),o["Content-Type"]="application/json"));try{const e=await fetch(i,s);if(!e.ok)throw new x(`HTTP ${e.status}: ${e.statusText}`,e.status,e.statusText);const t=e.headers.get("content-type");let n;return n=t&&t.includes("application/json")?await e.json():await e.text(),{data:n,status:e.status,statusText:e.statusText}}catch(a){if(a instanceof x)throw a;throw new x(a instanceof Error?a.message:"Unknown error",0,"Network Error")}}buildUrl(e){return`${this.config.baseURL.replace(/\/$/,"")}/${e.replace(/^\//,"")}`}}function A(e){return new C(e)}const S=t.createContext(null),E=()=>{const e=t.useContext(S);if(!e)throw new Error("useWidget must be used within WidgetProvider");return e},T={secretKey:"",accountId:"",orderlyKey:"",aiChatKey:"",telegramUserId:"",error:null},M={setSecretKeyAction:{action:e=>({type:m.AUTH,payload:{actionType:"setSecretKeyAction",data:e}}),reducer:(e,t)=>({...e,secretKey:t,error:null})},setAccountIdAction:{action:e=>({type:m.AUTH,payload:{actionType:"setAccountIdAction",data:e}}),reducer:(e,t)=>({...e,accountId:t,error:null})},setOrderlyKeyAction:{action:e=>({type:m.AUTH,payload:{actionType:"setOrderlyKeyAction",data:e}}),reducer:(e,t)=>({...e,orderlyKey:t,error:null})},setAiChatKeyAction:{action:e=>({type:m.AUTH,payload:{actionType:"setAiChatKeyAction",data:e}}),reducer:(e,t)=>({...e,aiChatKey:t,error:null})},setTelegramUserIdAction:{action:e=>({type:m.AUTH,payload:{actionType:"setTelegramUserIdAction",data:e}}),reducer:(e,t)=>({...e,telegramUserId:t,error:null})},setCredentialsAction:{action:e=>({type:m.AUTH,payload:{actionType:"setCredentialsAction",data:e}}),reducer:(e,t)=>({...e,...t,error:null})},setErrorAction:{action:e=>({type:m.AUTH,payload:{actionType:"setErrorAction",data:e}}),reducer:(e,t)=>({...e,error:t})},clearAction:{action:()=>({type:m.AUTH,payload:{actionType:"clearAction",data:null}}),reducer:()=>({...T})},destroyAction:{action:()=>({type:m.AUTH,payload:{actionType:"destroyAction",data:null}}),reducer:()=>({...T})}},j=M.setAiChatKeyAction.action,O=M.setTelegramUserIdAction.action,I=M.setCredentialsAction.action;function D(e=T,t){if(!t.payload||!t.payload.actionType)return e;const n=M[t.payload.actionType];return n?n.reducer(e,t.payload.data):e}function L(){const{state:e,dispatch:n}=E();return[e.auth.aiChatKey,t.useCallback(e=>{n(j(e))},[n])]}function z(){const{state:e,dispatch:n}=E();return[e.auth.telegramUserId,t.useCallback(e=>{n(O(e))},[n])]}let F="testnet";function R(){return F}const P={testnet:{restfulDomain:"https://tg-api-testnet-899f9ba9abd5.herokuapp.com"},mainnet:{restfulDomain:"https://tg-api-mainnet-a4ecd0c9d145.herokuapp.com"}},N=new Proxy({},{get:(e,t)=>{const n=R();return P[n][t]}}),B={testnet:{restfulDomain:"https://testnet-api.orderly.org"},mainnet:{restfulDomain:"https://api.orderly.org"}},U=new Proxy({},{get:(e,t)=>{const n=R();return B[n][t]}}),H={testnet:{pageDomain:"https://testnet.iamstarchild.com"},mainnet:{pageDomain:"https://iamstarchild.com"}},Z=new Proxy({},{get:(e,t)=>{const n=R();return H[n][t]}}),Y={mounted:!1,themeMode:h.DARK,locale:d.EN_US,environment:"testnet",error:null,isWindowVisible:!0},V={setMountedAction:{action:e=>({type:m.COMMON,payload:{actionType:"setMountedAction",data:e}}),reducer:(e,t)=>({...e,mounted:t})},setThemeModeAction:{action:e=>({type:m.COMMON,payload:{actionType:"setThemeModeAction",data:e}}),reducer:(e,t)=>({...e,themeMode:t})},setLocaleAction:{action:e=>({type:m.COMMON,payload:{actionType:"setLocaleAction",data:e}}),reducer:(e,t)=>({...e,locale:t})},setEnvironmentAction:{action:e=>({type:m.COMMON,payload:{actionType:"setEnvironmentAction",data:e}}),reducer:(e,t)=>({...e,environment:t})},setErrorAction:{action:e=>({type:m.COMMON,payload:{actionType:"setErrorAction",data:e}}),reducer:(e,t)=>({...e,error:t})},setIsWindowVisibleAction:{action:e=>({type:m.COMMON,payload:{actionType:"setIsWindowVisibleAction",data:e}}),reducer:(e,t)=>({...e,isWindowVisible:t})},destroyAction:{action:()=>({type:m.COMMON,payload:{actionType:"destroyAction",data:null}}),reducer:()=>({...Y})}},q=V.setMountedAction.action,W=V.setThemeModeAction.action,J=V.setLocaleAction.action,G=V.setEnvironmentAction.action,K=V.setErrorAction.action,Q=V.setIsWindowVisibleAction.action;function X(e=Y,t){if(!t.payload||!t.payload.actionType)return e;const n=V[t.payload.actionType];return n?n.reducer(e,t.payload.data):e}const _={},$={..._},ee={mode:h.LIGHT,..._,dn1:"#535E7B",dn2:"#4A5369",dn3:"#394155",dn4:"#333948",dn5:"#282E3A",dn6:"#20252F",dn7:"#1B2028",dn8:"#181C23",dn9:"#131519",dn10:"#07080A",brand1:"#B9D1FF",brand2:"#97B9FD",brand3:"#779DFF",brand4:"#608CFF",brand5:"#4774F6",brand6:"#335FFC",brand7:"#3347FD",brand8:"#283BEE",brand9:"#1D30DF",brand10:"#1728C1",brand4_15:"rgba(96, 140, 255, 0.15)",brand100:"#F84600",textDark20:"rgba(255, 255, 255, 0.20)",textDark36:"rgba(255, 255, 255, 0.36)",textDark54:"rgba(255, 255, 255, 0.54)",textDark80:"rgba(255, 255, 255, 0.80)",textDark98:"rgba(255, 255, 255, 0.98)",lineDark4:"rgba(255, 255, 255, 0.04)",lineDark6:"rgba(255, 255, 255, 0.06)",lineDark8:"rgba(255, 255, 255, 0.08)",lineDark12:"rgba(255, 255, 255, 0.12)",lineDark16:"rgba(255, 255, 255, 0.16)",success1:"#65ECD3",success2:"#27DEC8",success3:"#0FCBB4",success4:"#00B49E",success5:"#039886",success6:"#008676",success7:"#007769",success8:"#00685C",success9:"#0054AF",success10:"#00433B",success4_15:"rgba(0, 180, 158, 0.15)",danger1:"#FFD0DE",danger2:"#FFA5C0",danger3:"#FF608F",danger4:"#FF447C",danger5:"#E93E71",danger6:"#D92D6B",danger7:"#AC2D58",danger8:"#9D2D4D",danger9:"#791438",danger10:"#640B2B",danger4_15:"rgba(255,68,124,0.15)",warning1:"#FFF7E8",warning2:"#FFE4BA",warning3:"#FFCF8B",warning4:"#FFB65D",warning5:"#FF9A2E",warning6:"#FF7D00",warning7:"#D25F00",warning8:"#A64500",warning9:"#792E00",warning10:"#4D1B00",link1:"#FAEDFF",link2:"#EDC4FF",link3:"#D998FA",link4:"#BD6BED",link5:"#A141E0",link6:"#831BD3",link7:"#630EAD",link8:"#460487",link9:"#2D0061",link10:"#19003B",gradient:"linear-gradient(270deg, #59B0FE 0%, #26FEFE 100%)",red100:"#FF375B",black600:"#2F3133",black700:"#232527",black800:"#1A1C1E",black900:"#121315",textLight88:"rgba(0, 0, 0, 0.88)",white:"#FFFFFF"},te={mode:h.DARK,...$,dn1:"#535E7B",dn2:"#4A5369",dn3:"#394155",dn4:"#333948",dn5:"#282E3A",dn6:"#20252F",dn7:"#1B2028",dn8:"#181C23",dn9:"#131519",dn10:"#07080A",brand1:"#B9D1FF",brand2:"#97B9FD",brand3:"#779DFF",brand4:"#608CFF",brand5:"#4774F6",brand6:"#335FFC",brand7:"#3347FD",brand8:"#283BEE",brand9:"#1D30DF",brand10:"#1728C1",brand4_15:"rgba(96, 140, 255, 0.15)",brand100:"#F84600",textDark20:"rgba(255, 255, 255, 0.20)",textDark36:"rgba(255, 255, 255, 0.36)",textDark54:"rgba(255, 255, 255, 0.54)",textDark80:"rgba(255, 255, 255, 0.80)",textDark98:"rgba(255, 255, 255, 0.98)",lineDark4:"rgba(255, 255, 255, 0.04)",lineDark6:"rgba(255, 255, 255, 0.06)",lineDark8:"rgba(255, 255, 255, 0.08)",lineDark12:"rgba(255, 255, 255, 0.12)",lineDark16:"rgba(255, 255, 255, 0.16)",success1:"#65ECD3",success2:"#27DEC8",success3:"#0FCBB4",success4:"#00B49E",success5:"#039886",success6:"#008676",success7:"#007769",success8:"#00685C",success9:"#0054AF",success10:"#00433B",success4_15:"rgba(0, 180, 158, 0.15)",danger1:"#FFD0DE",danger2:"#FFA5C0",danger3:"#FF608F",danger4:"#FF447C",danger5:"#E93E71",danger6:"#D92D6B",danger7:"#AC2D58",danger8:"#9D2D4D",danger9:"#791438",danger10:"#640B2B",danger4_15:"rgba(255,68,124,0.15)",warning1:"#FFF7E8",warning2:"#FFE4BA",warning3:"#FFCF8B",warning4:"#FFB65D",warning5:"#FF9A2E",warning6:"#FF7D00",warning7:"#D25F00",warning8:"#A64500",warning9:"#792E00",warning10:"#4D1B00",link1:"#FAEDFF",link2:"#EDC4FF",link3:"#D998FA",link4:"#BD6BED",link5:"#A141E0",link6:"#831BD3",link7:"#630EAD",link8:"#460487",link9:"#2D0061",link10:"#19003B",gradient:"linear-gradient(270deg, #59B0FE 0%, #26FEFE 100%)",red100:"#FF375B",black600:"#2F3133",black700:"#232527",black800:"#1A1C1E",black900:"#121315",textLight88:"rgba(0, 0, 0, 0.88)",white:"#FFFFFF"},ne=(e,t)=>{const n=e===h.DARK?te:ee,r=((e,t)=>{if(!t)return;const n=e===h.DARK?t.dark:t.light,r=t.common;return r&&n?{...r,...n}:r||n||void 0})(e,t);return r?((e,t)=>({...e,...t}))(n,r):n};function re(){const{state:e,dispatch:n}=E();return[e.common.themeMode,t.useCallback(e=>{n(W(e))},[n])]}function ie(){const[e]=re();return ne(e)}function oe(){const{state:e,dispatch:n}=E();return[e.common.locale,t.useCallback(e=>{n(J(e))},[n])]}let se=null;function ae(){return se||(se=A({baseURL:N.restfulDomain,timeout:1e4})),se}function le(){const[e]=z(),[t]=L(),[n]=oe(),r=ae();r.setAccountId(e),r.setAiChatKey(t),r.setLanguage(k[n])}function ce(){return le(),t.useCallback(async({telegramUserId:e})=>{try{const t=ae();return(await t.get(`/threads?user_id=${e}`)).data}catch(t){throw t}},[])}function ue(){return le(),t.useCallback(async({threadId:e,telegramUserId:t})=>{try{const n=ae();return(await n.get(`/chat_content?thread_id=${e}&user_id=${t}`)).data}catch(n){throw n}},[])}const de={currentAiThreadId:"",searchSize:null,isShowVoiceTooltip:!0},he={setCurrentAiThreadIdAction:{action:e=>({type:m.CHAT_CACHE,payload:{actionType:"setCurrentAiThreadIdAction",data:e}}),reducer:(e,t)=>({...e,currentAiThreadId:t})},setSearchSizeAction:{action:e=>({type:m.CHAT_CACHE,payload:{actionType:"setSearchSizeAction",data:e}}),reducer:(e,t)=>({...e,searchSize:t})},loadAction:{action:e=>({type:m.CHAT_CACHE,payload:{actionType:"loadAction",data:e}}),reducer:(e,t)=>({...e,...t})},setIsShowVoiceTooltipAction:{action:e=>({type:m.CHAT_CACHE,payload:{actionType:"setIsShowVoiceTooltipAction",data:e}}),reducer:(e,t)=>({...e,isShowVoiceTooltip:t})},resetAllAction:{action:()=>({type:m.CHAT_CACHE,payload:{actionType:"resetAllAction",data:null}}),reducer:e=>({...e,currentAiThreadId:"",searchSize:null,isShowVoiceTooltip:!0})}},pe=he.setCurrentAiThreadIdAction.action,fe=he.setSearchSizeAction.action,ge=he.loadAction.action;function me(){const{state:e,dispatch:n}=E();return[e.chatcache.currentAiThreadId,t.useCallback(e=>{n(pe(e))},[n])]}function xe(){const{state:e,dispatch:n}=E();return[e.chatcache.searchSize,t.useCallback(e=>{n(fe(e))},[n])]}var ye=(e=>(e.USER="USER",e.ASSISTANT="ASSISTANT",e))(ye||{}),be=(e=>(e.FINAL_ANSWER="final_answer",e.TEMP="temp",e.END_THINKING="end_thinking",e.ERROR="error",e.SOURCE_LIST_DETAILS="source_list_details",e.ORDER_PARAMS="order_params",e))(be||{});function ve(e=8){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let r=0;r<e;r++){n+=t[Math.floor(62*Math.random())]}return n}function we(e){const t=window.open();t&&(t.opener=null,t.location=e)}const ke=e=>{if(!e)return["",""];try{const t=/(https?:\/\/[^\s?]+)/,n=e.match(t),r=n?n[1]:e.split("?")[0],i=new URL(r),o=i.hostname.split("."),s=`https://${o.length>=2?`${o[o.length-2]}.${o[o.length-1]}`:i.hostname}`;return[s,`https://www.google.com/s2/favicons?domain=${s}&sz=32`]}catch(t){return["",""]}},Ce=e=>`https://oss.orderly.network/static/symbol_logo/${e}.png`;function Ae(e){const t=Number(e);if(isNaN(t))return"0";const n=Math.abs(t),r=t<0?"-":"";return n>=1e9?`${r}${(n/1e9).toFixed(2)}B`:n>=1e6?`${r}${(n/1e6).toFixed(2)}M`:n>=1e3?`${r}${(n/1e3).toFixed(2)}K`:`${r}${n.toFixed(2)}`}function Se(e,t){const n=Number(e),r=Number(t);if(isNaN(n))return"0";if(isNaN(r)||r<=0)return n.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2});const i=Math.max(0,-Math.floor(Math.log10(r)));return n.toLocaleString("en-US",{minimumFractionDigits:i,maximumFractionDigits:i})}const Ee={visible:!1,disabled:!1,aiResponseContentList:[],tempAiContentData:{id:"",feedback:null,role:ye.ASSISTANT,thoughtContentList:[],sourceListDetails:[],content:"",timestamp:0,agentRecommendationList:[]},isFocus:!1,inputValue:"",isLoadingData:!1,isChatModalOpen:!1,isRenderingData:!1,threadsList:[],currentLoadingThreadId:"",currentRenderingId:"",isAnalyzeContent:!1,analyzeContentList:[],currentAiContentDeepThinkData:{id:"",feedback:null,role:ye.ASSISTANT,thoughtContentList:[],sourceListDetails:[],content:"",timestamp:0,agentRecommendationList:[]},chatRecommendationList:[],isShowThreadList:!1,isShowDeepThinkSources:!1,isShowDeepThink:!1,isRecording:!1,isHandleRecord:!1,realtimeText:"",userSetting:{searchbarShortcut:"",voiceShortcut:""},shouldTriggerVoiceRecording:!1},Te={setVisibleAction:{action:e=>({type:m.CHAT,payload:{actionType:"setVisibleAction",data:e}}),reducer:(e,t)=>({...e,visible:t})},setIsChatModalOpenAction:{action:e=>({type:m.CHAT,payload:{actionType:"setIsChatModalOpenAction",data:e}}),reducer:(e,t)=>({...e,isChatModalOpen:t})},setDisabledAction:{action:e=>({type:m.CHAT,payload:{actionType:"setDisabledAction",data:e}}),reducer:(e,t)=>({...e,disabled:t})},getAiSteamDataAction:{action:e=>({type:m.CHAT,payload:{actionType:"getAiSteamDataAction",data:e}}),reducer:(e,t)=>{const n=e.tempAiContentData,{id:r,type:i,content:o}=t,s={...e};if(i===be.ERROR)s.tempAiContentData={id:r,thoughtContentList:[],sourceListDetails:[],content:n.content+o,feedback:null,role:ye.ASSISTANT,timestamp:(new Date).getTime(),agentRecommendationList:[]};else if(n.id!==r)if(i===be.TEMP){const e=JSON.parse(o);s.tempAiContentData={id:r,feedback:null,thoughtContentList:n.thoughtContentList.concat({id:e.id,tool_name:e.tool_name,tool_type:e.tool_type,tool_description:e.description}),sourceListDetails:n.sourceListDetails,content:n.content?n.content:"",role:ye.ASSISTANT,timestamp:(new Date).getTime(),agentRecommendationList:[]}}else if(i===be.SOURCE_LIST_DETAILS){const e=JSON.parse(o);s.tempAiContentData={id:r,feedback:null,thoughtContentList:n.thoughtContentList,sourceListDetails:e,content:n.content,role:ye.ASSISTANT,timestamp:(new Date).getTime(),agentRecommendationList:[]}}else i===be.FINAL_ANSWER&&(s.tempAiContentData={id:r,feedback:null,thoughtContentList:n.thoughtContentList,sourceListDetails:n.sourceListDetails,content:o,role:ye.ASSISTANT,timestamp:(new Date).getTime(),agentRecommendationList:[]});else if(i===be.TEMP){const e=JSON.parse(o),{tool_name:t,tool_type:r,description:i,id:a}=e,l=n.thoughtContentList.some(e=>e.id===a);let c=[...n.thoughtContentList];l?c=c.map(e=>e.id===a?{...e,tool_description:e.tool_description+i}:e):c.push({id:a,tool_name:t,tool_type:r,tool_description:i}),s.tempAiContentData={...n,thoughtContentList:c}}else if(i===be.SOURCE_LIST_DETAILS){const e=JSON.parse(o),t=n.sourceListDetails.concat(e);s.tempAiContentData={...n,sourceListDetails:t}}else if(i===be.FINAL_ANSWER){const e=n.content+o;s.tempAiContentData={...n,content:e}}return s}},combineResponseDataAction:{action:()=>({type:m.CHAT,payload:{actionType:"combineResponseDataAction",data:null}}),reducer:e=>{const t={...e},n={...e.tempAiContentData,extraData:{done:!0}};return n.id||(n.id=String(ve())),t.aiResponseContentList.push(n),t.tempAiContentData=Ee.tempAiContentData,t}},changeAiResponseContentListAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeAiResponseContentListAction",data:e}}),reducer:(e,t)=>({...e,aiResponseContentList:t})},changeIsFocusAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsFocusAction",data:e}}),reducer:(e,t)=>({...e,isFocus:t})},changeInputValueAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeInputValueAction",data:e}}),reducer:(e,t)=>({...e,inputValue:t})},changeIsLoadingDataAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsLoadingDataAction",data:e}}),reducer:(e,t)=>({...e,isLoadingData:t})},changeIsRenderingDataAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsRenderingDataAction",data:e}}),reducer:(e,t)=>({...e,isRenderingData:t})},changeThreadsListAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeThreadsListAction",data:e}}),reducer:(e,t)=>({...e,threadsList:t})},changeCurrentRenderingIdAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeCurrentRenderingIdAction",data:e}}),reducer:(e,t)=>({...e,currentRenderingId:t})},changeCurrentLoadingThreadIdAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeCurrentLoadingThreadIdAction",data:e}}),reducer:(e,t)=>({...e,currentLoadingThreadId:t})},resetTempAiContentDataAction:{action:()=>({type:m.CHAT,payload:{actionType:"resetTempAiContentDataAction",data:null}}),reducer:e=>({...e,tempAiContentData:Ee.tempAiContentData})},changeIsAnalyzeContentAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsAnalyzeContentAction",data:e}}),reducer:(e,t)=>({...e,isAnalyzeContent:t})},changeAnalyzeContentListAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeAnalyzeContentListAction",data:e}}),reducer:(e,t)=>({...e,analyzeContentList:t})},changeCurrentAiContentDeepThinkDataAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeCurrentAiContentDeepThinkDataAction",data:e}}),reducer:(e,t)=>({...e,currentAiContentDeepThinkData:t})},changeChatRecommendationListAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeChatRecommendationListAction",data:e}}),reducer:(e,t)=>({...e,chatRecommendationList:t})},changeIsShowThreadListAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsShowThreadListAction",data:e}}),reducer:(e,t)=>({...e,isShowThreadList:t})},changeIsShowDeepThinkSourcesAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsShowDeepThinkSourcesAction",data:e}}),reducer:(e,t)=>({...e,isShowDeepThinkSources:t})},changeIsShowDeepThinkAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsShowDeepThinkAction",data:e}}),reducer:(e,t)=>({...e,isShowDeepThink:t})},changeIsRecordingAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsRecordingAction",data:e}}),reducer:(e,t)=>({...e,isRecording:t})},changeIsHandleRecordAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeIsHandleRecordAction",data:e}}),reducer:(e,t)=>({...e,isHandleRecord:t})},changeRealtimeTextAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeRealtimeTextAction",data:e}}),reducer:(e,t)=>({...e,realtimeText:t})},changeUserSettingAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeUserSettingAction",data:e}}),reducer:(e,t)=>({...e,userSetting:t})},changeShouldTriggerVoiceRecordingAction:{action:e=>({type:m.CHAT,payload:{actionType:"changeShouldTriggerVoiceRecordingAction",data:e}}),reducer:(e,t)=>({...e,shouldTriggerVoiceRecording:t})},resetAction:{action:()=>({type:m.CHAT,payload:{actionType:"resetAction",data:null}}),reducer:()=>({...Ee})}},Me=Te.setVisibleAction.action,je=Te.setDisabledAction.action,Oe=Te.getAiSteamDataAction.action,Ie=Te.combineResponseDataAction.action,De=Te.changeAiResponseContentListAction.action,Le=Te.changeInputValueAction.action,ze=Te.changeIsLoadingDataAction.action,Fe=Te.changeIsRenderingDataAction.action,Re=Te.changeThreadsListAction.action,Pe=Te.changeCurrentRenderingIdAction.action,Ne=Te.changeCurrentLoadingThreadIdAction.action,Be=Te.resetTempAiContentDataAction.action,Ue=Te.changeIsAnalyzeContentAction.action,He=Te.changeCurrentAiContentDeepThinkDataAction.action,Ze=Te.changeChatRecommendationListAction.action,Ye=Te.changeIsShowThreadListAction.action,Ve=Te.changeIsShowDeepThinkSourcesAction.action,qe=Te.changeIsShowDeepThinkAction.action,We=Te.changeIsRecordingAction.action,Je=Te.changeIsHandleRecordAction.action,Ge=Te.changeRealtimeTextAction.action,Ke=Te.changeUserSettingAction.action,Qe=Te.setIsChatModalOpenAction.action,Xe=Te.changeShouldTriggerVoiceRecordingAction.action;function _e(e=Ee,t){if(!t.payload||!t.payload.actionType)return e;const n=Te[t.payload.actionType];return n?n.reducer(e,t.payload.data):e}function $e(){const{state:e,dispatch:n}=E();return[e.chat.isRenderingData,t.useCallback(e=>{n(Fe(e))},[n])]}function et(){const{state:e,dispatch:n}=E();return[e.chat.isAnalyzeContent,t.useCallback(e=>{n(Ue(e))},[n])]}function tt(){const{state:e,dispatch:n}=E();return[e.chat.chatRecommendationList,t.useCallback(e=>{n(Ze(e))},[n])]}function nt(){const{state:e,dispatch:n}=E();return[e.chat.currentLoadingThreadId,t.useCallback(e=>{n(Ne(e))},[n])]}function rt(){const{state:e,dispatch:n}=E();return[e.chat.isShowThreadList,t.useCallback(e=>{n(Ye(e))},[n])]}function it(){const{state:e,dispatch:n}=E();return[e.chat.isRecording,t.useCallback(e=>{n(We(e))},[n])]}function ot(){const{state:e,dispatch:n}=E();return[e.chat.isHandleRecord,t.useCallback(e=>{n(Je(e))},[n])]}function st(){const{state:e,dispatch:n}=E();return[e.chat.realtimeText,t.useCallback(e=>{n(Ge(e))},[n])]}function at(){const{state:e,dispatch:n}=E();return[e.chat.shouldTriggerVoiceRecording,t.useCallback(e=>{n(Xe(e))},[n])]}function lt(){const{state:e,dispatch:n}=E();return[e.chat.threadsList,t.useCallback(e=>{n(Re(e))},[n])]}function ct(){const{state:e,dispatch:n}=E();return[e.chat.aiResponseContentList,t.useCallback(e=>{n(De(e))},[n])]}function ut(){const{state:e,dispatch:n}=E();return[e.chat.inputValue,t.useCallback(e=>{n(Le(e))},[n])]}function dt(){return t.useCallback(()=>{window.eventSourceStatue=!1,setTimeout(()=>{window.eventSourceStatue=!0},3e3)},[])}function ht(){const{state:e,dispatch:n}=E();return[e.chat.isLoadingData,t.useCallback(e=>{n(ze(e))},[n])]}function pt(){const e=t.useCallback(e=>new Promise(t=>{setTimeout(()=>{t(null)},e)}),[]),{dispatch:n}=E(),[,r]=$e(),[,i]=et();return t.useCallback(async({streamText:t,id:o=ve(),thoughtId:s,type:a=be.FINAL_ANSWER})=>{window.eventSourceStatue=!0;let l=0;const c=(e,n)=>{if(a===be.TEMP){const r=JSON.parse(t),{description:i}=r;return i?i.slice(5*e,5*n):""}return t.slice(5*e,5*n)};for(a===be.FINAL_ANSWER&&i(!1);c(l,l+1);){let r="";if(window.eventSourceStatue&&a!==be.SOURCE_LIST_DETAILS)if(a===be.TEMP){const e=JSON.parse(t),n=c(l,l+1);l+=1,r=JSON.stringify({id:s||ve(),tool_name:e.tool_name,tool_type:e.tool_type,description:n})}else r=c(l,l+1),l+=1;else r=c(l,l+1e9),l+=1e9;if(r){n(Oe({id:o,type:a,content:r,threadId:""})),a===be.FINAL_ANSWER?await e(17):await e(34)}}r(!1)},[e,n,r,i])}function ft(){const{dispatch:e}=E(),[n]=L(),[r]=z(),i=pt(),[,o]=lt(),s=ue(),[a,l]=me(),[,c]=function(){const{state:e,dispatch:n}=E();return[e.chat.currentRenderingId,t.useCallback(e=>{n(Pe(e))},[n])]}(),[,u]=$e(),[,d]=et(),[,h]=ht(),p=ce(),f=t.useCallback(()=>{var e;null==(e=window.abortController)||e.abort(),u(!1),d(!1),h(!1)},[u,d,h]);return t.useCallback(async({userValue:t,threadId:d})=>{let h=null;try{const f=N.restfulDomain;window.eventSourceStatue=!0;const m=[];let x=!1;const y=async()=>{if(!x&&0!==m.length){x=!0;try{for(;m.length>0;){const e=m.shift();e&&await e()}}catch(e){}finally{x=!1}}};window.abortController=new AbortController;const b=new URLSearchParams;b.append("user_id",r),b.append("thread_id",d),b.append("query",t);const v=await fetch(`${f}/chat`,{method:"POST",headers:{"ACCOUNT-ID":`${r||""}`,"ACCOUNT-API-KEY":`${n||""}`,"Content-Type":"application/x-www-form-urlencoded",Accept:"text/event-stream"},body:b,signal:window.abortController.signal});if(!v.ok)throw new Error(`HTTP error! status: ${v.status}`);if(!v.body)throw new Error("Response body is null");h=v.body.getReader();const w=new TextDecoder;let k="";for(;;){const{done:t,value:n}=await h.read();if(t)break;let d;for(k+=w.decode(n,{stream:!0});-1!==(d=k.indexOf("\n"));){const t=k.slice(0,d).trim();if(k=k.slice(d+1),""!==t)try{const n=JSON.parse(t);if(n.type!==be.ERROR)if(c(n.msg_id),n.type===be.END_THINKING)m.push(async()=>{if(u(!1),e(Ie()),!a){const e=(await p({telegramUserId:r})).map(e=>({threadId:e.thread_id,title:e.title,createdAt:e.created_at}));o(e),l(n.thread_id)}await s({threadId:a||n.thread_id,telegramUserId:r})}),y(),c("");else if(n.type===be.TEMP){const e=ve();m.push(async()=>{u(!0),await i({id:n.msg_id,thoughtId:e,type:n.type,streamText:t})}),y()}else n.type===be.SOURCE_LIST_DETAILS?(m.push(async()=>{u(!0),await i({id:n.msg_id,type:n.type,streamText:JSON.stringify(n.content)})}),y()):n.type===be.FINAL_ANSWER&&(m.push(async()=>{u(!0),await i({id:n.msg_id,type:n.type,streamText:n.content})}),y());else n.type===be.ERROR&&(m.push(async()=>{u(!0),await i({id:n.msg_id,type:n.type,streamText:n.content||""})}),y(),setTimeout(()=>{e(Ie())},1e3))}catch(g){}}}await y()}catch(m){f()}finally{if(h)try{h.releaseLock()}catch(x){}}},[a,n,r,e,s,i,o,c,l,p,u,f])}function gt(){const e=ft(),[,n]=ut(),[r]=me(),[i,o]=ht(),[,s]=et(),[a,l]=ct();return t.useCallback(async({value:t,nextAiResponseContentList:c})=>{if(t&&!i)try{o(!0),s(!0),l([...c||a,{id:`${ve()}`,content:t,feedback:null,thoughtContentList:[],sourceListDetails:[],role:ye.USER,timestamp:(new Date).getTime(),agentRecommendationList:[]}]),n(""),await e({threadId:r,userValue:t}),o(!1)}catch(u){o(!1)}},[i,a,r,s,l,o,n,e])}let mt=null;function xt(){return mt}function yt(){const[,e]=lt(),[,n]=me(),r=ce();return t.useCallback(async({telegramUserId:t})=>{try{if(t){const i=await r({telegramUserId:t}),o=i.map(e=>({threadId:e.thread_id,title:e.title,createdAt:e.created_at})),s=xt(),a=(null==s?void 0:s.chatcache.currentAiThreadId)||"";return a&&!o.some(e=>e.threadId===a)&&n(""),e(o),i}}catch(i){return i}},[n,e,r])}function bt(){const[e,n]=me(),r=(le(),t.useCallback(async({threadIds:e,telegramUserId:t})=>{try{const n=ae();return(await n.delete(`/batch_threads?user_id=${t}&thread_ids=${e.join(",")}`)).data}catch(n){throw n}},[]));return t.useCallback(async(t,i)=>{try{if(i){const o=await r({threadIds:t,telegramUserId:i});return e&&t.includes(e)&&n(""),o}}catch(o){return o}},[e,n,r])}function vt(){const[e]=ht(),n=dt(),r=function(){const{dispatch:e}=E();return t.useCallback(()=>{e(Be())},[e])}(),[i,o]=$e(),[,s]=ct(),[,a]=me();return t.useCallback(()=>{e||i||(n(),o(!1),a(""),s([]),r())},[e,i,r,a,s,n,o])}function wt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var kt,Ct,At,St={},Et={},Tt={exports:{}},Mt=Tt.exports;function jt(){return kt||(kt=1,t=Mt,n=function(){var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n="boolean"==typeof(new RegExp).sticky;function r(e){return e&&"[object RegExp]"===t.call(e)}function i(e){return e&&"object"==typeof e&&!r(e)&&!Array.isArray(e)}function o(e){return new RegExp("|"+e).exec("").length-1}function s(e){return"("+e+")"}function a(e){return e.length?"(?:"+e.map(function(e){return"(?:"+e+")"}).join("|")+")":"(?!)"}function l(e){if("string"==typeof e)return"(?:"+e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")+")";if(r(e)){if(e.ignoreCase)throw new Error("RegExp /i flag not allowed");if(e.global)throw new Error("RegExp /g flag is implied");if(e.sticky)throw new Error("RegExp /y flag is implied");if(e.multiline)throw new Error("RegExp /m flag is implied");return e.source}throw new Error("Not a pattern: "+e)}function c(e,t){return e.length>t?e:Array(t-e.length+1).join(" ")+e}function u(t,n){if(i(n)||(n={match:n}),n.include)throw new Error("Matching rules cannot also include states");var o={defaultType:t,lineBreaks:!!n.error||!!n.fallback,pop:!1,next:null,push:null,error:!1,fallback:!1,value:null,type:null,shouldThrow:!1};for(var s in n)e.call(n,s)&&(o[s]=n[s]);if("string"==typeof o.type&&t!==o.type)throw new Error("Type transform cannot be a string (type '"+o.type+"' for token '"+t+"')");var a=o.match;return o.match=Array.isArray(a)?a:a?[a]:[],o.match.sort(function(e,t){return r(e)&&r(t)?0:r(t)?-1:r(e)?1:t.length-e.length}),o}function d(e){return Array.isArray(e)?function(e){for(var t=[],n=0;n<e.length;n++){var r=e[n];if(r.include)for(var i=[].concat(r.include),o=0;o<i.length;o++)t.push({include:i[o]});else{if(!r.type)throw new Error("Rule has no type: "+JSON.stringify(r));t.push(u(r.type,r))}}return t}(e):function(e){for(var t=Object.getOwnPropertyNames(e),n=[],r=0;r<t.length;r++){var o=t[r],s=e[o],a=[].concat(s);if("include"!==o){var l=[];a.forEach(function(e){i(e)?(l.length&&n.push(u(o,l)),n.push(u(o,e)),l=[]):l.push(e)}),l.length&&n.push(u(o,l))}else for(var c=0;c<a.length;c++)n.push({include:a[c]})}return n}(e)}var h=u("error",{lineBreaks:!0,shouldThrow:!0});function p(e,t){for(var i=null,c=Object.create(null),u=!0,d=null,p=[],f=[],g=0;g<e.length;g++)e[g].fallback&&(u=!1);for(g=0;g<e.length;g++){var m=e[g];if(m.include)throw new Error("Inheritance is not allowed in stateless lexers");if(m.error||m.fallback){if(i)throw!m.fallback==!i.fallback?new Error("Multiple "+(m.fallback?"fallback":"error")+" rules not allowed (for token '"+m.defaultType+"')"):new Error("fallback and error are mutually exclusive (for token '"+m.defaultType+"')");i=m}var x=m.match.slice();if(u)for(;x.length&&"string"==typeof x[0]&&1===x[0].length;)c[x.shift().charCodeAt(0)]=m;if(m.pop||m.push||m.next){if(!t)throw new Error("State-switching options are not allowed in stateless lexers (for token '"+m.defaultType+"')");if(m.fallback)throw new Error("State-switching options are not allowed on fallback tokens (for token '"+m.defaultType+"')")}if(0!==x.length){u=!1,p.push(m);for(var y=0;y<x.length;y++){var b=x[y];if(r(b))if(null===d)d=b.unicode;else if(d!==b.unicode&&!1===m.fallback)throw new Error("If one rule is /u then all must be")}var v=a(x.map(l)),w=new RegExp(v);if(w.test(""))throw new Error("RegExp matches empty string: "+w);if(o(v)>0)throw new Error("RegExp has capture groups: "+w+"\nUse (?: … ) instead");if(!m.lineBreaks&&w.test("\n"))throw new Error("Rule should declare lineBreaks: "+w);f.push(s(v))}}var k=i&&i.fallback,C=n&&!k?"ym":"gm",A=n||k?"":"|";return!0===d&&(C+="u"),{regexp:new RegExp(a(f)+A,C),groups:p,fast:c,error:i||h}}function f(e,t,n){var r=e&&(e.push||e.next);if(r&&!n[r])throw new Error("Missing state '"+r+"' (in token '"+e.defaultType+"' of state '"+t+"')");if(e&&e.pop&&1!==+e.pop)throw new Error("pop must be 1 (in token '"+e.defaultType+"' of state '"+t+"')")}var g=function(e,t){this.startState=t,this.states=e,this.buffer="",this.stack=[],this.reset()};g.prototype.reset=function(e,t){return this.buffer=e||"",this.index=0,this.line=t?t.line:1,this.col=t?t.col:1,this.queuedToken=t?t.queuedToken:null,this.queuedText=t?t.queuedText:"",this.queuedThrow=t?t.queuedThrow:null,this.setState(t?t.state:this.startState),this.stack=t&&t.stack?t.stack.slice():[],this},g.prototype.save=function(){return{line:this.line,col:this.col,state:this.state,stack:this.stack.slice(),queuedToken:this.queuedToken,queuedText:this.queuedText,queuedThrow:this.queuedThrow}},g.prototype.setState=function(e){if(e&&this.state!==e){this.state=e;var t=this.states[e];this.groups=t.groups,this.error=t.error,this.re=t.regexp,this.fast=t.fast}},g.prototype.popState=function(){this.setState(this.stack.pop())},g.prototype.pushState=function(e){this.stack.push(this.state),this.setState(e)};var m=n?function(e,t){return e.exec(t)}:function(e,t){var n=e.exec(t);return 0===n[0].length?null:n};function x(){return this.value}if(g.prototype._getGroup=function(e){for(var t=this.groups.length,n=0;n<t;n++)if(void 0!==e[n+1])return this.groups[n];throw new Error("Cannot find token type for matched text")},g.prototype.next=function(){var e=this.index;if(this.queuedGroup){var t=this._token(this.queuedGroup,this.queuedText,e);return this.queuedGroup=null,this.queuedText="",t}var n=this.buffer;if(e!==n.length){if(s=this.fast[n.charCodeAt(e)])return this._token(s,n.charAt(e),e);var r=this.re;r.lastIndex=e;var i=m(r,n),o=this.error;if(null==i)return this._token(o,n.slice(e,n.length),e);var s=this._getGroup(i),a=i[0];return o.fallback&&i.index!==e?(this.queuedGroup=s,this.queuedText=a,this._token(o,n.slice(e,i.index),e)):this._token(s,a,e)}},g.prototype._token=function(e,t,n){var r=0;if(e.lineBreaks){var i=/\n/g,o=1;if("\n"===t)r=1;else for(;i.exec(t);)r++,o=i.lastIndex}var s={type:"function"==typeof e.type&&e.type(t)||e.defaultType,value:"function"==typeof e.value?e.value(t):t,text:t,toString:x,offset:n,lineBreaks:r,line:this.line,col:this.col},a=t.length;if(this.index+=a,this.line+=r,0!==r?this.col=a-o+1:this.col+=a,e.shouldThrow)throw new Error(this.formatError(s,"invalid syntax"));return e.pop?this.popState():e.push?this.pushState(e.push):e.next&&this.setState(e.next),s},"undefined"!=typeof Symbol&&Symbol.iterator){var y=function(e){this.lexer=e};y.prototype.next=function(){var e=this.lexer.next();return{value:e,done:!e}},y.prototype[Symbol.iterator]=function(){return this},g.prototype[Symbol.iterator]=function(){return new y(this)}}return g.prototype.formatError=function(e,t){if(null==e){var n=this.buffer.slice(this.index);e={text:n,offset:this.index,lineBreaks:-1===n.indexOf("\n")?0:1,line:this.line,col:this.col}}var r=Math.max(e.line-2,1),i=e.line+2,o=String(i).length,s=function(e,t){for(var n=e.length,r=0;;){var i=e.lastIndexOf("\n",n-1);if(-1===i)break;if(n=i,++r===t)break;if(0===n)break}var o=r<t?0:n+1;return e.substring(o).split("\n")}(this.buffer,this.line-e.line+2+1).slice(0,5),a=[];a.push(t+" at line "+e.line+" col "+e.col+":"),a.push("");for(var l=0;l<s.length;l++){var u=s[l],d=r+l;a.push(c(String(d),o)+" "+u),d===e.line&&a.push(c("",o+e.col+1)+"^")}return a.join("\n")},g.prototype.clone=function(){return new g(this.states,this.state)},g.prototype.has=function(e){return!0},{compile:function(e){var t=p(d(e));return new g({start:t},"start")},states:function(e,t){var n=e.$all?d(e.$all):[];delete e.$all;var r=Object.getOwnPropertyNames(e);t||(t=r[0]);for(var i=Object.create(null),o=0;o<r.length;o++)i[b=r[o]]=d(e[b]).concat(n);for(o=0;o<r.length;o++)for(var s=i[b=r[o]],a=Object.create(null),l=0;l<s.length;l++){var c=s[l];if(c.include){var u=[l,1];if(c.include!==b&&!a[c.include]){a[c.include]=!0;var h=i[c.include];if(!h)throw new Error("Cannot include nonexistent state '"+c.include+"' (in state '"+b+"')");for(var m=0;m<h.length;m++){var x=h[m];-1===s.indexOf(x)&&u.push(x)}}s.splice.apply(s,u),l--}}var y=Object.create(null);for(o=0;o<r.length;o++){var b;y[b=r[o]]=p(i[b],!0)}for(o=0;o<r.length;o++){var v=r[o],w=y[v],k=w.groups;for(l=0;l<k.length;l++)f(k[l],v,y);var C=Object.getOwnPropertyNames(w.fast);for(l=0;l<C.length;l++)f(w.fast[C[l]],v,y)}return new g(y,t)},error:Object.freeze({error:!0}),fallback:Object.freeze({fallback:!0}),keywords:function(e){for(var t="undefined"!=typeof Map,n=t?new Map:Object.create(null),r=Object.getOwnPropertyNames(e),i=0;i<r.length;i++){var o=r[i],s=e[o];(Array.isArray(s)?s:[s]).forEach(function(e){if("string"!=typeof e)throw new Error("keyword must be string (in keyword '"+o+"')");t?n.set(e,o):n[e]=o})}return function(e){return t?n.get(e):n[e]}}}},(e=Tt).exports?e.exports=n():t.moo=n()),Tt.exports;var e,t,n}function Ot(){return Ct||(Ct=1,function(e){var t=Et&&Et.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.lexer=e.states=void 0;const n=t(jt());e.states={body:{doubleapos:{match:"''",value:()=>"'"},quoted:{lineBreaks:!0,match:/'[{}#](?:[^']|'')*'(?!')/u,value:e=>e.slice(1,-1).replace(/''/g,"'")},argument:{lineBreaks:!0,match:/\{\s*[^\p{Pat_Syn}\p{Pat_WS}]+\s*/u,push:"arg",value:e=>e.substring(1).trim()},octothorpe:"#",end:{match:"}",pop:1},content:{lineBreaks:!0,match:/[^][^{}#']*/u}},arg:{select:{lineBreaks:!0,match:/,\s*(?:plural|select|selectordinal)\s*,\s*/u,next:"select",value:e=>e.split(",")[1].trim()},"func-args":{lineBreaks:!0,match:/,\s*[^\p{Pat_Syn}\p{Pat_WS}]+\s*,/u,next:"body",value:e=>e.split(",")[1].trim()},"func-simple":{lineBreaks:!0,match:/,\s*[^\p{Pat_Syn}\p{Pat_WS}]+\s*/u,value:e=>e.substring(1).trim()},end:{match:"}",pop:1}},select:{offset:{lineBreaks:!0,match:/\s*offset\s*:\s*\d+\s*/u,value:e=>e.split(":")[1].trim()},case:{lineBreaks:!0,match:/\s*(?:=\d+|[^\p{Pat_Syn}\p{Pat_WS}]+)\s*\{/u,push:"body",value:e=>e.substring(0,e.indexOf("{")).trim()},end:{match:/\s*\}/u,pop:1}}},e.lexer=n.default.states(e.states)}(Et)),Et}function It(){if(At)return St;At=1,Object.defineProperty(St,"__esModule",{value:!0}),St.ParseError=void 0,St.parse=function(e,t={}){return new s(e,t).parse()};const e=Ot(),t=e=>({offset:e.offset,line:e.line,col:e.col,text:e.text,lineBreaks:e.lineBreaks}),n=e=>"plural"===e||"select"===e||"selectordinal"===e;const r=["number","date","time","spellout","ordinal","duration"],i=["zero","one","two","few","many","other"];class o extends Error{constructor(t,n){super(e.lexer.formatError(t,n))}}St.ParseError=o;class s{constructor(t,n){var r,o,s,a;this.lexer=e.lexer.reset(t),this.cardinalKeys=null!==(r=null==n?void 0:n.cardinal)&&void 0!==r?r:i,this.ordinalKeys=null!==(o=null==n?void 0:n.ordinal)&&void 0!==o?o:i,this.strict=null!==(s=null==n?void 0:n.strict)&&void 0!==s&&s,this.strictPluralKeys=null===(a=null==n?void 0:n.strictPluralKeys)||void 0===a||a}parse(){return this.parseBody(!1,!0)}checkSelectKey(e,t,n){if("="===n[0]){if("select"===t)throw new o(e,`The case ${n} is not valid with select`)}else if("select"!==t){const r="plural"===t?this.cardinalKeys:this.ordinalKeys;if(this.strictPluralKeys&&r.length>0&&!r.includes(n)){throw new o(e,`The ${t} case ${n} is not valid in this locale`)}}}parseSelect({value:e},n,r,i){const s={type:i,arg:e,cases:[],ctx:r};"plural"===i||"selectordinal"===i?n=!0:this.strict&&(n=!1);for(const a of this.lexer)switch(a.type){case"offset":if("select"===i)throw new o(a,"Unexpected plural offset for select");if(s.cases.length>0)throw new o(a,"Plural offset must be set before cases");s.pluralOffset=Number(a.value),r.text+=a.text,r.lineBreaks+=a.lineBreaks;break;case"case":this.checkSelectKey(a,i,a.value),s.cases.push({key:a.value,tokens:this.parseBody(n),ctx:t(a)});break;case"end":return s;default:throw new o(a,`Unexpected lexer token: ${a.type}`)}throw new o(null,"Unexpected message end")}parseArgToken(e,i){const s=t(e),a=this.lexer.next();if(!a)throw new o(null,"Unexpected message end");if(s.text+=a.text,s.lineBreaks+=a.lineBreaks,this.strict&&("func-simple"===a.type||"func-args"===a.type)&&!r.includes(a.value)){const t=`Invalid strict mode function arg type: ${a.value}`;throw new o(e,t)}switch(a.type){case"end":return{type:"argument",arg:e.value,ctx:s};case"func-simple":{const t=this.lexer.next();if(!t)throw new o(null,"Unexpected message end");if("end"!==t.type)throw new o(t,`Unexpected lexer token: ${t.type}`);if(s.text+=t.text,n(a.value.toLowerCase()))throw new o(a,`Invalid type identifier: ${a.value}`);return{type:"function",arg:e.value,key:a.value,ctx:s}}case"func-args":{if(n(a.value.toLowerCase())){const e=`Invalid type identifier: ${a.value}`;throw new o(a,e)}let t=this.parseBody(!this.strict&&i);return this.strict&&t.length>0&&(t=function(e,t){let n="",r="";for(const i of t){const t=i.ctx.text;switch(r+=t,i.type){case"content":n+=i.value;break;case"argument":case"function":case"octothorpe":n+=t;break;default:throw new o(e,`Unsupported part in strict mode function arg style: ${t}`)}}return[{type:"content",value:n.trim(),ctx:Object.assign({},t[0].ctx,{text:r})}]}(e,t)),{type:"function",arg:e.value,key:a.value,param:t,ctx:s}}case"select":if(n(a.value))return this.parseSelect(e,i,s,a.value);throw new o(a,`Unexpected select type ${a.value}`);default:throw new o(a,`Unexpected lexer token: ${a.type}`)}}parseBody(e,n){const r=[];let i=null;for(const s of this.lexer)if("argument"===s.type)i&&(i=null),r.push(this.parseArgToken(s,e));else if("octothorpe"===s.type&&e)i&&(i=null),r.push({type:"octothorpe",ctx:t(s)});else{if("end"===s.type&&!n)return r;{let n=s.value;if(!e&&"quoted"===s.type&&"#"===n[0]){if(n.includes("{")){throw new o(s,`Unsupported escape pattern: ${n}`)}n=s.text}i?(i.value+=n,i.ctx.text+=s.text,i.ctx.lineBreaks+=s.lineBreaks):(i={type:"content",value:n,ctx:t(s)},r.push(i))}}if(n)return r;throw new o(null,"Unexpected message end")}}return St}var Dt=It();class Lt extends Error{constructor(e,t,n){super(e),this.token=t,this.type=n||"error"}}const zt=e=>e<4?"short":4===e?"long":"narrow",Ft=e=>e%2==0?"2-digit":"numeric";function Rt(e,t){switch(e.width){case 1:return"numeric";case 2:return"2-digit";case 3:return"short";case 4:return"long";case 5:return"narrow";default:return void t(`${e.desc} is not supported with width ${e.width}`)}}function Pt(e,t){const{char:n,desc:r,width:i}=e;return"d"===n?Ft(i):void t(`${r} is not supported`)}function Nt(e,t){const{char:n,desc:r,width:i}=e;if(("c"===n||"e"===n)&&i<3){t(`Numeric value is not supported for ${r}; falling back to weekday:short`,Lt.WARNING)}return zt(i)}function Bt(e,t){const{char:n,desc:r,width:i}=e;switch(n){case"v":case"z":return 4===i?"long":"short";case"V":return 4===i?"long":void t(`${r} is not supported with width ${i}`);case"X":return void t(`${r} is not supported`)}return"short"}function Ut(e,t){switch(e.field){case"era":return{era:zt(e.width)};case"year":return function(e,t){switch(e.char){case"y":return{year:Ft(e.width)};case"r":return{calendar:"gregory",year:"numeric"};default:return t(`${e.desc} is not supported; falling back to year:numeric`,Lt.WARNING),{year:"numeric"}}}(e,t);case"month":return{month:Rt(e,t)};case"day":return{day:Pt(e,t)};case"weekday":return{weekday:Nt(e,t)};case"period":return;case"hour":return function(e){const t=Ft(e.width);let n;switch(e.char){case"h":n="h12";break;case"H":n="h23";break;case"k":n="h24";break;case"K":n="h11"}return n?{hour:t,hourCycle:n}:{hour:t}}(e);case"min":return{minute:Ft(e.width)};case"sec":return{second:Ft(e.width)};case"tz":return{timeZoneName:Bt(e,t)};case"quarter":case"week":case"sec-frac":case"ms":t(`${e.desc} is not supported`)}}const Ht={G:{field:"era",desc:"Era"},y:{field:"year",desc:"Year"},Y:{field:"year",desc:'Year of "Week of Year"'},u:{field:"year",desc:"Extended year"},U:{field:"year",desc:"Cyclic year name"},r:{field:"year",desc:"Related Gregorian year"},Q:{field:"quarter",desc:"Quarter"},q:{field:"quarter",desc:"Stand-alone quarter"},M:{field:"month",desc:"Month in year"},L:{field:"month",desc:"Stand-alone month in year"},w:{field:"week",desc:"Week of year"},W:{field:"week",desc:"Week of month"},d:{field:"day",desc:"Day in month"},D:{field:"day",desc:"Day of year"},F:{field:"day",desc:"Day of week in month"},g:{field:"day",desc:"Modified julian day"},E:{field:"weekday",desc:"Day of week"},e:{field:"weekday",desc:"Local day of week"},c:{field:"weekday",desc:"Stand-alone local day of week"},a:{field:"period",desc:"AM/PM marker"},b:{field:"period",desc:"AM/PM/noon/midnight marker"},B:{field:"period",desc:"Flexible day period"},h:{field:"hour",desc:"Hour in AM/PM (1~12)"},H:{field:"hour",desc:"Hour in day (0~23)"},k:{field:"hour",desc:"Hour in day (1~24)"},K:{field:"hour",desc:"Hour in AM/PM (0~11)"},j:{field:"hour",desc:"Hour in preferred cycle"},J:{field:"hour",desc:"Hour in preferred cycle without marker"},C:{field:"hour",desc:"Hour in preferred cycle with flexible marker"},m:{field:"min",desc:"Minute in hour"},s:{field:"sec",desc:"Second in minute"},S:{field:"sec-frac",desc:"Fractional second"},A:{field:"ms",desc:"Milliseconds in day"},z:{field:"tz",desc:"Time Zone: specific non-location"},Z:{field:"tz",desc:"Time Zone"},O:{field:"tz",desc:"Time Zone: localized"},v:{field:"tz",desc:"Time Zone: generic non-location"},V:{field:"tz",desc:"Time Zone: ID"},X:{field:"tz",desc:"Time Zone: ISO8601 with Z"},x:{field:"tz",desc:"Time Zone: ISO8601"}},Zt=e=>e>="A"&&e<="Z"||e>="a"&&e<="z";function Yt(e,t){const n=e[t];if(!n)return null;if(Zt(n))return function(e,t){const n=e[t];let r=1;for(;e[++t]===n;)++r;const i=Ht[n];if(!i)return{char:n,error:new Error(`The letter ${n} is not a valid field identifier`),width:r};return{char:n,field:i.field,desc:i.desc,width:r}}(e,t);if("'"===n)return function(e,t){let n=e[++t],r=2;if("'"===n)return{char:"'",str:n,width:r};for(;;){const i=e[++t];if(++r,void 0===i)return{char:"'",error:new Error(`Unterminated quoted literal in pattern: ${n||e}`),str:n,width:r};if("'"===i){if("'"!==e[++t])return{char:"'",str:n,width:r};++r}n+=i}}(e,t);let r=n,i=1;for(;;){const o=e[++t];if(!o||Zt(o)||"'"===o)return{char:n,str:r,width:i};r+=o,i+=1}}function Vt(e,t){return e.filter(e=>"content"!==e.type).length?e.map(e=>{var n;if("content"===e.type)return t(e.value);if("octothorpe"===e.type)return"#";if("argument"===e.type)return[e.arg];if("function"===e.type){const t=null==(n=null==e?void 0:e.param)?void 0:n[0];if("date"===e.key&&t){const n=function(e,t){if(/^::/.test(e)){const n=function(e){const t=[];let n=0;for(;;){const r=Yt(e,n);if(!r)return t;t.push(r),n+=r.width}}(e.substring(2));return function(e,t,n=e=>{throw e}){const r={timeZone:t},i=[];for(const o of e){const{error:e,field:t,str:s}=o;if(e){const t=new Lt(e.message,o);t.stack=e.stack,n(t)}s&&n(new Lt(`Ignoring string part: ${s}`,o,Lt.WARNING)),t&&(-1===i.indexOf(t)?i.push(t):n(new Lt(`Duplicate ${t} token`,o)));const a=Ut(o,(e,t)=>n(new Lt(e,o,t)));a&&Object.assign(r,a)}return r}(n,void 0,t)}return e}(t.value.trim(),e=>{throw new Error(`Unable to compile date expression: ${e.message}`)});return[e.arg,e.key,n]}return t?[e.arg,e.key,t.value.trim()]:[e.arg,e.key]}const r=e.pluralOffset,i={};return e.cases.forEach(({key:e,tokens:n})=>{const r="="===e[0]?e.slice(1):e;i[r]=Vt(n,t)}),[e.arg,e.type,{offset:r,...i}]}):e.map(e=>t(e.value))}function qt(e,t=e=>e){try{return function(e,t=e=>e){return Vt(Dt.parse(e),t)}(e,t)}catch(n){return[e]}}const Wt=e=>"string"==typeof e,Jt=new Map;function Gt(e){return[...Array.isArray(e)?e:[e],"en"]}function Kt(e,t,n){const r=Gt(e);let i;if(n||(n="default"),"string"==typeof n)switch(i={day:"numeric",month:"short",year:"numeric"},n){case"full":i.weekday="long";case"long":i.month="long";break;case"short":i.month="numeric"}else i=n;return _t(()=>$t("date",r,n),()=>new Intl.DateTimeFormat(r,i)).format(Wt(t)?new Date(t):t)}function Qt(e,t,n){const r=Gt(e);return _t(()=>$t("number",r,n),()=>new Intl.NumberFormat(r,n)).format(t)}function Xt(e,t,n,{offset:r=0,...i}){const o=Gt(e),s=t?_t(()=>$t("plural-ordinal",o),()=>new Intl.PluralRules(o,{type:"ordinal"})):_t(()=>$t("plural-cardinal",o),()=>new Intl.PluralRules(o,{type:"cardinal"}));return i[n]??i[s.select(n-r)]??i.other}function _t(e,t){const n=e();let r=Jt.get(n);return r||(r=t(),Jt.set(n,r)),r}function $t(e,t,n){return`${e}-${t.join("-")}-${JSON.stringify(n)}`}const en=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/,tn=e=>e.replace(/\\u([a-fA-F0-9]{4})|\\x([a-fA-F0-9]{2})/g,(e,t,n)=>{if(t){const e=parseInt(t,16);return String.fromCharCode(e)}{const e=parseInt(n,16);return String.fromCharCode(e)}}),nn="%__lingui_octothorpe__%",rn=(e,t,n={})=>{const r=t||e,i=e=>"object"==typeof e?e:n[e],o=(e,t)=>{const o=Object.keys(n).length?i("number"):void 0,s=Qt(r,e,o);return t.replace(new RegExp(nn,"g"),s)};return{plural:(e,t)=>{const{offset:n=0}=t,i=Xt(r,!1,e,t);return o(e-n,i)},selectordinal:(e,t)=>{const{offset:n=0}=t,i=Xt(r,!0,e,t);return o(e-n,i)},select:on,number:(e,t)=>Qt(r,e,i(t)||{style:t}),date:(e,t)=>Kt(r,e,i(t)||t),time:(e,t)=>function(e,t,n){let r;if(n||(n="default"),"string"==typeof n)switch(r={second:"numeric",minute:"numeric",hour:"numeric"},n){case"full":case"long":r.timeZoneName="short";break;case"short":delete r.second}else r=n;return Kt(e,t,r)}(r,e,i(t)||t)}},on=(e,t)=>t[e]??t.other;var sn=Object.defineProperty,an=(e,t,n)=>(((e,t,n)=>{t in e?sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n})(e,t+"",n),n);class