@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,104 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { ownsFace } from '../../utils.js';
|
|
4
|
+
import { FacesAPIError } from '../../client.js';
|
|
5
|
+
import { EXIT_NO_SUCH_FACE, VERSIONS_PATH, faceExists } from '../../style.js';
|
|
6
|
+
export default class StyleVersions extends BaseCommand {
|
|
7
|
+
static description = 'List the styles built for a face, and which one is in use for each medium. A face holds one style per ' +
|
|
8
|
+
'medium, so more than one can be in use at once: an email style and an essay style are separate ' +
|
|
9
|
+
'and do not replace each other. Two versions are kept per medium, which is what style:revert has ' +
|
|
10
|
+
'to go back to.';
|
|
11
|
+
static examples = ['<%= config.bin %> <%= command.id %> alice', '<%= config.bin %> <%= command.id %> alice --json'];
|
|
12
|
+
static flags = { ...BaseCommand.baseFlags };
|
|
13
|
+
static args = {
|
|
14
|
+
alias: Args.string({ description: 'Face alias', required: true }),
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
const { args, flags } = await this.parse(StyleVersions);
|
|
18
|
+
const alias = args.alias;
|
|
19
|
+
const client = this.makeClient(flags);
|
|
20
|
+
let data;
|
|
21
|
+
try {
|
|
22
|
+
data = (await client.get(`${VERSIONS_PATH}/${encodeURIComponent(args.alias)}`));
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (err instanceof FacesAPIError && err.statusCode === 404) {
|
|
26
|
+
if (await faceExists(client, args.alias)) {
|
|
27
|
+
if (this.jsonEnabled())
|
|
28
|
+
return { self_face: args.alias, versions: [] };
|
|
29
|
+
if ((await ownsFace(client, args.alias)) === false) {
|
|
30
|
+
this.log(`'${args.alias}' belongs to another account. Only its owner can see or build its style versions.`);
|
|
31
|
+
return { self_face: args.alias, versions: [] };
|
|
32
|
+
}
|
|
33
|
+
this.log(`'${args.alias}' exists and has no built style yet.`);
|
|
34
|
+
this.log(`Build one with: faces style:make ${args.alias} --all`);
|
|
35
|
+
return { self_face: args.alias, versions: [] };
|
|
36
|
+
}
|
|
37
|
+
this.error(`No face named '${args.alias}'. It does not exist, or is not yours.`, { exit: EXIT_NO_SUCH_FACE });
|
|
38
|
+
}
|
|
39
|
+
if (err instanceof FacesAPIError)
|
|
40
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
const versions = data.versions ?? [];
|
|
44
|
+
if (this.jsonEnabled())
|
|
45
|
+
return data;
|
|
46
|
+
if (versions.length === 0) {
|
|
47
|
+
this.log(`'${args.alias}' has no built style. Build one with: faces style:make ${args.alias} --all`);
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
const rows = versions.map((v) => ({
|
|
51
|
+
medium: v.medium?.trim() || '(before media)',
|
|
52
|
+
version: String(v.version ?? '-'),
|
|
53
|
+
active: v.active ? 'yes' : '-',
|
|
54
|
+
revert: v.can_revert ? 'yes' : '-',
|
|
55
|
+
sources: v.sources_printed === null || v.sources_printed === undefined ? '-' : String(v.sources_printed),
|
|
56
|
+
model: v.model?.trim() || '-',
|
|
57
|
+
created: String(v.created_at ?? '').slice(0, 19).replace('T', ' ') || '-',
|
|
58
|
+
}));
|
|
59
|
+
const cols = [
|
|
60
|
+
['MEDIUM', (r) => r.medium],
|
|
61
|
+
['VERSION', (r) => r.version],
|
|
62
|
+
['IN USE', (r) => r.active],
|
|
63
|
+
['REVERTABLE', (r) => r.revert],
|
|
64
|
+
['SOURCES', (r) => r.sources],
|
|
65
|
+
['MODEL', (r) => r.model],
|
|
66
|
+
['BUILT', (r) => r.created],
|
|
67
|
+
];
|
|
68
|
+
const w = cols.map(([h, g]) => Math.max(h.length, ...rows.map((r) => g(r).length)));
|
|
69
|
+
const line = (c) => c.map((x, i) => (cols[i][0] === 'SOURCES' ? x.padStart(w[i]) : x.padEnd(w[i]))).join(' ').trimEnd();
|
|
70
|
+
this.log(line(cols.map(([h]) => h)));
|
|
71
|
+
for (const r of rows)
|
|
72
|
+
this.log(line(cols.map(([, g]) => g(r))));
|
|
73
|
+
const active = versions.filter((v) => v.active);
|
|
74
|
+
const label = (v) => `${v.medium?.trim() || '(before media)'} v${v.version}`;
|
|
75
|
+
this.log('');
|
|
76
|
+
if (active.length === 0) {
|
|
77
|
+
this.log(`${versions.length} version(s) kept, none in use.`);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.log(`In use: ${active.map((v) => label(v)).join(', ')}.`);
|
|
81
|
+
this.log(`${versions.length} version(s) kept in total, two per medium.`);
|
|
82
|
+
}
|
|
83
|
+
const revertable = versions.filter((v) => v.can_revert);
|
|
84
|
+
if (revertable.length > 0) {
|
|
85
|
+
const media = revertable.map((v) => v.medium?.trim()).filter(Boolean);
|
|
86
|
+
this.log(`Can step back: ${revertable.map((v) => label(v)).join(', ')}.`);
|
|
87
|
+
for (const v of revertable) {
|
|
88
|
+
const prior = versions
|
|
89
|
+
.filter((o) => o.medium === v.medium && (o.version ?? 0) < (v.version ?? 0))
|
|
90
|
+
.sort((a, b) => (b.version ?? 0) - (a.version ?? 0))[0];
|
|
91
|
+
if (!prior)
|
|
92
|
+
continue;
|
|
93
|
+
const when = String(prior.created_at ?? '').slice(0, 10);
|
|
94
|
+
const from = prior.sources_printed === null || prior.sources_printed === undefined
|
|
95
|
+
? ''
|
|
96
|
+
: ` from ${prior.sources_printed} source(s)`;
|
|
97
|
+
this.log(` ${label(v)} would go back to v${prior.version}, built ${when}${from}.`);
|
|
98
|
+
}
|
|
99
|
+
if (media.length > 0)
|
|
100
|
+
this.log(`Use: faces style:revert ${alias} --medium ${media[0]} --yes`);
|
|
101
|
+
}
|
|
102
|
+
return data;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class UserFollow 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
|
+
static args: {
|
|
11
|
+
username: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Args } 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 UserFollow extends BaseCommand {
|
|
6
|
+
static description = 'Follow an account';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
};
|
|
10
|
+
static args = {
|
|
11
|
+
username: Args.string({ description: 'Account to follow', required: true }),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
const { args, flags } = await this.parse(UserFollow);
|
|
15
|
+
const client = this.makeClient(flags);
|
|
16
|
+
let data;
|
|
17
|
+
try {
|
|
18
|
+
data = (await client.post(`/v1/users/${seg(args.username)}/follow`));
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err instanceof FacesAPIError) {
|
|
22
|
+
if (err.statusCode === 404)
|
|
23
|
+
this.error(`No account '${args.username}'.`);
|
|
24
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
if (!this.jsonEnabled()) {
|
|
29
|
+
this.log(data.is_following
|
|
30
|
+
? `You follow ${data.username}.`
|
|
31
|
+
: `${data.username} is not followed. The server reported no change.`);
|
|
32
|
+
const followers = data.counts?.followers;
|
|
33
|
+
if (typeof followers === 'number')
|
|
34
|
+
this.log(` they now have ${followers} follower(s)`);
|
|
35
|
+
}
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class UserFollowers 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
|
+
static args: {
|
|
11
|
+
username: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Args } 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 UserFollowers extends BaseCommand {
|
|
6
|
+
static description = 'List the accounts following someone. Follows the list to the end rather than stopping at the first page.';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
};
|
|
10
|
+
static args = {
|
|
11
|
+
username: Args.string({ description: 'Account username', required: true }),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
const { args, flags } = await this.parse(UserFollowers);
|
|
15
|
+
const client = this.makeClient(flags);
|
|
16
|
+
let all;
|
|
17
|
+
try {
|
|
18
|
+
all = await client.getAll(`/v1/users/${seg(args.username)}/followers`);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err instanceof FacesAPIError) {
|
|
22
|
+
if (err.statusCode === 404)
|
|
23
|
+
this.error(`No account '${args.username}'.`);
|
|
24
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
const rows = all.data;
|
|
29
|
+
const counts = (all.envelope.counts ?? {});
|
|
30
|
+
const data = { object: 'list', data: rows, counts, has_more: all.truncated, next_cursor: null };
|
|
31
|
+
if (!this.jsonEnabled()) {
|
|
32
|
+
if (rows.length === 0) {
|
|
33
|
+
this.log(`Nobody follows ${args.username}.`);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
const width = Math.max(...rows.map((u) => u.username.length));
|
|
37
|
+
for (const u of rows) {
|
|
38
|
+
const name = u.name && u.name !== u.username ? ` ${u.name}` : '';
|
|
39
|
+
const mine = u.is_following === true ? ' [you follow]' : '';
|
|
40
|
+
this.log(`${u.username.padEnd(width)}${name}${mine}`);
|
|
41
|
+
}
|
|
42
|
+
this.log('');
|
|
43
|
+
this.log(`${rows.length} follower(s)`);
|
|
44
|
+
if (all.truncated) {
|
|
45
|
+
this.log('This list is incomplete: the server had more than could be read in one go.');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class UserFollowing 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
|
+
static args: {
|
|
11
|
+
username: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Args } 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 UserFollowing extends BaseCommand {
|
|
6
|
+
static description = 'List the accounts someone follows. Follows the list to the end rather than stopping at the first page.';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
};
|
|
10
|
+
static args = {
|
|
11
|
+
username: Args.string({ description: 'Account username', required: true }),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
const { args, flags } = await this.parse(UserFollowing);
|
|
15
|
+
const client = this.makeClient(flags);
|
|
16
|
+
let all;
|
|
17
|
+
try {
|
|
18
|
+
all = await client.getAll(`/v1/users/${seg(args.username)}/following`);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err instanceof FacesAPIError) {
|
|
22
|
+
if (err.statusCode === 404)
|
|
23
|
+
this.error(`No account '${args.username}'.`);
|
|
24
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
const rows = all.data;
|
|
29
|
+
const counts = (all.envelope.counts ?? {});
|
|
30
|
+
const data = { object: 'list', data: rows, counts, has_more: all.truncated, next_cursor: null };
|
|
31
|
+
if (!this.jsonEnabled()) {
|
|
32
|
+
if (rows.length === 0) {
|
|
33
|
+
this.log(`${args.username} follows nobody.`);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
const width = Math.max(...rows.map((u) => u.username.length));
|
|
37
|
+
for (const u of rows) {
|
|
38
|
+
const name = u.name && u.name !== u.username ? ` ${u.name}` : '';
|
|
39
|
+
const mine = u.is_following === true ? ' [you follow]' : '';
|
|
40
|
+
this.log(`${u.username.padEnd(width)}${name}${mine}`);
|
|
41
|
+
}
|
|
42
|
+
this.log('');
|
|
43
|
+
this.log(`${rows.length} followed account(s)`);
|
|
44
|
+
if (all.truncated) {
|
|
45
|
+
this.log('This list is incomplete: the server had more than could be read in one go.');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class UserGet 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
|
+
static args: {
|
|
11
|
+
username: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Args } 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 UserGet extends BaseCommand {
|
|
6
|
+
static description = 'Get an account: who they are, how many follow them, and whether you follow them';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
};
|
|
10
|
+
static args = {
|
|
11
|
+
username: Args.string({ description: 'Account username', required: true }),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
const { args, flags } = await this.parse(UserGet);
|
|
15
|
+
const client = this.makeClient(flags);
|
|
16
|
+
let data;
|
|
17
|
+
try {
|
|
18
|
+
data = (await client.get(`/v1/users/${seg(args.username)}`));
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err instanceof FacesAPIError) {
|
|
22
|
+
if (err.statusCode === 404)
|
|
23
|
+
this.error(`No account '${args.username}'.`);
|
|
24
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
if (!this.jsonEnabled()) {
|
|
29
|
+
this.log(`username: ${data.username}`);
|
|
30
|
+
if (data.name && data.name !== data.username)
|
|
31
|
+
this.log(`name: ${data.name}`);
|
|
32
|
+
if (data.description)
|
|
33
|
+
this.log(`about: ${data.description}`);
|
|
34
|
+
if (data.created)
|
|
35
|
+
this.log(`joined: ${new Date(data.created * 1000).toISOString().slice(0, 10)}`);
|
|
36
|
+
const c = data.counts ?? {};
|
|
37
|
+
this.log(`following: ${c.following ?? '-'}`);
|
|
38
|
+
this.log(`followers: ${c.followers ?? '-'}`);
|
|
39
|
+
if (data.is_following === true)
|
|
40
|
+
this.log('You follow this account.');
|
|
41
|
+
else if (data.is_following === false) {
|
|
42
|
+
this.log(`You do not follow this account. Follow it with: faces user:follow ${data.username}`);
|
|
43
|
+
}
|
|
44
|
+
this.log('');
|
|
45
|
+
this.log(`Their published faces: faces face:list --public --from-users ${data.username}`);
|
|
46
|
+
}
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class UserUnfollow 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
|
+
static args: {
|
|
11
|
+
username: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Args } 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 UserUnfollow extends BaseCommand {
|
|
6
|
+
static description = 'Stop following an account';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
};
|
|
10
|
+
static args = {
|
|
11
|
+
username: Args.string({ description: 'Account to stop following', required: true }),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
const { args, flags } = await this.parse(UserUnfollow);
|
|
15
|
+
const client = this.makeClient(flags);
|
|
16
|
+
let data;
|
|
17
|
+
try {
|
|
18
|
+
data = (await client.delete(`/v1/users/${seg(args.username)}/follow`));
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
if (err instanceof FacesAPIError) {
|
|
22
|
+
if (err.statusCode === 404)
|
|
23
|
+
this.error(`No account '${args.username}'.`);
|
|
24
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
if (!this.jsonEnabled()) {
|
|
29
|
+
this.log(data.is_following
|
|
30
|
+
? `${data.username} is still followed. The server reported no change.`
|
|
31
|
+
: `You no longer follow ${data.username}.`);
|
|
32
|
+
const followers = data.counts?.followers;
|
|
33
|
+
if (typeof followers === 'number')
|
|
34
|
+
this.log(` they now have ${followers} follower(s)`);
|
|
35
|
+
}
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const CONFIG_PATH: string;
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://api.faces.sh";
|
|
3
|
+
export interface FacesConfig {
|
|
4
|
+
base_url?: string;
|
|
5
|
+
credentials_base_url?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
api_key?: string;
|
|
8
|
+
user_id?: string;
|
|
9
|
+
catalog?: string;
|
|
10
|
+
catalog_model?: string;
|
|
11
|
+
[key: string]: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function loadConfig(): FacesConfig;
|
|
14
|
+
export declare function saveConfig(data: Partial<FacesConfig>): void;
|
|
15
|
+
export declare function saveCredentials(data: Pick<FacesConfig, 'token' | 'api_key' | 'user_id'>, baseUrl: string): void;
|
|
16
|
+
export declare function originOf(url: string): string;
|
|
17
|
+
export declare function setConfigKey(key: string, value: string): void;
|
|
18
|
+
export declare function clearConfig(): void;
|
|
19
|
+
export declare function maskedConfig(): FacesConfig;
|
|
20
|
+
export interface ResolvedCredentials {
|
|
21
|
+
token?: string;
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
withheld?: string;
|
|
24
|
+
keySaved?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function resolveCredentials(flags: {
|
|
27
|
+
token?: string;
|
|
28
|
+
'api-key'?: string;
|
|
29
|
+
}, baseUrl: string): ResolvedCredentials;
|
|
30
|
+
export declare function resolveBaseUrl(override?: string): string;
|
|
31
|
+
export declare function resolveToken(override?: string): string | undefined;
|
|
32
|
+
export declare function resolveApiKey(override?: string): string | undefined;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export const CONFIG_PATH = path.join(os.homedir(), '.faces', 'config.json');
|
|
5
|
+
export const DEFAULT_BASE_URL = 'https://api.faces.sh';
|
|
6
|
+
let warnedCorrupt = false;
|
|
7
|
+
export function loadConfig() {
|
|
8
|
+
let raw;
|
|
9
|
+
try {
|
|
10
|
+
raw = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
if (!warnedCorrupt) {
|
|
20
|
+
process.stderr.write(`warn: ${CONFIG_PATH} is not valid JSON, so it is being ignored. It will be backed up before anything overwrites it.\n`);
|
|
21
|
+
warnedCorrupt = true;
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function saveConfig(data) {
|
|
27
|
+
const dir = path.dirname(CONFIG_PATH);
|
|
28
|
+
if (!fs.existsSync(dir))
|
|
29
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
30
|
+
backUpIfCorrupt();
|
|
31
|
+
const existing = loadConfig();
|
|
32
|
+
const merged = { ...existing, ...data };
|
|
33
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2), { mode: 0o600 });
|
|
34
|
+
}
|
|
35
|
+
function backUpIfCorrupt() {
|
|
36
|
+
try {
|
|
37
|
+
JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (err.code === 'ENOENT')
|
|
41
|
+
return;
|
|
42
|
+
const backup = `${CONFIG_PATH}.corrupt-${Date.now()}`;
|
|
43
|
+
fs.copyFileSync(CONFIG_PATH, backup);
|
|
44
|
+
fs.chmodSync(backup, 0o600);
|
|
45
|
+
process.stderr.write(`warn: the unreadable config was kept as ${backup}\n`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function saveCredentials(data, baseUrl) {
|
|
49
|
+
saveConfig({ ...data, credentials_base_url: originOf(baseUrl) });
|
|
50
|
+
}
|
|
51
|
+
export function originOf(url) {
|
|
52
|
+
try {
|
|
53
|
+
return new URL(url).origin;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return url;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function setConfigKey(key, value) {
|
|
60
|
+
saveConfig({ [key]: value });
|
|
61
|
+
}
|
|
62
|
+
export function clearConfig() {
|
|
63
|
+
try {
|
|
64
|
+
fs.unlinkSync(CONFIG_PATH);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function maskedConfig() {
|
|
70
|
+
const cfg = loadConfig();
|
|
71
|
+
const masked = { ...cfg };
|
|
72
|
+
if (masked.token)
|
|
73
|
+
masked.token = '***';
|
|
74
|
+
if (masked.api_key)
|
|
75
|
+
masked.api_key = '***';
|
|
76
|
+
return masked;
|
|
77
|
+
}
|
|
78
|
+
function isLocal(url) {
|
|
79
|
+
return ['localhost', '127.0.0.1', '[::1]', '::1'].includes(url.hostname);
|
|
80
|
+
}
|
|
81
|
+
export function resolveCredentials(flags, baseUrl) {
|
|
82
|
+
const cfg = loadConfig();
|
|
83
|
+
const explicitToken = flags.token !== undefined ? flags.token || undefined : process.env.FACES_TOKEN || undefined;
|
|
84
|
+
const explicitKey = flags['api-key'] !== undefined ? flags['api-key'] || undefined : process.env.FACES_API_KEY || undefined;
|
|
85
|
+
const tokenGiven = flags.token !== undefined || Boolean(process.env.FACES_TOKEN);
|
|
86
|
+
const keyGiven = flags['api-key'] !== undefined || Boolean(process.env.FACES_API_KEY);
|
|
87
|
+
let token = tokenGiven ? explicitToken : undefined;
|
|
88
|
+
let apiKey = keyGiven ? explicitKey : undefined;
|
|
89
|
+
let withheld;
|
|
90
|
+
const savedToken = tokenGiven ? undefined : cfg.token || undefined;
|
|
91
|
+
const savedKey = keyGiven ? undefined : cfg.api_key || undefined;
|
|
92
|
+
if (savedToken || savedKey) {
|
|
93
|
+
const owner = originOf(cfg.credentials_base_url ?? cfg.base_url ?? DEFAULT_BASE_URL);
|
|
94
|
+
if (owner === originOf(baseUrl)) {
|
|
95
|
+
token ??= savedToken;
|
|
96
|
+
apiKey ??= savedKey;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
withheld = `The saved credentials belong to ${owner}, so they were not sent to ${originOf(baseUrl)}. ` +
|
|
100
|
+
'Log in there, or pass --api-key or FACES_API_KEY for it.';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let parsed;
|
|
104
|
+
try {
|
|
105
|
+
parsed = new URL(baseUrl);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
}
|
|
109
|
+
if (parsed && parsed.protocol === 'http:' && !isLocal(parsed) && (token || apiKey)) {
|
|
110
|
+
throw new Error(`Refusing to send credentials over plain http to ${parsed.origin}. Use https, or localhost for development.`);
|
|
111
|
+
}
|
|
112
|
+
return { token, apiKey, withheld, keySaved: Boolean(apiKey) && !keyGiven };
|
|
113
|
+
}
|
|
114
|
+
export function resolveBaseUrl(override) {
|
|
115
|
+
if (override)
|
|
116
|
+
return override;
|
|
117
|
+
if (process.env.FACES_BASE_URL)
|
|
118
|
+
return process.env.FACES_BASE_URL;
|
|
119
|
+
const cfg = loadConfig();
|
|
120
|
+
if (cfg.base_url)
|
|
121
|
+
return cfg.base_url;
|
|
122
|
+
return 'https://api.faces.sh';
|
|
123
|
+
}
|
|
124
|
+
export function resolveToken(override) {
|
|
125
|
+
if (override !== undefined)
|
|
126
|
+
return override || undefined;
|
|
127
|
+
const env = process.env.FACES_TOKEN;
|
|
128
|
+
if (env)
|
|
129
|
+
return env;
|
|
130
|
+
return loadConfig().token || undefined;
|
|
131
|
+
}
|
|
132
|
+
export function resolveApiKey(override) {
|
|
133
|
+
if (override !== undefined)
|
|
134
|
+
return override || undefined;
|
|
135
|
+
const env = process.env.FACES_API_KEY;
|
|
136
|
+
if (env)
|
|
137
|
+
return env;
|
|
138
|
+
return loadConfig().api_key || undefined;
|
|
139
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FacesAPIError, FacesClient } from './client.js';
|
|
2
|
+
export declare const DECISION_MODELS: readonly ["jev-latest", "clef", "clef-flash"];
|
|
3
|
+
export declare function decisionModels(client: FacesClient): Promise<string[]>;
|
|
4
|
+
export declare const DECISION_FORMATS: readonly ["systemone", "openai"];
|
|
5
|
+
export declare function toOpenAIDecision(model: string | undefined, state: unknown, questions: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
6
|
+
export declare function fromOpenAIAnswers(answers: unknown, questions?: Record<string, unknown>): Record<string, unknown>;
|
|
7
|
+
export declare const MAX_QUESTIONS: {
|
|
8
|
+
face: number;
|
|
9
|
+
baseline: number;
|
|
10
|
+
openaiBaseline: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const CHOICE_OPTIONS: {
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function questionsProblem(questions: Record<string, unknown>, withFace: boolean, openaiModel?: boolean): string | undefined;
|
|
17
|
+
export declare const QUESTION_TYPES: readonly ["noul", "choice", "score"];
|
|
18
|
+
export declare function parseDecisionOption(raw: string): {
|
|
19
|
+
name: string;
|
|
20
|
+
definition: string | null;
|
|
21
|
+
} | undefined;
|
|
22
|
+
export declare function decisionLines(answers: Record<string, unknown>, barWidth?: number): string[];
|
|
23
|
+
export declare const MAX_WARM_UP_WAIT_S = 300;
|
|
24
|
+
export declare function warmUpWait(status: number, retryAfter: number | undefined, waitedS: number): number | undefined;
|
|
25
|
+
export interface DecisionCauses {
|
|
26
|
+
cause?: string;
|
|
27
|
+
causes?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare function causeLines(data: DecisionCauses, questionIds: string[]): string[];
|
|
30
|
+
export declare function heldDecisionError(data: unknown): FacesAPIError | undefined;
|
|
31
|
+
export declare function readStateFlags(flags: {
|
|
32
|
+
state?: string;
|
|
33
|
+
'state-file'?: string;
|
|
34
|
+
}, fail: (message: string) => never): unknown;
|
|
35
|
+
export declare function readQuestionFlags(flags: {
|
|
36
|
+
question?: string;
|
|
37
|
+
type?: string;
|
|
38
|
+
option?: string[];
|
|
39
|
+
level?: string[];
|
|
40
|
+
id?: string;
|
|
41
|
+
'questions-file'?: string;
|
|
42
|
+
}, fail: (message: string) => never): Record<string, unknown> | undefined;
|