@faces-sh/cli 1.0.3 → 1.2.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 (70) hide show
  1. package/README.md +107 -53
  2. package/dist/billing.js +11 -8
  3. package/dist/{commands/causes.d.ts → chat-command.d.ts} +13 -13
  4. package/dist/chat-command.js +110 -0
  5. package/dist/chat.d.ts +47 -0
  6. package/dist/chat.js +157 -0
  7. package/dist/choices.d.ts +20 -0
  8. package/dist/choices.js +49 -0
  9. package/dist/commands/auth/connect.js +2 -2
  10. package/dist/commands/billing/llm-costs.js +9 -5
  11. package/dist/commands/billing/subscription/index.js +1 -1
  12. package/dist/commands/catalog/doctor.js +9 -68
  13. package/dist/commands/chat/chat.d.ts +10 -26
  14. package/dist/commands/chat/chat.js +21 -366
  15. package/dist/commands/chat/messages.d.ts +13 -13
  16. package/dist/commands/chat/messages.js +15 -142
  17. package/dist/commands/chat/responses.d.ts +13 -14
  18. package/dist/commands/chat/responses.js +16 -153
  19. package/dist/commands/chat/thread.d.ts +3 -15
  20. package/dist/commands/chat/thread.js +128 -362
  21. package/dist/commands/choices.d.ts +20 -0
  22. package/dist/commands/choices.js +91 -0
  23. package/dist/commands/conversation/add.d.ts +2 -0
  24. package/dist/commands/conversation/add.js +21 -10
  25. package/dist/commands/conversation/close.js +5 -5
  26. package/dist/commands/conversation/compact.js +15 -18
  27. package/dist/commands/conversation/create.d.ts +2 -0
  28. package/dist/commands/conversation/create.js +20 -17
  29. package/dist/commands/conversation/get.js +4 -4
  30. package/dist/commands/conversation/items.js +5 -5
  31. package/dist/commands/decide.d.ts +4 -4
  32. package/dist/commands/decide.js +70 -81
  33. package/dist/commands/face/get.js +2 -2
  34. package/dist/commands/group/add.js +1 -1
  35. package/dist/commands/media/list.d.ts +12 -0
  36. package/dist/commands/media/list.js +35 -0
  37. package/dist/commands/models/list.js +16 -5
  38. package/dist/commands/session/close.js +1 -1
  39. package/dist/commands/session/compact.js +6 -9
  40. package/dist/commands/session/create.js +10 -9
  41. package/dist/commands/session/get.js +1 -1
  42. package/dist/commands/state/add.d.ts +3 -0
  43. package/dist/commands/state/add.js +3 -0
  44. package/dist/commands/state/close.d.ts +3 -0
  45. package/dist/commands/state/close.js +3 -0
  46. package/dist/commands/state/compact.d.ts +3 -0
  47. package/dist/commands/state/compact.js +3 -0
  48. package/dist/commands/state/create.d.ts +3 -0
  49. package/dist/commands/state/create.js +3 -0
  50. package/dist/commands/state/get.d.ts +3 -0
  51. package/dist/commands/state/get.js +3 -0
  52. package/dist/commands/state/items.d.ts +3 -0
  53. package/dist/commands/state/items.js +3 -0
  54. package/dist/commands/style/make.js +2 -6
  55. package/dist/commands/style/upload.js +1 -1
  56. package/dist/conversation.d.ts +27 -2
  57. package/dist/conversation.js +91 -16
  58. package/dist/decisions.d.ts +0 -5
  59. package/dist/decisions.js +0 -18
  60. package/dist/media.d.ts +8 -0
  61. package/dist/media.js +12 -0
  62. package/dist/model.d.ts +11 -0
  63. package/dist/model.js +53 -0
  64. package/dist/routing.d.ts +1 -4
  65. package/dist/routing.js +4 -40
  66. package/dist/utils.d.ts +1 -25
  67. package/dist/utils.js +10 -108
  68. package/oclif.manifest.json +2054 -1649
  69. package/package.json +10 -7
  70. package/dist/commands/causes.js +0 -146
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@faces-sh/cli",
3
- "version": "1.0.3",
4
- "description": "CLI for Faces: compile causal models from source texts, and get their causes",
3
+ "version": "1.2.0",
4
+ "description": "CLI for Faces: compile causal models from source texts, ask them what they would do, and chat with them on any model",
5
5
  "type": "module",
6
6
  "author": "Headwaters Lab Inc.",
7
7
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "description": "Create and manage faces"
53
53
  },
