@ykurilov/agent-chat-core 0.95.0 → 0.95.2

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 (41) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/{chunk-5ZJDBUMA.js → chunk-J4S522IU.js} +93 -79
  3. package/dist/chunk-J4S522IU.js.map +1 -0
  4. package/dist/index.js +1 -1
  5. package/dist/storage-contract.js +1 -1
  6. package/dist/types/agent-run/build-model-request.d.ts +1 -1
  7. package/dist/types/agent-run/chat-closure-request.d.ts +1 -1
  8. package/dist/types/agent-run/data-changes.d.ts +1 -1
  9. package/dist/types/agent-run/observe-model-calls.d.ts +1 -1
  10. package/dist/types/agent-run/reply-checks.d.ts +3 -3
  11. package/dist/types/agent-run/run-agent-turn.d.ts +2 -2
  12. package/dist/types/agent-run/screen-place.d.ts +1 -1
  13. package/dist/types/agent-run/step-context.d.ts +1 -1
  14. package/dist/types/agent-run/tool-result-images-policy.d.ts +1 -1
  15. package/dist/types/agent-run/turn-finished.d.ts +1 -1
  16. package/dist/types/app-state/app-state.d.ts +1 -1
  17. package/dist/types/app-state/state-changed.d.ts +1 -1
  18. package/dist/types/chat-service.d.ts +2 -2
  19. package/dist/types/chat-turn-lease.d.ts +1 -1
  20. package/dist/types/compaction/compaction-service.d.ts +1 -1
  21. package/dist/types/compaction/run-compaction.d.ts +1 -1
  22. package/dist/types/frozen-context/freeze-context.d.ts +1 -1
  23. package/dist/types/helpers/run-helper.d.ts +1 -1
  24. package/dist/types/memory/memory-after-answer.d.ts +1 -1
  25. package/dist/types/models/model-choice.d.ts +1 -1
  26. package/dist/types/provider-errors/provider-outages.d.ts +1 -1
  27. package/dist/types/provider-errors/transient-retry-middleware.d.ts +1 -1
  28. package/dist/types/subject-chats/subject-chats.d.ts +1 -1
  29. package/dist/types/thought-titles/thought-titles-setting.d.ts +3 -3
  30. package/dist/types/thought-titles/turn-thought-titles.d.ts +1 -1
  31. package/dist/types/turn-hooks/after-turn.d.ts +1 -1
  32. package/dist/types/turn-hooks/app-events.d.ts +1 -1
  33. package/dist/types/turn-hooks/turn-gate.d.ts +1 -1
  34. package/dist/types/usage/ask-model.d.ts +1 -1
  35. package/dist/types/usage/cache-miss-watch.d.ts +1 -1
  36. package/dist/types/usage/record-usage.d.ts +1 -1
  37. package/dist/types/usage/settle-generation-usage.d.ts +1 -1
  38. package/dist/types/widgets/widget-answer-check.d.ts +1 -1
  39. package/dist/types/widgets/widget-tools.d.ts +2 -2
  40. package/package.json +1 -1
  41. package/dist/chunk-5ZJDBUMA.js.map +0 -1
@@ -3649,7 +3649,7 @@ function createTransientRetryMiddleware(context = {}) {
3649
3649
  if (abortSignal?.aborted || delay === void 0 || !isTransient(error) || silences >= silenceAttempts()) throw error;
3650
3650
  const remainingMs = Math.max(0, delays.reduce((sum, value) => sum + value, 0) - waitedMs);
3651
3651
  const pauseMs = requestedPauseMs(error, remainingMs, now()) ?? Math.round(Math.min(delay * (1 + random() * RETRY_JITTER), remainingMs));
3652
- context.logError?.(retryLine(context, attempt + 2, error, pauseMs));
3652
+ context.logError?.(retryLine(context, attempt + 2, error, pauseMs), error);
3653
3653
  await pause2(pauseMs, abortSignal);
3654
3654
  waitedMs += pauseMs;
3655
3655
  }
@@ -3954,7 +3954,7 @@ async function recordSpentTokens(input) {
3954
3954
  });
3955
3955
  return id;
