aipexbase-js 1.1.21 → 1.1.22

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.
@@ -3038,29 +3038,37 @@
3038
3038
  }
3039
3039
  };
3040
3040
  this._taskId = null;
3041
+ console.log("🟢 VoiceRecognitionBuilder 初始化");
3041
3042
  }
3042
3043
 
3043
3044
  // 生成唯一 taskId
3044
3045
  _generateTaskId() {
3045
- return 'task-' + Date.now() + '-' + Math.random().toString(36).substring(2, 10);
3046
+ const id = 'task-' + Date.now() + '-' + Math.random().toString(36).substring(2, 10);
3047
+ console.log("🆔 生成 TaskId:", id);
3048
+ return id;
3046
3049
  }
3047
3050
  url(url) {
3051
+ console.log("📥 设置 audio.url =", url);
3048
3052
  this.params.audio.url = url;
3049
3053
  return this;
3050
3054
  }
3051
3055
  format(format) {
3056
+ console.log("📥 设置 audio.format =", format);
3052
3057
  this.params.audio.format = format;
3053
3058
  return this;
3054
3059
  }
3055
3060
  codec(codec) {
3061
+ console.log("📥 设置 audio.codec =", codec);
3056
3062
  this.params.audio.codec = codec;
3057
3063
  return this;
3058
3064
  }
3059
3065
  model(model_name) {
3066
+ console.log("📥 设置 model_name =", model_name);
3060
3067
  this.params.request.model_name = model_name;
3061
3068
  return this;
3062
3069
  }
3063
3070
  enableItn(enable) {
3071
+ console.log("📥 设置 enable_itn =", enable);
3064
3072
  this.params.request.enable_itn = enable;
3065
3073
  return this;
3066
3074
  }
@@ -3069,61 +3077,84 @@
3069
3077
  audio,
3070
3078
  request
3071
3079
  } = this.params;
3072
- if (!audio.url) throw new Error("音频 URL 不能为空");
3080
+ console.log("\n================= 📤 提交语音识别任务 =================");
3081
+ console.log("📦 Builder内部参数:");
3082
+ console.log(JSON.stringify(this.params, null, 2));
3083
+ if (!audio.url) {
3084
+ throw new Error("❌ 音频 URL 不能为空");
3085
+ }
3073
3086
  this._taskId = this._generateTaskId();
