sarangai-cli 1.0.10 → 1.0.11

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -10
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -35,12 +35,12 @@ var require_package = __commonJS({
35
35
  "package.json"(exports2, module2) {
36
36
  module2.exports = {
37
37
  name: "sarangai-cli",
38
- version: "1.0.10",
38
+ version: "1.0.11",
39
39
  description: "CLI resmi SarangAI \u2014 Gateway multi-model AI langsung dari terminal Anda",
40
40
  main: "dist/index.js",
41
41
  bin: {
42
42
  sarang: "dist/index.js",
43
- sarangai: "dist/index.cjs"
43
+ sarangai: "dist/index.js"
44
44
  },
45
45
  files: [
46
46
  "dist"
@@ -131,8 +131,8 @@ var greenDot = import_chalk.default.hex("#4ade80");
131
131
  var grayMuted = import_chalk.default.hex("#94a3b8");
132
132
  var CODING_MODELS = [
133
133
  {
134
- id: "anthropic/claude-3.7-sonnet",
135
- name: "Claude 3.7 Sonnet",
134
+ id: "anthropic/claude-sonnet-4.6",
135
+ name: "Claude Sonnet 4.6",
136
136
  desc: "Anthropic \u2022 Best coding & agentic workflow",
137
137
  rate: "12,000 Credits/hr"
138
138
  },
@@ -183,20 +183,20 @@ function copyToClipboard(text) {
183
183
  }
184
184
  async function fetchUserMeta(baseUrl2, apiKey) {
185
185
  try {
186
- const res = await fetch(`${baseUrl2}/api/user/stats`, {
186
+ const res = await fetch(`${baseUrl2}/api/gateway/v1/balance`, {
187
187
  headers: { Authorization: `Bearer ${apiKey}` }
188
188
  });
189
189
  if (res.ok) {
190
190
  const d = await res.json();
191
191
  return {
192
- balance: d.balance ?? 75313,
192
+ balance: d.balance ?? 0,
193
193
  tier: d.tier || "DEVELOPER",
194
- accountId: d.accountId || "SA-8WwREVSJ"
194
+ accountId: d.accountId ? `SA-${d.accountId}` : "SA-\u2014"
195
195
  };
196
196
  }
197
197
  } catch {
198
198
  }
199
- return { balance: 75313, tier: "DEVELOPER", accountId: "SA-8WwREVSJ" };
199
+ return { balance: 0, tier: "DEVELOPER", accountId: "SA-\u2014" };
200
200
  }
201
201
  function getDisplayDir() {
202
202
  const cwd = process.cwd();
@@ -378,7 +378,7 @@ function enterWorkspace() {
378
378
  }
379
379
  }, 1e3);
380
380
  }
381
- async function runPromptStream(query) {
381
+ async function runPromptStream(query, isRetry = false) {
382
382
  isExecuting = true;
383
383
  process.stdout.write("\x1B[?25l");
384
384
  const pad = getCenterPad(72);
@@ -399,9 +399,31 @@ async function runPromptStream(query) {
399
399
  })
400
400
  });
401
401
  if (!res.ok) {
402
+ let detail = res.statusText || `HTTP ${res.status}`;
403
+ try {
404
+ const errBody = await res.json();
405
+ const msg = errBody?.error?.message || errBody?.error || errBody?.message;
406
+ if (msg) detail = typeof msg === "string" ? msg : JSON.stringify(msg);
407
+ } catch {
408
+ }
402
409
  console.log(pad + import_chalk.default.red(`
403
- Error: ${res.statusText}
410
+ Error (${res.status}): ${detail}
404
411
  `));
412
+ if (res.status === 401 && !isRetry) {
413
+ console.log(pad + import_chalk.default.yellow("API key tidak valid atau sudah di-revoke. Memulai ulang otorisasi...\n"));
414
+ try {
415
+ saveConfig({ apiKey: void 0 });
416
+ } catch {
417
+ }
418
+ cfg = getConfig();
419
+ const newKey = await handleAutoAuth(baseUrl);
420
+ if (newKey) {
421
+ cfg = getConfig();
422
+ userMeta = await fetchUserMeta(baseUrl, cfg.apiKey || "");
423
+ return runPromptStream(query, true);
424
+ }
425
+ console.log(pad + import_chalk.default.red("Otorisasi ulang dibatalkan.\n"));
426
+ }
405
427
  } else {
406
428
  const reader = res.body?.getReader();
407
429
  const decoder = new TextDecoder();
@@ -468,6 +490,13 @@ async function handleAutoAuth(baseUrl2) {
468
490
  async function startInteractiveSession() {
469
491
  cfg = getConfig();
470
492
  baseUrl = resolveBaseUrl();
493
+ const MODEL_MIGRATIONS = {
494
+ "anthropic/claude-3.7-sonnet": "anthropic/claude-sonnet-4.6"
495
+ };
496
+ if (cfg.defaultModel && MODEL_MIGRATIONS[cfg.defaultModel]) {
497
+ cfg.defaultModel = MODEL_MIGRATIONS[cfg.defaultModel];
498
+ saveConfig({ defaultModel: cfg.defaultModel });
499
+ }
471
500
  if (!cfg.apiKey) {
472
501
  const key = await handleAutoAuth(baseUrl);
473
502
  if (!key) {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "sarangai-cli",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "CLI resmi SarangAI — Gateway multi-model AI langsung dari terminal Anda",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "sarang": "dist/index.js",
8
- "sarangai": "dist/index.cjs"
8
+ "sarangai": "dist/index.js"
9
9
  },
10
10
  "files": [
11
11
  "dist"