3956
3956
  } catch (failure) {
3957
- input.logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0438\u0441\u0430\u0442\u044C \u0440\u0430\u0441\u0445\u043E\u0434 (${input.source}, \u0447\u0430\u0442 ${input.chatId}): ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`);
3957
+ input.logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0438\u0441\u0430\u0442\u044C \u0440\u0430\u0441\u0445\u043E\u0434 (${input.source}, \u0447\u0430\u0442 ${input.chatId}): ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, failure);
3958
3958
  return null;
3959
3959
  }
3960
3960
  }
@@ -4323,7 +4323,8 @@ function observeModelCalls(model, context) {
4323
4323
  context.observer.modelCall(event);
4324
4324
  } catch (failure) {
4325
4325
  context.logError(
4326
- `\u041D\u0430\u0431\u043B\u044E\u0434\u0430\u0442\u0435\u043B\u044C \u0445\u043E\u0434\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u043B \u043E\u0431\u0440\u0430\u0449\u0435\u043D\u0438\u0435 \u043A \u043C\u043E\u0434\u0435\u043B\u0438 \u0432 \u0447\u0430\u0442\u0435 ${context.chatId}: ${failure instanceof Error ? failure.message : String(failure)}`
4326
+ `\u041D\u0430\u0431\u043B\u044E\u0434\u0430\u0442\u0435\u043B\u044C \u0445\u043E\u0434\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u043B \u043E\u0431\u0440\u0430\u0449\u0435\u043D\u0438\u0435 \u043A \u043C\u043E\u0434\u0435\u043B\u0438 \u0432 \u0447\u0430\u0442\u0435 ${context.chatId}: ${failure instanceof Error ? failure.message : String(failure)}`,
4327
+ failure
4327
4328
  );
4328
4329
  }
4329
4330
  }
@@ -6232,7 +6233,8 @@ async function recordCorrection(input, providerId, steps, known) {
6232
6233
  });
6233
6234
  } catch (failure) {
6234
6235
  input.logError(
6235
- `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0438\u0441\u0430\u0442\u044C \u043F\u043E\u043F\u0440\u0430\u0432\u043A\u0443 \u0440\u0430\u0441\u0445\u043E\u0434\u0430 (\u0447\u0430\u0442 ${input.chatId}): ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`
6236
+ `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0438\u0441\u0430\u0442\u044C \u043F\u043E\u043F\u0440\u0430\u0432\u043A\u0443 \u0440\u0430\u0441\u0445\u043E\u0434\u0430 (\u0447\u0430\u0442 ${input.chatId}): ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`,
6237
+ failure
6236
6238
  );
6237
6239
  }
6238
6240
  }
@@ -6353,7 +6355,7 @@ function createTurnThoughtTitles(input) {
6353
6355
  const title = cleanThoughtTitle(raw, rules());
6354
6356
  if (title) set(key, title);
6355
6357
  }).catch((error) => {
6356
- if (!input.signal?.aborted) input.logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] \u043D\u0435 \u0432\u044B\u0448\u0435\u043B: ${error instanceof Error ? error.message : String(error)}`);
6358
+ if (!input.signal?.aborted) input.logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] \u043D\u0435 \u0432\u044B\u0448\u0435\u043B: ${error instanceof Error ? error.message : String(error)}`, error);
6357
6359
  }).finally(() => pending.delete(job));
6358
6360
  pending.add(job);
6359
6361
  }
@@ -6602,7 +6604,7 @@ async function knownTextsOf(known, context, logError) {
6602
6604
  if (Array.isArray(texts)) return texts.filter((text) => typeof text === "string" && text !== "");
6603
6605
  logError(`[replyChecks] \u0447\u0430\u0442=${context.chatId} knownTexts \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435 \u0441\u043F\u0438\u0441\u043E\u043A \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0435\u0437 \u0442\u0435\u043A\u0441\u0442\u043E\u0432 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F`);
6604
6606
  } catch (failure) {
6605
- logError(`[replyChecks] \u0447\u0430\u0442=${context.chatId} knownTexts \u0443\u043F\u0430\u043B: ${failure instanceof Error ? failure.message : String(failure)} \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0435\u0437 \u0442\u0435\u043A\u0441\u0442\u043E\u0432 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F`);
6607
+ logError(`[replyChecks] \u0447\u0430\u0442=${context.chatId} knownTexts \u0443\u043F\u0430\u043B: ${failure instanceof Error ? failure.message : String(failure)} \u2014 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0435\u0437 \u0442\u0435\u043A\u0441\u0442\u043E\u0432 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F`, failure);
6606
6608
  }
6607
6609
  return [];
6608
6610
  }
@@ -6619,7 +6621,7 @@ async function runReplyChecks(input) {
6619
6621
  try {
6620
6622
  result = await check({ text, ownerId, chatId, messageId, seenTexts: [...input.seenTexts], rewrite });
6621
6623
  } catch (failure) {
6622
- logError(`${where} \u0443\u043F\u0430\u043B\u0430: ${failure instanceof Error ? failure.message : String(failure)} \u2014 \u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D \u0442\u0435\u043A\u0441\u0442 \u0434\u043E \u043D\u0435\u0451`);
6624
+ logError(`${where} \u0443\u043F\u0430\u043B\u0430: ${failure instanceof Error ? failure.message : String(failure)} \u2014 \u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D \u0442\u0435\u043A\u0441\u0442 \u0434\u043E \u043D\u0435\u0451`, failure);
6623
6625
  continue;
6624
6626
  }
6625
6627
  if (result === void 0 || result === null) continue;
@@ -6972,7 +6974,7 @@ function createChatClosureRequest(context) {
6972
6974
  if (!record) return;
6973
6975
  recording = recording.then(
6974
6976
  () => record(checked2).catch(
6975
- (failure) => context.logError(`\u0417\u0430\u043A\u0440\u044B\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${context.chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u0438 \u0432\u044B\u0437\u043E\u0432\u0435 closeChat: ${failure instanceof Error ? failure.message : String(failure)}`)
6977
+ (failure) => context.logError(`\u0417\u0430\u043A\u0440\u044B\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${context.chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u0438 \u0432\u044B\u0437\u043E\u0432\u0435 closeChat: ${failure instanceof Error ? failure.message : String(failure)}`, failure)
6976
6978
  )
6977
6979
  );
6978
6980
  },
@@ -7021,7 +7023,7 @@ function appBlocksSource(options2) {
7021
7023
  var sourceOf = (key) => isMemoryKey(key) ? "memory" : isReservedKey(key) ? "core" : "app";
7022
7024
  async function freezeContext(input) {
7023
7025
  const { chatId, sources, base, signal, memoryFrom, appContextFrom } = input;
7024
- const log = input.logError ?? console.error;
7026
+ const log = input.logError ?? ((message) => console.error(message));
7025
7027
  const fromBase = (source) => base?.data.blocks.filter((block) => sourceOf(block.key) === source) ?? [];
7026
7028
  const read = async (source, fetch, from) => {
7027
7029
  const previous = source === "memory" ? base?.data.memoryFrom : base?.data.appContextFrom;
@@ -7032,7 +7034,7 @@ async function freezeContext(input) {
7032
7034
  if (blocks2 !== null && blocks2 !== void 0 && !Array.isArray(blocks2)) throw new TypeError(`\u0436\u0434\u0451\u043C \u0441\u043F\u0438\u0441\u043E\u043A \u0431\u043B\u043E\u043A\u043E\u0432, \u0430 \u043F\u0440\u0438\u0448\u043B\u043E ${typeof blocks2}`);
7033
7035
  return { blocks: blocks2 ?? [], ...from !== void 0 && { from } };
7034
7036
  } catch (error) {
7035
- if (!signal?.aborted) log(`[\u0431\u043B\u043E\u043A\u0438 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430] \u0447\u0430\u0442=${chatId} \u0438\u0441\u0442\u043E\u0447\u043D\u0438\u043A=${source} \u0441\u0431\u043E\u0439: ${error instanceof Error ? error.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}; \u0431\u043B\u043E\u043A\u0438 \u0438\u0437 \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u0445\u043E\u0434\u0430`);
7037
+ if (!signal?.aborted) log(`[\u0431\u043B\u043E\u043A\u0438 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430] \u0447\u0430\u0442=${chatId} \u0438\u0441\u0442\u043E\u0447\u043D\u0438\u043A=${source} \u0441\u0431\u043E\u0439: ${error instanceof Error ? error.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}; \u0431\u043B\u043E\u043A\u0438 \u0438\u0437 \u043F\u0440\u043E\u0448\u043B\u043E\u0433\u043E \u0445\u043E\u0434\u0430`, error);
7036
7038
  return { blocks: fromBase(source) };
7037
7039
  }
7038
7040
  };
@@ -7188,7 +7190,7 @@ async function runTurn(turnInput, emitRaw) {
7188
7190
  const noNewAttempts = new AbortController();
7189
7191
  const input = { ...turnInput, abortSignal: AbortSignal.any([turnInput.abortSignal, takeover.signal, noNewAttempts.signal, ...turnInput.leaseSignal ? [turnInput.leaseSignal] : []]) };
7190
7192
  const { storage, messageId, modelId, resume } = input;
7191
- const logError = input.logError ?? console.error;
7193
+ const logError = input.logError ?? ((message) => console.error(message));
7192
7194
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
7193
7195
  if (!resume || resume.replay) {
7194
7196
  await storage.insertMessage(
@@ -7466,7 +7468,7 @@ async function runTurn(turnInput, emitRaw) {
7466
7468
  ...seenTexts && { seenTexts }
7467
7469
  });
7468
7470
  } catch (error2) {
7469
- if (error2 instanceof MissingProviderKeyError) logError(error2.message);
7471
+ if (error2 instanceof MissingProviderKeyError) logError(error2.message, error2);
7470
7472
  if (!input.abortSignal.aborted) {
7471
7473
  const kind = classify(error2);
7472
7474
  errorKind = errorKindForPerson(kind, firstOutage);
@@ -7611,7 +7613,8 @@ async function runTurn(turnInput, emitRaw) {
7611
7613
  errors = errorKind === result.kind ? attempt.errors : [{ type: "error", errorText: errorKind }];
7612
7614
  terminal = attempt.terminal;
7613
7615
  logError(
7614
- describeProviderFailure(result.error, { chatId: input.chatId, modelId, providerId, kind: result.kind, env: input.env, catalog: input.catalog })
7616
+ describeProviderFailure(result.error, { chatId: input.chatId, modelId, providerId, kind: result.kind, env: input.env, catalog: input.catalog }),
7617
+ result.error
7615
7618
  );
7616
7619
  break;
7617
7620
  }
@@ -7636,14 +7639,14 @@ async function runTurn(turnInput, emitRaw) {
7636
7639
  return summary !== null;
7637
7640
  } catch (error2) {
7638
7641
  if (!input.abortSignal.aborted) {
7639
- logError(`[\u043F\u0435\u0440\u0435\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0435] \u0447\u0430\u0442=${input.chatId} \u0441\u0436\u0430\u0442\u0438\u0435 \u0443\u043F\u0430\u043B\u043E: ${error2 instanceof Error ? error2.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`);
7642
+ logError(`[\u043F\u0435\u0440\u0435\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0435] \u0447\u0430\u0442=${input.chatId} \u0441\u0436\u0430\u0442\u0438\u0435 \u0443\u043F\u0430\u043B\u043E: ${error2 instanceof Error ? error2.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, error2);
7640
7643
  }
7641
7644
  return false;
7642
7645
  }
7643
7646
  }
