@unityclaw/sdk 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -30,18 +30,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ CONFIG_DIR: () => CONFIG_DIR,
34
+ CONFIG_FILE: () => CONFIG_FILE,
35
+ DEFAULT_TASKS_DIR: () => DEFAULT_TASKS_DIR,
33
36
  DocumentAPI: () => DocumentAPI,
34
37
  ImageAPI: () => ImageAPI,
35
38
  MediaAPI: () => MediaAPI,
36
39
  TaskFolderManager: () => TaskFolderManager,
37
40
  UnityClawClient: () => UnityClawClient,
38
- VideoAPI: () => VideoAPI
41
+ VideoAPI: () => VideoAPI,
42
+ getConfigPath: () => getConfigPath,
43
+ getConfigValue: () => getConfigValue,
44
+ loadConfig: () => loadConfig,
45
+ saveConfig: () => saveConfig,
46
+ setConfigValue: () => setConfigValue
39
47
  });
40
48
  module.exports = __toCommonJS(index_exports);
41
49
 
42
50
  // src/client.ts
43
- var import_path2 = __toESM(require("path"), 1);
44
- var import_os = __toESM(require("os"), 1);
45
51
  var import_axios2 = __toESM(require("axios"), 1);
46
52
 
47
53
  // src/task-folder.ts
@@ -227,6 +233,67 @@ var TaskFolderManager = class {
227
233
  }
228
234
  };
229
235
 
