@faces-sh/cli 1.0.0 → 1.0.2

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 (49) hide show
  1. package/README.md +32 -7
  2. package/dist/commands/auth/connections.js +1 -1
  3. package/dist/commands/billing/card/default.js +1 -1
  4. package/dist/commands/billing/card/remove.js +1 -1
  5. package/dist/commands/billing/card-setup.js +1 -1
  6. package/dist/commands/billing/subscription/activate.js +2 -2
  7. package/dist/commands/billing/subscription/cancel.js +1 -1
  8. package/dist/commands/billing/subscription/plan.js +1 -1
  9. package/dist/commands/billing/topup.js +2 -2
  10. package/dist/commands/causes.d.ts +6 -2
  11. package/dist/commands/causes.js +11 -0
  12. package/dist/commands/chat/chat.d.ts +12 -7
  13. package/dist/commands/chat/chat.js +19 -6
  14. package/dist/commands/chat/messages.d.ts +10 -6
  15. package/dist/commands/chat/messages.js +10 -1
  16. package/dist/commands/chat/responses.d.ts +10 -6
  17. package/dist/commands/chat/responses.js +10 -1
  18. package/dist/commands/chat/thread.d.ts +17 -10
  19. package/dist/commands/chat/thread.js +20 -6
  20. package/dist/commands/conversation/add.d.ts +18 -0
  21. package/dist/commands/conversation/add.js +66 -0
  22. package/dist/commands/conversation/close.d.ts +16 -0
  23. package/dist/commands/conversation/close.js +36 -0
  24. package/dist/commands/conversation/compact.d.ts +16 -0
  25. package/dist/commands/conversation/compact.js +69 -0
  26. package/dist/commands/conversation/create.d.ts +19 -0
  27. package/dist/commands/conversation/create.js +76 -0
  28. package/dist/commands/conversation/get.d.ts +15 -0
  29. package/dist/commands/conversation/get.js +35 -0
  30. package/dist/commands/conversation/items.d.ts +15 -0
  31. package/dist/commands/conversation/items.js +45 -0
  32. package/dist/commands/decide.d.ts +8 -4
  33. package/dist/commands/decide.js +10 -0
  34. package/dist/commands/face/delete.js +1 -1
  35. package/dist/commands/face/publish.js +1 -0
  36. package/dist/commands/face/share.js +1 -0
  37. package/dist/commands/face/unpublish.js +1 -0
  38. package/dist/commands/face/unshare.js +1 -1
  39. package/dist/commands/session/close.js +1 -1
  40. package/dist/commands/session/compact.js +1 -1
  41. package/dist/commands/session/create.js +1 -1
  42. package/dist/commands/session/get.js +1 -1
  43. package/dist/commands/style/delete.js +16 -14
  44. package/dist/conversation.d.ts +63 -0
  45. package/dist/conversation.js +237 -0
  46. package/dist/utils.d.ts +1 -1
  47. package/dist/utils.js +4 -3
  48. package/oclif.manifest.json +3007 -2319
  49. package/package.json +4 -1
@@ -4,6 +4,7 @@ import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { BaseCommand } from '../../base.js';
7
+ import { conversationFields, conversationTurnFlags } from '../../conversation.js';
7
8
  import { FacesAPIError } from '../../client.js';
8
9
  import { postChat, streamChat, resolveCause, CAUSE_FLAG_DESCRIPTION, CAUSE_FILE_FLAG_DESCRIPTION, retryOnceOnWarmUp, sayWarmUp, faceRefusalHint, STREAM_FLAG_DESCRIPTION, extractCause, extractStreamDelta, FACES_REASONING_ITEM_PREFIX, FACES_THINKING_SIGNATURE, extractStreamReasoning, isMaxTokensRenameError, MIN_MAX_OUTPUT_TOKENS, STYLE_FLAG_DESCRIPTION, MEDIUM_FLAG_DESCRIPTION, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION, chatExtras, reasoningHeading, REASONING_FLAG_DESCRIPTION, parseTemperature } from '../../utils.js';
9
10
  import { resolveEndpoint, isCompositeFormula, llmFromArg, MESSAGES_ENDPOINT, RESPONSES_ENDPOINT, CHAT_COMPLETIONS_ENDPOINT } from '../../routing.js';
