faces-cli 1.4.5 → 1.4.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.
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class CompileUpload extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
6
+ kind: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
+ perspective: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'face-speaker': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ };
13
+ static args: {
14
+ alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
15
+ };
16
+ run(): Promise<unknown>;
17
+ }
@@ -0,0 +1,66 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { BaseCommand } from '../../base.js';
5
+ import { FacesAPIError } from '../../client.js';
6
+ export default class CompileUpload extends BaseCommand {
7
+ static description = 'Upload a file (text/PDF/audio/video) to compile into a face';
8
+ static flags = {
9
+ ...BaseCommand.baseFlags,
10
+ file: Flags.string({ description: 'File to upload', required: true }),
11
+ kind: Flags.string({
12
+ description: 'Upload kind: document or thread',
13
+ options: ['document', 'thread'],
14
+ default: 'document',
15
+ }),
16
+ perspective: Flags.string({
17
+ description: 'Perspective (document only)',
18
+ options: ['first-person', 'third-person'],
19
+ default: 'third-person',
20
+ }),
21
+ 'face-speaker': Flags.string({
22
+ description: 'Speaker name to map to the face (thread only). If omitted, auto-detected from face name.',
23
+ }),
24
+ };
25
+ static args = {
26
+ alias: Args.string({ description: 'Face alias', required: true }),
27
+ };
28
+ async run() {
29
+ const { args, flags } = await this.parse(CompileUpload);
30
+ const client = this.makeClient(flags);
31
+ if (!fs.existsSync(flags.file))
32
+ this.error(`File not found: ${flags.file}`);
33
+ const filename = path.basename(flags.file);
34
+ const fileBlob = new Blob([fs.readFileSync(flags.file)], { type: 'application/octet-stream' });
35
+ const form = new FormData();
36
+ form.append('file', fileBlob, filename);
37
+ // type, perspective, face_speaker are query params (not form fields)
38
+ const params = new URLSearchParams();
39
+ params.set('type', flags.kind);
40
+ params.set('perspective', flags.perspective);
41
+ if (flags['face-speaker'])
42
+ params.set('face_speaker', flags['face-speaker']);
43
+ let data;
44
+ try {
45
+ data = await client.postForm(`/v1/faces/${args.alias}/upload?${params}`, form);
46
+ }
47
+ catch (err) {
48
+ if (err instanceof FacesAPIError)
49
+ this.error(`Error (${err.statusCode}): ${err.message}`);
50
+ throw err;
51
+ }
52
+ if (!this.jsonEnabled()) {
53
+ this.printHuman(data);
54
+ const res = data;
55
+ if (flags.kind === 'thread' && res.thread_id) {
56
+ this.log(`\nNext step:`);
57
+ this.log(` faces compile:thread:make ${res.thread_id}`);
58
+ }
59
+ else if (flags.kind === 'document' && res.document_id) {
60
+ this.log(`\nNext step:`);
61
+ this.log(` faces compile:doc:make ${res.document_id}`);
62
+ }
63
+ }
64
+ return data;
65
+ }
66
+ }