@cloudbase/js-sdk 3.6.2 → 3.6.3
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 +6 -0
- package/ai/dist/index.esm.js +1 -1
- package/ai/dist/index.esm.js.map +1 -1
- package/ai/dist/index.js +1 -1
- package/ai/dist/index.js.map +1 -1
- package/app/dist/index.esm.js +1 -1
- package/app/dist/index.esm.js.map +1 -1
- package/app/dist/index.js +1 -1
- package/app/dist/index.js.map +1 -1
- package/app/dist/index.node.esm.js +1 -1
- package/app/dist/index.node.esm.js.map +1 -1
- package/app/dist/index.node.js +1 -1
- package/app/dist/index.node.js.map +1 -1
- package/auth/dist/index.esm.js +1 -1
- package/auth/dist/index.esm.js.map +1 -1
- package/auth/dist/index.js +1 -1
- package/auth/dist/index.js.map +1 -1
- package/core.d.ts +4331 -0
- package/core.node.d.ts +294 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.node.cjs.js +1 -1
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.esm.js +1 -1
- package/dist/index.node.esm.js.map +1 -1
- package/index.d.ts +5 -4268
- package/index.node.d.ts +13 -0
- package/miniprogram_dist/ai/index.d.ts +42 -0
- package/miniprogram_dist/ai/index.js +2 -0
- package/miniprogram_dist/apis/index.d.ts +5 -0
- package/miniprogram_dist/{apis.js → apis/index.js} +1 -1
- package/miniprogram_dist/app/index.d.ts +67 -0
- package/miniprogram_dist/app/index.js +2 -0
- package/miniprogram_dist/auth/index.d.ts +284 -0
- package/miniprogram_dist/auth/index.js +2 -0
- package/miniprogram_dist/cloudrun/index.d.ts +4 -0
- package/miniprogram_dist/cloudrun/index.js +1 -0
- package/miniprogram_dist/container/index.d.ts +13 -0
- package/miniprogram_dist/container/index.js +1 -0
- package/miniprogram_dist/database/index.d.ts +3 -0
- package/miniprogram_dist/functions/index.d.ts +2 -0
- package/miniprogram_dist/functions/index.js +1 -0
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/model/index.d.ts +5 -0
- package/miniprogram_dist/model/index.js +1 -0
- package/miniprogram_dist/mysql/index.d.ts +3 -0
- package/miniprogram_dist/mysql/index.js +1 -0
- package/miniprogram_dist/oauth/index.d.ts +22 -0
- package/miniprogram_dist/oauth/index.js +2 -0
- package/miniprogram_dist/realtime/index.d.ts +2 -0
- package/miniprogram_dist/realtime/index.js +1 -0
- package/miniprogram_dist/storage/index.d.ts +13 -0
- package/miniprogram_dist/{storage.js → storage/index.js} +1 -1
- package/oauth/dist/index.esm.js +1 -1
- package/oauth/dist/index.esm.js.map +1 -1
- package/oauth/dist/index.js +1 -1
- package/oauth/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/types/package.json +1 -1
- package/utilities/package.json +2 -2
- package/dist/index.d.ts +0 -9
- package/miniprogram_dist/ai.js +0 -2
- package/miniprogram_dist/app.js +0 -2
- package/miniprogram_dist/auth.js +0 -2
- package/miniprogram_dist/cloudrun.js +0 -1
- package/miniprogram_dist/container.js +0 -1
- package/miniprogram_dist/functions.js +0 -1
- package/miniprogram_dist/model.js +0 -1
- package/miniprogram_dist/mysql.js +0 -1
- package/miniprogram_dist/oauth.js +0 -2
- package/miniprogram_dist/realtime.js +0 -1
- /package/miniprogram_dist/{database.js → database/index.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## [3.6.3] 2026-07-17
|
|
4
|
+
- [Changed] `timeout` 默认值区分运行环境:Node.js 环境(云函数/云托管/自建服务器)默认不设置超时(不限制),以适配服务端长耗时请求;Web 等非 Node.js 环境仍默认 15000ms。显式传入 `timeout` 时以传入值为准
|
|
5
|
+
- [Changed] `NodeRequest` 未设置 `timeout` 时不再施加超时中断(`download` 及 `createAbortController` 均按需启用超时),仅在显式传入 `timeout` 时启用
|
|
6
|
+
- [Changed] Auth `updateUser` 不再支持修改密码:传入 `password` / `new_password` 参数将抛出错误,请改用 `resetPasswordForOld`(旧密码修改)、`resetPasswordForEmail`(验证码重置)或 `reauthenticate`(重新认证后改密)
|
|
7
|
+
- [Changed] `UpdateUserReq` 类型从基础请求中剔除 `password` / `new_password` 字段(标记为 `never`)
|
|
8
|
+
|
|
3
9
|
## [3.6.2] 2026-06-29
|
|
4
10
|
- [Fixed] `getSecretInfo()` 中顶层 secretId/secretKey 场景下 `sessionToken` 错误地从环境变量 `TENCENTCLOUD_SESSIONTOKEN` 取值,修正为从 config 顶层 `sessionToken` 字段取值
|
|
5
11
|
- [Fixed] `getSecretInfo()` 中 `config.auth` 场景下 `sessionToken` 错误地从环境变量取值,修正为从 `config.auth.sessionToken` 取值
|
package/ai/dist/index.esm.js
CHANGED
|
@@ -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:()=>ge,rf:()=>C,pe:()=>we,jE:()=>xe,jM:()=>ke,Cq:()=>_e,el:()=>Ue,P6:()=>u});var u={};i.r(u),i.d(u,{ReadableStream:()=>g,TextDecoderStream:()=>_,TransformStream:()=>w,createAsyncIterable:()=>j,createEventSourceParserTransformStream:()=>S,createPromise:()=>U,functionToolToModelTool:()=>T,intoStandardStream:()=>x,intoTextStream:()=>k,isToolCallAssistantMessage:()=>q,readableStream2JsonObject:()=>P,toPolyfillReadable:()=>O});var s={};i.r(s),i.d(s,{ArkSimpleModel:()=>rt,DSSimpleModel:()=>st,DefaultImageModel:()=>Ct,DefaultSimpleModel:()=>At,HunYuanBetaSimpleModel:()=>K,HunYuanExpSimpleModel:()=>Ot,HunYuanOpenSimpleModel:()=>kt,HunYuanSimpleModel:()=>Q,MODELS:()=>Kt,MoonshotSimpleModel:()=>yt,ReactModel:()=>Nt,YiSimpleModel:()=>ht,ZhiPuSimpleModel:()=>N,toolMap:()=>Wt});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)}})},O=y?function(t){return t}:(0,p.createReadableStreamWrapper)(g),_=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 _).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(O(t).pipeThrough(new _))}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 T(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)},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(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 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: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=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=O(t);this._eventSourceStream=e.pipeThrough(new _).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}(),G=function(){return G=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},G.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())})},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 L(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return G(G({},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 N=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 D(this,function(o){switch(o.label){case 0:return n=L(t),[4,this.req({url:this.url,data:G(G({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,G(G({},r),{rawResponse:r})]}})})},t.prototype.doStream=function(t,e){return B(this,void 0,Promise,function(){var n,r,o,i;return D(this,function(a){switch(a.label){case 0:return n=L(t),r=null,[4,this.req({url:this.url,data:G(G({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=a.sent(),i=O(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?G(G({},t),{finish_reason:"tool_calls",delta:e}):t}),o=G(G({},t),{choices:n});e.enqueue(G(G({},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 W(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map(function(t){return W(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?W(o):o,t},{})}var H=function(){return H=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},H.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:H(H({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,H(H({},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:H(H({},F(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=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?H(H({},t),{finish_reason:"tool_calls",delta:e}):t}),o=H(H({},t),{choices:r});e.enqueue(H(H({},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=W(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=O(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=W(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=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=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=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=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=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}(),gt=function(){return gt=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},gt.apply(this,arguments)},wt=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())})},St=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 wt(this,void 0,Promise,function(){var e;return St(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:gt(gt({},F(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,gt(gt({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return wt(this,void 0,Promise,function(){var e,n,r;return St(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:gt(gt({},F(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=O(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?gt(gt({},t),{finish_reason:"tool_calls",delta:n}):t}),o=gt(gt({},t),{choices:r});n.enqueue(gt(gt({},o),{rawResponse:t}))}})))]}})})},t}(),_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)},jt=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])}}},kt=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 jt(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:_t(_t({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,_t(_t({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return jt(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:_t(_t({},F(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=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(_t({},t),{finish_reason:"tool_calls",delta:e}):t}),o=_t(_t({},t),{choices:r});e.enqueue(_t(_t({},o),{rawResponse:t}))}})))]}})})},t}(),Pt=function(){return Pt=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},Pt.apply(this,arguments)},Ut=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())})},qt=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 Ut(this,void 0,Promise,function(){var n;return qt(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Pt(Pt({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Pt(Pt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Ut(this,void 0,Promise,function(){var n,r,o;return qt(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Pt(Pt({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=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?Pt(Pt({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Pt(Pt({},t),{choices:r});e.enqueue(Pt(Pt({},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)},Rt=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])}}},At=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 Rt(this,void 0,Promise,function(){var e;return Et(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 Rt(this,void 0,Promise,function(){var e,n,r;return Et(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=O(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?It(It({},t),{finish_reason:"tool_calls",delta:n}):t}),o=It(It({},t),{choices:r});n.enqueue(It(It({},o),{rawResponse:t}))}})))]}})})},t}(),Ct=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}(),Mt=function(){return Mt=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},Mt.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())})},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])}}},Dt=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 Lt(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},Mt(Mt({},u),{tools:null===(e=u.tools)||void 0===e?void 0:e.map(function(t){return"fn"in t?T(t):t}),top_p:null!=i?i:u.top_p,tool_choice:null!=a?a:u.tool_choice})]}var Nt=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return Gt(this,void 0,Promise,function(){var o,i,a,u,s,l,c,f,p,h,d,v,b,m,y,g,w,S,O,_,j,x=this;return Bt(this,function(k){switch(k.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Lt(t),u=a[0],s=u.onStepFinish,l=u.maxSteps,c=void 0===l?10:l,f=a[1],[4,(p=function(){return x.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<c&&null!=(v=Jt(h))))return[3,9];b=Yt(h.usage),zt(i,b),k.label=3;case 3:return k.trys.push([3,7,,8]),[4,Ht(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(),Ft(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?Dt(Dt([],f.messages,!0),[S],!1):f.messages,j=Yt(h.usage),zt(i,j),[4,null==s?void 0:s({finishReason:w.finish_reason,messages:_.slice(),text:O,toolCall:Jt(h),toolResult:null,stepUsage:j,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 Gt(this,void 0,Promise,function(){var r,o,i,a,u,s,l,c,f,p,h,d,v,b,m,y,g,S,O,_,x,k,P,q,T,I,R,E,A,C,M,G,B,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=Lt(t),i=o[0],a=i.onStepFinish,u=i.maxSteps,s=void 0===u?10:u,l=o[1],[4,(c=function(){return J.model.doStream(l,e)})()];case 1:f=F.sent(),p=1,h=null,d=function(){var t=f.tee(),e=t[0],n=t[1];return f=j(e),function(t){var e,n,r,o,i,a,u,s,l,c;return Gt(this,void 0,Promise,function(){var f,p,h,d,v,b,m,y,g,w,S,O,_;return Bt(this,function(x){switch(x.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},p=j(t),d={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},x.label=1;case 1:x.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),x.label=2;case 2:return[4,b.next()];case 3:if(m=x.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===(l=null==y?void 0:y.usage)||void 0===l?void 0:l.prompt_tokens)&&(f.prompt_tokens=y.usage.prompt_tokens),(null===(c=null==y?void 0:y.usage)||void 0===c?void 0:c.total_tokens)&&(f.total_tokens=y.usage.total_tokens)}finally{v=!0}x.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return _=x.sent(),n={error:_},[3,12];case 7:return x.trys.push([7,,10,11]),v||e||!(r=b.return)?[3,9]:[4,r.call(b)];case 8:x.sent(),x.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,zt(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,Ht(y)];case 6:return g=F.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:b.content,toolCall:y,toolResult:g,stepUsage:m,totalUsage:Object.assign({},r)})];case 7:return F.sent(),Ft(l.messages,b,g),[4,c()];case 8:return f=F.sent(),[3,10];case 9:return S=F.sent(),O=f.tee(),_=O[0],x=O[1],[2,{messages:Promise.resolve(l.messages),dataStream:j(_),textStream:j(x.pipeThrough(new w({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,P=h.usage,zt(r,P),q=Dt(Dt([],l.messages,!0),[k],!1),a({messages:q.slice(),finishReason:"tool_call",stepUsage:P,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(Dt(Dt([],l.messages,!0),[k],!1)),dataStream:j(I),textStream:j(R.pipeThrough(new w({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=U(),A=U(),C={role:"assistant",content:""},M="",G={completion_tokens:0,prompt_tokens:0,total_tokens:0},B=f.pipeThrough(new w({transform:function(t,e){var n,r,o,i,a,u,s,l,c=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 c&&(C.content+=c);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===(l=null==t?void 0:t.usage)||void 0===l?void 0:l.total_tokens)&&(G.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){E.res(Dt(Dt([],l.messages,!0),[C],!1)),zt(r,G),A.res(Object.assign({},r)),null==a||a({messages:Dt(Dt([],l.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:j(L),textStream:j(N.pipeThrough(new w({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 Jt(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&&q(o)?o.tool_calls[0]:null}function Ft(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var Wt=new Map;function Ht(t){return Wt.get(t.function.name)(JSON.parse(t.function.arguments))}function Yt(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 zt(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var Kt={hunyuan:Q,"hunyuan-beta":K,ark:rt,dashscope:st,"01-ai":ht,moonshot:yt,zhipu:N,"hunyuan-exp":Ot,"hunyuan-open":kt,deepseek:Tt};var Xt="INVALID_OPERATION",Vt="OPERATION_FAIL";const Zt=(t=>{var e={};return i.d(e,t),e})({AbstractSDKRequest:()=>r.AbstractSDKRequest,AbstractStorage:()=>r.AbstractStorage});function Qt(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var $t,te,ee=($t=function(t,e){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(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}$t(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),ne=function(){return ne=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},ne.apply(this,arguments)},re=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())})},oe=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}ee(e,t),e.prototype.get=function(t){return this.request(ne(ne({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(ne(ne({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(ne(ne({},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(ne(ne({},t),{data:s,method:u}),this.restrictedMethods.includes("upload"))):this.request(ne(ne({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return re(this,void 0,Promise,function(){var e,n,r,o;return oe(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(ne(ne({},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 re(this,void 0,Promise,function(){var n,r,o,i,a,u,s,l,c,f,p,h,d,v=this;return oe(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,l=t.timeout,c=t.shouldThrowOnError,f=void 0===c||c,p=null!=l?l: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,ne(ne({},t),{signal:n.signal})).then(function(t){return re(v,void 0,void 0,function(){var e,n,r;return oe(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,l=t.responseType,c=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),l&&(d.responseType=l);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"===l?d.response:JSON.parse(d.responseText)}catch(e){t.data="blob"===l?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),c&&(d.withCredentials=!0),d.send(b)})}}(Zt.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(te||(te={}));var ie=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)}}(),ae=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())})},ue=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])}}},se=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return ie(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}(Zt.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:(Qt("INVALID_PARAMS","localStorage is not supported on current platform"),new se(e.root));case"none":return new se(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:Vt,msg:"[".concat("@cloudbase/js-sdk","][").concat(Vt,"]setStore failed"),info:t}))}}else Qt(Xt,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return ae(this,void 0,void 0,function(){var r;return ue(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:""}Qt(Xt,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return ae(this,void 0,void 0,function(){var r;return ue(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):Qt(Xt,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return ae(this,void 0,void 0,function(){return ue(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)}}(),ce=function(t,e){this.data=e||null,this.name=t},fe=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}(ce),pe=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 fe)return console.error(t.error),this;var n="string"==typeof t?new ce(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 pe;var he=new pe;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const de=(t=>{var e={};return i.d(e,t),e})({default:()=>o.default});de.default;var ve=function(){return ve=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},ve.apply(this,arguments)},be=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())})},me=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])}}},ye=Kt,ge=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 be(o,void 0,void 0,function(){var t,o,u,s,l,c,f;return me(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:ve(ve((l={},l[null===(c=this.i18n)||void 0===c?void 0:c.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,l),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 be(o,void 0,void 0,function(){var t,r,o,l,c,f,p,h,d;return me(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:ve(ve((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 l=v.sent(),c=l.data,f=l.header,[2,this.handleResponseData(c,f)]}var b})})},this._getBaseUrl=r,this.bot=new C(this.botRequest,this.aiBotBaseUrl),this.i18n=n,he.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 be(this,void 0,void 0,function(){var o,i,a,u,s=this;return me(this,function(l){switch(l.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),i=function(t){if("object"==typeof t&&t&&"code"in t&&"NORMAL"!==t.code)throw new Error("".concat(s.i18n.t("AI+ 请求出错,错误码"),":").concat(t.code,",").concat(s.i18n.t("错误信息"),":").concat(t.message,"\n").concat(o,"\n").concat(JSON.stringify(t,null,2)))},"object"==typeof t&&t&&"function"!=typeof t.getReader?"then"in t?[4,t]:[3,2]:[3,4];case 1:return a=l.sent(),[3,3];case 2:a=t,l.label=3;case 3:return i(u=a),[2,t];case 4:if("function"!=typeof(null==t?void 0:t.getReader)){if("object"==typeof(u=t)&&u&&"code"in u&&"NORMAL"!==u.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(u.code,",").concat(this.i18n.t("错误信息"),":").concat(u.message,"\n").concat(o,"\n").concat(JSON.stringify(u,null,2)));return[2,t]}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,P(t)]:[3,6];case 5:u=l.sent(),i(u),l.label=6;case 6:return[2,t]}})})},t.prototype.createModel=function(t,e){var n,r=ye[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 At(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new Nt(n)},t.prototype.registerModel=function(t,e){null==ye[t]?ye[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new Ct(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){Wt.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),Wt.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}(),we=function(){},Se=function(){return Se=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},Se.apply(this,arguments)},Oe=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},_e=Oe(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=Oe(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(Se({headers:Se({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 xe(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 ge(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 ke=xe,Pe={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)?xe({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):xe({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function Ue(t){try{t.registerComponent(Pe)}catch(t){console.warn(t)}}try{window.registerAi=Ue}catch(t){}var qe=a.AI,Te=a.rf,Ie=a.pe,Re=a.jE,Ee=a.jM,Ae=a.Cq,Ce=a.el,Me=a.P6;export{qe as AI,Te as Bot,Ie as SimpleChatModel,Re as createAI,Ee as createAi,Ae as models,Ce as registerAi,Me 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:()=>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.length>1)throw new Bt("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,images 最多只能有 1 个元素","images")}return o=this.defaultGenerateImageSubUrl,"object"==typeof t&&t&&"model"in t&&"string"==typeof t.model&&(i=this.getGenerateImageSubUrl(this.provider,t.model))&&(o=i),[4,this.req({url:this.getGenerateUrl(o),data:t,stream:!1})];case 1:return[2,a.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}(),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)},Nt=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])}}},Jt=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 Ft(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},Dt(Dt({},u),{tools:null===(e=u.tools)||void 0===e?void 0:e.map(function(t){return"fn"in t?I(t):t}),top_p:null!=i?i:u.top_p,tool_choice:null!=a?a:u.tool_choice})]}var Ht=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return Nt(this,void 0,Promise,function(){var o,i,a,u,s,l,c,f,p,h,d,v,b,m,y,g,w,S,_,O,j,x=this;return Lt(this,function(k){switch(k.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Ft(t),u=a[0],s=u.onStepFinish,l=u.maxSteps,c=void 0===l?10:l,f=a[1],[4,(p=function(){return x.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<c&&null!=(v=Wt(h))))return[3,9];b=Xt(h.usage),Vt(i,b),k.label=3;case 3:return k.trys.push([3,7,,8]),[4,Kt(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(),Yt(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,_=null!==(r=null==S?void 0:S.content)&&void 0!==r?r:"",O=S?Jt(Jt([],f.messages,!0),[S],!1):f.messages,j=Xt(h.usage),Vt(i,j),[4,null==s?void 0:s({finishReason:w.finish_reason,messages:O.slice(),text:_,toolCall:Wt(h),toolResult:null,stepUsage:j,totalUsage:Object.assign({},i)})];case 10:return k.sent(),[2,{text:_,messages:O,usage:i,rawResponses:o}]}})})},t.prototype.streamText=function(t,e){var n;return Nt(this,void 0,Promise,function(){var r,o,i,a,u,s,l,c,f,p,h,d,v,b,m,y,g,S,_,O,x,k,P,q,I,T,R,E,A,C,M,B,G,D,N,L,J=this;return Lt(this,function(F){switch(F.label){case 0:return r={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=Ft(t),i=o[0],a=i.onStepFinish,u=i.maxSteps,s=void 0===u?10:u,l=o[1],[4,(c=function(){return J.model.doStream(l,e)})()];case 1:f=F.sent(),p=1,h=null,d=function(){var t=f.tee(),e=t[0],n=t[1];return f=j(e),function(t){var e,n,r,o,i,a,u,s,l,c;return Nt(this,void 0,Promise,function(){var f,p,h,d,v,b,m,y,g,w,S,_,O;return Lt(this,function(x){switch(x.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},p=j(t),d={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},x.label=1;case 1:x.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),x.label=2;case 2:return[4,b.next()];case 3:if(m=x.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==(_=null===(i=null==S?void 0:S.tool_calls)||void 0===i?void 0:i[0])?void 0:_.id)&&(h.id=_.id),(null==_?void 0:_.type)&&(h.type=_.type),(null===(a=null==_?void 0:_.function)||void 0===a?void 0:a.name)&&(h.function.name=_.function.name),(null===(u=null==_?void 0:_.function)||void 0===u?void 0:u.arguments)&&(h.function.arguments+=_.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===(l=null==y?void 0:y.usage)||void 0===l?void 0:l.prompt_tokens)&&(f.prompt_tokens=y.usage.prompt_tokens),(null===(c=null==y?void 0:y.usage)||void 0===c?void 0:c.total_tokens)&&(f.total_tokens=y.usage.total_tokens)}finally{v=!0}x.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return O=x.sent(),n={error:O},[3,12];case 7:return x.trys.push([7,,10,11]),v||e||!(r=b.return)?[3,9]:[4,r.call(b)];case 8:x.sent(),x.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,Vt(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,Kt(y)];case 6:return g=F.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:b.content,toolCall:y,toolResult:g,stepUsage:m,totalUsage:Object.assign({},r)})];case 7:return F.sent(),Yt(l.messages,b,g),[4,c()];case 8:return f=F.sent(),[3,10];case 9:return S=F.sent(),_=f.tee(),O=_[0],x=_[1],[2,{messages:Promise.resolve(l.messages),dataStream:j(O),textStream:j(x.pipeThrough(new w({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,P=h.usage,Vt(r,P),q=Jt(Jt([],l.messages,!0),[k],!1),a({messages:q.slice(),finishReason:"tool_call",stepUsage:P,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(Jt(Jt([],l.messages,!0),[k],!1)),dataStream:j(T),textStream:j(R.pipeThrough(new w({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=U(),A=U(),C={role:"assistant",content:""},M="",B={completion_tokens:0,prompt_tokens:0,total_tokens:0},G=f.pipeThrough(new w({transform:function(t,e){var n,r,o,i,a,u,s,l,c=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 c&&(C.content+=c);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===(l=null==t?void 0:t.usage)||void 0===l?void 0:l.total_tokens)&&(B.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){E.res(Jt(Jt([],l.messages,!0),[C],!1)),Vt(r,B),A.res(Object.assign({},r)),null==a||a({messages:Jt(Jt([],l.messages,!0),[C],!1),finishReason:M,text:C.content,stepUsage:B,totalUsage:Object.assign({},r)})}})),D=G.tee(),N=D[0],L=D[1],[2,{messages:E.promise,dataStream:j(N),textStream:j(L.pipeThrough(new w({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 Wt(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&&q(o)?o.tool_calls[0]:null}function Yt(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var zt=new Map;function Kt(t){return zt.get(t.function.name)(JSON.parse(t.function.arguments))}function Xt(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 Vt(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var Zt={hunyuan:Q,"hunyuan-beta":K,ark:rt,dashscope:st,"01-ai":ht,moonshot:gt,zhipu:L,"hunyuan-exp":Ot,"hunyuan-open":Pt,deepseek:Tt};var Qt="INVALID_OPERATION",$t="OPERATION_FAIL";const te=(t=>{var e={};return i.d(e,t),e})({AbstractSDKRequest:()=>r.AbstractSDKRequest,AbstractStorage:()=>r.AbstractStorage});function ee(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var ne,re=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)}}(),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)},ie=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())})},ae=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}re(e,t),e.prototype.get=function(t){return this.request(oe(oe({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(oe(oe({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(oe(oe({},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(oe(oe({},t),{data:s,method:u}),this.restrictedMethods.includes("upload"))):this.request(oe(oe({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return ie(this,void 0,Promise,function(){var e,n,r,o;return ae(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(oe(oe({},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 ie(this,void 0,Promise,function(){var n,r,o,i,a,u,s,l,c,f,p,h,d,v=this;return ae(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,l=t.timeout,c=t.shouldThrowOnError,f=void 0===c||c,p=null!=l?l: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,oe(oe({},t),{signal:n.signal})).then(function(t){return ie(v,void 0,void 0,function(){var e,n,r;return ae(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,l=t.responseType,c=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),l&&(d.responseType=l);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"===l?d.response:JSON.parse(d.responseText)}catch(e){t.data="blob"===l?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),c&&(d.withCredentials=!0),d.send(b)})}}(te.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(ne||(ne={}));var ue=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)}}(),se=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())})},le=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 ue(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}(te.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:(ee("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:$t,msg:"[".concat("@cloudbase/js-sdk","][").concat($t,"]setStore failed"),info:t}))}}else ee(Qt,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return se(this,void 0,void 0,function(){var r;return le(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:""}ee(Qt,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return se(this,void 0,void 0,function(){var r;return le(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):ee(Qt,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return se(this,void 0,void 0,function(){return le(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})}}();var fe=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)}}(),pe=function(t,e){this.data=e||null,this.name=t},he=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return fe(e,t),e}(pe),de=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 he)return console.error(t.error),this;var n="string"==typeof t?new pe(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 de;var ve=new de;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const be=(t=>{var e={};return i.d(e,t),e})({default:()=>o.default});be.default;var me=function(){return me=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},me.apply(this,arguments)},ye=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())})},ge=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])}}},we=Zt,Se=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 ye(o,void 0,void 0,function(){var t,o,u,s,l,c,f;return ge(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:me(me((l={},l[null===(c=this.i18n)||void 0===c?void 0:c.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,l),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 ye(o,void 0,void 0,function(){var t,r,o,l,c,f,p,h,d;return ge(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:me(me((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 l=v.sent(),c=l.data,f=l.header,[2,this.handleResponseData(c,f)]}var b})})},this._getBaseUrl=r,this.bot=new C(this.botRequest,this.aiBotBaseUrl),this.i18n=n,ve.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 ye(this,void 0,void 0,function(){var o,i,a,u,s=this;return ge(this,function(l){switch(l.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),i=function(t){if("object"==typeof t&&t&&"code"in t&&"NORMAL"!==t.code)throw new Error("".concat(s.i18n.t("AI+ 请求出错,错误码"),":").concat(t.code,",").concat(s.i18n.t("错误信息"),":").concat(t.message,"\n").concat(o,"\n").concat(JSON.stringify(t,null,2)))},"object"==typeof t&&t&&"function"!=typeof t.getReader?"then"in t?[4,t]:[3,2]:[3,4];case 1:return a=l.sent(),[3,3];case 2:a=t,l.label=3;case 3:return i(u=a),[2,t];case 4:if("function"!=typeof(null==t?void 0:t.getReader)){if("object"==typeof(u=t)&&u&&"code"in u&&"NORMAL"!==u.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(u.code,",").concat(this.i18n.t("错误信息"),":").concat(u.message,"\n").concat(o,"\n").concat(JSON.stringify(u,null,2)));return[2,t]}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,P(t)]:[3,6];case 5:u=l.sent(),i(u),l.label=6;case 6:return[2,t]}})})},t.prototype.createModel=function(t,e){var n,r=we[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 Ct(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new Ht(n)},t.prototype.registerModel=function(t,e){null==we[t]?we[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new Gt(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){zt.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),zt.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}(),_e=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)},je=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=je(s,["MODELS"]),ke=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=je(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 Pe(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 Se(function(){if(null==a){if(null==i)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return ke({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 Ue=Pe,qe={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)?Pe({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):Pe({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function Ie(t){try{t.registerComponent(qe)}catch(t){console.warn(t)}}try{window.registerAi=Ie}catch(t){}var Te=a.AI,Re=a.rf,Ee=a.rT,Ae=a.pe,Ce=a.jE,Me=a.jM,Be=a.Cq,Ge=a.el,De=a.P6;export{Te as AI,Re as Bot,Ee as InvalidParamsError,Ae as SimpleChatModel,Ce as createAI,Me as createAi,Be as models,Ge as registerAi,De as utils};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|