kimiflare 0.9.0 → 0.9.1

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
@@ -1474,10 +1474,11 @@ var init_tool_view = __esm({
1474
1474
  });
1475
1475
 
1476
1476
  // src/ui/markdown.tsx
1477
+ import { useMemo } from "react";
1477
1478
  import { Box as Box3, Text as Text3 } from "ink";
1478
1479
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1479
1480
  function MD({ text, theme }) {
1480
- const blocks = parseBlocks(text);
1481
+ const blocks = useMemo(() => parseBlocks(text), [text]);
1481
1482
  return /* @__PURE__ */ jsx3(Box3, { flexDirection: "column", children: blocks.map((b, i) => /* @__PURE__ */ jsx3(Block, { block: b, theme }, i)) });
1482
1483
  }
1483
1484
  function parseBlocks(src) {
@@ -1633,19 +1634,10 @@ var init_markdown = __esm({
1633
1634
  });
1634
1635
 
1635
1636
  // src/ui/chat.tsx
1637
+ import React2 from "react";
1636
1638
  import { Box as Box4, Text as Text4 } from "ink";
1637
1639
  import Spinner2 from "ink-spinner";
1638
1640
  import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1639
- function ChatView({ events, showReasoning, theme, verbose }) {
1640
- return /* @__PURE__ */ jsx4(Box4, { flexDirection: "column", children: events.map((e, i) => {
1641
- const prev = events[i - 1];
1642
- const showSeparator = e.kind === "user" && prev && (prev.kind === "assistant" || prev.kind === "tool");
1643
- return /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", children: [
1644
- showSeparator && /* @__PURE__ */ jsx4(Box4, { marginY: 1, children: /* @__PURE__ */ jsx4(Text4, { color: theme.info.color, dimColor: theme.info.dim, children: "\u2500".repeat(40) }) }),
1645
- /* @__PURE__ */ jsx4(EventView, { evt: e, showReasoning, theme, verbose })
1646
- ] }, e.key);
1647
- }) });
1648
- }
1649
1641
  function EventView({
1650
1642
  evt,
1651
1643
  showReasoning,
@@ -1686,11 +1678,22 @@ function EventView({
1686
1678
  evt.text
1687
1679
  ] });
1688
1680
  }
1681
+ var ChatView;
1689
1682
  var init_chat = __esm({
1690
1683
  "src/ui/chat.tsx"() {
1691
1684
  "use strict";
1692
1685
  init_tool_view();
1693
1686
  init_markdown();
1687
+ ChatView = React2.memo(function ChatView2({ events, showReasoning, theme, verbose }) {
1688
+ return /* @__PURE__ */ jsx4(Box4, { flexDirection: "column", children: events.map((e, i) => {
1689
+ const prev = events[i - 1];
1690
+ const showSeparator = e.kind === "user" && prev && (prev.kind === "assistant" || prev.kind === "tool");
1691
+ return /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", children: [
1692
+ showSeparator && /* @__PURE__ */ jsx4(Box4, { marginY: 1, children: /* @__PURE__ */ jsx4(Text4, { color: theme.info.color, dimColor: theme.info.dim, children: "\u2500".repeat(40) }) }),
1693
+ /* @__PURE__ */ jsx4(EventView, { evt: e, showReasoning, theme, verbose })
1694
+ ] }, e.key);
1695
+ }) });
1696
+ });
1694
1697
  }
1695
1698
  });
1696
1699
 
@@ -1943,19 +1946,25 @@ var init_theme_picker = __esm({
1943
1946
  });
1944
1947
 
1945
1948
  // src/ui/task-list.tsx
1946
- import { useEffect as useEffect2, useState as useState3 } from "react";
1949
+ import { useEffect as useEffect2, useRef, useState as useState3 } from "react";
1947
1950
  import { Box as Box9, Text as Text9 } from "ink";
1948
1951
  import Spinner4 from "ink-spinner";
1949
1952
  import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
1950
1953
  function TaskList({ tasks, theme, startedAt, tokensDelta }) {
1951
1954
  const [now, setNow] = useState3(Date.now());
1955
+ const tasksRef = useRef(tasks);
1956
+ tasksRef.current = tasks;
1952
1957
  useEffect2(() => {
1953
1958
  if (startedAt === null) return;
1954
- const allDone2 = tasks.length > 0 && tasks.every((t) => t.status === "completed");
1955
- if (allDone2) return;
1956
- const id = setInterval(() => setNow(Date.now()), 1e3);
1959
+ const id = setInterval(() => {
1960
+ setNow(Date.now());
1961
+ const current = tasksRef.current;
1962
+ if (current.length > 0 && current.every((t) => t.status === "completed")) {
1963
+ clearInterval(id);
1964
+ }
1965
+ }, 1e3);
1957
1966
  return () => clearInterval(id);
1958
- }, [startedAt, tasks]);
1967
+ }, [startedAt]);
1959
1968
  if (tasks.length === 0) return null;
1960
1969
  const active = tasks.find((t) => t.status === "in_progress");
1961
1970
  const done = tasks.filter((t) => t.status === "completed").length;
@@ -2547,7 +2556,7 @@ var init_source = __esm({
2547
2556
  });
2548
2557
 
2549
2558
  // src/ui/text-input.tsx
2550
- import { useState as useState4, useEffect as useEffect3, useRef } from "react";
2559
+ import { useState as useState4, useEffect as useEffect3, useRef as useRef2 } from "react";
2551
2560
  import { Text as Text10, useInput } from "ink";
2552
2561
  import { jsx as jsx10 } from "react/jsx-runtime";
