@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.js CHANGED
@@ -1,6 +1,15 @@
1
+ import {
2
+ CONFIG_DIR,
3
+ CONFIG_FILE,
4
+ DEFAULT_TASKS_DIR,
5
+ getConfigPath,
6
+ getConfigValue,
7
+ loadConfig,
8
+ saveConfig,
9
+ setConfigValue
10
+ } from "./chunk-WG7OYNEX.js";
11
+
1
12
  // src/client.ts
2
- import path from "path";
3
- import os from "os";
4
13
  import axios2, { AxiosError } from "axios";
5
14
 
6
15
  // src/task-folder.ts
@@ -201,31 +210,31 @@ var ImageAPI = class {
201
210
  * prompt: 'A beautiful sunset over mountains',
202
211
  * size: { value: '2K', label: '2K' }
203
212
  * });
213
+ * console.log('Task folder:', result.taskFolder);
214
+ * console.log('Local path:', result.response.data?.[0]?.localPath);
204
215
  * ```
205
216
  */
206
217
  async gemini(params) {
207
- const taskResult = await this.client.request("/api/gemini/image", {
218
+ return this.client.request("/api/gemini/image", {
208
219
  prompt: params.prompt,
209
220
  attachment: params.attachment,
210
221
  model: params.model,
211
222
  aspect_ratio: params.aspect_ratio,
212
223
  size: params.size
213
224
  });
214
- return taskResult.response;
215
225
  }
216
226
  /**
217
227
  * Generate image using Gemini API v2
218
228
  * @see /api/gemini/image/v2
219
229
  */
220
230
  async geminiV2(params) {
221
- const taskResult = await this.client.request("/api/gemini/image/v2", {
231
+ return this.client.request("/api/gemini/image/v2", {
222
232
  prompt: params.prompt,
223
233
  attachment: params.attachment,
224
234
  model: params.model,
225
235
  aspect_ratio: params.aspect_ratio,
226
236
  size: params.size
227
237
  });
228
- return taskResult.response;
229
238
  }
230
239
  /**
231
240
  * Generate image using JiMeng (Doubao) API
@@ -237,10 +246,11 @@ var ImageAPI = class {
237
246
  * prompt: '一只可爱的猫咪',
238
247
  * size: { value: '1024x1024', label: '1:1' }
239
248
  * });
249
+ * console.log('Task folder:', result.taskFolder);
240
250
  * ```
241
251
  */
