openhorizon-cli 1.0.10 → 1.0.14
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 +42 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -234,7 +234,7 @@ async function* streamCompletion(baseUrl, apiKey, model, messages) {
|
|
|
234
234
|
Authorization: `Bearer ${apiKey}`,
|
|
235
235
|
"x-api-key": apiKey,
|
|
236
236
|
"x-client": "openhorizon-cli",
|
|
237
|
-
"x-client-version": "1.0.
|
|
237
|
+
"x-client-version": "1.0.14"
|
|
238
238
|
},
|
|
239
239
|
body: JSON.stringify({
|
|
240
240
|
model,
|
|
@@ -247,13 +247,8 @@ async function* streamCompletion(baseUrl, apiKey, model, messages) {
|
|
|
247
247
|
let errorMessage = res.statusText || String(res.status);
|
|
248
248
|
try {
|
|
249
249
|
const json = JSON.parse(bodyText);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
} else if (json.error) {
|
|
253
|
-
errorMessage = json.error;
|
|
254
|
-
} else {
|
|
255
|
-
errorMessage = bodyText;
|
|
256
|
-
}
|
|
250
|
+
let rawMsg = json.details || json.error || bodyText;
|
|
251
|
+
errorMessage = rawMsg.replace(/^(error:?\s*)+/i, "");
|
|
257
252
|
} catch {
|
|
258
253
|
errorMessage = bodyText || res.statusText || String(res.status);
|
|
259
254
|
}
|
|
@@ -335,12 +330,12 @@ async function runChatLoop(options) {
|
|
|
335
330
|
}
|
|
336
331
|
if (trimmed === "/version") {
|
|
337
332
|
console.log(chalk3.blue(`
|
|
338
|
-
OpenHorizon CLI version: ${chalk3.bold("1.0.
|
|
333
|
+
OpenHorizon CLI version: ${chalk3.bold("1.0.14")}
|
|
339
334
|
`));
|
|
340
335
|
continue;
|
|
341
336
|
}
|
|
342
337
|
if (trimmed === "/update") {
|
|
343
|
-
await runUpdate("1.0.
|
|
338
|
+
await runUpdate("1.0.14");
|
|
344
339
|
continue;
|
|
345
340
|
}
|
|
346
341
|
if (trimmed.startsWith("/history")) {
|
|
@@ -432,7 +427,7 @@ async function runChatLoop(options) {
|
|
|
432
427
|
// src/index.ts
|
|
433
428
|
dotenv.config();
|
|
434
429
|
var program = new Command();
|
|
435
|
-
var version = "1.0.
|
|
430
|
+
var version = "1.0.14";
|
|
436
431
|
program.name("openhorizon").description("CLI to interact with OpenHorizon AI Models").version(version, "-v, --version", "Output the current version");
|
|
437
432
|
program.command("version").description("Show the current CLI version").action(() => {
|
|
438
433
|
console.log(chalk4.blue(`OpenHorizon CLI version: ${chalk4.bold(version)}`));
|
|
@@ -461,13 +456,47 @@ program.command("chat", { isDefault: true }).description("Start an interactive c
|
|
|
461
456
|
const baseUrl = options.baseUrl || process.env.OPENHORIZON_API_URL || "https://api.openhorizon.devwtf.in/v1";
|
|
462
457
|
await runChatLoop({ apiKey, model, baseUrl });
|
|
463
458
|
});
|
|
464
|
-
program.command("model").description("Get or set the default AI model").argument("[modelName]", "The name of the model to set as default").action((modelName) => {
|
|
459
|
+
program.command("model").description("Get or set the default AI model").argument("[modelName]", "The name of the model to set as default").action(async (modelName) => {
|
|
465
460
|
const config = getConfig();
|
|
466
461
|
if (modelName) {
|
|
467
462
|
saveConfig({ defaultModel: modelName });
|
|
468
463
|
console.log(chalk4.green(`\u2713 Default model set to: ${chalk4.bold(modelName)}`));
|
|
469
|
-
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
try {
|
|
467
|
+
const baseUrl = process.env.OPENHORIZON_API_URL || "https://api.openhorizon.devwtf.in/v1";
|
|
468
|
+
console.log(chalk4.gray("\u27F3 Fetching available models..."));
|
|
469
|
+
const response = await fetch(`${baseUrl}/models`);
|
|
470
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
471
|
+
const json = await response.json();
|
|
472
|
+
if (!json.success || !Array.isArray(json.data)) throw new Error("Invalid response format");
|
|
473
|
+
const choices = json.data.flatMap(
|
|
474
|
+
(model) => model.versions.map((v) => ({
|
|
475
|
+
name: `${v.name} ${chalk4.gray(`(${v.size}, ${v.context} context)`)}`,
|
|
476
|
+
value: v.name,
|
|
477
|
+
description: model.description
|
|
478
|
+
}))
|
|
479
|
+
);
|
|
480
|
+
if (choices.length === 0) {
|
|
481
|
+
console.log(chalk4.yellow("! No models available on the server."));
|
|
482
|
+
console.log(chalk4.blue(`Current default model: ${chalk4.bold(config.defaultModel ?? "(not set)")}`));
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
const { select } = await import("@inquirer/prompts");
|
|
486
|
+
const selected = await select({
|
|
487
|
+
message: "Select default AI model:",
|
|
488
|
+
choices,
|
|
489
|
+
pageSize: 10,
|
|
490
|
+
default: config.defaultModel
|
|
491
|
+
});
|
|
492
|
+
saveConfig({ defaultModel: selected });
|
|
493
|
+
console.log(chalk4.green(`\u2713 Default model set to: ${chalk4.bold(selected)}`));
|
|
494
|
+
} catch (error) {
|
|
495
|
+
console.log(chalk4.yellow(`
|
|
496
|
+
! Could not fetch models from server: ${error instanceof Error ? error.message : String(error)}`));
|
|
470
497
|
console.log(chalk4.blue(`Current default model: ${chalk4.bold(config.defaultModel ?? "(not set)")}`));
|
|
498
|
+
console.log(chalk4.gray(`To set manually, use: ${chalk4.white("openhorizon model <name>")}
|
|
499
|
+
`));
|
|
471
500
|
}
|
|
472
501
|
});
|
|
473
502
|
program.command("login").description("Save your OpenHorizon API Key securely to local config").argument("[apiKey]", "Your OpenHorizon API Key").action(async (apiKeyInput) => {
|