@unieai/rabi-api-session-controller 0.0.0-stage → 0.2.1-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -2
  3. package/lib/client.js +4325 -0
  4. package/lib/index.js +3367 -0
  5. package/lib/typert.host.d.ts +3 -0
  6. package/lib/typert.host.js +4053 -0
  7. package/lib/typert.remote-client.d.ts +97 -0
  8. package/lib/typert.remote-client.js +2013 -0
  9. package/lib/types/agent.d.ts +198 -0
  10. package/lib/types/agent.js +609 -0
  11. package/lib/types/archived-session-gate.d.ts +30 -0
  12. package/lib/types/archived-session-gate.js +51 -0
  13. package/lib/types/assistant-stream.d.ts +26 -0
  14. package/lib/types/assistant-stream.js +82 -0
  15. package/lib/types/catalog.d.ts +24 -0
  16. package/lib/types/catalog.js +106 -0
  17. package/lib/types/client/contract/events.d.ts +102 -0
  18. package/lib/types/client/contract/events.js +111 -0
  19. package/lib/types/client/contract/session.d.ts +157 -0
  20. package/lib/types/client/contract/session.js +1 -0
  21. package/lib/types/client/contract/sessions.d.ts +161 -0
  22. package/lib/types/client/contract/sessions.js +1 -0
  23. package/lib/types/client/contract/snapshot.d.ts +81 -0
  24. package/lib/types/client/contract/snapshot.js +1 -0
  25. package/lib/types/client/index.d.ts +39 -0
  26. package/lib/types/client/index.js +60 -0
  27. package/lib/types/client/ordered-baseline.d.ts +12 -0
  28. package/lib/types/client/ordered-baseline.js +40 -0
  29. package/lib/types/client/scope.d.ts +46 -0
  30. package/lib/types/client/scope.js +46 -0
  31. package/lib/types/client/session-wire-event.d.ts +11 -0
  32. package/lib/types/client/session-wire-event.js +42 -0
  33. package/lib/types/client/sessions/assistant-stream.d.ts +56 -0
  34. package/lib/types/client/sessions/assistant-stream.js +182 -0
  35. package/lib/types/client/sessions/history-records.d.ts +22 -0
  36. package/lib/types/client/sessions/history-records.js +25 -0
  37. package/lib/types/client/sessions/lineage.d.ts +40 -0
  38. package/lib/types/client/sessions/lineage.js +54 -0
  39. package/lib/types/client/sessions/manager.d.ts +269 -0
  40. package/lib/types/client/sessions/manager.js +799 -0
  41. package/lib/types/client/sessions/notifier.d.ts +39 -0
  42. package/lib/types/client/sessions/notifier.js +97 -0
  43. package/lib/types/client/sessions/projection-store.d.ts +128 -0
  44. package/lib/types/client/sessions/projection-store.js +161 -0
  45. package/lib/types/client/sessions/remotes.d.ts +29 -0
  46. package/lib/types/client/sessions/remotes.js +7 -0
  47. package/lib/types/client/sessions/service.d.ts +258 -0
  48. package/lib/types/client/sessions/service.js +582 -0
  49. package/lib/types/client/sessions/session.d.ts +287 -0
  50. package/lib/types/client/sessions/session.js +866 -0
  51. package/lib/types/client/time-zone.d.ts +8 -0
  52. package/lib/types/client/time-zone.js +13 -0
  53. package/lib/types/client/transport.d.ts +77 -0
  54. package/lib/types/client/transport.js +129 -0
  55. package/lib/types/commands.d.ts +86 -0
  56. package/lib/types/commands.js +624 -0
  57. package/lib/types/control.d.ts +20 -0
  58. package/lib/types/control.js +106 -0
  59. package/lib/types/file-references.d.ts +27 -0
  60. package/lib/types/file-references.js +68 -0
  61. package/lib/types/history.d.ts +32 -0
  62. package/lib/types/history.js +441 -0
  63. package/lib/types/index.d.ts +222 -0
  64. package/lib/types/index.js +658 -0
  65. package/lib/types/list.d.ts +50 -0
  66. package/lib/types/list.js +325 -0
  67. package/lib/types/media-references.d.ts +16 -0
  68. package/lib/types/media-references.js +76 -0
  69. package/lib/types/model-selection-projection.d.ts +8 -0
  70. package/lib/types/model-selection-projection.js +65 -0
  71. package/lib/types/remote-events.d.ts +8 -0
  72. package/lib/types/remote-events.js +1 -0
  73. package/lib/types/skill-catalog.d.ts +28 -0
  74. package/lib/types/skill-catalog.js +203 -0
  75. package/lib/types/types.d.ts +611 -0
  76. package/lib/types/types.js +4 -0
  77. package/locale/en.json +5 -0
  78. package/locale/zh.json +6 -0
  79. package/package.json +114 -4
