@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,48 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { FacesAPIError } from '../../../client.js';
4
+ import { freshnessLines, messagesAfterSync, seg } from '../../../utils.js';
5
+ export default class CompileThreadGet extends BaseCommand {
6
+ static description = 'Get a thread by ID. Says so when messages have arrived since the last compile, or when a compile ' +
7
+ 'would be refused.';
8
+ static flags = {
9
+ ...BaseCommand.baseFlags,
10
+ 'status-only': Flags.boolean({
11
+ description: 'Fetch just the compile state, leaving out the messages. Hundreds of times smaller, and the right ' +
12
+ 'thing to poll with.',
13
+ default: false,
14
+ }),
15
+ };
16
+ static args = {
17
+ thread_id: Args.string({ description: 'Thread ID', required: true }),
18
+ };
19
+ async run() {
20
+ const { args, flags } = await this.parse(CompileThreadGet);
21
+ const client = this.makeClient(flags);
22
+ let data;
23
+ try {
24
+ const query = flags['status-only'] ? '?status_only=true' : '';
25
+ data = await client.get(`/v1/compile/threads/${seg(args.thread_id)}${query}`);
26
+ }
27
+ catch (err) {
28
+ if (err instanceof FacesAPIError)
29
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
30
+ throw err;
31
+ }
32
+ if (!this.jsonEnabled()) {
33
+ this.printHuman(data);
34
+ const t = data;
35
+ const lines = freshnessLines(data, `faces compile:thread:make ${args.thread_id}`, args.thread_id);
36
+ const { newer } = messagesAfterSync(t.messages, t.synced_at);
37
+ if (newer > 0) {
38
+ lines.unshift(`Stale: ${newer} message(s) arrived after the last compile.`);
39
+ }
40
+ if (lines.length > 0) {
41
+ this.log('');
42
+ for (const line of lines)
43
+ this.log(line);
44
+ }
45
+ }
46
+ return data;
47
+ }
48
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileThreadList extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
+ };
10
+ static args: {
11
+ face_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
12
+ };
13
+ run(): Promise<unknown>;
14
+ }
@@ -0,0 +1,38 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { FacesAPIError } from '../../../client.js';
4
+ import { freshnessSummary } from '../../../utils.js';
5
+ export default class CompileThreadList extends BaseCommand {
6
+ static description = 'List threads for a face, saying how many have moved on since their last compile and how many a ' +
7
+ 'compile would be refused for.';
8
+ static flags = {
9
+ ...BaseCommand.baseFlags,
10
+ };
11
+ static args = {
12
+ face_id: Args.string({ description: 'Face alias', required: true }),
13
+ };
14
+ async run() {
15
+ const { args, flags } = await this.parse(CompileThreadList);
16
+ const client = this.makeClient(flags);
17
+ let data;
18
+ try {
19
+ data = await client.get('/v1/compile/threads', { params: { alias: args.face_id } });
20
+ }
21
+ catch (err) {
22
+ if (err instanceof FacesAPIError)
23
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
24
+ throw err;
25
+ }
26
+ if (!this.jsonEnabled()) {
27
+ this.printHuman(data);
28
+ const items = Array.isArray(data) ? data : [];
29
+ const summary = freshnessSummary(items, 'thread');
30
+ if (summary.length > 0) {
31
+ this.log('');
32
+ for (const line of summary)
33
+ this.log(line);
34
+ }
35
+ }
36
+ return data;
37
+ }
38
+ }
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileThreadMake 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
+ 'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
8
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ };
13
+ static args: {
14
+ thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
15
+ };
16
+ run(): Promise<unknown>;
17
+ }
@@ -0,0 +1,87 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { FacesAPIError } from '../../../client.js';
4
+ import { pollCompileProgress, progressLine } from '../../../poll.js';
5
+ import { compileStatusOf, makeRefusalMessage, makeScheduleLines, msUntilStart, RUSH_FLAG_DESCRIPTION, seg } from '../../../utils.js';
6
+ export default class CompileThreadMake extends BaseCommand {
7
+ static description = 'Compile an existing thread and wait for it to finish. A compile may have a scheduled start: it says when, and ' +
8
+ 'waits for it; --rush starts it now at the rush rate, and --no-wait returns at once.';
9
+ static flags = {
10
+ ...BaseCommand.baseFlags,
11
+ timeout: Flags.integer({ description: 'Compile timeout in seconds, counted from the compile\'s start', default: 600 }),
12
+ rush: Flags.boolean({
13
+ description: RUSH_FLAG_DESCRIPTION,
14
+ default: false,
15
+ }),
16
+ 'no-wait': Flags.boolean({
17
+ description: 'Return immediately after triggering compilation. Prints the thread ID for manual polling.',
18
+ default: false,
19
+ }),
20
+ };
21
+ static args = {
22
+ thread_id: Args.string({ description: 'Thread ID', required: true }),
23
+ };
24
+ async run() {
25
+ const { args, flags } = await this.parse(CompileThreadMake);
26
+ const client = this.makeClient(flags);
27
+ const json = this.jsonEnabled();
28
+ let makeResponse;
29
+ try {
30
+ makeResponse = await client.post(`/v1/compile/threads/${seg(args.thread_id)}/make`, flags.rush ? { body: { rush: true } } : {});
31
+ }
32
+ catch (err) {
33
+ if (err instanceof FacesAPIError) {
34
+ this.error(makeRefusalMessage(err, args.thread_id));
35
+ }
36
+ throw err;
37
+ }
38
+ const queued = compileStatusOf(makeResponse.status) === 'queued';
39
+ const schedule = makeScheduleLines(makeResponse, flags.rush);
40
+ const scheduled = makeResponse.rush !== true && msUntilStart(makeResponse.starts_at) > 0;
41
+ if (!json)
42
+ for (const line of schedule)
43
+ process.stderr.write(`${line}\n`);
44
+ if (flags['no-wait']) {
45
+ if (!json) {
46
+ process.stderr.write(`Compilation started in background${queued ? ' (queued)' : ''}.\n`);
47
+ process.stderr.write(`Poll with: faces compile:thread:get ${args.thread_id} --json\n`);
48
+ }
49
+ return makeResponse;
50
+ }
51
+ if (!json) {
52
+ process.stderr.write(scheduled
53
+ ? 'Waiting for the scheduled start; it starts on its own, so stopping here leaves it scheduled.\n' +
54
+ `To start it now instead: faces compile:thread:make ${args.thread_id} --rush\n`
55
+ : `Compiling${queued ? ' (queued, and it starts on its own)' : ''}:\n`);
56
+ }
57
+ let result;
58
+ try {
59
+ result = await pollCompileProgress(client, args.thread_id, {
60
+ timeoutMs: flags.timeout * 1000,
61
+ startsAt: makeResponse.starts_at,
62
+ endpoint: `/v1/compile/threads/${seg(args.thread_id)}`,
63
+ onProgress: (p) => {
64
+ if (!json)
65
+ process.stderr.write(` ${progressLine(p)}\n`);
66
+ },
67
+ });
68
+ }
69
+ catch (err) {
70
+ if (err instanceof Error)
71
+ this.error(err.message);
72
+ throw err;
73
+ }
74
+ if (!json)
75
+ process.stderr.write('Done.\n');
76
+ if (result && typeof result === 'object') {
77
+ const r = result;
78
+ if (r.starts_at === undefined && 'starts_at' in makeResponse)
79
+ r.starts_at = makeResponse.starts_at;
80
+ if (r.rush === undefined && 'rush' in makeResponse)
81
+ r.rush = makeResponse.rush;
82
+ }
83
+ if (json)
84
+ this.log(JSON.stringify(result, null, 2));
85
+ return result;
86
+ }
87
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileThreadMessage extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ message: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
6
+ 'oauth-only': 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
+ static args: {
13
+ thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
14
+ };
15
+ run(): Promise<unknown>;
16
+ }
@@ -0,0 +1,43 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { FacesAPIError } from '../../../client.js';
4
+ import { seg } from '../../../utils.js';
5
+ export default class CompileThreadMessage extends BaseCommand {
6
+ static description = 'Send a user message to a thread';
7
+ static flags = {
8
+ ...BaseCommand.baseFlags,
9
+ message: Flags.string({ char: 'm', description: 'User message to append', required: true }),
10
+ 'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
11
+ };
12
+ static args = {
13
+ thread_id: Args.string({ description: 'Thread ID', required: true }),
14
+ };
15
+ async run() {
16
+ const { args, flags } = await this.parse(CompileThreadMessage);
17
+ const client = this.makeClient(flags);
18
+ const payload = { message: flags.message };
19
+ if (flags['oauth-only'])
20
+ payload.oauth_only = true;
21
+ let data;
22
+ try {
23
+ data = await client.post(`/v1/compile/threads/${seg(args.thread_id)}/messages`, {
24
+ body: payload,
25
+ });
26
+ }
27
+ catch (err) {
28
+ if (err instanceof FacesAPIError) {
29
+ if (err.errorCode === 'oauth_rejected') {
30
+ const hint = err.fallbackAvailable
31
+ ? 'Run `faces account:preferences api_fallback true` to allow paid fallback.'
32
+ : 'Run `faces billing:topup` to add credits, then enable fallback with `faces account:preferences api_fallback true`.';
33
+ this.error(`OAuth failed: ${err.message}\n${hint}`);
34
+ }
35
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
36
+ }
37
+ throw err;
38
+ }
39
+ if (!this.jsonEnabled())
40
+ this.printHuman(data);
41
+ return data;
42
+ }
43
+ }
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileThreadPause extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ 'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
+ timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
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
+ static args: {
13
+ thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
14
+ };
15
+ run(): Promise<unknown>;
16
+ private report;
17
+ }
@@ -0,0 +1,75 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { FacesAPIError } from '../../../client.js';
4
+ import { pollUntilPaused } from '../../../poll.js';
5
+ import { seg } from '../../../utils.js';
6
+ export default class CompileThreadPause extends BaseCommand {
7
+ static description = 'Ask a running thread compilation to stop (preserves progress, resume with make). ' +
8
+ 'The compile stops within a few seconds; this waits for it unless --no-wait.';
9
+ static flags = {
10
+ ...BaseCommand.baseFlags,
11
+ 'no-wait': Flags.boolean({
12
+ description: 'Return as soon as the pause is accepted, without waiting for the compile to stop.',
13
+ default: false,
14
+ }),
15
+ timeout: Flags.integer({ description: 'Seconds to wait for the compile to stop', default: 60 }),
16
+ };
17
+ static args = {
18
+ thread_id: Args.string({ description: 'Thread ID', required: true }),
19
+ };
20
+ async run() {
21
+ const { args, flags } = await this.parse(CompileThreadPause);
22
+ const client = this.makeClient(flags);
23
+ const json = this.jsonEnabled();
24
+ let data;
25
+ try {
26
+ data = await client.post(`/v1/compile/threads/${seg(args.thread_id)}/pause`);
27
+ }
28
+ catch (err) {
29
+ if (err instanceof FacesAPIError)
30
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
31
+ throw err;
32
+ }
33
+ if (flags['no-wait']) {
34
+ if (!json) {
35
+ process.stderr.write(`Pausing. Poll with: faces compile:thread:get ${args.thread_id} --json\n`);
36
+ }
37
+ return data;
38
+ }
39
+ if (!json)
40
+ process.stderr.write('Pausing');
41
+ const status = await pollUntilPaused(client, args.thread_id, {
42
+ endpoint: `/v1/compile/threads/${seg(args.thread_id)}`,
43
+ timeoutMs: flags.timeout * 1000,
44
+ onTick: () => {
45
+ if (!json && process.stderr.isTTY)
46
+ process.stderr.write('.');
47
+ },
48
+ });
49
+ if (!json)
50
+ process.stderr.write('\n');
51
+ if (!json)
52
+ this.log(this.report(status, args.thread_id, flags.timeout));
53
+ return { ...data, status: status ?? null };
54
+ }
55
+ report(status, id, timeout) {
56
+ switch (status) {
57
+ case 'paused': {
58
+ return `Paused. Resume with: faces compile:thread:make ${id}`;
59
+ }
60
+ case 'compiled': {
61
+ return 'Compile finished before the pause took effect. Nothing to resume.';
62
+ }
63
+ case 'failed': {
64
+ return 'Compile failed before the pause took effect.';
65
+ }
66
+ case 'not_compiled':
67
+ case null: {
68
+ return 'Stopped. The compile is no longer running.';
69
+ }
70
+ default: {
71
+ return `Still stopping after ${timeout}s. Poll with: faces compile:thread:get ${id} --json`;
72
+ }
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ interface ThreadMessage {
3
+ role: 'user' | 'assistant';
4
+ content: string;
5
+ name?: string;
6
+ }
7
+ export default class CompileThreadReplace extends BaseCommand {
8
+ static description: string;
9
+ static examples: string[];
10
+ static flags: {
11
+ file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'face-speaker': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
+ };
18
+ static args: {
19
+ thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
20
+ };
21
+ run(): Promise<unknown>;
22
+ }
23
+ export declare function parseMessages(raw: string, faceSpeaker?: string): {
24
+ messages: ThreadMessage[];
25
+ format: 'json' | 'transcript';
26
+ };
27
+ export {};
@@ -0,0 +1,114 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import fs from 'node:fs';
3
+ import { BaseCommand } from '../../../base.js';
4
+ import { FacesAPIError } from '../../../client.js';
5
+ import { seg } from '../../../utils.js';
6
+ export default class CompileThreadReplace extends BaseCommand {
7
+ static description = "Replace every message in a thread from a file, keeping the thread's id. For a conversation that " +
8
+ 'grows, this is what keeps it one thread: send the whole transcript again and compile it, rather ' +
9
+ 'than uploading each new stretch as another thread. Nothing is generated and nothing is billed; ' +
10
+ 'this only writes content. Run compile:thread:make afterwards to compile it.';
11
+ static examples = [
12
+ '<%= config.bin %> <%= command.id %> THREAD_ID --file transcript.txt --face-speaker Alice',
13
+ '<%= config.bin %> <%= command.id %> THREAD_ID --file messages.json',
14
+ ];
15
+ static flags = {
16
+ ...BaseCommand.baseFlags,
17
+ file: Flags.string({
18
+ description: 'Transcript ("SPEAKER: line" per turn) or a JSON array of {role, content, name}. Which one it ' +
19
+ 'is is detected and reported, so a wrong guess is visible before you compile. A `from` key in a ' +
20
+ 'JSON file is still read as the speaker label.',
21
+ required: true,
22
+ }),
23
+ 'face-speaker': Flags.string({
24
+ description: "Speaker whose lines are the face's own. Everyone else becomes the other side. Required for a " +
25
+ 'transcript unless it has only one speaker; for a JSON file it overrides the roles given.',
26
+ }),
27
+ };
28
+ static args = {
29
+ thread_id: Args.string({ description: 'Thread ID', required: true }),
30
+ };
31
+ async run() {
32
+ const { args, flags } = await this.parse(CompileThreadReplace);
33
+ const client = this.makeClient(flags);
34
+ const json = this.jsonEnabled();
35
+ if (!fs.existsSync(flags.file))
36
+ this.error(`File not found: ${flags.file}`);
37
+ const raw = fs.readFileSync(flags.file, 'utf8');
38
+ const parsed = parseMessages(raw, flags['face-speaker']);
39
+ if (parsed.messages.length === 0) {
40
+ this.error(`No messages found in ${flags.file}, so there is nothing to replace with.\n` +
41
+ 'A transcript needs one "SPEAKER: text" line per turn; a JSON file needs an array of ' +
42
+ '{role, content}. The thread was left alone.');
43
+ }
44
+ const speakers = [...new Set(parsed.messages.map((m) => m.name).filter(Boolean))];
45
+ if (parsed.format === 'transcript' && !flags['face-speaker'] && speakers.length > 1) {
46
+ this.error(`${flags.file} has more than one speaker (${speakers.join(', ')}) and none is marked as the face.\n` +
47
+ 'Say which with --face-speaker, or every line will be read as somebody else talking.');
48
+ }
49
+ if (parsed.format === 'transcript' && flags['face-speaker'] && !parsed.messages.some((m) => m.role === 'user')) {
50
+ this.error(`No speaker in ${flags.file} is called "${flags['face-speaker']}". The speakers are: ${speakers.join(', ') || 'none found'}.\n` +
51
+ 'The thread was left alone.');
52
+ }
53
+ let data;
54
+ try {
55
+ data = await client.patch(`/v1/compile/threads/${seg(args.thread_id)}/messages`, {
56
+ body: { messages: parsed.messages },
57
+ });
58
+ }
59
+ catch (err) {
60
+ if (err instanceof FacesAPIError) {
61
+ if (err.statusCode === 404)
62
+ this.error(`No thread '${args.thread_id}'. It does not exist, or is not yours.`);
63
+ if (err.statusCode === 409) {
64
+ this.error(`HTTP 409: ${err.message}\nThe thread or its face may be locked, or a compile may be running.`);
65
+ }
66
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
67
+ }
68
+ throw err;
69
+ }
70
+ if (json)
71
+ return { thread_id: args.thread_id, format: parsed.format, messages: parsed.messages.length, speakers };
72
+ const mine = parsed.messages.filter((m) => m.role === 'user').length;
73
+ this.log(`Replaced with ${parsed.messages.length} message(s) read as ${parsed.format}.`);
74
+ this.log(`${mine} from the face, ${parsed.messages.length - mine} from others.`);
75
+ this.log(`Compile it: faces compile:thread:make ${args.thread_id}`);
76
+ return data;
77
+ }
78
+ }
79
+ const SPEAKER_LINE = /^([^\n:]{1,64}):\s?(.*)$/;
80
+ export function parseMessages(raw, faceSpeaker) {
81
+ const trimmed = raw.trim();
82
+ if (trimmed.startsWith('[')) {
83
+ try {
84
+ const arr = JSON.parse(trimmed);
85
+ if (Array.isArray(arr) && arr.every((m) => typeof m?.content === 'string')) {
86
+ return { format: 'json', messages: arr.map((m) => toMessage(m, faceSpeaker)) };
87
+ }
88
+ }
89
+ catch {
90
+ }
91
+ }
92
+ const messages = [];
93
+ for (const line of raw.split('\n')) {
94
+ const m = SPEAKER_LINE.exec(line);
95
+ if (m) {
96
+ messages.push({ role: 'assistant', content: m[2].trim(), name: m[1].trim() });
97
+ continue;
98
+ }
99
+ const last = messages.at(-1);
100
+ if (last && line.trim())
101
+ last.content = `${last.content}\n${line.trim()}`.trim();
102
+ }
103
+ const lower = faceSpeaker?.trim().toLowerCase();
104
+ for (const msg of messages) {
105
+ msg.role = lower && msg.name?.toLowerCase() === lower ? 'user' : 'assistant';
106
+ }
107
+ return { format: 'transcript', messages: messages.filter((m) => m.content) };
108
+ }
109
+ function toMessage(m, faceSpeaker) {
110
+ const name = (m.name ?? m.from);
111
+ const lower = faceSpeaker?.trim().toLowerCase();
112
+ const role = lower ? (name?.toLowerCase() === lower ? 'user' : 'assistant') : m.role === 'user' ? 'user' : 'assistant';
113
+ return { role, content: String(m.content ?? ''), ...(name ? { name } : {}) };
114
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileThreadReset extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ };
11
+ static args: {
12
+ thread_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
13
+ };
14
+ run(): Promise<unknown>;
15
+ }
@@ -0,0 +1,33 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { FacesAPIError } from '../../../client.js';
4
+ import { seg } from '../../../utils.js';
5
+ export default class CompileThreadReset extends BaseCommand {
6
+ static description = 'Withdraw a thread from the face while keeping it. What it contributed leaves ' +
7
+ 'the face, and the messages are left untouched for recompiling. This is how to undo a compile that ' +
8
+ 'went wrong without deleting the material and paying to upload it again.';
9
+ static flags = {
10
+ ...BaseCommand.baseFlags,
11
+ yes: Flags.boolean({ description: 'Skip confirmation', default: false }),
12
+ };
13
+ static args = {
14
+ thread_id: Args.string({ description: 'Thread ID', required: true }),
15
+ };
16
+ async run() {
17
+ const { args, flags } = await this.parse(CompileThreadReset);
18
+ const client = this.makeClient(flags);
19
+ let data;
20
+ try {
21
+ data = await client.post(`/v1/compile/threads/${seg(args.thread_id)}/reset`);
22
+ }
23
+ catch (err) {
24
+ if (err instanceof FacesAPIError)
25
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
26
+ throw err;
27
+ }
28
+ if (!this.jsonEnabled()) {
29
+ this.log(`Reset. Recompile with: faces compile:thread:make ${args.thread_id}`);
30
+ }
31
+ return data;
32
+ }
33
+ }
@@ -0,0 +1,21 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class CompileUpload extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
7
+ kind: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
8
+ perspective: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'face-speaker': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ };
17
+ static args: {
18
+ alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
19
+ };
20
+ run(): Promise<unknown>;
21
+ }