UNPKG

@cloudbase/js-sdk

Version:
1 lines 85 kB
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:()=>Se,rf:()=>C,rT:()=>Bt,pe:()=>_e,jE:()=>Pe,jM:()=>Ue,Cq:()=>xe,el:()=>Ie,P6:()=>u});var u={};i.r(u),i.d(u,{ReadableStream:()=>g,TextDecoderStream:()=>O,TransformStream:()=>w,createAsyncIterable:()=>j,createEventSourceParserTransformStream:()=>S,createPromise:()=>U,functionToolToModelTool:()=>I,intoStandardStream:()=>x,intoTextStream:()=>k,isToolCallAssistantMessage:()=>q,readableStream2JsonObject:()=>P,toPolyfillReadable:()=>_});var s={};i.r(s),i.d(s,{ArkSimpleModel:()=>rt,DSSimpleModel:()=>st,DefaultImageModel:()=>Gt,DefaultSimpleModel:()=>Ct,HunYuanBetaSimpleModel:()=>K,HunYuanExpSimpleModel:()=>Ot,HunYuanOpenSimpleModel:()=>Pt,HunYuanSimpleModel:()=>Q,MODELS:()=>Zt,MoonshotSimpleModel:()=>gt,ReactModel:()=>Ht,YiSimpleModel:()=>ht,ZhiPuSimpleModel:()=>L,toolMap:()=>zt});const l=(c={ReadableStream:()=>t.ReadableStream,TransformStream:()=>t.TransformStream},f={},i.d(f,c),f);var c,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="function"==typeof globalThis.ReadableStream&&"function"==typeof globalThis.TransformStream&&"function"==typeof globalThis.ReadableStream.prototype.pipeThrough,g=y?globalThis.ReadableStream:l.ReadableStream,w=y?globalThis.TransformStream:l.TransformStream,S=function(){var t;return new w({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,c=o,f=void 0,p=r;s<0&&p<i;p++)":"===(f=n[p])&&c<0?c=p-a:"\r"===f?(u=!0,s=p-a):"\n"===f&&(s=p-a);if(s<0){r=i-a,o=c;break}r=0,o=-1,l(n,a,c,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 l(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,l=r<0,c=e.slice(n,n+(l?o:r)),f=n+(s=l?o:" "===e[n+r+1]?r+2:r+1),p=o-s,h=e.slice(f,f+p).toString();if("data"===c)u+=h?"".concat(h,"\n"):"\n";else if("event"===c)a=h;else if("id"!==c||h.includes("\0")){if("retry"===c){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)}})},_=y?function(t){return t}:(0,p.createReadableStreamWrapper)(g),O=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var n=this;this.transform=new w({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 j(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 j(t.pipeThrough(new O).pipeThrough(S()).pipeThrough(new w({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 k(t){return j(_(t).pipeThrough(new O))}function P(t){var e,n,r,o;return v(this,void 0,void 0,function(){var i,a,u,s,l,c;return b(this,function(f){switch(f.label){case 0:i=k(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(l=f.sent(),e=l.done)return[3,5];o=l.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 c=f.sent(),n={error:c},[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 U(){var t,e;return{promise:new Promise(function(n,r){t=n,e=r}),res:t,rej:e}}function q(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 I(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)},R=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())})},E=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])}}},A=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},C=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=A(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 R(this,void 0,void 0,function(){return E(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=A(t,["botId"]);return R(this,void 0,void 0,function(){return E(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=A(t,["pageSize","pageNumber","botId"]);return R(this,void 0,void 0,function(){var t,n;return E(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=A(t,["botId","conversationId"]);return R(this,void 0,void 0,function(){return E(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 R(this,void 0,void 0,function(){return E(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 R(this,void 0,void 0,function(){return E(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 R(this,void 0,void 0,function(){return E(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 R(this,void 0,void 0,function(){var n;return E(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 M(n)]}})})},t.prototype.generateBot=function(t,e){return R(this,void 0,void 0,function(){var n;return E(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 M(n)]}})})},t.prototype.getPreview=function(t,e){return R(this,void 0,void 0,function(){var n;return E(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 M(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 R(this,void 0,void 0,function(){var n;return E(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 M(n)]}})})},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),M=function(){function t(t){var e=_(t);this._eventSourceStream=e.pipeThrough(new O).pipeThrough(S())}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 j(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return j(this.eventSourceStream.pipeThrough(new w({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 j(this.dataStream.pipeThrough(new w({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}(),B=function(){return B=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},B.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())})},D=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 N(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return B(B({},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 D(this,function(o){switch(o.label){case 0:return n=N(t),[4,this.req({url:this.url,data:B(B({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,B(B({},r),{rawResponse:r})]}})})},t.prototype.doStream=function(t,e){return G(this,void 0,Promise,function(){var n,r,o,i;return D(this,function(a){switch(a.label){case 0:return n=N(t),r=null,[4,this.req({url:this.url,data:B(B({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=a.sent(),i=_(o),[2,j(x(i).pipeThrough(new w({transform:function(t,e){var n=t.choices.map(function(t){var e=t.delta;return null==r&&(r=q(e)),r?B(B({},t),{finish_reason:"tool_calls",delta:e}):t}),o=B(B({},t),{choices:n});e.enqueue(B(B({},o),{rawResponse:t}))}})))]}})})},t}(),J=function(){return J=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},J.apply(this,arguments)};function F(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return J(J({},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 H(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map(function(t){return H(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?H(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)},Y=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())})},z=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])}}},K=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 Y(this,void 0,Promise,function(){var n;return z(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:W(W({},F(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 Y(this,void 0,Promise,function(){var n,r,o;return z(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:W(W({},F(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(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}(),X=function(){return X=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},X.apply(this,arguments)},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())})},Z=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])}}},Q=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 V(this,void 0,Promise,function(){var n,r;return Z(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:X(X({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),r=H(n.Response),[2,X(X({},r),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return V(this,void 0,Promise,function(){var n,r,o;return Z(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:X(X({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=H(t),o=r.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?X(X({},t),{finish_reason:"tool_calls",delta:e}):t}),i=X(X({},r),{choices:o});e.enqueue(X(X({},i),{rawResponse:t}))}})))]}})})},t}(),$=function(){return $=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},$.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())})},et=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 nt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return $($({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var rt=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 tt(this,void 0,Promise,function(){var n;return et(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:$($({},nt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,$($({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return tt(this,void 0,Promise,function(){var n,r,o;return et(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:$($({},nt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?$($({},t),{finish_reason:"tool_calls",delta:e}):t}),o=$($({},t),{choices:r});e.enqueue($($({},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)},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())})},at=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 ut(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return ot(ot({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var st=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 it(this,void 0,Promise,function(){var n;return at(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:ot(ot({},ut(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 it(this,void 0,Promise,function(){var n,r,o;return at(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:ot(ot({},ut(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=q(e)),ot(ot({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),o=ot(ot({},t),{choices:r});e.enqueue(ot(ot({},o),{rawResponse:t}))}})))]}})})},t}(),lt=function(){return lt=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},lt.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())})},ft=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 pt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return lt(lt({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var ht=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 ft(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:lt(lt({},pt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,lt(lt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return ct(this,void 0,Promise,function(){var n,r,o,i,a;return ft(this,function(u){switch(u.label){case 0:return n=null,[4,this.req({url:this.url,data:lt(lt({},pt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=u.sent(),o=_(r),i=x(o),a=i.pipeThrough(new w({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 l=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=q(e)),lt(lt({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),c=lt(lt({},t),{choices:l});e.enqueue(lt(lt({},c),{rawResponse:t}))}}})),[2,j(a)]}})})},t}(),dt=function(){return dt=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},dt.apply(this,arguments)},vt=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])}}};function mt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return dt(dt({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var yt,gt=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 vt(this,void 0,Promise,function(){var n;return bt(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:dt(dt({},mt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,dt(dt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return vt(this,void 0,Promise,function(){var n,r,o;return bt(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:dt(dt({},mt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?dt(dt({},t),{finish_reason:"tool_calls",delta:e}):t}),o=dt(dt({},t),{choices:r});e.enqueue(dt(dt({},o),{rawResponse:t}))}})))]}})})},t}(),wt=function(){return wt=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},wt.apply(this,arguments)},St=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())})},_t=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])}}},Ot=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 St(this,void 0,Promise,function(){var e;return _t(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:wt(wt({},F(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,wt(wt({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return St(this,void 0,Promise,function(){var e,n,r;return _t(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:wt(wt({},F(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=_(n),[2,j(x(r).pipeThrough(new w({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=q(n)),e?wt(wt({},t),{finish_reason:"tool_calls",delta:n}):t}),o=wt(wt({},t),{choices:r});n.enqueue(wt(wt({},o),{rawResponse:t}))}})))]}})})},t}(),jt=function(){return jt=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},jt.apply(this,arguments)},xt=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())})},kt=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])}}},Pt=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 xt(this,void 0,Promise,function(){var n;return kt(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:jt(jt({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,jt(jt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return xt(this,void 0,Promise,function(){var n,r,o;return kt(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:jt(jt({},F(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?jt(jt({},t),{finish_reason:"tool_calls",delta:e}):t}),o=jt(jt({},t),{choices:r});e.enqueue(jt(jt({},o),{rawResponse:t}))}})))]}})})},t}(),Ut=function(){return Ut=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},Ut.apply(this,arguments)},qt=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])}}},Tt=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 qt(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:Ut(Ut({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ut(Ut({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return qt(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:Ut(Ut({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?Ut(Ut({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Ut(Ut({},t),{choices:r});e.enqueue(Ut(Ut({},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)},Et=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())})},At=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])}}},Ct=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 Et(this,void 0,Promise,function(){var e;return At(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Rt(Rt({},t),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,Rt(Rt({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return Et(this,void 0,Promise,function(){var e,n,r;return At(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:Rt(Rt({},t),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=_(n),[2,j(x(r).pipeThrough(new w({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=q(n)),e?Rt(Rt({},t),{finish_reason:"tool_calls",delta:n}):t}),o=Rt(Rt({},t),{choices:r});n.enqueue(Rt(Rt({},o),{rawResponse:t}))}})))]}})})},t}(),Mt=(yt=function(t,e){return yt=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])},yt(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}yt(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),Bt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.name="InvalidParamsError",r.code="INVALID_PARAMS",r.field=n,r}return Mt(e,t),e.prototype.toJSON=function(){return{code:this.code,message:this.message,field:this.field}},e}(Error),Gt=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,r,o,i;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(a){switch(a.label){case 0:if("object"==typeof t&&t&&"model"in t&&"HY-Image-v3.0-I2I-ToB-v1.0.1"===t.model&&(""===this.provider||"hunyuan-image"===this.provider)){if(n=(e=t).image_urls,r=e.images,n&&n.length>1)throw new Bt("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,image_urls 最多只能有 1 个元素","image_urls");if(r&&r.lengt