@assethub/cli 0.1.4 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/index.js +94 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14,26 +14,32 @@ const defaultPartExtractorName = 'V1.5';
14
14
  const partExtractorOptions = [
15
15
  {
16
16
  publicName: 'Part Extractor V3',
17
+ apiValue: 'ah_part_extractor_v3',
17
18
  aliases: ['part extractor v3', 'v3'],
18
19
  },
19
20
  {
20
21
  publicName: 'V1',
22
+ apiValue: 'ah_part_extractor_v5',
21
23
  aliases: ['v1', '1'],
22
24
  },
23
25
  {
24
26
  publicName: 'V1.5 alpha',
27
+ apiValue: 'ah_part_extractor_v55',
25
28
  aliases: ['v1.5 alpha', 'v1.5-alpha', '1.5 alpha', '1.5-alpha'],
26
29
  },
27
30
  {
28
31
  publicName: 'V1.5',
32
+ apiValue: 'ah_part_extractor_v65',
29
33
  aliases: ['v1.5', '1.5', 'latest', 'default'],
30
34
  },
31
35
  {
32
36
  publicName: 'V2.0 alpha',
37
+ apiValue: 'ah_part_extractor_v20_alpha',
33
38
  aliases: ['v2.0 alpha', 'v2 alpha', 'v2.0-alpha', 'v2-alpha', '2.0 alpha'],
34
39
  },
35
40
  {
36
41
  publicName: 'V2.1 alpha',
42
+ apiValue: 'ah_part_extractor_v21_alpha',
37
43
  aliases: ['v2.1 alpha', 'v2.1-alpha', '2.1 alpha'],
38
44
  },
39
45
  ];
@@ -41,13 +47,14 @@ const partExtractorPublicNames = partExtractorOptions
41
47
  .map(option => option.publicName)
42
48
  .join(', ');
43
49
  const normalizePartExtractorName = (value) => value.trim().toLowerCase().replace(/\s+/g, ' ');
