@faces-sh/cli 1.0.3 → 1.1.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 +71 -51
- package/dist/choices.d.ts +23 -0
- package/dist/choices.js +48 -0
- package/dist/commands/auth/connect.js +2 -2
- package/dist/commands/catalog/doctor.js +9 -68
- package/dist/commands/causes.d.ts +2 -0
- package/dist/commands/causes.js +2 -2
- package/dist/commands/{fidelity/run.d.ts → choices.d.ts} +9 -8
- package/dist/commands/choices.js +86 -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 +9 -9
- package/dist/commands/conversation/create.d.ts +2 -0
- package/dist/commands/conversation/create.js +14 -12
- package/dist/commands/conversation/get.js +4 -4
- package/dist/commands/conversation/items.js +5 -5
- package/dist/commands/decide.d.ts +3 -0
- package/dist/commands/decide.js +20 -3
- package/dist/commands/face/get.js +1 -1
- package/dist/commands/fidelity/pick.js +2 -2
- package/dist/commands/models/list.js +7 -3
- package/dist/commands/session/close.js +1 -1
- package/dist/commands/session/compact.js +2 -2
- package/dist/commands/session/create.js +2 -2
- 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/conversation.d.ts +27 -2
- package/dist/conversation.js +91 -16
- package/dist/fidelity.js +3 -3
- package/oclif.manifest.json +1794 -2187
- package/package.json +9 -9
- package/dist/commands/chat/chat.d.ts +0 -47
- package/dist/commands/chat/chat.js +0 -376
- package/dist/commands/chat/messages.d.ts +0 -30
- package/dist/commands/chat/messages.js +0 -148
- package/dist/commands/chat/responses.d.ts +0 -31
- package/dist/commands/chat/responses.js +0 -159
- package/dist/commands/chat/thread.d.ts +0 -50
- package/dist/commands/chat/thread.js +0 -472
- package/dist/commands/fidelity/run.js +0 -99
- package/dist/commands/fidelity/start.d.ts +0 -17
- package/dist/commands/fidelity/start.js +0 -56
- package/dist/commands/fidelity/turn.d.ts +0 -17
- package/dist/commands/fidelity/turn.js +0 -48
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faces-sh/cli",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "CLI for Faces: compile causal models from source texts, and
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "CLI for Faces: compile causal models from source texts, and ask them what they would do",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Headwaters Lab Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -51,9 +51,6 @@
|
|
|
51
51
|
"face": {
|
|
52
52
|
"description": "Create and manage faces"
|
|
53
53
|
},
|
|
54
|
-
"chat": {
|
|
55
|
-
"description": "Chat with a face on any supported model"
|
|
56
|
-
},
|
|
57
54
|
"compile": {
|
|
58
55
|
"description": "Compile source texts into a face"
|
|
59
56
|
},
|
|
@@ -73,7 +70,7 @@
|
|
|
73
70
|
"description": "Local CLI configuration"
|
|
74
71
|
},
|
|
75
72
|
"style": {
|
|
76
|
-
"description": "Build and manage
|
|
73
|
+
"description": "Build and manage a face's styles"
|
|
77
74
|
},
|
|
78
75
|
"compile:doc": {
|
|
79
76
|
"description": "Documents: create, compile, edit, pause, reset and delete"
|
|
@@ -103,16 +100,19 @@
|
|
|
103
100
|
"description": "Your plan: show, subscribe, switch and cancel"
|
|
104
101
|
},
|
|
105
102
|
"fidelity": {
|
|
106
|
-
"description": "Fidelity runs
|
|
103
|
+
"description": "Fidelity runs made before chat was retired: read, pick and save"
|
|
107
104
|
},
|
|
108
105
|
"benchmark": {
|
|
109
106
|
"description": "Compare a face against a reference model on its own material"
|
|
110
107
|
},
|
|
108
|
+
"state": {
|
|
109
|
+
"description": "States: the situation your agent builds, kept on the server, with premises, their status and what they depend on"
|
|
110
|
+
},
|
|
111
111
|
"conversation": {
|
|
112
|
-
"description": "
|
|
112
|
+
"description": "The old name for state"
|
|
113
113
|
},
|
|
114
114
|
"session": {
|
|
115
|
-
"description": "
|
|
115
|
+
"description": "An older name for state"
|
|
116
116
|
},
|
|
117
117
|
"models": {
|
|
118
118
|
"description": "The models you can name, with their prices"
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '../../base.js';
|
|
2
|
-
export default class ChatChat extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
-
compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
-
'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
-
'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
-
cause: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
-
'cause-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
-
'cause-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
-
conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
-
premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
-
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
-
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
-
message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
-
llm: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
-
formula: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
-
system: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
-
stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
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>;
|
|
24
|
-
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
25
|
-
responses: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
26
|
-
style: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
27
|
-
medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
28
|
-
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
29
|
-
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
|
-
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
|
-
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
32
|
-
};
|
|
33
|
-
static args: {
|
|
34
|
-
face_username: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
35
|
-
};
|
|
36
|
-
run(): Promise<unknown>;
|
|
37
|
-
private oauthHint;
|
|
38
|
-
private metaFor;
|
|
39
|
-
private streamDeltas;
|
|
40
|
-
private printReply;
|
|
41
|
-
private noteReasoningOnly;
|
|
42
|
-
private reasoningOnly;
|
|
43
|
-
private conversationBody;
|
|
44
|
-
private runChatCompletions;
|
|
45
|
-
private runMessages;
|
|
46
|
-
private runResponses;
|
|
47
|
-
}
|
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { BaseCommand } from '../../base.js';
|
|
4
|
-
import { chatgptLinked } from '../../style.js';
|
|
5
|
-
import { FacesAPIError } from '../../client.js';
|
|
6
|
-
import { postChat, writeReply, streamChat, resolveCause, CAUSE_FLAG_DESCRIPTION, CAUSE_FILE_FLAG_DESCRIPTION, retryOnceOnWarmUp, sayWarmUp, faceRefusalHint, STREAM_FLAG_DESCRIPTION, extractReasoning, extractStreamDelta, extractStreamReasoning, reasoningHeading, reasoningOnlyNote, REASONING_FLAG_DESCRIPTION, isMaxTokensRenameError, MIN_MAX_OUTPUT_TOKENS, STYLE_FLAG_DESCRIPTION, MEDIUM_FLAG_DESCRIPTION, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION, chatExtras, warnDroppedParams, CHAT_PARAM_FLAGS, parseTemperature } from '../../utils.js';
|
|
7
|
-
import { conversationFields, conversationTurnFlags } from '../../conversation.js';
|
|
8
|
-
import { resolveEndpoint, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT, isCompositeFormula, faceSpecOf, llmFromArg } from '../../routing.js';
|
|
9
|
-
export default class ChatChat extends BaseCommand {
|
|
10
|
-
static description = 'Chat with a face on any supported model. The face\'s cause steers the model\'s answer. Routes to the ' +
|
|
11
|
-
'right endpoint from the model catalog. A face named without a model answers on its default model. ' +
|
|
12
|
-
'--show-cause also prints the cause, and --cause-only asks for the cause alone, with no answer. ' +
|
|
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.';
|
|
15
|
-
static examples = [
|
|
16
|
-
'<%= config.bin %> <%= command.id %> socrates -m "What is virtue?"',
|
|
17
|
-
'<%= config.bin %> <%= command.id %> alice -m "Reply to the note below." --style email',
|
|
18
|
-
'<%= config.bin %> <%= command.id %> socrates -m "Should I sign a grant I have not read?" --show-cause',
|
|
19
|
-
'<%= config.bin %> <%= command.id %> socrates -m "Should I sign a grant I have not read?" --cause-only',
|
|
20
|
-
'<%= config.bin %> <%= command.id %> socrates -m "Can you just sign it?" --cause "I will not sign what I have not read."',
|
|
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 ' +
|
|
23
|
-
'--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
|
-
];
|
|
27
|
-
static flags = {
|
|
28
|
-
...BaseCommand.baseFlags,
|
|
29
|
-
message: Flags.string({ char: 'm', description: 'User message (repeatable)', multiple: true, required: false }),
|
|
30
|
-
llm: Flags.string({ description: 'LLM override (e.g. gpt-4o-mini, claude-sonnet-4-6)' }),
|
|
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
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
async run() {
|
|
62
|
-
const { args, flags } = await this.parse(ChatChat);
|
|
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;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '../../base.js';
|
|
2
|
-
export default class ChatMessages extends BaseCommand {
|
|
3
|
-
static description: string;
|
|
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
|
-
'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
|
-
conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
-
premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
-
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
-
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
-
message: import("@oclif/core/interfaces").OptionFlag<string[], 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, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
-
style: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
-
medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
-
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
|
-
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
-
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
|
-
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
25
|
-
};
|
|
26
|
-
static args: {
|
|
27
|
-
face_model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
28
|
-
};
|
|
29
|
-
run(): Promise<unknown>;
|
|
30
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { Args, Flags } from '@oclif/core';
|
|
2
|
-
import { BaseCommand } from '../../base.js';
|
|
3
|
-
import { postChat, writeReply, resolveCause, causeNeedsModel, CAUSE_FLAG_DESCRIPTION, CAUSE_FILE_FLAG_DESCRIPTION, retryOnceOnWarmUp, sayWarmUp, faceRefusalHint, STREAM_FLAG_DESCRIPTION, extractReasoning, extractStreamReasoning, STYLE_FLAG_DESCRIPTION, MEDIUM_FLAG_DESCRIPTION, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION, chatExtras, reasoningHeading, reasoningOnlyNote, REASONING_FLAG_DESCRIPTION } from '../../utils.js';
|
|
4
|
-
import { FacesAPIError } from '../../client.js';
|
|
5
|
-
import { conversationFields, conversationTurnFlags } from '../../conversation.js';
|
|
6
|
-
export default class ChatMessages extends BaseCommand {
|
|
7
|
-
static description = 'Chat with a face in the Anthropic Messages format (/v1/messages). chat:chat routes Anthropic models here on its own.';
|
|
8
|
-
static flags = {
|
|
9
|
-
...BaseCommand.baseFlags,
|
|
10
|
-
message: Flags.string({ char: 'm', description: 'User message (repeatable)', multiple: true, required: true }),
|
|
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
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
async run() {
|
|
33
|
-
const { args, flags } = await this.parse(ChatMessages);
|
|
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
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|