kimiflare 0.13.3 → 0.13.5

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
@@ -87,8 +87,6 @@ async function* readSSE(stream, signal) {
87
87
  const reader = stream.getReader();
88
88
  const decoder = new TextDecoder("utf-8");
89
89
  let buffer = "";
90
- const onAbort = () => reader.cancel(new DOMException("aborted", "AbortError"));
91
- signal?.addEventListener("abort", onAbort, { once: true });
92
90
  try {
93
91
  while (true) {
94
92
  if (signal?.aborted) throw new DOMException("aborted", "AbortError");
@@ -108,7 +106,6 @@ async function* readSSE(stream, signal) {
108
106
  const tail = extractData(buffer.trim());
109
107
  if (tail !== null) yield tail;
110
108
  } finally {
111
- signal?.removeEventListener("abort", onAbort);
112
109
  reader.releaseLock();
113
110
  }
114
111
  }
@@ -3731,7 +3728,6 @@ function App({ initialCfg, initialUpdateResult }) {
3731
3728
  const executorRef = useRef3(new ToolExecutor(ALL_TOOLS));
3732
3729
  const activeAsstIdRef = useRef3(null);
3733
3730
  const activeControllerRef = useRef3(null);
3734
- const permResolveRef = useRef3(null);
3735
3731
  const sessionIdRef = useRef3(null);
3736
3732
  const modeRef = useRef3(mode);
3737
3733
  const effortRef = useRef3(effort);
@@ -3740,7 +3736,6 @@ function App({ initialCfg, initialUpdateResult }) {
3740
3736
  const updateCheckedRef = useRef3(false);
3741
3737
  const updateNudgedRef = useRef3(false);
3742
3738
  const compactSuggestedRef = useRef3(false);
3743
- const interruptRequestedRef = useRef3(false);
3744
3739
  useEffect4(() => {
3745
3740
  if (!cfg || updateCheckedRef.current) return;
3746
3741
  updateCheckedRef.current = true;
@@ -3874,15 +3869,8 @@ function App({ initialCfg, initialUpdateResult }) {
3874
3869
  }, [cfg]);
3875
3870
  useInput2((inputChar, key) => {
3876
3871
  if (key.ctrl && inputChar === "c") {
3877
- if (busy) {
3878
- if (interruptRequestedRef.current) {
3879
- process.exit(0);
3880
- }
3881
- interruptRequestedRef.current = true;
3882
- activeControllerRef.current?.abort();
3883
- permResolveRef.current?.("deny");
3884
- permResolveRef.current = null;
3885
- setPerm(null);
3872
+ if (busy && activeControllerRef.current) {
3873
+ activeControllerRef.current.abort();
3886
3874
  setQueue([]);
3887
3875
  setEvents((e) => [...e, { kind: "info", key: mkKey(), text: "(interrupted)" }]);
3888
3876
  } else {
@@ -3974,7 +3962,6 @@ function App({ initialCfg, initialUpdateResult }) {
3974
3962
  setBusy(false);
3975
3963
  setTurnStartedAt(null);
3976
3964
  activeControllerRef.current = null;
3977
- interruptRequestedRef.current = false;
3978
3965
  }
3979
3966
  }, [cfg, busy, saveSessionSafe]);
3980
3967
  const openResumePicker = useCallback(async () => {
@@ -4105,11 +4092,7 @@ function App({ initialCfg, initialUpdateResult }) {
4105
4092
  resolve2("deny");
4106
4093
  return;
4107
4094
  }
4108
- permResolveRef.current = resolve2;
4109
- setPerm({ tool: req.tool, args: req.args, resolve: (d) => {
4110
- permResolveRef.current = null;
4111
- resolve2(d);
4112
- } });
4095
+ setPerm({ tool: req.tool, args: req.args, resolve: resolve2 });
4113
4096
  })
4114
4097
  }
4115
4098
  });
@@ -4136,26 +4119,17 @@ function App({ initialCfg, initialUpdateResult }) {
4136
4119
  ]);
4137
4120
  }
4138
4121
  } catch (e) {
4139
- if (e.name === "AbortError") {
4140
- setEvents((es) => [...es, { kind: "info", key: mkKey(), text: "(interrupted)" }]);
4141
- setEvents(
4142
- (evts) => evts.map((e2) => e2.kind === "tool" && e2.status === "running" ? { ...e2, status: "error", result: "(interrupted)" } : e2)
4143
- );
4144
- } else {
4122
+ if (e.name !== "AbortError") {
4145
4123
  setEvents((es) => [
4146
4124
  ...es,
4147
4125
  { kind: "error", key: mkKey(), text: `init failed: ${e.message}` }
4148
4126
  ]);
4149
4127
  }
4150
4128
  } finally {
4151
- const asstId = activeAsstIdRef.current;
4152
- if (asstId !== null) updateAssistant(asstId, () => ({ streaming: false }));
4153
4129
  setBusy(false);
4154
4130
  setTurnStartedAt(null);
4155
4131
  activeAsstIdRef.current = null;
4156
4132
  activeControllerRef.current = null;
4157
- permResolveRef.current = null;
4158
- interruptRequestedRef.current = false;
4159
4133
  }
4160
4134
  }, [cfg, busy, updateAssistant, updateTool]);
4161
4135
  const handleResumePick = useCallback(
@@ -4567,11 +4541,7 @@ use: /thinking low | medium | high`
4567
4541
  resolve2("deny");
4568
4542
  return;
4569
4543
  }
4570
- permResolveRef.current = resolve2;
4571
- setPerm({ tool: req.tool, args: req.args, resolve: (d) => {
4572
- permResolveRef.current = null;
4573
- resolve2(d);
4574
- } });
4544
+ setPerm({ tool: req.tool, args: req.args, resolve: resolve2 });
4575
4545
  })
4576
4546
  }
4577
4547
  });
@@ -4585,10 +4555,7 @@ use: /thinking low | medium | high`
4585
4555
  void saveSessionSafe();
4586
4556
  } catch (e) {
4587
4557
  if (e.name === "AbortError") {
4588
- setEvents((es) => [...es, { kind: "info", key: mkKey(), text: "(interrupted)" }]);
4589
- setEvents(
4590
- (evts) => evts.map((e2) => e2.kind === "tool" && e2.status === "running" ? { ...e2, status: "error", result: "(interrupted)" } : e2)
4591
- );
4558
+ setEvents((es) => [...es, { kind: "info", key: mkKey(), text: "(aborted)" }]);
4592
4559
  } else {
4593
4560
  const isInvalidJson400 = e instanceof KimiApiError && e.httpStatus === 400 && e.message.includes("invalid escaped character");
4594
4561
  if (isInvalidJson400) {
@@ -4609,25 +4576,14 @@ use: /thinking low | medium | high`
4609
4576
  }
4610
4577
  }
4611
4578
  } finally {
4612
- const asstId = activeAsstIdRef.current;
4613
- if (asstId !== null) updateAssistant(asstId, () => ({ streaming: false }));
4614
4579
  setBusy(false);
4615
4580
  setTurnStartedAt(null);
4616
4581
  activeAsstIdRef.current = null;
4617
4582
  activeControllerRef.current = null;
4618
- permResolveRef.current = null;
4619
- interruptRequestedRef.current = false;
4620
4583
  }
4621
4584
  },
4622
4585
  [cfg, handleSlash, updateAssistant, updateTool, saveSessionSafe]
4623
4586
  );
4624
- useEffect4(() => {
4625
- const onSigint = () => exit();
4626
- process.on("SIGINT", onSigint);
4627
- return () => {
4628
- process.off("SIGINT", onSigint);
4629
- };
4630
- }, [exit]);
4631
4587
  useEffect4(() => {
4632
4588
  if (!busy && queue.length > 0) {
4633
4589
  const next = queue[0];
@@ -4902,10 +4858,7 @@ async function runPrintMode(opts2) {
4902
4858
  { role: "user", content: opts2.prompt }
4903
4859
  ];
4904
4860
  const controller = new AbortController();
4905
- process.once("SIGINT", () => {
4906
- controller.abort();
4907
- setTimeout(() => process.exit(1), 500);
4908
- });
4861
+ process.on("SIGINT", () => controller.abort());
4909
4862
  let printedReasoningHeader = false;
4910
4863
  let printedAnswerHeader = false;
4911
4864
  await runAgentTurn({