@@ -122,6 +123,7 @@ export default class ChatThread extends BaseCommand {
122
123
  stream: Flags.boolean({ description: STREAM_FLAG_DESCRIPTION, default: true, allowNo: true }),
123
124
  style: Flags.string({ description: `${STYLE_FLAG_DESCRIPTION} For this turn only.` }),
124
125
  medium: Flags.string({ description: `${MEDIUM_FLAG_DESCRIPTION} For this turn only.` }),
126
+ ...conversationTurnFlags({ suffix: 'For this turn only. Only the new message is sent: the conversation holds the rest.' }),
125
127
  session: Flags.string({ description: `${SESSION_FLAG_DESCRIPTION} For this turn only.` }),
126
128
  compaction: Flags.string({ description: `${COMPACTION_FLAG_DESCRIPTION} For this turn only.` }),
127
129
  'oauth-only': Flags.boolean({ description: 'On a linked ChatGPT plan, run there or fail: never fall back to credits', default: false }),
@@ -224,6 +226,13 @@ export default class ChatThread extends BaseCommand {
224
226
  else {
225
227
  this.error('Provide --message/-m or --file');
226
228
  }
229
+ try {
230
+ this.conversationBody = conversationFields(flags);
231
+ }
232
+ catch (err) {
233
+ this.error(err instanceof Error ? err.message : String(err));
234
+ }
235
+ this.newOnly = Boolean(flags.conversation || flags.session);
227
236
  const client = this.makeClient(flags);
228
237
  let thread;
229
238
  if (flags.id) {
@@ -333,18 +342,23 @@ export default class ChatThread extends BaseCommand {
333
342
  throw err;
334
343
  }
335
344
  }
345
+ conversationBody = {};
346
+ newOnly = false;
347
+ sent(thread) {
348
+ return this.newOnly ? thread.messages.slice(-1) : thread.messages;
349
+ }
336
350
  async sendChatCompletions(client, thread, flags) {
337
351
  const messages = [];
338
352
  if (thread.system)
339
353
  messages.push({ role: 'system', content: thread.system });
340
- for (const m of thread.messages)
354
+ for (const m of this.sent(thread))
341
355
  messages.push(chatTurn(m));
342
356
  const payload = { model: thread.model, messages, stream: flags.stream };
343
357
  if (flags['max-tokens'])
344
358
  payload.max_tokens = flags['max-tokens'];
345
359
  if (flags.temperature !== undefined)
346
360
  payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
347
- Object.assign(payload, chatExtras(flags));
361
+ Object.assign(payload, chatExtras(flags), this.conversationBody);
348
362
  if (flags['oauth-only'])
349
363
  payload.oauth_only = true;
350
364
  if (flags.cause)
@@ -370,7 +384,7 @@ export default class ChatThread extends BaseCommand {
370
384
  return replyOf(data, CHAT_COMPLETIONS_ENDPOINT);
371
385
  }
372
386
  async sendResponses(client, thread, flags) {
373
- const input = thread.messages.flatMap((m) => responsesTurns(m));
387
+ const input = this.sent(thread).flatMap((m) => responsesTurns(m));
374
388
  const payload = { model: thread.model, input, stream: flags.stream };
375
389
  if (thread.system)
376
390
  payload.instructions = thread.system;
@@ -383,7 +397,7 @@ export default class ChatThread extends BaseCommand {
383
397
  }
384
398
  if (flags.temperature !== undefined)
385
399
  payload.temperature = parseTemperature(flags.temperature, (m) => this.error(m));
386
- Object.assign(payload, chatExtras(flags));
400
+ Object.assign(payload, chatExtras(flags), this.conversationBody);
387
401
  if (flags['oauth-only'])
388
402
  payload.oauth_only = true;
389
403
  if (flags.cause)
@@ -395,7 +409,7 @@ export default class ChatThread extends BaseCommand {
395
409
  return replyOf(data, RESPONSES_ENDPOINT);
396
410
  }
397
411
  async sendAnthropic(client, thread, flags) {
398
- const msgs = thread.messages.map((m) => messagesTurn(m));
412
+ const msgs = this.sent(thread).map((m) => messagesTurn(m));
399
413
  const payload = {
400
414
  model: thread.model,
401
415
  messages: msgs,
@@ -404,7 +418,7 @@ export default class ChatThread extends BaseCommand {
404
418
  };
405
419
  if (thread.system)
406
420
  payload.system = thread.system;
407
- Object.assign(payload, chatExtras(flags));
421
+ Object.assign(payload, chatExtras(flags), this.conversationBody);
408
422
  if (flags['oauth-only'])
409
423
  payload.oauth_only = true;
410
424
  if (flags.cause)
@@ -0,0 +1,18 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ConversationAdd extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ 'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ };
14
+ static args: {
15
+ conversation_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
16
+ };
17
+ run(): Promise<unknown>;
18
+ }
@@ -0,0 +1,66 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, clientItems, conversationHint, itemLines, parsePremises, premiseLines, staleDecisionLines, } from '../../conversation.js';
5
+ import { seg } from '../../utils.js';
6
+ export default class ConversationAdd extends BaseCommand {
7
+ static description = 'Add your own messages and premises to a conversation, without a face answering. Premises go in ' +
8
+ 'first, then messages. A newer value of a key replaces it from here on, and every earlier decision ' +
9
+ 'made while that key held a different value is listed, so you can choose which to ask again: nothing ' +
10
+ `is decided again for you. At most ${MAX_CONVERSATION_ITEMS} at a time. Free.`;
11
+ static examples = [
12
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID --premise vendor_certified=false',
13
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
14
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID -m "The vendor sent their audit report."',
15
+ ];
16
+ static flags = {
17
+ ...BaseCommand.baseFlags,
18
+ message: Flags.string({ char: 'm', description: 'A message of yours (repeatable, kept in order).', multiple: true }),
19
+ premise: Flags.string({ description: PREMISE_FLAG_DESCRIPTION, multiple: true }),
20
+ 'premise-description': Flags.string({ description: PREMISE_DESCRIPTION_FLAG_DESCRIPTION, multiple: true }),
21
+ };
22
+ static args = {
23
+ conversation_id: Args.string({ description: 'Conversation id (from conversation:create)', required: true }),
24
+ };
25
+ async run() {
26
+ const { args, flags } = await this.parse(ConversationAdd);
27
+ const client = this.makeClient(flags);
28
+ let items;
29
+ try {
30
+ items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description']));
31
+ }
32
+ catch (err) {
33
+ this.error(err instanceof Error ? err.message : String(err));
34
+ }
35
+ if (items.length === 0)
36
+ this.error('Nothing to add: give a message with -m, or a premise with --premise key=value.');
37
+ if (items.length > MAX_CONVERSATION_ITEMS) {
38
+ this.error(`At most ${MAX_CONVERSATION_ITEMS} messages and premises at a time (got ${items.length}). Split them across calls.`);
39
+ }
40
+ let data;
41
+ try {
42
+ data = (await client.post(`${CONVERSATIONS_PATH}/${seg(args.conversation_id)}/items`, { body: { items } }));
43
+ }
44
+ catch (err) {
45
+ if (err instanceof FacesAPIError) {
46
+ const hint = conversationHint(err);
47
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
48
+ }
49
+ throw err;
50
+ }
51
+ if (!this.jsonEnabled()) {
52
+ for (const line of itemLines(data.data ?? []))
53
+ this.log(line);
54
+ this.log('');
55
+ for (const line of premiseLines(data.premises))
56
+ this.log(line);
57
+ const stale = staleDecisionLines(data.decisions_made_under_old_values);
58
+ if (stale.length > 0) {
59
+ this.log('');
60
+ for (const line of stale)
61
+ this.log(line);
62
+ }
63
+ }
64
+ return data;
65
+ }
66
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ConversationClose extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ yes: 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
+ conversation_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
14
+ };
15
+ run(): Promise<unknown>;
16
+ }
@@ -0,0 +1,36 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { CONVERSATIONS_PATH, conversationHint } from '../../conversation.js';
5
+ import { seg } from '../../utils.js';
6
+ export default class ConversationClose extends BaseCommand {
7
+ static description = 'Close a conversation. A closed conversation takes no more turns and cannot be read or compacted. Its ' +
8
+ 'compactions stay usable until they expire. Free.';
9
+ static examples = ['<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID --yes'];
10
+ static flags = {
11
+ ...BaseCommand.baseFlags,
12
+ yes: Flags.boolean({ description: 'Skip confirmation', default: false }),
13
+ };
14
+ static args = {
15
+ conversation_id: Args.string({ description: 'Conversation id (from conversation:create)', required: true }),
16
+ };
17
+ async run() {
18
+ const { args, flags } = await this.parse(ConversationClose);
19
+ const client = this.makeClient(flags);
20
+ await this.confirmOrRefuse(`Close conversation ${args.conversation_id}? It cannot be reopened.`, flags.yes);
21
+ let data;
22
+ try {
23
+ data = await client.delete(`${CONVERSATIONS_PATH}/${seg(args.conversation_id)}`);
24
+ }
25
+ catch (err) {
26
+ if (err instanceof FacesAPIError) {
27
+ const hint = conversationHint(err);
28
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
29
+ }
30
+ throw err;
31
+ }
32
+ if (!this.jsonEnabled())
33
+ this.log(`Closed conversation ${args.conversation_id}.`);
34
+ return data;
35
+ }
36
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ConversationCompact extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
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
+ conversation_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
13
+ face: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
14
+ };
15
+ run(): Promise<unknown>;
16
+ }
@@ -0,0 +1,69 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { heldDecisionError } from '../../decisions.js';
5
+ import { CONVERSATIONS_PATH, conversationHint } from '../../conversation.js';
6
+ import { retryOnceOnWarmUp, sayWarmUp, seg } from '../../utils.js';
7
+ export default class ConversationCompact extends BaseCommand {
8
+ static description = 'Compact a conversation: a summary of one face\'s position over the conversation, in the face\'s own ' +
9
+ 'terms, stored under a compaction id. Pass that id with --compaction on a later request with the same ' +
10
+ 'face. A conversation that takes any face needs the face named. Billed at the cause rate on the tokens ' +
11
+ 'it reads and writes; on Connect and Pro it counts against the cause allowance. A failed compaction is ' +
12
+ 'not charged. A compaction expires 30 days after it is written.';
13
+ static examples = [
14
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID',
15
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID alice --json',
16
+ ];
17
+ static flags = {
18
+ ...BaseCommand.baseFlags,
19
+ };
20
+ static args = {
21
+ conversation_id: Args.string({ description: 'Conversation id (from conversation:create)', required: true }),
22
+ face: Args.string({
23
+ description: 'The face to compact, alone (no @model). Needed when the conversation takes any face; a ' +
24
+ 'conversation opened with one face compacts that face.',
25
+ required: false,
26
+ }),
27
+ };
28
+ async run() {
29
+ const { args, flags } = await this.parse(ConversationCompact);
30
+ const client = this.makeClient(flags);
31
+ const json = this.jsonEnabled();
32
+ const face = args.face?.trim();
33
+ if (face?.includes('@'))
34
+ this.error(`Compact a face alone, so leave the model off: ${face.slice(0, face.lastIndexOf('@'))}`);
35
+ let data;
36
+ try {
37
+ data = (await retryOnceOnWarmUp(async () => {
38
+ const res = await client.post(`${CONVERSATIONS_PATH}/${seg(args.conversation_id)}/compact`, { body: face ? { model: face } : {} });
39
+ const held = heldDecisionError(res);
40
+ if (held)
41
+ throw held;
42
+ return res;
43
+ }, json ? undefined : sayWarmUp));
44
+ }
45
+ catch (err) {
46
+ if (err instanceof FacesAPIError) {
47
+ if (err.statusCode === 422 && !face && /takes any face/.test(err.message)) {
48
+ this.error(`HTTP ${err.statusCode}: ${err.message}\nName the face: faces conversation:compact ${args.conversation_id} <face>`);
49
+ }
50
+ const hint = conversationHint(err);
51
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
52
+ }
53
+ throw err;
54
+ }
55
+ if (!json) {
56
+ if (typeof data.cause === 'string')
57
+ this.log(data.cause);
58
+ this.log('');
59
+ this.log(`compaction: ${data.compaction_id ?? '-'}`);
60
+ if (data.turns !== undefined)
61
+ this.log(`turns: ${data.turns}`);
62
+ if (data.expires_at)
63
+ this.log(`expires: ${data.expires_at}`);
64
+ if (data.compaction_id)
65
+ this.log(`\nUse it with: faces chat:chat ${face ?? '<face>'}@<model> --compaction ${data.compaction_id} -m "..."`);
66
+ }
67
+ return data;
68
+ }
69
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ConversationCreate extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ 'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ message: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ 'premise-description': 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
+ face: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
17
+ };
18
+ run(): Promise<unknown>;
19
+ }
@@ -0,0 +1,76 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, clientItems, conversationHint, conversationLines, parsePremises, } from '../../conversation.js';
5
+ export default class ConversationCreate extends BaseCommand {
6
+ static description = 'Start a conversation. The server keeps the whole conversation: your messages, each face\'s reply with ' +
7
+ 'its cause, decisions, and premises (named facts you declare). Pass its id with --conversation on chat, ' +
8
+ 'causes or decide and send only what is new. Name a face and the conversation takes that face only; ' +
9
+ 'leave it out and it takes any of your faces. Opening one is free; each turn costs what it costs ' +
10
+ 'without one. A conversation expires 30 days after it was last used.';
11
+ static examples = [
12
+ '<%= config.bin %> <%= command.id %> alice',
13
+ '<%= config.bin %> <%= command.id %>',
14
+ '<%= config.bin %> <%= command.id %> --no-causes-visible --json',
15
+ '<%= config.bin %> <%= command.id %> alice --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
16
+ ];
17
+ static flags = {
18
+ ...BaseCommand.baseFlags,
19
+ 'causes-visible': Flags.boolean({
20
+ description: 'Whether each face reads the other faces\' causes. On by default; --no-causes-visible keeps each ' +
21
+ 'face to its own. Matters only in a conversation with several faces.',
22
+ default: true,
23
+ allowNo: true,
24
+ }),
25
+ message: Flags.string({ char: 'm', description: 'A first message of yours (repeatable, kept in order).', multiple: true }),
26
+ premise: Flags.string({ description: PREMISE_FLAG_DESCRIPTION, multiple: true }),
27
+ 'premise-description': Flags.string({ description: PREMISE_DESCRIPTION_FLAG_DESCRIPTION, multiple: true }),
28
+ };
29
+ static args = {
30
+ face: Args.string({
31
+ description: 'The face alone: an alias, owner:alias, or a composite such as "(a | b)". No @model. Leave it out ' +
32
+ 'for a conversation that takes any of your faces.',
33
+ required: false,
34
+ }),
35
+ };
36
+ async run() {
37
+ const { args, flags } = await this.parse(ConversationCreate);
38
+ const client = this.makeClient(flags);
39
+ const face = args.face?.trim();
40
+ if (face?.includes('@'))
41
+ this.error(`A conversation is with a face alone: ${face.slice(0, face.lastIndexOf('@'))}`);
42
+ let items;
43
+ try {
44
+ items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description']));
45
+ }
46
+ catch (err) {
47
+ this.error(err instanceof Error ? err.message : String(err));
48
+ }
49
+ if (items.length > MAX_CONVERSATION_ITEMS) {
50
+ this.error(`At most ${MAX_CONVERSATION_ITEMS} messages and premises at a time (got ${items.length}). Add the rest with faces conversation:add.`);
51
+ }
52
+ const body = { causes_visible: flags['causes-visible'] };
53
+ if (face)
54
+ body.model = face;
55
+ if (items.length > 0)
56
+ body.items = items;
57
+ let data;
58
+ try {
59
+ data = (await client.post(CONVERSATIONS_PATH, { body }));
60
+ }
61
+ catch (err) {
62
+ if (err instanceof FacesAPIError) {
63
+ const hint = conversationHint(err);
64
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
65
+ }
66
+ throw err;
67
+ }
68
+ if (!this.jsonEnabled()) {
69
+ for (const line of conversationLines(data))
70
+ this.log(line);
71
+ if (data.id)
72
+ this.log(`\nTake a turn with: faces chat:chat ${face ?? '<face>'}@<model> --conversation ${data.id} -m "..."`);
73
+ }
74
+ return data;
75
+ }
76
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ConversationGet extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
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
+ conversation_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
13
+ };
14
+ run(): Promise<unknown>;
15
+ }
@@ -0,0 +1,35 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { CONVERSATIONS_PATH, conversationHint, conversationLines } from '../../conversation.js';
5
+ import { seg } from '../../utils.js';
6
+ export default class ConversationGet extends BaseCommand {
7
+ static description = 'Read a conversation: its face (or any), status, how many turns and items it holds, whether faces ' +
8
+ 'read each other\'s causes, and when it expires. Free. See its items with faces conversation:items.';
9
+ static examples = ['<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID'];
10
+ static flags = {
11
+ ...BaseCommand.baseFlags,
12
+ };
13
+ static args = {
14
+ conversation_id: Args.string({ description: 'Conversation id (from conversation:create)', required: true }),
15
+ };
16
+ async run() {
17
+ const { args, flags } = await this.parse(ConversationGet);
18
+ const client = this.makeClient(flags);
19
+ let data;
20
+ try {
21
+ data = (await client.get(`${CONVERSATIONS_PATH}/${seg(args.conversation_id)}`));
22
+ }
23
+ catch (err) {
24
+ if (err instanceof FacesAPIError) {
25
+ const hint = conversationHint(err);
26
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
27
+ }
28
+ throw err;
29
+ }
30
+ if (!this.jsonEnabled())
31
+ for (const line of conversationLines(data))
32
+ this.log(line);
33
+ return data;
34
+ }
35
+ }
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '../../base.js';
2
+ export default class ConversationItems extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
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
+ conversation_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
13
+ };
14
+ run(): Promise<unknown>;
15
+ }
@@ -0,0 +1,45 @@
1
+ import { Args } from '@oclif/core';
2
+ import { BaseCommand } from '../../base.js';
3
+ import { FacesAPIError } from '../../client.js';
4
+ import { CONVERSATIONS_PATH, conversationHint, itemLines, premiseLines } from '../../conversation.js';
5
+ import { seg } from '../../utils.js';
6
+ export default class ConversationItems extends BaseCommand {
7
+ static description = 'List a conversation\'s items in order: your messages, each face\'s reply with its cause, decisions ' +
8
+ 'with their choice and cause, and premises. Ends with the premises in force now. Free.';
9
+ static examples = [
10
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID',
11
+ '<%= config.bin %> <%= command.id %> fs_CONVERSATION_ID --json',
12
+ ];
13
+ static flags = {
14
+ ...BaseCommand.baseFlags,
15
+ };
16
+ static args = {
17
+ conversation_id: Args.string({ description: 'Conversation id (from conversation:create)', required: true }),
18
+ };
19
+ async run() {
20
+ const { args, flags } = await this.parse(ConversationItems);
21
+ const client = this.makeClient(flags);
22
+ let data;
23
+ try {
24
+ data = (await client.get(`${CONVERSATIONS_PATH}/${seg(args.conversation_id)}/items`));
25
+ }
26
+ catch (err) {
27
+ if (err instanceof FacesAPIError) {
28
+ const hint = conversationHint(err);
29
+ this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
30
+ }
31
+ throw err;
32
+ }
33
+ if (!this.jsonEnabled()) {
34
+ const items = data.data ?? [];
35
+ if (items.length === 0)
36
+ this.log('No items yet.');
37
+ for (const line of itemLines(items))
38
+ this.log(line);
39
+ this.log('');
40
+ for (const line of premiseLines(data.premises))
41
+ this.log(line);
42
+ }
43
+ return data;
44
+ }
45
+ }
@@ -3,6 +3,14 @@ export default class Decide extends BaseCommand {
3
3
  static description: string;
4
4
  static examples: string[];
5
5
  static flags: {
6
+ session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
+ compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
+ format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
9
+ retry: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
6
14
  state: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
7
15
  'state-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
16
  question: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -14,10 +22,6 @@ export default class Decide extends BaseCommand {
14
22
  model: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
23
  baseline: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
24
  'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
- session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
- compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
- format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
20
- retry: import("@oclif/core/interfaces").BooleanFlag<boolean>;
21
25
  'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
26
  token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
23
27
  'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -1,6 +1,7 @@
1
1
  import { Args, Flags } from '@oclif/core';
2
2
  import { BaseCommand } from '../base.js';
3
3
  import { FacesAPIError, missingFieldsNote } from '../client.js';
4
+ import { conversationFields, conversationTurnFlags } from '../conversation.js';
4
5
  import { DECISION_MODELS, decisionModels, DECISION_FORMATS, fromOpenAIAnswers, toOpenAIDecision, questionsProblem, MAX_WARM_UP_WAIT_S, QUESTION_TYPES, causeLines, decisionLines, heldDecisionError, readStateFlags, readQuestionFlags, warmUpWait, } from '../decisions.js';
5
6
  import { compileHint, reasoningHeading, sayWarmUp, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION } from '../utils.js';
6
7
  const OPENAI_FORMAT_ONLY = ['gpt-6-luna'];
@@ -90,6 +91,7 @@ export default class Decide extends BaseCommand {
90
91
  'the answers. It is always in --json, as cause and causes.',
91
92
  default: false,
92
93
  }),
94
+ ...conversationTurnFlags({ exclusive: ['baseline'] }),
93
95
  session: Flags.string({ description: SESSION_FLAG_DESCRIPTION, exclusive: ['baseline'] }),
94
96
  compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION, exclusive: ['baseline'] }),
