-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.mjs
More file actions
executable file
·208 lines (176 loc) · 5.4 KB
/
cli.mjs
File metadata and controls
executable file
·208 lines (176 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env node
/**
* Mind Reasoner CLI - Direct usage without MCP
* Use this to interact with Mind Reasoner API directly
*/
import { readFile } from "node:fs/promises";
import axios from "axios";
import dotenv from "dotenv";
import FormData from "form-data";
dotenv.config();
const API_BASE_URL = "https://app.mindreasoner.com/api/public/v1";
const API_KEY = process.env.MIND_REASONER_API_KEY;
if (!API_KEY) {
console.error("❌ Error: MIND_REASONER_API_KEY not set in .env file");
process.exit(1);
}
const api = axios.create({
baseURL: API_BASE_URL,
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
});
// Command line arguments
const command = process.argv[2];
const args = process.argv.slice(3);
async function createMind(name) {
console.log(`📝 Creating mind: "${name}"...`);
const response = await api.post("/minds", { name });
console.log("\n✅ Mind created successfully!\n");
console.log("Mind ID:", response.data.mind?.id);
console.log("Digital Twin ID:", response.data.digitalTwin?.id);
console.log("\n💾 Save these IDs for next steps!");
return response.data;
}
async function getSignedUrl(mindId, contentType = "application/octet-stream") {
console.log(`🔐 Getting signed upload URL for mind: ${mindId}...`);
const response = await api.get(
`/minds/${mindId}/signed-url?contentType=${contentType}`,
);
console.log("\n✅ Signed URL obtained!\n");
console.log("Artifact ID:", response.data.artifactId);
console.log("Signed URL:", `${response.data.signedUrl.substring(0, 50)}...`);
console.log("Content Type:", response.data.contentType);
console.log("\n💾 Save the Artifact ID!");
return response.data;
}
async function uploadFile(
signedUrl,
filePath,
contentType = "application/octet-stream",
) {
console.log(`📤 Uploading file: ${filePath}...`);
const fileContent = await readFile(filePath);
await axios.put(signedUrl, fileContent, {
headers: { "Content-Type": contentType },
});
console.log("\n✅ File uploaded successfully!");
}
async function createSnapshot(mindId, digitalTwinId, artifactId) {
console.log(`📸 Creating snapshot...`);
const form = new FormData();
form.append("digitalTwinId", digitalTwinId);
form.append("artifactId", artifactId);
const response = await axios.post(
`${API_BASE_URL}/minds/${mindId}/snapshots`,
form,
{
headers: {
...form.getHeaders(),
Authorization: `Bearer ${API_KEY}`,
},
},
);
console.log("\n✅ Snapshot creation started!\n");
console.log("Snapshot ID:", response.data.mindAssessmentId);
console.log(
'\n⏳ Snapshot is processing. Use "check-status" to monitor progress.',
);
return response.data;
}
async function checkStatus(mindId, snapshotId) {
console.log(`🔍 Checking snapshot status...`);
const response = await api.get(
`/minds/${mindId}/snapshots/${snapshotId}/status`,
);
console.log("\n📊 Status:", response.data.status);
if (response.data.status === "completed") {
console.log("✅ Snapshot is ready for simulation!");
} else {
console.log("⏳ Still processing... check again in a few minutes.");
}
return response.data;
}
async function simulate(mindId, scenario, model = "mind-reasoner-pro") {
console.log(`🎭 Running simulation...`);
const response = await api.post("/simulate", {
mindId,
selectedSimulationModel: model,
scenario: { message: scenario },
});
console.log("\n✅ Simulation complete!\n");
console.log("Response:", response.data.message);
return response.data;
}
// Help text
function showHelp() {
console.log(`
🧠 Mind Reasoner CLI
USAGE:
node cli.mjs <command> [arguments]
COMMANDS:
create <name>
Create a new mind
Example: node cli.mjs create "Customer Service Rep"
upload-url <mindId>
Get signed URL for uploading data
Example: node cli.mjs upload-url abc123-def456
upload <signedUrl> <filePath> <contentType>
Upload a file to signed URL
Example: node cli.mjs upload "https://..." ./transcript.vtt text/vtt
snapshot <mindId> <digitalTwinId> <artifactId>
Create snapshot from uploaded data
Example: node cli.mjs snapshot mind123 twin456 artifact789
status <mindId> <snapshotId>
Check snapshot processing status
Example: node cli.mjs status mind123 snapshot456
simulate <mindId> <scenario> [model]
Run a simulation
Example: node cli.mjs simulate mind123 "How would you handle this?"
help
Show this help message
ENVIRONMENT:
Set MIND_REASONER_API_KEY in .env file
EXAMPLES:
# Complete workflow
node cli.mjs create "Sales Assistant"
node cli.mjs upload-url <mindId>
node cli.mjs upload <signedUrl> ./data.vtt text/vtt
node cli.mjs snapshot <mindId> <digitalTwinId> <artifactId>
node cli.mjs status <mindId> <snapshotId>
node cli.mjs simulate <mindId> "How should I approach this sale?"
`);
}
// Main
async function main() {
try {
switch (command) {
case "create":
await createMind(args[0]);
break;
case "upload-url":
await getSignedUrl(args[0], args[1]);
break;
case "upload":
await uploadFile(args[0], args[1], args[2]);
break;
case "snapshot":
await createSnapshot(args[0], args[1], args[2]);
break;
case "status":
await checkStatus(args[0], args[1]);
break;
case "simulate":
await simulate(args[0], args[1], args[2]);
break;
default:
showHelp();
break;
}
} catch (error) {
console.error("\n❌ Error:", error.response?.data || error.message);
process.exit(1);
}
}
main();