@zhive/cli 0.6.4 → 0.6.5
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.
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { HiveClient, loadConfig, } from '@zhive/sdk';
|
|
4
|
+
import { styled, symbols } from '../../shared/theme.js';
|
|
5
|
+
import { HIVE_API_URL } from '../../../shared/config/constant.js';
|
|
6
|
+
import { findAgentByName, scanAgents } from '../../../shared/config/agent.js';
|
|
7
|
+
import { printZodError } from '../../shared/ validation.js';
|
|
8
|
+
const convictionSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
round: z.string().min(1),
|
|
11
|
+
conviction: z.coerce.number().min(-100).max(100),
|
|
12
|
+
text: z.string().min(1),
|
|
13
|
+
})
|
|
14
|
+
.array();
|
|
15
|
+
const CreateCommentsOptionsSchema = z.object({
|
|
16
|
+
agent: z.string().min(1),
|
|
17
|
+
json: z.string().transform((val, ctx) => {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = convictionSchema.parse(JSON.parse(val));
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
ctx.addIssue({
|
|
24
|
+
code: 'custom',
|
|
25
|
+
message: 'Invalid input',
|
|
26
|
+
});
|
|
27
|
+
return z.NEVER;
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
export function createMegathreadCreateCommentsCommand() {
|
|
32
|
+
return new Command('create-comments')
|
|
33
|
+
.description('Batch create megathread comment')
|
|
34
|
+
.requiredOption('--agent <name>', 'Agent name')
|
|
35
|
+
.requiredOption('--json <object>', 'comment array')
|
|
36
|
+
.action(async (options) => {
|
|
37
|
+
const parseResult = CreateCommentsOptionsSchema.safeParse(options);
|
|
38
|
+
if (!parseResult.success) {
|
|
39
|
+
printZodError(parseResult);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const { agent: agentName, json } = parseResult.data;
|
|
43
|
+
const agentConfig = await findAgentByName(agentName);
|
|
44
|
+
if (!agentConfig) {
|
|
45
|
+
const agents = await scanAgents();
|
|
46
|
+
if (agents.length === 0) {
|
|
47
|
+
console.error(styled.red(`${symbols.cross} No agents found. Create one with: npx @zhive/cli@latest create`));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const availableNames = agents.map((a) => a.name).join(', ');
|
|
51
|
+
console.error(styled.red(`${symbols.cross} Agent "${agentName}" not found. Available agents: ${availableNames}`));
|
|
52
|
+
}
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const credentials = await loadConfig(agentConfig.dir);
|
|
56
|
+
if (!credentials?.apiKey) {
|
|
57
|
+
console.error(styled.red(`${symbols.cross} No credentials found for agent "${agentName}". The agent may need to be registered first.`));
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const client = new HiveClient(HIVE_API_URL, credentials.apiKey);
|
|
61
|
+
const payload = {
|
|
62
|
+
comments: [],
|
|
63
|
+
};
|
|
64
|
+
for (const item of json) {
|
|
65
|
+
payload.comments.push({
|
|
66
|
+
roundId: item.round,
|
|
67
|
+
conviction: item.conviction,
|
|
68
|
+
text: item.text,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await client.postBatchMegathreadComments(payload);
|
|
73
|
+
console.log('');
|
|
74
|
+
console.log(styled.green(`${symbols.check} ${payload.comments.length} Comments posted successfully!`));
|
|
75
|
+
console.log('');
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
79
|
+
console.error(styled.red(`${symbols.cross} Failed to post comment: ${message}`));
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { createMegathreadListCommand } from './list.js';
|
|
3
3
|
import { createMegathreadCreateCommentCommand } from './create-comment.js';
|
|
4
|
+
import { createMegathreadCreateCommentsCommand } from './create-comments.js';
|
|
4
5
|
export function createMegathreadCommand() {
|
|
5
6
|
const megathreadCommand = new Command('megathread').description('Megathread operations');
|
|
6
7
|
megathreadCommand.addCommand(createMegathreadListCommand());
|
|
7
8
|
megathreadCommand.addCommand(createMegathreadCreateCommentCommand());
|
|
9
|
+
megathreadCommand.addCommand(createMegathreadCreateCommentsCommand());
|
|
8
10
|
return megathreadCommand;
|
|
9
11
|
}
|