@wzyjs/utils 0.3.27 → 0.3.28

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,5 +1,6 @@
1
1
  export * as ai302 from './302';
2
2
  export * as doubao from './doubao';
3
3
  export * as keling from './keling';
4
+ export * as openai from './openai';
4
5
  export * as xyq from './xyq';
5
6
  export * as text from './text';
@@ -1,4 +1,4 @@
1
- export { setCookie } from './utils';
1
+ export { setCookie, setApiAddress } from './utils';
2
2
  export declare const getVideoStatus: (taskId: string) => Promise<{
3
3
  status: any;
4
4
  url: any;
@@ -1,3 +1,6 @@
1
+ export declare const setApiAddress: (apiAddress?: string, uploadApiAddress?: string) => void;
2
+ export declare const buildApiUrl: (path: string) => string;
3
+ export declare const buildUploadApiUrl: (path: string) => string;
1
4
  export declare const uploadImage: (imageUrl: string) => Promise<any>;
2
5
  export declare const sbumit: (imageUrl: string, prompt?: string) => Promise<any>;
3
6
  export declare const calculateProgress: (taskData: any) => number;
@@ -0,0 +1,11 @@
1
+ export interface OpenAIImageGenerateParams {
2
+ apiAddress: string;
3
+ apiKey: string;
4
+ model: string;
5
+ prompt: string;
6
+ }
7
+ export interface OpenAIImageGenerateResult {
8
+ fileBase64: string;
9
+ format: string;
10
+ }
11
+ export declare const generateImage: (params: OpenAIImageGenerateParams) => Promise<OpenAIImageGenerateResult>;
package/dist/node.cjs.js CHANGED
@@ -35635,6 +35635,7 @@ var exports_ai = {};
35635
35635
  __export(exports_ai, {
35636
35636
  xyq: () => exports_xyq,
35637
35637
  text: () => exports_text,
35638
+ openai: () => exports_openai,
35638
35639
  keling: () => exports_keling,
35639
35640
  doubao: () => exports_doubao,
35640
35641
  ai302: () => exports_302
@@ -35890,6 +35891,7 @@ __export(exports_keling, {
35890
35891
  var exports_video = {};
35891
35892
  __export(exports_video, {
35892
35893
  setCookie: () => setCookie,
35894
+ setApiAddress: () => setApiAddress,
35893
35895
  getVideoStatus: () => getVideoStatus,
35894
35896
  generateVideo: () => generateVideo
35895
35897
  });
@@ -35908,9 +35910,28 @@ var axios4 = import_axios5.default.create({
35908
35910
  });
35909
35911
 
35910
35912
  // src/common/ai/keling/video/utils.ts
35913
+ var DEFAULT_API_ADDRESS = "https://klingai.kuaishou.com";
35914
+ var DEFAULT_UPLOAD_API_ADDRESS = "https://upload.kuaishouzt.com";
35915
+ var apiConfig = {
35916
+ apiAddress: DEFAULT_API_ADDRESS,
35917
+ uploadApiAddress: DEFAULT_UPLOAD_API_ADDRESS
35918
+ };
35919
+ var normalizeBaseUrl = (value) => {
35920
+ return value?.replace(/\/$/, "");
35921
+ };
35922
+ var setApiAddress = (apiAddress, uploadApiAddress) => {
35923
+ apiConfig.apiAddress = normalizeBaseUrl(apiAddress) || DEFAULT_API_ADDRESS;
35924
+ apiConfig.uploadApiAddress = normalizeBaseUrl(uploadApiAddress) || DEFAULT_UPLOAD_API_ADDRESS;
35925
+ };
35926
+ var buildApiUrl = (path2) => {
35927
+ return `${apiConfig.apiAddress}${path2}`;
35928
+ };
35929
+ var buildUploadApiUrl = (path2) => {
35930
+ return `${apiConfig.uploadApiAddress}${path2}`;
35931
+ };
35911
35932
  var getToken = async (filename) => {
35912
35933
  try {
35913
- const response = await axios4.get("https://klingai.kuaishou.com/api/upload/issue/token", {
35934
+ const response = await axios4.get(buildApiUrl("/api/upload/issue/token"), {
35914
35935
  params: { filename }
35915
35936
  });
35916
35937
  return response.data.data.token;
@@ -35921,7 +35942,7 @@ var getToken = async (filename) => {
35921
35942
  };
35922
35943
  var uploadFragment = async (uploadToken, imageBuffer) => {
35923
35944
  try {
35924
- const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
35945
+ const response = await axios4.post(buildUploadApiUrl("/api/upload/fragment"), imageBuffer, {
35925
35946
  params: {
35926
35947
  upload_token: uploadToken,
35927
35948
  fragment_id: 0
@@ -35938,7 +35959,7 @@ var uploadFragment = async (uploadToken, imageBuffer) => {
35938
35959
  };
35939
35960
  var completeUpload = async (uploadToken) => {
35940
35961
  try {
35941
- const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
35962
+ const response = await axios4.post(buildUploadApiUrl("/api/upload/complete"), null, {
35942
35963
  params: {
35943
35964
  upload_token: uploadToken,
35944
35965
  fragment_count: 1
@@ -35952,7 +35973,7 @@ var completeUpload = async (uploadToken) => {
35952
35973
  };
35953
35974
  var verifyUpload = async (token) => {
35954
35975
  try {
35955
- const response = await axios4.get("https://klingai.kuaishou.com/api/upload/verify/token", {
35976
+ const response = await axios4.get(buildApiUrl("/api/upload/verify/token"), {
35956
35977
  params: { token }
35957
35978
  });
35958
35979
  if (response.data?.result === 1 && response.data?.data?.status === 3) {
@@ -36049,7 +36070,7 @@ var sbumit = async (imageUrl, prompt) => {
36049
36070
  });
36050
36071
  const response = await axios4({
36051
36072
  method: "POST",
36052
- url: "https://klingai.kuaishou.com/api/task/submit",
36073
+ url: buildApiUrl("/api/task/submit"),
36053
36074
  data
36054
36075
  });
36055
36076
  return response.data?.data?.task?.id;
@@ -36086,7 +36107,7 @@ var getVideoStatus = async (taskId) => {
36086
36107
  return;
36087
36108
  }
36088
36109
  try {
36089
- const response = await axios4.get("https://klingai.kuaishou.com/api/task/status", {
36110
+ const response = await axios4.get(buildApiUrl("/api/task/status"), {
36090
36111
  params: { taskId }
36091
36112
  });
36092
36113
  return {
@@ -36107,13 +36128,44 @@ var generateVideo = async (imageUrl, prompt) => {
36107
36128
  console.log(666, "任务 id", taskId);
36108
36129
  return taskId;
36109
36130
  };
36131
+ // src/common/ai/openai/index.ts
36132
+ var exports_openai = {};
36133
+ __export(exports_openai, {
36134
+ generateImage: () => generateImage
36135
+ });
36136
+ var generateImage = async (params) => {
36137
+ const response = await fetch(`${params.apiAddress}/v1/images/generations`, {
36138
+ method: "POST",
36139
+ headers: {
36140
+ "Content-Type": "application/json",
36141
+ Authorization: `Bearer ${params.apiKey}`
36142
+ },
36143
+ body: JSON.stringify({
36144
+ model: params.model,
36145
+ prompt: params.prompt
36146
+ })
36147
+ });
36148
+ if (!response.ok) {
36149
+ const errorText = await response.text();
36150
+ throw new Error(`图片生成失败: ${response.status} ${errorText}`);
36151
+ }
36152
+ const data = await response.json();
36153
+ const fileBase64 = data?.data?.[0]?.b64_json;
36154
+ if (!fileBase64) {
36155
+ throw new Error("图片生成失败: 返回结果缺少图片数据");
36156
+ }
36157
+ return {
36158
+ fileBase64,
36159
+ format: "png"
36160
+ };
36161
+ };
36110
36162
  // src/common/ai/xyq/index.ts
36111
36163
  var exports_xyq = {};
36112
36164
  __export(exports_xyq, {
36113
36165
  submitRun: () => submitRun,
36114
36166
  pollUntilComplete: () => pollUntilComplete,
36115
36167
  getThreadStatus: () => getThreadStatus,
36116
- generateImage: () => generateImage,
36168
+ generateImage: () => generateImage2,
36117
36169
  extractMediaFromEntry: () => extractMediaFromEntry,
36118
36170
  RUN_STATE: () => RUN_STATE
36119
36171
  });
@@ -36268,7 +36320,7 @@ var pollUntilComplete = async (params, options = {}) => {
36268
36320
  }
36269
36321
  throw new Error("小云雀任务超时");
36270
36322
  };
36271
- var generateImage = async (prompt, options) => {
36323
+ var generateImage2 = async (prompt, options) => {
36272
36324
  const { threadId: existingThreadId, assetIds, onProgress, config } = options || {};
36273
36325
  onProgress?.("正在提交创作任务...");
36274
36326
  const submitResult = await submitRun({
package/dist/node.esm.js CHANGED
@@ -34731,6 +34731,7 @@ var exports_ai = {};
34731
34731
  __export(exports_ai, {
34732
34732
  xyq: () => exports_xyq,
34733
34733
  text: () => exports_text,
34734
+ openai: () => exports_openai,
34734
34735
  keling: () => exports_keling,
34735
34736
  doubao: () => exports_doubao,
34736
34737
  ai302: () => exports_302
@@ -34986,6 +34987,7 @@ __export(exports_keling, {
34986
34987
  var exports_video = {};
34987
34988
  __export(exports_video, {
34988
34989
  setCookie: () => setCookie,
34990
+ setApiAddress: () => setApiAddress,
34989
34991
  getVideoStatus: () => getVideoStatus,
34990
34992
  generateVideo: () => generateVideo
34991
34993
  });
@@ -35004,9 +35006,28 @@ var axios4 = axios_2.create({
35004
35006
  });
35005
35007
 
35006
35008
  // src/common/ai/keling/video/utils.ts
35009
+ var DEFAULT_API_ADDRESS = "https://klingai.kuaishou.com";
35010
+ var DEFAULT_UPLOAD_API_ADDRESS = "https://upload.kuaishouzt.com";
35011
+ var apiConfig = {
35012
+ apiAddress: DEFAULT_API_ADDRESS,
35013
+ uploadApiAddress: DEFAULT_UPLOAD_API_ADDRESS
35014
+ };
35015
+ var normalizeBaseUrl = (value) => {
35016
+ return value?.replace(/\/$/, "");
35017
+ };
35018
+ var setApiAddress = (apiAddress, uploadApiAddress) => {
35019
+ apiConfig.apiAddress = normalizeBaseUrl(apiAddress) || DEFAULT_API_ADDRESS;
35020
+ apiConfig.uploadApiAddress = normalizeBaseUrl(uploadApiAddress) || DEFAULT_UPLOAD_API_ADDRESS;
35021
+ };
35022
+ var buildApiUrl = (path2) => {
35023
+ return `${apiConfig.apiAddress}${path2}`;
35024
+ };
35025
+ var buildUploadApiUrl = (path2) => {
35026
+ return `${apiConfig.uploadApiAddress}${path2}`;
35027
+ };
35007
35028
  var getToken = async (filename) => {
35008
35029
  try {
35009
- const response = await axios4.get("https://klingai.kuaishou.com/api/upload/issue/token", {
35030
+ const response = await axios4.get(buildApiUrl("/api/upload/issue/token"), {
35010
35031
  params: { filename }
35011
35032
  });
35012
35033
  return response.data.data.token;
@@ -35017,7 +35038,7 @@ var getToken = async (filename) => {
35017
35038
  };
35018
35039
  var uploadFragment = async (uploadToken, imageBuffer) => {
35019
35040
  try {
35020
- const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
35041
+ const response = await axios4.post(buildUploadApiUrl("/api/upload/fragment"), imageBuffer, {
35021
35042
  params: {
35022
35043
  upload_token: uploadToken,
35023
35044
  fragment_id: 0
@@ -35034,7 +35055,7 @@ var uploadFragment = async (uploadToken, imageBuffer) => {
35034
35055
  };
35035
35056
  var completeUpload = async (uploadToken) => {
35036
35057
  try {
35037
- const response = await axios4.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
35058
+ const response = await axios4.post(buildUploadApiUrl("/api/upload/complete"), null, {
35038
35059
  params: {
35039
35060
  upload_token: uploadToken,
35040
35061
  fragment_count: 1
@@ -35048,7 +35069,7 @@ var completeUpload = async (uploadToken) => {
35048
35069
  };
35049
35070
  var verifyUpload = async (token) => {
35050
35071
  try {
35051
- const response = await axios4.get("https://klingai.kuaishou.com/api/upload/verify/token", {
35072
+ const response = await axios4.get(buildApiUrl("/api/upload/verify/token"), {
35052
35073
  params: { token }
35053
35074
  });
35054
35075
  if (response.data?.result === 1 && response.data?.data?.status === 3) {
@@ -35145,7 +35166,7 @@ var sbumit = async (imageUrl, prompt) => {
35145
35166
  });
35146
35167
  const response = await axios4({
35147
35168
  method: "POST",
35148
- url: "https://klingai.kuaishou.com/api/task/submit",
35169
+ url: buildApiUrl("/api/task/submit"),
35149
35170
  data
35150
35171
  });
35151
35172
  return response.data?.data?.task?.id;
@@ -35182,7 +35203,7 @@ var getVideoStatus = async (taskId) => {
35182
35203
  return;
35183
35204
  }
35184
35205
  try {
35185
- const response = await axios4.get("https://klingai.kuaishou.com/api/task/status", {
35206
+ const response = await axios4.get(buildApiUrl("/api/task/status"), {
35186
35207
  params: { taskId }
35187
35208
  });
35188
35209
  return {
@@ -35203,13 +35224,44 @@ var generateVideo = async (imageUrl, prompt) => {
35203
35224
  console.log(666, "任务 id", taskId);
35204
35225
  return taskId;
35205
35226
  };
35227
+ // src/common/ai/openai/index.ts
35228
+ var exports_openai = {};
35229
+ __export(exports_openai, {
35230
+ generateImage: () => generateImage
35231
+ });
35232
+ var generateImage = async (params) => {
35233
+ const response = await fetch(`${params.apiAddress}/v1/images/generations`, {
35234
+ method: "POST",
35235
+ headers: {
35236
+ "Content-Type": "application/json",
35237
+ Authorization: `Bearer ${params.apiKey}`
35238
+ },
35239
+ body: JSON.stringify({
35240
+ model: params.model,
35241
+ prompt: params.prompt
35242
+ })
35243
+ });
35244
+ if (!response.ok) {
35245
+ const errorText = await response.text();
35246
+ throw new Error(`图片生成失败: ${response.status} ${errorText}`);
35247
+ }
35248
+ const data = await response.json();
35249
+ const fileBase64 = data?.data?.[0]?.b64_json;
35250
+ if (!fileBase64) {
35251
+ throw new Error("图片生成失败: 返回结果缺少图片数据");
35252
+ }
35253
+ return {
35254
+ fileBase64,
35255
+ format: "png"
35256
+ };
35257
+ };
35206
35258
  // src/common/ai/xyq/index.ts
35207
35259
  var exports_xyq = {};
35208
35260
  __export(exports_xyq, {
35209
35261
  submitRun: () => submitRun,
35210
35262
  pollUntilComplete: () => pollUntilComplete,
35211
35263
  getThreadStatus: () => getThreadStatus,
35212
- generateImage: () => generateImage,
35264
+ generateImage: () => generateImage2,
35213
35265
  extractMediaFromEntry: () => extractMediaFromEntry,
35214
35266
  RUN_STATE: () => RUN_STATE
35215
35267
  });
@@ -35364,7 +35416,7 @@ var pollUntilComplete = async (params, options = {}) => {
35364
35416
  }
35365
35417
  throw new Error("小云雀任务超时");
35366
35418
  };
35367
- var generateImage = async (prompt, options) => {
35419
+ var generateImage2 = async (prompt, options) => {
35368
35420
  const { threadId: existingThreadId, assetIds, onProgress, config } = options || {};
35369
35421
  onProgress?.("正在提交创作任务...");
35370
35422
  const submitResult = await submitRun({
package/dist/web.cjs.js CHANGED
@@ -18306,6 +18306,7 @@ var exports_ai = {};
18306
18306
  __export(exports_ai, {
18307
18307
  xyq: () => exports_xyq,
18308
18308
  text: () => exports_text,
18309
+ openai: () => exports_openai,
18309
18310
  keling: () => exports_keling,
18310
18311
  doubao: () => exports_doubao,
18311
18312
  ai302: () => exports_302
@@ -18558,6 +18559,7 @@ __export(exports_keling, {
18558
18559
  var exports_video = {};
18559
18560
  __export(exports_video, {
18560
18561
  setCookie: () => setCookie,
18562
+ setApiAddress: () => setApiAddress,
18561
18563
  getVideoStatus: () => getVideoStatus,
18562
18564
  generateVideo: () => generateVideo
18563
18565
  });
@@ -19233,9 +19235,28 @@ var axios3 = axios_default.create({
19233
19235
  });
19234
19236
 
19235
19237
  // src/common/ai/keling/video/utils.ts
19238
+ var DEFAULT_API_ADDRESS = "https://klingai.kuaishou.com";
19239
+ var DEFAULT_UPLOAD_API_ADDRESS = "https://upload.kuaishouzt.com";
19240
+ var apiConfig = {
19241
+ apiAddress: DEFAULT_API_ADDRESS,
19242
+ uploadApiAddress: DEFAULT_UPLOAD_API_ADDRESS
19243
+ };
19244
+ var normalizeBaseUrl = (value) => {
19245
+ return value?.replace(/\/$/, "");
19246
+ };
19247
+ var setApiAddress = (apiAddress, uploadApiAddress) => {
19248
+ apiConfig.apiAddress = normalizeBaseUrl(apiAddress) || DEFAULT_API_ADDRESS;
19249
+ apiConfig.uploadApiAddress = normalizeBaseUrl(uploadApiAddress) || DEFAULT_UPLOAD_API_ADDRESS;
19250
+ };
19251
+ var buildApiUrl = (path) => {
19252
+ return `${apiConfig.apiAddress}${path}`;
19253
+ };
19254
+ var buildUploadApiUrl = (path) => {
19255
+ return `${apiConfig.uploadApiAddress}${path}`;
19256
+ };
19236
19257
  var getToken = async (filename) => {
19237
19258
  try {
19238
- const response = await axios3.get("https://klingai.kuaishou.com/api/upload/issue/token", {
19259
+ const response = await axios3.get(buildApiUrl("/api/upload/issue/token"), {
19239
19260
  params: { filename }
19240
19261
  });
19241
19262
  return response.data.data.token;
@@ -19246,7 +19267,7 @@ var getToken = async (filename) => {
19246
19267
  };
19247
19268
  var uploadFragment = async (uploadToken, imageBuffer) => {
19248
19269
  try {
19249
- const response = await axios3.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
19270
+ const response = await axios3.post(buildUploadApiUrl("/api/upload/fragment"), imageBuffer, {
19250
19271
  params: {
19251
19272
  upload_token: uploadToken,
19252
19273
  fragment_id: 0
@@ -19263,7 +19284,7 @@ var uploadFragment = async (uploadToken, imageBuffer) => {
19263
19284
  };
19264
19285
  var completeUpload = async (uploadToken) => {
19265
19286
  try {
19266
- const response = await axios3.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
19287
+ const response = await axios3.post(buildUploadApiUrl("/api/upload/complete"), null, {
19267
19288
  params: {
19268
19289
  upload_token: uploadToken,
19269
19290
  fragment_count: 1
@@ -19277,7 +19298,7 @@ var completeUpload = async (uploadToken) => {
19277
19298
  };
19278
19299
  var verifyUpload = async (token) => {
19279
19300
  try {
19280
- const response = await axios3.get("https://klingai.kuaishou.com/api/upload/verify/token", {
19301
+ const response = await axios3.get(buildApiUrl("/api/upload/verify/token"), {
19281
19302
  params: { token }
19282
19303
  });
19283
19304
  if (response.data?.result === 1 && response.data?.data?.status === 3) {
@@ -19374,7 +19395,7 @@ var sbumit = async (imageUrl, prompt) => {
19374
19395
  });
19375
19396
  const response = await axios3({
19376
19397
  method: "POST",
19377
- url: "https://klingai.kuaishou.com/api/task/submit",
19398
+ url: buildApiUrl("/api/task/submit"),
19378
19399
  data
19379
19400
  });
19380
19401
  return response.data?.data?.task?.id;
@@ -19411,7 +19432,7 @@ var getVideoStatus = async (taskId) => {
19411
19432
  return;
19412
19433
  }
19413
19434
  try {
19414
- const response = await axios3.get("https://klingai.kuaishou.com/api/task/status", {
19435
+ const response = await axios3.get(buildApiUrl("/api/task/status"), {
19415
19436
  params: { taskId }
19416
19437
  });
19417
19438
  return {
@@ -19432,13 +19453,44 @@ var generateVideo = async (imageUrl, prompt) => {
19432
19453
  console.log(666, "任务 id", taskId);
19433
19454
  return taskId;
19434
19455
  };
19456
+ // src/common/ai/openai/index.ts
19457
+ var exports_openai = {};
19458
+ __export(exports_openai, {
19459
+ generateImage: () => generateImage
19460
+ });
19461
+ var generateImage = async (params) => {
19462
+ const response = await fetch(`${params.apiAddress}/v1/images/generations`, {
19463
+ method: "POST",
19464
+ headers: {
19465
+ "Content-Type": "application/json",
19466
+ Authorization: `Bearer ${params.apiKey}`
19467
+ },
19468
+ body: JSON.stringify({
19469
+ model: params.model,
19470
+ prompt: params.prompt
19471
+ })
19472
+ });
19473
+ if (!response.ok) {
19474
+ const errorText = await response.text();
19475
+ throw new Error(`图片生成失败: ${response.status} ${errorText}`);
19476
+ }
19477
+ const data = await response.json();
19478
+ const fileBase64 = data?.data?.[0]?.b64_json;
19479
+ if (!fileBase64) {
19480
+ throw new Error("图片生成失败: 返回结果缺少图片数据");
19481
+ }
19482
+ return {
19483
+ fileBase64,
19484
+ format: "png"
19485
+ };
19486
+ };
19435
19487
  // src/common/ai/xyq/index.ts
19436
19488
  var exports_xyq = {};
19437
19489
  __export(exports_xyq, {
19438
19490
  submitRun: () => submitRun,
19439
19491
  pollUntilComplete: () => pollUntilComplete,
19440
19492
  getThreadStatus: () => getThreadStatus,
19441
- generateImage: () => generateImage,
19493
+ generateImage: () => generateImage2,
19442
19494
  extractMediaFromEntry: () => extractMediaFromEntry,
19443
19495
  RUN_STATE: () => RUN_STATE
19444
19496
  });
@@ -19592,7 +19644,7 @@ var pollUntilComplete = async (params, options = {}) => {
19592
19644
  }
19593
19645
  throw new Error("小云雀任务超时");
19594
19646
  };
19595
- var generateImage = async (prompt, options) => {
19647
+ var generateImage2 = async (prompt, options) => {
19596
19648
  const { threadId: existingThreadId, assetIds, onProgress, config } = options || {};
19597
19649
  onProgress?.("正在提交创作任务...");
19598
19650
  const submitResult = await submitRun({
package/dist/web.esm.js CHANGED
@@ -18115,6 +18115,7 @@ var exports_ai = {};
18115
18115
  __export(exports_ai, {
18116
18116
  xyq: () => exports_xyq,
18117
18117
  text: () => exports_text,
18118
+ openai: () => exports_openai,
18118
18119
  keling: () => exports_keling,
18119
18120
  doubao: () => exports_doubao,
18120
18121
  ai302: () => exports_302
@@ -18367,6 +18368,7 @@ __export(exports_keling, {
18367
18368
  var exports_video = {};
18368
18369
  __export(exports_video, {
18369
18370
  setCookie: () => setCookie,
18371
+ setApiAddress: () => setApiAddress,
18370
18372
  getVideoStatus: () => getVideoStatus,
18371
18373
  generateVideo: () => generateVideo
18372
18374
  });
@@ -19042,9 +19044,28 @@ var axios3 = axios_default.create({
19042
19044
  });
19043
19045
 
19044
19046
  // src/common/ai/keling/video/utils.ts
19047
+ var DEFAULT_API_ADDRESS = "https://klingai.kuaishou.com";
19048
+ var DEFAULT_UPLOAD_API_ADDRESS = "https://upload.kuaishouzt.com";
19049
+ var apiConfig = {
19050
+ apiAddress: DEFAULT_API_ADDRESS,
19051
+ uploadApiAddress: DEFAULT_UPLOAD_API_ADDRESS
19052
+ };
19053
+ var normalizeBaseUrl = (value) => {
19054
+ return value?.replace(/\/$/, "");
19055
+ };
19056
+ var setApiAddress = (apiAddress, uploadApiAddress) => {
19057
+ apiConfig.apiAddress = normalizeBaseUrl(apiAddress) || DEFAULT_API_ADDRESS;
19058
+ apiConfig.uploadApiAddress = normalizeBaseUrl(uploadApiAddress) || DEFAULT_UPLOAD_API_ADDRESS;
19059
+ };
19060
+ var buildApiUrl = (path) => {
19061
+ return `${apiConfig.apiAddress}${path}`;
19062
+ };
19063
+ var buildUploadApiUrl = (path) => {
19064
+ return `${apiConfig.uploadApiAddress}${path}`;
19065
+ };
19045
19066
  var getToken = async (filename) => {
19046
19067
  try {
19047
- const response = await axios3.get("https://klingai.kuaishou.com/api/upload/issue/token", {
19068
+ const response = await axios3.get(buildApiUrl("/api/upload/issue/token"), {
19048
19069
  params: { filename }
19049
19070
  });
19050
19071
  return response.data.data.token;
@@ -19055,7 +19076,7 @@ var getToken = async (filename) => {
19055
19076
  };
19056
19077
  var uploadFragment = async (uploadToken, imageBuffer) => {
19057
19078
  try {
19058
- const response = await axios3.post("https://upload.kuaishouzt.com/api/upload/fragment", imageBuffer, {
19079
+ const response = await axios3.post(buildUploadApiUrl("/api/upload/fragment"), imageBuffer, {
19059
19080
  params: {
19060
19081
  upload_token: uploadToken,
19061
19082
  fragment_id: 0
@@ -19072,7 +19093,7 @@ var uploadFragment = async (uploadToken, imageBuffer) => {
19072
19093
  };
19073
19094
  var completeUpload = async (uploadToken) => {
19074
19095
  try {
19075
- const response = await axios3.post("https://upload.kuaishouzt.com/api/upload/complete", null, {
19096
+ const response = await axios3.post(buildUploadApiUrl("/api/upload/complete"), null, {
19076
19097
  params: {
19077
19098
  upload_token: uploadToken,
19078
19099
  fragment_count: 1
@@ -19086,7 +19107,7 @@ var completeUpload = async (uploadToken) => {
19086
19107
  };
19087
19108
  var verifyUpload = async (token) => {
19088
19109
  try {
19089
- const response = await axios3.get("https://klingai.kuaishou.com/api/upload/verify/token", {
19110
+ const response = await axios3.get(buildApiUrl("/api/upload/verify/token"), {
19090
19111
  params: { token }
19091
19112
  });
19092
19113
  if (response.data?.result === 1 && response.data?.data?.status === 3) {
@@ -19183,7 +19204,7 @@ var sbumit = async (imageUrl, prompt) => {
19183
19204
  });
19184
19205
  const response = await axios3({
19185
19206
  method: "POST",
19186
- url: "https://klingai.kuaishou.com/api/task/submit",
19207
+ url: buildApiUrl("/api/task/submit"),
19187
19208
  data
19188
19209
  });
19189
19210
  return response.data?.data?.task?.id;
@@ -19220,7 +19241,7 @@ var getVideoStatus = async (taskId) => {
19220
19241
  return;
19221
19242
  }
19222
19243
  try {
19223
- const response = await axios3.get("https://klingai.kuaishou.com/api/task/status", {
19244
+ const response = await axios3.get(buildApiUrl("/api/task/status"), {
19224
19245
  params: { taskId }
19225
19246
  });
19226
19247
  return {
@@ -19241,13 +19262,44 @@ var generateVideo = async (imageUrl, prompt) => {
19241
19262
  console.log(666, "任务 id", taskId);
19242
19263
  return taskId;
19243
19264
  };
19265
+ // src/common/ai/openai/index.ts
19266
+ var exports_openai = {};
19267
+ __export(exports_openai, {
19268
+ generateImage: () => generateImage
19269
+ });
19270
+ var generateImage = async (params) => {
19271
+ const response = await fetch(`${params.apiAddress}/v1/images/generations`, {
19272
+ method: "POST",
19273
+ headers: {
19274
+ "Content-Type": "application/json",
19275
+ Authorization: `Bearer ${params.apiKey}`
19276
+ },
19277
+ body: JSON.stringify({
19278
+ model: params.model,
19279
+ prompt: params.prompt
19280
+ })
19281
+ });
19282
+ if (!response.ok) {
19283
+ const errorText = await response.text();
19284
+ throw new Error(`图片生成失败: ${response.status} ${errorText}`);
19285
+ }
19286
+ const data = await response.json();
19287
+ const fileBase64 = data?.data?.[0]?.b64_json;
19288
+ if (!fileBase64) {
19289
+ throw new Error("图片生成失败: 返回结果缺少图片数据");
19290
+ }
19291
+ return {
19292
+ fileBase64,
19293
+ format: "png"
19294
+ };
19295
+ };
19244
19296
  // src/common/ai/xyq/index.ts
19245
19297
  var exports_xyq = {};
19246
19298
  __export(exports_xyq, {
19247
19299
  submitRun: () => submitRun,
19248
19300
  pollUntilComplete: () => pollUntilComplete,
19249
19301
  getThreadStatus: () => getThreadStatus,
19250
- generateImage: () => generateImage,
19302
+ generateImage: () => generateImage2,
19251
19303
  extractMediaFromEntry: () => extractMediaFromEntry,
19252
19304
  RUN_STATE: () => RUN_STATE
19253
19305
  });
@@ -19401,7 +19453,7 @@ var pollUntilComplete = async (params, options = {}) => {
19401
19453
  }
19402
19454
  throw new Error("小云雀任务超时");
19403
19455
  };
19404
- var generateImage = async (prompt, options) => {
19456
+ var generateImage2 = async (prompt, options) => {
19405
19457
  const { threadId: existingThreadId, assetIds, onProgress, config } = options || {};
19406
19458
  onProgress?.("正在提交创作任务...");
19407
19459
  const submitResult = await submitRun({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/utils",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "sideEffects": false,
@@ -70,7 +70,7 @@
70
70
  "@types/nodemailer": "^6.4.7",
71
71
  "@types/papaparse": "^5.3.15"
72
72
  },
73
- "gitHead": "f9e5dcf56fea3b93a2614ad468ecb466e5da7945",
73
+ "gitHead": "cfb708a071a9f7f0e2c819760c95427d7196623b",
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  }