clixad 0.0.1-beta.33 → 0.0.1-beta.34

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/clixad.mjs +33 -1
  2. package/package.json +1 -1
package/dist/clixad.mjs CHANGED
@@ -488,6 +488,16 @@ function asSignupClosed(status, data) {
488
488
  const d = data;
489
489
  return d && d.error === "signup_closed" && typeof d.message === "string" ? { error: d.error, message: d.message, waitlist_url: d.waitlist_url ?? "https://clixad.io" } : void 0;
490
490
  }
491
+ async function refusal503(res, what) {
492
+ const text = await res.text().catch(() => "");
493
+ try {
494
+ const body = JSON.parse(text);
495
+ if (body.error === MAINTENANCE && typeof body.message === "string") return new MaintenanceError(body.message);
496
+ } catch {
497
+ }
498
+ const detail = safeDetail(text);
499
+ return new Error(detail ? `${what} failed: 503 \u2014 ${detail}` : `${what} failed: 503`);
500
+ }
491
501
  function spendableAt(raw, balance) {
492
502
  const figures = parseSpendable(raw);
493
503
  return figures && typeof balance === "number" && Number.isFinite(balance) ? { figures, balance } : void 0;
@@ -669,7 +679,7 @@ async function* parseSSE(body) {
669
679
  }
670
680
  }
671
681
  }