3074
- const url = VoiceRecognitionBuilder.API_MAP.submit;
3075
- const response = await this.client.request(url, {
3087
+
3088
+ // 按照后端模板要求,使用扁平化结构传递参数
3089
+ const body = {
3090
+ url: audio.url,
3091
+ // 直接使用 $url 变量
3092
+ format: audio.format,
3093
+ // 支持 $format 变量
3094
+ codec: audio.codec,
3095
+ // 支持 $codec 变量
3096
+ model_name: request.model_name,
3097
+ enable_itn: request.enable_itn,
3098
+ task_id: this._taskId
3099
+ };
3100
+ console.log("\n🌐 HTTP 请求地址:");
3101
+ console.log(VoiceRecognitionBuilder.API_MAP.submit);
3102
+ console.log("\n📨 HTTP 请求 Body:");
3103
+ console.log(JSON.stringify(body, null, 2));
3104
+ const response = await this.client.request(VoiceRecognitionBuilder.API_MAP.submit, {
3076
3105
  method: "POST",
3077
- body: JSON.stringify({
3078
- audio: audio,
3079
- request: request,
3080
- task_id: this._taskId
3081
- })
3106
+ body: JSON.stringify(body)
3082
3107
  });
3083
- console.log("====语音识别任务提交成功:====", response);
3084
- console.log("====TaskId:====", this._taskId);
3108
+ console.log("\n✅ 提交任务返回结果:");
3109
+ console.log(JSON.stringify(response, null, 2));
3110
+ console.log("🆔 TaskId:", this._taskId);
3085
3111
  return response;
3086
3112
  }
3087
3113
  async queryTask(taskId = null) {
3088
3114
  const id = taskId || this._taskId;
3089
3115
  if (!id) {
3090
- throw new Error('任务ID不能为空,请先提交任务');
3116
+ throw new Error('任务ID不能为空,请先提交任务');
3091
3117
  }
3092
- const url = VoiceRecognitionBuilder.API_MAP.query;
3093
- return await this.client.request(url, {
3118
+ console.log("\n================= 🔍 查询识别任务 =================");
3119
+ console.log("🆔 查询 TaskId:", id);
3120
+ const body = {
3121
+ task_id: id
3122
+ };
3123
+ console.log("📨 Query Body:");
3124
+ console.log(JSON.stringify(body, null, 2));
3125
+ const response = await this.client.request(VoiceRecognitionBuilder.API_MAP.query, {
3094
3126
  method: "POST",
3095
- body: JSON.stringify({
3096
- task_id: id
3097
- })
3127
+ body: JSON.stringify(body)
3098
3128
  });
3129
+ console.log("\n📩 Query 返回结果:");
3130
+ console.log(JSON.stringify(response, null, 2));
3131
+ return response;
3099
3132
  }
3100
3133
  async _execute() {
3101
- // 1. 提交任务
3134
+ console.log("\n🚀 开始执行语音识别流程");
3135
+
3136
+ // 1 提交任务
3102
3137
  await this.submitTask();
3103
3138
  const taskId = this._taskId;
3104
3139
  if (!taskId) {
3105
- throw new Error('任务提交失败,未获取到任务ID');
3140
+ throw new Error('任务提交失败,未获取到任务ID');
3106
3141
  }
3107
-
3108
- // 2. 轮询查询结果
3142
+ console.log("\n🔁 开始轮询识别结果...");
3109
3143
  while (true) {
3110
3144
  const queryRes = await this.queryTask(taskId);
3111
-
3112
- // 判断成功:有 result.text
3113
- const text = queryRes.data?.result?.text || queryRes.result?.text;
3145
+ const text = queryRes?.data?.result?.text || queryRes?.result?.text;
3114
3146
  if (text) {
3115
- console.log("====语音识别完成:====", queryRes);
3147
+ console.log("\n🎉 识别成功!");
3148
+ console.log("📝 识别文本:", text);
3116
3149
  return queryRes;
3117
3150
  }
3118
-
3119
- // 判断失败:有 error
3120
- const error = queryRes.data?.error || queryRes.error;
3151
+ const error = queryRes?.data?.error || queryRes?.error;
3121
3152
  if (error) {
3122
- console.log("====语音识别失败:====", queryRes);
3153
+ console.log("\n❌ 识别失败:");
3154
+ console.log(JSON.stringify(queryRes, null, 2));
3123
3155
  return queryRes;
3124
3156
  }
3125
-
3126
- // 等待 2 秒后继续查询
3157
+ console.log("⏳ 未完成,2秒后继续查询...\n");
3127
3158
  await new Promise(resolve => setTimeout(resolve, 2000));
3128
3159
  }
3129
3160
  }
@@ -3134,6 +3165,7 @@
3134
3165
  function voiceModule(client) {
3135
3166
  return {
3136
3167
  recognition() {
3168
+ console.log("🎤 创建 VoiceRecognitionBuilder");
3137
3169
  return new VoiceRecognitionBuilder(client);
3138
3170
  }
3139
3171
  };
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).aipexbase={})}(this,function(t){"use strict";const e={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")}}},s=async(t,e)=>(await fetch(t,e)).json();class r{constructor({baseUrl:t,apiKey:r,storage:a,request:i}){this.baseUrl=t,this.apiKey=r,this.storage=a||e,this.requestImpl=i||s}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||{}};return await this.requestImpl(s,{...e,headers:r})}}function a(t){return{async login({user_name:e,phone:s,email:r,password:a}={}){const i=e||s||r;if(!i)throw new Error("必须提供 user_name、phone 或 email 之一");if(!a)throw new Error("必须提供 password");const n=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:i,password:a})});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 n(this.client,this.table,"list")}page(){return new n(this.client,this.table,"page")}get(){return new n(this.client,this.table,"get")}insert(){return new o(this.client,this.table,"add")}update(){return new o(this.client,this.table,"update")}delete(){return new n(this.client,this.table,"delete")}}class n{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 n(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 o extends n{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 h(t){return{from:e=>new i(t,e)}}class u{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 u(t,e)}}class l{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(!l.API_MAP[t])throw new Error(`Unsupported comparison type: ${t}`);return this.type=t,this}async _execute(){const t=l.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 m(t){return{searchProduct:()=>new l(t,"search"),findLowestPrice:()=>new l(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 y{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 _(t){return{trackPackage:()=>new y(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 w{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(";"),[a,i]=s.split(",").map(Number),[n,o]=r.split(",").map(Number);return{success:!0,latitude:(i+o)/2,longitude:(a+n)/2,speed:0,altitude:0,horizontalAccuracy:1e3}}then(t,e){this._execute().then(t,e)}}class f{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:a}=r.data.result;return{success:!0,data:{paths:a.map(t=>{const e=this.decodePolyline([...t.polyline]),s=t.steps.map(t=>{const{polyline_idx:[s,r]}=t,a=[];for(let t=s;t<=r;t+=2)a.push({latitude:e[t],longitude:e[t+1]});return{...t,polylines:a}});return{distance:t.distance,duration:t.duration,steps:s}})}}}then(t,e){this._execute().then(t,e)}}class P{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 a={boundary:`nearby(${t},${e},${s})`,...r&&{keyword:r}};return{success:!0,data:(await this.client.request("/api/mapsearch",{method:"POST",body:JSON.stringify(a)})).data.map(t=>({...t,latitude:t.location.lat,longitude:t.location.lng}))}}then(t,e){this._execute().then(t,e)}}function q(t){return{locationToAddress:()=>new g(t,"location"),addressToLocation:()=>new g(t,"address"),currentLocation:()=>new w(t),driving:()=>new f(t),nearby:()=>new P(t)}}class T{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=T.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 T(t,"train"),flight:()=>new T(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 k{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 I(t){return{feishuRobot:()=>new b(t,"feishu"),wechatRobot:()=>new b(t,"wechat"),mail:()=>new k(t)}}class A{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}file(t){return this.params.files||(this.params.files=[]),this.params.files.push(t),this}files(t){return Array.isArray(t)||(t=[t]),this.params.files||(this.params.files=[]),this.params.files=this.params.files.concat(t),this}model(t){return this.params.model=t,this}async _execute(){const t=A.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 x{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 x{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 v{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 v{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,a=[{type:"image",transfer_method:"remote_url",url:t}],i={prompt:e,query:s,conversation_id:r,user:this.client.getApiKey(),files:t?a:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(i)})}then(t,e){this._execute().then(t,e)}}class M extends x{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=M.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=M.QUERY_API_MAP[this.mode];let r={};return r="video"===this.mode?{id:e}:{TaskID: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");if("video"===this.mode){let t="";for(;"succeeded"!==t;){const s=await this.queryTask(e);if(t=s.data?.status||"","succeeded"===t){const t=await this.uploadFile(s.data.content.video_url,"mp4","video/mp4");return s.data.content.video_url=t.data,s}if("failed"===t)return s;await new Promise(t=>setTimeout(t,2e3))}}else{let t=0;for(;2!==t;){const s=await this.queryTask(e);if(t=s.data?.Status||0,2===t){const t=await this.uploadFile(s.data.SongDetail.AudioUrl,"mp3","audio/mpeg");return s.data.SongDetail.AudioUrl=t.data,s}if(3===t)return s;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}}class E extends x{constructor(t,e){super(t),this.params={},this.mode=e,this.params.serverId="video"===e?0xb6540c7b88083:"frame"===e?7809632936052886:0x906a2f709413b}templateId(t){return this.params.templateId=t,this}serverId(t){return this.params.serverId=t,this}resourceList(t){return this.params.resourceList=t,this}createHuoshanTemplateTask(){const t=this.params.templateId,e=this.params.serverId,s=this.params.resourceList;if(!t||!e)throw new Error("模版Id或服务Id不能为空");if(s.length<1)throw new Error("图片不能为空");let r={templateId:t,serverId:e,resourceList:s};const a=this.client.request("/api/AIEffectsTemplateTask",{method:"POST",body:JSON.stringify(r)});return this._taskId=a.data,a}async queryHuoshanTemplateTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");let s={TaskId:e};return await this.client.request("/api/QueryAIEffectsTemplateTaskResult",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=await this.createHuoshanTemplateTask();console.log("====AI特效模版任务创建成功:====",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");let s=1e3;for(;0!==s;){const t=await this.queryHuoshanTemplateTask(e);if(s=t.data?.Code,0===s){let e="";return"video"!==this.mode&&"frame"!==this.mode||(e=await this.uploadFile(t.data.ResultUrl,"mp4","video/mp4")),"image"===this.mode&&(e=await this.uploadFile(t.data.ResultUrl,"png","image/png")),t.data.ResultUrl=e.data,t}if(2e3===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}class J extends x{constructor(t){super(t),this.params={},this.params.req_key="jimeng_t2i_v40",this.params.image_urls=[],this.params.scale=.5}image(t){return this.params.image_urls.push(t),this}scale(t){return this.params.scale=t,this}prompt(t){return this.params.prompt=t,this}createTask(){const{req_key:t,image_urls:e,prompt:s,scale:r}=this.params;let a={req_key:t,image_urls:e,prompt:s,scale:r};return this.client.request("/api/JMAI",{method:"POST",body:JSON.stringify(a)})}async queryTask(t){let e={req_key:"jimeng_t2i_v40",task_id:t};return await this.client.request("/api/JMAIQuery",{method:"POST",body:JSON.stringify(e)})}async _execute(){const t=(await this.createTask()).data.data.task_id;if(!t)throw new Error("任务创建失败,未返回任务ID");for(;;){const e=await this.queryTask(t),s=e?.data?.data?.status;if("done"===s){const t=await this.uploadFile(e.data.data.image_urls[0],"png","image/png");return e.data=t.data,e}await new Promise(t=>setTimeout(t,5e3))}}then(t,e){this._execute().then(t,e)}}class C extends x{constructor(t){super(t),this.params={},this.params.image_urls=[]}image(t){return this.params.image_urls.push(t),this}prompt(t){return this.params.prompt=t,this}_getTaskReqKey(){let t="";const e=this.params.image_urls.length;if(0===e)t="jimeng_t2v_v30";else if(1===e)t="jimeng_i2v_first_v30";else{if(2!==e)throw new Error("不支持超过2张图片");t="jimeng_i2v_first_tail_v30"}return t}createTask(t){let e={};if("jimeng_t2v_v30"===t)e={req_key:t,prompt:this.params.prompt};else if("jimeng_i2v_first_v30"===t)e={req_key:t,image_urls:this.params.image_urls,prompt:this.params.prompt};else{if("jimeng_i2v_first_tail_v30"!==t)throw new Error("不支持超过2张图片");e={req_key:t,image_urls:this.params.image_urls,prompt:this.params.prompt}}return this.client.request("/api/JMAI",{method:"POST",body:JSON.stringify(e)})}async queryTask(t,e){let s={req_key:t,task_id:e};return await this.client.request("/api/JMAIQuery",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=this._getTaskReqKey(),e=await this.createTask(t);console.log("==============",e);const s=e.data.data.task_id;if(!s)throw new Error("任务创建失败,未返回任务ID");for(;;){const e=await this.queryTask(t,s);if("done"===e.data.data.status){const t=await this.uploadFile(e.data.data.video_url,"mp4","video/mp4");return e.data=t.data,e}await new Promise(t=>setTimeout(t,2e3))}}then(t,e){this._execute().then(t,e)}}function D(t){return{textToImage:()=>new A(t,"text2pic"),textToSpeech:()=>new O(t),imageToText:()=>new N(t),chat:()=>new v(t),textToVideo:()=>new M(t,"video"),textToAudio:()=>new M(t,"audio"),imageToVideoEffect:()=>new E(t,"video"),imageToImageEffect:()=>new E(t,"image"),imageToVideoFrameEffect:()=>new E(t,"frame"),jmTextToImage:()=>new J(t),jmGenToVideo:()=>new C(t)}}class R{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(!R.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=R.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 B(t){return{search:()=>new R(t,"web"),webSearch:()=>new R(t,"web"),videoSearch:()=>new R(t,"video"),imageSearch:()=>new R(t,"image")}}const F=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 ${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 L(t){return{historytrend:()=>new $(t)}}class j{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=j.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 U(t){return{search:()=>new j(t)}}class W{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=W.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 W(t,"list"),queryToutiaoContent:()=>new W(t,"content"),queryNYNewsByCategory:()=>new W(t,"NewsByCategory"),queryNYNewsByRegion:()=>new W(t,"NewsByRegion")}}class G{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=G.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 K(t){return{queryNationalWeather:()=>new G(t,"nationalWeather"),queryWeather:()=>new G(t,"internationalWeather")}}class H{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=H.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 Q(t){return{frate:()=>new H(t,"frate"),rmbquot:()=>new H(t,"rmbquot")}}class V{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=V.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 Y(t){return{queryIngredients:()=>new V(t,"queryCaipu"),queryDishName:()=>new V(t,"queryCaipu"),query:()=>new V(t,"queryCaipu"),queryRandomRecipes:()=>new V(t,"RandomRecipes"),queryMealPlan:()=>new V(t,"MealPlan")}}class X{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=X.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 Z(t){return{query:()=>new X(t)}}class tt{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=tt.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 et(t){return{query:()=>new tt(t)}}class st{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=st.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 rt(t){return{query:()=>new st(t)}}class at{static API_MAP={nationalGoldprice:"/api/nationalGoldprice"};constructor(t){this.client=t,this.params={}}async _execute(){const t=at.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 it(t){return{query:()=>new at(t)}}class nt{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=nt.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 ot(t){return{search:()=>new nt(t)}}class ht{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=ht.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 ut(t){return{search:()=>new ht(t)}}class ct{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=ct.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 lt(t){return{query:()=>new ct(t,"queryNationalScenic"),queryRestaurantsSearch:()=>new ct(t,"restaurantsSearch"),queryHotelsSearch:()=>new ct(t,"hotelsSearch"),queryAttractionSearch:()=>new ct(t,"attractionSearch")}}class mt{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=mt.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 dt(t){return{match:()=>new mt(t,"queryFootballMatch"),rank:()=>new mt(t,"footballRank")}}class pt{static API_MAP={hsStock:"/api/hsStock",usaStock:"/api/usaStock",usaall:"/api/usaall",szall:"/api/szall",shall:"/api/shall"};constructor(t,e){this.client=t,this.mode=e,this.params={}}symbol(t){return this.params.gid=t,this}type(t){return this.params.type=t,this}stock(t){return this.params.stock=t,this}page(t){return this.params.page=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){return this._execute().then(t,e)}}function yt(t){return{queryHs:()=>new pt(t,"hsStock"),queryHk:()=>new gt(t,"hkStock"),queryUsa:()=>new pt(t,"usaStock"),queryHkAll:()=>new gt(t,"hkall"),queryUsaAll:()=>new pt(t,"usaall"),querySzAll:()=>new pt(t,"szall"),queryShAll:()=>new pt(t,"shall"),queryTimeDaily:()=>new _t(t,"TimeDaily"),queryCurrencyExchange:()=>new _t(t,"CurrencyExchange"),queryDigitalCurrencyDaily:()=>new _t(t,"DigitalCurrencyDaily"),queryTechnicalIndicators:()=>new _t(t,"TechnicalIndicators")}}class _t{static API_MAP={TimeDaily:"/api/TimeDaily",CurrencyExchange:"/api/CurrencyExchange",DigitalCurrencyDaily:"/api/DigitalCurrencyDaily",TechnicalIndicators:"/api/TechnicalIndicators"};constructor(t,e){this.client=t,this.mode=e,this.params={}}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=_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 gt{static API_MAP={hkStock:"/api/hkStock",hkall:"/api/hkall"};constructor(t,e){this.client=t,this.mode=e,this.params={}}symbol(t){return this.params.num=t,this}page(t){return this.params.page=t,this}async _execute(){const t=gt.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 wt{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=wt.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 ft(t){return{queryCocktail:()=>new wt(t,"SearchCocktail"),queryPopularCocktails:()=>new wt(t,"ListPopularCocktails"),queryLatestCocktails:()=>new wt(t,"ListMostLatestCocktails"),queryBeersData:()=>new wt(t,"GetBeersDataByBreweryOrBrand"),queryBeersDataByName:()=>new wt(t,"GetBeersDataByName")}}class Pt{constructor(t){this.client=t,this.params={}}userId(t){return this.params.userId=t,this}text(t){return this.params.text=t,this}putMessage(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");const e=this.params.userId;if(!e)throw new Error("用户不能为空");let s={userId:e,text:t};return this.client.request("/clawdbot/chat",{method:"POST",body:JSON.stringify(s)})}async getMessage(t){const e="/clawdbot/chat?messageId="+t;return await this.client.request(e,{method:"GET"})}async _execute(){const t=(await this.putMessage()).data;for(;;){const e=await this.getMessage(t);if(e.data.isComplete)return e;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}function qt(t){return{chat:()=>new Pt(t)}}class Tt{static API_MAP={submit:"/api/submitBigModelAudio",query:"/api/bigModelQuery"};constructor(t){this.client=t,this.params={audio:{},request:{model_name:"bigmodel",enable_itn:!0}},this._taskId=null}_generateTaskId(){return"task-"+Date.now()+"-"+Math.random().toString(36).substring(2,10)}url(t){return this.params.audio.url=t,this}format(t){return this.params.audio.format=t,this}codec(t){return this.params.audio.codec=t,this}model(t){return this.params.request.model_name=t,this}enableItn(t){return this.params.request.enable_itn=t,this}async submitTask(){const{audio:t,request:e}=this.params;if(!t.url)throw new Error("音频 URL 不能为空");this._taskId=this._generateTaskId();const s=Tt.API_MAP.submit,r=await this.client.request(s,{method:"POST",body:JSON.stringify({audio:t,request:e,task_id:this._taskId})});return console.log("====语音识别任务提交成功:====",r),console.log("====TaskId:====",this._taskId),r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先提交任务");const s=Tt.API_MAP.query;return await this.client.request(s,{method:"POST",body:JSON.stringify({task_id:e})})}async _execute(){await this.submitTask();const t=this._taskId;if(!t)throw new Error("任务提交失败,未获取到任务ID");for(;;){const e=await this.queryTask(t);if(e.data?.result?.text||e.result?.text)return console.log("====语音识别完成:====",e),e;if(e.data?.error||e.error)return console.log("====语音识别失败:====",e),e;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}function St(t){return{recognition:()=>new Tt(t)}}t.createClient=function(t){const e=new r(t),s={setToken:t=>e.setToken(t),getToken:()=>e.getToken(),auth:a(e),db:h(e),api:c(e),comparison:m(e),document:p(e),logistics:_(e),location:q(e),travel:S(e),notification:I(e),ai:D(e),baidu:B(e),bitcoin:L(e),google:U(e),news:z(e),weather:K(e),money:Q(e),caipu:Y(e),car:Z(e),disease:et(e),calorie:rt(e),goldprice:it(e),youtube:ot(e),timezone:ut(e),scenic:lt(e),football:dt(e),stock:yt(e),wine:ft(e),clawdbot:qt(e),voice:St(e)};return F.getRegisteredPlugins().forEach(t=>{try{const r=F.init(t,e);s[t]?(console.warn(`Plugin "${t}" conflicts with built-in module. Merging plugin methods into existing module.`),Object.assign(s[t],r)):s[t]=r}catch(e){console.error(`Failed to load plugin ${t}:`,e)}}),s},t.pluginLoader=F});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).aipexbase={})}(this,function(t){"use strict";const e={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")}}},s=async(t,e)=>(await fetch(t,e)).json();class r{constructor({baseUrl:t,apiKey:r,storage:a,request:i}){this.baseUrl=t,this.apiKey=r,this.storage=a||e,this.requestImpl=i||s}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||{}};return await this.requestImpl(s,{...e,headers:r})}}function a(t){return{async login({user_name:e,phone:s,email:r,password:a}={}){const i=e||s||r;if(!i)throw new Error("必须提供 user_name、phone 或 email 之一");if(!a)throw new Error("必须提供 password");const n=await t.request("/login/passwd",{method:"POST",body:JSON.stringify({phone:i,password:a})});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 n(this.client,this.table,"list")}page(){return new n(this.client,this.table,"page")}get(){return new n(this.client,this.table,"get")}insert(){return new o(this.client,this.table,"add")}update(){return new o(this.client,this.table,"update")}delete(){return new n(this.client,this.table,"delete")}}class n{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 n(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 o extends n{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 h(t){return{from:e=>new i(t,e)}}class c{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 u(t){return{call:e=>new c(t,e)}}class l{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(!l.API_MAP[t])throw new Error(`Unsupported comparison type: ${t}`);return this.type=t,this}async _execute(){const t=l.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 m(t){return{searchProduct:()=>new l(t,"search"),findLowestPrice:()=>new l(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 y{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 g(t){return{trackPackage:()=>new y(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 w{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(";"),[a,i]=s.split(",").map(Number),[n,o]=r.split(",").map(Number);return{success:!0,latitude:(i+o)/2,longitude:(a+n)/2,speed:0,altitude:0,horizontalAccuracy:1e3}}then(t,e){this._execute().then(t,e)}}class f{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:a}=r.data.result;return{success:!0,data:{paths:a.map(t=>{const e=this.decodePolyline([...t.polyline]),s=t.steps.map(t=>{const{polyline_idx:[s,r]}=t,a=[];for(let t=s;t<=r;t+=2)a.push({latitude:e[t],longitude:e[t+1]});return{...t,polylines:a}});return{distance:t.distance,duration:t.duration,steps:s}})}}}then(t,e){this._execute().then(t,e)}}class P{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 a={boundary:`nearby(${t},${e},${s})`,...r&&{keyword:r}};return{success:!0,data:(await this.client.request("/api/mapsearch",{method:"POST",body:JSON.stringify(a)})).data.map(t=>({...t,latitude:t.location.lat,longitude:t.location.lng}))}}then(t,e){this._execute().then(t,e)}}function q(t){return{locationToAddress:()=>new _(t,"location"),addressToLocation:()=>new _(t,"address"),currentLocation:()=>new w(t),driving:()=>new f(t),nearby:()=>new P(t)}}class T{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=T.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 T(t,"train"),flight:()=>new T(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 k{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 I(t){return{feishuRobot:()=>new b(t,"feishu"),wechatRobot:()=>new b(t,"wechat"),mail:()=>new k(t)}}class A{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}file(t){return this.params.files||(this.params.files=[]),this.params.files.push(t),this}files(t){return Array.isArray(t)||(t=[t]),this.params.files||(this.params.files=[]),this.params.files=this.params.files.concat(t),this}model(t){return this.params.model=t,this}async _execute(){const t=A.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 x{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 x{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 v{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 v{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,a=[{type:"image",transfer_method:"remote_url",url:t}],i={prompt:e,query:s,conversation_id:r,user:this.client.getApiKey(),files:t?a:[]};return await this.client.request("/api/AiAnalysis",{method:"POST",body:JSON.stringify(i)})}then(t,e){this._execute().then(t,e)}}class M extends x{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=M.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=M.QUERY_API_MAP[this.mode];let r={};return r="video"===this.mode?{id:e}:{TaskID: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");if("video"===this.mode){let t="";for(;"succeeded"!==t;){const s=await this.queryTask(e);if(t=s.data?.status||"","succeeded"===t){const t=await this.uploadFile(s.data.content.video_url,"mp4","video/mp4");return s.data.content.video_url=t.data,s}if("failed"===t)return s;await new Promise(t=>setTimeout(t,2e3))}}else{let t=0;for(;2!==t;){const s=await this.queryTask(e);if(t=s.data?.Status||0,2===t){const t=await this.uploadFile(s.data.SongDetail.AudioUrl,"mp3","audio/mpeg");return s.data.SongDetail.AudioUrl=t.data,s}if(3===t)return s;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}}class J extends x{constructor(t,e){super(t),this.params={},this.mode=e,this.params.serverId="video"===e?0xb6540c7b88083:"frame"===e?7809632936052886:0x906a2f709413b}templateId(t){return this.params.templateId=t,this}serverId(t){return this.params.serverId=t,this}resourceList(t){return this.params.resourceList=t,this}createHuoshanTemplateTask(){const t=this.params.templateId,e=this.params.serverId,s=this.params.resourceList;if(!t||!e)throw new Error("模版Id或服务Id不能为空");if(s.length<1)throw new Error("图片不能为空");let r={templateId:t,serverId:e,resourceList:s};const a=this.client.request("/api/AIEffectsTemplateTask",{method:"POST",body:JSON.stringify(r)});return this._taskId=a.data,a}async queryHuoshanTemplateTask(t=null){const e=t||this._taskId;if(!e)throw new Error("任务ID不能为空,请先创建任务");let s={TaskId:e};return await this.client.request("/api/QueryAIEffectsTemplateTaskResult",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=await this.createHuoshanTemplateTask();console.log("====AI特效模版任务创建成功:====",t);const e=t.data;if(!e)throw new Error("任务创建失败,未返回任务ID");let s=1e3;for(;0!==s;){const t=await this.queryHuoshanTemplateTask(e);if(s=t.data?.Code,0===s){let e="";return"video"!==this.mode&&"frame"!==this.mode||(e=await this.uploadFile(t.data.ResultUrl,"mp4","video/mp4")),"image"===this.mode&&(e=await this.uploadFile(t.data.ResultUrl,"png","image/png")),t.data.ResultUrl=e.data,t}if(2e3===s)return t;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}class E extends x{constructor(t){super(t),this.params={},this.params.req_key="jimeng_t2i_v40",this.params.image_urls=[],this.params.scale=.5}image(t){return this.params.image_urls.push(t),this}scale(t){return this.params.scale=t,this}prompt(t){return this.params.prompt=t,this}createTask(){const{req_key:t,image_urls:e,prompt:s,scale:r}=this.params;let a={req_key:t,image_urls:e,prompt:s,scale:r};return this.client.request("/api/JMAI",{method:"POST",body:JSON.stringify(a)})}async queryTask(t){let e={req_key:"jimeng_t2i_v40",task_id:t};return await this.client.request("/api/JMAIQuery",{method:"POST",body:JSON.stringify(e)})}async _execute(){const t=(await this.createTask()).data.data.task_id;if(!t)throw new Error("任务创建失败,未返回任务ID");for(;;){const e=await this.queryTask(t),s=e?.data?.data?.status;if("done"===s){const t=await this.uploadFile(e.data.data.image_urls[0],"png","image/png");return e.data=t.data,e}await new Promise(t=>setTimeout(t,5e3))}}then(t,e){this._execute().then(t,e)}}class C extends x{constructor(t){super(t),this.params={},this.params.image_urls=[]}image(t){return this.params.image_urls.push(t),this}prompt(t){return this.params.prompt=t,this}_getTaskReqKey(){let t="";const e=this.params.image_urls.length;if(0===e)t="jimeng_t2v_v30";else if(1===e)t="jimeng_i2v_first_v30";else{if(2!==e)throw new Error("不支持超过2张图片");t="jimeng_i2v_first_tail_v30"}return t}createTask(t){let e={};if("jimeng_t2v_v30"===t)e={req_key:t,prompt:this.params.prompt};else if("jimeng_i2v_first_v30"===t)e={req_key:t,image_urls:this.params.image_urls,prompt:this.params.prompt};else{if("jimeng_i2v_first_tail_v30"!==t)throw new Error("不支持超过2张图片");e={req_key:t,image_urls:this.params.image_urls,prompt:this.params.prompt}}return this.client.request("/api/JMAI",{method:"POST",body:JSON.stringify(e)})}async queryTask(t,e){let s={req_key:t,task_id:e};return await this.client.request("/api/JMAIQuery",{method:"POST",body:JSON.stringify(s)})}async _execute(){const t=this._getTaskReqKey(),e=await this.createTask(t);console.log("==============",e);const s=e.data.data.task_id;if(!s)throw new Error("任务创建失败,未返回任务ID");for(;;){const e=await this.queryTask(t,s);if("done"===e.data.data.status){const t=await this.uploadFile(e.data.data.video_url,"mp4","video/mp4");return e.data=t.data,e}await new Promise(t=>setTimeout(t,2e3))}}then(t,e){this._execute().then(t,e)}}function D(t){return{textToImage:()=>new A(t,"text2pic"),textToSpeech:()=>new O(t),imageToText:()=>new N(t),chat:()=>new v(t),textToVideo:()=>new M(t,"video"),textToAudio:()=>new M(t,"audio"),imageToVideoEffect:()=>new J(t,"video"),imageToImageEffect:()=>new J(t,"image"),imageToVideoFrameEffect:()=>new J(t,"frame"),jmTextToImage:()=>new E(t),jmGenToVideo:()=>new C(t)}}class R{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(!R.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=R.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 B(t){return{search:()=>new R(t,"web"),webSearch:()=>new R(t,"web"),videoSearch:()=>new R(t,"video"),imageSearch:()=>new R(t,"image")}}const F=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 ${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 L(t){return{historytrend:()=>new $(t)}}class j{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=j.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 U(t){return{search:()=>new j(t)}}class W{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=W.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 W(t,"list"),queryToutiaoContent:()=>new W(t,"content"),queryNYNewsByCategory:()=>new W(t,"NewsByCategory"),queryNYNewsByRegion:()=>new W(t,"NewsByRegion")}}class G{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=G.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 H(t){return{queryNationalWeather:()=>new G(t,"nationalWeather"),queryWeather:()=>new G(t,"internationalWeather")}}class K{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=K.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 Q(t){return{frate:()=>new K(t,"frate"),rmbquot:()=>new K(t,"rmbquot")}}class V{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=V.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 Y(t){return{queryIngredients:()=>new V(t,"queryCaipu"),queryDishName:()=>new V(t,"queryCaipu"),query:()=>new V(t,"queryCaipu"),queryRandomRecipes:()=>new V(t,"RandomRecipes"),queryMealPlan:()=>new V(t,"MealPlan")}}class X{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=X.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 Z(t){return{query:()=>new X(t)}}class tt{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=tt.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 et(t){return{query:()=>new tt(t)}}class st{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=st.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 rt(t){return{query:()=>new st(t)}}class at{static API_MAP={nationalGoldprice:"/api/nationalGoldprice"};constructor(t){this.client=t,this.params={}}async _execute(){const t=at.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 it(t){return{query:()=>new at(t)}}class nt{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=nt.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 ot(t){return{search:()=>new nt(t)}}class ht{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=ht.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 ct(t){return{search:()=>new ht(t)}}class ut{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=ut.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 lt(t){return{query:()=>new ut(t,"queryNationalScenic"),queryRestaurantsSearch:()=>new ut(t,"restaurantsSearch"),queryHotelsSearch:()=>new ut(t,"hotelsSearch"),queryAttractionSearch:()=>new ut(t,"attractionSearch")}}class mt{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=mt.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 dt(t){return{match:()=>new mt(t,"queryFootballMatch"),rank:()=>new mt(t,"footballRank")}}class pt{static API_MAP={hsStock:"/api/hsStock",usaStock:"/api/usaStock",usaall:"/api/usaall",szall:"/api/szall",shall:"/api/shall"};constructor(t,e){this.client=t,this.mode=e,this.params={}}symbol(t){return this.params.gid=t,this}type(t){return this.params.type=t,this}stock(t){return this.params.stock=t,this}page(t){return this.params.page=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){return this._execute().then(t,e)}}function yt(t){return{queryHs:()=>new pt(t,"hsStock"),queryHk:()=>new _t(t,"hkStock"),queryUsa:()=>new pt(t,"usaStock"),queryHkAll:()=>new _t(t,"hkall"),queryUsaAll:()=>new pt(t,"usaall"),querySzAll:()=>new pt(t,"szall"),queryShAll:()=>new pt(t,"shall"),queryTimeDaily:()=>new gt(t,"TimeDaily"),queryCurrencyExchange:()=>new gt(t,"CurrencyExchange"),queryDigitalCurrencyDaily:()=>new gt(t,"DigitalCurrencyDaily"),queryTechnicalIndicators:()=>new gt(t,"TechnicalIndicators")}}class gt{static API_MAP={TimeDaily:"/api/TimeDaily",CurrencyExchange:"/api/CurrencyExchange",DigitalCurrencyDaily:"/api/DigitalCurrencyDaily",TechnicalIndicators:"/api/TechnicalIndicators"};constructor(t,e){this.client=t,this.mode=e,this.params={}}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=gt.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 _t{static API_MAP={hkStock:"/api/hkStock",hkall:"/api/hkall"};constructor(t,e){this.client=t,this.mode=e,this.params={}}symbol(t){return this.params.num=t,this}page(t){return this.params.page=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 wt{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=wt.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 ft(t){return{queryCocktail:()=>new wt(t,"SearchCocktail"),queryPopularCocktails:()=>new wt(t,"ListPopularCocktails"),queryLatestCocktails:()=>new wt(t,"ListMostLatestCocktails"),queryBeersData:()=>new wt(t,"GetBeersDataByBreweryOrBrand"),queryBeersDataByName:()=>new wt(t,"GetBeersDataByName")}}class Pt{constructor(t){this.client=t,this.params={}}userId(t){return this.params.userId=t,this}text(t){return this.params.text=t,this}putMessage(){const t=this.params.text;if(!t)throw new Error("文本内容不能为空");const e=this.params.userId;if(!e)throw new Error("用户不能为空");let s={userId:e,text:t};return this.client.request("/clawdbot/chat",{method:"POST",body:JSON.stringify(s)})}async getMessage(t){const e="/clawdbot/chat?messageId="+t;return await this.client.request(e,{method:"GET"})}async _execute(){const t=(await this.putMessage()).data;for(;;){const e=await this.getMessage(t);if(e.data.isComplete)return e;await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}function qt(t){return{chat:()=>new Pt(t)}}class Tt{static API_MAP={submit:"/api/submitBigModelAudio",query:"/api/bigModelQuery"};constructor(t){this.client=t,this.params={audio:{},request:{model_name:"bigmodel",enable_itn:!0}},this._taskId=null,console.log("🟢 VoiceRecognitionBuilder 初始化")}_generateTaskId(){const t="task-"+Date.now()+"-"+Math.random().toString(36).substring(2,10);return console.log("🆔 生成 TaskId:",t),t}url(t){return console.log("📥 设置 audio.url =",t),this.params.audio.url=t,this}format(t){return console.log("📥 设置 audio.format =",t),this.params.audio.format=t,this}codec(t){return console.log("📥 设置 audio.codec =",t),this.params.audio.codec=t,this}model(t){return console.log("📥 设置 model_name =",t),this.params.request.model_name=t,this}enableItn(t){return console.log("📥 设置 enable_itn =",t),this.params.request.enable_itn=t,this}async submitTask(){const{audio:t,request:e}=this.params;if(console.log("\n================= 📤 提交语音识别任务 ================="),console.log("📦 Builder内部参数:"),console.log(JSON.stringify(this.params,null,2)),!t.url)throw new Error("❌ 音频 URL 不能为空");this._taskId=this._generateTaskId();const s={url:t.url,format:t.format,codec:t.codec,model_name:e.model_name,enable_itn:e.enable_itn,task_id:this._taskId};console.log("\n🌐 HTTP 请求地址:"),console.log(Tt.API_MAP.submit),console.log("\n📨 HTTP 请求 Body:"),console.log(JSON.stringify(s,null,2));const r=await this.client.request(Tt.API_MAP.submit,{method:"POST",body:JSON.stringify(s)});return console.log("\n✅ 提交任务返回结果:"),console.log(JSON.stringify(r,null,2)),console.log("🆔 TaskId:",this._taskId),r}async queryTask(t=null){const e=t||this._taskId;if(!e)throw new Error("❌ 任务ID不能为空,请先提交任务");console.log("\n================= 🔍 查询识别任务 ================="),console.log("🆔 查询 TaskId:",e);const s={task_id:e};console.log("📨 Query Body:"),console.log(JSON.stringify(s,null,2));const r=await this.client.request(Tt.API_MAP.query,{method:"POST",body:JSON.stringify(s)});return console.log("\n📩 Query 返回结果:"),console.log(JSON.stringify(r,null,2)),r}async _execute(){console.log("\n🚀 开始执行语音识别流程"),await this.submitTask();const t=this._taskId;if(!t)throw new Error("❌ 任务提交失败,未获取到任务ID");for(console.log("\n🔁 开始轮询识别结果...");;){const e=await this.queryTask(t),s=e?.data?.result?.text||e?.result?.text;if(s)return console.log("\n🎉 识别成功!"),console.log("📝 识别文本:",s),e;if(e?.data?.error||e?.error)return console.log("\n❌ 识别失败:"),console.log(JSON.stringify(e,null,2)),e;console.log("⏳ 未完成,2秒后继续查询...\n"),await new Promise(t=>setTimeout(t,2e3))}}then(t,e){return this._execute().then(t,e)}}function St(t){return{recognition:()=>(console.log("🎤 创建 VoiceRecognitionBuilder"),new Tt(t))}}t.createClient=function(t){const e=new r(t),s={setToken:t=>e.setToken(t),getToken:()=>e.getToken(),auth:a(e),db:h(e),api:u(e),comparison:m(e),document:p(e),logistics:g(e),location:q(e),travel:S(e),notification:I(e),ai:D(e),baidu:B(e),bitcoin:L(e),google:U(e),news:z(e),weather:H(e),money:Q(e),caipu:Y(e),car:Z(e),disease:et(e),calorie:rt(e),goldprice:it(e),youtube:ot(e),timezone:ct(e),scenic:lt(e),football:dt(e),stock:yt(e),wine:ft(e),clawdbot:qt(e),voice:St(e)};return F.getRegisteredPlugins().forEach(t=>{try{const r=F.init(t,e);s[t]?(console.warn(`Plugin "${t}" conflicts with built-in module. Merging plugin methods into existing module.`),Object.assign(s[t],r)):s[t]=r}catch(e){console.error(`Failed to load plugin ${t}:`,e)}}),s},t.pluginLoader=F});
package/dist/index.cjs.js CHANGED
@@ -3034,29 +3034,37 @@ class VoiceRecognitionBuilder {
3034
3034
  }
3035
3035
  };
3036
3036
  this._taskId = null;
3037
+ console.log("🟢 VoiceRecognitionBuilder 初始化");
3037
3038
  }
3038
3039
 
3039
3040
  // 生成唯一 taskId
3040
3041
  _generateTaskId() {
3041
- return 'task-' + Date.now() + '-' + Math.random().toString(36).substring(2, 10);
3042
+ const id = 'task-' + Date.now() + '-' + Math.random().toString(36).substring(2, 10);
3043
+ console.log("🆔 生成 TaskId:", id);
3044
+ return id;
3042
3045
  }
3043
3046
  url(url) {
3047
+ console.log("📥 设置 audio.url =", url);
3044
3048
  this.params.audio.url = url;
3045
3049
  return this;
3046
3050
  }
3047
3051
  format(format) {
3052
+ console.log("📥 设置 audio.format =", format);
3048
3053
  this.params.audio.format = format;
3049
3054
  return this;
3050
3055
  }
3051
3056
  codec(codec) {
3057
+ console.log("📥 设置 audio.codec =", codec);
3052
3058
  this.params.audio.codec = codec;
3053
3059
  return this;
3054
3060
  }
3055
3061
  model(model_name) {
3062
+ console.log("📥 设置 model_name =", model_name);
3056
3063
  this.params.request.model_name = model_name;
3057
3064
  return this;
3058
3065
  }
3059
3066
  enableItn(enable) {
3067
+ console.log("📥 设置 enable_itn =", enable);
3060
3068
  this.params.request.enable_itn = enable;
3061
3069
  return this;
3062
3070
  }
@@ -3065,61 +3073,84 @@ class VoiceRecognitionBuilder {
3065
3073
  audio,
3066
3074
  request
3067
3075
  } = this.params;
3068
- if (!audio.url) throw new Error("音频 URL 不能为空");
3076
+ console.log("\n================= 📤 提交语音识别任务 =================");
3077
+ console.log("📦 Builder内部参数:");
3078
+ console.log(JSON.stringify(this.params, null, 2));
3079
+ if (!audio.url) {
3080
+ throw new Error("❌ 音频 URL 不能为空");
3081
+ }
3069
3082
  this._taskId = this._generateTaskId();
3070
- const url = VoiceRecognitionBuilder.API_MAP.submit;
3071
- const response = await this.client.request(url, {
3083
+
3084
+ // 按照后端模板要求,使用扁平化结构传递参数
3085
+ const body = {
3086
+ url: audio.url,
3087
+ // 直接使用 $url 变量
3088
+ format: audio.format,
3089
+ // 支持 $format 变量
3090
+ codec: audio.codec,
3091
+ // 支持 $codec 变量
3092
+ model_name: request.model_name,
3093
+ enable_itn: request.enable_itn,
3094
+ task_id: this._taskId
3095
+ };
3096
+ console.log("\n🌐 HTTP 请求地址:");
3097
+ console.log(VoiceRecognitionBuilder.API_MAP.submit);
3098
+ console.log("\n📨 HTTP 请求 Body:");
3099
+ console.log(JSON.stringify(body, null, 2));
3100
+ const response = await this.client.request(VoiceRecognitionBuilder.API_MAP.submit, {
3072
3101
  method: "POST",
3073
- body: JSON.stringify({
3074
- audio: audio,
3075
- request: request,
3076
- task_id: this._taskId
3077
- })
3102
+ body: JSON.stringify(body)
3078
3103
  });
3079
- console.log("====语音识别任务提交成功:====", response);
3080
- console.log("====TaskId:====", this._taskId);
3104
+ console.log("\n✅ 提交任务返回结果:");
3105
+ console.log(JSON.stringify(response, null, 2));
3106
+ console.log("🆔 TaskId:", this._taskId);
3081
3107
  return response;
3082
3108
  }
3083
3109
  async queryTask(taskId = null) {
3084
3110
  const id = taskId || this._taskId;
3085
3111
  if (!id) {
3086
- throw new Error('任务ID不能为空,请先提交任务');
3112
+ throw new Error('任务ID不能为空,请先提交任务');
3087
3113
  }
3088
- const url = VoiceRecognitionBuilder.API_MAP.query;
3089
- return await this.client.request(url, {
3114
+ console.log("\n================= 🔍 查询识别任务 =================");
3115
+ console.log("🆔 查询 TaskId:", id);
3116
+ const body = {
3117
+ task_id: id
3118
+ };
3119
+ console.log("📨 Query Body:");
3120
+ console.log(JSON.stringify(body, null, 2));
3121
+ const response = await this.client.request(VoiceRecognitionBuilder.API_MAP.query, {
3090
3122
  method: "POST",
3091
- body: JSON.stringify({
3092
- task_id: id
3093
- })
3123
+ body: JSON.stringify(body)
3094
3124
  });
3125
+ console.log("\n📩 Query 返回结果:");
3126
+ console.log(JSON.stringify(response, null, 2));
3127
+ return response;
3095
3128
  }
3096
3129
  async _execute() {
3097
- // 1. 提交任务
3130
+ console.log("\n🚀 开始执行语音识别流程");
3131
+
3132
+ // 1 提交任务
3098
3133
  await this.submitTask();
3099
3134
  const taskId = this._taskId;
3100
3135
  if (!taskId) {
3101
- throw new Error('任务提交失败,未获取到任务ID');
3136
+ throw new Error('任务提交失败,未获取到任务ID');
3102
3137
  }
3103
-
3104
- // 2. 轮询查询结果
3138
+ console.log("\n🔁 开始轮询识别结果...");
3105
3139
  while (true) {
3106
3140
  const queryRes = await this.queryTask(taskId);
3107
-
3108
- // 判断成功:有 result.text
3109
- const text = queryRes.data?.result?.text || queryRes.result?.text;
3141
+ const text = queryRes?.data?.result?.text || queryRes?.result?.text;
3110
3142
  if (text) {
3111
- console.log("====语音识别完成:====", queryRes);
3143
+ console.log("\n🎉 识别成功!");
3144
+ console.log("📝 识别文本:", text);
3112
3145
  return queryRes;
3113
3146
  }
3114
-
3115
- // 判断失败:有 error
3116
- const error = queryRes.data?.error || queryRes.error;
3147
+ const error = queryRes?.data?.error || queryRes?.error;
3117
3148
  if (error) {
3118
- console.log("====语音识别失败:====", queryRes);
3149
+ console.log("\n❌ 识别失败:");
3150
+ console.log(JSON.stringify(queryRes, null, 2));
3119
3151
  return queryRes;
3120
3152
  }
3121
-
3122
- // 等待 2 秒后继续查询
3153
+ console.log("⏳ 未完成,2秒后继续查询...\n");
3123
3154
  await new Promise(resolve => setTimeout(resolve, 2000));
3124
3155
  }
3125
3156
  }
@@ -3130,6 +3161,7 @@ class VoiceRecognitionBuilder {
3130
3161
  function voiceModule(client) {
3131
3162
  return {
3132
3163
  recognition() {
3164
+ console.log("🎤 创建 VoiceRecognitionBuilder");
3133
3165
  return new VoiceRecognitionBuilder(client);
3134
3166
  }
3135
3167
  };
package/dist/index.esm.js CHANGED
@@ -3032,29 +3032,37 @@ class VoiceRecognitionBuilder {
3032
3032
  }
3033
3033
  };
3034
3034
  this._taskId = null;
3035
+ console.log("🟢 VoiceRecognitionBuilder 初始化");
3035
3036
  }
3036
3037
 
3037
3038
  // 生成唯一 taskId
3038
3039
  _generateTaskId() {
3039
- return 'task-' + Date.now() + '-' + Math.random().toString(36).substring(2, 10);
3040
+ const id = 'task-' + Date.now() + '-' + Math.random().toString(36).substring(2, 10);
3041
+ console.log("🆔 生成 TaskId:", id);
3042
+ return id;
3040
3043
  }
3041
3044
  url(url) {
3045
+ console.log("📥 设置 audio.url =", url);
3042
3046
  this.params.audio.url = url;
3043
3047
  return this;
3044
3048
  }
3045
3049
  format(format) {
3050
+ console.log("📥 设置 audio.format =", format);
3046
3051
  this.params.audio.format = format;
3047
3052
  return this;
3048
3053
  }
3049
3054
  codec(codec) {
3055
+ console.log("📥 设置 audio.codec =", codec);
3050
3056
  this.params.audio.codec = codec;
3051
3057
  return this;
3052
3058
  }
3053
3059
  model(model_name) {
3060
+ console.log("📥 设置 model_name =", model_name);
3054
3061
  this.params.request.model_name = model_name;
3055
3062
  return this;
3056
3063
  }
3057
3064
  enableItn(enable) {
3065
+ console.log("📥 设置 enable_itn =", enable);
3058
3066
  this.params.request.enable_itn = enable;
3059
3067
  return this;
3060
3068
  }
@@ -3063,61 +3071,84 @@ class VoiceRecognitionBuilder {
3063
3071
  audio,
3064
3072
  request
3065
3073
  } = this.params;
3066
- if (!audio.url) throw new Error("音频 URL 不能为空");
3074
+ console.log("\n================= 📤 提交语音识别任务 =================");
3075
+ console.log("📦 Builder内部参数:");
3076
+ console.log(JSON.stringify(this.params, null, 2));
3077
+ if (!audio.url) {
3078
+ throw new Error("❌ 音频 URL 不能为空");
3079
+ }
3067
3080
  this._taskId = this._generateTaskId();
3068
- const url = VoiceRecognitionBuilder.API_MAP.submit;
3069
- const response = await this.client.request(url, {
3081
+
3082
+ // 按照后端模板要求,使用扁平化结构传递参数
3083
+ const body = {
3084
+ url: audio.url,
3085
+ // 直接使用 $url 变量
3086
+ format: audio.format,
3087
+ // 支持 $format 变量
3088
+ codec: audio.codec,
3089
+ // 支持 $codec 变量
3090
+ model_name: request.model_name,
3091
+ enable_itn: request.enable_itn,
3092
+ task_id: this._taskId
3093
+ };
3094
+ console.log("\n🌐 HTTP 请求地址:");
3095
+ console.log(VoiceRecognitionBuilder.API_MAP.submit);
3096
+ console.log("\n📨 HTTP 请求 Body:");
3097
+ console.log(JSON.stringify(body, null, 2));
3098
+ const response = await this.client.request(VoiceRecognitionBuilder.API_MAP.submit, {
3070
3099
  method: "POST",
3071
- body: JSON.stringify({
3072
- audio: audio,
3073
- request: request,
3074
- task_id: this._taskId
3075
- })
3100
+ body: JSON.stringify(body)
3076
3101
  });
3077
- console.log("====语音识别任务提交成功:====", response);
3078
- console.log("====TaskId:====", this._taskId);
3102
+ console.log("\n✅ 提交任务返回结果:");
3103
+ console.log(JSON.stringify(response, null, 2));
3104
+ console.log("🆔 TaskId:", this._taskId);
3079
3105
  return response;
3080
3106
  }
3081
3107
  async queryTask(taskId = null) {
3082
3108
  const id = taskId || this._taskId;
3083
3109
  if (!id) {
3084
- throw new Error('任务ID不能为空,请先提交任务');
3110
+ throw new Error('任务ID不能为空,请先提交任务');
3085
3111
  }
3086
- const url = VoiceRecognitionBuilder.API_MAP.query;
3087
- return await this.client.request(url, {
3112
+ console.log("\n================= 🔍 查询识别任务 =================");
3113
+ console.log("🆔 查询 TaskId:", id);
3114
+ const body = {
3115
+ task_id: id
3116
+ };
3117
+ console.log("📨 Query Body:");
3118
+ console.log(JSON.stringify(body, null, 2));
3119
+ const response = await this.client.request(VoiceRecognitionBuilder.API_MAP.query, {
3088
3120
  method: "POST",
3089
- body: JSON.stringify({
3090
- task_id: id
3091
- })
3121
+ body: JSON.stringify(body)
3092
3122
  });
3123
+ console.log("\n📩 Query 返回结果:");
3124
+ console.log(JSON.stringify(response, null, 2));
3125
+ return response;
3093
3126
  }
3094
3127
  async _execute() {
3095
- // 1. 提交任务
3128
+ console.log("\n🚀 开始执行语音识别流程");
3129
+
3130
+ // 1 提交任务
3096
3131
  await this.submitTask();
3097
3132
  const taskId = this._taskId;
3098
3133
  if (!taskId) {
3099
- throw new Error('任务提交失败,未获取到任务ID');
3134
+ throw new Error('任务提交失败,未获取到任务ID');
3100
3135
  }
3101
-
3102
- // 2. 轮询查询结果
3136
+ console.log("\n🔁 开始轮询识别结果...");
3103
3137
  while (true) {
3104
3138
  const queryRes = await this.queryTask(taskId);
3105
-
3106
- // 判断成功:有 result.text
3107
- const text = queryRes.data?.result?.text || queryRes.result?.text;
3139
+ const text = queryRes?.data?.result?.text || queryRes?.result?.text;
3108
3140
  if (text) {
3109
- console.log("====语音识别完成:====", queryRes);
3141
+ console.log("\n🎉 识别成功!");
3142
+ console.log("📝 识别文本:", text);
3110
3143
  return queryRes;
3111
3144
  }
3112
-
3113
- // 判断失败:有 error
3114
- const error = queryRes.data?.error || queryRes.error;
3145
+ const error = queryRes?.data?.error || queryRes?.error;
3115
3146
  if (error) {
3116
- console.log("====语音识别失败:====", queryRes);
3147
+ console.log("\n❌ 识别失败:");
3148
+ console.log(JSON.stringify(queryRes, null, 2));
3117
3149
  return queryRes;
3118
3150
  }
3119
-
3120
- // 等待 2 秒后继续查询
3151
+ console.log("⏳ 未完成,2秒后继续查询...\n");
3121
3152
  await new Promise(resolve => setTimeout(resolve, 2000));
3122
3153
  }
3123
3154
  }
@@ -3128,6 +3159,7 @@ class VoiceRecognitionBuilder {
3128
3159
  function voiceModule(client) {
3129
3160
  return {
3130
3161
  recognition() {
3162
+ console.log("🎤 创建 VoiceRecognitionBuilder");
3131
3163
  return new VoiceRecognitionBuilder(client);
3132
3164
  }
3133
3165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aipexbase-js",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",