@unieai/rabi-api-session-controller 0.0.0-stage → 0.2.2-rc.5
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/LICENSE +21 -0
- package/README.md +7 -2
- package/lib/client.js +4 -0
- package/lib/index.js +4300 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +5013 -0
- package/lib/typert.remote-client.d.ts +115 -0
- package/lib/typert.remote-client.js +2714 -0
- package/lib/types/agent.d.ts +164 -0
- package/lib/types/agent.js +484 -0
- package/lib/types/archived-session-gate.d.ts +33 -0
- package/lib/types/archived-session-gate.js +54 -0
- package/lib/types/assistant-stream.d.ts +26 -0
- package/lib/types/assistant-stream.js +82 -0
- package/lib/types/catalog.d.ts +24 -0
- package/lib/types/catalog.js +107 -0
- package/lib/types/client/contract/events.d.ts +102 -0
- package/lib/types/client/contract/events.js +111 -0
- package/lib/types/client/contract/session.d.ts +178 -0
- package/lib/types/client/contract/session.js +1 -0
- package/lib/types/client/contract/sessions.d.ts +162 -0
- package/lib/types/client/contract/sessions.js +1 -0
- package/lib/types/client/contract/snapshot.d.ts +84 -0
- package/lib/types/client/contract/snapshot.js +1 -0
- package/lib/types/client/index.d.ts +39 -0
- package/lib/types/client/index.js +60 -0
- package/lib/types/client/ordered-baseline.d.ts +12 -0
- package/lib/types/client/ordered-baseline.js +40 -0
- package/lib/types/client/scope.d.ts +46 -0
- package/lib/types/client/scope.js +46 -0
- package/lib/types/client/session-wire-event.d.ts +11 -0
- package/lib/types/client/session-wire-event.js +42 -0
- package/lib/types/client/sessions/assistant-stream.d.ts +56 -0
- package/lib/types/client/sessions/assistant-stream.js +182 -0
- package/lib/types/client/sessions/history-records.d.ts +22 -0
- package/lib/types/client/sessions/history-records.js +25 -0
- package/lib/types/client/sessions/lineage.d.ts +48 -0
- package/lib/types/client/sessions/lineage.js +55 -0
- package/lib/types/client/sessions/manager.d.ts +272 -0
- package/lib/types/client/sessions/manager.js +774 -0
- package/lib/types/client/sessions/notifier.d.ts +39 -0
- package/lib/types/client/sessions/notifier.js +97 -0
- package/lib/types/client/sessions/projection-store.d.ts +128 -0
- package/lib/types/client/sessions/projection-store.js +161 -0
- package/lib/types/client/sessions/remotes.d.ts +29 -0
- package/lib/types/client/sessions/remotes.js +7 -0
- package/lib/types/client/sessions/service.d.ts +263 -0
- package/lib/types/client/sessions/service.js +597 -0
- package/lib/types/client/sessions/session.d.ts +303 -0
- package/lib/types/client/sessions/session.js +991 -0
- package/lib/types/client/time-zone.d.ts +8 -0
- package/lib/types/client/time-zone.js +13 -0
- package/lib/types/client/transport.d.ts +77 -0
- package/lib/types/client/transport.js +130 -0
- package/lib/types/commands.d.ts +92 -0
- package/lib/types/commands.js +575 -0
- package/lib/types/continuation.d.ts +35 -0
- package/lib/types/continuation.js +47 -0
- package/lib/types/control.d.ts +20 -0
- package/lib/types/control.js +106 -0
- package/lib/types/file-references.d.ts +27 -0
- package/lib/types/file-references.js +68 -0
- package/lib/types/history/assistant-stream.d.ts +43 -0
- package/lib/types/history/assistant-stream.js +79 -0
- package/lib/types/history/controller.d.ts +104 -0
- package/lib/types/history/controller.js +293 -0
- package/lib/types/history/listener.d.ts +105 -0
- package/lib/types/history/listener.js +296 -0
- package/lib/types/history.d.ts +58 -0
- package/lib/types/history.js +152 -0
- package/lib/types/index.d.ts +262 -0
- package/lib/types/index.js +693 -0
- package/lib/types/list.d.ts +62 -0
- package/lib/types/list.js +343 -0
- package/lib/types/media-references.d.ts +18 -0
- package/lib/types/media-references.js +84 -0
- package/lib/types/remote-events.d.ts +8 -0
- package/lib/types/remote-events.js +1 -0
- package/lib/types/skill-catalog.d.ts +28 -0
- package/lib/types/skill-catalog.js +203 -0
- package/lib/types/state/controller.d.ts +45 -0
- package/lib/types/state/controller.js +288 -0
- package/lib/types/state/listener.d.ts +40 -0
- package/lib/types/state/listener.js +111 -0
- package/lib/types/types.d.ts +687 -0
- package/lib/types/types.js +5 -0
- package/lib/types/web/controller.d.ts +25 -0
- package/lib/types/web/controller.js +138 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +119 -4
- package/src/agent.ts +474 -0
- package/src/archived-session-gate.ts +59 -0
- package/src/assistant-stream.ts +102 -0
- package/src/catalog.ts +117 -0
- package/src/client/contract/events.ts +205 -0
- package/src/client/contract/session.ts +174 -0
- package/src/client/contract/sessions.ts +169 -0
- package/src/client/contract/snapshot.ts +94 -0
- package/src/client/index.ts +149 -0
- package/src/client/ordered-baseline.ts +43 -0
- package/src/client/scope.ts +76 -0
- package/src/client/session-wire-event.ts +46 -0
- package/src/client/sessions/assistant-stream.ts +229 -0
- package/src/client/sessions/history-records.ts +35 -0
- package/src/client/sessions/lineage.ts +96 -0
- package/src/client/sessions/manager.ts +857 -0
- package/src/client/sessions/notifier.ts +97 -0
- package/src/client/sessions/projection-store.ts +244 -0
- package/src/client/sessions/remotes.ts +44 -0
- package/src/client/sessions/service.ts +741 -0
- package/src/client/sessions/session.ts +1055 -0
- package/src/client/time-zone.ts +14 -0
- package/src/client/transport.ts +247 -0
- package/src/commands.ts +602 -0
- package/src/continuation.ts +58 -0
- package/src/control.ts +121 -0
- package/src/file-references.ts +42 -0
- package/src/history/assistant-stream.ts +102 -0
- package/src/history/controller.ts +256 -0
- package/src/history/listener.ts +302 -0
- package/src/history.ts +189 -0
- package/src/index.ts +651 -0
- package/src/list.ts +382 -0
- package/src/media-references.ts +84 -0
- package/src/remote-events.ts +14 -0
- package/src/skill-catalog.ts +108 -0
- package/src/state/controller.ts +221 -0
- package/src/state/listener.ts +116 -0
- package/src/types.ts +720 -0
- package/src/web/controller.ts +78 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/** Host catalog, durable projection caches, and explicitly retained Client instances. */
|
|
2
|
+
import type { SubagentAddress } from '@unieai/rabi-subagent/client';
|
|
3
|
+
import { SessionSeq, type SessionId } from '@unieai/rabi-session/types';
|
|
4
|
+
import type { SessionProjectionMap, SessionProjectionViewValues } from '@unieai/rabi-session-projection/types';
|
|
5
|
+
import type { WorkspaceId } from '@unieai/rabi-workspace/types';
|
|
6
|
+
import type { SessionControlFrame, SessionRenameValue, SessionSummary } from '../../types.ts';
|
|
7
|
+
import type { RemoteFailure, RemoteResult } from '@unieai/rabi-typert-protocol';
|
|
8
|
+
import type { SessionListEntry } from './lineage.ts';
|
|
9
|
+
import { Session } from './session.ts';
|
|
10
|
+
import type { SessionRemotes } from './remotes.ts';
|
|
11
|
+
import type { SessionTarget } from '../contract/sessions.ts';
|
|
12
|
+
/**
|
|
13
|
+
* List arrival lifecycle, orthogonal to the pull-activity `state` axis:
|
|
14
|
+
* `pending` (no successful pull yet — an empty items array means "nothing
|
|
15
|
+
* arrived", not "nothing exists") → `ready` (at least one pull landed).
|
|
16
|
+
* Monotone: `ready` never steps back — later pull failures and reconnect
|
|
17
|
+
* re-pulls ride the `state`/`error` axis, which is where failure is modeled
|
|
18
|
+
* (no `error` phase here; that would duplicate `state`).
|
|
19
|
+
*/
|
|
20
|
+
export type SessionListPhase = 'pending' | 'ready';
|
|
21
|
+
/** Request-local content hit returned to sidebar search consumers. */
|
|
22
|
+
export interface SessionSearchResultItem {
|
|
23
|
+
sessionId: SessionId;
|
|
24
|
+
snippet: string;
|
|
25
|
+
}
|
|
26
|
+
/** Immutable session-list snapshot for useSessionList. */
|
|
27
|
+
export interface SessionListSnapshot {
|
|
28
|
+
items: readonly SessionListEntry[];
|
|
29
|
+
state: 'idle' | 'loading' | 'error';
|
|
30
|
+
/** Arrival lifecycle (see {@link SessionListPhase}); `state` stays the pull-activity axis. */
|
|
31
|
+
phase: SessionListPhase;
|
|
32
|
+
error: RemoteFailure | null;
|
|
33
|
+
projectionsBySession: Readonly<Record<SessionId, SessionProjectionSnapshot>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Every projection value the store currently holds, with the summary mark
|
|
37
|
+
* stripped, and the lifecycle of its explicit baseline read. This is the full
|
|
38
|
+
* attached-Session set, not a list row's summary contract (see
|
|
39
|
+
* `SessionListEntry.projectionValues`).
|
|
40
|
+
*/
|
|
41
|
+
export interface SessionProjectionSnapshot {
|
|
42
|
+
readonly values: Readonly<Partial<SessionProjectionViewValues>>;
|
|
43
|
+
readonly state: 'idle' | 'loading' | 'ready' | 'migration-required' | 'error';
|
|
44
|
+
readonly error: RemoteFailure | null;
|
|
45
|
+
}
|
|
46
|
+
/** Instance cluster + frame entry + the session list. */
|
|
47
|
+
export declare class SessionManager {
|
|
48
|
+
private readonly remote;
|
|
49
|
+
private readonly sessions;
|
|
50
|
+
/** In-flight Session disposals remain here after instances leave `sessions`, so manager disposal can await quiescence. */
|
|
51
|
+
private readonly sessionDisposals;
|
|
52
|
+
/**
|
|
53
|
+
* Accepted/running presentation must survive a later empty-history list
|
|
54
|
+
* response. Host-asserted running is recorded even before a row, instance, or
|
|
55
|
+
* address holds the identity — the listing that would hold it may not have
|
|
56
|
+
* landed yet — while the client-local acceptance callback requires a current
|
|
57
|
+
* holder, because it can arrive from a replaced or already-dropped Session.
|
|
58
|
+
*/
|
|
59
|
+
private readonly engagedSessions;
|
|
60
|
+
private disposed;
|
|
61
|
+
/** Per-session projection value stores, retained independently of instance arrival (the
|
|
62
|
+
* title-snapshot precedent, generalized): push frames land here whether or not the Session
|
|
63
|
+
* is instantiated (list rows read the 'title' key), and an instantiated Session adopts the
|
|
64
|
+
* same store so history-baseline seeding and frames converge on one row set. */
|
|
65
|
+
private readonly projectionStores;
|
|
66
|
+
private summaries;
|
|
67
|
+
private listState;
|
|
68
|
+
/** Arrival phase; the pending → ready edge fires on the first successful pull (see SessionListPhase). */
|
|
69
|
+
private listPhase;
|
|
70
|
+
private listError;
|
|
71
|
+
private listInflight;
|
|
72
|
+
/** Active list request's mutation log; its identity also fences completion after reconnect. */
|
|
73
|
+
private listMutations;
|
|
74
|
+
private readonly addresses;
|
|
75
|
+
private readonly projectionLoads;
|
|
76
|
+
private readonly projectionInflight;
|
|
77
|
+
private listSnapshotCache;
|
|
78
|
+
/** Entry-identity cache (reference stability): list rebuilds reuse the previous entry
|
|
79
|
+
* object when every field matches — wire refreshes mint all-new summary objects, so identity
|
|
80
|
+
* must be recovered by value or every SessionListItem memo misses on every refresh. */
|
|
81
|
+
private entryCache;
|
|
82
|
+
private itemsCache;
|
|
83
|
+
private readonly notifier;
|
|
84
|
+
/** @param remote - generated Remote namespaces used by catalog and history readers. */
|
|
85
|
+
constructor(remote: SessionRemotes);
|
|
86
|
+
/**
|
|
87
|
+
* Resolve an acquisition target without materializing a Session.
|
|
88
|
+
* @param target - known identity or durable direct-parent address.
|
|
89
|
+
* @returns the resolved identity with its explicit or catalog-derived history route installed.
|
|
90
|
+
*/
|
|
91
|
+
resolveTarget(target: SessionTarget): SessionId;
|
|
92
|
+
/**
|
|
93
|
+
* Resolve an address for breadcrumb navigation without retaining transport authority.
|
|
94
|
+
* @param sessionId - possible child id in received Session metadata.
|
|
95
|
+
* @returns A retained address, then a catalog address, then an unknown-mode address
|
|
96
|
+
* from a listed subagent header; undefined without that evidence.
|
|
97
|
+
*/
|
|
98
|
+
subagentAddress(sessionId: SessionId): SubagentAddress | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Withdraw an exact Client instance before running its teardown callbacks.
|
|
101
|
+
* @param sessionId - identity to withdraw.
|
|
102
|
+
* @param expected - instance being released; a replacement is left untouched.
|
|
103
|
+
* @returns completion of the detached instance's stream teardown.
|
|
104
|
+
*/
|
|
105
|
+
drop(sessionId: SessionId, expected: Session): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Stop catalog requests and dispose every resident Session.
|
|
108
|
+
* @returns once catalog requests and every Session stream have stopped.
|
|
109
|
+
*/
|
|
110
|
+
dispose(): Promise<void>;
|
|
111
|
+
private startSessionDisposal;
|
|
112
|
+
private drainSessionDisposals;
|
|
113
|
+
/**
|
|
114
|
+
* Lazy build: return the existing instance or construct one (no auto-open —
|
|
115
|
+
* the reference allocator opens history after binding the scope).
|
|
116
|
+
* New instances reconcile retained metadata before returning.
|
|
117
|
+
* @param sessionId - the session to get.
|
|
118
|
+
* @returns the resident instance.
|
|
119
|
+
*/
|
|
120
|
+
get(sessionId: SessionId): Session;
|
|
121
|
+
private createSession;
|
|
122
|
+
private effectiveBlank;
|
|
123
|
+
/**
|
|
124
|
+
* Identities an engagement may still belong to: the given list rows, resident
|
|
125
|
+
* Session instances, and retained child addresses.
|
|
126
|
+
* @param summaries - list rows of the caller's snapshot.
|
|
127
|
+
* @returns the retained identity set.
|
|
128
|
+
*/
|
|
129
|
+
private retainedIds;
|
|
130
|
+
/**
|
|
131
|
+
* Forget one engagement that no retained identity holds.
|
|
132
|
+
* @param sessionId - identity whose engagement may be dropped.
|
|
133
|
+
* @param retained - identities from {@link retainedIds} for the caller's snapshot.
|
|
134
|
+
*/
|
|
135
|
+
private pruneEngagement;
|
|
136
|
+
/** Resident per-session projection store (create-on-demand; outlives instantiation). */
|
|
137
|
+
private projectionStore;
|
|
138
|
+
/**
|
|
139
|
+
* Read projections without starting migration; retry failed or migration-deferred reads.
|
|
140
|
+
* @param sessionId - Session to inspect without opening its conversation.
|
|
141
|
+
* @returns completion of the current or newly started read.
|
|
142
|
+
*/
|
|
143
|
+
refreshProjections(sessionId: SessionId): Promise<void>;
|
|
144
|
+
/** Full refresh via session.list (single-flight within one Host generation). */
|
|
145
|
+
refreshList(): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Search visible session message content without adding transient query
|
|
148
|
+
* state to the list snapshot.
|
|
149
|
+
* @param query - non-blank literal phrase.
|
|
150
|
+
* @param signal - cancellation for superseded UI queries.
|
|
151
|
+
* @returns the Host result or a folded transport error.
|
|
152
|
+
*/
|
|
153
|
+
search(query: string, signal: AbortSignal): Promise<RemoteResult<{
|
|
154
|
+
items: SessionSearchResultItem[];
|
|
155
|
+
hasMore: boolean;
|
|
156
|
+
}>>;
|
|
157
|
+
/**
|
|
158
|
+
* Contract session.create; on success merge into summaries immediately (no
|
|
159
|
+
* wait for the next refresh). A created session is blank by definition
|
|
160
|
+
* (entity birth precedes the first message).
|
|
161
|
+
* @param opts - target workspace or working directory, an optional blank Session to reuse, and an optional Agent preset.
|
|
162
|
+
* @returns the create result, naming the Session the Host created or reused.
|
|
163
|
+
*/
|
|
164
|
+
create(opts?: {
|
|
165
|
+
workspaceId?: WorkspaceId;
|
|
166
|
+
cwd?: string;
|
|
167
|
+
sessionId?: SessionId;
|
|
168
|
+
agentPreset?: string;
|
|
169
|
+
}): Promise<RemoteResult<{
|
|
170
|
+
sessionId: SessionId;
|
|
171
|
+
}>>;
|
|
172
|
+
/**
|
|
173
|
+
* Contract session.fork; on success merge the child into summaries
|
|
174
|
+
* immediately (same synchronous-addressability guarantee as create).
|
|
175
|
+
* Blankness starts provisionally true so the authoritative Host summary can
|
|
176
|
+
* preserve it or lower it after an exact cut before the first `turn/start`;
|
|
177
|
+
* the fork has no durable source relationship. A child published before Workspace
|
|
178
|
+
* attachment fails is also reconciled into the list.
|
|
179
|
+
* @param opts - source session, optional exact inclusive boundary seq, and permission to start migration.
|
|
180
|
+
* @returns the fork result (the child session id).
|
|
181
|
+
*/
|
|
182
|
+
fork(opts: {
|
|
183
|
+
sessionId: SessionId;
|
|
184
|
+
atSeq?: SessionSeq;
|
|
185
|
+
allowMigration?: boolean;
|
|
186
|
+
}): Promise<RemoteResult<{
|
|
187
|
+
sessionId: SessionId;
|
|
188
|
+
}>>;
|
|
189
|
+
/**
|
|
190
|
+
* Rename a Session and update its title projection without opening its history.
|
|
191
|
+
* @param sessionId - Session to rename.
|
|
192
|
+
* @param title - raw title text for Host normalization.
|
|
193
|
+
* @returns the accepted title and event position, or the Remote failure.
|
|
194
|
+
*/
|
|
195
|
+
rename(sessionId: SessionId, title: string): Promise<RemoteResult<SessionRenameValue>>;
|
|
196
|
+
/**
|
|
197
|
+
* Merge a Host summary, replacing live state and filling missing metadata.
|
|
198
|
+
* Local create/fork placeholders only fill metadata on an existing row.
|
|
199
|
+
*/
|
|
200
|
+
private mergeSummary;
|
|
201
|
+
/** Apply immediately and retain for replay when a list response is in flight. */
|
|
202
|
+
private recordMutation;
|
|
203
|
+
/**
|
|
204
|
+
* uSES subscription entry for useSessionList.
|
|
205
|
+
* @param listener - change callback.
|
|
206
|
+
* @returns the unsubscribe function.
|
|
207
|
+
*/
|
|
208
|
+
subscribe(listener: () => void): () => void;
|
|
209
|
+
/**
|
|
210
|
+
* Cached list snapshot (rebuilt lazily when dirty with no listeners).
|
|
211
|
+
* @returns the cached reference (stable until the next flush).
|
|
212
|
+
*/
|
|
213
|
+
getListSnapshot(): SessionListSnapshot;
|
|
214
|
+
/**
|
|
215
|
+
* Read cached projection values for a Session that may exist only in a loaded subagent catalog.
|
|
216
|
+
* @param sessionId - Session whose control or history baseline supplied projections.
|
|
217
|
+
* @returns current values, or undefined before any projection store exists.
|
|
218
|
+
*/
|
|
219
|
+
projectionValues(sessionId: SessionId): Readonly<Partial<SessionProjectionMap>> | undefined;
|
|
220
|
+
/**
|
|
221
|
+
* Apply a complete control baseline or one later per-event projection frame.
|
|
222
|
+
* @param frame - baseline or live per-event projection change from Session Controller.
|
|
223
|
+
*/
|
|
224
|
+
handleControlFrame(frame: SessionControlFrame): void;
|
|
225
|
+
private replaceControlBaseline;
|
|
226
|
+
/**
|
|
227
|
+
* Apply one Session-list addition forwarded through `ctx.remote.$on`.
|
|
228
|
+
* @param summary - current Host summary for the added Session.
|
|
229
|
+
*/
|
|
230
|
+
handleSessionAdded(summary: SessionSummary): void;
|
|
231
|
+
/**
|
|
232
|
+
* Merge one list-surface projection block by the sequence space it declares.
|
|
233
|
+
* A `sequenced` block came from the Host's live registry for an attached
|
|
234
|
+
* Session, so each key lands under higher-seq-wins against that Session's
|
|
235
|
+
* baselines and frames. A `cached` block was viewed from the persisted
|
|
236
|
+
* checkpoint by a header-only listing: its watermark is not comparable with
|
|
237
|
+
* this connection's seqs, so it only fills keys no sequenced row holds.
|
|
238
|
+
*/
|
|
239
|
+
private applyListBlock;
|
|
240
|
+
/**
|
|
241
|
+
* Apply one Session removal forwarded through `ctx.remote.$on`.
|
|
242
|
+
* @param sessionId - removed Session identity.
|
|
243
|
+
*/
|
|
244
|
+
handleSessionRemoved(sessionId: SessionId): void;
|
|
245
|
+
/**
|
|
246
|
+
* Apply one live Agent running-state change.
|
|
247
|
+
* @param sessionId - Session whose Agent state changed.
|
|
248
|
+
* @param running - current Agent running state.
|
|
249
|
+
*/
|
|
250
|
+
handleSessionStatus(sessionId: SessionId, running: boolean): void;
|
|
251
|
+
/**
|
|
252
|
+
* Advance Session-list activity from one user-authored durable message.
|
|
253
|
+
* @param sessionId - Session whose activity changed.
|
|
254
|
+
* @param updatedAt - durable message timestamp.
|
|
255
|
+
*/
|
|
256
|
+
handleSessionActivity(sessionId: SessionId, updatedAt: number): void;
|
|
257
|
+
/**
|
|
258
|
+
* Surface one live Agent failure on an already-materialized Session.
|
|
259
|
+
* @param sessionId - Session whose Agent failed.
|
|
260
|
+
* @param message - caller-visible failure description.
|
|
261
|
+
*/
|
|
262
|
+
handleSessionError(sessionId: SessionId, message: string): void;
|
|
263
|
+
/**
|
|
264
|
+
* Repair one re-established Host-event generation with queryable baselines.
|
|
265
|
+
* Discard old projection cuts before new queries, including cold Sessions
|
|
266
|
+
* absent from the process-local control baseline.
|
|
267
|
+
* Opened Session follow streams resume independently through API Gateway.
|
|
268
|
+
*/
|
|
269
|
+
handleConnected(): void;
|
|
270
|
+
private buildListSnapshot;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=manager.d.ts.map
|