Files
ai-agent/web/public/sdk/cs-ai-agent-sdk.min.js
T

2 lines
10 KiB
JavaScript
Raw Normal View History

var __rest=this&&this.__rest||function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n};function getWidgetLocale(){var e,t;try{return((null===(e=window.localStorage)||void 0===e?void 0:e.getItem("cs_ai_agent_locale"))||document.documentElement.lang||(null===(t=window.navigator)||void 0===t?void 0:t.language)||"").toLowerCase().startsWith("en")?"en-US":"zh-CN"}catch(e){return"zh-CN"}}function getDefaultWidgetTitle(){return"en-US"===getWidgetLocale()?"Support":"\u5728\u7ebf\u5ba2\u670d"}function getLauncherText(){return"en-US"===getWidgetLocale()?"Support":"\u5ba2\u670d"}!function(){const e={position:"right",themeColor:"#0f6cbd",width:"380px"},t=window.__CS_AI_AGENT_WIDGET_STATE__,n=t||{button:null,frame:null,frameLoaded:!1,frameReady:!1,initSent:!1,isOpen:!1,isMaximized:!1,configLoading:!1,frameHideTimer:null,frameDestroyTimer:null,config:null,frameConfig:null,frameUrl:null,animationDuration:260};function i(t){const n=Object.assign(Object.assign({},e),t||{});return n.baseUrl=String(n.baseUrl||window.location.origin).replace(/\/$/,""),n.apiBaseUrl?n.apiBaseUrl=String(n.apiBaseUrl).replace(/\/$/,""):delete n.apiBaseUrl,n.channelId=String(n.channelId||""),n.externalId&&(n.externalId=String(n.externalId)),"function"!=typeof n.getUserToken&&delete n.getUserToken,n}function r(e){const t=document.currentScript;return(null==t?void 0:t.src)?t.src.replace(/\/sdk\/cs-ai-agent-sdk\.min\.js(?:\?.*)?$/,""):String(e.widgetBaseUrl||e.baseUrl||window.location.origin).replace(/\/$/,"")}function a(e,t){const{getUserToken:n}=e,i=__rest(e,["getUserToken"]);return t?Object.assign(Object.assign({},i),{userToken:t}):i}function o(){return function(){const e=n.config;if("function"!=typeof(null==e?void 0:e.getUserToken))return Promise.resolve("");try{return Promise.resolve(e.getUserToken()).then(e=>String(e||"").trim())}catch(e){return Promise.reject(e)}}().then(e=>{if(!n.config)throw new Error("channelId is required");return n.frameUrl=function(e,t){const n=r(e),i=new URL(`${n}/support/chat/`);return i.searchParams.set("channelId",e.channelId),i.searchParams.set("baseUrl",e.baseUrl),e.apiBaseUrl&&i.searchParams.set("apiBaseUrl",e.apiBaseUrl),e.externalId&&i.searchParams.set("externalId",e.externalId),e.externalName&&i.searchParams.set("externalName",e.externalName),t&&i.searchParams.set("userToken",t),i}(n.config,e),n.frameConfig=a(n.config,e),n.frameUrl})}function s(){n.frameHideTimer&&(window.clearTimeout(n.frameHideTimer),n.frameHideTimer=null),n.frameDestroyTimer&&(window.clearTimeout(n.frameDestroyTimer),n.frameDestroyTimer=null)}function l(){const e=n.frame,t=n.config;if(e&&t){if(e.style.position="fixed",e.style.border="0",e.style.overflow="hidden",e.style.background="#fff",e.style.zIndex="2147483000",e.style.boxShadow="0 28px 80px rgba(15, 35, 65, 0.28)",e.style.willChange="top,right,bottom,left,width,height,opacity,transform,border-radius",e.style.transition="top 260ms cubic-bezier(0.22, 1, 0.36, 1), right 260ms cubic-bezier(0.22, 1, 0.36, 1), bottom 260ms cubic-bezier(0.22, 1, 0.36, 1), left 260ms cubic-bezier(0.22, 1, 0.36, 1), width 260ms cubic-bezier(0.22, 1, 0.36, 1), height 260ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease, transform 260ms cubic-bezier(0.22, 1, 0.36, 1), border-radius 260ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 260ms ease",e.style.transformOrigin="left"===t.position?"left bottom":"right bottom",n.isMaximized)return e.style.top="max(12px, env(safe-area-inset-top))",e.style.right="max(12px, env(safe-area-inset-right))",e.style.bottom="max(12px, env(safe-area-inset-bottom))",e.style.left="max(12px, env(safe-area-inset-left))",e.style.width="calc(100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)))",e.style.maxWidth="none",e.style.height="calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-