@faces-sh/cli 1.1.0 → 1.2.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/README.md +64 -30
- package/dist/billing.js +11 -8
- package/dist/chat-command.d.ts +31 -0
- package/dist/chat-command.js +110 -0
- package/dist/chat.d.ts +47 -0
- package/dist/chat.js +157 -0
- package/dist/choices.d.ts +2 -5
- package/dist/choices.js +9 -8
- package/dist/commands/billing/llm-costs.js +9 -5
- package/dist/commands/billing/subscription/index.js +1 -1
- package/dist/commands/catalog/doctor.js +2 -2
- package/dist/commands/chat/chat.d.ts +31 -0
- package/dist/commands/chat/chat.js +31 -0
- package/dist/commands/chat/messages.d.ts +30 -0
- package/dist/commands/chat/messages.js +21 -0
- package/dist/commands/chat/responses.d.ts +30 -0
- package/dist/commands/chat/responses.js +22 -0
- package/dist/commands/{causes.d.ts → chat/thread.d.ts} +17 -12
- package/dist/commands/chat/thread.js +238 -0
- package/dist/commands/choices.d.ts +1 -2
- package/dist/commands/choices.js +20 -15
- package/dist/commands/conversation/compact.js +13 -16
- package/dist/commands/conversation/create.js +10 -9
- package/dist/commands/decide.d.ts +1 -4
- package/dist/commands/decide.js +53 -81
- package/dist/commands/face/get.js +1 -1
- package/dist/commands/fidelity/pick.js +2 -2
- package/dist/commands/fidelity/run.d.ts +20 -0
- package/dist/commands/fidelity/run.js +99 -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.js +1 -1
- package/dist/commands/media/list.d.ts +12 -0
- package/dist/commands/media/list.js +35 -0
- package/dist/commands/models/list.js +13 -6
- package/dist/commands/session/compact.js +5 -8
- package/dist/commands/session/create.js +9 -8
- package/dist/commands/style/make.js +1 -1
- package/dist/commands/style/upload.js +1 -1
- package/dist/decisions.d.ts +0 -5
- package/dist/decisions.js +0 -18
- package/dist/fidelity.js +3 -3
- package/dist/media.d.ts +8 -0
- package/dist/media.js +12 -0
- package/dist/model.d.ts +11 -0
- package/dist/model.js +53 -0
- package/dist/routing.d.ts +1 -4
- package/dist/routing.js +4 -40
- package/dist/utils.d.ts +1 -25
- package/dist/utils.js +10 -108
- package/oclif.manifest.json +1616 -818
- package/package.json +6 -3
- package/dist/commands/causes.js +0 -146
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { BaseCommand } from '../../base.js';
|
|
4
|
+
import { FacesAPIError } from '../../client.js';
|
|
5
|
+
import { answerLines, fidelityError, fidelityPost } from '../../fidelity.js';
|
|
6
|
+
import { seg } from '../../utils.js';
|
|
7
|
+
export default class FidelityTurn extends BaseCommand {
|
|
8
|
+
static description = 'Send the next turn\'s message on a fidelity run. Prints two answers, a and b, in random order, with ' +
|
|
9
|
+
'nothing saying which is the face. Pick one with faces fidelity:pick before the next turn.';
|
|
10
|
+
static examples = ['<%= config.bin %> <%= command.id %> <run> -m "How was the trip?"'];
|
|
11
|
+
static flags = {
|
|
12
|
+
...BaseCommand.baseFlags,
|
|
13
|
+
message: Flags.string({ char: 'm', description: 'Your message for this turn', exclusive: ['file'] }),
|
|
14
|
+
file: Flags.string({ description: 'Read the message from a file' }),
|
|
15
|
+
};
|
|
16
|
+
static args = {
|
|
17
|
+
run_id: Args.string({ description: 'Fidelity run id, from faces fidelity:start', required: true }),
|
|
18
|
+
};
|
|
19
|
+
async run() {
|
|
20
|
+
const { args, flags } = await this.parse(FidelityTurn);
|
|
21
|
+
const client = this.makeClient(flags);
|
|
22
|
+
let message = flags.message;
|
|
23
|
+
if (flags.file) {
|
|
24
|
+
if (!fs.existsSync(flags.file))
|
|
25
|
+
this.error(`File not found: ${flags.file}`);
|
|
26
|
+
message = fs.readFileSync(flags.file, 'utf8');
|
|
27
|
+
}
|
|
28
|
+
if (!message?.trim())
|
|
29
|
+
this.error('Give the message with -m "..." or --file <path>.');
|
|
30
|
+
let data;
|
|
31
|
+
try {
|
|
32
|
+
data = await fidelityPost(client, `/v1/fidelity/${seg(args.run_id)}/turns`, { message });
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof FacesAPIError)
|
|
36
|
+
this.error(fidelityError(err, { run: args.run_id }));
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
if (this.jsonEnabled())
|
|
40
|
+
return data;
|
|
41
|
+
const turn = Number(data.turn);
|
|
42
|
+
for (const line of answerLines(turn, (data.answers ?? {})))
|
|
43
|
+
this.log(line);
|
|
44
|
+
this.log('');
|
|
45
|
+
this.log(`Pick one: faces fidelity:pick ${args.run_id} a|b [--correction "what they would have said"]`);
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -5,7 +5,7 @@ import { GroupCatalogService } from '../../group-catalog.js';
|
|
|
5
5
|
import { resolveFace, seg } from '../../utils.js';
|
|
6
6
|
export default class GroupAdd extends BaseCommand {
|
|
7
7
|
static description = 'Add face(s) to a group. Any face this account can reach may join: your own, a published one, or one ' +
|
|
8
|
-
'shared with you. Name someone else\'s as owner:alias
|
|
8
|
+
'shared with you. Name someone else\'s as owner:alias.';
|
|
9
9
|
static flags = {
|
|
10
10
|
...BaseCommand.baseFlags,
|
|
11
11
|
face: Flags.string({ description: 'Face alias to add (repeatable)', multiple: true, required: true }),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class MediaList extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
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
|
+
run(): Promise<unknown>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
import { FacesAPIError } from '../../client.js';
|
|
3
|
+
import { MEDIA_PATH, mediaLines, mediaOf } from '../../media.js';
|
|
4
|
+
export default class MediaList extends BaseCommand {
|
|
5
|
+
static description = 'List the media (GET /v1/media): the kinds of writing a source can be, each with its description and ' +
|
|
6
|
+
'the subcategories it covers. A document declares one when it is compiled (--medium), styles are built ' +
|
|
7
|
+
'one per medium, and chat chooses one for each request. Send the name exactly: a subcategory such as ' +
|
|
8
|
+
'keynote is not a medium (it is a speech). No login needed.';
|
|
9
|
+
static examples = [
|
|
10
|
+
'<%= config.bin %> <%= command.id %>',
|
|
11
|
+
'<%= config.bin %> <%= command.id %> --json',
|
|
12
|
+
];
|
|
13
|
+
static flags = {
|
|
14
|
+
...BaseCommand.baseFlags,
|
|
15
|
+
};
|
|
16
|
+
async run() {
|
|
17
|
+
const { flags } = await this.parse(MediaList);
|
|
18
|
+
const client = this.makeClient(flags);
|
|
19
|
+
let raw;
|
|
20
|
+
try {
|
|
21
|
+
raw = await client.get(MEDIA_PATH, { optionalAuth: true });
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err instanceof FacesAPIError)
|
|
25
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}`);
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
const data = mediaOf(raw);
|
|
29
|
+
if (this.jsonEnabled())
|
|
30
|
+
return { object: 'list', data };
|
|
31
|
+
for (const line of mediaLines(data))
|
|
32
|
+
this.log(line);
|
|
33
|
+
return { object: 'list', data };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -2,24 +2,26 @@ import { Flags } from '@oclif/core';
|
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../client.js';
|
|
4
4
|
import { table } from '../../utils.js';
|
|
5
|
-
const KINDS = ['
|
|
5
|
+
const KINDS = ['upstream', 'chat', 'decision', 'compile', 'image', 'transcription'];
|
|
6
6
|
export default class ModelsList extends BaseCommand {
|
|
7
7
|
static description = 'List the models you can name, once each, with their kind, endpoint and price (GET /v1/models). ' +
|
|
8
|
-
'
|
|
8
|
+
'Upstream models are ours, the maestros, written after a face: @alice:maestro-1. Downstream models write ' +
|
|
9
|
+
'the answer, after the /: @alice:maestro-1/gpt-5.4. Each is priced on its own. Without --kind the maestros ' +
|
|
10
|
+
'and the chat models are listed; --kind decision lists the models faces decide answers on. ' +
|
|
9
11
|
'CHATGPT marks the Codex-eligible models, which can run on a linked ChatGPT plan (style builds, interviews). ' +
|
|
10
12
|
'Prices are per million tokens. No login needed.';
|
|
11
13
|
static examples = [
|
|
12
14
|
'<%= config.bin %> <%= command.id %>',
|
|
13
|
-
'<%= config.bin %> <%= command.id %> --kind
|
|
15
|
+
'<%= config.bin %> <%= command.id %> --kind upstream',
|
|
14
16
|
'<%= config.bin %> <%= command.id %> --kind decision',
|
|
15
|
-
'<%= config.bin %> <%= command.id %> --kind
|
|
17
|
+
'<%= config.bin %> <%= command.id %> --kind upstream,compile',
|
|
16
18
|
'<%= config.bin %> <%= command.id %> --kind all --json',
|
|
17
19
|
'<%= config.bin %> <%= command.id %> --provider anthropic',
|
|
18
20
|
];
|
|
19
21
|
static flags = {
|
|
20
22
|
...BaseCommand.baseFlags,
|
|
21
23
|
kind: Flags.string({
|
|
22
|
-
description: `One kind or a comma-separated list: ${KINDS.join(', ')}; or all. Default: chat.`,
|
|
24
|
+
description: `One kind or a comma-separated list: ${KINDS.join(', ')}; or all. Default: upstream and chat.`,
|
|
23
25
|
}),
|
|
24
26
|
provider: Flags.string({ description: 'Only models from this lab (e.g. openai, anthropic, qwen)' }),
|
|
25
27
|
chatgpt: Flags.boolean({
|
|
@@ -84,7 +86,12 @@ export default class ModelsList extends BaseCommand {
|
|
|
84
86
|
if (m.token_basis === 'source')
|
|
85
87
|
notes.push(`${m.id}: priced per million source tokens compiled.`);
|
|
86
88
|
if (m.token_basis === 'processed')
|
|
87
|
-
notes.push(`${m.id}: priced on the tokens each call processes, as its usage reports them.`);
|
|
89
|
+
notes.push(`${m.id}: on /v1/choices, priced on the tokens each call processes, as its usage reports them.`);
|
|
90
|
+
const st = m.steering;
|
|
91
|
+
if (st && typeof st === 'object' && typeof st.input_cost_per_million_tokens === 'number') {
|
|
92
|
+
notes.push(`${m.id}: steering a face over a downstream model (chat, decide) costs $${st.input_cost_per_million_tokens} per million ` +
|
|
93
|
+
`input tokens plus $${st.cost_per_call_usd} a call, with no output charge; the downstream model is billed at its listed price plus the markup.`);
|
|
94
|
+
}
|
|
88
95
|
const inc = m.included_tokens_per_month;
|
|
89
96
|
if (inc && typeof inc === 'object') {
|
|
90
97
|
const plans = Object.entries(inc).filter(([, n]) => typeof n === 'number' && n > 0).map(([p, n]) => `${p[0].toUpperCase()}${p.slice(1)} ${n.toLocaleString('en-US')}`);
|
|
@@ -5,10 +5,10 @@ import { heldDecisionError } from '../../decisions.js';
|
|
|
5
5
|
import { SESSIONS_PATH, sessionHint } from '../../session.js';
|
|
6
6
|
import { retryOnceOnWarmUp, sayWarmUp, seg } from '../../utils.js';
|
|
7
7
|
export default class SessionCompact extends BaseCommand {
|
|
8
|
-
static description = 'Compact a session:
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
8
|
+
static description = 'Compact a session: the face\'s position over the session, kept on the server under a compaction id. ' +
|
|
9
|
+
'Pass that id with --compaction on a later request with the same face, and send only the messages you ' +
|
|
10
|
+
'still want read. Billed on the tokens it reads and writes; on Connect and Pro it counts against the ' +
|
|
11
|
+
'plan\'s allowance. A failed compaction is not charged. ' +
|
|
12
12
|
'A compaction expires 30 days after it is written. Sessions are now called states: see faces state:compact.';
|
|
13
13
|
static examples = [
|
|
14
14
|
'<%= config.bin %> <%= command.id %> fs_SESSION_ID',
|
|
@@ -42,16 +42,13 @@ export default class SessionCompact extends BaseCommand {
|
|
|
42
42
|
throw err;
|
|
43
43
|
}
|
|
44
44
|
if (!json) {
|
|
45
|
-
if (typeof data.cause === 'string')
|
|
46
|
-
this.log(data.cause);
|
|
47
|
-
this.log('');
|
|
48
45
|
this.log(`compaction: ${data.compaction_id ?? '-'}`);
|
|
49
46
|
if (data.turns !== undefined)
|
|
50
47
|
this.log(`turns: ${data.turns}`);
|
|
51
48
|
if (data.expires_at)
|
|
52
49
|
this.log(`expires: ${data.expires_at}`);
|
|
53
50
|
if (data.compaction_id)
|
|
54
|
-
this.log(`\nUse it with: faces
|
|
51
|
+
this.log(`\nUse it with: faces chat:chat @<face>:maestro-1/<model> --compaction ${data.compaction_id} -m "..."`);
|
|
55
52
|
}
|
|
56
53
|
return data;
|
|
57
54
|
}
|
|
@@ -2,29 +2,30 @@ import { Args } from '@oclif/core';
|
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../client.js';
|
|
4
4
|
import { SESSIONS_PATH, sessionLines } from '../../session.js';
|
|
5
|
+
import { asFace as faceAlone } from '../../model.js';
|
|
5
6
|
export default class SessionCreate extends BaseCommand {
|
|
6
7
|
static description = 'Start a session with a face. A session groups the turns of one conversation with one face: pass its id ' +
|
|
7
|
-
'with --session on chat
|
|
8
|
+
'with --session on chat or decide, then compact it with session:compact. Opening one is free; ' +
|
|
8
9
|
'each turn costs what it costs without one. A session expires 30 days after its last turn. Sessions are now called states: see faces state:create.';
|
|
9
10
|
static examples = [
|
|
10
|
-
'<%= config.bin %> <%= command.id %> alice',
|
|
11
|
-
'<%= config.bin %> <%= command.id %> "(alice | bob)" --json',
|
|
11
|
+
'<%= config.bin %> <%= command.id %> @alice',
|
|
12
|
+
'<%= config.bin %> <%= command.id %> "(@alice | @bob)" --json',
|
|
12
13
|
];
|
|
13
14
|
static flags = {
|
|
14
15
|
...BaseCommand.baseFlags,
|
|
15
16
|
};
|
|
16
17
|
static args = {
|
|
17
18
|
face: Args.string({
|
|
18
|
-
description: 'The face alone:
|
|
19
|
+
description: 'The face alone: @alice, @owner~alice, or a composite such as "(@a | @b)". No maestro or model.',
|
|
19
20
|
required: true,
|
|
20
21
|
}),
|
|
21
22
|
};
|
|
22
23
|
async run() {
|
|
23
24
|
const { args, flags } = await this.parse(SessionCreate);
|
|
24
25
|
const client = this.makeClient(flags);
|
|
25
|
-
const face = args.face
|
|
26
|
-
if (face
|
|
27
|
-
this.error(`A session is with a face alone: ${face.
|
|
26
|
+
const face = faceAlone(args.face);
|
|
27
|
+
if (/[:/]/.test(face))
|
|
28
|
+
this.error(`A session is with a face alone, with no maestro or model: ${face.split(/[:/]/)[0]}`);
|
|
28
29
|
let data;
|
|
29
30
|
try {
|
|
30
31
|
data = (await client.post(SESSIONS_PATH, { body: { model: face } }));
|
|
@@ -38,7 +39,7 @@ export default class SessionCreate extends BaseCommand {
|
|
|
38
39
|
for (const line of sessionLines(data))
|
|
39
40
|
this.log(line);
|
|
40
41
|
if (data.id)
|
|
41
|
-
this.log(`\nAdd turns with: faces decide ${face}
|
|
42
|
+
this.log(`\nAdd turns with: faces decide ${face}:maestro-1/jev-latest --session ${data.id} --state "..." --question "..."`);
|
|
42
43
|
}
|
|
43
44
|
return data;
|
|
44
45
|
}
|
|
@@ -107,7 +107,7 @@ export default class StyleMake extends BaseCommand {
|
|
|
107
107
|
for (const line of formatBuildReport(final))
|
|
108
108
|
this.log(line);
|
|
109
109
|
this.log('');
|
|
110
|
-
this.log(`'${args.alias}' has built a style.
|
|
110
|
+
this.log(`'${args.alias}' has built a style. Chat with the face uses it when a request is in that medium.`);
|
|
111
111
|
this.log(`Go back to the previous style: faces style:revert ${args.alias} --yes`);
|
|
112
112
|
return final;
|
|
113
113
|
}
|
|
@@ -12,7 +12,7 @@ export default class StyleUpload extends BaseCommand {
|
|
|
12
12
|
'for plaintextBody. The server lists every problem with a refused line, and the fields it accepts. ' +
|
|
13
13
|
'Upload ONE medium per file: a file mixing, say, email and ' +
|
|
14
14
|
'text messages produces threads with no medium at all, which no style can be built from. A message that declares ' +
|
|
15
|
-
'its own `kind` must spell one of the
|
|
15
|
+
'its own `kind` must spell one of the media in faces media:list exactly; an unknown one is refused, naming the ' +
|
|
16
16
|
'message that carried it. The file is passed through as written, so this is the server answering.';
|
|
17
17
|
static examples = [
|
|
18
18
|
'<%= config.bin %> <%= command.id %> alice ./mail.jsonl',
|
package/dist/decisions.d.ts
CHANGED
|
@@ -22,11 +22,6 @@ export declare function parseDecisionOption(raw: string): {
|
|
|
22
22
|
export declare function decisionLines(answers: Record<string, unknown>, barWidth?: number): string[];
|
|
23
23
|
export declare const MAX_WARM_UP_WAIT_S = 300;
|
|
24
24
|
export declare function warmUpWait(status: number, retryAfter: number | undefined, waitedS: number): number | undefined;
|
|
25
|
-
export interface DecisionCauses {
|
|
26
|
-
cause?: string;
|
|
27
|
-
causes?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
export declare function causeLines(data: DecisionCauses, questionIds: string[]): string[];
|
|
30
25
|
export declare function heldDecisionError(data: unknown): FacesAPIError | undefined;
|
|
31
26
|
export declare function readStateFlags(flags: {
|
|
32
27
|
state?: string;
|
package/dist/decisions.js
CHANGED
|
@@ -158,24 +158,6 @@ export function warmUpWait(status, retryAfter, waitedS) {
|
|
|
158
158
|
return undefined;
|
|
159
159
|
return retryAfter;
|
|
160
160
|
}
|
|
161
|
-
export function causeLines(data, questionIds) {
|
|
162
|
-
const cause = typeof data.cause === 'string' ? data.cause : '';
|
|
163
|
-
const per = questionIds.map((id) => {
|
|
164
|
-
const c = data.causes?.[id];
|
|
165
|
-
return [id, typeof c === 'string' && c !== '' ? c : cause];
|
|
166
|
-
});
|
|
167
|
-
if (per.length === 0 || per.every(([, c]) => c === cause))
|
|
168
|
-
return cause ? [cause] : [];
|
|
169
|
-
const lines = [];
|
|
170
|
-
for (const [id, c] of per) {
|
|
171
|
-
if (!c)
|
|
172
|
-
continue;
|
|
173
|
-
if (lines.length > 0)
|
|
174
|
-
lines.push('');
|
|
175
|
-
lines.push(`${id}:`, c);
|
|
176
|
-
}
|
|
177
|
-
return lines;
|
|
178
|
-
}
|
|
179
161
|
export function heldDecisionError(data) {
|
|
180
162
|
if (!data || typeof data !== 'object')
|
|
181
163
|
return undefined;
|
package/dist/fidelity.js
CHANGED
|
@@ -23,7 +23,7 @@ export function nextStep(run) {
|
|
|
23
23
|
}
|
|
24
24
|
return run.next.awaiting === 'choice'
|
|
25
25
|
? `Pick the answer that sounds more like the person: faces fidelity:pick ${id} a|b [--correction "..."]`
|
|
26
|
-
: `
|
|
26
|
+
: `Send turn ${run.next.turn}'s message: faces fidelity:turn ${id} -m "..."`;
|
|
27
27
|
}
|
|
28
28
|
export function runLines(run) {
|
|
29
29
|
const total = run.turns_total ?? FIDELITY_TURNS;
|
|
@@ -73,7 +73,7 @@ export function fidelityHint(err, on = {}) {
|
|
|
73
73
|
case 'fidelity_choice_pending':
|
|
74
74
|
return `Pick one first: faces fidelity:pick ${id} a|b`;
|
|
75
75
|
case 'fidelity_run_finished':
|
|
76
|
-
return `Read the score: faces fidelity:get ${id}.`;
|
|
76
|
+
return `Read the score: faces fidelity:get ${id}. Start another with faces fidelity:start ${on.alias ?? '<alias>'}.`;
|
|
77
77
|
case 'fidelity_run_open':
|
|
78
78
|
return `See where it stands: faces fidelity:get ${id}`;
|
|
79
79
|
case 'fidelity_unknown_model':
|
|
@@ -81,7 +81,7 @@ export function fidelityHint(err, on = {}) {
|
|
|
81
81
|
case 'fidelity_nothing_compiled':
|
|
82
82
|
return `Add a source with: faces compile:upload ${on.alias ?? '<alias>'} --file <file>`;
|
|
83
83
|
case 'fidelity_run_not_found':
|
|
84
|
-
return '
|
|
84
|
+
return 'Run ids are printed by faces fidelity:start.';
|
|
85
85
|
default:
|
|
86
86
|
return undefined;
|
|
87
87
|
}
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const MEDIA_PATH = "/v1/media";
|
|
2
|
+
export interface Medium {
|
|
3
|
+
name?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
subcategories?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function mediaOf(raw: unknown): Medium[];
|
|
8
|
+
export declare function mediaLines(media: Medium[]): string[];
|
package/dist/media.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { table } from './utils.js';
|
|
2
|
+
export const MEDIA_PATH = '/v1/media';
|
|
3
|
+
export function mediaOf(raw) {
|
|
4
|
+
const data = Array.isArray(raw) ? raw : (raw?.data ?? []);
|
|
5
|
+
return Array.isArray(data) ? data : [];
|
|
6
|
+
}
|
|
7
|
+
export function mediaLines(media) {
|
|
8
|
+
if (media.length === 0)
|
|
9
|
+
return ['No media.'];
|
|
10
|
+
const rows = media.map((m) => [String(m.name ?? ''), String(m.description ?? ''), (m.subcategories ?? []).join(', ')]);
|
|
11
|
+
return table(['MEDIUM', 'DESCRIPTION', 'COVERS'], rows);
|
|
12
|
+
}
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const MAESTROS: readonly ["maestro-1", "maestro-1-flash"];
|
|
2
|
+
export declare const DEFAULT_MAESTRO: "maestro-1";
|
|
3
|
+
export interface ModelName {
|
|
4
|
+
upstream?: string;
|
|
5
|
+
faces?: string;
|
|
6
|
+
maestro?: string;
|
|
7
|
+
downstream?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseModel(raw: string): ModelName;
|
|
10
|
+
export declare function asFace(face: string): string;
|
|
11
|
+
export declare function modelProblem(raw: string, needs: 'upstream' | 'both', example?: string): string | undefined;
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const MAESTROS = ['maestro-1', 'maestro-1-flash'];
|
|
2
|
+
export const DEFAULT_MAESTRO = MAESTROS[0];
|
|
3
|
+
const MAESTRO_END = /:\s*(maestro-[^\s:/()@|&^~]*)\s*$/i;
|
|
4
|
+
export function parseModel(raw) {
|
|
5
|
+
const s = raw.trim();
|
|
6
|
+
const slash = s.indexOf('/');
|
|
7
|
+
const prefix = slash >= 0 ? s.slice(0, slash) : s;
|
|
8
|
+
const m = MAESTRO_END.exec(prefix);
|
|
9
|
+
if (!m || !/^[@(]/.test(prefix.trim()))
|
|
10
|
+
return { downstream: s || undefined };
|
|
11
|
+
const faces = prefix.slice(0, m.index).trim();
|
|
12
|
+
return {
|
|
13
|
+
upstream: `${faces}:${m[1]}`,
|
|
14
|
+
faces,
|
|
15
|
+
maestro: m[1],
|
|
16
|
+
downstream: slash >= 0 ? s.slice(slash + 1).trim() || undefined : undefined,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function asFace(face) {
|
|
20
|
+
const f = face.trim();
|
|
21
|
+
return /^[@(]/.test(f) ? f : `@${f}`;
|
|
22
|
+
}
|
|
23
|
+
export function modelProblem(raw, needs, example = 'gpt-5.4') {
|
|
24
|
+
const s = raw.trim();
|
|
25
|
+
if (!s)
|
|
26
|
+
return 'Name the model: @<face>:maestro-1' + (needs === 'both' ? `/<model>, e.g. @alice:maestro-1/${example}` : ', e.g. @alice:maestro-1');
|
|
27
|
+
const p = parseModel(s);
|
|
28
|
+
if (!p.upstream) {
|
|
29
|
+
const at = s.indexOf('@');
|
|
30
|
+
if (at > 0 && !s.startsWith('(')) {
|
|
31
|
+
const face = s.slice(0, at);
|
|
32
|
+
const down = s.slice(at + 1);
|
|
33
|
+
return `face@model is gone: write ${asFace(face)}:${DEFAULT_MAESTRO}${needs === 'both' ? `/${down}` : ''}`;
|
|
34
|
+
}
|
|
35
|
+
if (/^[@(]/.test(s)) {
|
|
36
|
+
const faces = s.split('/')[0].trim();
|
|
37
|
+
const rest = s.includes('/') ? s.slice(s.indexOf('/') + 1) : needs === 'both' ? '<model>' : '';
|
|
38
|
+
return `Name the maestro after the face: ${faces}:${DEFAULT_MAESTRO}${rest ? `/${rest}` : ''}`;
|
|
39
|
+
}
|
|
40
|
+
if (/^[a-z0-9][a-z0-9~:-]*$/i.test(s) && !/^maestro-/i.test(s) && needs === 'upstream') {
|
|
41
|
+
return `Write the face as ${asFace(s.replace(':', '~'))}:${DEFAULT_MAESTRO}`;
|
|
42
|
+
}
|
|
43
|
+
if (needs === 'both' && /^[a-z0-9][a-z0-9-]*$/i.test(s)) {
|
|
44
|
+
return `Add a face: @<face>:${DEFAULT_MAESTRO}/${s}, or, if ${s} is a face, @${s}:${DEFAULT_MAESTRO}/<model>`;
|
|
45
|
+
}
|
|
46
|
+
return `Add a face: @<face>:${DEFAULT_MAESTRO}${needs === 'both' ? `/${s}` : ''}`;
|
|
47
|
+
}
|
|
48
|
+
if (needs === 'upstream' && p.downstream)
|
|
49
|
+
return `faces choices takes the upstream model alone, with no model after it: ${p.upstream}`;
|
|
50
|
+
if (needs === 'both' && !p.downstream)
|
|
51
|
+
return `Name the model that answers after the maestro: ${p.upstream}/<model>, e.g. ${p.upstream}/${example}`;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
package/dist/routing.d.ts
CHANGED
|
@@ -8,8 +8,5 @@ export interface RouteInfo {
|
|
|
8
8
|
freeWhenConnected: boolean;
|
|
9
9
|
}
|
|
10
10
|
export declare function decisionModelError(llm?: string): string | undefined;
|
|
11
|
-
export declare function
|
|
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>;
|
|
11
|
+
export declare function resolveEndpoint(client: FacesClient, llm: string): Promise<RouteInfo>;
|
|
15
12
|
export declare function codexEligible(client: FacesClient, llm: string): Promise<boolean | undefined>;
|
package/dist/routing.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { CATALOG_INDEX } from './catalog.js';
|
|
5
4
|
import { DECISION_MODELS } from './decisions.js';
|
|
6
|
-
import { seg } from './utils.js';
|
|
7
5
|
export const MESSAGES_ENDPOINT = '/v1/messages';
|
|
8
6
|
export const RESPONSES_ENDPOINT = '/v1/responses';
|
|
9
7
|
export const CHAT_COMPLETIONS_ENDPOINT = '/v1/chat/completions';
|
|
@@ -69,55 +67,21 @@ function buildMap(models) {
|
|
|
69
67
|
}
|
|
70
68
|
return map;
|
|
71
69
|
}
|
|
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
70
|
export function decisionModelError(llm) {
|
|
83
71
|
if (!llm)
|
|
84
72
|
return undefined;
|
|
85
73
|
const want = llm.toLowerCase();
|
|
86
74
|
if (!DECISION_MODELS.includes(want))
|
|
87
75
|
return undefined;
|
|
88
|
-
return `${llm} is a decision model, not a chat model; use \`faces decide
|
|
76
|
+
return `${llm} is a decision model, not a chat model; use \`faces decide\` with @<face>:maestro-1/${llm}`;
|
|
89
77
|
}
|
|
90
|
-
export function
|
|
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);
|
|
78
|
+
export async function resolveEndpoint(client, llm) {
|
|
104
79
|
const notChat = decisionModelError(llm);
|
|
105
80
|
if (notChat)
|
|
106
81
|
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
82
|
const map = buildMap(await getModels(client));
|
|
120
|
-
const
|
|
83
|
+
const key = llm.toLowerCase();
|
|
84
|
+
const hit = map.get(key) ?? (key.includes('/') ? map.get(key.slice(key.indexOf('/') + 1)) : undefined);
|
|
121
85
|
if (hit)
|
|
122
86
|
return { endpoint: hit.endpoint, llm, freeWhenConnected: hit.freeWhenConnected };
|
|
123
87
|
return { endpoint: fallbackEndpoint(llm), llm, freeWhenConnected: false };
|
package/dist/utils.d.ts
CHANGED
|
@@ -23,46 +23,22 @@ export declare function badToolNames(names: string[]): string | undefined;
|
|
|
23
23
|
export declare function badFaceName(name: string): string | undefined;
|
|
24
24
|
export declare function compact(obj: unknown): unknown;
|
|
25
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
26
|
export declare function flattenAttributes(facts: Record<string, unknown>): Record<string, string>;
|
|
31
27
|
export declare const flattenBasicFacts: typeof flattenAttributes;
|
|
32
28
|
export declare function renameFaceFields(face: Record<string, unknown>): Record<string, unknown>;
|
|
33
29
|
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
30
|
export declare const STREAM_FLAG_DESCRIPTION: string;
|
|
47
31
|
export declare function postChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>): Promise<ResponseWithHeaders>;
|
|
48
32
|
export declare function retryOnceOnWarmUp<T>(send: () => Promise<T>, say?: (seconds: number) => void): Promise<T>;
|
|
49
33
|
export declare function streamChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>, onHeaders?: (headers: Record<string, string>) => void): AsyncGenerator<string>;
|
|
50
34
|
export declare function sayWarmUp(seconds: number): void;
|
|
51
35
|
export declare function compileHint(face: string, recompile: boolean, verb?: string): string;
|
|
52
|
-
export declare function faceRefusalHint(err: FacesAPIError, model: string
|
|
36
|
+
export declare function faceRefusalHint(err: FacesAPIError, model: string): string | undefined;
|
|
53
37
|
export declare const MIN_MAX_OUTPUT_TOKENS = 16;
|
|
54
38
|
export declare function isMaxTokensRenameError(message: string): boolean;
|
|
55
39
|
export declare const DOCUMENT_VS_THREAD: string;
|
|
56
|
-
export declare const STYLE_FLAG_DESCRIPTION: string;
|
|
57
|
-
export declare const MEDIUM_FLAG_DESCRIPTION: string;
|
|
58
40
|
export declare const SESSION_FLAG_DESCRIPTION: string;
|
|
59
41
|
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
42
|
export declare const MEDIUM_EDIT_DESCRIPTION: () => string;
|
|
67
43
|
export declare const MEDIUM_REQUIRED_DESCRIPTION: string;
|
|
68
44
|
export declare const MEDIUM_MISSING_MESSAGE: string;
|