@cloudbase/js-sdk 3.5.3 → 3.5.5-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # 更新日志
2
2
 
3
+ ## [3.5.4] 2026-06-25
4
+ - [Fixed] 修复 Node.js ESM 环境下初始化时 `getWxDefaultAdapter` 返回空对象导致 `useAdapters` 调用 `isMatch()` 报 `TypeError: i is not a function` 的问题
5
+ - [Fixed] 修复 GATEWAY 模式下文档型数据库集合查询时,后端返回数据缺少 `list` 字段导致 `formatResDocumentData` 报 `TypeError: Cannot read properties of undefined (reading 'map')` 的问题
6
+
3
7
  ## [3.5.3] 2026-06-25
4
8
  - [Added] App 实例新增 `registerHost(host, protocol?)` 方法,一次性设置所有端点(CLOUD_API / GATEWAY),只需传入 host 地址自动拼接路径
5
9
  - [Added] `cloudbase.app.App` 类型声明补充 `registerHost`、`getEndPointWithKey`、`registerEndPoint`、`registerEndPointWithKey`、`parseCaptcha` 实例方法
@@ -1,2 +1,2 @@
1
- import*as t from"web-streams-polyfill";import*as e from"@mattiasbuelens/web-streams-adapter";import*as n from"text-encoding-shim";import*as r from"@cloudbase/adapter-interface";import*as o from"jwt-decode";var i={d:(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},a={};i.d(a,{AI:()=>we,rf:()=>A,pe:()=>Se,jE:()=>ke,jM:()=>Pe,Cq:()=>xe,el:()=>qe,P6:()=>u});var u={};i.r(u),i.d(u,{ReadableStream:()=>y,TextDecoderStream:()=>O,TransformStream:()=>g,createAsyncIterable:()=>_,createEventSourceParserTransformStream:()=>w,createPromise:()=>P,functionToolToModelTool:()=>q,intoStandardStream:()=>x,intoTextStream:()=>j,isToolCallAssistantMessage:()=>U,readableStream2JsonObject:()=>k,toPolyfillReadable:()=>S});var s={};i.r(s),i.d(s,{ArkSimpleModel:()=>nt,DSSimpleModel:()=>ut,DefaultImageModel:()=>At,DefaultSimpleModel:()=>Et,HunYuanBetaSimpleModel:()=>z,HunYuanExpSimpleModel:()=>St,HunYuanOpenSimpleModel:()=>jt,HunYuanSimpleModel:()=>Z,MODELS:()=>zt,MoonshotSimpleModel:()=>mt,ReactModel:()=>Lt,YiSimpleModel:()=>pt,ZhiPuSimpleModel:()=>L,toolMap:()=>Ft});const c=(l={ReadableStream:()=>t.ReadableStream,TransformStream:()=>t.TransformStream},f={},i.d(f,l),f);var l,f;const p=(t=>{var e={};return i.d(e,t),e})({createReadableStreamWrapper:()=>e.createReadableStreamWrapper});var h=[239,187,191];const d=(t=>{var e={};return i.d(e,t),e})({TextDecoder:()=>n.TextDecoder});var v=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},b=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},m=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,o){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,o,(e=t[n](e)).done,e.value)}))}}},y=c.ReadableStream,g=c.TransformStream,w=function(){var t;return new g({start:function(e){t=function(t){var e,n,r,o,i,a,u;return s(),{feed:function(t){n=n?n+t:t,e&&function(t){return h.every((function(e,n){return t.charCodeAt(n)===e}))}(n)&&(n=n.slice(h.length)),e=!1;for(var i=n.length,a=0,u=!1;a<i;){u&&("\n"===n[a]&&(a+=1),u=!1);for(var s=-1,l=o,f=void 0,p=r;s<0&&p<i;p++)":"===(f=n[p])&&l<0?l=p-a:"\r"===f?(u=!0,s=p-a):"\n"===f&&(s=p-a);if(s<0){r=i-a,o=l;break}r=0,o=-1,c(n,a,l,s),a+=s+1}a===i?n="":a>0&&(n=n.slice(a))},reset:s};function s(){e=!0,n="",r=0,o=-1,i=void 0,a=void 0,u=""}function c(e,n,r,o){if(0===o)return u.length>0&&(t({type:"event",id:i,event:a||void 0,data:u.slice(0,-1)}),u="",i=void 0),void(a=void 0);var s,c=r<0,l=e.slice(n,n+(c?o:r)),f=n+(s=c?o:" "===e[n+r+1]?r+2:r+1),p=o-s,h=e.slice(f,f+p).toString();if("data"===l)u+=h?"".concat(h,"\n"):"\n";else if("event"===l)a=h;else if("id"!==l||h.includes("\0")){if("retry"===l){var d=parseInt(h,10);Number.isNaN(d)||t({type:"reconnect-interval",value:d})}}else i=h}}((function(t){"event"===t.type&&e.enqueue(t)}))},transform:function(e){t.feed(e)}})},S=(0,p.createReadableStreamWrapper)(y),O=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var n=this;this.transform=new g({transform:function(t,e){var r=n.handle.decode(new Uint8Array(t),{stream:!0});r&&e.enqueue(r)},flush:function(t){var e=n.handle.decode();e&&t.enqueue(e),t.terminate()}}),this.handle=new d.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 _(t){var e=t;return e[Symbol.asyncIterator]=function(){var e=t.getReader();return{next:function(){return v(this,void 0,Promise,(function(){var t,n,r;return b(this,(function(o){switch(o.label){case 0:return[4,e.read()];case 1:return t=o.sent(),n=t.done,r=t.value,[2,n?{done:!0,value:void 0}:{done:!1,value:r}]}}))}))}}},e}function x(t){return _(t.pipeThrough(new O).pipeThrough(w()).pipeThrough(new g({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))}function j(t){return _(S(t).pipeThrough(new O))}function k(t){var e,n,r,o;return v(this,void 0,void 0,(function(){var i,a,u,s,c,l;return b(this,(function(f){switch(f.label){case 0:i=j(t),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),u=!0,s=m(i),f.label=2;case 2:return[4,s.next()];case 3:if(c=f.sent(),e=c.done)return[3,5];o=c.value,u=!1;try{a+=o}finally{u=!0}f.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return l=f.sent(),n={error:l},[3,12];case 7:return f.trys.push([7,,10,11]),u||e||!(r=s.return)?[3,9]:[4,r.call(s)];case 8:f.sent(),f.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(a)]}}))}))}function P(){var t,e;return{promise:new Promise((function(n,r){t=n,e=r})),res:t,rej:e}}function U(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 q(t){return{type:"function",function:{description:t.description,name:t.name,parameters:t.parameters}}}var T=function(){return T=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},T.apply(this,arguments)},I=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},R=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},E=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},A=function(){function t(t,e){this.baseUrl=e;var n=arguments[2];this.req="string"==typeof n?function(e){var r=e.headers,o=void 0===r?{}:r,i=E(e,["headers"]);return t(T(T({},i),{headers:T(T({},o),{Authorization:"Bearer ".concat(n)})}))}: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 n=t.botInfo;return this.req({method:"post",url:this.join("bots"),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.get=function(t,e){var n=t.botId;return this.req({method:"get",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.update=function(t,e){var n=t.botId,r=t.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(n)),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.delete=function(t,e){var n=t.botId;return this.req({method:"delete",url:this.join("bots/".concat(n)),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 n=t.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(n.botId,"/feedback")),data:n,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 I(this,void 0,void 0,(function(){return R(this,(function(n){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 n=t.botId,r=E(t,["botId"]);return I(this,void 0,void 0,(function(){return R(this,(function(t){return[2,this.req({method:"post",url:this.join("bots/".concat(n,"/conversation")),data:r,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.getConversation=function(t,e){var n=t.pageSize,r=void 0===n?10:n,o=t.pageNumber,i=void 0===o?1:o,a=t.botId,u=E(t,["pageSize","pageNumber","botId"]);return I(this,void 0,void 0,(function(){var t,n;return R(this,(function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return t=r*(i-1),n=r,[2,this.req({method:"get",url:this.join("bots/".concat(a,"/conversation")),data:T(T({},u),{offset:t,limit:n}),timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.deleteConversation=function(t,e){var n=t.botId,r=t.conversationId,o=E(t,["botId","conversationId"]);return I(this,void 0,void 0,(function(){return R(this,(function(t){return[2,this.req({method:"delete",url:this.join("bots/".concat(n,"/conversation/").concat(r)),data:o,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.speechToText=function(t,e){return I(this,void 0,void 0,(function(){return R(this,(function(n){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 I(this,void 0,void 0,(function(){return R(this,(function(n){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 I(this,void 0,void 0,(function(){return R(this,(function(n){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 I(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},t.prototype.generateBot=function(t,e){return I(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},t.prototype.getPreview=function(t,e){return I(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},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 I(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),C=function(){function t(t){var e=S(t);this._eventSourceStream=e.pipeThrough(new O).pipeThrough(w())}return Object.defineProperty(t.prototype,"teeedStream",{get:function(){var t=this._eventSourceStream.tee(),e=t[0],n=t[1];return this._eventSourceStream=n,e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eventSourceStream",{get:function(){return _(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return _(this.eventSourceStream.pipeThrough(new g({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textStream",{get:function(){return _(this.dataStream.pipeThrough(new g({transform:function(t,e){var n;e.enqueue(null!==(n=null==t?void 0:t.content)&&void 0!==n?n:"")}})))},enumerable:!1,configurable:!0}),t}(),M=function(){return M=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},M.apply(this,arguments)},B=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},G=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function D(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return M(M({},t),{messages:e,model:n,temperature:r,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:a})}var L=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=n&&(this.subUrl=n)}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 B(this,void 0,Promise,(function(){var n,r;return G(this,(function(o){switch(o.label){case 0:return n=D(t),[4,this.req({url:this.url,data:M(M({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,M(M({},r),{rawResponse:r})]}}))}))},t.prototype.doStream=function(t,e){return B(this,void 0,Promise,(function(){var n,r,o,i;return G(this,(function(a){switch(a.label){case 0:return n=D(t),r=null,[4,this.req({url:this.url,data:M(M({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=a.sent(),i=S(o),[2,_(x(i).pipeThrough(new g({transform:function(t,e){var n=t.choices.map((function(t){var e=t.delta;return null==r&&(r=U(e)),r?M(M({},t),{finish_reason:"tool_calls",delta:e}):t})),o=M(M({},t),{choices:n});e.enqueue(M(M({},o),{rawResponse:t}))}})))]}}))}))},t}(),N=function(){return N=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},N.apply(this,arguments)};function J(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return N(N({},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:n,tools:function(){if(i)return i.forEach((function(t){"function"!==t.type&&console.warn("`type` in tool is not 'function'",t)})),i}(),top_p:a,tool_choice:o,temperature:r})}function F(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map((function(t){return F(t)})):Object.entries(t).reduce((function(t,e){var n,r=e[0],o=e[1];return t["_"===(n=r.replace(/[A-Z]/g,(function(t){return"_".concat(t.toLowerCase())}))).charAt(0)?n.slice(1):n]="object"==typeof o?F(o):o,t}),{})}var W=function(){return W=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},W.apply(this,arguments)},H=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Y=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},z=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=n&&(this.subUrl=n)}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 H(this,void 0,Promise,(function(){var n;return Y(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:W(W({},J(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,W(W({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return H(this,void 0,Promise,(function(){var n,r,o;return Y(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:W(W({},J(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(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}(),K=function(){return K=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},K.apply(this,arguments)},X=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},V=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Z=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan",null!=n&&(this.subUrl=n)}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 X(this,void 0,Promise,(function(){var n,r;return V(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:K(K({},J(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),r=F(n.Response),[2,K(K({},r),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return X(this,void 0,Promise,(function(){var n,r,o;return V(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:K(K({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=F(t),o=r.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?K(K({},t),{finish_reason:"tool_calls",delta:e}):t})),i=K(K({},r),{choices:o});e.enqueue(K(K({},i),{rawResponse:t}))}})))]}}))}))},t}(),Q=function(){return Q=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Q.apply(this,arguments)},$=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},tt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function et(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Q(Q({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var nt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="ark/api/v3/chat/completions",null!=n&&(this.subUrl=n)}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 $(this,void 0,Promise,(function(){var n;return tt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Q(Q({},et(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Q(Q({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return $(this,void 0,Promise,(function(){var n,r,o;return tt(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Q(Q({},et(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?Q(Q({},t),{finish_reason:"tool_calls",delta:e}):t})),o=Q(Q({},t),{choices:r});e.enqueue(Q(Q({},o),{rawResponse:t}))}})))]}}))}))},t}(),rt=function(){return rt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},rt.apply(this,arguments)},ot=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},it=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function at(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return rt(rt({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var ut=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=n&&(this.subUrl=n)}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 ot(this,void 0,Promise,(function(){var n;return it(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:rt(rt({},at(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,rt(rt({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return ot(this,void 0,Promise,(function(){var n,r,o;return it(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:rt(rt({},at(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=U(e)),rt(rt({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})})),o=rt(rt({},t),{choices:r});e.enqueue(rt(rt({},o),{rawResponse:t}))}})))]}}))}))},t}(),st=function(){return st=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},st.apply(this,arguments)},ct=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},lt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function ft(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return st(st({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var pt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="01-ai/v1/chat/completions",null!=n&&(this.subUrl=n)}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 ct(this,void 0,Promise,(function(){var n;return lt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:st(st({},ft(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,st(st({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return ct(this,void 0,Promise,(function(){var n,r,o,i,a;return lt(this,(function(u){switch(u.label){case 0:return n=null,[4,this.req({url:this.url,data:st(st({},ft(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=u.sent(),o=S(r),i=x(o),a=i.pipeThrough(new g({transform:function(t,e){var r,o,i,a,u,s;if((null===(i=null===(o=null===(r=null==t?void 0:t.choices)||void 0===r?void 0:r[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(s=null===(u=null===(a=null==t?void 0:t.choices)||void 0===a?void 0:a[0])||void 0===u?void 0:u.delta)||void 0===s?void 0:s.tool_calls)){var c=t.choices.map((function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=U(e)),st(st({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})})),l=st(st({},t),{choices:c});e.enqueue(st(st({},l),{rawResponse:t}))}}})),[2,_(a)]}}))}))},t}(),ht=function(){return ht=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ht.apply(this,arguments)},dt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},vt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function bt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return ht(ht({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var mt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="moonshot/v1/chat/completions",null!=n&&(this.subUrl=n)}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 dt(this,void 0,Promise,(function(){var n;return vt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:ht(ht({},bt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,ht(ht({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return dt(this,void 0,Promise,(function(){var n,r,o;return vt(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:ht(ht({},bt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?ht(ht({},t),{finish_reason:"tool_calls",delta:e}):t})),o=ht(ht({},t),{choices:r});e.enqueue(ht(ht({},o),{rawResponse:t}))}})))]}}))}))},t}(),yt=function(){return yt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},yt.apply(this,arguments)},gt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},wt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},St=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-exp/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return gt(this,void 0,Promise,(function(){var e;return wt(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:yt(yt({},J(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,yt(yt({},e),{rawResponse:e})]}}))}))},t.prototype.doStream=function(t){return gt(this,void 0,Promise,(function(){var e,n,r;return wt(this,(function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:yt(yt({},J(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=S(n),[2,_(x(r).pipeThrough(new g({transform:function(t,n){var r=t.choices.map((function(t){var n=t.delta;return null==e&&(e=U(n)),e?yt(yt({},t),{finish_reason:"tool_calls",delta:n}):t})),o=yt(yt({},t),{choices:r});n.enqueue(yt(yt({},o),{rawResponse:t}))}})))]}}))}))},t}(),Ot=function(){return Ot=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ot.apply(this,arguments)},_t=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},xt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},jt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-open/v1/chat/completions",null!=n&&(this.subUrl=n)}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 _t(this,void 0,Promise,(function(){var n;return xt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ot(Ot({},J(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ot(Ot({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return _t(this,void 0,Promise,(function(){var n,r,o;return xt(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ot(Ot({},J(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?Ot(Ot({},t),{finish_reason:"tool_calls",delta:e}):t})),o=Ot(Ot({},t),{choices:r});e.enqueue(Ot(Ot({},o),{rawResponse:t}))}})))]}}))}))},t}(),kt=function(){return kt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},kt.apply(this,arguments)},Pt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Ut=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},qt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="deepseek/chat/completions",null!=n&&(this.subUrl=n)}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 Pt(this,void 0,Promise,(function(){var n;return Ut(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:kt(kt({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,kt(kt({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return Pt(this,void 0,Promise,(function(){var n,r,o;return Ut(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:kt(kt({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?kt(kt({},t),{finish_reason:"tool_calls",delta:e}):t})),o=kt(kt({},t),{choices:r});e.enqueue(kt(kt({},o),{rawResponse:t}))}})))]}}))}))},t}(),Tt=function(){return Tt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Tt.apply(this,arguments)},It=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Rt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Et=function(){function t(t,e,n){void 0===n&&(n=""),this.req=t,this.baseUrl=e,this.subUrl=n}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return It(this,void 0,Promise,(function(){var e;return Rt(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Tt(Tt({},t),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,Tt(Tt({},e),{rawResponse:e})]}}))}))},t.prototype.doStream=function(t){return It(this,void 0,Promise,(function(){var e,n,r;return Rt(this,(function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:Tt(Tt({},t),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=S(n),[2,_(x(r).pipeThrough(new g({transform:function(t,n){var r=t.choices.map((function(t){var n=t.delta;return null==e&&(e=U(n)),e?Tt(Tt({},t),{finish_reason:"tool_calls",delta:n}):t})),o=Tt(Tt({},t),{choices:r});n.enqueue(Tt(Tt({},o),{rawResponse:t}))}})))]}}))}))},t}(),At=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.provider=n,this.defaultGenerateImageSubUrl="images/generations",this.generateImageSubUrlConfig={"hunyuan-image":{"hunyuan-image-v3.0-v1.0.4":"images/ar/generations","hunyuan-image-v3.0-v1.0.1":"images/ar/generations"}},this.generateImage=this.generateImageImpl.bind(this)}return t.prototype.generateImageImpl=function(t){var e,n,r,o,i;return n=this,r=void 0,i=function(){var n,r;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,(function(o){switch(o.label){case 0:return n=this.defaultGenerateImageSubUrl,"object"==typeof t&&t&&"model"in t&&"string"==typeof t.model&&(r=null===(e=this.generateImageSubUrlConfig[this.provider])||void 0===e?void 0:e[t.model])&&(n=r),[4,this.req({url:this.getGenerateUrl(n),data:t,stream:!1})];case 1:return[2,o.sent()]}}))},new((o=Promise)||(o=Promise))((function(t,e){function a(t){try{s(i.next(t))}catch(t){e(t)}}function u(t){try{s(i.throw(t))}catch(t){e(t)}}function s(e){var n;e.done?t(e.value):(n=e.value,n instanceof o?n:new o((function(t){t(n)}))).then(a,u)}s((i=i.apply(n,r||[])).next())}))},t.prototype.getGenerateUrl=function(t){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(t)},t}(),Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},Mt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Bt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Gt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Dt(t){var e,n=t.onStepFinish,r=t.abortSignal,o=t.maxSteps,i=t.topP,a=t.toolChoice,u=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:n,abortSignal:r,maxSteps:o},Ct(Ct({},u),{tools:null===(e=u.tools)||void 0===e?void 0:e.map((function(t){return"fn"in t?q(t):t})),top_p:null!=i?i:u.top_p,tool_choice:null!=a?a:u.tool_choice})]}var Lt=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return Mt(this,void 0,Promise,(function(){var o,i,a,u,s,c,l,f,p,h,d,v,b,m,y,g,w,S,O,_,x,j=this;return Bt(this,(function(k){switch(k.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Dt(t),u=a[0],s=u.onStepFinish,c=u.maxSteps,l=void 0===c?10:c,f=a[1],[4,(p=function(){return j.model.doGenerate(f,e)})()];case 1:h=k.sent(),d=1,h.rawResponse&&o.push(h.rawResponse),v=null,k.label=2;case 2:if(!(d<l&&null!=(v=Nt(h))))return[3,9];b=Ht(h.usage),Yt(i,b),k.label=3;case 3:return k.trys.push([3,7,,8]),[4,Wt(v)];case 4:return m=k.sent(),y=h.choices[0],[4,null==s?void 0:s({finishReason:y.finish_reason,messages:f.messages.slice(),text:y.message.content,toolCall:v,toolResult:m,stepUsage:b,totalUsage:Object.assign({},i)})];case 5:return k.sent(),Jt(f.messages,y.message,m),[4,p()];case 6:return(h=k.sent()).rawResponse&&o.push(h.rawResponse),d+=1,[3,8];case 7:return g=k.sent(),[2,{text:"",messages:f.messages,usage:i,error:g,rawResponses:o}];case 8:return[3,2];case 9:return w=null===(n=null==h?void 0:h.choices)||void 0===n?void 0:n[0],S=null==w?void 0:w.message,O=null!==(r=null==S?void 0:S.content)&&void 0!==r?r:"",_=S?Gt(Gt([],f.messages,!0),[S],!1):f.messages,x=Ht(h.usage),Yt(i,x),[4,null==s?void 0:s({finishReason:w.finish_reason,messages:_.slice(),text:O,toolCall:Nt(h),toolResult:null,stepUsage:x,totalUsage:Object.assign({},i)})];case 10:return k.sent(),[2,{text:O,messages:_,usage:i,rawResponses:o}]}}))}))},t.prototype.streamText=function(t,e){var n;return Mt(this,void 0,Promise,(function(){var r,o,i,a,u,s,c,l,f,p,h,d,v,b,m,y,w,S,O,x,j,k,U,q,T,I,R,E,A,C,M,B,G,D,L,N,J=this;return Bt(this,(function(F){switch(F.label){case 0:return r={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=Dt(t),i=o[0],a=i.onStepFinish,u=i.maxSteps,s=void 0===u?10:u,c=o[1],[4,(l=function(){return J.model.doStream(c,e)})()];case 1:f=F.sent(),p=1,h=null,d=function(){var t=f.tee(),e=t[0],n=t[1];return f=_(e),function(t){var e,n,r,o,i,a,u,s,c,l;return Mt(this,void 0,Promise,(function(){var f,p,h,d,v,b,m,y,g,w,S,O,x;return Bt(this,(function(j){switch(j.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},p=_(t),d={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},j.label=1;case 1:j.trys.push([1,6,7,12]),v=!0,b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,o){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,o,(e=t[n](e)).done,e.value)}))}}}(p),j.label=2;case 2:return[4,b.next()];case 3:if(m=j.sent(),e=m.done)return[3,5];o=m.value,v=!1;try{if(!(g=null==(y=o)?void 0:y.choices[0]))return[2,null];if(w=g.finish_reason,S=g.delta,"tool_calls"!==w)return[2,null];if(!S)return[3,4];if(S.content&&(d.content+=S.content),!("tool_calls"in S))return[3,4];(null==(O=null===(i=null==S?void 0:S.tool_calls)||void 0===i?void 0:i[0])?void 0:O.id)&&(h.id=O.id),(null==O?void 0:O.type)&&(h.type=O.type),(null===(a=null==O?void 0:O.function)||void 0===a?void 0:a.name)&&(h.function.name=O.function.name),(null===(u=null==O?void 0:O.function)||void 0===u?void 0:u.arguments)&&(h.function.arguments+=O.function.arguments),(null===(s=null==y?void 0:y.usage)||void 0===s?void 0:s.completion_tokens)&&(f.completion_tokens=y.usage.completion_tokens),(null===(c=null==y?void 0:y.usage)||void 0===c?void 0:c.prompt_tokens)&&(f.prompt_tokens=y.usage.prompt_tokens),(null===(l=null==y?void 0:y.usage)||void 0===l?void 0:l.total_tokens)&&(f.total_tokens=y.usage.total_tokens)}finally{v=!0}j.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return x=j.sent(),n={error:x},[3,12];case 7:return j.trys.push([7,,10,11]),v||e||!(r=b.return)?[3,9]:[4,r.call(b)];case 8:j.sent(),j.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,{message:d,usage:f}]}}))}))}(n)},F.label=2;case 2:return(v=p<s)?[4,d()]:[3,4];case 3:v=null!=(h=F.sent()),F.label=4;case 4:if(!v)return[3,11];b=h.message,m=h.usage,Yt(r,m),y=null===(n=b.tool_calls)||void 0===n?void 0:n[0],F.label=5;case 5:return F.trys.push([5,9,,10]),[4,Wt(y)];case 6:return w=F.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:c.messages.slice(),text:b.content,toolCall:y,toolResult:w,stepUsage:m,totalUsage:Object.assign({},r)})];case 7:return F.sent(),Jt(c.messages,b,w),[4,l()];case 8:return f=F.sent(),[3,10];case 9:return S=F.sent(),O=f.tee(),x=O[0],j=O[1],[2,{messages:Promise.resolve(c.messages),dataStream:_(x),textStream:_(j.pipeThrough(new g({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r),error:S}];case 10:return[3,2];case 11:return[4,d()];case 12:return(h=F.sent())?(k=h.message,U=h.usage,Yt(r,U),q=Gt(Gt([],c.messages,!0),[k],!1),a({messages:q.slice(),finishReason:"tool_call",stepUsage:U,text:k.content,toolCall:k.tool_calls[0],totalUsage:Object.assign({},r)}),T=f.tee(),I=T[0],R=T[1],[2,{messages:Promise.resolve(Gt(Gt([],c.messages,!0),[k],!1)),dataStream:_(I),textStream:_(R.pipeThrough(new g({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r)}]):(E=P(),A=P(),C={role:"assistant",content:""},M="",B={completion_tokens:0,prompt_tokens:0,total_tokens:0},G=f.pipeThrough(new g({transform:function(t,e){var n,r,o,i,a,u,s,c,l=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof l&&(C.content+=l);var f=null===(a=null===(i=null==t?void 0:t.choices)||void 0===i?void 0:i[0])||void 0===a?void 0:a.finish_reason;f&&(M=f),(null===(u=null==t?void 0:t.usage)||void 0===u?void 0:u.completion_tokens)&&(B.completion_tokens=t.usage.completion_tokens),(null===(s=null==t?void 0:t.usage)||void 0===s?void 0:s.prompt_tokens)&&(B.prompt_tokens=t.usage.prompt_tokens),(null===(c=null==t?void 0:t.usage)||void 0===c?void 0:c.total_tokens)&&(B.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){E.res(Gt(Gt([],c.messages,!0),[C],!1)),Yt(r,B),A.res(Object.assign({},r)),null==a||a({messages:Gt(Gt([],c.messages,!0),[C],!1),finishReason:M,text:C.content,stepUsage:B,totalUsage:Object.assign({},r)})}})),D=G.tee(),L=D[0],N=D[1],[2,{messages:E.promise,dataStream:_(L),textStream:_(N.pipeThrough(new g({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:A.promise}])}}))}))},t}();function Nt(t){var e,n=null===(e=null==t?void 0:t.choices)||void 0===e?void 0:e[0];if(!n)return null;var r=n.finish_reason,o=n.message;return"tool_calls"!==r?null:o&&U(o)?o.tool_calls[0]:null}function Jt(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var Ft=new Map;function Wt(t){return Ft.get(t.function.name)(JSON.parse(t.function.arguments))}function Ht(t){var e,n,r;return{completion_tokens:null!==(e=null==t?void 0:t.completion_tokens)&&void 0!==e?e:0,prompt_tokens:null!==(n=null==t?void 0:t.prompt_tokens)&&void 0!==n?n:0,total_tokens:null!==(r=null==t?void 0:t.total_tokens)&&void 0!==r?r:0}}function Yt(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var zt={hunyuan:Z,"hunyuan-beta":z,ark:nt,dashscope:ut,"01-ai":pt,moonshot:mt,zhipu:L,"hunyuan-exp":St,"hunyuan-open":jt,deepseek:qt},Kt="@cloudbase/js-sdk";function Xt(){return Kt}var Vt="INVALID_OPERATION",Zt="OPERATION_FAIL";const Qt=(t=>{var e={};return i.d(e,t),e})({AbstractSDKRequest:()=>r.AbstractSDKRequest,AbstractStorage:()=>r.AbstractStorage});function $t(t,e){console.warn("[".concat(Xt(),"][").concat(t,"]:").concat(e))}var te,ee,ne=(te=function(t,e){return te=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},te(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}te(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),re=function(){return re=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},re.apply(this,arguments)},oe=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},ie=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}ne(e,t),e.prototype.get=function(t){return this.request(re(re({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(re(re({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(re(re({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,i=t.headers,a=void 0===i?{}:i,u={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",s=new FormData;return"post"===u?(Object.keys(e).forEach((function(t){s.append(t,e[t])})),s.append("key",r),s.append("file",n),this.request(re(re({},t),{data:s,method:u}),this.restrictedMethods.includes("upload"))):this.request(re(re({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return oe(this,void 0,Promise,(function(){var e,n,r,o;return ie(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(re(re({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return oe(this,void 0,Promise,(function(){var n,r,o,i,a,u,s,c,l,f,p,h,d,v=this;return ie(this,(function(b){switch(b.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,a=t.stream,u=void 0!==a&&a,s=t.signal,c=t.timeout,l=t.shouldThrowOnError,f=void 0===l||l,p=null!=c?c:this.timeout,s&&(s.aborted&&n.abort(),s.addEventListener("abort",(function(){return n.abort()}))),h=null,i&&p&&(h=setTimeout((function(){console.warn(v.timeoutMsg),n.abort(new Error(v.timeoutMsg))}),p)),[4,fetch(r,re(re({},t),{signal:n.signal})).then((function(t){return oe(v,void 0,void 0,(function(){var e,n,r;return ie(this,(function(o){switch(o.label){case 0:return clearTimeout(h),f?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}}))}))})).catch((function(t){return clearTimeout(h),Promise.reject(t)}))];case 1:return d=b.sent(),[2,{data:u?d.body:(null===(e=d.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?d.json():d.text(),statusCode:d.status,header:d.headers,response:d}]}}))}))},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise((function(o){var i=t.url,a=t.headers,u=void 0===a?{}:a,s=t.data,c=t.responseType,l=t.withCredentials,f=t.body,p=t.onUploadProgress,h=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach((function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))})),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",i,"get"===r?s:{}),d=new XMLHttpRequest;d.open(r,h),c&&(d.responseType=c);var v,b,m,y=t.signal;y&&(y.aborted?d.abort():y.addEventListener("abort",(function(){return d.abort()}),{once:!0})),Object.keys(u).forEach((function(t){d.setRequestHeader(t,u[t])})),p&&d.upload.addEventListener("progress",p),d.onreadystatechange=function(){var t={};if(4===d.readyState){var e=d.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach((function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o})),t.header=n,t.statusCode=d.status;try{t.data="blob"===c?d.response:JSON.parse(d.responseText)}catch(e){t.data="blob"===c?d.response:d.responseText}clearTimeout(v),o(t)}},e&&n.timeout&&(v=setTimeout((function(){console.warn(n.timeoutMsg),d.abort()}),n.timeout)),m=s,b="[object FormData]"===Object.prototype.toString.call(m)?s:"application/x-www-form-urlencoded"===u["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))})),e.join("&")}(s):f||(s?JSON.stringify(s):void 0),l&&(d.withCredentials=!0),d.send(b)}))}}(Qt.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(ee||(ee={}));var ae=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ue=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},se=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},ce=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return ae(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(Qt.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:($t("INVALID_PARAMS","localStorage is not supported on current platform"),new ce(e.root));case"none":return new ce(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:Zt,msg:"[".concat(Xt(),"][").concat(Zt,"]setStore failed"),info:t}))}}else $t(Vt,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return ue(this,void 0,void 0,(function(){var r;return se(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}$t(Vt,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return ue(this,void 0,void 0,(function(){var r;return se(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):$t(Vt,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return ue(this,void 0,void 0,(function(){return se(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var le=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),fe=function(t,e){this.data=e||null,this.name=t},pe=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return le(e,t),e}(fe),he=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof pe)return console.error(t.error),this;var n="string"==typeof t?new fe(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new he;var de=new he;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const ve=(t=>{var e={};return i.d(e,t),e})({default:()=>o.default});ve.default;var be=function(){return be=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},be.apply(this,arguments)},me=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},ye=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},ge=zt,we=function(){function t(t,e,n,r){var o=this;this.req=t,this.baseUrl=e,this.modelRequest=function(t){var e=t.url,n=t.data,r=t.headers,i=t.stream,a=t.timeout;return me(o,void 0,void 0,(function(){var t,o,u,s,c,l,f;return ye(this,(function(p){switch(p.label){case 0:return t={"Content-Type":"application/json"},i&&Object.assign(t,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:be(be((c={},c[null===(l=this.i18n)||void 0===l?void 0:l.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,c),t),r),body:JSON.stringify(n),url:this.resolveUrl(e),stream:i,timeout:a})];case 1:return o=p.sent(),u=o.data,s=o.header,[2,this.handleResponseData(u,s)]}}))}))},this.botRequest=function(t){var e=t.method,n=t.url,r=t.data,i=void 0===r?{}:r,a=t.headers,u=t.stream,s=t.timeout;return me(o,void 0,void 0,(function(){var t,r,o,c,l,f,p,h,d;return ye(this,(function(v){switch(v.label){case 0:return t=this.resolveUrl(n),"get"!==e?[3,2]:(r=this.handleResponseData,[4,this.req.fetch({url:"".concat(t,"?").concat((b=i,Object.entries(b).map((function(t){var e=t[0],n=t[1];return"".concat(e,"=").concat(n)})).join("&"))),method:e,headers:a,stream:u,timeout:s})]);case 1:return[2,r.apply(this,[v.sent().data])];case 2:return o={"Content-Type":"application/json"},u&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:t,body:JSON.stringify(i),headers:be(be((p={},p[null===(h=this.i18n)||void 0===h?void 0:h.LANG_HEADER_KEY]=null===(d=this.i18n)||void 0===d?void 0:d.lang,p),o),a),stream:u,method:e,timeout:s})];case 3:return c=v.sent(),l=c.data,f=c.header,[2,this.handleResponseData(l,f)]}var b}))}))},this._getBaseUrl=r,this.bot=new A(this.botRequest,this.aiBotBaseUrl),this.i18n=n,de.on("lang_change",(function(t){var e;o.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||o.i18n}))}return Object.defineProperty(t.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),t.prototype.handleResponseData=function(t,e){var n,r;return me(this,void 0,void 0,(function(){var o,i;return ye(this,(function(a){switch(a.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),"object"==typeof t&&t&&"then"in t?[4,t]:[3,2];case 1:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));return[2,t];case 2:return(null===(r=null===(n=null==e?void 0:e.get)||void 0===n?void 0:n.call(e,"content-type"))||void 0===r?void 0:r.includes("application/json"))?[4,k(t)]:[3,4];case 3:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));a.label=4;case 4:return[2,t]}}))}))},t.prototype.createModel=function(t,e){var n,r=ge[t];if(r)n=new r(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==e?void 0:e.defaultModelSubUrl)?e.defaultModelSubUrl:"/chat/completions";n=new Et(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new Lt(n)},t.prototype.registerModel=function(t,e){null==ge[t]?ge[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new At(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){Ft.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),Ft.set(t.name,t.fn)},t.prototype.resolveUrl=function(t){if(!this._getBaseUrl)return t;var e=this._getBaseUrl();return e!==this.baseUrl&&t.startsWith(this.baseUrl)?t.replace(this.baseUrl,e):t},t}(),Se=function(){},Oe=function(){return Oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Oe.apply(this,arguments)},_e=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},xe=_e(s,["MODELS"]),je=function(t){var e=t.getAccessToken,n=t.req;return{download:n.download,post:n.post,upload:n.upload,fetch:function(t){return r=void 0,o=void 0,a=function(){var r,o,i,a,u;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,(function(s){switch(s.label){case 0:if("function"!=typeof n.fetch)throw new Error("req.fetch is not a function");return r=t.token,o=t.headers,i=void 0===o?{}:o,a=_e(t,["token","headers"]),null==r?[3,1]:(u=r,[3,3]);case 1:return[4,e()];case 2:u=s.sent().accessToken,s.label=3;case 3:return[2,n.fetch(Oe({headers:Oe({Authorization:"Bearer ".concat(u)},i)},a))]}}))},new((i=void 0)||(i=Promise))((function(t,e){function n(t){try{s(a.next(t))}catch(t){e(t)}}function u(t){try{s(a.throw(t))}catch(t){e(t)}}function s(e){var r;e.done?t(e.value):(r=e.value,r instanceof i?r:new i((function(t){t(r)}))).then(n,u)}s((a=a.apply(r,o||[])).next())}));var r,o,i,a}}};function ke(t){var e=t.env,n=t.baseUrl,r=t.getBaseUrl,o=t.req,i=t.getAccessToken,a=t.handleReqInstance,u=t.i18n;return new we(function(){if(null==a){if(null==i)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return je({req:o,getAccessToken:i})}return a({req:o})}(),function(){if(null!=r)return r();if(null!=n)return n;if(null==e)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(e,".api.tcloudbasegateway.com/v1")}(),u,r)}var Pe=ke,Ue={name:"ai",entity:{ai:function(t){var e=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var r=function(){var t=e.getEndPointWithKey("GATEWAY"),n=t.BASE_URL,r=t.PROTOCOL;return"".concat(r).concat(n)};return(null==t?void 0:t.baseUrl)?ke({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):ke({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function qe(t){try{t.registerComponent(Ue)}catch(t){console.warn(t)}}try{window.registerAi=qe}catch(t){}var Te=a.AI,Ie=a.rf,Re=a.pe,Ee=a.jE,Ae=a.jM,Ce=a.Cq,Me=a.el,Be=a.P6;export{Te as AI,Ie as Bot,Re as SimpleChatModel,Ee as createAI,Ae as createAi,Ce as models,Me as registerAi,Be as utils};
1
+ import*as t from"web-streams-polyfill";import*as e from"@mattiasbuelens/web-streams-adapter";import*as n from"text-encoding-shim";import*as r from"@cloudbase/adapter-interface";import*as o from"jwt-decode";var i={d:(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},a={};i.d(a,{AI:()=>we,rf:()=>A,pe:()=>Se,jE:()=>ke,jM:()=>Pe,Cq:()=>xe,el:()=>qe,P6:()=>u});var u={};i.r(u),i.d(u,{ReadableStream:()=>y,TextDecoderStream:()=>O,TransformStream:()=>g,createAsyncIterable:()=>_,createEventSourceParserTransformStream:()=>w,createPromise:()=>P,functionToolToModelTool:()=>q,intoStandardStream:()=>x,intoTextStream:()=>j,isToolCallAssistantMessage:()=>U,readableStream2JsonObject:()=>k,toPolyfillReadable:()=>S});var s={};i.r(s),i.d(s,{ArkSimpleModel:()=>nt,DSSimpleModel:()=>ut,DefaultImageModel:()=>At,DefaultSimpleModel:()=>Et,HunYuanBetaSimpleModel:()=>z,HunYuanExpSimpleModel:()=>St,HunYuanOpenSimpleModel:()=>jt,HunYuanSimpleModel:()=>Z,MODELS:()=>zt,MoonshotSimpleModel:()=>mt,ReactModel:()=>Lt,YiSimpleModel:()=>pt,ZhiPuSimpleModel:()=>L,toolMap:()=>Ft});const c=(l={ReadableStream:()=>t.ReadableStream,TransformStream:()=>t.TransformStream},f={},i.d(f,l),f);var l,f;const p=(t=>{var e={};return i.d(e,t),e})({createReadableStreamWrapper:()=>e.createReadableStreamWrapper});var h=[239,187,191];const d=(t=>{var e={};return i.d(e,t),e})({TextDecoder:()=>n.TextDecoder});var v=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},b=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},m=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,o){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,o,(e=t[n](e)).done,e.value)}))}}},y=c.ReadableStream,g=c.TransformStream,w=function(){var t;return new g({start:function(e){t=function(t){var e,n,r,o,i,a,u;return s(),{feed:function(t){n=n?n+t:t,e&&function(t){return h.every((function(e,n){return t.charCodeAt(n)===e}))}(n)&&(n=n.slice(h.length)),e=!1;for(var i=n.length,a=0,u=!1;a<i;){u&&("\n"===n[a]&&(a+=1),u=!1);for(var s=-1,l=o,f=void 0,p=r;s<0&&p<i;p++)":"===(f=n[p])&&l<0?l=p-a:"\r"===f?(u=!0,s=p-a):"\n"===f&&(s=p-a);if(s<0){r=i-a,o=l;break}r=0,o=-1,c(n,a,l,s),a+=s+1}a===i?n="":a>0&&(n=n.slice(a))},reset:s};function s(){e=!0,n="",r=0,o=-1,i=void 0,a=void 0,u=""}function c(e,n,r,o){if(0===o)return u.length>0&&(t({type:"event",id:i,event:a||void 0,data:u.slice(0,-1)}),u="",i=void 0),void(a=void 0);var s,c=r<0,l=e.slice(n,n+(c?o:r)),f=n+(s=c?o:" "===e[n+r+1]?r+2:r+1),p=o-s,h=e.slice(f,f+p).toString();if("data"===l)u+=h?"".concat(h,"\n"):"\n";else if("event"===l)a=h;else if("id"!==l||h.includes("\0")){if("retry"===l){var d=parseInt(h,10);Number.isNaN(d)||t({type:"reconnect-interval",value:d})}}else i=h}}((function(t){"event"===t.type&&e.enqueue(t)}))},transform:function(e){t.feed(e)}})},S=(0,p.createReadableStreamWrapper)(y),O=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var n=this;this.transform=new g({transform:function(t,e){var r=n.handle.decode(new Uint8Array(t),{stream:!0});r&&e.enqueue(r)},flush:function(t){var e=n.handle.decode();e&&t.enqueue(e),t.terminate()}}),this.handle=new d.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 _(t){var e=t;return e[Symbol.asyncIterator]=function(){var e=t.getReader();return{next:function(){return v(this,void 0,Promise,(function(){var t,n,r;return b(this,(function(o){switch(o.label){case 0:return[4,e.read()];case 1:return t=o.sent(),n=t.done,r=t.value,[2,n?{done:!0,value:void 0}:{done:!1,value:r}]}}))}))}}},e}function x(t){return _(t.pipeThrough(new O).pipeThrough(w()).pipeThrough(new g({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))}function j(t){return _(S(t).pipeThrough(new O))}function k(t){var e,n,r,o;return v(this,void 0,void 0,(function(){var i,a,u,s,c,l;return b(this,(function(f){switch(f.label){case 0:i=j(t),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),u=!0,s=m(i),f.label=2;case 2:return[4,s.next()];case 3:if(c=f.sent(),e=c.done)return[3,5];o=c.value,u=!1;try{a+=o}finally{u=!0}f.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return l=f.sent(),n={error:l},[3,12];case 7:return f.trys.push([7,,10,11]),u||e||!(r=s.return)?[3,9]:[4,r.call(s)];case 8:f.sent(),f.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(a)]}}))}))}function P(){var t,e;return{promise:new Promise((function(n,r){t=n,e=r})),res:t,rej:e}}function U(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 q(t){return{type:"function",function:{description:t.description,name:t.name,parameters:t.parameters}}}var I=function(){return I=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},I.apply(this,arguments)},T=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},R=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},E=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},A=function(){function t(t,e){this.baseUrl=e;var n=arguments[2];this.req="string"==typeof n?function(e){var r=e.headers,o=void 0===r?{}:r,i=E(e,["headers"]);return t(I(I({},i),{headers:I(I({},o),{Authorization:"Bearer ".concat(n)})}))}: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 n=t.botInfo;return this.req({method:"post",url:this.join("bots"),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.get=function(t,e){var n=t.botId;return this.req({method:"get",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.update=function(t,e){var n=t.botId,r=t.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(n)),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.delete=function(t,e){var n=t.botId;return this.req({method:"delete",url:this.join("bots/".concat(n)),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 n=t.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(n.botId,"/feedback")),data:n,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 T(this,void 0,void 0,(function(){return R(this,(function(n){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 n=t.botId,r=E(t,["botId"]);return T(this,void 0,void 0,(function(){return R(this,(function(t){return[2,this.req({method:"post",url:this.join("bots/".concat(n,"/conversation")),data:r,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.getConversation=function(t,e){var n=t.pageSize,r=void 0===n?10:n,o=t.pageNumber,i=void 0===o?1:o,a=t.botId,u=E(t,["pageSize","pageNumber","botId"]);return T(this,void 0,void 0,(function(){var t,n;return R(this,(function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return t=r*(i-1),n=r,[2,this.req({method:"get",url:this.join("bots/".concat(a,"/conversation")),data:I(I({},u),{offset:t,limit:n}),timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.deleteConversation=function(t,e){var n=t.botId,r=t.conversationId,o=E(t,["botId","conversationId"]);return T(this,void 0,void 0,(function(){return R(this,(function(t){return[2,this.req({method:"delete",url:this.join("bots/".concat(n,"/conversation/").concat(r)),data:o,timeout:null==e?void 0:e.timeout})]}))}))},t.prototype.speechToText=function(t,e){return T(this,void 0,void 0,(function(){return R(this,(function(n){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 T(this,void 0,void 0,(function(){return R(this,(function(n){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 T(this,void 0,void 0,(function(){return R(this,(function(n){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 T(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},t.prototype.generateBot=function(t,e){return T(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},t.prototype.getPreview=function(t,e){return T(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},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 T(this,void 0,void 0,(function(){var n;return R(this,(function(r){switch(r.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 n=r.sent(),[2,new C(n)]}}))}))},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),C=function(){function t(t){var e=S(t);this._eventSourceStream=e.pipeThrough(new O).pipeThrough(w())}return Object.defineProperty(t.prototype,"teeedStream",{get:function(){var t=this._eventSourceStream.tee(),e=t[0],n=t[1];return this._eventSourceStream=n,e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eventSourceStream",{get:function(){return _(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return _(this.eventSourceStream.pipeThrough(new g({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textStream",{get:function(){return _(this.dataStream.pipeThrough(new g({transform:function(t,e){var n;e.enqueue(null!==(n=null==t?void 0:t.content)&&void 0!==n?n:"")}})))},enumerable:!1,configurable:!0}),t}(),M=function(){return M=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},M.apply(this,arguments)},G=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},B=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function D(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return M(M({},t),{messages:e,model:n,temperature:r,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:a})}var L=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=n&&(this.subUrl=n)}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 G(this,void 0,Promise,(function(){var n,r;return B(this,(function(o){switch(o.label){case 0:return n=D(t),[4,this.req({url:this.url,data:M(M({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,M(M({},r),{rawResponse:r})]}}))}))},t.prototype.doStream=function(t,e){return G(this,void 0,Promise,(function(){var n,r,o,i;return B(this,(function(a){switch(a.label){case 0:return n=D(t),r=null,[4,this.req({url:this.url,data:M(M({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=a.sent(),i=S(o),[2,_(x(i).pipeThrough(new g({transform:function(t,e){var n=t.choices.map((function(t){var e=t.delta;return null==r&&(r=U(e)),r?M(M({},t),{finish_reason:"tool_calls",delta:e}):t})),o=M(M({},t),{choices:n});e.enqueue(M(M({},o),{rawResponse:t}))}})))]}}))}))},t}(),N=function(){return N=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},N.apply(this,arguments)};function J(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return N(N({},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:n,tools:function(){if(i)return i.forEach((function(t){"function"!==t.type&&console.warn("`type` in tool is not 'function'",t)})),i}(),top_p:a,tool_choice:o,temperature:r})}function F(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map((function(t){return F(t)})):Object.entries(t).reduce((function(t,e){var n,r=e[0],o=e[1];return t["_"===(n=r.replace(/[A-Z]/g,(function(t){return"_".concat(t.toLowerCase())}))).charAt(0)?n.slice(1):n]="object"==typeof o?F(o):o,t}),{})}var W=function(){return W=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},W.apply(this,arguments)},H=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Y=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},z=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=n&&(this.subUrl=n)}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 H(this,void 0,Promise,(function(){var n;return Y(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:W(W({},J(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,W(W({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return H(this,void 0,Promise,(function(){var n,r,o;return Y(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:W(W({},J(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(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}(),K=function(){return K=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},K.apply(this,arguments)},X=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},V=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Z=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan",null!=n&&(this.subUrl=n)}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 X(this,void 0,Promise,(function(){var n,r;return V(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:K(K({},J(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),r=F(n.Response),[2,K(K({},r),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return X(this,void 0,Promise,(function(){var n,r,o;return V(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:K(K({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=F(t),o=r.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?K(K({},t),{finish_reason:"tool_calls",delta:e}):t})),i=K(K({},r),{choices:o});e.enqueue(K(K({},i),{rawResponse:t}))}})))]}}))}))},t}(),Q=function(){return Q=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Q.apply(this,arguments)},$=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},tt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function et(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return Q(Q({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var nt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="ark/api/v3/chat/completions",null!=n&&(this.subUrl=n)}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 $(this,void 0,Promise,(function(){var n;return tt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Q(Q({},et(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Q(Q({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return $(this,void 0,Promise,(function(){var n,r,o;return tt(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Q(Q({},et(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?Q(Q({},t),{finish_reason:"tool_calls",delta:e}):t})),o=Q(Q({},t),{choices:r});e.enqueue(Q(Q({},o),{rawResponse:t}))}})))]}}))}))},t}(),rt=function(){return rt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},rt.apply(this,arguments)},ot=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},it=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function at(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return rt(rt({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var ut=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=n&&(this.subUrl=n)}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 ot(this,void 0,Promise,(function(){var n;return it(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:rt(rt({},at(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,rt(rt({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return ot(this,void 0,Promise,(function(){var n,r,o;return it(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:rt(rt({},at(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=U(e)),rt(rt({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})})),o=rt(rt({},t),{choices:r});e.enqueue(rt(rt({},o),{rawResponse:t}))}})))]}}))}))},t}(),st=function(){return st=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},st.apply(this,arguments)},ct=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},lt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function ft(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return st(st({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var pt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="01-ai/v1/chat/completions",null!=n&&(this.subUrl=n)}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 ct(this,void 0,Promise,(function(){var n;return lt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:st(st({},ft(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,st(st({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return ct(this,void 0,Promise,(function(){var n,r,o,i,a;return lt(this,(function(u){switch(u.label){case 0:return n=null,[4,this.req({url:this.url,data:st(st({},ft(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=u.sent(),o=S(r),i=x(o),a=i.pipeThrough(new g({transform:function(t,e){var r,o,i,a,u,s;if((null===(i=null===(o=null===(r=null==t?void 0:t.choices)||void 0===r?void 0:r[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(s=null===(u=null===(a=null==t?void 0:t.choices)||void 0===a?void 0:a[0])||void 0===u?void 0:u.delta)||void 0===s?void 0:s.tool_calls)){var c=t.choices.map((function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=U(e)),st(st({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})})),l=st(st({},t),{choices:c});e.enqueue(st(st({},l),{rawResponse:t}))}}})),[2,_(a)]}}))}))},t}(),ht=function(){return ht=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ht.apply(this,arguments)},dt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},vt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function bt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return ht(ht({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var mt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="moonshot/v1/chat/completions",null!=n&&(this.subUrl=n)}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 dt(this,void 0,Promise,(function(){var n;return vt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:ht(ht({},bt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,ht(ht({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return dt(this,void 0,Promise,(function(){var n,r,o;return vt(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:ht(ht({},bt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?ht(ht({},t),{finish_reason:"tool_calls",delta:e}):t})),o=ht(ht({},t),{choices:r});e.enqueue(ht(ht({},o),{rawResponse:t}))}})))]}}))}))},t}(),yt=function(){return yt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},yt.apply(this,arguments)},gt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},wt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},St=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-exp/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return gt(this,void 0,Promise,(function(){var e;return wt(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:yt(yt({},J(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,yt(yt({},e),{rawResponse:e})]}}))}))},t.prototype.doStream=function(t){return gt(this,void 0,Promise,(function(){var e,n,r;return wt(this,(function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:yt(yt({},J(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=S(n),[2,_(x(r).pipeThrough(new g({transform:function(t,n){var r=t.choices.map((function(t){var n=t.delta;return null==e&&(e=U(n)),e?yt(yt({},t),{finish_reason:"tool_calls",delta:n}):t})),o=yt(yt({},t),{choices:r});n.enqueue(yt(yt({},o),{rawResponse:t}))}})))]}}))}))},t}(),Ot=function(){return Ot=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ot.apply(this,arguments)},_t=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},xt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},jt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-open/v1/chat/completions",null!=n&&(this.subUrl=n)}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 _t(this,void 0,Promise,(function(){var n;return xt(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ot(Ot({},J(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ot(Ot({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return _t(this,void 0,Promise,(function(){var n,r,o;return xt(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ot(Ot({},J(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?Ot(Ot({},t),{finish_reason:"tool_calls",delta:e}):t})),o=Ot(Ot({},t),{choices:r});e.enqueue(Ot(Ot({},o),{rawResponse:t}))}})))]}}))}))},t}(),kt=function(){return kt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},kt.apply(this,arguments)},Pt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Ut=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},qt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="deepseek/chat/completions",null!=n&&(this.subUrl=n)}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 Pt(this,void 0,Promise,(function(){var n;return Ut(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:kt(kt({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,kt(kt({},n),{rawResponse:n})]}}))}))},t.prototype.doStream=function(t,e){return Pt(this,void 0,Promise,(function(){var n,r,o;return Ut(this,(function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:kt(kt({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=S(r),[2,_(x(o).pipeThrough(new g({transform:function(t,e){var r=t.choices.map((function(t){var e=t.delta;return null==n&&(n=U(e)),n?kt(kt({},t),{finish_reason:"tool_calls",delta:e}):t})),o=kt(kt({},t),{choices:r});e.enqueue(kt(kt({},o),{rawResponse:t}))}})))]}}))}))},t}(),It=function(){return It=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},It.apply(this,arguments)},Tt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Rt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Et=function(){function t(t,e,n){void 0===n&&(n=""),this.req=t,this.baseUrl=e,this.subUrl=n}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return Tt(this,void 0,Promise,(function(){var e;return Rt(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:It(It({},t),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,It(It({},e),{rawResponse:e})]}}))}))},t.prototype.doStream=function(t){return Tt(this,void 0,Promise,(function(){var e,n,r;return Rt(this,(function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:It(It({},t),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=S(n),[2,_(x(r).pipeThrough(new g({transform:function(t,n){var r=t.choices.map((function(t){var n=t.delta;return null==e&&(e=U(n)),e?It(It({},t),{finish_reason:"tool_calls",delta:n}):t})),o=It(It({},t),{choices:r});n.enqueue(It(It({},o),{rawResponse:t}))}})))]}}))}))},t}(),At=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.provider=n,this.defaultGenerateImageSubUrl="images/ar/generations",this.generateImageSubUrlConfig={"hunyuan-image":[[/^hunyuan-image(-v[12](\..*)?)?$/,"images/generations"]]},this.generateImage=this.generateImageImpl.bind(this)}return t.prototype.generateImageImpl=function(t){return e=this,n=void 0,o=function(){var e,n;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,(function(r){switch(r.label){case 0:return e=this.defaultGenerateImageSubUrl,"object"==typeof t&&t&&"model"in t&&"string"==typeof t.model&&(n=this.getGenerateImageSubUrl(this.provider,t.model))&&(e=n),[4,this.req({url:this.getGenerateUrl(e),data:t,stream:!1})];case 1:return[2,r.sent()]}}))},new((r=Promise)||(r=Promise))((function(t,i){function a(t){try{s(o.next(t))}catch(t){i(t)}}function u(t){try{s(o.throw(t))}catch(t){i(t)}}function s(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(a,u)}s((o=o.apply(e,n||[])).next())}));var e,n,r,o},t.prototype.getGenerateUrl=function(t){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(t)},t.prototype.getGenerateImageSubUrl=function(t,e){var n=this.generateImageSubUrlConfig[t];if(n)for(var r=0,o=n;r<o.length;r++){var i=o[r],a=i[0],u=i[1];if(a.test(e))return u}},t}(),Ct=function(){return Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ct.apply(this,arguments)},Mt=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},Gt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Bt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Dt(t){var e,n=t.onStepFinish,r=t.abortSignal,o=t.maxSteps,i=t.topP,a=t.toolChoice,u=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:n,abortSignal:r,maxSteps:o},Ct(Ct({},u),{tools:null===(e=u.tools)||void 0===e?void 0:e.map((function(t){return"fn"in t?q(t):t})),top_p:null!=i?i:u.top_p,tool_choice:null!=a?a:u.tool_choice})]}var Lt=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return Mt(this,void 0,Promise,(function(){var o,i,a,u,s,c,l,f,p,h,d,v,b,m,y,g,w,S,O,_,x,j=this;return Gt(this,(function(k){switch(k.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Dt(t),u=a[0],s=u.onStepFinish,c=u.maxSteps,l=void 0===c?10:c,f=a[1],[4,(p=function(){return j.model.doGenerate(f,e)})()];case 1:h=k.sent(),d=1,h.rawResponse&&o.push(h.rawResponse),v=null,k.label=2;case 2:if(!(d<l&&null!=(v=Nt(h))))return[3,9];b=Ht(h.usage),Yt(i,b),k.label=3;case 3:return k.trys.push([3,7,,8]),[4,Wt(v)];case 4:return m=k.sent(),y=h.choices[0],[4,null==s?void 0:s({finishReason:y.finish_reason,messages:f.messages.slice(),text:y.message.content,toolCall:v,toolResult:m,stepUsage:b,totalUsage:Object.assign({},i)})];case 5:return k.sent(),Jt(f.messages,y.message,m),[4,p()];case 6:return(h=k.sent()).rawResponse&&o.push(h.rawResponse),d+=1,[3,8];case 7:return g=k.sent(),[2,{text:"",messages:f.messages,usage:i,error:g,rawResponses:o}];case 8:return[3,2];case 9:return w=null===(n=null==h?void 0:h.choices)||void 0===n?void 0:n[0],S=null==w?void 0:w.message,O=null!==(r=null==S?void 0:S.content)&&void 0!==r?r:"",_=S?Bt(Bt([],f.messages,!0),[S],!1):f.messages,x=Ht(h.usage),Yt(i,x),[4,null==s?void 0:s({finishReason:w.finish_reason,messages:_.slice(),text:O,toolCall:Nt(h),toolResult:null,stepUsage:x,totalUsage:Object.assign({},i)})];case 10:return k.sent(),[2,{text:O,messages:_,usage:i,rawResponses:o}]}}))}))},t.prototype.streamText=function(t,e){var n;return Mt(this,void 0,Promise,(function(){var r,o,i,a,u,s,c,l,f,p,h,d,v,b,m,y,w,S,O,x,j,k,U,q,I,T,R,E,A,C,M,G,B,D,L,N,J=this;return Gt(this,(function(F){switch(F.label){case 0:return r={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=Dt(t),i=o[0],a=i.onStepFinish,u=i.maxSteps,s=void 0===u?10:u,c=o[1],[4,(l=function(){return J.model.doStream(c,e)})()];case 1:f=F.sent(),p=1,h=null,d=function(){var t=f.tee(),e=t[0],n=t[1];return f=_(e),function(t){var e,n,r,o,i,a,u,s,c,l;return Mt(this,void 0,Promise,(function(){var f,p,h,d,v,b,m,y,g,w,S,O,x;return Gt(this,(function(j){switch(j.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},p=_(t),d={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},j.label=1;case 1:j.trys.push([1,6,7,12]),v=!0,b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,o){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,o,(e=t[n](e)).done,e.value)}))}}}(p),j.label=2;case 2:return[4,b.next()];case 3:if(m=j.sent(),e=m.done)return[3,5];o=m.value,v=!1;try{if(!(g=null==(y=o)?void 0:y.choices[0]))return[2,null];if(w=g.finish_reason,S=g.delta,"tool_calls"!==w)return[2,null];if(!S)return[3,4];if(S.content&&(d.content+=S.content),!("tool_calls"in S))return[3,4];(null==(O=null===(i=null==S?void 0:S.tool_calls)||void 0===i?void 0:i[0])?void 0:O.id)&&(h.id=O.id),(null==O?void 0:O.type)&&(h.type=O.type),(null===(a=null==O?void 0:O.function)||void 0===a?void 0:a.name)&&(h.function.name=O.function.name),(null===(u=null==O?void 0:O.function)||void 0===u?void 0:u.arguments)&&(h.function.arguments+=O.function.arguments),(null===(s=null==y?void 0:y.usage)||void 0===s?void 0:s.completion_tokens)&&(f.completion_tokens=y.usage.completion_tokens),(null===(c=null==y?void 0:y.usage)||void 0===c?void 0:c.prompt_tokens)&&(f.prompt_tokens=y.usage.prompt_tokens),(null===(l=null==y?void 0:y.usage)||void 0===l?void 0:l.total_tokens)&&(f.total_tokens=y.usage.total_tokens)}finally{v=!0}j.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return x=j.sent(),n={error:x},[3,12];case 7:return j.trys.push([7,,10,11]),v||e||!(r=b.return)?[3,9]:[4,r.call(b)];case 8:j.sent(),j.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,{message:d,usage:f}]}}))}))}(n)},F.label=2;case 2:return(v=p<s)?[4,d()]:[3,4];case 3:v=null!=(h=F.sent()),F.label=4;case 4:if(!v)return[3,11];b=h.message,m=h.usage,Yt(r,m),y=null===(n=b.tool_calls)||void 0===n?void 0:n[0],F.label=5;case 5:return F.trys.push([5,9,,10]),[4,Wt(y)];case 6:return w=F.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:c.messages.slice(),text:b.content,toolCall:y,toolResult:w,stepUsage:m,totalUsage:Object.assign({},r)})];case 7:return F.sent(),Jt(c.messages,b,w),[4,l()];case 8:return f=F.sent(),[3,10];case 9:return S=F.sent(),O=f.tee(),x=O[0],j=O[1],[2,{messages:Promise.resolve(c.messages),dataStream:_(x),textStream:_(j.pipeThrough(new g({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r),error:S}];case 10:return[3,2];case 11:return[4,d()];case 12:return(h=F.sent())?(k=h.message,U=h.usage,Yt(r,U),q=Bt(Bt([],c.messages,!0),[k],!1),a({messages:q.slice(),finishReason:"tool_call",stepUsage:U,text:k.content,toolCall:k.tool_calls[0],totalUsage:Object.assign({},r)}),I=f.tee(),T=I[0],R=I[1],[2,{messages:Promise.resolve(Bt(Bt([],c.messages,!0),[k],!1)),dataStream:_(T),textStream:_(R.pipeThrough(new g({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r)}]):(E=P(),A=P(),C={role:"assistant",content:""},M="",G={completion_tokens:0,prompt_tokens:0,total_tokens:0},B=f.pipeThrough(new g({transform:function(t,e){var n,r,o,i,a,u,s,c,l=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof l&&(C.content+=l);var f=null===(a=null===(i=null==t?void 0:t.choices)||void 0===i?void 0:i[0])||void 0===a?void 0:a.finish_reason;f&&(M=f),(null===(u=null==t?void 0:t.usage)||void 0===u?void 0:u.completion_tokens)&&(G.completion_tokens=t.usage.completion_tokens),(null===(s=null==t?void 0:t.usage)||void 0===s?void 0:s.prompt_tokens)&&(G.prompt_tokens=t.usage.prompt_tokens),(null===(c=null==t?void 0:t.usage)||void 0===c?void 0:c.total_tokens)&&(G.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){E.res(Bt(Bt([],c.messages,!0),[C],!1)),Yt(r,G),A.res(Object.assign({},r)),null==a||a({messages:Bt(Bt([],c.messages,!0),[C],!1),finishReason:M,text:C.content,stepUsage:G,totalUsage:Object.assign({},r)})}})),D=B.tee(),L=D[0],N=D[1],[2,{messages:E.promise,dataStream:_(L),textStream:_(N.pipeThrough(new g({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:A.promise}])}}))}))},t}();function Nt(t){var e,n=null===(e=null==t?void 0:t.choices)||void 0===e?void 0:e[0];if(!n)return null;var r=n.finish_reason,o=n.message;return"tool_calls"!==r?null:o&&U(o)?o.tool_calls[0]:null}function Jt(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var Ft=new Map;function Wt(t){return Ft.get(t.function.name)(JSON.parse(t.function.arguments))}function Ht(t){var e,n,r;return{completion_tokens:null!==(e=null==t?void 0:t.completion_tokens)&&void 0!==e?e:0,prompt_tokens:null!==(n=null==t?void 0:t.prompt_tokens)&&void 0!==n?n:0,total_tokens:null!==(r=null==t?void 0:t.total_tokens)&&void 0!==r?r:0}}function Yt(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var zt={hunyuan:Z,"hunyuan-beta":z,ark:nt,dashscope:ut,"01-ai":pt,moonshot:mt,zhipu:L,"hunyuan-exp":St,"hunyuan-open":jt,deepseek:qt},Kt="@cloudbase/js-sdk";function Xt(){return Kt}var Vt="INVALID_OPERATION",Zt="OPERATION_FAIL";const Qt=(t=>{var e={};return i.d(e,t),e})({AbstractSDKRequest:()=>r.AbstractSDKRequest,AbstractStorage:()=>r.AbstractStorage});function $t(t,e){console.warn("[".concat(Xt(),"][").concat(t,"]:").concat(e))}var te,ee,ne=(te=function(t,e){return te=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},te(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}te(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),re=function(){return re=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},re.apply(this,arguments)},oe=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},ie=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}ne(e,t),e.prototype.get=function(t){return this.request(re(re({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(re(re({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(re(re({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,i=t.headers,a=void 0===i?{}:i,u={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",s=new FormData;return"post"===u?(Object.keys(e).forEach((function(t){s.append(t,e[t])})),s.append("key",r),s.append("file",n),this.request(re(re({},t),{data:s,method:u}),this.restrictedMethods.includes("upload"))):this.request(re(re({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return oe(this,void 0,Promise,(function(){var e,n,r,o;return ie(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(re(re({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return oe(this,void 0,Promise,(function(){var n,r,o,i,a,u,s,c,l,f,p,h,d,v=this;return ie(this,(function(b){switch(b.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,a=t.stream,u=void 0!==a&&a,s=t.signal,c=t.timeout,l=t.shouldThrowOnError,f=void 0===l||l,p=null!=c?c:this.timeout,s&&(s.aborted&&n.abort(),s.addEventListener("abort",(function(){return n.abort()}))),h=null,i&&p&&(h=setTimeout((function(){console.warn(v.timeoutMsg),n.abort(new Error(v.timeoutMsg))}),p)),[4,fetch(r,re(re({},t),{signal:n.signal})).then((function(t){return oe(v,void 0,void 0,(function(){var e,n,r;return ie(this,(function(o){switch(o.label){case 0:return clearTimeout(h),f?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}}))}))})).catch((function(t){return clearTimeout(h),Promise.reject(t)}))];case 1:return d=b.sent(),[2,{data:u?d.body:(null===(e=d.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?d.json():d.text(),statusCode:d.status,header:d.headers,response:d}]}}))}))},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise((function(o){var i=t.url,a=t.headers,u=void 0===a?{}:a,s=t.data,c=t.responseType,l=t.withCredentials,f=t.body,p=t.onUploadProgress,h=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach((function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))})),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",i,"get"===r?s:{}),d=new XMLHttpRequest;d.open(r,h),c&&(d.responseType=c);var v,b,m,y=t.signal;y&&(y.aborted?d.abort():y.addEventListener("abort",(function(){return d.abort()}),{once:!0})),Object.keys(u).forEach((function(t){d.setRequestHeader(t,u[t])})),p&&d.upload.addEventListener("progress",p),d.onreadystatechange=function(){var t={};if(4===d.readyState){var e=d.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach((function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o})),t.header=n,t.statusCode=d.status;try{t.data="blob"===c?d.response:JSON.parse(d.responseText)}catch(e){t.data="blob"===c?d.response:d.responseText}clearTimeout(v),o(t)}},e&&n.timeout&&(v=setTimeout((function(){console.warn(n.timeoutMsg),d.abort()}),n.timeout)),m=s,b="[object FormData]"===Object.prototype.toString.call(m)?s:"application/x-www-form-urlencoded"===u["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))})),e.join("&")}(s):f||(s?JSON.stringify(s):void 0),l&&(d.withCredentials=!0),d.send(b)}))}}(Qt.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(ee||(ee={}));var ae=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),ue=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},se=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},ce=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return ae(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(Qt.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:($t("INVALID_PARAMS","localStorage is not supported on current platform"),new ce(e.root));case"none":return new ce(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:Zt,msg:"[".concat(Xt(),"][").concat(Zt,"]setStore failed"),info:t}))}}else $t(Vt,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return ue(this,void 0,void 0,(function(){var r;return se(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}$t(Vt,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return ue(this,void 0,void 0,(function(){var r;return se(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):$t(Vt,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return ue(this,void 0,void 0,(function(){return se(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var le=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),fe=function(t,e){this.data=e||null,this.name=t},pe=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return le(e,t),e}(fe),he=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof pe)return console.error(t.error),this;var n="string"==typeof t?new fe(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new he;var de=new he;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const ve=(t=>{var e={};return i.d(e,t),e})({default:()=>o.default});ve.default;var be=function(){return be=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},be.apply(this,arguments)},me=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},ye=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},ge=zt,we=function(){function t(t,e,n,r){var o=this;this.req=t,this.baseUrl=e,this.modelRequest=function(t){var e=t.url,n=t.data,r=t.headers,i=t.stream,a=t.timeout;return me(o,void 0,void 0,(function(){var t,o,u,s,c,l,f;return ye(this,(function(p){switch(p.label){case 0:return t={"Content-Type":"application/json"},i&&Object.assign(t,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:be(be((c={},c[null===(l=this.i18n)||void 0===l?void 0:l.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,c),t),r),body:JSON.stringify(n),url:this.resolveUrl(e),stream:i,timeout:a})];case 1:return o=p.sent(),u=o.data,s=o.header,[2,this.handleResponseData(u,s)]}}))}))},this.botRequest=function(t){var e=t.method,n=t.url,r=t.data,i=void 0===r?{}:r,a=t.headers,u=t.stream,s=t.timeout;return me(o,void 0,void 0,(function(){var t,r,o,c,l,f,p,h,d;return ye(this,(function(v){switch(v.label){case 0:return t=this.resolveUrl(n),"get"!==e?[3,2]:(r=this.handleResponseData,[4,this.req.fetch({url:"".concat(t,"?").concat((b=i,Object.entries(b).map((function(t){var e=t[0],n=t[1];return"".concat(e,"=").concat(n)})).join("&"))),method:e,headers:a,stream:u,timeout:s})]);case 1:return[2,r.apply(this,[v.sent().data])];case 2:return o={"Content-Type":"application/json"},u&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:t,body:JSON.stringify(i),headers:be(be((p={},p[null===(h=this.i18n)||void 0===h?void 0:h.LANG_HEADER_KEY]=null===(d=this.i18n)||void 0===d?void 0:d.lang,p),o),a),stream:u,method:e,timeout:s})];case 3:return c=v.sent(),l=c.data,f=c.header,[2,this.handleResponseData(l,f)]}var b}))}))},this._getBaseUrl=r,this.bot=new A(this.botRequest,this.aiBotBaseUrl),this.i18n=n,de.on("lang_change",(function(t){var e;o.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||o.i18n}))}return Object.defineProperty(t.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),t.prototype.handleResponseData=function(t,e){var n,r;return me(this,void 0,void 0,(function(){var o,i;return ye(this,(function(a){switch(a.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),"object"==typeof t&&t&&"then"in t?[4,t]:[3,2];case 1:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));return[2,t];case 2:return(null===(r=null===(n=null==e?void 0:e.get)||void 0===n?void 0:n.call(e,"content-type"))||void 0===r?void 0:r.includes("application/json"))?[4,k(t)]:[3,4];case 3:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));a.label=4;case 4:return[2,t]}}))}))},t.prototype.createModel=function(t,e){var n,r=ge[t];if(r)n=new r(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==e?void 0:e.defaultModelSubUrl)?e.defaultModelSubUrl:"/chat/completions";n=new Et(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new Lt(n)},t.prototype.registerModel=function(t,e){null==ge[t]?ge[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new At(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){Ft.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),Ft.set(t.name,t.fn)},t.prototype.resolveUrl=function(t){if(!this._getBaseUrl)return t;var e=this._getBaseUrl();return e!==this.baseUrl&&t.startsWith(this.baseUrl)?t.replace(this.baseUrl,e):t},t}(),Se=function(){},Oe=function(){return Oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Oe.apply(this,arguments)},_e=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},xe=_e(s,["MODELS"]),je=function(t){var e=t.getAccessToken,n=t.req;return{download:n.download,post:n.post,upload:n.upload,fetch:function(t){return r=void 0,o=void 0,a=function(){var r,o,i,a,u;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,(function(s){switch(s.label){case 0:if("function"!=typeof n.fetch)throw new Error("req.fetch is not a function");return r=t.token,o=t.headers,i=void 0===o?{}:o,a=_e(t,["token","headers"]),null==r?[3,1]:(u=r,[3,3]);case 1:return[4,e()];case 2:u=s.sent().accessToken,s.label=3;case 3:return[2,n.fetch(Oe({headers:Oe({Authorization:"Bearer ".concat(u)},i)},a))]}}))},new((i=void 0)||(i=Promise))((function(t,e){function n(t){try{s(a.next(t))}catch(t){e(t)}}function u(t){try{s(a.throw(t))}catch(t){e(t)}}function s(e){var r;e.done?t(e.value):(r=e.value,r instanceof i?r:new i((function(t){t(r)}))).then(n,u)}s((a=a.apply(r,o||[])).next())}));var r,o,i,a}}};function ke(t){var e=t.env,n=t.baseUrl,r=t.getBaseUrl,o=t.req,i=t.getAccessToken,a=t.handleReqInstance,u=t.i18n;return new we(function(){if(null==a){if(null==i)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return je({req:o,getAccessToken:i})}return a({req:o})}(),function(){if(null!=r)return r();if(null!=n)return n;if(null==e)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(e,".api.tcloudbasegateway.com/v1")}(),u,r)}var Pe=ke,Ue={name:"ai",entity:{ai:function(t){var e=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var r=function(){var t=e.getEndPointWithKey("GATEWAY"),n=t.BASE_URL,r=t.PROTOCOL;return"".concat(r).concat(n)};return(null==t?void 0:t.baseUrl)?ke({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):ke({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function qe(t){try{t.registerComponent(Ue)}catch(t){console.warn(t)}}try{window.registerAi=qe}catch(t){}var Ie=a.AI,Te=a.rf,Re=a.pe,Ee=a.jE,Ae=a.jM,Ce=a.Cq,Me=a.el,Ge=a.P6;export{Ie as AI,Te as Bot,Re as SimpleChatModel,Ee as createAI,Ae as createAi,Ce as models,Me as registerAi,Ge as utils};
2
2
  //# sourceMappingURL=index.esm.js.map