operon-agents-core 0.1.0-alpha.31 → 0.1.0-alpha.32
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/events/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type { WorkflowRecordProjection } from "./publisher.ts";
|
|
|
5
5
|
export type { EventPublicationMode } from "./publisher.ts";
|
|
6
6
|
export { RedactingSink } from "./redacting-sink.ts";
|
|
7
7
|
export { SessionProjection, readSessionTails } from "./projection.ts";
|
|
8
|
+
export { readTranscriptPage } from "./transcript.ts";
|
|
9
|
+
export type { TranscriptCompactionItem, TranscriptItem, TranscriptMessageItem, TranscriptPage, TranscriptPageOptions, } from "./transcript.ts";
|
|
8
10
|
export type { WorkflowProgressEvent, WorkflowAgentRecord } from "./events.ts";
|
|
9
11
|
export type { AgentSnapshot, WorkflowRunSnapshot, DirectoryEntry, ProjectedPendingSteer, ProjectedToolCall, ProjectedTurn, ProjectionObservation, ProjectionListener, ProjectionSource, SessionSnapshot, SnapshotOptions, FrameCheckpoint, SessionProjectionOptions, } from "./projection.ts";
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/events/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { ListenerSink, NullSink, IterableSink, joinAddress, newAgentEventId, nor
|
|
|
2
2
|
export { SessionEventPublisher, agentEventFromRecord, isDurableAgentEvent, workflowProgressFromRecord } from "./publisher.js";
|
|
3
3
|
export { RedactingSink } from "./redacting-sink.js";
|
|
4
4
|
export { SessionProjection, readSessionTails } from "./projection.js";
|
|
5
|
+
export { readTranscriptPage } from "./transcript.js";
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Message } from "../protocol/index.ts";
|
|
2
|
+
import type { PromptOrigin } from "../store/origin.ts";
|
|
3
|
+
import { type SessionStore } from "../store/store.ts";
|
|
4
|
+
/**
|
|
5
|
+
* A session's transcript, read straight from its log — no `Session`, no capabilities, no run.
|
|
6
|
+
*
|
|
7
|
+
* WHAT HAPPENED, not what the model currently sees. The log is append-only, so a message the
|
|
8
|
+
* compaction later summarized away is still there, in its own record; a transcript reader wants
|
|
9
|
+
* exactly that. The model's current context (checkpoint + tail) is `SessionProjection`'s job.
|
|
10
|
+
*
|
|
11
|
+
* So only ORIGINALS are read: `context.append_message` and `custom_message`. The checkpoint
|
|
12
|
+
* records repeat messages that already have their own record — `context.apply_compaction.kept`
|
|
13
|
+
* and the trimmed history a `context.replace` commits — so taking them as well would show the same
|
|
14
|
+
* message twice. A compaction surfaces as a marker item instead, where it happened.
|
|
15
|
+
*
|
|
16
|
+
* Pages run backwards from the newest record (a viewer opens on the latest messages and scrolls
|
|
17
|
+
* up); the items of one page come back oldest first, ready to prepend. Cursors are the store's
|
|
18
|
+
* record sequences, and the log is immutable below the newest record, so paging is race-free
|
|
19
|
+
* however long the reader takes between pages.
|
|
20
|
+
*/
|
|
21
|
+
export interface TranscriptPageOptions {
|
|
22
|
+
/** The conversation shard to read. Default `main`, the root agent; a subagent's transcript is
|
|
23
|
+
* read by its own address. */
|
|
24
|
+
readonly address?: string;
|
|
25
|
+
/** Items per page. Default 50, at most 500. */
|
|
26
|
+
readonly limit?: number;
|
|
27
|
+
/** Return items OLDER than this cursor: the previous page's `next`. Omit for the newest page. */
|
|
28
|
+
readonly before?: string;
|
|
29
|
+
}
|
|
30
|
+
interface TranscriptItemBase {
|
|
31
|
+
/** This item's record sequence — what a `before` names to read on from just above it. */
|
|
32
|
+
readonly cursor: string;
|
|
33
|
+
/** The durable event id, matching the live `message.appended` / `history.compacted` event. Absent
|
|
34
|
+
* on records written outside a session's event publisher. */
|
|
35
|
+
readonly eventId?: string;
|
|
36
|
+
readonly time?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface TranscriptMessageItem extends TranscriptItemBase {
|
|
39
|
+
readonly kind: "message";
|
|
40
|
+
readonly message: Message;
|
|
41
|
+
readonly origin?: PromptOrigin;
|
|
42
|
+
/** A host-injected message (`custom_message`) that asked not to be displayed. It is in the
|
|
43
|
+
* model's context all the same; a viewer normally skips it. */
|
|
44
|
+
readonly hidden?: true;
|
|
45
|
+
}
|
|
46
|
+
export interface TranscriptCompactionItem extends TranscriptItemBase {
|
|
47
|
+
readonly kind: "compaction";
|
|
48
|
+
/** What the summarized messages were replaced with in the model's context. */
|
|
49
|
+
readonly summary: string;
|
|
50
|
+
/** How many leading messages of the context at that point the summary replaced. */
|
|
51
|
+
readonly compactedCount: number;
|
|
52
|
+
}
|
|
53
|
+
export type TranscriptItem = TranscriptMessageItem | TranscriptCompactionItem;
|
|
54
|
+
export interface TranscriptPage {
|
|
55
|
+
/** Oldest first. */
|
|
56
|
+
readonly items: readonly TranscriptItem[];
|
|
57
|
+
/** Cursor for the next OLDER page — present only when at least one older item exists, so it
|
|
58
|
+
* never leads to an empty page. Absent once the start of the transcript is reached. */
|
|
59
|
+
readonly next?: string;
|
|
60
|
+
}
|
|
61
|
+
/** One page of a session's transcript, read from its store. See the module doc for what counts. */
|
|
62
|
+
export declare function readTranscriptPage(store: SessionStore, options?: TranscriptPageOptions): Promise<TranscriptPage>;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { customMessage, DEFAULT_ADDRESS } from "../store/store.js";
|
|
2
|
+
const DEFAULT_LIMIT = 50;
|
|
3
|
+
const MAX_LIMIT = 500;
|
|
4
|
+
/** Records read per store page. Most records are not transcript items (lifecycle, usage), so
|
|
5
|
+
* scanning in larger strides than the item limit saves round trips. */
|
|
6
|
+
const SCAN_PAGE = 128;
|
|
7
|
+
function itemOf(stored) {
|
|
8
|
+
const { record, sequence } = stored;
|
|
9
|
+
const base = {
|
|
10
|
+
cursor: sequence,
|
|
11
|
+
...(record.eventId !== undefined ? { eventId: record.eventId } : {}),
|
|
12
|
+
...(record.time !== undefined ? { time: record.time } : {}),
|
|
13
|
+
};
|
|
14
|
+
switch (record.type) {
|
|
15
|
+
case "context.append_message":
|
|
16
|
+
return { ...base, kind: "message", message: record.message, ...(record.origin !== undefined ? { origin: record.origin } : {}) };
|
|
17
|
+
case "custom_message":
|
|
18
|
+
return {
|
|
19
|
+
...base,
|
|
20
|
+
kind: "message",
|
|
21
|
+
message: customMessage(record.content, record.time),
|
|
22
|
+
...(record.origin !== undefined ? { origin: record.origin } : {}),
|
|
23
|
+
...(record.display ? {} : { hidden: true }),
|
|
24
|
+
};
|
|
25
|
+
case "context.apply_compaction":
|
|
26
|
+
return { ...base, kind: "compaction", summary: record.summary, compactedCount: record.compactedCount };
|
|
27
|
+
default:
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function normalizeLimit(limit) {
|
|
32
|
+
if (limit === undefined)
|
|
33
|
+
return DEFAULT_LIMIT;
|
|
34
|
+
if (!Number.isSafeInteger(limit) || limit < 1)
|
|
35
|
+
throw new RangeError("transcript page limit must be a positive integer");
|
|
36
|
+
return Math.min(limit, MAX_LIMIT);
|
|
37
|
+
}
|
|
38
|
+
/** One page of a session's transcript, read from its store. See the module doc for what counts. */
|
|
39
|
+
export async function readTranscriptPage(store, options = {}) {
|
|
40
|
+
const limit = normalizeLimit(options.limit);
|
|
41
|
+
const address = options.address ?? DEFAULT_ADDRESS;
|
|
42
|
+
const newestFirst = [];
|
|
43
|
+
let after = options.before;
|
|
44
|
+
for (;;) {
|
|
45
|
+
const page = await store.readRecordPage({ address, order: "desc", limit: SCAN_PAGE, ...(after !== undefined ? { after } : {}) });
|
|
46
|
+
for (const stored of page.data) {
|
|
47
|
+
const item = itemOf(stored);
|
|
48
|
+
if (item === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
// One item past the limit is read and dropped: it is what proves an older page exists, so
|
|
51
|
+
// `next` never leads to an empty page.
|
|
52
|
+
if (newestFirst.length === limit) {
|
|
53
|
+
const oldest = newestFirst[newestFirst.length - 1];
|
|
54
|
+
return { items: newestFirst.reverse(), next: oldest.cursor };
|
|
55
|
+
}
|
|
56
|
+
newestFirst.push(item);
|
|
57
|
+
}
|
|
58
|
+
if (page.next === undefined)
|
|
59
|
+
return { items: newestFirst.reverse() };
|
|
60
|
+
after = page.next;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=transcript.js.map
|