@ykurilov/agent-chat-core 0.80.0 → 0.80.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/{chunk-Z44ZAFZC.js → chunk-PORXDIWX.js} +47 -18
- package/dist/chunk-PORXDIWX.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/storage-contract.js +1 -1
- package/dist/types/agent-run/build-model-request.d.ts +3 -9
- package/dist/types/compaction/run-compaction.d.ts +4 -0
- package/dist/types/compaction/summary-part.d.ts +10 -0
- package/dist/types/frozen-context/frozen-context-messages.d.ts +8 -2
- package/package.json +1 -1
- package/dist/chunk-Z44ZAFZC.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ykurilov/agent-chat-core
|
|
2
2
|
|
|
3
|
+
## 0.80.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d59ae4e: После сжатия истории в режиме `contextBlocksRefresh: "history-start"` полный свежий снимок приложения размещается рядом со сводкой. Старые снимки оставленного хвоста больше не возвращают устаревшие данные; последующие изменения идут от свежей базы. Ошибка источника сохраняет прежний fallback, успешный пустой снимок тоже учитывается. Дата, память, место и notices не переносятся; сохранённые ответы не переписываются.
|
|
8
|
+
|
|
9
|
+
Запрос сжатия использует тот же сборщик frozen context, что и обычный ход, с исключением личных app-блоков, памяти, даты и места из сохраняемой сводки. Задание пересказа уточняет границу сжимаемой части. Настройки рассуждений провайдера не меняются. Обновить все пакеты одной версией; SQL-миграций и новых настроек нет.
|
|
10
|
+
|
|
3
11
|
## 0.80.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -4656,6 +4656,11 @@ function withStaffRepliesJoined(history) {
|
|
|
4656
4656
|
return changed ? joined : history;
|
|
4657
4657
|
}
|
|
4658
4658
|
|
|
4659
|
+
// src/compaction/summary-part.ts
|
|
4660
|
+
var SUMMARY = /* @__PURE__ */ Symbol("compaction-summary");
|
|
4661
|
+
var summaryPart = (text) => ({ type: "text", text, [SUMMARY]: true });
|
|
4662
|
+
var isSummaryPart = (part) => part[SUMMARY] === true;
|
|
4663
|
+
|
|
4659
4664
|
// src/frozen-context/frozen-context-messages.ts
|
|
4660
4665
|
function frozenContextBase(history) {
|
|
4661
4666
|
for (let index = history.length - 1; index >= 0; index -= 1) {
|
|
@@ -4670,6 +4675,11 @@ var RESUME_NOTE_ID = "frozen-context-note-";
|
|
|
4670
4675
|
function withFrozenContext(history, options2) {
|
|
4671
4676
|
const { current, group } = options2;
|
|
4672
4677
|
const dataOf = (message) => message.role !== "assistant" ? void 0 : current && message.id === current.answerId ? current.data : frozenContextOf(message.parts);
|
|
4678
|
+
const root = history[0];
|
|
4679
|
+
const anchorHistory = options2.anchorHistory && options2.anchorHistory[0]?.id === root?.id ? options2.anchorHistory : history;
|
|
4680
|
+
const allowed = options2.includeKey ?? (() => true);
|
|
4681
|
+
const anchor = root?.parts.some(isSummaryPart) ? anchorHistory.flatMap((message) => message.role === "assistant" ? [dataOf(message), ...message.parts.filter((p) => p.type === FROZEN_CONTEXT_PART_TYPE).slice(1).map((p) => p.data)] : []).concat(current?.data).find((data) => data?.appContextFrom === root.id) : void 0;
|
|
4682
|
+
let anchored = false;
|
|
4673
4683
|
const seen = /* @__PURE__ */ new Map();
|
|
4674
4684
|
const output = [];
|
|
4675
4685
|
const place = (texts) => {
|
|
@@ -4679,22 +4689,28 @@ function withFrozenContext(history, options2) {
|
|
|
4679
4689
|
if (last?.role === "user") output[output.length - 1] = { ...last, parts: [...last.parts, ...parts] };
|
|
4680
4690
|
else output.push({ id: `frozen-context-${output.length}`, role: "user", parts: output.length === 0 ? [{ type: "text", text: GREETING_LEAD }, ...parts] : parts });
|
|
4681
4691
|
};
|
|
4682
|
-
const textsOf = (data
|
|
4692
|
+
const textsOf = (data, base) => {
|
|
4693
|
+
const include = (key) => allowed(key) && (!anchor || anchored || isReservedKey(key));
|
|
4694
|
+
const texts = blockTexts(data, base, group, anchor || options2.includeKey ? include : void 0);
|
|
4695
|
+
if (data === anchor) anchored = true;
|
|
4696
|
+
return texts;
|
|
4697
|
+
};
|
|
4683
4698
|
let currentPlaced = false;
|
|
4684
4699
|
for (const message of history) {
|
|
4685
4700
|
const data = dataOf(message);
|
|
4686
4701
|
if (data) {
|
|
4687
|
-
place(textsOf(data));
|
|
4702
|
+
place(textsOf(data, data.base === null ? void 0 : seen.get(data.base)));
|
|
4688
4703
|
seen.set(message.id, data);
|
|
4689
4704
|
if (message.id === current?.answerId) currentPlaced = true;
|
|
4690
4705
|
}
|
|
4691
|
-
|
|
4692
|
-
|
|
4706
|
+
const placed = anchor && message === root ? { ...message, parts: message.parts.flatMap((part) => isSummaryPart(part) ? [part, ...anchor.blocks.filter((block) => !isReservedKey(block.key) && allowed(block.key) && !(group && block.private)).map((block) => ({ type: "text", text: block.text }))] : [part]) } : message;
|
|
4707
|
+
output.push(...withResumeNotes(placed, (note) => {
|
|
4708
|
+
const texts = textsOf(note, seen.get(message.id));
|
|
4693
4709
|
seen.set(message.id, note);
|
|
4694
4710
|
return texts;
|
|
4695
4711
|
}));
|
|
4696
4712
|
}
|
|
4697
|
-
if (current && !currentPlaced) place(textsOf(current.data));
|
|
4713
|
+
if (current && !currentPlaced) place(textsOf(current.data, current.data.base === null ? void 0 : seen.get(current.data.base)));
|
|
4698
4714
|
return output;
|
|
4699
4715
|
}
|
|
4700
4716
|
function withResumeNotes(message, textsOf) {
|
|
@@ -4724,11 +4740,11 @@ function holdNoteAfterApprovals(messages) {
|
|
|
4724
4740
|
return { messages: messages.slice(0, -1), note };
|
|
4725
4741
|
}
|
|
4726
4742
|
var awaitsApprovedRun = (part) => part.state === "approval-responded";
|
|
4727
|
-
function blockTexts(data, base, group) {
|
|
4728
|
-
return [...changedBlockTexts(data, base, group), ...(data.notices ?? []).map(noticeText)];
|
|
4743
|
+
function blockTexts(data, base, group, include) {
|
|
4744
|
+
return [...changedBlockTexts(data, base, group, include), ...(data.notices ?? []).map(noticeText)];
|
|
4729
4745
|
}
|
|
4730
|
-
function changedBlockTexts(data, base, group) {
|
|
4731
|
-
const shown = (block) => !(group && block.private);
|
|
4746
|
+
function changedBlockTexts(data, base, group, include) {
|
|
4747
|
+
const shown = (block) => (!include || include(block.key)) && !(group && block.private);
|
|
4732
4748
|
if (data.sent === "all" || !base) return data.blocks.filter(shown).map((block) => block.text);
|
|
4733
4749
|
const now = new Map(data.blocks.map((block) => [block.key, block]));
|
|
4734
4750
|
const before = new Map(base.blocks.map((block) => [block.key, block]));
|
|
@@ -4736,7 +4752,7 @@ function changedBlockTexts(data, base, group) {
|
|
|
4736
4752
|
const block = now.get(key);
|
|
4737
4753
|
return block && shown(block) ? [block.text] : [];
|
|
4738
4754
|
});
|
|
4739
|
-
const visibleKeys = (keys) => keys.filter((key) => !(group && (before.get(key)?.private ?? isMemoryKey(key))));
|
|
4755
|
+
const visibleKeys = (keys) => keys.filter((key) => (!include || include(key)) && !(group && (before.get(key)?.private ?? isMemoryKey(key))));
|
|
4740
4756
|
const removed = visibleKeys(data.sent.removed);
|
|
4741
4757
|
if (removed.length > 0) texts.push(noLongerValid(removed));
|
|
4742
4758
|
const hidden = visibleKeys(data.sent.hidden ?? []);
|
|
@@ -5106,7 +5122,10 @@ async function buildModelRequest(input) {
|
|
|
5106
5122
|
const cleaned = sendableHistory(input.serviceBlocks ? withoutForgedBlocks(untitled, input.serviceBlocks) : untitled);
|
|
5107
5123
|
const sendable = input.switchableTools ? withSwitchedOffCallsAsText(cleaned, input.switchableTools, tools) : cleaned;
|
|
5108
5124
|
const noted = withStaffRepliesJoined(withChannelNotes(withModeNotes(withBurstsJoined(withCorrectionsJoined(sendable)), input.modeNotes)));
|
|
5109
|
-
const held = input.frozenContext ? holdNoteAfterApprovals(withFrozenContext(noted,
|
|
5125
|
+
const held = input.frozenContext ? holdNoteAfterApprovals(withFrozenContext(noted, {
|
|
5126
|
+
...input.frozenContext,
|
|
5127
|
+
...input.frozenContext.anchorHistory && { anchorHistory: sendableHistory(input.frozenContext.anchorHistory) }
|
|
5128
|
+
})) : { messages: noted };
|
|
5110
5129
|
const history = selectReasoningForModel(held.messages, {
|
|
5111
5130
|
modelId: profile.id,
|
|
5112
5131
|
providerId: provider.id,
|
|
@@ -11577,7 +11596,7 @@ function tokens(count) {
|
|
|
11577
11596
|
}
|
|
11578
11597
|
function compactionTask(input) {
|
|
11579
11598
|
if (input.instruction !== void 0) return input.instruction;
|
|
11580
|
-
return `\u0421\u0434\u0435\u043B\u0430\u0439 \u0441\u0432\u043E\u0434\u043A\u0443 \
|
|
11599
|
+
return `\u0421\u0434\u0435\u043B\u0430\u0439 \u0441\u0432\u043E\u0434\u043A\u0443 \u0441\u0436\u0438\u043C\u0430\u0435\u043C\u043E\u0439 \u0447\u0430\u0441\u0442\u0438 \u043F\u0435\u0440\u0435\u043F\u0438\u0441\u043A\u0438 \u0432\u044B\u0448\u0435. \u041E\u043D\u0430 \u0437\u0430\u043A\u0430\u043D\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044F \u043D\u0430 \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0435\u043C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0438 \u043F\u0435\u0440\u0435\u0434 \u044D\u0442\u0438\u043C \u0437\u0430\u0434\u0430\u043D\u0438\u0435\u043C; \u0431\u043E\u043B\u0435\u0435 \u043F\u043E\u0437\u0434\u043D\u044F\u044F \u043F\u0435\u0440\u0435\u043F\u0438\u0441\u043A\u0430 \u043E\u0441\u0442\u0430\u043D\u0435\u0442\u0441\u044F \u0432 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0435 \u043E\u0442\u0434\u0435\u043B\u044C\u043D\u043E. \u041F\u0435\u0440\u0435\u0441\u043A\u0430\u0437 \u0434\u043E\u043B\u0436\u0435\u043D \u043E\u0442\u0440\u0430\u0436\u0430\u0442\u044C \u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435 \u043D\u0430 \u044D\u0442\u043E\u0439 \u0433\u0440\u0430\u043D\u0438\u0446\u0435, \u0447\u0442\u043E\u0431\u044B \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440 \u0432\u043C\u0435\u0441\u0442\u0435 \u0441 \u043E\u0441\u0442\u0430\u0432\u043B\u0435\u043D\u043D\u044B\u043C \u0445\u0432\u043E\u0441\u0442\u043E\u043C, \u0431\u0435\u0437 \u043F\u043E\u0432\u0442\u043E\u0440\u0435\u043D\u0438\u044F \u0443\u0436\u0435 \u0441\u0434\u0435\u043B\u0430\u043D\u043D\u043E\u0433\u043E \u0432 \u043D\u0451\u043C.
|
|
11581
11600
|
|
|
11582
11601
|
\u0415\u0441\u043B\u0438 \u0432 \u043D\u0430\u0447\u0430\u043B\u0435 \u043F\u0435\u0440\u0435\u043F\u0438\u0441\u043A\u0438 \u0443\u0436\u0435 \u0435\u0441\u0442\u044C \u0441\u0432\u043E\u0434\u043A\u0430, \u043D\u0435 \u0434\u043E\u043F\u0438\u0441\u044B\u0432\u0430\u0439 \u043A \u043D\u0435\u0439, \u0430 \u043F\u0435\u0440\u0435\u043F\u0438\u0448\u0438 \u0435\u0451 \u0446\u0435\u043B\u0438\u043A\u043E\u043C \u0432\u043C\u0435\u0441\u0442\u0435 \u0441 \u043D\u043E\u0432\u044B\u043C\u0438 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u044F\u043C\u0438: \u043F\u043E\u043B\u0443\u0447\u0438\u0442\u0441\u044F \u043E\u0434\u043D\u0430 \u0441\u0432\u043E\u0434\u043A\u0430.
|
|
11583
11602
|
|
|
@@ -11608,10 +11627,10 @@ ${summary}
|
|
|
11608
11627
|
function applyCompaction(branch, active) {
|
|
11609
11628
|
if (!active) return branch.map(toAgentChatMessage);
|
|
11610
11629
|
const tail = branch.slice(active.throughIndex + 1).map(toAgentChatMessage);
|
|
11611
|
-
const
|
|
11630
|
+
const summary = summaryPart(summaryFrame(active.record.summary));
|
|
11612
11631
|
const [first, ...rest] = tail;
|
|
11613
|
-
if (first?.role === "user") return [{ ...first, parts: [
|
|
11614
|
-
return [{ id: `${active.record.id}-summary`, role: "user", parts: [
|
|
11632
|
+
if (first?.role === "user") return [{ ...first, parts: [summary, ...first.parts] }, ...rest];
|
|
11633
|
+
return [{ id: `${active.record.id}-summary`, role: "user", parts: [summary] }, ...tail];
|
|
11615
11634
|
}
|
|
11616
11635
|
|
|
11617
11636
|
// src/compaction/run-compaction.ts
|
|
@@ -11643,6 +11662,13 @@ async function runCompaction(input) {
|
|
|
11643
11662
|
const request = await buildModelRequest({
|
|
11644
11663
|
...requestInput,
|
|
11645
11664
|
...input.model,
|
|
11665
|
+
// Общая сводка не несёт privacy-схему: только публичные app blocks, без памяти/даты/места.
|
|
11666
|
+
// Пересказ шагов остаётся на прежнем пути без frozen blocks; никакого нового private opt-in.
|
|
11667
|
+
...!input.transient && { frozenContext: {
|
|
11668
|
+
group: true,
|
|
11669
|
+
includeKey: (key) => !isReservedKey(key),
|
|
11670
|
+
...input.contextHistory && { anchorHistory: input.contextHistory }
|
|
11671
|
+
} },
|
|
11646
11672
|
// Бюджет рассуждений — от предела сводки, а не от потолка модели: иначе он больше предела.
|
|
11647
11673
|
maxOutputTokens,
|
|
11648
11674
|
...lowestLevel && { reasoning: lowestLevel },
|
|
@@ -11653,7 +11679,7 @@ async function runCompaction(input) {
|
|
|
11653
11679
|
role: "user",
|
|
11654
11680
|
content: input.task ?? compactionTask({ summaryCeilingTokens: settings.summaryCeilingTokens, instruction: settings.instruction })
|
|
11655
11681
|
};
|
|
11656
|
-
let base = [...request.messages, task];
|
|
11682
|
+
let base = [...request.messages, ...request.noteAfterApprovals ?? [], task];
|
|
11657
11683
|
let messages = base;
|
|
11658
11684
|
let summary = "";
|
|
11659
11685
|
let summaryTokens = 0;
|
|
@@ -11788,7 +11814,8 @@ function createCompactionService(options2) {
|
|
|
11788
11814
|
}
|
|
11789
11815
|
overflow?.onStart();
|
|
11790
11816
|
model = settings.model ?? model;
|
|
11791
|
-
const
|
|
11817
|
+
const active = activeCompaction(branch, compactions);
|
|
11818
|
+
const history = applyCompaction(branch.slice(0, plan.throughIndex + 1), active);
|
|
11792
11819
|
const chat = await storage.getChat(chatId);
|
|
11793
11820
|
const ownerId = chat?.ownerId ?? "";
|
|
11794
11821
|
const result = await runCompaction({
|
|
@@ -11801,6 +11828,7 @@ function createCompactionService(options2) {
|
|
|
11801
11828
|
...options2.switchableTools && { switchableTools: options2.switchableTools },
|
|
11802
11829
|
...observation(ownerId, answerId),
|
|
11803
11830
|
history,
|
|
11831
|
+
contextHistory: applyCompaction(branch, active),
|
|
11804
11832
|
...options2.attachments && { attachments: options2.attachments },
|
|
11805
11833
|
...options2.serviceBlocks && { serviceBlocks: options2.serviceBlocks },
|
|
11806
11834
|
settings,
|
|
@@ -11945,6 +11973,7 @@ function createCompactionService(options2) {
|
|
|
11945
11973
|
...options2.switchableTools && { switchableTools: options2.switchableTools },
|
|
11946
11974
|
...observation(ownerId, answerId),
|
|
11947
11975
|
history: [...history, { id: `${chatId}-answer-steps`, role: "assistant", parts: steps }],
|
|
11976
|
+
transient: true,
|
|
11948
11977
|
...options2.attachments && { attachments: options2.attachments },
|
|
11949
11978
|
...options2.serviceBlocks && { serviceBlocks: options2.serviceBlocks },
|
|
11950
11979
|
settings,
|
|
@@ -15323,4 +15352,4 @@ export {
|
|
|
15323
15352
|
InvalidWidgetAnswerError,
|
|
15324
15353
|
createChatService
|
|
15325
15354
|
};
|
|
15326
|
-
//# sourceMappingURL=chunk-
|
|
15355
|
+
//# sourceMappingURL=chunk-PORXDIWX.js.map
|