@ykurilov/agent-chat-core 0.97.0 → 0.97.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.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/{chunk-OKZDW7G3.js → chunk-N4BEH2WJ.js} +65 -61
- package/dist/chunk-N4BEH2WJ.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/storage-contract.js +1 -1
- package/dist/types/agent-run/reply-check-types.d.ts +2 -2
- package/dist/types/agent-run/reply-checks.d.ts +4 -7
- package/dist/types/agent-run/run-agent-turn.d.ts +2 -2
- package/dist/types/agent-run/step-reset.d.ts +2 -1
- package/package.json +1 -1
- package/dist/chunk-OKZDW7G3.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ykurilov/agent-chat-core
|
|
2
2
|
|
|
3
|
+
## 0.97.2
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.97.1
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- bdb32b8: `replyChecks` проверяет каждую видимую текстовую часть законченного ответа, включая фразы перед вызовами инструментов. В `replace` исправление меняет только текст и сохраняет карточки инструментов. В `hold` поток с первого текста ждёт проверки; инструменты исполняются без повтора. Копия веб-хода в мессенджере также учитывает замену раннего текста. Прежние ошибки/повторы каждой проверки и `answer_correction` сохранены. Запросы основного агента внутри хода прежние, следующий ход получает исправленную историю; кэш после изменённой ранней части может не совпасть.
|
|
12
|
+
|
|
13
|
+
### Как обновить приложение
|
|
14
|
+
|
|
15
|
+
1. Обновить установленные пакеты SDK на сервере и в браузере одной версией 0.97.1. Настройки `replyChecks` и `foreignWords` прежние; миграций нет.
|
|
16
|
+
2. Своя проверка вызывается для каждой текстовой части, а не только последней. Своя лента на сырых UI-частях применяет `withoutResetSteps(parts)` из core/react: он обрабатывает и `data-reply-text` (`{ index, text }`, номер текста среди оставшихся частей с нуля).
|
|
17
|
+
3. Проверить ответ с фразой перед инструментом: после завершения исправлены обе части, инструмент выполнен один раз. Для запрета показа исходных фраз выбрать прежний `web: "hold"`; карточки после первого текста тоже появятся после проверки.
|
|
18
|
+
|
|
3
19
|
## 0.97.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ docs/getting-started.md, «Значки шагов и заголовки раз
|
|
|
109
109
|
|
|
110
110
|
С 0.49. Всё по желанию; без этих настроек ход побайтно прежний.
|
|
111
111
|
|
|
112
|
-
- `replyChecks` у `createChatService` — проверки готового
|
|
112
|
+
- `replyChecks` у `createChatService` — проверки каждой видимой текстовой части готового ответа, включая фразы перед инструментами: список или `{ checks, web }`. Готовые —
|
|
113
113
|
пакет `@ykurilov/agent-chat-reply-check` (чужие слова, выдуманные ссылки); своя — `ReplyCheck`: `({ text, seenTexts,
|
|
114
114
|
rewrite, … }) => { text, note? } | void`. Веб: `web: "replace"` (по умолчанию) — печатать и заменить исправленным,
|
|
115
115
|
`"hold"` — не печатать до проверки. Мессенджеры получают только проверенный текст. Переписка — расход
|
|
@@ -3098,9 +3098,22 @@ function shortThoughtTitle(text, rules) {
|
|
|
3098
3098
|
var STEP_RESET_PART_TYPE = "data-step-reset";
|
|
3099
3099
|
var STEPS_MAY_RESET_PART_TYPE = "data-steps-may-reset";
|
|
3100
3100
|
function withoutResetSteps(parts) {
|
|
3101
|
-
if (!parts.some((part) => part.type === STEP_RESET_PART_TYPE)) return parts;
|
|
3101
|
+
if (!parts.some((part) => part.type === STEP_RESET_PART_TYPE || part.type === "data-reply-text")) return parts;
|
|
3102
3102
|
const kept = [];
|
|
3103
3103
|
for (const part of parts) {
|
|
3104
|
+
if (part.type === "data-reply-text") {
|
|
3105
|
+
const data = part.data;
|
|
3106
|
+
if (data && Number.isSafeInteger(data.index) && data.index >= 0 && typeof data.text === "string") {
|
|
3107
|
+
let index = 0;
|
|
3108
|
+
for (let at = 0; at < kept.length; at += 1) {
|
|
3109
|
+
if (kept[at].type === "text" && index++ === data.index) {
|
|
3110
|
+
kept[at] = { ...kept[at], text: data.text };
|
|
3111
|
+
break;
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
continue;
|
|
3116
|
+
}
|
|
3104
3117
|
if (part.type !== STEP_RESET_PART_TYPE) {
|
|
3105
3118
|
kept.push(part);
|
|
3106
3119
|
continue;
|
|
@@ -6676,7 +6689,6 @@ function createReplyRewrite(input) {
|
|
|
6676
6689
|
return result.text;
|
|
6677
6690
|
};
|
|
6678
6691
|
}
|
|
6679
|
-
var lastTextIndex = (parts) => parts.findLastIndex((part) => part.type === "text");
|
|
6680
6692
|
function withTextAt(parts, index, text) {
|
|
6681
6693
|
return parts.map((part, at) => at === index ? { ...part, text } : part);
|
|
6682
6694
|
}
|
|
@@ -6708,46 +6720,42 @@ function replacementChunks(corrected, index, resets, providerId) {
|
|
|
6708
6720
|
const erase = Array.from({ length: resets }, () => ({ type: STEP_RESET_PART_TYPE, data: { providerId } }));
|
|
6709
6721
|
return [...erase, ...chunksForParts(corrected.slice(stepStart))];
|
|
6710
6722
|
}
|
|
6711
|
-
var continuesAnswer = (chunk) => chunk.type === "start-step" || chunk.type.startsWith("tool-") || chunk.type.startsWith("reasoning-") || chunk.type.startsWith("source-") || chunk.type === "file";
|
|
6712
6723
|
function createHeldReplyText() {
|
|
6713
6724
|
let held = null;
|
|
6714
6725
|
let released = false;
|
|
6726
|
+
const release = (values) => {
|
|
6727
|
+
released = true;
|
|
6728
|
+
const out = held ?? [];
|
|
6729
|
+
held = null;
|
|
6730
|
+
let index = 0;
|
|
6731
|
+
return out.flatMap((chunk) => {
|
|
6732
|
+
if (chunk.type === "text-delta") return [];
|
|
6733
|
+
if (chunk.type === "text-start") return [chunk, { type: "text-delta", id: chunk.id, delta: values[index++] ?? "" }];
|
|
6734
|
+
return [chunk];
|
|
6735
|
+
});
|
|
6736
|
+
};
|
|
6715
6737
|
return {
|
|
6716
6738
|
pass(chunk) {
|
|
6717
|
-
if (released) return [chunk];
|
|
6718
|
-
if (chunk.type === STEP_RESET_PART_TYPE) {
|
|
6739
|
+
if (released || "transient" in chunk && chunk.transient) return [chunk];
|
|
6740
|
+
if (chunk.type === STEP_RESET_PART_TYPE && held) {
|
|
6741
|
+
const start = held.findLastIndex((part) => part.type === "start-step");
|
|
6742
|
+
if (start !== -1) {
|
|
6743
|
+
held.length = start;
|
|
6744
|
+
return [];
|
|
6745
|
+
}
|
|
6719
6746
|
held = null;
|
|
6720
6747
|
return [chunk];
|
|
6721
6748
|
}
|
|
6722
6749
|
if (held) {
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
return [];
|
|
6726
|
-
}
|
|
6727
|
-
const out = [...held, chunk];
|
|
6728
|
-
held = null;
|
|
6729
|
-
return out;
|
|
6750
|
+
held.push(chunk);
|
|
6751
|
+
return [];
|
|
6730
6752
|
}
|
|
6731
6753
|
if (chunk.type !== "text-start") return [chunk];
|
|
6732
6754
|
held = [chunk];
|
|
6733
6755
|
return [];
|
|
6734
6756
|
},
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
/** Конец хода: придержанное — сейчас, последний текст — `text`, если он задан. Дальше куски идут сразу. */
|
|
6738
|
-
release(text) {
|
|
6739
|
-
released = true;
|
|
6740
|
-
const out = held ?? [];
|
|
6741
|
-
held = null;
|
|
6742
|
-
if (text === void 0) return out;
|
|
6743
|
-
const lastStart = out.findLast((chunk) => chunk.type === "text-start");
|
|
6744
|
-
if (!lastStart) return out;
|
|
6745
|
-
const { id } = lastStart;
|
|
6746
|
-
return out.flatMap((chunk) => {
|
|
6747
|
-
if (chunk.type === "text-delta" && chunk.id === id) return [];
|
|
6748
|
-
if (chunk.type === "text-start" && chunk.id === id) return [chunk, { type: "text-delta", id, delta: text }];
|
|
6749
|
-
return [chunk];
|
|
6750
|
-
});
|
|
6757
|
+
releaseParts(parts) {
|
|
6758
|
+
return release(parts.flatMap((part) => part.type === "text" ? [part.text] : []));
|
|
6751
6759
|
}
|
|
6752
6760
|
};
|
|
6753
6761
|
}
|
|
@@ -7173,7 +7181,6 @@ function runAgentTurn(input) {
|
|
|
7173
7181
|
async function runTurn(turnInput, emitRaw) {
|
|
7174
7182
|
const externalContent = createExternalContentWatch();
|
|
7175
7183
|
const emitShown = (chunk) => {
|
|
7176
|
-
shownSteps?.observe(chunk);
|
|
7177
7184
|
screenSteps.observe(chunk);
|
|
7178
7185
|
emitRaw(chunk);
|
|
7179
7186
|
if (turnInput.liveDemos && externalContent.observe(chunk)) emitRaw(externalContentChunk());
|
|
@@ -7181,7 +7188,6 @@ async function runTurn(turnInput, emitRaw) {
|
|
|
7181
7188
|
const replyChecks = turnInput.reply === void 0 ? turnInput.replyChecks : void 0;
|
|
7182
7189
|
const seenTexts = replyChecks && createSeenTexts();
|
|
7183
7190
|
const heldText = replyChecks && (replyChecks.web === "hold" || (turnInput.channel ?? "web") !== "web") ? createHeldReplyText() : void 0;
|
|
7184
|
-
const shownSteps = replyChecks && createShownSteps();
|
|
7185
7191
|
const screenSteps = createShownSteps();
|
|
7186
7192
|
const emitToClient = (chunk) => {
|
|
7187
7193
|
for (const passed of heldText ? heldText.pass(chunk) : [chunk]) emitShown(passed);
|
|
@@ -7693,36 +7699,41 @@ async function runTurn(turnInput, emitRaw) {
|
|
|
7693
7699
|
if (garbled) {
|
|
7694
7700
|
logError(`[\u0445\u0432\u043E\u0441\u0442 \u043E\u0431\u0440\u0435\u0437\u0430\u043D] ${garbleLog} \u043F\u0440\u0438\u0437\u043D\u0430\u043A\u0438=${garbled.signs.join(",")} \u0437\u043D\u0430\u043A\u043E\u0432=${garbled.removedChars} \u0432\u044B\u0437\u043E\u0432\u043E\u0432_\u043D\u0435_\u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043E=${droppedCalls}`);
|
|
7695
7701
|
const cut = garbled.parts.filter((part) => !garbledTail.isDroppedCall(part));
|
|
7696
|
-
if (!takeover.signal.aborted) showCutAnswer(parts, cut, garbled.textIndex, {
|
|
7702
|
+
if (!takeover.signal.aborted && !heldText) showCutAnswer(parts, cut, garbled.textIndex, { screenSteps, providerId: answeredProviderId, emit: emitShown });
|
|
7697
7703
|
parts = cut;
|
|
7698
7704
|
} else if (findGarbledTail(garbledTail.forCut(parts))) logError(`[\u0445\u0432\u043E\u0441\u0442 \u043D\u0435 \u043E\u0431\u0440\u0435\u0437\u0430\u043D: \u043E\u0442\u0432\u0435\u0442 \u043E\u0441\u0442\u0430\u043B\u0441\u044F \u0431\u044B \u043F\u0443\u0441\u0442\u044B\u043C] ${garbleLog}`);
|
|
7699
7705
|
const status = input.abortSignal.aborted ? "stopped" : errors.length > 0 ? "error" : pendingHumanInput(parts, input.waitingWidgets).length > 0 ? "awaiting_approval" : "complete";
|
|
7700
7706
|
if (endTurns.hasText()) logError(`[endTurn] \u0447\u0430\u0442=${input.chatId} \u0433\u043E\u0442\u043E\u0432\u044B\u0439 \u0442\u0435\u043A\u0441\u0442 \u043D\u0435 \u043F\u043E\u043A\u0430\u0437\u0430\u043D: \u0445\u043E\u0434 \u043A\u043E\u043D\u0447\u0438\u043B\u0441\u044F \u0441\u043E \u0441\u0442\u0430\u0442\u0443\u0441\u043E\u043C ${status}`);
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
const
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
text
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7707
|
+
if (replyChecks && status === "complete" && parts.some((part) => part.type === "text") && !takeover.signal.aborted) {
|
|
7708
|
+
const seen = [...seenTexts?.list() ?? [], ...await knownTextsOf(replyChecks.knownTexts, { ownerId: input.ownerId ?? "", chatId: input.chatId }, logError)];
|
|
7709
|
+
const rewrite = createReplyRewrite({ ...input, providerId: answeredProviderId, messageId, logError });
|
|
7710
|
+
let textIndex = 0;
|
|
7711
|
+
for (const [index, part] of parts.entries()) {
|
|
7712
|
+
if (part.type !== "text") continue;
|
|
7713
|
+
const original = part.text;
|
|
7714
|
+
const checked2 = await checkedReplyText({
|
|
7715
|
+
checks: replyChecks.checks,
|
|
7716
|
+
text: original,
|
|
7717
|
+
ownerId: input.ownerId ?? "",
|
|
7718
|
+
chatId: input.chatId,
|
|
7719
|
+
messageId,
|
|
7720
|
+
seenTexts: seen,
|
|
7721
|
+
rewrite,
|
|
7722
|
+
logError
|
|
7723
|
+
});
|
|
7724
|
+
if (takeover.signal.aborted) break;
|
|
7725
|
+
const text = checked2 === original ? checked2 : withoutForgedBlocksInRewrite(forgedBlocks.cutText(checked2), checked2, (name) => logError(`[\u0441\u043B\u0443\u0436\u0435\u0431\u043D\u044B\u0439 \u0431\u043B\u043E\u043A \u0432\u044B\u0440\u0435\u0437\u0430\u043D] \u0442\u0435\u0433=${name} ${garbleLog}`));
|
|
7726
|
+
if (text !== original) {
|
|
7727
|
+
parts = withTextAt(parts, index, text);
|
|
7728
|
+
if (!heldText) emitShown({ type: "data-reply-text", data: { index: textIndex, text } });
|
|
7721
7729
|
}
|
|
7722
|
-
|
|
7730
|
+
textIndex += 1;
|
|
7723
7731
|
}
|
|
7724
7732
|
}
|
|
7725
|
-
for (const chunk of heldText?.
|
|
7733
|
+
for (const chunk of heldText?.releaseParts(parts) ?? []) emitShown(chunk);
|
|
7734
|
+
if (garbled && heldText && !takeover.signal.aborted) {
|
|
7735
|
+
showCutAnswer(titledParts, parts, garbled.textIndex, { screenSteps, providerId: answeredProviderId, emit: emitShown });
|
|
7736
|
+
}
|
|
7726
7737
|
turnUsage.closeAttempt();
|
|
7727
7738
|
const usage = messageUsage();
|
|
7728
7739
|
const error = status === "error" ? { kind: errorKind ?? "other", ...errorDetails && { details: errorDetails } } : null;
|
|
@@ -8379,13 +8390,6 @@ var FINISH_RETRY_PAUSES_MS = [1e3, 3e3];
|
|
|
8379
8390
|
function showCutAnswer(original, cut, anchor, screen) {
|
|
8380
8391
|
if (anchor === -1) return;
|
|
8381
8392
|
const textsAfter = original.slice(anchor + 1).filter((part) => part.type === "text").length;
|
|
8382
|
-
if (screen.heldText?.holdsText()) {
|
|
8383
|
-
if (textsAfter === 0 && lastTextIndex(cut) === anchor) {
|
|
8384
|
-
for (const chunk of screen.heldText.release(cut[anchor].text)) screen.emit(chunk);
|
|
8385
|
-
return;
|
|
8386
|
-
}
|
|
8387
|
-
for (const chunk of screen.heldText.release()) screen.emit(chunk);
|
|
8388
|
-
}
|
|
8389
8393
|
const resets = screen.screenSteps.resetsToText(textsAfter);
|
|
8390
8394
|
for (const chunk of resets && replacementChunks(cut, anchor, resets, screen.providerId) || []) screen.emit(chunk);
|
|
8391
8395
|
}
|
|
@@ -15756,4 +15760,4 @@ export {
|
|
|
15756
15760
|
InvalidWidgetAnswerError,
|
|
15757
15761
|
createChatService
|
|
15758
15762
|
};
|
|
15759
|
-
//# sourceMappingURL=chunk-
|
|
15763
|
+
//# sourceMappingURL=chunk-N4BEH2WJ.js.map
|