@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,106 @@
|
|
|
1
|
+
/** Live Session projection state with reconnect baselines. */
|
|
2
|
+
import { Deque } from '@unieai/rabi-deque';
|
|
3
|
+
/** Owns the Host-wide Session control stream. */
|
|
4
|
+
export class SessionControlController {
|
|
5
|
+
ctx;
|
|
6
|
+
streams = new Set();
|
|
7
|
+
/** @param ctx - Host context carrying live Agent and projection services. */
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this.ctx = ctx;
|
|
10
|
+
ctx.sessionProjections.onEventChanged((session, changes, seq) => {
|
|
11
|
+
this.broadcast({
|
|
12
|
+
type: 'projection',
|
|
13
|
+
sessionId: session.id,
|
|
14
|
+
seq,
|
|
15
|
+
// Every projection definition validates its value before change publication.
|
|
16
|
+
changes: changes,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
ctx.effect(() => () => {
|
|
20
|
+
for (const stream of this.streams)
|
|
21
|
+
stream.end();
|
|
22
|
+
this.streams.clear();
|
|
23
|
+
}, 'session-controller.control');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Open one generation of Host-wide live control state.
|
|
27
|
+
* @param signal - Remote stream cancellation.
|
|
28
|
+
* @returns one complete baseline followed by live replacement frames.
|
|
29
|
+
*/
|
|
30
|
+
async *control(signal) {
|
|
31
|
+
signal.throwIfAborted();
|
|
32
|
+
const queue = new ControlQueue();
|
|
33
|
+
this.streams.add(queue);
|
|
34
|
+
try {
|
|
35
|
+
yield { type: 'baseline', value: this.baseline() };
|
|
36
|
+
yield* queue.iterate(signal);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
this.streams.delete(queue);
|
|
40
|
+
queue.end();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
baseline() {
|
|
44
|
+
const sessions = this.ctx.sessions.list();
|
|
45
|
+
return {
|
|
46
|
+
projections: this.projectionBaseline(sessions),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
projectionBaseline(sessions) {
|
|
50
|
+
const blocks = Object.create(null);
|
|
51
|
+
for (const session of sessions) {
|
|
52
|
+
const snapshot = this.ctx.sessionProjections.snapshot(session);
|
|
53
|
+
blocks[session.id] = {
|
|
54
|
+
asOfSeq: snapshot.asOfSeq,
|
|
55
|
+
// Every projection definition validates its value before snapshot publication.
|
|
56
|
+
values: snapshot.values,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return blocks;
|
|
60
|
+
}
|
|
61
|
+
broadcast(frame) {
|
|
62
|
+
for (const stream of this.streams)
|
|
63
|
+
stream.push(frame);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class ControlQueue {
|
|
67
|
+
buffer = new Deque();
|
|
68
|
+
wake;
|
|
69
|
+
done = false;
|
|
70
|
+
push(frame) {
|
|
71
|
+
if (this.done)
|
|
72
|
+
return;
|
|
73
|
+
this.buffer.pushBack(frame);
|
|
74
|
+
const wake = this.wake;
|
|
75
|
+
this.wake = undefined;
|
|
76
|
+
wake?.();
|
|
77
|
+
}
|
|
78
|
+
end() {
|
|
79
|
+
if (this.done)
|
|
80
|
+
return;
|
|
81
|
+
this.done = true;
|
|
82
|
+
const wake = this.wake;
|
|
83
|
+
this.wake = undefined;
|
|
84
|
+
wake?.();
|
|
85
|
+
}
|
|
86
|
+
async *iterate(signal) {
|
|
87
|
+
const onAbort = () => { this.end(); };
|
|
88
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
89
|
+
try {
|
|
90
|
+
while (!this.done && !signal.aborted) {
|
|
91
|
+
const frame = this.buffer.popFront();
|
|
92
|
+
if (frame !== undefined) {
|
|
93
|
+
yield frame;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
await new Promise((resolve) => { this.wake = resolve; });
|
|
97
|
+
}
|
|
98
|
+
while (this.buffer.size > 0 && !signal.aborted)
|
|
99
|
+
yield this.buffer.popFront();
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
signal.removeEventListener('abort', onAbort);
|
|
103
|
+
this.end();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Session Controller adapter for Agent-scoped file-reference discovery. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
import type { Agent } from '@unieai/rabi-agent';
|
|
4
|
+
import type { FileReferenceCandidate } from '@unieai/rabi-file-reference/types';
|
|
5
|
+
import { TypertRemoteService } from '@unieai/rabi-typert-protocol';
|
|
6
|
+
declare module '@unieai/cordis' {
|
|
7
|
+
interface Context {
|
|
8
|
+
/** Host owner of the `fileReferences` Remote namespace. */
|
|
9
|
+
sessionFileReferences: SessionFileReferences;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Host Remote adapter over the composed file-reference provider. */
|
|
13
|
+
export declare class SessionFileReferences extends TypertRemoteService {
|
|
14
|
+
static inject: string[];
|
|
15
|
+
/** @param ctx - Host context carrying the selected file-reference provider. */
|
|
16
|
+
constructor(ctx: Context);
|
|
17
|
+
/**
|
|
18
|
+
* List file and directory candidates for one Agent's working directory.
|
|
19
|
+
* @param agent - target Agent resolved from the Session identity on the wire.
|
|
20
|
+
* @param query - path text following `@` or `@"`.
|
|
21
|
+
* @param signal - caller cancellation.
|
|
22
|
+
* @returns deterministic path-only candidates from the composed provider.
|
|
23
|
+
*/
|
|
24
|
+
list(agent: Agent, query: string, signal: AbortSignal): Promise<FileReferenceCandidate[]>;
|
|
25
|
+
}
|
|
26
|
+
export default SessionFileReferences;
|
|
27
|
+
//# sourceMappingURL=file-references.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Session Controller adapter for Agent-scoped file-reference discovery. */
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
36
|
+
import { Remote, TypertRemoteService } from '@unieai/rabi-typert-protocol';
|
|
37
|
+
/** Host Remote adapter over the composed file-reference provider. */
|
|
38
|
+
let SessionFileReferences = (() => {
|
|
39
|
+
let _classSuper = TypertRemoteService;
|
|
40
|
+
let _instanceExtraInitializers = [];
|
|
41
|
+
let _list_decorators;
|
|
42
|
+
return class SessionFileReferences extends _classSuper {
|
|
43
|
+
static {
|
|
44
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
45
|
+
_list_decorators = [Remote];
|
|
46
|
+
__esDecorate(this, null, _list_decorators, { kind: "method", name: "list", static: false, private: false, access: { has: obj => "list" in obj, get: obj => obj.list }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
47
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
48
|
+
}
|
|
49
|
+
static inject = ['fileReferences', 'typert'];
|
|
50
|
+
/** @param ctx - Host context carrying the selected file-reference provider. */
|
|
51
|
+
constructor(ctx) {
|
|
52
|
+
super(ctx, 'sessionFileReferences', { namespace: 'fileReferences' });
|
|
53
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* List file and directory candidates for one Agent's working directory.
|
|
57
|
+
* @param agent - target Agent resolved from the Session identity on the wire.
|
|
58
|
+
* @param query - path text following `@` or `@"`.
|
|
59
|
+
* @param signal - caller cancellation.
|
|
60
|
+
* @returns deterministic path-only candidates from the composed provider.
|
|
61
|
+
*/
|
|
62
|
+
list(agent, query, signal) {
|
|
63
|
+
return this.ctx.fileReferences.list(agent, query, signal);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
})();
|
|
67
|
+
export { SessionFileReferences };
|
|
68
|
+
export default SessionFileReferences;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Assistant stream baselines and per-connection subscriptions. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
import type { SessionId } from '@unieai/rabi-session';
|
|
4
|
+
import type { SessionAssistantStreamBaseline, SessionAssistantStreamFrame } from '../types.ts';
|
|
5
|
+
import { ListenerBuffer } from './listener.ts';
|
|
6
|
+
/** One accumulator per live Session, shared by every subscription bound to it. */
|
|
7
|
+
export declare class SessionAssistantStreamsListener {
|
|
8
|
+
private readonly ctx;
|
|
9
|
+
private readonly streams;
|
|
10
|
+
/** @param ctx - service context owning the accumulator listeners. */
|
|
11
|
+
constructor(ctx: Context);
|
|
12
|
+
/**
|
|
13
|
+
* Bind one connection to a Session assistant stream.
|
|
14
|
+
* @param sessionId - Session to subscribe.
|
|
15
|
+
* @param signal - cancellation owned by the caller.
|
|
16
|
+
* @param queue - caller-owned raw notification buffer.
|
|
17
|
+
* @returns a listener the caller disposes.
|
|
18
|
+
*/
|
|
19
|
+
bind(sessionId: SessionId, signal: AbortSignal, queue: Pick<ListenerBuffer<AssistantEntry>, 'createInput' | 'capture'>): AssistantStreamListener;
|
|
20
|
+
}
|
|
21
|
+
type AssistantEntry = {
|
|
22
|
+
type: 'assistant-stream';
|
|
23
|
+
frame: SessionAssistantStreamFrame;
|
|
24
|
+
};
|
|
25
|
+
/** Writes assistant notifications into the connection's shared queue. */
|
|
26
|
+
declare class AssistantStreamListener implements Disposable {
|
|
27
|
+
private _snapshot;
|
|
28
|
+
private readonly disposes;
|
|
29
|
+
private ordinal;
|
|
30
|
+
private cut;
|
|
31
|
+
constructor(ctx: Context, sessionId: SessionId, signal: AbortSignal, _snapshot: () => SessionAssistantStreamBaseline, output: Pick<ListenerBuffer<AssistantEntry>, 'createInput' | 'capture'>);
|
|
32
|
+
/** @returns the baseline and local arrival cut captured synchronously together. */
|
|
33
|
+
snapshot(): {
|
|
34
|
+
baseline: SessionAssistantStreamBaseline;
|
|
35
|
+
ordinal: number;
|
|
36
|
+
};
|
|
37
|
+
/** @param ordinal - local snapshot cut set before queue consumption. */
|
|
38
|
+
setOrdinalCut(ordinal: number): void;
|
|
39
|
+
private transform;
|
|
40
|
+
[Symbol.dispose](): void;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=assistant-stream.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Assistant stream baselines and per-connection subscriptions. */
|
|
2
|
+
import { SessionSeq } from '@unieai/rabi-session';
|
|
3
|
+
import { SessionAssistantStreamAccumulator } from "../assistant-stream.js";
|
|
4
|
+
/** One accumulator per live Session, shared by every subscription bound to it. */
|
|
5
|
+
export class SessionAssistantStreamsListener {
|
|
6
|
+
ctx;
|
|
7
|
+
streams = new Map();
|
|
8
|
+
/** @param ctx - service context owning the accumulator listeners. */
|
|
9
|
+
constructor(ctx) {
|
|
10
|
+
this.ctx = ctx;
|
|
11
|
+
ctx.on('agent/assistant-stream', ({ agent, frame }) => {
|
|
12
|
+
let stream = this.streams.get(agent.session.id);
|
|
13
|
+
if (stream === undefined) {
|
|
14
|
+
stream = new SessionAssistantStreamAccumulator();
|
|
15
|
+
this.streams.set(agent.session.id, stream);
|
|
16
|
+
}
|
|
17
|
+
stream.accept(frame, agent.session.seq === 0 ? -1 : SessionSeq(agent.session.seq - 1));
|
|
18
|
+
}, { global: true });
|
|
19
|
+
ctx.on('agent/disposed', ({ agent }) => { this.streams.delete(agent.session.id); }, { global: true });
|
|
20
|
+
ctx.effect(() => () => { this.streams.clear(); }, 'session-controller.assistant-streams');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Bind one connection to a Session assistant stream.
|
|
24
|
+
* @param sessionId - Session to subscribe.
|
|
25
|
+
* @param signal - cancellation owned by the caller.
|
|
26
|
+
* @param queue - caller-owned raw notification buffer.
|
|
27
|
+
* @returns a listener the caller disposes.
|
|
28
|
+
*/
|
|
29
|
+
bind(sessionId, signal, queue) {
|
|
30
|
+
return new AssistantStreamListener(this.ctx, sessionId, signal, () => {
|
|
31
|
+
return this.streams.get(sessionId)?.snapshot() ?? { revision: 0 };
|
|
32
|
+
}, queue);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Writes assistant notifications into the connection's shared queue. */
|
|
36
|
+
class AssistantStreamListener {
|
|
37
|
+
_snapshot;
|
|
38
|
+
disposes = [];
|
|
39
|
+
ordinal = 0;
|
|
40
|
+
cut = 0;
|
|
41
|
+
constructor(ctx, sessionId, signal, _snapshot, output) {
|
|
42
|
+
this._snapshot = _snapshot;
|
|
43
|
+
signal.throwIfAborted();
|
|
44
|
+
const input = output.createInput(item => this.transform(item));
|
|
45
|
+
try {
|
|
46
|
+
this.disposes.push(ctx.on('agent/assistant-stream', ({ agent, frame }) => {
|
|
47
|
+
if (agent.session.id !== sessionId)
|
|
48
|
+
return;
|
|
49
|
+
output.capture(() => {
|
|
50
|
+
const wire = frame.type === 'start'
|
|
51
|
+
? { ...frame, startedAfterSeq: agent.session.seq === 0 ? -1 : SessionSeq(agent.session.seq - 1) }
|
|
52
|
+
: frame.type === 'chunk' ? { ...frame, chunk: frame.chunk } : frame;
|
|
53
|
+
input.append({ type: 'assistant-stream', session: agent.session, frame: wire, ordinal: ++this.ordinal });
|
|
54
|
+
});
|
|
55
|
+
}, { global: true }));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this[Symbol.dispose]();
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** @returns the baseline and local arrival cut captured synchronously together. */
|
|
63
|
+
snapshot() {
|
|
64
|
+
return { baseline: this._snapshot(), ordinal: this.ordinal };
|
|
65
|
+
}
|
|
66
|
+
/** @param ordinal - local snapshot cut set before queue consumption. */
|
|
67
|
+
setOrdinalCut(ordinal) {
|
|
68
|
+
this.cut = ordinal;
|
|
69
|
+
}
|
|
70
|
+
*transform(item) {
|
|
71
|
+
if (this.disposes.length === 0 || item.ordinal <= this.cut)
|
|
72
|
+
return;
|
|
73
|
+
yield { type: 'assistant-stream', frame: item.frame };
|
|
74
|
+
}
|
|
75
|
+
[Symbol.dispose]() {
|
|
76
|
+
for (const dispose of this.disposes.splice(0).reverse())
|
|
77
|
+
dispose();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** Independent Session snapshots and passive event subscriptions. */
|
|
2
|
+
import type { Context } from '@unieai/cordis';
|
|
3
|
+
import type { SessionId } from '@unieai/rabi-session';
|
|
4
|
+
import type { SessionObservation } from '@unieai/rabi-session-query';
|
|
5
|
+
import { SessionAssistantStreamsListener } from './assistant-stream.ts';
|
|
6
|
+
import type { SessionEventFrame, SessionEventsPage, SessionPageRequest, SessionObserveEventRequest, SessionProjectionsRequest, SessionProjectionFrame, SessionAddress, SessionProjectionBaseline, SessionProjectionsValue, SessionWaitOutput } from '../types.ts';
|
|
7
|
+
/** Session snapshots do not share lifetime with passive subscriptions. */
|
|
8
|
+
export declare class HistoryController {
|
|
9
|
+
private readonly ctx;
|
|
10
|
+
/** Reconnect state for this controller's assistant subscriptions. */
|
|
11
|
+
readonly streamsListener: SessionAssistantStreamsListener;
|
|
12
|
+
/** @param ctx - Host context carrying Session reads and projections. */
|
|
13
|
+
constructor(ctx: Context);
|
|
14
|
+
/**
|
|
15
|
+
* Read a passive page of Session events at an exact cut.
|
|
16
|
+
* @param request - Session identity and optional cut and page window.
|
|
17
|
+
* @param signal - read cancellation.
|
|
18
|
+
* @returns a page at the supplied cut, or the observed log end when omitted.
|
|
19
|
+
*/
|
|
20
|
+
events(request: SessionPageRequest, signal: AbortSignal): Promise<SessionEventsPage>;
|
|
21
|
+
/**
|
|
22
|
+
* Subscribe to Session events without reading or activating the Session.
|
|
23
|
+
* @param request - Session address to subscribe.
|
|
24
|
+
* @param signal - stream cancellation.
|
|
25
|
+
* @returns subscription readiness followed by event frames; readiness does not establish existence.
|
|
26
|
+
*/
|
|
27
|
+
observeEvent(request: SessionObserveEventRequest, signal: AbortSignal): AsyncIterable<SessionEventFrame>;
|
|
28
|
+
/**
|
|
29
|
+
* Read exact projections or migration cache hints without activating the Session.
|
|
30
|
+
* @param request - Session identity whose exact projection baseline is required.
|
|
31
|
+
* @param signal - read cancellation.
|
|
32
|
+
* @returns exact sequenced values, migration cache hints, or null when absent.
|
|
33
|
+
*/
|
|
34
|
+
projections(request: SessionProjectionsRequest, signal: AbortSignal): Promise<SessionProjectionsValue>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscribe to projection changes without reading a baseline.
|
|
37
|
+
* @param request - Session identity to subscribe without reading a baseline.
|
|
38
|
+
* @param signal - stream cancellation.
|
|
39
|
+
* @returns readiness followed by one change frame per committed event, listing every key it changed.
|
|
40
|
+
*/
|
|
41
|
+
observeProjections(request: SessionProjectionsRequest, signal: AbortSignal): AsyncIterable<SessionProjectionFrame>;
|
|
42
|
+
/**
|
|
43
|
+
* Read bounded committed assistant messages through a stopping cursor.
|
|
44
|
+
* @param sessionId - Session whose committed assistant messages are requested.
|
|
45
|
+
* @param afterSeq - exclusive lower bound.
|
|
46
|
+
* @param throughSeq - inclusive stopping-state cursor.
|
|
47
|
+
* @param maxMessages - positive assistant record limit.
|
|
48
|
+
* @param signal - caller cancellation, independent of a completed wait deadline.
|
|
49
|
+
* @returns newest-first assistant messages and whether further matching records were omitted.
|
|
50
|
+
*/
|
|
51
|
+
assistantOutput(sessionId: SessionId, afterSeq: number, throughSeq: number, maxMessages: number, signal: AbortSignal): Promise<SessionWaitOutput>;
|
|
52
|
+
/**
|
|
53
|
+
* Acquire a read without activating a Session; projections are opt-in.
|
|
54
|
+
* @param request - Session identity and whether to compute projections.
|
|
55
|
+
* @param signal - read cancellation.
|
|
56
|
+
* @param callback - omitted to transfer lease ownership to the caller.
|
|
57
|
+
* @returns a lease the caller must dispose.
|
|
58
|
+
*/
|
|
59
|
+
usingObservation(request: {
|
|
60
|
+
readonly sessionId: SessionId;
|
|
61
|
+
readonly projection: boolean;
|
|
62
|
+
}, signal: AbortSignal, callback?: undefined): Promise<SessionObservation>;
|
|
63
|
+
/**
|
|
64
|
+
* Keep the borrowed lease alive until the callback settles, then dispose it.
|
|
65
|
+
* @param request - Session identity and whether to compute projections.
|
|
66
|
+
* @param signal - read cancellation.
|
|
67
|
+
* @param callback - synchronous or asynchronous computation; retain a separate lease if it must escape.
|
|
68
|
+
* @returns the callback result; read and callback failures propagate.
|
|
69
|
+
*/
|
|
70
|
+
usingObservation<T>(request: {
|
|
71
|
+
readonly sessionId: SessionId;
|
|
72
|
+
readonly projection: boolean;
|
|
73
|
+
}, signal: AbortSignal, callback: (observation: SessionObservation) => T): Promise<Awaited<T>>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validate an Address against the exact read used by a Controller.
|
|
77
|
+
* @param address - caller-supplied Session address.
|
|
78
|
+
* @param observation - borrowed read; subagent addresses require projections.
|
|
79
|
+
*/
|
|
80
|
+
export declare function validateObservationAddress(address: SessionAddress, observation: SessionObservation): void;
|
|
81
|
+
/**
|
|
82
|
+
* Convert a borrowed observation to one page without acquiring or retaining it.
|
|
83
|
+
* @param observation - exact read cut owned by the caller.
|
|
84
|
+
* @param request - validated page window and optional inclusive cut.
|
|
85
|
+
* @returns a chronological page at the requested cut.
|
|
86
|
+
*/
|
|
87
|
+
export declare function history(observation: SessionObservation, request: Omit<SessionPageRequest, 'address'> & {
|
|
88
|
+
readonly maxMessages: number;
|
|
89
|
+
}): SessionEventsPage;
|
|
90
|
+
/**
|
|
91
|
+
* Convert the projection baseline without acquiring or retaining its observation.
|
|
92
|
+
* @param observation - projected read cut owned by the caller.
|
|
93
|
+
* @returns the exact baseline; missing projection support fails explicitly.
|
|
94
|
+
*/
|
|
95
|
+
export declare function projections(observation: SessionObservation): SessionProjectionBaseline;
|
|
96
|
+
/**
|
|
97
|
+
* Validate and resolve the history page window.
|
|
98
|
+
* @param request - external history window.
|
|
99
|
+
* @returns the validated request with an explicit message budget.
|
|
100
|
+
*/
|
|
101
|
+
export declare function resolveHistoryRequest(request: SessionPageRequest): SessionPageRequest & {
|
|
102
|
+
readonly maxMessages: number;
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=controller.d.ts.map
|