@copilotkit/runtime 1.62.1 → 1.62.2-canary.1783457132
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/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/v2/index.cjs +5 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/runtime/core/fetch-handler.cjs +27 -0
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.mjs +27 -0
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.cjs +10 -0
- package/dist/v2/runtime/core/fetch-router.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.mjs +10 -0
- package/dist/v2/runtime/core/fetch-router.mjs.map +1 -1
- package/dist/v2/runtime/core/hooks.cjs.map +1 -1
- package/dist/v2/runtime/core/hooks.d.cts +7 -0
- package/dist/v2/runtime/core/hooks.d.cts.map +1 -1
- package/dist/v2/runtime/core/hooks.d.mts +7 -0
- package/dist/v2/runtime/core/hooks.d.mts.map +1 -1
- package/dist/v2/runtime/core/hooks.mjs.map +1 -1
- package/dist/v2/runtime/core/runtime.cjs +5 -0
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +21 -0
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +21 -0
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +5 -0
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +2 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +2 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/header-utils.cjs +169 -9
- package/dist/v2/runtime/handlers/header-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/header-utils.d.cts +54 -0
- package/dist/v2/runtime/handlers/header-utils.d.cts.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.d.mts +54 -0
- package/dist/v2/runtime/handlers/header-utils.d.mts.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.mjs +168 -9
- package/dist/v2/runtime/handlers/header-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/memories.cjs +209 -0
- package/dist/v2/runtime/handlers/intelligence/memories.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/memories.mjs +204 -0
- package/dist/v2/runtime/handlers/intelligence/memories.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +18 -5
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +18 -5
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs +2 -2
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs +3 -3
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/v2/runtime/index.d.cts +1 -1
- package/dist/v2/runtime/index.d.mts +1 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs +71 -2
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +112 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +112 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +71 -2
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.cjs +221 -37
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.cts +164 -3
- package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.mts +164 -3
- package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.mjs +218 -38
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
- package/dist/v2/runtime/runner/index.d.cts +1 -1
- package/dist/v2/runtime/runner/index.d.mts +1 -1
- package/dist/v2/runtime/runner/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,65 @@
|
|
|
1
1
|
|
|
2
2
|
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest } from "./agent-runner.cjs";
|
|
3
|
-
import { Observable } from "rxjs";
|
|
4
|
-
import { BaseEvent, Message } from "@ag-ui/client";
|
|
3
|
+
import { Observable, ReplaySubject } from "rxjs";
|
|
4
|
+
import { AbstractAgent, BaseEvent, Message } from "@ag-ui/client";
|
|
5
5
|
|
|
6
6
|
//#region src/v2/runtime/runner/in-memory.d.ts
|
|
7
|
+
interface InMemoryLimits {
|
|
8
|
+
/** LRU cap on distinct threads. */
|
|
9
|
+
maxThreads?: number;
|
|
10
|
+
/** FIFO cap on runs kept per thread. `Infinity` or `0` disables the cap. */
|
|
11
|
+
maxRunsPerThread?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Approximate byte ceiling on RETAINED thread/run history. Enforced at run
|
|
14
|
+
* completion (in `appendRun`), where LRU non-running threads are evicted to
|
|
15
|
+
* keep the total under this limit.
|
|
16
|
+
*
|
|
17
|
+
* Limitation: this bounds only history that has already been committed. A
|
|
18
|
+
* single in-flight run's buffered events (`currentRunEvents` and the two
|
|
19
|
+
* `ReplaySubject<BaseEvent>(Infinity)` buffers in `run()`) are NOT counted
|
|
20
|
+
* until that run completes, so `maxBytes` does not bound a single runaway
|
|
21
|
+
* run mid-stream.
|
|
22
|
+
*
|
|
23
|
+
* Limitation: byte eviction drops only other LRU non-running threads and
|
|
24
|
+
* never self-evicts the active/just-appended thread, so a single dominant
|
|
25
|
+
* thread's own retained history is not byte-trimmed (bounded only by
|
|
26
|
+
* `maxRunsPerThread`). `maxBytes` is thus a cross-thread ceiling enforced by
|
|
27
|
+
* evicting OTHER threads, not a per-thread cap.
|
|
28
|
+
*/
|
|
29
|
+
maxBytes?: number;
|
|
30
|
+
}
|
|
31
|
+
declare const ɵINMEMORY_DEFAULTS: Required<InMemoryLimits>;
|
|
32
|
+
/**
|
|
33
|
+
* Best-effort approximate byte size of a value, via serialized length.
|
|
34
|
+
* Never throws — returns 0 when the value cannot be serialized. This is an
|
|
35
|
+
* approximation (UTF-16 length, not exact heap bytes), used only for relative
|
|
36
|
+
* accounting against `maxBytes`.
|
|
37
|
+
*/
|
|
38
|
+
declare function ɵestimateBytes(value: unknown): number;
|
|
39
|
+
interface HistoricRun {
|
|
40
|
+
threadId: string;
|
|
41
|
+
runId: string;
|
|
42
|
+
/** ID of the agent that executed this run. */
|
|
43
|
+
agentId: string;
|
|
44
|
+
parentRunId: string | null;
|
|
45
|
+
events: BaseEvent[];
|
|
46
|
+
/**
|
|
47
|
+
* Snapshot of all messages (input + generated) at the end of this run, as
|
|
48
|
+
* passed in by the caller. NOTE: `BoundedThreadStore.appendRun` moves this
|
|
49
|
+
* snapshot to the THREAD level (`InMemoryEventStore.messagesSnapshot`) and
|
|
50
|
+
* clears this field to `[]`, so a stored HistoricRun never carries messages.
|
|
51
|
+
* The thread-messages fallback reads the thread-level snapshot, not this.
|
|
52
|
+
*/
|
|
53
|
+
messages: Message[];
|
|
54
|
+
createdAt: number;
|
|
55
|
+
/** Approximate retained byte size of `events`; set by BoundedThreadStore at append. */
|
|
56
|
+
approxEventBytes?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Legacy field retained for shape compatibility. `appendRun` always zeroes it
|
|
59
|
+
* because message bytes are accounted at the thread level, not per run.
|
|
60
|
+
*/
|
|
61
|
+
approxMessageBytes?: number;
|
|
62
|
+
}
|
|
7
63
|
/**
|
|
8
64
|
* Lightweight thread summary returned by {@link InMemoryAgentRunner.listThreads}.
|
|
9
65
|
* Shape matches the Intelligence platform's ThreadRecord so the same HTTP
|
|
@@ -19,8 +75,113 @@ interface InMemoryThread {
|
|
|
19
75
|
createdAt: string;
|
|
20
76
|
updatedAt: string;
|
|
21
77
|
}
|
|
78
|
+
declare class InMemoryEventStore {
|
|
79
|
+
threadId: string;
|
|
80
|
+
constructor(threadId: string);
|
|
81
|
+
/** The subject that current consumers subscribe to. */
|
|
82
|
+
subject: ReplaySubject<BaseEvent> | null;
|
|
83
|
+
/** True while a run is actively producing events. */
|
|
84
|
+
isRunning: boolean;
|
|
85
|
+
/** Current run ID */
|
|
86
|
+
currentRunId: string | null;
|
|
87
|
+
/** Historic completed runs */
|
|
88
|
+
historicRuns: HistoricRun[];
|
|
89
|
+
/** Currently running agent instance (if any). */
|
|
90
|
+
agent: AbstractAgent | null;
|
|
91
|
+
/** Subject returned from run() while the run is active. */
|
|
92
|
+
runSubject: ReplaySubject<BaseEvent> | null;
|
|
93
|
+
/** True once stop() has been requested but the run has not yet finalized. */
|
|
94
|
+
stopRequested: boolean;
|
|
95
|
+
/** Reference to the events emitted in the current run. */
|
|
96
|
+
currentEvents: BaseEvent[] | null;
|
|
97
|
+
/**
|
|
98
|
+
* The thread's single latest NON-EMPTY message snapshot, held at the THREAD
|
|
99
|
+
* level (independent of `historicRuns` lifecycle). Decoupling the snapshot
|
|
100
|
+
* from per-run storage means run-cap FIFO eviction and interleaved
|
|
101
|
+
* empty-snapshot runs can never drop or pin the thread's message history.
|
|
102
|
+
*/
|
|
103
|
+
messagesSnapshot: Message[];
|
|
104
|
+
/** Approximate retained byte size of `messagesSnapshot`. */
|
|
105
|
+
approxMessagesSnapshotBytes: number;
|
|
106
|
+
}
|
|
107
|
+
declare class ɵBoundedThreadStore {
|
|
108
|
+
private limits;
|
|
109
|
+
private readonly map;
|
|
110
|
+
private totalBytes;
|
|
111
|
+
private warned;
|
|
112
|
+
/** True once limits have been EXPLICITLY set (via setLimits), not just the constructor default. */
|
|
113
|
+
private limitsExplicitlySet;
|
|
114
|
+
/** Warn-once latch for the clobber warning, kept distinct from the eviction `warned` latch. */
|
|
115
|
+
private clobberWarned;
|
|
116
|
+
constructor(limits: Required<InMemoryLimits>);
|
|
117
|
+
get byteTotal(): number;
|
|
118
|
+
/**
|
|
119
|
+
* Reconfigure the process-global store's bounds. Called by the
|
|
120
|
+
* {@link InMemoryAgentRunner} constructor when limits are passed. Because the
|
|
121
|
+
* store is a per-process singleton, this replaces the bounds for ALL in-memory
|
|
122
|
+
* threads. Emits {@link LIMITS_CLOBBER_GUIDANCE} at most ONCE per store when a
|
|
123
|
+
* SECOND (or later) explicit set arrives whose resolved values differ from the
|
|
124
|
+
* prior explicit set — i.e. a genuine clobber of an already-customized config.
|
|
125
|
+
* The first explicit customization (defaults → custom) is the intended
|
|
126
|
+
* override and never warns; identical re-sets never warn.
|
|
127
|
+
*/
|
|
128
|
+
setLimits(limits: Required<InMemoryLimits>): void;
|
|
129
|
+
get size(): number;
|
|
130
|
+
/** Re-insert at the tail so Map iteration order stays LRU-first. */
|
|
131
|
+
private touchOrder;
|
|
132
|
+
getOrCreate(threadId: string): InMemoryEventStore;
|
|
133
|
+
get(threadId: string, opts: {
|
|
134
|
+
touch: boolean;
|
|
135
|
+
}): InMemoryEventStore | undefined;
|
|
136
|
+
peek(threadId: string): InMemoryEventStore | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Evict the least-recently-used thread that is neither running NOR
|
|
139
|
+
* mid-finalization. Returns false if none evictable. The `protect` thread
|
|
140
|
+
* (typically the one just created) is never evicted, so a fresh thread is not
|
|
141
|
+
* immediately dropped when it is the only non-running candidate.
|
|
142
|
+
*
|
|
143
|
+
* A thread is skipped while `isRunning` OR `stopRequested` is set.
|
|
144
|
+
* `stop()` flips `isRunning` to false the moment it aborts the agent, but the
|
|
145
|
+
* run keeps finalizing asynchronously (the abort trips the `catch` in
|
|
146
|
+
* `runAgent`, which later calls `appendRun`). During that window
|
|
147
|
+
* `stopRequested` stays true; evicting the thread then would make the pending
|
|
148
|
+
* `appendRun` hit `if (!store) return` and silently drop the aborted run's
|
|
149
|
+
* history. Guarding on `stopRequested` keeps the thread alive until
|
|
150
|
+
* finalization completes.
|
|
151
|
+
*/
|
|
152
|
+
private evictOneLru;
|
|
153
|
+
appendRun(threadId: string, run: HistoricRun): void;
|
|
154
|
+
private enforceRunCap;
|
|
155
|
+
/**
|
|
156
|
+
* Trim the store back under the byte ceiling by evicting LRU non-running
|
|
157
|
+
* threads. `protect` (the just-appended thread) is never self-evicted, so a
|
|
158
|
+
* fresh run pushes OTHER threads out rather than dropping itself.
|
|
159
|
+
*/
|
|
160
|
+
private evictByBytesIfNeeded;
|
|
161
|
+
private removeThread;
|
|
162
|
+
private evictThreadsIfNeeded;
|
|
163
|
+
private noteEviction;
|
|
164
|
+
listThreads(): InMemoryThread[];
|
|
165
|
+
clear(): void;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Process-wide singleton backing every {@link InMemoryAgentRunner}. Exported
|
|
169
|
+
* (with the `ɵ` internal-API prefix) so tests can inspect the exact store the
|
|
170
|
+
* runner writes to; not part of the public API.
|
|
171
|
+
*/
|
|
172
|
+
declare const ɵGLOBAL_STORE: ɵBoundedThreadStore;
|
|
22
173
|
declare class InMemoryAgentRunner extends AgentRunner {
|
|
23
174
|
readonly ɵsupportsLocalThreadEndpoints = true;
|
|
175
|
+
/**
|
|
176
|
+
* @param limits Optional bounds for the process-global in-memory store. Omit
|
|
177
|
+
* for safe defaults ({@link ɵINMEMORY_DEFAULTS}). When multiple runners are
|
|
178
|
+
* constructed with differing limits, the last-constructed wins — in practice
|
|
179
|
+
* the OSS/SSE default construction passes nothing. If a second (or later)
|
|
180
|
+
* runner is constructed with limits that DIFFER from an already-customized
|
|
181
|
+
* store, a one-time `console.warn` is emitted to signal that the shared store's
|
|
182
|
+
* bounds are being clobbered for ALL in-memory threads.
|
|
183
|
+
*/
|
|
184
|
+
constructor(limits?: InMemoryLimits);
|
|
24
185
|
run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
|
|
25
186
|
connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
|
|
26
187
|
isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
|
|
@@ -75,5 +236,5 @@ declare class InMemoryAgentRunner extends AgentRunner {
|
|
|
75
236
|
clearThreads(): void;
|
|
76
237
|
}
|
|
77
238
|
//#endregion
|
|
78
|
-
export { InMemoryAgentRunner, InMemoryThread };
|
|
239
|
+
export { InMemoryAgentRunner, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵestimateBytes };
|
|
79
240
|
//# sourceMappingURL=in-memory.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.cts","names":[],"sources":["../../../../src/v2/runtime/runner/in-memory.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"in-memory.d.cts","names":[],"sources":["../../../../src/v2/runtime/runner/in-memory.ts"],"mappings":";;;;;;UAmBiB,cAAA;;EAEf,UAAA;EAAA;EAEA,gBAAA;EAkBA;;;AAGF;;;;;AAwBA;;;;;AAMC;;;;EAjCC,QAAA;AAAA;AAAA,cAGW,kBAAA,EAAoB,QAAA,CAAS,cAAA;;;;;;;iBAwB1B,cAAA,CAAe,KAAA;AAAA,UAQrB,WAAA;EACR,QAAA;EACA,KAAA;EA4Be;EA1Bf,OAAA;EACA,WAAA;EACA,MAAA,EAAQ,SAAA;EAyBR;;;;;;;EAjBA,QAAA,EAAU,OAAA;EACV,SAAA;EAuBS;EArBT,gBAAA;EAwBsB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aAAA,EAAa,mBAAA;AAAA,cAGb,mBAAA,SAA4B,WAAA;EAAA,SAC9B,6BAAA;EAD8B;;;;;;;;;cAY3B,MAAA,GAAS,cAAA;EAOrB,GAAA,CAAI,OAAA,EAAS,qBAAA,GAAwB,UAAA,CAAW,SAAA;EA2MhD,OAAA,CAAQ,OAAA,EAAS,yBAAA,GAA4B,UAAA,CAAW,SAAA;EAqDxD,SAAA,CAAU,OAAA,EAAS,2BAAA,GAA8B,OAAA;EAKjD,IAAA,CAAK,OAAA,EAAS,sBAAA,GAAyB,OAAA;EA1DiB;;;;;;;EA+FxD,WAAA,CAAA,GAAe,cAAA;EArCwB;;;;;;;;;EAkDvC,iBAAA,CAAkB,QAAA,WAAmB,OAAA;EA6CtB;;;;;;;;EAlBf,eAAA,CAAgB,QAAA,WAAmB,SAAA;;;;;;;;;;;EAkBnC,cAAA,CAAe,QAAA,WAAmB,MAAA;;;;;;;;;;EAmClC,YAAA,CAAA;AAAA"}
|
|
@@ -1,9 +1,65 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest } from "./agent-runner.mjs";
|
|
3
|
-
import { Observable } from "rxjs";
|
|
4
|
-
import { BaseEvent, Message } from "@ag-ui/client";
|
|
3
|
+
import { Observable, ReplaySubject } from "rxjs";
|
|
4
|
+
import { AbstractAgent, BaseEvent, Message } from "@ag-ui/client";
|
|
5
5
|
|
|
6
6
|
//#region src/v2/runtime/runner/in-memory.d.ts
|
|
7
|
+
interface InMemoryLimits {
|
|
8
|
+
/** LRU cap on distinct threads. */
|
|
9
|
+
maxThreads?: number;
|
|
10
|
+
/** FIFO cap on runs kept per thread. `Infinity` or `0` disables the cap. */
|
|
11
|
+
maxRunsPerThread?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Approximate byte ceiling on RETAINED thread/run history. Enforced at run
|
|
14
|
+
* completion (in `appendRun`), where LRU non-running threads are evicted to
|
|
15
|
+
* keep the total under this limit.
|
|
16
|
+
*
|
|
17
|
+
* Limitation: this bounds only history that has already been committed. A
|
|
18
|
+
* single in-flight run's buffered events (`currentRunEvents` and the two
|
|
19
|
+
* `ReplaySubject<BaseEvent>(Infinity)` buffers in `run()`) are NOT counted
|
|
20
|
+
* until that run completes, so `maxBytes` does not bound a single runaway
|
|
21
|
+
* run mid-stream.
|
|
22
|
+
*
|
|
23
|
+
* Limitation: byte eviction drops only other LRU non-running threads and
|
|
24
|
+
* never self-evicts the active/just-appended thread, so a single dominant
|
|
25
|
+
* thread's own retained history is not byte-trimmed (bounded only by
|
|
26
|
+
* `maxRunsPerThread`). `maxBytes` is thus a cross-thread ceiling enforced by
|
|
27
|
+
* evicting OTHER threads, not a per-thread cap.
|
|
28
|
+
*/
|
|
29
|
+
maxBytes?: number;
|
|
30
|
+
}
|
|
31
|
+
declare const ɵINMEMORY_DEFAULTS: Required<InMemoryLimits>;
|
|
32
|
+
/**
|
|
33
|
+
* Best-effort approximate byte size of a value, via serialized length.
|
|
34
|
+
* Never throws — returns 0 when the value cannot be serialized. This is an
|
|
35
|
+
* approximation (UTF-16 length, not exact heap bytes), used only for relative
|
|
36
|
+
* accounting against `maxBytes`.
|
|
37
|
+
*/
|
|
38
|
+
declare function ɵestimateBytes(value: unknown): number;
|
|
39
|
+
interface HistoricRun {
|
|
40
|
+
threadId: string;
|
|
41
|
+
runId: string;
|
|
42
|
+
/** ID of the agent that executed this run. */
|
|
43
|
+
agentId: string;
|
|
44
|
+
parentRunId: string | null;
|
|
45
|
+
events: BaseEvent[];
|
|
46
|
+
/**
|
|
47
|
+
* Snapshot of all messages (input + generated) at the end of this run, as
|
|
48
|
+
* passed in by the caller. NOTE: `BoundedThreadStore.appendRun` moves this
|
|
49
|
+
* snapshot to the THREAD level (`InMemoryEventStore.messagesSnapshot`) and
|
|
50
|
+
* clears this field to `[]`, so a stored HistoricRun never carries messages.
|
|
51
|
+
* The thread-messages fallback reads the thread-level snapshot, not this.
|
|
52
|
+
*/
|
|
53
|
+
messages: Message[];
|
|
54
|
+
createdAt: number;
|
|
55
|
+
/** Approximate retained byte size of `events`; set by BoundedThreadStore at append. */
|
|
56
|
+
approxEventBytes?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Legacy field retained for shape compatibility. `appendRun` always zeroes it
|
|
59
|
+
* because message bytes are accounted at the thread level, not per run.
|
|
60
|
+
*/
|
|
61
|
+
approxMessageBytes?: number;
|
|
62
|
+
}
|
|
7
63
|
/**
|
|
8
64
|
* Lightweight thread summary returned by {@link InMemoryAgentRunner.listThreads}.
|
|
9
65
|
* Shape matches the Intelligence platform's ThreadRecord so the same HTTP
|
|
@@ -19,8 +75,113 @@ interface InMemoryThread {
|
|
|
19
75
|
createdAt: string;
|
|
20
76
|
updatedAt: string;
|
|
21
77
|
}
|
|
78
|
+
declare class InMemoryEventStore {
|
|
79
|
+
threadId: string;
|
|
80
|
+
constructor(threadId: string);
|
|
81
|
+
/** The subject that current consumers subscribe to. */
|
|
82
|
+
subject: ReplaySubject<BaseEvent> | null;
|
|
83
|
+
/** True while a run is actively producing events. */
|
|
84
|
+
isRunning: boolean;
|
|
85
|
+
/** Current run ID */
|
|
86
|
+
currentRunId: string | null;
|
|
87
|
+
/** Historic completed runs */
|
|
88
|
+
historicRuns: HistoricRun[];
|
|
89
|
+
/** Currently running agent instance (if any). */
|
|
90
|
+
agent: AbstractAgent | null;
|
|
91
|
+
/** Subject returned from run() while the run is active. */
|
|
92
|
+
runSubject: ReplaySubject<BaseEvent> | null;
|
|
93
|
+
/** True once stop() has been requested but the run has not yet finalized. */
|
|
94
|
+
stopRequested: boolean;
|
|
95
|
+
/** Reference to the events emitted in the current run. */
|
|
96
|
+
currentEvents: BaseEvent[] | null;
|
|
97
|
+
/**
|
|
98
|
+
* The thread's single latest NON-EMPTY message snapshot, held at the THREAD
|
|
99
|
+
* level (independent of `historicRuns` lifecycle). Decoupling the snapshot
|
|
100
|
+
* from per-run storage means run-cap FIFO eviction and interleaved
|
|
101
|
+
* empty-snapshot runs can never drop or pin the thread's message history.
|
|
102
|
+
*/
|
|
103
|
+
messagesSnapshot: Message[];
|
|
104
|
+
/** Approximate retained byte size of `messagesSnapshot`. */
|
|
105
|
+
approxMessagesSnapshotBytes: number;
|
|
106
|
+
}
|
|
107
|
+
declare class ɵBoundedThreadStore {
|
|
108
|
+
private limits;
|
|
109
|
+
private readonly map;
|
|
110
|
+
private totalBytes;
|
|
111
|
+
private warned;
|
|
112
|
+
/** True once limits have been EXPLICITLY set (via setLimits), not just the constructor default. */
|
|
113
|
+
private limitsExplicitlySet;
|
|
114
|
+
/** Warn-once latch for the clobber warning, kept distinct from the eviction `warned` latch. */
|
|
115
|
+
private clobberWarned;
|
|
116
|
+
constructor(limits: Required<InMemoryLimits>);
|
|
117
|
+
get byteTotal(): number;
|
|
118
|
+
/**
|
|
119
|
+
* Reconfigure the process-global store's bounds. Called by the
|
|
120
|
+
* {@link InMemoryAgentRunner} constructor when limits are passed. Because the
|
|
121
|
+
* store is a per-process singleton, this replaces the bounds for ALL in-memory
|
|
122
|
+
* threads. Emits {@link LIMITS_CLOBBER_GUIDANCE} at most ONCE per store when a
|
|
123
|
+
* SECOND (or later) explicit set arrives whose resolved values differ from the
|
|
124
|
+
* prior explicit set — i.e. a genuine clobber of an already-customized config.
|
|
125
|
+
* The first explicit customization (defaults → custom) is the intended
|
|
126
|
+
* override and never warns; identical re-sets never warn.
|
|
127
|
+
*/
|
|
128
|
+
setLimits(limits: Required<InMemoryLimits>): void;
|
|
129
|
+
get size(): number;
|
|
130
|
+
/** Re-insert at the tail so Map iteration order stays LRU-first. */
|
|
131
|
+
private touchOrder;
|
|
132
|
+
getOrCreate(threadId: string): InMemoryEventStore;
|
|
133
|
+
get(threadId: string, opts: {
|
|
134
|
+
touch: boolean;
|
|
135
|
+
}): InMemoryEventStore | undefined;
|
|
136
|
+
peek(threadId: string): InMemoryEventStore | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Evict the least-recently-used thread that is neither running NOR
|
|
139
|
+
* mid-finalization. Returns false if none evictable. The `protect` thread
|
|
140
|
+
* (typically the one just created) is never evicted, so a fresh thread is not
|
|
141
|
+
* immediately dropped when it is the only non-running candidate.
|
|
142
|
+
*
|
|
143
|
+
* A thread is skipped while `isRunning` OR `stopRequested` is set.
|
|
144
|
+
* `stop()` flips `isRunning` to false the moment it aborts the agent, but the
|
|
145
|
+
* run keeps finalizing asynchronously (the abort trips the `catch` in
|
|
146
|
+
* `runAgent`, which later calls `appendRun`). During that window
|
|
147
|
+
* `stopRequested` stays true; evicting the thread then would make the pending
|
|
148
|
+
* `appendRun` hit `if (!store) return` and silently drop the aborted run's
|
|
149
|
+
* history. Guarding on `stopRequested` keeps the thread alive until
|
|
150
|
+
* finalization completes.
|
|
151
|
+
*/
|
|
152
|
+
private evictOneLru;
|
|
153
|
+
appendRun(threadId: string, run: HistoricRun): void;
|
|
154
|
+
private enforceRunCap;
|
|
155
|
+
/**
|
|
156
|
+
* Trim the store back under the byte ceiling by evicting LRU non-running
|
|
157
|
+
* threads. `protect` (the just-appended thread) is never self-evicted, so a
|
|
158
|
+
* fresh run pushes OTHER threads out rather than dropping itself.
|
|
159
|
+
*/
|
|
160
|
+
private evictByBytesIfNeeded;
|
|
161
|
+
private removeThread;
|
|
162
|
+
private evictThreadsIfNeeded;
|
|
163
|
+
private noteEviction;
|
|
164
|
+
listThreads(): InMemoryThread[];
|
|
165
|
+
clear(): void;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Process-wide singleton backing every {@link InMemoryAgentRunner}. Exported
|
|
169
|
+
* (with the `ɵ` internal-API prefix) so tests can inspect the exact store the
|
|
170
|
+
* runner writes to; not part of the public API.
|
|
171
|
+
*/
|
|
172
|
+
declare const ɵGLOBAL_STORE: ɵBoundedThreadStore;
|
|
22
173
|
declare class InMemoryAgentRunner extends AgentRunner {
|
|
23
174
|
readonly ɵsupportsLocalThreadEndpoints = true;
|
|
175
|
+
/**
|
|
176
|
+
* @param limits Optional bounds for the process-global in-memory store. Omit
|
|
177
|
+
* for safe defaults ({@link ɵINMEMORY_DEFAULTS}). When multiple runners are
|
|
178
|
+
* constructed with differing limits, the last-constructed wins — in practice
|
|
179
|
+
* the OSS/SSE default construction passes nothing. If a second (or later)
|
|
180
|
+
* runner is constructed with limits that DIFFER from an already-customized
|
|
181
|
+
* store, a one-time `console.warn` is emitted to signal that the shared store's
|
|
182
|
+
* bounds are being clobbered for ALL in-memory threads.
|
|
183
|
+
*/
|
|
184
|
+
constructor(limits?: InMemoryLimits);
|
|
24
185
|
run(request: AgentRunnerRunRequest): Observable<BaseEvent>;
|
|
25
186
|
connect(request: AgentRunnerConnectRequest): Observable<BaseEvent>;
|
|
26
187
|
isRunning(request: AgentRunnerIsRunningRequest): Promise<boolean>;
|
|
@@ -75,5 +236,5 @@ declare class InMemoryAgentRunner extends AgentRunner {
|
|
|
75
236
|
clearThreads(): void;
|
|
76
237
|
}
|
|
77
238
|
//#endregion
|
|
78
|
-
export { InMemoryAgentRunner, InMemoryThread };
|
|
239
|
+
export { InMemoryAgentRunner, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵestimateBytes };
|
|
79
240
|
//# sourceMappingURL=in-memory.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.mts","names":[],"sources":["../../../../src/v2/runtime/runner/in-memory.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"in-memory.d.mts","names":[],"sources":["../../../../src/v2/runtime/runner/in-memory.ts"],"mappings":";;;;;;UAmBiB,cAAA;;EAEf,UAAA;EAAA;EAEA,gBAAA;EAkBA;;;AAGF;;;;;AAwBA;;;;;AAMC;;;;EAjCC,QAAA;AAAA;AAAA,cAGW,kBAAA,EAAoB,QAAA,CAAS,cAAA;;;;;;;iBAwB1B,cAAA,CAAe,KAAA;AAAA,UAQrB,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