7644
7647
  } catch (error2) {
7645
7648
  if (!input.abortSignal.aborted) {
7646
- if (error2 instanceof AgentViewerError) logError(`[agent.viewer] \u0447\u0430\u0442=${input.chatId} \u0445\u043E\u0434 \u043D\u0435 \u043D\u0430\u0447\u0430\u0442: ${error2.message}`);
7649
+ if (error2 instanceof AgentViewerError) logError(`[agent.viewer] \u0447\u0430\u0442=${input.chatId} \u0445\u043E\u0434 \u043D\u0435 \u043D\u0430\u0447\u0430\u0442: ${error2.message}`, error2);
7647
7650
  errorKind = error2 instanceof AgentViewerError ? "other" : classifyProviderError(error2, void 0);
7648
7651
  errorDetails = void 0;
7649
7652
  errors = [{ type: "error", errorText: errorKind }];
@@ -7796,7 +7799,7 @@ async function runTurn(turnInput, emitRaw) {
7796
7799
  async function chatClosedNow() {
7797
7800
  if (!input.isChatClosed) return false;
7798
7801
  return input.isChatClosed().catch((failure) => {
7799
- logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${input.chatId} \u0432 \u043A\u043E\u043D\u0446\u0435 \u0445\u043E\u0434\u0430: ${failure instanceof Error ? failure.message : String(failure)}`);
7802
+ logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${input.chatId} \u0432 \u043A\u043E\u043D\u0446\u0435 \u0445\u043E\u0434\u0430: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
7800
7803
  return false;
7801
7804
  });
7802
7805
  }
@@ -7805,7 +7808,7 @@ async function runTurn(turnInput, emitRaw) {
7805
7808
  try {
7806
7809
  await input.closeChat(closure2);
7807
7810
  } catch (failure) {
7808
- logError(`\u0427\u0430\u0442 ${input.chatId} \u043D\u0435 \u0437\u0430\u043A\u0440\u044B\u043B\u0441\u044F \u043F\u043E\u0441\u043B\u0435 \u0445\u043E\u0434\u0430 (closeChat): ${failure instanceof Error ? failure.message : String(failure)}`);
7811
+ logError(`\u0427\u0430\u0442 ${input.chatId} \u043D\u0435 \u0437\u0430\u043A\u0440\u044B\u043B\u0441\u044F \u043F\u043E\u0441\u043B\u0435 \u0445\u043E\u0434\u0430 (closeChat): ${failure instanceof Error ? failure.message : String(failure)}`, failure);
7809
7812
  return;
7810
7813
  }
7811
7814
  emitToClient({ type: CHAT_CLOSED_PART_TYPE, data: closure2, transient: true });
@@ -7818,7 +7821,7 @@ async function runTurn(turnInput, emitRaw) {
7818
7821
  // Потеря аренды ещё не значит, что чужая копия закрыла ответ. Идущий снимок учтёт recovery.
7819
7822
  (closed) => closed?.status === "streaming" ? null : [closed?.usage ?? {}],
7820
7823
  (failure) => {
7821
- logError(`\u0420\u0430\u0441\u0445\u043E\u0434 \u043F\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043D\u043D\u043E\u0433\u043E \u043E\u0442\u0432\u0435\u0442\u0430 ${messageId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`);
7824
+ logError(`\u0420\u0430\u0441\u0445\u043E\u0434 \u043F\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043D\u043D\u043E\u0433\u043E \u043E\u0442\u0432\u0435\u0442\u0430 ${messageId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, failure);
7822
7825
  return null;
7823
7826
  }
7824
7827
  );
@@ -7908,7 +7911,7 @@ function readAnswerAttempt(input, attempt, opened, classify) {
7908
7911
  });
7909
7912
  }
7910
7913
  async function openAttempt(input, attempt, attemptSignal) {
7911
- const logError = input.logError ?? console.error;
7914
+ const logError = input.logError ?? ((message) => console.error(message));
7912
7915
  const { found } = attempt;
7913
7916
  const providerId = found.provider.id;
7914
7917
  const limit = input.toolResultLimit ?? DEFAULT_TOOL_RESULT_LIMIT;
@@ -8150,7 +8153,8 @@ function withToolObserver(tools, context) {
8150
8153
  });
8151
8154
  } catch (failure) {
8152
8155
  context.logError(
8153
- `\u041D\u0430\u0431\u043B\u044E\u0434\u0430\u0442\u0435\u043B\u044C \u0445\u043E\u0434\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u043B \u0432\u044B\u0437\u043E\u0432 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u0430 ${name} \u0432 \u0447\u0430\u0442\u0435 ${context.chatId}: ${failure instanceof Error ? failure.message : String(failure)}`
8156
+ `\u041D\u0430\u0431\u043B\u044E\u0434\u0430\u0442\u0435\u043B\u044C \u0445\u043E\u0434\u0430 \u043D\u0435 \u043F\u0440\u0438\u043D\u044F\u043B \u0432\u044B\u0437\u043E\u0432 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u0430 ${name} \u0432 \u0447\u0430\u0442\u0435 ${context.chatId}: ${failure instanceof Error ? failure.message : String(failure)}`,
8157
+ failure
8154
8158
  );
8155
8159
  }
8156
8160
  };
@@ -8310,7 +8314,7 @@ function onlyAllowedHelpers(helpers, group) {
8310
8314
  return Object.fromEntries(Object.entries(helpers).filter(([name]) => allowed.has(`helper_${name}`)));
8311
8315
  }
8312
8316
  function runFinishedHook(input, status, answeredProviderId) {
8313
- const reportFailure = (failure) => (input.logError ?? console.error)(`\u0425\u0443\u043A \u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u044F \u0445\u043E\u0434\u0430 \u0443\u043F\u0430\u043B: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`);
8317
+ const reportFailure = (failure) => (input.logError ?? ((message) => console.error(message)))(`\u0425\u0443\u043A \u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u044F \u0445\u043E\u0434\u0430 \u0443\u043F\u0430\u043B: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, failure);
8314
8318
  try {
8315
8319
  void Promise.resolve(input.onFinished({ status, messageId: input.messageId, answeredProviderId })).catch(reportFailure);
8316
8320
  } catch (failure) {
@@ -8410,7 +8414,8 @@ async function finishWithRetries(storage, messageId, final, logError) {
8410
8414
  }
8411
8415
  const pause2 = FINISH_RETRY_PAUSES_MS[attempt];
8412
8416
  logError(
8413
- `\u041A\u043E\u043D\u0435\u0447\u043D\u0430\u044F \u0437\u0430\u043F\u0438\u0441\u044C \u043E\u0442\u0432\u0435\u0442\u0430 ${messageId} \u043D\u0435 \u0443\u0434\u0430\u043B\u0430\u0441\u044C (\u043F\u043E\u043F\u044B\u0442\u043A\u0430 ${attempt + 1}): ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}${pause2 === void 0 ? "" : `; \u043F\u043E\u0432\u0442\u043E\u0440 \u0447\u0435\u0440\u0435\u0437 ${pause2} \u043C\u0441`}`
8417
+ `\u041A\u043E\u043D\u0435\u0447\u043D\u0430\u044F \u0437\u0430\u043F\u0438\u0441\u044C \u043E\u0442\u0432\u0435\u0442\u0430 ${messageId} \u043D\u0435 \u0443\u0434\u0430\u043B\u0430\u0441\u044C (\u043F\u043E\u043F\u044B\u0442\u043A\u0430 ${attempt + 1}): ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}${pause2 === void 0 ? "" : `; \u043F\u043E\u0432\u0442\u043E\u0440 \u0447\u0435\u0440\u0435\u0437 ${pause2} \u043C\u0441`}`,
8418
+ failure
8414
8419
  );
8415
8420
  if (pause2 === void 0) return isOurFinal(storage, messageId, final).catch(() => false);
8416
8421
  await new Promise((resolve) => setTimeout(resolve, pause2));
@@ -8551,7 +8556,7 @@ async function* helperSteps(input) {
8551
8556
  providerId = next.providerId;
8552
8557
  continue;
8553
8558
  }
8554
- context.logError(describeProviderFailure(error, { chatId: context.chatId, modelId, providerId, kind, env: context.env, catalog: context.catalog }));
8559
+ context.logError(describeProviderFailure(error, { chatId: context.chatId, modelId, providerId, kind, env: context.env, catalog: context.catalog }), error);
8555
8560
  yield report("failed", { error: FAILURE_REASONS[errorKindForPerson(kind, firstOutage)] });
8556
8561
  return;
8557
8562
  }
@@ -9899,7 +9904,9 @@ function createAfterTurn(context) {
9899
9904
  const where = `\u0447\u0430\u0442 ${result.chatId}, \u043E\u0442\u0432\u0435\u0442 ${result.messageId}, \u0438\u0442\u043E\u0433 ${result.status}`;
9900
9905
  const outcome = await callWithRetries(settings.handler, result, { timeoutMs, attempts });
9901
9906
  if (!outcome.ok) {
9902
- logError(`afterTurn \u043D\u0435 \u043E\u0442\u0440\u0430\u0431\u043E\u0442\u0430\u043B (${where}): ${outcome.reason}`);
9907
+ const message = `afterTurn \u043D\u0435 \u043E\u0442\u0440\u0430\u0431\u043E\u0442\u0430\u043B (${where}): ${outcome.reason}`;
9908
+ if ("error" in outcome) logError(message, outcome.error);
9909
+ else logError(message);
9903
9910
  chatEvents.emit({ type: "after-turn-failed", ownerId: result.ownerId, chatId: result.chatId, messageId: result.messageId });
9904
9911
  await closeState(storage, result.messageId, "failed", [], logError, where);
9905
9912
  return [];
@@ -9915,7 +9922,7 @@ function createAfterTurn(context) {
9915
9922
  const sums = await storage.sumUsage({ chatId: answer.chatId, messageId: answer.messageId });
9916
9923
  return sums.reduce((total, sum) => total + sum.costUsd, 0);
9917
9924
  } catch (failure) {
9918
- logError(`\u0426\u0435\u043D\u0430 \u043E\u0442\u0432\u0435\u0442\u0430 ${answer.messageId} \u0434\u043B\u044F afterTurn \u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043D\u0430: ${failure instanceof Error ? failure.message : String(failure)}`);
9925
+ logError(`\u0426\u0435\u043D\u0430 \u043E\u0442\u0432\u0435\u0442\u0430 ${answer.messageId} \u0434\u043B\u044F afterTurn \u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043D\u0430: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
9919
9926
  return null;
9920
9927
  }
9921
9928
  }
