@faces-sh/cli 0.0.0-stage → 1.0.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.
Files changed (290) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/bin/dev.js +5 -0
  4. package/bin/run.js +5 -0
  5. package/dist/base.d.ts +26 -0
  6. package/dist/base.js +181 -0
  7. package/dist/benchmark.d.ts +21 -0
  8. package/dist/benchmark.js +95 -0
  9. package/dist/billing.d.ts +17 -0
  10. package/dist/billing.js +101 -0
  11. package/dist/catalog.d.ts +35 -0
  12. package/dist/catalog.js +242 -0
  13. package/dist/client.d.ts +98 -0
  14. package/dist/client.js +590 -0
  15. package/dist/commands/account/preferences.d.ts +20 -0
  16. package/dist/commands/account/preferences.js +190 -0
  17. package/dist/commands/account/state.d.ts +11 -0
  18. package/dist/commands/account/state.js +24 -0
  19. package/dist/commands/auth/connect.d.ts +17 -0
  20. package/dist/commands/auth/connect.js +190 -0
  21. package/dist/commands/auth/connections.d.ts +12 -0
  22. package/dist/commands/auth/connections.js +40 -0
  23. package/dist/commands/auth/disconnect.d.ts +15 -0
  24. package/dist/commands/auth/disconnect.js +49 -0
  25. package/dist/commands/auth/login.d.ts +13 -0
  26. package/dist/commands/auth/login.js +42 -0
  27. package/dist/commands/auth/logout.d.ts +11 -0
  28. package/dist/commands/auth/logout.js +14 -0
  29. package/dist/commands/auth/refresh.d.ts +11 -0
  30. package/dist/commands/auth/refresh.js +30 -0
  31. package/dist/commands/auth/register.d.ts +15 -0
  32. package/dist/commands/auth/register.js +98 -0
  33. package/dist/commands/auth/whoami.d.ts +11 -0
  34. package/dist/commands/auth/whoami.js +108 -0
  35. package/dist/commands/benchmark/get.d.ts +16 -0
  36. package/dist/commands/benchmark/get.js +42 -0
  37. package/dist/commands/benchmark/list.d.ts +13 -0
  38. package/dist/commands/benchmark/list.js +47 -0
  39. package/dist/commands/benchmark/start.d.ts +22 -0
  40. package/dist/commands/benchmark/start.js +80 -0
  41. package/dist/commands/billing/balance.d.ts +11 -0
  42. package/dist/commands/billing/balance.js +27 -0
  43. package/dist/commands/billing/card/default.d.ts +15 -0
  44. package/dist/commands/billing/card/default.js +33 -0
  45. package/dist/commands/billing/card/remove.d.ts +16 -0
  46. package/dist/commands/billing/card/remove.js +41 -0
  47. package/dist/commands/billing/card-setup.d.ts +13 -0
  48. package/dist/commands/billing/card-setup.js +41 -0
  49. package/dist/commands/billing/cards.d.ts +11 -0
  50. package/dist/commands/billing/cards.js +34 -0
  51. package/dist/commands/billing/llm-costs.d.ts +14 -0
  52. package/dist/commands/billing/llm-costs.js +95 -0
  53. package/dist/commands/billing/subscription/activate.d.ts +14 -0
  54. package/dist/commands/billing/subscription/activate.js +91 -0
  55. package/dist/commands/billing/subscription/cancel.d.ts +12 -0
  56. package/dist/commands/billing/subscription/cancel.js +54 -0
  57. package/dist/commands/billing/subscription/index.d.ts +11 -0
  58. package/dist/commands/billing/subscription/index.js +46 -0
  59. package/dist/commands/billing/subscription/plan.d.ts +16 -0
  60. package/dist/commands/billing/subscription/plan.js +86 -0
  61. package/dist/commands/billing/topup.d.ts +16 -0
  62. package/dist/commands/billing/topup.js +60 -0
  63. package/dist/commands/billing/usage.d.ts +15 -0
  64. package/dist/commands/billing/usage.js +68 -0
  65. package/dist/commands/catalog/backup.d.ts +11 -0
  66. package/dist/commands/catalog/backup.js +169 -0
  67. package/dist/commands/catalog/doctor.d.ts +14 -0
  68. package/dist/commands/catalog/doctor.js +303 -0
  69. package/dist/commands/catalog/list.d.ts +11 -0
  70. package/dist/commands/catalog/list.js +39 -0
  71. package/dist/commands/catalog/restore.d.ts +17 -0
  72. package/dist/commands/catalog/restore.js +259 -0
  73. package/dist/commands/causes.d.ts +27 -0
  74. package/dist/commands/causes.js +135 -0
  75. package/dist/commands/chat/chat.d.ts +42 -0
  76. package/dist/commands/chat/chat.js +363 -0
  77. package/dist/commands/chat/messages.d.ts +26 -0
  78. package/dist/commands/chat/messages.js +139 -0
  79. package/dist/commands/chat/responses.d.ts +27 -0
  80. package/dist/commands/chat/responses.js +150 -0
  81. package/dist/commands/chat/thread.d.ts +43 -0
  82. package/dist/commands/chat/thread.js +458 -0
  83. package/dist/commands/compile/all.d.ts +14 -0
  84. package/dist/commands/compile/all.js +186 -0
  85. package/dist/commands/compile/doc/create.d.ts +19 -0
  86. package/dist/commands/compile/doc/create.js +58 -0
  87. package/dist/commands/compile/doc/delete.d.ts +15 -0
  88. package/dist/commands/compile/doc/delete.js +33 -0
  89. package/dist/commands/compile/doc/edit.d.ts +19 -0
  90. package/dist/commands/compile/doc/edit.js +59 -0
  91. package/dist/commands/compile/doc/get.d.ts +15 -0
  92. package/dist/commands/compile/doc/get.js +43 -0
  93. package/dist/commands/compile/doc/index.d.ts +24 -0
  94. package/dist/commands/compile/doc/index.js +211 -0
  95. package/dist/commands/compile/doc/list.d.ts +15 -0
  96. package/dist/commands/compile/doc/list.js +46 -0
  97. package/dist/commands/compile/doc/make.d.ts +17 -0
  98. package/dist/commands/compile/doc/make.js +95 -0
  99. package/dist/commands/compile/doc/pause.d.ts +17 -0
  100. package/dist/commands/compile/doc/pause.js +74 -0
  101. package/dist/commands/compile/doc/reset.d.ts +15 -0
  102. package/dist/commands/compile/doc/reset.js +33 -0
  103. package/dist/commands/compile/import.d.ts +20 -0
  104. package/dist/commands/compile/import.js +138 -0
  105. package/dist/commands/compile/stats.d.ts +11 -0
  106. package/dist/commands/compile/stats.js +75 -0
  107. package/dist/commands/compile/status.d.ts +17 -0
  108. package/dist/commands/compile/status.js +110 -0
  109. package/dist/commands/compile/thread/create.d.ts +16 -0
  110. package/dist/commands/compile/thread/create.js +42 -0
  111. package/dist/commands/compile/thread/delete.d.ts +15 -0
  112. package/dist/commands/compile/thread/delete.js +33 -0
  113. package/dist/commands/compile/thread/edit.d.ts +19 -0
  114. package/dist/commands/compile/thread/edit.js +120 -0
  115. package/dist/commands/compile/thread/get.d.ts +15 -0
  116. package/dist/commands/compile/thread/get.js +48 -0
  117. package/dist/commands/compile/thread/list.d.ts +14 -0
  118. package/dist/commands/compile/thread/list.js +38 -0
  119. package/dist/commands/compile/thread/make.d.ts +17 -0
  120. package/dist/commands/compile/thread/make.js +87 -0
  121. package/dist/commands/compile/thread/message.d.ts +16 -0
  122. package/dist/commands/compile/thread/message.js +43 -0
  123. package/dist/commands/compile/thread/pause.d.ts +17 -0
  124. package/dist/commands/compile/thread/pause.js +75 -0
  125. package/dist/commands/compile/thread/replace.d.ts +27 -0
  126. package/dist/commands/compile/thread/replace.js +114 -0
  127. package/dist/commands/compile/thread/reset.d.ts +15 -0
  128. package/dist/commands/compile/thread/reset.js +33 -0
  129. package/dist/commands/compile/upload.d.ts +21 -0
  130. package/dist/commands/compile/upload.js +162 -0
  131. package/dist/commands/config/clear.d.ts +12 -0
  132. package/dist/commands/config/clear.js +17 -0
  133. package/dist/commands/config/set.d.ts +15 -0
  134. package/dist/commands/config/set.js +43 -0
  135. package/dist/commands/config/show.d.ts +11 -0
  136. package/dist/commands/config/show.js +19 -0
  137. package/dist/commands/decide.d.ts +35 -0
  138. package/dist/commands/decide.js +242 -0
  139. package/dist/commands/face/attributes.d.ts +11 -0
  140. package/dist/commands/face/attributes.js +44 -0
  141. package/dist/commands/face/avatar/delete.d.ts +15 -0
  142. package/dist/commands/face/avatar/delete.js +38 -0
  143. package/dist/commands/face/avatar/get.d.ts +20 -0
  144. package/dist/commands/face/avatar/get.js +100 -0
  145. package/dist/commands/face/avatar/list.d.ts +14 -0
  146. package/dist/commands/face/avatar/list.js +56 -0
  147. package/dist/commands/face/avatar/make.d.ts +16 -0
  148. package/dist/commands/face/avatar/make.js +64 -0
  149. package/dist/commands/face/avatar/upload.d.ts +15 -0
  150. package/dist/commands/face/avatar/upload.js +67 -0
  151. package/dist/commands/face/create.d.ts +23 -0
  152. package/dist/commands/face/create.js +122 -0
  153. package/dist/commands/face/delete.d.ts +15 -0
  154. package/dist/commands/face/delete.js +39 -0
  155. package/dist/commands/face/diff.d.ts +12 -0
  156. package/dist/commands/face/diff.js +50 -0
  157. package/dist/commands/face/edit.d.ts +25 -0
  158. package/dist/commands/face/edit.js +155 -0
  159. package/dist/commands/face/get.d.ts +16 -0
  160. package/dist/commands/face/get.js +145 -0
  161. package/dist/commands/face/groups.d.ts +15 -0
  162. package/dist/commands/face/groups.js +34 -0
  163. package/dist/commands/face/list.d.ts +23 -0
  164. package/dist/commands/face/list.js +168 -0
  165. package/dist/commands/face/lock.d.ts +15 -0
  166. package/dist/commands/face/lock.js +35 -0
  167. package/dist/commands/face/neighbors.d.ts +16 -0
  168. package/dist/commands/face/neighbors.js +63 -0
  169. package/dist/commands/face/publish.d.ts +16 -0
  170. package/dist/commands/face/publish.js +42 -0
  171. package/dist/commands/face/share.d.ts +22 -0
  172. package/dist/commands/face/share.js +103 -0
  173. package/dist/commands/face/sources.d.ts +21 -0
  174. package/dist/commands/face/sources.js +169 -0
  175. package/dist/commands/face/stats.d.ts +12 -0
  176. package/dist/commands/face/stats.js +46 -0
  177. package/dist/commands/face/tag/add.d.ts +15 -0
  178. package/dist/commands/face/tag/add.js +40 -0
  179. package/dist/commands/face/tag/all.d.ts +11 -0
  180. package/dist/commands/face/tag/all.js +31 -0
  181. package/dist/commands/face/tag/list.d.ts +14 -0
  182. package/dist/commands/face/tag/list.js +36 -0
  183. package/dist/commands/face/tag/remove.d.ts +16 -0
  184. package/dist/commands/face/tag/remove.js +44 -0
  185. package/dist/commands/face/tag/set.d.ts +15 -0
  186. package/dist/commands/face/tag/set.js +40 -0
  187. package/dist/commands/face/unlock.d.ts +15 -0
  188. package/dist/commands/face/unlock.js +35 -0
  189. package/dist/commands/face/unpublish.d.ts +14 -0
  190. package/dist/commands/face/unpublish.js +31 -0
  191. package/dist/commands/face/unshare.d.ts +18 -0
  192. package/dist/commands/face/unshare.js +66 -0
  193. package/dist/commands/fidelity/get.d.ts +15 -0
  194. package/dist/commands/fidelity/get.js +42 -0
  195. package/dist/commands/fidelity/pick.d.ts +19 -0
  196. package/dist/commands/fidelity/pick.js +70 -0
  197. package/dist/commands/fidelity/run.d.ts +20 -0
  198. package/dist/commands/fidelity/run.js +99 -0
  199. package/dist/commands/fidelity/save-thread.d.ts +15 -0
  200. package/dist/commands/fidelity/save-thread.js +35 -0
  201. package/dist/commands/fidelity/start.d.ts +17 -0
  202. package/dist/commands/fidelity/start.js +56 -0
  203. package/dist/commands/fidelity/turn.d.ts +17 -0
  204. package/dist/commands/fidelity/turn.js +48 -0
  205. package/dist/commands/group/add.d.ts +16 -0
  206. package/dist/commands/group/add.js +83 -0
  207. package/dist/commands/group/create.d.ts +16 -0
  208. package/dist/commands/group/create.js +68 -0
  209. package/dist/commands/group/delete.d.ts +15 -0
  210. package/dist/commands/group/delete.js +39 -0
  211. package/dist/commands/group/edit.d.ts +18 -0
  212. package/dist/commands/group/edit.js +75 -0
  213. package/dist/commands/group/get.d.ts +14 -0
  214. package/dist/commands/group/get.js +29 -0
  215. package/dist/commands/group/list.d.ts +11 -0
  216. package/dist/commands/group/list.js +39 -0
  217. package/dist/commands/group/members.d.ts +15 -0
  218. package/dist/commands/group/members.js +68 -0
  219. package/dist/commands/group/remove.d.ts +15 -0
  220. package/dist/commands/group/remove.js +55 -0
  221. package/dist/commands/group/tag/add.d.ts +15 -0
  222. package/dist/commands/group/tag/add.js +30 -0
  223. package/dist/commands/group/tag/list.d.ts +14 -0
  224. package/dist/commands/group/tag/list.js +36 -0
  225. package/dist/commands/group/tag/remove.d.ts +15 -0
  226. package/dist/commands/group/tag/remove.js +30 -0
  227. package/dist/commands/group/tag/set.d.ts +15 -0
  228. package/dist/commands/group/tag/set.js +30 -0
  229. package/dist/commands/keys/create.d.ts +17 -0
  230. package/dist/commands/keys/create.js +72 -0
  231. package/dist/commands/keys/list.d.ts +11 -0
  232. package/dist/commands/keys/list.js +24 -0
  233. package/dist/commands/keys/revoke.d.ts +15 -0
  234. package/dist/commands/keys/revoke.js +49 -0
  235. package/dist/commands/keys/update.d.ts +17 -0
  236. package/dist/commands/keys/update.js +41 -0
  237. package/dist/commands/models/list.d.ts +15 -0
  238. package/dist/commands/models/list.js +98 -0
  239. package/dist/commands/session/close.d.ts +16 -0
  240. package/dist/commands/session/close.js +36 -0
  241. package/dist/commands/session/compact.d.ts +15 -0
  242. package/dist/commands/session/compact.js +58 -0
  243. package/dist/commands/session/create.d.ts +15 -0
  244. package/dist/commands/session/create.js +45 -0
  245. package/dist/commands/session/get.d.ts +15 -0
  246. package/dist/commands/session/get.js +34 -0
  247. package/dist/commands/style/delete.d.ts +19 -0
  248. package/dist/commands/style/delete.js +92 -0
  249. package/dist/commands/style/make.d.ts +28 -0
  250. package/dist/commands/style/make.js +298 -0
  251. package/dist/commands/style/revert.d.ts +17 -0
  252. package/dist/commands/style/revert.js +66 -0
  253. package/dist/commands/style/status.d.ts +20 -0
  254. package/dist/commands/style/status.js +109 -0
  255. package/dist/commands/style/upload.d.ts +19 -0
  256. package/dist/commands/style/upload.js +100 -0
  257. package/dist/commands/style/versions.d.ts +15 -0
  258. package/dist/commands/style/versions.js +104 -0
  259. package/dist/commands/user/follow.d.ts +14 -0
  260. package/dist/commands/user/follow.js +38 -0
  261. package/dist/commands/user/followers.d.ts +14 -0
  262. package/dist/commands/user/followers.js +50 -0
  263. package/dist/commands/user/following.d.ts +14 -0
  264. package/dist/commands/user/following.js +50 -0
  265. package/dist/commands/user/get.d.ts +14 -0
  266. package/dist/commands/user/get.js +49 -0
  267. package/dist/commands/user/unfollow.d.ts +14 -0
  268. package/dist/commands/user/unfollow.js +38 -0
  269. package/dist/config.d.ts +32 -0
  270. package/dist/config.js +139 -0
  271. package/dist/decisions.d.ts +42 -0
  272. package/dist/decisions.js +262 -0
  273. package/dist/fidelity.d.ts +50 -0
  274. package/dist/fidelity.js +92 -0
  275. package/dist/group-catalog.d.ts +22 -0
  276. package/dist/group-catalog.js +133 -0
  277. package/dist/paths.d.ts +1 -0
  278. package/dist/paths.js +8 -0
  279. package/dist/poll.d.ts +26 -0
  280. package/dist/poll.js +75 -0
  281. package/dist/routing.d.ts +15 -0
  282. package/dist/routing.js +135 -0
  283. package/dist/session.d.ts +14 -0
  284. package/dist/session.js +18 -0
  285. package/dist/style.d.ts +46 -0
  286. package/dist/style.js +285 -0
  287. package/dist/utils.d.ts +149 -0
  288. package/dist/utils.js +865 -0
  289. package/oclif.manifest.json +11070 -0
  290. package/package.json +127 -4
