kimiflare 0.48.3 → 0.48.4

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
@@ -357,7 +357,7 @@ function log(level, event, data) {
357
357
  };
358
358
  console.error(JSON.stringify(entry));
359
359
  }
360
- var globalMinLevel, LEVEL_ORDER, logger2;
360
+ var globalMinLevel, LEVEL_ORDER, logger;
361
361
  var init_logger = __esm({
362
362
  "src/util/logger.ts"() {
363
363
  "use strict";
@@ -369,7 +369,7 @@ var init_logger = __esm({
369
369
  error: 3,
370
370
  off: 4
371
371
  };
372
- logger2 = {
372
+ logger = {
373
373
  debug: (event, data) => log("debug", event, data),
374
374
  info: (event, data) => log("info", event, data),
375
375
  warn: (event, data) => log("warn", event, data),
@@ -406,7 +406,7 @@ async function* readSSE(stream, signal, idleTimeoutMs) {
406
406
  while (true) {
407
407
  if (signal?.aborted) throw new DOMException("aborted", "AbortError");
408
408
  if (idleTimeoutMs !== void 0 && Date.now() - lastDataAt > idleTimeoutMs) {
409
- logger2.warn("sse:idle_timeout", { idleTimeoutMs });
409
+ logger.warn("sse:idle_timeout", { idleTimeoutMs });
410
410
  throw new DOMException(
411
411
  `kimiflare: stream idle for ${idleTimeoutMs}ms \u2014 no data received from API`,
412
412
  "TimeoutError"
@@ -581,7 +581,7 @@ async function* runKimi(opts2) {
581
581
  if (opts2.reasoningEffort) {
582
582
  body.reasoning_effort = opts2.reasoningEffort;
583
583
  }
584
- logger2.debug("runKimi:request", { requestId, attempt: 0, model: opts2.model });
584
+ logger.debug("runKimi:request", { requestId, attempt: 0, model: opts2.model });
585
585
  for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
586
586
  let res;
587
587
  try {
@@ -604,7 +604,7 @@ async function* runKimi(opts2) {
604
604
  });
605
605
  } catch (fetchErr) {
606
606
  const msg = fetchErr instanceof Error ? fetchErr.message : String(fetchErr);
607
- logger2.warn("runKimi:fetch_error", { requestId, attempt, error: msg });
607
+ logger.warn("runKimi:fetch_error", { requestId, attempt, error: msg });
608
608
  if (attempt < MAX_ATTEMPTS - 1) {
609
609
  const delay = 500 * 2 ** attempt + Math.random() * 250;
610
610
  await sleep(delay, opts2.signal);
@@ -635,12 +635,12 @@ async function* runKimi(opts2) {
635
635
  const meta = readGatewayMeta(res.headers);
636
636
  if (meta) yield { type: "gateway_meta", meta };
637
637
  let lastUsage = null;
638
- logger2.debug("runKimi:stream_start", { requestId });
638
+ logger.debug("runKimi:stream_start", { requestId });
639
639
  for await (const ev of parseStream(res.body, opts2.signal, opts2.idleTimeoutMs)) {
640
640
  if (ev.type === "usage") lastUsage = ev.usage;
641
641
  yield ev;
642
642
  }
643
- logger2.debug("runKimi:stream_end", { requestId });
643
+ logger.debug("runKimi:stream_end", { requestId });
644
644
  if (opts2.cloudMode && lastUsage && opts2.cloudToken) {
645
645
  const reportUrl = "https://api.kimiflare.com/v1/usage/report";
646
646
  const reportHeaders = {
@@ -2375,7 +2375,7 @@ function isHighSignalMemory(memory) {
2375
2375
  }
2376
2376
  async function runAgentTurn(opts2) {
2377
2377
  const turnStart = performance.now();
2378
- logger2.info("turn:start", { sessionId: opts2.sessionId, codeMode: opts2.codeMode ?? false });
2378
+ logger.info("turn:start", { sessionId: opts2.sessionId, codeMode: opts2.codeMode ?? false });
2379
2379
  const max = opts2.maxToolIterations ?? 50;
2380
2380
  const codeMode = opts2.codeMode ?? false;
2381
2381
  let toolDefs;
@@ -2512,7 +2512,7 @@ Use console.log() to return results. Only console.log output will be sent back t
2512
2512
  `kimiflare: context window exceeded (~${promptTokens.toLocaleString()} tokens). Run /compact to summarize older turns, or /clear to start fresh.`
2513
2513
  );
2514
2514
  }
2515
- logger2.debug("turn:api_request", { sessionId: opts2.sessionId, messageCount: apiMessages.length });
2515
+ logger.debug("turn:api_request", { sessionId: opts2.sessionId, messageCount: apiMessages.length });
2516
2516
  const events = runKimi({
2517
2517
  accountId: opts2.accountId,
2518
2518
  apiToken: opts2.apiToken,
@@ -2534,7 +2534,7 @@ Use console.log() to return results. Only console.log output will be sent back t
2534
2534
  for await (const ev of events) {
2535
2535
  if (!gotFirstChunk) {
2536
2536
  gotFirstChunk = true;
2537
- logger2.debug("turn:api_first_chunk", { sessionId: opts2.sessionId });
2537
+ logger.debug("turn:api_first_chunk", { sessionId: opts2.sessionId });
2538
2538
  }
2539
2539
  switch (ev.type) {
2540
2540
  case "gateway_meta":
@@ -2613,7 +2613,7 @@ Use console.log() to return results. Only console.log output will be sent back t
2613
2613
  if (budgetExhausted) {
2614
2614
  throw new BudgetExhaustedError();
2615
2615
  }
2616
- logger2.info("turn:complete", { sessionId: opts2.sessionId, durationMs: Math.round(performance.now() - turnStart) });
2616
+ logger.info("turn:complete", { sessionId: opts2.sessionId, durationMs: Math.round(performance.now() - turnStart) });
2617
2617
  return;
2618
2618
  }
2619
2619
  for (const tc of toolCalls) {
@@ -2742,7 +2742,7 @@ ${sandboxResult.output}` : `${warningPrefix}${sandboxResult.output}`;
2742
2742
  recentToolCalls.push(loopSignature);
2743
2743
  if (recentToolCalls.length > LOOP_WINDOW) recentToolCalls.shift();
2744
2744
  } else {
2745
- logger2.debug("turn:tool_start", { sessionId: opts2.sessionId, tool: tc.function.name, toolCallId: tc.id });
2745
+ logger.debug("turn:tool_start", { sessionId: opts2.sessionId, tool: tc.function.name, toolCallId: tc.id });
2746
2746
  const result = await opts2.executor.run(
2747
2747
  { id: tc.id, name: tc.function.name, arguments: tc.function.arguments },
2748
2748
  opts2.callbacks.askPermission,
@@ -2755,7 +2755,7 @@ ${sandboxResult.output}` : `${warningPrefix}${sandboxResult.output}`;
2755
2755
 
2756
2756
  [truncated: ${content2.length - MAX_TOOL_CONTENT_CHARS} chars omitted]`;
2757
2757
  }
2758
- logger2.debug("turn:tool_end", { sessionId: opts2.sessionId, tool: tc.function.name, toolCallId: tc.id, ok: result.ok });
2758
+ logger.debug("turn:tool_end", { sessionId: opts2.sessionId, tool: tc.function.name, toolCallId: tc.id, ok: result.ok });
2759
2759
  toolResults.push(result);
2760
2760
  opts2.messages.push({
2761
2761
  role: "tool",
@@ -3411,7 +3411,7 @@ function runBash(args, ctx) {
3411
3411
  const timeout = Math.min(Math.max(1e3, args.timeout_ms ?? DEFAULT_TIMEOUT), MAX_TIMEOUT);
3412
3412
  const command = injectCoauthor(args.command, ctx.coauthor);
3413
3413
  return new Promise((resolve2, reject) => {
3414
- logger2.debug("bash:spawn", { command: args.command.slice(0, 200), cwd: ctx.cwd });
3414
+ logger.debug("bash:spawn", { command: args.command.slice(0, 200), cwd: ctx.cwd });
3415
3415
  const child = spawn("bash", ["-lc", command], {
3416
3416
  cwd: ctx.cwd,
3417
3417
  env: {
@@ -3425,12 +3425,12 @@ function runBash(args, ctx) {
3425
3425
  let killedByAbort = false;
3426
3426
  const timer = setTimeout(() => {
3427
3427
  killedByTimeout = true;
3428
- logger2.warn("bash:kill_timeout", { command: args.command.slice(0, 200) });
3428
+ logger.warn("bash:kill_timeout", { command: args.command.slice(0, 200) });
3429
3429
  child.kill("SIGKILL");
3430
3430
  }, timeout);
3431
3431
  const onAbort = () => {
3432
3432
  killedByAbort = true;
3433
- logger2.warn("bash:kill_abort", { command: args.command.slice(0, 200), pid: child.pid });
3433
+ logger.warn("bash:kill_abort", { command: args.command.slice(0, 200), pid: child.pid });
3434
3434
  child.kill("SIGKILL");
3435
3435
  };
3436
3436
  ctx.signal?.addEventListener("abort", onAbort, { once: true });
@@ -3443,18 +3443,18 @@ function runBash(args, ctx) {
3443
3443
  child.on("error", (e) => {
3444
3444
  clearTimeout(timer);
3445
3445
  ctx.signal?.removeEventListener("abort", onAbort);
3446
- logger2.error("bash:error", { error: e.message, pid: child.pid });
3446
+ logger.error("bash:error", { error: e.message, pid: child.pid });
3447
3447
  reject(e);
3448
3448
  });
3449
3449
  child.on("exit", (code, signal) => {
3450
- logger2.debug("bash:exit", { code, signal, pid: child.pid, killedByTimeout, killedByAbort });
3450
+ logger.debug("bash:exit", { code, signal, pid: child.pid, killedByTimeout, killedByAbort });
3451
3451
  child.stdout?.destroy();
3452
3452
  child.stderr?.destroy();
3453
3453
  });
3454
3454
  child.on("close", (code, signal) => {
3455
3455
  clearTimeout(timer);
3456
3456
  ctx.signal?.removeEventListener("abort", onAbort);
3457
- logger2.debug("bash:close", { code, signal, pid: child.pid, killedByTimeout, killedByAbort });
3457
+ logger.debug("bash:close", { code, signal, pid: child.pid, killedByTimeout, killedByAbort });
3458
3458
  const header = killedByTimeout ? `(timed out after ${timeout}ms)` : killedByAbort ? `(aborted \u2014 sent SIGKILL)` : `exit=${code ?? "?"}${signal ? ` signal=${signal}` : ""}`;
3459
3459
  const parts = [header];
3460
3460
  if (stdout) parts.push(`--- stdout ---
@@ -6249,24 +6249,24 @@ var init_supervisor = __esm({
6249
6249
  }
6250
6250
  startTurn(opts2, callbacks) {
6251
6251
  if (this.isRunning) {
6252
- logger2.warn("supervisor:start_rejected", { reason: "turn_already_running", phase: this._phase });
6252
+ logger.warn("supervisor:start_rejected", { reason: "turn_already_running", phase: this._phase });
6253
6253
  throw new Error("TurnSupervisor: turn already in progress");
6254
6254
  }
6255
6255
  this._phase = "streaming";
6256
6256
  this._killRequested = false;
6257
- logger2.debug("supervisor:turn_start", { sessionId: opts2.sessionId });
6257
+ logger.debug("supervisor:turn_start", { sessionId: opts2.sessionId });
6258
6258
  this.currentTurn = runAgentTurn(opts2).then(async () => {
6259
6259
  this._phase = "idle";
6260
6260
  if (this._killRequested) {
6261
- logger2.debug("supervisor:turn_killed", { sessionId: opts2.sessionId });
6261
+ logger.debug("supervisor:turn_killed", { sessionId: opts2.sessionId });
6262
6262
  } else {
6263
- logger2.debug("supervisor:turn_done", { sessionId: opts2.sessionId });
6263
+ logger.debug("supervisor:turn_done", { sessionId: opts2.sessionId });
6264
6264
  }
6265
6265
  await callbacks?.onDone?.();
6266
6266
  }).catch(async (error) => {
6267
6267
  this._phase = "idle";
6268
6268
  const err = error;
6269
- logger2.warn("supervisor:turn_error", {
6269
+ logger.warn("supervisor:turn_error", {
6270
6270
  sessionId: opts2.sessionId,
6271
6271
  error: err.message ?? String(err),
6272
6272
  name: err.name
@@ -6284,7 +6284,7 @@ var init_supervisor = __esm({
6284
6284
  killTurn() {
6285
6285
  if (!this.isRunning) return;
6286
6286
  this._killRequested = true;
6287
- logger2.debug("supervisor:kill_requested", { phase: this._phase });
6287
+ logger.debug("supervisor:kill_requested", { phase: this._phase });
6288
6288
  }
6289
6289
  };
6290
6290
  }
@@ -19250,6 +19250,7 @@ var init_app = __esm({
19250
19250
  init_messages();
19251
19251
  init_errors();
19252
19252
  init_abort_scope();
19253
+ init_logger();
19253
19254
  init_chat();
19254
19255
  init_status();
19255
19256
  init_permission();