@unieai/rabi-api-session-controller 0.0.0-stage → 0.2.1-rc.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.
- package/LICENSE +21 -0
- package/README.md +7 -2
- package/lib/client.js +4325 -0
- package/lib/index.js +3367 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +4053 -0
- package/lib/typert.remote-client.d.ts +97 -0
- package/lib/typert.remote-client.js +2013 -0
- package/lib/types/agent.d.ts +198 -0
- package/lib/types/agent.js +609 -0
- package/lib/types/archived-session-gate.d.ts +30 -0
- package/lib/types/archived-session-gate.js +51 -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 +106 -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 +157 -0
- package/lib/types/client/contract/session.js +1 -0
- package/lib/types/client/contract/sessions.d.ts +161 -0
- package/lib/types/client/contract/sessions.js +1 -0
- package/lib/types/client/contract/snapshot.d.ts +81 -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 +40 -0
- package/lib/types/client/sessions/lineage.js +54 -0
- package/lib/types/client/sessions/manager.d.ts +269 -0
- package/lib/types/client/sessions/manager.js +799 -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 +258 -0
- package/lib/types/client/sessions/service.js +582 -0
- package/lib/types/client/sessions/session.d.ts +287 -0
- package/lib/types/client/sessions/session.js +866 -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 +129 -0
- package/lib/types/commands.d.ts +86 -0
- package/lib/types/commands.js +624 -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.d.ts +32 -0
- package/lib/types/history.js +441 -0
- package/lib/types/index.d.ts +222 -0
- package/lib/types/index.js +658 -0
- package/lib/types/list.d.ts +50 -0
- package/lib/types/list.js +325 -0
- package/lib/types/media-references.d.ts +16 -0
- package/lib/types/media-references.js +76 -0
- package/lib/types/model-selection-projection.d.ts +8 -0
- package/lib/types/model-selection-projection.js +65 -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/types.d.ts +611 -0
- package/lib/types/types.js +4 -0
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +114 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/** Web presentation fold joining transient Assistant frames to one durable v2 settlement. */
|
|
2
|
+
import { expandAssistantStream } from '@unieai/rabi-llm/assistant-stream';
|
|
3
|
+
/** Keeps transient Assistant presentation behind one settlement-aware interface. */
|
|
4
|
+
export class ClientAssistantStream {
|
|
5
|
+
activeAttempt;
|
|
6
|
+
retainedAttempt;
|
|
7
|
+
pending = new Map();
|
|
8
|
+
publishedSeqs = new Set();
|
|
9
|
+
durableCursor = -1;
|
|
10
|
+
transientInGap = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Replace the durable Web window and adopt an optional reconnect baseline.
|
|
13
|
+
* @param entries - durable entries in the replacement window.
|
|
14
|
+
* @param baseline - compact prefix for an Assistant attempt that is still live.
|
|
15
|
+
* @returns immediately visible durable entries plus reconstructed transient chunks.
|
|
16
|
+
*/
|
|
17
|
+
replace(entries, baseline) {
|
|
18
|
+
this.pending.clear();
|
|
19
|
+
this.transientInGap = 0;
|
|
20
|
+
this.activeAttempt = undefined;
|
|
21
|
+
this.retainedAttempt = undefined;
|
|
22
|
+
const opening = baseline?.activeAttempt;
|
|
23
|
+
if (opening !== undefined) {
|
|
24
|
+
this.activeAttempt = {
|
|
25
|
+
attemptId: opening.attemptId,
|
|
26
|
+
startedAfterSeq: opening.startedAfterSeq,
|
|
27
|
+
turn: opening.turn,
|
|
28
|
+
step: opening.step,
|
|
29
|
+
nextIndex: opening.nextIndex,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const visible = [...entries];
|
|
33
|
+
this.publishedSeqs = new Set(visible.map(entry => entry.event.seq));
|
|
34
|
+
this.durableCursor = visible.reduce((cursor, entry) => Math.max(cursor, entry.event.seq), -1);
|
|
35
|
+
if (opening !== undefined) {
|
|
36
|
+
for (const [index, member] of expandAssistantStream(opening.stream).entries()) {
|
|
37
|
+
this.transientInGap += 1;
|
|
38
|
+
visible.push({
|
|
39
|
+
type: 'transient',
|
|
40
|
+
event: {
|
|
41
|
+
type: 'assistant/live-chunk',
|
|
42
|
+
seq: this.durableCursor + 1 - 1 / (this.transientInGap + 1),
|
|
43
|
+
time: member.time,
|
|
44
|
+
data: {
|
|
45
|
+
attemptId: opening.attemptId,
|
|
46
|
+
turn: opening.turn,
|
|
47
|
+
step: opening.step,
|
|
48
|
+
chunk: member.chunk,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
if (index + 1 >= opening.nextIndex)
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return visible;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stage one durable v2 settlement while its matching live attempt is open.
|
|
60
|
+
* @param entry - newly followed durable entry.
|
|
61
|
+
* @returns a publication decision, or `undefined` when no entry becomes visible.
|
|
62
|
+
*/
|
|
63
|
+
acceptDurable(entry) {
|
|
64
|
+
const event = entry.event;
|
|
65
|
+
this.durableCursor = Math.max(this.durableCursor, event.seq);
|
|
66
|
+
this.transientInGap = 0;
|
|
67
|
+
const settlement = assistantSettlementEntry(entry);
|
|
68
|
+
if (settlement !== undefined && this.attemptForSettlement(settlement.event) !== undefined) {
|
|
69
|
+
if (this.pending.has(event.seq))
|
|
70
|
+
return { type: 'rebaseline' };
|
|
71
|
+
this.pending.set(event.seq, settlement);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return this.publish(entry);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fold one dense transient frame and release its named durable settlement.
|
|
78
|
+
* Successful messages retain their transient rows until the owning Step ends;
|
|
79
|
+
* interrupted messages, failed attempts, and abandonment retire them immediately.
|
|
80
|
+
* @param frame - next Assistant stream frame received by the follow connection.
|
|
81
|
+
* @returns a transient, publication, or rebaseline decision, or `undefined` when no entry becomes visible.
|
|
82
|
+
*/
|
|
83
|
+
acceptFrame(frame) {
|
|
84
|
+
switch (frame.type) {
|
|
85
|
+
case 'start':
|
|
86
|
+
if (this.activeAttempt !== undefined || this.retainedAttempt !== undefined
|
|
87
|
+
|| this.pending.size > 0)
|
|
88
|
+
return { type: 'rebaseline' };
|
|
89
|
+
this.pending.clear();
|
|
90
|
+
this.activeAttempt = {
|
|
91
|
+
attemptId: frame.attemptId,
|
|
92
|
+
startedAfterSeq: frame.startedAfterSeq,
|
|
93
|
+
turn: frame.turn,
|
|
94
|
+
step: frame.step,
|
|
95
|
+
nextIndex: 0,
|
|
96
|
+
};
|
|
97
|
+
return undefined;
|
|
98
|
+
case 'chunk': {
|
|
99
|
+
const attempt = this.activeAttempt;
|
|
100
|
+
// A controller mounted after the Host saw this attempt has no start
|
|
101
|
+
// frame to reconstruct. Its durable settlement publishes directly;
|
|
102
|
+
// ignore the transient suffix until the next known start.
|
|
103
|
+
if (attempt === undefined || attempt.attemptId !== frame.attemptId)
|
|
104
|
+
return undefined;
|
|
105
|
+
if (frame.index !== attempt.nextIndex)
|
|
106
|
+
return { type: 'rebaseline' };
|
|
107
|
+
attempt.nextIndex += 1;
|
|
108
|
+
this.transientInGap += 1;
|
|
109
|
+
return {
|
|
110
|
+
type: 'transient',
|
|
111
|
+
entry: {
|
|
112
|
+
type: 'transient',
|
|
113
|
+
event: {
|
|
114
|
+
type: 'assistant/live-chunk',
|
|
115
|
+
seq: this.durableCursor + 1 - 1 / (this.transientInGap + 1),
|
|
116
|
+
time: frame.time,
|
|
117
|
+
data: {
|
|
118
|
+
attemptId: frame.attemptId,
|
|
119
|
+
turn: attempt.turn,
|
|
120
|
+
step: attempt.step,
|
|
121
|
+
chunk: frame.chunk,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
case 'end': {
|
|
128
|
+
const attempt = this.activeAttempt;
|
|
129
|
+
if (attempt === undefined || attempt.attemptId !== frame.attemptId) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
this.activeAttempt = undefined;
|
|
133
|
+
if (frame.index !== attempt.nextIndex)
|
|
134
|
+
return { type: 'rebaseline' };
|
|
135
|
+
if (frame.outcome.kind === 'abandoned') {
|
|
136
|
+
return this.pending.size === 0
|
|
137
|
+
? { type: 'abandonment', attemptId: attempt.attemptId }
|
|
138
|
+
: { type: 'rebaseline' };
|
|
139
|
+
}
|
|
140
|
+
if (this.publishedSeqs.has(frame.outcome.seq))
|
|
141
|
+
return undefined;
|
|
142
|
+
const entry = this.pending.get(frame.outcome.seq);
|
|
143
|
+
if (entry === undefined
|
|
144
|
+
|| entry.event.type !== frame.outcome.eventType) {
|
|
145
|
+
return { type: 'rebaseline' };
|
|
146
|
+
}
|
|
147
|
+
this.pending.delete(frame.outcome.seq);
|
|
148
|
+
if (entry.event.type === 'assistant/message' && entry.event.data.interrupted !== true) {
|
|
149
|
+
this.retainedAttempt = { attemptId: attempt.attemptId, turn: attempt.turn, step: attempt.step };
|
|
150
|
+
return this.publish(entry);
|
|
151
|
+
}
|
|
152
|
+
this.publishedSeqs.add(entry.event.seq);
|
|
153
|
+
return { type: 'settlement', attemptId: attempt.attemptId, entry };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
attemptForSettlement(event) {
|
|
158
|
+
const attempt = this.activeAttempt;
|
|
159
|
+
if (attempt === undefined
|
|
160
|
+
|| (event.type === 'assistant/message' && event.surfaceOp !== 'append')
|
|
161
|
+
|| event.seq <= attempt.startedAfterSeq
|
|
162
|
+
|| attempt.turn !== event.data.turn
|
|
163
|
+
|| attempt.step !== event.data.step)
|
|
164
|
+
return undefined;
|
|
165
|
+
return attempt;
|
|
166
|
+
}
|
|
167
|
+
publish(entry) {
|
|
168
|
+
this.publishedSeqs.add(entry.event.seq);
|
|
169
|
+
const retained = this.retainedAttempt;
|
|
170
|
+
if (retained !== undefined && entry.event.type === 'step/end'
|
|
171
|
+
&& entry.event.data.turn === retained.turn && entry.event.data.step === retained.step) {
|
|
172
|
+
this.retainedAttempt = undefined;
|
|
173
|
+
return { type: 'publish', entry, retireAttemptId: retained.attemptId };
|
|
174
|
+
}
|
|
175
|
+
return { type: 'publish', entry };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function assistantSettlementEntry(entry) {
|
|
179
|
+
return entry.event.type === 'assistant/message' || entry.event.type === 'assistant/attempt'
|
|
180
|
+
? entry
|
|
181
|
+
: undefined;
|
|
182
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Client range access and type narrowing for aligned Session history records. */
|
|
2
|
+
import type { SessionHistoryRecord } from '../../types.ts';
|
|
3
|
+
import type { SessionEventLikeEntry } from '../contract/events.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Narrow aligned wire records to their Client event types without allocation.
|
|
6
|
+
* @param records - validated history transport records.
|
|
7
|
+
* @returns the same record array with typed inner events.
|
|
8
|
+
*/
|
|
9
|
+
export declare function historyEntries(records: readonly SessionHistoryRecord[]): readonly SessionEventLikeEntry[];
|
|
10
|
+
/**
|
|
11
|
+
* Read the first logical sequence represented by one wire record.
|
|
12
|
+
* @param record - validated Session event.
|
|
13
|
+
* @returns inclusive first Session sequence.
|
|
14
|
+
*/
|
|
15
|
+
export declare function historyRecordFirstSeq(record: SessionHistoryRecord): number;
|
|
16
|
+
/**
|
|
17
|
+
* Read the final logical sequence represented by one wire record.
|
|
18
|
+
* @param record - validated Session event.
|
|
19
|
+
* @returns inclusive final Session sequence.
|
|
20
|
+
*/
|
|
21
|
+
export declare function historyRecordLastSeq(record: SessionHistoryRecord): number;
|
|
22
|
+
//# sourceMappingURL=history-records.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Client range access and type narrowing for aligned Session history records. */
|
|
2
|
+
/**
|
|
3
|
+
* Narrow aligned wire records to their Client event types without allocation.
|
|
4
|
+
* @param records - validated history transport records.
|
|
5
|
+
* @returns the same record array with typed inner events.
|
|
6
|
+
*/
|
|
7
|
+
export function historyEntries(records) {
|
|
8
|
+
return records;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Read the first logical sequence represented by one wire record.
|
|
12
|
+
* @param record - validated Session event.
|
|
13
|
+
* @returns inclusive first Session sequence.
|
|
14
|
+
*/
|
|
15
|
+
export function historyRecordFirstSeq(record) {
|
|
16
|
+
return record.event.seq;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read the final logical sequence represented by one wire record.
|
|
20
|
+
* @param record - validated Session event.
|
|
21
|
+
* @returns inclusive final Session sequence.
|
|
22
|
+
*/
|
|
23
|
+
export function historyRecordLastSeq(record) {
|
|
24
|
+
return record.event.seq;
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SessionId } from '@unieai/rabi-session/types';
|
|
2
|
+
import type { SessionProjectionMap } from '@unieai/rabi-session-projection/types';
|
|
3
|
+
import type { SessionSummary } from '../../types.ts';
|
|
4
|
+
/** Host list summary enriched with the latest Session Controller title projection. */
|
|
5
|
+
export interface TitledSessionSummary extends SessionSummary {
|
|
6
|
+
title?: string;
|
|
7
|
+
/** Current host-computed projection values for list consumers. */
|
|
8
|
+
projectionValues?: Readonly<Partial<SessionProjectionMap>>;
|
|
9
|
+
}
|
|
10
|
+
/** One flattened session-list row with lineage depth. */
|
|
11
|
+
export interface SessionListEntry {
|
|
12
|
+
sessionId: SessionId;
|
|
13
|
+
title?: string;
|
|
14
|
+
updatedAt: number;
|
|
15
|
+
running: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* New Session presentation and reuse eligibility, reconciled with
|
|
18
|
+
* `sessionListMetadata`; lists hide blank sessions (filtering stays with the consumer).
|
|
19
|
+
*/
|
|
20
|
+
blank: boolean;
|
|
21
|
+
parentSessionId?: SessionId;
|
|
22
|
+
/** Coarse durable origin for navigation filtering; not a continuation capability. */
|
|
23
|
+
origin?: 'subagent';
|
|
24
|
+
/** Format classification supplied by the Host list. */
|
|
25
|
+
formatStatus?: SessionSummary['formatStatus'];
|
|
26
|
+
cwd?: string;
|
|
27
|
+
/** Current host-computed projection values for list consumers. */
|
|
28
|
+
projectionValues?: Readonly<Partial<SessionProjectionMap>>;
|
|
29
|
+
/** Lineage indent depth: root = 0; the UI just multiplies by the indent width. */
|
|
30
|
+
depth: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Summaries -> flat list with lineage indentation. Root and sibling order
|
|
34
|
+
* follows the established input order; this projection never re-sorts a
|
|
35
|
+
* hydrated list from mutable timestamps.
|
|
36
|
+
* @param summaries - the host's session.list items.
|
|
37
|
+
* @returns display rows in render order.
|
|
38
|
+
*/
|
|
39
|
+
export declare function flattenLineage(summaries: readonly TitledSessionSummary[]): SessionListEntry[];
|
|
40
|
+
//# sourceMappingURL=lineage.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// flattenLineage: summaries -> flat list with lineage indentation (pure function).
|
|
2
|
+
// The input order is authoritative; lineage only makes each child adjacent to its parent.
|
|
3
|
+
// Orphaned lineage degrades to root level; cycles fail soft and emit as roots.
|
|
4
|
+
/**
|
|
5
|
+
* Summaries -> flat list with lineage indentation. Root and sibling order
|
|
6
|
+
* follows the established input order; this projection never re-sorts a
|
|
7
|
+
* hydrated list from mutable timestamps.
|
|
8
|
+
* @param summaries - the host's session.list items.
|
|
9
|
+
* @returns display rows in render order.
|
|
10
|
+
*/
|
|
11
|
+
export function flattenLineage(summaries) {
|
|
12
|
+
const byId = new Map();
|
|
13
|
+
for (const s of summaries)
|
|
14
|
+
byId.set(s.sessionId, s);
|
|
15
|
+
const children = new Map();
|
|
16
|
+
const roots = [];
|
|
17
|
+
for (const s of summaries) {
|
|
18
|
+
if (s.parentSessionId !== undefined && byId.has(s.parentSessionId)) {
|
|
19
|
+
const list = children.get(s.parentSessionId) ?? [];
|
|
20
|
+
list.push(s);
|
|
21
|
+
children.set(s.parentSessionId, list);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
roots.push(s); // root, or an orphan whose parent is absent from summaries (degrade to root, never drop)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const out = [];
|
|
28
|
+
const visited = new Set();
|
|
29
|
+
const walk = (s, depth) => {
|
|
30
|
+
if (visited.has(s.sessionId)) {
|
|
31
|
+
console.warn(`[session-controller] lineage cycle at ${s.sessionId}; emitting as root`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
visited.add(s.sessionId);
|
|
35
|
+
const { agentAvailable: _agentAvailable, ...row } = s;
|
|
36
|
+
out.push({
|
|
37
|
+
...row,
|
|
38
|
+
depth,
|
|
39
|
+
});
|
|
40
|
+
const kids = children.get(s.sessionId);
|
|
41
|
+
if (kids === undefined)
|
|
42
|
+
return;
|
|
43
|
+
for (const kid of kids)
|
|
44
|
+
walk(kid, depth + 1);
|
|
45
|
+
};
|
|
46
|
+
for (const root of roots)
|
|
47
|
+
walk(root, 0);
|
|
48
|
+
// Cycle members (unreachable from any root): emit as roots so no entry is lost.
|
|
49
|
+
for (const s of summaries) {
|
|
50
|
+
if (!visited.has(s.sessionId))
|
|
51
|
+
walk(s, 0);
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
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 } 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
|
+
/** Shared projection values and the lifecycle of their explicit baseline read. */
|
|
36
|
+
export interface SessionProjectionSnapshot {
|
|
37
|
+
readonly values: Readonly<Partial<SessionProjectionMap>>;
|
|
38
|
+
readonly state: 'idle' | 'loading' | 'ready' | 'migration-required' | 'error';
|
|
39
|
+
readonly error: RemoteFailure | null;
|
|
40
|
+
}
|
|
41
|
+
/** Instance cluster + frame entry + the session list. */
|
|
42
|
+
export declare class SessionManager {
|
|
43
|
+
private readonly remote;
|
|
44
|
+
private readonly sessions;
|
|
45
|
+
/** In-flight Session disposals remain here after instances leave `sessions`, so manager disposal can await quiescence. */
|
|
46
|
+
private readonly sessionDisposals;
|
|
47
|
+
/**
|
|
48
|
+
* Accepted/running presentation must survive a later empty-history list
|
|
49
|
+
* response. Host-asserted running is recorded even before a row, instance, or
|
|
50
|
+
* address holds the identity — the listing that would hold it may not have
|
|
51
|
+
* landed yet — while the client-local acceptance callback requires a current
|
|
52
|
+
* holder, because it can arrive from a replaced or already-dropped Session.
|
|
53
|
+
*/
|
|
54
|
+
private readonly engagedSessions;
|
|
55
|
+
private disposed;
|
|
56
|
+
/** Per-session projection value stores, retained independently of instance arrival (the
|
|
57
|
+
* title-snapshot precedent, generalized): push frames land here whether or not the Session
|
|
58
|
+
* is instantiated (list rows read the 'title' key), and an instantiated Session adopts the
|
|
59
|
+
* same store so history-baseline seeding and frames converge on one row set. */
|
|
60
|
+
private readonly projectionStores;
|
|
61
|
+
private summaries;
|
|
62
|
+
private listState;
|
|
63
|
+
/** Arrival phase; the pending → ready edge fires on the first successful pull (see SessionListPhase). */
|
|
64
|
+
private listPhase;
|
|
65
|
+
private listError;
|
|
66
|
+
private listInflight;
|
|
67
|
+
/** Active list request's mutation log; its identity also fences completion after reconnect. */
|
|
68
|
+
private listMutations;
|
|
69
|
+
private readonly addresses;
|
|
70
|
+
private readonly projectionLoads;
|
|
71
|
+
private readonly projectionInflight;
|
|
72
|
+
private listSnapshotCache;
|
|
73
|
+
/** Entry-identity cache (reference stability): list rebuilds reuse the previous entry
|
|
74
|
+
* object when every field matches — wire refreshes mint all-new summary objects, so identity
|
|
75
|
+
* must be recovered by value or every SessionListItem memo misses on every refresh. */
|
|
76
|
+
private entryCache;
|
|
77
|
+
private itemsCache;
|
|
78
|
+
private readonly notifier;
|
|
79
|
+
/** @param remote - generated Remote namespaces used by catalog and history readers. */
|
|
80
|
+
constructor(remote: SessionRemotes);
|
|
81
|
+
/**
|
|
82
|
+
* Resolve an acquisition target without materializing a Session.
|
|
83
|
+
* @param target - known identity or durable direct-parent address.
|
|
84
|
+
* @returns the resolved identity with its explicit or catalog-derived history route installed.
|
|
85
|
+
*/
|
|
86
|
+
resolveTarget(target: SessionTarget): SessionId;
|
|
87
|
+
/**
|
|
88
|
+
* Resolve an address for breadcrumb navigation without retaining transport authority.
|
|
89
|
+
* @param sessionId - possible child id in received Session metadata.
|
|
90
|
+
* @returns A retained address, then a catalog address, then an unknown-mode address
|
|
91
|
+
* from a listed subagent header; undefined without that evidence.
|
|
92
|
+
*/
|
|
93
|
+
subagentAddress(sessionId: SessionId): SubagentAddress | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Withdraw an exact Client instance before running its teardown callbacks.
|
|
96
|
+
* @param sessionId - identity to withdraw.
|
|
97
|
+
* @param expected - instance being released; a replacement is left untouched.
|
|
98
|
+
* @returns completion of the detached instance's stream teardown.
|
|
99
|
+
*/
|
|
100
|
+
drop(sessionId: SessionId, expected: Session): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Stop catalog requests and dispose every resident Session.
|
|
103
|
+
* @returns once catalog requests and every Session stream have stopped.
|
|
104
|
+
*/
|
|
105
|
+
dispose(): Promise<void>;
|
|
106
|
+
private startSessionDisposal;
|
|
107
|
+
private drainSessionDisposals;
|
|
108
|
+
/**
|
|
109
|
+
* Lazy build: return the existing instance or construct one (no auto-open —
|
|
110
|
+
* the reference allocator opens history after binding the scope).
|
|
111
|
+
* New instances reconcile retained metadata before returning.
|
|
112
|
+
* @param sessionId - the session to get.
|
|
113
|
+
* @returns the resident instance.
|
|
114
|
+
*/
|
|
115
|
+
get(sessionId: SessionId): Session;
|
|
116
|
+
private createSession;
|
|
117
|
+
private effectiveBlank;
|
|
118
|
+
/**
|
|
119
|
+
* Identities an engagement may still belong to: the given list rows, resident
|
|
120
|
+
* Session instances, and retained child addresses.
|
|
121
|
+
* @param summaries - list rows of the caller's snapshot.
|
|
122
|
+
* @returns the retained identity set.
|
|
123
|
+
*/
|
|
124
|
+
private retainedIds;
|
|
125
|
+
/**
|
|
126
|
+
* Forget one engagement that no retained identity holds.
|
|
127
|
+
* @param sessionId - identity whose engagement may be dropped.
|
|
128
|
+
* @param retained - identities from {@link retainedIds} for the caller's snapshot.
|
|
129
|
+
*/
|
|
130
|
+
private pruneEngagement;
|
|
131
|
+
/** Resident per-session projection store (create-on-demand; outlives instantiation). */
|
|
132
|
+
private projectionStore;
|
|
133
|
+
/**
|
|
134
|
+
* Read projections without starting migration; retry failed or migration-deferred reads.
|
|
135
|
+
* @param sessionId - Session to inspect without opening its conversation.
|
|
136
|
+
* @returns completion of the current or newly started read.
|
|
137
|
+
*/
|
|
138
|
+
refreshProjections(sessionId: SessionId): Promise<void>;
|
|
139
|
+
private agentAvailable;
|
|
140
|
+
private updateParentAvailability;
|
|
141
|
+
/** Full refresh via session.list (single-flight within one Host generation). */
|
|
142
|
+
refreshList(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Search visible session message content without adding transient query
|
|
145
|
+
* state to the list snapshot.
|
|
146
|
+
* @param query - non-blank literal phrase.
|
|
147
|
+
* @param signal - cancellation for superseded UI queries.
|
|
148
|
+
* @returns the Host result or a folded transport error.
|
|
149
|
+
*/
|
|
150
|
+
search(query: string, signal: AbortSignal): Promise<RemoteResult<{
|
|
151
|
+
items: SessionSearchResultItem[];
|
|
152
|
+
hasMore: boolean;
|
|
153
|
+
}>>;
|
|
154
|
+
/**
|
|
155
|
+
* Contract session.create; on success merge into summaries immediately (no
|
|
156
|
+
* wait for the next refresh). A created session is blank by definition
|
|
157
|
+
* (entity birth precedes the first message).
|
|
158
|
+
* @param opts - target workspace or working directory, an optional blank Session to reuse, and an optional Agent preset.
|
|
159
|
+
* @returns the create result, naming the Session the Host created or reused.
|
|
160
|
+
*/
|
|
161
|
+
create(opts?: {
|
|
162
|
+
workspaceId?: WorkspaceId;
|
|
163
|
+
cwd?: string;
|
|
164
|
+
sessionId?: SessionId;
|
|
165
|
+
agentPreset?: string;
|
|
166
|
+
}): Promise<RemoteResult<{
|
|
167
|
+
sessionId: SessionId;
|
|
168
|
+
}>>;
|
|
169
|
+
/**
|
|
170
|
+
* Contract session.fork; on success merge the child into summaries
|
|
171
|
+
* immediately (same synchronous-addressability guarantee as create).
|
|
172
|
+
* Blankness starts provisionally true so the authoritative Host summary can
|
|
173
|
+
* preserve it or lower it after an exact cut before the first `turn/start`;
|
|
174
|
+
* lineage rides parentSessionId. A child published before Workspace
|
|
175
|
+
* attachment fails is also reconciled into the list.
|
|
176
|
+
* @param opts - source session, optional exact inclusive boundary seq, and permission to start migration.
|
|
177
|
+
* @returns the fork result (the child session id).
|
|
178
|
+
*/
|
|
179
|
+
fork(opts: {
|
|
180
|
+
sessionId: SessionId;
|
|
181
|
+
atSeq?: SessionSeq;
|
|
182
|
+
allowMigration?: boolean;
|
|
183
|
+
}): Promise<RemoteResult<{
|
|
184
|
+
sessionId: SessionId;
|
|
185
|
+
}>>;
|
|
186
|
+
/**
|
|
187
|
+
* Rename a Session and update its title projection without opening its history.
|
|
188
|
+
* @param sessionId - Session to rename.
|
|
189
|
+
* @param title - raw title text for Host normalization.
|
|
190
|
+
* @returns the accepted title and event position, or the Remote failure.
|
|
191
|
+
*/
|
|
192
|
+
rename(sessionId: SessionId, title: string): Promise<RemoteResult<SessionRenameValue>>;
|
|
193
|
+
/**
|
|
194
|
+
* Merge a Host summary, replacing live state and filling missing metadata.
|
|
195
|
+
* Local create/fork placeholders only fill metadata on an existing row.
|
|
196
|
+
*/
|
|
197
|
+
private mergeSummary;
|
|
198
|
+
/** Apply immediately and retain for replay when a list response is in flight. */
|
|
199
|
+
private recordMutation;
|
|
200
|
+
/**
|
|
201
|
+
* uSES subscription entry for useSessionList.
|
|
202
|
+
* @param listener - change callback.
|
|
203
|
+
* @returns the unsubscribe function.
|
|
204
|
+
*/
|
|
205
|
+
subscribe(listener: () => void): () => void;
|
|
206
|
+
/**
|
|
207
|
+
* Cached list snapshot (rebuilt lazily when dirty with no listeners).
|
|
208
|
+
* @returns the cached reference (stable until the next flush).
|
|
209
|
+
*/
|
|
210
|
+
getListSnapshot(): SessionListSnapshot;
|
|
211
|
+
/**
|
|
212
|
+
* Read cached projection values for a Session that may exist only in a loaded subagent catalog.
|
|
213
|
+
* @param sessionId - Session whose control or history baseline supplied projections.
|
|
214
|
+
* @returns current values, or undefined before any projection store exists.
|
|
215
|
+
*/
|
|
216
|
+
projectionValues(sessionId: SessionId): Readonly<Partial<SessionProjectionMap>> | undefined;
|
|
217
|
+
/**
|
|
218
|
+
* Apply a complete control baseline or one later replacement frame.
|
|
219
|
+
* @param frame - baseline or live control replacement from Session Controller.
|
|
220
|
+
*/
|
|
221
|
+
handleControlFrame(frame: SessionControlFrame): void;
|
|
222
|
+
private replaceControlBaseline;
|
|
223
|
+
/**
|
|
224
|
+
* Apply one Session-list addition forwarded through `ctx.remote.$on`.
|
|
225
|
+
* @param summary - current Host summary for the added Session.
|
|
226
|
+
*/
|
|
227
|
+
handleSessionAdded(summary: SessionSummary): void;
|
|
228
|
+
/**
|
|
229
|
+
* Merge one list-surface projection block by the sequence space it declares.
|
|
230
|
+
* A `sequenced` block came from the Host's live registry for an attached
|
|
231
|
+
* Session, so each key lands under higher-seq-wins against that Session's
|
|
232
|
+
* baselines and frames. A `cached` block was viewed from the persisted
|
|
233
|
+
* checkpoint by a header-only listing: its watermark is not comparable with
|
|
234
|
+
* this connection's seqs, so it only fills keys no sequenced row holds.
|
|
235
|
+
*/
|
|
236
|
+
private applyListBlock;
|
|
237
|
+
/**
|
|
238
|
+
* Apply one Session removal forwarded through `ctx.remote.$on`.
|
|
239
|
+
* @param sessionId - removed Session identity.
|
|
240
|
+
*/
|
|
241
|
+
handleSessionRemoved(sessionId: SessionId): void;
|
|
242
|
+
/**
|
|
243
|
+
* Apply one live Agent running-state change.
|
|
244
|
+
* @param sessionId - Session whose Agent state changed.
|
|
245
|
+
* @param running - current Agent running state.
|
|
246
|
+
*/
|
|
247
|
+
handleSessionStatus(sessionId: SessionId, running: boolean): void;
|
|
248
|
+
/**
|
|
249
|
+
* Advance Session-list activity from one user-authored durable message.
|
|
250
|
+
* @param sessionId - Session whose activity changed.
|
|
251
|
+
* @param updatedAt - durable message timestamp.
|
|
252
|
+
*/
|
|
253
|
+
handleSessionActivity(sessionId: SessionId, updatedAt: number): void;
|
|
254
|
+
/**
|
|
255
|
+
* Surface one live Agent failure on an already-materialized Session.
|
|
256
|
+
* @param sessionId - Session whose Agent failed.
|
|
257
|
+
* @param message - caller-visible failure description.
|
|
258
|
+
*/
|
|
259
|
+
handleSessionError(sessionId: SessionId, message: string): void;
|
|
260
|
+
/**
|
|
261
|
+
* Repair one re-established Host-event generation with queryable baselines.
|
|
262
|
+
* Discard old projection cuts before new queries, including cold Sessions
|
|
263
|
+
* absent from the process-local control baseline.
|
|
264
|
+
* Opened Session follow streams resume independently through API Gateway.
|
|
265
|
+
*/
|
|
266
|
+
handleConnected(): void;
|
|
267
|
+
private buildListSnapshot;
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=manager.d.ts.map
|