kiosapi 0.1.1 → 0.1.3
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/api.js +16 -0
- package/dist/commands.js +60 -1
- package/dist/help.js +18 -2
- package/dist/index.js +3 -1
- package/dist/session.js +26 -29
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -21,6 +21,22 @@ export async function fetchModels() {
|
|
|
21
21
|
const body = (await res.json());
|
|
22
22
|
return body.data ?? [];
|
|
23
23
|
}
|
|
24
|
+
/** Latest published version of the CLI on npm (best-effort; null on failure/offline). */
|
|
25
|
+
export async function fetchLatestVersion(timeoutMs = 2500) {
|
|
26
|
+
try {
|
|
27
|
+
const ctrl = new AbortController();
|
|
28
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
29
|
+
const res = await fetch('https://registry.npmjs.org/kiosapi/latest', { signal: ctrl.signal });
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
if (!res.ok)
|
|
32
|
+
return null;
|
|
33
|
+
const body = (await res.json());
|
|
34
|
+
return body.version ?? null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
24
40
|
/** Best-effort: does a model support tool calling? Defaults to true if unknown/offline. */
|
|
25
41
|
export async function modelSupportsTools(id) {
|
|
26
42
|
try {
|
package/dist/commands.js
CHANGED
|
@@ -5,8 +5,9 @@ import { createInterface } from 'node:readline/promises';
|
|
|
5
5
|
import { parseArgs } from 'node:util';
|
|
6
6
|
import { runAgent } from './agent/run.js';
|
|
7
7
|
import { runTeam } from './agent/team.js';
|
|
8
|
-
import { createTopup, fetchBytesAuthed, fetchModels, fetchPemakaian, fetchSaldo, generateImage, modelSupportsTools, pollJob, resolveMediaModel, resolveModel, streamChat, streamVision, submitVideo, } from './api.js';
|
|
8
|
+
import { createTopup, fetchBytesAuthed, fetchLatestVersion, fetchModels, fetchPemakaian, fetchSaldo, generateImage, modelSupportsTools, pollJob, resolveMediaModel, resolveModel, streamChat, streamVision, submitVideo, } from './api.js';
|
|
9
9
|
import { clearKey, fileConfig, loadConfig, saveConfig } from './config.js';
|
|
10
|
+
import { VERSION } from './help.js';
|
|
10
11
|
import { bold, cyan, dim, green, idn, prompt, promptHidden, readStdin, red, rupiah, sleep, thinking, yellow, } from './ui.js';
|
|
11
12
|
const IMAGE_MIME = {
|
|
12
13
|
'.png': 'image/png',
|
|
@@ -48,6 +49,64 @@ export async function cmdPeriksa() {
|
|
|
48
49
|
catch {
|
|
49
50
|
console.log(red('tidak terhubung'));
|
|
50
51
|
}
|
|
52
|
+
const latest = await fetchLatestVersion();
|
|
53
|
+
const upd = latest && isNewerVersion(latest, VERSION)
|
|
54
|
+
? yellow(` → versi ${latest} tersedia (kiosapi perbarui)`)
|
|
55
|
+
: latest
|
|
56
|
+
? green(' ✓ terbaru')
|
|
57
|
+
: '';
|
|
58
|
+
console.log(` Versi : ${VERSION}${upd}`);
|
|
59
|
+
}
|
|
60
|
+
/** Compare two dotted versions; true if `latest` is strictly newer than `current`. */
|
|
61
|
+
function isNewerVersion(latest, current) {
|
|
62
|
+
const a = latest.split('.').map((n) => Number(n) || 0);
|
|
63
|
+
const b = current.split('.').map((n) => Number(n) || 0);
|
|
64
|
+
for (let i = 0; i < 3; i++) {
|
|
65
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0))
|
|
66
|
+
return (a[i] ?? 0) > (b[i] ?? 0);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/** perbarui — update the CLI to the latest npm version (or print the manual command). */
|
|
71
|
+
export async function cmdPerbarui() {
|
|
72
|
+
const latest = await fetchLatestVersion();
|
|
73
|
+
if (!latest) {
|
|
74
|
+
console.log(dim('Tak bisa cek versi terbaru (offline?).'));
|
|
75
|
+
console.log(`Update manual: ${cyan('npm i -g kiosapi@latest')}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!isNewerVersion(latest, VERSION)) {
|
|
79
|
+
console.log(green(`✓ Sudah versi terbaru (${VERSION}).`));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
console.log(`Versi baru ${green(latest)} (sekarang ${VERSION}). Memperbarui…`);
|
|
83
|
+
const res = spawnSync('npm', ['i', '-g', `kiosapi@${latest}`], {
|
|
84
|
+
stdio: 'inherit',
|
|
85
|
+
shell: process.platform === 'win32',
|
|
86
|
+
});
|
|
87
|
+
if (res.status === 0) {
|
|
88
|
+
console.log(green(`✓ Terpasang kiosapi ${latest}.`));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(yellow('Gagal update otomatis. Jalankan manual:'));
|
|
92
|
+
console.log(` ${cyan('npm i -g kiosapi@latest')}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Once-a-day best-effort "versi baru tersedia" nudge (TTY only; cached in config). */
|
|
96
|
+
export async function maybeNotifyUpdate() {
|
|
97
|
+
if (!process.stdout.isTTY)
|
|
98
|
+
return;
|
|
99
|
+
const cfg = fileConfig();
|
|
100
|
+
const now = Date.now();
|
|
101
|
+
const DAY = 24 * 3_600_000;
|
|
102
|
+
let latest = cfg.latestVersion;
|
|
103
|
+
if (!cfg.updateCheckedAt || now - cfg.updateCheckedAt > DAY) {
|
|
104
|
+
latest = (await fetchLatestVersion(1500)) ?? undefined;
|
|
105
|
+
saveConfig({ updateCheckedAt: now, latestVersion: latest });
|
|
106
|
+
}
|
|
107
|
+
if (latest && isNewerVersion(latest, VERSION)) {
|
|
108
|
+
console.log(yellow(`Versi baru kiosapi ${latest} tersedia (sekarang ${VERSION}). Jalankan: kiosapi perbarui`));
|
|
109
|
+
}
|
|
51
110
|
}
|
|
52
111
|
/** model — list available models. `--cari q` filters; `--tools` shows only tool-capable models. */
|
|
53
112
|
export async function cmdModel(args) {
|
package/dist/help.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
1
2
|
import { bold, dim } from './ui.js';
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Version — single source of truth is package.json (always shipped in the npm tarball, sitting next
|
|
5
|
+
* to dist/). Read at runtime so a bump only needs editing package.json (e.g. `npm version patch`).
|
|
6
|
+
* dist/help.js → ../package.json resolves to the package root in both dev and the published package.
|
|
7
|
+
*/
|
|
8
|
+
function readVersion() {
|
|
9
|
+
try {
|
|
10
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
11
|
+
return pkg.version ?? '0.0.0';
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return '0.0.0';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const VERSION = readVersion();
|
|
3
18
|
export function printVersion() {
|
|
4
19
|
console.log(`kiosapi ${VERSION}`);
|
|
5
20
|
}
|
|
@@ -12,7 +27,8 @@ ${bold('Penggunaan:')} kiosapi [perintah] [opsi]
|
|
|
12
27
|
${bold('Perintah:')}
|
|
13
28
|
masuk Simpan API key (kios_live_…)
|
|
14
29
|
keluar Hapus API key tersimpan
|
|
15
|
-
periksa Cek konektivitas, key, & setelan
|
|
30
|
+
periksa Cek konektivitas, key, versi & setelan
|
|
31
|
+
perbarui Update CLI ke versi npm terbaru
|
|
16
32
|
model [--cari q] Daftar model (--tools = hanya yang mendukung tool/agen; 🔧)
|
|
17
33
|
tanya "…" Tanya sekali (streaming); dukung pipe stdin
|
|
18
34
|
ngobrol Mode percakapan interaktif (REPL)
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { cmdBuat, cmdEdit, cmdGambar, cmdIsi, cmdKeluar, cmdLihat, cmdMasuk, cmdModel, cmdNgobrol, cmdPakai, cmdPeriksa, cmdRencana, cmdSaldo, cmdSambung, cmdSetel, cmdTanya, cmdTim, cmdVideo, } from './commands.js';
|
|
2
|
+
import { cmdBuat, cmdEdit, cmdGambar, cmdIsi, cmdKeluar, cmdLihat, cmdMasuk, cmdModel, cmdNgobrol, cmdPakai, cmdPerbarui, cmdPeriksa, cmdRencana, cmdSaldo, cmdSambung, cmdSetel, cmdTanya, cmdTim, cmdVideo, } from './commands.js';
|
|
3
3
|
import { printHelp, printVersion } from './help.js';
|
|
4
4
|
import { startSession } from './session.js';
|
|
5
5
|
import { red } from './ui.js';
|
|
@@ -11,6 +11,8 @@ const COMMANDS = {
|
|
|
11
11
|
logout: cmdKeluar,
|
|
12
12
|
periksa: cmdPeriksa,
|
|
13
13
|
doctor: cmdPeriksa,
|
|
14
|
+
perbarui: cmdPerbarui,
|
|
15
|
+
update: cmdPerbarui,
|
|
14
16
|
model: cmdModel,
|
|
15
17
|
models: cmdModel,
|
|
16
18
|
tanya: cmdTanya,
|
package/dist/session.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { createInterface } from 'node:readline/promises';
|
|
2
1
|
import { newSession, resetSession, runTurn } from './agent/run.js';
|
|
3
2
|
import { runTeam } from './agent/team.js';
|
|
4
3
|
import { resolveModel } from './api.js';
|
|
5
|
-
import { cmdGambar, cmdIsi, cmdLihat, cmdMasuk, cmdPakai, cmdSaldo, cmdVideo, pickModel, warnIfNoTools, } from './commands.js';
|
|
4
|
+
import { cmdGambar, cmdIsi, cmdLihat, cmdMasuk, cmdPakai, cmdSaldo, cmdVideo, maybeNotifyUpdate, pickModel, warnIfNoTools, } from './commands.js';
|
|
6
5
|
import { loadConfig } from './config.js';
|
|
7
|
-
import { bold, cyan, dim, green, red } from './ui.js';
|
|
6
|
+
import { bold, cyan, dim, green, prompt, red } from './ui.js';
|
|
8
7
|
const MODES = ['rencana', 'edit', 'buat'];
|
|
9
8
|
/** The prompt indicator shows the active mode (and ⚡ when auto-approve is on). */
|
|
10
9
|
function label(s) {
|
|
@@ -134,37 +133,35 @@ export async function startSession() {
|
|
|
134
133
|
if (!loadConfig().apiKey)
|
|
135
134
|
return;
|
|
136
135
|
}
|
|
136
|
+
await maybeNotifyUpdate();
|
|
137
137
|
const model = await resolveModel(undefined);
|
|
138
138
|
const s = newSession(model, 'buat', false);
|
|
139
139
|
banner(s);
|
|
140
140
|
await warnIfNoTools(model);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
141
|
+
// One readline at a time: each turn uses prompt() (create+close), and slash commands that need
|
|
142
|
+
// their own input (e.g. /model picker, masuk) also use prompt(). A persistent interface here would
|
|
143
|
+
// collide with those → double-echoed input and a stray close that exits the session.
|
|
144
|
+
while (true) {
|
|
145
|
+
let line;
|
|
146
|
+
try {
|
|
147
|
+
line = (await prompt(label(s))).trim();
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
break; // stdin closed (Ctrl+D / EOF)
|
|
151
|
+
}
|
|
152
|
+
if (!line)
|
|
153
|
+
continue;
|
|
154
|
+
if (line.startsWith('/')) {
|
|
155
|
+
if (await runSlash(line, s))
|
|
156
|
+
break;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
await runTurn(s, line);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
console.error(red(err instanceof Error ? err.message : String(err)));
|
|
164
164
|
}
|
|
165
|
-
}
|
|
166
|
-
finally {
|
|
167
|
-
rl.close();
|
|
168
165
|
}
|
|
169
166
|
console.log(green('Sampai jumpa.'));
|
|
170
167
|
}
|