@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,15 @@
|
|
|
1
|
+
import { FacesClient } from './client.js';
|
|
2
|
+
export declare const MESSAGES_ENDPOINT = "/v1/messages";
|
|
3
|
+
export declare const RESPONSES_ENDPOINT = "/v1/responses";
|
|
4
|
+
export declare const CHAT_COMPLETIONS_ENDPOINT = "/v1/chat/completions";
|
|
5
|
+
export interface RouteInfo {
|
|
6
|
+
endpoint: string;
|
|
7
|
+
llm?: string;
|
|
8
|
+
freeWhenConnected: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function decisionModelError(llm?: string): string | undefined;
|
|
11
|
+
export declare function llmFromArg(modelArg: string): string | undefined;
|
|
12
|
+
export declare function faceSpecOf(modelArg: string): string;
|
|
13
|
+
export declare function isCompositeFormula(modelArg: string): boolean;
|
|
14
|
+
export declare function resolveEndpoint(client: FacesClient, modelArg: string): Promise<RouteInfo>;
|
|
15
|
+
export declare function codexEligible(client: FacesClient, llm: string): Promise<boolean | undefined>;
|
package/dist/routing.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { CATALOG_INDEX } from './catalog.js';
|
|
5
|
+
import { DECISION_MODELS } from './decisions.js';
|
|
6
|
+
import { seg } from './utils.js';
|
|
7
|
+
export const MESSAGES_ENDPOINT = '/v1/messages';
|
|
8
|
+
export const RESPONSES_ENDPOINT = '/v1/responses';
|
|
9
|
+
export const CHAT_COMPLETIONS_ENDPOINT = '/v1/chat/completions';
|
|
10
|
+
const CACHE_PATH = path.join(os.homedir(), '.faces', 'models-cache.json');
|
|
11
|
+
const TTL_MS = 60 * 60 * 1000;
|
|
12
|
+
function fallbackEndpoint(llm) {
|
|
13
|
+
if (llm && llm.startsWith('claude'))
|
|
14
|
+
return MESSAGES_ENDPOINT;
|
|
15
|
+
return CHAT_COMPLETIONS_ENDPOINT;
|
|
16
|
+
}
|
|
17
|
+
function readCache() {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(fs.readFileSync(CACHE_PATH, 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function writeCache(models) {
|
|
26
|
+
try {
|
|
27
|
+
const dir = path.dirname(CACHE_PATH);
|
|
28
|
+
if (!fs.existsSync(dir))
|
|
29
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
30
|
+
fs.writeFileSync(CACHE_PATH, JSON.stringify({ fetched_at: Date.now(), models }), { mode: 0o600 });
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function fetchModels(client) {
|
|
36
|
+
const raw = (await client.get('/v1/models'));
|
|
37
|
+
const data = Array.isArray(raw) ? raw : (raw.data ?? raw.models ?? []);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
async function getModels(client) {
|
|
41
|
+
const cache = readCache();
|
|
42
|
+
if (cache && Date.now() - cache.fetched_at < TTL_MS)
|
|
43
|
+
return cache.models;
|
|
44
|
+
try {
|
|
45
|
+
const models = await fetchModels(client);
|
|
46
|
+
writeCache(models);
|
|
47
|
+
return models;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return cache?.models ?? [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function buildMap(models) {
|
|
54
|
+
const map = new Map();
|
|
55
|
+
for (const m of models) {
|
|
56
|
+
if (!m.id || !m.endpoint)
|
|
57
|
+
continue;
|
|
58
|
+
if (m.kind && m.kind !== 'chat')
|
|
59
|
+
continue;
|
|
60
|
+
const key = m.id.toLowerCase();
|
|
61
|
+
const existing = map.get(key);
|
|
62
|
+
const free = m.codex_eligible === true || m.provider === 'openai_oauth';
|
|
63
|
+
if (existing) {
|
|
64
|
+
existing.freeWhenConnected = existing.freeWhenConnected || free;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
map.set(key, { endpoint: m.endpoint, freeWhenConnected: free });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return map;
|
|
71
|
+
}
|
|
72
|
+
function defaultModelFromCatalog(alias) {
|
|
73
|
+
try {
|
|
74
|
+
const entries = JSON.parse(fs.readFileSync(CATALOG_INDEX, 'utf8'));
|
|
75
|
+
const hit = entries.find((e) => e.alias === alias);
|
|
76
|
+
return hit?.default_model || undefined;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function decisionModelError(llm) {
|
|
83
|
+
if (!llm)
|
|
84
|
+
return undefined;
|
|
85
|
+
const want = llm.toLowerCase();
|
|
86
|
+
if (!DECISION_MODELS.includes(want))
|
|
87
|
+
return undefined;
|
|
88
|
+
return `${llm} is a decision model, not a chat model; use \`faces decide\``;
|
|
89
|
+
}
|
|
90
|
+
export function llmFromArg(modelArg) {
|
|
91
|
+
const i = modelArg.lastIndexOf('@');
|
|
92
|
+
return i >= 0 ? modelArg.slice(i + 1) : undefined;
|
|
93
|
+
}
|
|
94
|
+
export function faceSpecOf(modelArg) {
|
|
95
|
+
const i = modelArg.lastIndexOf('@');
|
|
96
|
+
return i >= 0 ? modelArg.slice(0, i) : modelArg;
|
|
97
|
+
}
|
|
98
|
+
export function isCompositeFormula(modelArg) {
|
|
99
|
+
const spec = faceSpecOf(modelArg).trim();
|
|
100
|
+
return /[|&^()]/.test(spec) || /\S\s+\S/.test(spec);
|
|
101
|
+
}
|
|
102
|
+
export async function resolveEndpoint(client, modelArg) {
|
|
103
|
+
let llm = llmFromArg(modelArg);
|
|
104
|
+
const notChat = decisionModelError(llm);
|
|
105
|
+
if (notChat)
|
|
106
|
+
throw new Error(notChat);
|
|
107
|
+
if (!llm && !isCompositeFormula(modelArg)) {
|
|
108
|
+
const alias = modelArg.split('@')[0];
|
|
109
|
+
llm = defaultModelFromCatalog(alias);
|
|
110
|
+
if (!llm) {
|
|
111
|
+
try {
|
|
112
|
+
const face = (await client.get(`/v1/faces/${seg(alias)}`));
|
|
113
|
+
llm = face.default_model || undefined;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const map = buildMap(await getModels(client));
|
|
120
|
+
const hit = llm ? map.get(llm.toLowerCase()) : undefined;
|
|
121
|
+
if (hit)
|
|
122
|
+
return { endpoint: hit.endpoint, llm, freeWhenConnected: hit.freeWhenConnected };
|
|
123
|
+
return { endpoint: fallbackEndpoint(llm), llm, freeWhenConnected: false };
|
|
124
|
+
}
|
|
125
|
+
export async function codexEligible(client, llm) {
|
|
126
|
+
const want = llm.toLowerCase();
|
|
127
|
+
const hits = (await getModels(client)).filter((m) => m.id?.toLowerCase() === want);
|
|
128
|
+
if (hits.length === 0)
|
|
129
|
+
return undefined;
|
|
130
|
+
if (hits.some((m) => m.codex_eligible === true))
|
|
131
|
+
return true;
|
|
132
|
+
if (hits.every((m) => m.codex_eligible === false))
|
|
133
|
+
return false;
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FacesAPIError } from './client.js';
|
|
2
|
+
export declare const SESSIONS_PATH = "/v1/sessions";
|
|
3
|
+
export interface Session {
|
|
4
|
+
object?: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
turns?: number;
|
|
8
|
+
status?: string;
|
|
9
|
+
created_at?: string;
|
|
10
|
+
last_used_at?: string;
|
|
11
|
+
expires_at?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function sessionLines(s: Session): string[];
|
|
14
|
+
export declare function sessionHint(err: FacesAPIError): string | undefined;
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const SESSIONS_PATH = '/v1/sessions';
|
|
2
|
+
export function sessionLines(s) {
|
|
3
|
+
const pairs = [
|
|
4
|
+
['session', s.id],
|
|
5
|
+
['face', s.model],
|
|
6
|
+
['status', s.status],
|
|
7
|
+
['turns', s.turns],
|
|
8
|
+
['created', s.created_at],
|
|
9
|
+
['last used', s.last_used_at],
|
|
10
|
+
['expires', s.expires_at],
|
|
11
|
+
];
|
|
12
|
+
return pairs.filter(([, v]) => v !== undefined && v !== null).map(([k, v]) => `${`${k}:`.padEnd(11)}${v}`);
|
|
13
|
+
}
|
|
14
|
+
export function sessionHint(err) {
|
|
15
|
+
if (err.statusCode === 404)
|
|
16
|
+
return 'Sessions expire 30 days after their last turn, and a closed one cannot be used. Start another with: faces session:create <face>';
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FacesClient } from './client.js';
|
|
2
|
+
export declare const BUILDS_PATH = "/v1/style/builds";
|
|
3
|
+
export declare const VERSIONS_PATH = "/v1/style/versions";
|
|
4
|
+
export declare const STYLE_FACES_PATH = "/v1/style/faces";
|
|
5
|
+
export declare const LIVE_THREAD_MEDIUM = "conversation";
|
|
6
|
+
export declare const EXIT_NO_SUCH_FACE = 4;
|
|
7
|
+
export declare function faceExists(client: FacesClient, alias: string): Promise<boolean>;
|
|
8
|
+
export interface Selectable {
|
|
9
|
+
id: string;
|
|
10
|
+
sourceType: 'thread' | 'document';
|
|
11
|
+
medium?: string;
|
|
12
|
+
isLiveThread: boolean;
|
|
13
|
+
label: string;
|
|
14
|
+
synced: boolean;
|
|
15
|
+
isCorpus: boolean;
|
|
16
|
+
authored?: number;
|
|
17
|
+
printedAt?: string;
|
|
18
|
+
printedMedium?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SourceRef {
|
|
21
|
+
id: string;
|
|
22
|
+
medium?: string;
|
|
23
|
+
source_type: 'thread' | 'document';
|
|
24
|
+
}
|
|
25
|
+
export declare function listSelectable(client: FacesClient, alias: string): Promise<Selectable[]>;
|
|
26
|
+
export declare function parseSourceArg(raw: string): {
|
|
27
|
+
id: string;
|
|
28
|
+
medium?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function pollStyleJob(client: FacesClient, basePath: string, jobId: string, opts?: {
|
|
31
|
+
intervalMs?: number;
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
onPoll?: (d: Record<string, unknown>) => void;
|
|
34
|
+
}): Promise<Record<string, unknown>>;
|
|
35
|
+
export declare function internalFault(error: string, status?: number, errorCode?: string): {
|
|
36
|
+
reference?: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
export declare function chatgptLinked(client: FacesClient): Promise<boolean | undefined>;
|
|
39
|
+
export declare function jobFailureMessage(error: unknown, linked?: boolean, errorCode?: unknown, status?: number): string;
|
|
40
|
+
export declare function publicJob(data: Record<string, unknown>): Record<string, unknown>;
|
|
41
|
+
export declare function jobMedium(job: Record<string, unknown>): string | undefined;
|
|
42
|
+
export declare function formatBuildReport(data: Record<string, unknown>): string[];
|
|
43
|
+
export declare function servedBy(report: Record<string, unknown>): string | undefined;
|
|
44
|
+
export declare function autoTrigger(job: Record<string, unknown>): string | undefined;
|
|
45
|
+
export declare function reportWarnings(job: Record<string, unknown>): string[];
|
|
46
|
+
export declare function styleCreditRefusal(details: Record<string, unknown> | undefined): string;
|
package/dist/style.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { FacesAPIError } from './client.js';
|
|
2
|
+
import { seg } from './utils.js';
|
|
3
|
+
export const BUILDS_PATH = '/v1/style/builds';
|
|
4
|
+
export const VERSIONS_PATH = '/v1/style/versions';
|
|
5
|
+
export const STYLE_FACES_PATH = '/v1/style/faces';
|
|
6
|
+
export const LIVE_THREAD_MEDIUM = 'conversation';
|
|
7
|
+
const UNIDENTIFIED_CORPUS = 'unknown';
|
|
8
|
+
export const EXIT_NO_SUCH_FACE = 4;
|
|
9
|
+
export async function faceExists(client, alias) {
|
|
10
|
+
try {
|
|
11
|
+
await client.get(`/v1/faces/${seg(alias)}`);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
if (err instanceof FacesAPIError && err.statusCode === 404)
|
|
16
|
+
return false;
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function mediumOf(r, sourceType) {
|
|
21
|
+
if (sourceType === 'document')
|
|
22
|
+
return r.medium?.trim() || undefined;
|
|
23
|
+
const declared = r.medium?.trim() || r.corpus_medium?.trim();
|
|
24
|
+
return !declared || declared === UNIDENTIFIED_CORPUS ? undefined : declared;
|
|
25
|
+
}
|
|
26
|
+
function rowToSelectable(r, sourceType) {
|
|
27
|
+
const stamp = r.style ?? undefined;
|
|
28
|
+
return {
|
|
29
|
+
id: String(r.document_id ?? r.thread_id ?? ''),
|
|
30
|
+
sourceType,
|
|
31
|
+
medium: mediumOf(r, sourceType),
|
|
32
|
+
label: r.label?.trim() || '(untitled)',
|
|
33
|
+
synced: Boolean(r.synced),
|
|
34
|
+
isCorpus: sourceType === 'document' || Boolean(r.corpus_medium?.trim()),
|
|
35
|
+
isLiveThread: sourceType === 'thread' && !r.corpus_medium?.trim(),
|
|
36
|
+
authored: r.authored_message_count ?? undefined,
|
|
37
|
+
printedMedium: stamp?.medium,
|
|
38
|
+
printedAt: stamp?.captured_at,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function rowsOf(data) {
|
|
42
|
+
if (Array.isArray(data))
|
|
43
|
+
return data;
|
|
44
|
+
const obj = (data ?? {});
|
|
45
|
+
for (const key of ['documents', 'threads', 'data', 'items']) {
|
|
46
|
+
if (Array.isArray(obj[key]))
|
|
47
|
+
return obj[key];
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
export async function listSelectable(client, alias) {
|
|
52
|
+
const a = encodeURIComponent(alias);
|
|
53
|
+
const [docs, threads] = await Promise.all([
|
|
54
|
+
client.get(`/v1/compile/documents?alias=${a}`),
|
|
55
|
+
client.get(`/v1/compile/threads?alias=${a}&include_uploads=true`),
|
|
56
|
+
]);
|
|
57
|
+
const out = [
|
|
58
|
+
...rowsOf(docs).map((r) => rowToSelectable(r, 'document')),
|
|
59
|
+
...rowsOf(threads).map((r) => rowToSelectable(r, 'thread')),
|
|
60
|
+
];
|
|
61
|
+
return out.filter((s) => s.id);
|
|
62
|
+
}
|
|
63
|
+
export function parseSourceArg(raw) {
|
|
64
|
+
const at = raw.indexOf(':');
|
|
65
|
+
if (at === -1)
|
|
66
|
+
return { id: raw.trim() };
|
|
67
|
+
return { id: raw.slice(0, at).trim(), medium: raw.slice(at + 1).trim() || undefined };
|
|
68
|
+
}
|
|
69
|
+
export async function pollStyleJob(client, basePath, jobId, opts = {}) {
|
|
70
|
+
const interval = opts.intervalMs ?? 3000;
|
|
71
|
+
const timeout = opts.timeoutMs ?? 3_600_000;
|
|
72
|
+
const start = Date.now();
|
|
73
|
+
const endpoint = `${basePath}/${encodeURIComponent(jobId)}`;
|
|
74
|
+
while (true) {
|
|
75
|
+
if (Date.now() - start > timeout) {
|
|
76
|
+
throw new Error(`Timed out after ${Math.round(timeout / 1000)}s. The build may still finish; read it later with: faces style:status ${jobId}`);
|
|
77
|
+
}
|
|
78
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
79
|
+
let data;
|
|
80
|
+
try {
|
|
81
|
+
data = (await client.get(endpoint));
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
if (err instanceof FacesAPIError && err.statusCode >= 500)
|
|
85
|
+
continue;
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
opts.onPoll?.(data);
|
|
89
|
+
const status = String(data.status ?? '');
|
|
90
|
+
if (status === 'done' || status === 'failed')
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const FAULT_REFERENCE = /\bReference ([0-9a-f]{6,})\.?\s*$/i;
|
|
95
|
+
export function internalFault(error, status, errorCode) {
|
|
96
|
+
const ref = FAULT_REFERENCE.exec(error.trim());
|
|
97
|
+
const internal = status === 500 || Boolean(ref) || /^INTERNAL/i.test(errorCode ?? '');
|
|
98
|
+
return internal ? { reference: ref?.[1] } : undefined;
|
|
99
|
+
}
|
|
100
|
+
export async function chatgptLinked(client) {
|
|
101
|
+
try {
|
|
102
|
+
const rows = (await client.get('/v1/oauth', { requireJwt: true }));
|
|
103
|
+
return Array.isArray(rows) && rows.some((r) => r.provider === 'openai');
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function jobFailureMessage(error, linked, errorCode, status) {
|
|
110
|
+
const e = typeof error === 'string' && error ? error : 'unknown error';
|
|
111
|
+
const code = (typeof errorCode === 'string' && errorCode ? errorCode : e).toUpperCase();
|
|
112
|
+
const fault = internalFault(e, status, typeof errorCode === 'string' ? errorCode : undefined);
|
|
113
|
+
if (fault) {
|
|
114
|
+
const ref = fault.reference ? ` Quote reference ${fault.reference} and` : ' Quote';
|
|
115
|
+
return ('the server failed internally, so nothing was installed. This is a fault on the server, not ' +
|
|
116
|
+
`something you did, and re-running is unlikely to help.${ref} the job id from above if you report it.`);
|
|
117
|
+
}
|
|
118
|
+
if (code.startsWith('CHATGPT_AUTH')) {
|
|
119
|
+
const cause = linked === false
|
|
120
|
+
? 'No ChatGPT account is linked, so the build had nothing to run on. Link one with: faces auth:connect openai\n'
|
|
121
|
+
: linked === true
|
|
122
|
+
? 'The ChatGPT link was refused, most likely expired. Reconnect it with: faces auth:connect openai\n'
|
|
123
|
+
: 'The ChatGPT link was refused: it has expired, or none is linked. Check with: faces auth:connections, then: faces auth:connect openai\n';
|
|
124
|
+
return (`${e}\n` +
|
|
125
|
+
cause +
|
|
126
|
+
'Your uploaded material is preserved, so re-running costs nothing extra. Do not switch to a ' +
|
|
127
|
+
'paid model to get around this: it turns a login problem into a bill.');
|
|
128
|
+
}
|
|
129
|
+
if (code.startsWith('CONNECT_REQUIRED')) {
|
|
130
|
+
return (`${e}\n` +
|
|
131
|
+
'A build on the ChatGPT route needs Connect or Pro with ChatGPT linked, and this account is not on ' +
|
|
132
|
+
'either. Re-run with --allow-paid to pay from credits, or subscribe: faces billing:subscription:activate');
|
|
133
|
+
}
|
|
134
|
+
if (code.startsWith('INSUFFICIENT_CREDIT_FOR_STYLE_BUILD')) {
|
|
135
|
+
return (`${e}\n` +
|
|
136
|
+
'Not enough credit for this build, so it was not started and nothing was charged. Top up with: ' +
|
|
137
|
+
'faces billing:topup --amount <usd>. An automatic build is tried again later. On Connect or Pro, a ' +
|
|
138
|
+
'linked ChatGPT account builds at no charge: faces auth:connect openai');
|
|
139
|
+
}
|
|
140
|
+
if (code.startsWith('MODEL_NOT_FREE')) {
|
|
141
|
+
return (`${e}\n` +
|
|
142
|
+
'That model is not Codex-eligible, so it cannot run on a linked ChatGPT plan. Leave out --model to build on the default model, or re-run ' +
|
|
143
|
+
'with --allow-paid if you meant to pay.');
|
|
144
|
+
}
|
|
145
|
+
return e;
|
|
146
|
+
}
|
|
147
|
+
const REPORT_FIELDS = [
|
|
148
|
+
['corpus_threads', 'threads read'],
|
|
149
|
+
];
|
|
150
|
+
const REPORT_PUBLIC_KEYS = new Set([
|
|
151
|
+
'corpus_threads',
|
|
152
|
+
'served_by',
|
|
153
|
+
'skipped_third_person',
|
|
154
|
+
'thin_corpus',
|
|
155
|
+
'auto',
|
|
156
|
+
]);
|
|
157
|
+
const AUTO_PUBLIC_KEYS = ['medium', 'multiple', 'words', 'threshold', 'trigger', 'oauth_only'];
|
|
158
|
+
const SKIPPED_PUBLIC_KEYS = ['id', 'document_id', 'label', 'medium'];
|
|
159
|
+
function pick(obj, keys) {
|
|
160
|
+
const out = {};
|
|
161
|
+
if (!obj || typeof obj !== 'object')
|
|
162
|
+
return out;
|
|
163
|
+
for (const k of keys)
|
|
164
|
+
if (k in obj)
|
|
165
|
+
out[k] = obj[k];
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
export function publicJob(data) {
|
|
169
|
+
const report = data.report;
|
|
170
|
+
if (!report || typeof report !== 'object')
|
|
171
|
+
return data;
|
|
172
|
+
const clean = {};
|
|
173
|
+
for (const [k, v] of Object.entries(report)) {
|
|
174
|
+
if (REPORT_PUBLIC_KEYS.has(k))
|
|
175
|
+
clean[k] = v;
|
|
176
|
+
}
|
|
177
|
+
if (clean.auto && typeof clean.auto === 'object')
|
|
178
|
+
clean.auto = pick(clean.auto, AUTO_PUBLIC_KEYS);
|
|
179
|
+
if (clean.served_by && typeof clean.served_by === 'object')
|
|
180
|
+
clean.served_by = pick(clean.served_by, ['route', 'model', 'fell_back']);
|
|
181
|
+
if (Array.isArray(clean.skipped_third_person)) {
|
|
182
|
+
clean.skipped_third_person = clean.skipped_third_person.map((d) => d !== null && typeof d === 'object' ? pick(d, SKIPPED_PUBLIC_KEYS) : d);
|
|
183
|
+
}
|
|
184
|
+
if (clean.thin_corpus && typeof clean.thin_corpus === 'object') {
|
|
185
|
+
const thin = {};
|
|
186
|
+
for (const [medium, v] of Object.entries(clean.thin_corpus)) {
|
|
187
|
+
thin[medium] = pick(v, ['words', 'threshold']);
|
|
188
|
+
}
|
|
189
|
+
clean.thin_corpus = thin;
|
|
190
|
+
}
|
|
191
|
+
return { ...data, report: clean };
|
|
192
|
+
}
|
|
193
|
+
export function jobMedium(job) {
|
|
194
|
+
const one = job.medium;
|
|
195
|
+
if (typeof one === 'string' && one.trim())
|
|
196
|
+
return one;
|
|
197
|
+
const many = job.media;
|
|
198
|
+
if (Array.isArray(many) && many.length > 0)
|
|
199
|
+
return many.join(', ');
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
export function formatBuildReport(data) {
|
|
203
|
+
const report = (data.report ?? {});
|
|
204
|
+
const pairs = [
|
|
205
|
+
['job', data.job_id ?? '-'],
|
|
206
|
+
['status', data.status ?? '-'],
|
|
207
|
+
];
|
|
208
|
+
const medium = jobMedium(data);
|
|
209
|
+
if (medium)
|
|
210
|
+
pairs.push(['medium', medium]);
|
|
211
|
+
if (data.version_id)
|
|
212
|
+
pairs.push(['version', data.version_id]);
|
|
213
|
+
for (const [key, label] of REPORT_FIELDS) {
|
|
214
|
+
const v = report[key];
|
|
215
|
+
if (v !== undefined && v !== null)
|
|
216
|
+
pairs.push([label, v]);
|
|
217
|
+
}
|
|
218
|
+
const served = servedBy(report);
|
|
219
|
+
if (served)
|
|
220
|
+
pairs.push(['served by', served]);
|
|
221
|
+
const auto = autoTrigger(data);
|
|
222
|
+
if (auto)
|
|
223
|
+
pairs.push(['started by', auto]);
|
|
224
|
+
const width = Math.max(...pairs.map(([label]) => label.length)) + 2;
|
|
225
|
+
const lines = pairs.map(([label, v]) => `${(label + ':').padEnd(width)}${v}`);
|
|
226
|
+
return [...lines, ...reportWarnings(data)];
|
|
227
|
+
}
|
|
228
|
+
export function servedBy(report) {
|
|
229
|
+
const s = report.served_by;
|
|
230
|
+
if (!s || typeof s !== 'object')
|
|
231
|
+
return undefined;
|
|
232
|
+
const where = s.route === 'chatgpt' ? 'your linked ChatGPT account' : s.route === 'faces' ? 'Faces' : String(s.route ?? '-');
|
|
233
|
+
const model = typeof s.model === 'string' ? ` (${s.model})` : '';
|
|
234
|
+
const charged = s.route !== 'faces' ? '' : s.fell_back ? ', the rest charged to credits' : ', charged to credits';
|
|
235
|
+
return `${where}${model}${s.fell_back ? ', after the ChatGPT link failed' : ''}${charged}`;
|
|
236
|
+
}
|
|
237
|
+
export function autoTrigger(job) {
|
|
238
|
+
const auto = job.report?.auto;
|
|
239
|
+
if (!auto || typeof auto !== 'object')
|
|
240
|
+
return undefined;
|
|
241
|
+
const parts = ['automatic build'];
|
|
242
|
+
if (typeof auto.trigger === 'string')
|
|
243
|
+
parts.push(`after ${auto.trigger === 'compile' ? 'a compile' : 'an upload'}`);
|
|
244
|
+
if (typeof auto.words === 'number' && typeof auto.threshold === 'number') {
|
|
245
|
+
const at = typeof auto.multiple === 'number' && auto.multiple > 1 ? `${auto.multiple}x ` : '';
|
|
246
|
+
parts.push(`(${auto.words} words, past ${at}the ${auto.threshold}-word threshold)`);
|
|
247
|
+
}
|
|
248
|
+
return parts.join(' ');
|
|
249
|
+
}
|
|
250
|
+
export function reportWarnings(job) {
|
|
251
|
+
const report = (job.report ?? {});
|
|
252
|
+
const lines = [];
|
|
253
|
+
const skipped = report.skipped_third_person;
|
|
254
|
+
if (Array.isArray(skipped) && skipped.length > 0) {
|
|
255
|
+
const ids = skipped
|
|
256
|
+
.map((d) => (d !== null && typeof d === 'object' ? d.id ?? d.document_id : d))
|
|
257
|
+
.filter((v) => typeof v === 'string' && v);
|
|
258
|
+
lines.push(`Left out ${skipped.length} third-person document(s): writing about this person does not go into a style.` +
|
|
259
|
+
(ids.length > 0 ? ` ${ids.join(', ')}` : ''));
|
|
260
|
+
lines.push(' If one is really their own writing, mark it: faces compile:doc:edit <id> --perspective first-person');
|
|
261
|
+
}
|
|
262
|
+
const thin = report.thin_corpus;
|
|
263
|
+
if (thin && typeof thin === 'object') {
|
|
264
|
+
for (const [medium, v] of Object.entries(thin)) {
|
|
265
|
+
const t = (v ?? {});
|
|
266
|
+
const n = typeof t.words === 'number' ? `${t.words} words` : 'a small sample';
|
|
267
|
+
const of = typeof t.threshold === 'number' ? ` (the automatic threshold is ${t.threshold})` : '';
|
|
268
|
+
lines.push(`Thin sample for ${medium}: built from ${n}${of}. It is installed, but rests on little writing.`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return lines;
|
|
272
|
+
}
|
|
273
|
+
export function styleCreditRefusal(details) {
|
|
274
|
+
const est = details?.estimated_usd;
|
|
275
|
+
const bal = details?.balance_usd;
|
|
276
|
+
const usd = (n) => `$${n.toFixed(2)}`;
|
|
277
|
+
const figures = typeof est === 'number' && typeof bal === 'number'
|
|
278
|
+
? ` It is estimated at up to ${usd(est)}, and your balance is ${usd(bal)}.`
|
|
279
|
+
: typeof est === 'number' ? ` It is estimated at up to ${usd(est)}.` : '';
|
|
280
|
+
const short = typeof est === 'number' && typeof bal === 'number' && est > bal ? Math.ceil(est - bal) : undefined;
|
|
281
|
+
return (`Not enough credit for this style build, which is charged to credits.${figures}\n` +
|
|
282
|
+
`Top up with: faces billing:topup --amount ${short ?? '<usd>'}` +
|
|
283
|
+
', or on Connect or Pro link ChatGPT to build there at no charge: faces auth:connect openai\n' +
|
|
284
|
+
'Nothing was started, and nothing was charged.');
|
|
285
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { FacesAPIError, FacesClient, type ResponseWithHeaders } from './client.js';
|
|
2
|
+
export declare const PROFILE_ADDENDUM_MAX_CHARS = 100000;
|
|
3
|
+
export declare function seg(value: string): string;
|
|
4
|
+
export declare function parseBudget(raw: string, fail: (message: string) => never, flag?: string, max?: number): number;
|
|
5
|
+
export declare function parseTemperature(raw: string, fail: (message: string) => never): number;
|
|
6
|
+
export declare function isMeAlias(alias: string): boolean;
|
|
7
|
+
export declare const ME_MISSING: string;
|
|
8
|
+
export declare function table(headers: string[], rows: string[][], right?: Set<string>): string[];
|
|
9
|
+
export declare function isCalendarDate(s: string): boolean;
|
|
10
|
+
export declare function usd(n: unknown): string;
|
|
11
|
+
export declare function similarityText(v: unknown): string;
|
|
12
|
+
export declare const BINARY_HINTS: Record<string, string>;
|
|
13
|
+
export declare function readTextFile(file: string): string;
|
|
14
|
+
export declare function transcriptSpeakers(text: string): string[] | null;
|
|
15
|
+
export declare function transcriptWarningLines(text: string, alias: string, file?: string): string[];
|
|
16
|
+
export declare function withoutWarnings(data: unknown): unknown;
|
|
17
|
+
export declare function documentWarningLines(result: unknown, text: string | undefined, alias: string, file?: string): string[];
|
|
18
|
+
export declare const COMPILE_USD_PER_MILLION = 25;
|
|
19
|
+
export declare const LARGE_COMPILE_USD = 1;
|
|
20
|
+
export declare function compileRate(client: FacesClient): Promise<number>;
|
|
21
|
+
export declare function compileCostNote(tokens: unknown, ratePerMillion: number): string | undefined;
|
|
22
|
+
export declare function badToolNames(names: string[]): string | undefined;
|
|
23
|
+
export declare function badFaceName(name: string): string | undefined;
|
|
24
|
+
export declare function compact(obj: unknown): unknown;
|
|
25
|
+
export declare function resolveProfileAddendum(text: string | undefined, file: string | undefined): string | undefined;
|
|
26
|
+
export declare function resolveCause(text: string | undefined, file: string | undefined): string | undefined;
|
|
27
|
+
export declare const CAUSE_FLAG_DESCRIPTION: string;
|
|
28
|
+
export declare const CAUSE_FILE_FLAG_DESCRIPTION = "Read --cause from a file.";
|
|
29
|
+
export declare function causeNeedsModel(face: string): string;
|
|
30
|
+
export declare function flattenAttributes(facts: Record<string, unknown>): Record<string, string>;
|
|
31
|
+
export declare const flattenBasicFacts: typeof flattenAttributes;
|
|
32
|
+
export declare function renameFaceFields(face: Record<string, unknown>): Record<string, unknown>;
|
|
33
|
+
export declare function extractStreamDelta(parsed: Record<string, unknown>): string;
|
|
34
|
+
export declare function extractStreamReasoning(parsed: Record<string, unknown>): string;
|
|
35
|
+
export declare const FACES_THINKING_SIGNATURE = "faces-reasoning";
|
|
36
|
+
export declare const FACES_REASONING_ITEM_PREFIX = "rs_faces_";
|
|
37
|
+
export declare function extractCause(body: Record<string, unknown>, endpoint: string): {
|
|
38
|
+
text: string;
|
|
39
|
+
id?: string;
|
|
40
|
+
};
|
|
41
|
+
export declare function extractReasoning(body: Record<string, unknown>, endpoint: string): string;
|
|
42
|
+
export declare const REASONING_FLAG_DESCRIPTION: string;
|
|
43
|
+
export declare function reasoningHeading(face: string): string;
|
|
44
|
+
export declare function reasoningOnlyNote(face: string, llmFlag?: boolean): string;
|
|
45
|
+
export declare function writeReply(model: string, reasoning: string, text: string, showReasoning: boolean, note?: string): void;
|
|
46
|
+
export declare const STREAM_FLAG_DESCRIPTION: string;
|
|
47
|
+
export declare function postChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>): Promise<ResponseWithHeaders>;
|
|
48
|
+
export declare function retryOnceOnWarmUp<T>(send: () => Promise<T>, say?: (seconds: number) => void): Promise<T>;
|
|
49
|
+
export declare function streamChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>, onHeaders?: (headers: Record<string, string>) => void): AsyncGenerator<string>;
|
|
50
|
+
export declare function sayWarmUp(seconds: number): void;
|
|
51
|
+
export declare function compileHint(face: string, recompile: boolean, verb?: string): string;
|
|
52
|
+
export declare function faceRefusalHint(err: FacesAPIError, model: string, style?: string): string | undefined;
|
|
53
|
+
export declare const MIN_MAX_OUTPUT_TOKENS = 16;
|
|
54
|
+
export declare function isMaxTokensRenameError(message: string): boolean;
|
|
55
|
+
export declare const DOCUMENT_VS_THREAD: string;
|
|
56
|
+
export declare const STYLE_FLAG_DESCRIPTION: string;
|
|
57
|
+
export declare const MEDIUM_FLAG_DESCRIPTION: string;
|
|
58
|
+
export declare const SESSION_FLAG_DESCRIPTION = "Add this turn to a session, by id (from faces session:create). The session must be with this face.";
|
|
59
|
+
export declare const COMPACTION_FLAG_DESCRIPTION: string;
|
|
60
|
+
export declare function chatExtras(flags: {
|
|
61
|
+
style?: string;
|
|
62
|
+
medium?: string;
|
|
63
|
+
session?: string;
|
|
64
|
+
compaction?: string;
|
|
65
|
+
}): Record<string, string>;
|
|
66
|
+
export declare const MEDIUM_EDIT_DESCRIPTION: () => string;
|
|
67
|
+
export declare const MEDIUM_REQUIRED_DESCRIPTION: string;
|
|
68
|
+
export declare const MEDIUM_MISSING_MESSAGE: string;
|
|
69
|
+
export declare function warnDroppedParams(headers: Record<string, string>, flagFor: Record<string, string>): void;
|
|
70
|
+
export declare const CHAT_PARAM_FLAGS: Record<string, string>;
|
|
71
|
+
export interface ResolvedFace {
|
|
72
|
+
face: Record<string, unknown>;
|
|
73
|
+
owned: boolean;
|
|
74
|
+
handle: string;
|
|
75
|
+
owner?: string;
|
|
76
|
+
}
|
|
77
|
+
export declare function resolveFace(client: {
|
|
78
|
+
get: (path: string) => Promise<unknown>;
|
|
79
|
+
}, spec: string, include?: string): Promise<ResolvedFace>;
|
|
80
|
+
export declare function currentUsername(client: {
|
|
81
|
+
get: (path: string) => Promise<unknown>;
|
|
82
|
+
}): Promise<string | undefined>;
|
|
83
|
+
export declare function ownsFace(client: {
|
|
84
|
+
get: (path: string) => Promise<unknown>;
|
|
85
|
+
}, spec: string): Promise<boolean | undefined>;
|
|
86
|
+
export declare const MAX_FRONTMATTER_VALUE: number;
|
|
87
|
+
export declare function quoteYaml(value: string): string;
|
|
88
|
+
export declare function unquoteYaml(raw: string): string;
|
|
89
|
+
export declare function faceStyles(face: {
|
|
90
|
+
styles?: unknown;
|
|
91
|
+
}): string[];
|
|
92
|
+
export declare const COMPILE_BLOCKED_FIX: Record<string, string>;
|
|
93
|
+
export declare function compileBlockedLabel(reason: string | null | undefined): string;
|
|
94
|
+
export type Freshness = 'current' | 'stale' | 'unknown';
|
|
95
|
+
export declare function freshnessOf(s: {
|
|
96
|
+
version?: number | null;
|
|
97
|
+
synced_version?: number | null;
|
|
98
|
+
}): Freshness;
|
|
99
|
+
export declare function revisionsBehind(s: {
|
|
100
|
+
version?: number | null;
|
|
101
|
+
synced_version?: number | null;
|
|
102
|
+
}): number | null;
|
|
103
|
+
export declare function messagesAfterSync(messages: Array<{
|
|
104
|
+
timestamp?: string | null;
|
|
105
|
+
}> | null | undefined, syncedAt: string | null | undefined): {
|
|
106
|
+
newer: number;
|
|
107
|
+
unknown: number;
|
|
108
|
+
};
|
|
109
|
+
export declare function freshnessLines(s: {
|
|
110
|
+
version?: number | null;
|
|
111
|
+
synced_version?: number | null;
|
|
112
|
+
compilable?: boolean | null;
|
|
113
|
+
compile_blocked_reason?: string | null;
|
|
114
|
+
}, recompile: string, id?: string): string[];
|
|
115
|
+
export declare function freshnessSummary(items: Array<{
|
|
116
|
+
version?: number | null;
|
|
117
|
+
synced_version?: number | null;
|
|
118
|
+
compilable?: boolean | null;
|
|
119
|
+
compile_blocked_reason?: string | null;
|
|
120
|
+
}>, noun: string): string[];
|
|
121
|
+
export declare const UPLOAD_WARNING_HELP: Record<string, {
|
|
122
|
+
says: string;
|
|
123
|
+
fix?: string;
|
|
124
|
+
}>;
|
|
125
|
+
export declare function uploadWarningLines(result: {
|
|
126
|
+
warnings?: unknown;
|
|
127
|
+
warning_count?: unknown;
|
|
128
|
+
}): string[];
|
|
129
|
+
export declare function readablePatternError(message: string): string;
|
|
130
|
+
export declare function compileStatusOf(status: unknown): string | null;
|
|
131
|
+
export declare function compileProgressLabel(g: {
|
|
132
|
+
status?: string | null;
|
|
133
|
+
progress?: number | null;
|
|
134
|
+
measurable?: boolean | null;
|
|
135
|
+
starts_at?: string | null;
|
|
136
|
+
rush?: boolean | null;
|
|
137
|
+
}, now?: number): string;
|
|
138
|
+
export declare function readableLimit(n: unknown, unit?: string): string;
|
|
139
|
+
export declare const RUSH_FLAG_DESCRIPTION: string;
|
|
140
|
+
export declare function localTime(iso: unknown): string;
|
|
141
|
+
export declare function startsAtLine(iso: unknown, now?: number): string | undefined;
|
|
142
|
+
export declare function msUntilStart(iso: unknown, now?: number): number;
|
|
143
|
+
export declare function makeScheduleLines(resp: {
|
|
144
|
+
starts_at?: unknown;
|
|
145
|
+
rush?: unknown;
|
|
146
|
+
}, askedRush: boolean, now?: number): string[];
|
|
147
|
+
export declare function makeRefusalMessage(err: FacesAPIError, id: string): string;
|
|
148
|
+
export declare function compileLimitText(n: unknown): string;
|
|
149
|
+
export declare function compileFieldLine(key: string, value: unknown, now?: number): string | null | undefined;
|