@faces-sh/cli 1.1.0 → 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 (55) hide show
  1. package/README.md +64 -30
  2. package/dist/billing.js +11 -8
  3. package/dist/chat-command.d.ts +31 -0
  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 +2 -5
  8. package/dist/choices.js +9 -8
  9. package/dist/commands/billing/llm-costs.js +9 -5
  10. package/dist/commands/billing/subscription/index.js +1 -1
  11. package/dist/commands/catalog/doctor.js +2 -2
  12. package/dist/commands/chat/chat.d.ts +31 -0
  13. package/dist/commands/chat/chat.js +31 -0
  14. package/dist/commands/chat/messages.d.ts +30 -0
  15. package/dist/commands/chat/messages.js +21 -0
  16. package/dist/commands/chat/responses.d.ts +30 -0
  17. package/dist/commands/chat/responses.js +22 -0
  18. package/dist/commands/{causes.d.ts → chat/thread.d.ts} +17 -12
  19. package/dist/commands/chat/thread.js +238 -0
  20. package/dist/commands/choices.d.ts +1 -2
  21. package/dist/commands/choices.js +20 -15
  22. package/dist/commands/conversation/compact.js +13 -16
  23. package/dist/commands/conversation/create.js +10 -9
  24. package/dist/commands/decide.d.ts +1 -4
  25. package/dist/commands/decide.js +53 -81
  26. package/dist/commands/face/get.js +1 -1
  27. package/dist/commands/fidelity/pick.js +2 -2
  28. package/dist/commands/fidelity/run.d.ts +20 -0
  29. package/dist/commands/fidelity/run.js +99 -0
  30. package/dist/commands/fidelity/start.d.ts +17 -0
  31. package/dist/commands/fidelity/start.js +56 -0
  32. package/dist/commands/fidelity/turn.d.ts +17 -0
  33. package/dist/commands/fidelity/turn.js +48 -0
  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 +13 -6
  38. package/dist/commands/session/compact.js +5 -8
  39. package/dist/commands/session/create.js +9 -8
  40. package/dist/commands/style/make.js +1 -1
  41. package/dist/commands/style/upload.js +1 -1
  42. package/dist/decisions.d.ts +0 -5
  43. package/dist/decisions.js +0 -18
  44. package/dist/fidelity.js +3 -3
  45. package/dist/media.d.ts +8 -0
  46. package/dist/media.js +12 -0
  47. package/dist/model.d.ts +11 -0
  48. package/dist/model.js +53 -0
  49. package/dist/routing.d.ts +1 -4
  50. package/dist/routing.js +4 -40
  51. package/dist/utils.d.ts +1 -25
  52. package/dist/utils.js +10 -108
  53. package/oclif.manifest.json +1616 -818
  54. package/package.json +6 -3
  55. 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.1.0",
4
- "description": "CLI for Faces: compile causal models from source texts, and ask them what they would do",
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",
@@ -51,6 +51,9 @@
51
51
  "face": {
52
52
  "description": "Create and manage faces"
53
53
  },
54
+ "chat": {
55
+ "description": "Chat with a face on any chat model: @face:maestro-1/<model>"
56
+ },
54
57
  "compile": {
55
58
  "description": "Compile source texts into a face"
56
59
  },
@@ -100,7 +103,7 @@
100
103
  "description": "Your plan: show, subscribe, switch and cancel"
101
104
  },
102
105
  "fidelity": {
103
- "description": "Fidelity runs made before chat was retired: read, pick and save"
106
+ "description": "Fidelity runs: start, turn, pick, read and save"
104
107
  },
105
108
  "benchmark": {
106
109
  "description": "Compare a face against a reference model on its own material"
@@ -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. For the options a face would weigh, use choices; for typed answers, 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('@'))}\nFor the options a face would weigh, use faces choices.`);
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
- }