@vincemakes/kiso-runtime 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +6 -0
- package/dist/session.d.ts +26 -0
- package/dist/session.js +37 -0
- package/package.json +5 -5
package/dist/agent.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ export interface AgentDefinition {
|
|
|
42
42
|
readonly maxTurns?: number;
|
|
43
43
|
readonly maxTokens?: number;
|
|
44
44
|
readonly temperature?: number;
|
|
45
|
+
/**
|
|
46
|
+
* DEPRECATED (ADR-0044): the classic auto-compaction path is retired —
|
|
47
|
+
* the loop ignores this (microcompact absorbed the responsibility; old
|
|
48
|
+
* sessions' `compacted` events still replay). Kept so old definitions
|
|
49
|
+
* type-check; removed at 1.0.
|
|
50
|
+
*/
|
|
45
51
|
readonly compaction?: {
|
|
46
52
|
readonly thresholdTokens: number;
|
|
47
53
|
};
|
package/dist/session.d.ts
CHANGED
|
@@ -49,6 +49,13 @@ export interface ApprovalRequest {
|
|
|
49
49
|
readonly name: string;
|
|
50
50
|
readonly input: Readonly<Record<string, unknown>>;
|
|
51
51
|
}
|
|
52
|
+
/** The /compact result — what the NoticeCell shows (ADR-0044). */
|
|
53
|
+
export interface SummarizeResult {
|
|
54
|
+
readonly coversToSeq: number;
|
|
55
|
+
readonly summary: string;
|
|
56
|
+
/** The estimated tokens the compression saved (chars/4 proxy). */
|
|
57
|
+
readonly savedTokens: number;
|
|
58
|
+
}
|
|
52
59
|
export declare class AgentSession {
|
|
53
60
|
#private;
|
|
54
61
|
readonly id: string;
|
|
@@ -78,6 +85,21 @@ export declare class AgentSession {
|
|
|
78
85
|
* Yields nothing when the session already completed.
|
|
79
86
|
*/
|
|
80
87
|
resume(): Run;
|
|
88
|
+
/**
|
|
89
|
+
* /compact (ADR-0044): compress the older conversation with a model
|
|
90
|
+
* summary. Covers the range (previous summary point, boundary] —
|
|
91
|
+
* boundary = the event before the keepRounds-th most recent round —
|
|
92
|
+
* and persists ONE `summarized` event. The summary call is OFF-LOOP
|
|
93
|
+
* through the session's OWN adapter: it writes nothing; a failure
|
|
94
|
+
* throws and the session is unchanged ("nothing happened"). Returns
|
|
95
|
+
* null when fewer than keepRounds+1 uncovered rounds exist (nothing
|
|
96
|
+
* worth covering yet). Crash semantics: a crash BEFORE the persist is
|
|
97
|
+
* "nothing happened"; after it, a resume projects the compressed view.
|
|
98
|
+
*/
|
|
99
|
+
summarize(options?: {
|
|
100
|
+
keepRounds?: number;
|
|
101
|
+
signal?: AbortSignalLike;
|
|
102
|
+
}): Promise<SummarizeResult | null>;
|
|
81
103
|
/**
|
|
82
104
|
* Pauses that still await a human decision (durable, survives restart).
|
|
83
105
|
* B 组: a request whose RUN has terminated is DEAD — it is neither
|
|
@@ -136,6 +158,10 @@ export interface SessionConfig {
|
|
|
136
158
|
readonly maxTurns?: number;
|
|
137
159
|
readonly maxTokens?: number;
|
|
138
160
|
readonly temperature?: number;
|
|
161
|
+
/**
|
|
162
|
+
* DEPRECATED (ADR-0044): forwarded to the loop's deprecated field,
|
|
163
|
+
* which IGNORES it — kept for type compatibility, removed at 1.0.
|
|
164
|
+
*/
|
|
139
165
|
readonly compaction?: {
|
|
140
166
|
readonly thresholdTokens: number;
|
|
141
167
|
};
|
package/dist/session.js
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import { EventLog, executionLedger, loop, projectMessages, } from "@vincemakes/kiso-core";
|
|
27
27
|
import { denialResult } from "@vincemakes/kiso-core";
|
|
28
|
+
import { estimateSummarySavings, KEEP_RECENT_ROUNDS, lastSummaryPoint, summarizeConversation, summaryBoundarySeq, } from "@vincemakes/kiso-core";
|
|
28
29
|
import { StaleWriterError } from "./store.js";
|
|
29
30
|
/** A session whose disk write was rejected (stale handle) is PERMANENTLY
|
|
30
31
|
* poisoned: its in-memory log no longer matches the disk, so no further
|
|
@@ -148,6 +149,42 @@ export class AgentSession {
|
|
|
148
149
|
this.ensureHealthy();
|
|
149
150
|
return new Run(this.#store, this.#adapter, this.#config, this, undefined, undefined, true);
|
|
150
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* /compact (ADR-0044): compress the older conversation with a model
|
|
154
|
+
* summary. Covers the range (previous summary point, boundary] —
|
|
155
|
+
* boundary = the event before the keepRounds-th most recent round —
|
|
156
|
+
* and persists ONE `summarized` event. The summary call is OFF-LOOP
|
|
157
|
+
* through the session's OWN adapter: it writes nothing; a failure
|
|
158
|
+
* throws and the session is unchanged ("nothing happened"). Returns
|
|
159
|
+
* null when fewer than keepRounds+1 uncovered rounds exist (nothing
|
|
160
|
+
* worth covering yet). Crash semantics: a crash BEFORE the persist is
|
|
161
|
+
* "nothing happened"; after it, a resume projects the compressed view.
|
|
162
|
+
*/
|
|
163
|
+
async summarize(options = {}) {
|
|
164
|
+
this.ensureHealthy();
|
|
165
|
+
const keepRounds = options.keepRounds ?? KEEP_RECENT_ROUNDS;
|
|
166
|
+
const events = this.log.all;
|
|
167
|
+
const boundary = summaryBoundarySeq(events, keepRounds);
|
|
168
|
+
if (boundary === undefined)
|
|
169
|
+
return null;
|
|
170
|
+
const prevPoint = lastSummaryPoint(events);
|
|
171
|
+
const covered = projectMessages(events.filter((e) => e.seq > prevPoint && e.seq <= boundary && e.type !== "summarized"));
|
|
172
|
+
const summary = await summarizeConversation({
|
|
173
|
+
adapter: this.#adapter,
|
|
174
|
+
model: this.#config.model,
|
|
175
|
+
messages: covered,
|
|
176
|
+
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
177
|
+
});
|
|
178
|
+
const full = this.log.append({ type: "summarized", coversToSeq: boundary, summary });
|
|
179
|
+
// The record rides the LAST recorded run's id — a summarized fact
|
|
180
|
+
// must never open a run of its own: the open-run gate keys on
|
|
181
|
+
// terminal-less runIds, and a "compact" runId would block the next
|
|
182
|
+
// run() ("still has an open run").
|
|
183
|
+
const records = this.#store.load(this.id);
|
|
184
|
+
const runId = records.length > 0 ? records[records.length - 1].runId : "compact";
|
|
185
|
+
await this.persist(runId, full);
|
|
186
|
+
return { coversToSeq: boundary, summary, savedTokens: estimateSummarySavings(covered, summary) };
|
|
187
|
+
}
|
|
151
188
|
// ── Phase D: approvals ───────────────────────────────────────────────
|
|
152
189
|
/**
|
|
153
190
|
* Pauses that still await a human decision (durable, survives restart).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vincemakes/kiso-runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "kiso runtime — durable multi-turn agent sessions: AgentDefinition, AgentRuntime, AgentSession, Run, append-only JSONL store.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"test": "vitest run"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@vincemakes/kiso-core": "0.1.
|
|
24
|
+
"@vincemakes/kiso-core": "0.1.20"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@vincemakes/kiso-provider-anthropic": "0.1.
|
|
28
|
-
"@vincemakes/kiso-provider-openai": "0.1.
|
|
27
|
+
"@vincemakes/kiso-provider-anthropic": "0.1.20",
|
|
28
|
+
"@vincemakes/kiso-provider-openai": "0.1.20"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
31
31
|
"@vincemakes/kiso-provider-anthropic": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@vincemakes/kiso-evals": "0.1.
|
|
39
|
+
"@vincemakes/kiso-evals": "0.1.20",
|
|
40
40
|
"@types/node": "^26.1.2",
|
|
41
41
|
"typescript": "^5.7.2",
|
|
42
42
|
"vitest": "^3.0.0"
|