sarangai-cli 1.0.3 → 1.0.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.
- package/dist/index.cjs +35 -33
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -59,7 +59,7 @@ function saveConfig(newConfig) {
|
|
|
59
59
|
var program = new import_commander.Command();
|
|
60
60
|
function resolveBaseUrl() {
|
|
61
61
|
const cfg = getConfig();
|
|
62
|
-
return process.env.SARANGAI_BASE_URL || cfg.baseUrl || "https://
|
|
62
|
+
return process.env.SARANGAI_BASE_URL || cfg.baseUrl || "https://idshop.or.id";
|
|
63
63
|
}
|
|
64
64
|
function getGitBranch() {
|
|
65
65
|
try {
|
|
@@ -81,7 +81,7 @@ function renderBanner(modelName) {
|
|
|
81
81
|
console.log(import_chalk.default.cyanBright(banner));
|
|
82
82
|
console.log(import_chalk.default.gray(" Tips for getting started:"));
|
|
83
83
|
console.log(import_chalk.default.gray(" 1. Ketik pesan Anda langsung untuk chat streaming."));
|
|
84
|
-
console.log(import_chalk.default.gray(" 2. Perintah
|
|
84
|
+
console.log(import_chalk.default.gray(" 2. Perintah: ") + import_chalk.default.yellow("/clear") + import_chalk.default.gray(", ") + import_chalk.default.yellow("/model <id>") + import_chalk.default.gray(", ") + import_chalk.default.yellow("/exit") + import_chalk.default.gray("."));
|
|
85
85
|
console.log("");
|
|
86
86
|
const cwd = import_path2.default.basename(process.cwd());
|
|
87
87
|
const branch = getGitBranch();
|
|
@@ -94,7 +94,7 @@ function renderBanner(modelName) {
|
|
|
94
94
|
async function startInteractiveSession(initialModel) {
|
|
95
95
|
const cfg = getConfig();
|
|
96
96
|
if (!cfg.apiKey) {
|
|
97
|
-
console.log(import_chalk.default.yellow("
|
|
97
|
+
console.log(import_chalk.default.yellow("\nSilakan login terlebih dahulu: sarang login\n"));
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
let currentModel = initialModel || cfg.defaultModel || "minimax/minimax-m2.7";
|
|
@@ -133,7 +133,7 @@ async function startInteractiveSession(initialModel) {
|
|
|
133
133
|
`));
|
|
134
134
|
} else {
|
|
135
135
|
console.log(import_chalk.default.yellow(`
|
|
136
|
-
Format: /model <model-id>
|
|
136
|
+
Format: /model <model-id>
|
|
137
137
|
`));
|
|
138
138
|
}
|
|
139
139
|
ask();
|
|
@@ -201,30 +201,44 @@ Error: ${err.message}
|
|
|
201
201
|
};
|
|
202
202
|
ask();
|
|
203
203
|
}
|
|
204
|
-
program.name("sarang").description(import_chalk.default.cyanBright("SarangAI CLI \u2014 Gateway ratusan model AI langsung di terminal")).version("1.0.
|
|
204
|
+
program.name("sarang").description(import_chalk.default.cyanBright("SarangAI CLI \u2014 Gateway ratusan model AI langsung di terminal")).version("1.0.3").action(() => {
|
|
205
205
|
startInteractiveSession();
|
|
206
206
|
});
|
|
207
207
|
program.command("login").description("Hubungkan API Key SarangAI akun Anda").action(async () => {
|
|
208
208
|
const baseUrl = resolveBaseUrl();
|
|
209
209
|
console.log(import_chalk.default.cyanBright("\n\u{1F510} Autentikasi SarangAI CLI"));
|
|
210
|
-
console.log(import_chalk.default.gray("Dapatkan API Key
|
|
210
|
+
console.log(import_chalk.default.gray("Dapatkan API Key di: ") + import_chalk.default.underline.cyan(`${baseUrl}/dashboard`));
|
|
211
211
|
console.log(import_chalk.default.gray("--------------------------------------------------\n"));
|
|
212
212
|
const res = await (0, import_prompts.default)({
|
|
213
213
|
type: "password",
|
|
214
214
|
name: "key",
|
|
215
|
-
message: "Masukkan
|
|
215
|
+
message: "Masukkan API Key:"
|
|
216
216
|
});
|
|
217
217
|
if (!res.key) {
|
|
218
218
|
console.log(import_chalk.default.red("\nLogin dibatalkan.\n"));
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
221
221
|
saveConfig({ apiKey: res.key.trim() });
|
|
222
|
-
console.log(import_chalk.default.green("\n\u2714 Berhasil
|
|
222
|
+
console.log(import_chalk.default.green("\n\u2714 Berhasil! API Key tersimpan di ~/.sarangairc\n"));
|
|
223
|
+
});
|
|
224
|
+
program.command("set-url [url]").description("Atur Base URL Gateway SarangAI").action(async (url) => {
|
|
225
|
+
let target = url;
|
|
226
|
+
if (!target) {
|
|
227
|
+
const res = await (0, import_prompts.default)({
|
|
228
|
+
type: "text",
|
|
229
|
+
name: "url",
|
|
230
|
+
message: "Masukkan URL Gateway:"
|
|
231
|
+
});
|
|
232
|
+
target = res.url;
|
|
233
|
+
}
|
|
234
|
+
if (!target) return;
|
|
235
|
+
saveConfig({ baseUrl: target.trim().replace(/\/+$/, "") });
|
|
236
|
+
console.log(import_chalk.default.green(`\u2714 Base URL diatur ke: ${target.trim()}`));
|
|
223
237
|
});
|
|
224
238
|
program.command("balance").description("Cek sisa saldo kredit akun SarangAI Anda").action(async () => {
|
|
225
239
|
const cfg = getConfig();
|
|
226
240
|
if (!cfg.apiKey) {
|
|
227
|
-
console.log(import_chalk.default.yellow("
|
|
241
|
+
console.log(import_chalk.default.yellow("\nAnda belum login. Jalankan: sarang login\n"));
|
|
228
242
|
return;
|
|
229
243
|
}
|
|
230
244
|
const baseUrl = resolveBaseUrl();
|
|
@@ -238,7 +252,7 @@ program.command("balance").description("Cek sisa saldo kredit akun SarangAI Anda
|
|
|
238
252
|
try {
|
|
239
253
|
data = JSON.parse(rawText);
|
|
240
254
|
} catch {
|
|
241
|
-
throw new Error(`
|
|
255
|
+
throw new Error(`Respons server non-JSON (${res.status}): ${rawText.slice(0, 100)}`);
|
|
242
256
|
}
|
|
243
257
|
spinner.stop();
|
|
244
258
|
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
|
|
@@ -250,11 +264,11 @@ program.command("balance").description("Cek sisa saldo kredit akun SarangAI Anda
|
|
|
250
264
|
spinner.fail(import_chalk.default.red(err.message));
|
|
251
265
|
}
|
|
252
266
|
});
|
|
253
|
-
program.command("models").option("-s, --search <keyword>", "Filter nama model
|
|
267
|
+
program.command("models").option("-s, --search <keyword>", "Filter nama model").description("Daftar model AI yang tersedia").action(async (cmd) => {
|
|
254
268
|
var _a;
|
|
255
269
|
const cfg = getConfig();
|
|
256
270
|
if (!cfg.apiKey) {
|
|
257
|
-
console.log(import_chalk.default.yellow("
|
|
271
|
+
console.log(import_chalk.default.yellow("\nAnda belum login. Jalankan: sarang login\n"));
|
|
258
272
|
return;
|
|
259
273
|
}
|
|
260
274
|
const baseUrl = resolveBaseUrl();
|
|
@@ -274,34 +288,22 @@ program.command("models").option("-s, --search <keyword>", "Filter nama model (c
|
|
|
274
288
|
if (!res.ok) throw new Error(((_a = data.error) == null ? void 0 : _a.message) || data.error || `HTTP ${res.status}`);
|
|
275
289
|
let list = Array.isArray(data) ? data : data.data || [];
|
|
276
290
|
if (list.length === 0) {
|
|
277
|
-
console.log(import_chalk.default.yellow("Tidak ada model
|
|
291
|
+
console.log(import_chalk.default.yellow("Tidak ada model yang ditemukan."));
|
|
278
292
|
return;
|
|
279
293
|
}
|
|
280
294
|
if (cmd.search) {
|
|
281
|
-
const
|
|
282
|
-
list = list.filter((m) =>
|
|
283
|
-
const id = (m.id || m.modelId || m.name || "").toLowerCase();
|
|
284
|
-
return id.includes(query);
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
if (list.length === 0) {
|
|
288
|
-
console.log(import_chalk.default.yellow(`
|
|
289
|
-
Tidak ada model yang cocok dengan kata kunci "${cmd.search}".
|
|
290
|
-
`));
|
|
291
|
-
return;
|
|
295
|
+
const q = cmd.search.toLowerCase();
|
|
296
|
+
list = list.filter((m) => (m.id || m.modelId || m.name || "").toLowerCase().includes(q));
|
|
292
297
|
}
|
|
293
298
|
console.log(import_chalk.default.bold(`
|
|
294
|
-
Model Tersedia (${list.length}
|
|
299
|
+
Model Tersedia (${list.length}):`));
|
|
295
300
|
console.log(import_chalk.default.gray("---------------------------------------------------------"));
|
|
296
301
|
list.forEach((m) => {
|
|
297
302
|
const id = m.id || m.modelId || m.name;
|
|
298
303
|
const isCurrent = id === cfg.defaultModel;
|
|
299
|
-
|
|
300
|
-
console.log(`${prefix}${import_chalk.default.cyan(id)}`);
|
|
304
|
+
console.log(`${isCurrent ? import_chalk.default.green("\u2714 [Aktif] ") : " "}${import_chalk.default.cyan(id)}`);
|
|
301
305
|
});
|
|
302
|
-
console.log(import_chalk.default.gray("
|
|
303
|
-
console.log(import_chalk.default.dim("Ganti model default : sarang set-model <model-id>"));
|
|
304
|
-
console.log(import_chalk.default.dim('Chat model tertentu : sarang chat -m <model-id> "..."\n'));
|
|
306
|
+
console.log(import_chalk.default.gray("---------------------------------------------------------\n"));
|
|
305
307
|
} catch (err) {
|
|
306
308
|
spinner.fail(import_chalk.default.red(err.message));
|
|
307
309
|
}
|
|
@@ -312,7 +314,7 @@ program.command("set-model [modelId]").description("Atur model default untuk cha
|
|
|
312
314
|
const res = await (0, import_prompts.default)({
|
|
313
315
|
type: "text",
|
|
314
316
|
name: "model",
|
|
315
|
-
message: "Masukkan Model ID default baru
|
|
317
|
+
message: "Masukkan Model ID default baru:"
|
|
316
318
|
});
|
|
317
319
|
target = res.model;
|
|
318
320
|
}
|
|
@@ -320,7 +322,7 @@ program.command("set-model [modelId]").description("Atur model default untuk cha
|
|
|
320
322
|
saveConfig({ defaultModel: target.trim() });
|
|
321
323
|
console.log(import_chalk.default.green(`\u2714 Default model berhasil diubah ke: ${target.trim()}`));
|
|
322
324
|
});
|
|
323
|
-
program.command("chat [prompt...]").option("-m, --model <modelId>", "Pilih model
|
|
325
|
+
program.command("chat [prompt...]").option("-m, --model <modelId>", "Pilih model spesifik").description("Kirim instruksi / chat (Mendukung streaming teks atau Unix Pipe)").action(async (promptArr, cmd) => {
|
|
324
326
|
var _a, _b, _c, _d, _e;
|
|
325
327
|
let prompt = promptArr == null ? void 0 : promptArr.join(" ");
|
|
326
328
|
if (!process.stdin.isTTY) {
|
|
@@ -339,7 +341,7 @@ ${pipedData}` : pipedData;
|
|
|
339
341
|
}
|
|
340
342
|
const cfg = getConfig();
|
|
341
343
|
if (!cfg.apiKey) {
|
|
342
|
-
console.log(import_chalk.default.yellow("
|
|
344
|
+
console.log(import_chalk.default.yellow("\nSilakan login terlebih dahulu: sarang login\n"));
|
|
343
345
|
return;
|
|
344
346
|
}
|
|
345
347
|
const baseUrl = resolveBaseUrl();
|