@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
|
@@ -1,376 +1,31 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import { BaseCommand } from '../../base.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'Add --style <medium> to apply a style the face has built, --conversation to take the turn in a ' +
|
|
14
|
-
'conversation (see faces conversation:create), and --compaction to read a compaction.';
|
|
3
|
+
import { RESPONSES_ENDPOINT, chatFlags, MODEL_ARG_DESCRIPTION } from '../../chat.js';
|
|
4
|
+
import { ChatCommand } from '../../chat-command.js';
|
|
5
|
+
export default class ChatChat extends ChatCommand {
|
|
6
|
+
static description = 'Chat with a face. Name the upstream model over the downstream model: @alice:maestro-1/gpt-5.4. The face ' +
|
|
7
|
+
'steers, and the downstream model writes the reply. Routes to /v1/chat/completions, /v1/responses or ' +
|
|
8
|
+
'/v1/messages from the model catalog (--responses forces /v1/responses). The face\'s style is chosen for ' +
|
|
9
|
+
'each request. Add --conversation to take the turn in a state (see faces state:create). The steering is ' +
|
|
10
|
+
'billed per input token plus a small fee per call (faces models:list --kind upstream), and the downstream ' +
|
|
11
|
+
'model at its listed price.';
|
|
15
12
|
static examples = [
|
|
16
|
-
'<%= config.bin %> <%= command.id %> socrates -m "What is virtue?"',
|
|
17
|
-
'<%= config.bin %> <%= command.id %>
|
|
18
|
-
'<%= config.bin %> <%= command.id %> socrates -m "
|
|
19
|
-
'<%= config.bin %> <%= command.id %>
|
|
20
|
-
'<%= config.bin %> <%= command.id %>
|
|
21
|
-
'<%= config.bin %> <%= command.id %> alice -m "So what do I tell them tomorrow?" --conversation fs_CONVERSATION_ID',
|
|
22
|
-
'<%= config.bin %> <%= command.id %> alice -m "Is this vendor worth a closer look?" --conversation fs_CONVERSATION_ID ' +
|
|
13
|
+
'<%= config.bin %> <%= command.id %> @socrates:maestro-1/gpt-5.4 -m "What is virtue?"',
|
|
14
|
+
'<%= config.bin %> <%= command.id %> @head~socrates:maestro-1-flash/claude-sonnet-4-6 -m "What is virtue?"',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> "(@socrates | @nietzsche):maestro-1/gpt-5.4" -m "What is virtue?"',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/gpt-5.4 -m "So what do I tell them tomorrow?" --conversation fs_STATE_ID',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/gpt-5.4 -m "Is this vendor worth a closer look?" --conversation fs_STATE_ID ' +
|
|
23
18
|
'--premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
|
|
24
|
-
'<%= config.bin %> <%= command.id %> "(socrates | nietzsche)@claude-sonnet-4-6" -m "What is virtue?"',
|
|
25
|
-
'<%= config.bin %> <%= command.id %> --formula "socrates | nietzsche" --llm claude-sonnet-4-6 -m "What is virtue?"',
|
|
26
19
|
];
|
|
20
|
+
static args = {
|
|
21
|
+
model: Args.string({ description: MODEL_ARG_DESCRIPTION, required: true }),
|
|
22
|
+
};
|
|
27
23
|
static flags = {
|
|
28
24
|
...BaseCommand.baseFlags,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
formula: Flags.string({ description: 'Compose a run-time composite from your own faces, e.g. "socrates | nietzsche" (operators: | & ^ -). Requires --llm, except with --cause-only. The composite takes the name of its first operand; use face:create --formula for a named, persisted composite.' }),
|
|
32
|
-
system: Flags.string({ description: 'System prompt / instructions' }),
|
|
33
|
-
stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
|
|
34
|
-
'max-tokens': Flags.integer({ description: 'Max tokens (at least 1)', min: 1 }),
|
|
35
|
-
temperature: Flags.string({ description: 'Temperature (0.0-2.0)' }),
|
|
36
|
-
file: Flags.string({ description: 'Read message from file' }),
|
|
37
|
-
responses: Flags.boolean({ description: 'Force the OpenAI Responses API endpoint (escape hatch; routing is automatic otherwise)', default: false }),
|
|
38
|
-
style: Flags.string({ description: STYLE_FLAG_DESCRIPTION }),
|
|
39
|
-
medium: Flags.string({ description: MEDIUM_FLAG_DESCRIPTION }),
|
|
40
|
-
...conversationTurnFlags(),
|
|
41
|
-
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
|
|
42
|
-
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
|
|
43
|
-
'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
|
|
44
|
-
'show-cause': Flags.boolean({ description: REASONING_FLAG_DESCRIPTION, default: false }),
|
|
45
|
-
cause: Flags.string({ description: CAUSE_FLAG_DESCRIPTION }),
|
|
46
|
-
'cause-file': Flags.string({ description: CAUSE_FILE_FLAG_DESCRIPTION, exclusive: ['cause'] }),
|
|
47
|
-
'cause-only': Flags.boolean({
|
|
48
|
-
description: 'Ask for the face\'s cause alone, with no answer: no model is called, and only the cause is ' +
|
|
49
|
-
'charged. Printed to stdout.',
|
|
50
|
-
default: false,
|
|
51
|
-
exclusive: ['llm', 'style', 'medium', 'show-cause', 'cause', 'cause-file'],
|
|
52
|
-
}),
|
|
53
|
-
};
|
|
54
|
-
static args = {
|
|
55
|
-
face_username: Args.string({
|
|
56
|
-
description: 'Face alias (alias@model, owner:alias@model for a published face, or a composite formula like ' +
|
|
57
|
-
'"(a | b)@model"). Omit when using --formula.',
|
|
58
|
-
required: false,
|
|
59
|
-
}),
|
|
25
|
+
...chatFlags(),
|
|
26
|
+
responses: Flags.boolean({ description: 'Send it to /v1/responses whatever the catalog says (routing is automatic otherwise).', default: false }),
|
|
60
27
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const client = this.makeClient(flags);
|
|
64
|
-
let model;
|
|
65
|
-
if (flags.formula) {
|
|
66
|
-
if (args.face_username)
|
|
67
|
-
this.error('Pass either a face argument or --formula, not both.');
|
|
68
|
-
if (!flags.llm && !flags['cause-only'])
|
|
69
|
-
this.error('--formula needs a model. Add --llm <model>, e.g. --llm claude-sonnet-4-6.');
|
|
70
|
-
model = flags.llm ? `(${flags.formula.trim()})@${flags.llm}` : `(${flags.formula.trim()})`;
|
|
71
|
-
}
|
|
72
|
-
else if (!args.face_username) {
|
|
73
|
-
this.error('Provide a face (alias, owner:alias, or a composite formula), or use --formula.');
|
|
74
|
-
}
|
|
75
|
-
else if (flags.llm) {
|
|
76
|
-
const base = faceSpecOf(args.face_username);
|
|
77
|
-
model = `${base}@${flags.llm}`;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
model = args.face_username;
|
|
81
|
-
}
|
|
82
|
-
if (isCompositeFormula(model) && !llmFromArg(model) && !flags['cause-only']) {
|
|
83
|
-
const spec = faceSpecOf(model);
|
|
84
|
-
this.error(`Composite face '${spec}' has no default model. Specify one explicitly, ` +
|
|
85
|
-
`e.g. '${spec}@claude-sonnet-4-6', or pass --llm <model>.`);
|
|
86
|
-
}
|
|
87
|
-
if (flags.style && isCompositeFormula(model)) {
|
|
88
|
-
this.error('--style applies to one face, not a combination of faces.');
|
|
89
|
-
}
|
|
90
|
-
const userMessages = [];
|
|
91
|
-
if (flags.file) {
|
|
92
|
-
if (!fs.existsSync(flags.file))
|
|
93
|
-
this.error(`File not found: ${flags.file}`);
|
|
94
|
-
userMessages.push(fs.readFileSync(flags.file, 'utf8'));
|
|
95
|
-
}
|
|
96
|
-
else if (flags.message && flags.message.length > 0) {
|
|
97
|
-
userMessages.push(...flags.message);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.error('Provide at least one --message/-m or --file');
|
|
101
|
-
}
|
|
102
|
-
if (flags['cause-only'] && llmFromArg(model)) {
|
|
103
|
-
this.error(`--cause-only asks the face alone, so leave the model off: ${faceSpecOf(model)}`);
|
|
104
|
-
}
|
|
105
|
-
let turn;
|
|
106
|
-
try {
|
|
107
|
-
turn = conversationFields(flags);
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
this.error(err instanceof Error ? err.message : String(err));
|
|
111
|
-
}
|
|
112
|
-
this.conversationBody = turn;
|
|
113
|
-
const route = await resolveEndpoint(client, model);
|
|
114
|
-
const endpoint = flags.responses ? RESPONSES_ENDPOINT : route.endpoint;
|
|
115
|
-
if (!flags['cause-only'] && !llmFromArg(model)) {
|
|
116
|
-
if (!route.llm) {
|
|
117
|
-
this.error(`${model} has no default model to answer on, so name one: ${model}@<model>, or add --llm <model>.\n` +
|
|
118
|
-
'For the face\'s cause alone, with no answer, add --cause-only.');
|
|
119
|
-
}
|
|
120
|
-
model = `${model}@${route.llm}`;
|
|
121
|
-
}
|
|
122
|
-
let cause;
|
|
123
|
-
try {
|
|
124
|
-
cause = resolveCause(flags.cause, flags['cause-file']);
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
this.error(err instanceof Error ? err.message : String(err));
|
|
128
|
-
}
|
|
129
|
-
const send = { ...flags, cause, stream: flags.stream && !this.jsonEnabled() };
|
|
130
|
-
this.reasoningOnly = flags['cause-only'];
|
|
131
|
-
try {
|
|
132
|
-
if (endpoint === MESSAGES_ENDPOINT) {
|
|
133
|
-
return await this.runMessages(client, model, userMessages, send);
|
|
134
|
-
}
|
|
135
|
-
else if (endpoint === RESPONSES_ENDPOINT) {
|
|
136
|
-
return await this.runResponses(client, model, userMessages, send);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return await this.runChatCompletions(client, model, userMessages, send);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
if (err instanceof FacesAPIError) {
|
|
144
|
-
if (err.errorCode === 'oauth_rejected')
|
|
145
|
-
this.error(`OAuth failed: ${err.message}\n${await this.oauthHint(err, { ...route, endpoint }, client)}`);
|
|
146
|
-
if (err.errorCode === 'model_not_supported') {
|
|
147
|
-
this.error(`${err.message}\n` +
|
|
148
|
-
'Your ChatGPT plan does not serve this model. Pick another with --llm, ' +
|
|
149
|
-
'or let it run on credits: faces account:preferences api_fallback true');
|
|
150
|
-
}
|
|
151
|
-
const hint = faceRefusalHint(err, model, flags.style);
|
|
152
|
-
this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
|
|
153
|
-
}
|
|
154
|
-
throw err;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async oauthHint(err, route, client) {
|
|
158
|
-
const hints = [];
|
|
159
|
-
const linked = await chatgptLinked(client);
|
|
160
|
-
if (linked === false)
|
|
161
|
-
hints.push('No ChatGPT account is linked. Link one with: faces auth:connect openai');
|
|
162
|
-
else
|
|
163
|
-
hints.push('If the ChatGPT link has lapsed, link it again with: faces auth:connect openai');
|
|
164
|
-
if (route.endpoint === RESPONSES_ENDPOINT && route.freeWhenConnected && linked === false) {
|
|
165
|
-
hints.push('This model is free once it is linked.');
|
|
166
|
-
}
|
|
167
|
-
if (err.fallbackAvailable) {
|
|
168
|
-
hints.push('Or allow paid fallback: faces account:preferences api_fallback true');
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
let balance;
|
|
172
|
-
try {
|
|
173
|
-
balance = Number((await client.get('/v1/billing/balance')).balance_usd);
|
|
174
|
-
}
|
|
175
|
-
catch { }
|
|
176
|
-
hints.push(balance !== undefined && balance > 0
|
|
177
|
-
? 'Or allow paid fallback on your credits: faces account:preferences api_fallback true'
|
|
178
|
-
: 'Or add credits (faces billing:topup --amount <usd>) and allow paid fallback: faces account:preferences api_fallback true');
|
|
179
|
-
}
|
|
180
|
-
return hints.join('\n');
|
|
181
|
-
}
|
|
182
|
-
metaFor(headers, endpoint, model) {
|
|
183
|
-
const meta = {};
|
|
184
|
-
if (headers['x-faces-provider'])
|
|
185
|
-
meta.provider = headers['x-faces-provider'];
|
|
186
|
-
if (headers['x-faces-cost-usd'])
|
|
187
|
-
meta.cost_usd = headers['x-faces-cost-usd'];
|
|
188
|
-
if (headers['x-faces-billing'])
|
|
189
|
-
meta.billing = headers['x-faces-billing'];
|
|
190
|
-
meta.endpoint = endpoint;
|
|
191
|
-
meta.model = model;
|
|
192
|
-
return meta;
|
|
193
|
-
}
|
|
194
|
-
async streamDeltas(client, endpoint, payload, showReasoning) {
|
|
195
|
-
const model = String(payload.model);
|
|
196
|
-
let reasoning = '';
|
|
197
|
-
let replied = false;
|
|
198
|
-
const onHeaders = (headers) => warnDroppedParams(headers, CHAT_PARAM_FLAGS);
|
|
199
|
-
for await (const line of streamChat(client, endpoint, payload, onHeaders)) {
|
|
200
|
-
if (!line.startsWith('data: '))
|
|
201
|
-
continue;
|
|
202
|
-
const chunk = line.slice(6);
|
|
203
|
-
if (chunk.trim() === '[DONE]' || chunk.trim() === '')
|
|
204
|
-
continue;
|
|
205
|
-
try {
|
|
206
|
-
const parsed = JSON.parse(chunk);
|
|
207
|
-
const thought = extractStreamReasoning(parsed);
|
|
208
|
-
if (thought) {
|
|
209
|
-
if (showReasoning && !reasoning)
|
|
210
|
-
process.stderr.write(`${reasoningHeading(model)}\n`);
|
|
211
|
-
if (showReasoning)
|
|
212
|
-
process.stderr.write(thought);
|
|
213
|
-
reasoning += thought;
|
|
214
|
-
}
|
|
215
|
-
const delta = extractStreamDelta(parsed);
|
|
216
|
-
if (delta) {
|
|
217
|
-
if (showReasoning && reasoning && !replied)
|
|
218
|
-
process.stderr.write('\n\n');
|
|
219
|
-
replied = true;
|
|
220
|
-
process.stdout.write(delta);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
catch { }
|
|
224
|
-
}
|
|
225
|
-
if (!replied && reasoning) {
|
|
226
|
-
if (showReasoning)
|
|
227
|
-
process.stderr.write('\n');
|
|
228
|
-
else
|
|
229
|
-
process.stdout.write(`${reasoning}\n`);
|
|
230
|
-
this.noteReasoningOnly(model);
|
|
231
|
-
}
|
|
232
|
-
else if (!replied) {
|
|
233
|
-
this.error('The reply stream ended with no answer and no cause. Run it again with --no-stream to see what the server said.');
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
process.stdout.write('\n');
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
printReply(model, reasoning, text, showReasoning) {
|
|
240
|
-
writeReply(model, reasoning, text, showReasoning, this.reasoningOnly ? undefined : reasoningOnlyNote(model));
|
|
241
|
-
}
|
|
242
|
-
noteReasoningOnly(model) {
|
|
243
|
-
if (this.reasoningOnly)
|
|
244
|
-
return;
|
|
245
|
-
process.stderr.write(`\n${reasoningOnlyNote(model)}\n`);
|
|
246
|
-
}
|
|
247
|
-
reasoningOnly = false;
|
|
248
|
-
conversationBody = {};
|
|
249
|
-
async runChatCompletions(client, model, userMessages, flags) {
|
|
250
|
-
const messages = [];
|
|
251
|
-
if (flags.system)
|
|
252
|
-
messages.push({ role: 'system', content: flags.system });
|
|
253
|
-
for (const m of userMessages)
|
|
254
|
-
messages.push({ role: 'user', content: m });
|
|
255
|
-
const payload = { model, messages, stream: flags.stream };
|
|
256
|
-
if (flags['max-tokens'])
|
|
257
|
-
payload.max_tokens = flags['max-tokens'];
|
|
258
|
-
if (flags.temperature !== undefined)
|
|
259
|
-
payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
|
|
260
|
-
Object.assign(payload, chatExtras(flags), this.conversationBody);
|
|
261
|
-
if (flags['oauth-only'])
|
|
262
|
-
payload.oauth_only = true;
|
|
263
|
-
if (flags.cause)
|
|
264
|
-
payload.cause = flags.cause;
|
|
265
|
-
if (flags.stream) {
|
|
266
|
-
await this.streamDeltas(client, '/v1/chat/completions', payload, flags['show-cause']);
|
|
267
|
-
return {};
|
|
268
|
-
}
|
|
269
|
-
let data;
|
|
270
|
-
let headers;
|
|
271
|
-
try {
|
|
272
|
-
;
|
|
273
|
-
({ data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/chat/completions', payload), sayWarmUp));
|
|
274
|
-
}
|
|
275
|
-
catch (err) {
|
|
276
|
-
if (err instanceof FacesAPIError && isMaxTokensRenameError(err.message) && payload.max_tokens !== undefined) {
|
|
277
|
-
payload.max_completion_tokens = payload.max_tokens;
|
|
278
|
-
delete payload.max_tokens;
|
|
279
|
-
({ data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/chat/completions', payload), sayWarmUp));
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
throw err;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (!this.jsonEnabled())
|
|
286
|
-
warnDroppedParams(headers, CHAT_PARAM_FLAGS);
|
|
287
|
-
const body = data;
|
|
288
|
-
const choices = body.choices;
|
|
289
|
-
const text = String(choices?.[0]?.message?.content ?? '');
|
|
290
|
-
if (this.jsonEnabled()) {
|
|
291
|
-
body._meta = this.metaFor(headers, '/v1/chat/completions', model);
|
|
292
|
-
return body;
|
|
293
|
-
}
|
|
294
|
-
this.printReply(model, extractReasoning(body, '/v1/chat/completions'), text, flags['show-cause']);
|
|
295
|
-
return body;
|
|
296
|
-
}
|
|
297
|
-
async runMessages(client, model, userMessages, flags) {
|
|
298
|
-
const msgs = userMessages.map((m) => ({ role: 'user', content: m }));
|
|
299
|
-
const payload = {
|
|
300
|
-
model,
|
|
301
|
-
messages: msgs,
|
|
302
|
-
max_tokens: flags['max-tokens'] ?? 1024,
|
|
303
|
-
stream: flags.stream,
|
|
304
|
-
};
|
|
305
|
-
if (flags.system)
|
|
306
|
-
payload.system = flags.system;
|
|
307
|
-
Object.assign(payload, chatExtras(flags), this.conversationBody);
|
|
308
|
-
if (flags['oauth-only'])
|
|
309
|
-
payload.oauth_only = true;
|
|
310
|
-
if (flags.cause)
|
|
311
|
-
payload.cause = flags.cause;
|
|
312
|
-
if (flags.stream) {
|
|
313
|
-
await this.streamDeltas(client, '/v1/messages', payload, flags['show-cause']);
|
|
314
|
-
return {};
|
|
315
|
-
}
|
|
316
|
-
const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/messages', payload), sayWarmUp);
|
|
317
|
-
if (!this.jsonEnabled())
|
|
318
|
-
warnDroppedParams(headers, CHAT_PARAM_FLAGS);
|
|
319
|
-
const body = data;
|
|
320
|
-
if (this.jsonEnabled()) {
|
|
321
|
-
body._meta = this.metaFor(headers, '/v1/messages', model);
|
|
322
|
-
return body;
|
|
323
|
-
}
|
|
324
|
-
let content = '';
|
|
325
|
-
for (const block of body.content ?? []) {
|
|
326
|
-
if (block.type === 'text')
|
|
327
|
-
content += String(block.text ?? '');
|
|
328
|
-
}
|
|
329
|
-
this.printReply(model, extractReasoning(body, '/v1/messages'), content, flags['show-cause']);
|
|
330
|
-
return body;
|
|
331
|
-
}
|
|
332
|
-
async runResponses(client, model, userMessages, flags) {
|
|
333
|
-
const payload = {
|
|
334
|
-
model,
|
|
335
|
-
input: userMessages.map((m) => ({ role: 'user', content: m })),
|
|
336
|
-
stream: flags.stream,
|
|
337
|
-
};
|
|
338
|
-
if (flags.system)
|
|
339
|
-
payload.instructions = flags.system;
|
|
340
|
-
if (flags['max-tokens'] !== undefined) {
|
|
341
|
-
if (flags['max-tokens'] < MIN_MAX_OUTPUT_TOKENS) {
|
|
342
|
-
this.error(`--max-tokens must be at least ${MIN_MAX_OUTPUT_TOKENS} for this model (got ${flags['max-tokens']}). ` +
|
|
343
|
-
'The Responses API rejects a smaller output cap.');
|
|
344
|
-
}
|
|
345
|
-
payload.max_output_tokens = flags['max-tokens'];
|
|
346
|
-
}
|
|
347
|
-
if (flags.temperature !== undefined)
|
|
348
|
-
payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
|
|
349
|
-
Object.assign(payload, chatExtras(flags), this.conversationBody);
|
|
350
|
-
if (flags['oauth-only'])
|
|
351
|
-
payload.oauth_only = true;
|
|
352
|
-
if (flags.cause)
|
|
353
|
-
payload.cause = flags.cause;
|
|
354
|
-
if (flags.stream) {
|
|
355
|
-
await this.streamDeltas(client, '/v1/responses', payload, flags['show-cause']);
|
|
356
|
-
return {};
|
|
357
|
-
}
|
|
358
|
-
const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/responses', payload), sayWarmUp);
|
|
359
|
-
if (!this.jsonEnabled())
|
|
360
|
-
warnDroppedParams(headers, CHAT_PARAM_FLAGS);
|
|
361
|
-
const body = data;
|
|
362
|
-
if (this.jsonEnabled()) {
|
|
363
|
-
body._meta = this.metaFor(headers, '/v1/responses', model);
|
|
364
|
-
return body;
|
|
365
|
-
}
|
|
366
|
-
let outputText = '';
|
|
367
|
-
for (const item of body.output ?? []) {
|
|
368
|
-
for (const block of item.content ?? []) {
|
|
369
|
-
if (block.type === 'output_text')
|
|
370
|
-
outputText += String(block.text ?? '');
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
this.printReply(model, extractReasoning(body, '/v1/responses'), outputText, flags['show-cause']);
|
|
374
|
-
return body;
|
|
28
|
+
forcedEndpoint(flags) {
|
|
29
|
+
return flags.responses ? RESPONSES_ENDPOINT : undefined;
|
|
375
30
|
}
|
|
376
31
|
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class ChatMessages extends
|
|
1
|
+
import { ChatCommand } from '../../chat-command.js';
|
|
2
|
+
export default class ChatMessages extends ChatCommand {
|
|
3
3
|
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static args: {
|
|
6
|
+
model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
7
|
+
};
|
|
4
8
|
static flags: {
|
|
5
9
|
session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
10
|
compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
11
|
'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
-
'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
-
cause: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
-
'cause-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
12
|
conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
13
|
premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
14
|
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
17
|
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
-
message: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
20
|
system: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
21
|
stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
-
'max-tokens': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
-
|
|
20
|
-
medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
+
'max-tokens': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
+
temperature: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
24
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
25
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
26
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
27
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
25
28
|
};
|
|
26
|
-
|
|
27
|
-
face_model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
28
|
-
};
|
|
29
|
-
run(): Promise<unknown>;
|
|
29
|
+
protected forcedEndpoint(): string;
|
|
30
30
|
}
|
|
@@ -1,148 +1,21 @@
|
|
|
1
|
-
import { Args
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { MESSAGES_ENDPOINT, chatFlags, MODEL_ARG_DESCRIPTION } from '../../chat.js';
|
|
4
|
+
import { ChatCommand } from '../../chat-command.js';
|
|
5
|
+
export default class ChatMessages extends ChatCommand {
|
|
6
|
+
static description = 'Chat with a face in the Anthropic Messages format (/v1/messages), whatever the model. chat:chat routes ' +
|
|
7
|
+
'Anthropic models here on its own. Name the model as for chat:chat: @alice:maestro-1/claude-sonnet-4-6.';
|
|
8
|
+
static examples = [
|
|
9
|
+
'<%= config.bin %> <%= command.id %> @socrates:maestro-1/claude-sonnet-4-6 -m "What is virtue?" --max-tokens 400',
|
|
10
|
+
];
|
|
11
|
+
static args = {
|
|
12
|
+
model: Args.string({ description: MODEL_ARG_DESCRIPTION, required: true }),
|
|
13
|
+
};
|
|
8
14
|
static flags = {
|
|
9
15
|
...BaseCommand.baseFlags,
|
|
10
|
-
|
|
11
|
-
system: Flags.string({ description: 'System prompt' }),
|
|
12
|
-
stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
|
|
13
|
-
'max-tokens': Flags.integer({ description: 'Max tokens (at least 1)', default: 1024, min: 1 }),
|
|
14
|
-
style: Flags.string({ description: STYLE_FLAG_DESCRIPTION }),
|
|
15
|
-
medium: Flags.string({ description: MEDIUM_FLAG_DESCRIPTION }),
|
|
16
|
-
...conversationTurnFlags(),
|
|
17
|
-
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
|
|
18
|
-
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
|
|
19
|
-
'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
|
|
20
|
-
'show-cause': Flags.boolean({ description: REASONING_FLAG_DESCRIPTION, default: false }),
|
|
21
|
-
cause: Flags.string({ description: CAUSE_FLAG_DESCRIPTION }),
|
|
22
|
-
'cause-file': Flags.string({ description: CAUSE_FILE_FLAG_DESCRIPTION, exclusive: ['cause'] }),
|
|
23
|
-
};
|
|
24
|
-
static args = {
|
|
25
|
-
face_model: Args.string({
|
|
26
|
-
description: 'Face model, sent as typed (e.g. myface@claude-sonnet-4-6, head:socrates@claude-sonnet-4-6). A face named without a model ' +
|
|
27
|
-
'returns only its cause, with no answer: name the model for one, or use chat:chat, which adds the ' +
|
|
28
|
-
'face\'s default model.',
|
|
29
|
-
required: true,
|
|
30
|
-
}),
|
|
16
|
+
...chatFlags(),
|
|
31
17
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const client = this.makeClient(flags);
|
|
35
|
-
const msgs = flags.message.map((m) => ({ role: 'user', content: m }));
|
|
36
|
-
let turn;
|
|
37
|
-
try {
|
|
38
|
-
turn = conversationFields(flags);
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
this.error(err instanceof Error ? err.message : String(err));
|
|
42
|
-
}
|
|
43
|
-
let cause;
|
|
44
|
-
try {
|
|
45
|
-
cause = resolveCause(flags.cause, flags['cause-file']);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
this.error(err instanceof Error ? err.message : String(err));
|
|
49
|
-
}
|
|
50
|
-
const model = args.face_model;
|
|
51
|
-
if (cause && !model.includes('@'))
|
|
52
|
-
this.error(causeNeedsModel(model));
|
|
53
|
-
const stream = flags.stream && !this.jsonEnabled();
|
|
54
|
-
const payload = {
|
|
55
|
-
model,
|
|
56
|
-
messages: msgs,
|
|
57
|
-
max_tokens: flags['max-tokens'],
|
|
58
|
-
stream,
|
|
59
|
-
};
|
|
60
|
-
if (flags.system)
|
|
61
|
-
payload.system = flags.system;
|
|
62
|
-
Object.assign(payload, chatExtras(flags), turn);
|
|
63
|
-
if (flags['oauth-only'])
|
|
64
|
-
payload.oauth_only = true;
|
|
65
|
-
if (cause)
|
|
66
|
-
payload.cause = cause;
|
|
67
|
-
try {
|
|
68
|
-
if (stream) {
|
|
69
|
-
let reasoning = '';
|
|
70
|
-
let replied = false;
|
|
71
|
-
for await (const line of client.stream('/v1/messages', payload)) {
|
|
72
|
-
if (!line.startsWith('data: '))
|
|
73
|
-
continue;
|
|
74
|
-
const chunk = line.slice(6);
|
|
75
|
-
if (chunk.trim() === '[DONE]' || chunk.trim() === '')
|
|
76
|
-
continue;
|
|
77
|
-
try {
|
|
78
|
-
const obj = JSON.parse(chunk);
|
|
79
|
-
const thought = extractStreamReasoning(obj);
|
|
80
|
-
if (thought) {
|
|
81
|
-
if (flags['show-cause'] && !reasoning)
|
|
82
|
-
process.stderr.write(`${reasoningHeading(model)}\n`);
|
|
83
|
-
if (flags['show-cause'])
|
|
84
|
-
process.stderr.write(thought);
|
|
85
|
-
reasoning += thought;
|
|
86
|
-
}
|
|
87
|
-
if (obj.type === 'content_block_delta') {
|
|
88
|
-
const delta = obj.delta?.text ?? '';
|
|
89
|
-
if (delta) {
|
|
90
|
-
if (flags['show-cause'] && reasoning && !replied)
|
|
91
|
-
process.stderr.write('\n\n');
|
|
92
|
-
replied = true;
|
|
93
|
-
process.stdout.write(String(delta));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (!replied && reasoning) {
|
|
101
|
-
if (flags['show-cause'])
|
|
102
|
-
process.stderr.write('\n');
|
|
103
|
-
else
|
|
104
|
-
process.stdout.write(`${reasoning}\n`);
|
|
105
|
-
process.stderr.write(`\n${reasoningOnlyNote(model, false)}\n`);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
process.stdout.write('\n');
|
|
109
|
-
}
|
|
110
|
-
return {};
|
|
111
|
-
}
|
|
112
|
-
const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/messages', payload), sayWarmUp);
|
|
113
|
-
const body = data;
|
|
114
|
-
if (this.jsonEnabled()) {
|
|
115
|
-
const meta = {};
|
|
116
|
-
if (headers['x-faces-provider'])
|
|
117
|
-
meta.provider = headers['x-faces-provider'];
|
|
118
|
-
if (headers['x-faces-cost-usd'])
|
|
119
|
-
meta.cost_usd = headers['x-faces-cost-usd'];
|
|
120
|
-
if (headers['x-faces-billing'])
|
|
121
|
-
meta.billing = headers['x-faces-billing'];
|
|
122
|
-
if (Object.keys(meta).length > 0)
|
|
123
|
-
body._meta = meta;
|
|
124
|
-
return body;
|
|
125
|
-
}
|
|
126
|
-
let content = '';
|
|
127
|
-
for (const block of body.content ?? []) {
|
|
128
|
-
if (block.type === 'text')
|
|
129
|
-
content += String(block.text ?? '');
|
|
130
|
-
}
|
|
131
|
-
writeReply(model, extractReasoning(body, '/v1/messages'), content, flags['show-cause'], reasoningOnlyNote(model, false));
|
|
132
|
-
return body;
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
if (err instanceof FacesAPIError) {
|
|
136
|
-
if (err.errorCode === 'oauth_rejected') {
|
|
137
|
-
const hint = err.fallbackAvailable
|
|
138
|
-
? 'Run `faces account:preferences api_fallback true` to allow paid fallback.'
|
|
139
|
-
: 'Run `faces billing:topup` to add credits, then enable fallback with `faces account:preferences api_fallback true`.';
|
|
140
|
-
this.error(`OAuth failed: ${err.message}\n${hint}`);
|
|
141
|
-
}
|
|
142
|
-
const hint = faceRefusalHint(err, model, flags.style);
|
|
143
|
-
this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
|
|
144
|
-
}
|
|
145
|
-
throw err;
|
|
146
|
-
}
|
|
18
|
+
forcedEndpoint() {
|
|
19
|
+
return MESSAGES_ENDPOINT;
|
|
147
20
|
}
|
|
148
21
|
}
|