ardabot 0.2.0 → 0.2.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.
- package/dist/index.js +92 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1206,9 +1206,100 @@ async function unlinkDevice(rl, client, devices) {
|
|
|
1206
1206
|
}
|
|
1207
1207
|
}
|
|
1208
1208
|
|
|
1209
|
+
// src/commands/print.ts
|
|
1210
|
+
import { EventSourceParserStream as EventSourceParserStream2 } from "eventsource-parser/stream";
|
|
1211
|
+
async function printCommand(options) {
|
|
1212
|
+
if (!hasCredentials()) {
|
|
1213
|
+
process.stderr.write("Error: Not logged in. Run `ardabot login` or `ardabot auth` first.\n");
|
|
1214
|
+
process.exit(1);
|
|
1215
|
+
}
|
|
1216
|
+
const parts = [];
|
|
1217
|
+
if (!process.stdin.isTTY) {
|
|
1218
|
+
const stdin = await readStdin();
|
|
1219
|
+
if (stdin.length > 0) {
|
|
1220
|
+
parts.push(stdin);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (typeof options.prompt === "string" && options.prompt.length > 0) {
|
|
1224
|
+
parts.push(options.prompt);
|
|
1225
|
+
}
|
|
1226
|
+
if (parts.length === 0) {
|
|
1227
|
+
process.stderr.write("Error: No prompt provided. Pass a prompt after -p or pipe input via stdin.\n");
|
|
1228
|
+
process.exit(1);
|
|
1229
|
+
}
|
|
1230
|
+
const message = parts.join("\n\n");
|
|
1231
|
+
const sessionId = options.session ?? `cli:${Date.now()}`;
|
|
1232
|
+
const client = new ApiClient();
|
|
1233
|
+
try {
|
|
1234
|
+
await streamPrint(client, message, sessionId);
|
|
1235
|
+
process.stdout.write("\n");
|
|
1236
|
+
} catch (err) {
|
|
1237
|
+
process.stderr.write(`Error: ${err.message}
|
|
1238
|
+
`);
|
|
1239
|
+
process.exit(1);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
async function streamPrint(client, message, sessionId) {
|
|
1243
|
+
let responseBody;
|
|
1244
|
+
try {
|
|
1245
|
+
responseBody = await client.chatStream(message, sessionId);
|
|
1246
|
+
} catch {
|
|
1247
|
+
const result = await client.chat(message, sessionId);
|
|
1248
|
+
process.stdout.write(result.response);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
const eventStream = responseBody.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2());
|
|
1252
|
+
let hasText = false;
|
|
1253
|
+
for await (const event of eventStream) {
|
|
1254
|
+
if (event.data === "[DONE]") {
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
try {
|
|
1258
|
+
const chunk = JSON.parse(event.data);
|
|
1259
|
+
switch (chunk.type) {
|
|
1260
|
+
case "text":
|
|
1261
|
+
if (chunk.text) {
|
|
1262
|
+
process.stdout.write(chunk.text);
|
|
1263
|
+
hasText = true;
|
|
1264
|
+
}
|
|
1265
|
+
break;
|
|
1266
|
+
case "done":
|
|
1267
|
+
if (!hasText && chunk.output?.response) {
|
|
1268
|
+
process.stdout.write(chunk.output.response);
|
|
1269
|
+
}
|
|
1270
|
+
break;
|
|
1271
|
+
case "error":
|
|
1272
|
+
if (chunk.error) {
|
|
1273
|
+
throw new Error(chunk.error);
|
|
1274
|
+
}
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
} catch (err) {
|
|
1278
|
+
if (err instanceof Error && err.message !== "Unexpected end of JSON input") {
|
|
1279
|
+
throw err;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
function readStdin() {
|
|
1285
|
+
return new Promise((resolve, reject) => {
|
|
1286
|
+
const chunks = [];
|
|
1287
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
1288
|
+
process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8").trim()));
|
|
1289
|
+
process.stdin.on("error", reject);
|
|
1290
|
+
process.stdin.resume();
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1209
1294
|
// src/index.ts
|
|
1210
1295
|
var program = new Command();
|
|
1211
|
-
program.name("ardabot").description("Your AI sidekick, from the terminal.").version("0.1.0")
|
|
1296
|
+
program.name("ardabot").description("Your AI sidekick, from the terminal.").version("0.1.0").option("-p, --print [prompt]", "Send a prompt and print the response (non-interactive)").option("--session <id>", "Session ID (use with -p)").action(async (options) => {
|
|
1297
|
+
if (options.print !== void 0) {
|
|
1298
|
+
await printCommand({ prompt: options.print, session: options.session });
|
|
1299
|
+
} else {
|
|
1300
|
+
program.help();
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1212
1303
|
program.command("login").description("Log in or sign up").option("--url <url>", "API base URL").option("--promo <code>", "Redeem a promo code during signup").action(loginCommand);
|
|
1213
1304
|
program.command("auth").description("Log in with an API key").requiredOption("--api-key <key>", "API key (arda_sk_...)").option("--url <url>", "API base URL").action(authCommand);
|
|
1214
1305
|
program.command("chat").description("Talk to your agent").option("--session <id>", "Session ID for conversation continuity").action(chatCommand);
|