faces-cli 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,8 @@ import { BaseCommand } from '../../../base.js';
|
|
|
2
2
|
export default class CompileThreadEdit extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static flags: {
|
|
5
|
-
label: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
5
|
+
label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
|
+
'face-speaker': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
6
7
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
8
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
9
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -2,10 +2,13 @@ import { Args, Flags } from '@oclif/core';
|
|
|
2
2
|
import { BaseCommand } from '../../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../../client.js';
|
|
4
4
|
export default class CompileThreadEdit extends BaseCommand {
|
|
5
|
-
static description = 'Edit a thread (label)';
|
|
5
|
+
static description = 'Edit a thread (label and/or reassign face speaker)';
|
|
6
6
|
static flags = {
|
|
7
7
|
...BaseCommand.baseFlags,
|
|
8
|
-
label: Flags.string({ description: 'New thread label'
|
|
8
|
+
label: Flags.string({ description: 'New thread label' }),
|
|
9
|
+
'face-speaker': Flags.string({
|
|
10
|
+
description: 'Reassign face speaker: set this speaker to role=user, all others to role=assistant',
|
|
11
|
+
}),
|
|
9
12
|
};
|
|
10
13
|
static args = {
|
|
11
14
|
thread_id: Args.string({ description: 'Thread ID', required: true }),
|
|
@@ -13,16 +16,77 @@ export default class CompileThreadEdit extends BaseCommand {
|
|
|
13
16
|
async run() {
|
|
14
17
|
const { args, flags } = await this.parse(CompileThreadEdit);
|
|
15
18
|
const client = this.makeClient(flags);
|
|
19
|
+
const json = this.jsonEnabled();
|
|
20
|
+
if (!flags.label && !flags['face-speaker']) {
|
|
21
|
+
this.error('Provide at least one of --label or --face-speaker');
|
|
22
|
+
}
|
|
23
|
+
// If --face-speaker, fetch messages, remap roles, PATCH back
|
|
24
|
+
if (flags['face-speaker']) {
|
|
25
|
+
const speaker = flags['face-speaker'];
|
|
26
|
+
// Fetch current thread
|
|
27
|
+
let thread;
|
|
28
|
+
try {
|
|
29
|
+
thread = await client.get(`/v1/compile/threads/${args.thread_id}`);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (err instanceof FacesAPIError)
|
|
33
|
+
this.error(`Error (${err.statusCode}): ${err.message}`);
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
const messages = thread.messages;
|
|
37
|
+
if (!messages || messages.length === 0) {
|
|
38
|
+
this.error('Thread has no messages to remap');
|
|
39
|
+
}
|
|
40
|
+
// Remap roles
|
|
41
|
+
let remapped = 0;
|
|
42
|
+
const updated = messages.map((m) => {
|
|
43
|
+
const isFace = m.name && m.name.toLowerCase() === speaker.toLowerCase();
|
|
44
|
+
const newRole = isFace ? 'user' : 'assistant';
|
|
45
|
+
if (m.role !== newRole)
|
|
46
|
+
remapped++;
|
|
47
|
+
return { role: newRole, content: m.content, from: m.name };
|
|
48
|
+
});
|
|
49
|
+
// PATCH messages
|
|
50
|
+
try {
|
|
51
|
+
await client.patch(`/v1/compile/threads/${args.thread_id}/messages`, {
|
|
52
|
+
body: { messages: updated },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (err instanceof FacesAPIError)
|
|
57
|
+
this.error(`Error (${err.statusCode}): ${err.message}`);
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
if (!json) {
|
|
61
|
+
const userCount = updated.filter((m) => m.role === 'user').length;
|
|
62
|
+
const assistantCount = updated.filter((m) => m.role === 'assistant').length;
|
|
63
|
+
process.stderr.write(`Remapped ${remapped} messages: "${speaker}" → user (${userCount}), all others → assistant (${assistantCount})\n`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// If --label, update it
|
|
67
|
+
if (flags.label) {
|
|
68
|
+
try {
|
|
69
|
+
await client.patch(`/v1/compile/threads/${args.thread_id}`, { body: { label: flags.label } });
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err instanceof FacesAPIError)
|
|
73
|
+
this.error(`Error (${err.statusCode}): ${err.message}`);
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
if (!json)
|
|
77
|
+
process.stderr.write(`Label updated to "${flags.label}"\n`);
|
|
78
|
+
}
|
|
79
|
+
// Fetch final state and return
|
|
16
80
|
let data;
|
|
17
81
|
try {
|
|
18
|
-
data = await client.
|
|
82
|
+
data = await client.get(`/v1/compile/threads/${args.thread_id}`);
|
|
19
83
|
}
|
|
20
84
|
catch (err) {
|
|
21
85
|
if (err instanceof FacesAPIError)
|
|
22
86
|
this.error(`Error (${err.statusCode}): ${err.message}`);
|
|
23
87
|
throw err;
|
|
24
88
|
}
|
|
25
|
-
if (!
|
|
89
|
+
if (!json)
|
|
26
90
|
this.printHuman(data);
|
|
27
91
|
return data;
|
|
28
92
|
}
|