@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
package/dist/client.js
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export const CLI_VERSION = (() => {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
})();
|
|
12
|
+
export function outOfDateHint(latest) {
|
|
13
|
+
const version = CLI_VERSION ? ` (${CLI_VERSION})` : '';
|
|
14
|
+
if (latest && CLI_VERSION && compareVersions(CLI_VERSION, latest) >= 0) {
|
|
15
|
+
return `Faces CLI ${CLI_VERSION} is up to date (the latest on npm is ${latest}), so this looks like a Faces CLI bug rather than an old install. ` +
|
|
16
|
+
'Please report it, with the command you ran: https://github.com/faces-sh/cli/issues';
|
|
17
|
+
}
|
|
18
|
+
if (latest && CLI_VERSION) {
|
|
19
|
+
return `Your Faces CLI (${CLI_VERSION}) is out of date; the latest is ${latest}. Update with \`npm install -g @faces-sh/cli@latest\` and try again.`;
|
|
20
|
+
}
|
|
21
|
+
return `Your Faces CLI${version} may be out of date. Update with \`npm install -g @faces-sh/cli@latest\` and try again.`;
|
|
22
|
+
}
|
|
23
|
+
export function compareVersions(a, b) {
|
|
24
|
+
const parts = (v) => v.split('-')[0].split('.').map((n) => Number.parseInt(n, 10) || 0);
|
|
25
|
+
const [x, y] = [parts(a), parts(b)];
|
|
26
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
27
|
+
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
28
|
+
if (d !== 0)
|
|
29
|
+
return d < 0 ? -1 : 1;
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
const DEFAULT_API = 'https://api.faces.sh';
|
|
34
|
+
const LATEST_CACHE = path.join(os.homedir(), '.faces', 'latest-version.json');
|
|
35
|
+
const LATEST_TTL_MS = 6 * 3600_000;
|
|
36
|
+
export async function latestCliVersion() {
|
|
37
|
+
try {
|
|
38
|
+
const cached = JSON.parse(fs.readFileSync(LATEST_CACHE, 'utf8'));
|
|
39
|
+
if (cached.latest && Date.now() - (cached.checked_at ?? 0) < LATEST_TTL_MS)
|
|
40
|
+
return cached.latest;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const resp = await fetch('https://registry.npmjs.org/@faces-sh%2fcli/latest', { signal: AbortSignal.timeout(1500) });
|
|
46
|
+
if (!resp.ok)
|
|
47
|
+
return null;
|
|
48
|
+
const latest = (await resp.json()).version ?? null;
|
|
49
|
+
if (latest) {
|
|
50
|
+
try {
|
|
51
|
+
fs.mkdirSync(path.dirname(LATEST_CACHE), { recursive: true });
|
|
52
|
+
fs.writeFileSync(LATEST_CACHE, JSON.stringify({ latest, checked_at: Date.now() }));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return latest;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function missingFieldsNote(data, fields) {
|
|
64
|
+
const o = (data && typeof data === 'object' ? data : {});
|
|
65
|
+
const missing = fields.filter((f) => o[f] === undefined || o[f] === null);
|
|
66
|
+
if (missing.length === 0)
|
|
67
|
+
return undefined;
|
|
68
|
+
const named = missing.map((f) => `\`${f}\``).join(' or ');
|
|
69
|
+
return `The Faces API response did not include ${named}. ${outOfDateHint()}`;
|
|
70
|
+
}
|
|
71
|
+
export function looksOutOfDate(status, message) {
|
|
72
|
+
if (status === 404)
|
|
73
|
+
return message === 'Not Found';
|
|
74
|
+
if (status === 405 || status === 410)
|
|
75
|
+
return true;
|
|
76
|
+
if (status === 422)
|
|
77
|
+
return /\b(body|query) → [\w-]+: (Field required|Extra inputs are not permitted)/.test(message);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
export class FacesAPIError extends Error {
|
|
81
|
+
statusCode;
|
|
82
|
+
errorCode;
|
|
83
|
+
fallbackAvailable;
|
|
84
|
+
details;
|
|
85
|
+
retryAfter;
|
|
86
|
+
retryable;
|
|
87
|
+
constructor(statusCode, message, opts) {
|
|
88
|
+
super(message);
|
|
89
|
+
this.statusCode = statusCode;
|
|
90
|
+
this.name = 'FacesAPIError';
|
|
91
|
+
this.errorCode = opts?.errorCode;
|
|
92
|
+
this.fallbackAvailable = opts?.fallbackAvailable;
|
|
93
|
+
this.details = opts?.details;
|
|
94
|
+
this.retryAfter = opts?.retryAfter;
|
|
95
|
+
this.retryable = opts?.retryable ?? (typeof opts?.details?.retryable === 'boolean' ? opts.details.retryable : undefined);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function refusalGuidance(status, errorCode, message) {
|
|
99
|
+
if (status === 429 && /allowance/i.test(message)) {
|
|
100
|
+
return 'To continue on credits until it resets: faces account:preferences api_fallback true';
|
|
101
|
+
}
|
|
102
|
+
if (status === 429 && /rate limit/i.test(message)) {
|
|
103
|
+
return 'Wait that long before asking again: a request sent sooner is refused too. Limits per plan: https://api.faces.sh/v1/rates';
|
|
104
|
+
}
|
|
105
|
+
if (status === 402 && /card/i.test(message))
|
|
106
|
+
return 'Add a card with: faces billing:card-setup';
|
|
107
|
+
if (status === 401)
|
|
108
|
+
return 'Check what you are signed in with: faces auth:whoami. To sign in again: faces auth:login';
|
|
109
|
+
if (status === 402 && errorCode === 'insufficient_credit_for_rush') {
|
|
110
|
+
return 'Add credit with: faces billing:topup --amount <usd>, or run make again without --rush to start at the scheduled time.';
|
|
111
|
+
}
|
|
112
|
+
if (status === 402)
|
|
113
|
+
return 'Add credit with: faces billing:topup --amount <usd>';
|
|
114
|
+
if (status === 422 && errorCode === 'oauth_only_unavailable') {
|
|
115
|
+
return ('To run it on credits instead, drop --oauth-only. On Free, OAuth-only needs Connect or Pro: ' +
|
|
116
|
+
'faces billing:subscription:activate');
|
|
117
|
+
}
|
|
118
|
+
if (status === 422 && errorCode === 'empty_composite') {
|
|
119
|
+
return 'Nothing is left once the formula is applied, so there is no face to answer. Use a formula whose result is not empty, such as a union (|).';
|
|
120
|
+
}
|
|
121
|
+
if ((status === 502 || status === 503) && errorCode === 'oauth_incomplete') {
|
|
122
|
+
return ('ChatGPT stopped its reply partway, twice in a row. Nothing was charged; try again. To let a ' +
|
|
123
|
+
'reply like this finish on the paid route instead: faces account:preferences api_fallback true');
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
export function readableDetail(detail) {
|
|
128
|
+
if (typeof detail !== 'string' || !detail.trim())
|
|
129
|
+
return undefined;
|
|
130
|
+
try {
|
|
131
|
+
const inner = JSON.parse(detail);
|
|
132
|
+
if (inner && typeof inner === 'object') {
|
|
133
|
+
const o = inner;
|
|
134
|
+
const said = o.detail ?? o.message ?? o.error?.message;
|
|
135
|
+
if (typeof said === 'string' && said.trim())
|
|
136
|
+
return said;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
}
|
|
141
|
+
return detail;
|
|
142
|
+
}
|
|
143
|
+
export function parseRetryAfter(raw) {
|
|
144
|
+
if (!raw || !/^\s*\d+\s*$/.test(raw))
|
|
145
|
+
return undefined;
|
|
146
|
+
return Number(raw.trim());
|
|
147
|
+
}
|
|
148
|
+
export const MAX_RATE_LIMIT_WAIT_S = 60;
|
|
149
|
+
export function rateLimitWait(retryAfter, body) {
|
|
150
|
+
if (retryAfter === undefined || retryAfter > MAX_RATE_LIMIT_WAIT_S)
|
|
151
|
+
return undefined;
|
|
152
|
+
if (/allowance/i.test(body))
|
|
153
|
+
return undefined;
|
|
154
|
+
return retryAfter;
|
|
155
|
+
}
|
|
156
|
+
export class FacesClient {
|
|
157
|
+
baseUrl;
|
|
158
|
+
lastError;
|
|
159
|
+
withheld;
|
|
160
|
+
keySaved;
|
|
161
|
+
token;
|
|
162
|
+
apiKey;
|
|
163
|
+
constructor(baseUrl, token, apiKey, withheld, keySaved = false) {
|
|
164
|
+
this.withheld = withheld;
|
|
165
|
+
this.keySaved = keySaved;
|
|
166
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
167
|
+
this.token = token;
|
|
168
|
+
this.apiKey = apiKey;
|
|
169
|
+
}
|
|
170
|
+
url(p) {
|
|
171
|
+
const full = `${this.baseUrl}${p}`;
|
|
172
|
+
const parsed = new URL(full);
|
|
173
|
+
const sent = full.slice(parsed.origin.length).split(/[?#]/)[0];
|
|
174
|
+
if (parsed.pathname !== sent) {
|
|
175
|
+
throw new Error(`Refusing to send a request whose path would be rewritten: ${sent}`);
|
|
176
|
+
}
|
|
177
|
+
return full;
|
|
178
|
+
}
|
|
179
|
+
authHeader(requireJwt = false) {
|
|
180
|
+
if (requireJwt) {
|
|
181
|
+
if (!this.token) {
|
|
182
|
+
throw new Error(this.withheld ?? 'JWT login required. Run: faces auth:login');
|
|
183
|
+
}
|
|
184
|
+
return { Authorization: `Bearer ${this.token}` };
|
|
185
|
+
}
|
|
186
|
+
if (this.apiKey)
|
|
187
|
+
return { Authorization: `Bearer ${this.apiKey}` };
|
|
188
|
+
if (this.token)
|
|
189
|
+
return { Authorization: `Bearer ${this.token}` };
|
|
190
|
+
throw new Error(this.withheld ?? 'Authentication required. Run: faces auth:login or set FACES_API_KEY');
|
|
191
|
+
}
|
|
192
|
+
wrapNetworkError(err, path) {
|
|
193
|
+
const cause = err?.cause;
|
|
194
|
+
const why = cause?.code ?? cause?.message ?? (err instanceof Error ? err.message : String(err));
|
|
195
|
+
throw new FacesAPIError(0, `Could not reach ${this.baseUrl} (${why}) for ${path}. Check your network connection, and the base URL in: faces config:show`);
|
|
196
|
+
}
|
|
197
|
+
async send(path, url, init) {
|
|
198
|
+
const once = async () => {
|
|
199
|
+
try {
|
|
200
|
+
return await fetch(url, init);
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
this.wrapNetworkError(err, path);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
let resp = await once();
|
|
207
|
+
const sentKey = this.apiKey && init.headers?.Authorization === `Bearer ${this.apiKey}`;
|
|
208
|
+
if (resp.status === 401 && sentKey && this.keySaved && this.token) {
|
|
209
|
+
process.stderr.write('warn: the saved API key was refused (revoked or expired), so the saved login was used instead. Remove the key with: faces config:set api_key ""\n');
|
|
210
|
+
this.apiKey = undefined;
|
|
211
|
+
init = { ...init, headers: { ...init.headers, Authorization: `Bearer ${this.token}` } };
|
|
212
|
+
resp = await once();
|
|
213
|
+
}
|
|
214
|
+
if (resp.ok)
|
|
215
|
+
this.lastError = undefined;
|
|
216
|
+
if (resp.status !== 429)
|
|
217
|
+
return resp;
|
|
218
|
+
const wait = rateLimitWait(parseRetryAfter(resp.headers.get('retry-after')), await resp.clone().text());
|
|
219
|
+
if (wait === undefined)
|
|
220
|
+
return resp;
|
|
221
|
+
process.stderr.write(`Rate limited. Waiting ${wait}s, then asking once more.\n`);
|
|
222
|
+
await new Promise((r) => setTimeout(r, wait * 1000));
|
|
223
|
+
return once();
|
|
224
|
+
}
|
|
225
|
+
async parseError(resp) {
|
|
226
|
+
let msg = resp.statusText;
|
|
227
|
+
let errorCode;
|
|
228
|
+
let fallbackAvailable;
|
|
229
|
+
let details;
|
|
230
|
+
try {
|
|
231
|
+
const body = await resp.json();
|
|
232
|
+
if (body.error === 'oauth_rejected') {
|
|
233
|
+
errorCode = 'oauth_rejected';
|
|
234
|
+
fallbackAvailable = body.fallback_available;
|
|
235
|
+
msg = String(body.detail ?? 'OAuth request rejected');
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (typeof body.error === 'string' && body.detail !== undefined)
|
|
239
|
+
errorCode = body.error;
|
|
240
|
+
else if (typeof body.error_code === 'string')
|
|
241
|
+
errorCode = body.error_code;
|
|
242
|
+
let raw = body.detail ?? body.error ?? body.message ?? msg;
|
|
243
|
+
if (typeof raw === 'object' && raw !== null) {
|
|
244
|
+
const inner = raw.error;
|
|
245
|
+
if (typeof inner === 'object' && inner !== null && 'message' in inner)
|
|
246
|
+
raw = inner;
|
|
247
|
+
}
|
|
248
|
+
if (typeof raw === 'object' && raw !== null) {
|
|
249
|
+
const obj = raw;
|
|
250
|
+
details = obj;
|
|
251
|
+
if (typeof obj.error === 'string')
|
|
252
|
+
errorCode = obj.error;
|
|
253
|
+
else if (typeof obj.code === 'string')
|
|
254
|
+
errorCode = obj.code;
|
|
255
|
+
else if (typeof obj.error_code === 'string')
|
|
256
|
+
errorCode = obj.error_code;
|
|
257
|
+
msg = 'message' in obj ? String(obj.message) : (readableDetail(obj.detail) ?? JSON.stringify(obj));
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
msg = String(raw);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
}
|
|
266
|
+
const type = resp.headers.get('content-type') ?? '';
|
|
267
|
+
if (!type.includes('json')) {
|
|
268
|
+
const origin = new URL(this.baseUrl).origin;
|
|
269
|
+
const error = new FacesAPIError(resp.status, `${origin} did not answer like the Faces API (HTTP ${resp.status}${type ? `, ${type.split(';')[0]}` : ''}). ` +
|
|
270
|
+
`Check the base URL in: faces config:show (the Faces API is ${DEFAULT_API})`);
|
|
271
|
+
this.lastError = error;
|
|
272
|
+
return error;
|
|
273
|
+
}
|
|
274
|
+
if (resp.status === 402)
|
|
275
|
+
msg = `Payment required: ${msg}`;
|
|
276
|
+
if (resp.status === 403)
|
|
277
|
+
msg = `Forbidden: ${msg}`;
|
|
278
|
+
const guidance = refusalGuidance(resp.status, errorCode, msg);
|
|
279
|
+
if (guidance)
|
|
280
|
+
msg = `${msg}\n${guidance}`;
|
|
281
|
+
else if (looksOutOfDate(resp.status, msg)) {
|
|
282
|
+
const base = new URL(this.baseUrl);
|
|
283
|
+
const basePath = base.pathname.replace(/\/$/, '');
|
|
284
|
+
msg = resp.status === 404 && basePath
|
|
285
|
+
? `${msg}\nThe base URL ends in ${basePath}, but routes already include it. Use: faces config:set base_url ${base.origin}`
|
|
286
|
+
: `${msg}\n${outOfDateHint(await latestCliVersion())}`;
|
|
287
|
+
}
|
|
288
|
+
const error = new FacesAPIError(resp.status, msg, {
|
|
289
|
+
errorCode,
|
|
290
|
+
fallbackAvailable,
|
|
291
|
+
details,
|
|
292
|
+
retryAfter: parseRetryAfter(resp.headers.get('retry-after')),
|
|
293
|
+
});
|
|
294
|
+
this.lastError = error;
|
|
295
|
+
return error;
|
|
296
|
+
}
|
|
297
|
+
async get(path, opts = {}) {
|
|
298
|
+
let url = this.url(path);
|
|
299
|
+
if (opts.params && Object.keys(opts.params).length > 0) {
|
|
300
|
+
url += '?' + new URLSearchParams(opts.params).toString();
|
|
301
|
+
}
|
|
302
|
+
let auth = {};
|
|
303
|
+
if (opts.optionalAuth) {
|
|
304
|
+
try {
|
|
305
|
+
auth = this.authHeader();
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
auth = {};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
auth = this.authHeader(opts.requireJwt);
|
|
313
|
+
}
|
|
314
|
+
const resp = await this.send(path, url, { headers: { ...auth } });
|
|
315
|
+
if (!resp.ok)
|
|
316
|
+
throw await this.parseError(resp);
|
|
317
|
+
return resp.json();
|
|
318
|
+
}
|
|
319
|
+
async getAll(path, opts = {}) {
|
|
320
|
+
const maxPages = opts.maxPages ?? 100;
|
|
321
|
+
const rows = [];
|
|
322
|
+
const seen = new Set();
|
|
323
|
+
let cursor;
|
|
324
|
+
let pages = 0;
|
|
325
|
+
let envelope = {};
|
|
326
|
+
for (;;) {
|
|
327
|
+
const extra = new URLSearchParams();
|
|
328
|
+
if (opts.pageSize)
|
|
329
|
+
extra.set('limit', String(opts.pageSize));
|
|
330
|
+
if (cursor)
|
|
331
|
+
extra.set('cursor', cursor);
|
|
332
|
+
const q = extra.toString();
|
|
333
|
+
const url = q ? (path.includes('?') ? `${path}&${q}` : `${path}?${q}`) : path;
|
|
334
|
+
const resp = (await this.get(url, { requireJwt: opts.requireJwt }));
|
|
335
|
+
pages++;
|
|
336
|
+
if (Array.isArray(resp)) {
|
|
337
|
+
return { data: resp, pages, truncated: false, envelope: {} };
|
|
338
|
+
}
|
|
339
|
+
const env = (resp ?? {});
|
|
340
|
+
if (!Array.isArray(env.data)) {
|
|
341
|
+
throw new FacesAPIError(502, `${new URL(this.baseUrl).origin} did not answer like the Faces API: ${path} returned no list. Check the base URL in: faces config:show`);
|
|
342
|
+
}
|
|
343
|
+
if (pages === 1)
|
|
344
|
+
envelope = env;
|
|
345
|
+
if (Array.isArray(env.data))
|
|
346
|
+
rows.push(...env.data);
|
|
347
|
+
const next = typeof env.next_cursor === 'string' && env.next_cursor !== '' ? env.next_cursor : undefined;
|
|
348
|
+
if (env.has_more !== true || !next)
|
|
349
|
+
return { data: rows, pages, truncated: false, envelope };
|
|
350
|
+
if (seen.has(next) || pages >= maxPages)
|
|
351
|
+
return { data: rows, pages, truncated: true, envelope };
|
|
352
|
+
seen.add(next);
|
|
353
|
+
cursor = next;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
async post(path, opts = {}) {
|
|
357
|
+
const resp = await this.send(path, this.url(path), {
|
|
358
|
+
method: 'POST',
|
|
359
|
+
headers: { ...this.authHeader(opts.requireJwt), 'Content-Type': 'application/json' },
|
|
360
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
361
|
+
});
|
|
362
|
+
if (!resp.ok)
|
|
363
|
+
throw await this.parseError(resp);
|
|
364
|
+
return resp.json();
|
|
365
|
+
}
|
|
366
|
+
async postWithHeaders(path, opts = {}) {
|
|
367
|
+
const resp = await this.send(path, this.url(path), {
|
|
368
|
+
method: 'POST',
|
|
369
|
+
headers: { ...this.authHeader(opts.requireJwt), 'Content-Type': 'application/json' },
|
|
370
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
371
|
+
});
|
|
372
|
+
if (!resp.ok)
|
|
373
|
+
throw await this.parseError(resp);
|
|
374
|
+
const headers = {};
|
|
375
|
+
for (const [k, v] of resp.headers.entries())
|
|
376
|
+
headers[k] = v;
|
|
377
|
+
const data = await resp.json();
|
|
378
|
+
return { data, headers };
|
|
379
|
+
}
|
|
380
|
+
async postNoAuth(path, body) {
|
|
381
|
+
const resp = await this.send(path, this.url(path), {
|
|
382
|
+
method: 'POST',
|
|
383
|
+
headers: { 'Content-Type': 'application/json' },
|
|
384
|
+
body: JSON.stringify(body),
|
|
385
|
+
});
|
|
386
|
+
if (!resp.ok)
|
|
387
|
+
throw await this.parseError(resp);
|
|
388
|
+
return resp.json();
|
|
389
|
+
}
|
|
390
|
+
async put(path, opts = {}) {
|
|
391
|
+
const resp = await this.send(path, this.url(path), {
|
|
392
|
+
method: 'PUT',
|
|
393
|
+
headers: { ...this.authHeader(opts.requireJwt), 'Content-Type': 'application/json' },
|
|
394
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
395
|
+
});
|
|
396
|
+
if (!resp.ok)
|
|
397
|
+
throw await this.parseError(resp);
|
|
398
|
+
return resp.json();
|
|
399
|
+
}
|
|
400
|
+
async patch(path, opts = {}) {
|
|
401
|
+
const resp = await this.send(path, this.url(path), {
|
|
402
|
+
method: 'PATCH',
|
|
403
|
+
headers: { ...this.authHeader(opts.requireJwt), 'Content-Type': 'application/json' },
|
|
404
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
405
|
+
});
|
|
406
|
+
if (!resp.ok)
|
|
407
|
+
throw await this.parseError(resp);
|
|
408
|
+
return resp.json();
|
|
409
|
+
}
|
|
410
|
+
async delete(path, opts = {}) {
|
|
411
|
+
const resp = await this.send(path, this.url(path), {
|
|
412
|
+
method: 'DELETE',
|
|
413
|
+
headers: { ...this.authHeader(opts.requireJwt) },
|
|
414
|
+
});
|
|
415
|
+
if (!resp.ok)
|
|
416
|
+
throw await this.parseError(resp);
|
|
417
|
+
const text = await resp.text();
|
|
418
|
+
if (!text)
|
|
419
|
+
return {};
|
|
420
|
+
try {
|
|
421
|
+
return JSON.parse(text);
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return {};
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async getBinary(path, opts = {}) {
|
|
428
|
+
const resp = await this.send(path, this.url(path), { headers: { ...this.authHeader(opts.requireJwt) } });
|
|
429
|
+
if (!resp.ok)
|
|
430
|
+
throw await this.parseError(resp);
|
|
431
|
+
const headers = {};
|
|
432
|
+
for (const [k, v] of resp.headers.entries())
|
|
433
|
+
headers[k.toLowerCase()] = v;
|
|
434
|
+
return {
|
|
435
|
+
bytes: new Uint8Array(await resp.arrayBuffer()),
|
|
436
|
+
contentType: resp.headers.get('content-type') ?? 'application/octet-stream',
|
|
437
|
+
headers,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
async putForm(path, formData, opts = {}) {
|
|
441
|
+
const resp = await this.send(path, this.url(path), {
|
|
442
|
+
method: 'PUT',
|
|
443
|
+
headers: { ...this.authHeader(opts.requireJwt) },
|
|
444
|
+
body: formData,
|
|
445
|
+
});
|
|
446
|
+
if (!resp.ok)
|
|
447
|
+
throw await this.parseError(resp);
|
|
448
|
+
return resp.json();
|
|
449
|
+
}
|
|
450
|
+
async postForm(path, formData, opts = {}) {
|
|
451
|
+
const resp = await this.send(path, this.url(path), {
|
|
452
|
+
method: 'POST',
|
|
453
|
+
headers: { ...this.authHeader(opts.requireJwt) },
|
|
454
|
+
body: formData,
|
|
455
|
+
});
|
|
456
|
+
if (!resp.ok)
|
|
457
|
+
throw await this.parseError(resp);
|
|
458
|
+
return resp.json();
|
|
459
|
+
}
|
|
460
|
+
async *stream(path, body, opts = {}) {
|
|
461
|
+
const resp = await this.send(path, this.url(path), {
|
|
462
|
+
method: 'POST',
|
|
463
|
+
headers: { ...this.authHeader(opts.requireJwt), 'Content-Type': 'application/json' },
|
|
464
|
+
body: JSON.stringify(body),
|
|
465
|
+
});
|
|
466
|
+
if (!resp.ok || !resp.body) {
|
|
467
|
+
throw await this.parseError(resp);
|
|
468
|
+
}
|
|
469
|
+
if (opts.onHeaders) {
|
|
470
|
+
const headers = {};
|
|
471
|
+
for (const [k, v] of resp.headers.entries())
|
|
472
|
+
headers[k.toLowerCase()] = v;
|
|
473
|
+
opts.onHeaders(headers);
|
|
474
|
+
}
|
|
475
|
+
const reader = resp.body.getReader();
|
|
476
|
+
const dec = new TextDecoder();
|
|
477
|
+
let buf = '';
|
|
478
|
+
let sawEvent = false;
|
|
479
|
+
let bare = '';
|
|
480
|
+
const take = (raw) => {
|
|
481
|
+
const line = raw.replace(/\r$/, '');
|
|
482
|
+
if (!line.trim() || line.startsWith(':'))
|
|
483
|
+
return undefined;
|
|
484
|
+
if (/^(data|event|id|retry):/.test(line))
|
|
485
|
+
sawEvent = true;
|
|
486
|
+
else if (!sawEvent)
|
|
487
|
+
bare += line + '\n';
|
|
488
|
+
if (line.startsWith('data:')) {
|
|
489
|
+
const err = streamErrorOf(line.slice(5).trim());
|
|
490
|
+
if (err)
|
|
491
|
+
throw err;
|
|
492
|
+
}
|
|
493
|
+
return line;
|
|
494
|
+
};
|
|
495
|
+
while (true) {
|
|
496
|
+
const { done, value } = await reader.read();
|
|
497
|
+
if (done)
|
|
498
|
+
break;
|
|
499
|
+
buf += dec.decode(value, { stream: true });
|
|
500
|
+
const lines = buf.split('\n');
|
|
501
|
+
buf = lines.pop() ?? '';
|
|
502
|
+
for (const raw of lines) {
|
|
503
|
+
const line = take(raw);
|
|
504
|
+
if (line !== undefined)
|
|
505
|
+
yield line;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const last = take(buf);
|
|
509
|
+
if (last !== undefined)
|
|
510
|
+
yield last;
|
|
511
|
+
if (!sawEvent && bare.trim()) {
|
|
512
|
+
throw streamErrorOf(bare) ?? new FacesAPIError(502, `The server sent a stream with no events in it: ${bare.trim().slice(0, 200)}`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const ANTHROPIC_ERROR_STATUS = {
|
|
517
|
+
invalid_request_error: 400,
|
|
518
|
+
authentication_error: 401,
|
|
519
|
+
billing_error: 402,
|
|
520
|
+
permission_error: 403,
|
|
521
|
+
not_found_error: 404,
|
|
522
|
+
request_too_large: 413,
|
|
523
|
+
rate_limit_error: 429,
|
|
524
|
+
api_error: 500,
|
|
525
|
+
overloaded_error: 503,
|
|
526
|
+
};
|
|
527
|
+
export function streamErrorOf(data) {
|
|
528
|
+
if (!data.includes('error'))
|
|
529
|
+
return undefined;
|
|
530
|
+
let parsed;
|
|
531
|
+
try {
|
|
532
|
+
parsed = JSON.parse(data);
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
537
|
+
if (!parsed || typeof parsed !== 'object')
|
|
538
|
+
return undefined;
|
|
539
|
+
const status = (code) => {
|
|
540
|
+
const n = Number(code);
|
|
541
|
+
return Number.isInteger(n) && n >= 400 && n < 600 ? n : 503;
|
|
542
|
+
};
|
|
543
|
+
const statusOf = (s) => {
|
|
544
|
+
const n = Number(s);
|
|
545
|
+
return s !== undefined && s !== null && Number.isInteger(n) && n >= 400 && n < 600 ? n : undefined;
|
|
546
|
+
};
|
|
547
|
+
const flag = (v) => (typeof v === 'boolean' ? v : undefined);
|
|
548
|
+
const named = (code) => typeof code === 'string' && code !== '' && !/^\d+$/.test(code) ? code : undefined;
|
|
549
|
+
if (parsed.type === 'error') {
|
|
550
|
+
const inner = parsed.error;
|
|
551
|
+
if (inner && typeof inner === 'object') {
|
|
552
|
+
const type = typeof inner.type === 'string' ? inner.type : undefined;
|
|
553
|
+
return new FacesAPIError(statusOf(inner.status) ?? ((type && ANTHROPIC_ERROR_STATUS[type]) || 503), String(inner.message ?? type ?? 'The stream ended with an error.'), { errorCode: named(inner.code) ?? type, retryable: flag(inner.retryable) });
|
|
554
|
+
}
|
|
555
|
+
return new FacesAPIError(statusOf(parsed.status) ?? status(parsed.code), String(parsed.message ?? 'The stream ended with an error.'), {
|
|
556
|
+
errorCode: named(parsed.code),
|
|
557
|
+
retryable: flag(parsed.retryable),
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
const inner = parsed.error;
|
|
561
|
+
if (inner && typeof inner === 'object' && !parsed.choices) {
|
|
562
|
+
const byType = typeof inner.type === 'string' ? ANTHROPIC_ERROR_STATUS[inner.type] : undefined;
|
|
563
|
+
const code = Number(inner.code);
|
|
564
|
+
return new FacesAPIError(statusOf(inner.status) ?? (Number.isInteger(code) && code >= 400 && code < 600 ? code : byType ?? 503), String(inner.message ?? 'The stream ended with an error.'), {
|
|
565
|
+
errorCode: named(inner.code) ?? (typeof inner.type === 'string' ? inner.type : undefined),
|
|
566
|
+
retryable: flag(inner.retryable),
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
return undefined;
|
|
570
|
+
}
|
|
571
|
+
export function heldChatError(data) {
|
|
572
|
+
if (!data || typeof data !== 'object' || Array.isArray(data))
|
|
573
|
+
return undefined;
|
|
574
|
+
const d = data;
|
|
575
|
+
if (!d.error || typeof d.error !== 'object')
|
|
576
|
+
return undefined;
|
|
577
|
+
if ('choices' in d || 'output' in d || d.object === 'response' || d.object === 'chat.completion')
|
|
578
|
+
return undefined;
|
|
579
|
+
if (d.type === 'message' || 'content' in d)
|
|
580
|
+
return undefined;
|
|
581
|
+
const e = d.error;
|
|
582
|
+
const n = Number(e.status);
|
|
583
|
+
const status = Number.isInteger(n) && n >= 400 && n < 600 ? n : 502;
|
|
584
|
+
const said = readableDetail(d.detail) ?? (typeof e.message === 'string' && e.message.trim() ? e.message : undefined);
|
|
585
|
+
const code = typeof e.code === 'string' && !/^\d+$/.test(e.code) ? e.code : typeof e.type === 'string' ? e.type : undefined;
|
|
586
|
+
return new FacesAPIError(status, said ?? 'The request failed after the server held it open.', {
|
|
587
|
+
errorCode: code,
|
|
588
|
+
retryable: typeof e.retryable === 'boolean' ? e.retryable : undefined,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class AccountPreferences extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
'allow-paid': 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
|
+
key: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
|
+
value: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
14
|
+
};
|
|
15
|
+
static examples: string[];
|
|
16
|
+
run(): Promise<unknown>;
|
|
17
|
+
private refuseIfPaid;
|
|
18
|
+
private parseThresholds;
|
|
19
|
+
private printPreferences;
|
|
20
|
+
}
|