@@ -9924,7 +9931,7 @@ function createAfterTurn(context) {
9924
9931
  const chat = await storage.getChat(turn.chatId);
9925
9932
  return chat ? chatDataOfInput(chat) : turn.chatData;
9926
9933
  } catch (failure) {
9927
- logError(`\u0414\u0430\u043D\u043D\u044B\u0435 \u0447\u0430\u0442\u0430 ${turn.chatId} \u0434\u043B\u044F afterTurn \u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043D\u044B: ${failure instanceof Error ? failure.message : String(failure)}`);
9934
+ logError(`\u0414\u0430\u043D\u043D\u044B\u0435 \u0447\u0430\u0442\u0430 ${turn.chatId} \u0434\u043B\u044F afterTurn \u043D\u0435 \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u043D\u044B: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
9928
9935
  return turn.chatData;
9929
9936
  }
9930
9937
  }
@@ -9977,7 +9984,7 @@ function createAfterTurn(context) {
9977
9984
  chatEvents.emit({ type: "app-event", ownerId: turn.ownerId, chatId: turn.chatId, messageId: turn.messageId, event });
9978
9985
  }
9979
9986
  }).catch(
9980
- (failure) => logError(`\u0421\u043E\u0431\u044B\u0442\u0438\u044F afterTurn \u043E\u0442\u0432\u0435\u0442\u0430 ${turn.messageId} \u043F\u043E\u0441\u043B\u0435 \xAB\u0421\u0442\u043E\u043F\u0430\xBB \u043D\u0435 \u043E\u0442\u0434\u0430\u043D\u044B: ${failure instanceof Error ? failure.message : String(failure)}`)
9987
+ (failure) => logError(`\u0421\u043E\u0431\u044B\u0442\u0438\u044F afterTurn \u043E\u0442\u0432\u0435\u0442\u0430 ${turn.messageId} \u043F\u043E\u0441\u043B\u0435 \xAB\u0421\u0442\u043E\u043F\u0430\xBB \u043D\u0435 \u043E\u0442\u0434\u0430\u043D\u044B: ${failure instanceof Error ? failure.message : String(failure)}`, failure)
9981
9988
  );
9982
9989
  return [];
9983
9990
  },
@@ -9985,7 +9992,7 @@ function createAfterTurn(context) {
9985
9992
  if (inFlight.has(messageId)) return;
9986
9993
  inFlight.add(messageId);
9987
9994
  void track(recover(messageId)).catch(
9988
- (failure) => logError(`afterTurn \u043E\u0442\u0432\u0435\u0442\u0430 ${messageId} \u043F\u043E\u0441\u043B\u0435 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430 \u043D\u0435 \u0434\u043E\u0434\u0435\u043B\u0430\u043D: ${failure instanceof Error ? failure.message : String(failure)}`)
9995
+ (failure) => logError(`afterTurn \u043E\u0442\u0432\u0435\u0442\u0430 ${messageId} \u043F\u043E\u0441\u043B\u0435 \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0430 \u043D\u0435 \u0434\u043E\u0434\u0435\u043B\u0430\u043D: ${failure instanceof Error ? failure.message : String(failure)}`, failure)
9989
9996
  ).finally(() => inFlight.delete(messageId));
9990
9997
  },
9991
9998
  async recoverPending(skip) {
@@ -10047,6 +10054,7 @@ async function callWithRetries(handler, result, limits) {
10047
10054
  let expired = false;
10048
10055
  const tries = (async () => {
10049
10056
  let reason = "";
10057
+ let lastError;
10050
10058
  for (let attempt = 1; attempt <= limits.attempts && !expired; attempt++) {
10051
10059
  if (attempt > 1) await pause(AFTER_TURN_RETRY_PAUSES_MS[Math.min(attempt - 2, AFTER_TURN_RETRY_PAUSES_MS.length - 1)], giveUp.signal);
10052
10060
  if (expired) break;
@@ -10054,16 +10062,17 @@ async function callWithRetries(handler, result, limits) {
10054
10062
  try {
10055
10063
  returned = await handler(result);
10056
10064
  } catch (failure) {
10065
+ lastError = failure;
10057
10066
  reason = `\u043F\u043E\u043F\u044B\u0442\u043A\u0430 ${attempt} \u0438\u0437 ${limits.attempts}: ${failure instanceof Error ? failure.message : String(failure)}`;
10058
10067
  continue;
10059
10068
  }
10060
10069
  try {
10061
10070
  return { ok: true, events: checkedEvents(returned) };
10062
10071
  } catch (failure) {
10063
- return { ok: false, reason: failure instanceof Error ? failure.message : String(failure) };
10072
+ return { ok: false, reason: failure instanceof Error ? failure.message : String(failure), error: failure };
10064
10073
  }
10065
10074
  }
10066
- return { ok: false, reason };
10075
+ return { ok: false, reason, error: lastError };
10067
10076
  })();
10068
10077
  try {
10069
10078
  return await Promise.race([tries, deadline]);
@@ -10085,7 +10094,7 @@ async function closeState(storage, messageId, state, appendParts, logError, wher
10085
10094
  try {
10086
10095
  return await storage.setAfterTurnState(messageId, state, appendParts.length > 0 ? { appendParts } : void 0);
10087
10096
  } catch (failure) {
10088
- logError(`\u0421\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435 afterTurn \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D\u043E (${where}): ${failure instanceof Error ? failure.message : String(failure)}`);
10097
+ logError(`\u0421\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435 afterTurn \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043D\u043E (${where}): ${failure instanceof Error ? failure.message : String(failure)}`, failure);
10089
10098
  return false;
10090
10099
  }
10091
10100
  }
@@ -10126,7 +10135,9 @@ function createStateChanged(context) {
10126
10135
  async function callHandler(handler, input) {
10127
10136
  const failure = await callWithRetries2(handler, input, timeoutMs, attempts);
10128
10137
  if (failure === void 0) return;
10129
- context.logError(`onStateChanged \u043D\u0435 \u043E\u0442\u0440\u0430\u0431\u043E\u0442\u0430\u043B (\u0447\u0430\u0442 ${input.chatId}, \u043F\u0440\u0438\u0447\u0438\u043D\u0430 ${input.reason}): ${failure}`);
10138
+ const message = `onStateChanged \u043D\u0435 \u043E\u0442\u0440\u0430\u0431\u043E\u0442\u0430\u043B (\u0447\u0430\u0442 ${input.chatId}, \u043F\u0440\u0438\u0447\u0438\u043D\u0430 ${input.reason}): ${failure.reason}`;
10139
+ if ("error" in failure) context.logError(message, failure.error);
10140
+ else context.logError(message);
10130
10141
  context.chatEvents.emit({ type: "state-changed-failed", ownerId: input.ownerId, chatId: input.chatId });
10131
10142
  }
10132
10143
  return {
@@ -10155,10 +10166,11 @@ async function callWithRetries2(handler, input, timeoutMs, attempts) {
10155
10166
  let timer;
10156
10167
  let expired = false;
10157
10168
  const deadline = new Promise((resolve) => {
10158
- timer = setTimeout(() => resolve(`\u0441\u0440\u043E\u043A ${timeoutMs} \u043C\u0441 \u0432\u044B\u0448\u0435\u043B`), timeoutMs);
10169
+ timer = setTimeout(() => resolve({ reason: `\u0441\u0440\u043E\u043A ${timeoutMs} \u043C\u0441 \u0432\u044B\u0448\u0435\u043B` }), timeoutMs);
10159
10170
  });
10160
10171
  const tries = (async () => {
10161
10172
  let reason = "";
10173
+ let lastError;
10162
10174
  for (let attempt = 1; attempt <= attempts && !expired; attempt++) {
10163
10175
  if (attempt > 1) await new Promise((resolve) => setTimeout(resolve, RETRY_PAUSES_MS[Math.min(attempt - 2, RETRY_PAUSES_MS.length - 1)]));
10164
10176
  if (expired) break;
@@ -10166,10 +10178,11 @@ async function callWithRetries2(handler, input, timeoutMs, attempts) {
10166
10178
  await handler(structuredClone(input));
10167
10179
  return void 0;
10168
10180
  } catch (failure) {
10181
+ lastError = failure;
10169
10182
  reason = `\u043F\u043E\u043F\u044B\u0442\u043A\u0430 ${attempt} \u0438\u0437 ${attempts}: ${failure instanceof Error ? failure.message : String(failure)}`;
10170
10183
  }
10171
10184
  }
10172
- return reason;
10185
+ return { reason, error: lastError };
10173
10186
  })();
10174
10187
  try {
10175
10188
  return await Promise.race([tries, deadline]);
@@ -10773,7 +10786,7 @@ function createSubjectChats(deps) {
10773
10786
  try {
10774
10787
  await deps.wakeAgent(chat.ownerId, chat.id, instruction);
10775
10788
  } catch (error) {
10776
- deps.logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442\u044C \u0430\u0433\u0435\u043D\u0442\u0430 \u043D\u043E\u0432\u043E\u0433\u043E \u0447\u0430\u0442\u0430 ${chat.id}: ${error instanceof Error ? error.message : String(error)}`);
10789
+ deps.logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u0431\u0443\u0434\u0438\u0442\u044C \u0430\u0433\u0435\u043D\u0442\u0430 \u043D\u043E\u0432\u043E\u0433\u043E \u0447\u0430\u0442\u0430 ${chat.id}: ${error instanceof Error ? error.message : String(error)}`, error);
10777
10790
  }
10778
10791
  }
10779
10792
  async function createChat(input, greeting) {
@@ -10840,7 +10853,7 @@ function createSubjectChats(deps) {
10840
10853
  const uploaded = [];
10841
10854
  const discardUploaded = async () => {
10842
10855
  if (uploaded.length === 0) return;
10843
- await deps.attachments?.discardImportedFiles?.(uploaded).catch((error) => deps.logError(`\u0418\u043C\u043F\u043E\u0440\u0442 \u0447\u0430\u0442\u0430 ${chatId}: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0431\u0440\u0430\u0442\u044C \u0444\u0430\u0439\u043B\u044B: ${String(error)}`));
10856
+ await deps.attachments?.discardImportedFiles?.(uploaded).catch((error) => deps.logError(`\u0418\u043C\u043F\u043E\u0440\u0442 \u0447\u0430\u0442\u0430 ${chatId}: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0431\u0440\u0430\u0442\u044C \u0444\u0430\u0439\u043B\u044B: ${String(error)}`, error));
10844
10857
  };
10845
10858
  const createdAt = isoDate(source.createdAt ?? incoming[0].createdAt);
10846
10859
  try {
@@ -10898,7 +10911,7 @@ function createSubjectChats(deps) {
10898
10911
  throw error;
10899
10912
  }
10900
10913
  if (closure && storage.setChatClosed) {
10901
- await storage.setChatClosed(chatId, closure).catch((error) => deps.logError(`\u0418\u043C\u043F\u043E\u0440\u0442 \u0447\u0430\u0442\u0430 ${chatId}: \u043A\u043E\u043F\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C: ${String(error)}`));
10914
+ await storage.setChatClosed(chatId, closure).catch((error) => deps.logError(`\u0418\u043C\u043F\u043E\u0440\u0442 \u0447\u0430\u0442\u0430 ${chatId}: \u043A\u043E\u043F\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C: ${String(error)}`, error));
10902
10915
  }
10903
10916
  return { chatId };
10904
10917
  }
@@ -11036,7 +11049,8 @@ function resolveDefaultChoice(catalog, env, configured, logError) {
11036
11049
  return validateModelChoice(catalog, env, configured, { requireKey: false, allowHidden: true });
11037
11050
  } catch (error) {
11038
11051
  logError(
11039
- `\u0412\u044B\u0431\u043E\u0440 \u043C\u043E\u0434\u0435\u043B\u0438 \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E \xAB${configured.modelId}\xBB \u0443 \xAB${configured.providerId}\xBB \u043D\u0435 \u043F\u043E\u0434\u0445\u043E\u0434\u0438\u0442: ${error.message}. \u0412\u0437\u044F\u0442\u0430 \u043F\u0435\u0440\u0432\u0430\u044F \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430\u044F \u043C\u043E\u0434\u0435\u043B\u044C.`
11052
+ `\u0412\u044B\u0431\u043E\u0440 \u043C\u043E\u0434\u0435\u043B\u0438 \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E \xAB${configured.modelId}\xBB \u0443 \xAB${configured.providerId}\xBB \u043D\u0435 \u043F\u043E\u0434\u0445\u043E\u0434\u0438\u0442: ${error.message}. \u0412\u0437\u044F\u0442\u0430 \u043F\u0435\u0440\u0432\u0430\u044F \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430\u044F \u043C\u043E\u0434\u0435\u043B\u044C.`,
11053
+ error
11040
11054
  );
11041
11055
  }
11042
11056
  }
@@ -11560,7 +11574,7 @@ function thoughtTitleLanguage(resolved, input, logError) {
11560
11574
  const chosen = language(input);
11561
11575
  if (typeof chosen === "string" && chosen.trim()) return chosen.trim();
11562
11576
  } catch (error) {
11563
- logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] thoughtTitles.language \u0443\u043F\u0430\u043B\u0430: ${error instanceof Error ? error.message : String(error)}`);
11577
+ logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] thoughtTitles.language \u0443\u043F\u0430\u043B\u0430: ${error instanceof Error ? error.message : String(error)}`, error);
11564
11578
  }
11565
11579
  }
11566
11580
  return languageOfText(input.lastUserText);
@@ -11570,7 +11584,7 @@ function thoughtTitlesEnabled(resolved, chat, logError) {
11570
11584
  try {
11571
11585
  return resolved.enabled(chat) === true;
11572
11586
  } catch (error) {
11573
- logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] thoughtTitles.enabled \u0443\u043F\u0430\u043B\u0430: ${error instanceof Error ? error.message : String(error)}`);
11587
+ logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] thoughtTitles.enabled \u0443\u043F\u0430\u043B\u0430: ${error instanceof Error ? error.message : String(error)}`, error);
11574
11588
  return false;
11575
11589
  }
11576
11590
  }
@@ -11580,7 +11594,7 @@ async function thoughtTitleHiddenNames(resolved, chat, logError) {
11580
11594
  const names = await resolved.hiddenNames(chat);
11581
11595
  return Array.isArray(names) ? names.filter((name) => typeof name === "string") : [];
11582
11596
  } catch (error) {
11583
- logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] thoughtTitles.hiddenNames \u0443\u043F\u0430\u043B\u0430: ${error instanceof Error ? error.message : String(error)}`);
11597
+ logError(`[\u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A \u0440\u0430\u0437\u0434\u0443\u043C\u044C\u044F] thoughtTitles.hiddenNames \u0443\u043F\u0430\u043B\u0430: ${error instanceof Error ? error.message : String(error)}`, error);
11584
11598
  return [];
