@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,258 @@
1
+ /** Client catalog and source-labelled ownership of exact Session generations. */
2
+ import type { Context } from '@unieai/cordis';
3
+ import type { SubagentAddress } from '@unieai/rabi-subagent/client';
4
+ import { type SessionId } from '@unieai/rabi-session/types';
5
+ import type { WorkspaceId } from '@unieai/rabi-workspace/types';
6
+ import type { SessionProjectionMap } from '@unieai/rabi-session-projection/types';
7
+ import { type ObservableSnapshot, type SnapshotStore } from '@unieai/rabi-client-store';
8
+ import type { RemoteFailure, RemoteResult } from '@unieai/rabi-typert-protocol';
9
+ import type { SessionEventSource } from '../contract/events.ts';
10
+ import type { SessionFace } from '../contract/session.ts';
11
+ import type { AgentContext, ISessions, SessionReference, SessionRetainInfo, SessionRetainOptions, SessionTarget } from '../contract/sessions.ts';
12
+ import { SessionManager } from './manager.ts';
13
+ import type { SessionRemotes } from './remotes.ts';
14
+ import type { SessionListPhase, SessionSearchResultItem, SessionProjectionSnapshot } from './manager.ts';
15
+ import type { SessionListEntry } from './lineage.ts';
16
+ /** Session list row projected from the host list RPC plus live stream increments. */
17
+ export interface SessionSummary {
18
+ id: SessionId;
19
+ /** Latest durable log-backed title, absent until the host projects one. */
20
+ title?: string;
21
+ /** Human-facing label: durable title, project basename, then session id. */
22
+ displayTitle: string;
23
+ cwd?: string;
24
+ parentId?: SessionId;
25
+ /** Coarse durable origin for navigation filtering; not a continuation capability. */
26
+ origin?: 'subagent';
27
+ /** Format classification supplied by the Host list, when available. */
28
+ formatStatus?: SessionListEntry['formatStatus'];
29
+ /** Host running state for `ids` members; a display fallback for other rows. */
30
+ running: boolean;
31
+ /** Local ownership counts; Host metadata refreshes cannot overwrite them. */
32
+ readonly retainedBy: SessionRetainInfo['retainedBy'];
33
+ /**
34
+ * New Session presentation and reuse eligibility, derived from the Host
35
+ * summary, `sessionListMetadata`, and client acceptance/running observations.
36
+ * New Session and Workspace reconnection may reuse a blank in the same workspace. Filtering
37
+ * stays with the consumer: the store carries every row, while the Workspace
38
+ * browser shows only the selected blank entry.
39
+ */
40
+ blank: boolean;
41
+ updatedAt: number;
42
+ /** Current host-computed projection values retained by the object layer. */
43
+ projectionValues?: Readonly<Partial<SessionProjectionMap>>;
44
+ }
45
+ /** Catalog metadata and local source counts; catalog membership owns no Client generation. */
46
+ export interface SessionListState {
47
+ /** Host list order; every id has a matching byId row in the same snapshot. */
48
+ ids: SessionId[];
49
+ /** Host/catalog rows plus retained subagent fallbacks; only `ids` expresses Host-list membership. */
50
+ byId: Record<SessionId, SessionSummary>;
51
+ /** Arrival lifecycle projected 1:1 from the manager snapshot (see SessionListPhase): empty-with-ready means "truly no sessions". */
52
+ phase: SessionListPhase;
53
+ /** Shared projection values and explicit-read state, including unopened Sessions. */
54
+ projectionsBySession: Readonly<Record<SessionId, SessionProjectionSnapshot>>;
55
+ }
56
+ /** Structured session-create failure. */
57
+ export declare class SessionCreateError extends Error {
58
+ readonly rpcError: RemoteFailure;
59
+ readonly requestedSessionId: SessionId | undefined;
60
+ readonly name = "SessionCreateError";
61
+ /**
62
+ * @param rpcError - Host business or folded transport error.
63
+ * @param requestedSessionId - caller-preallocated id used for later stream/list reconciliation.
64
+ */
65
+ constructor(rpcError: RemoteFailure, requestedSessionId: SessionId | undefined);
66
+ }
67
+ /** Structured session-fork failure. */
68
+ export declare class SessionForkError extends Error {
69
+ readonly rpcError: RemoteFailure;
70
+ readonly sourceSessionId: SessionId;
71
+ readonly name = "SessionForkError";
72
+ /**
73
+ * @param rpcError - Host business or folded transport error.
74
+ * @param sourceSessionId - the session the fork was cut from.
75
+ */
76
+ constructor(rpcError: RemoteFailure, sourceSessionId: SessionId);
77
+ }
78
+ /** Identity-stable logical binding for one materialized Client Session. */
79
+ export interface SessionBinding {
80
+ readonly sessionId: SessionId;
81
+ /** The outward session face only — feature code never sees the concrete class. */
82
+ readonly session: SessionFace;
83
+ /** Contiguous event window reserved for Conversation assembly. */
84
+ readonly eventSource: SessionEventSource;
85
+ readonly ctx: AgentContext;
86
+ }
87
+ export { scopeOf } from '../scope.ts';
88
+ /** Host catalog and local reference allocator; view selection remains outside the Controller. */
89
+ export declare class ClientSessions implements ISessions {
90
+ private readonly rootCtx;
91
+ /**
92
+ * The wire schema's own result bound, re-exposed for presentation plugins as
93
+ * injected data. Not per-connection state: the `session.search` response
94
+ * schema caps `items` at this constant, so every transport (fixture included)
95
+ * reports the same number.
96
+ */
97
+ readonly searchResultLimit = 20;
98
+ /** Catalog metadata and local reference-source projection. */
99
+ readonly list: SnapshotStore<SessionListState>;
100
+ /** The object-layer instance cluster and frame dispatch entry. */
101
+ private readonly manager;
102
+ private readonly scopes;
103
+ /** Stable per-id sources retained for the Client root lifetime, including across generation replacement. */
104
+ private readonly retainObservers;
105
+ private readonly scopeDrops;
106
+ private closed;
107
+ /**
108
+ * @param ctx - client root context (scope fibers mount under it).
109
+ * @param remote - generated Remote namespaces shared with every Session.
110
+ */
111
+ constructor(rootCtx: Context, remote: SessionRemotes);
112
+ retain(target: SessionTarget, options: SessionRetainOptions): SessionReference;
113
+ using<T>(target: SessionTarget, options: SessionRetainOptions, operation: (reference: SessionReference) => T | Promise<T>): Promise<T>;
114
+ retainInfo(id: SessionId): ObservableSnapshot<SessionRetainInfo>;
115
+ /**
116
+ * Resolve an already discovered direct-parent address without opening it.
117
+ * Feature plugins use this to avoid Agent-bound RPCs in persisted child views.
118
+ * @param id - possible addressed child id.
119
+ * @returns A retained, catalog-derived, or unknown-mode listed address, without retaining a new selection or scope.
120
+ */
121
+ subagentAddress(id: SessionId): SubagentAddress | undefined;
122
+ /**
123
+ * Read projections without starting migration; retry failed or migration-deferred reads.
124
+ * @param sessionId - Session to inspect without opening its conversation.
125
+ */
126
+ refreshProjections(sessionId: SessionId): Promise<void>;
127
+ /**
128
+ * Refresh the real Session baseline, reusing an in-flight pull.
129
+ * @returns completion of the current or newly started baseline pull.
130
+ */
131
+ refresh(): Promise<void>;
132
+ /**
133
+ * Search the Host's visible message-content index. Results stay
134
+ * request-local; the list snapshot remains the metadata authority.
135
+ * @param query - non-blank literal phrase.
136
+ * @param signal - cancellation for a superseded search.
137
+ * @returns bounded results or a business/transport error.
138
+ */
139
+ search(query: string, signal: AbortSignal): Promise<RemoteResult<{
140
+ items: SessionSearchResultItem[];
141
+ hasMore: boolean;
142
+ }>>;
143
+ /**
144
+ * Apply one Session Controller live-control frame.
145
+ * @param frame - baseline or live control replacement.
146
+ */
147
+ handleControlFrame(frame: Parameters<SessionManager['handleControlFrame']>[0]): void;
148
+ /**
149
+ * Apply one remotely forwarded Session-list addition.
150
+ * @param summary - current Host summary for the added Session.
151
+ */
152
+ handleSessionAdded(summary: Parameters<SessionManager['handleSessionAdded']>[0]): void;
153
+ /**
154
+ * Apply one remotely forwarded Session removal.
155
+ * @param sessionId - removed Session identity.
156
+ */
157
+ handleSessionRemoved(sessionId: Parameters<SessionManager['handleSessionRemoved']>[0]): void;
158
+ /**
159
+ * Apply one remotely forwarded running-state change.
160
+ * @param args - Session identity and current Agent running state.
161
+ */
162
+ handleSessionStatus(...args: Parameters<SessionManager['handleSessionStatus']>): void;
163
+ /**
164
+ * Apply one remotely forwarded list-activity change.
165
+ * @param args - Session identity and durable activity timestamp.
166
+ */
167
+ handleSessionActivity(...args: Parameters<SessionManager['handleSessionActivity']>): void;
168
+ /**
169
+ * Apply one remotely forwarded Agent failure.
170
+ * @param args - Session identity and caller-visible failure description.
171
+ */
172
+ handleSessionError(...args: Parameters<SessionManager['handleSessionError']>): void;
173
+ /** Rebuild the Session baseline and every opened window after connection. */
174
+ handleConnected(): void;
175
+ /**
176
+ * Create a Host Session and publish its catalog row before resolving.
177
+ * Callers retain the returned identity before borrowing its binding.
178
+ * @param opts - target workspace or directory, an optional blank Session to reuse, and an optional Agent preset.
179
+ * @returns the created or reused session id.
180
+ * @throws {SessionCreateError} with the requested id.
181
+ */
182
+ create(opts?: {
183
+ workspaceId?: WorkspaceId;
184
+ cwd?: string;
185
+ sessionId?: SessionId;
186
+ agentPreset?: string;
187
+ }): Promise<SessionId>;
188
+ /**
189
+ * Fork a session from an exact inclusive prefix of the source (same
190
+ * synchronous-addressability guarantee as {@link ClientSessions.create}:
191
+ * on resolution the child is catalogued and may be explicitly retained).
192
+ * @param opts - source session id, the optional exact inclusive boundary
193
+ * seq (a real event seq the caller already knows; a cut inside an open
194
+ * turn is balanced Host-side with synthetic closers, and omission selects
195
+ * the latest completed-turn prefix), and whether to increment an
196
+ * inherited durable title before resolving, plus permission to start source migration.
197
+ * @returns the child session id.
198
+ * @throws {SessionForkError} with the source id.
199
+ * @throws {Error} when a requested child-title rename fails after creation.
200
+ */
201
+ fork(opts: {
202
+ sessionId: SessionId;
203
+ atSeq?: number;
204
+ increaseTitle?: boolean;
205
+ onCreated?: (childId: SessionId) => void;
206
+ allowMigration?: boolean;
207
+ }): Promise<SessionId>;
208
+ /**
209
+ * Borrow an already-retained Agent-scoped Context.
210
+ * @param id - session id (the agent identity — 1:1 same axis).
211
+ * @returns the scoped Context, or undefined without a retained generation.
212
+ */
213
+ scope(id: SessionId): AgentContext | undefined;
214
+ /**
215
+ * Retain a validated Gateway identity synchronously, without history or catalog I/O.
216
+ * @param id - Host-projected Session identity, possibly not yet catalogued.
217
+ * @returns a Gateway-source reference owned by the invocation.
218
+ */
219
+ retainAgentScope(id: SessionId): SessionReference;
220
+ /**
221
+ * Read the Agent scope tag off a context. Service-method boundary: fetch
222
+ * bundles must reach scope resolution through ctx.sessions — a cross-bundle
223
+ * value import of the standalone helper would inline a second module
224
+ * instance whose private tag Symbol never matches.
225
+ * @param ctx - any client context.
226
+ * @returns the session id, or undefined on root contexts.
227
+ */
228
+ scopeOf(ctx: Context): SessionId | undefined;
229
+ /**
230
+ * Resolve the business Session behind an Agent-scoped context — the one
231
+ * hop every scoped consumer (event listeners, per-session controllers)
232
+ * takes from ctx-space into object-space (the client mirror of host
233
+ * `agent.session`). Same service-method boundary as
234
+ * {@link ClientSessions.scopeOf}.
235
+ * @param ctx - an Agent-scoped context.
236
+ * @returns the matching live Session, or undefined for an untagged or ended generation.
237
+ */
238
+ sessionOf(ctx: Context): SessionFace | undefined;
239
+ /**
240
+ * Borrow an already-retained binding without extending its lifetime.
241
+ * @param id - Session identity.
242
+ * @returns the live binding, or undefined without a retained generation.
243
+ */
244
+ binding(id: SessionId): SessionBinding | undefined;
245
+ private retainScope;
246
+ private retentionSnapshot;
247
+ private publishRetention;
248
+ private retireScope;
249
+ /** Materialize one scope after its caller establishes that the id may be addressed. */
250
+ private materializeScope;
251
+ /** Project the manager's list snapshot into the store (title derivation is display-only). */
252
+ private projectList;
253
+ private startScopeDrop;
254
+ private drainScopeDrops;
255
+ /** Await the already-withdrawn Session and scoped cleanup to quiescence. */
256
+ private dropScope;
257
+ }
258
+ //# sourceMappingURL=service.d.ts.map