@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
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Command-line interface for [Faces](https://faces.sh). Faces are causal models: compile one from an
|
|
4
4
|
author's source texts, then describe a situation and ask it what it would do: it proposes the options
|
|
5
|
-
it would weigh, strongest first.
|
|
6
|
-
|
|
5
|
+
it would weigh, strongest first. A face also steers any chat model's replies, and a decision model's
|
|
6
|
+
typed decisions.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -29,16 +29,16 @@ faces compile:doc alice --file essay.txt --medium essay
|
|
|
29
29
|
faces compile:upload alice --file interview.txt --kind thread --face-speaker Alice
|
|
30
30
|
|
|
31
31
|
# Ask what it would do: the options it would weigh, strongest first
|
|
32
|
-
faces choices alice --state "A startup offers me a lead role at a lower salary." --question "Should I take the offer?"
|
|
32
|
+
faces choices @alice:maestro-1 --state "A startup offers me a lead role at a lower salary." --question "Should I take the offer?"
|
|
33
33
|
|
|
34
34
|
# Or let it propose the question it would ask
|
|
35
|
-
faces choices alice --state "A startup offers me a lead role at a lower salary."
|
|
35
|
+
faces choices @alice:maestro-1 --state "A startup offers me a lead role at a lower salary."
|
|
36
36
|
|
|
37
|
-
#
|
|
38
|
-
faces
|
|
37
|
+
# Chat: the face steers, gpt-5.4 writes the reply
|
|
38
|
+
faces chat:chat @alice:maestro-1/gpt-5.4 -m "Should I take the offer?"
|
|
39
39
|
|
|
40
|
-
# Decide: typed answers
|
|
41
|
-
faces decide alice --state "A colleague asks you to sign a proposal you have not read." \
|
|
40
|
+
# Decide: typed answers from a decision model, steered by the face
|
|
41
|
+
faces decide @alice:maestro-1/jev-latest --state "A colleague asks you to sign a proposal you have not read." \
|
|
42
42
|
--question "Does the speaker sign?"
|
|
43
43
|
|
|
44
44
|
# Compare and compose
|
|
@@ -58,7 +58,7 @@ faces face:avatar:list / get / make / upload / delete
|
|
|
58
58
|
faces face:tag:add / list / remove / set / all
|
|
59
59
|
|
|
60
60
|
faces choices # what a face would do: its options, or the question it would ask
|
|
61
|
-
faces
|
|
61
|
+
faces chat:chat / messages / responses / thread # chat with a face on any chat model
|
|
62
62
|
faces decide # what a face would decide: yes/no, a choice, or a score
|
|
63
63
|
faces state:create / get / items / add / compact / close
|
|
64
64
|
faces conversation:create / ... # the old name for state:*
|
|
@@ -71,8 +71,9 @@ faces compile:upload / import / all / status / stats
|
|
|
71
71
|
faces style:upload / make / status / versions / revert / delete
|
|
72
72
|
|
|
73
73
|
faces models:list # the models you can name; --kind takes a list, or all
|
|
74
|
+
faces media:list # the media a document can be, with what each covers
|
|
74
75
|
faces benchmark:start / get / list
|
|
75
|
-
faces fidelity:
|
|
76
|
+
faces fidelity:start / turn / pick / get / run / save-thread
|
|
76
77
|
|
|
77
78
|
faces group:create / list / get / edit / delete / members / add / remove
|
|
78
79
|
faces group:tag:add / list / remove / set
|
|
@@ -107,9 +108,32 @@ faces compile:upload alice --file interview.txt --kind thread --face-speaker Ali
|
|
|
107
108
|
faces compile:upload alice --file podcast.mp3 --kind thread --face-speaker A
|
|
108
109
|
```
|
|
109
110
|
|
|
111
|
+
A document's `--medium` is one of the 25 media `faces media:list` shows, each with what it
|
|
112
|
+
covers: a keynote is a `speech`, a diary a `journal entry`. A subcategory is not accepted.
|
|
113
|
+
|
|
110
114
|
A labelled dialogue uploaded as a document is read as entirely the face's own words, other
|
|
111
115
|
speakers included. The document commands warn when a text file reads as a transcript.
|
|
112
116
|
|
|
117
|
+
## Naming a model
|
|
118
|
+
|
|
119
|
+
Every command that runs a face takes one `model`, written the way the API takes it: our
|
|
120
|
+
**upstream** model (a face and its maestro) over a **downstream** model (the model that writes the
|
|
121
|
+
answer), as a fraction:
|
|
122
|
+
|
|
123
|
+
| `model` | Command |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `@alice:maestro-1` | `faces choices` (the upstream model answers) |
|
|
126
|
+
| `@alice:maestro-1/gpt-5.4` | `faces chat:*` |
|
|
127
|
+
| `@alice:maestro-1/jev-latest` | `faces decide` |
|
|
128
|
+
| `@dana~alice:maestro-1/gpt-5.4` | another account's face, published or shared with you |
|
|
129
|
+
| `(@alice \| @bob):maestro-1-flash/gpt-5.4` | a composite, with `\|`, `&`, `-` and `^` |
|
|
130
|
+
|
|
131
|
+
Your own face is `@alice`; another account's is `@owner~alice` (a system face is `@head~socrates`).
|
|
132
|
+
`maestro-1-flash` answers sooner and costs 10 times more on the upstream part. Everything after the
|
|
133
|
+
first `/` is the downstream model's id as `faces models:list` lists it. Quote a composite, because
|
|
134
|
+
the shell reads `|` and `&`. A plain model with no face is not served, and the old forms
|
|
135
|
+
(`alice@gpt-5.4`, a bare alias, `owner:alias`) are refused with the new form to use.
|
|
136
|
+
|
|
113
137
|
## Choices
|
|
114
138
|
|
|
115
139
|
`faces choices` asks a face what it would do (`POST /v1/choices`). Describe the situation with
|
|
@@ -117,9 +141,9 @@ speakers included. The document commands warn when a text file reads as a transc
|
|
|
117
141
|
`--question`:
|
|
118
142
|
|
|
119
143
|
```bash
|
|
120
|
-
faces choices alice --state "A startup offers me a lead role at a lower salary." --question "Should I take the offer?"
|
|
121
|
-
faces choices head:
|
|
122
|
-
faces choices "(alice | bob)" --state-file situation.txt -q "What next?"
|
|
144
|
+
faces choices @alice:maestro-1 --state "A startup offers me a lead role at a lower salary." --question "Should I take the offer?"
|
|
145
|
+
faces choices @head~socrates:maestro-1 --state-id fs_STATE_ID --question "What should the shop do?" --max-choices 3
|
|
146
|
+
faces choices "(@alice | @bob):maestro-1-flash" --state-file situation.txt -q "What next?"
|
|
123
147
|
```
|
|
124
148
|
|
|
125
149
|
With both `--state-id` and `--state`, the prose is an addendum for that one call: read with the
|
|
@@ -127,33 +151,41 @@ state, never saved to it. Anything that should persist goes in the state as prem
|
|
|
127
151
|
`faces state:add --premise`.
|
|
128
152
|
|
|
129
153
|
The face proposes the options it would weigh, strongest first. Leave `--question` out and it
|
|
130
|
-
proposes the question it would ask.
|
|
131
|
-
which answers sooner and costs 10 times more when a question is asked. Prices:
|
|
132
|
-
`faces models:list --kind choices`.
|
|
154
|
+
proposes the question it would ask. Prices: `faces models:list --kind upstream`.
|
|
133
155
|
|
|
134
|
-
## Chat
|
|
156
|
+
## Chat
|
|
157
|
+
|
|
158
|
+
`faces chat:chat` sends your message to a face: the face steers, and the downstream model writes
|
|
159
|
+
the reply. It picks `/v1/chat/completions`, `/v1/responses` or `/v1/messages` from the model
|
|
160
|
+
catalog; `chat:messages` and `chat:responses` force one. `chat:thread` keeps a multi-turn
|
|
161
|
+
conversation under `~/.faces/threads`.
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
faces chat:chat @alice:maestro-1/gpt-5.4 -m "What matters most to you in your work?"
|
|
165
|
+
faces chat:chat "(@socrates | @nietzsche):maestro-1/claude-sonnet-4-6" -m "What is virtue?"
|
|
166
|
+
faces chat:thread @alice:maestro-1/gpt-5.4 -m "Should I take the offer?"
|
|
167
|
+
faces chat:thread --id t_THREAD_ID -m "And if they raise the salary?"
|
|
168
|
+
faces chat:chat @alice:maestro-1/gpt-5.4 -m "So what now?" --conversation fs_STATE_ID
|
|
169
|
+
```
|
|
135
170
|
|
|
136
|
-
The
|
|
137
|
-
`fidelity:start`, `fidelity:turn` and `fidelity:run`. Use `faces choices` to ask a face. Runs made
|
|
138
|
-
before can still be read with `fidelity:get` and saved with `fidelity:save-thread`. `style:*` still
|
|
139
|
-
builds styles, which no route applies now, and `catalog:doctor --generate` is retired.
|
|
171
|
+
The face's style is chosen for each request, from the face's built styles. `style:*` builds them.
|
|
140
172
|
|
|
141
173
|
## States
|
|
142
174
|
|
|
143
175
|
A state keeps the situation your agent builds on the server: **premises** (named facts, each with
|
|
144
176
|
a status and what it depends on), the decisions faces made, and your messages. Hand it to a face
|
|
145
|
-
with `faces choices --state-id`, or pass it to `
|
|
177
|
+
with `faces choices --state-id`, or pass it to `chat:*` and `decide` with `--conversation`.
|
|
146
178
|
|
|
147
179
|
```bash
|
|
148
|
-
faces state:create alice
|
|
180
|
+
faces state:create @alice
|
|
149
181
|
faces state:add fs_STATE_ID --premise rent_rises='"12% in March"' --premise-status rent_rises=assumed \
|
|
150
182
|
--premise-description rent_rises="the landlord says rent goes up 12% in March"
|
|
151
183
|
faces state:add fs_STATE_ID --premise can_afford=false --premise-depends-on can_afford=rent_rises \
|
|
152
184
|
--premise-description can_afford="the shop can carry the higher rent"
|
|
153
|
-
faces decide alice --conversation fs_STATE_ID --depends-on can_afford \
|
|
185
|
+
faces decide @alice:maestro-1/jev-latest --conversation fs_STATE_ID --depends-on can_afford \
|
|
154
186
|
--state "Decide about the lease." --question "Move the shop to a cheaper street?"
|
|
155
187
|
faces state:add fs_STATE_ID --premise rent_rises='"no rise this year"' --premise-status rent_rises=invalidated
|
|
156
|
-
faces choices alice --state-id fs_STATE_ID --question "What should the shop do?"
|
|
188
|
+
faces choices @alice:maestro-1 --state-id fs_STATE_ID --question "What should the shop do?"
|
|
157
189
|
faces state:items fs_STATE_ID
|
|
158
190
|
```
|
|
159
191
|
|
|
@@ -170,7 +202,7 @@ decision that rested on a value you changed. Nothing is decided again for you. `
|
|
|
170
202
|
--depends-on` says what a decision rests on, and prints its decision id to name in a later one.
|
|
171
203
|
|
|
172
204
|
`--conversation`, `--premise`, `--premise-description`, `--premise-status` and
|
|
173
|
-
`--premise-depends-on` work on `
|
|
205
|
+
`--premise-depends-on` work on `chat:*` and `decide`.
|
|
174
206
|
|
|
175
207
|
States were called conversations, and before that sessions. The `conversation:*` and `session:*`
|
|
176
208
|
commands, and `--session`, still work and name the same thing.
|
|
@@ -188,14 +220,16 @@ export FACES_BASE_URL=https://api.faces.sh # optional override
|
|
|
188
220
|
## Plans
|
|
189
221
|
|
|
190
222
|
- **Free**: a $5 activation, added as credits. Everything is paid as it goes, from credits.
|
|
191
|
-
- **Connect** ($17/month): 25M choices and
|
|
223
|
+
- **Connect** ($17/month): 25M choices and steering tokens a month (6.25M a week, 1.6M per 5 hours) and
|
|
192
224
|
500k compile source tokens.
|
|
193
|
-
- **Pro** ($49/month): 75M choices and
|
|
225
|
+
- **Pro** ($49/month): 75M choices and steering tokens a month (18.75M a week, 4.8M per 5 hours) and
|
|
194
226
|
1.5M compile source tokens.
|
|
195
227
|
|
|
196
228
|
Past an allowance, work is paid from credits only with `api_fallback` on (`faces account:preferences`).
|
|
197
|
-
Choices cost $0.42 per million input tokens and $1.00 per million output tokens on `maestro-1
|
|
198
|
-
|
|
229
|
+
Choices cost $0.42 per million input tokens and $1.00 per million output tokens on `maestro-1`.
|
|
230
|
+
On chat and decisions the steering costs $0.42 per million input tokens plus $0.00042 a call, with no
|
|
231
|
+
output charge, and the downstream model its listed price plus 5%. `maestro-1-flash` is 10 times the
|
|
232
|
+
`maestro-1` price, on the upstream part only. Compiling costs $16 per million source tokens, $21 for a rush. Link a ChatGPT account with
|
|
199
233
|
`faces auth:connect openai` and interviews and style builds run on the ChatGPT plan. Current prices:
|
|
200
234
|
`faces models:list --kind all`.
|
|
201
235
|
|
package/dist/billing.js
CHANGED
|
@@ -8,9 +8,9 @@ export function planName(plan) {
|
|
|
8
8
|
return p ? p[0].toUpperCase() + p.slice(1) : 'unknown';
|
|
9
9
|
}
|
|
10
10
|
const ALLOWANCES = [
|
|
11
|
-
['
|
|
12
|
-
['
|
|
13
|
-
['
|
|
11
|
+
['upstream_5h', 'choices and steering, rolling 5 hours'],
|
|
12
|
+
['upstream_week', 'choices and steering, this week'],
|
|
13
|
+
['upstream_month', 'choices and steering, this month'],
|
|
14
14
|
['compile_month', 'compile, this month'],
|
|
15
15
|
];
|
|
16
16
|
export function tokens(n) {
|
|
@@ -77,15 +77,18 @@ export function allowanceLines(sub) {
|
|
|
77
77
|
if (!unlimited) {
|
|
78
78
|
const rates = sub.rates;
|
|
79
79
|
let past = 'Past an allowance, api_fallback on pays from your credits; off refuses with a 429 until it resets.';
|
|
80
|
-
if (rates && typeof rates.
|
|
81
|
-
const added = typeof rates.cause_added_tokens === 'number' && rates.cause_added_tokens > 0
|
|
82
|
-
? `, each cause counting its input tokens plus ${rates.cause_added_tokens.toLocaleString('en-US')},`
|
|
83
|
-
: '';
|
|
80
|
+
if (rates && typeof rates.compile_usd_per_million_source_tokens === 'number') {
|
|
84
81
|
const rush = typeof rates.compile_rush_usd_per_million_source_tokens === 'number'
|
|
85
82
|
? ` ($${rates.compile_rush_usd_per_million_source_tokens} for a rush)`
|
|
86
83
|
: '';
|
|
84
|
+
const steer = typeof rates.steering_usd_per_million_input_tokens === 'number' && typeof rates.steering_usd_per_call === 'number'
|
|
85
|
+
? `$${rates.steering_usd_per_million_input_tokens} per million steering tokens plus $${rates.steering_usd_per_call} a call, `
|
|
86
|
+
: '';
|
|
87
|
+
const choices = typeof rates.choices_usd_per_million_input_tokens === 'number' && typeof rates.choices_usd_per_million_output_tokens === 'number'
|
|
88
|
+
? `$${rates.choices_usd_per_million_input_tokens} and $${rates.choices_usd_per_million_output_tokens} per million choices input and output tokens, `
|
|
89
|
+
: '';
|
|
87
90
|
past +=
|
|
88
|
-
` Credits pay
|
|
91
|
+
` Credits pay ${steer}${choices}on maestro-1 (10 times on maestro-1-flash), and ` +
|
|
89
92
|
`$${rates.compile_usd_per_million_source_tokens} per million compile tokens${rush}.`;
|
|
90
93
|
}
|
|
91
94
|
lines.push(` ${past}`);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseCommand } from './base.js';
|
|
2
|
+
import { FacesAPIError, FacesClient } from './client.js';
|
|
3
|
+
export declare abstract class ChatCommand extends BaseCommand {
|
|
4
|
+
static flags: {
|
|
5
|
+
session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
system: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
'max-tokens': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
temperature: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
24
|
+
};
|
|
25
|
+
static args: {
|
|
26
|
+
model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
27
|
+
};
|
|
28
|
+
protected abstract forcedEndpoint(flags: Record<string, unknown>): string | undefined;
|
|
29
|
+
run(): Promise<unknown>;
|
|
30
|
+
}
|
|
31
|
+
export declare function chatRefusal(err: FacesAPIError, model: string, endpoint: string, freeWhenConnected: boolean, client: FacesClient): Promise<string>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { BaseCommand } from './base.js';
|
|
4
|
+
import { FacesAPIError } from './client.js';
|
|
5
|
+
import { conversationFields } from './conversation.js';
|
|
6
|
+
import { chatgptLinked } from './style.js';
|
|
7
|
+
import { CHAT_COMPLETIONS_ENDPOINT, MODEL_ARG_DESCRIPTION, RESPONSES_ENDPOINT, chatFlags, chatMeta, chatModelProblem, chatPayload, sendChat, } from './chat.js';
|
|
8
|
+
import { parseModel } from './model.js';
|
|
9
|
+
import { resolveEndpoint } from './routing.js';
|
|
10
|
+
import { faceRefusalHint, parseTemperature } from './utils.js';
|
|
11
|
+
export class ChatCommand extends BaseCommand {
|
|
12
|
+
static flags = {
|
|
13
|
+
...BaseCommand.baseFlags,
|
|
14
|
+
...chatFlags(),
|
|
15
|
+
};
|
|
16
|
+
static args = {
|
|
17
|
+
model: Args.string({ description: MODEL_ARG_DESCRIPTION, required: true }),
|
|
18
|
+
};
|
|
19
|
+
async run() {
|
|
20
|
+
const { args, flags } = await this.parse(this.constructor);
|
|
21
|
+
const client = this.makeClient(flags);
|
|
22
|
+
const json = this.jsonEnabled();
|
|
23
|
+
const model = args.model.trim();
|
|
24
|
+
const problem = chatModelProblem(model);
|
|
25
|
+
if (problem)
|
|
26
|
+
this.error(problem);
|
|
27
|
+
const turns = [];
|
|
28
|
+
if (flags.file) {
|
|
29
|
+
if (!fs.existsSync(flags.file))
|
|
30
|
+
this.error(`File not found: ${flags.file}`);
|
|
31
|
+
turns.push({ role: 'user', content: fs.readFileSync(flags.file, 'utf8') });
|
|
32
|
+
}
|
|
33
|
+
for (const m of flags.message ?? [])
|
|
34
|
+
turns.push({ role: 'user', content: m });
|
|
35
|
+
if (turns.length === 0)
|
|
36
|
+
this.error('Provide at least one --message/-m or --file.');
|
|
37
|
+
let turn;
|
|
38
|
+
try {
|
|
39
|
+
turn = conversationFields(flags);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
43
|
+
}
|
|
44
|
+
const downstream = parseModel(model).downstream;
|
|
45
|
+
const route = await resolveEndpoint(client, downstream);
|
|
46
|
+
const endpoint = this.forcedEndpoint(flags) ?? route.endpoint;
|
|
47
|
+
const temperature = flags.temperature === undefined ? undefined : parseTemperature(flags.temperature, (m) => this.error(m));
|
|
48
|
+
let payload;
|
|
49
|
+
try {
|
|
50
|
+
payload = chatPayload(endpoint, model, turns, {
|
|
51
|
+
system: flags.system,
|
|
52
|
+
maxTokens: flags['max-tokens'],
|
|
53
|
+
temperature,
|
|
54
|
+
stream: flags.stream && !json,
|
|
55
|
+
oauthOnly: flags['oauth-only'],
|
|
56
|
+
session: flags.session,
|
|
57
|
+
compaction: flags.compaction,
|
|
58
|
+
turn,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
this.error(err instanceof Error ? err.message : String(err));
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const res = await sendChat(client, endpoint, payload, (d) => process.stdout.write(d), json);
|
|
66
|
+
if (payload.stream) {
|
|
67
|
+
if (!res.text)
|
|
68
|
+
this.error('The reply stream ended with no answer. Run it again with --no-stream to see what the server said.');
|
|
69
|
+
process.stdout.write('\n');
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
if (json) {
|
|
73
|
+
const body = res.body ?? {};
|
|
74
|
+
body._meta = chatMeta(res.headers ?? {}, endpoint, model);
|
|
75
|
+
return body;
|
|
76
|
+
}
|
|
77
|
+
this.log(res.text);
|
|
78
|
+
return res.body;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err instanceof FacesAPIError)
|
|
82
|
+
this.error(await chatRefusal(err, model, endpoint, route.freeWhenConnected, client));
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export async function chatRefusal(err, model, endpoint, freeWhenConnected, client) {
|
|
88
|
+
if (err.errorCode === 'oauth_rejected') {
|
|
89
|
+
const hints = [];
|
|
90
|
+
const linked = await chatgptLinked(client);
|
|
91
|
+
if (linked === false)
|
|
92
|
+
hints.push('No ChatGPT account is linked. Link one with: faces auth:connect openai');
|
|
93
|
+
else
|
|
94
|
+
hints.push('If the ChatGPT link has lapsed, link it again with: faces auth:connect openai');
|
|
95
|
+
if (endpoint === RESPONSES_ENDPOINT && freeWhenConnected && linked === false)
|
|
96
|
+
hints.push('This model is free once it is linked.');
|
|
97
|
+
hints.push(err.fallbackAvailable
|
|
98
|
+
? 'Or allow paid fallback: faces account:preferences api_fallback true'
|
|
99
|
+
: 'Or add credits (faces billing:topup --amount <usd>) and allow paid fallback: faces account:preferences api_fallback true');
|
|
100
|
+
return `OAuth failed: ${err.message}\n${hints.join('\n')}`;
|
|
101
|
+
}
|
|
102
|
+
if (err.errorCode === 'model_not_supported') {
|
|
103
|
+
return `${err.message}\nYour ChatGPT plan does not serve this model. Name another after the /, or let it run on credits: faces account:preferences api_fallback true`;
|
|
104
|
+
}
|
|
105
|
+
if (err.errorCode === 'use_responses_for_free_oauth' && endpoint === CHAT_COMPLETIONS_ENDPOINT) {
|
|
106
|
+
return `HTTP ${err.statusCode}: ${err.message}\nRun it on your ChatGPT plan with --responses (or faces chat:responses).`;
|
|
107
|
+
}
|
|
108
|
+
const hint = faceRefusalHint(err, model);
|
|
109
|
+
return `HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`;
|
|
110
|
+
}
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { FacesClient } from './client.js';
|
|
2
|
+
import { CHAT_COMPLETIONS_ENDPOINT, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT } from './routing.js';
|
|
3
|
+
export type ChatEndpoint = typeof CHAT_COMPLETIONS_ENDPOINT | typeof RESPONSES_ENDPOINT | typeof MESSAGES_ENDPOINT;
|
|
4
|
+
export interface Turn {
|
|
5
|
+
role: 'user' | 'assistant';
|
|
6
|
+
content: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ChatOptions {
|
|
9
|
+
system?: string;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
stream: boolean;
|
|
13
|
+
oauthOnly?: boolean;
|
|
14
|
+
session?: string;
|
|
15
|
+
compaction?: string;
|
|
16
|
+
turn?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export declare const MODEL_ARG_DESCRIPTION: string;
|
|
19
|
+
export declare function chatFlags(): {
|
|
20
|
+
session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
23
|
+
conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
|
+
premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
25
|
+
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
26
|
+
'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
27
|
+
'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
28
|
+
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
29
|
+
message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
|
+
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
|
+
system: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
32
|
+
stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
33
|
+
'max-tokens': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
|
+
temperature: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
|
+
};
|
|
36
|
+
export declare function chatModelProblem(model: string): string | undefined;
|
|
37
|
+
export declare function chatPayload(endpoint: string, model: string, turns: Turn[], o: ChatOptions): Record<string, unknown>;
|
|
38
|
+
export declare function replyText(body: Record<string, unknown>, endpoint: string): string;
|
|
39
|
+
export declare function chatMeta(headers: Record<string, string>, endpoint: string, model: string): Record<string, string>;
|
|
40
|
+
export interface ChatResult {
|
|
41
|
+
text: string;
|
|
42
|
+
body?: Record<string, unknown>;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
export declare function sendChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>, onDelta: (text: string) => void, quiet?: boolean): Promise<ChatResult>;
|
|
46
|
+
export declare function faceOfModel(model: string): string;
|
|
47
|
+
export { CHAT_COMPLETIONS_ENDPOINT, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT };
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { FacesAPIError } from './client.js';
|
|
3
|
+
import { conversationTurnFlags } from './conversation.js';
|
|
4
|
+
import { modelProblem, parseModel } from './model.js';
|
|
5
|
+
import { CHAT_COMPLETIONS_ENDPOINT, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT } from './routing.js';
|
|
6
|
+
import { CHAT_PARAM_FLAGS, COMPACTION_FLAG_DESCRIPTION, MIN_MAX_OUTPUT_TOKENS, SESSION_FLAG_DESCRIPTION, STREAM_FLAG_DESCRIPTION, extractStreamDelta, isMaxTokensRenameError, postChat, retryOnceOnWarmUp, sayWarmUp, streamChat, warnDroppedParams, } from './utils.js';
|
|
7
|
+
export const MODEL_ARG_DESCRIPTION = 'The upstream model over the downstream model: @<face>:<maestro>/<model>, e.g. @alice:maestro-1/gpt-5.4. ' +
|
|
8
|
+
'Another account\'s face is @owner~face; a composite is "(@a | @b):maestro-1/<model>" (operators | & - ^). ' +
|
|
9
|
+
'maestro-1-flash steers sooner, at 10 times the steering price. The model after the / is any chat model ' +
|
|
10
|
+
'in faces models:list, written as it is listed.';
|
|
11
|
+
export function chatFlags() {
|
|
12
|
+
return {
|
|
13
|
+
message: Flags.string({ char: 'm', description: 'Your message (repeatable, sent in order).', multiple: true }),
|
|
14
|
+
file: Flags.string({ description: 'Read the message from a file.' }),
|
|
15
|
+
system: Flags.string({ description: 'System prompt (instructions on /v1/responses).' }),
|
|
16
|
+
stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
|
|
17
|
+
'max-tokens': Flags.integer({ description: 'The most tokens the reply may take (at least 1; 16 on /v1/responses).', min: 1 }),
|
|
18
|
+
temperature: Flags.string({ description: 'Temperature (0.0-2.0).' }),
|
|
19
|
+
...conversationTurnFlags(),
|
|
20
|
+
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
|
|
21
|
+
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
|
|
22
|
+
'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits.', default: false }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function chatModelProblem(model) {
|
|
26
|
+
return modelProblem(model, 'both');
|
|
27
|
+
}
|
|
28
|
+
export function chatPayload(endpoint, model, turns, o) {
|
|
29
|
+
let payload;
|
|
30
|
+
if (endpoint === MESSAGES_ENDPOINT) {
|
|
31
|
+
payload = { model, messages: turns.map((t) => ({ role: t.role, content: t.content })), max_tokens: o.maxTokens ?? 1024, stream: o.stream };
|
|
32
|
+
if (o.system)
|
|
33
|
+
payload.system = o.system;
|
|
34
|
+
}
|
|
35
|
+
else if (endpoint === RESPONSES_ENDPOINT) {
|
|
36
|
+
payload = { model, input: turns.map((t) => ({ role: t.role, content: t.content })), stream: o.stream };
|
|
37
|
+
if (o.system)
|
|
38
|
+
payload.instructions = o.system;
|
|
39
|
+
if (o.maxTokens !== undefined) {
|
|
40
|
+
if (o.maxTokens < MIN_MAX_OUTPUT_TOKENS) {
|
|
41
|
+
throw new Error(`--max-tokens must be at least ${MIN_MAX_OUTPUT_TOKENS} on /v1/responses (got ${o.maxTokens}).`);
|
|
42
|
+
}
|
|
43
|
+
payload.max_output_tokens = o.maxTokens;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const messages = [];
|
|
48
|
+
if (o.system)
|
|
49
|
+
messages.push({ role: 'system', content: o.system });
|
|
50
|
+
for (const t of turns)
|
|
51
|
+
messages.push({ role: t.role, content: t.content });
|
|
52
|
+
payload = { model, messages, stream: o.stream };
|
|
53
|
+
if (o.maxTokens !== undefined)
|
|
54
|
+
payload.max_tokens = o.maxTokens;
|
|
55
|
+
}
|
|
56
|
+
if (o.temperature !== undefined)
|
|
57
|
+
payload.temperature = o.temperature;
|
|
58
|
+
if (o.session)
|
|
59
|
+
payload.session = o.session;
|
|
60
|
+
if (o.compaction)
|
|
61
|
+
payload.compaction = o.compaction;
|
|
62
|
+
if (o.turn)
|
|
63
|
+
Object.assign(payload, o.turn);
|
|
64
|
+
if (o.oauthOnly)
|
|
65
|
+
payload.oauth_only = true;
|
|
66
|
+
return payload;
|
|
67
|
+
}
|
|
68
|
+
export function replyText(body, endpoint) {
|
|
69
|
+
if (endpoint === MESSAGES_ENDPOINT) {
|
|
70
|
+
let text = '';
|
|
71
|
+
for (const block of body.content ?? []) {
|
|
72
|
+
if (block.type === 'text')
|
|
73
|
+
text += String(block.text ?? '');
|
|
74
|
+
}
|
|
75
|
+
return text;
|
|
76
|
+
}
|
|
77
|
+
if (endpoint === RESPONSES_ENDPOINT) {
|
|
78
|
+
let text = '';
|
|
79
|
+
for (const item of body.output ?? []) {
|
|
80
|
+
for (const block of item.content ?? []) {
|
|
81
|
+
if (block.type === 'output_text')
|
|
82
|
+
text += String(block.text ?? '');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return text;
|
|
86
|
+
}
|
|
87
|
+
const choices = body.choices;
|
|
88
|
+
return String(choices?.[0]?.message?.content ?? '');
|
|
89
|
+
}
|
|
90
|
+
export function chatMeta(headers, endpoint, model) {
|
|
91
|
+
const meta = {};
|
|
92
|
+
if (headers['x-faces-provider'])
|
|
93
|
+
meta.provider = headers['x-faces-provider'];
|
|
94
|
+
if (headers['x-faces-cost-usd'])
|
|
95
|
+
meta.cost_usd = headers['x-faces-cost-usd'];
|
|
96
|
+
if (headers['x-faces-billing'])
|
|
97
|
+
meta.billing = headers['x-faces-billing'];
|
|
98
|
+
meta.endpoint = endpoint;
|
|
99
|
+
meta.model = model;
|
|
100
|
+
return meta;
|
|
101
|
+
}
|
|
102
|
+
export async function sendChat(client, endpoint, payload, onDelta, quiet = false) {
|
|
103
|
+
if (payload.stream) {
|
|
104
|
+
let text = '';
|
|
105
|
+
const onHeaders = (headers) => warnDroppedParams(headers, CHAT_PARAM_FLAGS);
|
|
106
|
+
for await (const line of streamChat(client, endpoint, payload, onHeaders)) {
|
|
107
|
+
if (!line.startsWith('data: '))
|
|
108
|
+
continue;
|
|
109
|
+
const chunk = line.slice(6).trim();
|
|
110
|
+
if (chunk === '[DONE]' || chunk === '')
|
|
111
|
+
continue;
|
|
112
|
+
let parsed;
|
|
113
|
+
try {
|
|
114
|
+
parsed = JSON.parse(chunk);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const error = parsed.error;
|
|
120
|
+
if (parsed.type === 'error' || (error && typeof error === 'object' && !parsed.choices)) {
|
|
121
|
+
const inner = (error ?? parsed);
|
|
122
|
+
const status = Number(inner.status ?? parsed.status ?? 500);
|
|
123
|
+
throw new FacesAPIError(status, String(inner.message ?? parsed.message ?? 'The stream ended with an error.'));
|
|
124
|
+
}
|
|
125
|
+
const delta = extractStreamDelta(parsed);
|
|
126
|
+
if (delta) {
|
|
127
|
+
text += delta;
|
|
128
|
+
onDelta(delta);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { text };
|
|
132
|
+
}
|
|
133
|
+
const say = quiet ? undefined : sayWarmUp;
|
|
134
|
+
let res;
|
|
135
|
+
try {
|
|
136
|
+
res = await retryOnceOnWarmUp(() => postChat(client, endpoint, payload), say);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
if (err instanceof FacesAPIError && isMaxTokensRenameError(err.message) && payload.max_tokens !== undefined) {
|
|
140
|
+
payload.max_completion_tokens = payload.max_tokens;
|
|
141
|
+
delete payload.max_tokens;
|
|
142
|
+
res = await retryOnceOnWarmUp(() => postChat(client, endpoint, payload), say);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!quiet)
|
|
149
|
+
warnDroppedParams(res.headers, CHAT_PARAM_FLAGS);
|
|
150
|
+
const body = res.data;
|
|
151
|
+
return { text: replyText(body, endpoint), body, headers: res.headers };
|
|
152
|
+
}
|
|
153
|
+
export function faceOfModel(model) {
|
|
154
|
+
const faces = parseModel(model).faces ?? model;
|
|
155
|
+
return faces.replace(/^@/, '').replace('~', ':');
|
|
156
|
+
}
|
|
157
|
+
export { CHAT_COMPLETIONS_ENDPOINT, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT };
|
package/dist/choices.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export declare const CHOICES_PATH = "/v1/choices";
|
|
2
|
-
export
|
|
2
|
+
export { MAESTROS as CHOICES_MAESTROS } from './model.js';
|
|
3
3
|
export declare const MAX_CHOICES = 32;
|
|
4
4
|
export declare const MAX_STATE_TOKENS = 3000;
|
|
5
5
|
export interface ChoicesResponse {
|
|
6
6
|
object?: string;
|
|
7
|
-
view?: string;
|
|
8
7
|
model?: string;
|
|
9
|
-
version?: string;
|
|
10
8
|
choices?: Array<{
|
|
11
9
|
name?: string;
|
|
12
10
|
description?: string;
|
|
@@ -18,6 +16,5 @@ export interface ChoicesResponse {
|
|
|
18
16
|
output_tokens?: number;
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
|
-
export declare function asView(face: string): string;
|
|
22
19
|
export declare function choicesLines(data: ChoicesResponse): string[];
|
|
23
|
-
export declare function choicesHint(status: number, message: string,
|
|
20
|
+
export declare function choicesHint(status: number, message: string, model: string): string | undefined;
|
package/dist/choices.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { parseModel } from './model.js';
|
|
1
2
|
export const CHOICES_PATH = '/v1/choices';
|
|
2
|
-
export
|
|
3
|
+
export { MAESTROS as CHOICES_MAESTROS } from './model.js';
|
|
3
4
|
export const MAX_CHOICES = 32;
|
|
4
5
|
export const MAX_STATE_TOKENS = 3000;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return f.startsWith('@') ? f : `@${f}`;
|
|
6
|
+
function faceOf(model) {
|
|
7
|
+
return model ? parseModel(model).faces ?? model : undefined;
|
|
8
8
|
}
|
|
9
9
|
export function choicesLines(data) {
|
|
10
10
|
const lines = [];
|
|
11
11
|
if (data.object === 'choices.question') {
|
|
12
|
-
lines.push(`${data.
|
|
12
|
+
lines.push(`${faceOf(data.model) ?? 'The face'} would ask: ${data.question ?? '-'}`);
|
|
13
13
|
const alts = data.alternatives ?? [];
|
|
14
14
|
if (alts.length > 0) {
|
|
15
15
|
lines.push('', 'Or:');
|
|
@@ -34,14 +34,15 @@ export function choicesLines(data) {
|
|
|
34
34
|
}
|
|
35
35
|
return lines;
|
|
36
36
|
}
|
|
37
|
-
export function choicesHint(status, message,
|
|
37
|
+
export function choicesHint(status, message, model) {
|
|
38
|
+
const face = (parseModel(model).faces ?? model).replace(/^@/, '').replace('~', ':');
|
|
38
39
|
if (status === 422 && /at most 3,000/.test(message)) {
|
|
39
40
|
return 'Put the situation in a state, one premise per fact (faces state:create, then faces state:add), and pass --state-id.';
|
|
40
41
|
}
|
|
41
42
|
if (status === 409 && /nothing compiled/i.test(message))
|
|
42
|
-
return `Give it a first source: faces compile:upload ${face
|
|
43
|
+
return `Give it a first source: faces compile:upload ${face} --file <file>.`;
|
|
43
44
|
if (status === 409 && /compiled before/i.test(message))
|
|
44
|
-
return `Recompile one of its sources (list them with: faces face:sources ${face
|
|
45
|
+
return `Recompile one of its sources (list them with: faces face:sources ${face}).`;
|
|
45
46
|
if (status === 404 && /state/i.test(message))
|
|
46
47
|
return 'A state expires 30 days after it was last used. Start another with: faces state:create';
|
|
47
48
|
return undefined;
|