@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,111 @@
|
|
|
1
|
+
/** Coalesced Session state observations with Host-local revisions. */
|
|
2
|
+
/** Coalesces Session/Agent invalidations with local revisions; pending events are sampled on reads. */
|
|
3
|
+
export class StateListener {
|
|
4
|
+
readState;
|
|
5
|
+
disposes = [];
|
|
6
|
+
cancellation = new AbortController();
|
|
7
|
+
signal;
|
|
8
|
+
revision = 0;
|
|
9
|
+
resolver = createDeferredSignal();
|
|
10
|
+
closed = false;
|
|
11
|
+
/**
|
|
12
|
+
* @param ctx - lifecycle notification owner.
|
|
13
|
+
* @param target - Session to observe.
|
|
14
|
+
* @param signal - caller cancellation.
|
|
15
|
+
* @param readState - passive complete-state reader.
|
|
16
|
+
*/
|
|
17
|
+
constructor(ctx, target, signal, readState) {
|
|
18
|
+
this.readState = readState;
|
|
19
|
+
signal.throwIfAborted();
|
|
20
|
+
this.signal = AbortSignal.any([signal, this.cancellation.signal]);
|
|
21
|
+
const notify = (id) => {
|
|
22
|
+
if (id !== target || this.closed)
|
|
23
|
+
return;
|
|
24
|
+
this.revision++;
|
|
25
|
+
const resolver = this.resolver;
|
|
26
|
+
this.resolver = createDeferredSignal();
|
|
27
|
+
resolver.resolve();
|
|
28
|
+
};
|
|
29
|
+
const close = () => { this[Symbol.dispose](); };
|
|
30
|
+
signal.addEventListener('abort', close, { once: true });
|
|
31
|
+
this.disposes.push(() => { signal.removeEventListener('abort', close); });
|
|
32
|
+
try {
|
|
33
|
+
this.disposes.push(ctx.on('session/event', (session) => { notify(session.id); }, { global: true }));
|
|
34
|
+
this.disposes.push(ctx.on('session/created', (session) => { notify(session.id); }, { global: true }));
|
|
35
|
+
this.disposes.push(ctx.on('session/disposed', (session) => { notify(session.id); }, { global: true }));
|
|
36
|
+
this.disposes.push(ctx.on('agent/status', ({ agent }) => { notify(agent.id); }, { global: true }));
|
|
37
|
+
this.disposes.push(ctx.on('agent/created', ({ agent }) => { notify(agent.id); }, { global: true }));
|
|
38
|
+
this.disposes.push(ctx.on('agent/disposed', ({ agent }) => { notify(agent.id); }, { global: true }));
|
|
39
|
+
const dispose = ctx.effect(() => close, 'session-controller.state-listener');
|
|
40
|
+
this.disposes.push(() => { void dispose(); });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
this[Symbol.dispose]();
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check whether a completed read still represents the latest invalidation.
|
|
49
|
+
* @param revision - revision captured with a completed read.
|
|
50
|
+
* @returns whether no intervening invalidation occurred.
|
|
51
|
+
*/
|
|
52
|
+
isCurrent(revision) { return !this.closed && revision === this.revision; }
|
|
53
|
+
/**
|
|
54
|
+
* Read coalesced state replacements with optional periodic refresh.
|
|
55
|
+
* @param refreshMs - optional idle recheck interval; omitted for event-only observation.
|
|
56
|
+
* @returns complete state replacements with internal consistency revisions.
|
|
57
|
+
*/
|
|
58
|
+
async *observeStates(refreshMs) {
|
|
59
|
+
let lastRevision = -1;
|
|
60
|
+
try {
|
|
61
|
+
while (!this.closed) {
|
|
62
|
+
if (lastRevision === this.revision) {
|
|
63
|
+
if (refreshMs === undefined) {
|
|
64
|
+
await this.resolver.promise;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
let timer;
|
|
68
|
+
try {
|
|
69
|
+
await Promise.race([
|
|
70
|
+
this.resolver.promise,
|
|
71
|
+
new Promise((resolve) => { timer = setTimeout(resolve, refreshMs); }),
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
}
|
|
77
|
+
if (this.isCurrent(lastRevision)) {
|
|
78
|
+
this.revision++;
|
|
79
|
+
const resolver = this.resolver;
|
|
80
|
+
this.resolver = createDeferredSignal();
|
|
81
|
+
resolver.resolve();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!this.isCurrent(this.revision))
|
|
86
|
+
return;
|
|
87
|
+
lastRevision = this.revision;
|
|
88
|
+
const state = await this.readState(this.signal);
|
|
89
|
+
if (this.isCurrent(lastRevision))
|
|
90
|
+
yield { state, revision: lastRevision };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
this[Symbol.dispose]();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
[Symbol.dispose]() {
|
|
98
|
+
if (this.closed)
|
|
99
|
+
return;
|
|
100
|
+
this.closed = true;
|
|
101
|
+
this.cancellation.abort();
|
|
102
|
+
this.resolver.resolve();
|
|
103
|
+
for (const dispose of this.disposes.splice(0).reverse())
|
|
104
|
+
dispose();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function createDeferredSignal() {
|
|
108
|
+
let resolve;
|
|
109
|
+
const promise = new Promise((settle) => { resolve = settle; });
|
|
110
|
+
return { promise, resolve };
|
|
111
|
+
}
|