@cloudbase/js-sdk
Version:
cloudbase javascript sdk
2 lines • 567 kB
JavaScript
/*! For license information please see index.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase",[],e):"object"==typeof exports?exports.cloudbase=e():t.cloudbase=e()}("undefined"!=typeof window?window:this,(function(){return function(){var t={2829:function(t,e,r){"use strict";var n;r.r(e),r.d(e,{AbstractSDKRequest:function(){return o},AbstractStorage:function(){return i},StorageType:function(){return n},formatUrl:function(){return s}}),function(t){t.local="local",t.none="none",t.session="session"}(n||(n={}));var o=function(){},i=function(){};function s(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),o="";for(var i in r)""===o?!n&&(e+="?"):o+="&",o+=i+"="+encodeURIComponent(r[i]);return/^http(s)?\:\/\//.test(e+=o)?e:""+t+e}},190:function(t,e,r){"use strict";var n,o=r(2829),i=r(5993),s=(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},n(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),a=function(){return a=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},a.apply(this,arguments)},u="Error when aborting requestTask",c=function(t){function e(e){void 0===e&&(e={});var r=t.call(this)||this,n=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return r._timeout=n||0,r._timeoutMsg=o||"请求超时",r._restrictedMethods=i||["get","post","upload","download"],r}return s(e,t),e.prototype.post=function(t){var e=this;return new Promise((function(r,n){var i=t.url,s=t.data,a=t.headers,u=wx.request({url:(0,o.formatUrl)("https:",i),data:s,timeout:e._timeout,method:"POST",header:a,success:function(t){t.statusCode>=200&&t.statusCode<300?r({statusCode:t.statusCode,status:t.statusCode,data:t.data}):n(t)},fail:function(t){n(t)},complete:function(t){if(t&&t.errMsg&&e._timeout&&-1!==e._restrictedMethods.indexOf("post")&&"request:fail timeout"===t.errMsg){console.warn(e._timeoutMsg);try{u.abort()}catch(t){}}}})}))},e.prototype.get=function(t){var e=this;return new Promise((function(r,n){var i=t.url,s=t.body,a=t.headers,c=(0,o.formatUrl)("https:",i),l=wx.request({url:c,data:s,timeout:e._timeout,method:"GET",header:a,success:function(t){t.statusCode>=200&&t.statusCode<300?r({statusCode:t.statusCode,status:t.statusCode,data:t.data}):n(t)},fail:function(t){n(t)},complete:function(t){if(t&&t.errMsg&&e._timeout&&-1!==e._restrictedMethods.indexOf("get")&&t.errMsg.includes("timeout")){console.warn(e._timeoutMsg);try{l.abort()}catch(t){console.warn(u,t)}}}})}))},e.prototype.upload=function(t){var e=this,r=this;return new Promise((function(n){return o=e,i=void 0,u=function(){var e,o,i,s,u,c;return function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}(this,(function(l){return e=t.url,o=t.file,i=t.data,s=t.headers,u=t.onUploadProgress,c=wx.uploadFile({url:e,filePath:o,name:"file",formData:a({},i),header:s,timeout:this._timeout,success:function(t){var e={statusCode:t.statusCode,data:t.data||{}};200===t.statusCode&&i.success_action_status&&(e.statusCode=parseInt(i.success_action_status,10)),n(e)},fail:function(t){n(t)},complete:function(t){if(t&&t.errMsg&&r._timeout&&-1!==r._restrictedMethods.indexOf("upload")&&"request:fail timeout"===t.errMsg){console.warn(r._timeoutMsg);try{c.abort()}catch(t){}}}}),u&&c.onProgressUpdate((function(t){u(t)})),[2]}))},new((s=void 0)||(s=Promise))((function(t,e){function r(t){try{a(u.next(t))}catch(t){e(t)}}function n(t){try{a(u.throw(t))}catch(t){e(t)}}function a(e){var o;e.done?t(e.value):(o=e.value,o instanceof s?o:new s((function(t){t(o)}))).then(r,n)}a((u=u.apply(o,i||[])).next())}));var o,i,s,u}))},e.prototype.download=function(t){var e=this,r=this;return new Promise((function(n,i){var s=t.url,a=t.headers,u=wx.downloadFile({url:(0,o.formatUrl)("https:",s),header:a,timeout:e._timeout,success:function(t){200===t.statusCode&&t.tempFilePath?n({statusCode:200,tempFilePath:t.tempFilePath}):n(t)},fail:function(t){i(t)},complete:function(t){if(t&&t.errMsg&&r._timeout&&-1!==r._restrictedMethods.indexOf("download")&&"request:fail timeout"===t.errMsg){console.warn(r._timeoutMsg);try{u.abort()}catch(t){}}}})}))},e.prototype.fetch=function(t){var e=t.url,r=t.body,n=t.enableAbort,s=t.headers,a=t.method,c=t.stream,l=void 0!==c&&c,f=t.signal,h=t.timeout,d=this,p=null!=h?h:this._timeout,y=null,v=new i.Pz({start:function(t){y=t},cancel:function(){y=null}});return new Promise((function(t,i){l&&t({data:v});var c=wx.request({url:(0,o.formatUrl)("https:",e),data:r,timeout:p,method:a.toUpperCase(),header:s,success:function(e){var r;null===(r=y)||void 0===r||r.close(),!l&&t(e)},fail:function(t){var e;if(null===(e=y)||void 0===e||e.close(),i(t),l)throw t},complete:function(t){if(t&&t.errMsg&&p&&-1!==d._restrictedMethods.indexOf("post")&&n&&"request:fail timeout"===t.errMsg){console.warn(d._timeoutMsg);try{c.abort()}catch(t){console.warn(u,t)}}},enableChunked:l});if(c.onChunkReceived((function(t){var e;null===(e=y)||void 0===e||e.enqueue(new Uint8Array(t.data))})),f){var h=function(){try{c.abort()}catch(t){console.warn(u,t)}};f.aborted?h():f.addEventListener("abort",(function(){return h()}))}}))},e}(o.AbstractSDKRequest),l={setItem:function(t,e){wx.setStorageSync(t,e)},getItem:function(t){return wx.getStorageSync(t)},removeItem:function(t){wx.removeStorageSync(t)},clear:function(){wx.clearStorageSync()}},f=function(t,e){void 0===e&&(e={});var r=wx.connectSocket(a({url:t},e));return{set onopen(t){r.onOpen(t)},set onmessage(t){r.onMessage(t)},set onclose(t){r.onClose(t)},set onerror(t){r.onError(t)},send:function(t){return r.send({data:t})},close:function(t,e){return r.close({code:t,reason:e})},get readyState(){return r.readyState},CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3}},h={genAdapter:function(t){return{root:{globalThis:{}},reqClass:c,wsClass:f,captchaOptions:{openURIWithCallback:function(e){var r=t.EventBus,n={},o=e;console.log("openURIWithCallback",e);var i=e.match(/^(data:.*?)(\?[^#\s]*)?$/);if(i){o=i[1],console.log("openURIWithCallback url",o);var s=i[2];s&&(n=function(t){var e={},r=t.replace(/^[?#]/,"");return r?(r.split("&").forEach((function(t){var r=t.split("="),n=r[0],o=r[1];n=decodeURIComponent(n),o=decodeURIComponent(o),n&&(e[n]?Array.isArray(e[n])?e[n].push(o):e[n]=[e[n],o]:e[n]=o)})),e):e}(s))}console.log("openURIWithCallback queryObj",n);var u=n.token,c=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}(n,["token"]);return/^data:/.test(o)&&!u?Promise.reject({error:"invalid_argument",error_description:"invalie captcha data: "+e}):u?new Promise((function(t){console.log("wait for captcha..."),r.$emit("CAPTCHA_DATA_CHANGE",a(a({},c),{token:u,url:o})),r.$once("RESOLVE_CAPTCHA_DATA",(function(e){t(e)}))})):Promise.reject({error:"unimplemented",error_description:"need to impl captcha data"})}},localStorage:l,primaryStorage:o.StorageType.local,getAppSign:function(){var t=wx.getAccountInfoSync();return"undefined"!=typeof App||"undefined"!=typeof getApp||wx.onAppHide||wx.offAppHide||wx.onAppShow||wx.offAppShow?t&&t.miniProgram?t.miniProgram.appId:"":t&&t.plugin?t.plugin.appId:""}}},isMatch:function(){if("undefined"==typeof wx)return!1;if("undefined"==typeof Page)return!1;if(!wx.getSystemInfoSync)return!1;if(!wx.getStorageSync)return!1;if(!wx.setStorageSync)return!1;if(!wx.connectSocket)return!1;if(!wx.request)return!1;try{if(!wx.getSystemInfoSync())return!1;if("qq"===wx.getSystemInfoSync().AppPlatform)return!1}catch(t){return!1}return!0},runtime:"wx_mp"};e.ZP=h},5304:function(t,e){!function(t){"use strict";var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},e(t,r)};var r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function n(t,e,r,n){return new(r||(r=Promise))((function(e,o){function i(t){try{a(n.next(t))}catch(t){o(t)}}function s(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(t){t(n)}))).then(i,s)}a((n=n.apply(t,[])).next())}))}function o(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}var i=function(t){function r(e,r){var n=t.call(this,e)||this;return n.name="WxCloudSDKError",n.code=null==r?void 0:r.code,n.requestId=null==r?void 0:r.requestId,n.originError=null==r?void 0:r.originError,n}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(r,t),r}(Error);function s(){return"undefined"!=typeof window&&window||"undefined"!=typeof globalThis&&globalThis}function a(){try{var t=s();if(!t)return;return"undefined"==typeof wx?s().location.href:t.__wxRoute}catch(t){}}var u=function(t){var e=t.dataSourceName,r=t.methodName,u=t.params,c=t.realMethodName,l=t.callFunction,f=t.envType,h=void 0===f?"prod":f,d=t.mode;return n(void 0,0,void 0,(function(){var t,n,f,p,y,v;return o(this,(function(o){switch(o.label){case 0:t={data:{},requestId:""},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,l({name:"lowcode-datasource",data:{dataSourceName:e,methodName:r,params:u,userAgent:(m=s(),(null==m?void 0:m.navigator)?m.navigator.userAgent:"undefined"!=typeof wx&&wx.getSystemInfo?(wx.getSystemInfo({success:function(t){t&&(g=["brand","model","version","system","platform","SDKVersion","language"].map((function(e){return"".concat(e,": ").concat(t[e])})).join(", "))}}),g):void 0),referrer:a(),"x-sdk-version":"1.5.0",envType:h,mode:d}})];case 2:if(n=o.sent(),f=(null===(y=null==n?void 0:n.result)||void 0===y?void 0:y.requestId)||(null==n?void 0:n.requestId)||(null==n?void 0:n.requestID),null==n?void 0:n.result.code)throw new i("【错误】".concat(null==n?void 0:n.result.message,"\n【操作】调用 models.").concat(e?"".concat(e,"."):"").concat(c,"\n【错误码】").concat(null==n?void 0:n.result.code,"\n【请求ID】").concat(f||"N/A"),{code:null==n?void 0:n.result.code,requestId:f});return t.data=(null===(v=null==n?void 0:n.result)||void 0===v?void 0:v.data)||{},t.requestId=f,[3,4];case 3:throw"WxCloudSDKError"===(p=o.sent()).name?p:(console.log(p),new i("【错误】".concat(p.message,"\n 【操作】调用 models.").concat(e?"".concat(e,"."):"").concat(c,"\n 【请求ID】N/A"),{code:"UnknownError",originError:p}));case 4:return[2,t]}var g,m}))}))},c=function(t){var e=t.sql,r=t.params,i=t.config,s=t.callFunction,a=t.unsafe,c=void 0!==a&&a;return n(void 0,0,void 0,(function(){return o(this,(function(t){return[2,u({realMethodName:"$runSQL",methodName:"callWedaApi",params:{action:"RunMysqlCommand",data:{sqlTemplate:e,config:i,parameter:c?"":Object.entries(r||{}).reduce((function(t,e){var r=e[0],n=e[1];if(void 0!==n){var o="OBJECT";switch(typeof n){case"boolean":o="BOOLEAN";break;case"number":o="NUMBER";break;case"string":o="STRING";break;default:o=Array.isArray(n)?"ARRAY":"OBJECT"}t.push({key:r,type:o,value:"STRING"===o?n:JSON.stringify(n)})}return t}),[])||[]}},callFunction:s,mode:"sdk"})]}))}))},l=function(t){return{$runSQL:function(e,i,s){return n(this,0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,c({sql:e,params:i,config:r(r({},s),{preparedStatements:!0}),callFunction:t})];case 1:return[2,n.sent()]}}))}))},$runSQLRaw:function(e,i){return n(this,0,void 0,(function(){return o(this,(function(n){switch(n.label){case 0:return[4,c({sql:e,params:[],config:r(r({},i),{preparedStatements:!1}),callFunction:t})];case 1:return[2,n.sent()]}}))}))}}},f={create:{methodName:"wedaCreateV2"},createMany:{methodName:"wedaBatchCreateV2"},update:{methodName:"wedaUpdateV2"},upsert:{methodName:"wedaUpsertV2"},updateMany:{methodName:"wedaBatchUpdateV2"},delete:{methodName:"wedaDeleteV2"},deleteMany:{methodName:"wedaBatchDeleteV2"},get:{methodName:"wedaGetItemV2",defaultParams:{filter:{where:{}},select:{$master:!0}}},list:{methodName:"wedaGetRecordsV2",defaultParams:{filter:{where:{}},select:{$master:!0}}}},h=function(t){var e=l(t);return new Proxy({},{get:function(s,a){if("string"==typeof a)return Object.prototype.hasOwnProperty.call(e,a)?e[a]:function(t,e){return new Proxy({},{get:function(s,a){var c=f[a];if(!c){var l=new Error("不支持的操作: ".concat(a));throw new i(l.message||"Unknown error occurred",{originError:l,code:"NotSupported",requestId:"N/A"})}return function(i){return n(void 0,0,void 0,(function(){var n,s,l,f,h;return o(this,(function(o){switch(o.label){case 0:return n=r(r({},c.defaultParams||{}),i||{}),[4,u({callFunction:e,dataSourceName:t,methodName:c.methodName,realMethodName:a,params:n,envType:null==i?void 0:i.envType})];case 1:return s=o.sent(),l={data:{}},f=c.responseKey,l.data=f?null===(h=null==s?void 0:s.data)||void 0===h?void 0:h[f]:null==s?void 0:s.data,[2,l]}}))}))}}})}(a,t)}})},d={filter:{where:{}},select:{$master:!0}};function p(t){return{getUrl:function(e){return"".concat(e,"/").concat(t)},method:"post"}}var y={get:r(r({},p("get")),{defaultParams:r({},d)}),list:r(r({},p("list")),{defaultParams:r({},d)}),create:p("create"),createMany:p("createMany"),update:r(r({},p("update")),{method:"put"}),updateMany:r(r({},p("updateMany")),{method:"put"}),upsert:p("upsert"),delete:p("delete"),deleteMany:p("deleteMany")},v="Unknown error occurred",g="NotSupported",m=function(t,e,r,n){var o=l(t);return new Proxy({},{get:function(t,i){if("string"==typeof i)return Object.prototype.hasOwnProperty.call(o,i)?o[i]:w(r,i,e,n)}})},b=function(t,e,r,n,o){return new i("【错误】".concat(t,"\n【操作】调用 models.").concat(e,".").concat(r,"\n【错误码】").concat(n,"\n【请求ID】").concat(o),{code:n,requestId:o})},w=function(t,e,s,a){return new Proxy({},{get:function(u,c){if("runSQLTemplate"!==c){var l=y[c];if(!l){var f=new Error("不支持的操作: ".concat(c));throw new i(f.message||v,{originError:f,code:g,requestId:"N/A"})}return function(r){return void 0===r&&(r={}),n(void 0,0,void 0,(function(){var n,a,u,f,h,d,p,y,g,m;return o(this,(function(o){switch(o.label){case 0:n=l.getUrl,a=l.method,u=l.defaultParams,f=void 0===u?{}:u,h=Object.assign({},f,r),d="pre"===h.envType?"pre":"prod",p=[t,d,n(e)].join("/"),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,s({url:p,body:JSON.stringify(h),method:a})];case 2:if((y=o.sent()).code)throw b(null==y?void 0:y.message,e,c,null==y?void 0:y.code,null==y?void 0:y.requestId);return"get"===c&&Object.assign(y,{data:null!==(m=y.data.record)&&void 0!==m?m:y.data}),[2,y];case 3:throw g=o.sent(),new i((null==g?void 0:g.message)||v,{originError:g});case 4:return[2]}}))}))}}if(!(null==a?void 0:a.sqlBaseUrl))throw f=new Error("不支持的操作: ".concat(c)),new i(f.message||v,{originError:f,code:g,requestId:"N/A"});return function(t){return n(void 0,0,void 0,(function(){var n,u,l,f,h,d,p,y,g,m,w,_,S,E,I,O;return o(this,(function(o){switch(o.label){case 0:n=t.params,u=t.templateName,l=t.envType,f="pre"===l?"pre":"prod",h=[a.sqlBaseUrl,f,u,"run"].join("/"),d=Object.entries(n||{}).reduce((function(t,e){var r=e[0],n=e[1];if(void 0!==n){var o="OBJECT";switch(typeof n){case"boolean":o="BOOLEAN";break;case"number":o="NUMBER";break;case"string":o="STRING";break;default:o=Array.isArray(n)?"ARRAY":"OBJECT"}t.push({key:r,type:o,value:"STRING"===o?n:JSON.stringify(n)})}return t}),[]),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,s({url:h,body:JSON.stringify({parameter:d}),method:"POST"})];case 2:if(p=o.sent(),null===(g=null==p?void 0:p.Response)||void 0===g?void 0:g.Error)throw b(null===(w=null===(m=null==p?void 0:p.Response)||void 0===m?void 0:m.Error)||void 0===w?void 0:w.Message,e,c,null===(S=null===(_=null==p?void 0:p.Response)||void 0===_?void 0:_.Error)||void 0===S?void 0:S.Code,null===(E=null==p?void 0:p.Response)||void 0===E?void 0:E.RequestId);return[2,r(r({},null!==(I=null==p?void 0:p.Response)&&void 0!==I?I:{}),{data:null===(O=null==p?void 0:p.Response)||void 0===O?void 0:O.Data})];case 3:throw y=o.sent(),new i((null==y?void 0:y.message)||v,{originError:y});case 4:return[2]}}))}))}}})};function _(t){if(!t)throw new Error("cloud is required");if(!t.callFunction)throw new Error("cloud.callFunction is required");var e=h(t.callFunction.bind(t));return t.models=e,t}var S={init:_,generateHTTPClient:m};t.default=S,t.generateHTTPClient=m,t.init=_,Object.defineProperty(t,"__esModule",{value:!0})}(e)},972:function(t,e,r){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}},o=n(r(2856)),i=r(9297),s=r(2363),a=r(614),u=r(9063),c=r(7505),l=r(9679),f=r(7801),h=r(7596),d=r(8622),p=n(r(4536)).default.version;o.default.registerVersion(p);try{(0,i.registerAuth)(o.default),(0,s.registerFunctions)(o.default),(0,a.registerStorage)(o.default),(0,d.registerDatabase)(o.default),(0,u.registerRealtime)(o.default),(0,c.registerAnalytics)(o.default),(0,l.registerModel)(o.default),(0,f.registerAi)(o.default),(0,h.registerCloudrun)(o.default)}catch(t){}try{window.cloudbase=o.default}catch(t){}e.default=o.default,t.exports=o.default},7801:function(t,e,r){"use strict";r.r(e),r.d(e,{AI:function(){return ne},Bot:function(){return M},SimpleChatModel:function(){return oe},createAi:function(){return ce},models:function(){return ae},registerAi:function(){return fe},utils:function(){return n}});var n={};r.r(n),r.d(n,{ReadableStream:function(){return E},TextDecoderStream:function(){return A},TransformStream:function(){return I},createAsyncIterable:function(){return R},createEventSourceParserTransformStream:function(){return O},createPromise:function(){return N},functionToolToModelTool:function(){return j},intoStandardStream:function(){return P},intoTextStream:function(){return x},isToolCallAssistantMessage:function(){return L},readableStream2JsonObject:function(){return C},toPolyfillReadable:function(){return T}});var o={};r.r(o),r.d(o,{ArkSimpleModel:function(){return at},DSSimpleModel:function(){return ht},DefaultSimpleModel:function(){return qt},HunYuanBetaSimpleModel:function(){return Z},HunYuanExpSimpleModel:function(){return Tt},HunYuanOpenSimpleModel:function(){return xt},HunYuanSimpleModel:function(){return rt},MODELS:function(){return Qt},MoonshotSimpleModel:function(){return St},ReactModel:function(){return Ht},YiSimpleModel:function(){return gt},ZhiPuSimpleModel:function(){return G},toolMap:function(){return Kt}});var i=r(5993),s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},s(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function u(t){if(!t)throw new TypeError("Assertion failed")}function c(){}function l(t){return!(e=t,("object"!=typeof e||null===e)&&"function"!=typeof e||"function"!=typeof t.getReader);var e}function f(t){try{return t.getReader({mode:"byob"}).releaseLock(),!0}catch(t){return!1}}function h(t,e){var r=(void 0===e?{}:e).type;return u(l(t)),u(!1===t.locked),"bytes"===(r=d(r))?new g(t):new y(t)}function d(t){var e=String(t);if("bytes"===e)return e;if(void 0===t)return t;throw new RangeError("Invalid type is specified")}var p=function(){function t(t){this._underlyingReader=void 0,this._readerMode=void 0,this._readableStreamController=void 0,this._pendingRead=void 0,this._underlyingStream=t,this._attachDefaultReader()}return t.prototype.start=function(t){this._readableStreamController=t},t.prototype.cancel=function(t){return u(void 0!==this._underlyingReader),this._underlyingReader.cancel(t)},t.prototype._attachDefaultReader=function(){if("default"!==this._readerMode){this._detachReader();var t=this._underlyingStream.getReader();this._readerMode="default",this._attachReader(t)}},t.prototype._attachReader=function(t){var e=this;u(void 0===this._underlyingReader),this._underlyingReader=t;var r=this._underlyingReader.closed;r&&r.then((function(){return e._finishPendingRead()})).then((function(){t===e._underlyingReader&&e._readableStreamController.close()}),(function(r){t===e._underlyingReader&&e._readableStreamController.error(r)})).catch(c)},t.prototype._detachReader=function(){void 0!==this._underlyingReader&&(this._underlyingReader.releaseLock(),this._underlyingReader=void 0,this._readerMode=void 0)},t.prototype._pullWithDefaultReader=function(){var t=this;this._attachDefaultReader();var e=this._underlyingReader.read().then((function(e){var r=t._readableStreamController;e.done?t._tryClose():r.enqueue(e.value)}));return this._setPendingRead(e),e},t.prototype._tryClose=function(){try{this._readableStreamController.close()}catch(t){}},t.prototype._setPendingRead=function(t){var e,r=this,n=function(){r._pendingRead===e&&(r._pendingRead=void 0)};this._pendingRead=e=t.then(n,n)},t.prototype._finishPendingRead=function(){var t=this;if(this._pendingRead){var e=function(){return t._finishPendingRead()};return this._pendingRead.then(e,e)}},t}(),y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.pull=function(){return this._pullWithDefaultReader()},e}(p);function v(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}var g=function(t){function e(e){var r=this,n=f(e);return(r=t.call(this,e)||this)._supportsByob=n,r}return a(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),e.prototype._attachByobReader=function(){if("byob"!==this._readerMode){u(this._supportsByob),this._detachReader();var t=this._underlyingStream.getReader({mode:"byob"});this._readerMode="byob",this._attachReader(t)}},e.prototype.pull=function(){if(this._supportsByob){var t=this._readableStreamController.byobRequest;if(t)return this._pullWithByobRequest(t)}return this._pullWithDefaultReader()},e.prototype._pullWithByobRequest=function(t){var e=this;this._attachByobReader();var r=new Uint8Array(t.view.byteLength),n=this._underlyingReader.read(r).then((function(r){var n,o,i;e._readableStreamController,r.done?(e._tryClose(),t.respond(0)):(n=r.value,o=t.view,i=v(n),v(o).set(i,0),t.respond(r.value.byteLength))}));return this._setPendingRead(n),n},e}(p);!function(){function t(t){var e=this;this._writableStreamController=void 0,this._pendingWrite=void 0,this._state="writable",this._storedError=void 0,this._underlyingWriter=t,this._errorPromise=new Promise((function(t,r){e._errorPromiseReject=r})),this._errorPromise.catch(c)}t.prototype.start=function(t){var e=this;this._writableStreamController=t,this._underlyingWriter.closed.then((function(){e._state="closed"})).catch((function(t){return e._finishErroring(t)}))},t.prototype.write=function(t){var e=this,r=this._underlyingWriter;if(null===r.desiredSize)return r.ready;var n=r.write(t);n.catch((function(t){return e._finishErroring(t)})),r.ready.catch((function(t){return e._startErroring(t)}));var o=Promise.race([n,this._errorPromise]);return this._setPendingWrite(o),o},t.prototype.close=function(){var t=this;return void 0===this._pendingWrite?this._underlyingWriter.close():this._finishPendingWrite().then((function(){return t.close()}))},t.prototype.abort=function(t){if("errored"!==this._state)return this._underlyingWriter.abort(t)},t.prototype._setPendingWrite=function(t){var e,r=this,n=function(){r._pendingWrite===e&&(r._pendingWrite=void 0)};this._pendingWrite=e=t.then(n,n)},t.prototype._finishPendingWrite=function(){var t=this;if(void 0===this._pendingWrite)return Promise.resolve();var e=function(){return t._finishPendingWrite()};return this._pendingWrite.then(e,e)},t.prototype._startErroring=function(t){var e=this;if("writable"===this._state){this._state="erroring",this._storedError=t;var r=function(){return e._finishErroring(t)};void 0===this._pendingWrite?r():this._finishPendingWrite().then(r,r),this._writableStreamController.error(t)}},t.prototype._finishErroring=function(t){"writable"===this._state&&this._startErroring(t),"erroring"===this._state&&(this._state="errored",this._errorPromiseReject(this._storedError))}}(),function(){function t(t,e){var r=this;this._transformStreamController=void 0,this._onRead=function(t){if(!t.done)return r._transformStreamController.enqueue(t.value),r._reader.read().then(r._onRead)},this._onError=function(t){r._flushReject(t),r._transformStreamController.error(t),r._reader.cancel(t).catch(c),r._writer.abort(t).catch(c)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var t=new TypeError("TransformStream terminated");r._writer.abort(t).catch(c)},this._reader=t,this._writer=e,this._flushPromise=new Promise((function(t,e){r._flushResolve=t,r._flushReject=e}))}t.prototype.start=function(t){this._transformStreamController=t,this._reader.read().then(this._onRead).then(this._onTerminate,this._onError);var e=this._reader.closed;e&&e.then(this._onTerminate,this._onError)},t.prototype.transform=function(t){return this._writer.write(t)},t.prototype.flush=function(){var t=this;return this._writer.close().then((function(){return t._flushPromise}))}}();var m=[239,187,191],b=r(4410),w=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},_=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},S=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise((function(n,o){!function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)}(n,o,(e=t[r](e)).done,e.value)}))}}},E=i.Pz,I=i.GJ,O=function(){var t;return new I({start:function(e){t=function(t){var e,r,n,o,i,s,a;return u(),{feed:function(t){r=r?r+t:t,e&&function(t){return m.every((function(e,r){return t.charCodeAt(r)===e}))}(r)&&(r=r.slice(m.length)),e=!1;for(var i=r.length,s=0,a=!1;s<i;){a&&("\n"===r[s]&&(s+=1),a=!1);for(var u=-1,l=o,f=void 0,h=n;u<0&&h<i;h++)":"===(f=r[h])&&l<0?l=h-s:"\r"===f?(a=!0,u=h-s):"\n"===f&&(u=h-s);if(u<0){n=i-s,o=l;break}n=0,o=-1,c(r,s,l,u),s+=u+1}s===i?r="":s>0&&(r=r.slice(s))},reset:u};function u(){e=!0,r="",n=0,o=-1,i=void 0,s=void 0,a=""}function c(e,r,n,o){if(0===o)return a.length>0&&(t({type:"event",id:i,event:s||void 0,data:a.slice(0,-1)}),a="",i=void 0),void(s=void 0);var u,c=n<0,l=e.slice(r,r+(c?o:n)),f=r+(u=c?o:" "===e[r+n+1]?n+2:n+1),h=o-u,d=e.slice(f,f+h).toString();if("data"===l)a+=d?"".concat(d,"\n"):"\n";else if("event"===l)s=d;else if("id"!==l||d.includes("\0")){if("retry"===l){var p=parseInt(d,10);Number.isNaN(p)||t({type:"reconnect-interval",value:p})}}else i=d}}((function(t){"event"===t.type&&e.enqueue(t)}))},transform:function(e){t.feed(e)}})},T=function(t){u(function(t){return!!function(t){if("function"!=typeof t)return!1;var e=!1;try{new t({start:function(){e=!0}})}catch(t){}return e}(t)&&!!l(new t)}(t));var e=function(t){try{return new t({type:"bytes"}),!0}catch(t){return!1}}(t);return function(r,n){var o=(void 0===n?{}:n).type;if("bytes"!==(o=d(o))||e||(o=void 0),r.constructor===t&&("bytes"!==o||f(r)))return r;if("bytes"===o){var i=h(r,{type:o});return new t(i)}return i=h(r),new t(i)}}(E),A=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var r=this;this.transform=new I({transform:function(t,e){var n=r.handle.decode(new Uint8Array(t),{stream:!0});n&&e.enqueue(n)},flush:function(t){var e=r.handle.decode();e&&t.enqueue(e),t.terminate()}}),this.handle=new b.TextDecoder(t,e)}return Object.defineProperty(t.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),t}();function R(t){var e=t;return e[Symbol.asyncIterator]=function(){var e=t.getReader();return{next:function(){return w(this,void 0,void 0,(function(){var t,r,n;return _(this,(function(o){switch(o.label){case 0:return[4,e.read()];case 1:return t=o.sent(),r=t.done,n=t.value,[2,r?{done:!0,value:void 0}:{done:!1,value:n}]}}))}))}}},e}function P(t){return R(t.pipeThrough(new A).pipeThrough(O()).pipeThrough(new I({transform:function(t,e){try{var r=JSON.parse(t.data);e.enqueue(r)}catch(r){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",r,t):e.terminate()}}})))}function x(t){return R(T(t).pipeThrough(new A))}function C(t){var e,r,n,o;return w(this,void 0,void 0,(function(){var i,s,a,u,c,l;return _(this,(function(f){switch(f.label){case 0:i=x(t),s="",f.label=1;case 1:f.trys.push([1,6,7,12]),a=!0,u=S(i),f.label=2;case 2:return[4,u.next()];case 3:if(c=f.sent(),e=c.done)return[3,5];o=c.value,a=!1;try{s+=o}finally{a=!0}f.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return l=f.sent(),r={error:l},[3,12];case 7:return f.trys.push([7,,10,11]),a||e||!(n=u.return)?[3,9]:[4,n.call(u)];case 8:f.sent(),f.label=9;case 9:return[3,11];case 10:if(r)throw r.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(s)]}}))}))}function N(){var t,e;return{promise:new Promise((function(r,n){t=r,e=n})),res:t,rej:e}}function L(t){var e;return"assistant"===t.role&&"tool_calls"in t&&null!=(null===(e=t.tool_calls)||void 0===e?void 0:e[0])}function j(t){return{type:"function",function:{description:t.description,name:t.name,parameters:t.parameters}}}var U=function(){return U=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},U.apply(this,arguments)},k=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},D=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},q=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r},M=function(){function t(t,e){this.baseUrl=e;var r=arguments[2];this.req="string"==typeof r?function(e){var n=e.headers,o=void 0===n?{}:n,i=q(e,["headers"]);return t(U(U({},i),{headers:U(U({},o),{Authorization:"Bearer ".concat(r)})}))}:t}return t.prototype.list=function(t,e){return this.req({method:"get",url:this.join("bots"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.create=function(t,e){var r=t.botInfo;return this.req({method:"post",url:this.join("bots"),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.get=function(t,e){var r=t.botId;return this.req({method:"get",url:this.join("bots/".concat(r)),timeout:null==e?void 0:e.timeout})},t.prototype.update=function(t,e){var r=t.botId,n=t.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(r)),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.delete=function(t,e){var r=t.botId;return this.req({method:"delete",url:this.join("bots/".concat(r)),timeout:null==e?void 0:e.timeout})},t.prototype.getChatRecords=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/records")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendFeedback=function(t,e){var r=t.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(r.botId,"/feedback")),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.getFeedback=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/feedback")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.uploadFiles=function(t,e){return k(this,void 0,void 0,(function(){return D(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/files")),data:t,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.createConversation=function(t,e){var r=t.botId,n=q(t,["botId"]);return k(this,void 0,void 0,(function(){return D(this,(function(t){return[2,this.req({method:"post",url:this.join("bots/".concat(r,"/conversation")),data:n,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.getConversation=function(t,e){var r=t.pageSize,n=void 0===r?10:r,o=t.pageNumber,i=void 0===o?1:o,s=t.botId,a=q(t,["pageSize","pageNumber","botId"]);return k(this,void 0,void 0,(function(){var t,r;return D(this,(function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return t=n*(i-1),r=n,[2,this.req({method:"get",url:this.join("bots/".concat(s,"/conversation")),data:U(U({},a),{offset:t,limit:r}),timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.deleteConversation=function(t,e){var r=t.botId,n=t.conversationId,o=q(t,["botId","conversationId"]);return k(this,void 0,void 0,(function(){return D(this,(function(t){return[2,this.req({method:"delete",url:this.join("bots/".concat(r,"/conversation/").concat(n)),data:o,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.speechToText=function(t,e){return k(this,void 0,void 0,(function(){return D(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/speech-to-text")),data:t,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.textToSpeech=function(t,e){return k(this,void 0,void 0,(function(){return D(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.getTextToSpeechResult=function(t,e){return k(this,void 0,void 0,(function(){return D(this,(function(r){return[2,this.req({method:"get",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.getRecommendQuestions=function(t,e){return k(this,void 0,void 0,(function(){var r;return D(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/recommend-questions")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=n.sent(),[2,new B(r)]}}))}))},t.prototype.generateBot=function(t,e){return k(this,void 0,void 0,(function(){var r;return D(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=n.sent(),[2,new B(r)]}}))}))},t.prototype.getPreview=function(t,e){return k(this,void 0,void 0,(function(){var r;return D(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=n.sent(),[2,new B(r)]}}))}))},t.prototype.generateImage=function(t,e){return this.req({method:"post",url:this.join("generate-image"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendMessage=function(t,e){return k(this,void 0,void 0,(function(){var r;return D(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/send-message")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=n.sent(),[2,new B(r)]}}))}))},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),B=function(){function t(t){var e=T(t);this._eventSourceStream=e.pipeThrough(new A).pipeThrough(O())}return Object.defineProperty(t.prototype,"teeedStream",{get:function(){var t=this._eventSourceStream.tee(),e=t[0],r=t[1];return this._eventSourceStream=r,e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eventSourceStream",{get:function(){return R(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return R(this.eventSourceStream.pipeThrough(new I({transform:function(t,e){try{var r=JSON.parse(t.data);e.enqueue(r)}catch(r){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",r,t):e.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textStream",{get:function(){return R(this.dataStream.pipeThrough(new I({transform:function(t,e){var r;e.enqueue(null!==(r=null==t?void 0:t.content)&&void 0!==r?r:"")}})))},enumerable:!1,configurable:!0}),t}(),W=function(){return W=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},W.apply(this,arguments)},F=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},V=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};function H(t){var e=t.messages,r=t.model,n=t.temperature,o=t.tool_choice,i=t.tools,s=t.top_p;return W(W({},t),{messages:e,model:r,temperature:n,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:s})}var G=function(){function t(t,e,r){this.req=t,this.baseUrl=e,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return F(this,void 0,void 0,(function(){var r,n;return V(this,(function(o){switch(o.label){case 0:return r=H(t),[4,this.req({url:this.url,data:W(W({},r),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),[2,W(W({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return F(this,void 0,void 0,(function(){var r,n,o,i;return V(this,(function(s){switch(s.label){case 0:return r=H(t),n=null,[4,this.req({url:this.url,data:W(W({},r),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=s.sent(),i=T(o),[2,R(P(i).pipeThrough(new I({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=L(e)),n?W(W({},t),{finish_reason:"tool_calls",delta:e}):t})),o=W(W({},t),{choices:r});e.enqueue(W(W({},o),{rawResponse:t}))}})))]}}))}))},t}(),$=function(){return $=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},$.apply(this,arguments)};function K(t){var e=t.messages,r=t.model,n=t.temperature,o=t.tool_choice,i=t.tools,s=t.top_p;return $($({},t),{messages:(e.forEach((function(t){"tool_calls"in t&&t.tool_calls.filter((function(t){return"function"!==t.type})).forEach((function(e){return console.warn("`type` in tool_call is not 'function'",e,t)}))})),e),model:r,tools:function(){if(i)return i.forEach((function(t){"function"!==t.type&&console.warn("`type` in tool is not 'function'",t)})),i}(),top_p:s,tool_choice:o,temperature:n})}function z(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map((function(t){return z(t)})):Object.entries(t).reduce((function(t,e){var r,n=e[0],o=e[1];return t["_"===(r=n.replace(/[A-Z]/g,(function(t){return"_".concat(t.toLowerCase())}))).charAt(0)?r.slice(1):r]="object"==typeof o?z(o):o,t}),{})}var J=function(){return J=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},J.apply(this,arguments)},Y=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},Q=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},Z=function(){function t(t,e,r){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Y(this,void 0,void 0,(function(){var r;return Q(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:J(J({},K(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=n.sent(),[2,J(J({},r),{rawResponse:r})]}}))}))},t.prototype.doStream=function(t,e){return Y(this,void 0,void 0,(function(){var r,n,o;return Q(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:J(J({},K(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=i.sent(),o=T(n),[2,R(P(o).pipeThrough(new I({transform:function(t,e){var n=t.choices.map((function(t){var e=t.delta;return null==r&&(r=L(e)),r?J(J({},t),{finish_reason:"tool_calls",delta:e}):t})),o=J(J({},t),{choices:n});e.enqueue(J(J({},o),{rawResponse:t}))}})))]}}))}))},t}(),X=function(){return X=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},X.apply(this,arguments)},tt=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},et=function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},rt=function(){function t(t,e,r){this.req=t,this.ba