54
54
  "chat": {
55
- "description": "Chat with a face on any supported model"
55
+ "description": "Chat with a face on any chat model: @face:maestro-1/<model>"
56
56
  },
57
57
  "compile": {
58
58
  "description": "Compile source texts into a face"
@@ -73,7 +73,7 @@
73
73
  "description": "Local CLI configuration"
74
74
  },
75
75
  "style": {
76
- "description": "Build and manage the styles a face applies on chat"
76
+ "description": "Build and manage a face's styles"
77
77
  },
78
78
  "compile:doc": {
79
79
  "description": "Documents: create, compile, edit, pause, reset and delete"
@@ -103,16 +103,19 @@
103
103
  "description": "Your plan: show, subscribe, switch and cancel"
104
104
  },
105
105
  "fidelity": {
106
- "description": "Fidelity runs: ten blind turns, scored out of 10"
106
+ "description": "Fidelity runs: start, turn, pick, read and save"
107
107
  },
108
108
  "benchmark": {
109
109
  "description": "Compare a face against a reference model on its own material"
110
110
  },
111
+ "state": {
112
+ "description": "States: the situation your agent builds, kept on the server, with premises, their status and what they depend on"
113
+ },
111
114
  "conversation": {
112
- "description": "Conversations: keep a whole exchange with faces on the server, with premises"
115
+ "description": "The old name for state"
113
116
  },
114
117
  "session": {
115
- "description": "Sessions: group turns with a face, then compact them"
118
+ "description": "An older name for state"
116
119
  },
