@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,150 @@
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, MIN_MAX_OUTPUT_TOKENS, parseTemperature, warnDroppedParams, CHAT_PARAM_FLAGS } from '../../utils.js';
4
+ import { FacesAPIError } from '../../client.js';
5
+ export default class ChatResponses extends BaseCommand {
6
+ static description = 'Chat with a face in the OpenAI Responses format (/v1/responses). The same as chat:chat --responses. On Connect and Pro with ChatGPT linked, Codex-eligible models (see faces models:list --chatgpt) run on the ChatGPT plan.';
7
+ static flags = {
8
+ ...BaseCommand.baseFlags,
9
+ message: Flags.string({ char: 'm', description: 'User input message', required: true }),
10
+ instructions: Flags.string({ description: 'System instructions' }),
11
+ 'max-tokens': Flags.integer({ description: `Max output tokens (at least ${MIN_MAX_OUTPUT_TOKENS})` }),
12
+ temperature: Flags.string({ description: 'Temperature (0.0-2.0)' }),
13
+ stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
14
+ style: Flags.string({ description: STYLE_FLAG_DESCRIPTION }),
15
+ medium: Flags.string({ description: MEDIUM_FLAG_DESCRIPTION }),
16
+ session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
17
+ compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
18
+ 'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
19
+ 'show-cause': Flags.boolean({ description: REASONING_FLAG_DESCRIPTION, default: false }),
20
+ cause: Flags.string({ description: CAUSE_FLAG_DESCRIPTION }),
21
+ 'cause-file': Flags.string({ description: CAUSE_FILE_FLAG_DESCRIPTION, exclusive: ['cause'] }),
22
+ };
23
+ static args = {
24
+ face_model: Args.string({
25
+ description: 'Face model, sent as typed (e.g. myface@gpt-4o, head:socrates@gpt-5.4). A face named without a model ' +
26
+ 'returns only its cause, with no answer: name the model for one, or use chat:chat, which adds the ' +
27
+ 'face\'s default model.',
28
+ required: true,
29
+ }),
30
+ };
31
+ async run() {
32
+ const { args, flags } = await this.parse(ChatResponses);
33
+ const client = this.makeClient(flags);
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
+ input: flags.message,
48
+ stream,
49
+ };
50
+ if (flags.instructions)
51
+ payload.instructions = flags.instructions;
52
+ if (flags['max-tokens'] !== undefined) {
53
+ if (flags['max-tokens'] < MIN_MAX_OUTPUT_TOKENS) {
54
+ this.error(`--max-tokens must be at least ${MIN_MAX_OUTPUT_TOKENS} (got ${flags['max-tokens']}). The Responses API rejects a smaller output cap.`);
55
+ }
56
+ payload.max_output_tokens = flags['max-tokens'];
57
+ }
58
+ if (flags.temperature !== undefined)
59
+ payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
60
+ Object.assign(payload, chatExtras(flags));
61
+ if (flags['oauth-only'])
62
+ payload.oauth_only = true;
63
+ if (cause)
64
+ payload.cause = cause;
65
+ try {
66
+ if (stream) {
67
+ let reasoning = '';
68
+ let replied = false;
69
+ for await (const line of client.stream('/v1/responses', payload, { onHeaders: (h) => warnDroppedParams(h, CHAT_PARAM_FLAGS) })) {
70
+ if (!line.startsWith('data: '))
71
+ continue;
72
+ const chunk = line.slice(6);
73
+ if (chunk.trim() === '[DONE]' || chunk.trim() === '')
74
+ continue;
75
+ try {
76
+ const obj = JSON.parse(chunk);
77
+ const thought = extractStreamReasoning(obj);
78
+ if (thought) {
79
+ if (flags['show-cause'] && !reasoning)
80
+ process.stderr.write(`${reasoningHeading(model)}\n`);
81
+ if (flags['show-cause'])
82
+ process.stderr.write(thought);
83
+ reasoning += thought;
84
+ }
85
+ if (obj.type === 'response.output_text.delta') {
86
+ const delta = obj.delta ?? '';
87
+ if (delta) {
88
+ if (flags['show-cause'] && reasoning && !replied)
89
+ process.stderr.write('\n\n');
90
+ replied = true;
91
+ process.stdout.write(String(delta));
92
+ }
93
+ }
94
+ }
95
+ catch {
96
+ }
97
+ }
98
+ if (!replied && reasoning) {
99
+ if (flags['show-cause'])
100
+ process.stderr.write('\n');
101
+ else
102
+ process.stdout.write(`${reasoning}\n`);
103
+ process.stderr.write(`\n${reasoningOnlyNote(model, false)}\n`);
104
+ }
105
+ else {
106
+ process.stdout.write('\n');
107
+ }
108
+ return {};
109
+ }
110
+ const { data, headers } = await retryOnceOnWarmUp(() => postChat(client, '/v1/responses', payload), sayWarmUp);
111
+ const body = data;
112
+ if (!this.jsonEnabled())
113
+ warnDroppedParams(headers, CHAT_PARAM_FLAGS);
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 outputText = '';
127
+ for (const item of body.output ?? []) {
128
+ for (const block of item.content ?? []) {
129
+ if (block.type === 'output_text')
130
+ outputText += String(block.text ?? '');
131
+ }
132
+ }
133
+ writeReply(model, extractReasoning(body, '/v1/responses'), outputText, flags['show-cause'], reasoningOnlyNote(model, false));
134
+ return body;
135
+ }
136
+ catch (err) {
137
+ if (err instanceof FacesAPIError) {
138
+ if (err.errorCode === 'oauth_rejected') {
139
+ const hint = err.fallbackAvailable
140
+ ? 'Run `faces account:preferences api_fallback true` to allow paid fallback.'
141
+ : 'Run `faces billing:topup` to add credits, then enable fallback with `faces account:preferences api_fallback true`.';
142
+ this.error(`OAuth failed: ${err.message}\n${hint}`);
143
+ }
144
+ const hint = faceRefusalHint(err, model, flags.style);
145
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
146
+ }
147
+ throw err;
148
+ }
149
+ }
150
+ }
@@ -0,0 +1,43 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ChatThread extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ message: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ llm: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ system: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'max-tokens': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ temperature: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ stream: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ style: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'oauth-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
19
+ 'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
20
+ cause: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
21
+ 'cause-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ list: import("@oclif/core/interfaces").BooleanFlag<boolean>;
23
+ show: import("@oclif/core/interfaces").BooleanFlag<boolean>;
24
+ delete: import("@oclif/core/interfaces").BooleanFlag<boolean>;
25
+ yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
26
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
27
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
28
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
29
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
30
+ };
31
+ static args: {
32
+ face_username: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
33
+ };
34
+ run(): Promise<unknown>;
35
+ private handleList;
36
+ private handleDelete;
37
+ private handleShow;
38
+ private handleMessage;
39
+ private sendChatCompletions;
40
+ private sendResponses;
41
+ private sendAnthropic;
42
+ private streamAndAccumulate;
43
+ }
@@ -0,0 +1,458 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import crypto from 'node:crypto';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { BaseCommand } from '../../base.js';
7
+ import { FacesAPIError } from '../../client.js';
8
+ import { postChat, streamChat, resolveCause, CAUSE_FLAG_DESCRIPTION, CAUSE_FILE_FLAG_DESCRIPTION, retryOnceOnWarmUp, sayWarmUp, faceRefusalHint, STREAM_FLAG_DESCRIPTION, extractCause, extractStreamDelta, FACES_REASONING_ITEM_PREFIX, FACES_THINKING_SIGNATURE, extractStreamReasoning, isMaxTokensRenameError, MIN_MAX_OUTPUT_TOKENS, STYLE_FLAG_DESCRIPTION, MEDIUM_FLAG_DESCRIPTION, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION, chatExtras, reasoningHeading, REASONING_FLAG_DESCRIPTION, parseTemperature } from '../../utils.js';
9
+ import { resolveEndpoint, isCompositeFormula, llmFromArg, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT, CHAT_COMPLETIONS_ENDPOINT } from '../../routing.js';
10
+ const THREADS_DIR = path.join(os.homedir(), '.faces', 'threads');
11
+ function extractAssistantText(body, endpoint) {
12
+ if (endpoint === MESSAGES_ENDPOINT) {
13
+ let text = '';
14
+ for (const block of body.content ?? []) {
15
+ if (block.type === 'text')
16
+ text += String(block.text ?? '');
17
+ }
18
+ return text;
19
+ }
20
+ if (endpoint === RESPONSES_ENDPOINT) {
21
+ let text = '';
22
+ for (const item of body.output ?? []) {
23
+ for (const block of item.content ?? []) {
24
+ if (block.type === 'output_text')
25
+ text += String(block.text ?? '');
26
+ }
27
+ }
28
+ return text;
29
+ }
30
+ const choices = body.choices;
31
+ return String(choices?.[0]?.message?.content ?? '');
32
+ }
33
+ function replyOf(body, endpoint) {
34
+ const cause = extractCause(body, endpoint);
35
+ const message = body.choices?.[0]?.message;
36
+ const modelReasoning = endpoint === CHAT_COMPLETIONS_ENDPOINT && message?.reasoning_content ? String(message.reasoning_content) : undefined;
37
+ return { text: extractAssistantText(body, endpoint), reasoning: cause.text, causeId: cause.id, modelReasoning };
38
+ }
39
+ function chatTurn(m) {
40
+ const turn = { role: m.role, content: m.content };
41
+ if (m.role === 'assistant' && m.cause)
42
+ turn.cause = m.cause;
43
+ if (m.role === 'assistant' && m.reasoning_content)
44
+ turn.reasoning_content = m.reasoning_content;
45
+ return turn;
46
+ }
47
+ function responsesTurns(m) {
48
+ const turn = { role: m.role, content: m.content };
49
+ if (m.role !== 'assistant' || !m.cause || !m.cause_id)
50
+ return [turn];
51
+ return [{ type: 'reasoning', id: m.cause_id, summary: [{ type: 'summary_text', text: m.cause }] }, turn];
52
+ }
53
+ function messagesTurn(m) {
54
+ if (m.role !== 'assistant' || !m.cause)
55
+ return { role: m.role, content: m.content };
56
+ return {
57
+ role: m.role,
58
+ content: [
59
+ { type: 'thinking', thinking: m.cause, signature: FACES_THINKING_SIGNATURE },
60
+ { type: 'text', text: m.content },
61
+ ],
62
+ };
63
+ }
64
+ function newThreadId() {
65
+ return 't_' + crypto.randomBytes(6).toString('hex');
66
+ }
67
+ function threadPath(id) {
68
+ if (!/^[A-Za-z0-9_-]+$/.test(id))
69
+ throw new Error(`"${id}" is not a thread id. List them with: faces chat:thread --list`);
70
+ return path.join(THREADS_DIR, `${id}.json`);
71
+ }
72
+ function ensureThreadsDir() {
73
+ if (!fs.existsSync(THREADS_DIR))
74
+ fs.mkdirSync(THREADS_DIR, { recursive: true, mode: 0o700 });
75
+ }
76
+ function loadThread(id) {
77
+ const p = threadPath(id);
78
+ if (!fs.existsSync(p))
79
+ return null;
80
+ return JSON.parse(fs.readFileSync(p, 'utf8'));
81
+ }
82
+ function saveThread(t) {
83
+ ensureThreadsDir();
84
+ t.updated_at = new Date().toISOString();
85
+ fs.writeFileSync(threadPath(t.id), JSON.stringify(t, null, 2), { mode: 0o600 });
86
+ }
87
+ function listThreads() {
88
+ if (!fs.existsSync(THREADS_DIR))
89
+ return [];
90
+ const out = [];
91
+ for (const f of fs.readdirSync(THREADS_DIR)) {
92
+ if (!f.endsWith('.json'))
93
+ continue;
94
+ try {
95
+ out.push(JSON.parse(fs.readFileSync(path.join(THREADS_DIR, f), 'utf8')));
96
+ }
97
+ catch { }
98
+ }
99
+ out.sort((a, b) => (b.updated_at ?? '').localeCompare(a.updated_at ?? ''));
100
+ return out;
101
+ }
102
+ export default class ChatThread extends BaseCommand {
103
+ static description = 'Multi-turn chat thread. Conversation history is stored under ~/.faces/threads/<id>.json. Resume any thread later with --id. ' +
104
+ 'A face named without a model answers on its default model, which is fixed on the thread when it starts. ' +
105
+ 'Each turn keeps the face\'s cause and sends it back with the transcript.';
106
+ static examples = [
107
+ '<%= config.bin %> <%= command.id %> socrates -m "What is justice?"',
108
+ '<%= config.bin %> <%= command.id %> --id t_abc123 -m "Say more about that"',
109
+ '<%= config.bin %> <%= command.id %> --list',
110
+ '<%= config.bin %> <%= command.id %> --id t_abc123 --show',
111
+ '<%= config.bin %> <%= command.id %> --id t_abc123 --delete',
112
+ ];
113
+ static flags = {
114
+ ...BaseCommand.baseFlags,
115
+ id: Flags.string({ description: 'Resume an existing thread by id' }),
116
+ message: Flags.string({ char: 'm', description: 'User message' }),
117
+ file: Flags.string({ description: 'Read message from file' }),
118
+ llm: Flags.string({ description: 'LLM override (only honored when starting a new thread)' }),
119
+ system: Flags.string({ description: 'System prompt (only honored when starting a new thread)' }),
120
+ 'max-tokens': Flags.integer({ description: 'Max tokens (at least 1)', min: 1 }),
121
+ temperature: Flags.string({ description: 'Temperature (0.0-2.0)' }),
122
+ stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
123
+ style: Flags.string({ description: `${STYLE_FLAG_DESCRIPTION} For this turn only.` }),
124
+ medium: Flags.string({ description: `${MEDIUM_FLAG_DESCRIPTION} For this turn only.` }),
125
+ session: Flags.string({ description: `${SESSION_FLAG_DESCRIPTION} For this turn only.` }),
126
+ compaction: Flags.string({ description: `${COMPACTION_FLAG_DESCRIPTION} For this turn only.` }),
127
+ 'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
128
+ 'show-cause': Flags.boolean({ description: REASONING_FLAG_DESCRIPTION, default: false }),
129
+ cause: Flags.string({ description: `${CAUSE_FLAG_DESCRIPTION} For this turn only; it is kept on the thread like any.` }),
130
+ 'cause-file': Flags.string({ description: CAUSE_FILE_FLAG_DESCRIPTION, exclusive: ['cause'] }),
131
+ list: Flags.boolean({ description: 'List saved threads', default: false }),
132
+ show: Flags.boolean({ description: 'Show the thread transcript (requires --id)', default: false }),
133
+ delete: Flags.boolean({ description: 'Delete the thread (requires --id)', default: false }),
134
+ yes: Flags.boolean({ description: 'Skip confirmation for --delete', default: false }),
135
+ };
136
+ static args = {
137
+ face_username: Args.string({
138
+ description: 'Face alias (alias@model, or owner:alias@model for a published face). Required when starting a new thread',
139
+ required: false,
140
+ }),
141
+ };
142
+ async run() {
143
+ const { args, flags } = await this.parse(ChatThread);
144
+ if (flags.list)
145
+ return this.handleList();
146
+ if (flags.delete)
147
+ return this.handleDelete(flags.id, flags.yes);
148
+ if (flags.show)
149
+ return this.handleShow(flags.id);
150
+ return this.handleMessage(args.face_username, flags);
151
+ }
152
+ handleList() {
153
+ const threads = listThreads();
154
+ if (this.jsonEnabled()) {
155
+ return threads.map((t) => ({
156
+ id: t.id,
157
+ face: t.face_username,
158
+ model: t.model,
159
+ turns: t.messages.length,
160
+ created_at: t.created_at,
161
+ updated_at: t.updated_at,
162
+ }));
163
+ }
164
+ if (threads.length === 0) {
165
+ this.log('(no threads)');
166
+ return {};
167
+ }
168
+ for (const t of threads) {
169
+ const last = t.messages[t.messages.length - 1];
170
+ const preview = last
171
+ ? last.content.slice(0, 60).replace(/\s+/g, ' ') + (last.content.length > 60 ? '…' : '')
172
+ : '';
173
+ this.log(`${t.id} ${t.model} (${t.messages.length} turns, updated ${t.updated_at})`);
174
+ if (preview)
175
+ this.log(` ${last.role}: ${preview}`);
176
+ }
177
+ return {};
178
+ }
179
+ async handleDelete(id, yes) {
180
+ if (!id)
181
+ this.error('--delete requires --id <thread-id>');
182
+ const p = threadPath(id);
183
+ if (!fs.existsSync(p))
184
+ this.error(`Thread not found: ${id}`);
185
+ await this.confirmOrRefuse(`Delete thread ${id} and its history?`, yes);
186
+ fs.unlinkSync(p);
187
+ if (this.jsonEnabled())
188
+ return { deleted: id };
189
+ this.log(`Deleted thread ${id}`);
190
+ return { deleted: id };
191
+ }
192
+ handleShow(id) {
193
+ if (!id)
194
+ this.error('--show requires --id <thread-id>');
195
+ const t = loadThread(id);
196
+ if (!t)
197
+ this.error(`Thread not found: ${id}`);
198
+ if (this.jsonEnabled())
199
+ return t;
200
+ this.log(`Thread ${t.id} (${t.model}, provider=${t.provider})`);
201
+ this.log(`Created: ${t.created_at}`);
202
+ this.log(`Updated: ${t.updated_at}`);
203
+ if (t.system) {
204
+ this.log('---');
205
+ this.log(`system: ${t.system}`);
206
+ }
207
+ for (const m of t.messages) {
208
+ this.log('---');
209
+ this.log(`${m.role} [${m.ts}]:`);
210
+ this.log(m.content);
211
+ }
212
+ return t;
213
+ }
214
+ async handleMessage(face_username, flags) {
215
+ let userMessage;
216
+ if (flags.file) {
217
+ if (!fs.existsSync(flags.file))
218
+ this.error(`File not found: ${flags.file}`);
219
+ userMessage = fs.readFileSync(flags.file, 'utf8');
220
+ }
221
+ else if (flags.message) {
222
+ userMessage = flags.message;
223
+ }
224
+ else {
225
+ this.error('Provide --message/-m or --file');
226
+ }
227
+ const client = this.makeClient(flags);
228
+ let thread;
229
+ if (flags.id) {
230
+ const existing = loadThread(flags.id);
231
+ if (!existing)
232
+ this.error(`Thread not found: ${flags.id}`);
233
+ thread = existing;
234
+ if (flags.llm || flags.system) {
235
+ this.warn('--llm and --system are ignored when resuming a thread; using values stored on the thread');
236
+ }
237
+ }
238
+ else {
239
+ if (!face_username) {
240
+ this.error('Provide a face (e.g. `faces chat:thread socrates -m "…"`) or --id <thread-id> to resume');
241
+ }
242
+ const baseAlias = face_username.split('@')[0];
243
+ const model = flags.llm ? `${baseAlias}@${flags.llm}` : face_username;
244
+ const now = new Date().toISOString();
245
+ thread = {
246
+ id: newThreadId(),
247
+ face_username: baseAlias,
248
+ model,
249
+ provider: 'openai',
250
+ system: flags.system,
251
+ created_at: now,
252
+ updated_at: now,
253
+ messages: [],
254
+ };
255
+ }
256
+ thread.messages.push({ role: 'user', content: userMessage, ts: new Date().toISOString() });
257
+ const bare = !llmFromArg(thread.model) && !isCompositeFormula(thread.model);
258
+ let endpoint = thread.endpoint;
259
+ if (!endpoint || bare) {
260
+ const route = await resolveEndpoint(client, thread.model);
261
+ if (bare) {
262
+ if (!route.llm) {
263
+ this.error(`${thread.model} has no default model to answer on, so name one: ${thread.model}@<model>, or add --llm <model>.`);
264
+ }
265
+ thread.model = `${thread.model}@${route.llm}`;
266
+ }
267
+ endpoint = route.endpoint;
268
+ thread.endpoint = endpoint;
269
+ thread.provider = endpoint === MESSAGES_ENDPOINT ? 'anthropic' : 'openai';
270
+ }
271
+ let cause;
272
+ try {
273
+ cause = resolveCause(flags.cause, flags['cause-file']);
274
+ }
275
+ catch (err) {
276
+ this.error(err instanceof Error ? err.message : String(err));
277
+ }
278
+ flags = { ...flags, cause, stream: flags.stream && !this.jsonEnabled() };
279
+ try {
280
+ let reply;
281
+ if (endpoint === MESSAGES_ENDPOINT) {
282
+ reply = await this.sendAnthropic(client, thread, flags);
283
+ }
284
+ else if (endpoint === RESPONSES_ENDPOINT) {
285
+ reply = await this.sendResponses(client, thread, flags);
286
+ }
287
+ else {
288
+ reply = await this.sendChatCompletions(client, thread, flags);
289
+ }
290
+ const assistantText = reply.text;
291
+ if (!flags.stream && flags['show-cause'] && reply.reasoning && !this.jsonEnabled()) {
292
+ process.stderr.write(`${reasoningHeading(thread.model)}\n${reply.reasoning}\n\n`);
293
+ }
294
+ const turn = { role: 'assistant', content: assistantText, ts: new Date().toISOString() };
295
+ if (reply.reasoning)
296
+ turn.cause = reply.reasoning;
297
+ if (reply.causeId)
298
+ turn.cause_id = reply.causeId;
299
+ if (reply.modelReasoning)
300
+ turn.reasoning_content = reply.modelReasoning;
301
+ thread.messages.push(turn);
302
+ saveThread(thread);
303
+ if (this.jsonEnabled()) {
304
+ return {
305
+ thread_id: thread.id,
306
+ model: thread.model,
307
+ provider: thread.provider,
308
+ assistant: assistantText,
309
+ ...(reply.reasoning ? { cause: reply.reasoning } : {}),
310
+ turns: thread.messages.length,
311
+ };
312
+ }
313
+ if (!flags.stream)
314
+ this.log(assistantText);
315
+ this.log(`\n[thread ${thread.id} · ${thread.messages.length} turns]`);
316
+ return { thread_id: thread.id, assistant: assistantText };
317
+ }
318
+ catch (err) {
319
+ if (err instanceof FacesAPIError) {
320
+ if (err.errorCode === 'oauth_rejected') {
321
+ const hints = [];
322
+ if (endpoint === RESPONSES_ENDPOINT) {
323
+ hints.push('This model is free when you link your ChatGPT account: faces auth:connect openai');
324
+ }
325
+ hints.push(err.fallbackAvailable
326
+ ? 'Run `faces account:preferences api_fallback true` to allow paid fallback.'
327
+ : 'Run `faces billing:topup` to add credits, then enable fallback with `faces account:preferences api_fallback true`.');
328
+ this.error(`OAuth failed: ${err.message}\n${hints.join('\n')}`);
329
+ }
330
+ const hint = faceRefusalHint(err, thread.model, flags.style);
331
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
332
+ }
333
+ throw err;
334
+ }
335
+ }
336
+ async sendChatCompletions(client, thread, flags) {
337
+ const messages = [];
338
+ if (thread.system)
339
+ messages.push({ role: 'system', content: thread.system });
340
+ for (const m of thread.messages)
341
+ messages.push(chatTurn(m));
342
+ const payload = { model: thread.model, messages, stream: flags.stream };
343
+ if (flags['max-tokens'])
344
+ payload.max_tokens = flags['max-tokens'];
345
+ if (flags.temperature !== undefined)
346
+ payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
347
+ Object.assign(payload, chatExtras(flags));
348
+ if (flags['oauth-only'])
349
+ payload.oauth_only = true;
350
+ if (flags.cause)
351
+ payload.cause = flags.cause;
352
+ if (flags.stream) {
353
+ return this.streamAndAccumulate(client, CHAT_COMPLETIONS_ENDPOINT, payload, flags['show-cause'] ? thread.model : undefined);
354
+ }
355
+ let data;
356
+ try {
357
+ ;
358
+ ({ data } = await retryOnceOnWarmUp(() => postChat(client, CHAT_COMPLETIONS_ENDPOINT, payload), sayWarmUp));
359
+ }
360
+ catch (err) {
361
+ if (err instanceof FacesAPIError && isMaxTokensRenameError(err.message) && payload.max_tokens !== undefined) {
362
+ payload.max_completion_tokens = payload.max_tokens;
363
+ delete payload.max_tokens;
364
+ ({ data } = await retryOnceOnWarmUp(() => postChat(client, CHAT_COMPLETIONS_ENDPOINT, payload), sayWarmUp));
365
+ }
366
+ else {
367
+ throw err;
368
+ }
369
+ }
370
+ return replyOf(data, CHAT_COMPLETIONS_ENDPOINT);
371
+ }
372
+ async sendResponses(client, thread, flags) {
373
+ const input = thread.messages.flatMap((m) => responsesTurns(m));
374
+ const payload = { model: thread.model, input, stream: flags.stream };
375
+ if (thread.system)
376
+ payload.instructions = thread.system;
377
+ if (flags['max-tokens'] !== undefined) {
378
+ if (flags['max-tokens'] < MIN_MAX_OUTPUT_TOKENS) {
379
+ throw new Error(`--max-tokens must be at least ${MIN_MAX_OUTPUT_TOKENS} for this model (got ${flags['max-tokens']}). ` +
380
+ 'The Responses API rejects a smaller output cap.');
381
+ }
382
+ payload.max_output_tokens = flags['max-tokens'];
383
+ }
384
+ if (flags.temperature !== undefined)
385
+ payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
386
+ Object.assign(payload, chatExtras(flags));
387
+ if (flags['oauth-only'])
388
+ payload.oauth_only = true;
389
+ if (flags.cause)
390
+ payload.cause = flags.cause;
391
+ if (flags.stream) {
392
+ return this.streamAndAccumulate(client, RESPONSES_ENDPOINT, payload, flags['show-cause'] ? thread.model : undefined);
393
+ }
394
+ const { data } = await retryOnceOnWarmUp(() => postChat(client, RESPONSES_ENDPOINT, payload), sayWarmUp);
395
+ return replyOf(data, RESPONSES_ENDPOINT);
396
+ }
397
+ async sendAnthropic(client, thread, flags) {
398
+ const msgs = thread.messages.map((m) => messagesTurn(m));
399
+ const payload = {
400
+ model: thread.model,
401
+ messages: msgs,
402
+ max_tokens: flags['max-tokens'] ?? 1024,
403
+ stream: flags.stream,
404
+ };
405
+ if (thread.system)
406
+ payload.system = thread.system;
407
+ Object.assign(payload, chatExtras(flags));
408
+ if (flags['oauth-only'])
409
+ payload.oauth_only = true;
410
+ if (flags.cause)
411
+ payload.cause = flags.cause;
412
+ if (flags.stream) {
413
+ return this.streamAndAccumulate(client, MESSAGES_ENDPOINT, payload, flags['show-cause'] ? thread.model : undefined);
414
+ }
415
+ const { data } = await retryOnceOnWarmUp(() => postChat(client, MESSAGES_ENDPOINT, payload), sayWarmUp);
416
+ return replyOf(data, MESSAGES_ENDPOINT);
417
+ }
418
+ async streamAndAccumulate(client, endpoint, payload, showReasoningAs) {
419
+ let accum = '';
420
+ let reasoning = '';
421
+ let causeId;
422
+ let modelReasoning = '';
423
+ for await (const line of streamChat(client, endpoint, payload)) {
424
+ if (!line.startsWith('data: '))
425
+ continue;
426
+ const chunk = line.slice(6);
427
+ if (chunk.trim() === '[DONE]' || chunk.trim() === '')
428
+ continue;
429
+ try {
430
+ const parsed = JSON.parse(chunk);
431
+ const item = parsed.item_id;
432
+ if (typeof item === 'string' && item.startsWith(FACES_REASONING_ITEM_PREFIX))
433
+ causeId = item;
434
+ const own = parsed.choices?.[0]?.delta;
435
+ if (own?.reasoning_content)
436
+ modelReasoning += String(own.reasoning_content);
437
+ const thought = extractStreamReasoning(parsed);
438
+ if (thought) {
439
+ if (showReasoningAs && !reasoning)
440
+ process.stderr.write(`${reasoningHeading(showReasoningAs)}\n`);
441
+ if (showReasoningAs)
442
+ process.stderr.write(thought);
443
+ reasoning += thought;
444
+ }
445
+ const delta = extractStreamDelta(parsed);
446
+ if (delta) {
447
+ if (showReasoningAs && reasoning && !accum)
448
+ process.stderr.write('\n\n');
449
+ accum += delta;
450
+ process.stdout.write(delta);
451
+ }
452
+ }
453
+ catch { }
454
+ }
455
+ process.stdout.write('\n');
456
+ return { text: accum, reasoning, causeId, modelReasoning: modelReasoning || undefined };
457
+ }
458
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class CompileAll extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
6
+ rush: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ private reportBlocked;
13
+ run(): Promise<unknown>;
14
+ }