236
+ // src/config.ts
237
+ var import_path2 = __toESM(require("path"), 1);
238
+ var import_os = __toESM(require("os"), 1);
239
+ var import_fs2 = require("fs");
240
+ var CONFIG_DIR = import_path2.default.join(import_os.default.homedir(), ".unityclaw");
241
+ var CONFIG_FILE = import_path2.default.join(CONFIG_DIR, "config.json");
242
+ var DEFAULT_TASKS_DIR = import_path2.default.join(CONFIG_DIR, "tasks");
243
+ function getConfigPath() {
244
+ return CONFIG_FILE;
245
+ }
246
+ function loadConfig() {
247
+ try {
248
+ if ((0, import_fs2.existsSync)(CONFIG_FILE)) {
249
+ const content = (0, import_fs2.readFileSync)(CONFIG_FILE, "utf-8");
250
+ return JSON.parse(content);
251
+ }
252
+ } catch {
253
+ }
254
+ return {};
255
+ }
256
+ function saveConfig(config) {
257
+ if (!(0, import_fs2.existsSync)(CONFIG_DIR)) {
258
+ (0, import_fs2.mkdirSync)(CONFIG_DIR, { recursive: true });
259
+ }
260
+ (0, import_fs2.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
261
+ }
262
+ function setConfigValue(key, value) {
263
+ const config = loadConfig();
264
+ const keyMap = {
265
+ "apiKey": "apiKey",
266
+ "api_key": "apiKey",
267
+ "key": "apiKey",
268
+ "baseUrl": "baseUrl",
269
+ "base_url": "baseUrl",
270
+ "url": "baseUrl",
271
+ "taskDir": "taskDir",
272
+ "task_dir": "taskDir",
273
+ "tasks": "taskDir"
274
+ };
275
+ const configKey = keyMap[key] || key;
276
+ config[configKey] = value;
277
+ saveConfig(config);
278
+ }
279
+ function getConfigValue(key) {
280
+ const config = loadConfig();
281
+ const keyMap = {
282
+ "apiKey": "apiKey",
283
+ "api_key": "apiKey",
284
+ "key": "apiKey",
285
+ "baseUrl": "baseUrl",
286
+ "base_url": "baseUrl",
287
+ "url": "baseUrl",
288
+ "taskDir": "taskDir",
289
+ "task_dir": "taskDir",
290
+ "tasks": "taskDir"
291
+ };
292
+ const configKey = keyMap[key] || key;
293
+ const value = config[configKey];
294
+ return value ? String(value) : void 0;
295
+ }
296
+
230
297
  // src/apis/image.ts
231
298
  var ImageAPI = class {
232
299
  constructor(client) {
@@ -242,31 +309,31 @@ var ImageAPI = class {
242
309
  * prompt: 'A beautiful sunset over mountains',
243
310
  * size: { value: '2K', label: '2K' }
244
311
  * });
312
+ * console.log('Task folder:', result.taskFolder);
313
+ * console.log('Local path:', result.response.data?.[0]?.localPath);
245
314
  * ```
246
315
  */
247
316
  async gemini(params) {
248
- const taskResult = await this.client.request("/api/gemini/image", {
317
+ return this.client.request("/api/gemini/image", {
249
318
  prompt: params.prompt,
250
319
  attachment: params.attachment,
251
320
  model: params.model,
252
321
  aspect_ratio: params.aspect_ratio,
253
322
  size: params.size
254
323
  });
255
- return taskResult.response;
256
324
  }
257
325
  /**
258
326
  * Generate image using Gemini API v2
259
327
  * @see /api/gemini/image/v2
260
328
  */
261
329
  async geminiV2(params) {
262
- const taskResult = await this.client.request("/api/gemini/image/v2", {
330
+ return this.client.request("/api/gemini/image/v2", {
263
331
  prompt: params.prompt,
264
332
  attachment: params.attachment,
265
333
  model: params.model,
266
334
  aspect_ratio: params.aspect_ratio,
267
335
  size: params.size
268
336
  });
269
- return taskResult.response;
270
337
  }
271
338
  /**
272
339
  * Generate image using JiMeng (Doubao) API
@@ -278,10 +345,11 @@ var ImageAPI = class {
278
345
  * prompt: '一只可爱的猫咪',
279
346
  * size: { value: '1024x1024', label: '1:1' }
280
347
  * });
348
+ * console.log('Task folder:', result.taskFolder);
281
349
  * ```
282
350
  */
283
351
  async jimeng(params) {
284
- const taskResult = await this.client.request("/api/jimeng/image", {
352
+ return this.client.request("/api/jimeng/image", {
285
353
  prompt: params.prompt,
286
354
  attachment: params.attachment,
287
355
  size: params.size,
@@ -290,14 +358,13 @@ var ImageAPI = class {
290
358
  image_count: params.image_count,
291
359
  model: params.model
292
360
  });
293
- return taskResult.response;
294
361
  }
295
362
  /**
296
363
  * Generate image using JiMeng V3 API
297
364
  * @see /api/jimeng/image/v3
298
365
  */
299
366
  async jimengV3(params) {
300
- const taskResult = await this.client.request("/api/jimeng/image/v3", {
367
+ return this.client.request("/api/jimeng/image/v3", {
301
368
  prompt: params.prompt,
302
369
  attachment: params.attachment,
303
370
  size: params.size,
@@ -306,18 +373,16 @@ var ImageAPI = class {
306
373
  image_count: params.image_count,
307
374
  model: params.model
308
375
  });
309
- return taskResult.response;
310
376
  }
311
377
  /**
312
378
  * Compress image
313
379
  * @see /api/image/compress
314
380
  */
315
381
  async compress(params) {
316
- const taskResult = await this.client.request("/api/image/compress", {
382
+ return this.client.request("/api/image/compress", {
317
383
  attachment: params.attachment,
318
384
  quality: params.quality
319
385
  });
320
- return taskResult.response;
321
386
  }
322
387
  };
323
388
 
@@ -336,28 +401,27 @@ var VideoAPI = class {
336
401
  * prompt: 'A cat playing piano',
337
402
  * orientation: { value: 'landscape', label: 'Landscape' }
338
403
  * });
404
+ * console.log('Task folder:', result.taskFolder);
339
405
  * ```
340
406
  */
341
407
  async sora(params) {
342
- const taskResult = await this.client.request("/api/sora/video", {
408
+ return this.client.request("/api/sora/video", {
343
409
  attachment: params.attachment,
344
410
  prompt: params.prompt,
345
411
  orientation: params.orientation
346
412
  });
347
- return taskResult.response;
348
413
  }
349
414
  /**
350
415
  * Generate video using Sora Stable API
351
416
  * @see /api/sora/video/stable
352
417
  */
353
418
  async soraStable(params) {
354
- const taskResult = await this.client.request("/api/sora/video/stable", {
419
+ return this.client.request("/api/sora/video/stable", {
355
420
  attachment: params.attachment,
356
421
  prompt: params.prompt,
357
422
  size: params.size,
358
423
  seconds: params.seconds
359
424
  });
360
- return taskResult.response;
361
425
  }
362
426
  /**
363
427
  * Generate video using Veo API
@@ -373,7 +437,7 @@ var VideoAPI = class {
373
437
  * ```
374
438
  */
375
439
  async veo(params) {
376
- const taskResult = await this.client.request("/api/veo/video", {
440
+ return this.client.request("/api/veo/video", {
377
441
  prompt: params.prompt,
378
442
  attachment: params.attachment,
379
443
  first_frame: params.first_frame,
@@ -382,7 +446,6 @@ var VideoAPI = class {
382
446
  resolution: params.resolution,
383
447
  duration: params.duration
384
448
  });
385
- return taskResult.response;
386
449
  }
387
450
  /**
388
451
  * Generate video using Kling API
@@ -399,14 +462,13 @@ var VideoAPI = class {
399
462
  * ```
400
463
  */
401
464
  async kling(params) {
402
- const taskResult = await this.client.request("/api/kling/video", {
465
+ return this.client.request("/api/kling/video", {
403
466
  attachment: params.attachment,
404
467
  prompt: params.prompt,
405
468
  aspect_ratio: params.aspect_ratio,
406
469
  duration: params.duration,
407
470
  model: params.model
408
471
  });
409
- return taskResult.response;
410
472
  }
411
473
  /**
412
474
  * Generate video using JiMeng API
@@ -422,13 +484,12 @@ var VideoAPI = class {
422
484
  * ```
423
485
  */
424
486
  async jimeng(params) {
425
- const taskResult = await this.client.request("/api/jimeng/video", {
487
+ return this.client.request("/api/jimeng/video", {
426
488
  action: params.action,
427
489
  attachment: params.attachment,
428
490
  prompt: params.prompt,
429
491
  aspect_ratio: params.aspect_ratio
430
492
  });
431
- return taskResult.response;
432
493
  }
433
494
  /**
434
495
  * Generate video using Doubao API
@@ -444,7 +505,7 @@ var VideoAPI = class {
444
505
  * ```
445
506
  */
446
507
  async doubao(params) {
447
- const taskResult = await this.client.request("/api/doubao/video", {
508
+ return this.client.request("/api/doubao/video", {
448
509
  action: params.action,
449
510
  attachment: params.attachment,
450
511
  prompt: params.prompt,
@@ -452,7 +513,6 @@ var VideoAPI = class {
452
513
  ratio: params.ratio,
453
514
  duration: params.duration
454
515
  });
455
- return taskResult.response;
456
516
  }
457
517
  /**
458
518
  * Generate video using Wan API (Alibaba)
@@ -469,7 +529,7 @@ var VideoAPI = class {
469
529
  * ```
470
530
  */
471
531
  async wan(params) {
472
- const taskResult = await this.client.request("/api/wan/video", {
532
+ return this.client.request("/api/wan/video", {
473
533
  attachment: params.attachment,
474
534
  prompt: params.prompt,
475
535
  size: params.size,
@@ -477,7 +537,6 @@ var VideoAPI = class {
477
537
  model: params.model,
478
538
  shot_type: params.shot_type
479
539
  });
480
- return taskResult.response;
481
540
  }
482
541
  /**
483
542
  * Generate video using MiniMax API
@@ -493,14 +552,13 @@ var VideoAPI = class {
493
552
  * ```
494
553
  */
495
554
  async minimax(params) {
496
- const taskResult = await this.client.request("/api/minimax/video", {
555
+ return this.client.request("/api/minimax/video", {
497
556
  attachment: params.attachment,
498
557
  prompt: params.prompt,
499
558
  size: params.size,
500
559
  duration: params.duration,
501
560
  model: params.model
502
561
  });
503
- return taskResult.response;
504
562
  }
505
563
  };
506
564
 
@@ -520,119 +578,111 @@ var DocumentAPI = class {
520
578
  * source_language: { value: 'en', label: 'English' },
521
579
  * target_language: { value: 'zh', label: 'Chinese' }
522
580
  * });
581
+ * console.log('Task folder:', result.taskFolder);
523
582
  * ```
524
583
  */
525
584
  async translate(params) {
526
- const taskResult = await this.client.request("/api/doc/translate", {
585
+ return this.client.request("/api/doc/translate", {
527
586
  attachment: params.attachment,
528
587
  source_language: params.source_language,
529
588
  target_language: params.target_language
530
589
  });
531
- return taskResult.response;
532
590
  }
533
591
  /**
534
592
  * Convert image to Word document
535
593
  * @see /api/doc_convert/image2word
536
594
  */
537
595
  async image2Word(params) {
538
- const taskResult = await this.client.request(
596
+ return this.client.request(
539
597
  "/api/doc_convert/image2word",
540
598
  {
541
599
  attachment: params.attachment
542
600
  }
543
601
  );
544
- return taskResult.response;
545
602
  }
546
603
  /**
547
604
  * Convert image to PowerPoint
548
605
  * @see /api/doc_convert/image2ppt
549
606
  */
550
607
  async image2Ppt(params) {
551
- const taskResult = await this.client.request(
608
+ return this.client.request(
552
609
  "/api/doc_convert/image2ppt",
553
610
  {
554
611
  attachment: params.attachment
555
612
  }
556
613
  );
557
- return taskResult.response;
558
614
  }
559
615
  /**
560
616
  * Convert image to Excel
561
617
  * @see /api/doc_convert/image2excel
562
618
  */
563
619
  async image2Excel(params) {
564
- const taskResult = await this.client.request(
620
+ return this.client.request(
565
621
  "/api/doc_convert/image2excel",
566
622
  {
567
623
  attachment: params.attachment
568
624
  }
569
625
  );
570
- return taskResult.response;
571
626
  }
572
627
  /**
573
628
  * Convert image to PDF
574
629
  * @see /api/doc_convert/image2pdf
575
630
  */
576
631
  async image2Pdf(params) {
577
- const taskResult = await this.client.request(
632
+ return this.client.request(
578
633
  "/api/doc_convert/image2pdf",
579
634
  {
580
635
  attachment: params.attachment
581
636
  }
582
637
  );
583
- return taskResult.response;
584
638
  }
585
639
  /**
586
640
  * Convert PDF to Word document
587
641
  * @see /api/doc_convert/pdf2word
588
642
  */
589
643
  async pdf2Word(params) {
590
- const taskResult = await this.client.request(
644
+ return this.client.request(
591
645
  "/api/doc_convert/pdf2word",
592
646
  {
593
647
  attachment: params.attachment
594
648
  }
595
649
  );
596
- return taskResult.response;
597
650
  }
598
651
  /**
599
652
  * Convert PDF to PowerPoint
600
653
  * @see /api/doc_convert/pdf2ppt
601
654
  */
602
655
  async pdf2Ppt(params) {
603
- const taskResult = await this.client.request(
656
+ return this.client.request(
604
657
  "/api/doc_convert/pdf2ppt",
605
658
  {
606
659
  attachment: params.attachment
607
660
  }
608
661
  );
609
- return taskResult.response;
610
662
  }
611
663
  /**
612
664
  * Convert PDF to Excel
613
665
  * @see /api/doc_convert/pdf2excel
614
666
  */
615
667
  async pdf2Excel(params) {
616
- const taskResult = await this.client.request(
668
+ return this.client.request(
617
669
  "/api/doc_convert/pdf2excel",
618
670
  {
619
671
  attachment: params.attachment
620
672
  }
621
673
  );
622
- return taskResult.response;
623
674
  }
624
675
  /**
625
676
  * Convert PDF to image
626
677
  * @see /api/doc_convert/pdf2image
627
678
  */
628
679
  async pdf2Image(params) {
629
- const taskResult = await this.client.request(
680
+ return this.client.request(
630
681
  "/api/doc_convert/pdf2image",
631
682
  {
632
683
  attachment: params.attachment
633
684
  }
634
685
  );
635
- return taskResult.response;
636
686
  }
637
687
  /**
638
688
  * Generic document conversion
@@ -642,12 +692,11 @@ var DocumentAPI = class {
642
692
  async convert(params) {
643
693
  const isImage = params.input_format === "image" || !params.input_format;
644
694
  const endpoint = isImage ? "/api/doc_convert/image" : "/api/doc_convert/pdf";
645
- const taskResult = await this.client.request(endpoint, {
695
+ return this.client.request(endpoint, {
646
696
  attachment: params.attachment,
647
697
  input_format: params.input_format,
648
698
  output_format: params.output_format
649
699
  });
650
- return taskResult.response;
651
700
  }
652
701
  };
653
702
 
@@ -671,13 +720,15 @@ var MediaAPI = class {
671
720
  * const result = await client.media.analyze({
672
721
  * url: [{ tmp_url: 'https://...', type: 'video/mp4', name: 'video.mp4' }]
673
722
  * });
723
+ *
724
+ * console.log('Task folder:', result.taskFolder);
725
+ * console.log('Summary:', result.response.data?.summary);
674
726
  * ```
675
727
  */
676
728
  async analyze(params) {
677
- const taskResult = await this.client.request("/api/media_analysis", {
729
+ return this.client.request("/api/media_analysis", {
678
730
  url: params.url
679
731
  });
680
- return taskResult.response;
681
732
  }
682
733
  /**
683
734
  * Analyze video file directly
@@ -692,7 +743,7 @@ var MediaAPI = class {
692
743
  * ```
693
744
  */
694
745
  async analyzeVideo(params) {
695
- const taskResult = await this.client.request("/api/media_analysis", {
746
+ return this.client.request("/api/media_analysis", {
696
747
  url: [
697
748
  {
698
749
  tmp_url: params.file.tmp_url,
@@ -702,7 +753,6 @@ var MediaAPI = class {
702
753
  }
703
754
  ]
704
755
  });
705
- return taskResult.response;
706
756
  }
707
757
  /**
708
758
  * Analyze social media video (TikTok, YouTube, etc.)
@@ -716,10 +766,9 @@ var MediaAPI = class {
716
766
  * ```
717
767
  */
718
768
  async analyzeSocialVideo(params) {
719
- const taskResult = await this.client.request("/api/media_analysis", {
769
+ return this.client.request("/api/media_analysis", {
720
770
  url: [{ link: params.url, type: "url" }]
721
771
  });
722
- return taskResult.response;
723
772
  }
724
773
  };
725
774
 
@@ -736,21 +785,16 @@ var UnityClawClient = class {
736
785
  document;
737
786
  media;
738
787
  constructor(config = {}) {
739
- const apiKey = config.apiKey ?? process.env.UNITYCLAW_API_KEY ?? "";
740
- const baseUrl = config.baseUrl ?? process.env.UNITYCLAW_BASE_URL ?? DEFAULT_BASE_URL;
788
+ const fileConfig = loadConfig();
789
+ const apiKey = config.apiKey ?? process.env.UNITYCLAW_API_KEY ?? fileConfig.apiKey ?? "";
790
+ const baseUrl = config.baseUrl ?? process.env.UNITYCLAW_BASE_URL ?? fileConfig.baseUrl ?? DEFAULT_BASE_URL;
741
791
  if (!apiKey) {
742
792
  throw new Error("API key is required. Set UNITYCLAW_API_KEY environment variable or pass apiKey in config.");
743
793
  }
744
794
  this.config = {
745
795
  apiKey,
746
796
  baseUrl,
747
- taskDir: config.taskDir ?? (() => {
748
- try {
749
- return import_path2.default.join(process.cwd(), "tasks");
750
- } catch {
751
- return import_path2.default.join(import_os.default.homedir(), "tasks");
752
- }
753
- })(),
797
+ taskDir: config.taskDir ?? fileConfig.taskDir ?? DEFAULT_TASKS_DIR,
754
798
  timeout: config.timeout ?? DEFAULT_TIMEOUT,
755
799
  downloadAttachments: config.downloadAttachments ?? true,
756
800
  context: config.context ?? {}
@@ -928,10 +972,18 @@ var UnityClawClient = class {
928
972
  };
929
973
  // Annotate the CommonJS export names for ESM import in node:
930
974
  0 && (module.exports = {
975
+ CONFIG_DIR,
976
+ CONFIG_FILE,
977
+ DEFAULT_TASKS_DIR,
931
978
  DocumentAPI,
932
979
  ImageAPI,
933
980
  MediaAPI,
934
981
  TaskFolderManager,
935
982
  UnityClawClient,
936
- VideoAPI
983
+ VideoAPI,
984
+ getConfigPath,
985
+ getConfigValue,
986
+ loadConfig,
987
+ saveConfig,
988
+ setConfigValue
937
989
  });