@faces-sh/cli 0.0.0-stage → 1.0.1
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 +43 -0
- package/dist/commands/face/share.d.ts +22 -0
- package/dist/commands/face/share.js +104 -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 +32 -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 +94 -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,68 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { isCalendarDate, table, usd } from '../../utils.js';
|
|
5
|
+
export default class BillingUsage extends BaseCommand {
|
|
6
|
+
static description = 'Aggregated usage analytics';
|
|
7
|
+
static flags = {
|
|
8
|
+
...BaseCommand.baseFlags,
|
|
9
|
+
'group-by': Flags.string({
|
|
10
|
+
description: 'Group results',
|
|
11
|
+
options: ['api_key', 'model', 'llm', 'date'],
|
|
12
|
+
}),
|
|
13
|
+
from: Flags.string({ description: 'Start date (YYYY-MM-DD)' }),
|
|
14
|
+
to: Flags.string({ description: 'End date (YYYY-MM-DD)' }),
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
const { flags } = await this.parse(BillingUsage);
|
|
18
|
+
const client = this.makeClient(flags);
|
|
19
|
+
const groupByMap = {
|
|
20
|
+
api_key: 'api_key_id',
|
|
21
|
+
model: 'llm_model',
|
|
22
|
+
llm: 'llm_model',
|
|
23
|
+
date: 'date',
|
|
24
|
+
};
|
|
25
|
+
for (const [flag, v] of [['--from', flags.from], ['--to', flags.to]]) {
|
|
26
|
+
if (v !== undefined && !isCalendarDate(v))
|
|
27
|
+
this.error(`${flag} must be a date as YYYY-MM-DD (got "${v}").`);
|
|
28
|
+
}
|
|
29
|
+
if (flags.from && flags.to && flags.from > flags.to)
|
|
30
|
+
this.error(`--from (${flags.from}) is after --to (${flags.to}).`);
|
|
31
|
+
const params = {};
|
|
32
|
+
if (flags['group-by'])
|
|
33
|
+
params.group_by = groupByMap[flags['group-by']] ?? flags['group-by'];
|
|
34
|
+
if (flags.from)
|
|
35
|
+
params.from = flags.from;
|
|
36
|
+
if (flags.to)
|
|
37
|
+
params.to = flags.to;
|
|
38
|
+
let data;
|
|
39
|
+
try {
|
|
40
|
+
data = await client.get('/v1/billing/usage', { params });
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (err instanceof FacesAPIError)
|
|
44
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
if (!this.jsonEnabled())
|
|
48
|
+
this.printTable(data, flags['group-by']);
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
printTable(data, groupBy) {
|
|
52
|
+
const all = data.rows ?? [];
|
|
53
|
+
const rows = all.filter((r) => r.group_key !== '__total__');
|
|
54
|
+
if (rows.length === 0) {
|
|
55
|
+
this.log('No usage in this period.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const n = (v) => (typeof v === 'number' ? v.toLocaleString('en-US') : '-');
|
|
59
|
+
const label = (r) => String(r.group_label ?? r.group_key ?? '(none)');
|
|
60
|
+
const head = (groupBy ?? 'api_key').toUpperCase();
|
|
61
|
+
const sum = (k) => rows.reduce((a, r) => a + (typeof r[k] === 'number' ? r[k] : 0), 0);
|
|
62
|
+
const cols = [head, 'REQUESTS', 'INPUT', 'OUTPUT', 'COST'];
|
|
63
|
+
const body = rows.map((r) => [label(r), n(r.request_count), n(r.input_tokens), n(r.output_tokens), usd(r.total_cost_usd)]);
|
|
64
|
+
body.push(['total', n(sum('request_count')), n(sum('input_tokens')), n(sum('output_tokens')), usd(sum('total_cost_usd'))]);
|
|
65
|
+
for (const line of table(cols, body, new Set(cols.slice(1))))
|
|
66
|
+
this.log(line);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class CatalogBackup 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,169 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { BaseCommand } from '../../base.js';
|
|
5
|
+
import { FacesAPIError } from '../../client.js';
|
|
6
|
+
import { flattenAttributes, seg } from '../../utils.js';
|
|
7
|
+
export default class CatalogBackup extends BaseCommand {
|
|
8
|
+
static description = 'Snapshot all faces, groups, and source material for migration';
|
|
9
|
+
static flags = {
|
|
10
|
+
...BaseCommand.baseFlags,
|
|
11
|
+
};
|
|
12
|
+
async run() {
|
|
13
|
+
const { flags } = await this.parse(CatalogBackup);
|
|
14
|
+
const client = this.makeClient(flags);
|
|
15
|
+
const json = this.jsonEnabled();
|
|
16
|
+
let faces;
|
|
17
|
+
try {
|
|
18
|
+
const all = await client.getAll('/v1/faces?include=tags,profile');
|
|
19
|
+
faces = all.data;
|
|
20
|
+
if (all.truncated) {
|
|
21
|
+
this.error('The face list was cut short, so this backup would be incomplete. Nothing was written.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (err instanceof FacesAPIError)
|
|
26
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
if (!json)
|
|
30
|
+
process.stderr.write(`Found ${faces.length} face(s)\n`);
|
|
31
|
+
const backupFaces = [];
|
|
32
|
+
for (const face of faces) {
|
|
33
|
+
const alias = face.alias;
|
|
34
|
+
if (!json)
|
|
35
|
+
process.stderr.write(` ${alias}: `);
|
|
36
|
+
const tags = face.tags ?? [];
|
|
37
|
+
const entry = {
|
|
38
|
+
alias,
|
|
39
|
+
name: face.name,
|
|
40
|
+
description: face.description ?? null,
|
|
41
|
+
basic_facts: face.basic_facts ? flattenAttributes(face.basic_facts) : null,
|
|
42
|
+
default_model: face.default_model ?? null,
|
|
43
|
+
default_tools: face.default_tools ?? [],
|
|
44
|
+
formula: face.formula ?? null,
|
|
45
|
+
tags,
|
|
46
|
+
documents: [],
|
|
47
|
+
threads: [],
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const full = await client.get(`/v1/faces/${seg(alias)}?include=profile`);
|
|
51
|
+
entry.specialty = full.specialty ?? null;
|
|
52
|
+
entry.profile_addendum = full.profile_addendum ?? null;
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
try {
|
|
56
|
+
const docs = await client.get('/v1/compile/documents', { params: { alias } });
|
|
57
|
+
for (const doc of docs) {
|
|
58
|
+
entry.documents.push({
|
|
59
|
+
label: doc.label ?? null,
|
|
60
|
+
content: doc.content,
|
|
61
|
+
perspective: doc.perspective ?? null,
|
|
62
|
+
medium: doc.medium ?? null,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
try {
|
|
68
|
+
const threads = await client.get('/v1/compile/threads', { params: { alias, include_uploads: 'true' } });
|
|
69
|
+
for (const thread of threads) {
|
|
70
|
+
const threadId = thread.thread_id;
|
|
71
|
+
try {
|
|
72
|
+
const full = await client.get(`/v1/compile/threads/${seg(threadId)}`);
|
|
73
|
+
const messages = full.messages ?? [];
|
|
74
|
+
entry.threads.push({
|
|
75
|
+
label: thread.label ?? null,
|
|
76
|
+
messages,
|
|
77
|
+
medium: thread.medium ?? null,
|
|
78
|
+
source: thread.source ?? null,
|
|
79
|
+
corpus: Boolean(thread.corpus_medium) || thread.read_only === true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch { }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
if (!json)
|
|
87
|
+
process.stderr.write(`${entry.documents.length} doc(s), ${entry.threads.length} thread(s), ${tags.length} tag(s)\n`);
|
|
88
|
+
backupFaces.push(entry);
|
|
89
|
+
}
|
|
90
|
+
const backupGroups = [];
|
|
91
|
+
const gaps = [];
|
|
92
|
+
try {
|
|
93
|
+
const resp = await client.get('/v1/me/groups');
|
|
94
|
+
let groups = resp.data ?? resp;
|
|
95
|
+
groups = groups.filter(t => t.kind !== 'personal');
|
|
96
|
+
for (const group of groups) {
|
|
97
|
+
const groupId = group.id;
|
|
98
|
+
if (!json)
|
|
99
|
+
process.stderr.write(` group ${group.name}: `);
|
|
100
|
+
let memberAliases = [];
|
|
101
|
+
try {
|
|
102
|
+
const membersResp = await client.get(`/v1/groups/${seg(groupId)}/members`);
|
|
103
|
+
const members = membersResp.data ?? [];
|
|
104
|
+
const uidToAlias = new Map();
|
|
105
|
+
for (const f of faces) {
|
|
106
|
+
if (f.uid)
|
|
107
|
+
uidToAlias.set(f.uid, f.alias);
|
|
108
|
+
}
|
|
109
|
+
for (const m of members) {
|
|
110
|
+
const iamId = m.iam_id;
|
|
111
|
+
const alias = uidToAlias.get(iamId) ?? iamId;
|
|
112
|
+
memberAliases.push(alias);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
gaps.push(`members of group ${group.name}`);
|
|
117
|
+
}
|
|
118
|
+
let groupTags = [];
|
|
119
|
+
try {
|
|
120
|
+
const tagResp = await client.get(`/v1/groups/${seg(groupId)}/tags`);
|
|
121
|
+
groupTags = tagResp.tags ?? [];
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
gaps.push(`tags of group ${group.name}`);
|
|
125
|
+
}
|
|
126
|
+
backupGroups.push({
|
|
127
|
+
name: group.name,
|
|
128
|
+
description: group.description ?? null,
|
|
129
|
+
protocol: group.protocol ?? null,
|
|
130
|
+
tags: groupTags,
|
|
131
|
+
members: memberAliases,
|
|
132
|
+
});
|
|
133
|
+
if (!json)
|
|
134
|
+
process.stderr.write(`${memberAliases.length} member(s), ${groupTags.length} tag(s)\n`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
gaps.push('groups');
|
|
139
|
+
}
|
|
140
|
+
const backup = {
|
|
141
|
+
version: 2,
|
|
142
|
+
created_at: new Date().toISOString(),
|
|
143
|
+
faces: backupFaces,
|
|
144
|
+
groups: backupGroups,
|
|
145
|
+
};
|
|
146
|
+
const backupDir = path.join(os.homedir(), '.faces', 'backups');
|
|
147
|
+
fs.mkdirSync(backupDir, { recursive: true });
|
|
148
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
149
|
+
const filePath = path.join(backupDir, `${timestamp}.json`);
|
|
150
|
+
fs.writeFileSync(filePath, JSON.stringify(backup, null, 2));
|
|
151
|
+
const totalDocs = backupFaces.reduce((n, f) => n + f.documents.length, 0);
|
|
152
|
+
const totalThreads = backupFaces.reduce((n, f) => n + f.threads.length, 0);
|
|
153
|
+
if (!json) {
|
|
154
|
+
this.log(`\nBackup saved: ${filePath}`);
|
|
155
|
+
this.log(` ${backupFaces.length} face(s), ${totalDocs} document(s), ${totalThreads} thread(s), ${backupGroups.length} group(s)`);
|
|
156
|
+
if (gaps.length > 0) {
|
|
157
|
+
this.log(` Not captured: ${gaps.join(', ')}. Restoring from this file will not bring them back.`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
path: filePath,
|
|
162
|
+
faces: backupFaces.length,
|
|
163
|
+
documents: totalDocs,
|
|
164
|
+
threads: totalThreads,
|
|
165
|
+
groups: backupGroups.length,
|
|
166
|
+
...(gaps.length > 0 ? { not_captured: gaps } : {}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class CatalogDoctor extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
fix: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
6
|
+
generate: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
'allow-paid': 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
|
+
run(): Promise<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { Flags } from '@oclif/core';
|
|
4
|
+
import { BaseCommand } from '../../base.js';
|
|
5
|
+
import { FacesAPIError } from '../../client.js';
|
|
6
|
+
import { loadConfig } from '../../config.js';
|
|
7
|
+
import { unquoteYaml, seg, postChat } from '../../utils.js';
|
|
8
|
+
import { CatalogService, CATALOG_DIR } from '../../catalog.js';
|
|
9
|
+
import { GroupCatalogService, GROUPS_DIR, slugifyGroupName } from '../../group-catalog.js';
|
|
10
|
+
import { resolveEndpoint, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT } from '../../routing.js';
|
|
11
|
+
export default class CatalogDoctor extends BaseCommand {
|
|
12
|
+
static description = 'Diagnose and repair the local face and group catalog. --generate bills, so it needs --allow-paid.';
|
|
13
|
+
static flags = {
|
|
14
|
+
...BaseCommand.baseFlags,
|
|
15
|
+
fix: Flags.boolean({ description: 'Rebuild missing or stale catalog entries from API', default: false }),
|
|
16
|
+
generate: Flags.boolean({
|
|
17
|
+
description: 'Fix, then write a description for each face that has none by asking the face. This bills: each one ' +
|
|
18
|
+
'is a chat on gpt-5-nano (or the catalog_model you set), charged to credits. Needs --allow-paid.',
|
|
19
|
+
default: false,
|
|
20
|
+
}),
|
|
21
|
+
'allow-paid': Flags.boolean({
|
|
22
|
+
description: 'Permit the charge for --generate. Without this flag --generate sends nothing and nothing is charged.',
|
|
23
|
+
default: false,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(CatalogDoctor);
|
|
28
|
+
if (flags.generate && !flags['allow-paid']) {
|
|
29
|
+
this.error('Generating descriptions bills your account: each one is a chat with the face, charged to credits. ' +
|
|
30
|
+
'Re-run with --allow-paid if you meant to pay.\n' +
|
|
31
|
+
'To repair the catalog without generating anything, which is free: faces catalog:doctor --fix');
|
|
32
|
+
}
|
|
33
|
+
const client = this.makeClient(flags);
|
|
34
|
+
const catalog = new CatalogService();
|
|
35
|
+
const groupCatalog = new GroupCatalogService();
|
|
36
|
+
let remoteFaces;
|
|
37
|
+
try {
|
|
38
|
+
const all = await client.getAll('/v1/faces?include=tags,profile');
|
|
39
|
+
if (all.truncated) {
|
|
40
|
+
this.error('The face list was cut short, so a comparison against the catalog would be wrong.');
|
|
41
|
+
}
|
|
42
|
+
const arr = all.data;
|
|
43
|
+
remoteFaces = await Promise.all(arr.map(async (f) => {
|
|
44
|
+
try {
|
|
45
|
+
const full = await client.get(`/v1/faces/${seg(f.alias)}?include=tags,profile`);
|
|
46
|
+
return full;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return { ...f, uid: f.alias };
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
if (err instanceof FacesAPIError)
|
|
55
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
const remoteByAlias = new Map();
|
|
59
|
+
for (const f of remoteFaces) {
|
|
60
|
+
remoteByAlias.set(f.alias, f);
|
|
61
|
+
}
|
|
62
|
+
const localAliases = new Set();
|
|
63
|
+
const localFrontmatters = new Map();
|
|
64
|
+
try {
|
|
65
|
+
if (fs.existsSync(CATALOG_DIR)) {
|
|
66
|
+
for (const dirent of fs.readdirSync(CATALOG_DIR, { withFileTypes: true })) {
|
|
67
|
+
if (!dirent.isDirectory())
|
|
68
|
+
continue;
|
|
69
|
+
localAliases.add(dirent.name);
|
|
70
|
+
const faceMdPath = path.join(CATALOG_DIR, dirent.name, 'FACE.md');
|
|
71
|
+
if (fs.existsSync(faceMdPath)) {
|
|
72
|
+
const content = fs.readFileSync(faceMdPath, 'utf8');
|
|
73
|
+
const match = content.match(/^---\n([\s\S]*?)\n---/);
|
|
74
|
+
if (match) {
|
|
75
|
+
const fm = { alias: dirent.name };
|
|
76
|
+
for (const line of match[1].split('\n')) {
|
|
77
|
+
if (line.startsWith(' '))
|
|
78
|
+
continue;
|
|
79
|
+
const ci = line.indexOf(':');
|
|
80
|
+
if (ci < 0)
|
|
81
|
+
continue;
|
|
82
|
+
const k = line.slice(0, ci).trim();
|
|
83
|
+
const v = unquoteYaml(line.slice(ci + 1));
|
|
84
|
+
if (k === 'name')
|
|
85
|
+
fm.name = v;
|
|
86
|
+
if (k === 'description')
|
|
87
|
+
fm.description = v;
|
|
88
|
+
}
|
|
89
|
+
if (fm.name)
|
|
90
|
+
localFrontmatters.set(dirent.name, fm);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch { }
|
|
97
|
+
const missing = [];
|
|
98
|
+
const stale = [];
|
|
99
|
+
const noDescription = [];
|
|
100
|
+
const orphaned = [];
|
|
101
|
+
for (const [alias, remote] of remoteByAlias) {
|
|
102
|
+
if (!localAliases.has(alias)) {
|
|
103
|
+
missing.push(remote);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const local = localFrontmatters.get(alias);
|
|
107
|
+
if (local && local.name !== remote.name) {
|
|
108
|
+
stale.push(remote);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const local = localFrontmatters.get(alias);
|
|
112
|
+
if (!local?.description)
|
|
113
|
+
noDescription.push(alias);
|
|
114
|
+
}
|
|
115
|
+
for (const alias of localAliases) {
|
|
116
|
+
if (!remoteByAlias.has(alias))
|
|
117
|
+
orphaned.push(alias);
|
|
118
|
+
}
|
|
119
|
+
let remoteGroups = [];
|
|
120
|
+
let allRemoteSlugs = new Set();
|
|
121
|
+
let groupsFetched = false;
|
|
122
|
+
const localGroupNames = new Set(groupCatalog.listGroups());
|
|
123
|
+
try {
|
|
124
|
+
const resp = await client.get('/v1/me/groups');
|
|
125
|
+
const all = resp.data ?? resp;
|
|
126
|
+
allRemoteSlugs = new Set(all.map(t => slugifyGroupName(String(t.name))));
|
|
127
|
+
remoteGroups = all.filter(t => t.kind !== 'personal');
|
|
128
|
+
groupsFetched = true;
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
131
|
+
const missingGroups = remoteGroups.filter(t => !localGroupNames.has(slugifyGroupName(String(t.name))));
|
|
132
|
+
const orphanedGroups = groupsFetched
|
|
133
|
+
? [...localGroupNames].filter(name => !allRemoteSlugs.has(name))
|
|
134
|
+
: [];
|
|
135
|
+
const removableGroups = orphanedGroups.filter(name => !groupCatalog.hasLocalContent(name));
|
|
136
|
+
const keptGroups = orphanedGroups.filter(name => groupCatalog.hasLocalContent(name));
|
|
137
|
+
const doFix = flags.fix || flags.generate;
|
|
138
|
+
if (!doFix) {
|
|
139
|
+
const issues = [];
|
|
140
|
+
if (missing.length > 0)
|
|
141
|
+
issues.push(`${missing.length} face(s) missing from catalog`);
|
|
142
|
+
if (stale.length > 0)
|
|
143
|
+
issues.push(`${stale.length} face(s) out of sync`);
|
|
144
|
+
if (orphaned.length > 0)
|
|
145
|
+
issues.push(`${orphaned.length} orphaned catalog entries (face deleted on server)`);
|
|
146
|
+
if (noDescription.length > 0)
|
|
147
|
+
issues.push(`${noDescription.length} face(s) without a description`);
|
|
148
|
+
if (missingGroups.length > 0)
|
|
149
|
+
issues.push(`${missingGroups.length} group(s) missing from local catalog`);
|
|
150
|
+
if (removableGroups.length > 0)
|
|
151
|
+
issues.push(`${removableGroups.length} local group(s) no longer on the server`);
|
|
152
|
+
if (keptGroups.length > 0) {
|
|
153
|
+
issues.push(`${keptGroups.length} local group(s) no longer on the server with local content: ${keptGroups.join(', ')}`);
|
|
154
|
+
}
|
|
155
|
+
if (issues.length === 0) {
|
|
156
|
+
this.log('Catalog is healthy.');
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
for (const issue of issues)
|
|
160
|
+
this.log(issue);
|
|
161
|
+
this.log('');
|
|
162
|
+
this.log('Run faces catalog:doctor --fix to repair catalog');
|
|
163
|
+
if (noDescription.length > 0) {
|
|
164
|
+
this.log('Run faces catalog:doctor --generate --allow-paid to also write missing descriptions (billed)');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
missing: missing.length,
|
|
169
|
+
stale: stale.length,
|
|
170
|
+
orphaned: orphaned.length,
|
|
171
|
+
noDescription: noDescription.length,
|
|
172
|
+
missingGroups: missingGroups.length,
|
|
173
|
+
orphanedGroups: removableGroups.length,
|
|
174
|
+
orphanedGroupsKept: keptGroups,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
let fixed = 0;
|
|
178
|
+
for (const face of [...missing, ...stale]) {
|
|
179
|
+
catalog.writeFace(face);
|
|
180
|
+
fixed++;
|
|
181
|
+
}
|
|
182
|
+
for (const [alias, remote] of remoteByAlias) {
|
|
183
|
+
if (!missing.some((f) => f.alias === alias) && !stale.some((f) => f.alias === alias)) {
|
|
184
|
+
catalog.writeFace(remote);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
let removed = 0;
|
|
188
|
+
for (const alias of orphaned) {
|
|
189
|
+
catalog.deleteFace(alias);
|
|
190
|
+
removed++;
|
|
191
|
+
}
|
|
192
|
+
let groupsSynced = 0;
|
|
193
|
+
const uidToAlias = new Map();
|
|
194
|
+
for (const f of remoteFaces) {
|
|
195
|
+
if (f.uid)
|
|
196
|
+
uidToAlias.set(f.uid, f.alias);
|
|
197
|
+
}
|
|
198
|
+
for (const group of remoteGroups) {
|
|
199
|
+
const groupId = group.id;
|
|
200
|
+
const slug = slugifyGroupName(String(group.name));
|
|
201
|
+
let memberAliases = [];
|
|
202
|
+
try {
|
|
203
|
+
const membersResp = await client.get(`/v1/groups/${seg(groupId)}/members`);
|
|
204
|
+
memberAliases = (membersResp.data ?? []).map(m => {
|
|
205
|
+
const iamId = m.iam_id;
|
|
206
|
+
return uidToAlias.get(iamId) ?? iamId;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch { }
|
|
210
|
+
let tags = [];
|
|
211
|
+
try {
|
|
212
|
+
const tagResp = await client.get(`/v1/groups/${seg(groupId)}/tags`);
|
|
213
|
+
tags = tagResp.tags ?? [];
|
|
214
|
+
}
|
|
215
|
+
catch { }
|
|
216
|
+
groupCatalog.writeGroup(slug, {
|
|
217
|
+
id: groupId,
|
|
218
|
+
name: group.name,
|
|
219
|
+
description: group.description ?? undefined,
|
|
220
|
+
tags,
|
|
221
|
+
members: memberAliases,
|
|
222
|
+
}, group.protocol ?? undefined);
|
|
223
|
+
groupsSynced++;
|
|
224
|
+
}
|
|
225
|
+
let groupsRemoved = 0;
|
|
226
|
+
for (const name of removableGroups) {
|
|
227
|
+
groupCatalog.deleteGroup(name);
|
|
228
|
+
groupsRemoved++;
|
|
229
|
+
}
|
|
230
|
+
this.log(`Fixed ${fixed} face(s), removed ${removed} orphaned face(s) and ${groupsRemoved} orphaned group(s), ` +
|
|
231
|
+
`synced ${groupsSynced} group(s).`);
|
|
232
|
+
for (const name of keptGroups) {
|
|
233
|
+
this.log(`Kept '${name}': the group is gone from the server but TEAM.md has content that exists nowhere else. ` +
|
|
234
|
+
`Remove it yourself with: rm -rf ${path.join(GROUPS_DIR, name)}`);
|
|
235
|
+
}
|
|
236
|
+
if (!groupsFetched) {
|
|
237
|
+
this.log('Could not reach the groups API, so local groups were not checked against the server.');
|
|
238
|
+
}
|
|
239
|
+
if (flags.generate && noDescription.length > 0) {
|
|
240
|
+
const cfg = loadConfig();
|
|
241
|
+
const catalogModel = cfg.catalog_model ?? 'gpt-5-nano';
|
|
242
|
+
this.log(`Generating descriptions for ${noDescription.length} face(s) via ${catalogModel}...`);
|
|
243
|
+
const { endpoint: descEndpoint } = await resolveEndpoint(client, `_@${catalogModel}`);
|
|
244
|
+
let generated = 0;
|
|
245
|
+
for (const alias of noDescription) {
|
|
246
|
+
const remote = remoteByAlias.get(alias);
|
|
247
|
+
if (!remote)
|
|
248
|
+
continue;
|
|
249
|
+
try {
|
|
250
|
+
const prompt = 'Describe yourself in one paragraph. Who are you, what do you care about, and what kind of questions are you best suited to answer?';
|
|
251
|
+
const faceModel = `${alias}@${catalogModel}`;
|
|
252
|
+
let text;
|
|
253
|
+
if (descEndpoint === MESSAGES_ENDPOINT) {
|
|
254
|
+
const resp = (await postChat(client, '/v1/messages', { model: faceModel, messages: [{ role: 'user', content: prompt }], max_tokens: 256 })).data;
|
|
255
|
+
text = resp.content?.find((b) => b.type === 'text')?.text;
|
|
256
|
+
}
|
|
257
|
+
else if (descEndpoint === RESPONSES_ENDPOINT) {
|
|
258
|
+
const resp = (await postChat(client, '/v1/responses', { model: faceModel, input: [{ role: 'user', content: prompt }], max_output_tokens: 256 })).data;
|
|
259
|
+
let out = '';
|
|
260
|
+
for (const item of resp.output ?? []) {
|
|
261
|
+
for (const block of item.content ?? []) {
|
|
262
|
+
if (block.type === 'output_text')
|
|
263
|
+
out += block.text ?? '';
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
text = out || undefined;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
const resp = (await postChat(client, '/v1/chat/completions', { model: faceModel, messages: [{ role: 'user', content: prompt }], max_tokens: 256 })).data;
|
|
270
|
+
text = resp.choices?.[0]?.message?.content;
|
|
271
|
+
}
|
|
272
|
+
if (text) {
|
|
273
|
+
const desc = text.trim();
|
|
274
|
+
catalog.writeFace({ ...remote, description: desc });
|
|
275
|
+
try {
|
|
276
|
+
await client.patch(`/v1/faces/${seg(alias)}`, { body: { description: desc } });
|
|
277
|
+
}
|
|
278
|
+
catch { }
|
|
279
|
+
generated++;
|
|
280
|
+
this.log(` ${alias}: done`);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
this.log(` ${alias}: no response`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
const msg = err instanceof FacesAPIError ? `HTTP ${err.statusCode}: ${err.message}` : String(err);
|
|
288
|
+
this.log(` ${alias}: failed: ${msg}`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
this.log(`Generated ${generated} description(s).`);
|
|
292
|
+
}
|
|
293
|
+
catalog.rebuildIndex();
|
|
294
|
+
return {
|
|
295
|
+
fixed,
|
|
296
|
+
removed,
|
|
297
|
+
groupsRemoved,
|
|
298
|
+
groupsKept: keptGroups,
|
|
299
|
+
groupsSynced,
|
|
300
|
+
generated: flags.generate ? noDescription.length : 0,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class CatalogList 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,39 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { CATALOG_INDEX } from '../../catalog.js';
|
|
4
|
+
export default class CatalogList extends BaseCommand {
|
|
5
|
+
static description = 'List all faces in the local catalog';
|
|
6
|
+
static flags = {
|
|
7
|
+
...BaseCommand.baseFlags,
|
|
8
|
+
};
|
|
9
|
+
async run() {
|
|
10
|
+
let entries = [];
|
|
11
|
+
try {
|
|
12
|
+
if (fs.existsSync(CATALOG_INDEX)) {
|
|
13
|
+
entries = JSON.parse(fs.readFileSync(CATALOG_INDEX, 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
this.error('Could not read catalog.json');
|
|
18
|
+
}
|
|
19
|
+
if (this.jsonEnabled())
|
|
20
|
+
return entries;
|
|
21
|
+
if (entries.length === 0) {
|
|
22
|
+
this.log('(no faces in the local catalog. If you have faces on your account, sync them with: faces catalog:doctor --fix)');
|
|
23
|
+
return entries;
|
|
24
|
+
}
|
|
25
|
+
const clean = (v, max) => {
|
|
26
|
+
const t = String(v ?? '').replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, '');
|
|
27
|
+
return t.length > max ? `${t.slice(0, max - 3)}...` : t;
|
|
28
|
+
};
|
|
29
|
+
const nameWidth = Math.max(...entries.map((e) => clean(e.alias, 40).length));
|
|
30
|
+
const displayWidth = Math.max(...entries.map((e) => clean(e.name, 40).length));
|
|
31
|
+
for (const e of entries) {
|
|
32
|
+
const alias = clean(e.alias, 40).padEnd(nameWidth);
|
|
33
|
+
const name = clean(e.name, 40).padEnd(displayWidth);
|
|
34
|
+
const desc = e.description ? ` ${String(e.description).slice(0, 60)}...` : '';
|
|
35
|
+
this.log(`${alias} ${name}${desc}`);
|
|
36
|
+
}
|
|
37
|
+
return entries;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class CatalogRestore extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
compile: 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
|
+
file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<unknown>;
|
|
15
|
+
private createFace;
|
|
16
|
+
private findLatestBackup;
|
|
17
|
+
}
|