@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,298 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { codexEligible } from '../../routing.js';
|
|
5
|
+
import { BUILDS_PATH, LIVE_THREAD_MEDIUM, formatBuildReport, jobFailureMessage, jobMedium, listSelectable, parseSourceArg, pollStyleJob, publicJob, chatgptLinked, styleCreditRefusal, } from '../../style.js';
|
|
6
|
+
export default class StyleMake extends BaseCommand {
|
|
7
|
+
static description = 'Build a style for a face from its own writing, one per medium, and install it. Building does not ' +
|
|
8
|
+
'apply it: chat with --style <medium> to use it. Name the sources with --source, or take everything ' +
|
|
9
|
+
'ready with --all. On Connect or Pro with ChatGPT linked, a build runs there at no charge. Anywhere ' +
|
|
10
|
+
'else it is charged to credits, which needs --allow-paid.';
|
|
11
|
+
static examples = [
|
|
12
|
+
'<%= config.bin %> <%= command.id %> alice --all',
|
|
13
|
+
'<%= config.bin %> <%= command.id %> alice --source 1a2b3c4d --source 5e6f7a8b',
|
|
14
|
+
'<%= config.bin %> <%= command.id %> alice --source 1a2b3c4d:essay',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> alice --all --medium essay --no-wait',
|
|
16
|
+
];
|
|
17
|
+
static flags = {
|
|
18
|
+
...BaseCommand.baseFlags,
|
|
19
|
+
source: Flags.string({
|
|
20
|
+
description: 'A document or thread to build from, by id (repeatable). Append :<medium> to declare what it ' +
|
|
21
|
+
'is, e.g. --source 1a2b3c4d:essay, when the source does not already say.',
|
|
22
|
+
multiple: true,
|
|
23
|
+
}),
|
|
24
|
+
all: Flags.boolean({
|
|
25
|
+
description: 'Use every source on the face that is ready. Anything skipped is listed.',
|
|
26
|
+
default: false,
|
|
27
|
+
}),
|
|
28
|
+
medium: Flags.string({
|
|
29
|
+
description: 'Medium for selected sources that do not already declare one. It does not override a source ' +
|
|
30
|
+
'that does. Each medium\'s style is built separately.',
|
|
31
|
+
}),
|
|
32
|
+
model: Flags.string({
|
|
33
|
+
description: 'The model the build runs on through your linked ChatGPT account. Leave it out for the default. ' +
|
|
34
|
+
'A named model is used only when it can run on ChatGPT (see faces models:list --chatgpt). ' +
|
|
35
|
+
'A build charged to credits always runs on the default build model, whatever is named here.',
|
|
36
|
+
}),
|
|
37
|
+
'allow-paid': Flags.boolean({
|
|
38
|
+
description: 'Permit a build charged to credits, at the build model\'s listed price. Without it a build runs ' +
|
|
39
|
+
'only on a linked ChatGPT account, at no charge, or does not start. Needed on Free, and on ' +
|
|
40
|
+
'Connect or Pro without ChatGPT linked.',
|
|
41
|
+
default: false,
|
|
42
|
+
}),
|
|
43
|
+
compile: Flags.boolean({
|
|
44
|
+
description: 'Compile any named source that is not compiled yet, before the build, billed as an ordinary ' +
|
|
45
|
+
'compile. On by default. --no-compile builds from what is already compiled and never bills for compiling.',
|
|
46
|
+
default: true,
|
|
47
|
+
allowNo: true,
|
|
48
|
+
}),
|
|
49
|
+
'no-wait': Flags.boolean({ description: 'Start the build and return the job id without polling.', default: false }),
|
|
50
|
+
timeout: Flags.integer({ description: 'How long to wait, in seconds', default: 3600 }),
|
|
51
|
+
};
|
|
52
|
+
static args = {
|
|
53
|
+
alias: Args.string({ description: 'Face alias', required: true }),
|
|
54
|
+
};
|
|
55
|
+
async run() {
|
|
56
|
+
const { args, flags } = await this.parse(StyleMake);
|
|
57
|
+
const client = this.makeClient(flags);
|
|
58
|
+
const json = this.jsonEnabled();
|
|
59
|
+
if (!flags.all && (!flags.source || flags.source.length === 0)) {
|
|
60
|
+
this.error('Name what to build from: --source <id> (repeatable), or --all for everything ready.\n' +
|
|
61
|
+
`See what is available with: faces face:sources ${args.alias}`);
|
|
62
|
+
}
|
|
63
|
+
if (flags.all && flags.source?.length) {
|
|
64
|
+
this.error('Pass either --all or --source, not both.');
|
|
65
|
+
}
|
|
66
|
+
const available = await this.load(client, args.alias);
|
|
67
|
+
const { sources, skipped } = this.select(available, flags, args.alias);
|
|
68
|
+
if (flags.model)
|
|
69
|
+
await this.checkBilling(client, flags.model, flags['allow-paid']);
|
|
70
|
+
const payload = {
|
|
71
|
+
self_face: args.alias,
|
|
72
|
+
sources,
|
|
73
|
+
compile: flags.compile,
|
|
74
|
+
oauth_only: !flags['allow-paid'],
|
|
75
|
+
};
|
|
76
|
+
if (flags.model)
|
|
77
|
+
payload.model = flags.model;
|
|
78
|
+
if (!json && skipped.length > 0) {
|
|
79
|
+
for (const line of skipped)
|
|
80
|
+
process.stderr.write(`skipped: ${line}\n`);
|
|
81
|
+
}
|
|
82
|
+
if (!json) {
|
|
83
|
+
process.stderr.write(`Building a style for '${args.alias}' from ${sources.length} source(s)${flags.model ? ` using ${flags.model}` : ''}.\n`);
|
|
84
|
+
}
|
|
85
|
+
let started;
|
|
86
|
+
try {
|
|
87
|
+
started = (await client.post(BUILDS_PATH, { body: payload }));
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
this.reportStartFailure(err);
|
|
91
|
+
}
|
|
92
|
+
const jobId = String(started.job_id ?? '');
|
|
93
|
+
if (!jobId)
|
|
94
|
+
this.error('The server accepted the build but returned no job id.');
|
|
95
|
+
if (flags['no-wait']) {
|
|
96
|
+
if (json)
|
|
97
|
+
return { ...started, sources, skipped };
|
|
98
|
+
this.log(`Build started: ${jobId}`);
|
|
99
|
+
this.log(`Read it with: faces style:status ${jobId}`);
|
|
100
|
+
return started;
|
|
101
|
+
}
|
|
102
|
+
const final = await this.awaitJob(client, jobId, flags.timeout, json);
|
|
103
|
+
if (final.status === 'failed')
|
|
104
|
+
this.error(`Build failed: ${jobFailureMessage(final.error, await chatgptLinked(client), final.error_code)}`);
|
|
105
|
+
if (json)
|
|
106
|
+
return { ...publicJob(final), sources, skipped };
|
|
107
|
+
for (const line of formatBuildReport(final))
|
|
108
|
+
this.log(line);
|
|
109
|
+
this.log('');
|
|
110
|
+
const medium = jobMedium(final)?.split(', ')[0];
|
|
111
|
+
const style = !medium ? '<medium>' : medium.includes(' ') ? `"${medium}"` : medium;
|
|
112
|
+
this.log(`'${args.alias}' has built a style. Use it with --style and the medium:`);
|
|
113
|
+
this.log(` faces chat:chat ${args.alias} --style ${style} -m "..."`);
|
|
114
|
+
this.log(`Without --style, no built style is applied.`);
|
|
115
|
+
this.log(`Go back to the previous style: faces style:revert ${args.alias} --yes`);
|
|
116
|
+
return final;
|
|
117
|
+
}
|
|
118
|
+
async load(client, alias) {
|
|
119
|
+
try {
|
|
120
|
+
return await listSelectable(client, alias);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
if (err instanceof FacesAPIError) {
|
|
124
|
+
if (err.statusCode === 404)
|
|
125
|
+
this.error(`No face named '${alias}'. It does not exist, or is not yours.`);
|
|
126
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
127
|
+
}
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
select(available, flags, alias) {
|
|
132
|
+
const byId = new Map(available.map((s) => [s.id, s]));
|
|
133
|
+
const skipped = [];
|
|
134
|
+
let chosen;
|
|
135
|
+
if (flags.all) {
|
|
136
|
+
if (available.length === 0) {
|
|
137
|
+
this.error(`'${alias}' has no sources to build from. Add some with faces compile:doc or faces style:upload.`);
|
|
138
|
+
}
|
|
139
|
+
chosen = [];
|
|
140
|
+
for (const s of available) {
|
|
141
|
+
if (s.authored === 0) {
|
|
142
|
+
skipped.push(`${s.label} (${s.id}) has nothing written by this person to build from.`);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (s.isCorpus || s.synced) {
|
|
146
|
+
if (!flags.compile && !s.synced) {
|
|
147
|
+
skipped.push(`${s.label} (${s.id}) is not compiled, and --no-compile leaves it out.`);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
chosen.push({ s });
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
skipped.push(`${s.label} (${s.id}) is a thread that is still compiling. Name it with --source once it is done.`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (chosen.length === 0) {
|
|
157
|
+
this.error(`Nothing on '${alias}' is ready to build from.\n` +
|
|
158
|
+
(flags.compile
|
|
159
|
+
? 'Add material with faces style:upload or faces compile:doc, then try again.'
|
|
160
|
+
: '--no-compile only uses sources that are already compiled, and none are. Drop it to compile them as part of this build.'));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
chosen = [];
|
|
165
|
+
const missing = [];
|
|
166
|
+
const seen = new Map();
|
|
167
|
+
for (const raw of flags.source ?? []) {
|
|
168
|
+
const { id, medium } = parseSourceArg(raw);
|
|
169
|
+
if (!byId.has(id)) {
|
|
170
|
+
missing.push(id);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (seen.has(id) && medium === undefined)
|
|
174
|
+
continue;
|
|
175
|
+
seen.set(id, medium ?? seen.get(id));
|
|
176
|
+
}
|
|
177
|
+
for (const [id, medium] of seen)
|
|
178
|
+
chosen.push({ s: byId.get(id), declared: medium });
|
|
179
|
+
if (missing.length > 0) {
|
|
180
|
+
this.error(`Not a source on '${alias}': ${missing.join(', ')}\n` +
|
|
181
|
+
`List what is there with: faces face:sources ${alias}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const undeclared = [];
|
|
185
|
+
const sources = [];
|
|
186
|
+
for (const { s, declared } of chosen) {
|
|
187
|
+
const chosenMedium = declared ?? (s.medium ? undefined : flags.medium);
|
|
188
|
+
if (chosenMedium) {
|
|
189
|
+
sources.push({ id: s.id, medium: chosenMedium, source_type: s.sourceType });
|
|
190
|
+
}
|
|
191
|
+
else if (s.medium) {
|
|
192
|
+
sources.push({ id: s.id, source_type: s.sourceType });
|
|
193
|
+
}
|
|
194
|
+
else if (s.isLiveThread) {
|
|
195
|
+
sources.push({ id: s.id, medium: LIVE_THREAD_MEDIUM, source_type: s.sourceType });
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
undeclared.push(s);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (undeclared.length > 0) {
|
|
202
|
+
const list = undeclared
|
|
203
|
+
.map((s) => ` ${s.id} ${s.label}${s.sourceType === 'thread' ? ' (thread)' : ''}`)
|
|
204
|
+
.join('\n');
|
|
205
|
+
const first = undeclared[0];
|
|
206
|
+
const ways = [
|
|
207
|
+
' --medium email applies to every source that does not say',
|
|
208
|
+
` --source ${first.id}:email applies to just this one`,
|
|
209
|
+
];
|
|
210
|
+
ways.push(first.sourceType === 'document'
|
|
211
|
+
? ` faces compile:doc:edit ${first.id} --medium email records it permanently`
|
|
212
|
+
: ` faces compile:thread:edit ${first.id} --medium email records it permanently`);
|
|
213
|
+
this.error(`These sources do not say what sort of writing they are, and a style build will not guess:\n${list}\n\n` +
|
|
214
|
+
`Declare it, using the real medium rather than the example:\n${ways.join('\n')}\n\n` +
|
|
215
|
+
'A wrong declaration is worse than a missing one: a mislabelled source goes into the wrong ' +
|
|
216
|
+
'medium\'s style, and nothing afterwards says it happened.');
|
|
217
|
+
}
|
|
218
|
+
return { sources, skipped };
|
|
219
|
+
}
|
|
220
|
+
async checkBilling(client, model, allowPaid) {
|
|
221
|
+
const eligible = await codexEligible(client, model);
|
|
222
|
+
if (allowPaid) {
|
|
223
|
+
if (eligible === false && !this.jsonEnabled()) {
|
|
224
|
+
process.stderr.write(`'${model}' cannot run on ChatGPT, so this build runs on the default build model, charged to credits.\n`);
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (eligible === false) {
|
|
229
|
+
this.error(`'${model}' cannot run on ChatGPT, so this build would run on the default build model and be charged to credits.\n` +
|
|
230
|
+
'Leave out --model to build on your linked ChatGPT account at no charge, ' +
|
|
231
|
+
'or re-run with --allow-paid if you mean to pay.\n' +
|
|
232
|
+
'If you are here because a build failed on authentication, reconnect instead: faces auth:connect openai');
|
|
233
|
+
}
|
|
234
|
+
if ((await chatgptLinked(client)) === false) {
|
|
235
|
+
this.error('No ChatGPT account is linked, so this build has nothing to run on without being charged.\n' +
|
|
236
|
+
'Link one with: faces auth:connect openai (Connect or Pro), ' +
|
|
237
|
+
'or re-run with --allow-paid to pay from credits. Nothing was started.');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
reportStartFailure(err) {
|
|
241
|
+
if (!(err instanceof FacesAPIError))
|
|
242
|
+
throw err;
|
|
243
|
+
if (err.errorCode === 'build_in_progress') {
|
|
244
|
+
const running = typeof err.details?.job_id === 'string' ? err.details.job_id : undefined;
|
|
245
|
+
this.error(`${err.message}\n` +
|
|
246
|
+
(running
|
|
247
|
+
? `Follow that one instead: faces style:status ${running} --wait`
|
|
248
|
+
: 'Find it with: faces style:status --face <alias>') +
|
|
249
|
+
'\nNothing was started, and nothing was charged.');
|
|
250
|
+
}
|
|
251
|
+
if (err.errorCode === 'oauth_only_unavailable') {
|
|
252
|
+
this.error(`HTTP 422: ${err.message.split('\n')[0]}\n` +
|
|
253
|
+
'On the Free plan a style build is charged to credits. Re-run with --allow-paid to pay, ' +
|
|
254
|
+
'or subscribe to Connect or Pro and link ChatGPT, where a build runs at no charge: ' +
|
|
255
|
+
'faces billing:subscription:activate\nNothing was started.');
|
|
256
|
+
}
|
|
257
|
+
if (err.errorCode === 'chatgpt_not_linked') {
|
|
258
|
+
this.error('This build cannot run on a linked ChatGPT account: none is linked, or the named --model cannot run there.\n' +
|
|
259
|
+
'Link ChatGPT with: faces auth:connect openai (Connect or Pro), ' +
|
|
260
|
+
'or re-run with --allow-paid to pay from credits.\nNothing was started, and nothing was charged.');
|
|
261
|
+
}
|
|
262
|
+
if (err.errorCode === 'insufficient_credit_for_style_build') {
|
|
263
|
+
this.error(styleCreditRefusal(err.details));
|
|
264
|
+
}
|
|
265
|
+
const hint = {
|
|
266
|
+
403: 'That source belongs to another account.',
|
|
267
|
+
404: 'Check the id against: faces face:sources <alias>',
|
|
268
|
+
409: 'A source is compiling right now, or the face is locked. Wait for it to finish, or unlock the face.',
|
|
269
|
+
422: 'A named thread has messages that are not compiled yet. Compile it first, or pass --no-compile.',
|
|
270
|
+
};
|
|
271
|
+
const extra = hint[err.statusCode];
|
|
272
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}${extra ? `\n${extra}` : ''}\nNothing was started.`);
|
|
273
|
+
}
|
|
274
|
+
async awaitJob(client, jobId, timeout, json) {
|
|
275
|
+
let last = '';
|
|
276
|
+
try {
|
|
277
|
+
return await pollStyleJob(client, BUILDS_PATH, jobId, {
|
|
278
|
+
timeoutMs: timeout * 1000,
|
|
279
|
+
onPoll: (d) => {
|
|
280
|
+
if (json)
|
|
281
|
+
return;
|
|
282
|
+
const p = d.progress;
|
|
283
|
+
const status = String(d.status ?? '');
|
|
284
|
+
const key = `${status}:${p?.done ?? ''}/${p?.total ?? ''}`;
|
|
285
|
+
if (key === last)
|
|
286
|
+
return;
|
|
287
|
+
last = key;
|
|
288
|
+
process.stderr.write(` ${status}${p?.total ? ` ${p.done ?? 0}/${p.total}` : ''}\n`);
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
catch (err) {
|
|
293
|
+
if (err instanceof FacesAPIError)
|
|
294
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
295
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class StyleRevert extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
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
|
+
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 { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { VERSIONS_PATH } from '../../style.js';
|
|
5
|
+
export default class StyleRevert extends BaseCommand {
|
|
6
|
+
static description = 'Go back to the style a face had before the last build, whether you ran style:make or it was an ' +
|
|
7
|
+
'automatic build. Two versions are kept per medium, so this is a toggle: running it again returns to ' +
|
|
8
|
+
'where you started. A build after a revert keeps the version you reverted to as its previous one, so ' +
|
|
9
|
+
'reverting never loses the style you chose. A face holds one style per medium, ' +
|
|
10
|
+
'so name which one with --medium when it has more than one. It takes effect ' +
|
|
11
|
+
'immediately, so it asks first.';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> <%= command.id %> alice --yes',
|
|
14
|
+
'<%= config.bin %> <%= command.id %> alice --medium email --yes',
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
...BaseCommand.baseFlags,
|
|
18
|
+
medium: Flags.string({
|
|
19
|
+
description: 'Which style to step back, when the face has more than one. See faces style:versions <alias>.',
|
|
20
|
+
}),
|
|
21
|
+
yes: Flags.boolean({ description: 'Skip confirmation', default: false }),
|
|
22
|
+
};
|
|
23
|
+
static args = {
|
|
24
|
+
alias: Args.string({ description: 'Face alias', required: true }),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { args, flags } = await this.parse(StyleRevert);
|
|
28
|
+
const client = this.makeClient(flags);
|
|
29
|
+
if (!flags.yes) {
|
|
30
|
+
this.error(`This changes the style '${args.alias}' applies${flags.medium ? ` for ${flags.medium}` : ''}, straight away. ` +
|
|
31
|
+
'Re-run with --yes to confirm.\n' +
|
|
32
|
+
`See what it would go back to: faces style:versions ${args.alias}`);
|
|
33
|
+
}
|
|
34
|
+
const body = { self_face: args.alias };
|
|
35
|
+
if (flags.medium !== undefined)
|
|
36
|
+
body.medium = flags.medium;
|
|
37
|
+
let data;
|
|
38
|
+
try {
|
|
39
|
+
data = (await client.post(`${VERSIONS_PATH}/revert`, { body }));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof FacesAPIError) {
|
|
43
|
+
if (err.statusCode === 404)
|
|
44
|
+
this.error(`No face named '${args.alias}'. It does not exist, or is not yours.`);
|
|
45
|
+
if (err.statusCode === 409) {
|
|
46
|
+
this.error(`HTTP 409: ${err.message}\nSee what is there: faces style:versions ${args.alias}`);
|
|
47
|
+
}
|
|
48
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
if (this.jsonEnabled())
|
|
53
|
+
return data;
|
|
54
|
+
const from = data.from_version;
|
|
55
|
+
const to = data.to_version;
|
|
56
|
+
if (from !== undefined && to !== undefined) {
|
|
57
|
+
this.log(`'${args.alias}' moved from version ${from} back to version ${to}.`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.log(`'${args.alias}' reverted.`);
|
|
61
|
+
}
|
|
62
|
+
const back = from === undefined ? '' : ` to return to version ${from}`;
|
|
63
|
+
this.log(`Run it again${back}. List versions: faces style:versions ${args.alias}`);
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class StyleStatus extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
face: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
wait: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
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
|
+
job_id: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<unknown>;
|
|
19
|
+
private list;
|
|
20
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { BUILDS_PATH, EXIT_NO_SUCH_FACE, chatgptLinked, formatBuildReport, jobFailureMessage, faceExists, jobMedium, pollStyleJob, publicJob } from '../../style.js';
|
|
5
|
+
export default class StyleStatus extends BaseCommand {
|
|
6
|
+
static description = 'Read a style build. Give a job id for one build, or --face to list a face\'s recent builds. ' +
|
|
7
|
+
'Listing is how you find a job id you no longer have.';
|
|
8
|
+
static examples = [
|
|
9
|
+
'<%= config.bin %> <%= command.id %> 7a8b9c0d',
|
|
10
|
+
'<%= config.bin %> <%= command.id %> --face alice',
|
|
11
|
+
'<%= config.bin %> <%= command.id %> 7a8b9c0d --wait',
|
|
12
|
+
];
|
|
13
|
+
static flags = {
|
|
14
|
+
...BaseCommand.baseFlags,
|
|
15
|
+
face: Flags.string({ description: 'List recent builds for this face instead of reading one job' }),
|
|
16
|
+
limit: Flags.integer({ description: 'How many builds to list with --face (1-100, default: 10)', default: 10, min: 1, max: 100 }),
|
|
17
|
+
wait: Flags.boolean({ description: 'Block until the job finishes', default: false }),
|
|
18
|
+
timeout: Flags.integer({ description: 'How long to wait with --wait, in seconds', default: 3600 }),
|
|
19
|
+
};
|
|
20
|
+
static args = {
|
|
21
|
+
job_id: Args.string({ description: 'Build job id', required: false }),
|
|
22
|
+
};
|
|
23
|
+
async run() {
|
|
24
|
+
const { args, flags } = await this.parse(StyleStatus);
|
|
25
|
+
const client = this.makeClient(flags);
|
|
26
|
+
const json = this.jsonEnabled();
|
|
27
|
+
if (!args.job_id && !flags.face) {
|
|
28
|
+
this.error('Give a job id, or --face <alias> to list a face\'s builds.');
|
|
29
|
+
}
|
|
30
|
+
if (args.job_id && flags.face) {
|
|
31
|
+
this.error('Pass either a job id or --face, not both.');
|
|
32
|
+
}
|
|
33
|
+
if (flags.face)
|
|
34
|
+
return this.list(client, flags.face, flags.limit, json);
|
|
35
|
+
let data;
|
|
36
|
+
try {
|
|
37
|
+
data = flags.wait
|
|
38
|
+
? await pollStyleJob(client, BUILDS_PATH, args.job_id, { timeoutMs: flags.timeout * 1000 })
|
|
39
|
+
: (await client.get(`${BUILDS_PATH}/${encodeURIComponent(args.job_id)}`));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof FacesAPIError) {
|
|
43
|
+
if (err.statusCode === 404)
|
|
44
|
+
this.error(`No build job '${args.job_id}'. List a face's builds with --face <alias>.`);
|
|
45
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
46
|
+
}
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
if (data.status === 'failed')
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
if (json)
|
|
52
|
+
return publicJob(data);
|
|
53
|
+
for (const line of formatBuildReport(data))
|
|
54
|
+
this.log(line);
|
|
55
|
+
if (data.status === 'failed')
|
|
56
|
+
this.log(`\nerror: ${jobFailureMessage(data.error, await chatgptLinked(client), data.error_code)}`);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
async list(client, face, limit, json) {
|
|
60
|
+
let data;
|
|
61
|
+
try {
|
|
62
|
+
data = (await client.get(`${BUILDS_PATH}?self_face=${encodeURIComponent(face)}&limit=${limit}`));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err instanceof FacesAPIError) {
|
|
66
|
+
if (err.statusCode === 404)
|
|
67
|
+
this.error(`No face named '${face}'. It does not exist, or is not yours.`);
|
|
68
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
69
|
+
}
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
const jobs = data.jobs ?? [];
|
|
73
|
+
if (jobs.length === 0 && !(await faceExists(client, face))) {
|
|
74
|
+
this.error(`No face named '${face}'. It does not exist, or is not yours.`, { exit: EXIT_NO_SUCH_FACE });
|
|
75
|
+
}
|
|
76
|
+
if (json)
|
|
77
|
+
return { ...data, jobs: jobs.map((j) => publicJob(j)) };
|
|
78
|
+
if (jobs.length === 0) {
|
|
79
|
+
this.log(`'${face}' has no style builds yet. Build one with: faces style:make ${face} --all`);
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
const rows = jobs.map((j) => ({
|
|
83
|
+
job: String(j.job_id ?? '-'),
|
|
84
|
+
status: String(j.status ?? '-'),
|
|
85
|
+
medium: jobMedium(j) ?? '-',
|
|
86
|
+
when: String(j.created_at ?? '').slice(0, 19).replace('T', ' ') || '-',
|
|
87
|
+
by: j.report?.auto ? 'auto' : 'manual',
|
|
88
|
+
}));
|
|
89
|
+
const cols = [
|
|
90
|
+
['JOB', (r) => r.job],
|
|
91
|
+
['STATUS', (r) => r.status],
|
|
92
|
+
['MEDIUM', (r) => r.medium],
|
|
93
|
+
['STARTED', (r) => r.when],
|
|
94
|
+
['BY', (r) => r.by],
|
|
95
|
+
];
|
|
96
|
+
const w = cols.map(([h, g]) => Math.max(h.length, ...rows.map((r) => g(r).length)));
|
|
97
|
+
const line = (c) => c.map((x, i) => x.padEnd(w[i])).join(' ').trimEnd();
|
|
98
|
+
this.log(line(cols.map(([h]) => h)));
|
|
99
|
+
for (const r of rows)
|
|
100
|
+
this.log(line(cols.map(([, g]) => g(r))));
|
|
101
|
+
this.log('');
|
|
102
|
+
this.log(`${rows.length} build(s) shown, newest first. Raise the cap with --limit.`);
|
|
103
|
+
if (rows.some((r) => r.by === 'auto')) {
|
|
104
|
+
this.log('BY auto means an automatic build: it ran once the face had enough of its own writing. Read one');
|
|
105
|
+
this.log('for why, or turn them off: faces account:preferences auto_style off');
|
|
106
|
+
}
|
|
107
|
+
return data;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class StyleUpload extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
type: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'messages-per-thread': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
strict: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
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
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
static args: {
|
|
15
|
+
alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
16
|
+
file: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<unknown>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
import { seg } from '../../utils.js';
|
|
7
|
+
export default class StyleUpload extends BaseCommand {
|
|
8
|
+
static description = 'Load a corpus of a person\'s own writing (a mail export, a message archive) as source material for ' +
|
|
9
|
+
'building a style. This only stores the material: nothing is compiled and nothing is billed. Build ' +
|
|
10
|
+
'the style afterwards with style:make. Each message needs author (self, for the face, or other), ' +
|
|
11
|
+
'sender, date (ISO-8601) and its text in plaintextBody, htmlBody or snippet; body and text are accepted ' +
|
|
12
|
+
'for plaintextBody. The server lists every problem with a refused line, and the fields it accepts. ' +
|
|
13
|
+
'Upload ONE medium per file: a file mixing, say, email and ' +
|
|
14
|
+
'text messages produces threads with no medium at all, which no style can be built from. A message that declares ' +
|
|
15
|
+
'its own `kind` must spell one of the eleven media exactly; an unknown one is refused, naming the ' +
|
|
16
|
+
'message that carried it. The file is passed through as written, so this is the server answering.';
|
|
17
|
+
static examples = [
|
|
18
|
+
'<%= config.bin %> <%= command.id %> alice ./mail.jsonl',
|
|
19
|
+
'<%= config.bin %> <%= command.id %> alice ./thread.json --type thread_json',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> alice ./mail.jsonl --messages-per-thread 100 --strict',
|
|
21
|
+
];
|
|
22
|
+
static flags = {
|
|
23
|
+
...BaseCommand.baseFlags,
|
|
24
|
+
type: Flags.string({
|
|
25
|
+
description: 'jsonl: one message per line, split across threads, for any medium (email_jsonl is the same). ' +
|
|
26
|
+
'thread_json: a JSON array that becomes a single thread.',
|
|
27
|
+
options: ['jsonl', 'email_jsonl', 'thread_json'],
|
|
28
|
+
default: 'jsonl',
|
|
29
|
+
}),
|
|
30
|
+
'messages-per-thread': Flags.integer({
|
|
31
|
+
description: 'Messages per thread for a line-per-message file (1-1000, default: 50). Set this above the length ' +
|
|
32
|
+
'of a conversation you want kept whole in one thread; at 50 a long conversation is cut into slices.',
|
|
33
|
+
default: 50,
|
|
34
|
+
min: 1,
|
|
35
|
+
max: 1000,
|
|
36
|
+
}),
|
|
37
|
+
strict: Flags.boolean({
|
|
38
|
+
description: 'Reject the whole upload if any message is invalid. By default invalid messages are skipped and ' +
|
|
39
|
+
'reported, and the rest are kept.',
|
|
40
|
+
default: false,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
static args = {
|
|
44
|
+
alias: Args.string({ description: 'Face alias', required: true }),
|
|
45
|
+
file: Args.string({ description: 'Corpus file', required: true }),
|
|
46
|
+
};
|
|
47
|
+
async run() {
|
|
48
|
+
const { args, flags } = await this.parse(StyleUpload);
|
|
49
|
+
const client = this.makeClient(flags);
|
|
50
|
+
const json = this.jsonEnabled();
|
|
51
|
+
if (!fs.existsSync(args.file))
|
|
52
|
+
this.error(`File not found: ${args.file}`);
|
|
53
|
+
const form = new FormData();
|
|
54
|
+
form.append('file', new Blob([fs.readFileSync(args.file)], { type: 'application/json' }), path.basename(args.file));
|
|
55
|
+
const params = new URLSearchParams({ type: flags.type });
|
|
56
|
+
if (flags.type !== 'thread_json')
|
|
57
|
+
params.set('per_thread', String(flags['messages-per-thread']));
|
|
58
|
+
if (flags.strict)
|
|
59
|
+
params.set('strict', 'true');
|
|
60
|
+
let data;
|
|
61
|
+
try {
|
|
62
|
+
data = (await client.postForm(`/v1/faces/${seg(args.alias)}/upload?${params}`, form));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err instanceof FacesAPIError) {
|
|
66
|
+
if (err.statusCode === 404)
|
|
67
|
+
this.error(`No face named '${args.alias}'. It does not exist, or is not yours.`);
|
|
68
|
+
if (err.statusCode === 422 && flags.strict) {
|
|
69
|
+
this.error(`HTTP 422: ${err.message}\nDrop --strict to skip invalid messages instead of refusing the upload.`);
|
|
70
|
+
}
|
|
71
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
72
|
+
}
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
if (json)
|
|
76
|
+
return data;
|
|
77
|
+
const threadIds = data.thread_ids ?? [];
|
|
78
|
+
const skipped = data.skipped;
|
|
79
|
+
const medium = data.medium;
|
|
80
|
+
this.log(`face: ${data.alias ?? args.alias}`);
|
|
81
|
+
this.log(`messages: ${data.message_count ?? '?'}`);
|
|
82
|
+
this.log(`threads: ${data.thread_count ?? threadIds.length}`);
|
|
83
|
+
this.log(`medium: ${medium ?? 'none'}`);
|
|
84
|
+
if (skipped?.length) {
|
|
85
|
+
this.log(`skipped: ${skipped.length} message(s) failed validation and were not stored.`);
|
|
86
|
+
this.log(' Re-run with --strict to refuse the whole upload instead.');
|
|
87
|
+
}
|
|
88
|
+
this.log('');
|
|
89
|
+
if (medium) {
|
|
90
|
+
this.log(`Build the style: faces style:make ${args.alias} --all`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.log('These threads have NO medium, so no style can be built from them until one is set.');
|
|
94
|
+
this.log('That happens when one file mixes media, or when the messages declared none.');
|
|
95
|
+
this.log('Upload one medium per file, or set it: faces compile:thread:edit <id> --medium <medium>');
|
|
96
|
+
this.log(`Inspect what landed: faces face:sources ${args.alias} --type thread`);
|
|
97
|
+
}
|
|
98
|
+
return data;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class StyleVersions extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
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
|
+
alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<unknown>;
|
|
15
|
+
}
|