242
252
  async jimeng(params) {
243
- const taskResult = await this.client.request("/api/jimeng/image", {
253
+ return this.client.request("/api/jimeng/image", {
244
254
  prompt: params.prompt,
245
255
  attachment: params.attachment,
246
256
  size: params.size,
@@ -249,14 +259,13 @@ var ImageAPI = class {
249
259
  image_count: params.image_count,
250
260
  model: params.model
251
261
  });
252
- return taskResult.response;
253
262
  }
254
263
  /**
255
264
  * Generate image using JiMeng V3 API
256
265
  * @see /api/jimeng/image/v3
257
266
  */
258
267
  async jimengV3(params) {
259
- const taskResult = await this.client.request("/api/jimeng/image/v3", {
268
+ return this.client.request("/api/jimeng/image/v3", {
260
269
  prompt: params.prompt,
261
270
  attachment: params.attachment,
262
271
  size: params.size,
@@ -265,18 +274,16 @@ var ImageAPI = class {
265
274
  image_count: params.image_count,
266
275
  model: params.model
267
276
  });
268
- return taskResult.response;
269
277
  }
270
278
  /**
271
279
  * Compress image
272
280
  * @see /api/image/compress
273
281
  */
274
282
  async compress(params) {
275
- const taskResult = await this.client.request("/api/image/compress", {
283
+ return this.client.request("/api/image/compress", {
276
284
  attachment: params.attachment,
277
285
  quality: params.quality
278
286
  });
279
- return taskResult.response;
280
287
  }
281
288
  };
282
289
 
@@ -295,28 +302,27 @@ var VideoAPI = class {
295
302
  * prompt: 'A cat playing piano',
296
303
  * orientation: { value: 'landscape', label: 'Landscape' }
297
304
  * });
305
+ * console.log('Task folder:', result.taskFolder);
298
306
  * ```
299
307
  */
300
308
  async sora(params) {
301
- const taskResult = await this.client.request("/api/sora/video", {
309
+ return this.client.request("/api/sora/video", {
302
310
  attachment: params.attachment,
303
311
  prompt: params.prompt,
304
312
  orientation: params.orientation
305
313
  });
306
- return taskResult.response;
307
314
  }
308
315
  /**
309
316
  * Generate video using Sora Stable API
310
317
  * @see /api/sora/video/stable
311
318
  */
312
319
  async soraStable(params) {
313
- const taskResult = await this.client.request("/api/sora/video/stable", {
320
+ return this.client.request("/api/sora/video/stable", {
314
321
  attachment: params.attachment,
315
322
  prompt: params.prompt,
316
323
  size: params.size,
317
324
  seconds: params.seconds
318
325
  });
319
- return taskResult.response;
320
326
  }
321
327
  /**
322
328
  * Generate video using Veo API
@@ -332,7 +338,7 @@ var VideoAPI = class {
332
338
  * ```
333
339
  */
334
340
  async veo(params) {
335
- const taskResult = await this.client.request("/api/veo/video", {
341
+ return this.client.request("/api/veo/video", {
336
342
  prompt: params.prompt,
337
343
  attachment: params.attachment,
338
344
  first_frame: params.first_frame,
@@ -341,7 +347,6 @@ var VideoAPI = class {
341
347
  resolution: params.resolution,
342
348
  duration: params.duration
343
349
  });
344
- return taskResult.response;
345
350
  }
346
351
  /**
347
352
  * Generate video using Kling API
@@ -358,14 +363,13 @@ var VideoAPI = class {
358
363
  * ```
359
364
  */
360
365
  async kling(params) {
361
- const taskResult = await this.client.request("/api/kling/video", {
366
+ return this.client.request("/api/kling/video", {
362
367
  attachment: params.attachment,
363
368
  prompt: params.prompt,
364
369
  aspect_ratio: params.aspect_ratio,
365
370
  duration: params.duration,
366
371
  model: params.model
367
372
  });
368
- return taskResult.response;
369
373
  }
370
374
  /**
371
375
  * Generate video using JiMeng API
@@ -381,13 +385,12 @@ var VideoAPI = class {
381
385
  * ```
382
386
  */
383
387
  async jimeng(params) {
384
- const taskResult = await this.client.request("/api/jimeng/video", {
388
+ return this.client.request("/api/jimeng/video", {
385
389
  action: params.action,
386
390
  attachment: params.attachment,
387
391
  prompt: params.prompt,
388
392
  aspect_ratio: params.aspect_ratio
389
393
  });
390
- return taskResult.response;
391
394
  }
392
395
  /**
393
396
  * Generate video using Doubao API
@@ -403,7 +406,7 @@ var VideoAPI = class {
403
406
  * ```
404
407
  */
405
408
  async doubao(params) {
406
- const taskResult = await this.client.request("/api/doubao/video", {
409
+ return this.client.request("/api/doubao/video", {
407
410
  action: params.action,
408
411
  attachment: params.attachment,
409
412
  prompt: params.prompt,
@@ -411,7 +414,6 @@ var VideoAPI = class {
411
414
  ratio: params.ratio,
412
415
  duration: params.duration
413
416
  });
414
- return taskResult.response;
415
417
  }
416
418
  /**
417
419
  * Generate video using Wan API (Alibaba)
@@ -428,7 +430,7 @@ var VideoAPI = class {
428
430
  * ```
429
431
  */
430
432
  async wan(params) {
431
- const taskResult = await this.client.request("/api/wan/video", {
433
+ return this.client.request("/api/wan/video", {
432
434
  attachment: params.attachment,
433
435
  prompt: params.prompt,
434
436
  size: params.size,
@@ -436,7 +438,6 @@ var VideoAPI = class {
436
438
  model: params.model,
437
439
  shot_type: params.shot_type
438
440
  });
439
- return taskResult.response;
440
441
  }
441
442
  /**
442
443
  * Generate video using MiniMax API
@@ -452,14 +453,13 @@ var VideoAPI = class {
452
453
  * ```
453
454
  */
454
455
  async minimax(params) {
455
- const taskResult = await this.client.request("/api/minimax/video", {
456
+ return this.client.request("/api/minimax/video", {
456
457
  attachment: params.attachment,
457
458
  prompt: params.prompt,
458
459
  size: params.size,
459
460
  duration: params.duration,
460
461
  model: params.model
461
462
  });
462
- return taskResult.response;
463
463
  }
464
464
  };
465
465
 
@@ -479,119 +479,111 @@ var DocumentAPI = class {
479
479
  * source_language: { value: 'en', label: 'English' },
480
480
  * target_language: { value: 'zh', label: 'Chinese' }
481
481
  * });
482
+ * console.log('Task folder:', result.taskFolder);
482
483
  * ```
483
484
  */
484
485
  async translate(params) {
485
- const taskResult = await this.client.request("/api/doc/translate", {
486
+ return this.client.request("/api/doc/translate", {
486
487
  attachment: params.attachment,
487
488
  source_language: params.source_language,
488
489
  target_language: params.target_language
489
490
  });
490
- return taskResult.response;
491
491
  }
492
492
  /**
493
493
  * Convert image to Word document
494
494
  * @see /api/doc_convert/image2word
495
495
  */
496
496
  async image2Word(params) {
497
- const taskResult = await this.client.request(
497
+ return this.client.request(
498
498
  "/api/doc_convert/image2word",
499
499
  {
500
500
  attachment: params.attachment
501
501
  }
502
502
  );
503
- return taskResult.response;
504
503
  }
505
504
  /**
506
505
  * Convert image to PowerPoint
507
506
  * @see /api/doc_convert/image2ppt
508
507
  */
509
508
  async image2Ppt(params) {
510
- const taskResult = await this.client.request(
509
+ return this.client.request(
511
510
  "/api/doc_convert/image2ppt",
512
511
  {
513
512
  attachment: params.attachment
514
513
  }
515
514
  );
516
- return taskResult.response;
517
515
  }
518
516
  /**
519
517
  * Convert image to Excel
520
518
  * @see /api/doc_convert/image2excel
521
519
  */
522
520
  async image2Excel(params) {
523
- const taskResult = await this.client.request(
521
+ return this.client.request(
524
522
  "/api/doc_convert/image2excel",
525
523
  {
526
524
  attachment: params.attachment
527
525
  }
528
526
  );
529
- return taskResult.response;
530
527
  }
531
528
  /**
532
529
  * Convert image to PDF
533
530
  * @see /api/doc_convert/image2pdf
534
531
  */
535
532
  async image2Pdf(params) {
536
- const taskResult = await this.client.request(
533
+ return this.client.request(
537
534
  "/api/doc_convert/image2pdf",
538
535
  {
539
536
  attachment: params.attachment
540
537
  }
541
538
  );
542
- return taskResult.response;
543
539
  }
544
540
  /**
545
541
  * Convert PDF to Word document
546
542
  * @see /api/doc_convert/pdf2word
547
543
  */
548
544
  async pdf2Word(params) {
549
- const taskResult = await this.client.request(
545
+ return this.client.request(
550
546
  "/api/doc_convert/pdf2word",
551
547
  {
552
548
  attachment: params.attachment
553
549
  }
554
550
  );
555
- return taskResult.response;
556
551
  }
557
552
  /**
558
553
  * Convert PDF to PowerPoint
559
554
  * @see /api/doc_convert/pdf2ppt
560
555
  */
561
556
  async pdf2Ppt(params) {
562
- const taskResult = await this.client.request(
557
+ return this.client.request(
563
558
  "/api/doc_convert/pdf2ppt",
564
559
  {
565
560
  attachment: params.attachment
566
561
  }
567
562
  );
568
- return taskResult.response;
569
563
  }
570
564
  /**
571
565
  * Convert PDF to Excel
572
566
  * @see /api/doc_convert/pdf2excel
573
567
  */
574
568
  async pdf2Excel(params) {
575
- const taskResult = await this.client.request(
569
+ return this.client.request(
576
570
  "/api/doc_convert/pdf2excel",
577
571
  {
578
572
  attachment: params.attachment
579
573
  }
580
574
  );
581
- return taskResult.response;
582
575
  }
583
576
  /**
584
577
  * Convert PDF to image
585
578
  * @see /api/doc_convert/pdf2image
586
579
  */
587
580
  async pdf2Image(params) {
588
- const taskResult = await this.client.request(
581
+ return this.client.request(
589
582
  "/api/doc_convert/pdf2image",
590
583
  {
591
584
  attachment: params.attachment
592
585
  }
593
586
  );
594
- return taskResult.response;
595
587
  }
596
588
  /**
597
589
  * Generic document conversion
@@ -601,12 +593,11 @@ var DocumentAPI = class {
601
593
  async convert(params) {
602
594
  const isImage = params.input_format === "image" || !params.input_format;
603
595
  const endpoint = isImage ? "/api/doc_convert/image" : "/api/doc_convert/pdf";
604
- const taskResult = await this.client.request(endpoint, {
596
+ return this.client.request(endpoint, {
605
597
  attachment: params.attachment,
606
598
  input_format: params.input_format,
607
599
  output_format: params.output_format
608
600
  });
609
- return taskResult.response;
610
601
  }
611
602
  };
612
603
 
@@ -630,13 +621,15 @@ var MediaAPI = class {
630
621
  * const result = await client.media.analyze({
631
622
  * url: [{ tmp_url: 'https://...', type: 'video/mp4', name: 'video.mp4' }]
632
623
  * });
624
+ *
625
+ * console.log('Task folder:', result.taskFolder);
626
+ * console.log('Summary:', result.response.data?.summary);
633
627
  * ```
634
628
  */
635
629
  async analyze(params) {
636
- const taskResult = await this.client.request("/api/media_analysis", {
630
+ return this.client.request("/api/media_analysis", {
637
631
  url: params.url
638
632
  });
639
- return taskResult.response;
640
633
  }
641
634
  /**
642
635
  * Analyze video file directly
@@ -651,7 +644,7 @@ var MediaAPI = class {
651
644
  * ```
652
645
  */
653
646
  async analyzeVideo(params) {
654
- const taskResult = await this.client.request("/api/media_analysis", {
647
+ return this.client.request("/api/media_analysis", {
655
648
  url: [
656
649
  {
657
650
  tmp_url: params.file.tmp_url,
@@ -661,7 +654,6 @@ var MediaAPI = class {
661
654
  }
662
655
  ]
663
656
  });
664
- return taskResult.response;
665
657
  }
666
658
  /**
667
659
  * Analyze social media video (TikTok, YouTube, etc.)
@@ -675,10 +667,9 @@ var MediaAPI = class {
675
667
  * ```
676
668
  */
677
669
  async analyzeSocialVideo(params) {
678
- const taskResult = await this.client.request("/api/media_analysis", {
670
+ return this.client.request("/api/media_analysis", {
679
671
  url: [{ link: params.url, type: "url" }]
680
672
  });
681
- return taskResult.response;
682
673
  }
683
674
  };
684
675
 
@@ -695,21 +686,16 @@ var UnityClawClient = class {
695
686
  document;
696
687
  media;
697
688
  constructor(config = {}) {
698
- const apiKey = config.apiKey ?? process.env.UNITYCLAW_API_KEY ?? "";
699
- const baseUrl = config.baseUrl ?? process.env.UNITYCLAW_BASE_URL ?? DEFAULT_BASE_URL;
689
+ const fileConfig = loadConfig();
690
+ const apiKey = config.apiKey ?? process.env.UNITYCLAW_API_KEY ?? fileConfig.apiKey ?? "";
691
+ const baseUrl = config.baseUrl ?? process.env.UNITYCLAW_BASE_URL ?? fileConfig.baseUrl ?? DEFAULT_BASE_URL;
700
692
  if (!apiKey) {
701
693
  throw new Error("API key is required. Set UNITYCLAW_API_KEY environment variable or pass apiKey in config.");
702
694
  }
703
695
  this.config = {
704
696
  apiKey,
705
697
  baseUrl,
706
- taskDir: config.taskDir ?? (() => {
707
- try {
708
- return path.join(process.cwd(), "tasks");
709
- } catch {
710
- return path.join(os.homedir(), "tasks");
711
- }
712
- })(),
698
+ taskDir: config.taskDir ?? fileConfig.taskDir ?? DEFAULT_TASKS_DIR,
713
699
  timeout: config.timeout ?? DEFAULT_TIMEOUT,
714
700
  downloadAttachments: config.downloadAttachments ?? true,
715
701
  context: config.context ?? {}
@@ -886,10 +872,18 @@ var UnityClawClient = class {
886
872
  }
887
873
  };
888
874
  export {
875
+ CONFIG_DIR,
876
+ CONFIG_FILE,
877
+ DEFAULT_TASKS_DIR,
889
878
  DocumentAPI,
890
879
  ImageAPI,
891
880
  MediaAPI,
892
881
  TaskFolderManager,
893
882
  UnityClawClient,
894
- VideoAPI
883
+ VideoAPI,
884
+ getConfigPath,
885
+ getConfigValue,
886
+ loadConfig,
887
+ saveConfig,
888
+ setConfigValue
895
889
  };
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@unityclaw/sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Node.js SDK for UnityClaw API - AI-powered image/video generation, media analysis, and more",
5
5
  "type": "module",
6
+ "bin": {
7
+ "unityclaw-sdk": "./dist/cli.js"
8
+ },
6
9
  "main": "./dist/index.cjs",
7
10
  "module": "./dist/index.js",
8
11
  "types": "./dist/index.d.ts",
@@ -15,11 +18,12 @@
15
18
  },
16
19
  "files": [
17
20
  "dist",
18
- "README.md"
21
+ "README.md",
22
+ "src/cli.ts"
19
23
  ],
20
24
  "scripts": {
21
- "build": "tsup src/index.ts --format cjs,esm --dts --clean",
22
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
25
+ "build": "tsup src/index.ts src/cli.ts --format cjs,esm --dts --clean",
26
+ "dev": "tsup src/index.ts src/cli.ts --format cjs,esm --dts --watch",
23
27
  "typecheck": "tsc --noEmit",
24
28
  "prepublishOnly": "npm run build"
25
29
  },
package/src/cli.ts ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @unityclaw/sdk CLI
4
+ * Configuration management for UnityClaw SDK
5
+ */
6
+
7
+ import {
8
+ loadConfig,
9
+ setConfigValue,
10
+ getConfigValue,
11
+ getConfigPath,
12
+ } from './config.js';
13
+
14
+ const args = process.argv.slice(2);
15
+ const command = args[0];
16
+
17
+ function showHelp() {
18
+ console.log(`
19
+ @unityclaw/sdk CLI - Configuration Management
20
+
21
+ Usage:
22
+ unityclaw-sdk config Show current configuration
23
+ unityclaw-sdk config set <key> <value> Set a configuration value
24
+ unityclaw-sdk config get <key> Get a configuration value
25
+ unityclaw-sdk config list List all configuration
26
+
27
+ Configuration keys:
28
+ apiKey API key for UnityClaw
29
+ baseUrl Base URL for API (default: https://unityclaw.com)
30
+ taskDir Directory for task folders (default: ~/.unityclaw/tasks)
31
+
32
+ Examples:
33
+ unityclaw-sdk config set apiKey your-api-key
34
+ unityclaw-sdk config set baseUrl https://custom.example.com
35
+ unityclaw-sdk config get apiKey
36
+ unityclaw-sdk config list
37
+ `);
38
+ }
39
+
40
+ if (!command || command === 'help' || command === '--help' || command === '-h') {
41
+ showHelp();
42
+ process.exit(0);
43
+ }
44
+
45
+ if (command === 'config') {
46
+ const action = args[1];
47
+ const key = args[2];
48
+ const value = args[3];
49
+
50
+ if (!action) {
51
+ // Show current config
52
+ const config = loadConfig();
53
+ console.log('\nCurrent configuration:\n');
54
+ console.log(` Config file: ${getConfigPath()}\n`);
55
+ if (Object.keys(config).length === 0) {
56
+ console.log(' (empty - no configuration set)\n');
57
+ } else {
58
+ for (const [k, v] of Object.entries(config)) {
59
+ // Mask API key for security
60
+ const displayValue = k === 'apiKey' && v
61
+ ? `${String(v).slice(0, 8)}...${String(v).slice(-4)}`
62
+ : v;
63
+ console.log(` ${k}: ${displayValue}`);
64
+ }
65
+ console.log();
66
+ }
67
+ } else if (action === 'set' && key && value) {
68
+ setConfigValue(key, value);
69
+ console.log(`✅ Config saved to ${getConfigPath()}`);
70
+ } else if (action === 'get' && key) {
71
+ const val = getConfigValue(key);
72
+ if (val) {
73
+ console.log(val);
74
+ } else {
75
+ console.log(`(not set)`);
76
+ }
77
+ } else if (action === 'list') {
78
+ const config = loadConfig();
79
+ console.log('\nConfiguration:\n');
80
+ for (const [k, v] of Object.entries(config)) {
81
+ const displayValue = k === 'apiKey' && v
82
+ ? `${String(v).slice(0, 8)}...${String(v).slice(-4)}`
83
+ : v;
84
+ console.log(` ${k}: ${displayValue}`);
85
+ }
86
+ console.log();
87
+ } else {
88
+ console.error('Invalid usage. Run `unityclaw-sdk config --help` for help.');
89
+ process.exit(1);
90
+ }
91
+ } else {
92
+ console.error(`Unknown command: ${command}`);
93
+ showHelp();
94
+ process.exit(1);
95
+ }