@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
@@ -1,6 +1,8 @@
1
1
  import { FacesAPIError } from './client.js';
2
- export declare const CONVERSATIONS_PATH = "/v1/conversations";
2
+ export declare const CONVERSATIONS_PATH = "/v1/states";
3
3
  export declare const MAX_CONVERSATION_ITEMS = 20;
4
+ export declare const PREMISE_STATUSES: readonly ["stated", "verified", "assumed", "unresolved", "invalidated"];
5
+ export declare const MAX_DEPENDS_ON = 200;
4
6
  export interface Conversation {
5
7
  object?: string;
6
8
  id?: string;
@@ -17,14 +19,30 @@ export interface Premise {
17
19
  key: string;
18
20
  value: unknown;
19
21
  description?: string;
22
+ status?: string;
23
+ depends_on?: string[];
20
24
  }
21
25
  export interface PremiseState {
22
26
  value?: unknown;
23
27
  description?: string | null;
28
+ status?: string;
29
+ asserted_status?: string;
30
+ because?: string | null;
31
+ depends_on?: string[];
32
+ }
33
+ export interface StatusChange {
34
+ kind?: string;
35
+ key?: string;
36
+ id?: string;
37
+ from?: string;
38
+ to?: string;
39
+ because?: string | null;
24
40
  }
25
41
  export declare const CONVERSATION_FLAG_DESCRIPTION: string;
26
42
  export declare const PREMISE_FLAG_DESCRIPTION: string;
27
43
  export declare const PREMISE_DESCRIPTION_FLAG_DESCRIPTION: string;
44
+ export declare const PREMISE_STATUS_FLAG_DESCRIPTION: string;
45
+ export declare const PREMISE_DEPENDS_ON_FLAG_DESCRIPTION: string;
28
46
  export declare const CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION: string;
29
47
  export declare function conversationTurnFlags(opts?: {
30
48
  suffix?: string;
@@ -33,21 +51,27 @@ export declare function conversationTurnFlags(opts?: {
33
51
  conversation: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
34
52
  premise: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
35
53
  'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
54
+ 'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
55
+ 'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
36
56
  'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
37
57
  };
38
58
  export declare function conversationLines(c: Conversation): string[];
39
59
  export declare function conversationHint(err: FacesAPIError): string | undefined;
40
60
  export declare function premiseValue(raw: string): unknown;
41
- export declare function parsePremises(premises?: string[], descriptions?: string[]): Premise[];
61
+ export declare function parsePremises(premises?: string[], descriptions?: string[], statuses?: string[], dependsOn?: string[]): Premise[];
62
+ export declare function parseDependsOn(raw: string, flag?: string): string[];
42
63
  export declare function conversationFields(flags: {
43
64
  conversation?: string;
44
65
  session?: string;
45
66
  premise?: string[];
46
67
  'premise-description'?: string[];
68
+ 'premise-status'?: string[];
69
+ 'premise-depends-on'?: string[];
47
70
  'causes-visible'?: boolean;
48
71
  }): Record<string, unknown>;
49
72
  export declare function clientItems(messages?: string[], premises?: Premise[]): Array<Record<string, unknown>>;
50
73
  export declare function shownValue(v: unknown): string;
74
+ export declare function statusChangeLines(changes: StatusChange[] | undefined): string[];
51
75
  export declare function premiseLines(premises: Record<string, PremiseState> | undefined): string[];
52
76
  export declare function itemLines(items: Array<Record<string, unknown>>): string[];
53
77
  export interface StaleDecision {
@@ -59,5 +83,6 @@ export interface StaleDecision {
59
83
  was?: unknown;
60
84
  now?: unknown;
61
85
  }>;
86
+ via?: string | null;
62
87
  }
63
88
  export declare function staleDecisionLines(stale: StaleDecision[] | undefined): string[];
@@ -1,19 +1,27 @@
1
1
  import { Flags } from '@oclif/core';
2
- export const CONVERSATIONS_PATH = '/v1/conversations';
2
+ export const CONVERSATIONS_PATH = '/v1/states';
3
3
  export const MAX_CONVERSATION_ITEMS = 20;
4
4
  const PREMISE_KEY = /^[A-Za-z0-9_-]{1,64}$/;
5
- export const CONVERSATION_FLAG_DESCRIPTION = 'Add this turn to a conversation, by id (from faces conversation:create). Send only the new message: ' +
6
- 'the conversation so far is read before it. A conversation opened with one face takes only that face.';
5
+ export const PREMISE_STATUSES = ['stated', 'verified', 'assumed', 'unresolved', 'invalidated'];
6
+ export const MAX_DEPENDS_ON = 200;
7
+ export const CONVERSATION_FLAG_DESCRIPTION = 'Add this turn to a state, by id (from faces state:create). Send only what is new: ' +
8
+ 'the state so far is read before it. A state opened with one face takes only that face.';
7
9
  export const PREMISE_FLAG_DESCRIPTION = 'A premise, as key=value (repeatable): a named fact the face\'s answers depend on, kept on the ' +
8
- 'conversation. The key is 1 to 64 letters, digits, _ or -. The value is read as JSON when it is JSON ' +
10
+ 'state. The key is 1 to 64 letters, digits, _ or -. The value is read as JSON when it is JSON ' +
9
11
  '(50000, true, null, ["a","b"], {"max":3}) and as text otherwise, so plan=annual is the text "annual". ' +
10
12
  'Quote it to keep a number as text: --premise \'code="007"\'. A newer value of a key replaces it from ' +
11
13
  'then on. A key used for the first time needs --premise-description.';
12
14
  export const PREMISE_DESCRIPTION_FLAG_DESCRIPTION = 'What a --premise means, in plain words, as key="text" (repeatable, one per key), e.g. ' +
13
15
  '--premise-description budget_usd="the most we can spend this year". Required the first time a key is ' +
14
- 'used in a conversation, and kept after that.';
16
+ 'used in a state, and kept after that.';
17
+ export const PREMISE_STATUS_FLAG_DESCRIPTION = `A --premise's status, as key=status (repeatable, one per key): ${PREMISE_STATUSES.join(', ')}. ` +
18
+ 'Left out, a new premise is stated. An invalidated premise invalidates everything that depends on it; ' +
19
+ 'set it to another status to restore them.';
20
+ export const PREMISE_DEPENDS_ON_FLAG_DESCRIPTION = 'What a --premise rests on, as key=a,b (repeatable, one per key): premise keys and decision ids already in ' +
21
+ `the state or set in the same request, at most ${MAX_DEPENDS_ON}. key= with nothing after it clears it; ` +
22
+ 'left out, a newer value keeps what the key rested on before.';
15
23
  export const CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION = 'Whether the face reads the other faces\' causes on this turn, in a conversation with several faces. ' +
16
- 'Leave it out to follow the conversation (see faces conversation:create --no-causes-visible).';
24
+ 'Leave it out to follow the state (see faces state:create --no-causes-visible).';
17
25
  export function conversationTurnFlags(opts = {}) {
18
26
  const d = (text) => (opts.suffix ? `${text} ${opts.suffix}` : text);
19
27
  const exclusive = opts.exclusive;
@@ -21,13 +29,15 @@ export function conversationTurnFlags(opts = {}) {
21
29
  conversation: Flags.string({ description: d(CONVERSATION_FLAG_DESCRIPTION), exclusive }),
22
30
  premise: Flags.string({ description: d(`${PREMISE_FLAG_DESCRIPTION} Needs --conversation.`), multiple: true, exclusive }),
23
31
  'premise-description': Flags.string({ description: d(PREMISE_DESCRIPTION_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
32
+ 'premise-status': Flags.string({ description: d(PREMISE_STATUS_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
33
+ 'premise-depends-on': Flags.string({ description: d(PREMISE_DEPENDS_ON_FLAG_DESCRIPTION), multiple: true, dependsOn: ['premise'], exclusive }),
24
34
  'causes-visible': Flags.boolean({ description: d(`${CAUSES_VISIBLE_TURN_FLAG_DESCRIPTION} Needs --conversation.`), allowNo: true, exclusive }),
25
35
  };
26
36
  }
27
37
  export function conversationLines(c) {
28
38
  const pairs = [
29
- ['conversation', c.id],
30
- ['face', c.model ?? (c.object === 'conversation' ? 'any of your faces' : undefined)],
39
+ ['state', c.id],
40
+ ['face', c.model ?? (c.object === 'conversation' || c.object === 'state' ? 'any of your faces' : undefined)],
31
41
  ['status', c.status],
32
42
  ['turns', c.turns],
33
43
  ['items', c.items],
@@ -40,12 +50,15 @@ export function conversationLines(c) {
40
50
  }
41
51
  export function conversationHint(err) {
42
52
  if (err.statusCode === 404) {
43
- return 'A conversation expires 30 days after it was last used, and a closed one cannot be used. ' +
44
- 'Start another with: faces conversation:create';
53
+ return 'A state expires 30 days after it was last used, and a closed one cannot be used. ' +
54
+ 'Start another with: faces state:create';
45
55
  }
46
56
  const fresh = err.statusCode === 422 ? /premise '([A-Za-z0-9_-]{1,64})' is new/.exec(err.message) : null;
47
57
  if (fresh)
48
58
  return `Say what it means: --premise-description ${fresh[1]}="what it means, in plain words"`;
59
+ if (err.statusCode === 422 && /depends_on` names no premise or decision/.test(err.message)) {
60
+ return 'Name premise keys and decision ids already in the state (faces state:items <id>), or premises set in the same request.';
61
+ }
49
62
  return undefined;
50
63
  }
51
64
  export function premiseValue(raw) {
@@ -71,7 +84,7 @@ function checkKey(key, flag) {
71
84
  if (!PREMISE_KEY.test(key))
72
85
  throw new Error(`${flag}: a premise key is 1 to 64 letters, digits, _ or - (got '${key}').`);
73
86
  }
74
- export function parsePremises(premises = [], descriptions = []) {
87
+ export function parsePremises(premises = [], descriptions = [], statuses = [], dependsOn = []) {
75
88
  const out = [];
76
89
  const seen = new Map();
77
90
  for (const raw of premises) {
@@ -97,6 +110,43 @@ export function parsePremises(premises = [], descriptions = []) {
97
110
  described.add(key);
98
111
  p.description = text.trim();
99
112
  }
113
+ const statused = new Set();
114
+ for (const raw of statuses) {
115
+ const [key, text] = splitPair(raw, '--premise-status', 'key=status');
116
+ checkKey(key, '--premise-status');
117
+ const p = seen.get(key);
118
+ if (!p)
119
+ throw new Error(`--premise-status names '${key}', which no --premise sets. Add --premise ${key}=<value>.`);
120
+ if (statused.has(key))
121
+ throw new Error(`--premise-status sets '${key}' twice. Give one status per key.`);
122
+ const status = text.trim().toLowerCase();
123
+ if (!PREMISE_STATUSES.includes(status)) {
124
+ throw new Error(`--premise-status for '${key}' is one of ${PREMISE_STATUSES.join(', ')} (got '${text}').`);
125
+ }
126
+ statused.add(key);
127
+ p.status = status;
128
+ }
129
+ const linked = new Set();
130
+ for (const raw of dependsOn) {
131
+ const [key, text] = splitPair(raw, '--premise-depends-on', 'key=a,b');
132
+ checkKey(key, '--premise-depends-on');
133
+ const p = seen.get(key);
134
+ if (!p)
135
+ throw new Error(`--premise-depends-on names '${key}', which no --premise sets. Add --premise ${key}=<value>.`);
136
+ if (linked.has(key))
137
+ throw new Error(`--premise-depends-on sets '${key}' twice. List everything it rests on once, comma separated.`);
138
+ const deps = parseDependsOn(text, '--premise-depends-on');
139
+ if (deps.includes(key))
140
+ throw new Error(`--premise-depends-on: premise '${key}' cannot depend on itself.`);
141
+ linked.add(key);
142
+ p.depends_on = deps;
143
+ }
144
+ return out;
145
+ }
146
+ export function parseDependsOn(raw, flag = '--depends-on') {
147
+ const out = [...new Set(raw.split(',').map((x) => x.trim()).filter(Boolean))];
148
+ if (out.length > MAX_DEPENDS_ON)
149
+ throw new Error(`${flag} names at most ${MAX_DEPENDS_ON} premises and decisions (got ${out.length}).`);
100
150
  return out;
101
151
  }
102
152
  export function conversationFields(flags) {
@@ -104,10 +154,10 @@ export function conversationFields(flags) {
104
154
  if (flags.conversation && flags.session && flags.conversation !== flags.session) {
105
155
  throw new Error('--session is the old name for --conversation: pass one of them, not two different ids.');
106
156
  }
107
- const premises = parsePremises(flags.premise, flags['premise-description']);
157
+ const premises = parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on']);
108
158
  const inConversation = Boolean(flags.conversation || flags.session);
109
159
  if (!inConversation && (premises.length > 0 || flags['causes-visible'] !== undefined)) {
110
- throw new Error('Premises and --causes-visible belong to a conversation: add --conversation <id> (from faces conversation:create).');
160
+ throw new Error('Premises and --causes-visible belong to a state: add --conversation <id> (from faces state:create).');
111
161
  }
112
162
  if (flags.conversation)
113
163
  out.conversation = flags.conversation;
@@ -123,13 +173,37 @@ export function clientItems(messages = [], premises = []) {
123
173
  export function shownValue(v) {
124
174
  return v === undefined ? '-' : JSON.stringify(v);
125
175
  }
176
+ function statusNote(p) {
177
+ if (!p)
178
+ return '';
179
+ const parts = [];
180
+ if (p.status && p.status !== 'stated')
181
+ parts.push(p.status);
182
+ if (p.asserted_status)
183
+ parts.push(`set ${p.asserted_status}`);
184
+ if (p.because)
185
+ parts.push(`because ${p.because}`);
186
+ if (p.depends_on && p.depends_on.length > 0)
187
+ parts.push(`rests on ${p.depends_on.join(', ')}`);
188
+ return parts.length > 0 ? ` [${parts.join('; ')}]` : '';
189
+ }
190
+ export function statusChangeLines(changes) {
191
+ if (!changes || changes.length === 0)
192
+ return [];
193
+ const lines = [`${changes.length === 1 ? '1 status changed' : `${changes.length} statuses changed`}:`];
194
+ for (const c of changes) {
195
+ const what = c.kind === 'decision' ? `decision ${c.id ?? '?'}` : `premise ${c.key ?? '?'}`;
196
+ lines.push(` ${what}: ${c.from ?? '-'} -> ${c.to ?? '-'}${c.because ? ` (because ${c.because})` : ''}`);
197
+ }
198
+ return lines;
199
+ }
126
200
  export function premiseLines(premises) {
127
201
  const entries = Object.entries(premises ?? {});
128
202
  if (entries.length === 0)
129
203
  return ['premises: none'];
130
204
  const lines = ['premises:'];
131
205
  for (const [key, p] of entries) {
132
- lines.push(` ${key} = ${shownValue(p?.value)}${p?.description ? ` (${p.description})` : ''}`);
206
+ lines.push(` ${key} = ${shownValue(p?.value)}${statusNote(p)}${p?.description ? ` (${p.description})` : ''}`);
133
207
  }
134
208
  return lines;
135
209
  }
@@ -186,7 +260,8 @@ export function itemLines(items) {
186
260
  const answer = (it.answer && typeof it.answer === 'object' ? it.answer : {});
187
261
  const question = (it.question && typeof it.question === 'object' ? it.question : {});
188
262
  const result = answer.result === undefined || answer.result === null ? '-' : String(answer.result);
189
- lines.push(`${head}${String(it.face ?? 'face')}${it.model ? ` (${it.model})` : ''} decided: ${questionText(question)} -> ${result}`);
263
+ const status = it.status === 'invalidated' ? ` [invalidated${it.because ? `, because ${String(it.because)}` : ''}]` : '';
264
+ lines.push(`${head}${String(it.face ?? 'face')}${it.model ? ` (${it.model})` : ''} decided: ${questionText(question)} -> ${result}${status}`);
190
265
  if (typeof it.cause === 'string' && it.cause)
191
266
  lines.push(`${pad}cause: ${it.cause}`);
192
267
  continue;
@@ -237,7 +312,7 @@ export function staleDecisionLines(stale) {
237
312
  for (const d of stale) {
238
313
  const q = d.question ? questionText(d.question) : '?';
239
314
  const choice = d.choice === undefined || d.choice === null ? '-' : String(d.choice);
240
- lines.push(` ${d.face ?? 'face'}: ${q} -> ${choice}${d.call_id ? ` [${d.call_id}]` : ''}`);
315
+ lines.push(` ${d.face ?? 'face'}: ${q} -> ${choice}${d.call_id ? ` [${d.call_id}]` : ''}${d.via ? `, through ${d.via}` : ''}`);
241
316
  for (const [key, c] of Object.entries(d.changed ?? {})) {
242
317
  lines.push(` ${key}: was ${shownValue(c?.was)}, now ${shownValue(c?.now)}`);
243
318
  }
@@ -22,11 +22,6 @@ export declare function parseDecisionOption(raw: string): {
22
22
  export declare function decisionLines(answers: Record<string, unknown>, barWidth?: number): string[];
23
23
  export declare const MAX_WARM_UP_WAIT_S = 300;
24
24
  export declare function warmUpWait(status: number, retryAfter: number | undefined, waitedS: number): number | undefined;
25
- export interface DecisionCauses {
26
- cause?: string;
27
- causes?: Record<string, unknown>;
28
- }
29
- export declare function causeLines(data: DecisionCauses, questionIds: string[]): string[];
30
25
  export declare function heldDecisionError(data: unknown): FacesAPIError | undefined;
31
26
  export declare function readStateFlags(flags: {
32
27
  state?: string;
package/dist/decisions.js CHANGED
@@ -158,24 +158,6 @@ export function warmUpWait(status, retryAfter, waitedS) {
158
158
  return undefined;
159
159
  return retryAfter;
160
160
  }
161
- export function causeLines(data, questionIds) {
162
- const cause = typeof data.cause === 'string' ? data.cause : '';
163
- const per = questionIds.map((id) => {
164
- const c = data.causes?.[id];
165
- return [id, typeof c === 'string' && c !== '' ? c : cause];
166
- });
167
- if (per.length === 0 || per.every(([, c]) => c === cause))
168
- return cause ? [cause] : [];
169
- const lines = [];
170
- for (const [id, c] of per) {
171
- if (!c)
172
- continue;
173
- if (lines.length > 0)
174
- lines.push('');
175
- lines.push(`${id}:`, c);
176
- }
177
- return lines;
178
- }
179
161
  export function heldDecisionError(data) {
180
162
  if (!data || typeof data !== 'object')
181
163
  return undefined;
@@ -0,0 +1,8 @@
1
+ export declare const MEDIA_PATH = "/v1/media";
2
+ export interface Medium {
3
+ name?: string;
4
+ description?: string;
5
+ subcategories?: string[];
6
+ }
7
+ export declare function mediaOf(raw: unknown): Medium[];
8
+ export declare function mediaLines(media: Medium[]): string[];
package/dist/media.js ADDED
@@ -0,0 +1,12 @@
1
+ import { table } from './utils.js';
2
+ export const MEDIA_PATH = '/v1/media';
3
+ export function mediaOf(raw) {
4
+ const data = Array.isArray(raw) ? raw : (raw?.data ?? []);
5
+ return Array.isArray(data) ? data : [];
6
+ }
7
+ export function mediaLines(media) {
8
+ if (media.length === 0)
9
+ return ['No media.'];
10
+ const rows = media.map((m) => [String(m.name ?? ''), String(m.description ?? ''), (m.subcategories ?? []).join(', ')]);
11
+ return table(['MEDIUM', 'DESCRIPTION', 'COVERS'], rows);
12
+ }
@@ -0,0 +1,11 @@
1
+ export declare const MAESTROS: readonly ["maestro-1", "maestro-1-flash"];
2
+ export declare const DEFAULT_MAESTRO: "maestro-1";
3
+ export interface ModelName {
4
+ upstream?: string;
5
+ faces?: string;
6
+ maestro?: string;
7
+ downstream?: string;
8
+ }
9
+ export declare function parseModel(raw: string): ModelName;
10
+ export declare function asFace(face: string): string;
11
+ export declare function modelProblem(raw: string, needs: 'upstream' | 'both', example?: string): string | undefined;
package/dist/model.js ADDED
@@ -0,0 +1,53 @@
1
+ export const MAESTROS = ['maestro-1', 'maestro-1-flash'];
2
+ export const DEFAULT_MAESTRO = MAESTROS[0];
3
+ const MAESTRO_END = /:\s*(maestro-[^\s:/()@|&^~]*)\s*$/i;
4
+ export function parseModel(raw) {
5
+ const s = raw.trim();
6
+ const slash = s.indexOf('/');
7
+ const prefix = slash >= 0 ? s.slice(0, slash) : s;
8
+ const m = MAESTRO_END.exec(prefix);
9
+ if (!m || !/^[@(]/.test(prefix.trim()))
10
+ return { downstream: s || undefined };
11
+ const faces = prefix.slice(0, m.index).trim();
12
+ return {
13
+ upstream: `${faces}:${m[1]}`,
14
+ faces,
15
+ maestro: m[1],
16
+ downstream: slash >= 0 ? s.slice(slash + 1).trim() || undefined : undefined,
17
+ };
18
+ }
19
+ export function asFace(face) {
20
+ const f = face.trim();
21
+ return /^[@(]/.test(f) ? f : `@${f}`;
22
+ }
23
+ export function modelProblem(raw, needs, example = 'gpt-5.4') {
24
+ const s = raw.trim();
25
+ if (!s)
26
+ return 'Name the model: @<face>:maestro-1' + (needs === 'both' ? `/<model>, e.g. @alice:maestro-1/${example}` : ', e.g. @alice:maestro-1');
27
+ const p = parseModel(s);
28
+ if (!p.upstream) {
29
+ const at = s.indexOf('@');
30
+ if (at > 0 && !s.startsWith('(')) {
31
+ const face = s.slice(0, at);
32
+ const down = s.slice(at + 1);
33
+ return `face@model is gone: write ${asFace(face)}:${DEFAULT_MAESTRO}${needs === 'both' ? `/${down}` : ''}`;
34
+ }
35
+ if (/^[@(]/.test(s)) {
36
+ const faces = s.split('/')[0].trim();
37
+ const rest = s.includes('/') ? s.slice(s.indexOf('/') + 1) : needs === 'both' ? '<model>' : '';
38
+ return `Name the maestro after the face: ${faces}:${DEFAULT_MAESTRO}${rest ? `/${rest}` : ''}`;
39
+ }
40
+ if (/^[a-z0-9][a-z0-9~:-]*$/i.test(s) && !/^maestro-/i.test(s) && needs === 'upstream') {
41
+ return `Write the face as ${asFace(s.replace(':', '~'))}:${DEFAULT_MAESTRO}`;
42
+ }
43
+ if (needs === 'both' && /^[a-z0-9][a-z0-9-]*$/i.test(s)) {
44
+ return `Add a face: @<face>:${DEFAULT_MAESTRO}/${s}, or, if ${s} is a face, @${s}:${DEFAULT_MAESTRO}/<model>`;
45
+ }
46
+ return `Add a face: @<face>:${DEFAULT_MAESTRO}${needs === 'both' ? `/${s}` : ''}`;
47
+ }
48
+ if (needs === 'upstream' && p.downstream)
49
+ return `faces choices takes the upstream model alone, with no model after it: ${p.upstream}`;
50
+ if (needs === 'both' && !p.downstream)
51
+ return `Name the model that answers after the maestro: ${p.upstream}/<model>, e.g. ${p.upstream}/${example}`;
52
+ return undefined;
53
+ }
package/dist/routing.d.ts CHANGED
@@ -8,8 +8,5 @@ export interface RouteInfo {
8
8
  freeWhenConnected: boolean;
9
9
  }
10
10
  export declare function decisionModelError(llm?: string): string | undefined;
11
- export declare function llmFromArg(modelArg: string): string | undefined;
12
- export declare function faceSpecOf(modelArg: string): string;
13
- export declare function isCompositeFormula(modelArg: string): boolean;
14
- export declare function resolveEndpoint(client: FacesClient, modelArg: string): Promise<RouteInfo>;
11
+ export declare function resolveEndpoint(client: FacesClient, llm: string): Promise<RouteInfo>;
15
12
  export declare function codexEligible(client: FacesClient, llm: string): Promise<boolean | undefined>;
package/dist/routing.js CHANGED
@@ -1,9 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
- import { CATALOG_INDEX } from './catalog.js';
5
4
  import { DECISION_MODELS } from './decisions.js';
6
- import { seg } from './utils.js';
7
5
  export const MESSAGES_ENDPOINT = '/v1/messages';
8
6
  export const RESPONSES_ENDPOINT = '/v1/responses';
9
7
  export const CHAT_COMPLETIONS_ENDPOINT = '/v1/chat/completions';
@@ -69,55 +67,21 @@ function buildMap(models) {
69
67
  }
70
68
  return map;
71
69
  }
72
- function defaultModelFromCatalog(alias) {
73
- try {
74
- const entries = JSON.parse(fs.readFileSync(CATALOG_INDEX, 'utf8'));
75
- const hit = entries.find((e) => e.alias === alias);
76
- return hit?.default_model || undefined;
77
- }
78
- catch {
79
- return undefined;
80
- }
81
- }
82
70
  export function decisionModelError(llm) {
83
71
  if (!llm)
84
72
  return undefined;
85
73
  const want = llm.toLowerCase();
86
74
  if (!DECISION_MODELS.includes(want))
87
75
  return undefined;
88
- return `${llm} is a decision model, not a chat model; use \`faces decide\``;
76
+ return `${llm} is a decision model, not a chat model; use \`faces decide\` with @<face>:maestro-1/${llm}`;
89
77
  }
90
- export function llmFromArg(modelArg) {
91
- const i = modelArg.lastIndexOf('@');
92
- return i >= 0 ? modelArg.slice(i + 1) : undefined;
93
- }
94
- export function faceSpecOf(modelArg) {
95
- const i = modelArg.lastIndexOf('@');
96
- return i >= 0 ? modelArg.slice(0, i) : modelArg;
97
- }
98
- export function isCompositeFormula(modelArg) {
99
- const spec = faceSpecOf(modelArg).trim();
100
- return /[|&^()]/.test(spec) || /\S\s+\S/.test(spec);
101
- }
102
- export async function resolveEndpoint(client, modelArg) {
103
- let llm = llmFromArg(modelArg);
78
+ export async function resolveEndpoint(client, llm) {
104
79
  const notChat = decisionModelError(llm);
105
80
  if (notChat)
106
81
  throw new Error(notChat);
107
- if (!llm && !isCompositeFormula(modelArg)) {
108
- const alias = modelArg.split('@')[0];
109
- llm = defaultModelFromCatalog(alias);
110
- if (!llm) {
111
- try {
112
- const face = (await client.get(`/v1/faces/${seg(alias)}`));
113
- llm = face.default_model || undefined;
114
- }
115
- catch {
116
- }
117
- }
118
- }
119
82
  const map = buildMap(await getModels(client));
120
- const hit = llm ? map.get(llm.toLowerCase()) : undefined;
83
+ const key = llm.toLowerCase();
84
+ const hit = map.get(key) ?? (key.includes('/') ? map.get(key.slice(key.indexOf('/') + 1)) : undefined);
121
85
  if (hit)
122
86
  return { endpoint: hit.endpoint, llm, freeWhenConnected: hit.freeWhenConnected };
123
87
  return { endpoint: fallbackEndpoint(llm), llm, freeWhenConnected: false };
package/dist/utils.d.ts CHANGED
@@ -23,46 +23,22 @@ export declare function badToolNames(names: string[]): string | undefined;
23
23
  export declare function badFaceName(name: string): string | undefined;
24
24
  export declare function compact(obj: unknown): unknown;
25
25
  export declare function resolveProfileAddendum(text: string | undefined, file: string | undefined): string | undefined;
26
- export declare function resolveCause(text: string | undefined, file: string | undefined): string | undefined;
27
- export declare const CAUSE_FLAG_DESCRIPTION: string;
28
- export declare const CAUSE_FILE_FLAG_DESCRIPTION = "Read --cause from a file.";
29
- export declare function causeNeedsModel(face: string): string;
30
26
  export declare function flattenAttributes(facts: Record<string, unknown>): Record<string, string>;
31
27
  export declare const flattenBasicFacts: typeof flattenAttributes;
32
28
  export declare function renameFaceFields(face: Record<string, unknown>): Record<string, unknown>;
33
29
  export declare function extractStreamDelta(parsed: Record<string, unknown>): string;
34
- export declare function extractStreamReasoning(parsed: Record<string, unknown>): string;
35
- export declare const FACES_THINKING_SIGNATURE = "faces-reasoning";
36
- export declare const FACES_REASONING_ITEM_PREFIX = "rs_faces_";
37
- export declare function extractCause(body: Record<string, unknown>, endpoint: string): {
38
- text: string;
39
- id?: string;
40
- };
41
- export declare function extractReasoning(body: Record<string, unknown>, endpoint: string): string;
42
- export declare const REASONING_FLAG_DESCRIPTION: string;
43
- export declare function reasoningHeading(face: string): string;
44
- export declare function reasoningOnlyNote(face: string, llmFlag?: boolean): string;
45
- export declare function writeReply(model: string, reasoning: string, text: string, showReasoning: boolean, note?: string): void;
46
30
  export declare const STREAM_FLAG_DESCRIPTION: string;
47
31
  export declare function postChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>): Promise<ResponseWithHeaders>;
48
32
  export declare function retryOnceOnWarmUp<T>(send: () => Promise<T>, say?: (seconds: number) => void): Promise<T>;
49
33
  export declare function streamChat(client: FacesClient, endpoint: string, payload: Record<string, unknown>, onHeaders?: (headers: Record<string, string>) => void): AsyncGenerator<string>;
50
34
  export declare function sayWarmUp(seconds: number): void;
51
35
  export declare function compileHint(face: string, recompile: boolean, verb?: string): string;
52
- export declare function faceRefusalHint(err: FacesAPIError, model: string, style?: string): string | undefined;
36
+ export declare function faceRefusalHint(err: FacesAPIError, model: string): string | undefined;
53
37
  export declare const MIN_MAX_OUTPUT_TOKENS = 16;
54
38
  export declare function isMaxTokensRenameError(message: string): boolean;
55
39
  export declare const DOCUMENT_VS_THREAD: string;
56
- export declare const STYLE_FLAG_DESCRIPTION: string;
57
- export declare const MEDIUM_FLAG_DESCRIPTION: string;
58
40
  export declare const SESSION_FLAG_DESCRIPTION: string;
59
41
  export declare const COMPACTION_FLAG_DESCRIPTION: string;
60
- export declare function chatExtras(flags: {
61
- style?: string;
62
- medium?: string;
63
- session?: string;
64
- compaction?: string;
65
- }): Record<string, string>;
66
42
  export declare const MEDIUM_EDIT_DESCRIPTION: () => string;
67
43
  export declare const MEDIUM_REQUIRED_DESCRIPTION: string;
68
44
  export declare const MEDIUM_MISSING_MESSAGE: string;