@faces-sh/cli 1.0.3 → 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 +107 -53
- package/dist/billing.js +11 -8
- package/dist/{commands/causes.d.ts → chat-command.d.ts} +13 -13
- 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 +20 -0
- package/dist/choices.js +49 -0
- package/dist/commands/auth/connect.js +2 -2
- package/dist/commands/billing/llm-costs.js +9 -5
- package/dist/commands/billing/subscription/index.js +1 -1
- package/dist/commands/catalog/doctor.js +9 -68
- package/dist/commands/chat/chat.d.ts +10 -26
- package/dist/commands/chat/chat.js +21 -366
- package/dist/commands/chat/messages.d.ts +13 -13
- package/dist/commands/chat/messages.js +15 -142
- package/dist/commands/chat/responses.d.ts +13 -14
- package/dist/commands/chat/responses.js +16 -153
- package/dist/commands/chat/thread.d.ts +3 -15
- package/dist/commands/chat/thread.js +128 -362
- package/dist/commands/choices.d.ts +20 -0
- package/dist/commands/choices.js +91 -0
- package/dist/commands/conversation/add.d.ts +2 -0
- package/dist/commands/conversation/add.js +21 -10
- package/dist/commands/conversation/close.js +5 -5
- package/dist/commands/conversation/compact.js +15 -18
- package/dist/commands/conversation/create.d.ts +2 -0
- package/dist/commands/conversation/create.js +20 -17
- package/dist/commands/conversation/get.js +4 -4
- package/dist/commands/conversation/items.js +5 -5
- package/dist/commands/decide.d.ts +4 -4
- package/dist/commands/decide.js +70 -81
- package/dist/commands/face/get.js +2 -2
- 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 +16 -5
- package/dist/commands/session/close.js +1 -1
- package/dist/commands/session/compact.js +6 -9
- package/dist/commands/session/create.js +10 -9
- package/dist/commands/session/get.js +1 -1
- package/dist/commands/state/add.d.ts +3 -0
- package/dist/commands/state/add.js +3 -0
- package/dist/commands/state/close.d.ts +3 -0
- package/dist/commands/state/close.js +3 -0
- package/dist/commands/state/compact.d.ts +3 -0
- package/dist/commands/state/compact.js +3 -0
- package/dist/commands/state/create.d.ts +3 -0
- package/dist/commands/state/create.js +3 -0
- package/dist/commands/state/get.d.ts +3 -0
- package/dist/commands/state/get.js +3 -0
- package/dist/commands/state/items.d.ts +3 -0
- package/dist/commands/state/items.js +3 -0
- package/dist/commands/style/make.js +2 -6
- package/dist/commands/style/upload.js +1 -1
- package/dist/conversation.d.ts +27 -2
- package/dist/conversation.js +91 -16
- package/dist/decisions.d.ts +0 -5
- package/dist/decisions.js +0 -18
- 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 +2054 -1649
- package/package.json +10 -7
- package/dist/commands/causes.js +0 -146
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Faces CLI
|
|
2
2
|
|
|
3
3
|
Command-line interface for [Faces](https://faces.sh). Faces are causal models: compile one from an
|
|
4
|
-
author's source texts, and
|
|
5
|
-
|
|
6
|
-
|
|
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. A face also steers any chat model's replies, and a decision model's
|
|
6
|
+
typed decisions.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -28,15 +28,17 @@ faces face:create --name "Alice" --alias alice --default-model gpt-5.4-mini \
|
|
|
28
28
|
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
|
-
#
|
|
32
|
-
faces
|
|
31
|
+
# Ask what it would do: the options it would weigh, strongest first
|
|
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
|
-
#
|
|
35
|
-
faces
|
|
36
|
-
faces chat:chat alice -m "Tell me more" --llm claude-sonnet-4-6 --show-cause
|
|
34
|
+
# Or let it propose the question it would ask
|
|
35
|
+
faces choices @alice:maestro-1 --state "A startup offers me a lead role at a lower salary."
|
|
37
36
|
|
|
38
|
-
#
|
|
39
|
-
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
|
+
|
|
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." \
|
|
40
42
|
--question "Does the speaker sign?"
|
|
41
43
|
|
|
42
44
|
# Compare and compose
|
|
@@ -55,11 +57,12 @@ faces face:diff / neighbors / lock / unlock / publish / unpublish / share / unsh
|
|
|
55
57
|
faces face:avatar:list / get / make / upload / delete
|
|
56
58
|
faces face:tag:add / list / remove / set / all
|
|
57
59
|
|
|
58
|
-
faces
|
|
59
|
-
faces chat:chat / messages / responses / thread
|
|
60
|
+
faces choices # what a face would do: its options, or the question it would ask
|
|
61
|
+
faces chat:chat / messages / responses / thread # chat with a face on any chat model
|
|
60
62
|
faces decide # what a face would decide: yes/no, a choice, or a score
|
|
61
|
-
faces
|
|
62
|
-
faces
|
|
63
|
+
faces state:create / get / items / add / compact / close
|
|
64
|
+
faces conversation:create / ... # the old name for state:*
|
|
65
|
+
faces session:create / get / compact / close # an older name
|
|
63
66
|
|
|
64
67
|
faces compile:doc / compile:doc:create / list / get / edit / make / pause / reset / delete
|
|
65
68
|
faces compile:thread:create / list / get / edit / message / replace / make / pause / reset / delete
|
|
@@ -68,6 +71,7 @@ faces compile:upload / import / all / status / stats
|
|
|
68
71
|
faces style:upload / make / status / versions / revert / delete
|
|
69
72
|
|
|
70
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
|
|
71
75
|
faces benchmark:start / get / list
|
|
72
76
|
faces fidelity:start / turn / pick / get / run / save-thread
|
|
73
77
|
|
|
@@ -104,59 +108,104 @@ faces compile:upload alice --file interview.txt --kind thread --face-speaker Ali
|
|
|
104
108
|
faces compile:upload alice --file podcast.mp3 --kind thread --face-speaker A
|
|
105
109
|
```
|
|
106
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
|
+
|
|
107
114
|
A labelled dialogue uploaded as a document is read as entirely the face's own words, other
|
|
108
115
|
speakers included. The document commands warn when a text file reads as a transcript.
|
|
109
116
|
|
|
110
|
-
##
|
|
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 `^` |
|
|
111
130
|
|
|
112
|
-
|
|
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
|
+
|
|
137
|
+
## Choices
|
|
138
|
+
|
|
139
|
+
`faces choices` asks a face what it would do (`POST /v1/choices`). Describe the situation with
|
|
140
|
+
`--state` (prose, at most 3,000 tokens) or `--state-id` (a [state](#states)), and ask with
|
|
141
|
+
`--question`:
|
|
113
142
|
|
|
114
143
|
```bash
|
|
115
|
-
faces
|
|
116
|
-
faces
|
|
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?"
|
|
117
147
|
```
|
|
118
148
|
|
|
119
|
-
`--
|
|
120
|
-
|
|
149
|
+
With both `--state-id` and `--state`, the prose is an addendum for that one call: read with the
|
|
150
|
+
state, never saved to it. Anything that should persist goes in the state as premises, with
|
|
151
|
+
`faces state:add --premise`.
|
|
121
152
|
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
The face proposes the options it would weigh, strongest first. Leave `--question` out and it
|
|
154
|
+
proposes the question it would ask. Prices: `faces models:list --kind upstream`.
|
|
124
155
|
|
|
125
|
-
##
|
|
156
|
+
## Chat
|
|
126
157
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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`.
|
|
130
162
|
|
|
131
163
|
```bash
|
|
132
|
-
faces
|
|
133
|
-
faces chat:chat
|
|
134
|
-
|
|
135
|
-
faces
|
|
136
|
-
|
|
137
|
-
faces conversation:add fs_CONVERSATION_ID --premise vendor_certified=false \
|
|
138
|
-
--premise-description vendor_certified="the vendor holds a security audit report"
|
|
139
|
-
faces conversation:items fs_CONVERSATION_ID
|
|
140
|
-
faces conversation:compact fs_CONVERSATION_ID
|
|
141
|
-
faces chat:chat alice -m "So what do I tell them tomorrow?" --compaction fcmp_COMPACTION_ID
|
|
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
|
|
142
169
|
```
|
|
143
170
|
|
|
144
|
-
|
|
145
|
-
|
|
171
|
+
The face's style is chosen for each request, from the face's built styles. `style:*` builds them.
|
|
172
|
+
|
|
173
|
+
## States
|
|
174
|
+
|
|
175
|
+
A state keeps the situation your agent builds on the server: **premises** (named facts, each with
|
|
176
|
+
a status and what it depends on), the decisions faces made, and your messages. Hand it to a face
|
|
177
|
+
with `faces choices --state-id`, or pass it to `chat:*` and `decide` with `--conversation`.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
faces state:create @alice
|
|
181
|
+
faces state:add fs_STATE_ID --premise rent_rises='"12% in March"' --premise-status rent_rises=assumed \
|
|
182
|
+
--premise-description rent_rises="the landlord says rent goes up 12% in March"
|
|
183
|
+
faces state:add fs_STATE_ID --premise can_afford=false --premise-depends-on can_afford=rent_rises \
|
|
184
|
+
--premise-description can_afford="the shop can carry the higher rent"
|
|
185
|
+
faces decide @alice:maestro-1/jev-latest --conversation fs_STATE_ID --depends-on can_afford \
|
|
186
|
+
--state "Decide about the lease." --question "Move the shop to a cheaper street?"
|
|
187
|
+
faces state:add fs_STATE_ID --premise rent_rises='"no rise this year"' --premise-status rent_rises=invalidated
|
|
188
|
+
faces choices @alice:maestro-1 --state-id fs_STATE_ID --question "What should the shop do?"
|
|
189
|
+
faces state:items fs_STATE_ID
|
|
190
|
+
```
|
|
146
191
|
|
|
147
192
|
A premise is `--premise key=value`, repeatable. The key is 1 to 64 letters, digits, `_` or `-`. The
|
|
148
193
|
value is read as JSON when it is JSON (`50000`, `true`, `null`, `["a","b"]`) and as text otherwise;
|
|
149
194
|
quote it to keep a number as text: `--premise 'code="007"'`. The first time a key is used it needs
|
|
150
|
-
a description
|
|
151
|
-
|
|
152
|
-
|
|
195
|
+
a description: `--premise-description key="what it means"`.
|
|
196
|
+
|
|
197
|
+
`--premise-status key=status` is `stated` (the default), `verified`, `assumed`, `unresolved` or
|
|
198
|
+
`invalidated`. `--premise-depends-on key=a,b` names the premise keys and decision ids it rests on
|
|
199
|
+
(`key=` clears it). An invalidated premise invalidates everything that depends on it, and setting it
|
|
200
|
+
to another status restores them: `state:add` prints every status that changed, and every earlier
|
|
201
|
+
decision that rested on a value you changed. Nothing is decided again for you. `decide
|
|
202
|
+
--depends-on` says what a decision rests on, and prints its decision id to name in a later one.
|
|
153
203
|
|
|
154
|
-
|
|
155
|
-
`
|
|
156
|
-
one names the face: `faces conversation:compact fs_CONVERSATION_ID alice`.
|
|
204
|
+
`--conversation`, `--premise`, `--premise-description`, `--premise-status` and
|
|
205
|
+
`--premise-depends-on` work on `chat:*` and `decide`.
|
|
157
206
|
|
|
158
|
-
|
|
159
|
-
the same thing.
|
|
207
|
+
States were called conversations, and before that sessions. The `conversation:*` and `session:*`
|
|
208
|
+
commands, and `--session`, still work and name the same thing.
|
|
160
209
|
|
|
161
210
|
## Authentication
|
|
162
211
|
|
|
@@ -171,13 +220,18 @@ export FACES_BASE_URL=https://api.faces.sh # optional override
|
|
|
171
220
|
## Plans
|
|
172
221
|
|
|
173
222
|
- **Free**: a $5 activation, added as credits. Everything is paid as it goes, from credits.
|
|
174
|
-
- **Connect** ($17/month) and
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
and `
|
|
223
|
+
- **Connect** ($17/month): 25M choices and steering tokens a month (6.25M a week, 1.6M per 5 hours) and
|
|
224
|
+
500k compile source tokens.
|
|
225
|
+
- **Pro** ($49/month): 75M choices and steering tokens a month (18.75M a week, 4.8M per 5 hours) and
|
|
226
|
+
1.5M compile source tokens.
|
|
227
|
+
|
|
228
|
+
Past an allowance, work is paid from credits only with `api_fallback` on (`faces account:preferences`).
|
|
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
|
|
233
|
+
`faces auth:connect openai` and interviews and style builds run on the ChatGPT plan. Current prices:
|
|
234
|
+
`faces models:list --kind all`.
|
|
181
235
|
|
|
182
236
|
## License
|
|
183
237
|
|
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}`);
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { BaseCommand } from '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
static examples: string[];
|
|
1
|
+
import { BaseCommand } from './base.js';
|
|
2
|
+
import { FacesAPIError, FacesClient } from './client.js';
|
|
3
|
+
export declare abstract class ChatCommand extends BaseCommand {
|
|
5
4
|
static flags: {
|
|
6
5
|
session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
6
|
compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
8
|
conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
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>;
|
|
11
13
|
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
14
|
message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
15
|
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
option: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
-
level: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
-
id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
-
'questions-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>;
|
|
22
20
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
21
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
22
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
25
23
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
26
24
|
};
|
|
27
25
|
static args: {
|
|
28
|
-
|
|
26
|
+
model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
29
27
|
};
|
|
28
|
+
protected abstract forcedEndpoint(flags: Record<string, unknown>): string | undefined;
|
|
30
29
|
run(): Promise<unknown>;
|
|
31
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 };
|