@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,186 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { RUSH_FLAG_DESCRIPTION, compileBlockedLabel, compileProgressLabel, localTime, makeRefusalMessage, msUntilStart, seg } from '../../utils.js';
5
+ import { pollCompileProgress } from '../../poll.js';
6
+ export default class CompileAll extends BaseCommand {
7
+ static description = 'Compile all uncompiled documents and threads across all faces. A compile with a scheduled start is ' +
8
+ 'left to start on its own, and listed with its start time; --rush starts them all now.';
9
+ static flags = {
10
+ ...BaseCommand.baseFlags,
11
+ timeout: Flags.integer({ description: 'Per-item compile timeout in seconds', default: 600 }),
12
+ rush: Flags.boolean({ description: RUSH_FLAG_DESCRIPTION, default: false }),
13
+ };
14
+ reportBlocked(blocked) {
15
+ if (blocked.size === 0)
16
+ return;
17
+ const total = [...blocked.values()].reduce((a, b) => a + b, 0);
18
+ const parts = [...blocked.entries()].map(([why, n]) => `${n} ${why}`).join(', ');
19
+ this.log(`Skipping ${total} the server would refuse: ${parts}.`);
20
+ if (blocked.has('no medium declared')) {
21
+ this.log(' Declare one on each with: faces compile:doc:edit <id> --medium essay');
22
+ }
23
+ }
24
+ async run() {
25
+ const { flags } = await this.parse(CompileAll);
26
+ const client = this.makeClient(flags);
27
+ const json = this.jsonEnabled();
28
+ let faces;
29
+ try {
30
+ const all = await client.getAll('/v1/faces');
31
+ faces = all.data;
32
+ if (all.truncated && !json) {
33
+ process.stderr.write('Warning: the face list was cut short, so some faces were not examined.\n');
34
+ }
35
+ }
36
+ catch (err) {
37
+ if (err instanceof FacesAPIError)
38
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
39
+ throw err;
40
+ }
41
+ const items = [];
42
+ let busy = 0;
43
+ const blocked = new Map();
44
+ for (const face of faces) {
45
+ const alias = face.alias;
46
+ if (face.formula)
47
+ continue;
48
+ try {
49
+ const docs = await client.get('/v1/compile/documents', { params: { alias } });
50
+ for (const doc of docs) {
51
+ if (doc.finishing) {
52
+ busy++;
53
+ }
54
+ else if (doc.compilable === false) {
55
+ const why = compileBlockedLabel(doc.compile_blocked_reason) || 'cannot be compiled';
56
+ blocked.set(why, (blocked.get(why) ?? 0) + 1);
57
+ }
58
+ else if (!doc.synced) {
59
+ items.push({
60
+ type: 'document',
61
+ id: doc.document_id,
62
+ alias,
63
+ label: doc.label ?? null,
64
+ });
65
+ }
66
+ }
67
+ }
68
+ catch { }
69
+ try {
70
+ const threads = await client.get('/v1/compile/threads', { params: { alias } });
71
+ for (const thread of threads) {
72
+ if (thread.finishing) {
73
+ busy++;
74
+ }
75
+ else if (thread.compilable === false) {
76
+ const why = compileBlockedLabel(thread.compile_blocked_reason) || 'cannot be compiled';
77
+ blocked.set(why, (blocked.get(why) ?? 0) + 1);
78
+ }
79
+ else if (!thread.synced) {
80
+ items.push({
81
+ type: 'thread',
82
+ id: thread.thread_id,
83
+ alias,
84
+ label: thread.label ?? null,
85
+ });
86
+ }
87
+ }
88
+ }
89
+ catch { }
90
+ }
91
+ if (items.length === 0) {
92
+ if (!json) {
93
+ if (busy > 0) {
94
+ this.log(`Nothing to compile. ${busy} source(s) are still being worked on by the server; they need ` +
95
+ 'no action and will finish on their own.');
96
+ }
97
+ else if (blocked.size > 0) {
98
+ this.log('Nothing to compile.');
99
+ }
100
+ else {
101
+ this.log('Nothing to compile. All documents and threads are up to date.');
102
+ }
103
+ this.reportBlocked(blocked);
104
+ }
105
+ return { compiled: 0, failed: 0, scheduled: 0, items: [] };
106
+ }
107
+ if (!json) {
108
+ this.log(`Found ${items.length} item(s) to compile`);
109
+ if (busy > 0) {
110
+ this.log(`Skipping ${busy} the server is already working on; they need no action.`);
111
+ }
112
+ this.reportBlocked(blocked);
113
+ this.log('');
114
+ }
115
+ let compiled = 0;
116
+ let failed = 0;
117
+ let scheduled = 0;
118
+ const results = [];
119
+ for (let i = 0; i < items.length; i++) {
120
+ const item = items[i];
121
+ const tag = `[${i + 1}/${items.length}]`;
122
+ const name = item.label ?? item.id.slice(0, 8);
123
+ if (!json)
124
+ process.stderr.write(`${tag} ${item.type} "${name}" (${item.alias})... `);
125
+ const makeEndpoint = item.type === 'document'
126
+ ? `/v1/compile/documents/${seg(item.id)}/make`
127
+ : `/v1/compile/threads/${seg(item.id)}/make`;
128
+ const pollEndpoint = item.type === 'document'
129
+ ? `/v1/compile/documents/${seg(item.id)}`
130
+ : `/v1/compile/threads/${seg(item.id)}`;
131
+ try {
132
+ const made = (await client.post(makeEndpoint, flags.rush ? { body: { rush: true } } : {}));
133
+ const sched = {
134
+ ...('starts_at' in made ? { starts_at: made.starts_at ?? null } : {}),
135
+ ...(typeof made.rush === 'boolean' ? { rush: made.rush } : {}),
136
+ };
137
+ if (made.rush !== true && msUntilStart(made.starts_at) > 0) {
138
+ scheduled++;
139
+ results.push({ ...item, status: 'scheduled', ...sched });
140
+ if (!json)
141
+ process.stderr.write(`scheduled, starts ${localTime(made.starts_at)}\n`);
142
+ continue;
143
+ }
144
+ await pollCompileProgress(client, item.id, {
145
+ fullOnFinish: false,
146
+ timeoutMs: flags.timeout * 1000,
147
+ endpoint: pollEndpoint,
148
+ onProgress: (p) => {
149
+ if (!json)
150
+ process.stderr.write(`[${compileProgressLabel(p)}] `);
151
+ },
152
+ });
153
+ compiled++;
154
+ results.push({ ...item, status: 'compiled', ...sched });
155
+ if (!json)
156
+ process.stderr.write('done\n');
157
+ }
158
+ catch (err) {
159
+ if (err instanceof FacesAPIError && err.errorCode === 'already_compiled') {
160
+ results.push({ ...item, status: 'already compiled' });
161
+ if (!json)
162
+ process.stderr.write('already compiled\n');
163
+ continue;
164
+ }
165
+ if (err instanceof FacesAPIError && err.errorCode === 'compile_already_started') {
166
+ results.push({ ...item, status: 'already started' });
167
+ if (!json)
168
+ process.stderr.write('already started, so --rush does not apply\n');
169
+ continue;
170
+ }
171
+ failed++;
172
+ const msg = err instanceof FacesAPIError ? makeRefusalMessage(err, item.id) : err instanceof Error ? err.message : String(err);
173
+ results.push({ ...item, status: `failed: ${msg}` });
174
+ if (!json)
175
+ process.stderr.write(`failed: ${msg}\n`);
176
+ }
177
+ }
178
+ if (!json) {
179
+ this.log(`\nCompile complete: ${compiled} succeeded, ${failed} failed`);
180
+ if (scheduled > 0) {
181
+ this.log(`${scheduled} scheduled to start on their own. Follow them with: faces compile:status`);
182
+ }
183
+ }
184
+ return { compiled, failed, scheduled, items: results };
185
+ }
186
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileDocCreate extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ content: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ perspective: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ };
15
+ static args: {
16
+ face_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
17
+ };
18
+ run(): Promise<unknown>;
19
+ }
@@ -0,0 +1,58 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { MEDIUM_MISSING_MESSAGE, MEDIUM_REQUIRED_DESCRIPTION, readTextFile, documentWarningLines, withoutWarnings } from '../../../utils.js';
4
+ import { FacesAPIError } from '../../../client.js';
5
+ export default class CompileDocCreate extends BaseCommand {
6
+ static description = 'Submit a document to a face. A document is the face\'s own writing, and every word in it is read ' +
7
+ 'as theirs. An interview, transcript or dialogue is a thread: upload it with ' +
8
+ 'faces compile:upload ALIAS --file FILE --kind thread --face-speaker NAME.';
9
+ static flags = {
10
+ ...BaseCommand.baseFlags,
11
+ label: Flags.string({ description: 'Document label/title' }),
12
+ content: Flags.string({ description: 'Inline text content', exclusive: ['file'] }),
13
+ file: Flags.string({ description: 'Read content from file' }),
14
+ medium: Flags.string({ description: MEDIUM_REQUIRED_DESCRIPTION }),
15
+ perspective: Flags.string({ description: 'Perspective (first-person or third-person)', options: ['first-person', 'third-person'], default: 'first-person' }),
16
+ };
17
+ static args = {
18
+ face_id: Args.string({ description: 'Face alias', required: true }),
19
+ };
20
+ async run() {
21
+ const { args, flags } = await this.parse(CompileDocCreate);
22
+ const client = this.makeClient(flags);
23
+ let content = flags.content;
24
+ if (flags.file) {
25
+ try {
26
+ content = readTextFile(flags.file);
27
+ }
28
+ catch (err) {
29
+ this.error(err instanceof Error ? err.message : String(err));
30
+ }
31
+ }
32
+ if (content === undefined)
33
+ this.error('Provide --content or --file.');
34
+ if (!content.trim())
35
+ this.error('--content is empty, or only whitespace.');
36
+ if (!flags.medium)
37
+ this.error(MEDIUM_MISSING_MESSAGE);
38
+ const payload = { alias: args.face_id, content, medium: flags.medium };
39
+ if (flags.label)
40
+ payload.label = flags.label;
41
+ if (flags.perspective)
42
+ payload.perspective = flags.perspective;
43
+ let data;
44
+ try {
45
+ data = await client.post('/v1/compile/documents', { body: payload });
46
+ }
47
+ catch (err) {
48
+ if (err instanceof FacesAPIError)
49
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
50
+ throw err;
51
+ }
52
+ if (!this.jsonEnabled())
53
+ this.printHuman(withoutWarnings(data));
54
+ for (const line of documentWarningLines(data, content, args.face_id, flags.file))
55
+ process.stderr.write(`${line}\n`);
56
+ return data;
57
+ }
58
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileDocDelete 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
+ doc_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 CompileDocDelete extends BaseCommand {
6
+ static description = "Delete a document and its content. To withdraw it from the face while KEEPING the material, use " +
7
+ 'compile:doc:reset instead: that withdraws what it contributed and keeps the document, so it can be ' +
8
+ 'recompiled without re-uploading.';
9
+ static flags = {
10
+ ...BaseCommand.baseFlags,
11
+ yes: Flags.boolean({ description: 'Skip confirmation', default: false }),
12
+ };
13
+ static args = {
14
+ doc_id: Args.string({ description: 'Document ID', required: true }),
15
+ };
16
+ async run() {
17
+ const { args, flags } = await this.parse(CompileDocDelete);
18
+ const client = this.makeClient(flags);
19
+ await this.confirmOrRefuse(`Delete document '${args.doc_id}' and its content? This cannot be undone.`, flags.yes);
20
+ let data;
21
+ try {
22
+ data = await client.delete(`/v1/compile/documents/${seg(args.doc_id)}`);
23
+ }
24
+ catch (err) {
25
+ if (err instanceof FacesAPIError)
26
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
27
+ throw err;
28
+ }
29
+ if (!this.jsonEnabled())
30
+ this.printHuman(data);
31
+ return data;
32
+ }
33
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileDocEdit extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
6
+ content: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ perspective: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ };
15
+ static args: {
16
+ doc_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
17
+ };
18
+ run(): Promise<unknown>;
19
+ }
@@ -0,0 +1,59 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../../base.js';
3
+ import { MEDIUM_EDIT_DESCRIPTION, seg, readTextFile, documentWarningLines, withoutWarnings } from '../../../utils.js';
4
+ import { FacesAPIError } from '../../../client.js';
5
+ export default class CompileDocEdit extends BaseCommand {
6
+ static description = 'Edit a document (label, content, or perspective)';
7
+ static flags = {
8
+ ...BaseCommand.baseFlags,
9
+ label: Flags.string({ description: 'New label/title' }),
10
+ content: Flags.string({ description: 'New inline text content', exclusive: ['file'] }),
11
+ file: Flags.string({ description: 'Read new content from file' }),
12
+ medium: Flags.string({ description: MEDIUM_EDIT_DESCRIPTION() }),
13
+ perspective: Flags.string({ description: 'Perspective (first-person or third-person)', options: ['first-person', 'third-person'] }),
14
+ };
15
+ static args = {
16
+ doc_id: Args.string({ description: 'Document ID', required: true }),
17
+ };
18
+ async run() {
19
+ const { args, flags } = await this.parse(CompileDocEdit);
20
+ const client = this.makeClient(flags);
21
+ const payload = {};
22
+ if (flags.label)
23
+ payload.label = flags.label;
24
+ if (flags.medium)
25
+ payload.medium = flags.medium;
26
+ if (flags.perspective)
27
+ payload.perspective = flags.perspective;
28
+ if (flags.file) {
29
+ try {
30
+ payload.content = readTextFile(flags.file);
31
+ }
32
+ catch (err) {
33
+ this.error(err instanceof Error ? err.message : String(err));
34
+ }
35
+ }
36
+ else if (flags.content) {
37
+ payload.content = flags.content;
38
+ }
39
+ if (Object.keys(payload).length === 0)
40
+ this.error('Provide at least one field to edit.');
41
+ let data;
42
+ try {
43
+ data = await client.patch(`/v1/compile/documents/${seg(args.doc_id)}`, { body: payload });
44
+ }
45
+ catch (err) {
46
+ if (err instanceof FacesAPIError)
47
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
48
+ throw err;
49
+ }
50
+ if (!this.jsonEnabled())
51
+ this.printHuman(withoutWarnings(data));
52
+ if (typeof payload.content === 'string') {
53
+ const alias = String(data?.alias ?? 'ALIAS');
54
+ for (const line of documentWarningLines(data, payload.content, alias, flags.file))
55
+ process.stderr.write(`${line}\n`);
56
+ }
57
+ return data;
58
+ }
59
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileDocGet extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ 'status-only': 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
+ doc_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
13
+ };
14
+ run(): Promise<unknown>;
15
+ }
@@ -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 { freshnessLines, seg } from '../../../utils.js';
5
+ export default class CompileDocGet extends BaseCommand {
6
+ static description = 'Get a document by ID. Says so when the text has moved on 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 document text. Hundreds of times smaller, and the ' +
12
+ 'right thing to poll with.',
13
+ default: false,
14
+ }),
15
+ };
16
+ static args = {
17
+ doc_id: Args.string({ description: 'Document ID', required: true }),
18
+ };
19
+ async run() {
20
+ const { args, flags } = await this.parse(CompileDocGet);
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/documents/${seg(args.doc_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 lines = freshnessLines(data, `faces compile:doc:make ${args.doc_id}`, args.doc_id);
35
+ if (lines.length > 0) {
36
+ this.log('');
37
+ for (const line of lines)
38
+ this.log(line);
39
+ }
40
+ }
41
+ return data;
42
+ }
43
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseCommand } from '../../../base.js';
2
+ export default class CompileDoc extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ content: 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
+ medium: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ perspective: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ timeout: import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
12
+ rush: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ 'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
+ };
19
+ static args: {
20
+ face_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
21
+ };
22
+ run(): Promise<unknown>;
23
+ private shape;
24
+ }