@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,46 @@
|
|
|
1
|
+
/** Client scope generations route local events independently of Host Agent residency. */
|
|
2
|
+
import { Context as CordisContext } from '@unieai/cordis';
|
|
3
|
+
/** Context tag written by {@link createScope}. */
|
|
4
|
+
const kScope = Symbol('rabi.client.scope');
|
|
5
|
+
/** Shared no-op plugin backing each Agent scope fiber. */
|
|
6
|
+
function agentScope() { }
|
|
7
|
+
/**
|
|
8
|
+
* Mint an Agent scope under `ctx`: a no-op plugin fiber whose context
|
|
9
|
+
* carries the agent tag and the dispatch filter — untagged listeners are
|
|
10
|
+
* admitted globally, tagged listeners only for the same Client generation.
|
|
11
|
+
* Registrations through the returned ctx dispose with the fiber.
|
|
12
|
+
* @param ctx - client root context the scope fiber mounts under.
|
|
13
|
+
* @param key - durable Session identity carried by this generation.
|
|
14
|
+
* @returns the tagged context and its backing fiber.
|
|
15
|
+
*/
|
|
16
|
+
export function createScope(ctx, key) {
|
|
17
|
+
const fiber = ctx.plugin(agentScope);
|
|
18
|
+
const identity = { sessionId: key };
|
|
19
|
+
const scoped = fiber.ctx.extend({
|
|
20
|
+
[kScope]: identity,
|
|
21
|
+
[CordisContext.filter](listenerCtx) {
|
|
22
|
+
const tag = scopeIdentityOf(listenerCtx);
|
|
23
|
+
return tag === undefined || tag === identity;
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
fiber,
|
|
28
|
+
ctx: scoped,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read the nearest agent tag inherited by a context.
|
|
33
|
+
* @param ctx - any client context.
|
|
34
|
+
* @returns its agent identity (the session id), or undefined for root contexts.
|
|
35
|
+
*/
|
|
36
|
+
export function scopeOf(ctx) {
|
|
37
|
+
return scopeIdentityOf(ctx)?.sessionId;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read the exact generation identity inherited by a Client Context.
|
|
41
|
+
* @param ctx - scoped or root Client Context.
|
|
42
|
+
* @returns the generation identity, or undefined for an unscoped Context.
|
|
43
|
+
*/
|
|
44
|
+
export function scopeIdentityOf(ctx) {
|
|
45
|
+
return ctx[kScope];
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Event-local acceptance for raw Session journal responses; payloads remain owner-defined JSON. */
|
|
2
|
+
import type { SessionWireEvent } from '../types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Reject non-current event envelopes without stripping or normalizing wire fields.
|
|
5
|
+
* Range membership and source existence require the durable log and remain Host-owned.
|
|
6
|
+
* @param value - one event received in a follow frame or history page.
|
|
7
|
+
* @returns nothing after narrowing the accepted event envelope.
|
|
8
|
+
* @throws when the envelope or current event-local metadata is invalid.
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertSessionWireEvent(value: unknown): asserts value is SessionWireEvent;
|
|
11
|
+
//# sourceMappingURL=session-wire-event.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Event-local acceptance for raw Session journal responses; payloads remain owner-defined JSON. */
|
|
2
|
+
import { validateSessionEventData, validateSurfaceMetadata } from '@unieai/rabi-session/surface';
|
|
3
|
+
/**
|
|
4
|
+
* Reject non-current event envelopes without stripping or normalizing wire fields.
|
|
5
|
+
* Range membership and source existence require the durable log and remain Host-owned.
|
|
6
|
+
* @param value - one event received in a follow frame or history page.
|
|
7
|
+
* @returns nothing after narrowing the accepted event envelope.
|
|
8
|
+
* @throws when the envelope or current event-local metadata is invalid.
|
|
9
|
+
*/
|
|
10
|
+
export function assertSessionWireEvent(value) {
|
|
11
|
+
const subject = 'session wire event';
|
|
12
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
13
|
+
throw new Error(`${subject} must be an object`);
|
|
14
|
+
}
|
|
15
|
+
const event = value;
|
|
16
|
+
for (const key of Object.keys(event)) {
|
|
17
|
+
switch (key) {
|
|
18
|
+
case 'type':
|
|
19
|
+
case 'seq':
|
|
20
|
+
case 'time':
|
|
21
|
+
case 'data':
|
|
22
|
+
case 'ignorable':
|
|
23
|
+
case 'surfaceOp':
|
|
24
|
+
case 'sourceEventSeqs':
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`${subject} has unexpected field ${key}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const seq = event['seq'];
|
|
31
|
+
if (typeof event['type'] !== 'string'
|
|
32
|
+
|| typeof seq !== 'number' || !Number.isSafeInteger(seq) || seq < 0 || Object.is(seq, -0)
|
|
33
|
+
|| typeof event['time'] !== 'number' || !Number.isSafeInteger(event['time'])
|
|
34
|
+
|| !Object.hasOwn(event, 'data') || event['data'] === undefined
|
|
35
|
+
|| (Object.hasOwn(event, 'ignorable') && event['ignorable'] !== true)) {
|
|
36
|
+
throw new Error(`${subject} has an invalid envelope`);
|
|
37
|
+
}
|
|
38
|
+
// Event names and payloads are merge-extensible; only event-local owner rules run here.
|
|
39
|
+
const current = event;
|
|
40
|
+
validateSurfaceMetadata(current);
|
|
41
|
+
validateSessionEventData(current, subject);
|
|
42
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Web presentation fold joining transient Assistant frames to one durable v2 settlement. */
|
|
2
|
+
import type { SessionAssistantStreamBaseline, SessionAssistantStreamFrame } from '../../types.ts';
|
|
3
|
+
import type { LlmAttemptId } from '@unieai/rabi-llm/brand';
|
|
4
|
+
import type { SessionAssistantSettlementEntry, SessionEventLikeEntry, SessionLiveEventEntry, SessionTransientEventEntry } from '../contract/events.ts';
|
|
5
|
+
/** One Web publication decision from the assistant stream fold. */
|
|
6
|
+
export type ClientAssistantStreamResult = {
|
|
7
|
+
readonly type: 'publish';
|
|
8
|
+
readonly entry: SessionLiveEventEntry;
|
|
9
|
+
/** Retire the successful attempt's transient rows after publishing its Step end. */
|
|
10
|
+
readonly retireAttemptId?: LlmAttemptId;
|
|
11
|
+
} | {
|
|
12
|
+
readonly type: 'settlement';
|
|
13
|
+
readonly attemptId: LlmAttemptId;
|
|
14
|
+
readonly entry: SessionAssistantSettlementEntry;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: 'abandonment';
|
|
17
|
+
readonly attemptId: LlmAttemptId;
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: 'transient';
|
|
20
|
+
readonly entry: SessionTransientEventEntry;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: 'rebaseline';
|
|
23
|
+
} | undefined;
|
|
24
|
+
/** Keeps transient Assistant presentation behind one settlement-aware interface. */
|
|
25
|
+
export declare class ClientAssistantStream {
|
|
26
|
+
private activeAttempt;
|
|
27
|
+
private retainedAttempt;
|
|
28
|
+
private readonly pending;
|
|
29
|
+
private publishedSeqs;
|
|
30
|
+
private durableCursor;
|
|
31
|
+
private transientInGap;
|
|
32
|
+
/**
|
|
33
|
+
* Replace the durable Web window and adopt an optional reconnect baseline.
|
|
34
|
+
* @param entries - durable entries in the replacement window.
|
|
35
|
+
* @param baseline - compact prefix for an Assistant attempt that is still live.
|
|
36
|
+
* @returns immediately visible durable entries plus reconstructed transient chunks.
|
|
37
|
+
*/
|
|
38
|
+
replace(entries: readonly SessionEventLikeEntry[], baseline?: SessionAssistantStreamBaseline): readonly SessionEventLikeEntry[];
|
|
39
|
+
/**
|
|
40
|
+
* Stage one durable v2 settlement while its matching live attempt is open.
|
|
41
|
+
* @param entry - newly followed durable entry.
|
|
42
|
+
* @returns a publication decision, or `undefined` when no entry becomes visible.
|
|
43
|
+
*/
|
|
44
|
+
acceptDurable(entry: SessionLiveEventEntry): ClientAssistantStreamResult;
|
|
45
|
+
/**
|
|
46
|
+
* Fold one dense transient frame and release its named durable settlement.
|
|
47
|
+
* Successful messages retain their transient rows until the owning Step ends;
|
|
48
|
+
* interrupted messages, failed attempts, and abandonment retire them immediately.
|
|
49
|
+
* @param frame - next Assistant stream frame received by the follow connection.
|
|
50
|
+
* @returns a transient, publication, or rebaseline decision, or `undefined` when no entry becomes visible.
|
|
51
|
+
*/
|
|
52
|
+
acceptFrame(frame: SessionAssistantStreamFrame): ClientAssistantStreamResult;
|
|
53
|
+
private attemptForSettlement;
|
|
54
|
+
private publish;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=assistant-stream.d.ts.map
|
|
@@ -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,48 @@
|
|
|
1
|
+
import type { SessionId } from '@unieai/rabi-session/types';
|
|
2
|
+
import type { SessionProjectionSummaryValues } 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
|
+
/**
|
|
8
|
+
* The row's summary projection values, never the full projection set. A
|
|
9
|
+
* connected Session's client store may hold more values from its
|
|
10
|
+
* control/follow baseline; those are outside the list contract and must not
|
|
11
|
+
* be read here.
|
|
12
|
+
*/
|
|
13
|
+
projectionValues?: Readonly<Partial<SessionProjectionSummaryValues>>;
|
|
14
|
+
}
|
|
15
|
+
/** One flattened session-list row with lineage depth. */
|
|
16
|
+
export interface SessionListEntry {
|
|
17
|
+
sessionId: SessionId;
|
|
18
|
+
title?: string;
|
|
19
|
+
updatedAt: number;
|
|
20
|
+
running: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* New Session presentation and reuse eligibility, reconciled with
|
|
23
|
+
* `sessionListMetadata`; lists hide blank sessions (filtering stays with the consumer).
|
|
24
|
+
*/
|
|
25
|
+
blank: boolean;
|
|
26
|
+
parentSessionId?: SessionId;
|
|
27
|
+
/** Coarse durable origin for navigation filtering; not a continuation capability. */
|
|
28
|
+
origin?: 'subagent';
|
|
29
|
+
/** Format classification supplied by the Host list. */
|
|
30
|
+
formatStatus?: SessionSummary['formatStatus'];
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The row's summary projection values, never the full projection set; see
|
|
34
|
+
* `TitledSessionSummary.projectionValues`.
|
|
35
|
+
*/
|
|
36
|
+
projectionValues?: Readonly<Partial<SessionProjectionSummaryValues>>;
|
|
37
|
+
/** Lineage indent depth: root = 0; the UI just multiplies by the indent width. */
|
|
38
|
+
depth: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Summaries -> flat list with lineage indentation. Root and sibling order
|
|
42
|
+
* follows the established input order; this projection never re-sorts a
|
|
43
|
+
* hydrated list from mutable timestamps.
|
|
44
|
+
* @param summaries - the host's session.list items.
|
|
45
|
+
* @returns display rows in render order.
|
|
46
|
+
*/
|
|
47
|
+
export declare function flattenLineage(summaries: readonly TitledSessionSummary[]): SessionListEntry[];
|
|
48
|
+
//# sourceMappingURL=lineage.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
// Historical ordinary forks may retain a parent id without being subagents.
|
|
19
|
+
if (s.origin === 'subagent' && s.parentSessionId !== undefined && byId.has(s.parentSessionId)) {
|
|
20
|
+
const list = children.get(s.parentSessionId) ?? [];
|
|
21
|
+
list.push(s);
|
|
22
|
+
children.set(s.parentSessionId, list);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
roots.push(s); // root, or an orphan whose parent is absent from summaries (degrade to root, never drop)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const out = [];
|
|
29
|
+
const visited = new Set();
|
|
30
|
+
const walk = (s, depth) => {
|
|
31
|
+
if (visited.has(s.sessionId)) {
|
|
32
|
+
console.warn(`[session-controller] lineage cycle at ${s.sessionId}; emitting as root`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
visited.add(s.sessionId);
|
|
36
|
+
const { agentAvailable: _agentAvailable, ...row } = s;
|
|
37
|
+
out.push({
|
|
38
|
+
...row,
|
|
39
|
+
depth,
|
|
40
|
+
});
|
|
41
|
+
const kids = children.get(s.sessionId);
|
|
42
|
+
if (kids === undefined)
|
|
43
|
+
return;
|
|
44
|
+
for (const kid of kids)
|
|
45
|
+
walk(kid, depth + 1);
|
|
46
|
+
};
|
|
47
|
+
for (const root of roots)
|
|
48
|
+
walk(root, 0);
|
|
49
|
+
// Cycle members (unreachable from any root): emit as roots so no entry is lost.
|
|
50
|
+
for (const s of summaries) {
|
|
51
|
+
if (!visited.has(s.sessionId))
|
|
52
|
+
walk(s, 0);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|