11585
11599
  }
11586
11600
  }
@@ -11652,9 +11666,9 @@ function createMemoryAfterAnswer({ memory, storage, catalog, env, logError, turn
11652
11666
  await memory.afterAnswer({ userId: ownerId, chatId, model, recordUsage });
11653
11667
  } catch (failure) {
11654
11668
  const kind = classifyProviderError(failure, found.provider);
11655
- logError(describeProviderFailure(failure, { chatId, modelId, providerId, kind, env, catalog }));
11669
+ logError(describeProviderFailure(failure, { chatId, modelId, providerId, kind, env, catalog }), failure);
11656
11670
  }
11657
- })().catch((failure) => logError(`\u0414\u0435\u043B\u0430 \u043F\u0430\u043C\u044F\u0442\u0438 \u043F\u043E\u0441\u043B\u0435 \u043E\u0442\u0432\u0435\u0442\u0430 \u0432 \u0447\u0430\u0442\u0435 ${chatId} \u043D\u0435 \u0443\u0434\u0430\u043B\u0438\u0441\u044C: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`)).finally(() => running.delete(job));
11671
+ })().catch((failure) => logError(`\u0414\u0435\u043B\u0430 \u043F\u0430\u043C\u044F\u0442\u0438 \u043F\u043E\u0441\u043B\u0435 \u043E\u0442\u0432\u0435\u0442\u0430 \u0432 \u0447\u0430\u0442\u0435 ${chatId} \u043D\u0435 \u0443\u0434\u0430\u043B\u0438\u0441\u044C: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, failure)).finally(() => running.delete(job));
11658
11672
  running.add(job);
11659
11673
  },
11660
11674
  async drain() {
@@ -11963,7 +11977,7 @@ function createCompactionService(options2) {
11963
11977
  if (error instanceof CompactionFailedError && error.usage) await recordCompactionUsage({ chatId, model, spent: error.usage, startedAt });
11964
11978
  if (signal.aborted) return "failed";
11965
11979
  pausedAt.set(chatId, now());
11966
- logError(compactionFailureLine(chatId, model, error));
11980
+ logError(compactionFailureLine(chatId, model, error), error);
11967
11981
  return "failed";
11968
11982
  }
11969
11983
  }
@@ -12095,7 +12109,7 @@ function createCompactionService(options2) {
12095
12109
  } catch (error) {
12096
12110
  if (error instanceof CompactionFailedError && error.usage) await recordCompactionUsage({ chatId, model, spent: error.usage, startedAt });
12097
12111
  if (abortSignal?.aborted) return null;
12098
- logError(compactionFailureLine(chatId, model, error));
12112
+ logError(compactionFailureLine(chatId, model, error), error);
12099
12113
  line("\u043D\u0435 \u0432\u044B\u0448\u043B\u043E");
12100
12114
  return null;
12101
12115
  }
@@ -12119,7 +12133,7 @@ function createCompactionService(options2) {
12119
12133
  if (!isCompactionDue({ branch: branchThroughAnswer(branch, answerId), compactions, contextWindowTokens: profile.contextWindowTokens, settings })) return;
12120
12134
  void compact(chatId, { modelId: answer.modelId, providerId: answer.providerId }, void 0, answerId);
12121
12135
  } catch (error) {
12122
- logError(`\u0421\u0436\u0430\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${chatId}: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C, \u043D\u0443\u0436\u043D\u043E \u043B\u0438 \u043E\u043D\u043E: ${error instanceof Error ? error.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`);
12136
+ logError(`\u0421\u0436\u0430\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${chatId}: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C, \u043D\u0443\u0436\u043D\u043E \u043B\u0438 \u043E\u043D\u043E: ${error instanceof Error ? error.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, error);
12123
12137
  }
12124
12138
  }
12125
12139
  async function mustWaitForCompaction(chatId, branch, compactions, choice) {
@@ -12302,7 +12316,7 @@ function createChatTurnLeases(input) {
12302
12316
  clearTimeout(timer);
12303
12317
  if (expired) {
12304
12318
  void pending.then(() => release(chatId, lease.token), () => release(chatId, lease.token)).catch((error) => {
12305
- logError(`\u041F\u043E\u0437\u0434\u043D\u0435\u0435 \u0441\u043D\u044F\u0442\u0438\u0435 \u0430\u0440\u0435\u043D\u0434\u044B \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`);
12319
+ logError(`\u041F\u043E\u0437\u0434\u043D\u0435\u0435 \u0441\u043D\u044F\u0442\u0438\u0435 \u0430\u0440\u0435\u043D\u0434\u044B \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`, error);
12306
12320
  });
12307
12321
  }
12308
12322
  resolve();
@@ -12323,7 +12337,7 @@ function createChatTurnLeases(input) {
12323
12337
  const previous = releasing.get(chatId);
12324
12338
  const after = [previous, renewalBarrier(chatId, lease)].filter((step) => step !== void 0);
12325
12339
  const done = (after.length > 0 ? Promise.all(after).then(() => release(chatId, lease.token)) : release(chatId, lease.token)).catch((error) => {
12326
- logError(`\u0410\u0440\u0435\u043D\u0434\u0430 \u0445\u043E\u0434\u0430 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0441\u043D\u044F\u043B\u0430\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`);
12340
+ logError(`\u0410\u0440\u0435\u043D\u0434\u0430 \u0445\u043E\u0434\u0430 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0441\u043D\u044F\u043B\u0430\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`, error);
12327
12341
  }).finally(() => {
12328
12342
  if (releasing.get(chatId) === done) releasing.delete(chatId);
12329
12343
  });
@@ -12537,7 +12551,7 @@ function createTurnGate(hooks) {
12537
12551
  const text = decision.reply?.text;
12538
12552
  if (typeof text !== "string" || text.trim().length === 0) {
12539
12553
  const error = new TypeError("\u0413\u043E\u0442\u043E\u0432\u044B\u0439 \u0442\u0435\u043A\u0441\u0442 beforeTurn \u2014 \u043D\u0435\u043F\u0443\u0441\u0442\u0430\u044F \u0441\u0442\u0440\u043E\u043A\u0430: { reply: { text } }");
12540
- logError(`beforeTurn \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0433\u043E\u0442\u043E\u0432\u044B\u0439 \u0442\u0435\u043A\u0441\u0442 (\u0447\u0430\u0442 ${input.chat.id}, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 ${input.action}): ${error.message}`);
12554
+ logError(`beforeTurn \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0433\u043E\u0442\u043E\u0432\u044B\u0439 \u0442\u0435\u043A\u0441\u0442 (\u0447\u0430\u0442 ${input.chat.id}, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 ${input.action}): ${error.message}`, error);
12541
12555
  throw error;
12542
12556
  }
12543
12557
  return REPLY_ACTIONS.has(input.action) ? { kind: "reply", text } : new TurnRefusedError({ code: TURN_HELD_CODE, message: TURN_HELD_MESSAGE });
@@ -12545,7 +12559,7 @@ function createTurnGate(hooks) {
12545
12559
  try {
12546
12560
  return new TurnRefusedError(decision);
12547
12561
  } catch (error) {
12548
- logError(`beforeTurn \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043E\u0442\u043A\u0430\u0437 (\u0447\u0430\u0442 ${input.chat.id}, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 ${input.action}): ${error instanceof Error ? error.message : String(error)}`);
12562
+ logError(`beforeTurn \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043E\u0442\u043A\u0430\u0437 (\u0447\u0430\u0442 ${input.chat.id}, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 ${input.action}): ${error instanceof Error ? error.message : String(error)}`, error);
12549
12563
  throw error;
12550
12564
  }
12551
12565
  }
@@ -12564,7 +12578,7 @@ function createTurnGate(hooks) {
12564
12578
  ...abandonedOf(input)
12565
12579
  });
12566
12580
  } catch (error) {
12567
- logError(`turnNotStarted \u0443\u043F\u0430\u043B (\u0447\u0430\u0442 ${input.chat.id}, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 ${input.action}, \u043F\u0440\u0438\u0447\u0438\u043D\u0430 ${reason}): ${error instanceof Error ? error.message : String(error)}`);
12581
+ logError(`turnNotStarted \u0443\u043F\u0430\u043B (\u0447\u0430\u0442 ${input.chat.id}, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 ${input.action}, \u043F\u0440\u0438\u0447\u0438\u043D\u0430 ${reason}): ${error instanceof Error ? error.message : String(error)}`, error);
12568
12582
  }
12569
12583
  }
12570
12584
  function reasonOf(error) {
@@ -12929,7 +12943,7 @@ function createInstructionsAssembler(blocks) {
12929
12943
 
12930
12944
  // src/agent-run/turn-finished.ts
12931
12945
  function notifyTurnFinished(handler, turn, logError) {
12932
- const reportFailure = (failure) => logError(`onTurnFinished \u0443\u043F\u0430\u043B (\u0447\u0430\u0442 ${turn.chatId}, \u043E\u0442\u0432\u0435\u0442 ${turn.messageId}): ${failure instanceof Error ? failure.message : String(failure)}`);
12946
+ const reportFailure = (failure) => logError(`onTurnFinished \u0443\u043F\u0430\u043B (\u0447\u0430\u0442 ${turn.chatId}, \u043E\u0442\u0432\u0435\u0442 ${turn.messageId}): ${failure instanceof Error ? failure.message : String(failure)}`, failure);
12933
12947
  try {
12934
12948
  void Promise.resolve(handler(turn)).catch(reportFailure);
12935
12949
  } catch (failure) {
@@ -13137,7 +13151,7 @@ function createChatService(input) {
13137
13151
  const { storage } = options2;
13138
13152
  const uneditableTools = /* @__PURE__ */ new Set([...input.lockedToolOutputs ?? [], ...Object.keys(widgets.tools)]);
13139
13153
  const instructionsOfChat = chatInstructionsSource(input.chatInstructions, options2.agent.instructions, instructionBlocks, input.background?.instructions);
13140
- const chatEvents = input.chatEvents ?? createChatEvents((error) => logError(`\u0421\u043B\u0443\u0448\u0430\u0442\u0435\u043B\u044C \u0441\u043E\u0431\u044B\u0442\u0438\u0439 \u0447\u0430\u0442\u0430 \u0443\u043F\u0430\u043B: ${String(error)}`));
13154
+ const chatEvents = input.chatEvents ?? createChatEvents((error) => logError(`\u0421\u043B\u0443\u0448\u0430\u0442\u0435\u043B\u044C \u0441\u043E\u0431\u044B\u0442\u0438\u0439 \u0447\u0430\u0442\u0430 \u0443\u043F\u0430\u043B: ${String(error)}`, error));
13141
13155
  const afterTurn = options2.afterTurn && createAfterTurn({
13142
13156
  settings: { handler: options2.afterTurn, timeoutMs: options2.afterTurnTimeoutMs, attempts: options2.afterTurnAttempts },
13143
13157
  storage,
@@ -13205,7 +13219,7 @@ function createChatService(input) {
13205
13219
  try {
13206
13220
  return await voices?.current(userId);
13207
13221
  } catch (error) {
13208
- logError(`\u0413\u043E\u043B\u043E\u0441: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0437\u043D\u0430\u0442\u044C \u0433\u043E\u043B\u043E\u0441 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430: ${error instanceof Error ? error.message : String(error)}`);
13222
+ logError(`\u0413\u043E\u043B\u043E\u0441: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0437\u043D\u0430\u0442\u044C \u0433\u043E\u043B\u043E\u0441 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430: ${error instanceof Error ? error.message : String(error)}`, error);
13209
13223
  return void 0;
13210
13224
  }
13211
13225
  };
@@ -13328,7 +13342,7 @@ function createChatService(input) {
13328
13342
  });
13329
13343
  } catch (error) {
13330
13344
  if (!isWidgetCheckOutcome(error)) {
13331
- logError(`[\u0432\u0438\u0434\u0436\u0435\u0442] \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u0447\u0430\u0442=${logValue(call.chat.id)} \u0432\u044B\u0437\u043E\u0432=${logValue(call.toolCallId)}: ${logValue(error instanceof Error ? error.name : "\u043D\u0435 \u043E\u0448\u0438\u0431\u043A\u0430")}`);
13345
+ logError(`[\u0432\u0438\u0434\u0436\u0435\u0442] \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u0447\u0430\u0442=${logValue(call.chat.id)} \u0432\u044B\u0437\u043E\u0432=${logValue(call.toolCallId)}: ${logValue(error instanceof Error ? error.name : "\u043D\u0435 \u043E\u0448\u0438\u0431\u043A\u0430")}`, error);
13332
13346
  }
13333
13347
  throw error;
13334
13348
  } finally {
@@ -13390,7 +13404,7 @@ function createChatService(input) {
13390
13404
  }
13391
13405
  function afterSpending(userId, chatId) {
13392
13406
  if (!options2.limits?.afterSpending) return;
13393
- const report = (failure) => logError(`\u041B\u0438\u043C\u0438\u0442\u044B \u043F\u043E\u0441\u043B\u0435 \u0440\u0430\u0441\u0445\u043E\u0434\u0430 (\u0447\u0430\u0442 ${chatId}): ${failure instanceof Error ? failure.message : String(failure)}`);
13407
+ const report = (failure) => logError(`\u041B\u0438\u043C\u0438\u0442\u044B \u043F\u043E\u0441\u043B\u0435 \u0440\u0430\u0441\u0445\u043E\u0434\u0430 (\u0447\u0430\u0442 ${chatId}): ${failure instanceof Error ? failure.message : String(failure)}`, failure);
13394
13408
  try {
13395
13409
  options2.limits.afterSpending({ userId, chatId }).catch(report);
13396
13410
  } catch (failure) {
@@ -13423,7 +13437,7 @@ function createChatService(input) {
13423
13437
  try {
13424
13438
  return await write();
13425
13439
  } catch (error) {
13426
- await giveBack?.().catch((failure) => logError(`\u041C\u0435\u0441\u0442\u043E \u0432 \u043B\u0438\u043C\u0438\u0442\u0435 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0439 \u043D\u0435 \u0432\u0435\u0440\u043D\u0443\u043B\u043E\u0441\u044C (\u0447\u0430\u0442 ${chatId}): ${failure instanceof Error ? failure.message : String(failure)}`));
13440
+ await giveBack?.().catch((failure) => logError(`\u041C\u0435\u0441\u0442\u043E \u0432 \u043B\u0438\u043C\u0438\u0442\u0435 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0439 \u043D\u0435 \u0432\u0435\u0440\u043D\u0443\u043B\u043E\u0441\u044C (\u0447\u0430\u0442 ${chatId}): ${failure instanceof Error ? failure.message : String(failure)}`, failure));
13427
13441
  throw error;
13428
13442
  }
13429
13443
  }
@@ -13470,7 +13484,7 @@ function createChatService(input) {
13470
13484
  warnErrorDetailsWithoutModel(given);
13471
13485
  return resolveChatCapabilities(given);
13472
13486
  } catch (error) {
13473
- logError(`chatCapabilities \u0443\u043F\u0430\u043B \u0438\u043B\u0438 \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0435 \u043F\u0440\u0430\u0432\u0430 (\u0447\u0430\u0442 ${chat.id}): ${error instanceof Error ? error.message : String(error)}`);
13487
+ logError(`chatCapabilities \u0443\u043F\u0430\u043B \u0438\u043B\u0438 \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0435 \u043F\u0440\u0430\u0432\u0430 (\u0447\u0430\u0442 ${chat.id}): ${error instanceof Error ? error.message : String(error)}`, error);
13474
13488
  throw error;
13475
13489
  }
13476
13490
  }
@@ -13502,7 +13516,7 @@ function createChatService(input) {
13502
13516
  try {
13503
13517
  refused = new ChatCreationRefusedError(refusal);
13504
13518
  } catch (error) {
13505
- logError(`beforeCreateChat \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043E\u0442\u043A\u0430\u0437 (\u0447\u0435\u043B\u043E\u0432\u0435\u043A ${userId}): ${error instanceof Error ? error.message : String(error)}`);
13519
+ logError(`beforeCreateChat \u0432\u0435\u0440\u043D\u0443\u043B \u043D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u043E\u0442\u043A\u0430\u0437 (\u0447\u0435\u043B\u043E\u0432\u0435\u043A ${userId}): ${error instanceof Error ? error.message : String(error)}`, error);
13506
13520
  throw error;
13507
13521
  }
13508
13522
  throw refused;
@@ -13527,7 +13541,7 @@ function createChatService(input) {
13527
13541
  async function repairClosureCopy(chat, closed) {
13528
13542
  if (!storage.setChatClosed || sameClosure(chat.closed, closed)) return;
13529
13543
  await storage.setChatClosed(chat.id, closed ?? null).catch(
13530
- (failure) => logError(`\u041A\u043E\u043F\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u0447\u0430\u0442\u0430 ${chat.id} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : String(failure)}`)
13544
+ (failure) => logError(`\u041A\u043E\u043F\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u0447\u0430\u0442\u0430 ${chat.id} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : String(failure)}`, failure)
13531
13545
  );
13532
13546
  }
13533
13547
  const sameClosure = (a, b) => (a ?? null) === (b ?? null) || a?.code === b?.code && a?.message === b?.message;
@@ -13549,7 +13563,7 @@ function createChatService(input) {
13549
13563
  async function writeClosureCopy(ownerId, chatId, closed) {
13550
13564
  if (storage.setChatClosed) {
13551
13565
  await storage.setChatClosed(chatId, closed).catch(
13552
- (failure) => logError(`\u041A\u043E\u043F\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : String(failure)}`)
13566
+ (failure) => logError(`\u041A\u043E\u043F\u0438\u044F \u0437\u0430\u043A\u0440\u044B\u0442\u0438\u044F \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : String(failure)}`, failure)
13553
13567
  );
13554
13568
  }
13555
13569
  chatEvents.emit(closed ? { type: "chat-closed", ownerId, chatId, closed } : { type: "chat-reopened", ownerId, chatId });
@@ -13567,7 +13581,7 @@ function createChatService(input) {
13567
13581
  stateChanged.notify({ ownerId, chatId, reason, before, after: state.values, atMessageId: state.atMessageId });
13568
13582
  await syncClosureCopy(ownerId, chatId, state);
13569
13583
  } catch (failure) {
13570
- logError(`\u0421\u043C\u0435\u043D\u0430 \u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u044F \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0440\u0430\u0437\u043E\u0441\u043B\u0430\u043D\u0430: ${failure instanceof Error ? failure.message : String(failure)}`);
13584
+ logError(`\u0421\u043C\u0435\u043D\u0430 \u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u044F \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0440\u0430\u0437\u043E\u0441\u043B\u0430\u043D\u0430: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
13571
13585
  }
13572
13586
  }
13573
13587
  function afterTurnTask(work) {
@@ -13586,7 +13600,7 @@ function createChatService(input) {
13586
13600
  try {
13587
13601
  await writeUndelivered(chatId);
13588
13602
  } catch (failure) {
13589
- logError(`\u041F\u043E\u043C\u0435\u0442\u043A\u0430 \xAB\u043D\u0435 \u0434\u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u043E\xBB \u0432 \u0447\u0430\u0442\u0435 ${chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C \u043F\u043E\u0441\u043B\u0435 \u0445\u043E\u0434\u0430: ${failure instanceof Error ? failure.message : String(failure)}`);
13603
+ logError(`\u041F\u043E\u043C\u0435\u0442\u043A\u0430 \xAB\u043D\u0435 \u0434\u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u043E\xBB \u0432 \u0447\u0430\u0442\u0435 ${chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u0430\u0441\u044C \u043F\u043E\u0441\u043B\u0435 \u0445\u043E\u0434\u0430: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
13590
13604
  } finally {
13591
13605
  writingUndelivered.delete(chatId);
13592
13606
  }
@@ -13619,7 +13633,7 @@ function createChatService(input) {
13619
13633
  await appendClosure({ id: chatId }, closed);
13620
13634
  });
13621
13635
  } catch (failure) {
13622
- logError(`\u0417\u0430\u043A\u0440\u044B\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u0441\u043B\u0435 \u0445\u043E\u0434\u0430: ${failure instanceof Error ? failure.message : String(failure)}`);
13636
+ logError(`\u0417\u0430\u043A\u0440\u044B\u0442\u0438\u0435 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0437\u0430\u043F\u0438\u0441\u0430\u043B\u043E\u0441\u044C \u043F\u043E\u0441\u043B\u0435 \u0445\u043E\u0434\u0430: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
13623
13637
  } finally {
13624
13638
  writingClosures.delete(chatId);
13625
13639
  }
@@ -13643,7 +13657,7 @@ function createChatService(input) {
13643
13657
  const remembered = await storage.getUserModelChoice(userId);
13644
13658
  return remembered ? effectiveChoiceOfChat(options2.catalog, env, remembered, defaultChoice) : null;
13645
13659
  } catch (error) {
13646
- logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u0442\u044C \u0437\u0430\u043F\u043E\u043C\u043D\u0435\u043D\u043D\u044B\u0439 \u0432\u044B\u0431\u043E\u0440 \u043C\u043E\u0434\u0435\u043B\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 ${userId}: ${String(error)}`);
13660
+ logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0447\u0438\u0442\u0430\u0442\u044C \u0437\u0430\u043F\u043E\u043C\u043D\u0435\u043D\u043D\u044B\u0439 \u0432\u044B\u0431\u043E\u0440 \u043C\u043E\u0434\u0435\u043B\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 ${userId}: ${String(error)}`, error);
13647
13661
  return null;
13648
13662
  }
13649
13663
  }
@@ -13656,7 +13670,7 @@ function createChatService(input) {
13656
13670
  let { messages, selections, branch } = await loadTree(chatId);
13657
13671
  if (write && isDetachedAnswer(answerBeforeCorrections(branch), runningId) && storage.listSilentAnswerIds) {
13658
13672
  const recovered = await recoverStaleAnswers({ chatId }).catch((failure) => {
13659
- logError(`\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u043E\u0433\u043E \u043E\u0442\u0432\u0435\u0442\u0430 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0443\u0434\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`);
13673
+ logError(`\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u043E\u0433\u043E \u043E\u0442\u0432\u0435\u0442\u0430 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0443\u0434\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, failure);
13660
13674
  return 0;
13661
13675
  });
13662
13676
  if (recovered > 0) ({ messages, selections, branch } = await loadTree(chatId));
@@ -13717,12 +13731,12 @@ function createChatService(input) {
13717
13731
  try {
13718
13732
  await options2.onModelChosen({ userId, chatId, choice: { ...choice } });
13719
13733
  } catch (error) {
13720
- logError(`onModelChosen: \u0441\u0431\u043E\u0439 \u0445\u0443\u043A\u0430 (\u0447\u0430\u0442 ${chatId}): ${error instanceof Error ? error.message : String(error)}`);
13734
+ logError(`onModelChosen: \u0441\u0431\u043E\u0439 \u0445\u0443\u043A\u0430 (\u0447\u0430\u0442 ${chatId}): ${error instanceof Error ? error.message : String(error)}`, error);
13721
13735
  }
13722
13736
  }
13723
13737
  async function rememberChoice(userId, choice) {
13724
13738
  if (!storage.saveUserModelChoice) return;
13725
- await storage.saveUserModelChoice(userId, choice).catch((error) => logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u043E\u043C\u043D\u0438\u0442\u044C \u0432\u044B\u0431\u043E\u0440 \u043C\u043E\u0434\u0435\u043B\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 ${userId}: ${String(error)}`));
13739
+ await storage.saveUserModelChoice(userId, choice).catch((error) => logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u043E\u043C\u043D\u0438\u0442\u044C \u0432\u044B\u0431\u043E\u0440 \u043C\u043E\u0434\u0435\u043B\u0438 \u0447\u0435\u043B\u043E\u0432\u0435\u043A\u0430 ${userId}: ${String(error)}`, error));
13726
13740
  }
13727
13741
  async function loadTree(chatId) {
13728
13742
  const [stored, selections] = await Promise.all([storage.listMessages(chatId), storage.listBranchSelections(chatId)]);
@@ -14302,7 +14316,7 @@ function createChatService(input) {
14302
14316
  (held) => {
14303
14317
  if (!held) clearInterval(timer);
14304
14318
  },
14305
- (error) => logError(`\u0423\u0434\u0435\u0440\u0436\u0430\u043D\u0438\u0435 \u043F\u0430\u0447\u043A\u0438 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u043F\u0440\u043E\u0434\u043B\u0438\u043B\u043E\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`)
14319
+ (error) => logError(`\u0423\u0434\u0435\u0440\u0436\u0430\u043D\u0438\u0435 \u043F\u0430\u0447\u043A\u0438 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u043F\u0440\u043E\u0434\u043B\u0438\u043B\u043E\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`, error)
14306
14320
  );
14307
14321
  }, BURST_HOLD_RENEW_MS);
14308
14322
  timer.unref?.();
@@ -14319,7 +14333,7 @@ function createChatService(input) {
14319
14333
  (error) => !burstWaitsForNextSweep(error)
14320
14334
  ).then((decided) => {
14321
14335
  if (decided)
14322
- return storage.removePendingBurst(chatId, questionId).catch((error) => logError(`\u0417\u0430\u043F\u0438\u0441\u044C \u043F\u0430\u0447\u043A\u0438 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0441\u043D\u044F\u043B\u0430\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`));
14336
+ return storage.removePendingBurst(chatId, questionId).catch((error) => logError(`\u0417\u0430\u043F\u0438\u0441\u044C \u043F\u0430\u0447\u043A\u0438 \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u0441\u043D\u044F\u043B\u0430\u0441\u044C: ${error instanceof Error ? error.message : String(error)}`, error));
14323
14337
  });
14324
14338
  return answering;
14325
14339
  }
@@ -14355,7 +14369,7 @@ function createChatService(input) {
14355
14369
  if (!chat) return receivingAbandonedBurst(burst);
14356
14370
  target = await serviceFor({ ownerId: burst.ownerId, chatId: burst.chatId, chat });
14357
14371
  } catch (error) {
14358
- logError(`\u0421\u043B\u0443\u0436\u0431\u0430 \u0434\u043B\u044F \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u043E\u0439 \u043F\u0430\u0447\u043A\u0438 \u0447\u0430\u0442\u0430 ${burst.chatId} \u043D\u0435 \u043D\u0430\u0448\u043B\u0430\u0441\u044C (serviceFor): ${error instanceof Error ? error.message : String(error)} \u2014 \u043F\u0430\u0447\u043A\u0430 \u0436\u0434\u0451\u0442 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0435\u0433\u043E \u043E\u0431\u0445\u043E\u0434\u0430`);
14372
+ logError(`\u0421\u043B\u0443\u0436\u0431\u0430 \u0434\u043B\u044F \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u043E\u0439 \u043F\u0430\u0447\u043A\u0438 \u0447\u0430\u0442\u0430 ${burst.chatId} \u043D\u0435 \u043D\u0430\u0448\u043B\u0430\u0441\u044C (serviceFor): ${error instanceof Error ? error.message : String(error)} \u2014 \u043F\u0430\u0447\u043A\u0430 \u0436\u0434\u0451\u0442 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0435\u0433\u043E \u043E\u0431\u0445\u043E\u0434\u0430`, error);
14359
14373
  return;
14360
14374
  }
14361
14375
  if (!target) {
@@ -14387,7 +14401,7 @@ function createChatService(input) {
14387
14401
  void routingAbandonedBurst(burst).finally(releasingBurstDecision);
14388
14402
  }
14389
14403
  }
14390
- })().catch((error) => logError(`\u041E\u0431\u0445\u043E\u0434 \u0436\u0434\u0443\u0449\u0438\u0445 \u043F\u0430\u0447\u0435\u043A \u043D\u0435 \u0443\u0434\u0430\u043B\u0441\u044F: ${error instanceof Error ? error.message : String(error)}`)).finally(() => burstSweeps.delete(sweep));
14404
+ })().catch((error) => logError(`\u041E\u0431\u0445\u043E\u0434 \u0436\u0434\u0443\u0449\u0438\u0445 \u043F\u0430\u0447\u0435\u043A \u043D\u0435 \u0443\u0434\u0430\u043B\u0441\u044F: ${error instanceof Error ? error.message : String(error)}`, error)).finally(() => burstSweeps.delete(sweep));
14391
14405
  burstSweeps.add(sweep);
14392
14406
  return sweep;
14393
14407
  }
@@ -14483,7 +14497,7 @@ function createChatService(input) {
14483
14497
  throw error;
14484
14498
  }
14485
14499
  await launchTurn(ownerId, chatId, [...before, ...branch.slice(first)], { parentId: last.id, page: continuationRequestContext(page, turn.correctionPages()), action: "send", detached: true });
14486
- }, { lease: "required" }).catch((failure) => logError(`\u0425\u043E\u0434 \u043F\u043E \u043F\u043E\u043F\u0440\u0430\u0432\u043A\u0430\u043C \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u043D\u0430\u0447\u0430\u043B\u0441\u044F: ${failure instanceof Error ? failure.message : String(failure)}`)).finally(() => {
14500
+ }, { lease: "required" }).catch((failure) => logError(`\u0425\u043E\u0434 \u043F\u043E \u043F\u043E\u043F\u0440\u0430\u0432\u043A\u0430\u043C \u0447\u0430\u0442\u0430 ${chatId} \u043D\u0435 \u043D\u0430\u0447\u0430\u043B\u0441\u044F: ${failure instanceof Error ? failure.message : String(failure)}`, failure)).finally(() => {
14487
14501
  if (handOffs.get(chatId) === handOff) handOffs.delete(chatId);
14488
14502
  });
14489
14503
  handOffs.set(chatId, handOff);
@@ -14726,8 +14740,8 @@ function createChatService(input) {
14726
14740
  await options2.attachments?.removeChatFiles?.(chatId);
14727
14741
  await storage.deleteChat(chatId);
14728
14742
  }, { lease: "required" }).finally(() => deleting.delete(chatId));
14729
- await options2.background?.chatDeleted(userId, chatId).catch((error) => logError(`\u0424\u043E\u043D: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0431\u0440\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u0434\u0430\u043B\u0451\u043D\u043D\u043E\u0433\u043E \u0447\u0430\u0442\u0430 ${chatId}: ${String(error)}`));
14730
- await options2.limits?.chatDeleted?.({ userId, chatId }).catch((error) => logError(`\u041B\u0438\u043C\u0438\u0442\u044B: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0441\u0442\u0435\u0440\u0435\u0442\u044C \u043E\u043A\u043D\u0430 \u0443\u0434\u0430\u043B\u0451\u043D\u043D\u043E\u0433\u043E \u0447\u0430\u0442\u0430 ${chatId}: ${String(error)}`));
14743
+ await options2.background?.chatDeleted(userId, chatId).catch((error) => logError(`\u0424\u043E\u043D: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0431\u0440\u0430\u0442\u044C \u0437\u0430\u0434\u0430\u0447\u0438 \u0443\u0434\u0430\u043B\u0451\u043D\u043D\u043E\u0433\u043E \u0447\u0430\u0442\u0430 ${chatId}: ${String(error)}`, error));
14744
+ await options2.limits?.chatDeleted?.({ userId, chatId }).catch((error) => logError(`\u041B\u0438\u043C\u0438\u0442\u044B: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0441\u0442\u0435\u0440\u0435\u0442\u044C \u043E\u043A\u043D\u0430 \u0443\u0434\u0430\u043B\u0451\u043D\u043D\u043E\u0433\u043E \u0447\u0430\u0442\u0430 ${chatId}: ${String(error)}`, error));
14731
14745
  },
