kimiflare 0.93.1 → 0.94.0

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 CHANGED
@@ -28883,7 +28883,7 @@ function dispatchSlashCommand(ctx, cmd) {
28883
28883
  if (!handler) return false;
28884
28884
  return handler(ctx, rest, arg);
28885
28885
  }
28886
- var handleExit, handleClear, handleFresh, handleReasoning, handleCost, handleShell, handleModel, handleGateway, handleMode, handleMultiAgent, handleTheme, handleUi, handlePlan, handleAuto, handleEdit, handleSkills, handleMemory, handleResume, handleCheckpoint, handleCompact, handleInit, handleUpdate, handleMcp, handleLsp, handleHooks, handleHello, handleInbox, handleReport, handleLogout, handleUpgrade, handleCommand, handleRemote, handleHelp, handleChangelogImage, handlers;
28886
+ var handleExit, handleClear, handleFresh, handleReasoning, handleCost, handleShell, handleModel, handleGateway, handleMode, handleMultiAgent, handleTheme, handleUi, handlePlan, handleAuto, handleEdit, handleSkills, handleMemory, handleResume, handleCheckpoint, handleCompact, handleInit, handleUpdate, handleMcp, handleLsp, handleHooks, handleHello, handleInbox, handleReport, handleLogout, handleUpgrade, handleTopup, handleManage, handleCommand, handleRemote, handleHelp, handleChangelogImage, handlers;
28887
28887
  var init_slash_commands = __esm({
28888
28888
  "src/ui/slash-commands.ts"() {
28889
28889
  "use strict";
@@ -30066,6 +30066,14 @@ project: ${projectSettingsPath(cwd)}`
30066
30066
  void ctx.upgrade();
30067
30067
  return true;
30068
30068
  };
30069
+ handleTopup = (ctx) => {
30070
+ void ctx.topup();
30071
+ return true;
30072
+ };
30073
+ handleManage = (ctx) => {
30074
+ void ctx.manageMembership();
30075
+ return true;
30076
+ };
30069
30077
  handleCommand = (ctx, rest) => {
30070
30078
  const { setEvents, mkKey: mkKey2 } = ctx;
30071
30079
  const sub = rest[0]?.toLowerCase() ?? "";
@@ -30389,6 +30397,8 @@ project: ${projectSettingsPath(cwd)}`
30389
30397
  "/report": handleReport,
30390
30398
  "/logout": handleLogout,
30391
30399
  "/upgrade": handleUpgrade,
30400
+ "/topup": handleTopup,
30401
+ "/manage": handleManage,
30392
30402
  "/command": handleCommand,
30393
30403
  "/remote": handleRemote,
30394
30404
  "/changelog-image": handleChangelogImage,
@@ -32005,6 +32015,7 @@ var billing_exports = {};
32005
32015
  __export(billing_exports, {
32006
32016
  createCheckoutSession: () => createCheckoutSession,
32007
32017
  createCustomerPortalSession: () => createCustomerPortalSession,
32018
+ createTopupSession: () => createTopupSession,
32008
32019
  fetchBillingStatus: () => fetchBillingStatus
32009
32020
  });
32010
32021
  function authHeaders2(token, deviceId) {
@@ -32044,6 +32055,21 @@ async function createCheckoutSession(token, deviceId, priceId) {
32044
32055
  if (typeof data.url !== "string") return null;
32045
32056
  return { url: data.url };
32046
32057
  }
32058
+ async function createTopupSession(token, deviceId) {
32059
+ const res = await fetch(`${CLOUD_API_URL}/v1/billing/topup`, {
32060
+ method: "POST",
32061
+ headers: authHeaders2(token, deviceId),
32062
+ body: JSON.stringify({})
32063
+ });
32064
+ await detectKillSwitch(res);
32065
+ if (!res.ok) {
32066
+ const err = await res.json().catch(() => ({}));
32067
+ throw new Error(err.error || `Top-up failed: ${res.statusText}`);
32068
+ }
32069
+ const data = await res.json();
32070
+ if (typeof data.url !== "string") return null;
32071
+ return { url: data.url };
32072
+ }
32047
32073
  async function createCustomerPortalSession(token, deviceId) {
32048
32074
  const res = await fetch(`${CLOUD_API_URL}/v1/billing/portal`, {
32049
32075
  method: "POST",
@@ -32424,7 +32450,11 @@ ${wcagWarnings.join("\n")}` }
32424
32450
  description: c.description ?? "",
32425
32451
  source: c.source
32426
32452
  }));
32427
- const cloudCommands = cfg?.cloudMode ? [{ name: "upgrade", description: "Upgrade to KimiFlare Pro", source: "builtin" }] : [];
32453
+ const cloudCommands = cfg?.cloudMode ? [
32454
+ { name: "upgrade", description: "Upgrade to KimiFlare Pro", source: "builtin" },
32455
+ { name: "topup", description: "Buy a one-time token top-up (+50M)", source: "builtin" },
32456
+ { name: "manage", description: "Manage membership, billing & invoices", source: "builtin" }
32457
+ ] : [];
32428
32458
  return [...BUILTIN_COMMANDS, ...cloudCommands, ...customs];
32429
32459
  }, [customCommandsVersion, cfg?.cloudMode]);
32430
32460
  const modalActive = commandWizard !== null || commandPicker !== null || commandToDelete !== null || showCommandList || showLspWizard || resumeSessions !== null || checkpointSession !== null || resuming || perm !== null || limitModal !== null || loopModal !== null || showInboxModal || showHelpMenu || showModePicker || showMemoryPicker || showGatewayPicker || showSkillsPicker || showShellPicker;
@@ -33165,6 +33195,98 @@ ${wcagWarnings.join("\n")}` }
33165
33195
  ]);
33166
33196
  }
33167
33197
  }, [cloudToken, cloudDeviceId, initialCloudToken, initialCloudDeviceId, mkKey, setEvents, setCloudBudget]);
33198
+ const handleTopup2 = useCallback10(async () => {
33199
+ const token = cloudToken ?? initialCloudToken;
33200
+ const did = cloudDeviceId ?? initialCloudDeviceId;
33201
+ if (!token) {
33202
+ setEvents((e) => [
33203
+ ...e,
33204
+ { kind: "error", key: mkKey(), text: "Cloud authentication required to buy a top-up." }
33205
+ ]);
33206
+ return;
33207
+ }
33208
+ setEvents((e) => [...e, { kind: "info", key: mkKey(), text: "Opening top-up checkout\u2026" }]);
33209
+ try {
33210
+ const { createTopupSession: createTopupSession2 } = await Promise.resolve().then(() => (init_billing(), billing_exports));
33211
+ const session = await createTopupSession2(token, did);
33212
+ if (session?.url) {
33213
+ const { openBrowser: openBrowser2 } = await Promise.resolve().then(() => (init_app_helpers(), app_helpers_exports));
33214
+ openBrowser2(session.url);
33215
+ setEvents((e) => [
33216
+ ...e,
33217
+ { kind: "info", key: mkKey(), text: "Complete the one-time payment in your browser \u2014 your tokens are added automatically." }
33218
+ ]);
33219
+ const { fetchCloudUsage: fetchCloudUsage2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
33220
+ const baseline = cloudBudget?.limit ?? 0;
33221
+ for (let i = 0; i < 40; i++) {
33222
+ await new Promise((r) => setTimeout(r, 5e3));
33223
+ let usage2;
33224
+ try {
33225
+ usage2 = await fetchCloudUsage2(token, did);
33226
+ } catch {
33227
+ continue;
33228
+ }
33229
+ if (usage2 && usage2.input_token_limit > baseline) {
33230
+ setCloudBudget({ remaining: usage2.remaining, limit: usage2.input_token_limit });
33231
+ setEvents((e) => [
33232
+ ...e,
33233
+ { kind: "info", key: mkKey(), text: "\u2713 Top-up applied \u2014 your token balance has been increased. Thank you!" }
33234
+ ]);
33235
+ return;
33236
+ }
33237
+ }
33238
+ } else {
33239
+ setEvents((e) => [...e, { kind: "error", key: mkKey(), text: "Top-up unavailable. Please try again later." }]);
33240
+ }
33241
+ } catch (err) {
33242
+ setEvents((e) => [
33243
+ ...e,
33244
+ { kind: "error", key: mkKey(), text: `Top-up failed: ${err instanceof Error ? err.message : String(err)}` }
33245
+ ]);
33246
+ }
33247
+ }, [cloudToken, cloudDeviceId, initialCloudToken, initialCloudDeviceId, cloudBudget, mkKey, setEvents, setCloudBudget]);
33248
+ const handleManageMembership = useCallback10(async () => {
33249
+ const token = cloudToken ?? initialCloudToken;
33250
+ const did = cloudDeviceId ?? initialCloudDeviceId;
33251
+ if (!token) {
33252
+ setEvents((e) => [
33253
+ ...e,
33254
+ { kind: "error", key: mkKey(), text: "Cloud authentication required to manage your membership." }
33255
+ ]);
33256
+ return;
33257
+ }
33258
+ if (cloudBudget) {
33259
+ const used = cloudBudget.limit - cloudBudget.remaining;
33260
+ const fmt = (n) => `${(n / 1e6).toFixed(1)}M`;
33261
+ setEvents((e) => [
33262
+ ...e,
33263
+ { kind: "info", key: mkKey(), text: `Tokens this period: ${fmt(used)} used \xB7 ${fmt(cloudBudget.remaining)} left of ${fmt(cloudBudget.limit)}.` }
33264
+ ]);
33265
+ }
33266
+ setEvents((e) => [...e, { kind: "info", key: mkKey(), text: "Opening your billing portal\u2026" }]);
33267
+ try {
33268
+ const { createCustomerPortalSession: createCustomerPortalSession2 } = await Promise.resolve().then(() => (init_billing(), billing_exports));
33269
+ const session = await createCustomerPortalSession2(token, did);
33270
+ if (session?.url) {
33271
+ const { openBrowser: openBrowser2 } = await Promise.resolve().then(() => (init_app_helpers(), app_helpers_exports));
33272
+ openBrowser2(session.url);
33273
+ setEvents((e) => [
33274
+ ...e,
33275
+ { kind: "info", key: mkKey(), text: "Manage your card, invoices, or cancel anytime in the browser tab that just opened." }
33276
+ ]);
33277
+ } else {
33278
+ setEvents((e) => [
33279
+ ...e,
33280
+ { kind: "error", key: mkKey(), text: "Billing portal unavailable. You may not have an active subscription \u2014 run /upgrade to start one." }
33281
+ ]);
33282
+ }
33283
+ } catch (err) {
33284
+ setEvents((e) => [
33285
+ ...e,
33286
+ { kind: "error", key: mkKey(), text: `Couldn't open billing portal: ${err instanceof Error ? err.message : String(err)}` }
33287
+ ]);
33288
+ }
33289
+ }, [cloudToken, cloudDeviceId, initialCloudToken, initialCloudDeviceId, cloudBudget, mkKey, setEvents]);
33168
33290
  const handleSaveProviderKey = useCallback10(
33169
33291
  (model, result) => {
33170
33292
  setKeyEntryFor(null);
@@ -33263,6 +33385,8 @@ ${wcagWarnings.join("\n")}` }
33263
33385
  initLsp: initLsp2,
33264
33386
  ensureSessionId,
33265
33387
  upgrade: handleUpgrade2,
33388
+ topup: handleTopup2,
33389
+ manageMembership: handleManageMembership,
33266
33390
  lspManagerRef,
33267
33391
  mcpManagerRef,
33268
33392
  hooksManagerRef,