117
120
  "models": {
118
121
  "description": "The models you can name, with their prices"
@@ -1,146 +0,0 @@
1
- import fs from 'node:fs';
2
- import { Args, Flags } from '@oclif/core';
3
- import { BaseCommand } from '../base.js';
4
- import { FacesAPIError } from '../client.js';
5
- import { conversationFields, conversationTurnFlags } from '../conversation.js';
6
- import { QUESTION_TYPES, causeLines, heldDecisionError, readQuestionFlags, readStateFlags } from '../decisions.js';
7
- import { compileHint, isMeAlias, ME_MISSING, retryOnceOnWarmUp, sayWarmUp, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION } from '../utils.js';
8
- const MAX_CAUSE_QUESTIONS = 10;
9
- export default class Causes extends BaseCommand {
10
- static description = 'Get a face\'s cause alone, with no answering model: the principal why behind its response in this ' +
11
- 'context (POST /v1/causes). Send a conversation with -m, or a situation with --state, optionally with ' +
12
- 'questions for one cause per question. Billed at the cause rate only (see faces models:list --kind cause). ' +
13
- 'A cause takes about 10 seconds. To have a model answer, use chat:chat or decide.';
14
- static examples = [
15
- '<%= config.bin %> <%= command.id %> alice -m "Should I take the offer?"',
16
- '<%= config.bin %> <%= command.id %> alice --state "A fund offers $80k to change a finding before it is published."',
17
- '<%= config.bin %> <%= command.id %> alice --state-file situation.txt --question "Does the speaker take the money?"',
18
- '<%= config.bin %> <%= command.id %> "(alice | bob)" -m "What matters most here?" --json',
19
- '<%= config.bin %> <%= command.id %> alice -m "So what do I tell them tomorrow?" --compaction fcmp_COMPACTION_ID',
20
- '<%= config.bin %> <%= command.id %> alice -m "And now?" --conversation fs_CONVERSATION_ID --premise vendor_certified=false',
21
- ];
22
- static flags = {
23
- ...BaseCommand.baseFlags,
24
- message: Flags.string({
25
- char: 'm',
26
- description: 'A user message (repeatable, sent in order). The cause is for the last one.',
27
- multiple: true,
28
- exclusive: ['state', 'state-file', 'file'],
29
- }),
30
- file: Flags.string({ description: 'Read the user message from a file.', exclusive: ['message', 'state', 'state-file'] }),
31
- state: Flags.string({
32
- description: 'A situation, as plain text, in place of a conversation.',
33
- exclusive: ['state-file', 'message', 'file'],
34
- }),
35
- 'state-file': Flags.string({
36
- description: 'Read the situation from this file. A .json file is sent as the JSON it holds.',
37
- exclusive: ['state', 'message', 'file'],
38
- }),
39
- question: Flags.string({
40
- description: 'A question about the situation, for a cause of its own. Its type follows from --option (a choice), ' +
41
- '--level (a score), or neither (a yes-or-no). Needs --state or --state-file.',
42
- exclusive: ['questions-file'],
43
- }),
44
- type: Flags.string({ description: 'The type of --question.', options: [...QUESTION_TYPES], dependsOn: ['question'] }),
45
- option: Flags.string({ description: 'An option for a choice, as name="description" (repeatable).', multiple: true, dependsOn: ['question'], exclusive: ['level'] }),
46
- level: Flags.string({ description: 'A level of a score, lowest first (repeatable).', multiple: true, dependsOn: ['question'], exclusive: ['option'] }),
47
- id: Flags.string({ description: 'Key for the --question in the result (default: answer)', dependsOn: ['question'] }),
48
- 'questions-file': Flags.string({
49
- description: `A JSON file of 1 to ${MAX_CAUSE_QUESTIONS} questions in System One's format, as for faces decide. Needs --state or --state-file.`,
50
- exclusive: ['question'],
51
- }),
52
- ...conversationTurnFlags(),
53
- session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
54
- compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
55
- };
56
- static args = {
57
- face: Args.string({
58
- description: 'The face: an alias, owner:alias for a face shared with you, or a composite such as "(a | b)". No @model.',
59
- required: true,
60
- }),
61
- };
62
- async run() {
63
- const { args, flags } = await this.parse(Causes);
64
- const client = this.makeClient(flags);
65
- const json = this.jsonEnabled();
66
- const face = args.face.trim();
67
- if (face.includes('@')) {
68
- this.error(`A cause is the face's alone, so leave the model off: ${face.slice(0, face.lastIndexOf('@'))}\nTo have a model answer, use faces chat:chat.`);
69
- }
70
- const fail = (m) => this.error(m);
71
- let turn = {};
72
- try {
73
- turn = conversationFields(flags);
74
- }
75
- catch (err) {
76
- fail(err instanceof Error ? err.message : String(err));
77
- }
78
- const body = { model: face };
79
- const situation = flags.state !== undefined || flags['state-file'] !== undefined;
80
- const questions = readQuestionFlags(flags, fail);
81
- if (situation) {
82
- body.state = readStateFlags(flags, fail);
83
- if (questions) {
84
- const n = Object.keys(questions).length;
85
- if (n > MAX_CAUSE_QUESTIONS)
86
- this.error(`At most ${MAX_CAUSE_QUESTIONS} questions (got ${n}). Split them across requests.`);
87
- body.questions = questions;
88
- }
89
- }
90
- else {
91
- if (questions)
92
- this.error('Questions go with a situation: add --state or --state-file.');
93
- const messages = [];
94
- if (flags.file) {
95
- if (!fs.existsSync(flags.file))
96
- this.error(`File not found: ${flags.file}`);
97
- messages.push(fs.readFileSync(flags.file, 'utf8'));
98
- }
99
- else if (flags.message?.length) {
100
- messages.push(...flags.message);
101
- }
102
- else {
103
- this.error('Send a conversation with -m (or --file), or a situation with --state (or --state-file).');
104
- }
105
- body.messages = messages.map((content) => ({ role: 'user', content }));
106
- }
107
- if (flags.session)
108
- body.session = flags.session;
109
- if (flags.compaction)
110
- body.compaction = flags.compaction;
111
- Object.assign(body, turn);
112
- let data;
113
- try {
114
- data = (await retryOnceOnWarmUp(async () => {
115
- const res = await client.post('/v1/causes', { body });
116
- const held = heldDecisionError(res);
117
- if (held)
118
- throw held;
119
- return res;
120
- }, json ? undefined : sayWarmUp));
121
- }
122
- catch (err) {
123
- if (err instanceof FacesAPIError) {
124
- const head = `HTTP ${err.statusCode}: ${err.message}`;
125
- if (err.statusCode === 409)
126
- this.error(`${head}\n${compileHint(face, !/nothing compiled/i.test(err.message), 'give a cause')}`);
127
- if (err.statusCode === 404 && isMeAlias(face))
128
- this.error(`${head}\n${ME_MISSING}`);
129
- if (err.statusCode === 503)
130
- this.error(`${head}\n${err.retryAfter === undefined ? 'Try again.' : `Try again in ${err.retryAfter}s.`}`);
131
- if (err.statusCode === 504)
132
- this.error(`${head}\nThe face did not finish within 300 seconds. Ask again.`);
133
- this.error(head);
134
- }
135
- throw err;
136
- }
137
- if (json)
138
- return data;
139
- const lines = causeLines(data, questions ? Object.keys(questions) : []);
140
- if (lines.length === 0)
141
- this.error('The response carried no cause. Run it again with --json to see what the server said.');
142
- for (const line of lines)
143
- this.log(line);
144
- return data;
145
- }
146
- }