pi-tuck 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -3
- package/README.md +138 -57
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -4
- package/dist/src/budget.d.ts +17 -4
- package/dist/src/budget.js +33 -10
- package/dist/src/build-id.d.ts +1 -1
- package/dist/src/build-id.js +1 -1
- package/dist/src/compaction.d.ts +7 -0
- package/dist/src/compaction.js +32 -16
- package/dist/src/diagnostics.d.ts +2 -1
- package/dist/src/omissions.d.ts +1 -1
- package/dist/src/omissions.js +8 -8
- package/dist/src/tuck/core/brief.d.ts +13 -43
- package/dist/src/tuck/core/brief.js +41 -255
- package/dist/src/tuck/core/filter-noise.js +2 -1
- package/dist/src/tuck/core/format.d.ts +2 -6
- package/dist/src/tuck/core/format.js +4 -10
- package/dist/src/tuck/core/normalize.js +22 -50
- package/dist/src/tuck/core/shrink.d.ts +33 -0
- package/dist/src/tuck/core/shrink.js +218 -0
- package/dist/src/tuck/core/summarize.d.ts +15 -7
- package/dist/src/tuck/core/summarize.js +17 -22
- package/dist/src/tuck/core/transcript.d.ts +24 -13
- package/dist/src/tuck/core/transcript.js +251 -83
- package/dist/src/tuck/types.d.ts +4 -21
- package/dist/src/tuck.d.ts +8 -10
- package/dist/src/tuck.js +23 -25
- package/index.ts +8 -5
- package/package.json +1 -1
- package/src/budget.ts +29 -9
- package/src/build-id.ts +1 -1
- package/src/compaction.ts +33 -14
- package/src/diagnostics.ts +1 -1
- package/src/omissions.ts +8 -8
- package/src/tuck/core/brief.ts +48 -265
- package/src/tuck/core/filter-noise.ts +2 -1
- package/src/tuck/core/format.ts +4 -11
- package/src/tuck/core/normalize.ts +21 -50
- package/src/tuck/core/shrink.ts +217 -0
- package/src/tuck/core/summarize.ts +26 -24
- package/src/tuck/core/transcript.ts +238 -82
- package/src/tuck/types.ts +9 -20
- package/src/tuck.ts +30 -32
- package/dist/src/tuck/core/brief-meter.d.ts +0 -42
- package/dist/src/tuck/core/brief-meter.js +0 -273
- package/dist/src/tuck/core/rank.d.ts +0 -42
- package/dist/src/tuck/core/rank.js +0 -292
- package/src/tuck/core/brief-meter.ts +0 -235
- package/src/tuck/core/rank.ts +0 -331
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { NormalizedBlock } from "../types";
|
|
2
|
+
import { blockRecords, decorateRecord, isDialogue, isOmittable, omissionRecord, type Clip, type DialogueBlock } from "./brief";
|
|
3
|
+
import { DIALOGUE_SUFFIX } from "./format";
|
|
4
|
+
import { orderByOriginalSource } from "./source-order";
|
|
5
|
+
import { serializeRecord, serializeTranscript, TRANSCRIPT_HEADER, type TranscriptRecord } from "./transcript";
|
|
6
|
+
|
|
7
|
+
type Role = "user" | "assistant" | "notice";
|
|
8
|
+
const ROLES: readonly Role[] = ["user", "assistant", "notice"];
|
|
9
|
+
|
|
10
|
+
/** The lossy variants of a unit, least clipped first: the words kept from the start of its text and from its end. */
|
|
11
|
+
const TIERS: Record<Role, readonly Clip[]> = {
|
|
12
|
+
assistant: [[80, 120], [40, 40], [16, 0]],
|
|
13
|
+
user: [[256, 0], [64, 0], [24, 0]],
|
|
14
|
+
notice: [[256, 0]],
|
|
15
|
+
};
|
|
16
|
+
const TOOLS_OMITTED: TranscriptRecord = { kind: "omission", reason: "Historical tool actions and observations omitted; read original sources with tuck_recall" };
|
|
17
|
+
|
|
18
|
+
export interface DialogueInput {
|
|
19
|
+
/** Normalized, noise-filtered blocks of the pre-cut history in chronological order: dialogue and tool blocks alike. */
|
|
20
|
+
blocks: NormalizedBlock[];
|
|
21
|
+
/** Sources the adapter quotes in its own base: they render as nothing here and are not counted as omitted. */
|
|
22
|
+
mandatorySourceIndices?: ReadonlySet<number>;
|
|
23
|
+
/** The source index of each original message and, when known, its entry id, for the original order of the records. */
|
|
24
|
+
sourceIndices: readonly (number | undefined)[];
|
|
25
|
+
sourceEntryIds?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The configurations the ladder tries, in order; "none" is no configuration that fits. */
|
|
29
|
+
export type Step = "whole" | `A${1 | 2 | 3}` | "B" | `C${1 | 2 | 3}` | "D" | "E1" | "E2" | "none";
|
|
30
|
+
export interface Shrunk {
|
|
31
|
+
/** The summary text, or "" when nothing fits. */
|
|
32
|
+
text: string;
|
|
33
|
+
step: Step;
|
|
34
|
+
/** The length the ladder computed from per-unit lengths before it rendered `text`. */
|
|
35
|
+
size: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** What one unit renders in a configuration, and its serialized size: each record's line plus a newline. */
|
|
39
|
+
interface Rendered { records: TranscriptRecord[]; cost: number }
|
|
40
|
+
const rendered = (records: TranscriptRecord[]): Rendered => ({ records, cost: records.reduce((n, r) => n + serializeRecord(r).length + 1, 0) });
|
|
41
|
+
|
|
42
|
+
/** Units [0, drop) of a role are dropped, [drop, end) are clipped to `tier`, and the rest stay whole. */
|
|
43
|
+
interface Setting { drop: number; tier: number; end: number }
|
|
44
|
+
type Config = Record<Role, Setting>;
|
|
45
|
+
const WHOLE: Setting = { drop: 0, tier: 0, end: 0 };
|
|
46
|
+
|
|
47
|
+
/** The units of one role in chronological order, with each variant's cost summed over every prefix. */
|
|
48
|
+
const createLane = (role: Role, units: DialogueBlock[], mandatory: ReadonlySet<number> | undefined, decorate: (record: TranscriptRecord) => TranscriptRecord) => {
|
|
49
|
+
const n = units.length;
|
|
50
|
+
const records = (block: DialogueBlock, clip?: Clip) => rendered(blockRecords(block, mandatory, clip).map(decorate));
|
|
51
|
+
const prefix = (level: Rendered[]) => { const sums = new Float64Array(n + 1); level.forEach((r, i) => sums[i + 1] = sums[i]! + r.cost); return sums; };
|
|
52
|
+
const levels: Rendered[][] = [units.map(block => records(block))];
|
|
53
|
+
const sums = [prefix(levels[0]!)];
|
|
54
|
+
// A clip keeps whole passages, so a unit that is one long sentence, code block or JSON region can keep no text at all. Such a clip renders
|
|
55
|
+
// nothing and its unit is counted in the role's one omission notice, like a dropped unit: a notice per empty clip would cost more than text.
|
|
56
|
+
const NONE: Rendered = { records: [], cost: 0 };
|
|
57
|
+
const emptied: Uint8Array[] = [new Uint8Array(n)];
|
|
58
|
+
const emptyCounts: Int32Array[] = [new Int32Array(n + 1)];
|
|
59
|
+
/** Level t holds each unit's tier-t variant. A clip that would not make the unit smaller is not taken, so sizes never grow with t. */
|
|
60
|
+
const level = (t: number): Rendered[] => {
|
|
61
|
+
while (levels.length <= t) {
|
|
62
|
+
const previous = levels[levels.length - 1]!, wasEmpty = emptied[emptied.length - 1]!, clip = TIERS[role][levels.length - 1]!;
|
|
63
|
+
const empty = new Uint8Array(n);
|
|
64
|
+
const next = units.map((block, i) => {
|
|
65
|
+
if (wasEmpty[i]) { empty[i] = 1; return previous[i]!; }
|
|
66
|
+
const clipped = records(block, clip);
|
|
67
|
+
if (role !== "notice" && isOmittable(block, mandatory) && !clipped.records.some(record => record.kind === "excerpt")) { empty[i] = 1; return NONE; }
|
|
68
|
+
return clipped.cost < previous[i]!.cost ? clipped : previous[i]!;
|
|
69
|
+
});
|
|
70
|
+
const counts = new Int32Array(n + 1);
|
|
71
|
+
empty.forEach((e, i) => counts[i + 1] = counts[i]! + e);
|
|
72
|
+
levels.push(next); sums.push(prefix(next)); emptied.push(empty); emptyCounts.push(counts);
|
|
73
|
+
}
|
|
74
|
+
return levels[t]!;
|
|
75
|
+
};
|
|
76
|
+
const sum = (t: number) => { level(t); return sums[t]!; };
|
|
77
|
+
|
|
78
|
+
// The notice for a dropped prefix of p units: how many unselected text blocks, the first locators, and whether some have none.
|
|
79
|
+
let tally: { counts: Int32Array; unlocated: Uint8Array; smallest: number[][] } | undefined;
|
|
80
|
+
/** The notice for the units a setting omits: the dropped prefix, and the clips in [drop, end) that kept no text. */
|
|
81
|
+
const omission = ({ drop, tier, end }: Setting): TranscriptRecord | undefined => {
|
|
82
|
+
if (role === "notice") return undefined;
|
|
83
|
+
if (!tally) {
|
|
84
|
+
tally = { counts: new Int32Array(n + 1), unlocated: new Uint8Array(n + 1), smallest: new Array(n + 1) };
|
|
85
|
+
let smallest: number[] = [], count = 0, unlocated = 0;
|
|
86
|
+
tally.smallest[0] = smallest;
|
|
87
|
+
units.forEach((block, i) => {
|
|
88
|
+
if (isOmittable(block, mandatory)) {
|
|
89
|
+
count++;
|
|
90
|
+
const source = block.sourceIndex;
|
|
91
|
+
if (source === undefined) unlocated = 1;
|
|
92
|
+
else if (!smallest.includes(source) && (smallest.length < 9 || source < smallest[8]!)) {
|
|
93
|
+
smallest = [...smallest, source].sort((a, b) => a - b).slice(0, 9);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
tally!.counts[i + 1] = count; tally!.unlocated[i + 1] = unlocated; tally!.smallest[i + 1] = smallest;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
let count = tally.counts[drop]!, unlocated = tally.unlocated[drop] === 1, sources = tally.smallest[drop]!;
|
|
100
|
+
if (end > drop && tier > 0) {
|
|
101
|
+
level(tier);
|
|
102
|
+
const empty = emptied[tier]!, counts = emptyCounts[tier]!;
|
|
103
|
+
count += counts[end]! - counts[drop]!;
|
|
104
|
+
if (counts[end]! > counts[drop]!) {
|
|
105
|
+
// Text blocks of one message share a locator: collect distinct ones, enough to tell whether the shown list is complete.
|
|
106
|
+
const extra = new Set<number>();
|
|
107
|
+
for (let i = drop; i < end && (extra.size < 9 || !unlocated); i++) if (empty[i]) {
|
|
108
|
+
const source = units[i]!.sourceIndex;
|
|
109
|
+
if (source === undefined) unlocated = true; else if (extra.size < 9) extra.add(source);
|
|
110
|
+
}
|
|
111
|
+
sources = [...new Set([...sources, ...extra])].sort((a, b) => a - b).slice(0, 9);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return count ? decorate(omissionRecord(role, count, sources, unlocated)) : undefined;
|
|
115
|
+
};
|
|
116
|
+
const omissionCosts = new Map<string, number>();
|
|
117
|
+
const omissionCost = (setting: Setting) => {
|
|
118
|
+
const key = `${setting.drop}:${setting.tier}:${setting.end}`;
|
|
119
|
+
let cost = omissionCosts.get(key);
|
|
120
|
+
if (cost === undefined) { const record = omission(setting); omissionCosts.set(key, cost = record ? rendered([record]).cost : 0); }
|
|
121
|
+
return cost;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
n, level, sum, omission,
|
|
126
|
+
cost: ({ drop, tier, end }: Setting) => sums[0]![n]! - sums[0]![Math.max(drop, end)]! + (end > drop ? sum(tier)[end]! - sum(tier)[drop]! : 0) + omissionCost({ drop, tier, end }),
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** The units of a dialogue and what any configuration of them renders, by arithmetic over per-unit lengths or as the summary text. */
|
|
131
|
+
const createDialogue = (input: DialogueInput) => {
|
|
132
|
+
const dialogue = input.blocks.filter(isDialogue);
|
|
133
|
+
const times = dialogue.find(block => block.sourceTimes)?.sourceTimes;
|
|
134
|
+
const decorate = (record: TranscriptRecord) => decorateRecord(record, times);
|
|
135
|
+
const lanes = Object.fromEntries(ROLES.map(role => [role, createLane(role, dialogue.filter(block => block.kind === role), input.mandatorySourceIndices, decorate)])) as
|
|
136
|
+
Record<Role, ReturnType<typeof createLane>>;
|
|
137
|
+
const seen: Record<Role, number> = { user: 0, assistant: 0, notice: 0 };
|
|
138
|
+
const order = dialogue.map(block => ({ role: block.kind, i: seen[block.kind]++ }));
|
|
139
|
+
const tools = input.blocks.length > dialogue.length ? rendered([TOOLS_OMITTED]) : undefined;
|
|
140
|
+
const overhead = TRANSCRIPT_HEADER.length + DIALOGUE_SUFFIX.length;
|
|
141
|
+
|
|
142
|
+
/** The length of the summary text of a configuration: its header, one line per record, and the closing section; 0 when it has no record. */
|
|
143
|
+
const size = (config: Config): number => {
|
|
144
|
+
const cost = ROLES.reduce((n, role) => n + lanes[role].cost(config[role]), tools?.cost ?? 0);
|
|
145
|
+
return cost === 0 ? 0 : overhead + cost;
|
|
146
|
+
};
|
|
147
|
+
const text = (config: Config): string => {
|
|
148
|
+
const records: TranscriptRecord[] = [];
|
|
149
|
+
for (const { role, i } of order) {
|
|
150
|
+
const { drop, tier, end } = config[role];
|
|
151
|
+
if (i >= drop) records.push(...lanes[role].level(i < end ? tier : 0)[i]!.records);
|
|
152
|
+
}
|
|
153
|
+
for (const role of ROLES) { const record = lanes[role].omission(config[role]); if (record) records.push(record); }
|
|
154
|
+
if (tools) records.push(...tools.records);
|
|
155
|
+
orderByOriginalSource(records, input.sourceIndices, input.sourceEntryIds);
|
|
156
|
+
return records.length ? serializeTranscript(records) + DIALOGUE_SUFFIX : "";
|
|
157
|
+
};
|
|
158
|
+
return { lanes, size, text };
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** The whole pre-cut dialogue: user, assistant and notice records; tool actions and observations are omitted. "" when it renders nothing. */
|
|
162
|
+
export const wholeDialogue = (input: DialogueInput): string => {
|
|
163
|
+
const { text } = createDialogue(input);
|
|
164
|
+
return text({ user: WHOLE, assistant: WHOLE, notice: WHOLE });
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The same dialogue shrunk until its summary text is at most `limit` characters, oldest first. The first configuration that fits wins:
|
|
169
|
+
* A. the newest k assistant units whole, the older ones clipped to tier 1, 2, 3 (the largest k that fits, for each tier in turn);
|
|
170
|
+
* B. the newest assistant units that fit a third of the limit whole, the older ones at tier 3 with the oldest d dropped;
|
|
171
|
+
* C. the newest assistant units that fit a third of the limit at tier 3, the rest dropped; then the oldest u user units clipped to tier 1, 2, 3;
|
|
172
|
+
* D. every user unit at tier 3, the oldest dropped;
|
|
173
|
+
* E. the oldest notices dropped, then the oldest of the remaining assistant units.
|
|
174
|
+
* Every step is a one-parameter family whose size is read from prefix sums of the per-unit lengths, so a step costs O(units). A notice is clipped
|
|
175
|
+
* to its one tier in every configuration but the whole dialogue. The size is arithmetic over unit lengths; the rendered text has the last say:
|
|
176
|
+
* a configuration whose text is over the limit is passed over.
|
|
177
|
+
*/
|
|
178
|
+
export const shrinkDialogue = (input: DialogueInput, limit: number): Shrunk => {
|
|
179
|
+
const { lanes, size, text } = createDialogue(input);
|
|
180
|
+
const { user, assistant, notice } = lanes;
|
|
181
|
+
const clipped: Setting = { drop: 0, tier: 1, end: notice.n };
|
|
182
|
+
const found = (step: Step, config: Config): Shrunk | undefined => {
|
|
183
|
+
const length = size(config);
|
|
184
|
+
if (length > limit) return undefined;
|
|
185
|
+
const summary = text(config);
|
|
186
|
+
return summary.length <= limit ? { text: summary, step, size: length } : undefined;
|
|
187
|
+
};
|
|
188
|
+
const gone = (lane: { n: number }): Setting => ({ drop: lane.n, tier: 3, end: lane.n });
|
|
189
|
+
const tiers = [1, 2, 3] as const;
|
|
190
|
+
|
|
191
|
+
let hit = found("whole", { user: WHOLE, assistant: WHOLE, notice: WHOLE });
|
|
192
|
+
if (hit) return hit;
|
|
193
|
+
for (const t of tiers) for (let k = assistant.n; k >= 0; k--)
|
|
194
|
+
if (hit = found(`A${t}`, { user: WHOLE, assistant: { drop: 0, tier: t, end: assistant.n - k }, notice: clipped })) return hit;
|
|
195
|
+
// The newest assistant units that fit a third of the limit whole are kept until users have given way: B clips and drops only older ones.
|
|
196
|
+
// A clip can keep no text at all, so the third is sized on whole units; when the newest alone is over the third, it keeps its largest clip
|
|
197
|
+
// that fits and still has text.
|
|
198
|
+
let kept = 0;
|
|
199
|
+
while (kept < assistant.n && assistant.sum(0)[assistant.n]! - assistant.sum(0)[kept]! > limit / 3) kept++;
|
|
200
|
+
let recent: Setting = { drop: kept, tier: 3, end: kept };
|
|
201
|
+
if (kept === assistant.n && assistant.n > 0) for (const t of tiers) {
|
|
202
|
+
const cost = assistant.level(t)[assistant.n - 1]!.cost;
|
|
203
|
+
if (cost > 0 && cost <= limit / 3) { recent = { drop: assistant.n - 1, tier: t, end: assistant.n }; break; }
|
|
204
|
+
}
|
|
205
|
+
for (let d = 0; d <= recent.drop; d++)
|
|
206
|
+
if (hit = found("B", { user: WHOLE, assistant: { ...recent, drop: d }, notice: clipped })) return hit;
|
|
207
|
+
// From here users give way, and the assistant keeps only that recent third.
|
|
208
|
+
for (const t of tiers) for (let u = 0; u <= user.n; u++)
|
|
209
|
+
if (hit = found(`C${t}`, { user: { drop: 0, tier: t, end: u }, assistant: recent, notice: clipped })) return hit;
|
|
210
|
+
for (let d = 0; d <= user.n; d++)
|
|
211
|
+
if (hit = found("D", { user: { drop: d, tier: 3, end: user.n }, assistant: recent, notice: clipped })) return hit;
|
|
212
|
+
for (let d = 0; d <= notice.n; d++)
|
|
213
|
+
if (hit = found("E1", { user: gone(user), assistant: recent, notice: { drop: d, tier: 1, end: notice.n } })) return hit;
|
|
214
|
+
for (let d = recent.drop; d <= assistant.n; d++)
|
|
215
|
+
if (hit = found("E2", { user: gone(user), assistant: { ...recent, drop: d }, notice: gone(notice) })) return hit;
|
|
216
|
+
return { text: "", step: "none", size: 0 };
|
|
217
|
+
};
|
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
import { orderByOriginalSource } from "./source-order";
|
|
2
1
|
import type { CompilerMessage } from "../types";
|
|
3
2
|
import { normalize } from "./normalize";
|
|
4
3
|
import { filterNoise } from "./filter-noise";
|
|
5
|
-
import {
|
|
6
|
-
import { DIALOGUE_SUFFIX, RANKED_SUFFIX } from "./format";
|
|
7
|
-
import { parseRecords, serializeTranscript } from "./transcript";
|
|
8
|
-
import { selectRankedBriefBlocks, type BriefRankingOptions } from "./rank";
|
|
4
|
+
import { shrinkDialogue, wholeDialogue, type DialogueInput } from "./shrink";
|
|
9
5
|
|
|
10
|
-
export interface
|
|
6
|
+
export interface CompileInput {
|
|
11
7
|
messages: CompilerMessage[];
|
|
12
|
-
/** Eligible original branch only
|
|
8
|
+
/** Eligible original branch only: receipt identity and order. */
|
|
13
9
|
receiptContext?: { messages: CompilerMessage[]; sourceIndices: Array<number | undefined> };
|
|
14
10
|
/** Native session-global source indices parallel to messages. */
|
|
15
11
|
sourceIndices?: Array<number | undefined>;
|
|
16
12
|
/** Actual native entry IDs parallel to originals, not inferred from text. */
|
|
17
13
|
sourceEntryIds?: readonly string[];
|
|
18
14
|
sourceTimes?: readonly import("./source-time").SourceTime[];
|
|
19
|
-
ranking?:
|
|
15
|
+
ranking?: {
|
|
16
|
+
/** The complete serialized length a summary of the dialogue may have, header and closing section included. */
|
|
17
|
+
maxBriefChars?: number;
|
|
18
|
+
/** Full sources rendered separately by the caller: they render as nothing here. */
|
|
19
|
+
mandatorySourceIndices?: ReadonlySet<number>;
|
|
20
|
+
};
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
// A cut offers the whole dialogue and then, when it does not fit, the shrunk one, from the same input: normalize it once. The blocks are
|
|
24
|
+
// never mutated, and keeping the same objects also keeps their cached passage analyses.
|
|
25
|
+
const inputs = new WeakMap<CompileInput, DialogueInput>();
|
|
26
|
+
const dialogueInput = (input: CompileInput): DialogueInput => {
|
|
27
|
+
let prepared = inputs.get(input);
|
|
28
|
+
if (!prepared) inputs.set(input, prepared = {
|
|
29
|
+
blocks: filterNoise(normalize(input.messages, input.sourceIndices, input.receiptContext, input.sourceEntryIds, input.sourceTimes)),
|
|
30
|
+
mandatorySourceIndices: input.ranking?.mandatorySourceIndices,
|
|
31
|
+
sourceIndices: input.sourceIndices ?? input.messages.map((_, index) => index),
|
|
32
|
+
sourceEntryIds: input.sourceEntryIds,
|
|
33
|
+
});
|
|
34
|
+
return prepared;
|
|
28
35
|
};
|
|
29
36
|
|
|
30
37
|
/** The whole pre-cut dialogue: user, assistant and notice records; tool actions and observations are omitted.
|
|
31
38
|
* This disposable view grants neither present authority nor native tool execution. */
|
|
32
|
-
export const compileDialogue = (input:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (blocks.length < originals.length) records.push({ kind: "omission",
|
|
38
|
-
reason: "Historical tool actions and observations omitted; read original sources with tuck_recall" });
|
|
39
|
-
orderByOriginalSource(records, input.sourceIndices ?? input.messages.map((_, index) => index), input.sourceEntryIds);
|
|
40
|
-
return records.length ? serializeTranscript(records) + DIALOGUE_SUFFIX : "";
|
|
41
|
-
};
|
|
39
|
+
export const compileDialogue = (input: CompileInput): string => wholeDialogue(dialogueInput(input));
|
|
40
|
+
|
|
41
|
+
/** The dialogue shrunk to `ranking.maxBriefChars`, oldest assistant text first (see `shrinkDialogue`); "" when nothing fits. */
|
|
42
|
+
export const compileShrunkDialogue = (input: CompileInput & { ranking: { maxBriefChars: number } }): string =>
|
|
43
|
+
shrinkDialogue(dialogueInput(input), input.ranking.maxBriefChars).text;
|