@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,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batches structural updates in microtasks and stream updates by animation
|
|
3
|
+
* frame. Reads may rebuild a dirty snapshot without consuming the pending
|
|
4
|
+
* subscriber notification.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Notifier {
|
|
7
|
+
private readonly rebuild;
|
|
8
|
+
private listeners;
|
|
9
|
+
private dirty;
|
|
10
|
+
private notifyPending;
|
|
11
|
+
private scheduled;
|
|
12
|
+
private scheduleGeneration;
|
|
13
|
+
/** @param rebuild - snapshot rebuild function injected by the owner (writes the owner's snapshotCache). */
|
|
14
|
+
constructor(rebuild: () => void);
|
|
15
|
+
/**
|
|
16
|
+
* uSES subscription entry.
|
|
17
|
+
* @param listener - change callback.
|
|
18
|
+
* @returns the unsubscribe function.
|
|
19
|
+
*/
|
|
20
|
+
subscribe(listener: () => void): () => void;
|
|
21
|
+
/** Mark the snapshot dirty and notify in a microtask. */
|
|
22
|
+
markDirty(): void;
|
|
23
|
+
/** Mark the snapshot dirty and publish cumulative state at most once per frame. */
|
|
24
|
+
markFrameDirty(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Synchronous flush: controlled-input writes must notify in the same tick as
|
|
27
|
+
* onChange, or React rolls the DOM back to the stale value and the caret jumps to the end.
|
|
28
|
+
*/
|
|
29
|
+
notifyNow(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Pre-getSnapshot check: rebuild synchronously when dirty (read path
|
|
32
|
+
* before first subscribe / while unobserved). Notification stays pending.
|
|
33
|
+
*/
|
|
34
|
+
ensureFresh(): void;
|
|
35
|
+
private schedule;
|
|
36
|
+
private invalidateSchedule;
|
|
37
|
+
private flush;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=notifier.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { notifySubscribers } from '@unieai/rabi-client-store';
|
|
2
|
+
/**
|
|
3
|
+
* Batches structural updates in microtasks and stream updates by animation
|
|
4
|
+
* frame. Reads may rebuild a dirty snapshot without consuming the pending
|
|
5
|
+
* subscriber notification.
|
|
6
|
+
*/
|
|
7
|
+
export class Notifier {
|
|
8
|
+
rebuild;
|
|
9
|
+
listeners = new Set();
|
|
10
|
+
dirty = false;
|
|
11
|
+
notifyPending = false;
|
|
12
|
+
scheduled = 'none';
|
|
13
|
+
scheduleGeneration = 0;
|
|
14
|
+
/** @param rebuild - snapshot rebuild function injected by the owner (writes the owner's snapshotCache). */
|
|
15
|
+
constructor(rebuild) {
|
|
16
|
+
this.rebuild = rebuild;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* uSES subscription entry.
|
|
20
|
+
* @param listener - change callback.
|
|
21
|
+
* @returns the unsubscribe function.
|
|
22
|
+
*/
|
|
23
|
+
subscribe(listener) {
|
|
24
|
+
this.listeners.add(listener);
|
|
25
|
+
return () => {
|
|
26
|
+
this.listeners.delete(listener);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Mark the snapshot dirty and notify in a microtask. */
|
|
30
|
+
markDirty() {
|
|
31
|
+
this.dirty = true;
|
|
32
|
+
this.notifyPending = true;
|
|
33
|
+
if (this.scheduled === 'microtask')
|
|
34
|
+
return;
|
|
35
|
+
this.schedule('microtask');
|
|
36
|
+
}
|
|
37
|
+
/** Mark the snapshot dirty and publish cumulative state at most once per frame. */
|
|
38
|
+
markFrameDirty() {
|
|
39
|
+
this.dirty = true;
|
|
40
|
+
this.notifyPending = true;
|
|
41
|
+
if (this.scheduled !== 'none')
|
|
42
|
+
return;
|
|
43
|
+
this.schedule(typeof globalThis.requestAnimationFrame === 'function' ? 'frame' : 'microtask');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Synchronous flush: controlled-input writes must notify in the same tick as
|
|
47
|
+
* onChange, or React rolls the DOM back to the stale value and the caret jumps to the end.
|
|
48
|
+
*/
|
|
49
|
+
notifyNow() {
|
|
50
|
+
this.dirty = true;
|
|
51
|
+
this.notifyPending = true;
|
|
52
|
+
this.invalidateSchedule();
|
|
53
|
+
this.flush();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Pre-getSnapshot check: rebuild synchronously when dirty (read path
|
|
57
|
+
* before first subscribe / while unobserved). Notification stays pending.
|
|
58
|
+
*/
|
|
59
|
+
ensureFresh() {
|
|
60
|
+
if (!this.dirty)
|
|
61
|
+
return;
|
|
62
|
+
this.dirty = false;
|
|
63
|
+
this.rebuild();
|
|
64
|
+
}
|
|
65
|
+
schedule(kind) {
|
|
66
|
+
const generation = ++this.scheduleGeneration;
|
|
67
|
+
this.scheduled = kind;
|
|
68
|
+
const publish = () => {
|
|
69
|
+
if (generation !== this.scheduleGeneration)
|
|
70
|
+
return;
|
|
71
|
+
this.scheduled = 'none';
|
|
72
|
+
this.flush();
|
|
73
|
+
};
|
|
74
|
+
if (kind === 'frame') {
|
|
75
|
+
globalThis.requestAnimationFrame(publish);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
queueMicrotask(publish);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
invalidateSchedule() {
|
|
82
|
+
this.scheduleGeneration++;
|
|
83
|
+
this.scheduled = 'none';
|
|
84
|
+
}
|
|
85
|
+
flush() {
|
|
86
|
+
if (!this.notifyPending)
|
|
87
|
+
return;
|
|
88
|
+
if (this.listeners.size === 0)
|
|
89
|
+
return; // lazy: dirty (if still set) rebuilds on next getSnapshot
|
|
90
|
+
this.notifyPending = false;
|
|
91
|
+
if (this.dirty) {
|
|
92
|
+
this.dirty = false;
|
|
93
|
+
this.rebuild();
|
|
94
|
+
}
|
|
95
|
+
notifySubscribers(this.listeners, '[session-controller]');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic per-session projection value store (push model; see the
|
|
3
|
+
* session-projection subsystem page, docs/subsystems/session-projection.md):
|
|
4
|
+
* the host is the only computation site; the client holds finished whole
|
|
5
|
+
* values per key in one of two row kinds. A `sequenced` row
|
|
6
|
+
* (`{ value, seq }`) comes from the connected Host — a follow opening
|
|
7
|
+
* baseline, a Session Controller `projection` frame, a list block the Host
|
|
8
|
+
* computed for an attached Session — and merges under **higher seq wins**
|
|
9
|
+
* against other sequenced rows. A `cached` row (`{ value }`) comes from
|
|
10
|
+
* a Host view of the persisted checkpoint, carries no comparable
|
|
11
|
+
* seq, and yields to every sequenced write. No client-side domain folding
|
|
12
|
+
* exists: a domain ships projection support with zero client code. Per-key
|
|
13
|
+
* bare observable faces feed `useProjection` (ui-renderer binds them).
|
|
14
|
+
*/
|
|
15
|
+
import type { SessionProjectionMap } from '@unieai/rabi-session-projection/types';
|
|
16
|
+
import type { SessionSeqCursor } from '@unieai/rabi-session/types';
|
|
17
|
+
import type { ObservableSnapshot } from '@unieai/rabi-client-store';
|
|
18
|
+
export type { SessionProjectionMap } from '@unieai/rabi-session-projection/types';
|
|
19
|
+
/**
|
|
20
|
+
* The fifth framework hook seat (see the session-projection subsystem page,
|
|
21
|
+
* docs/subsystems/session-projection.md): key-addressed
|
|
22
|
+
* projection reader delivered through the standard kit. `undefined` uniformly
|
|
23
|
+
* means capability absent — host unit unmounted, or no baseline/frame has
|
|
24
|
+
* carried the key yet. The selector overload mirrors useSession (per-key uSES
|
|
25
|
+
* binding; reference stability holds because a key's value reference changes
|
|
26
|
+
* only when a frame or baseline lands).
|
|
27
|
+
*/
|
|
28
|
+
export type UseProjection = {
|
|
29
|
+
<K extends Extract<keyof SessionProjectionMap, string>>(key: K): SessionProjectionMap[K] | undefined;
|
|
30
|
+
<K extends Extract<keyof SessionProjectionMap, string>, S>(key: K, selector: (value: SessionProjectionMap[K] | undefined) => S, eq?: (a: S, b: S) => boolean): S;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Follow-opening projection baseline, restated here so the
|
|
34
|
+
* React-free store depends only on the type table, not the wire package's
|
|
35
|
+
* response vocabulary.
|
|
36
|
+
*/
|
|
37
|
+
export interface ProjectionsBaseline {
|
|
38
|
+
/** The consistent-cut seq (equals the window tail seq by construction). */
|
|
39
|
+
asOfSeq: SessionSeqCursor;
|
|
40
|
+
/** Whole current values by key; a registered key absent here means the capability is absent. */
|
|
41
|
+
values: Readonly<Record<string, unknown>>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One session's projection values. Framework semantics, uniform across every
|
|
45
|
+
* key. Sequenced writes (a baseline seeds rows at its cut, a push frame
|
|
46
|
+
* updates one row) compare seqs among themselves: a lower-or-equal seq within
|
|
47
|
+
* the Host generation loses, so a replayed frame cannot regress a value and a
|
|
48
|
+
* stale baseline cannot overwrite a newer frame. Cached writes (the session
|
|
49
|
+
* list's zero-I/O block) only fill keys no sequenced row holds, and a baseline
|
|
50
|
+
* discards every cached row before it seeds, regardless of seq: the connected
|
|
51
|
+
* Session is the truth and a cached value never outranks it. A key the store
|
|
52
|
+
* has never seen reads `undefined` (capability absent). Faces are identity-stable
|
|
53
|
+
* per key (create-on-demand, cached) so the React side binds each exactly
|
|
54
|
+
* once; the store-level channel (`subscribeAny`) serves coarse consumers (the
|
|
55
|
+
* manager's list projection reads the `title` key).
|
|
56
|
+
*/
|
|
57
|
+
export declare class ProjectionValueStore {
|
|
58
|
+
private readonly rows;
|
|
59
|
+
private readonly channels;
|
|
60
|
+
private valuesCache;
|
|
61
|
+
/** Coarse any-key channel (no snapshot cache to rebuild: reads hit rows directly). */
|
|
62
|
+
private readonly anyNotifier;
|
|
63
|
+
/**
|
|
64
|
+
* Key-addressed bare observable face (the useProjection resolution path).
|
|
65
|
+
* Always defined — absence is an `undefined` snapshot, never a missing
|
|
66
|
+
* face, so a component may subscribe before the key ever carries a value.
|
|
67
|
+
* @param key - projection key.
|
|
68
|
+
* @returns the identity-stable face for this key.
|
|
69
|
+
*/
|
|
70
|
+
faceOf(key: string): ObservableSnapshot<unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Current whole value for a key (erased framework read; typed reads go
|
|
73
|
+
* through `useProjection`'s map lookup).
|
|
74
|
+
* @param key - projection key.
|
|
75
|
+
* @returns the value, or undefined while the key is absent.
|
|
76
|
+
*/
|
|
77
|
+
get(key: string): unknown;
|
|
78
|
+
/**
|
|
79
|
+
* Read the accepted Host watermark without subscribing or copying a value.
|
|
80
|
+
* @param key - projection key.
|
|
81
|
+
* @returns the current sequence, or undefined for absent and cached values.
|
|
82
|
+
*/
|
|
83
|
+
seqOf(key: string): SessionSeqCursor | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Read every current projection value as one reference-stable snapshot.
|
|
86
|
+
* @returns The same frozen value map until a row changes.
|
|
87
|
+
*/
|
|
88
|
+
values(): Readonly<Partial<SessionProjectionMap>>;
|
|
89
|
+
/**
|
|
90
|
+
* Subscribe to any-key changes (microtask-batched) — the manager's list
|
|
91
|
+
* rebuild channel.
|
|
92
|
+
* @param listener - change callback.
|
|
93
|
+
* @returns the unsubscribe function.
|
|
94
|
+
*/
|
|
95
|
+
subscribeAny(listener: () => void): () => void;
|
|
96
|
+
/**
|
|
97
|
+
* Apply one finished value from the Session control stream.
|
|
98
|
+
* @param key - projection key.
|
|
99
|
+
* @param value - whole value computed by the host unit.
|
|
100
|
+
* @param seq - the unit's watermark at emission.
|
|
101
|
+
*/
|
|
102
|
+
apply(key: string, value: unknown, seq: SessionSeqCursor): void;
|
|
103
|
+
/**
|
|
104
|
+
* Fill keys from a Host block labeled `cached`: a zero-I/O
|
|
105
|
+
* view of the persisted checkpoint. A cached value lands only where no
|
|
106
|
+
* sequenced row exists: a connected Session has already answered for such
|
|
107
|
+
* a key, and the list's view of the persisted checkpoint cannot be newer
|
|
108
|
+
* than it.
|
|
109
|
+
* @param values - whole values by key viewed from the persisted checkpoint.
|
|
110
|
+
*/
|
|
111
|
+
applyCached(values: Readonly<Record<string, unknown>>): void;
|
|
112
|
+
/**
|
|
113
|
+
* Seed from a history tail page's projections block. Every cached row is
|
|
114
|
+
* discarded first, regardless of seq: the block comes from the connected
|
|
115
|
+
* Session, and a value viewed from the persisted checkpoint never outranks
|
|
116
|
+
* it. Then every carried key lands under the same seq rule as frames, and a
|
|
117
|
+
* key the block omits is capability-absent as of the cut — its row clears
|
|
118
|
+
* unless a newer frame already superseded the cut (a stale baseline can
|
|
119
|
+
* neither overwrite nor clear newer sequenced values).
|
|
120
|
+
* @param baseline - the response's projections block.
|
|
121
|
+
*/
|
|
122
|
+
seed(baseline: ProjectionsBaseline): void;
|
|
123
|
+
/** Discard one Host generation's values and watermarks while preserving subscribed faces. */
|
|
124
|
+
clear(): void;
|
|
125
|
+
private changed;
|
|
126
|
+
private channel;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=projection-store.d.ts.map
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Notifier } from "./notifier.js";
|
|
2
|
+
/**
|
|
3
|
+
* One session's projection values. Framework semantics, uniform across every
|
|
4
|
+
* key. Sequenced writes (a baseline seeds rows at its cut, a push frame
|
|
5
|
+
* updates one row) compare seqs among themselves: a lower-or-equal seq within
|
|
6
|
+
* the Host generation loses, so a replayed frame cannot regress a value and a
|
|
7
|
+
* stale baseline cannot overwrite a newer frame. Cached writes (the session
|
|
8
|
+
* list's zero-I/O block) only fill keys no sequenced row holds, and a baseline
|
|
9
|
+
* discards every cached row before it seeds, regardless of seq: the connected
|
|
10
|
+
* Session is the truth and a cached value never outranks it. A key the store
|
|
11
|
+
* has never seen reads `undefined` (capability absent). Faces are identity-stable
|
|
12
|
+
* per key (create-on-demand, cached) so the React side binds each exactly
|
|
13
|
+
* once; the store-level channel (`subscribeAny`) serves coarse consumers (the
|
|
14
|
+
* manager's list projection reads the `title` key).
|
|
15
|
+
*/
|
|
16
|
+
export class ProjectionValueStore {
|
|
17
|
+
rows = new Map();
|
|
18
|
+
channels = new Map();
|
|
19
|
+
valuesCache;
|
|
20
|
+
/** Coarse any-key channel (no snapshot cache to rebuild: reads hit rows directly). */
|
|
21
|
+
anyNotifier = new Notifier(() => { });
|
|
22
|
+
/**
|
|
23
|
+
* Key-addressed bare observable face (the useProjection resolution path).
|
|
24
|
+
* Always defined — absence is an `undefined` snapshot, never a missing
|
|
25
|
+
* face, so a component may subscribe before the key ever carries a value.
|
|
26
|
+
* @param key - projection key.
|
|
27
|
+
* @returns the identity-stable face for this key.
|
|
28
|
+
*/
|
|
29
|
+
faceOf(key) {
|
|
30
|
+
return this.channel(key).face;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Current whole value for a key (erased framework read; typed reads go
|
|
34
|
+
* through `useProjection`'s map lookup).
|
|
35
|
+
* @param key - projection key.
|
|
36
|
+
* @returns the value, or undefined while the key is absent.
|
|
37
|
+
*/
|
|
38
|
+
get(key) {
|
|
39
|
+
return this.rows.get(key)?.value;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Read the accepted Host watermark without subscribing or copying a value.
|
|
43
|
+
* @param key - projection key.
|
|
44
|
+
* @returns the current sequence, or undefined for absent and cached values.
|
|
45
|
+
*/
|
|
46
|
+
seqOf(key) {
|
|
47
|
+
const row = this.rows.get(key);
|
|
48
|
+
return row?.kind === 'sequenced' ? row.seq : undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read every current projection value as one reference-stable snapshot.
|
|
52
|
+
* @returns The same frozen value map until a row changes.
|
|
53
|
+
*/
|
|
54
|
+
values() {
|
|
55
|
+
if (this.valuesCache === undefined) {
|
|
56
|
+
this.valuesCache = Object.freeze(Object.fromEntries([...this.rows].map(([key, row]) => [key, row.value])));
|
|
57
|
+
}
|
|
58
|
+
return this.valuesCache;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Subscribe to any-key changes (microtask-batched) — the manager's list
|
|
62
|
+
* rebuild channel.
|
|
63
|
+
* @param listener - change callback.
|
|
64
|
+
* @returns the unsubscribe function.
|
|
65
|
+
*/
|
|
66
|
+
subscribeAny(listener) {
|
|
67
|
+
return this.anyNotifier.subscribe(listener);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Apply one finished value from the Session control stream.
|
|
71
|
+
* @param key - projection key.
|
|
72
|
+
* @param value - whole value computed by the host unit.
|
|
73
|
+
* @param seq - the unit's watermark at emission.
|
|
74
|
+
*/
|
|
75
|
+
apply(key, value, seq) {
|
|
76
|
+
const row = this.rows.get(key);
|
|
77
|
+
// higher seq wins among sequenced rows; replays and stale frames drop. A
|
|
78
|
+
// cached row has no comparable seq and always yields.
|
|
79
|
+
if (row?.kind === 'sequenced' && seq <= row.seq)
|
|
80
|
+
return;
|
|
81
|
+
this.rows.set(key, { kind: 'sequenced', value, seq });
|
|
82
|
+
this.changed(key);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Fill keys from a Host block labeled `cached`: a zero-I/O
|
|
86
|
+
* view of the persisted checkpoint. A cached value lands only where no
|
|
87
|
+
* sequenced row exists: a connected Session has already answered for such
|
|
88
|
+
* a key, and the list's view of the persisted checkpoint cannot be newer
|
|
89
|
+
* than it.
|
|
90
|
+
* @param values - whole values by key viewed from the persisted checkpoint.
|
|
91
|
+
*/
|
|
92
|
+
applyCached(values) {
|
|
93
|
+
for (const key of Object.keys(values)) {
|
|
94
|
+
if (this.rows.get(key)?.kind === 'sequenced')
|
|
95
|
+
continue;
|
|
96
|
+
this.rows.set(key, { kind: 'cached', value: values[key] });
|
|
97
|
+
this.changed(key);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Seed from a history tail page's projections block. Every cached row is
|
|
102
|
+
* discarded first, regardless of seq: the block comes from the connected
|
|
103
|
+
* Session, and a value viewed from the persisted checkpoint never outranks
|
|
104
|
+
* it. Then every carried key lands under the same seq rule as frames, and a
|
|
105
|
+
* key the block omits is capability-absent as of the cut — its row clears
|
|
106
|
+
* unless a newer frame already superseded the cut (a stale baseline can
|
|
107
|
+
* neither overwrite nor clear newer sequenced values).
|
|
108
|
+
* @param baseline - the response's projections block.
|
|
109
|
+
*/
|
|
110
|
+
seed(baseline) {
|
|
111
|
+
for (const [key, row] of this.rows) {
|
|
112
|
+
if (row.kind !== 'cached')
|
|
113
|
+
continue;
|
|
114
|
+
this.rows.delete(key);
|
|
115
|
+
this.changed(key);
|
|
116
|
+
}
|
|
117
|
+
// Erased walk: the framework crosses the open key space; per-key typing
|
|
118
|
+
// is re-established at the consumer (useProjection's map lookup).
|
|
119
|
+
const values = baseline.values;
|
|
120
|
+
for (const key of Object.keys(values))
|
|
121
|
+
this.apply(key, values[key], baseline.asOfSeq);
|
|
122
|
+
for (const [key, row] of this.rows) {
|
|
123
|
+
if (Object.hasOwn(values, key))
|
|
124
|
+
continue;
|
|
125
|
+
// Every cached row was deleted above; the kind test only narrows the
|
|
126
|
+
// type so `row.seq` is readable.
|
|
127
|
+
if (row.kind === 'sequenced' && row.seq > baseline.asOfSeq)
|
|
128
|
+
continue;
|
|
129
|
+
this.rows.delete(key);
|
|
130
|
+
this.changed(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Discard one Host generation's values and watermarks while preserving subscribed faces. */
|
|
134
|
+
clear() {
|
|
135
|
+
for (const key of this.rows.keys()) {
|
|
136
|
+
this.rows.delete(key);
|
|
137
|
+
this.changed(key);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
changed(key) {
|
|
141
|
+
this.valuesCache = undefined;
|
|
142
|
+
this.channels.get(key)?.notifier.markDirty();
|
|
143
|
+
this.anyNotifier.markDirty();
|
|
144
|
+
}
|
|
145
|
+
channel(key) {
|
|
146
|
+
let channel = this.channels.get(key);
|
|
147
|
+
if (channel === undefined) {
|
|
148
|
+
// The notifier only batches (no snapshot cache to rebuild: faces read rows directly).
|
|
149
|
+
const notifier = new Notifier(() => { });
|
|
150
|
+
channel = {
|
|
151
|
+
notifier,
|
|
152
|
+
face: {
|
|
153
|
+
getSnapshot: () => this.rows.get(key)?.value,
|
|
154
|
+
subscribe: listener => notifier.subscribe(listener),
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
this.channels.set(key, channel);
|
|
158
|
+
}
|
|
159
|
+
return channel;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote namespaces the Session cluster calls. One parameter for one concept:
|
|
3
|
+
* the generated surface a Session and its manager reach the Host through.
|
|
4
|
+
*
|
|
5
|
+
* @module @unieai/rabi-api-session-controller/client/sessions/remotes
|
|
6
|
+
*/
|
|
7
|
+
import type { ClientRemote } from '@unieai/rabi-api-gateway/client';
|
|
8
|
+
import type { CommandSubmitAttachment } from '@unieai/rabi-commands/types';
|
|
9
|
+
import type { SessionId } from '@unieai/rabi-session/types';
|
|
10
|
+
import type { SubagentInterruptReceipt, SubagentPromptReceipt, SubagentPromptRequest } from '@unieai/rabi-subagent/client';
|
|
11
|
+
import type { RemoteResult } from '@unieai/rabi-typert-protocol';
|
|
12
|
+
import type { SessionRemote } from '../transport.ts';
|
|
13
|
+
/** Narrow Commands namespace consumed by a Client Session. */
|
|
14
|
+
export interface SessionCommandsRemote {
|
|
15
|
+
execute(agentId: SessionId, line: string, attachments: readonly CommandSubmitAttachment[], signal?: AbortSignal): Promise<RemoteResult<object | undefined>>;
|
|
16
|
+
}
|
|
17
|
+
/** Narrow subagent namespace consumed by a Client Session and its manager. */
|
|
18
|
+
export interface SessionSubagentsRemote {
|
|
19
|
+
prompt(request: SubagentPromptRequest, signal?: AbortSignal): Promise<RemoteResult<SubagentPromptReceipt>>;
|
|
20
|
+
interruptByUser(childSessionId: SessionId): Promise<RemoteResult<SubagentInterruptReceipt>>;
|
|
21
|
+
}
|
|
22
|
+
/** Generated Remote namespaces consumed by the Client Session object layer. */
|
|
23
|
+
export interface SessionRemotes {
|
|
24
|
+
readonly $stream: ClientRemote['$stream'];
|
|
25
|
+
readonly commands: SessionCommandsRemote;
|
|
26
|
+
readonly session: SessionRemote;
|
|
27
|
+
readonly subagents: SessionSubagentsRemote;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=remotes.d.ts.map
|