@wzyjs/utils 0.3.9 → 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
  });
@@ -10462,7 +10472,6 @@ __export(exports_web, {
10462
10472
  INVALID: () => INVALID,
10463
10473
  Enum: () => Enum,
10464
10474
  EMPTY_PATH: () => EMPTY_PATH,
10465
- Dayjs: () => import_dayjs2.Dayjs,
10466
10475
  DIRTY: () => DIRTY,
10467
10476
  BRAND: () => BRAND
10468
10477
  });
@@ -18273,8 +18282,9 @@ var import_copy_to_clipboard = __toESM(require_copy_to_clipboard());
18273
18282
  // src/common/ai/index.ts
18274
18283
  var exports_ai = {};
18275
18284
  __export(exports_ai, {
18276
- video: () => exports_video,
18277
18285
  text: () => exports_text,
18286
+ keling: () => exports_keling,
18287
+ doubao: () => exports_doubao,
18278
18288
  ai302: () => exports_302
18279
18289
  });
18280
18290
 
@@ -18309,27 +18319,237 @@ var chat = async (message, model = "gpt-4.1", isParse = true) => {
18309
18319
  console.log(666, typeof data, data);
18310
18320
  const output = typeof data === "string" ? import_json5.default.parse(data)?.output : data?.output;
18311
18321
  if (isParse) {
18312
- const match = /```(json)?(.*)```/s.exec(output);
18313
- if (!match) {
18314
- return import_json5.default.parse(output);
18315
- } else {
18316
- return import_json5.default.parse(match[2]);
18317
- }
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);
18318
18344
  }
18319
18345
  return output;
18320
18346
  } catch (error) {
18321
18347
  throw new Error(error?.response?.statusText || error?.message || "未知原因");
18322
18348
  }
18323
18349
  };
18324
- // src/common/ai/video/index.ts
18325
- var exports_video = {};
18326
- __export(exports_video, {
18327
- keling: () => exports_keling
18350
+ // src/common/ai/doubao/index.ts
18351
+ var exports_doubao = {};
18352
+ __export(exports_doubao, {
18353
+ vc: () => vc,
18354
+ tts: () => tts
18328
18355
  });
18329
18356
 
18330
- // 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
18331
18545
  var exports_keling = {};
18332
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, {
18333
18553
  setCookie: () => setCookie,
18334
18554
  getVideoStatus: () => getVideoStatus,
18335
18555
  generateVideo: () => generateVideo
@@ -18747,7 +18967,7 @@ g.win32 = y.win32 = y;
18747
18967
  g.posix = g;
18748
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;
18749
18969
 
18750
- // src/common/ai/video/keling/axios.ts
18970
+ // src/common/ai/keling/video/axios.ts
18751
18971
  var axios3 = axios_default.create({
18752
18972
  headers: {
18753
18973
  "Content-Type": "application/json",
@@ -18755,7 +18975,7 @@ var axios3 = axios_default.create({
18755
18975
  }
18756
18976
  });
18757
18977
 
18758
- // src/common/ai/video/keling/utils.ts
18978
+ // src/common/ai/keling/video/utils.ts
18759
18979
  var getToken = async (filename) => {
18760
18980
  try {
18761
18981
  const response = await axios3.get("https://klingai.kuaishou.com/api/upload/issue/token", {
@@ -18928,7 +19148,7 @@ var setCookie = (newCookieValue) => {
18928
19148
  axios3.defaults.headers.Cookie = newCookieValue;
18929
19149
  };
18930
19150
 
18931
- // src/common/ai/video/keling/index.ts
19151
+ // src/common/ai/keling/video/index.ts
18932
19152
  var getVideoStatus = async (taskId) => {
18933
19153
  if (!taskId) {
18934
19154
  return;
@@ -18985,11 +19205,28 @@ var complete = async (apiUrl, model, token, messages, json = true) => {
18985
19205
  throw new Error("No content in response");
18986
19206
  }
18987
19207
  if (json) {
18988
- const match = /```(json)?(.*)```/s.exec(content);
18989
- if (match && match[2]) {
18990
- return import_json52.default.parse(match[2]);
18991
- }
18992
- 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);
18993
19230
  }
18994
19231
  return content;
18995
19232
  } catch (error) {
@@ -21748,7 +21985,6 @@ var import_isSameOrAfter = __toESM(require_isSameOrAfter());
21748
21985
  var import_isSameOrBefore = __toESM(require_isSameOrBefore());
21749
21986
  var import_utc = __toESM(require_utc());
21750
21987
  var import_zh_cn = __toESM(require_zh_cn());
21751
- var import_dayjs2 = __toESM(require_dayjs_min());
21752
21988
  import_dayjs.default.extend(import_utc.default);
21753
21989
  import_dayjs.default.extend(import_isBetween.default);
21754
21990
  import_dayjs.default.extend(import_weekday.default);