@faces-sh/cli 0.0.0-stage → 1.0.1

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 +43 -0
  171. package/dist/commands/face/share.d.ts +22 -0
  172. package/dist/commands/face/share.js +104 -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 +32 -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 +94 -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,190 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { chatgptLinked } from '../../style.js';
5
+ const VALID_KEYS = ['api_fallback', 'default_model', 'auto_style', 'auto_style_thresholds'];
6
+ const AUTO_STYLE_VALUES = ['on', 'off', 'default'];
7
+ export default class AccountPreferences extends BaseCommand {
8
+ static description = 'View or update account preferences: api_fallback, default_model, auto_style and ' +
9
+ 'auto_style_thresholds. auto_style builds each face\'s style on its own once it has enough of its ' +
10
+ 'own writing in a medium. It is on by default on Connect and Pro, and off on Free. A build runs at no ' +
11
+ 'charge on Connect or Pro with ChatGPT linked, and is otherwise charged to credits, so turning it on ' +
12
+ 'without a linked ChatGPT account needs --allow-paid. A build that credit cannot cover does not start, ' +
13
+ 'and is tried again later.';
14
+ static flags = {
15
+ ...BaseCommand.baseFlags,
16
+ 'allow-paid': Flags.boolean({
17
+ description: 'Permit turning auto_style on where automatic builds are charged to credits: on Free, and on Connect ' +
18
+ 'or Pro without ChatGPT linked. Not needed on Connect or Pro with ChatGPT linked, where they run at no charge.',
19
+ default: false,
20
+ }),
21
+ };
22
+ static args = {
23
+ key: Args.string({ description: `Preference key to update (${VALID_KEYS.join(', ')})` }),
24
+ value: Args.string({
25
+ description: 'New value. auto_style takes on, off or default (the plan\'s own: on for Connect and Pro, off for Free). ' +
26
+ 'auto_style_thresholds takes medium=words pairs separated by commas, where words is at least 500 ' +
27
+ 'and default puts that medium back, e.g. "email=25000,essay=default".',
28
+ }),
29
+ };
30
+ static examples = [
31
+ 'faces account:preferences',
32
+ 'faces account:preferences default_model gpt-5.4',
33
+ 'faces account:preferences api_fallback true',
34
+ 'faces account:preferences auto_style off',
35
+ 'faces account:preferences auto_style default',
36
+ 'faces account:preferences auto_style on --allow-paid',
37
+ 'faces account:preferences auto_style_thresholds "email=25000,text message=default"',
38
+ ];
39
+ async run() {
40
+ const { args, flags } = await this.parse(AccountPreferences);
41
+ const client = this.makeClient(flags);
42
+ if (!args.key) {
43
+ let data;
44
+ try {
45
+ data = await client.get('/v1/user/preferences');
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
+ await this.printPreferences(client, data);
54
+ return data;
55
+ }
56
+ if (!args.value)
57
+ this.error('Provide a value to set.');
58
+ if (!VALID_KEYS.includes(args.key)) {
59
+ this.error(`Unknown preference '${args.key}'. Valid keys: ${VALID_KEYS.join(', ')}`);
60
+ }
61
+ let parsedValue = args.value;
62
+ if (args.key === 'api_fallback') {
63
+ if (args.value !== 'true' && args.value !== 'false') {
64
+ this.error('api_fallback must be "true" or "false"');
65
+ }
66
+ parsedValue = args.value === 'true';
67
+ }
68
+ if (args.key === 'auto_style') {
69
+ if (!AUTO_STYLE_VALUES.includes(args.value)) {
70
+ this.error(`auto_style must be one of: ${AUTO_STYLE_VALUES.join(', ')}`);
71
+ }
72
+ if (args.value === 'on' && !flags['allow-paid'])
73
+ await this.refuseIfPaid(client);
74
+ }
75
+ if (args.key === 'auto_style_thresholds')
76
+ parsedValue = this.parseThresholds(args.value);
77
+ let data;
78
+ try {
79
+ data = await client.patch('/v1/user/preferences', { body: { [args.key]: parsedValue } });
80
+ }
81
+ catch (err) {
82
+ if (err instanceof FacesAPIError && err.statusCode === 422 && args.key === 'api_fallback' && parsedValue === false) {
83
+ this.error(`HTTP 422: ${err.message.split('\n')[0]}\nOn the Free plan every request runs on credits, so api_fallback stays on. ` +
84
+ 'It can be turned off on Connect or Pro: faces billing:subscription:activate');
85
+ }
86
+ if (err instanceof FacesAPIError)
87
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
88
+ throw err;
89
+ }
90
+ if (!this.jsonEnabled()) {
91
+ this.log(`Set ${args.key} = ${args.value}`);
92
+ this.log('');
93
+ await this.printPreferences(client, data);
94
+ }
95
+ return data;
96
+ }
97
+ async refuseIfPaid(client) {
98
+ let plan;
99
+ try {
100
+ const sub = (await client.get('/v1/billing/subscription'));
101
+ plan = typeof sub.plan === 'string' ? sub.plan : undefined;
102
+ }
103
+ catch {
104
+ plan = undefined;
105
+ }
106
+ if (plan === 'team')
107
+ return;
108
+ const paidPlan = plan === 'connect' || plan === 'pro';
109
+ const linked = paidPlan ? await chatgptLinked(client) : false;
110
+ if (paidPlan && linked === true)
111
+ return;
112
+ const name = plan === 'pro' ? 'Pro' : 'Connect';
113
+ this.error((!plan
114
+ ? 'Could not read the plan, so automatic builds may be charged to credits.\n'
115
+ : !paidPlan
116
+ ? `This account is on ${plan === 'free' ? 'the Free plan' : `the ${plan} plan`}, where every automatic build is charged to credits.\n`
117
+ : linked === false
118
+ ? `No ChatGPT account is linked, so on ${name} every automatic build is charged to credits.\n`
119
+ : 'Could not check for a linked ChatGPT account, so automatic builds may be charged to credits.\n') +
120
+ 'Re-run with --allow-paid if you mean that. On Connect or Pro with ChatGPT linked they run at no charge: ' +
121
+ (paidPlan ? 'faces auth:connect openai' : 'faces billing:subscription:activate'));
122
+ }
123
+ parseThresholds(raw) {
124
+ const out = {};
125
+ for (const part of raw.split(',')) {
126
+ if (!part.trim())
127
+ continue;
128
+ const at = part.lastIndexOf('=');
129
+ if (at === -1)
130
+ this.error(`'${part.trim()}' is not medium=words. Example: "email=25000,essay=default"`);
131
+ const medium = part.slice(0, at).trim();
132
+ const value = part.slice(at + 1).trim();
133
+ if (!medium)
134
+ this.error(`'${part.trim()}' names no medium.`);
135
+ if (value === 'default' || value === 'null') {
136
+ out[medium] = null;
137
+ continue;
138
+ }
139
+ if (!/^\d+$/.test(value))
140
+ this.error(`'${value}' for ${medium} is not a whole number of words, or default.`);
141
+ out[medium] = Number(value);
142
+ }
143
+ if (Object.keys(out).length === 0)
144
+ this.error('Give at least one medium=words pair.');
145
+ return out;
146
+ }
147
+ async printPreferences(client, prefs) {
148
+ const shown = new Set(['auto_style', 'auto_style_setting', 'auto_style_thresholds']);
149
+ for (const [k, v] of Object.entries(prefs)) {
150
+ if (shown.has(k))
151
+ continue;
152
+ this.log(`${k}: ${v === null || v === undefined ? '-' : v}`);
153
+ }
154
+ if (!('auto_style' in prefs))
155
+ return;
156
+ let plan;
157
+ try {
158
+ const sub = (await client.get('/v1/billing/subscription'));
159
+ plan = typeof sub.plan === 'string' ? sub.plan : undefined;
160
+ }
161
+ catch {
162
+ plan = undefined;
163
+ }
164
+ const on = prefs.auto_style === true;
165
+ const setting = prefs.auto_style_setting;
166
+ const why = setting === null || setting === undefined ? 'the plan\'s default' : 'set by you';
167
+ let cost = '';
168
+ if (on && (plan === 'connect' || plan === 'pro')) {
169
+ const linked = await chatgptLinked(client);
170
+ cost = linked === true
171
+ ? ', at no charge on your linked ChatGPT account'
172
+ : linked === false
173
+ ? ', charged to credits until ChatGPT is linked'
174
+ : ', at no charge with ChatGPT linked, otherwise charged to credits';
175
+ }
176
+ else if (on && plan && plan !== 'team') {
177
+ cost = ', charged to credits';
178
+ }
179
+ this.log(`auto_style: ${on ? 'on' : 'off'} (${why}${cost})`);
180
+ const thresholds = prefs.auto_style_thresholds;
181
+ if (thresholds && typeof thresholds === 'object' && Object.keys(thresholds).length > 0) {
182
+ this.log('auto_style_thresholds (words of the face\'s own writing before a build runs):');
183
+ const width = Math.max(...Object.keys(thresholds).map((m) => m.length)) + 1;
184
+ for (const [medium, words] of Object.entries(thresholds)) {
185
+ const note = medium === 'other' ? ' (never built automatically)' : '';
186
+ this.log(` ${(medium + ':').padEnd(width)} ${words}${note}`);
187
+ }
188
+ }
189
+ }
190
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AccountState 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
+ run(): Promise<unknown>;
11
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ import { FacesAPIError } from '../../client.js';
3
+ export default class AccountState extends BaseCommand {
4
+ static description = 'Your plan, balance and onboarding.';
5
+ static flags = {
6
+ ...BaseCommand.baseFlags,
7
+ };
8
+ async run() {
9
+ const { flags } = await this.parse(AccountState);
10
+ const client = this.makeClient(flags);
11
+ let data;
12
+ try {
13
+ data = await client.get('/v1/account/state');
14
+ }
15
+ catch (err) {
16
+ if (err instanceof FacesAPIError)
17
+ this.error(`HTTP ${err.statusCode}: ${err.message}`);
18
+ throw err;
19
+ }
20
+ if (!this.jsonEnabled())
21
+ this.printHuman(data);
22
+ return data;
23
+ }
24
+ }
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthConnect extends BaseCommand {
3
+ static description: string;
4
+ static args: {
5
+ provider: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
6
+ };
7
+ static flags: {
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 examples: string[];
14
+ run(): Promise<unknown>;
15
+ private startDevice;
16
+ private handleStartError;
17
+ }
@@ -0,0 +1,190 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ const HARD_STOP_MS = 15 * 60 * 1000;
5
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
6
+ const emit = (msg = '') => process.stderr.write(msg + '\n');
7
+ function unwrap(raw, key) {
8
+ const r = raw;
9
+ if (r && typeof r === 'object' && !(key in r) && r.data && typeof r.data === 'object') {
10
+ return r.data;
11
+ }
12
+ return raw;
13
+ }
14
+ function planLabel(plan) {
15
+ if (!plan)
16
+ return '';
17
+ return plan.charAt(0).toUpperCase() + plan.slice(1);
18
+ }
19
+ export default class AuthConnect extends BaseCommand {
20
+ static description = 'Link your ChatGPT account by device-code authorization (Connect and Pro). Codex-eligible models then run on the ChatGPT plan, at /v1/responses.';
21
+ static args = {
22
+ provider: Args.string({
23
+ description: 'OAuth provider to connect',
24
+ required: true,
25
+ options: ['openai'],
26
+ }),
27
+ };
28
+ static flags = {
29
+ ...BaseCommand.baseFlags,
30
+ };
31
+ static examples = [
32
+ '<%= config.bin %> auth:connect openai',
33
+ '<%= config.bin %> auth:connect openai --json',
34
+ ];
35
+ async run() {
36
+ const { flags } = await this.parse(AuthConnect);
37
+ const client = this.makeClient(flags, true);
38
+ try {
39
+ const existing = (await client.get('/v1/oauth', { requireJwt: true }));
40
+ const row = existing.find((r) => r.provider === 'openai');
41
+ if (row) {
42
+ const email = row.account_email ?? null;
43
+ const plan = row.chatgpt_plan_type ?? null;
44
+ const output = { provider: 'openai', connected: true, already_connected: true, account_email: email, chatgpt_plan_type: plan };
45
+ if (!this.jsonEnabled()) {
46
+ const who = email ? ` as ${email}` : '';
47
+ const tier = plan ? ` (${planLabel(plan)})` : '';
48
+ this.log(`Already connected to ChatGPT${who}${tier}. Run 'faces auth:disconnect openai' to reconnect.`);
49
+ }
50
+ return output;
51
+ }
52
+ }
53
+ catch {
54
+ }
55
+ let start;
56
+ try {
57
+ start = await this.startDevice(client);
58
+ }
59
+ catch (err) {
60
+ this.handleStartError(err);
61
+ }
62
+ const verificationUri = start.verification_uri;
63
+ if (!verificationUri)
64
+ this.error('The server did not return a sign-in address. Try again in a moment.');
65
+ let done = false;
66
+ const onSigint = () => {
67
+ if (done)
68
+ return;
69
+ done = true;
70
+ emit('\nAborted. Cancelling device authorization…');
71
+ Promise.race([
72
+ client.post('/v1/oauth/openai/device/cancel', { requireJwt: true, body: { device_auth_id: start.device_auth_id } }).catch(() => { }),
73
+ sleep(2000),
74
+ ]).finally(() => process.exit(130));
75
+ };
76
+ process.once('SIGINT', onSigint);
77
+ emit('');
78
+ emit('To connect ChatGPT:');
79
+ emit(` 1. Open this URL in any browser (phone, laptop, anywhere):`);
80
+ emit(` ${verificationUri}`);
81
+ emit(` 2. Enter this code: ${start.user_code}`);
82
+ emit(` 3. Sign in to ChatGPT and click Continue.`);
83
+ emit('');
84
+ emit('If this is your first time, you may need to enable device-code authorization in ChatGPT first:');
85
+ emit(" 1. In ChatGPT's Security settings, turn on device code authorization");
86
+ emit(' 2. Then enter the code above');
87
+ emit('');
88
+ emit('Waiting for approval (the code expires in 15 minutes; press Ctrl-C to cancel)…');
89
+ const startedAt = Date.now();
90
+ const expiresAt = Date.parse(start.expires_at);
91
+ let intervalMs = Math.max(1, start.interval || 5) * 1000;
92
+ for (;;) {
93
+ const now = Date.now();
94
+ if (now - startedAt > HARD_STOP_MS || (!Number.isNaN(expiresAt) && now >= expiresAt)) {
95
+ process.removeListener('SIGINT', onSigint);
96
+ this.error('The code expired before it was approved. Run `faces auth:connect openai` again to get a new code.');
97
+ }
98
+ await sleep(intervalMs);
99
+ let poll;
100
+ try {
101
+ const raw = await client.post('/v1/oauth/openai/device/poll', {
102
+ requireJwt: true,
103
+ body: { device_auth_id: start.device_auth_id },
104
+ });
105
+ poll = unwrap(raw, 'status');
106
+ }
107
+ catch (err) {
108
+ if (err instanceof FacesAPIError && (err.statusCode === 502 || err.statusCode === 503)) {
109
+ process.stderr.write('.');
110
+ continue;
111
+ }
112
+ process.removeListener('SIGINT', onSigint);
113
+ if (err instanceof FacesAPIError)
114
+ this.error(`Polling failed (${err.statusCode}): ${err.message}`);
115
+ throw err;
116
+ }
117
+ if (poll.status === 'completed') {
118
+ done = true;
119
+ process.removeListener('SIGINT', onSigint);
120
+ const email = poll.account_email ?? null;
121
+ const plan = poll.chatgpt_plan_type ?? null;
122
+ const output = { provider: 'openai', connected: true, account_email: email, chatgpt_plan_type: plan };
123
+ if (!this.jsonEnabled()) {
124
+ const who = email ? ` as ${email}` : '';
125
+ const tier = plan ? ` (${planLabel(plan)})` : '';
126
+ this.log(`\n✅ ChatGPT connected${who}${tier}.`);
127
+ if (!plan || plan === 'free') {
128
+ this.log('⚠️ Your ChatGPT plan may not include API access. Connecting requires a paid plan (Plus/Pro/Team, etc.).');
129
+ }
130
+ else {
131
+ this.log('Codex-eligible models (see faces models:list --chatgpt) now run on your ChatGPT plan, at /v1/responses.');
132
+ }
133
+ }
134
+ return output;
135
+ }
136
+ if (poll.status === 'expired') {
137
+ process.removeListener('SIGINT', onSigint);
138
+ this.error('The code expired or was not recognized. Run `faces auth:connect openai` again to get a new code.');
139
+ }
140
+ intervalMs = (poll.retry_after && poll.retry_after > 0 ? poll.retry_after : (start.interval || 5)) * 1000;
141
+ process.stderr.write('.');
142
+ }
143
+ }
144
+ async startDevice(client) {
145
+ let attempts502 = 0;
146
+ let attempts503 = 0;
147
+ for (;;) {
148
+ try {
149
+ const raw = await client.post('/v1/oauth/openai/device/start', { requireJwt: true });
150
+ return unwrap(raw, 'device_auth_id');
151
+ }
152
+ catch (err) {
153
+ if (err instanceof FacesAPIError && err.statusCode === 503 && attempts503 < 4) {
154
+ attempts503++;
155
+ emit('OpenAI is temporarily unavailable, retrying…');
156
+ await sleep(2000);
157
+ continue;
158
+ }
159
+ if (err instanceof FacesAPIError && err.statusCode === 502 && attempts502 < 2) {
160
+ attempts502++;
161
+ emit('OpenAI returned an error, retrying…');
162
+ await sleep(2000);
163
+ continue;
164
+ }
165
+ throw err;
166
+ }
167
+ }
168
+ }
169
+ handleStartError(err) {
170
+ if (err instanceof FacesAPIError) {
171
+ if (err.statusCode === 401) {
172
+ this.error('Your Faces session is missing or expired. Run `faces auth:login` and try again.');
173
+ }
174
+ if (err.statusCode === 403 || err.errorCode === 'connect_plan_required') {
175
+ this.error('Connecting ChatGPT requires the Connect or Pro plan.\n' +
176
+ 'Subscribe with: faces billing:subscription:activate --plan connect');
177
+ }
178
+ if (err.statusCode === 422 || err.errorCode === 'device_auth_not_enabled') {
179
+ const steps = [
180
+ "In ChatGPT's Security settings, turn on device code authorization",
181
+ 'Then run `faces auth:connect openai` again',
182
+ ];
183
+ this.error('Device-code authorization is not enabled on your ChatGPT account yet:\n' +
184
+ steps.map((s, i) => ` ${i + 1}. ${s}`).join('\n'));
185
+ }
186
+ this.error(`Failed to start device authorization (${err.statusCode}): ${err.message}`);
187
+ }
188
+ throw err;
189
+ }
190
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthConnections 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 examples: string[];
11
+ run(): Promise<unknown>;
12
+ }
@@ -0,0 +1,40 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthConnections extends BaseCommand {
3
+ static description = 'List connected OAuth provider accounts';
4
+ static flags = {
5
+ ...BaseCommand.baseFlags,
6
+ };
7
+ static examples = [
8
+ '<%= config.bin %> auth:connections',
9
+ '<%= config.bin %> auth:connections --json',
10
+ ];
11
+ async run() {
12
+ const { flags } = await this.parse(AuthConnections);
13
+ const client = this.makeClient(flags);
14
+ const data = await client.get('/v1/oauth', { requireJwt: true });
15
+ if (!this.jsonEnabled()) {
16
+ const rows = data;
17
+ if (!rows || rows.length === 0) {
18
+ this.log('No connected providers.');
19
+ }
20
+ else {
21
+ for (const row of rows) {
22
+ if (row.provider === 'openai') {
23
+ const plan = row.chatgpt_plan_type;
24
+ const label = plan ? plan.charAt(0).toUpperCase() + plan.slice(1) : null;
25
+ const who = row.account_email ? ` as ${row.account_email}` : '';
26
+ const tier = label ? ` (${label})` : '';
27
+ this.log(`openai connected${who}${tier} connected_at=${row.connected_at}`);
28
+ if (!plan || plan === 'free') {
29
+ this.log(' ⚠️ This ChatGPT plan may not include API access. Connecting requires a paid plan (Plus/Pro/Team, etc.).');
30
+ }
31
+ }
32
+ else {
33
+ this.log(`${row.provider} connected_at=${row.connected_at}${row.scope ? ` scope=${row.scope}` : ''}`);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return data;
39
+ }
40
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthDisconnect extends BaseCommand {
3
+ static description: string;
4
+ static args: {
5
+ provider: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
6
+ };
7
+ static flags: {
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 examples: string[];
14
+ run(): Promise<unknown>;
15
+ }
@@ -0,0 +1,49 @@
1
+ import { Args } 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 AuthDisconnect extends BaseCommand {
6
+ static description = 'Disconnect a linked OAuth provider account';
7
+ static args = {
8
+ provider: Args.string({
9
+ description: 'OAuth provider to disconnect',
10
+ required: true,
11
+ options: ['openai'],
12
+ }),
13
+ };
14
+ static flags = {
15
+ ...BaseCommand.baseFlags,
16
+ };
17
+ static examples = [
18
+ '<%= config.bin %> auth:disconnect openai',
19
+ ];
20
+ async run() {
21
+ const { args, flags } = await this.parse(AuthDisconnect);
22
+ const client = this.makeClient(flags, true);
23
+ try {
24
+ const rows = (await client.get('/v1/oauth', { requireJwt: true }));
25
+ if (Array.isArray(rows) && !rows.some((r) => r.provider === args.provider)) {
26
+ this.error(`No ${args.provider} account is connected, so there is nothing to disconnect. See: faces auth:connections`);
27
+ }
28
+ }
29
+ catch (err) {
30
+ if (!(err instanceof FacesAPIError))
31
+ throw err;
32
+ }
33
+ try {
34
+ await client.delete(`/v1/oauth/${seg(args.provider)}`, { requireJwt: true });
35
+ }
36
+ catch (err) {
37
+ if (err instanceof FacesAPIError) {
38
+ if (err.statusCode === 404)
39
+ this.error(`No connected ${args.provider} account found.`);
40
+ this.error(`Disconnect failed (${err.statusCode}): ${err.message}`);
41
+ }
42
+ throw err;
43
+ }
44
+ const output = { provider: args.provider, connected: false };
45
+ if (!this.jsonEnabled())
46
+ this.log(`✅ ${args.provider} disconnected.`);
47
+ return output;
48
+ }
49
+ }
@@ -0,0 +1,13 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthLogin extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ email: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
6
+ password: import("@oclif/core/interfaces").OptionFlag<string | undefined, 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
+ run(): Promise<unknown>;
13
+ }
@@ -0,0 +1,42 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { saveCredentials, resolveBaseUrl } from '../../config.js';
5
+ export default class AuthLogin extends BaseCommand {
6
+ static description = 'Login and save JWT credentials';
7
+ static flags = {
8
+ ...BaseCommand.baseFlags,
9
+ email: Flags.string({ description: 'Account email', required: true }),
10
+ password: Flags.string({ description: 'Account password. Leave it out to be asked for it, without it showing as you type' }),
11
+ };
12
+ async run() {
13
+ const { flags } = await this.parse(AuthLogin);
14
+ const password = await this.secretOrPrompt(flags.password, 'password', 'Password');
15
+ const baseUrl = resolveBaseUrl(flags['base-url']);
16
+ const { FacesClient } = await import('../../client.js');
17
+ const client = new FacesClient(baseUrl);
18
+ let data;
19
+ try {
20
+ data = (await client.postNoAuth('/auth/login', {
21
+ email: flags.email,
22
+ password,
23
+ }));
24
+ }
25
+ catch (err) {
26
+ if (err instanceof FacesAPIError) {
27
+ this.error(`Login failed (${err.statusCode}): ${err.message}`);
28
+ }
29
+ throw err;
30
+ }
31
+ const inner = (data.data ?? data);
32
+ const token = (inner.access_token ?? inner.token);
33
+ const userId = inner.user_id ?? inner.id ?? inner.user?.id;
34
+ if (!token)
35
+ this.error(`Unexpected response: ${JSON.stringify(data)}`);
36
+ saveCredentials({ token, user_id: userId ? String(userId) : undefined }, baseUrl);
37
+ const result = { status: 'logged_in', user_id: userId };
38
+ if (!this.jsonEnabled())
39
+ this.printHuman(result);
40
+ return result;
41
+ }
42
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthLogout 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
+ run(): Promise<unknown>;
11
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ import { clearConfig } from '../../config.js';
3
+ export default class AuthLogout extends BaseCommand {
4
+ static description = 'Clear saved credentials';
5
+ static flags = {
6
+ ...BaseCommand.baseFlags,
7
+ };
8
+ async run() {
9
+ await this.parse(AuthLogout);
10
+ clearConfig();
11
+ this.log('Logged out. Credentials cleared.');
12
+ return { status: 'logged_out' };
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class AuthRefresh 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
+ run(): Promise<unknown>;
11
+ }