14732
14746
  async getModelMenu(userId) {
14733
14747
  if (userId !== void 0 && options2.modelMenu && !await options2.modelMenu({ userId })) throw new ActionForbiddenError("modelDetails");
@@ -15193,7 +15207,7 @@ function createChatService(input) {
15193
15207
  if (sweep.stopped) return;
15194
15208
  sweep.timer = setTimeout(() => {
15195
15209
  sweep.running = Promise.all([recoverStaleAnswers(), afterTurn?.recoverPending(liveAnswerIds), ...recoverBurstsOnSweep ? [sweepingBursts({ abandonedBefore: now().toISOString() })] : []]).then(() => void 0).catch(
15196
- (failure) => logError(`\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u044B\u0445 \u043E\u0442\u0432\u0435\u0442\u043E\u0432 \u043D\u0435 \u0443\u0434\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`)
15210
+ (failure) => logError(`\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u044B\u0445 \u043E\u0442\u0432\u0435\u0442\u043E\u0432 \u043D\u0435 \u0443\u0434\u0430\u043B\u0430\u0441\u044C: ${failure instanceof Error ? failure.message : "\u043D\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430"}`, failure)
15197
15211
  ).finally(() => {
15198
15212
  sweep.running = void 0;
15199
15213
  next();
@@ -15225,7 +15239,7 @@ function createChatService(input) {
15225
15239
  try {
15226
15240
  if (await interruptAnswer(messageId)) recovered += 1;
15227
15241
  } catch (failure) {
15228
- logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u0435\u0440\u0432\u0430\u0442\u044C \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442 ${messageId}: ${failure instanceof Error ? failure.message : String(failure)}`);
15242
+ logError(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u0435\u0440\u0432\u0430\u0442\u044C \u0431\u0440\u043E\u0448\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442 ${messageId}: ${failure instanceof Error ? failure.message : String(failure)}`, failure);
15229
15243
  }
15230
15244
  }
15231
15245
  return recovered;
@@ -15325,7 +15339,7 @@ function createChatService(input) {
15325
15339
  });
15326
15340
  },
15327
15341
  assertWithinLimit: (ownerId, chatId) => assertWithinSpendingLimit(ownerId, chatId),
15328
- logError: (error) => logError(`\u0424\u043E\u043D: ${error instanceof Error ? error.message : String(error)}`),
15342
+ logError: (error) => logError(`\u0424\u043E\u043D: ${error instanceof Error ? error.message : String(error)}`, error),
15329
15343
  helpers: backgroundHelpers
15330
15344
  };
15331
15345
  }
@@ -15651,4 +15665,4 @@ export {
15651
15665
  InvalidWidgetAnswerError,
15652
15666
  createChatService
15653
15667
  };
15654
- //# sourceMappingURL=chunk-5ZJDBUMA.js.map
15668
+ //# sourceMappingURL=chunk-J4S522IU.js.map