@wzyjs/utils 0.3.10 → 0.3.16

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.
@@ -1,4 +1,7 @@
1
- import { Option } from '@wzyjs/types';
1
+ interface Option {
2
+ label: string;
3
+ value: string;
4
+ }
2
5
  export declare const options2valueEnum: (options: string[]) => {
3
6
  [key: string]: {
4
7
  text: string;
@@ -9,3 +12,4 @@ export declare const getColumns: (dataSource: any) => {
9
12
  title: string;
10
13
  dataIndex: string;
11
14
  }[];
15
+ export {};
package/dist/web.cjs.js CHANGED
@@ -10082,16 +10082,26 @@ var require_isoWeek = __commonJS((exports2, module2) => {
10082
10082
 
10083
10083
  // ../../node_modules/dayjs/plugin/updateLocale.js
10084
10084
  var require_updateLocale = __commonJS((exports2, module2) => {
10085
- (function(e, n) {
10086
- typeof exports2 == "object" && typeof module2 != "undefined" ? module2.exports = n() : typeof define == "function" && define.amd ? define(n) : (e = typeof globalThis != "undefined" ? globalThis : e || self).dayjs_plugin_updateLocale = n();
10085
+ (function(e, t) {
10086
+ typeof exports2 == "object" && typeof module2 != "undefined" ? module2.exports = t() : typeof define == "function" && define.amd ? define(t) : (e = typeof globalThis != "undefined" ? globalThis : e || self).dayjs_plugin_updateLocale = t();
10087
10087
  })(exports2, function() {
10088
- return function(e, n, t) {
10089
- t.updateLocale = function(e2, n2) {
10090
- var o = t.Ls[e2];
10091
- if (o)
10092
- return (n2 ? Object.keys(n2) : []).forEach(function(e3) {
10093
- o[e3] = n2[e3];
10094
- }), o;
10088
+ function e() {
10089
+ return e = Object.assign || function(e2) {
10090
+ for (var t = 1;t < arguments.length; t++) {
10091
+ var n = arguments[t];
10092
+ for (var o in n)
10093
+ Object.prototype.hasOwnProperty.call(n, o) && (e2[o] = n[o]);
10094
+ }
10095
+ return e2;
10096
+ }, e.apply(this, arguments);
10097
+ }
10098
+ return function(t, n, o) {
10099
+ o.updateLocale = function(t2, n2) {
10100
+ var r = o.Ls[t2];
10101
+ if (r)
10102
+ return (n2 ? Object.keys(n2) : []).forEach(function(t3) {
10103
+ r[t3] && n2[t3] && typeof r[t3] == "object" && typeof n2[t3] == "object" && !Array.isArray(r[t3]) ? r[t3] = e({}, r[t3], n2[t3]) : r[t3] = n2[t3];
10104
+ }), r;
10095
10105
  };
10096
10106
  };
10097
10107
  });
@@ -18272,8 +18282,9 @@ var import_copy_to_clipboard = __toESM(require_copy_to_clipboard());
18272
18282
  // src/common/ai/index.ts
18273
18283
  var exports_ai = {};
18274
18284
  __export(exports_ai, {
18275
- video: () => exports_video,
18276
18285
  text: () => exports_text,
18286
+ keling: () => exports_keling,
18287
+ doubao: () => exports_doubao,
18277
18288
  ai302: () => exports_302
18278
18289
  });
18279
18290
 
@@ -18308,27 +18319,237 @@ var chat = async (message, model = "gpt-4.1", isParse = true) => {
18308
18319
  console.log(666, typeof data, data);
18309
18320
  const output = typeof data === "string" ? import_json5.default.parse(data)?.output : data?.output;
18310
18321
  if (isParse) {
18311
- const match = /```(json)?(.*)```/s.exec(output);
18312
- if (!match) {
18313
- return import_json5.default.parse(output);
18314
- } else {
18315
- return import_json5.default.parse(match[2]);
18316
- }
18322
+ const cleanOutput = output.replace(/<think>[\s\S]*?<\/think>/g, "");
18323
+ let jsonString = cleanOutput;
18324
+ const startBlockJson = jsonString.indexOf("```json");
18325
+ const startBlock = startBlockJson !== -1 ? startBlockJson : jsonString.indexOf("```");
18326
+ if (startBlock !== -1) {
18327
+ const endBlock = jsonString.lastIndexOf("```");
18328
+ if (endBlock > startBlock) {
18329
+ jsonString = jsonString.substring(startBlock + (startBlockJson !== -1 ? 7 : 3), endBlock);
18330
+ }
18331
+ }
18332
+ const firstBrace = jsonString.indexOf("{");
18333
+ const lastBrace = jsonString.lastIndexOf("}");
18334
+ const firstBracket = jsonString.indexOf("[");
18335
+ const lastBracket = jsonString.lastIndexOf("]");
18336
+ const isObject2 = firstBrace !== -1 && (firstBracket === -1 || firstBrace < firstBracket);
18337
+ const isArray2 = firstBracket !== -1 && (firstBrace === -1 || firstBracket < firstBrace);
18338
+ if (isObject2 && lastBrace >= firstBrace) {
18339
+ jsonString = jsonString.substring(firstBrace, lastBrace + 1);
18340
+ } else if (isArray2 && lastBracket >= firstBracket) {
18341
+ jsonString = jsonString.substring(firstBracket, lastBracket + 1);
18342
+ }
18343
+ return import_json5.default.parse(jsonString);
18317
18344
  }
18318
18345
  return output;
18319
18346
  } catch (error) {
18320
18347
  throw new Error(error?.response?.statusText || error?.message || "未知原因");
18321
18348
  }
18322
18349
  };
18323
- // src/common/ai/video/index.ts
18324
- var exports_video = {};
18325
- __export(exports_video, {
18326
- keling: () => exports_keling
18350
+ // src/common/ai/doubao/index.ts
18351
+ var exports_doubao = {};
18352
+ __export(exports_doubao, {
18353
+ vc: () => vc,
18354
+ tts: () => tts
18327
18355
  });
18328
18356
 
18329
- // src/common/ai/video/keling/index.ts
18357
+ // src/common/ai/doubao/tts.ts
18358
+ var createReqid = () => {
18359
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
18360
+ return crypto.randomUUID();
18361
+ }
18362
+ return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
18363
+ };
18364
+ var decodeBase64ToArrayBuffer = (value) => {
18365
+ if (typeof window !== "undefined" && typeof window.atob === "function") {
18366
+ const binary = window.atob(value);
18367
+ const bytes = new Uint8Array(binary.length);
18368
+ for (let i = 0;i < binary.length; i++) {
18369
+ bytes[i] = binary.charCodeAt(i);
18370
+ }
18371
+ return bytes.buffer;
18372
+ }
18373
+ const buf = Buffer.from(value, "base64");
18374
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
18375
+ };
18376
+ var tts = async (params) => {
18377
+ const { app = {}, user, audio, request } = params;
18378
+ const url = "https://openspeech.bytedance.com/api/v3/tts/unidirectional";
18379
+ const reqid = request.reqid || createReqid();
18380
+ const speechRate = audio.speed_ratio ? Math.round((audio.speed_ratio - 1) * 100) : 0;
18381
+ const loudnessRate = audio.volume_ratio ? Math.round((audio.volume_ratio - 1) * 100) : 0;
18382
+ const headers = {
18383
+ "X-Api-App-Id": app.appid || process.env.DOUBAO_TTS_APPID || "",
18384
+ "X-Api-Access-Key": app.accessToken || process.env.DOUBAO_TTS_ACCESS_TOKEN || "",
18385
+ "X-Api-Resource-Id": app.resourceId || (audio.voice_type.startsWith("S_") ? "seed-icl-2.0" : "seed-tts-2.0"),
18386
+ "Content-Type": "application/json",
18387
+ "X-Api-Request-Id": reqid
18388
+ };
18389
+ const payload = {
18390
+ user: {
18391
+ uid: user?.uid || "uid"
18392
+ },
18393
+ req_params: {
18394
+ text: request.text,
18395
+ speaker: audio.voice_type,
18396
+ audio_params: {
18397
+ format: audio.encoding || "pcm",
18398
+ sample_rate: 24000,
18399
+ speech_rate: speechRate,
18400
+ loudness_rate: loudnessRate,
18401
+ emotion: audio.emotion,
18402
+ emotion_scale: audio.emotion_scale
18403
+ }
18404
+ }
18405
+ };
18406
+ if (audio.context_texts) {
18407
+ payload.req_params.additions = JSON.stringify({
18408
+ context_texts: audio.context_texts
18409
+ });
18410
+ }
18411
+ try {
18412
+ const response = await axios_default.post(url, payload, {
18413
+ headers,
18414
+ responseType: "arraybuffer"
18415
+ });
18416
+ const responseText = new TextDecoder().decode(response.data);
18417
+ const jsonObjects = [];
18418
+ let depth = 0;
18419
+ let start = 0;
18420
+ for (let i = 0;i < responseText.length; i++) {
18421
+ if (responseText[i] === "{") {
18422
+ if (depth === 0)
18423
+ start = i;
18424
+ depth++;
18425
+ } else if (responseText[i] === "}") {
18426
+ depth--;
18427
+ if (depth === 0) {
18428
+ try {
18429
+ const jsonStr = responseText.substring(start, i + 1);
18430
+ const jsonObj = JSON.parse(jsonStr);
18431
+ jsonObjects.push(jsonObj);
18432
+ } catch (e) {
18433
+ console.warn("Failed to parse JSON chunk", e);
18434
+ }
18435
+ }
18436
+ }
18437
+ }
18438
+ if (jsonObjects.length === 0) {
18439
+ try {
18440
+ jsonObjects.push(JSON.parse(responseText));
18441
+ } catch (e) {
18442
+ console.error("Doubao TTS Response Parse Error:", responseText);
18443
+ throw new Error("Invalid response format");
18444
+ }
18445
+ }
18446
+ const audioChunks = [];
18447
+ let totalLength = 0;
18448
+ for (const data of jsonObjects) {
18449
+ const code = data.code;
18450
+ const message = data.message;
18451
+ if (typeof code === "number" && code !== 0 && code !== 20000000) {
18452
+ console.error("Doubao TTS Error Response:", JSON.stringify(data, null, 2));
18453
+ const err = new Error(`豆包语音合成失败: ${message} (code: ${code})`);
18454
+ err.code = code;
18455
+ err.reqid = data.reqid;
18456
+ throw err;
18457
+ }
18458
+ if (data.data) {
18459
+ const chunkBuffer = decodeBase64ToArrayBuffer(data.data);
18460
+ audioChunks.push(chunkBuffer);
18461
+ totalLength += chunkBuffer.byteLength;
18462
+ }
18463
+ }
18464
+ if (totalLength === 0) {
18465
+ throw new Error("豆包语音合成失败:未返回音频数据");
18466
+ }
18467
+ const resultBuffer = new Uint8Array(totalLength);
18468
+ let offset = 0;
18469
+ for (const chunk of audioChunks) {
18470
+ resultBuffer.set(new Uint8Array(chunk), offset);
18471
+ offset += chunk.byteLength;
18472
+ }
18473
+ return resultBuffer.buffer;
18474
+ } catch (error) {
18475
+ if (error.response) {
18476
+ try {
18477
+ let errorData = error.response.data;
18478
+ if (errorData instanceof ArrayBuffer || typeof Buffer !== "undefined" && Buffer.isBuffer(errorData)) {
18479
+ errorData = new TextDecoder().decode(errorData);
18480
+ } else if (typeof errorData === "object") {
18481
+ errorData = JSON.stringify(errorData);
18482
+ }
18483
+ throw new Error(`Doubao TTS Error: ${error.response.status} - ${errorData}`);
18484
+ } catch (e) {
18485
+ if (e.message && e.message.startsWith("Doubao TTS Error")) {
18486
+ throw e;
18487
+ }
18488
+ throw new Error(`Doubao TTS Error: ${error.response.status} ${error.message}`);
18489
+ }
18490
+ }
18491
+ throw error;
18492
+ }
18493
+ };
18494
+ // src/common/ai/doubao/vc.ts
18495
+ var getHeaders = (accessToken, contentType) => {
18496
+ const headers = {
18497
+ Authorization: `Bearer; ${accessToken}`
18498
+ };
18499
+ if (contentType) {
18500
+ headers["content-type"] = contentType;
18501
+ }
18502
+ return headers;
18503
+ };
18504
+ var handleResponse = (data) => {
18505
+ if (data instanceof ArrayBuffer) {
18506
+ return data;
18507
+ }
18508
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
18509
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
18510
+ }
18511
+ return data;
18512
+ };
18513
+ var vc = {
18514
+ submit: async (params) => {
18515
+ const { app, audio, options = {} } = params;
18516
+ const url = new URL("https://openspeech.bytedance.com/api/v1/vc/submit");
18517
+ url.searchParams.set("appid", app.appid);
18518
+ Object.entries(options).forEach(([key2, value]) => {
18519
+ if (value !== undefined && value !== null) {
18520
+ url.searchParams.set(key2, String(value));
18521
+ }
18522
+ });
18523
+ const response = await axios_default.post(url.toString(), audio.data, {
18524
+ headers: getHeaders(app.accessToken, audio.contentType || "audio/wav"),
18525
+ responseType: "arraybuffer"
18526
+ });
18527
+ return handleResponse(response.data);
18528
+ },
18529
+ query: async (params) => {
18530
+ const { app, id, blocking } = params;
18531
+ const url = new URL("https://openspeech.bytedance.com/api/v1/vc/query");
18532
+ url.searchParams.set("appid", app.appid);
18533
+ url.searchParams.set("id", id);
18534
+ if (blocking !== undefined) {
18535
+ url.searchParams.set("blocking", String(blocking));
18536
+ }
18537
+ const response = await axios_default.get(url.toString(), {
18538
+ headers: getHeaders(app.accessToken),
18539
+ responseType: "arraybuffer"
18540
+ });
18541
+ return handleResponse(response.data);
18542
+ }
18543
+ };
18544
+ // src/common/ai/keling/index.ts
18330
18545
  var exports_keling = {};
18331
18546
  __export(exports_keling, {
18547
+ video: () => exports_video
18548
+ });
18549
+
18550
+ // src/common/ai/keling/video/index.ts
18551
+ var exports_video = {};
18552
+ __export(exports_video, {
18332
18553
  setCookie: () => setCookie,
18333
18554
  getVideoStatus: () => getVideoStatus,
18334
18555
  generateVideo: () => generateVideo
@@ -18746,7 +18967,7 @@ g.win32 = y.win32 = y;
18746
18967
  g.posix = g;
18747
18968
  var { resolve: B2, normalize: G2, isAbsolute: H2, join: K2, relative: Q2, toNamespacedPath: U, dirname: V, basename: X2, extname: Y2, format: Z2, parse: $, sep: I2, delimiter: O } = g;
18748
18969
 
18749
- // src/common/ai/video/keling/axios.ts
18970
+ // src/common/ai/keling/video/axios.ts
18750
18971
  var axios3 = axios_default.create({
18751
18972
  headers: {
18752
18973
  "Content-Type": "application/json",
@@ -18754,7 +18975,7 @@ var axios3 = axios_default.create({
18754
18975
  }
18755
18976
  });
18756
18977
 
18757
- // src/common/ai/video/keling/utils.ts
18978
+ // src/common/ai/keling/video/utils.ts
18758
18979
  var getToken = async (filename) => {
18759
18980
  try {
18760
18981
  const response = await axios3.get("https://klingai.kuaishou.com/api/upload/issue/token", {
@@ -18927,7 +19148,7 @@ var setCookie = (newCookieValue) => {
18927
19148
  axios3.defaults.headers.Cookie = newCookieValue;
18928
19149
  };
18929
19150
 
18930
- // src/common/ai/video/keling/index.ts
19151
+ // src/common/ai/keling/video/index.ts
18931
19152
  var getVideoStatus = async (taskId) => {
18932
19153
  if (!taskId) {
18933
19154
  return;
@@ -18984,11 +19205,28 @@ var complete = async (apiUrl, model, token, messages, json = true) => {
18984
19205
  throw new Error("No content in response");
18985
19206
  }
18986
19207
  if (json) {
18987
- const match = /```(json)?(.*)```/s.exec(content);
18988
- if (match && match[2]) {
18989
- return import_json52.default.parse(match[2]);
18990
- }
18991
- return import_json52.default.parse(content);
19208
+ const cleanContent = content.replace(/<think>[\s\S]*?<\/think>/g, "");
19209
+ let jsonString = cleanContent;
19210
+ const startBlockJson = jsonString.indexOf("```json");
19211
+ const startBlock = startBlockJson !== -1 ? startBlockJson : jsonString.indexOf("```");
19212
+ if (startBlock !== -1) {
19213
+ const endBlock = jsonString.lastIndexOf("```");
19214
+ if (endBlock > startBlock) {
19215
+ jsonString = jsonString.substring(startBlock + (startBlockJson !== -1 ? 7 : 3), endBlock);
19216
+ }
19217
+ }
19218
+ const firstBrace = jsonString.indexOf("{");
19219
+ const lastBrace = jsonString.lastIndexOf("}");
19220
+ const firstBracket = jsonString.indexOf("[");
19221
+ const lastBracket = jsonString.lastIndexOf("]");
19222
+ const isObject2 = firstBrace !== -1 && (firstBracket === -1 || firstBrace < firstBracket);
19223
+ const isArray2 = firstBracket !== -1 && (firstBrace === -1 || firstBracket < firstBrace);
19224
+ if (isObject2 && lastBrace >= firstBrace) {
19225
+ jsonString = jsonString.substring(firstBrace, lastBrace + 1);
19226
+ } else if (isArray2 && lastBracket >= firstBracket) {
19227
+ jsonString = jsonString.substring(firstBracket, lastBracket + 1);
19228
+ }
19229
+ return import_json52.default.parse(jsonString);
18992
19230
  }
18993
19231
  return content;
18994
19232
  } catch (error) {