@stratusagent/gateway 0.14.1 → 0.14.3

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.
@@ -0,0 +1,137 @@
1
+ import { type AgentMemoryStore, type MemoryAuditEntry, type MemoryEntry, type MemoryPassHandle, type Message, type Session, type StratusEvent, type Tool, type TrustLevel } from '@stratusagent/core';
2
+ import { type MemoryPassSlice, type MemoryPassSummary, type MemoryShadowEntry } from '@stratusagent/state';
3
+ /** What the host hands a pass's one model run. */
4
+ export interface MemoryPassModelRun {
5
+ agentId: string;
6
+ passId: string;
7
+ /** The pass's own session, never stored: `memoryPassSessionId(passId)`. */
8
+ sessionId: string;
9
+ /** Exactly this model, with no fallback. */
10
+ model: string | undefined;
11
+ /** The one message: the request, the conversation, the instruction. */
12
+ prompt: string;
13
+ /** The label the pass session starts at: the slice's. */
14
+ trust: TrustLevel;
15
+ /** Only these: the pass's recall and remember. */
16
+ tools: Tool[];
17
+ signal: AbortSignal;
18
+ }
19
+ /** What the memory pass host needs from the gateway. */
20
+ export interface MemoryPassHostOptions {
21
+ stateDir: string;
22
+ /** The home, so the ledger and shadow files are owner-only. */
23
+ stateHome?: string;
24
+ /** This daemon run's id, written on every ledger record. */
25
+ run: string;
26
+ memory: AgentMemoryStore | undefined;
27
+ /**
28
+ * Whether the selected store takes a list in `supersedes`, so a pass may
29
+ * merge several facts into one. Asked per pass: the store is chosen once
30
+ * the plugins have loaded. Default: no.
31
+ */
32
+ supersedesMany?: () => boolean;
33
+ sessions: {
34
+ get(id: string): Promise<Session | undefined>;
35
+ };
36
+ /**
37
+ * The session's single-flight chain: whether it is idle now, and a way
38
+ * to queue one step on it. The idle check and the queueing happen in
39
+ * the same tick, so nothing gets between them.
40
+ */
41
+ chain: {
42
+ idle(sessionId: string): boolean;
43
+ queue<T>(sessionId: string, work: () => Promise<T>): Promise<T>;
44
+ };
45
+ hasAgent(agentId: string): boolean;
46
+ isSubAgentSession(session: Session): boolean;
47
+ /** The model the agent runs on, for a request that names none. */
48
+ defaultModel(agentId: string): Promise<string | undefined>;
49
+ /** Runs the pass's model turn; rejects when it fails. */
50
+ runModel(run: MemoryPassModelRun): Promise<void>;
51
+ emit(event: StratusEvent): void;
52
+ log(line: string): void;
53
+ now?: () => Date;
54
+ passId?: () => string;
55
+ }
56
+ /** One pass and the facts it wrote, or in shadow would have, oldest first. */
57
+ export interface MemoryPassDetail {
58
+ pass: MemoryPassSummary;
59
+ /** Write mode: from the agent's memory, forgotten ones included. Shadow: from `memory-shadow.jsonl`. */
60
+ entries: Array<MemoryAuditEntry | MemoryShadowEntry>;
61
+ }
62
+ export interface MemoryPassHost {
63
+ handle: MemoryPassHandle;
64
+ /** The agent's passes from its ledger, newest first. No ledger reads as none. */
65
+ passes(agentId: string): Promise<MemoryPassSummary[]>;
66
+ /** One pass and what it wrote; undefined when the ledger has no claim for it. */
67
+ pass(agentId: string, passId: string): Promise<MemoryPassDetail | undefined>;
68
+ /**
69
+ * The daemon has loaded its agents and chosen its memory store. Plugins
70
+ * are set up before either, and the spec has the upkeep plugin call
71
+ * `start` from its setup, so until this a start takes any well-formed
72
+ * agent id, writes its start record, and leaves the claims a crash left
73
+ * open to be settled here: settling reads what a claim wrote, from the
74
+ * store this daemon uses, which is not chosen until now. A save pass asked
75
+ * for before this is skipped as `not-started`. Resolves once those
76
+ * settles are written; never rejects.
77
+ */
78
+ ready(): Promise<void>;
79
+ /**
80
+ * The daemon is stopping: refuse new passes, abort running ones (they are
81
+ * low priority and do not hold the drain), settle them, then write a stop
82
+ * record for every agent and mode started in this run.
83
+ */
84
+ close(): Promise<void>;
85
+ }
86
+ export interface SaveSlice {
87
+ /** The rendered entries, oldest first. */
88
+ entries: string[];
89
+ slice: MemoryPassSlice;
90
+ /** Counted messages wait past this slice. */
91
+ more: boolean;
92
+ }
93
+ /**
94
+ * The messages a save pass reads next (spec 962): after the watermark,
95
+ * written while upkeep was on, oldest first, up to about
96
+ * `MEMORY_PASS_SLICE_MAX_BYTES`. A message alone over the cap goes in a
97
+ * slice of its own, cut to fit, and the slice says how much was left out,
98
+ * so the watermark always moves. Undefined when nothing is new.
99
+ */
100
+ export declare const takeSaveSlice: (messages: readonly Message[], watermark: string | undefined, counts: (createdAt: string) => boolean, maxBytes?: number) => SaveSlice | undefined;
101
+ /** The save pass's one message: the request, the conversation in tags, the instruction after it. */
102
+ export declare const saveSlicePrompt: (entries: readonly string[]) => string;
103
+ export interface TidyChunk {
104
+ /** `kind/label/about`, the about key folded: what the ledger names the group by. */
105
+ key: string;
106
+ /** The group's label: the pass starts at it, recalls only it, and writes it. */
107
+ trust: TrustLevel;
108
+ /** The facts handed over, oldest first. */
109
+ members: MemoryEntry[];
110
+ /** One JSON object a line, for the `<facts>` tags. */
111
+ lines: string[];
112
+ /** SHA-256 of the sorted member ids: what a later pass of the mode skips. */
113
+ hash: string;
114
+ /** Another chunk, of this group or another, waits after this one. */
115
+ more: boolean;
116
+ }
117
+ /**
118
+ * The chunk a tidy pass is handed next (spec 962). A group is at least
119
+ * `MEMORY_TIDY_GROUP_MIN` live facts sharing an about key, a kind and a
120
+ * label, leaving out episodic facts (#961 retires those), pinned ones and
121
+ * operator-asserted ones (no pass may supersede either). A fact with two
122
+ * about keys counts in both groups. The largest group goes first; a group
123
+ * over `MEMORY_TIDY_CHUNK_MAX_BYTES` goes in chunks, oldest facts first.
124
+ * A chunk whose member ids a pass of this mode already looked at
125
+ * (`claimed`) is passed over for the next, so a chunk that merges nothing
126
+ * still moves the tidy on, while a merge changes the members and so the
127
+ * chunks. Undefined when no chunk is left.
128
+ */
129
+ export declare const takeTidyChunk: (live: readonly MemoryEntry[], pinned: ReadonlySet<string>, claimed: ReadonlySet<string>, maxBytes?: number) => TidyChunk | undefined;
130
+ /** The tidy pass's one message: the request, the facts in tags, the instruction after them. */
131
+ export declare const tidyChunkPrompt: (lines: readonly string[]) => string;
132
+ /**
133
+ * The gateway's `PluginContext.memoryPasses` (spec 962). A plugin decides
134
+ * when to ask; everything a pass may read and write is decided here.
135
+ */
136
+ export declare const createMemoryPassHost: (options: MemoryPassHostOptions) => MemoryPassHost;
137
+ //# sourceMappingURL=memory-passes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-passes.d.ts","sourceRoot":"","sources":["../src/memory-passes.ts"],"names":[],"mappings":"AAGA,OAAO,EAmBL,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EAMrB,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAiBL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAEvB,MAAM,qBAAqB,CAAC;AAE7B,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,KAAK,EAAE,UAAU,CAAC;IAClB,kDAAkD;IAClD,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,wDAAwD;AACxD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACrC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC;IAC/B,QAAQ,EAAE;QAAE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAA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