672
- var CHAT_ENCODED_CONTENT_TYPE, LEDGER_REASONS, SignupClosedError, PaywallError, PremiumLockedError, LimitRefusalError, LIMIT_REFUSALS, GatewayUnreachableError, NEVER_CONNECTED, AuthError, GatewayClient;
682
+ var CHAT_ENCODED_CONTENT_TYPE, LEDGER_REASONS, SignupClosedError, PaywallError, PremiumLockedError, LimitRefusalError, MaintenanceError, MAINTENANCE, LIMIT_REFUSALS, GatewayUnreachableError, NEVER_CONNECTED, AuthError, GatewayClient;
673
683
  var init_client = __esm({
674
684
  "src/client.ts"() {
675
685
  "use strict";
@@ -753,6 +763,13 @@ var init_client = __esm({
753
763
  type;
754
764
  spendable;
755
765
  };
766
+ MaintenanceError = class extends Error {
767
+ constructor(message) {
768
+ super(message);
769
+ this.name = "MaintenanceError";
770
+ }
771
+ };
772
+ MAINTENANCE = "maintenance";
756
773
  LIMIT_REFUSALS = /* @__PURE__ */ new Set(["paid_user_limit_reached", "paid_budget_spent", "paid_budget_unavailable"]);
757
774
  GatewayUnreachableError = class extends Error {
758
775
  constructor(host, code) {
@@ -1312,6 +1329,8 @@ var init_client = __esm({
1312
1329
  });
1313
1330
  if (res.status === 401) throw await authFailure(res, "web search");
1314
1331
  if (res.status === 503) {
1332
+ const body = await res.json().catch(() => ({}));
1333
+ if (body.error === MAINTENANCE && typeof body.message === "string") throw new MaintenanceError(body.message);
1315
1334
  throw new Error(
1316
1335
  "Web search isn't enabled on this gateway (no search key configured). Use web_fetch on a URL you know."
1317
1336
  );
@@ -1453,6 +1472,7 @@ var init_client = __esm({
1453
1472
  if (res.status === 401) throw await authFailure(res, "chat");
1454
1473
  if (res.status === 402) throw await refusal402(res, model);
1455
1474
  if (res.status === 429) throw await refusal429(res);
1475
+ if (res.status === 503) throw await refusal503(res, "chat");
1456
1476
  if (!res.ok) throw new Error(await httpFailure(res, "chat"));
1457
1477
  const data = await res.json();
1458
1478
  const choice = data.choices[0];
@@ -1486,6 +1506,7 @@ var init_client = __esm({
1486
1506
  );
1487
1507
  if (res.status === 401) throw await authFailure(res, "chat");
1488
1508
  if (res.status === 402) throw await refusal402(res, model);
1509
+ if (res.status === 503) throw await refusal503(res, "chat");
1489
1510
  if (!res.ok || !res.body) throw new Error(await httpFailure(res, "chat"));
1490
1511
  let content = "";
1491
1512
  let finishReason = "stop";
@@ -1537,6 +1558,7 @@ var init_client = __esm({
1537
1558
  }
1538
1559
  }
1539
1560
  if (premiumRefusal) throw premiumRefusal;
1561
+ if (streamError && streamErrorType === MAINTENANCE) throw new MaintenanceError(streamError);
1540
1562
  if (streamError && streamErrorType && LIMIT_REFUSALS.has(streamErrorType)) {
1541
1563
  throw new LimitRefusalError(streamError, streamErrorType, spendable ? { figures: spendable, balance } : void 0);
1542
1564
  }
@@ -5103,6 +5125,7 @@ function parseReview(text) {
5103
5125
  function reviewFailure(err) {
5104
5126
  if (err instanceof PaywallError) return "there are no credits left for the check";
5105
5127
  if (err instanceof LimitRefusalError) return "a daily limit stopped the check";
5128
+ if (err instanceof MaintenanceError) return "Clixad is down for the moment";
5106
5129
  if (err instanceof PremiumLockedError) return "the model it runs on is locked";
5107
5130
  if (err instanceof GatewayUnreachableError) return "the gateway could not be reached";
5108
5131
  if (err instanceof AuthError) return "this session is not signed in";
@@ -8174,6 +8197,8 @@ ${preferencesText}` : ""),
8174
8197
  });
8175
8198
  } else if (err instanceof AuthError) {
8176
8199
  push({ kind: "notice", tone: "error", text: NOT_SIGNED_IN });
8200
+ } else if (err instanceof MaintenanceError) {
8201
+ push({ kind: "notice", tone: "warn", text: ` ${errorNotice(err.message, void 0, " ")}` });
8177
8202
  } else {
8178
8203
  push({ kind: "notice", tone: "error", text: ` error: ${errorNotice(err.message, void 0, " ")}` });
8179
8204
  }
@@ -8220,6 +8245,8 @@ ${preferencesText}` : ""),
8220
8245
  } catch (err) {
8221
8246
  if (ac.signal.aborted) push({ kind: "notice", tone: "warn", text: " (stopped)" });
8222
8247
  else if (err instanceof AuthError) push({ kind: "notice", tone: "error", text: NOT_SIGNED_IN });
8248
+ else if (err instanceof MaintenanceError)
8249
+ push({ kind: "notice", tone: "warn", text: ` ${errorNotice(err.message, void 0, " ")}` });
8223
8250
  else push({ kind: "notice", tone: "error", text: ` ${errorNotice(err.message, void 0, " ")}` });
8224
8251
  } finally {
8225
8252
  busyAbortRef.current = null;
@@ -10272,6 +10299,9 @@ ${shortfallHeadline(err, config.model)}`));
10272
10299
  console.log(c.dim(" Offers you are screened out of pay nothing \u2014 that is normal, just start another."));
10273
10300
  } else if (err instanceof AuthError) {
10274
10301
  console.log(c.red(err.message));
10302
+ } else if (err instanceof MaintenanceError) {
10303
+ console.log(c.yellow(`
10304
+ ${err.message}`));
10275
10305
  } else {
10276
10306
  console.log(c.red(`
10277
10307
  agent error: ${err.message}`));
@@ -10410,6 +10440,8 @@ async function runTurn(client, config, messages) {
10410
10440
  console.log(c.dim(" Offers you are screened out of pay nothing \u2014 that is normal, just start another."));
10411
10441
  } else if (err instanceof AuthError) {
10412
10442
  console.log(c.red(err.message));
10443
+ } else if (err instanceof MaintenanceError) {
10444
+ console.log(c.yellow(err.message));
10413
10445
  } else {
10414
10446
  console.log(c.red(`error: ${err.message}`));
10415
10447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clixad",
3
- "version": "0.0.1-beta.33",
3
+ "version": "0.0.1-beta.34",
4
4
  "description": "Free AI coding agent in your terminal, funded by rewarded ads.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",