95
97
  format: Flags.string({
@@ -116,6 +118,13 @@ export default class Decide extends BaseCommand {
116
118
  this.error('--baseline asks with no face, so leave the face out.');
117
119
  if (!flags.baseline && !args.face)
118
120
  this.error('Name a face to ask, or pass --baseline to ask with none.');
121
+ let turn = {};
122
+ try {
123
+ turn = conversationFields(flags);
124
+ }
125
+ catch (err) {
126
+ this.error(err instanceof Error ? err.message : String(err));
127
+ }
119
128
  const state = this.readState(flags);
120
129
  const questions = this.readQuestions(flags);
121
130
  if (!questions && flags.baseline)
@@ -151,6 +160,7 @@ export default class Decide extends BaseCommand {
151
160
  body.session = flags.session;
152
161
  if (flags.compaction)
153
162
  body.compaction = flags.compaction;
163
+ Object.assign(body, turn);
154
164
  if (!json) {
155
165
  process.stderr.write(!questions
156
166
  ? `Asking ${face} for its cause alone, with no questions.\n`
@@ -18,7 +18,7 @@ export default class FaceDelete extends BaseCommand {
18
18
  await this.confirmOrRefuse(`Delete face '${args.face_id}'? This cannot be undone.`, flags.yes);
19
19
  let data;
20
20
  try {
21
- data = await client.delete(`/v1/faces/${seg(args.face_id)}`);
21
+ data = await client.delete(`/v1/faces/${seg(args.face_id)}`, { requireJwt: true });
22
22
  }
23
23
  catch (err) {
24
24
  if (err instanceof FacesAPIError && err.statusCode === 404 && isMeAlias(args.face_id))
@@ -23,6 +23,7 @@ export default class FacePublish extends BaseCommand {
23
23
  let data;
24
24
  try {
25
25
  data = (await client.patch(`/v1/faces/${seg(args.alias)}/publish`, {
26
+ requireJwt: true,
26
27
  body: { published: true },
27
28
  }));
28
29
  }
@@ -63,6 +63,7 @@ export default class FaceShare extends BaseCommand {
63
63
  let data;
64
64
  try {
65
65
  data = (await client.patch(`/v1/faces/${seg(args.alias)}/share`, {
66
+ requireJwt: true,
66
67
  body: { shared_with: next },
67
68
  }));
68
69
  }
@@ -15,6 +15,7 @@ export default class FaceUnpublish extends BaseCommand {
15
15
  let data;
16
16
  try {
17
17
  data = (await client.patch(`/v1/faces/${seg(args.alias)}/publish`, {
18
+ requireJwt: true,
18
19
  body: { published: false },
19
20
  }));
20
21
  }