@@ -0,0 +1,363 @@
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 { resolveEndpoint, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT, isCompositeFormula, faceSpecOf, llmFromArg } from '../../routing.js';
8
+ export default class ChatChat extends BaseCommand {
9
+ static description = 'Chat with a face on any supported model. The face\'s cause steers the model\'s answer. Routes to the ' +
10
+ 'right endpoint from the model catalog. A face named without a model answers on its default model. ' +
11
+ '--show-cause also prints the cause, and --cause-only asks for the cause alone, with no answer. ' +
12
+ 'Add --style <medium> to apply a style the face has built, and --session or --compaction to use a ' +
13
+ 'session (see faces session:create).';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> socrates -m "What is virtue?"',
16
+ '<%= config.bin %> <%= command.id %> alice -m "Reply to the note below." --style email',
17
+ '<%= config.bin %> <%= command.id %> socrates -m "Should I sign a grant I have not read?" --show-cause',
18
+ '<%= config.bin %> <%= command.id %> socrates -m "Should I sign a grant I have not read?" --cause-only',
19
+ '<%= config.bin %> <%= command.id %> socrates -m "Can you just sign it?" --cause "I will not sign what I have not read."',
20
+ '<%= config.bin %> <%= command.id %> alice -m "So what do I tell them tomorrow?" --session fs_SESSION_ID',
21
+ '<%= config.bin %> <%= command.id %> "(socrates | nietzsche)@claude-sonnet-4-6" -m "What is virtue?"',
22
+ '<%= config.bin %> <%= command.id %> --formula "socrates | nietzsche" --llm claude-sonnet-4-6 -m "What is virtue?"',
23
+ ];
24
+ static flags = {
25
+ ...BaseCommand.baseFlags,
26
+ message: Flags.string({ char: 'm', description: 'User message (repeatable)', multiple: true, required: false }),
27
+ llm: Flags.string({ description: 'LLM override (e.g. gpt-4o-mini, claude-sonnet-4-6)' }),
28
+ 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.' }),
29
+ system: Flags.string({ description: 'System prompt / instructions' }),
30
+ stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
31
+ 'max-tokens': Flags.integer({ description: 'Max tokens (at least 1)', min: 1 }),
32
+ temperature: Flags.string({ description: 'Temperature (0.0-2.0)' }),
33
+ file: Flags.string({ description: 'Read message from file' }),
34
+ responses: Flags.boolean({ description: 'Force the OpenAI Responses API endpoint (escape hatch; routing is automatic otherwise)', default: false }),
35
+ style: Flags.string({ description: STYLE_FLAG_DESCRIPTION }),
36
+ medium: Flags.string({ description: MEDIUM_FLAG_DESCRIPTION }),
37
+ session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
38
+ compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
39
+ 'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
40
+ 'show-cause': Flags.boolean({ description: REASONING_FLAG_DESCRIPTION, default: false }),
41
+ cause: Flags.string({ description: CAUSE_FLAG_DESCRIPTION }),
42
+ 'cause-file': Flags.string({ description: CAUSE_FILE_FLAG_DESCRIPTION, exclusive: ['cause'] }),
43
+ 'cause-only': Flags.boolean({
44
+ description: 'Ask for the face\'s cause alone, with no answer: no model is called, and only the cause is ' +
45
+ 'charged. Printed to stdout.',
46
+ default: false,
47
+ exclusive: ['llm', 'style', 'medium', 'show-cause', 'cause', 'cause-file'],
48
+ }),
49
+ };
50
+ static args = {
51
+ face_username: Args.string({
52
+ description: 'Face alias (alias@model, owner:alias@model for a published face, or a composite formula like ' +
53
+ '"(a | b)@model"). Omit when using --formula.',
54
+ required: false,
55
+ }),
56
+ };
57
+ async run() {
58
+ const { args, flags } = await this.parse(ChatChat);
59
+ const client = this.makeClient(flags);
60
+ let model;
61
+ if (flags.formula) {
62
+ if (args.face_username)
63
+ this.error('Pass either a face argument or --formula, not both.');
64
+ if (!flags.llm && !flags['cause-only'])
65
+ this.error('--formula needs a model. Add --llm <model>, e.g. --llm claude-sonnet-4-6.');
66
+ model = flags.llm ? `(${flags.formula.trim()})@${flags.llm}` : `(${flags.formula.trim()})`;
67
+ }
68
+ else if (!args.face_username) {
69
+ this.error('Provide a face (alias, owner:alias, or a composite formula), or use --formula.');
70
+ }
71
+ else if (flags.llm) {
72
+ const base = faceSpecOf(args.face_username);
73
+ model = `${base}@${flags.llm}`;
74
+ }
75
+ else {
76
+ model = args.face_username;
77
+ }
78
+ if (isCompositeFormula(model) && !llmFromArg(model) && !flags['cause-only']) {
79
+ const spec = faceSpecOf(model);
80
+ this.error(`Composite face '${spec}' has no default model. Specify one explicitly, ` +
81
+ `e.g. '${spec}@claude-sonnet-4-6', or pass --llm <model>.`);
82
+ }
83
+ if (flags.style && isCompositeFormula(model)) {
84
+ this.error('--style applies to one face, not a combination of faces.');
85
+ }
86
+ const userMessages = [];
87
+ if (flags.file) {
88
+ if (!fs.existsSync(flags.file))
89
+ this.error(`File not found: ${flags.file}`);
90
+ userMessages.push(fs.readFileSync(flags.file, 'utf8'));
91
+ }
92
+ else if (flags.message && flags.message.length > 0) {
93
+ userMessages.push(...flags.message);
94
+ }
95
+ else {
96
+ this.error('Provide at least one --message/-m or --file');
97
+ }
98
+ if (flags['cause-only'] && llmFromArg(model)) {
99
+ this.error(`--cause-only asks the face alone, so leave the model off: ${faceSpecOf(model)}`);
100
+ }
101
+ const route = await resolveEndpoint(client, model);
102
+ const endpoint = flags.responses ? RESPONSES_ENDPOINT : route.endpoint;
103
+ if (!flags['cause-only'] && !llmFromArg(model)) {
104
+ if (!route.llm) {
105
+ this.error(`${model} has no default model to answer on, so name one: ${model}@<model>, or add --llm <model>.\n` +
106
+ 'For the face\'s cause alone, with no answer, add --cause-only.');
107
+ }
108
+ model = `${model}@${route.llm}`;
109
+ }
110
+ let cause;
111
+ try {
112
+ cause = resolveCause(flags.cause, flags['cause-file']);
113
+ }
114
+ catch (err) {
115
+ this.error(err instanceof Error ? err.message : String(err));
116
+ }
117
+ const send = { ...flags, cause, stream: flags.stream && !this.jsonEnabled() };
118
+ this.reasoningOnly = flags['cause-only'];
119
+ try {
120
+ if (endpoint === MESSAGES_ENDPOINT) {
121
+ return await this.runMessages(client, model, userMessages, send);
122
+ }
123
+ else if (endpoint === RESPONSES_ENDPOINT) {
124
+ return await this.runResponses(client, model, userMessages, send);
125
+ }
126
+ else {
127
+ return await this.runChatCompletions(client, model, userMessages, send);
128
+ }
129
+ }
130
+ catch (err) {
131
+ if (err instanceof FacesAPIError) {
132
+ if (err.errorCode === 'oauth_rejected')
133
+ this.error(`OAuth failed: ${err.message}\n${await this.oauthHint(err, { ...route, endpoint }, client)}`);
134
+ if (err.errorCode === 'model_not_supported') {
135
+ this.error(`${err.message}\n` +
136
+ 'Your ChatGPT plan does not serve this model. Pick another with --llm, ' +
137
+ 'or let it run on credits: faces account:preferences api_fallback true');
138
+ }
139
+ const hint = faceRefusalHint(err, model, flags.style);
140
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
141
+ }
142
+ throw err;
143
+ }
144
+ }
145
+ async oauthHint(err, route, client) {
146
+ const hints = [];
147
+ const linked = await chatgptLinked(client);
148
+ if (linked === false)
149
+ hints.push('No ChatGPT account is linked. Link one with: faces auth:connect openai');
150
+ else
151
+ hints.push('If the ChatGPT link has lapsed, link it again with: faces auth:connect openai');
152
+ if (route.endpoint === RESPONSES_ENDPOINT && route.freeWhenConnected && linked === false) {
153
+ hints.push('This model is free once it is linked.');
154
+ }
155
+ if (err.fallbackAvailable) {
156
+ hints.push('Or allow paid fallback: faces account:preferences api_fallback true');
157
+ }
158
+ else {
159
+ let balance;
160
+ try {
161
+ balance = Number((await client.get('/v1/billing/balance')).balance_usd);
162
+ }
163
+ catch { }
164
+ hints.push(balance !== undefined && balance > 0
165
+ ? 'Or allow paid fallback on your credits: faces account:preferences api_fallback true'
166
+ : 'Or add credits (faces billing:topup --amount <usd>) and allow paid fallback: faces account:preferences api_fallback true');
167
+ }
168
+ return hints.join('\n');
169
+ }
170
+ metaFor(headers, endpoint, model) {
171
+ const meta = {};
172
+ if (headers['x-faces-provider'])
173
+ meta.provider = headers['x-faces-provider'];
174
+ if (headers['x-faces-cost-usd'])
175
+ meta.cost_usd = headers['x-faces-cost-usd'];
176
+ if (headers['x-faces-billing'])
177
+ meta.billing = headers['x-faces-billing'];
178
+ meta.endpoint = endpoint;
179
+ meta.model = model;
180
+ return meta;
181
+ }
182
+ async streamDeltas(client, endpoint, payload, showReasoning) {
183
+ const model = String(payload.model);
184
+ let reasoning = '';
185
+ let replied = false;
186
+ const onHeaders = (headers) => warnDroppedParams(headers, CHAT_PARAM_FLAGS);
187
+ for await (const line of streamChat(client, endpoint, payload, onHeaders)) {
188
+ if (!line.startsWith('data: '))
189
+ continue;
190
+ const chunk = line.slice(6);
191
+ if (chunk.trim() === '[DONE]' || chunk.trim() === '')
192
+ continue;
193
+ try {
194
+ const parsed = JSON.parse(chunk);
195
+ const thought = extractStreamReasoning(parsed);
196
+ if (thought) {
197
+ if (showReasoning && !reasoning)
198
+ process.stderr.write(`${reasoningHeading(model)}\n`);
199
+ if (showReasoning)
200
+ process.stderr.write(thought);
201
+ reasoning += thought;
202
+ }
203
+ const delta = extractStreamDelta(parsed);
204
+ if (delta) {
205
+ if (showReasoning && reasoning && !replied)
206
+ process.stderr.write('\n\n');
207
+ replied = true;
208
+ process.stdout.write(delta);
209
+ }
210
+ }
211
+ catch { }
212
+ }
213
+ if (!replied && reasoning) {
214
+ if (showReasoning)
215
+ process.stderr.write('\n');
216
+ else
217
+ process.stdout.write(`${reasoning}\n`);
218
+ this.noteReasoningOnly(model);
219
+ }
220
+ else if (!replied) {
221
+ this.error('The reply stream ended with no answer and no cause. Run it again with --no-stream to see what the server said.');
222
+ }
223
+ else {
224
+ process.stdout.write('\n');
225
+ }
226
+ }
227
+ printReply(model, reasoning, text, showReasoning) {
228
+ writeReply(model, reasoning, text, showReasoning, this.reasoningOnly ? undefined : reasoningOnlyNote(model));
229
+ }
230
+ noteReasoningOnly(model) {
231
+ if (this.reasoningOnly)
232
+ return;
233
+ process.stderr.write(`\n${reasoningOnlyNote(model)}\n`);
234
+ }
235
+ reasoningOnly = false;
236
+ async runChatCompletions(client, model, userMessages, flags) {
237
+ const messages = [];
238
+ if (flags.system)
239
+ messages.push({ role: 'system', content: flags.system });
240
+ for (const m of userMessages)
241
+ messages.push({ role: 'user', content: m });
242
+ const payload = { model, messages, stream: flags.stream };
243
+ if (flags['max-tokens'])
244
+ payload.max_tokens = flags['max-tokens'];
245
+ if (flags.temperature !== undefined)
246
+ payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
247
+ Object.assign(payload, chatExtras(flags));
248
+ if (flags['oauth-only'])
249
+ payload.oauth_only = true;
250
+ if (flags.cause)
251
+ payload.cause = flags.cause;
252
+ if (flags.stream) {
253
+ await this.streamDeltas(client, '/v1/chat/completions', payload, flags['show-cause']);
254
+ return {};
255
+ }
256
+ let data;
257
+ let headers;
258
+ try {
259
+ ;
260
+ ({ data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/chat/completions', payload), sayWarmUp));
261
+ }
262
+ catch (err) {
263
+ if (err instanceof FacesAPIError && isMaxTokensRenameError(err.message) && payload.max_tokens !== undefined) {
264
+ payload.max_completion_tokens = payload.max_tokens;
265
+ delete payload.max_tokens;
266
+ ({ data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/chat/completions', payload), sayWarmUp));
267
+ }
268
+ else {
269
+ throw err;
270
+ }
271
+ }
272
+ if (!this.jsonEnabled())
273
+ warnDroppedParams(headers, CHAT_PARAM_FLAGS);
274
+ const body = data;
275
+ const choices = body.choices;
276
+ const text = String(choices?.[0]?.message?.content ?? '');
277
+ if (this.jsonEnabled()) {
278
+ body._meta = this.metaFor(headers, '/v1/chat/completions', model);
279
+ return body;
280
+ }
281
+ this.printReply(model, extractReasoning(body, '/v1/chat/completions'), text, flags['show-cause']);
282
+ return body;
283
+ }
284
+ async runMessages(client, model, userMessages, flags) {
285
+ const msgs = userMessages.map((m) => ({ role: 'user', content: m }));
286
+ const payload = {
287
+ model,
288
+ messages: msgs,
289
+ max_tokens: flags['max-tokens'] ?? 1024,
290
+ stream: flags.stream,
291
+ };
292
+ if (flags.system)
293
+ payload.system = flags.system;
294
+ Object.assign(payload, chatExtras(flags));
295
+ if (flags['oauth-only'])
296
+ payload.oauth_only = true;
297
+ if (flags.cause)
298
+ payload.cause = flags.cause;
299
+ if (flags.stream) {
300
+ await this.streamDeltas(client, '/v1/messages', payload, flags['show-cause']);
301
+ return {};
302
+ }
303
+ const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/messages', payload), sayWarmUp);
304
+ if (!this.jsonEnabled())
305
+ warnDroppedParams(headers, CHAT_PARAM_FLAGS);
306
+ const body = data;
307
+ if (this.jsonEnabled()) {
308
+ body._meta = this.metaFor(headers, '/v1/messages', model);
309
+ return body;
310
+ }
311
+ let content = '';
312
+ for (const block of body.content ?? []) {
313
+ if (block.type === 'text')
314
+ content += String(block.text ?? '');
315
+ }
316
+ this.printReply(model, extractReasoning(body, '/v1/messages'), content, flags['show-cause']);
317
+ return body;
318
+ }
319
+ async runResponses(client, model, userMessages, flags) {
320
+ const payload = {
321
+ model,
322
+ input: userMessages.map((m) => ({ role: 'user', content: m })),
323
+ stream: flags.stream,
324
+ };
325
+ if (flags.system)
326
+ payload.instructions = flags.system;
327
+ if (flags['max-tokens'] !== undefined) {
328
+ if (flags['max-tokens'] < MIN_MAX_OUTPUT_TOKENS) {
329
+ this.error(`--max-tokens must be at least ${MIN_MAX_OUTPUT_TOKENS} for this model (got ${flags['max-tokens']}). ` +
330
+ 'The Responses API rejects a smaller output cap.');
331
+ }
332
+ payload.max_output_tokens = flags['max-tokens'];
333
+ }
334
+ if (flags.temperature !== undefined)
335
+ payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
336
+ Object.assign(payload, chatExtras(flags));
337
+ if (flags['oauth-only'])
338
+ payload.oauth_only = true;
339
+ if (flags.cause)
340
+ payload.cause = flags.cause;
341
+ if (flags.stream) {
342
+ await this.streamDeltas(client, '/v1/responses', payload, flags['show-cause']);
343
+ return {};
344
+ }
345
+ const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/responses', payload), sayWarmUp);
346
+ if (!this.jsonEnabled())
347
+ warnDroppedParams(headers, CHAT_PARAM_FLAGS);
348
+ const body = data;
349
+ if (this.jsonEnabled()) {
350
+ body._meta = this.metaFor(headers, '/v1/responses', model);
351
+ return body;
352
+ }
353
+ let outputText = '';
354
+ for (const item of body.output ?? []) {
355
+ for (const block of item.content ?? []) {
356
+ if (block.type === 'output_text')
357
+ outputText += String(block.text ?? '');
358
+ }
359
+ }
360
+ this.printReply(model, extractReasoning(body, '/v1/responses'), outputText, flags['show-cause']);
361
+ return body;
362
+ }
363
+ }
@@ -0,0 +1,26 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ChatMessages extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ message: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
6
+ system: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ 'max-tokens': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
9
+ style: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ 'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ cause: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ 'cause-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
21
+ };
22
+ static args: {
23
+ face_model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
24
+ };
25
+ run(): Promise<unknown>;
26
+ }
@@ -0,0 +1,139 @@
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
+ export default class ChatMessages extends BaseCommand {
6
+ static description = 'Chat with a face in the Anthropic Messages format (/v1/messages). chat:chat routes Anthropic models here on its own.';
7
+ static flags = {
8
+ ...BaseCommand.baseFlags,
9
+ message: Flags.string({ char: 'm', description: 'User message (repeatable)', multiple: true, required: true }),
10
+ system: Flags.string({ description: 'System prompt' }),
11
+ stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
12
+ 'max-tokens': Flags.integer({ description: 'Max tokens (at least 1)', default: 1024, min: 1 }),
13
+ style: Flags.string({ description: STYLE_FLAG_DESCRIPTION }),
14
+ medium: Flags.string({ description: MEDIUM_FLAG_DESCRIPTION }),
15
+ session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
16
+ compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
17
+ 'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
18
+ 'show-cause': Flags.boolean({ description: REASONING_FLAG_DESCRIPTION, default: false }),
19
+ cause: Flags.string({ description: CAUSE_FLAG_DESCRIPTION }),
20
+ 'cause-file': Flags.string({ description: CAUSE_FILE_FLAG_DESCRIPTION, exclusive: ['cause'] }),
21
+ };
22
+ static args = {
23
+ face_model: Args.string({
24
+ 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 ' +
25
+ 'returns only its cause, with no answer: name the model for one, or use chat:chat, which adds the ' +
26
+ 'face\'s default model.',
27
+ required: true,
28
+ }),
29
+ };
30
+ async run() {
31
+ const { args, flags } = await this.parse(ChatMessages);
32
+ const client = this.makeClient(flags);
33
+ const msgs = flags.message.map((m) => ({ role: 'user', content: m }));
34
+ let cause;
35
+ try {
36
+ cause = resolveCause(flags.cause, flags['cause-file']);
37
+ }
38
+ catch (err) {
39
+ this.error(err instanceof Error ? err.message : String(err));
40
+ }
41
+ const model = args.face_model;
42
+ if (cause && !model.includes('@'))
43
+ this.error(causeNeedsModel(model));
44
+ const stream = flags.stream && !this.jsonEnabled();
45
+ const payload = {
46
+ model,
47
+ messages: msgs,
48
+ max_tokens: flags['max-tokens'],
49
+ stream,
50
+ };
51
+ if (flags.system)
52
+ payload.system = flags.system;
53
+ Object.assign(payload, chatExtras(flags));
54
+ if (flags['oauth-only'])
55
+ payload.oauth_only = true;
56
+ if (cause)
57
+ payload.cause = cause;
58
+ try {
59
+ if (stream) {
60
+ let reasoning = '';
61
+ let replied = false;
62
+ for await (const line of client.stream('/v1/messages', payload)) {
63
+ if (!line.startsWith('data: '))
64
+ continue;
65
+ const chunk = line.slice(6);
66
+ if (chunk.trim() === '[DONE]' || chunk.trim() === '')
67
+ continue;
68
+ try {
69
+ const obj = JSON.parse(chunk);
70
+ const thought = extractStreamReasoning(obj);
71
+ if (thought) {
72
+ if (flags['show-cause'] && !reasoning)
73
+ process.stderr.write(`${reasoningHeading(model)}\n`);
74
+ if (flags['show-cause'])
75
+ process.stderr.write(thought);
76
+ reasoning += thought;
77
+ }
78
+ if (obj.type === 'content_block_delta') {
79
+ const delta = obj.delta?.text ?? '';
80
+ if (delta) {
81
+ if (flags['show-cause'] && reasoning && !replied)
82
+ process.stderr.write('\n\n');
83
+ replied = true;
84
+ process.stdout.write(String(delta));
85
+ }
86
+ }
87
+ }
88
+ catch {
89
+ }
90
+ }
91
+ if (!replied && reasoning) {
92
+ if (flags['show-cause'])
93
+ process.stderr.write('\n');
94
+ else
95
+ process.stdout.write(`${reasoning}\n`);
96
+ process.stderr.write(`\n${reasoningOnlyNote(model, false)}\n`);
97
+ }
98
+ else {
99
+ process.stdout.write('\n');
100
+ }
101
+ return {};
102
+ }
103
+ const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/messages', payload), sayWarmUp);
104
+ const body = data;
105
+ if (this.jsonEnabled()) {
106
+ const meta = {};
107
+ if (headers['x-faces-provider'])
108
+ meta.provider = headers['x-faces-provider'];
109
+ if (headers['x-faces-cost-usd'])
110
+ meta.cost_usd = headers['x-faces-cost-usd'];
111
+ if (headers['x-faces-billing'])
112
+ meta.billing = headers['x-faces-billing'];
113
+ if (Object.keys(meta).length > 0)
114
+ body._meta = meta;
115
+ return body;
116
+ }
117
+ let content = '';
118
+ for (const block of body.content ?? []) {
119
+ if (block.type === 'text')
120
+ content += String(block.text ?? '');
121
+ }
122
+ writeReply(model, extractReasoning(body, '/v1/messages'), content, flags['show-cause'], reasoningOnlyNote(model, false));
123
+ return body;
124
+ }
125
+ catch (err) {
126
+ if (err instanceof FacesAPIError) {
127
+ if (err.errorCode === 'oauth_rejected') {
128
+ const hint = err.fallbackAvailable
129
+ ? 'Run `faces account:preferences api_fallback true` to allow paid fallback.'
130
+ : 'Run `faces billing:topup` to add credits, then enable fallback with `faces account:preferences api_fallback true`.';
131
+ this.error(`OAuth failed: ${err.message}\n${hint}`);
132
+ }
133
+ const hint = faceRefusalHint(err, model, flags.style);
134
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
135
+ }
136
+ throw err;
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ChatResponses extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ message: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
6
+ instructions: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ 'max-tokens': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ temperature: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ style: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ 'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ cause: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ 'cause-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
20
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
+ };
23
+ static args: {
24
+ face_model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
25
+ };
26
+ run(): Promise<unknown>;
27
+ }