@faces-sh/cli 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/dev.js +5 -0
- package/bin/run.js +5 -0
- package/dist/base.d.ts +26 -0
- package/dist/base.js +181 -0
- package/dist/benchmark.d.ts +21 -0
- package/dist/benchmark.js +95 -0
- package/dist/billing.d.ts +17 -0
- package/dist/billing.js +101 -0
- package/dist/catalog.d.ts +35 -0
- package/dist/catalog.js +242 -0
- package/dist/client.d.ts +98 -0
- package/dist/client.js +590 -0
- package/dist/commands/account/preferences.d.ts +20 -0
- package/dist/commands/account/preferences.js +190 -0
- package/dist/commands/account/state.d.ts +11 -0
- package/dist/commands/account/state.js +24 -0
- package/dist/commands/auth/connect.d.ts +17 -0
- package/dist/commands/auth/connect.js +190 -0
- package/dist/commands/auth/connections.d.ts +12 -0
- package/dist/commands/auth/connections.js +40 -0
- package/dist/commands/auth/disconnect.d.ts +15 -0
- package/dist/commands/auth/disconnect.js +49 -0
- package/dist/commands/auth/login.d.ts +13 -0
- package/dist/commands/auth/login.js +42 -0
- package/dist/commands/auth/logout.d.ts +11 -0
- package/dist/commands/auth/logout.js +14 -0
- package/dist/commands/auth/refresh.d.ts +11 -0
- package/dist/commands/auth/refresh.js +30 -0
- package/dist/commands/auth/register.d.ts +15 -0
- package/dist/commands/auth/register.js +98 -0
- package/dist/commands/auth/whoami.d.ts +11 -0
- package/dist/commands/auth/whoami.js +108 -0
- package/dist/commands/benchmark/get.d.ts +16 -0
- package/dist/commands/benchmark/get.js +42 -0
- package/dist/commands/benchmark/list.d.ts +13 -0
- package/dist/commands/benchmark/list.js +47 -0
- package/dist/commands/benchmark/start.d.ts +22 -0
- package/dist/commands/benchmark/start.js +80 -0
- package/dist/commands/billing/balance.d.ts +11 -0
- package/dist/commands/billing/balance.js +27 -0
- package/dist/commands/billing/card/default.d.ts +15 -0
- package/dist/commands/billing/card/default.js +33 -0
- package/dist/commands/billing/card/remove.d.ts +16 -0
- package/dist/commands/billing/card/remove.js +41 -0
- package/dist/commands/billing/card-setup.d.ts +13 -0
- package/dist/commands/billing/card-setup.js +41 -0
- package/dist/commands/billing/cards.d.ts +11 -0
- package/dist/commands/billing/cards.js +34 -0
- package/dist/commands/billing/llm-costs.d.ts +14 -0
- package/dist/commands/billing/llm-costs.js +95 -0
- package/dist/commands/billing/subscription/activate.d.ts +14 -0
- package/dist/commands/billing/subscription/activate.js +91 -0
- package/dist/commands/billing/subscription/cancel.d.ts +12 -0
- package/dist/commands/billing/subscription/cancel.js +54 -0
- package/dist/commands/billing/subscription/index.d.ts +11 -0
- package/dist/commands/billing/subscription/index.js +46 -0
- package/dist/commands/billing/subscription/plan.d.ts +16 -0
- package/dist/commands/billing/subscription/plan.js +86 -0
- package/dist/commands/billing/topup.d.ts +16 -0
- package/dist/commands/billing/topup.js +60 -0
- package/dist/commands/billing/usage.d.ts +15 -0
- package/dist/commands/billing/usage.js +68 -0
- package/dist/commands/catalog/backup.d.ts +11 -0
- package/dist/commands/catalog/backup.js +169 -0
- package/dist/commands/catalog/doctor.d.ts +14 -0
- package/dist/commands/catalog/doctor.js +303 -0
- package/dist/commands/catalog/list.d.ts +11 -0
- package/dist/commands/catalog/list.js +39 -0
- package/dist/commands/catalog/restore.d.ts +17 -0
- package/dist/commands/catalog/restore.js +259 -0
- package/dist/commands/causes.d.ts +27 -0
- package/dist/commands/causes.js +135 -0
- package/dist/commands/chat/chat.d.ts +42 -0
- package/dist/commands/chat/chat.js +363 -0
- package/dist/commands/chat/messages.d.ts +26 -0
- package/dist/commands/chat/messages.js +139 -0
- package/dist/commands/chat/responses.d.ts +27 -0
- package/dist/commands/chat/responses.js +150 -0
- package/dist/commands/chat/thread.d.ts +43 -0
- package/dist/commands/chat/thread.js +458 -0
- package/dist/commands/compile/all.d.ts +14 -0
- package/dist/commands/compile/all.js +186 -0
- package/dist/commands/compile/doc/create.d.ts +19 -0
- package/dist/commands/compile/doc/create.js +58 -0
- package/dist/commands/compile/doc/delete.d.ts +15 -0
- package/dist/commands/compile/doc/delete.js +33 -0
- package/dist/commands/compile/doc/edit.d.ts +19 -0
- package/dist/commands/compile/doc/edit.js +59 -0
- package/dist/commands/compile/doc/get.d.ts +15 -0
- package/dist/commands/compile/doc/get.js +43 -0
- package/dist/commands/compile/doc/index.d.ts +24 -0
- package/dist/commands/compile/doc/index.js +211 -0
- package/dist/commands/compile/doc/list.d.ts +15 -0
- package/dist/commands/compile/doc/list.js +46 -0
- package/dist/commands/compile/doc/make.d.ts +17 -0
- package/dist/commands/compile/doc/make.js +95 -0
- package/dist/commands/compile/doc/pause.d.ts +17 -0
- package/dist/commands/compile/doc/pause.js +74 -0
- package/dist/commands/compile/doc/reset.d.ts +15 -0
- package/dist/commands/compile/doc/reset.js +33 -0
- package/dist/commands/compile/import.d.ts +20 -0
- package/dist/commands/compile/import.js +138 -0
- package/dist/commands/compile/stats.d.ts +11 -0
- package/dist/commands/compile/stats.js +75 -0
- package/dist/commands/compile/status.d.ts +17 -0
- package/dist/commands/compile/status.js +110 -0
- package/dist/commands/compile/thread/create.d.ts +16 -0
- package/dist/commands/compile/thread/create.js +42 -0
- package/dist/commands/compile/thread/delete.d.ts +15 -0
- package/dist/commands/compile/thread/delete.js +33 -0
- package/dist/commands/compile/thread/edit.d.ts +19 -0
- package/dist/commands/compile/thread/edit.js +120 -0
- package/dist/commands/compile/thread/get.d.ts +15 -0
- package/dist/commands/compile/thread/get.js +48 -0
- package/dist/commands/compile/thread/list.d.ts +14 -0
- package/dist/commands/compile/thread/list.js +38 -0
- package/dist/commands/compile/thread/make.d.ts +17 -0
- package/dist/commands/compile/thread/make.js +87 -0
- package/dist/commands/compile/thread/message.d.ts +16 -0
- package/dist/commands/compile/thread/message.js +43 -0
- package/dist/commands/compile/thread/pause.d.ts +17 -0
- package/dist/commands/compile/thread/pause.js +75 -0
- package/dist/commands/compile/thread/replace.d.ts +27 -0
- package/dist/commands/compile/thread/replace.js +114 -0
- package/dist/commands/compile/thread/reset.d.ts +15 -0
- package/dist/commands/compile/thread/reset.js +33 -0
- package/dist/commands/compile/upload.d.ts +21 -0
- package/dist/commands/compile/upload.js +162 -0
- package/dist/commands/config/clear.d.ts +12 -0
- package/dist/commands/config/clear.js +17 -0
- package/dist/commands/config/set.d.ts +15 -0
- package/dist/commands/config/set.js +43 -0
- package/dist/commands/config/show.d.ts +11 -0
- package/dist/commands/config/show.js +19 -0
- package/dist/commands/decide.d.ts +35 -0
- package/dist/commands/decide.js +242 -0
- package/dist/commands/face/attributes.d.ts +11 -0
- package/dist/commands/face/attributes.js +44 -0
- package/dist/commands/face/avatar/delete.d.ts +15 -0
- package/dist/commands/face/avatar/delete.js +38 -0
- package/dist/commands/face/avatar/get.d.ts +20 -0
- package/dist/commands/face/avatar/get.js +100 -0
- package/dist/commands/face/avatar/list.d.ts +14 -0
- package/dist/commands/face/avatar/list.js +56 -0
- package/dist/commands/face/avatar/make.d.ts +16 -0
- package/dist/commands/face/avatar/make.js +64 -0
- package/dist/commands/face/avatar/upload.d.ts +15 -0
- package/dist/commands/face/avatar/upload.js +67 -0
- package/dist/commands/face/create.d.ts +23 -0
- package/dist/commands/face/create.js +122 -0
- package/dist/commands/face/delete.d.ts +15 -0
- package/dist/commands/face/delete.js +39 -0
- package/dist/commands/face/diff.d.ts +12 -0
- package/dist/commands/face/diff.js +50 -0
- package/dist/commands/face/edit.d.ts +25 -0
- package/dist/commands/face/edit.js +155 -0
- package/dist/commands/face/get.d.ts +16 -0
- package/dist/commands/face/get.js +145 -0
- package/dist/commands/face/groups.d.ts +15 -0
- package/dist/commands/face/groups.js +34 -0
- package/dist/commands/face/list.d.ts +23 -0
- package/dist/commands/face/list.js +168 -0
- package/dist/commands/face/lock.d.ts +15 -0
- package/dist/commands/face/lock.js +35 -0
- package/dist/commands/face/neighbors.d.ts +16 -0
- package/dist/commands/face/neighbors.js +63 -0
- package/dist/commands/face/publish.d.ts +16 -0
- package/dist/commands/face/publish.js +42 -0
- package/dist/commands/face/share.d.ts +22 -0
- package/dist/commands/face/share.js +103 -0
- package/dist/commands/face/sources.d.ts +21 -0
- package/dist/commands/face/sources.js +169 -0
- package/dist/commands/face/stats.d.ts +12 -0
- package/dist/commands/face/stats.js +46 -0
- package/dist/commands/face/tag/add.d.ts +15 -0
- package/dist/commands/face/tag/add.js +40 -0
- package/dist/commands/face/tag/all.d.ts +11 -0
- package/dist/commands/face/tag/all.js +31 -0
- package/dist/commands/face/tag/list.d.ts +14 -0
- package/dist/commands/face/tag/list.js +36 -0
- package/dist/commands/face/tag/remove.d.ts +16 -0
- package/dist/commands/face/tag/remove.js +44 -0
- package/dist/commands/face/tag/set.d.ts +15 -0
- package/dist/commands/face/tag/set.js +40 -0
- package/dist/commands/face/unlock.d.ts +15 -0
- package/dist/commands/face/unlock.js +35 -0
- package/dist/commands/face/unpublish.d.ts +14 -0
- package/dist/commands/face/unpublish.js +31 -0
- package/dist/commands/face/unshare.d.ts +18 -0
- package/dist/commands/face/unshare.js +66 -0
- package/dist/commands/fidelity/get.d.ts +15 -0
- package/dist/commands/fidelity/get.js +42 -0
- package/dist/commands/fidelity/pick.d.ts +19 -0
- package/dist/commands/fidelity/pick.js +70 -0
- package/dist/commands/fidelity/run.d.ts +20 -0
- package/dist/commands/fidelity/run.js +99 -0
- package/dist/commands/fidelity/save-thread.d.ts +15 -0
- package/dist/commands/fidelity/save-thread.js +35 -0
- package/dist/commands/fidelity/start.d.ts +17 -0
- package/dist/commands/fidelity/start.js +56 -0
- package/dist/commands/fidelity/turn.d.ts +17 -0
- package/dist/commands/fidelity/turn.js +48 -0
- package/dist/commands/group/add.d.ts +16 -0
- package/dist/commands/group/add.js +83 -0
- package/dist/commands/group/create.d.ts +16 -0
- package/dist/commands/group/create.js +68 -0
- package/dist/commands/group/delete.d.ts +15 -0
- package/dist/commands/group/delete.js +39 -0
- package/dist/commands/group/edit.d.ts +18 -0
- package/dist/commands/group/edit.js +75 -0
- package/dist/commands/group/get.d.ts +14 -0
- package/dist/commands/group/get.js +29 -0
- package/dist/commands/group/list.d.ts +11 -0
- package/dist/commands/group/list.js +39 -0
- package/dist/commands/group/members.d.ts +15 -0
- package/dist/commands/group/members.js +68 -0
- package/dist/commands/group/remove.d.ts +15 -0
- package/dist/commands/group/remove.js +55 -0
- package/dist/commands/group/tag/add.d.ts +15 -0
- package/dist/commands/group/tag/add.js +30 -0
- package/dist/commands/group/tag/list.d.ts +14 -0
- package/dist/commands/group/tag/list.js +36 -0
- package/dist/commands/group/tag/remove.d.ts +15 -0
- package/dist/commands/group/tag/remove.js +30 -0
- package/dist/commands/group/tag/set.d.ts +15 -0
- package/dist/commands/group/tag/set.js +30 -0
- package/dist/commands/keys/create.d.ts +17 -0
- package/dist/commands/keys/create.js +72 -0
- package/dist/commands/keys/list.d.ts +11 -0
- package/dist/commands/keys/list.js +24 -0
- package/dist/commands/keys/revoke.d.ts +15 -0
- package/dist/commands/keys/revoke.js +49 -0
- package/dist/commands/keys/update.d.ts +17 -0
- package/dist/commands/keys/update.js +41 -0
- package/dist/commands/models/list.d.ts +15 -0
- package/dist/commands/models/list.js +98 -0
- package/dist/commands/session/close.d.ts +16 -0
- package/dist/commands/session/close.js +36 -0
- package/dist/commands/session/compact.d.ts +15 -0
- package/dist/commands/session/compact.js +58 -0
- package/dist/commands/session/create.d.ts +15 -0
- package/dist/commands/session/create.js +45 -0
- package/dist/commands/session/get.d.ts +15 -0
- package/dist/commands/session/get.js +34 -0
- package/dist/commands/style/delete.d.ts +19 -0
- package/dist/commands/style/delete.js +92 -0
- package/dist/commands/style/make.d.ts +28 -0
- package/dist/commands/style/make.js +298 -0
- package/dist/commands/style/revert.d.ts +17 -0
- package/dist/commands/style/revert.js +66 -0
- package/dist/commands/style/status.d.ts +20 -0
- package/dist/commands/style/status.js +109 -0
- package/dist/commands/style/upload.d.ts +19 -0
- package/dist/commands/style/upload.js +100 -0
- package/dist/commands/style/versions.d.ts +15 -0
- package/dist/commands/style/versions.js +104 -0
- package/dist/commands/user/follow.d.ts +14 -0
- package/dist/commands/user/follow.js +38 -0
- package/dist/commands/user/followers.d.ts +14 -0
- package/dist/commands/user/followers.js +50 -0
- package/dist/commands/user/following.d.ts +14 -0
- package/dist/commands/user/following.js +50 -0
- package/dist/commands/user/get.d.ts +14 -0
- package/dist/commands/user/get.js +49 -0
- package/dist/commands/user/unfollow.d.ts +14 -0
- package/dist/commands/user/unfollow.js +38 -0
- package/dist/config.d.ts +32 -0
- package/dist/config.js +139 -0
- package/dist/decisions.d.ts +42 -0
- package/dist/decisions.js +262 -0
- package/dist/fidelity.d.ts +50 -0
- package/dist/fidelity.js +92 -0
- package/dist/group-catalog.d.ts +22 -0
- package/dist/group-catalog.js +133 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +8 -0
- package/dist/poll.d.ts +26 -0
- package/dist/poll.js +75 -0
- package/dist/routing.d.ts +15 -0
- package/dist/routing.js +135 -0
- package/dist/session.d.ts +14 -0
- package/dist/session.js +18 -0
- package/dist/style.d.ts +46 -0
- package/dist/style.js +285 -0
- package/dist/utils.d.ts +149 -0
- package/dist/utils.js +865 -0
- package/oclif.manifest.json +11070 -0
- package/package.json +127 -4
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { MEDIUM_MISSING_MESSAGE, MEDIUM_REQUIRED_DESCRIPTION, seg } from '../../utils.js';
|
|
5
|
+
function sleep(ms) {
|
|
6
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7
|
+
}
|
|
8
|
+
export default class CompileImport extends BaseCommand {
|
|
9
|
+
static description = 'Import a YouTube video into a face via server-side download and transcription';
|
|
10
|
+
static flags = {
|
|
11
|
+
...BaseCommand.baseFlags,
|
|
12
|
+
url: Flags.string({
|
|
13
|
+
description: 'YouTube URL (youtube.com/watch?v=... or youtu.be/...)',
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
type: Flags.string({
|
|
17
|
+
description: '"document" for the face speaking alone (a talk, a lecture, a monologue); "thread" for an interview ' +
|
|
18
|
+
'or any recording with more than one speaker, so only the face\'s turns are used. A recording with ' +
|
|
19
|
+
'other speakers imported as a document is read as entirely the face\'s words.',
|
|
20
|
+
options: ['document', 'thread'],
|
|
21
|
+
default: 'document',
|
|
22
|
+
}),
|
|
23
|
+
perspective: Flags.string({
|
|
24
|
+
description: '"first-person" if the face is the speaker; "third-person" if the video is about the face',
|
|
25
|
+
options: ['first-person', 'third-person'],
|
|
26
|
+
default: 'third-person',
|
|
27
|
+
}),
|
|
28
|
+
medium: Flags.string({
|
|
29
|
+
description: MEDIUM_REQUIRED_DESCRIPTION + ' Required with --type document, and only valid with it.',
|
|
30
|
+
}),
|
|
31
|
+
'face-speaker': Flags.string({
|
|
32
|
+
description: 'For --type thread: the speaker label (e.g. "A") that is the face. Defaults to the first detected speaker.',
|
|
33
|
+
}),
|
|
34
|
+
'no-wait': Flags.boolean({
|
|
35
|
+
description: 'Return immediately after import starts (do not poll for transcription). Prints the ID for manual polling.',
|
|
36
|
+
default: false,
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
static args = {
|
|
40
|
+
face_id: Args.string({ description: 'Face alias', required: true }),
|
|
41
|
+
};
|
|
42
|
+
async run() {
|
|
43
|
+
const { args, flags } = await this.parse(CompileImport);
|
|
44
|
+
const client = this.makeClient(flags);
|
|
45
|
+
const json = this.jsonEnabled();
|
|
46
|
+
if (flags['face-speaker'] && flags.type !== 'thread') {
|
|
47
|
+
this.error('--face-speaker is only valid with --type thread');
|
|
48
|
+
}
|
|
49
|
+
if (flags.medium && flags.type !== 'document') {
|
|
50
|
+
this.error(`--medium applies to --type document only (got --type ${flags.type}); a thread carries a kind per message.`);
|
|
51
|
+
}
|
|
52
|
+
if (!flags.medium && flags.type === 'document')
|
|
53
|
+
this.error(MEDIUM_MISSING_MESSAGE);
|
|
54
|
+
const payload = {
|
|
55
|
+
url: flags.url,
|
|
56
|
+
type: flags.type,
|
|
57
|
+
perspective: flags.perspective,
|
|
58
|
+
};
|
|
59
|
+
if (flags['face-speaker'])
|
|
60
|
+
payload.face_speaker = flags['face-speaker'];
|
|
61
|
+
if (flags.medium)
|
|
62
|
+
payload.medium = flags.medium;
|
|
63
|
+
if (!json)
|
|
64
|
+
process.stderr.write('Importing (downloading + transcribing in background)...\n');
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
data = await client.post(`/v1/faces/${seg(args.face_id)}/import`, { body: payload });
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (err instanceof FacesAPIError) {
|
|
71
|
+
if (err.statusCode === 422 && flags.type === 'thread') {
|
|
72
|
+
this.error(`${err.message}. Try again with --type document`);
|
|
73
|
+
}
|
|
74
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
75
|
+
}
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
if (data.status === 'transcribing' && flags['no-wait']) {
|
|
79
|
+
const id = (data.thread_id ?? data.document_id);
|
|
80
|
+
if (!json) {
|
|
81
|
+
process.stderr.write(`Import started in background (downloading + transcribing).\n`);
|
|
82
|
+
process.stderr.write(`Poll with: faces compile:${flags.type === 'thread' ? 'thread' : 'doc'}:get ${id} --json\n`);
|
|
83
|
+
}
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
if (data.status === 'transcribing') {
|
|
87
|
+
const id = (data.thread_id ?? data.document_id);
|
|
88
|
+
const endpoint = flags.type === 'thread'
|
|
89
|
+
? `/v1/compile/threads/${seg(id)}`
|
|
90
|
+
: `/v1/compile/documents/${seg(id)}`;
|
|
91
|
+
const timeout = 3600_000;
|
|
92
|
+
const start = Date.now();
|
|
93
|
+
while (Date.now() - start < timeout) {
|
|
94
|
+
await sleep(5000);
|
|
95
|
+
try {
|
|
96
|
+
const poll = await client.get(endpoint);
|
|
97
|
+
const status = poll.status;
|
|
98
|
+
if (status !== 'transcribing') {
|
|
99
|
+
data = poll;
|
|
100
|
+
if (!json) {
|
|
101
|
+
if (status === 'failed') {
|
|
102
|
+
process.stderr.write('Transcription failed.\n');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const msgCount = poll.message_count ?? poll.token_count ?? 0;
|
|
106
|
+
process.stderr.write(`Transcription complete: ${msgCount} ${flags.type === 'thread' ? 'messages' : 'tokens'}\n`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (!json)
|
|
112
|
+
process.stderr.write('Transcribing...\n');
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!json) {
|
|
119
|
+
if (data.thread_id) {
|
|
120
|
+
this.log(`\nImported as thread: ${data.thread_id}`);
|
|
121
|
+
this.log(`label: ${data.label ?? 'youtube-import'}`);
|
|
122
|
+
this.log(`\nReview the transcript:`);
|
|
123
|
+
this.log(` faces compile:thread:get ${data.thread_id}`);
|
|
124
|
+
this.log(`\nWhen ready to compile:`);
|
|
125
|
+
this.log(` faces compile:thread:make ${data.thread_id}`);
|
|
126
|
+
}
|
|
127
|
+
else if (data.document_id) {
|
|
128
|
+
this.log(`\nImported as document: ${data.document_id}`);
|
|
129
|
+
this.log(`label: ${data.label ?? 'youtube-import'}`);
|
|
130
|
+
this.log(`\nReview the document:`);
|
|
131
|
+
this.log(` faces compile:doc:get ${data.document_id}`);
|
|
132
|
+
this.log(`\nWhen ready to compile:`);
|
|
133
|
+
this.log(` faces compile:doc:make ${data.document_id}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class CompileStats extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
import { FacesAPIError } from '../../client.js';
|
|
3
|
+
import { readableLimit } from '../../utils.js';
|
|
4
|
+
export default class CompileStats extends BaseCommand {
|
|
5
|
+
static description = 'Show compile usage: your plan, the source tokens compiled this month against its allowance, and the ' +
|
|
6
|
+
'compile rates, standard and rush. For one face\'s numbers, that is face:stats; for what is compiling right ' +
|
|
7
|
+
'now, compile:status.';
|
|
8
|
+
static flags = {
|
|
9
|
+
...BaseCommand.baseFlags,
|
|
10
|
+
};
|
|
11
|
+
async run() {
|
|
12
|
+
const { flags } = await this.parse(CompileStats);
|
|
13
|
+
const client = this.makeClient(flags);
|
|
14
|
+
let sub;
|
|
15
|
+
let rates;
|
|
16
|
+
try {
|
|
17
|
+
;
|
|
18
|
+
[sub, rates] = (await Promise.all([
|
|
19
|
+
client.get('/v1/billing/subscription'),
|
|
20
|
+
client.get('/v1/rates'),
|
|
21
|
+
]));
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err instanceof FacesAPIError)
|
|
25
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
const plan = typeof sub.plan === 'string' ? sub.plan : 'free';
|
|
29
|
+
const allowances = (sub.allowances ?? null);
|
|
30
|
+
const compile = allowances?.compile_month && allowances.compile_month.limit !== 0 ? allowances.compile_month : null;
|
|
31
|
+
const compileRates = (rates.compile ?? {});
|
|
32
|
+
const usdPerMillion = typeof compileRates.usd_per_million_source_tokens === 'number'
|
|
33
|
+
? compileRates.usd_per_million_source_tokens
|
|
34
|
+
: undefined;
|
|
35
|
+
const rushPerMillion = typeof compileRates.rush_usd_per_million_source_tokens === 'number'
|
|
36
|
+
? compileRates.rush_usd_per_million_source_tokens
|
|
37
|
+
: undefined;
|
|
38
|
+
const data = {
|
|
39
|
+
plan,
|
|
40
|
+
compile_this_month: compile,
|
|
41
|
+
pay_as_you_go: { usd_per_million_source_tokens: usdPerMillion },
|
|
42
|
+
rush: { usd_per_million_source_tokens: rushPerMillion },
|
|
43
|
+
};
|
|
44
|
+
if (!this.jsonEnabled()) {
|
|
45
|
+
const lines = [`Plan: ${plan}`];
|
|
46
|
+
if (compile) {
|
|
47
|
+
const unlimited = typeof compile.limit === 'number' && compile.limit < 0;
|
|
48
|
+
const used = (compile.used ?? 0).toLocaleString('en-US');
|
|
49
|
+
if (unlimited) {
|
|
50
|
+
lines.push(`Compiled this month: ${used} source tokens (${readableLimit(compile.limit)})`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const limit = (compile.limit ?? 0).toLocaleString('en-US');
|
|
54
|
+
const pct = compile.limit ? ` (${Math.round(((compile.used ?? 0) / compile.limit) * 100)}%)` : '';
|
|
55
|
+
const reset = compile.resets_at ? `, resets ${compile.resets_at.slice(0, 10)}` : '';
|
|
56
|
+
lines.push(`Compiled this month: ${used} of ${limit} source tokens${pct}${reset}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
lines.push('No compile allowance on this plan: compiles are paid per source token.');
|
|
61
|
+
}
|
|
62
|
+
if (usdPerMillion !== undefined) {
|
|
63
|
+
lines.push(`Pay-as-you-go compile rate: $${usdPerMillion} per million source tokens` +
|
|
64
|
+
(compile ? ' (past the allowance, with api_fallback on)' : ''));
|
|
65
|
+
}
|
|
66
|
+
if (rushPerMillion !== undefined) {
|
|
67
|
+
lines.push(`Rush compile rate: $${rushPerMillion} per million source tokens, with --rush on a compile that ` +
|
|
68
|
+
'has a scheduled start' +
|
|
69
|
+
(compile ? '. Within the allowance a rush pays only the difference, from credit.' : '.'));
|
|
70
|
+
}
|
|
71
|
+
this.log(lines.join('\n'));
|
|
72
|
+
}
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class CompileStatus extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
watch: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
interval: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
private fetch;
|
|
15
|
+
private printHumanActivity;
|
|
16
|
+
private printPaused;
|
|
17
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { compileProgressLabel } from '../../utils.js';
|
|
5
|
+
const ACTIVITY_PATH = '/v1/compile/activity';
|
|
6
|
+
function groupLabel(g, sources) {
|
|
7
|
+
if (sources.length > 0 && sources.every((s) => s.status === 'queued'))
|
|
8
|
+
return 'queued';
|
|
9
|
+
return compileProgressLabel(g);
|
|
10
|
+
}
|
|
11
|
+
function resumeCommand(s) {
|
|
12
|
+
return `faces compile:${s.kind === 'document' ? 'doc' : 'thread'}:make ${s.id}`;
|
|
13
|
+
}
|
|
14
|
+
function sleep(ms) {
|
|
15
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
|
+
}
|
|
17
|
+
export default class CompileStatus extends BaseCommand {
|
|
18
|
+
static description = 'What is compiling on this account right now, grouped by face. One small request covers every ' +
|
|
19
|
+
'source in flight, which is the question a resumed session cannot answer from memory, and lists ' +
|
|
20
|
+
'paused sources apart, since they wait for you. For this ' +
|
|
21
|
+
'month\'s compile usage against your allowance, that is compile:stats.';
|
|
22
|
+
static examples = [
|
|
23
|
+
'<%= config.bin %> <%= command.id %>',
|
|
24
|
+
'<%= config.bin %> <%= command.id %> --watch',
|
|
25
|
+
'<%= config.bin %> <%= command.id %> --json',
|
|
26
|
+
];
|
|
27
|
+
static flags = {
|
|
28
|
+
...BaseCommand.baseFlags,
|
|
29
|
+
watch: Flags.boolean({
|
|
30
|
+
description: 'Keep polling until nothing is in flight, then exit.',
|
|
31
|
+
default: false,
|
|
32
|
+
}),
|
|
33
|
+
interval: Flags.integer({
|
|
34
|
+
description: 'Seconds between polls with --watch (1-60).',
|
|
35
|
+
default: 3,
|
|
36
|
+
min: 1,
|
|
37
|
+
max: 60,
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
async run() {
|
|
41
|
+
const { flags } = await this.parse(CompileStatus);
|
|
42
|
+
const client = this.makeClient(flags);
|
|
43
|
+
const json = this.jsonEnabled();
|
|
44
|
+
let data = await this.fetch(client);
|
|
45
|
+
if (flags.watch && !json) {
|
|
46
|
+
while ((data.sources_active ?? 0) > 0) {
|
|
47
|
+
this.printHumanActivity(data);
|
|
48
|
+
this.log('');
|
|
49
|
+
await sleep(flags.interval * 1000);
|
|
50
|
+
data = await this.fetch(client);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (flags.watch && json) {
|
|
54
|
+
while ((data.sources_active ?? 0) > 0) {
|
|
55
|
+
await sleep(flags.interval * 1000);
|
|
56
|
+
data = await this.fetch(client);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!json)
|
|
60
|
+
this.printHumanActivity(data);
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
async fetch(client) {
|
|
64
|
+
try {
|
|
65
|
+
return (await client.get(ACTIVITY_PATH));
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (err instanceof FacesAPIError)
|
|
69
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
printHumanActivity(data) {
|
|
74
|
+
const active = data.sources_active ?? 0;
|
|
75
|
+
if (active === 0) {
|
|
76
|
+
this.log('Nothing is compiling.');
|
|
77
|
+
if (data.paused?.length)
|
|
78
|
+
this.log('');
|
|
79
|
+
this.printPaused(data.paused ?? []);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const faces = data.faces ?? [];
|
|
83
|
+
this.log(`${active} source(s) compiling across ${data.faces_active ?? faces.length} face(s)`);
|
|
84
|
+
this.log(` ${groupLabel(data, faces.flatMap((f) => f.sources ?? []))}`);
|
|
85
|
+
this.log('');
|
|
86
|
+
for (const face of faces) {
|
|
87
|
+
this.log(`${face.alias} (${face.sources_active ?? face.sources?.length ?? 0} source(s), ${groupLabel(face, face.sources ?? [])})`);
|
|
88
|
+
for (const s of face.sources ?? []) {
|
|
89
|
+
const kind = s.kind ?? '-';
|
|
90
|
+
const label = s.label ?? s.id;
|
|
91
|
+
this.log(` ${kind.padEnd(8)} ${label}`);
|
|
92
|
+
this.log(` ${compileProgressLabel({ ...s, status: s.status ?? 'compiling' })}`);
|
|
93
|
+
if (s.stall_reason)
|
|
94
|
+
this.log(` stopped once: ${s.stall_reason} (being retried)`);
|
|
95
|
+
}
|
|
96
|
+
this.log('');
|
|
97
|
+
}
|
|
98
|
+
this.printPaused(data.paused ?? []);
|
|
99
|
+
}
|
|
100
|
+
printPaused(paused) {
|
|
101
|
+
if (paused.length === 0)
|
|
102
|
+
return;
|
|
103
|
+
this.log(`${paused.length} paused source(s), waiting for you to resume:`);
|
|
104
|
+
for (const s of paused) {
|
|
105
|
+
this.log(` ${s.alias} ${(s.kind ?? '-').padEnd(8)} ${s.label ?? s.id}`);
|
|
106
|
+
this.log(` ${compileProgressLabel({ ...s, status: s.status ?? 'paused' })}`);
|
|
107
|
+
this.log(` resume: ${resumeCommand(s)}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base.js';
|
|
2
|
+
export default class CompileThreadCreate extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
static args: {
|
|
13
|
+
face_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<unknown>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
export default class CompileThreadCreate extends BaseCommand {
|
|
5
|
+
static description = 'Start a new thread for a face';
|
|
6
|
+
static flags = {
|
|
7
|
+
...BaseCommand.baseFlags,
|
|
8
|
+
label: Flags.string({ description: 'Thread label' }),
|
|
9
|
+
'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
|
|
10
|
+
};
|
|
11
|
+
static args = {
|
|
12
|
+
face_id: Args.string({ description: 'Face alias', required: true }),
|
|
13
|
+
};
|
|
14
|
+
async run() {
|
|
15
|
+
const { args, flags } = await this.parse(CompileThreadCreate);
|
|
16
|
+
const client = this.makeClient(flags);
|
|
17
|
+
const payload = { alias: args.face_id };
|
|
18
|
+
if (flags.label)
|
|
19
|
+
payload.label = flags.label;
|
|
20
|
+
if (flags['oauth-only'])
|
|
21
|
+
payload.oauth_only = true;
|
|
22
|
+
let data;
|
|
23
|
+
try {
|
|
24
|
+
data = await client.post('/v1/compile/threads', { body: payload });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err instanceof FacesAPIError) {
|
|
28
|
+
if (err.errorCode === 'oauth_rejected') {
|
|
29
|
+
const hint = err.fallbackAvailable
|
|
30
|
+
? 'Run `faces account:preferences api_fallback true` to allow paid fallback.'
|
|
31
|
+
: 'Run `faces billing:topup` to add credits, then enable fallback with `faces account:preferences api_fallback true`.';
|
|
32
|
+
this.error(`OAuth failed: ${err.message}\n${hint}`);
|
|
33
|
+
}
|
|
34
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
35
|
+
}
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
if (!this.jsonEnabled())
|
|
39
|
+
this.printHuman(data);
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base.js';
|
|
2
|
+
export default class CompileThreadDelete extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
static args: {
|
|
12
|
+
thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
import { seg } from '../../../utils.js';
|
|
5
|
+
export default class CompileThreadDelete extends BaseCommand {
|
|
6
|
+
static description = "Delete a thread and its messages. To withdraw it from the face while KEEPING the material, use " +
|
|
7
|
+
'compile:thread:reset instead: that withdraws what it contributed and keeps the thread, so it can be ' +
|
|
8
|
+
'recompiled without re-uploading.';
|
|
9
|
+
static flags = {
|
|
10
|
+
...BaseCommand.baseFlags,
|
|
11
|
+
yes: Flags.boolean({ description: 'Skip confirmation', default: false }),
|
|
12
|
+
};
|
|
13
|
+
static args = {
|
|
14
|
+
thread_id: Args.string({ description: 'Thread ID', required: true }),
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
const { args, flags } = await this.parse(CompileThreadDelete);
|
|
18
|
+
const client = this.makeClient(flags);
|
|
19
|
+
await this.confirmOrRefuse(`Delete thread '${args.thread_id}'? This cannot be undone.`, flags.yes);
|
|
20
|
+
let data;
|
|
21
|
+
try {
|
|
22
|
+
data = await client.delete(`/v1/compile/threads/${seg(args.thread_id)}`);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (err instanceof FacesAPIError)
|
|
26
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
if (!this.jsonEnabled())
|
|
30
|
+
this.printHuman(data);
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base.js';
|
|
2
|
+
export default class CompileThreadEdit extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'face-speaker': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'clear-medium': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
};
|
|
15
|
+
static args: {
|
|
16
|
+
thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<unknown>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../../client.js';
|
|
4
|
+
import { seg, MEDIUM_EDIT_DESCRIPTION } from '../../../utils.js';
|
|
5
|
+
export default class CompileThreadEdit extends BaseCommand {
|
|
6
|
+
static description = 'Edit a thread: its label, what medium it is read as, and/or which speaker is the face.';
|
|
7
|
+
static examples = [
|
|
8
|
+
'<%= config.bin %> <%= command.id %> THREAD_ID --label "Interview"',
|
|
9
|
+
'<%= config.bin %> <%= command.id %> THREAD_ID --medium lecture',
|
|
10
|
+
'<%= config.bin %> <%= command.id %> THREAD_ID --clear-medium',
|
|
11
|
+
];
|
|
12
|
+
static flags = {
|
|
13
|
+
...BaseCommand.baseFlags,
|
|
14
|
+
label: Flags.string({ description: 'New thread label' }),
|
|
15
|
+
'face-speaker': Flags.string({
|
|
16
|
+
description: 'Reassign face speaker: set this speaker to role=user, all others to role=assistant',
|
|
17
|
+
}),
|
|
18
|
+
medium: Flags.string({
|
|
19
|
+
description: 'What this thread should be read as. ' +
|
|
20
|
+
MEDIUM_EDIT_DESCRIPTION() +
|
|
21
|
+
' This is a correction that sticks: it overrides what an imported corpus arrived as, without ' +
|
|
22
|
+
'changing the record of what that was.',
|
|
23
|
+
exclusive: ['clear-medium'],
|
|
24
|
+
}),
|
|
25
|
+
'clear-medium': Flags.boolean({
|
|
26
|
+
description: 'Remove a medium correction, so the thread is read as whatever it arrived as.',
|
|
27
|
+
default: false,
|
|
28
|
+
exclusive: ['medium'],
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
static args = {
|
|
32
|
+
thread_id: Args.string({ description: 'Thread ID', required: true }),
|
|
33
|
+
};
|
|
34
|
+
async run() {
|
|
35
|
+
const { args, flags } = await this.parse(CompileThreadEdit);
|
|
36
|
+
const client = this.makeClient(flags);
|
|
37
|
+
const json = this.jsonEnabled();
|
|
38
|
+
if (!flags.label && !flags['face-speaker'] && !flags.medium && !flags['clear-medium']) {
|
|
39
|
+
this.error('Provide at least one of --label, --medium, --clear-medium or --face-speaker');
|
|
40
|
+
}
|
|
41
|
+
if (flags['face-speaker']) {
|
|
42
|
+
const speaker = flags['face-speaker'];
|
|
43
|
+
let thread;
|
|
44
|
+
try {
|
|
45
|
+
thread = await client.get(`/v1/compile/threads/${seg(args.thread_id)}`);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err instanceof FacesAPIError)
|
|
49
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
const messages = thread.messages;
|
|
53
|
+
if (!messages || messages.length === 0) {
|
|
54
|
+
this.error('Thread has no messages to remap');
|
|
55
|
+
}
|
|
56
|
+
let remapped = 0;
|
|
57
|
+
const speakerLower = speaker.toLowerCase();
|
|
58
|
+
const updated = messages.map((m) => {
|
|
59
|
+
const isFace = (m.name ?? '').toLowerCase() === speakerLower;
|
|
60
|
+
const newRole = isFace ? 'user' : 'assistant';
|
|
61
|
+
if (m.role !== newRole)
|
|
62
|
+
remapped++;
|
|
63
|
+
return { role: newRole, content: m.content, name: m.name };
|
|
64
|
+
});
|
|
65
|
+
try {
|
|
66
|
+
await client.patch(`/v1/compile/threads/${seg(args.thread_id)}/messages`, {
|
|
67
|
+
body: { messages: updated },
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err instanceof FacesAPIError)
|
|
72
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
if (!json) {
|
|
76
|
+
const userCount = updated.filter((m) => m.role === 'user').length;
|
|
77
|
+
const assistantCount = updated.filter((m) => m.role === 'assistant').length;
|
|
78
|
+
process.stderr.write(`Remapped ${remapped} messages: "${speaker}" → user (${userCount}), all others → assistant (${assistantCount})\n`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (flags.label || flags.medium || flags['clear-medium']) {
|
|
82
|
+
const body = {};
|
|
83
|
+
if (flags.label)
|
|
84
|
+
body.label = flags.label;
|
|
85
|
+
if (flags.medium)
|
|
86
|
+
body.medium = flags.medium;
|
|
87
|
+
if (flags['clear-medium'])
|
|
88
|
+
body.medium = null;
|
|
89
|
+
try {
|
|
90
|
+
await client.patch(`/v1/compile/threads/${seg(args.thread_id)}`, { body });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof FacesAPIError) {
|
|
94
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
95
|
+
}
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
if (!json) {
|
|
99
|
+
if (flags.label)
|
|
100
|
+
process.stderr.write(`Label updated to "${flags.label}"\n`);
|
|
101
|
+
if (flags.medium)
|
|
102
|
+
process.stderr.write(`Now read as: ${flags.medium}\n`);
|
|
103
|
+
if (flags['clear-medium'])
|
|
104
|
+
process.stderr.write('Medium correction removed.\n');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let data;
|
|
108
|
+
try {
|
|
109
|
+
data = await client.get(`/v1/compile/threads/${seg(args.thread_id)}`);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
if (err instanceof FacesAPIError)
|
|
113
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
if (!json)
|
|
117
|
+
this.printHuman(data);
|
|
118
|
+
return data;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../../base.js';
|
|
2
|
+
export default class CompileThreadGet extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'status-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
};
|
|
11
|
+
static args: {
|
|
12
|
+
thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<unknown>;
|
|
15
|
+
}
|