@@ -0,0 +1,287 @@
1
+ import type { Context } from '@unieai/cordis';
2
+ import type { AttachmentIdType, ImageAttachmentRef } from '@unieai/rabi-attachment';
3
+ import type { SubagentAddress } from '@unieai/rabi-subagent/client';
4
+ import type { MessageId } from '@unieai/rabi-llm/brand';
5
+ import { SessionSeq, type SessionId } from '@unieai/rabi-session/types';
6
+ import type { PromptContentPart, QueueAction, SessionRequestId } from '../../types.ts';
7
+ import type { BeginSubmissionInput, SessionFace, SubmissionHandle } from '../contract/session.ts';
8
+ import type { SessionSnapshot } from '../contract/snapshot.ts';
9
+ import { MutableSessionEventSource } from '../contract/events.ts';
10
+ import type { RemoteResult } from '@unieai/rabi-typert-protocol';
11
+ import type { SessionRemotes } from './remotes.ts';
12
+ import { ProjectionValueStore } from './projection-store.ts';
13
+ /** Minimum message count for ordinary history windows. */
14
+ export declare const PAGE_MESSAGES = 50;
15
+ /** Minimum messages per page while a turn jump loops backwards. */
16
+ export declare const JUMP_PAGE_MESSAGES = 200;
17
+ /** Manager-owned observers of a Session object's local state edges. */
18
+ export interface SessionOptions {
19
+ /** Catalog-discovered address selecting non-activating subagent transport. */
20
+ address?: SubagentAddress;
21
+ /** Whether the exact direct parent Agent is available in Host summaries; absent until known. */
22
+ parentAvailable?: boolean;
23
+ /**
24
+ * Publish each accepted prompt to the Manager, including after this Session
25
+ * object is replaced. Acceptance converts display state, but does not
26
+ * establish that a turn started or reached durable history.
27
+ */
28
+ onEngaged?(session: Session): void;
29
+ /**
30
+ * Manager-owned projection value store to adopt (frames route through the
31
+ * manager and values outlive instantiation); omitted, the Session owns a
32
+ * private store (bare object-layer construction).
33
+ */
34
+ projections?: ProjectionValueStore;
35
+ }
36
+ /**
37
+ * Owns a session's event window, lifecycle state, and observable
38
+ * snapshot. React bindings remain outside this data layer. Features see only
39
+ * the {@link SessionFace} slice (ISession verbs + the snapshot source); the
40
+ * remaining public members are Session Controller internals.
41
+ */
42
+ export declare class Session implements SessionFace {
43
+ readonly sessionId: SessionId;
44
+ private readonly remote;
45
+ private readonly options;
46
+ private baseSeq;
47
+ private hasMore;
48
+ private openState;
49
+ private openError;
50
+ private openPromise;
51
+ /** Bumped by stream replacement to invalidate an in-flight doOpen. Stale
52
+ * passes drop all writes once the generation moves on. */
53
+ private openGeneration;
54
+ private loadingOlder;
55
+ /** Shared low-water target of the running jump loop; null when no jump is paging. */
56
+ private jumpTargetSeq;
57
+ /** The running jump loop's completion, shared by retargeting callers. */
58
+ private jumpPromise;
59
+ private pendingHistory;
60
+ private readonly stopObservingInbox;
61
+ private readonly assistantStream;
62
+ private running;
63
+ private address;
64
+ private parentAvailable;
65
+ /**
66
+ * Sticky send marker, private input of the composerPhase derivation: set
67
+ * synchronously before prompt()'s first await, never reset — the blank →
68
+ * engaging edge of the phase machine (see ComposerPhase).
69
+ */
70
+ private promptAttempted;
71
+ /** A first accepted prompt stays in the engaging phase until its turn is observable. */
72
+ private firstPromptPendingTurn;
73
+ /** New Session display state; unknown bare sessions begin conservatively blank. */
74
+ private blankBit;
75
+ private removed;
76
+ private promptError;
77
+ private lastAgentError;
78
+ /** Local submission echoes, insertion-ordered (see SessionSnapshot.pendingSubmissions). */
79
+ private pendingSubmissions;
80
+ /** Per-echo settlement state; `retiring` latches the first observation so a
81
+ * Inbox projection and its durable event cannot both retire one echo. */
82
+ private readonly submissionSettlements;
83
+ /** Owns the addressed page/follow lifecycle while this Session is open. */
84
+ private events;
85
+ /**
86
+ * Per-session projection value store (push model; see the session-projection
87
+ * subsystem page, docs/subsystems/session-projection.md): finished whole
88
+ * values computed on the Host, seeded by the tail page's
89
+ * projections block and updated by Session Controller control frames;
90
+ * Host-sequenced writes merge under higher-seq-wins and cached list blocks
91
+ * yield to them (projection-store.ts). Keys are read via `projections.faceOf(key)`
92
+ * (the useProjection resolution face); the conversation snapshot never
93
+ * carries projection values, and no client-side domain folding exists.
94
+ * Manager-owned when constructed through SessionManager (frames route and
95
+ * the store outlives instantiation, the title-snapshot precedent); a bare
96
+ * construction gets a private store.
97
+ */
98
+ readonly projections: ProjectionValueStore;
99
+ /** Contiguous history and live tail consumed by Conversation assembly. */
100
+ readonly eventSource: MutableSessionEventSource;
101
+ private snapshotCache;
102
+ private readonly notifier;
103
+ /**
104
+ * Agent-scoped cordis context, bound once by ClientSessions when it
105
+ * mints the scope (the client mirror of the host Agent's loopCtx). The
106
+ * Session dispatches its own scoped events through it; undefined means
107
+ * unbound (bare object-layer construction) or already pruned — both skip
108
+ * dispatch-dependent behavior rather than fail.
109
+ */
110
+ private actx;
111
+ /**
112
+ * @param sessionId - Host session identity (client sessions are always Host-born).
113
+ * @param remote - generated Remote namespaces this session calls.
114
+ * @param options - optional manager-owned state observers.
115
+ */
116
+ constructor(sessionId: SessionId, remote: SessionRemotes, options?: SessionOptions);
117
+ /**
118
+ * Bind the Agent-scoped context minted by ClientSessions (single write;
119
+ * a second bind is a wiring error and throws). Direction stays one-way at
120
+ * this binding boundary: consumers still reach the Session via `sessions.sessionOf`,
121
+ * while the Session holds its own dispatch point (host Agent.loopCtx
122
+ * mirror).
123
+ * @param actx - the agent's scoped context.
124
+ */
125
+ bindScope(actx: Context): void;
126
+ /** Release the bound scope at prune time (a later rebind accompanies a freshly minted scope). */
127
+ unbindScope(): void;
128
+ /**
129
+ * Register one local submission echo (see the ISession declaration).
130
+ * Synchronous through markDirty: the echo is in the very next snapshot, so
131
+ * the conversation can paint it before the caller starts serializing.
132
+ * @param input - echo content and the optional settlement callback.
133
+ * @returns the minted identity for {@link prompt} plus the pre-prompt abandon path.
134
+ */
135
+ beginSubmission(input: BeginSubmissionInput): SubmissionHandle;
136
+ /**
137
+ * Send (queue/steer passed through 1:1); failures land in the snapshot's promptError.
138
+ * @param content - text, browser-owned temporary image uploads, and staged-file receipts.
139
+ * @param mode - queue appends after the current turn; steer interrupts it.
140
+ * @param signal - optional caller cancellation for the complete admission round-trip.
141
+ * @param requestId - identity from {@link beginSubmission}; a failed identified prompt retires its echo.
142
+ * @returns the prompt result (also mirrored into promptError on failure).
143
+ */
144
+ prompt(content: PromptContentPart[], mode: 'queue' | 'steer', signal?: AbortSignal, requestId?: SessionRequestId): Promise<RemoteResult<{
145
+ accepted: true;
146
+ }>>;
147
+ /**
148
+ * Resolve one image referenced by this session into browser-consumable bytes.
149
+ * @param attachmentId - opaque id found in the folded session log.
150
+ * @returns the authenticated reference and decoded bytes.
151
+ */
152
+ readAttachment(attachmentId: AttachmentIdType): Promise<RemoteResult<{
153
+ attachment: ImageAttachmentRef;
154
+ data: Uint8Array;
155
+ }>>;
156
+ /** Apply one operation to a still-pending queue occurrence. */
157
+ updateQueue(itemId: MessageId, action: QueueAction): Promise<RemoteResult<{
158
+ accepted: true;
159
+ }>>;
160
+ /**
161
+ * Stop the active turn while the Host preserves pending inbox work; failures
162
+ * land in promptError (same error-strip display slot). A subagent address
163
+ * routes through `subagents.interruptByParent`, whose durable parent-address
164
+ * authority works without a live parent Agent.
165
+ * @returns the cancel result.
166
+ */
167
+ cancel(): Promise<RemoteResult<{
168
+ accepted: true;
169
+ }>>;
170
+ /**
171
+ * Rename: contract session.rename 1:1. On success settle the 'title'
172
+ * projection cell from the response's `{title, seq}` under the store's
173
+ * higher-seq-wins rule (the push frame arriving later is a no-op replay),
174
+ * so the list row and any useProjection('title') reader update without
175
+ * waiting for the control-stream projection update.
176
+ * @param title - raw title text (the host normalizes acceptance).
177
+ * @returns the rename result (normalized accepted title + title event seq).
178
+ */
179
+ rename(title: string): Promise<RemoteResult<{
180
+ title: string;
181
+ seq: SessionSeq;
182
+ }>>;
183
+ /**
184
+ * Execute one slash-command line against this session's agent — pure
185
+ * admission semantics (the host executor durably logs the lifecycle;
186
+ * outcomes render as flow nodes, never as a response echo).
187
+ * @param line - the full command line, leading slash included.
188
+ * @returns the admission result.
189
+ */
190
+ command(line: string): Promise<RemoteResult<{
191
+ matched: boolean;
192
+ }>>;
193
+ /** First open: pull the tail page (idempotent — in-flight/already-open returns the existing promise). */
194
+ open(): Promise<void>;
195
+ /** Prepend one Turn-aligned page: at least 50 messages and two Turn starts, capped at 500 messages. */
196
+ loadOlder(): Promise<void>;
197
+ /** Jump loader: page backwards until the window covers seq (see ISession.loadThrough). */
198
+ loadThrough(seq: SessionSeq): Promise<void>;
199
+ /** Rebuild an opened history source after address replacement.
200
+ * Invalidates any in-flight open first; projection state belongs to the independently
201
+ * reconnecting control stream and remains untouched. */
202
+ resync(): Promise<void>;
203
+ /**
204
+ * uSES subscription entry.
205
+ * @param listener - change callback.
206
+ * @returns the unsubscribe function.
207
+ */
208
+ subscribe(listener: () => void): () => void;
209
+ /**
210
+ * Cached Session snapshot (rebuilt lazily when dirty with no listeners).
211
+ * @returns the cached reference (stable until the next flush).
212
+ */
213
+ getSnapshot(): SessionSnapshot;
214
+ /**
215
+ * Running-bit relay from the host stream (list entry and snapshot stay consistent).
216
+ * @param running - the new running state.
217
+ */
218
+ handleRunning(running: boolean): void;
219
+ /**
220
+ * Install or clear the catalog-discovered transport address. A changed
221
+ * address rebuilds an already-open window through its new history route.
222
+ * @param address - direct parent/child address, or undefined for ordinary transport.
223
+ * @param parentAvailable - latest exact-parent availability hint, or undefined before a catalog read.
224
+ */
225
+ configureSubagent(address: SubagentAddress | undefined, parentAvailable?: boolean): void;
226
+ /**
227
+ * Update only the parent availability hint from a catalog refresh.
228
+ * @param available - whether the exact direct parent is live.
229
+ */
230
+ handleSubagentParentAvailable(available: boolean): void;
231
+ /**
232
+ * Apply the Manager's effective display blank, further reconciled with the
233
+ * current `sessionListMetadata` projection. Local send attempts and current
234
+ * running state prevent re-blanking; an earlier false summary alone does not.
235
+ * The Manager retains acceptance and earlier running observations across
236
+ * Session-object replacement.
237
+ * @param blank - New Session display state after Manager reconciliation.
238
+ */
239
+ handleBlank(blank: boolean): void;
240
+ /** `api-session/removed` relay: flag the snapshot while retaining the resident instance. */
241
+ handleRemoved(): void;
242
+ /**
243
+ * `api-session/error` relay: the outlet for live failures with no turn position.
244
+ * @param message - the stringified error.
245
+ */
246
+ handleAgentError(message: string): void;
247
+ /**
248
+ * Stop the Session's live Remote source.
249
+ * @returns when the Remote iterator has completed teardown.
250
+ */
251
+ dispose(): Promise<void>;
252
+ /** @param generation - openGeneration at launch; stale passes cannot publish after replacement. */
253
+ private doOpen;
254
+ /** Apply one contiguous journal update already reconciled by the Remote stream. */
255
+ private acceptEventChange;
256
+ /** Replace the complete contiguous window and apply page-owned projection metadata. */
257
+ private installWindow;
258
+ private publishAssistantEntry;
259
+ /** Prepend one stream-validated history page. */
260
+ private prependWindow;
261
+ /** Append one stream-validated live event. */
262
+ private appendLive;
263
+ /** Observe durable acceptance even when insertion and claim share one projection notification. */
264
+ private observeSubmissionEvent;
265
+ private observeSubmissionInsertions;
266
+ private observeSubmissionMessage;
267
+ /** Retire admitted Chat identities only after stale Inbox rows can no longer reappear. */
268
+ private retireAdmittedSubmission;
269
+ /** Inbox acceptance retires queued echoes; its watermark completes admitted Chat handoffs. */
270
+ private observeSubmissionInbox;
271
+ /**
272
+ * Latch one observed settlement and remove the echo an animation frame
273
+ * later. The delay keeps the echo in the snapshot until the frame in which
274
+ * the durable node (whose assembly frame was registered first) is
275
+ * renderable; the render-time rpcId dedupe hides the one-frame overlap.
276
+ */
277
+ private scheduleObservedRetirement;
278
+ /** Remove one unsettled echo immediately (prompt rejection, abort, or disposal). */
279
+ private retireFailedSubmission;
280
+ /** Single removal point: drop the echo, publish, then notify the owner. */
281
+ private finishSubmission;
282
+ /** Publish a terminal background failure only while this stream still owns the Session. */
283
+ private failEventStream;
284
+ private buildSnapshot;
285
+ private sessionAddress;
286
+ }
287
+ //# sourceMappingURL=session.d.ts.map