2553
2562
  function shouldTreatAsPaste(input) {
@@ -2583,7 +2592,7 @@ function CustomTextInput({
2583
2592
  enablePaste = false
2584
2593
  }) {
2585
2594
  const [cursorOffset, setCursorOffset] = useState4(value.length);
2586
- const pastesRef = useRef(/* @__PURE__ */ new Map());
2595
+ const pastesRef = useRef2(/* @__PURE__ */ new Map());
2587
2596
  useEffect3(() => {
2588
2597
  if (!focus) return;
2589
2598
  setCursorOffset((prev) => prev > value.length ? value.length : prev);
@@ -3269,16 +3278,29 @@ var app_exports = {};
3269
3278
  __export(app_exports, {
3270
3279
  renderApp: () => renderApp
3271
3280
  });
3272
- import { useState as useState6, useRef as useRef2, useEffect as useEffect4, useCallback } from "react";
3281
+ import { useState as useState6, useRef as useRef3, useEffect as useEffect4, useCallback } from "react";
3273
3282
  import { Box as Box12, Text as Text13, useApp, useInput as useInput2, render } from "ink";
3274
3283
  import { existsSync } from "fs";
3275
3284
  import { join as join5 } from "path";
3276
3285
  import { unlink } from "fs/promises";
3277
3286
  import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
3287
+ function capEvents(prev) {
3288
+ if (prev.length <= MAX_EVENTS) return prev;
3289
+ return prev.slice(prev.length - MAX_EVENTS);
3290
+ }
3278
3291
  function App({ initialCfg, initialUpdateResult }) {
3279
3292
  const { exit } = useApp();
3280
3293
  const [cfg, setCfg] = useState6(initialCfg);
3281
- const [events, setEvents] = useState6([]);
3294
+ const [events, setRawEvents] = useState6([]);
3295
+ const setEvents = useCallback(
3296
+ (updater) => {
3297
+ setRawEvents((prev) => {
3298
+ const next = typeof updater === "function" ? updater(prev) : updater;
3299
+ return capEvents(next);
3300
+ });
3301
+ },
3302
+ []
3303
+ );
3282
3304
  const [input, setInput] = useState6("");
3283
3305
  const [busy, setBusy] = useState6(false);
3284
3306
  const [usage, setUsage] = useState6(null);
@@ -3303,7 +3325,7 @@ function App({ initialCfg, initialUpdateResult }) {
3303
3325
  const [verbose, setVerbose] = useState6(false);
3304
3326
  const [hasUpdate, setHasUpdate] = useState6(initialUpdateResult?.hasUpdate ?? false);
3305
3327
  const [latestVersion, setLatestVersion] = useState6(initialUpdateResult?.latestVersion ?? null);
3306
- const messagesRef = useRef2([
3328
+ const messagesRef = useRef3([
3307
3329
  {
3308
3330
  role: "system",
3309
3331
  content: buildSystemPrompt({
@@ -3314,17 +3336,17 @@ function App({ initialCfg, initialUpdateResult }) {
3314
3336
  })
3315
3337
  }
3316
3338
  ]);
3317
- const executorRef = useRef2(new ToolExecutor(ALL_TOOLS));
3318
- const activeAsstIdRef = useRef2(null);
3319
- const activeControllerRef = useRef2(null);
3320
- const sessionIdRef = useRef2(null);
3321
- const modeRef = useRef2(mode);
3322
- const effortRef = useRef2(effort);
3323
- const tasksRef = useRef2([]);
3324
- const usageRef = useRef2(null);
3325
- const updateCheckedRef = useRef2(false);
3326
- const updateNudgedRef = useRef2(false);
3327
- const compactSuggestedRef = useRef2(false);
3339
+ const executorRef = useRef3(new ToolExecutor(ALL_TOOLS));
3340
+ const activeAsstIdRef = useRef3(null);
3341
+ const activeControllerRef = useRef3(null);
3342
+ const sessionIdRef = useRef3(null);
3343
+ const modeRef = useRef3(mode);
3344
+ const effortRef = useRef3(effort);
3345
+ const tasksRef = useRef3([]);
3346
+ const usageRef = useRef3(null);
3347
+ const updateCheckedRef = useRef3(false);
3348
+ const updateNudgedRef = useRef3(false);
3349
+ const compactSuggestedRef = useRef3(false);
3328
3350
  useEffect4(() => {
3329
3351
  if (!cfg || updateCheckedRef.current) return;
3330
3352
  updateCheckedRef.current = true;
@@ -4242,7 +4264,7 @@ async function renderApp(cfg, updateResult) {
4242
4264
  const instance = render(/* @__PURE__ */ jsx13(App, { initialCfg: cfg, initialUpdateResult: updateResult }));
4243
4265
  await instance.waitUntilExit();
4244
4266
  }
4245
- var CONTEXT_LIMIT, AUTO_COMPACT_SUGGEST_PCT, nextAssistantId, nextKey, mkKey, EFFORT_DESCRIPTIONS;
4267
+ var CONTEXT_LIMIT, AUTO_COMPACT_SUGGEST_PCT, MAX_EVENTS, nextAssistantId, nextKey, mkKey, EFFORT_DESCRIPTIONS;
4246
4268
  var init_app = __esm({
4247
4269
  "src/app.tsx"() {
4248
4270
  "use strict";
@@ -4267,6 +4289,7 @@ var init_app = __esm({
4267
4289
  init_sessions();
4268
4290
  CONTEXT_LIMIT = 262e3;
4269
4291
  AUTO_COMPACT_SUGGEST_PCT = 0.8;
4292
+ MAX_EVENTS = 500;
4270
4293
  nextAssistantId = 1;
4271
4294
  nextKey = 1;
4272
4295
  mkKey = () => `evt_${nextKey++}`;