aipexbase-js 1.1.6 → 1.1.7

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/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";const t={getItem(t){try{return localStorage.getItem(t)}catch(t){return console.warn("No localStorage available"),null}},setItem(t,e){try{localStorage.setItem(t,e)}catch(t){console.warn("Cannot write to localStorage")}},removeItem(t){try{localStorage.removeItem(t)}catch(t){console.warn("Cannot remove from localStorage")}}},e=async(t,e)=>(await fetch(t,e)).json();class s{constructor({baseUrl:s,apiKey:r,storage:i,request:a}){this.baseUrl=s,this.apiKey=r,this.storage=i||t,this.requestImpl=a||e}getApiKey(){return this.apiKey}setToken(t){t?this.storage.setItem("baas_token",t):this.storage.removeItem("baas_token")}getToken(){return this.storage.getItem("baas_token")}async request(t,e={}){const s=`${this.baseUrl}${t}`,r={"Content-Type":"application/json",CODE_FLYING:`${this.apiKey}`,...this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{},...e.headers||{}},i=await this.requestImpl(s,{...e,headers:r});return console.log("url: ",s,"\n header:",r,"\n response:",i),i}}function r(t){return{async login({user_name:e,phone:s,email:r,password:i}={}){const a=e||s||r;if(!a)throw new Error("必须提供 user_name、phone 或 email 之一");if(!i)throw new Error("必须提供 password");const n=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:a,password:i})});return n.success&&t.setToken(n.data),n},async loginByEmailAndCode({email:e,code:s}={}){const r=await t.request("/login/mail",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByPhoneAndCode({phone:e,code:s}={}){const r=await t.request("/login/phone",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByWeChat({code:e}={}){const s=await t.request("/login/wechat",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},async loginByWeApp({code:e}={}){const s=await t.request("/login/weapp",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},getUser:async()=>t.request("/getUserInfo",{method:"GET"}),register:async e=>await t.request("/login/register",{method:"POST",body:JSON.stringify(e)}),logout:async()=>(t.setToken(null),t.request("/logout",{method:"GET"})),loginOauth2Uri:async({provider:e}={})=>await t.request("/oauth2/authorize/"+e,{method:"GET"})}}class i{constructor(t,e){this.client=t,this.table=e,this._body=null,this._method=""}list(){return new a(this.client,this.table,"list")}page(){return new a(this.client,this.table,"page")}get(){return new a(this.client,this.table,"get")}insert(){return new n(this.client,this.table,"add")}update(){return new n(this.client,this.table,"update")}delete(){return new a(this.client,this.table,"delete")}}class a{constructor(t,e,s){this.client=t,this.table=e,this.method=s,this.filters={}}_addFilter(t,e,s){return this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t][e]=s,this}eq(t,e){return this._addFilter(t,"eq",e)}neq(t,e){return this._addFilter(t,"neq",e)}gt(t,e){return this._addFilter(t,"gt",e)}gte(t,e){return this._addFilter(t,"gte",e)}lt(t,e){return this._addFilter(t,"lt",e)}lte(t,e){return this._addFilter(t,"lte",e)}like(t,e){return this._addFilter(t,"like",e)}in(t,e){return this._addFilter(t,"in",e)}between(t,e){return this._addFilter(t,"between",e)}or(t){this.filters.or||(this.filters.or=[]);const e=new a(this.client,this.table,"or");return t(e),this.filters.or.push(e.build()),this}limit(t){return this}page(t,e){return this.filters.current=t,this.filters.pageSize=e,this}order(t,e="asc"){this.filters.order_by||(this.filters.order_by=[]);let s="asc";return"string"==typeof e?s=e.toLowerCase():"object"==typeof e&&null!==e&&("ascending"in e?s=e.ascending?"asc":"desc":"direction"in e&&(s=e.direction.toLowerCase())),this.filters.order_by.push({field:t,direction:s}),this}build(){return this.filters}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:this.filters?JSON.stringify(this.filters):void 0})}then(t,e){this._execute().then(t,e)}}class n extends a{constructor(t,e,s){super(t,e,s),this.data={}}values(t){return this.data={...t},this}set(t){return this.data={...t},this}build(){return{...this.filters,...this.data}}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:JSON.stringify(this.build())})}then(t,e){this._execute().then(t,e)}}function o(t){return{from:e=>new i(t,e)}}class h{constructor(t,e){this.client=t,this.apiName=e,this._params={},this._headers={},this._method="POST"}param(t,e){return this._params[t]=e,this}params(t){return Object.assign(this._params,t),this}header(t,e){return this._headers[t]=e,this}headers(t){return Object.assign(this._headers,t),this}async _execute(){const t=JSON.stringify(this._params),e=`/api/${this.apiName}`;return await this.client.request(e,{method:this._method,headers:this._headers,body:t})}then(t,e){this._execute().then(t,e)}}function c(t){return{call:e=>new h(t,e)}}class u{static API_MAP={search:"/api/bijia_spu_search",compare:"/api/bijia_spu_goods_search"};constructor(t,e){this.client=t,this._params={},this.type=e}keyword(t){return this._params.query=t,this}setParams(t={}){return Object.assign(this._params,t),this}type(t){if(!u.API_MAP[t])throw new Error(`Unsupported comparison type: ${t}`);return this.type=t,this}async _execute(){const t=u.API_MAP[this.type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){this._execute().then(t,e)}}function l(t){return{searchProduct:()=>new u(t,"search"),findLowestPrice:()=>new u(t,"compare")}}class d{constructor(t){this.client=t,this._params={},this._taskId=null,this._pollingInterval=2e3,this._maxRetries=30}url(t){return this._params.url=t,this._params.format="pdf-to-image",this}format(t="pdf-to-image"){return this._params.format=t,this}pollingInterval(t){return this._pollingInterval=t,this}maxRetries(t){return this._maxRetries=t,this}async createTask(){if(!this._params.url)throw new Error("PDF文件URL不能为空");const t=await this.client.request("/api/pdf2image",{method:"POST",body:JSON.stringify({url:this._params.url,format:this._params.format})});return this._taskId=t.data,t}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");return await this.client.request("/api/queryPDF2ImageTask",{method:"POST",body:JSON.stringify({taskId:e})})}async convert(){try{console.log("开始创建PDF转图片任务...");const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");console.log("开始轮询查询任务状态...");let s=0;for(;s<this._maxRetries;){const t=await this.queryTask(e);console.log(`第${s+1}次查询结果:`,t);const r=t.data?.state;if(1===r)return console.log("PDF转图片任务完成:",t.data),t;if(r<0)return console.log("PDF转图片任务失败,状态码:",r),t;s++,s<this._maxRetries&&(console.log(`等待${this._pollingInterval}ms后进行第${s+1}次查询...`),await new Promise(t=>setTimeout(t,this._pollingInterval)))}throw new Error(`PDF转图片任务超时,已重试${this._maxRetries}次`)}catch(t){throw console.error("PDF转图片失败:",t),t}}then(t,e){return this.convert().then(t,e)}catch(t){return this.convert().catch(t)}}function p(t){return{convertPdf:()=>new d(t),async quickConvert(e={}){const s=new d(t);return e.url&&s.url(e.url),e.format&&s.format(e.format),e.pollingInterval&&s.pollingInterval(e.pollingInterval),e.maxRetries&&s.maxRetries(e.maxRetries),await s.convert()}}}class m{constructor(t){this.client=t,this._params={}}company(t){return this._params.com=t,this}trackingNumber(t){return this._params.num=t,this}phone(t){return this._params.phone=t,this}_validateParams(){if(!this._params.com)throw new Error("快递公司代码不能为空");if(!this._params.num)throw new Error("快递单号不能为空");if(("shunfeng"===this._params.com||"shunfengkuaiyun"===this._params.com)&&!this._params.phone)throw new Error("顺丰快递必须提供手机号参数")}async track(){return this._validateParams(),await this.client.request("/api/expressInquiry",{method:"POST",body:JSON.stringify({com:this._params.com,num:this._params.num,resultv2:4,...this._params.phone?{phone:this._params.phone}:{}})})}then(t,e){return this.track().then(t,e)}catch(t){return this.track().catch(t)}}function y(t){return{trackPackage:()=>new m(t)}}class _{static LOCATION_MAP={location:"/api/geocoder",address:"/api/geoaddress"};constructor(t,e){this.client=t,this._params={},this.type=e}latitude(t){return this._params.latitude=t,this}longitude(t){return this._params.longitude=t,this}address(t){return this._params.address=t,this}_validateLocationParams(){if(!this._params.latitude||!this._params.longitude)throw new Error("经纬度参数不能为空")}_validateAddressParams(){if(!this._params.address)throw new Error("地址参数不能为空")}_data(){return"location"===this.type?(this._validateLocationParams(),{location:`${this._params.latitude},${this._params.longitude}`}):(this._validateAddressParams(),{address:this._params.address})}async _execute(){const t=_.LOCATION_MAP[this.type],e=this._data();let s=await this.client.request(t,{method:"POST",body:JSON.stringify(e)}),r=s;return"data"in s&&"result"in s.data&&(r.result=s.data.result,r.result.latitude=s.data.result.location.lat,r.result.longitude=s.data.result.location.lng,r.status=s.data.status),r}then(t,e){this._execute().then(t,e)}}class g{constructor(t){this.client=t}async _execute(){const t=await this.client.request("/api/amap_ip_location",{method:"POST",body:JSON.stringify({})}),e=t?.data?.rectangle;if(!e)throw new Error("返回数据中缺少 rectangle 字段");const[s,r]=e.split(";"),[i,a]=s.split(",").map(Number),[n,o]=r.split(",").map(Number);return{success:!0,latitude:(a+o)/2,longitude:(i+n)/2,speed:0,altitude:0,horizontalAccuracy:1e3}}then(t,e){this._execute().then(t,e)}}class w{constructor(t){this.client=t,this._params={}}from(t,e){return this._params.from={lat:t,lng:e},this}to(t,e){return this._params.to={lat:t,lng:e},this}decodePolyline(t){for(let e=2;e<t.length;e++)t[e]=t[e-2]+t[e]/1e6;return t}async _execute(){const{from:t,to:e}=this._params;if(!t||!e)throw new Error("必须提供起点和终点坐标");const s={from:`${t.lat},${t.lng}`,to:`${e.lat},${e.lng}`},r=await this.client.request("/api/driving",{method:"POST",body:JSON.stringify(s)}),{routes:i}=r.data.result;return{success:!0,data:{paths:i.map(t=>{const e=this.decodePolyline([...t.polyline]),s=t.steps.map(t=>{const{polyline_idx:[s,r]}=t,i=[];for(let t=s;t<=r;t+=2)i.push({latitude:e[t],longitude:e[t+1]});return{...t,polylines:i}});return{distance:t.distance,duration:t.duration,steps:s}})}}}then(t,e){this._execute().then(t,e)}}class f{constructor(t){this.client=t,this._params={}}lat(t){return this._params.lat=t,this}lng(t){return this._params.lng=t,this}radius(t){return this._params.radius=t,this}keyword(t){return this._params.keyword=t,this}async _execute(){const{lat:t,lng:e,radius:s=1e3,keyword:r}=this._params;if(!t||!e)throw new Error("必须提供经纬度参数");const i={boundary:`nearby(${t},${e},${s})`,...r&&{keyword:r}},a=await this.client.request("/api/mapsearch",{method:"POST",body:JSON.stringify(i)}),{data:n}=a.data;return{success:!0,data:n.map(t=>({...t,latitude:t.location.lat,longitude:t.location.lng}))}}then(t,e){this._execute().then(t,e)}}function P(t){return{locationToAddress:()=>new _(t,"location"),addressToLocation:()=>new _(t,"address"),currentLocation:()=>new g(t),driving:()=>new w(t),nearby:()=>new f(t)}}class S{static API_MAP={train:"/api/queryTickets",flight:"/api/queryFlight"};constructor(t,e){this.client=t,this.params={},this.mode=e}from(t){return this.params.from=t,this}to(t){return this.params.to=t,this}date(t){return this.params.date=t,this}async _execute(){const t=S.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function b(t){return{train:()=>new S(t,"train"),flight:()=>new S(t,"flight")}}class q{static API_MAP={feishu:"/api/feishuRobotText",wechat:"/api/wechatRobotText"};constructor(t,e){this.client=t,this.params={},this.mode=e}content(t){return this.params.content=t?.replace(/\r?\n/g," "),this}async _execute(){const t=q.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}class A{constructor(t){this.client=t,this.payload={}}title(t){return this.payload.title=t,this}content(t){return this.payload.content=t?.replace(/\r?\n/g," "),this}to(t){return this.payload.to=t,this}params(t={}){return this.payload.params=t,this}async _execute(){return await this.client.request("/common/mail/send",{method:"POST",body:JSON.stringify(this.payload)})}then(t,e){this._execute().then(t,e)}}function x(t){return{feishuRobot:()=>new q(t,"feishu"),wechatRobot:()=>new q(t,"wechat"),mail:()=>new A(t)}}class T{static API_MAP={text2pic:"/api/word2pic",text2tts:"/api/text/tts"};constructor(t,e){this.client=t,this.params={model:"gemini-3-pro-image-preview"},this.mode=e}text(t){return this.params.text=t,this}model(t){return this.params.model=t,this}async _execute(){const t=T.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}class O{constructor(t){this.client=t}async uploadFile(t,e="mp3",s="audio/mpeg"){const r=await this.client.request("/common/uploadByUrl",{method:"POST",body:JSON.stringify({fileUrl:t,formatter:e,contentType:s})});return console.log("uploadFile response:",r),r}}class k extends O{constructor(t){super(t),this.params={}}text(t){return this.params.text=t,this}speaker(t){return this.params.speaker=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");let e=this.params.speaker;e&&""!==e||(e="zh_female_cancan_mars_bigtts");let s={text:t,speaker:e};const r=this.client.request("/api/ttsTask",{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");let s={taskId:e};return await this.client.request("/api/queryTts",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=await this.createTask();console.log("====TTS任务创建成功:====",t);const e=t.data.task_id;if(!e)throw new Error("任务创建失败,未返回任务ID");let s=0;for(;2!==s;){const t=await this.queryTask(e);if(s=t.data?.task_status||0,2===s){const e=await this.uploadFile(t.data.audio_url);return t.data=e.data,t}if(3===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}class I{constructor(t){this.client=t,this.params={}}text(t){return this.params.text=t,this}prompt(t){return this.params.prompt=t,this}conversationId(t){return this.params.conversationId=t,this}async _execute(){const{text:t,prompt:e="",conversationId:s=""}=this.params,r={prompt:e,query:t,conversation_id:s,user:this.client.getApiKey(),files:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(r)})}then(t,e){this._execute().then(t,e)}}class v extends I{constructor(t){super(t)}url(t){return this.params.url=t,this}async _execute(){const{url:t,prompt:e,text:s,conversationId:r=""}=this.params,i=[{type:"image",transfer_method:"remote_url",url:t}],a={prompt:e,query:s,conversation_id:r,user:this.client.getApiKey(),files:t?i:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(a)})}then(t,e){this._execute().then(t,e)}}class N extends O{static CREATE_API_MAP={video:"/api/text2video",audio:"/api/text2music"};static QUERY_API_MAP={video:"/api/queryVideo",audio:"/api/queryMusic"};constructor(t,e){super(t),this.params={},this.mode=e,this._taskId=null}text(t){return this.params.text=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");const e=N.CREATE_API_MAP[this.mode];let s={};s="video"===this.mode?{text:t}:{prompt:this.cleanString(t)};const r=this.client.request(e,{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");const s=N.QUERY_API_MAP[this.mode];let r={};return r="video"===this.mode?{id:e}:{item_ids:e},await this.client.request(s,{method:"POST",body:JSON.stringify(r)})}async _execute(){const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");let s="";for(;"succeeded"!==s;){const t=await this.queryTask(e);if(s=t.data?.status||"","succeeded"===s){if("video"===this.mode){const e=await this.uploadFile(t.data.content.video_url,"mp4","video/mp4");t.data.content.video_url=e.data}else{const e=await this.uploadFile(t.data.audio_url,"mp3","audio/mpeg");t.data.audio_url=e.data}return t}if("failed"===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){this._execute().then(t,e)}cleanString(t){return t?(t=(t=(t=t.toString()).replace(/[\n\r\t]+/g,",")).replace(/\s{2,}/g,",")).trim():t}}function M(t){return{textToImage:()=>new T(t,"text2pic"),textToSpeech:()=>new k(t),imageToText:()=>new v(t),chat:()=>new I(t),textToVideo:()=>new N(t,"video"),textToAudio:()=>new N(t,"audio")}}class J{static API_MAP={web:"/api/webSearch",video:"/api/webSearch",image:"/api/webSearch"};constructor(t,e){this.client=t,this._params={type:e,top_k:20,site:[]},this._type=e}content(t){return this._params.content=t,this}type(t){if(!J.API_MAP[t])throw new Error(`Unsupported search type: ${t}`);return this._type=t,this._params.type=t,this}site(t){return this._params.site||(this._params.site=[]),null==t||this._params.site.push(t),this}async _execute(){const t=J.API_MAP[this._type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){return this._execute().then(t,e)}}function E(t){return{search:()=>new J(t,"web"),webSearch:()=>new J(t,"web"),videoSearch:()=>new J(t,"video"),imageSearch:()=>new J(t,"image")}}const $=new class{constructor(){this.plugins=new Map,this.pluginModules=new Map}register(t,e){if(this.plugins.has(t))console.warn(`Plugin ${t} is already registered`);else{if(!this.validatePlugin(e))throw console.log(`Invalid plugin module for ${t}:`,{type:typeof e,value:e,constructor:e?.constructor?.name,keys:"object"==typeof e?Object.keys(e):"N/A"}),new Error(`Invalid plugin module structure for ${t}`);this.plugins.set(t,{name:t,module:e,initialized:!1}),console.log(`Plugin ${t} registered successfully`)}}validatePlugin(t){return null!=t&&("function"==typeof t||"object"==typeof t&&!Array.isArray(t))}init(t,e){const s=this.plugins.get(t);if(!s)throw new Error(`Plugin ${t} not found`);let r;if("function"!=typeof s.module&&"object"!=typeof s.module)throw new Error(`Invalid plugin module type for ${t}`);return r=s.module,s.initialized=!0,"function"==typeof r.init&&r.init(),r}getRegisteredPlugins(){return Array.from(this.plugins.keys())}isRegistered(t){return this.plugins.has(t)}unregister(t){this.plugins.has(t)&&(this.plugins.delete(t),console.log(`Plugin ${t} unregistered`))}};class C{constructor(t){this.client=t,this._params={}}interval(t){return this._params.interval=t,this}vsCurrency(t){return this._params.vsCurrency=t,this}days(t){return this._params.days=t,this}async query(){return await this.client.request("/api/historytrend",{method:"POST",body:JSON.stringify({interval:this._params.interval,vs_currency:this._params.vsCurrency,days:this._params.days})})}then(t,e){return this.query().then(t,e)}catch(t){return this.query().catch(t)}}function F(t){return{historytrend:()=>new C(t)}}class R{static API_MAP={googleSearch:"/api/googleSearch"};constructor(t){this.client=t,this.params={}}content(t){return this.params.content=t,this}num(t){return this.params.num=t,this}type(t){return this.params.type=t,this}async _execute(){const t=R.API_MAP.googleSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function W(t){return{search:()=>new R(t)}}class D{static API_MAP={list:"/api/queryToutiaoIndex",content:"/api/queryToutiaoContent"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}page(t){return this.params.page=t,this}page_size(t){return this.params.pageSize=t,this}is_filter(t){return this.params.isFilter=t,this}uniquekey(t){return this.params.uniquekey=t,this}async _execute(){const t=D.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function z(t){return{queryToutiaoIndex:()=>new D(t,"list"),queryToutiaoContent:()=>new D(t,"content")}}class U{static API_MAP={nationalWeather:"/api/nationalWeather",internationalWeather:"/api/weather"};constructor(t,e){this.client=t,this.mode=e,this.params={}}city(t){return"nationalWeather"!==this.mode&&console.warn("city 参数仅适用于 nationalWeather 模式"),this.params.city=t,this}latitude(t){return"internationalWeather"!==this.mode&&console.warn("latitude 参数仅适用于 internationalWeather 模式"),this.params["location.latitude"]=t,this}longitude(t){return"internationalWeather"!==this.mode&&console.warn("longitude 参数仅适用于 internationalWeather 模式"),this.params["location.longitude"]=t,this}async _execute(){this._validateParams();const t=U.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}_validateParams(){if("nationalWeather"===this.mode){if(!this.params.city)throw new Error("nationalWeather 模式需要提供 city 参数")}else if(!("internationalWeather"!==this.mode||this.params["location.latitude"]&&this.params["location.longitude"]))throw new Error("internationalWeather 模式需要提供 latitude 和 longitude 参数")}then(t,e){return this._execute().then(t,e)}}function j(t){return{queryNationalWeather:()=>new U(t,"nationalWeather"),queryWeather:()=>new U(t,"internationalWeather")}}class L{static API_MAP={frate:"/api/frate",rmbquot:"/api/rmbquot"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}bank(t){return this.params.bank=t,this}async _execute(){const t=L.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function B(t){return{frate:()=>new L(t,"frate"),rmbquot:()=>new L(t,"rmbquot")}}class G{static API_MAP={queryCaipu:"/api/queryCaipu"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}async _execute(){const t=G.API_MAP.queryCaipu;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function K(t){return{queryIngredients:()=>new G(t),queryDishName:()=>new G(t),query:()=>new G(t)}}class H{static API_MAP={queryCarPrice:"/api/queryCarPrice"};constructor(t){this.client=t,this.params={}}search(t){return this.params.search=t,this}async _execute(){const t=H.API_MAP.queryCarPrice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function Y(t){return{query:()=>new H(t)}}class Q{static API_MAP={queryDiseaseByName:"/api/queryDiseaseByName"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}async _execute(){const t=Q.API_MAP.queryDiseaseByName;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function V(t){return{query:()=>new Q(t)}}class X{static API_MAP={queryCalorie:"/api/queryCalorie"};constructor(t){this.client=t,this.params={}}sex(t){return this.params.sex=t,this}height(t){return this.params.height=t,this}weight(t){return this.params.weight=t,this}age(t){return this.params.age=t,this}level(t){return this.params.level=t,this}async _execute(){const t=X.API_MAP.queryCalorie;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function Z(t){return{query:()=>new X(t)}}class tt{static API_MAP={nationalGoldprice:"/api/nationalGoldprice"};constructor(t){this.client=t,this.params={}}async _execute(){const t=tt.API_MAP.nationalGoldprice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function et(t){return{query:()=>new tt(t)}}class st{static API_MAP={youtubeSearch:"/api/youtubeSearch"};constructor(t){this.client=t,this.params={}}q(t){return this.params.q=t,this}type(t){return this.params.type=t,this}async _execute(){const t=st.API_MAP.youtubeSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function rt(t){return{search:()=>new st(t)}}class it{static API_MAP={queryTimezone:"/api/timezone"};constructor(t){this.client=t,this.params={}}location(t){return this.params.location=t,this}timestamp(t){return this.params.timestamp=t,this}async _execute(){const t=it.API_MAP.queryTimezone;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function at(t){return{search:()=>new it(t)}}class nt{static API_MAP={queryNationalScenic:"/api/queryNationalScenic"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}province(t){return this.params.province=t,this}city(t){return this.params.city=t,this}async _execute(){const t=nt.API_MAP.queryNationalScenic;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ot(t){return{query:()=>new nt(t)}}class ht{static API_MAP={queryFootballMatch:"/api/queryFootballMatch",footballRank:"/api/footballRank"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}async _execute(){const t=ht.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ct(t){return{match:()=>new ht(t,"queryFootballMatch"),rank:()=>new ht(t,"footballRank")}}class ut{static API_MAP={hsStock:"/api/hsStock",hkStock:"/api/hkStock",usaStock:"/api/usaStock",hkall:"/api/hkall",usaall:"/api/usaall",szall:"/api/szall",shall:"/api/shall"};constructor(t,e){this.client=t,this.mode=e,this.params={}}gid(t){return this.params.gid=t,this}type(t){return this.params.type=t,this}num(t){return this.params.num=t,this}stock(t){return this.params.stock=t,this}page(t){return this.params.page=t,this}async _execute(){const t=ut.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function lt(t){return{queryHs:()=>new ut(t,"hsStock"),queryHk:()=>new ut(t,"hkStock"),queryUsa:()=>new ut(t,"usaStock"),queryHkAll:()=>new ut(t,"hkall"),queryUsaAll:()=>new ut(t,"usaall"),querySzAll:()=>new ut(t,"szall"),queryShAll:()=>new ut(t,"shall")}}exports.createClient=function(t){const e=new s(t),i={setToken:t=>e.setToken(t),getToken:()=>e.getToken(),auth:r(e),db:o(e),api:c(e),comparison:l(e),document:p(e),logistics:y(e),location:P(e),travel:b(e),notification:x(e),ai:M(e),baidu:E(e),bitcoin:F(e),google:W(e),news:z(e),weather:j(e),money:B(e),caipu:K(e),car:Y(e),disease:V(e),calorie:Z(e),goldprice:et(e),youtube:rt(e),timezone:at(e),scenic:ot(e),football:ct(e),stock:lt(e)};return $.getRegisteredPlugins().forEach(t=>{try{const s=$.init(t,e);i[t]?(console.warn(`Plugin "${t}" conflicts with built-in module. Merging plugin methods into existing module.`),Object.assign(i[t],s)):i[t]=s}catch(e){console.error(`Failed to load plugin ${t}:`,e)}}),i},exports.pluginLoader=$;
1
+ "use strict";const t={getItem(t){try{return localStorage.getItem(t)}catch(t){return console.warn("No localStorage available"),null}},setItem(t,e){try{localStorage.setItem(t,e)}catch(t){console.warn("Cannot write to localStorage")}},removeItem(t){try{localStorage.removeItem(t)}catch(t){console.warn("Cannot remove from localStorage")}}},e=async(t,e)=>(await fetch(t,e)).json();class s{constructor({baseUrl:s,apiKey:r,storage:i,request:a}){this.baseUrl=s,this.apiKey=r,this.storage=i||t,this.requestImpl=a||e}getApiKey(){return this.apiKey}setToken(t){t?this.storage.setItem("baas_token",t):this.storage.removeItem("baas_token")}getToken(){return this.storage.getItem("baas_token")}async request(t,e={}){const s=`${this.baseUrl}${t}`,r={"Content-Type":"application/json",CODE_FLYING:`${this.apiKey}`,...this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{},...e.headers||{}},i=await this.requestImpl(s,{...e,headers:r});return console.log("url: ",s,"\n header:",r,"\n response:",i),i}}function r(t){return{async login({user_name:e,phone:s,email:r,password:i}={}){const a=e||s||r;if(!a)throw new Error("必须提供 user_name、phone 或 email 之一");if(!i)throw new Error("必须提供 password");const n=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:a,password:i})});return n.success&&t.setToken(n.data),n},async loginByEmailAndCode({email:e,code:s}={}){const r=await t.request("/login/mail",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByPhoneAndCode({phone:e,code:s}={}){const r=await t.request("/login/phone",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByWeChat({code:e}={}){const s=await t.request("/login/wechat",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},async loginByWeApp({code:e}={}){const s=await t.request("/login/weapp",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},getUser:async()=>t.request("/getUserInfo",{method:"GET"}),register:async e=>await t.request("/login/register",{method:"POST",body:JSON.stringify(e)}),logout:async()=>(t.setToken(null),t.request("/logout",{method:"GET"})),loginOauth2Uri:async({provider:e}={})=>await t.request("/oauth2/authorize/"+e,{method:"GET"})}}class i{constructor(t,e){this.client=t,this.table=e,this._body=null,this._method=""}list(){return new a(this.client,this.table,"list")}page(){return new a(this.client,this.table,"page")}get(){return new a(this.client,this.table,"get")}insert(){return new n(this.client,this.table,"add")}update(){return new n(this.client,this.table,"update")}delete(){return new a(this.client,this.table,"delete")}}class a{constructor(t,e,s){this.client=t,this.table=e,this.method=s,this.filters={}}_addFilter(t,e,s){return this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t][e]=s,this}eq(t,e){return this._addFilter(t,"eq",e)}neq(t,e){return this._addFilter(t,"neq",e)}gt(t,e){return this._addFilter(t,"gt",e)}gte(t,e){return this._addFilter(t,"gte",e)}lt(t,e){return this._addFilter(t,"lt",e)}lte(t,e){return this._addFilter(t,"lte",e)}like(t,e){return this._addFilter(t,"like",e)}in(t,e){return this._addFilter(t,"in",e)}between(t,e){return this._addFilter(t,"between",e)}or(t){this.filters.or||(this.filters.or=[]);const e=new a(this.client,this.table,"or");return t(e),this.filters.or.push(e.build()),this}limit(t){return this}page(t,e){return this.filters.current=t,this.filters.pageSize=e,this}order(t,e="asc"){this.filters.order_by||(this.filters.order_by=[]);let s="asc";return"string"==typeof e?s=e.toLowerCase():"object"==typeof e&&null!==e&&("ascending"in e?s=e.ascending?"asc":"desc":"direction"in e&&(s=e.direction.toLowerCase())),this.filters.order_by.push({field:t,direction:s}),this}build(){return this.filters}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:this.filters?JSON.stringify(this.filters):void 0})}then(t,e){this._execute().then(t,e)}}class n extends a{constructor(t,e,s){super(t,e,s),this.data={}}values(t){return this.data={...t},this}set(t){return this.data={...t},this}build(){return{...this.filters,...this.data}}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:JSON.stringify(this.build())})}then(t,e){this._execute().then(t,e)}}function o(t){return{from:e=>new i(t,e)}}class h{constructor(t,e){this.client=t,this.apiName=e,this._params={},this._headers={},this._method="POST"}param(t,e){return this._params[t]=e,this}params(t){return Object.assign(this._params,t),this}header(t,e){return this._headers[t]=e,this}headers(t){return Object.assign(this._headers,t),this}async _execute(){const t=JSON.stringify(this._params),e=`/api/${this.apiName}`;return await this.client.request(e,{method:this._method,headers:this._headers,body:t})}then(t,e){this._execute().then(t,e)}}function c(t){return{call:e=>new h(t,e)}}class u{static API_MAP={search:"/api/bijia_spu_search",compare:"/api/bijia_spu_goods_search"};constructor(t,e){this.client=t,this._params={},this.type=e}keyword(t){return this._params.query=t,this}setParams(t={}){return Object.assign(this._params,t),this}type(t){if(!u.API_MAP[t])throw new Error(`Unsupported comparison type: ${t}`);return this.type=t,this}async _execute(){const t=u.API_MAP[this.type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){this._execute().then(t,e)}}function l(t){return{searchProduct:()=>new u(t,"search"),findLowestPrice:()=>new u(t,"compare")}}class p{constructor(t){this.client=t,this._params={},this._taskId=null,this._pollingInterval=2e3,this._maxRetries=30}url(t){return this._params.url=t,this._params.format="pdf-to-image",this}format(t="pdf-to-image"){return this._params.format=t,this}pollingInterval(t){return this._pollingInterval=t,this}maxRetries(t){return this._maxRetries=t,this}async createTask(){if(!this._params.url)throw new Error("PDF文件URL不能为空");const t=await this.client.request("/api/pdf2image",{method:"POST",body:JSON.stringify({url:this._params.url,format:this._params.format})});return this._taskId=t.data,t}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");return await this.client.request("/api/queryPDF2ImageTask",{method:"POST",body:JSON.stringify({taskId:e})})}async convert(){try{console.log("开始创建PDF转图片任务...");const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");console.log("开始轮询查询任务状态...");let s=0;for(;s<this._maxRetries;){const t=await this.queryTask(e);console.log(`第${s+1}次查询结果:`,t);const r=t.data?.state;if(1===r)return console.log("PDF转图片任务完成:",t.data),t;if(r<0)return console.log("PDF转图片任务失败,状态码:",r),t;s++,s<this._maxRetries&&(console.log(`等待${this._pollingInterval}ms后进行第${s+1}次查询...`),await new Promise(t=>setTimeout(t,this._pollingInterval)))}throw new Error(`PDF转图片任务超时,已重试${this._maxRetries}次`)}catch(t){throw console.error("PDF转图片失败:",t),t}}then(t,e){return this.convert().then(t,e)}catch(t){return this.convert().catch(t)}}function d(t){return{convertPdf:()=>new p(t),async quickConvert(e={}){const s=new p(t);return e.url&&s.url(e.url),e.format&&s.format(e.format),e.pollingInterval&&s.pollingInterval(e.pollingInterval),e.maxRetries&&s.maxRetries(e.maxRetries),await s.convert()}}}class m{constructor(t){this.client=t,this._params={}}company(t){return this._params.com=t,this}trackingNumber(t){return this._params.num=t,this}phone(t){return this._params.phone=t,this}_validateParams(){if(!this._params.com)throw new Error("快递公司代码不能为空");if(!this._params.num)throw new Error("快递单号不能为空");if(("shunfeng"===this._params.com||"shunfengkuaiyun"===this._params.com)&&!this._params.phone)throw new Error("顺丰快递必须提供手机号参数")}async track(){return this._validateParams(),await this.client.request("/api/expressInquiry",{method:"POST",body:JSON.stringify({com:this._params.com,num:this._params.num,resultv2:4,...this._params.phone?{phone:this._params.phone}:{}})})}then(t,e){return this.track().then(t,e)}catch(t){return this.track().catch(t)}}function y(t){return{trackPackage:()=>new m(t)}}class g{static LOCATION_MAP={location:"/api/geocoder",address:"/api/geoaddress"};constructor(t,e){this.client=t,this._params={},this.type=e}latitude(t){return this._params.latitude=t,this}longitude(t){return this._params.longitude=t,this}address(t){return this._params.address=t,this}_validateLocationParams(){if(!this._params.latitude||!this._params.longitude)throw new Error("经纬度参数不能为空")}_validateAddressParams(){if(!this._params.address)throw new Error("地址参数不能为空")}_data(){return"location"===this.type?(this._validateLocationParams(),{location:`${this._params.latitude},${this._params.longitude}`}):(this._validateAddressParams(),{address:this._params.address})}async _execute(){const t=g.LOCATION_MAP[this.type],e=this._data();let s=await this.client.request(t,{method:"POST",body:JSON.stringify(e)}),r=s;return"data"in s&&"result"in s.data&&(r.result=s.data.result,r.result.latitude=s.data.result.location.lat,r.result.longitude=s.data.result.location.lng,r.status=s.data.status),r}then(t,e){this._execute().then(t,e)}}class _{constructor(t){this.client=t}async _execute(){const t=await this.client.request("/api/amap_ip_location",{method:"POST",body:JSON.stringify({})}),e=t?.data?.rectangle;if(!e)throw new Error("返回数据中缺少 rectangle 字段");const[s,r]=e.split(";"),[i,a]=s.split(",").map(Number),[n,o]=r.split(",").map(Number);return{success:!0,latitude:(a+o)/2,longitude:(i+n)/2,speed:0,altitude:0,horizontalAccuracy:1e3}}then(t,e){this._execute().then(t,e)}}class w{constructor(t){this.client=t,this._params={}}from(t,e){return this._params.from={lat:t,lng:e},this}to(t,e){return this._params.to={lat:t,lng:e},this}decodePolyline(t){for(let e=2;e<t.length;e++)t[e]=t[e-2]+t[e]/1e6;return t}async _execute(){const{from:t,to:e}=this._params;if(!t||!e)throw new Error("必须提供起点和终点坐标");const s={from:`${t.lat},${t.lng}`,to:`${e.lat},${e.lng}`},r=await this.client.request("/api/driving",{method:"POST",body:JSON.stringify(s)}),{routes:i}=r.data.result;return{success:!0,data:{paths:i.map(t=>{const e=this.decodePolyline([...t.polyline]),s=t.steps.map(t=>{const{polyline_idx:[s,r]}=t,i=[];for(let t=s;t<=r;t+=2)i.push({latitude:e[t],longitude:e[t+1]});return{...t,polylines:i}});return{distance:t.distance,duration:t.duration,steps:s}})}}}then(t,e){this._execute().then(t,e)}}class f{constructor(t){this.client=t,this._params={}}lat(t){return this._params.lat=t,this}lng(t){return this._params.lng=t,this}radius(t){return this._params.radius=t,this}keyword(t){return this._params.keyword=t,this}async _execute(){const{lat:t,lng:e,radius:s=1e3,keyword:r}=this._params;if(!t||!e)throw new Error("必须提供经纬度参数");const i={boundary:`nearby(${t},${e},${s})`,...r&&{keyword:r}},a=await this.client.request("/api/mapsearch",{method:"POST",body:JSON.stringify(i)}),{data:n}=a.data;return{success:!0,data:n.map(t=>({...t,latitude:t.location.lat,longitude:t.location.lng}))}}then(t,e){this._execute().then(t,e)}}function P(t){return{locationToAddress:()=>new g(t,"location"),addressToLocation:()=>new g(t,"address"),currentLocation:()=>new _(t),driving:()=>new w(t),nearby:()=>new f(t)}}class q{static API_MAP={train:"/api/queryTickets",flight:"/api/queryFlight"};constructor(t,e){this.client=t,this.params={},this.mode=e}from(t){return this.params.from=t,this}to(t){return this.params.to=t,this}date(t){return this.params.date=t,this}async _execute(){const t=q.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function S(t){return{train:()=>new q(t,"train"),flight:()=>new q(t,"flight")}}class b{static API_MAP={feishu:"/api/feishuRobotText",wechat:"/api/wechatRobotText"};constructor(t,e){this.client=t,this.params={},this.mode=e}content(t){return this.params.content=t?.replace(/\r?\n/g," "),this}async _execute(){const t=b.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}class A{constructor(t){this.client=t,this.payload={}}title(t){return this.payload.title=t,this}content(t){return this.payload.content=t?.replace(/\r?\n/g," "),this}to(t){return this.payload.to=t,this}params(t={}){return this.payload.params=t,this}async _execute(){return await this.client.request("/common/mail/send",{method:"POST",body:JSON.stringify(this.payload)})}then(t,e){this._execute().then(t,e)}}function x(t){return{feishuRobot:()=>new b(t,"feishu"),wechatRobot:()=>new b(t,"wechat"),mail:()=>new A(t)}}class T{static API_MAP={text2pic:"/api/word2pic",text2tts:"/api/text/tts"};constructor(t,e){this.client=t,this.params={model:"gemini-3-pro-image-preview"},this.mode=e}text(t){return this.params.text=t,this}model(t){return this.params.model=t,this}async _execute(){const t=T.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}class k{constructor(t){this.client=t}async uploadFile(t,e="mp3",s="audio/mpeg"){const r=await this.client.request("/common/uploadByUrl",{method:"POST",body:JSON.stringify({fileUrl:t,formatter:e,contentType:s})});return console.log("uploadFile response:",r),r}}class O extends k{constructor(t){super(t),this.params={}}text(t){return this.params.text=t,this}speaker(t){return this.params.speaker=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");let e=this.params.speaker;e&&""!==e||(e="zh_female_cancan_mars_bigtts");let s={text:t,speaker:e};const r=this.client.request("/api/ttsTask",{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");let s={taskId:e};return await this.client.request("/api/queryTts",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=await this.createTask();console.log("====TTS任务创建成功:====",t);const e=t.data.task_id;if(!e)throw new Error("任务创建失败,未返回任务ID");let s=0;for(;2!==s;){const t=await this.queryTask(e);if(s=t.data?.task_status||0,2===s){const e=await this.uploadFile(t.data.audio_url);return t.data=e.data,t}if(3===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}class I{constructor(t){this.client=t,this.params={}}text(t){return this.params.text=t,this}prompt(t){return this.params.prompt=t,this}conversationId(t){return this.params.conversationId=t,this}async _execute(){const{text:t,prompt:e="",conversationId:s=""}=this.params,r={prompt:e,query:t,conversation_id:s,user:this.client.getApiKey(),files:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(r)})}then(t,e){this._execute().then(t,e)}}class N extends I{constructor(t){super(t)}url(t){return this.params.url=t,this}async _execute(){const{url:t,prompt:e,text:s,conversationId:r=""}=this.params,i=[{type:"image",transfer_method:"remote_url",url:t}],a={prompt:e,query:s,conversation_id:r,user:this.client.getApiKey(),files:t?i:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(a)})}then(t,e){this._execute().then(t,e)}}class v extends k{static CREATE_API_MAP={video:"/api/text2video",audio:"/api/text2music"};static QUERY_API_MAP={video:"/api/queryVideo",audio:"/api/queryMusic"};constructor(t,e){super(t),this.params={},this.mode=e,this._taskId=null}text(t){return this.params.text=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");const e=v.CREATE_API_MAP[this.mode];let s={};s="video"===this.mode?{text:t}:{prompt:this.cleanString(t)};const r=this.client.request(e,{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");const s=v.QUERY_API_MAP[this.mode];let r={};return r="video"===this.mode?{id:e}:{item_ids:e},await this.client.request(s,{method:"POST",body:JSON.stringify(r)})}async _execute(){const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");let s="";for(;"succeeded"!==s;){const t=await this.queryTask(e);if(s=t.data?.status||"","succeeded"===s){if("video"===this.mode){const e=await this.uploadFile(t.data.content.video_url,"mp4","video/mp4");t.data.content.video_url=e.data}else{const e=await this.uploadFile(t.data.audio_url,"mp3","audio/mpeg");t.data.audio_url=e.data}return t}if("failed"===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){this._execute().then(t,e)}cleanString(t){return t?(t=(t=(t=t.toString()).replace(/[\n\r\t]+/g,",")).replace(/\s{2,}/g,",")).trim():t}}function M(t){return{textToImage:()=>new T(t,"text2pic"),textToSpeech:()=>new O(t),imageToText:()=>new N(t),chat:()=>new I(t),textToVideo:()=>new v(t,"video"),textToAudio:()=>new v(t,"audio")}}class C{static API_MAP={web:"/api/webSearch",video:"/api/webSearch",image:"/api/webSearch"};constructor(t,e){this.client=t,this._params={type:e,top_k:20,site:[]},this._type=e}content(t){return this._params.content=t,this}type(t){if(!C.API_MAP[t])throw new Error(`Unsupported search type: ${t}`);return this._type=t,this._params.type=t,this}site(t){return this._params.site||(this._params.site=[]),null==t||this._params.site.push(t),this}async _execute(){const t=C.API_MAP[this._type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){return this._execute().then(t,e)}}function J(t){return{search:()=>new C(t,"web"),webSearch:()=>new C(t,"web"),videoSearch:()=>new C(t,"video"),imageSearch:()=>new C(t,"image")}}const E=new class{constructor(){this.plugins=new Map,this.pluginModules=new Map}register(t,e){if(this.plugins.has(t))console.warn(`Plugin ${t} is already registered`);else{if(!this.validatePlugin(e))throw console.log(`Invalid plugin module for ${t}:`,{type:typeof e,value:e,constructor:e?.constructor?.name,keys:"object"==typeof e?Object.keys(e):"N/A"}),new Error(`Invalid plugin module structure for ${t}`);this.plugins.set(t,{name:t,module:e,initialized:!1}),console.log(`Plugin ${t} registered successfully`)}}validatePlugin(t){return null!=t&&("function"==typeof t||"object"==typeof t&&!Array.isArray(t))}init(t,e){const s=this.plugins.get(t);if(!s)throw new Error(`Plugin ${t} not found`);let r;if("function"!=typeof s.module&&"object"!=typeof s.module)throw new Error(`Invalid plugin module type for ${t}`);return r=s.module,s.initialized=!0,"function"==typeof r.init&&r.init(),r}getRegisteredPlugins(){return Array.from(this.plugins.keys())}isRegistered(t){return this.plugins.has(t)}unregister(t){this.plugins.has(t)&&(this.plugins.delete(t),console.log(`Plugin ${t} unregistered`))}};class B{constructor(t){this.client=t,this._params={}}interval(t){return this._params.interval=t,this}vsCurrency(t){return this._params.vsCurrency=t,this}days(t){return this._params.days=t,this}async query(){return await this.client.request("/api/historytrend",{method:"POST",body:JSON.stringify({interval:this._params.interval,vs_currency:this._params.vsCurrency,days:this._params.days})})}then(t,e){return this.query().then(t,e)}catch(t){return this.query().catch(t)}}function D(t){return{historytrend:()=>new B(t)}}class R{static API_MAP={googleSearch:"/api/googleSearch"};constructor(t){this.client=t,this.params={}}content(t){return this.params.content=t,this}num(t){return this.params.num=t,this}type(t){return this.params.type=t,this}async _execute(){const t=R.API_MAP.googleSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function $(t){return{search:()=>new R(t)}}class F{static API_MAP={list:"/api/queryToutiaoIndex",content:"/api/queryToutiaoContent",NewsByCategory:"/api/NewsByCategory",NewsByRegion:"/api/NewsByRegion"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}page(t){return this.params.page=t,this}page_size(t){return this.params.pageSize=t,this}is_filter(t){return this.params.isFilter=t,this}uniquekey(t){return this.params.uniquekey=t,this}category(t){return this.params.category=t,this}region(t){return this.params.region=t,this}async _execute(){const t=F.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function L(t){return{queryToutiaoIndex:()=>new F(t,"list"),queryToutiaoContent:()=>new F(t,"content"),queryNYNewsByCategory:()=>new F(t,"NewsByCategory"),queryNYNewsByRegion:()=>new F(t,"NewsByRegion")}}class W{static API_MAP={nationalWeather:"/api/nationalWeather",internationalWeather:"/api/weather"};constructor(t,e){this.client=t,this.mode=e,this.params={}}city(t){return"nationalWeather"!==this.mode&&console.warn("city 参数仅适用于 nationalWeather 模式"),this.params.city=t,this}latitude(t){return"internationalWeather"!==this.mode&&console.warn("latitude 参数仅适用于 internationalWeather 模式"),this.params["location.latitude"]=t,this}longitude(t){return"internationalWeather"!==this.mode&&console.warn("longitude 参数仅适用于 internationalWeather 模式"),this.params["location.longitude"]=t,this}async _execute(){this._validateParams();const t=W.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}_validateParams(){if("nationalWeather"===this.mode){if(!this.params.city)throw new Error("nationalWeather 模式需要提供 city 参数")}else if(!("internationalWeather"!==this.mode||this.params["location.latitude"]&&this.params["location.longitude"]))throw new Error("internationalWeather 模式需要提供 latitude 和 longitude 参数")}then(t,e){return this._execute().then(t,e)}}function z(t){return{queryNationalWeather:()=>new W(t,"nationalWeather"),queryWeather:()=>new W(t,"internationalWeather")}}class U{static API_MAP={frate:"/api/frate",rmbquot:"/api/rmbquot"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}bank(t){return this.params.bank=t,this}async _execute(){const t=U.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function j(t){return{frate:()=>new U(t,"frate"),rmbquot:()=>new U(t,"rmbquot")}}class G{static API_MAP={queryCaipu:"/api/queryCaipu",RandomRecipes:"/api/RandomRecipes",MealPlan:"/api/MealPlan"};constructor(t,e){this.client=t,this.params={},this.mode=e}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}tags(t){return this.params.tags=t,this}number(t){return this.params.number=t,this}timeFrame(t){return this.params.timeFrame=t,this}targetCalories(t){return this.params.targetCalories=t,this}diet(t){return this.params.diet=t,this}exclude(t){return this.params.exclude=t,this}async _execute(){const t=G.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function K(t){return{queryIngredients:()=>new G(t,"queryCaipu"),queryDishName:()=>new G(t,"queryCaipu"),query:()=>new G(t,"queryCaipu"),queryRandomRecipes:()=>new G(t,"RandomRecipes"),queryMealPlan:()=>new G(t,"MealPlan")}}class Y{static API_MAP={queryCarPrice:"/api/queryCarPrice"};constructor(t){this.client=t,this.params={}}search(t){return this.params.search=t,this}async _execute(){const t=Y.API_MAP.queryCarPrice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function H(t){return{query:()=>new Y(t)}}class Q{static API_MAP={queryDiseaseByName:"/api/queryDiseaseByName"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}async _execute(){const t=Q.API_MAP.queryDiseaseByName;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function V(t){return{query:()=>new Q(t)}}class X{static API_MAP={queryCalorie:"/api/queryCalorie"};constructor(t){this.client=t,this.params={}}sex(t){return this.params.sex=t,this}height(t){return this.params.height=t,this}weight(t){return this.params.weight=t,this}age(t){return this.params.age=t,this}level(t){return this.params.level=t,this}async _execute(){const t=X.API_MAP.queryCalorie;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function Z(t){return{query:()=>new X(t)}}class tt{static API_MAP={nationalGoldprice:"/api/nationalGoldprice"};constructor(t){this.client=t,this.params={}}async _execute(){const t=tt.API_MAP.nationalGoldprice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function et(t){return{query:()=>new tt(t)}}class st{static API_MAP={youtubeSearch:"/api/youtubeSearch"};constructor(t){this.client=t,this.params={}}q(t){return this.params.q=t,this}type(t){return this.params.type=t,this}async _execute(){const t=st.API_MAP.youtubeSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function rt(t){return{search:()=>new st(t)}}class it{static API_MAP={queryTimezone:"/api/timezone"};constructor(t){this.client=t,this.params={}}location(t){return this.params.location=t,this}timestamp(t){return this.params.timestamp=t,this}async _execute(){const t=it.API_MAP.queryTimezone;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function at(t){return{search:()=>new it(t)}}class nt{static API_MAP={queryNationalScenic:"/api/queryNationalScenic",restaurantsSearch:"/api/restaurantsSearch",hotelsSearch:"/api/hotelsSearch",attractionSearch:"/api/attractionSearch"};constructor(t,e){this.client=t,this.params={},this.model=e}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}province(t){return this.params.province=t,this}city(t){return this.params.city=t,this}query(t){return this.params.query=t,this}async _execute(){const t=nt.API_MAP[this.model];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ot(t){return{query:()=>new nt(t,"queryNationalScenic"),queryRestaurantsSearch:()=>new nt(t,"restaurantsSearch"),queryHotelsSearch:()=>new nt(t,"hotelsSearch"),queryAttractionSearch:()=>new nt(t,"attractionSearch")}}class ht{static API_MAP={queryFootballMatch:"/api/queryFootballMatch",footballRank:"/api/footballRank"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}async _execute(){const t=ht.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ct(t){return{match:()=>new ht(t,"queryFootballMatch"),rank:()=>new ht(t,"footballRank")}}class ut{static API_MAP={hsStock:"/api/hsStock",hkStock:"/api/hkStock",usaStock:"/api/usaStock",hkall:"/api/hkall",usaall:"/api/usaall",szall:"/api/szall",shall:"/api/shall",TimeDaily:"/api/TimeDaily",CurrencyExchange:"/api/CurrencyExchange",DigitalCurrencyDaily:"/api/DigitalCurrencyDaily",TechnicalIndicators:"/api/TechnicalIndicators"};constructor(t,e){this.client=t,this.mode=e,this.params={}}gid(t){return this.params.gid=t,this}type(t){return this.params.type=t,this}num(t){return this.params.num=t,this}stock(t){return this.params.stock=t,this}page(t){return this.params.page=t,this}symbol(t){return this.params.symbol=t,this}to_currency(t){return this.params.to_currency=t,this}from_currency(t){return this.params.from_currency=t,this}market(t){return this.params.market=t,this}time_period(t){return this.params.time_period=t,this}interval(t){return this.params.interval=t,this}series_type(t){return this.params.series_type=t,this}async _execute(){const t=ut.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function lt(t){return{queryHs:()=>new ut(t,"hsStock"),queryHk:()=>new ut(t,"hkStock"),queryUsa:()=>new ut(t,"usaStock"),queryHkAll:()=>new ut(t,"hkall"),queryUsaAll:()=>new ut(t,"usaall"),querySzAll:()=>new ut(t,"szall"),queryShAll:()=>new ut(t,"shall"),queryTimeDaily:()=>new ut(t,"TimeDaily"),queryCurrencyExchange:()=>new ut(t,"CurrencyExchange"),queryDigitalCurrencyDaily:()=>new ut(t,"DigitalCurrencyDaily"),queryTechnicalIndicators:()=>new ut(t,"TechnicalIndicators")}}class pt{static API_MAP={SearchCocktail:"/api/SearchCocktail",ListPopularCocktails:"/api/ListPopularCocktails",ListMostLatestCocktails:"/api/ ListMostLatestCocktails",GetBeersDataByBreweryOrBrand:"/api/GetBeersDataByBreweryOrBrand",GetBeersDataByName:"/api/GetBeersDataByName"};constructor(t,e){this.client=t,this.params={},this.mode=e}s(t){return this.params.s=t,this}brewery(t){return this.params.brewery=t,this}name(t){return this.params.name=t,this}async _execute(){const t=pt.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function dt(t){return{queryCocktail:()=>new pt(t,"SearchCocktail"),queryPopularCocktails:()=>new pt(t,"ListPopularCocktails"),queryLatestCocktails:()=>new pt(t,"ListMostLatestCocktails"),queryBeersData:()=>new pt(t,"GetBeersDataByBreweryOrBrand"),queryBeersDataByName:()=>new pt(t,"GetBeersDataByName")}}exports.createClient=function(t){const e=new s(t),i={setToken:t=>e.setToken(t),getToken:()=>e.getToken(),auth:r(e),db:o(e),api:c(e),comparison:l(e),document:d(e),logistics:y(e),location:P(e),travel:S(e),notification:x(e),ai:M(e),baidu:J(e),bitcoin:D(e),google:$(e),news:L(e),weather:z(e),money:j(e),caipu:K(e),car:H(e),disease:V(e),calorie:Z(e),goldprice:et(e),youtube:rt(e),timezone:at(e),scenic:ot(e),football:ct(e),stock:lt(e),wine:dt(e)};return E.getRegisteredPlugins().forEach(t=>{try{const s=E.init(t,e);i[t]?(console.warn(`Plugin "${t}" conflicts with built-in module. Merging plugin methods into existing module.`),Object.assign(i[t],s)):i[t]=s}catch(e){console.error(`Failed to load plugin ${t}:`,e)}}),i},exports.pluginLoader=E;
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- const t={getItem(t){try{return localStorage.getItem(t)}catch(t){return console.warn("No localStorage available"),null}},setItem(t,e){try{localStorage.setItem(t,e)}catch(t){console.warn("Cannot write to localStorage")}},removeItem(t){try{localStorage.removeItem(t)}catch(t){console.warn("Cannot remove from localStorage")}}},e=async(t,e)=>(await fetch(t,e)).json();class s{constructor({baseUrl:s,apiKey:r,storage:i,request:a}){this.baseUrl=s,this.apiKey=r,this.storage=i||t,this.requestImpl=a||e}getApiKey(){return this.apiKey}setToken(t){t?this.storage.setItem("baas_token",t):this.storage.removeItem("baas_token")}getToken(){return this.storage.getItem("baas_token")}async request(t,e={}){const s=`${this.baseUrl}${t}`,r={"Content-Type":"application/json",CODE_FLYING:`${this.apiKey}`,...this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{},...e.headers||{}},i=await this.requestImpl(s,{...e,headers:r});return console.log("url: ",s,"\n header:",r,"\n response:",i),i}}function r(t){return{async login({user_name:e,phone:s,email:r,password:i}={}){const a=e||s||r;if(!a)throw new Error("必须提供 user_name、phone 或 email 之一");if(!i)throw new Error("必须提供 password");const n=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:a,password:i})});return n.success&&t.setToken(n.data),n},async loginByEmailAndCode({email:e,code:s}={}){const r=await t.request("/login/mail",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByPhoneAndCode({phone:e,code:s}={}){const r=await t.request("/login/phone",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByWeChat({code:e}={}){const s=await t.request("/login/wechat",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},async loginByWeApp({code:e}={}){const s=await t.request("/login/weapp",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},getUser:async()=>t.request("/getUserInfo",{method:"GET"}),register:async e=>await t.request("/login/register",{method:"POST",body:JSON.stringify(e)}),logout:async()=>(t.setToken(null),t.request("/logout",{method:"GET"})),loginOauth2Uri:async({provider:e}={})=>await t.request("/oauth2/authorize/"+e,{method:"GET"})}}class i{constructor(t,e){this.client=t,this.table=e,this._body=null,this._method=""}list(){return new a(this.client,this.table,"list")}page(){return new a(this.client,this.table,"page")}get(){return new a(this.client,this.table,"get")}insert(){return new n(this.client,this.table,"add")}update(){return new n(this.client,this.table,"update")}delete(){return new a(this.client,this.table,"delete")}}class a{constructor(t,e,s){this.client=t,this.table=e,this.method=s,this.filters={}}_addFilter(t,e,s){return this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t][e]=s,this}eq(t,e){return this._addFilter(t,"eq",e)}neq(t,e){return this._addFilter(t,"neq",e)}gt(t,e){return this._addFilter(t,"gt",e)}gte(t,e){return this._addFilter(t,"gte",e)}lt(t,e){return this._addFilter(t,"lt",e)}lte(t,e){return this._addFilter(t,"lte",e)}like(t,e){return this._addFilter(t,"like",e)}in(t,e){return this._addFilter(t,"in",e)}between(t,e){return this._addFilter(t,"between",e)}or(t){this.filters.or||(this.filters.or=[]);const e=new a(this.client,this.table,"or");return t(e),this.filters.or.push(e.build()),this}limit(t){return this}page(t,e){return this.filters.current=t,this.filters.pageSize=e,this}order(t,e="asc"){this.filters.order_by||(this.filters.order_by=[]);let s="asc";return"string"==typeof e?s=e.toLowerCase():"object"==typeof e&&null!==e&&("ascending"in e?s=e.ascending?"asc":"desc":"direction"in e&&(s=e.direction.toLowerCase())),this.filters.order_by.push({field:t,direction:s}),this}build(){return this.filters}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:this.filters?JSON.stringify(this.filters):void 0})}then(t,e){this._execute().then(t,e)}}class n extends a{constructor(t,e,s){super(t,e,s),this.data={}}values(t){return this.data={...t},this}set(t){return this.data={...t},this}build(){return{...this.filters,...this.data}}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:JSON.stringify(this.build())})}then(t,e){this._execute().then(t,e)}}function o(t){return{from:e=>new i(t,e)}}class h{constructor(t,e){this.client=t,this.apiName=e,this._params={},this._headers={},this._method="POST"}param(t,e){return this._params[t]=e,this}params(t){return Object.assign(this._params,t),this}header(t,e){return this._headers[t]=e,this}headers(t){return Object.assign(this._headers,t),this}async _execute(){const t=JSON.stringify(this._params),e=`/api/${this.apiName}`;return await this.client.request(e,{method:this._method,headers:this._headers,body:t})}then(t,e){this._execute().then(t,e)}}function c(t){return{call:e=>new h(t,e)}}class u{static API_MAP={search:"/api/bijia_spu_search",compare:"/api/bijia_spu_goods_search"};constructor(t,e){this.client=t,this._params={},this.type=e}keyword(t){return this._params.query=t,this}setParams(t={}){return Object.assign(this._params,t),this}type(t){if(!u.API_MAP[t])throw new Error(`Unsupported comparison type: ${t}`);return this.type=t,this}async _execute(){const t=u.API_MAP[this.type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){this._execute().then(t,e)}}function l(t){return{searchProduct:()=>new u(t,"search"),findLowestPrice:()=>new u(t,"compare")}}class d{constructor(t){this.client=t,this._params={},this._taskId=null,this._pollingInterval=2e3,this._maxRetries=30}url(t){return this._params.url=t,this._params.format="pdf-to-image",this}format(t="pdf-to-image"){return this._params.format=t,this}pollingInterval(t){return this._pollingInterval=t,this}maxRetries(t){return this._maxRetries=t,this}async createTask(){if(!this._params.url)throw new Error("PDF文件URL不能为空");const t=await this.client.request("/api/pdf2image",{method:"POST",body:JSON.stringify({url:this._params.url,format:this._params.format})});return this._taskId=t.data,t}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");return await this.client.request("/api/queryPDF2ImageTask",{method:"POST",body:JSON.stringify({taskId:e})})}async convert(){try{console.log("开始创建PDF转图片任务...");const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");console.log("开始轮询查询任务状态...");let s=0;for(;s<this._maxRetries;){const t=await this.queryTask(e);console.log(`第${s+1}次查询结果:`,t);const r=t.data?.state;if(1===r)return console.log("PDF转图片任务完成:",t.data),t;if(r<0)return console.log("PDF转图片任务失败,状态码:",r),t;s++,s<this._maxRetries&&(console.log(`等待${this._pollingInterval}ms后进行第${s+1}次查询...`),await new Promise(t=>setTimeout(t,this._pollingInterval)))}throw new Error(`PDF转图片任务超时,已重试${this._maxRetries}次`)}catch(t){throw console.error("PDF转图片失败:",t),t}}then(t,e){return this.convert().then(t,e)}catch(t){return this.convert().catch(t)}}function p(t){return{convertPdf:()=>new d(t),async quickConvert(e={}){const s=new d(t);return e.url&&s.url(e.url),e.format&&s.format(e.format),e.pollingInterval&&s.pollingInterval(e.pollingInterval),e.maxRetries&&s.maxRetries(e.maxRetries),await s.convert()}}}class m{constructor(t){this.client=t,this._params={}}company(t){return this._params.com=t,this}trackingNumber(t){return this._params.num=t,this}phone(t){return this._params.phone=t,this}_validateParams(){if(!this._params.com)throw new Error("快递公司代码不能为空");if(!this._params.num)throw new Error("快递单号不能为空");if(("shunfeng"===this._params.com||"shunfengkuaiyun"===this._params.com)&&!this._params.phone)throw new Error("顺丰快递必须提供手机号参数")}async track(){return this._validateParams(),await this.client.request("/api/expressInquiry",{method:"POST",body:JSON.stringify({com:this._params.com,num:this._params.num,resultv2:4,...this._params.phone?{phone:this._params.phone}:{}})})}then(t,e){return this.track().then(t,e)}catch(t){return this.track().catch(t)}}function y(t){return{trackPackage:()=>new m(t)}}class _{static LOCATION_MAP={location:"/api/geocoder",address:"/api/geoaddress"};constructor(t,e){this.client=t,this._params={},this.type=e}latitude(t){return this._params.latitude=t,this}longitude(t){return this._params.longitude=t,this}address(t){return this._params.address=t,this}_validateLocationParams(){if(!this._params.latitude||!this._params.longitude)throw new Error("经纬度参数不能为空")}_validateAddressParams(){if(!this._params.address)throw new Error("地址参数不能为空")}_data(){return"location"===this.type?(this._validateLocationParams(),{location:`${this._params.latitude},${this._params.longitude}`}):(this._validateAddressParams(),{address:this._params.address})}async _execute(){const t=_.LOCATION_MAP[this.type],e=this._data();let s=await this.client.request(t,{method:"POST",body:JSON.stringify(e)}),r=s;return"data"in s&&"result"in s.data&&(r.result=s.data.result,r.result.latitude=s.data.result.location.lat,r.result.longitude=s.data.result.location.lng,r.status=s.data.status),r}then(t,e){this._execute().then(t,e)}}class g{constructor(t){this.client=t}async _execute(){const t=await this.client.request("/api/amap_ip_location",{method:"POST",body:JSON.stringify({})}),e=t?.data?.rectangle;if(!e)throw new Error("返回数据中缺少 rectangle 字段");const[s,r]=e.split(";"),[i,a]=s.split(",").map(Number),[n,o]=r.split(",").map(Number);return{success:!0,latitude:(a+o)/2,longitude:(i+n)/2,speed:0,altitude:0,horizontalAccuracy:1e3}}then(t,e){this._execute().then(t,e)}}class w{constructor(t){this.client=t,this._params={}}from(t,e){return this._params.from={lat:t,lng:e},this}to(t,e){return this._params.to={lat:t,lng:e},this}decodePolyline(t){for(let e=2;e<t.length;e++)t[e]=t[e-2]+t[e]/1e6;return t}async _execute(){const{from:t,to:e}=this._params;if(!t||!e)throw new Error("必须提供起点和终点坐标");const s={from:`${t.lat},${t.lng}`,to:`${e.lat},${e.lng}`},r=await this.client.request("/api/driving",{method:"POST",body:JSON.stringify(s)}),{routes:i}=r.data.result;return{success:!0,data:{paths:i.map(t=>{const e=this.decodePolyline([...t.polyline]),s=t.steps.map(t=>{const{polyline_idx:[s,r]}=t,i=[];for(let t=s;t<=r;t+=2)i.push({latitude:e[t],longitude:e[t+1]});return{...t,polylines:i}});return{distance:t.distance,duration:t.duration,steps:s}})}}}then(t,e){this._execute().then(t,e)}}class f{constructor(t){this.client=t,this._params={}}lat(t){return this._params.lat=t,this}lng(t){return this._params.lng=t,this}radius(t){return this._params.radius=t,this}keyword(t){return this._params.keyword=t,this}async _execute(){const{lat:t,lng:e,radius:s=1e3,keyword:r}=this._params;if(!t||!e)throw new Error("必须提供经纬度参数");const i={boundary:`nearby(${t},${e},${s})`,...r&&{keyword:r}},a=await this.client.request("/api/mapsearch",{method:"POST",body:JSON.stringify(i)}),{data:n}=a.data;return{success:!0,data:n.map(t=>({...t,latitude:t.location.lat,longitude:t.location.lng}))}}then(t,e){this._execute().then(t,e)}}function P(t){return{locationToAddress:()=>new _(t,"location"),addressToLocation:()=>new _(t,"address"),currentLocation:()=>new g(t),driving:()=>new w(t),nearby:()=>new f(t)}}class S{static API_MAP={train:"/api/queryTickets",flight:"/api/queryFlight"};constructor(t,e){this.client=t,this.params={},this.mode=e}from(t){return this.params.from=t,this}to(t){return this.params.to=t,this}date(t){return this.params.date=t,this}async _execute(){const t=S.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function b(t){return{train:()=>new S(t,"train"),flight:()=>new S(t,"flight")}}class q{static API_MAP={feishu:"/api/feishuRobotText",wechat:"/api/wechatRobotText"};constructor(t,e){this.client=t,this.params={},this.mode=e}content(t){return this.params.content=t?.replace(/\r?\n/g," "),this}async _execute(){const t=q.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}class A{constructor(t){this.client=t,this.payload={}}title(t){return this.payload.title=t,this}content(t){return this.payload.content=t?.replace(/\r?\n/g," "),this}to(t){return this.payload.to=t,this}params(t={}){return this.payload.params=t,this}async _execute(){return await this.client.request("/common/mail/send",{method:"POST",body:JSON.stringify(this.payload)})}then(t,e){this._execute().then(t,e)}}function x(t){return{feishuRobot:()=>new q(t,"feishu"),wechatRobot:()=>new q(t,"wechat"),mail:()=>new A(t)}}class T{static API_MAP={text2pic:"/api/word2pic",text2tts:"/api/text/tts"};constructor(t,e){this.client=t,this.params={model:"gemini-3-pro-image-preview"},this.mode=e}text(t){return this.params.text=t,this}model(t){return this.params.model=t,this}async _execute(){const t=T.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}class O{constructor(t){this.client=t}async uploadFile(t,e="mp3",s="audio/mpeg"){const r=await this.client.request("/common/uploadByUrl",{method:"POST",body:JSON.stringify({fileUrl:t,formatter:e,contentType:s})});return console.log("uploadFile response:",r),r}}class k extends O{constructor(t){super(t),this.params={}}text(t){return this.params.text=t,this}speaker(t){return this.params.speaker=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");let e=this.params.speaker;e&&""!==e||(e="zh_female_cancan_mars_bigtts");let s={text:t,speaker:e};const r=this.client.request("/api/ttsTask",{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");let s={taskId:e};return await this.client.request("/api/queryTts",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=await this.createTask();console.log("====TTS任务创建成功:====",t);const e=t.data.task_id;if(!e)throw new Error("任务创建失败,未返回任务ID");let s=0;for(;2!==s;){const t=await this.queryTask(e);if(s=t.data?.task_status||0,2===s){const e=await this.uploadFile(t.data.audio_url);return t.data=e.data,t}if(3===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}class I{constructor(t){this.client=t,this.params={}}text(t){return this.params.text=t,this}prompt(t){return this.params.prompt=t,this}conversationId(t){return this.params.conversationId=t,this}async _execute(){const{text:t,prompt:e="",conversationId:s=""}=this.params,r={prompt:e,query:t,conversation_id:s,user:this.client.getApiKey(),files:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(r)})}then(t,e){this._execute().then(t,e)}}class v extends I{constructor(t){super(t)}url(t){return this.params.url=t,this}async _execute(){const{url:t,prompt:e,text:s,conversationId:r=""}=this.params,i=[{type:"image",transfer_method:"remote_url",url:t}],a={prompt:e,query:s,conversation_id:r,user:this.client.getApiKey(),files:t?i:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(a)})}then(t,e){this._execute().then(t,e)}}class N extends O{static CREATE_API_MAP={video:"/api/text2video",audio:"/api/text2music"};static QUERY_API_MAP={video:"/api/queryVideo",audio:"/api/queryMusic"};constructor(t,e){super(t),this.params={},this.mode=e,this._taskId=null}text(t){return this.params.text=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");const e=N.CREATE_API_MAP[this.mode];let s={};s="video"===this.mode?{text:t}:{prompt:this.cleanString(t)};const r=this.client.request(e,{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");const s=N.QUERY_API_MAP[this.mode];let r={};return r="video"===this.mode?{id:e}:{item_ids:e},await this.client.request(s,{method:"POST",body:JSON.stringify(r)})}async _execute(){const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");let s="";for(;"succeeded"!==s;){const t=await this.queryTask(e);if(s=t.data?.status||"","succeeded"===s){if("video"===this.mode){const e=await this.uploadFile(t.data.content.video_url,"mp4","video/mp4");t.data.content.video_url=e.data}else{const e=await this.uploadFile(t.data.audio_url,"mp3","audio/mpeg");t.data.audio_url=e.data}return t}if("failed"===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){this._execute().then(t,e)}cleanString(t){return t?(t=(t=(t=t.toString()).replace(/[\n\r\t]+/g,",")).replace(/\s{2,}/g,",")).trim():t}}function M(t){return{textToImage:()=>new T(t,"text2pic"),textToSpeech:()=>new k(t),imageToText:()=>new v(t),chat:()=>new I(t),textToVideo:()=>new N(t,"video"),textToAudio:()=>new N(t,"audio")}}class J{static API_MAP={web:"/api/webSearch",video:"/api/webSearch",image:"/api/webSearch"};constructor(t,e){this.client=t,this._params={type:e,top_k:20,site:[]},this._type=e}content(t){return this._params.content=t,this}type(t){if(!J.API_MAP[t])throw new Error(`Unsupported search type: ${t}`);return this._type=t,this._params.type=t,this}site(t){return this._params.site||(this._params.site=[]),null==t||this._params.site.push(t),this}async _execute(){const t=J.API_MAP[this._type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){return this._execute().then(t,e)}}function E(t){return{search:()=>new J(t,"web"),webSearch:()=>new J(t,"web"),videoSearch:()=>new J(t,"video"),imageSearch:()=>new J(t,"image")}}const $=new class{constructor(){this.plugins=new Map,this.pluginModules=new Map}register(t,e){if(this.plugins.has(t))console.warn(`Plugin ${t} is already registered`);else{if(!this.validatePlugin(e))throw console.log(`Invalid plugin module for ${t}:`,{type:typeof e,value:e,constructor:e?.constructor?.name,keys:"object"==typeof e?Object.keys(e):"N/A"}),new Error(`Invalid plugin module structure for ${t}`);this.plugins.set(t,{name:t,module:e,initialized:!1}),console.log(`Plugin ${t} registered successfully`)}}validatePlugin(t){return null!=t&&("function"==typeof t||"object"==typeof t&&!Array.isArray(t))}init(t,e){const s=this.plugins.get(t);if(!s)throw new Error(`Plugin ${t} not found`);let r;if("function"!=typeof s.module&&"object"!=typeof s.module)throw new Error(`Invalid plugin module type for ${t}`);return r=s.module,s.initialized=!0,"function"==typeof r.init&&r.init(),r}getRegisteredPlugins(){return Array.from(this.plugins.keys())}isRegistered(t){return this.plugins.has(t)}unregister(t){this.plugins.has(t)&&(this.plugins.delete(t),console.log(`Plugin ${t} unregistered`))}};class F{constructor(t){this.client=t,this._params={}}interval(t){return this._params.interval=t,this}vsCurrency(t){return this._params.vsCurrency=t,this}days(t){return this._params.days=t,this}async query(){return await this.client.request("/api/historytrend",{method:"POST",body:JSON.stringify({interval:this._params.interval,vs_currency:this._params.vsCurrency,days:this._params.days})})}then(t,e){return this.query().then(t,e)}catch(t){return this.query().catch(t)}}function C(t){return{historytrend:()=>new F(t)}}class R{static API_MAP={googleSearch:"/api/googleSearch"};constructor(t){this.client=t,this.params={}}content(t){return this.params.content=t,this}num(t){return this.params.num=t,this}type(t){return this.params.type=t,this}async _execute(){const t=R.API_MAP.googleSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function W(t){return{search:()=>new R(t)}}class D{static API_MAP={list:"/api/queryToutiaoIndex",content:"/api/queryToutiaoContent"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}page(t){return this.params.page=t,this}page_size(t){return this.params.pageSize=t,this}is_filter(t){return this.params.isFilter=t,this}uniquekey(t){return this.params.uniquekey=t,this}async _execute(){const t=D.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function z(t){return{queryToutiaoIndex:()=>new D(t,"list"),queryToutiaoContent:()=>new D(t,"content")}}class U{static API_MAP={nationalWeather:"/api/nationalWeather",internationalWeather:"/api/weather"};constructor(t,e){this.client=t,this.mode=e,this.params={}}city(t){return"nationalWeather"!==this.mode&&console.warn("city 参数仅适用于 nationalWeather 模式"),this.params.city=t,this}latitude(t){return"internationalWeather"!==this.mode&&console.warn("latitude 参数仅适用于 internationalWeather 模式"),this.params["location.latitude"]=t,this}longitude(t){return"internationalWeather"!==this.mode&&console.warn("longitude 参数仅适用于 internationalWeather 模式"),this.params["location.longitude"]=t,this}async _execute(){this._validateParams();const t=U.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}_validateParams(){if("nationalWeather"===this.mode){if(!this.params.city)throw new Error("nationalWeather 模式需要提供 city 参数")}else if(!("internationalWeather"!==this.mode||this.params["location.latitude"]&&this.params["location.longitude"]))throw new Error("internationalWeather 模式需要提供 latitude 和 longitude 参数")}then(t,e){return this._execute().then(t,e)}}function j(t){return{queryNationalWeather:()=>new U(t,"nationalWeather"),queryWeather:()=>new U(t,"internationalWeather")}}class L{static API_MAP={frate:"/api/frate",rmbquot:"/api/rmbquot"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}bank(t){return this.params.bank=t,this}async _execute(){const t=L.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function B(t){return{frate:()=>new L(t,"frate"),rmbquot:()=>new L(t,"rmbquot")}}class G{static API_MAP={queryCaipu:"/api/queryCaipu"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}async _execute(){const t=G.API_MAP.queryCaipu;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function K(t){return{queryIngredients:()=>new G(t),queryDishName:()=>new G(t),query:()=>new G(t)}}class H{static API_MAP={queryCarPrice:"/api/queryCarPrice"};constructor(t){this.client=t,this.params={}}search(t){return this.params.search=t,this}async _execute(){const t=H.API_MAP.queryCarPrice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function Y(t){return{query:()=>new H(t)}}class Q{static API_MAP={queryDiseaseByName:"/api/queryDiseaseByName"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}async _execute(){const t=Q.API_MAP.queryDiseaseByName;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function V(t){return{query:()=>new Q(t)}}class X{static API_MAP={queryCalorie:"/api/queryCalorie"};constructor(t){this.client=t,this.params={}}sex(t){return this.params.sex=t,this}height(t){return this.params.height=t,this}weight(t){return this.params.weight=t,this}age(t){return this.params.age=t,this}level(t){return this.params.level=t,this}async _execute(){const t=X.API_MAP.queryCalorie;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function Z(t){return{query:()=>new X(t)}}class tt{static API_MAP={nationalGoldprice:"/api/nationalGoldprice"};constructor(t){this.client=t,this.params={}}async _execute(){const t=tt.API_MAP.nationalGoldprice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function et(t){return{query:()=>new tt(t)}}class st{static API_MAP={youtubeSearch:"/api/youtubeSearch"};constructor(t){this.client=t,this.params={}}q(t){return this.params.q=t,this}type(t){return this.params.type=t,this}async _execute(){const t=st.API_MAP.youtubeSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function rt(t){return{search:()=>new st(t)}}class it{static API_MAP={queryTimezone:"/api/timezone"};constructor(t){this.client=t,this.params={}}location(t){return this.params.location=t,this}timestamp(t){return this.params.timestamp=t,this}async _execute(){const t=it.API_MAP.queryTimezone;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function at(t){return{search:()=>new it(t)}}class nt{static API_MAP={queryNationalScenic:"/api/queryNationalScenic"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}province(t){return this.params.province=t,this}city(t){return this.params.city=t,this}async _execute(){const t=nt.API_MAP.queryNationalScenic;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ot(t){return{query:()=>new nt(t)}}class ht{static API_MAP={queryFootballMatch:"/api/queryFootballMatch",footballRank:"/api/footballRank"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}async _execute(){const t=ht.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ct(t){return{match:()=>new ht(t,"queryFootballMatch"),rank:()=>new ht(t,"footballRank")}}class ut{static API_MAP={hsStock:"/api/hsStock",hkStock:"/api/hkStock",usaStock:"/api/usaStock",hkall:"/api/hkall",usaall:"/api/usaall",szall:"/api/szall",shall:"/api/shall"};constructor(t,e){this.client=t,this.mode=e,this.params={}}gid(t){return this.params.gid=t,this}type(t){return this.params.type=t,this}num(t){return this.params.num=t,this}stock(t){return this.params.stock=t,this}page(t){return this.params.page=t,this}async _execute(){const t=ut.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function lt(t){return{queryHs:()=>new ut(t,"hsStock"),queryHk:()=>new ut(t,"hkStock"),queryUsa:()=>new ut(t,"usaStock"),queryHkAll:()=>new ut(t,"hkall"),queryUsaAll:()=>new ut(t,"usaall"),querySzAll:()=>new ut(t,"szall"),queryShAll:()=>new ut(t,"shall")}}function dt(t){const e=new s(t),i={setToken:t=>e.setToken(t),getToken:()=>e.getToken(),auth:r(e),db:o(e),api:c(e),comparison:l(e),document:p(e),logistics:y(e),location:P(e),travel:b(e),notification:x(e),ai:M(e),baidu:E(e),bitcoin:C(e),google:W(e),news:z(e),weather:j(e),money:B(e),caipu:K(e),car:Y(e),disease:V(e),calorie:Z(e),goldprice:et(e),youtube:rt(e),timezone:at(e),scenic:ot(e),football:ct(e),stock:lt(e)};return $.getRegisteredPlugins().forEach(t=>{try{const s=$.init(t,e);i[t]?(console.warn(`Plugin "${t}" conflicts with built-in module. Merging plugin methods into existing module.`),Object.assign(i[t],s)):i[t]=s}catch(e){console.error(`Failed to load plugin ${t}:`,e)}}),i}export{dt as createClient,$ as pluginLoader};
1
+ const t={getItem(t){try{return localStorage.getItem(t)}catch(t){return console.warn("No localStorage available"),null}},setItem(t,e){try{localStorage.setItem(t,e)}catch(t){console.warn("Cannot write to localStorage")}},removeItem(t){try{localStorage.removeItem(t)}catch(t){console.warn("Cannot remove from localStorage")}}},e=async(t,e)=>(await fetch(t,e)).json();class s{constructor({baseUrl:s,apiKey:r,storage:i,request:a}){this.baseUrl=s,this.apiKey=r,this.storage=i||t,this.requestImpl=a||e}getApiKey(){return this.apiKey}setToken(t){t?this.storage.setItem("baas_token",t):this.storage.removeItem("baas_token")}getToken(){return this.storage.getItem("baas_token")}async request(t,e={}){const s=`${this.baseUrl}${t}`,r={"Content-Type":"application/json",CODE_FLYING:`${this.apiKey}`,...this.getToken()?{Authorization:`Bearer ${this.getToken()}`}:{},...e.headers||{}},i=await this.requestImpl(s,{...e,headers:r});return console.log("url: ",s,"\n header:",r,"\n response:",i),i}}function r(t){return{async login({user_name:e,phone:s,email:r,password:i}={}){const a=e||s||r;if(!a)throw new Error("必须提供 user_name、phone 或 email 之一");if(!i)throw new Error("必须提供 password");const n=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:a,password:i})});return n.success&&t.setToken(n.data),n},async loginByEmailAndCode({email:e,code:s}={}){const r=await t.request("/login/mail",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByPhoneAndCode({phone:e,code:s}={}){const r=await t.request("/login/phone",{method:"POST",body:JSON.stringify({phone:e,code:s})});return r.success&&t.setToken(r.data),r},async loginByWeChat({code:e}={}){const s=await t.request("/login/wechat",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},async loginByWeApp({code:e}={}){const s=await t.request("/login/weapp",{method:"POST",body:JSON.stringify({code:e})});return s.success&&t.setToken(s.data),s},getUser:async()=>t.request("/getUserInfo",{method:"GET"}),register:async e=>await t.request("/login/register",{method:"POST",body:JSON.stringify(e)}),logout:async()=>(t.setToken(null),t.request("/logout",{method:"GET"})),loginOauth2Uri:async({provider:e}={})=>await t.request("/oauth2/authorize/"+e,{method:"GET"})}}class i{constructor(t,e){this.client=t,this.table=e,this._body=null,this._method=""}list(){return new a(this.client,this.table,"list")}page(){return new a(this.client,this.table,"page")}get(){return new a(this.client,this.table,"get")}insert(){return new n(this.client,this.table,"add")}update(){return new n(this.client,this.table,"update")}delete(){return new a(this.client,this.table,"delete")}}class a{constructor(t,e,s){this.client=t,this.table=e,this.method=s,this.filters={}}_addFilter(t,e,s){return this.filters.hasOwnProperty(t)||(this.filters[t]={}),this.filters[t][e]=s,this}eq(t,e){return this._addFilter(t,"eq",e)}neq(t,e){return this._addFilter(t,"neq",e)}gt(t,e){return this._addFilter(t,"gt",e)}gte(t,e){return this._addFilter(t,"gte",e)}lt(t,e){return this._addFilter(t,"lt",e)}lte(t,e){return this._addFilter(t,"lte",e)}like(t,e){return this._addFilter(t,"like",e)}in(t,e){return this._addFilter(t,"in",e)}between(t,e){return this._addFilter(t,"between",e)}or(t){this.filters.or||(this.filters.or=[]);const e=new a(this.client,this.table,"or");return t(e),this.filters.or.push(e.build()),this}limit(t){return this}page(t,e){return this.filters.current=t,this.filters.pageSize=e,this}order(t,e="asc"){this.filters.order_by||(this.filters.order_by=[]);let s="asc";return"string"==typeof e?s=e.toLowerCase():"object"==typeof e&&null!==e&&("ascending"in e?s=e.ascending?"asc":"desc":"direction"in e&&(s=e.direction.toLowerCase())),this.filters.order_by.push({field:t,direction:s}),this}build(){return this.filters}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:this.filters?JSON.stringify(this.filters):void 0})}then(t,e){this._execute().then(t,e)}}class n extends a{constructor(t,e,s){super(t,e,s),this.data={}}values(t){return this.data={...t},this}set(t){return this.data={...t},this}build(){return{...this.filters,...this.data}}async _execute(){return await this.client.request(`/api/data/invoke?table=${this.table}&method=${this.method}`,{method:"POST",body:JSON.stringify(this.build())})}then(t,e){this._execute().then(t,e)}}function o(t){return{from:e=>new i(t,e)}}class h{constructor(t,e){this.client=t,this.apiName=e,this._params={},this._headers={},this._method="POST"}param(t,e){return this._params[t]=e,this}params(t){return Object.assign(this._params,t),this}header(t,e){return this._headers[t]=e,this}headers(t){return Object.assign(this._headers,t),this}async _execute(){const t=JSON.stringify(this._params),e=`/api/${this.apiName}`;return await this.client.request(e,{method:this._method,headers:this._headers,body:t})}then(t,e){this._execute().then(t,e)}}function c(t){return{call:e=>new h(t,e)}}class u{static API_MAP={search:"/api/bijia_spu_search",compare:"/api/bijia_spu_goods_search"};constructor(t,e){this.client=t,this._params={},this.type=e}keyword(t){return this._params.query=t,this}setParams(t={}){return Object.assign(this._params,t),this}type(t){if(!u.API_MAP[t])throw new Error(`Unsupported comparison type: ${t}`);return this.type=t,this}async _execute(){const t=u.API_MAP[this.type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){this._execute().then(t,e)}}function l(t){return{searchProduct:()=>new u(t,"search"),findLowestPrice:()=>new u(t,"compare")}}class p{constructor(t){this.client=t,this._params={},this._taskId=null,this._pollingInterval=2e3,this._maxRetries=30}url(t){return this._params.url=t,this._params.format="pdf-to-image",this}format(t="pdf-to-image"){return this._params.format=t,this}pollingInterval(t){return this._pollingInterval=t,this}maxRetries(t){return this._maxRetries=t,this}async createTask(){if(!this._params.url)throw new Error("PDF文件URL不能为空");const t=await this.client.request("/api/pdf2image",{method:"POST",body:JSON.stringify({url:this._params.url,format:this._params.format})});return this._taskId=t.data,t}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");return await this.client.request("/api/queryPDF2ImageTask",{method:"POST",body:JSON.stringify({taskId:e})})}async convert(){try{console.log("开始创建PDF转图片任务...");const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");console.log("开始轮询查询任务状态...");let s=0;for(;s<this._maxRetries;){const t=await this.queryTask(e);console.log(`第${s+1}次查询结果:`,t);const r=t.data?.state;if(1===r)return console.log("PDF转图片任务完成:",t.data),t;if(r<0)return console.log("PDF转图片任务失败,状态码:",r),t;s++,s<this._maxRetries&&(console.log(`等待${this._pollingInterval}ms后进行第${s+1}次查询...`),await new Promise(t=>setTimeout(t,this._pollingInterval)))}throw new Error(`PDF转图片任务超时,已重试${this._maxRetries}次`)}catch(t){throw console.error("PDF转图片失败:",t),t}}then(t,e){return this.convert().then(t,e)}catch(t){return this.convert().catch(t)}}function d(t){return{convertPdf:()=>new p(t),async quickConvert(e={}){const s=new p(t);return e.url&&s.url(e.url),e.format&&s.format(e.format),e.pollingInterval&&s.pollingInterval(e.pollingInterval),e.maxRetries&&s.maxRetries(e.maxRetries),await s.convert()}}}class m{constructor(t){this.client=t,this._params={}}company(t){return this._params.com=t,this}trackingNumber(t){return this._params.num=t,this}phone(t){return this._params.phone=t,this}_validateParams(){if(!this._params.com)throw new Error("快递公司代码不能为空");if(!this._params.num)throw new Error("快递单号不能为空");if(("shunfeng"===this._params.com||"shunfengkuaiyun"===this._params.com)&&!this._params.phone)throw new Error("顺丰快递必须提供手机号参数")}async track(){return this._validateParams(),await this.client.request("/api/expressInquiry",{method:"POST",body:JSON.stringify({com:this._params.com,num:this._params.num,resultv2:4,...this._params.phone?{phone:this._params.phone}:{}})})}then(t,e){return this.track().then(t,e)}catch(t){return this.track().catch(t)}}function y(t){return{trackPackage:()=>new m(t)}}class g{static LOCATION_MAP={location:"/api/geocoder",address:"/api/geoaddress"};constructor(t,e){this.client=t,this._params={},this.type=e}latitude(t){return this._params.latitude=t,this}longitude(t){return this._params.longitude=t,this}address(t){return this._params.address=t,this}_validateLocationParams(){if(!this._params.latitude||!this._params.longitude)throw new Error("经纬度参数不能为空")}_validateAddressParams(){if(!this._params.address)throw new Error("地址参数不能为空")}_data(){return"location"===this.type?(this._validateLocationParams(),{location:`${this._params.latitude},${this._params.longitude}`}):(this._validateAddressParams(),{address:this._params.address})}async _execute(){const t=g.LOCATION_MAP[this.type],e=this._data();let s=await this.client.request(t,{method:"POST",body:JSON.stringify(e)}),r=s;return"data"in s&&"result"in s.data&&(r.result=s.data.result,r.result.latitude=s.data.result.location.lat,r.result.longitude=s.data.result.location.lng,r.status=s.data.status),r}then(t,e){this._execute().then(t,e)}}class _{constructor(t){this.client=t}async _execute(){const t=await this.client.request("/api/amap_ip_location",{method:"POST",body:JSON.stringify({})}),e=t?.data?.rectangle;if(!e)throw new Error("返回数据中缺少 rectangle 字段");const[s,r]=e.split(";"),[i,a]=s.split(",").map(Number),[n,o]=r.split(",").map(Number);return{success:!0,latitude:(a+o)/2,longitude:(i+n)/2,speed:0,altitude:0,horizontalAccuracy:1e3}}then(t,e){this._execute().then(t,e)}}class w{constructor(t){this.client=t,this._params={}}from(t,e){return this._params.from={lat:t,lng:e},this}to(t,e){return this._params.to={lat:t,lng:e},this}decodePolyline(t){for(let e=2;e<t.length;e++)t[e]=t[e-2]+t[e]/1e6;return t}async _execute(){const{from:t,to:e}=this._params;if(!t||!e)throw new Error("必须提供起点和终点坐标");const s={from:`${t.lat},${t.lng}`,to:`${e.lat},${e.lng}`},r=await this.client.request("/api/driving",{method:"POST",body:JSON.stringify(s)}),{routes:i}=r.data.result;return{success:!0,data:{paths:i.map(t=>{const e=this.decodePolyline([...t.polyline]),s=t.steps.map(t=>{const{polyline_idx:[s,r]}=t,i=[];for(let t=s;t<=r;t+=2)i.push({latitude:e[t],longitude:e[t+1]});return{...t,polylines:i}});return{distance:t.distance,duration:t.duration,steps:s}})}}}then(t,e){this._execute().then(t,e)}}class f{constructor(t){this.client=t,this._params={}}lat(t){return this._params.lat=t,this}lng(t){return this._params.lng=t,this}radius(t){return this._params.radius=t,this}keyword(t){return this._params.keyword=t,this}async _execute(){const{lat:t,lng:e,radius:s=1e3,keyword:r}=this._params;if(!t||!e)throw new Error("必须提供经纬度参数");const i={boundary:`nearby(${t},${e},${s})`,...r&&{keyword:r}},a=await this.client.request("/api/mapsearch",{method:"POST",body:JSON.stringify(i)}),{data:n}=a.data;return{success:!0,data:n.map(t=>({...t,latitude:t.location.lat,longitude:t.location.lng}))}}then(t,e){this._execute().then(t,e)}}function P(t){return{locationToAddress:()=>new g(t,"location"),addressToLocation:()=>new g(t,"address"),currentLocation:()=>new _(t),driving:()=>new w(t),nearby:()=>new f(t)}}class q{static API_MAP={train:"/api/queryTickets",flight:"/api/queryFlight"};constructor(t,e){this.client=t,this.params={},this.mode=e}from(t){return this.params.from=t,this}to(t){return this.params.to=t,this}date(t){return this.params.date=t,this}async _execute(){const t=q.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function S(t){return{train:()=>new q(t,"train"),flight:()=>new q(t,"flight")}}class b{static API_MAP={feishu:"/api/feishuRobotText",wechat:"/api/wechatRobotText"};constructor(t,e){this.client=t,this.params={},this.mode=e}content(t){return this.params.content=t?.replace(/\r?\n/g," "),this}async _execute(){const t=b.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}class A{constructor(t){this.client=t,this.payload={}}title(t){return this.payload.title=t,this}content(t){return this.payload.content=t?.replace(/\r?\n/g," "),this}to(t){return this.payload.to=t,this}params(t={}){return this.payload.params=t,this}async _execute(){return await this.client.request("/common/mail/send",{method:"POST",body:JSON.stringify(this.payload)})}then(t,e){this._execute().then(t,e)}}function x(t){return{feishuRobot:()=>new b(t,"feishu"),wechatRobot:()=>new b(t,"wechat"),mail:()=>new A(t)}}class T{static API_MAP={text2pic:"/api/word2pic",text2tts:"/api/text/tts"};constructor(t,e){this.client=t,this.params={model:"gemini-3-pro-image-preview"},this.mode=e}text(t){return this.params.text=t,this}model(t){return this.params.model=t,this}async _execute(){const t=T.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}class k{constructor(t){this.client=t}async uploadFile(t,e="mp3",s="audio/mpeg"){const r=await this.client.request("/common/uploadByUrl",{method:"POST",body:JSON.stringify({fileUrl:t,formatter:e,contentType:s})});return console.log("uploadFile response:",r),r}}class O extends k{constructor(t){super(t),this.params={}}text(t){return this.params.text=t,this}speaker(t){return this.params.speaker=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");let e=this.params.speaker;e&&""!==e||(e="zh_female_cancan_mars_bigtts");let s={text:t,speaker:e};const r=this.client.request("/api/ttsTask",{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");let s={taskId:e};return await this.client.request("/api/queryTts",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=await this.createTask();console.log("====TTS任务创建成功:====",t);const e=t.data.task_id;if(!e)throw new Error("任务创建失败,未返回任务ID");let s=0;for(;2!==s;){const t=await this.queryTask(e);if(s=t.data?.task_status||0,2===s){const e=await this.uploadFile(t.data.audio_url);return t.data=e.data,t}if(3===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}class I{constructor(t){this.client=t,this.params={}}text(t){return this.params.text=t,this}prompt(t){return this.params.prompt=t,this}conversationId(t){return this.params.conversationId=t,this}async _execute(){const{text:t,prompt:e="",conversationId:s=""}=this.params,r={prompt:e,query:t,conversation_id:s,user:this.client.getApiKey(),files:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(r)})}then(t,e){this._execute().then(t,e)}}class N extends I{constructor(t){super(t)}url(t){return this.params.url=t,this}async _execute(){const{url:t,prompt:e,text:s,conversationId:r=""}=this.params,i=[{type:"image",transfer_method:"remote_url",url:t}],a={prompt:e,query:s,conversation_id:r,user:this.client.getApiKey(),files:t?i:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(a)})}then(t,e){this._execute().then(t,e)}}class v extends k{static CREATE_API_MAP={video:"/api/text2video",audio:"/api/text2music"};static QUERY_API_MAP={video:"/api/queryVideo",audio:"/api/queryMusic"};constructor(t,e){super(t),this.params={},this.mode=e,this._taskId=null}text(t){return this.params.text=t,this}createTask(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");const e=v.CREATE_API_MAP[this.mode];let s={};s="video"===this.mode?{text:t}:{prompt:this.cleanString(t)};const r=this.client.request(e,{method:"POST",body:JSON.stringify(s)});return this._taskId=r.data,r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");const s=v.QUERY_API_MAP[this.mode];let r={};return r="video"===this.mode?{id:e}:{item_ids:e},await this.client.request(s,{method:"POST",body:JSON.stringify(r)})}async _execute(){const t=await this.createTask();console.log("任务创建成功:",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");let s="";for(;"succeeded"!==s;){const t=await this.queryTask(e);if(s=t.data?.status||"","succeeded"===s){if("video"===this.mode){const e=await this.uploadFile(t.data.content.video_url,"mp4","video/mp4");t.data.content.video_url=e.data}else{const e=await this.uploadFile(t.data.audio_url,"mp3","audio/mpeg");t.data.audio_url=e.data}return t}if("failed"===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){this._execute().then(t,e)}cleanString(t){return t?(t=(t=(t=t.toString()).replace(/[\n\r\t]+/g,",")).replace(/\s{2,}/g,",")).trim():t}}function M(t){return{textToImage:()=>new T(t,"text2pic"),textToSpeech:()=>new O(t),imageToText:()=>new N(t),chat:()=>new I(t),textToVideo:()=>new v(t,"video"),textToAudio:()=>new v(t,"audio")}}class C{static API_MAP={web:"/api/webSearch",video:"/api/webSearch",image:"/api/webSearch"};constructor(t,e){this.client=t,this._params={type:e,top_k:20,site:[]},this._type=e}content(t){return this._params.content=t,this}type(t){if(!C.API_MAP[t])throw new Error(`Unsupported search type: ${t}`);return this._type=t,this._params.type=t,this}site(t){return this._params.site||(this._params.site=[]),null==t||this._params.site.push(t),this}async _execute(){const t=C.API_MAP[this._type];return await this.client.request(t,{method:"POST",body:JSON.stringify(this._params)})}then(t,e){return this._execute().then(t,e)}}function J(t){return{search:()=>new C(t,"web"),webSearch:()=>new C(t,"web"),videoSearch:()=>new C(t,"video"),imageSearch:()=>new C(t,"image")}}const E=new class{constructor(){this.plugins=new Map,this.pluginModules=new Map}register(t,e){if(this.plugins.has(t))console.warn(`Plugin ${t} is already registered`);else{if(!this.validatePlugin(e))throw console.log(`Invalid plugin module for ${t}:`,{type:typeof e,value:e,constructor:e?.constructor?.name,keys:"object"==typeof e?Object.keys(e):"N/A"}),new Error(`Invalid plugin module structure for ${t}`);this.plugins.set(t,{name:t,module:e,initialized:!1}),console.log(`Plugin ${t} registered successfully`)}}validatePlugin(t){return null!=t&&("function"==typeof t||"object"==typeof t&&!Array.isArray(t))}init(t,e){const s=this.plugins.get(t);if(!s)throw new Error(`Plugin ${t} not found`);let r;if("function"!=typeof s.module&&"object"!=typeof s.module)throw new Error(`Invalid plugin module type for ${t}`);return r=s.module,s.initialized=!0,"function"==typeof r.init&&r.init(),r}getRegisteredPlugins(){return Array.from(this.plugins.keys())}isRegistered(t){return this.plugins.has(t)}unregister(t){this.plugins.has(t)&&(this.plugins.delete(t),console.log(`Plugin ${t} unregistered`))}};class B{constructor(t){this.client=t,this._params={}}interval(t){return this._params.interval=t,this}vsCurrency(t){return this._params.vsCurrency=t,this}days(t){return this._params.days=t,this}async query(){return await this.client.request("/api/historytrend",{method:"POST",body:JSON.stringify({interval:this._params.interval,vs_currency:this._params.vsCurrency,days:this._params.days})})}then(t,e){return this.query().then(t,e)}catch(t){return this.query().catch(t)}}function D(t){return{historytrend:()=>new B(t)}}class R{static API_MAP={googleSearch:"/api/googleSearch"};constructor(t){this.client=t,this.params={}}content(t){return this.params.content=t,this}num(t){return this.params.num=t,this}type(t){return this.params.type=t,this}async _execute(){const t=R.API_MAP.googleSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function $(t){return{search:()=>new R(t)}}class F{static API_MAP={list:"/api/queryToutiaoIndex",content:"/api/queryToutiaoContent",NewsByCategory:"/api/NewsByCategory",NewsByRegion:"/api/NewsByRegion"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}page(t){return this.params.page=t,this}page_size(t){return this.params.pageSize=t,this}is_filter(t){return this.params.isFilter=t,this}uniquekey(t){return this.params.uniquekey=t,this}category(t){return this.params.category=t,this}region(t){return this.params.region=t,this}async _execute(){const t=F.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function L(t){return{queryToutiaoIndex:()=>new F(t,"list"),queryToutiaoContent:()=>new F(t,"content"),queryNYNewsByCategory:()=>new F(t,"NewsByCategory"),queryNYNewsByRegion:()=>new F(t,"NewsByRegion")}}class W{static API_MAP={nationalWeather:"/api/nationalWeather",internationalWeather:"/api/weather"};constructor(t,e){this.client=t,this.mode=e,this.params={}}city(t){return"nationalWeather"!==this.mode&&console.warn("city 参数仅适用于 nationalWeather 模式"),this.params.city=t,this}latitude(t){return"internationalWeather"!==this.mode&&console.warn("latitude 参数仅适用于 internationalWeather 模式"),this.params["location.latitude"]=t,this}longitude(t){return"internationalWeather"!==this.mode&&console.warn("longitude 参数仅适用于 internationalWeather 模式"),this.params["location.longitude"]=t,this}async _execute(){this._validateParams();const t=W.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}_validateParams(){if("nationalWeather"===this.mode){if(!this.params.city)throw new Error("nationalWeather 模式需要提供 city 参数")}else if(!("internationalWeather"!==this.mode||this.params["location.latitude"]&&this.params["location.longitude"]))throw new Error("internationalWeather 模式需要提供 latitude 和 longitude 参数")}then(t,e){return this._execute().then(t,e)}}function z(t){return{queryNationalWeather:()=>new W(t,"nationalWeather"),queryWeather:()=>new W(t,"internationalWeather")}}class U{static API_MAP={frate:"/api/frate",rmbquot:"/api/rmbquot"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}bank(t){return this.params.bank=t,this}async _execute(){const t=U.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function j(t){return{frate:()=>new U(t,"frate"),rmbquot:()=>new U(t,"rmbquot")}}class G{static API_MAP={queryCaipu:"/api/queryCaipu",RandomRecipes:"/api/RandomRecipes",MealPlan:"/api/MealPlan"};constructor(t,e){this.client=t,this.params={},this.mode=e}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}tags(t){return this.params.tags=t,this}number(t){return this.params.number=t,this}timeFrame(t){return this.params.timeFrame=t,this}targetCalories(t){return this.params.targetCalories=t,this}diet(t){return this.params.diet=t,this}exclude(t){return this.params.exclude=t,this}async _execute(){const t=G.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function K(t){return{queryIngredients:()=>new G(t,"queryCaipu"),queryDishName:()=>new G(t,"queryCaipu"),query:()=>new G(t,"queryCaipu"),queryRandomRecipes:()=>new G(t,"RandomRecipes"),queryMealPlan:()=>new G(t,"MealPlan")}}class Y{static API_MAP={queryCarPrice:"/api/queryCarPrice"};constructor(t){this.client=t,this.params={}}search(t){return this.params.search=t,this}async _execute(){const t=Y.API_MAP.queryCarPrice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function H(t){return{query:()=>new Y(t)}}class Q{static API_MAP={queryDiseaseByName:"/api/queryDiseaseByName"};constructor(t){this.client=t,this.params={}}word(t){return this.params.word=t,this}async _execute(){const t=Q.API_MAP.queryDiseaseByName;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function V(t){return{query:()=>new Q(t)}}class X{static API_MAP={queryCalorie:"/api/queryCalorie"};constructor(t){this.client=t,this.params={}}sex(t){return this.params.sex=t,this}height(t){return this.params.height=t,this}weight(t){return this.params.weight=t,this}age(t){return this.params.age=t,this}level(t){return this.params.level=t,this}async _execute(){const t=X.API_MAP.queryCalorie;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function Z(t){return{query:()=>new X(t)}}class tt{static API_MAP={nationalGoldprice:"/api/nationalGoldprice"};constructor(t){this.client=t,this.params={}}async _execute(){const t=tt.API_MAP.nationalGoldprice;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function et(t){return{query:()=>new tt(t)}}class st{static API_MAP={youtubeSearch:"/api/youtubeSearch"};constructor(t){this.client=t,this.params={}}q(t){return this.params.q=t,this}type(t){return this.params.type=t,this}async _execute(){const t=st.API_MAP.youtubeSearch;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function rt(t){return{search:()=>new st(t)}}class it{static API_MAP={queryTimezone:"/api/timezone"};constructor(t){this.client=t,this.params={}}location(t){return this.params.location=t,this}timestamp(t){return this.params.timestamp=t,this}async _execute(){const t=it.API_MAP.queryTimezone;return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function at(t){return{search:()=>new it(t)}}class nt{static API_MAP={queryNationalScenic:"/api/queryNationalScenic",restaurantsSearch:"/api/restaurantsSearch",hotelsSearch:"/api/hotelsSearch",attractionSearch:"/api/attractionSearch"};constructor(t,e){this.client=t,this.params={},this.model=e}word(t){return this.params.word=t,this}num(t){return this.params.num=t,this}page(t){return this.params.page=t,this}province(t){return this.params.province=t,this}city(t){return this.params.city=t,this}query(t){return this.params.query=t,this}async _execute(){const t=nt.API_MAP[this.model];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ot(t){return{query:()=>new nt(t,"queryNationalScenic"),queryRestaurantsSearch:()=>new nt(t,"restaurantsSearch"),queryHotelsSearch:()=>new nt(t,"hotelsSearch"),queryAttractionSearch:()=>new nt(t,"attractionSearch")}}class ht{static API_MAP={queryFootballMatch:"/api/queryFootballMatch",footballRank:"/api/footballRank"};constructor(t,e){this.client=t,this.mode=e,this.params={}}type(t){return this.params.type=t,this}async _execute(){const t=ht.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function ct(t){return{match:()=>new ht(t,"queryFootballMatch"),rank:()=>new ht(t,"footballRank")}}class ut{static API_MAP={hsStock:"/api/hsStock",hkStock:"/api/hkStock",usaStock:"/api/usaStock",hkall:"/api/hkall",usaall:"/api/usaall",szall:"/api/szall",shall:"/api/shall",TimeDaily:"/api/TimeDaily",CurrencyExchange:"/api/CurrencyExchange",DigitalCurrencyDaily:"/api/DigitalCurrencyDaily",TechnicalIndicators:"/api/TechnicalIndicators"};constructor(t,e){this.client=t,this.mode=e,this.params={}}gid(t){return this.params.gid=t,this}type(t){return this.params.type=t,this}num(t){return this.params.num=t,this}stock(t){return this.params.stock=t,this}page(t){return this.params.page=t,this}symbol(t){return this.params.symbol=t,this}to_currency(t){return this.params.to_currency=t,this}from_currency(t){return this.params.from_currency=t,this}market(t){return this.params.market=t,this}time_period(t){return this.params.time_period=t,this}interval(t){return this.params.interval=t,this}series_type(t){return this.params.series_type=t,this}async _execute(){const t=ut.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){return this._execute().then(t,e)}}function lt(t){return{queryHs:()=>new ut(t,"hsStock"),queryHk:()=>new ut(t,"hkStock"),queryUsa:()=>new ut(t,"usaStock"),queryHkAll:()=>new ut(t,"hkall"),queryUsaAll:()=>new ut(t,"usaall"),querySzAll:()=>new ut(t,"szall"),queryShAll:()=>new ut(t,"shall"),queryTimeDaily:()=>new ut(t,"TimeDaily"),queryCurrencyExchange:()=>new ut(t,"CurrencyExchange"),queryDigitalCurrencyDaily:()=>new ut(t,"DigitalCurrencyDaily"),queryTechnicalIndicators:()=>new ut(t,"TechnicalIndicators")}}class pt{static API_MAP={SearchCocktail:"/api/SearchCocktail",ListPopularCocktails:"/api/ListPopularCocktails",ListMostLatestCocktails:"/api/ ListMostLatestCocktails",GetBeersDataByBreweryOrBrand:"/api/GetBeersDataByBreweryOrBrand",GetBeersDataByName:"/api/GetBeersDataByName"};constructor(t,e){this.client=t,this.params={},this.mode=e}s(t){return this.params.s=t,this}brewery(t){return this.params.brewery=t,this}name(t){return this.params.name=t,this}async _execute(){const t=pt.API_MAP[this.mode];return await this.client.request(t,{method:"POST",body:JSON.stringify(this.params)})}then(t,e){this._execute().then(t,e)}}function dt(t){return{queryCocktail:()=>new pt(t,"SearchCocktail"),queryPopularCocktails:()=>new pt(t,"ListPopularCocktails"),queryLatestCocktails:()=>new pt(t,"ListMostLatestCocktails"),queryBeersData:()=>new pt(t,"GetBeersDataByBreweryOrBrand"),queryBeersDataByName:()=>new pt(t,"GetBeersDataByName")}}function mt(t){const e=new s(t),i={setToken:t=>e.setToken(t),getToken:()=>e.getToken(),auth:r(e),db:o(e),api:c(e),comparison:l(e),document:d(e),logistics:y(e),location:P(e),travel:S(e),notification:x(e),ai:M(e),baidu:J(e),bitcoin:D(e),google:$(e),news:L(e),weather:z(e),money:j(e),caipu:K(e),car:H(e),disease:V(e),calorie:Z(e),goldprice:et(e),youtube:rt(e),timezone:at(e),scenic:ot(e),football:ct(e),stock:lt(e),wine:dt(e)};return E.getRegisteredPlugins().forEach(t=>{try{const s=E.init(t,e);i[t]?(console.warn(`Plugin "${t}" conflicts with built-in module. Merging plugin methods into existing module.`),Object.assign(i[t],s)):i[t]=s}catch(e){console.error(`Failed to load plugin ${t}:`,e)}}),i}export{mt as createClient,E as pluginLoader};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aipexbase-js",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",