@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
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { loadConfig } from './config.js';
|
|
5
|
+
import { MAX_FRONTMATTER_VALUE, quoteYaml, unquoteYaml } from './utils.js';
|
|
6
|
+
import { childPath } from './paths.js';
|
|
7
|
+
export const CATALOG_DIR = path.join(os.homedir(), '.faces', 'catalog');
|
|
8
|
+
export const CATALOG_INDEX = path.join(os.homedir(), '.faces', 'catalog.json');
|
|
9
|
+
function serializeFrontmatter(fm) {
|
|
10
|
+
const lines = ['---'];
|
|
11
|
+
lines.push(`name: ${quoteYaml(fm.name)}`);
|
|
12
|
+
if (fm.description)
|
|
13
|
+
lines.push(`description: ${quoteYaml(fm.description)}`);
|
|
14
|
+
lines.push(`alias: ${quoteYaml(fm.alias)}`);
|
|
15
|
+
if (fm.default_model)
|
|
16
|
+
lines.push(`default_model: ${quoteYaml(fm.default_model)}`);
|
|
17
|
+
if (fm.formula)
|
|
18
|
+
lines.push(`formula: ${quoteYaml(fm.formula)}`);
|
|
19
|
+
if (fm.attributes && Object.keys(fm.attributes).length > 0) {
|
|
20
|
+
lines.push('attributes:');
|
|
21
|
+
for (const [k, v] of Object.entries(fm.attributes)) {
|
|
22
|
+
lines.push(` ${k}: ${quoteYaml(String(v))}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (fm.tags && fm.tags.length > 0) {
|
|
26
|
+
lines.push(`tags: [${fm.tags.join(', ')}]`);
|
|
27
|
+
}
|
|
28
|
+
if (fm.compiled_tokens !== undefined) {
|
|
29
|
+
lines.push(`compiled_tokens: ${fm.compiled_tokens}`);
|
|
30
|
+
}
|
|
31
|
+
for (const line of fm.extraLines ?? [])
|
|
32
|
+
lines.push(line);
|
|
33
|
+
lines.push('---');
|
|
34
|
+
return lines.join('\n');
|
|
35
|
+
}
|
|
36
|
+
function parseFrontmatter(content) {
|
|
37
|
+
const block = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
38
|
+
let match = content.match(block);
|
|
39
|
+
if (!match)
|
|
40
|
+
return { frontmatter: null, body: content, extraKeys: {}, partial: {} };
|
|
41
|
+
const fm = {};
|
|
42
|
+
const extraKeys = {};
|
|
43
|
+
const extraLines = [];
|
|
44
|
+
const attributes = {};
|
|
45
|
+
const knownKeys = new Set(['name', 'description', 'alias', 'attributes', 'tags', 'default_model', 'formula', 'component_counts', 'compiled_tokens', 'profile_token_count']);
|
|
46
|
+
let rest = content;
|
|
47
|
+
while (match) {
|
|
48
|
+
let section = null;
|
|
49
|
+
for (const line of match[1].split('\n')) {
|
|
50
|
+
if (/^\s/.test(line) && line.trim()) {
|
|
51
|
+
if (section === 'attributes') {
|
|
52
|
+
const colonIdx = line.indexOf(':');
|
|
53
|
+
if (colonIdx > 0) {
|
|
54
|
+
const k = line.slice(0, colonIdx).trim();
|
|
55
|
+
if (!(k in attributes))
|
|
56
|
+
attributes[k] = unquoteYaml(line.slice(colonIdx + 1));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (section === 'extra') {
|
|
60
|
+
extraLines.push(line);
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
section = null;
|
|
65
|
+
const colonIdx = line.indexOf(':');
|
|
66
|
+
if (colonIdx < 0)
|
|
67
|
+
continue;
|
|
68
|
+
const key = line.slice(0, colonIdx).trim();
|
|
69
|
+
const val = unquoteYaml(line.slice(colonIdx + 1));
|
|
70
|
+
const seen = fm[key] !== undefined;
|
|
71
|
+
if (key === 'attributes')
|
|
72
|
+
section = 'attributes';
|
|
73
|
+
else if (!knownKeys.has(key)) {
|
|
74
|
+
if (key in extraKeys)
|
|
75
|
+
continue;
|
|
76
|
+
extraKeys[key] = val;
|
|
77
|
+
extraLines.push(line);
|
|
78
|
+
section = 'extra';
|
|
79
|
+
}
|
|
80
|
+
else if (seen)
|
|
81
|
+
continue;
|
|
82
|
+
else if (key === 'name')
|
|
83
|
+
fm.name = val;
|
|
84
|
+
else if (key === 'description')
|
|
85
|
+
fm.description = val;
|
|
86
|
+
else if (key === 'alias')
|
|
87
|
+
fm.alias = val;
|
|
88
|
+
else if (key === 'default_model')
|
|
89
|
+
fm.default_model = val;
|
|
90
|
+
else if (key === 'formula')
|
|
91
|
+
fm.formula = val;
|
|
92
|
+
else if (key === 'tags') {
|
|
93
|
+
const inner = val.replace(/^\[/, '').replace(/\]$/, '');
|
|
94
|
+
fm.tags = inner ? inner.split(',').map(s => s.trim()).filter(Boolean) : [];
|
|
95
|
+
}
|
|
96
|
+
else if (key === 'compiled_tokens')
|
|
97
|
+
fm.compiled_tokens = Number(val) || 0;
|
|
98
|
+
}
|
|
99
|
+
rest = rest.slice(match[0].length);
|
|
100
|
+
match = rest.match(block);
|
|
101
|
+
}
|
|
102
|
+
if (Object.keys(attributes).length > 0)
|
|
103
|
+
fm.attributes = attributes;
|
|
104
|
+
if (extraLines.length > 0)
|
|
105
|
+
fm.extraLines = extraLines;
|
|
106
|
+
if (!fm.name || !fm.alias)
|
|
107
|
+
return { frontmatter: null, body: rest, extraKeys, partial: fm };
|
|
108
|
+
return { frontmatter: fm, body: rest, extraKeys, partial: fm };
|
|
109
|
+
}
|
|
110
|
+
const DEFAULT_BODY = '\n## Notes\n\n';
|
|
111
|
+
export class CatalogService {
|
|
112
|
+
isEnabled() {
|
|
113
|
+
const cfg = loadConfig();
|
|
114
|
+
return cfg.catalog !== 'false';
|
|
115
|
+
}
|
|
116
|
+
writeFace(faceData, description) {
|
|
117
|
+
if (!this.isEnabled())
|
|
118
|
+
return;
|
|
119
|
+
try {
|
|
120
|
+
const alias = faceData.alias;
|
|
121
|
+
const dir = childPath(CATALOG_DIR, alias);
|
|
122
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
123
|
+
const filePath = path.join(dir, 'FACE.md');
|
|
124
|
+
let existingBody = DEFAULT_BODY;
|
|
125
|
+
let existingDescription;
|
|
126
|
+
let existingExtraLines = [];
|
|
127
|
+
if (fs.existsSync(filePath)) {
|
|
128
|
+
const existing = fs.readFileSync(filePath, 'utf8');
|
|
129
|
+
const parsed = parseFrontmatter(existing);
|
|
130
|
+
if (parsed.body.trim())
|
|
131
|
+
existingBody = parsed.body;
|
|
132
|
+
if (parsed.partial.description)
|
|
133
|
+
existingDescription = parsed.partial.description;
|
|
134
|
+
existingExtraLines = parsed.partial.extraLines ?? [];
|
|
135
|
+
}
|
|
136
|
+
const fm = {
|
|
137
|
+
name: faceData.name,
|
|
138
|
+
alias,
|
|
139
|
+
};
|
|
140
|
+
if (description) {
|
|
141
|
+
fm.description = description;
|
|
142
|
+
}
|
|
143
|
+
else if (faceData.description) {
|
|
144
|
+
fm.description = faceData.description;
|
|
145
|
+
}
|
|
146
|
+
else if (existingDescription) {
|
|
147
|
+
if (existingDescription.length > MAX_FRONTMATTER_VALUE) {
|
|
148
|
+
process.stderr.write(`warn: discarded a ${existingDescription.length}-character description on '${alias}': ` +
|
|
149
|
+
'too large to be real. It will be restored from the server on the next sync.\n');
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
fm.description = existingDescription;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (faceData.default_model)
|
|
156
|
+
fm.default_model = faceData.default_model;
|
|
157
|
+
if (faceData.formula)
|
|
158
|
+
fm.formula = faceData.formula;
|
|
159
|
+
if (faceData.basic_facts && Object.keys(faceData.basic_facts).length > 0) {
|
|
160
|
+
const attrs = {};
|
|
161
|
+
for (const [k, v] of Object.entries(faceData.basic_facts)) {
|
|
162
|
+
attrs[k] = typeof v === 'object' && v !== null && 'value' in v ? v.value : String(v);
|
|
163
|
+
}
|
|
164
|
+
fm.attributes = attrs;
|
|
165
|
+
}
|
|
166
|
+
if (faceData.tags && faceData.tags.length > 0)
|
|
167
|
+
fm.tags = faceData.tags;
|
|
168
|
+
if (typeof faceData.compile_tokens_synced === 'number')
|
|
169
|
+
fm.compiled_tokens = faceData.compile_tokens_synced;
|
|
170
|
+
else
|
|
171
|
+
fm.compiled_tokens = 0;
|
|
172
|
+
if (existingExtraLines.length > 0)
|
|
173
|
+
fm.extraLines = existingExtraLines;
|
|
174
|
+
const content = serializeFrontmatter(fm) + '\n' + existingBody;
|
|
175
|
+
fs.writeFileSync(filePath, content);
|
|
176
|
+
this.rebuildIndex();
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
180
|
+
process.stderr.write(`warn: catalog write failed: ${msg}\n`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
deleteFace(alias) {
|
|
184
|
+
if (!this.isEnabled())
|
|
185
|
+
return;
|
|
186
|
+
try {
|
|
187
|
+
const dir = childPath(CATALOG_DIR, alias);
|
|
188
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
189
|
+
this.rebuildIndex();
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
193
|
+
process.stderr.write(`warn: catalog delete failed: ${msg}\n`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
updateTags(alias, tags) {
|
|
197
|
+
if (!this.isEnabled())
|
|
198
|
+
return;
|
|
199
|
+
try {
|
|
200
|
+
const filePath = path.join(childPath(CATALOG_DIR, alias), 'FACE.md');
|
|
201
|
+
if (!fs.existsSync(filePath))
|
|
202
|
+
return;
|
|
203
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
204
|
+
const parsed = parseFrontmatter(content);
|
|
205
|
+
if (!parsed.frontmatter)
|
|
206
|
+
return;
|
|
207
|
+
parsed.frontmatter.tags = tags;
|
|
208
|
+
const newContent = serializeFrontmatter(parsed.frontmatter) + '\n' + parsed.body;
|
|
209
|
+
fs.writeFileSync(filePath, newContent);
|
|
210
|
+
this.rebuildIndex();
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
214
|
+
process.stderr.write(`warn: catalog tag update failed: ${msg}\n`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
rebuildIndex() {
|
|
218
|
+
if (!this.isEnabled())
|
|
219
|
+
return;
|
|
220
|
+
try {
|
|
221
|
+
fs.mkdirSync(CATALOG_DIR, { recursive: true });
|
|
222
|
+
const entries = [];
|
|
223
|
+
const dirs = fs.readdirSync(CATALOG_DIR, { withFileTypes: true });
|
|
224
|
+
for (const dirent of dirs) {
|
|
225
|
+
if (!dirent.isDirectory())
|
|
226
|
+
continue;
|
|
227
|
+
const faceMdPath = path.join(childPath(CATALOG_DIR, dirent.name), 'FACE.md');
|
|
228
|
+
if (!fs.existsSync(faceMdPath))
|
|
229
|
+
continue;
|
|
230
|
+
const content = fs.readFileSync(faceMdPath, 'utf8');
|
|
231
|
+
const { frontmatter } = parseFrontmatter(content);
|
|
232
|
+
if (frontmatter)
|
|
233
|
+
entries.push(frontmatter);
|
|
234
|
+
}
|
|
235
|
+
fs.writeFileSync(CATALOG_INDEX, JSON.stringify(entries, null, 2));
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
239
|
+
process.stderr.write(`warn: catalog index rebuild failed: ${msg}\n`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export declare const CLI_VERSION: string | undefined;
|
|
2
|
+
export declare function outOfDateHint(latest?: string | null): string;
|
|
3
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
4
|
+
export declare function latestCliVersion(): Promise<string | null>;
|
|
5
|
+
export declare function missingFieldsNote(data: unknown, fields: string[]): string | undefined;
|
|
6
|
+
export declare function looksOutOfDate(status: number, message: string): boolean;
|
|
7
|
+
export declare class FacesAPIError extends Error {
|
|
8
|
+
statusCode: number;
|
|
9
|
+
errorCode?: string;
|
|
10
|
+
fallbackAvailable?: boolean;
|
|
11
|
+
details?: Record<string, unknown>;
|
|
12
|
+
retryAfter?: number;
|
|
13
|
+
retryable?: boolean;
|
|
14
|
+
constructor(statusCode: number, message: string, opts?: {
|
|
15
|
+
errorCode?: string;
|
|
16
|
+
fallbackAvailable?: boolean;
|
|
17
|
+
details?: Record<string, unknown>;
|
|
18
|
+
retryAfter?: number;
|
|
19
|
+
retryable?: boolean;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export declare function refusalGuidance(status: number, errorCode: string | undefined, message: string): string | undefined;
|
|
23
|
+
export declare function readableDetail(detail: unknown): string | undefined;
|
|
24
|
+
export declare function parseRetryAfter(raw: string | null | undefined): number | undefined;
|
|
25
|
+
export declare const MAX_RATE_LIMIT_WAIT_S = 60;
|
|
26
|
+
export declare function rateLimitWait(retryAfter: number | undefined, body: string): number | undefined;
|
|
27
|
+
export interface ResponseWithHeaders<T = unknown> {
|
|
28
|
+
data: T;
|
|
29
|
+
headers: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
export declare class FacesClient {
|
|
32
|
+
private baseUrl;
|
|
33
|
+
lastError?: FacesAPIError;
|
|
34
|
+
private withheld?;
|
|
35
|
+
private keySaved;
|
|
36
|
+
private token?;
|
|
37
|
+
private apiKey?;
|
|
38
|
+
constructor(baseUrl: string, token?: string, apiKey?: string, withheld?: string, keySaved?: boolean);
|
|
39
|
+
private url;
|
|
40
|
+
authHeader(requireJwt?: boolean): Record<string, string>;
|
|
41
|
+
private wrapNetworkError;
|
|
42
|
+
private send;
|
|
43
|
+
private parseError;
|
|
44
|
+
get(path: string, opts?: {
|
|
45
|
+
requireJwt?: boolean;
|
|
46
|
+
params?: Record<string, string>;
|
|
47
|
+
optionalAuth?: boolean;
|
|
48
|
+
}): Promise<unknown>;
|
|
49
|
+
getAll(path: string, opts?: {
|
|
50
|
+
requireJwt?: boolean;
|
|
51
|
+
pageSize?: number;
|
|
52
|
+
maxPages?: number;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
data: Array<Record<string, unknown>>;
|
|
55
|
+
pages: number;
|
|
56
|
+
truncated: boolean;
|
|
57
|
+
envelope: Record<string, unknown>;
|
|
58
|
+
}>;
|
|
59
|
+
post(path: string, opts?: {
|
|
60
|
+
requireJwt?: boolean;
|
|
61
|
+
body?: unknown;
|
|
62
|
+
}): Promise<unknown>;
|
|
63
|
+
postWithHeaders(path: string, opts?: {
|
|
64
|
+
requireJwt?: boolean;
|
|
65
|
+
body?: unknown;
|
|
66
|
+
}): Promise<ResponseWithHeaders>;
|
|
67
|
+
postNoAuth(path: string, body: unknown): Promise<unknown>;
|
|
68
|
+
put(path: string, opts?: {
|
|
69
|
+
requireJwt?: boolean;
|
|
70
|
+
body?: unknown;
|
|
71
|
+
}): Promise<unknown>;
|
|
72
|
+
patch(path: string, opts?: {
|
|
73
|
+
requireJwt?: boolean;
|
|
74
|
+
body?: unknown;
|
|
75
|
+
}): Promise<unknown>;
|
|
76
|
+
delete(path: string, opts?: {
|
|
77
|
+
requireJwt?: boolean;
|
|
78
|
+
}): Promise<unknown>;
|
|
79
|
+
getBinary(path: string, opts?: {
|
|
80
|
+
requireJwt?: boolean;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
bytes: Uint8Array;
|
|
83
|
+
contentType: string;
|
|
84
|
+
headers: Record<string, string>;
|
|
85
|
+
}>;
|
|
86
|
+
putForm(path: string, formData: FormData, opts?: {
|
|
87
|
+
requireJwt?: boolean;
|
|
88
|
+
}): Promise<unknown>;
|
|
89
|
+
postForm(path: string, formData: FormData, opts?: {
|
|
90
|
+
requireJwt?: boolean;
|
|
91
|
+
}): Promise<unknown>;
|
|
92
|
+
stream(path: string, body: unknown, opts?: {
|
|
93
|
+
requireJwt?: boolean;
|
|
94
|
+
onHeaders?: (headers: Record<string, string>) => void;
|
|
95
|
+
}): AsyncGenerator<string>;
|
|
96
|
+
}
|
|
97
|
+
export declare function streamErrorOf(data: string): FacesAPIError | undefined;
|
|
98
|
+
export declare function heldChatError(data: unknown): FacesAPIError | undefined;
|