44
- const partExtractorPublicNameByInput = new Map(partExtractorOptions.flatMap(option => [
45
- [normalizePartExtractorName(option.publicName), option.publicName],
50
+ const partExtractorByInput = new Map(partExtractorOptions.flatMap(option => [
51
+ [normalizePartExtractorName(option.publicName), option],
46
52
  ...option.aliases.map(alias => [
47
53
  normalizePartExtractorName(alias),
48
- option.publicName,
54
+ option,
49
55
  ]),
50
56
  ]));
57
+ const partExtractorPublicNameByApiValue = new Map(partExtractorOptions.map(option => [option.apiValue, option.publicName]));
51
58
  const isInternalPartExtractorId = (value) => value.trim().includes('_');
52
59
  const execFileAsync = promisify(execFile);
53
60
  const usage = `AssetHub CLI
@@ -173,18 +180,29 @@ const resolvePartExtractorPublicName = (value) => {
173
180
  if (isInternalPartExtractorId(value)) {
174
181
  throw new Error(`Internal part extractor IDs are not accepted by the public CLI. Use one of: ${partExtractorPublicNames}.`);
175
182
  }
176
- const publicName = partExtractorPublicNameByInput.get(normalizePartExtractorName(value));
177
- if (publicName == null) {
183
+ const option = partExtractorByInput.get(normalizePartExtractorName(value));
184
+ if (option == null) {
178
185
  throw new Error(`Unknown part extractor: ${value}. Use one of: ${partExtractorPublicNames}.`);
179
186
  }
180
- return publicName;
187
+ return option.publicName;
181
188
  };
182
- const resolvePartExtractorForAnalyze = (flags) => resolvePartExtractorPublicName(getPartExtractorFlag(flags) ?? defaultPartExtractorName);
189
+ const resolvePartExtractorApiValue = (value) => {
190
+ if (isInternalPartExtractorId(value)) {
191
+ throw new Error(`Internal part extractor IDs are not accepted by the public CLI. Use one of: ${partExtractorPublicNames}.`);
192
+ }
193
+ const option = partExtractorByInput.get(normalizePartExtractorName(value));
194
+ if (option == null) {
195
+ throw new Error(`Unknown part extractor: ${value}. Use one of: ${partExtractorPublicNames}.`);
196
+ }
197
+ return option.apiValue;
198
+ };
199
+ const resolvePartExtractorForAnalyze = (flags) => resolvePartExtractorApiValue(getPartExtractorFlag(flags) ?? defaultPartExtractorName);
183
200
  const publicPartExtractorName = (value) => {
184
201
  if (value == null) {
185
202
  return null;
186
203
  }
187
- return (isInternalPartExtractorId(value) ? 'Unknown' : value);
204
+ return (partExtractorPublicNameByApiValue.get(value) ??
205
+ (isInternalPartExtractorId(value) ? 'Unknown' : value));
188
206
  };
189
207
  const sanitizeProductionOutput = (value) => {
190
208
  if (Array.isArray(value)) {
@@ -419,6 +437,61 @@ const extensionFromMimeType = (mimeType, mediaType) => {
419
437
  return 'gltf';
420
438
  return mediaType === 'image' ? 'png' : 'glb';
421
439
  };
440
+ const contentTypeFromExtension = (extension) => {
441
+ switch (extension.toLowerCase()) {
442
+ case 'png':
443
+ return 'image/png';
444
+ case 'jpg':
445
+ case 'jpeg':
446
+ return 'image/jpeg';
447
+ case 'webp':
448
+ return 'image/webp';
449
+ case 'gif':
450
+ return 'image/gif';
451
+ case 'bmp':
452
+ return 'image/bmp';
453
+ case 'tif':
454
+ case 'tiff':
455
+ return 'image/tiff';
456
+ case 'glb':
457
+ return 'model/gltf-binary';
458
+ case 'gltf':
459
+ return 'model/gltf+json';
460
+ case 'obj':
461
+ return 'model/obj';
462
+ case 'fbx':
463
+ return 'application/fbx';
464
+ case 'stl':
465
+ return 'model/stl';
466
+ case 'ply':
467
+ return 'text/plain';
468
+ case 'usdz':
469
+ return 'model/vnd.usdz+zip';
470
+ case 'usd':
471
+ case 'usdc':
472
+ return 'model/vnd.usd';
473
+ default:
474
+ return undefined;
475
+ }
476
+ };
477
+ const isNonspecificContentType = (contentType) => {
478
+ const clean = contentType?.split(';')[0]?.trim().toLowerCase() ?? '';
479
+ return (clean === '' ||
480
+ clean === 'application/octet-stream' ||
481
+ clean === 'binary/octet-stream');
482
+ };
483
+ const inferContentTypeFromFileName = (fileName) => {
484
+ const extension = extname(fileName).replace(/^\./, '');
485
+ if (extension === '')
486
+ return undefined;
487
+ return contentTypeFromExtension(extension);
488
+ };
489
+ const resolveUploadContentType = (fileName, explicitContentType) => {
490
+ if (!isNonspecificContentType(explicitContentType)) {
491
+ return explicitContentType;
492
+ }
493
+ return inferContentTypeFromFileName(fileName);
494
+ };
422
495
  const ensureFileNameExtension = (fileName, mediaType, mimeType) => {
423
496
  if (extname(fileName) !== '') {
424
497
  return fileName;
@@ -681,15 +754,19 @@ const uploadSourceDescriptor = async ({ descriptor, client, mediaType, }) => {
681
754
  if (descriptor.kind === 'source') {
682
755
  return descriptor.source;
683
756
  }
684
- const file = descriptor.kind === 'file'
685
- ? await readBlob(descriptor.path, descriptor.contentType)
686
- : descriptor.blob;
687
757
  const fileName = descriptor.kind === 'file'
688
758
  ? basename(descriptor.path)
689
759
  : descriptor.fileName;
760
+ const fileNameWithExtension = ensureFileNameExtension(fileName, mediaType, descriptor.contentType);
761
+ const contentType = resolveUploadContentType(fileNameWithExtension, descriptor.contentType);
762
+ const file = descriptor.kind === 'file'
763
+ ? await readBlob(descriptor.path, contentType)
764
+ : isNonspecificContentType(descriptor.blob.type) && contentType != null
765
+ ? new Blob([descriptor.blob], { type: contentType })
766
+ : descriptor.blob;
690
767
  const upload = await client.v2.uploadFile({
691
768
  file,
692
- fileName: ensureFileNameExtension(fileName, mediaType, descriptor.contentType),
769
+ fileName: fileNameWithExtension,
693
770
  mediaType,
694
771
  });
695
772
  return { fileRef: upload.fileRef };
@@ -1131,11 +1208,12 @@ const resolvePartExtractorFromMission = async (ctx, orderId, missionId) => {
1131
1208
  throw new Error('Could not infer the part extractor from the mission. Pass --part-extractor with one of: ' +
1132
1209
  partExtractorPublicNames);
1133
1210
  }
1134
- if (isInternalPartExtractorId(mission.agentVersion)) {
1211
+ const publicName = publicPartExtractorName(mission.agentVersion);
1212
+ if (publicName == null || publicName === 'Unknown') {
1135
1213
  throw new Error('Could not infer the public part extractor from the mission. Pass --part-extractor with one of: ' +
1136
1214
  partExtractorPublicNames);
1137
1215
  }
1138
- return resolvePartExtractorPublicName(mission.agentVersion);
1216
+ return resolvePartExtractorApiValue(publicName);
1139
1217
  };
1140
1218
  const redactUrl = (value) => {
1141
1219
  try {
@@ -1444,7 +1522,7 @@ const commandProduction = async (subcommand, positionals, ctx) => {
1444
1522
  const partExtractorFlag = getPartExtractorFlag(ctx.flags);
1445
1523
  const agentVersion = partExtractorFlag == null
1446
1524
  ? await resolvePartExtractorFromMission(ctx, orderId, missionId)
1447
- : resolvePartExtractorPublicName(partExtractorFlag);
1525
+ : resolvePartExtractorApiValue(partExtractorFlag);
1448
1526
  const executed = await ctx.client.v1.executeProduction({
1449
1527
  orderId,
1450
1528
  missionId,
@@ -1515,7 +1593,7 @@ const commandParts = async (subcommand, ctx) => {
1515
1593
  const partExtractorFlag = getPartExtractorFlag(ctx.flags);
1516
1594
  const agentVersion = partExtractorFlag == null
1517
1595
  ? await resolvePartExtractorFromMission(ctx, orderId, missionId)
1518
- : resolvePartExtractorPublicName(partExtractorFlag);
1596
+ : resolvePartExtractorApiValue(partExtractorFlag);
1519
1597
  const partExtractionMode = getFlag(ctx.flags, 'part-extraction-mode');
1520
1598
  if (partExtractionMode != null &&
1521
1599
  partExtractionMode !== 'fast' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assethub/cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Command line interface for AssetHub.",
5
5
  "type": "module",
6
6
  "bin": {