@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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -2
  3. package/lib/client.js +4 -0
  4. package/lib/index.js +4300 -0
  5. package/lib/typert.host.d.ts +3 -0
  6. package/lib/typert.host.js +5013 -0
  7. package/lib/typert.remote-client.d.ts +115 -0
  8. package/lib/typert.remote-client.js +2714 -0
  9. package/lib/types/agent.d.ts +164 -0
  10. package/lib/types/agent.js +484 -0
  11. package/lib/types/archived-session-gate.d.ts +33 -0
  12. package/lib/types/archived-session-gate.js +54 -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 +107 -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 +178 -0
  20. package/lib/types/client/contract/session.js +1 -0
  21. package/lib/types/client/contract/sessions.d.ts +162 -0
  22. package/lib/types/client/contract/sessions.js +1 -0
  23. package/lib/types/client/contract/snapshot.d.ts +84 -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 +48 -0
  38. package/lib/types/client/sessions/lineage.js +55 -0
  39. package/lib/types/client/sessions/manager.d.ts +272 -0
  40. package/lib/types/client/sessions/manager.js +774 -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 +263 -0
  48. package/lib/types/client/sessions/service.js +597 -0
  49. package/lib/types/client/sessions/session.d.ts +303 -0
  50. package/lib/types/client/sessions/session.js +991 -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 +130 -0
  55. package/lib/types/commands.d.ts +92 -0
  56. package/lib/types/commands.js +575 -0
  57. package/lib/types/continuation.d.ts +35 -0
  58. package/lib/types/continuation.js +47 -0
  59. package/lib/types/control.d.ts +20 -0
  60. package/lib/types/control.js +106 -0
  61. package/lib/types/file-references.d.ts +27 -0
  62. package/lib/types/file-references.js +68 -0
  63. package/lib/types/history/assistant-stream.d.ts +43 -0
  64. package/lib/types/history/assistant-stream.js +79 -0
  65. package/lib/types/history/controller.d.ts +104 -0
  66. package/lib/types/history/controller.js +293 -0
  67. package/lib/types/history/listener.d.ts +105 -0
  68. package/lib/types/history/listener.js +296 -0
  69. package/lib/types/history.d.ts +58 -0
  70. package/lib/types/history.js +152 -0
  71. package/lib/types/index.d.ts +262 -0
  72. package/lib/types/index.js +693 -0
  73. package/lib/types/list.d.ts +62 -0
  74. package/lib/types/list.js +343 -0
  75. package/lib/types/media-references.d.ts +18 -0
  76. package/lib/types/media-references.js +84 -0
  77. package/lib/types/remote-events.d.ts +8 -0
  78. package/lib/types/remote-events.js +1 -0
  79. package/lib/types/skill-catalog.d.ts +28 -0
  80. package/lib/types/skill-catalog.js +203 -0
  81. package/lib/types/state/controller.d.ts +45 -0
  82. package/lib/types/state/controller.js +288 -0
  83. package/lib/types/state/listener.d.ts +40 -0
  84. package/lib/types/state/listener.js +111 -0
  85. package/lib/types/types.d.ts +687 -0
  86. package/lib/types/types.js +5 -0
  87. package/lib/types/web/controller.d.ts +25 -0
  88. package/lib/types/web/controller.js +138 -0
  89. package/locale/de.json +6 -0
  90. package/locale/en.json +5 -0
  91. package/locale/es.json +6 -0
  92. package/locale/fr.json +6 -0
  93. package/locale/ja.json +6 -0
  94. package/locale/pt.json +6 -0
  95. package/locale/ru.json +6 -0
  96. package/locale/zh.json +6 -0
  97. package/package.json +119 -4
  98. package/src/agent.ts +474 -0
  99. package/src/archived-session-gate.ts +59 -0
  100. package/src/assistant-stream.ts +102 -0
  101. package/src/catalog.ts +117 -0
  102. package/src/client/contract/events.ts +205 -0
  103. package/src/client/contract/session.ts +174 -0
  104. package/src/client/contract/sessions.ts +169 -0
  105. package/src/client/contract/snapshot.ts +94 -0
  106. package/src/client/index.ts +149 -0
  107. package/src/client/ordered-baseline.ts +43 -0
  108. package/src/client/scope.ts +76 -0
  109. package/src/client/session-wire-event.ts +46 -0
  110. package/src/client/sessions/assistant-stream.ts +229 -0
  111. package/src/client/sessions/history-records.ts +35 -0
  112. package/src/client/sessions/lineage.ts +96 -0
  113. package/src/client/sessions/manager.ts +857 -0
  114. package/src/client/sessions/notifier.ts +97 -0
  115. package/src/client/sessions/projection-store.ts +244 -0
  116. package/src/client/sessions/remotes.ts +44 -0
  117. package/src/client/sessions/service.ts +741 -0
  118. package/src/client/sessions/session.ts +1055 -0
  119. package/src/client/time-zone.ts +14 -0
  120. package/src/client/transport.ts +247 -0
  121. package/src/commands.ts +602 -0
  122. package/src/continuation.ts +58 -0
  123. package/src/control.ts +121 -0
  124. package/src/file-references.ts +42 -0
  125. package/src/history/assistant-stream.ts +102 -0
  126. package/src/history/controller.ts +256 -0
  127. package/src/history/listener.ts +302 -0
  128. package/src/history.ts +189 -0
  129. package/src/index.ts +651 -0
  130. package/src/list.ts +382 -0
  131. package/src/media-references.ts +84 -0
  132. package/src/remote-events.ts +14 -0
  133. package/src/skill-catalog.ts +108 -0
  134. package/src/state/controller.ts +221 -0
  135. package/src/state/listener.ts +116 -0
  136. package/src/types.ts +720 -0
  137. package/src/web/controller.ts +78 -0
package/src/types.ts ADDED
@@ -0,0 +1,720 @@
1
+ /** Browser-safe request, result, and lifecycle vocabulary for the Session Remote service. */
2
+
3
+ import type {} from '@unieai/rabi-agent/types'
4
+ import type { NativeFileApplication } from '@unieai/rabi-native-command/types'
5
+ import type {
6
+ ImageAttachmentLimits, ImageAttachmentRef, ImageMediaType,
7
+ } from '@unieai/rabi-attachment'
8
+ import type { Branded } from '@unieai/rabi-brand'
9
+ import type { LlmAttemptId, MessageId } from '@unieai/rabi-llm/brand'
10
+ import type { LlmModelBadge, TextBlock } from '@unieai/rabi-llm'
11
+ import type { SessionId, SessionSeq, SessionSeqCursor } from '@unieai/rabi-session/types'
12
+ import type { SessionProjectionMap, SessionProjectionSummaryExcluded, SessionProjectionSummaryValues } from '@unieai/rabi-session-projection/types'
13
+ import type { Principal } from '@unieai/rabi-typert-protocol'
14
+ import type { JsonValue } from '@unieai/rabi-util-values'
15
+ import type { WorkspaceId } from '@unieai/rabi-workspace/types'
16
+
17
+ declare module '@unieai/rabi-session-projection/types' {
18
+ interface SessionProjectionMap {
19
+ /** Eligible latest failed turn/end for an empty prompt, or null. */
20
+ conversationContinuation: SessionSeq | null
21
+ /** Persisted facts used to summarize a Session without activating it. */
22
+ sessionListMetadata: SessionListMetadata
23
+ /**
24
+ * Image-intake limits enforced by the Session prompt endpoint. Boot
25
+ * constant, excluded from Session summary payloads: every Session shares
26
+ * it, so a list row would repeat one host-wide fact.
27
+ */
28
+ imageLimits: SessionProjectionSummaryExcluded<ImageAttachmentLimits>
29
+ }
30
+ }
31
+
32
+ /** Persisted hints used to summarize a cold Session. */
33
+ export interface SessionListMetadata {
34
+ /** Whether the folded prefix contains no turn. */
35
+ readonly blank: boolean
36
+ /** Latest human-authored prompt time in the folded prefix. */
37
+ readonly lastPromptAt: number | null
38
+ }
39
+
40
+ /**
41
+ * Summary wire values a Session-list row carries. A `sequenced` block carries
42
+ * every summary key computed at its `asOfSeq`; a `cached` block carries the
43
+ * values the persisted cache holds and may omit keys or trail the Session.
44
+ * The block omits the keys whose unit declares `summary: false`. `kind` and `asOfSeq` are independent facts: `kind` says
45
+ * which sequence space `asOfSeq` belongs to, and therefore how a client may
46
+ * merge the block; `asOfSeq` is the producer's watermark in that space.
47
+ */
48
+ export interface SessionProjectionHints {
49
+ /**
50
+ * `sequenced`: the Host's live registry produced the block for an attached
51
+ * Session, so `asOfSeq` is comparable with baselines and frames of the same
52
+ * connection. `cached`: a header-only listing viewed the block from the
53
+ * persisted projection cache, so `asOfSeq` is the stored record's own
54
+ * watermark and must not be compared with the connected Session's values.
55
+ */
56
+ readonly kind: 'cached' | 'sequenced'
57
+ /** Watermark of the block in the sequence space named by `kind`. */
58
+ readonly asOfSeq: number
59
+ /** Provider-validated summary values present in the block; omitted keys remain unknown. */
60
+ readonly values: Partial<SessionProjectionSummaryValues>
61
+ }
62
+
63
+ /** Complete projection values at an exact Session event cursor. */
64
+ export interface SessionProjectionBaseline {
65
+ readonly asOfSeq: number
66
+ /** Provider-validated values; omitted keys are absent capabilities at this cut. */
67
+ readonly values: SessionProjectionValues
68
+ }
69
+
70
+ /** Typed known projections plus JSON-safe values contributed outside this compilation face. */
71
+ export type SessionProjectionValues = Partial<SessionProjectionMap>
72
+ & Readonly<Record<string, SessionProjectionValue>>
73
+
74
+ /**
75
+ * Browser-submitted prompt content; the Host promotes image bytes to durable
76
+ * references. File parts carry the opaque receipt returned by a preceding
77
+ * upload on the same Session; the receipt of an image upload enters the
78
+ * message as that image.
79
+ */
80
+ export type PromptContentPart =
81
+ | { readonly type: 'text'; readonly text: string }
82
+ | {
83
+ readonly type: 'image'
84
+ readonly mediaType: ImageMediaType
85
+ readonly data: string
86
+ readonly name?: string
87
+ }
88
+ | { readonly type: 'file'; readonly receiptId: Branded<'file-upload-receipt-id'> }
89
+
90
+ /** Complete model selection for one Session. */
91
+ export interface ModelSelection {
92
+ readonly provider: string
93
+ readonly model: string
94
+ readonly reasoningEffort?: string
95
+ }
96
+
97
+ /** One adapter-owned reasoning effort for an exact model route. */
98
+ export interface ModelReasoningEffort {
99
+ readonly id: string
100
+ readonly name: string
101
+ readonly description?: string
102
+ }
103
+
104
+ /** Selectable reasoning metadata for one exact model route. */
105
+ export interface ModelReasoning {
106
+ readonly efforts: readonly ModelReasoningEffort[]
107
+ readonly defaultEffort?: string
108
+ }
109
+
110
+ /** One model displayed inside its provider group. */
111
+ export interface ModelCatalogModel {
112
+ readonly id: string
113
+ readonly name: string
114
+ readonly description?: string
115
+ readonly reasoning?: ModelReasoning
116
+ /** Provider-authored label shown beside the name; display data only. */
117
+ readonly badge?: LlmModelBadge
118
+ }
119
+
120
+ /** One provider and its successfully loaded model catalog. */
121
+ export interface ModelProviderGroup {
122
+ readonly id: string
123
+ readonly name: string
124
+ readonly models: readonly ModelCatalogModel[]
125
+ }
126
+
127
+ /** One provider whose model catalog lookup failed. */
128
+ export interface ModelCatalogFailure {
129
+ readonly id: string
130
+ readonly name: string
131
+ readonly message: string
132
+ }
133
+
134
+ /** Host-generation model catalog and the default used by unconfigured Sessions. */
135
+ export interface ModelCatalog {
136
+ readonly default: ModelSelection
137
+ /** Provider routes with at least one currently available catalog model. */
138
+ readonly routableProviders: readonly string[]
139
+ readonly groups: readonly ModelProviderGroup[]
140
+ readonly failures: readonly ModelCatalogFailure[]
141
+ }
142
+
143
+ /** One client-requested mutation of a still-pending queue item. */
144
+ export type QueueAction =
145
+ | {
146
+ readonly kind: 'edit'
147
+ /** Non-empty text-only replacement content. */
148
+ readonly content: readonly TextBlock[]
149
+ }
150
+ | { readonly kind: 'remove' }
151
+ | { readonly kind: 'steer' }
152
+
153
+ /** One Session list entry. */
154
+ export interface SessionSummary {
155
+ /** Whether this Session currently owns a live Agent. */
156
+ readonly agentAvailable: boolean
157
+ /** Current for attached Sessions; otherwise the persistence format status when reported. */
158
+ readonly formatStatus?: 'current' | 'migration-required'
159
+ readonly sessionId: SessionId
160
+ readonly updatedAt: number
161
+ readonly running: boolean
162
+ readonly blank: boolean
163
+ readonly parentSessionId?: SessionId
164
+ readonly origin?: 'subagent'
165
+ readonly cwd?: string
166
+ readonly projections?: SessionProjectionHints
167
+ }
168
+
169
+ /** One session-content search result. */
170
+ export interface SessionSearchItem {
171
+ readonly sessionId: SessionId
172
+ readonly snippet: string
173
+ }
174
+
175
+ /** Maximum number of Sessions returned by one search. */
176
+ export const SESSION_SEARCH_RESULT_LIMIT = 20
177
+
178
+ /** Maximum search snippet length in Unicode code points. */
179
+ export const SESSION_SEARCH_SNIPPET_MAX_CODE_POINTS = 240
180
+
181
+ declare module '@unieai/rabi-typert-protocol' {
182
+ interface RemoteErrorDetailsMap {
183
+ /** A wait observation ended before a stopping state; the caller should reread. */
184
+ 'session/observation-ended': Record<string, never>
185
+ /** No state arrived before the deadline; a timeout after a state returns its value instead. */
186
+ 'session/wait-timeout': Record<string, never>
187
+ 'session/provider-credentials-unavailable': Record<string, never>
188
+ 'session/provider-models-unavailable': { readonly provider: string }
189
+ 'session/model-unavailable': { readonly provider: string; readonly model: string }
190
+ 'session/conflict': {
191
+ readonly sessionId: SessionId
192
+ readonly requestedCwd: string
193
+ readonly existingCwd?: string
194
+ }
195
+ 'session/projections-unavailable': Record<string, never>
196
+ 'session/writer-held': { readonly sessionId: SessionId }
197
+ 'session/agent-busy': { readonly reason: string }
198
+ 'session/invalid-time-zone': { readonly value: string }
199
+ 'session/workspace-attach-failed': { readonly sessionId: SessionId; readonly workspaceId: string }
200
+ 'agent-preset/conflict': {
201
+ readonly sessionId: SessionId
202
+ readonly requestedPreset: string
203
+ }
204
+ 'session/attachment-invalid': { readonly reason: string }
205
+ 'session/queue-item-not-found': { readonly itemId: MessageId }
206
+ 'session/steer-unavailable': { readonly itemId: MessageId }
207
+ 'session/title-invalid': { readonly sessionId: SessionId }
208
+ 'session/fork-unavailable': { readonly sessionId: SessionId }
209
+ 'session/migration-required': { readonly sessionId: SessionId }
210
+ 'subagent/not-found': {
211
+ readonly parentSessionId: SessionId
212
+ readonly childSessionId: SessionId
213
+ }
214
+ 'subagent/catalog-diagnostic': {
215
+ readonly parentSessionId: SessionId
216
+ readonly childSessionId: SessionId
217
+ readonly reason: 'corrupt' | 'unsupported' | 'unavailable'
218
+ }
219
+ }
220
+ }
221
+
222
+ /** Session-addressed request for the human-invocable skill catalog. */
223
+ export interface SkillListRequest {
224
+ readonly sessionId: SessionId
225
+ }
226
+
227
+ /** One skill available to the Session's human-facing composer. */
228
+ export interface SkillEntry {
229
+ /** Absolute SKILL.md path when supplied by a filesystem provider. */
230
+ readonly path?: string
231
+ /** Kebab-case identifier referenced as `/name`. */
232
+ readonly name: string
233
+ /** Short routing description. */
234
+ readonly description: string
235
+ /** Optional extra routing guidance. */
236
+ readonly whenToUse?: string
237
+ /** Whether the same skill is also advertised to the model. */
238
+ readonly modelInvocable: boolean
239
+ }
240
+
241
+ /** Human-invocable skills visible through one Session's composition. */
242
+ export interface SkillListValue {
243
+ readonly skills: readonly SkillEntry[]
244
+ }
245
+
246
+ /** Session list request. */
247
+ export interface SessionListRequest {
248
+ readonly cursor?: string
249
+ }
250
+
251
+ /** Session list response value. */
252
+ export interface SessionListValue {
253
+ readonly items: readonly SessionSummary[]
254
+ }
255
+
256
+ /** Session search request. */
257
+ export interface SessionSearchRequest {
258
+ readonly query: string
259
+ }
260
+
261
+ /** Session search response value. */
262
+ export interface SessionSearchValue {
263
+ readonly items: readonly SessionSearchItem[]
264
+ readonly hasMore: boolean
265
+ }
266
+
267
+ /** Request for a Session for a new conversation. */
268
+ export interface SessionCreateRequest {
269
+ /** Workspace the Session joins; exclusive with `cwd`. */
270
+ readonly workspaceId?: WorkspaceId
271
+ /** Directory the Session owns when no Workspace is named. */
272
+ readonly cwd?: string
273
+ /** Blank Session to reuse while it is reusable, or the identity of a new Session when none is stored under it. */
274
+ readonly sessionId?: SessionId
275
+ /** Preset the Session runs, replacing a reused Session's recorded preset; the configured default when omitted. */
276
+ readonly agentPreset?: string
277
+ }
278
+
279
+ /** Session creation response value. */
280
+ export interface SessionCreateValue {
281
+ /** The created or reused Session, which may differ from the requested `sessionId`. */
282
+ readonly sessionId: SessionId
283
+ /** Preset the Session runs, when the deployment composes a preset roster. */
284
+ readonly agentPreset?: string
285
+ }
286
+
287
+ /** Session model-selection request. */
288
+ export interface SessionSelectModelRequest extends ModelSelection {
289
+ readonly sessionId: SessionId
290
+ }
291
+
292
+ /** Accepted model selection after Host resolution. */
293
+ export interface SessionSelectModelValue {
294
+ readonly selected: ModelSelection
295
+ }
296
+
297
+ /** Session rename request. */
298
+ export interface SessionRenameRequest {
299
+ readonly sessionId: SessionId
300
+ readonly title: string
301
+ }
302
+
303
+ /** Normalized title and the durable event position that committed it. */
304
+ export interface SessionRenameValue {
305
+ readonly title: string
306
+ readonly seq: number
307
+ }
308
+
309
+ /** Session fork request. */
310
+ export interface SessionForkRequest {
311
+ readonly sessionId: SessionId
312
+ /** Exact inclusive source event seq; omission selects the latest completed-turn prefix. */
313
+ readonly atSeq?: number
314
+ /** False asks the Host to check for required migration before forking. Defaults to true. */
315
+ readonly allowMigration?: boolean
316
+ }
317
+
318
+ /** Identity of a newly forked Session. */
319
+ export interface SessionForkValue {
320
+ readonly sessionId: SessionId
321
+ }
322
+
323
+ /** Session prompt request. */
324
+ export interface SessionPromptRequest {
325
+ /** Client-minted identity persisted on the accepted inbox input, including empty continuation. */
326
+ readonly requestId: SessionRequestId
327
+ readonly sessionId: SessionId
328
+ readonly mode: 'queue' | 'steer'
329
+ /** Non-whitespace text or attachments; an empty array continues an eligible failed idle Session. */
330
+ readonly content: readonly PromptContentPart[]
331
+ readonly clientTimeZone?: string
332
+ }
333
+
334
+ /** Receipt after one prompt enters the target Agent inbox. */
335
+ export interface SessionPromptValue {
336
+ readonly accepted: true
337
+ }
338
+
339
+ /** Durable image read request. */
340
+ export interface SessionAttachmentRequest {
341
+ /** Gateway permission scope only; neither Session existence nor its image references are checked. */
342
+ readonly sessionId: SessionId
343
+ readonly attachment: ImageAttachmentRef
344
+ }
345
+
346
+ /** Durable image read response value. */
347
+ export interface SessionAttachmentValue {
348
+ /** Supplied reference after ID, format, byte length, and dimensions verification; display fields are preserved. */
349
+ readonly attachment: ImageAttachmentRef
350
+ readonly data: string
351
+ }
352
+
353
+ /** Pending queue mutation request. */
354
+ export interface SessionUpdateQueueRequest {
355
+ readonly sessionId: SessionId
356
+ readonly itemId: MessageId
357
+ readonly action: QueueAction
358
+ }
359
+
360
+ /** Receipt after one pending queue mutation commits. */
361
+ export interface SessionUpdateQueueValue {
362
+ readonly accepted: true
363
+ }
364
+
365
+ /** Active-turn cancellation request. */
366
+ export interface SessionCancelRequest {
367
+ readonly sessionId: SessionId
368
+ }
369
+
370
+ /** Receipt after cancellation is admitted to the live Agent. */
371
+ export interface SessionCancelValue {
372
+ readonly accepted: true
373
+ }
374
+
375
+ /** Request to open one path prepared by a Session-aware caller on the Host desktop. */
376
+ export interface SessionOpenWorkspacePathRequest {
377
+ /** File-manager navigation when requested; omission uses the default application. */
378
+ readonly action?: 'reveal'
379
+ /** Registered application identifier; ignored for reveal. Omission preserves the operating system default. */
380
+ readonly application?: string
381
+ /** Path after best-effort Session workspace resolution, in Host filesystem syntax. */
382
+ readonly path: string
383
+ }
384
+
385
+ /** Confirmation that the Host handed a workspace path to its native opener. */
386
+ export interface SessionOpenWorkspacePathValue {
387
+ readonly opened: true
388
+ }
389
+
390
+ /** Client-minted prompt identity used to reconcile optimistic and durable messages. */
391
+ export type SessionRequestId = Branded<'session-request-id'>
392
+
393
+ declare module '@unieai/rabi-llm' {
394
+ interface MessageSourceMap {
395
+ /**
396
+ * Browser prompt correlation, optional Host-validated time zone, and the
397
+ * caller that submitted the prompt. `principal` is written only for a
398
+ * caller other than the owner, so an absent `principal` means the owner.
399
+ */
400
+ 'user-rpc': { kind: 'user'; rpcId: SessionRequestId; clientTimeZone?: string; principal?: Principal }
401
+ /** Empty retry user message with browser prompt correlation and caller metadata. */
402
+ 'retry-rpc': { kind: 'retry'; rpcId: SessionRequestId; clientTimeZone?: string; principal?: Principal }
403
+ }
404
+ }
405
+
406
+ /** Durable identity selecting an ordinary Session or one direct subagent child. */
407
+ export type SessionAddress =
408
+ | { readonly kind: 'session'; readonly sessionId: SessionId }
409
+ | {
410
+ readonly kind: 'subagent'
411
+ readonly parentSessionId: SessionId
412
+ readonly childSessionId: SessionId
413
+ readonly mode: 'one-shot' | 'continuable' | 'unknown'
414
+ }
415
+
416
+ /** One non-activating Session projection read. */
417
+ export interface SessionProjectionsRequest {
418
+ readonly sessionId: SessionId
419
+ }
420
+
421
+ /** Exact projections carry their event cut; required migration returns sequence-free cache hints. Null means absent. */
422
+ export type SessionProjectionsValue =
423
+ | (SessionProjectionBaseline & { readonly kind: 'sequenced' })
424
+ | { readonly kind: 'migration-required'; readonly values: SessionProjectionValues }
425
+ | null
426
+
427
+ /** One raw Session event in the Remote journal. */
428
+ export interface SessionEventEntry {
429
+ readonly type: 'event'
430
+ readonly event: SessionWireEvent
431
+ }
432
+
433
+ /** Current logical Session metadata carried on the browser wire. */
434
+ export interface SessionWireHeader {
435
+ readonly version: number
436
+ readonly id: SessionId
437
+ readonly createdAt: number
438
+ readonly cwd?: string
439
+ readonly parentSession?: SessionId
440
+ /** Whether the Session contains a fork-inherited prefix. */
441
+ readonly isSeeded: boolean
442
+ readonly origin?: 'subagent'
443
+ readonly delegationDepth?: number
444
+ readonly agentPreset?: string
445
+ }
446
+
447
+ /** Browser wire surface operation; replacement endpoints are earlier event seqs in surface order. */
448
+ export type SessionWireSurfaceOp =
449
+ | 'append'
450
+ | { readonly op: 'replace'; readonly startSeq: number; readonly endSeq: number }
451
+
452
+ /** One history-page record with compact Assistant streams embedded inside events. */
453
+ export type SessionHistoryRecord = SessionEventEntry
454
+
455
+ /**
456
+ * Exact Session event envelope accepted by the Client journal adapter.
457
+ * Surface events require surfaceOp; only non-Assistant surface events may cite earlier sources.
458
+ * Durable readers own recognition of merge-extensible event names.
459
+ */
460
+ export interface SessionWireEvent {
461
+ readonly type: string
462
+ readonly seq: number
463
+ readonly time: number
464
+ readonly data: JsonValue
465
+ readonly ignorable?: true
466
+ /** Earlier sources on current surface events; opaque JSON on unknown ignorable events. */
467
+ readonly sourceEventSeqs?: JsonValue
468
+ /** Canonical placement on current surface events; opaque JSON on unknown ignorable events. */
469
+ readonly surfaceOp?: JsonValue
470
+ }
471
+
472
+ /** One message-aligned backwards-history request. */
473
+ export interface SessionPageRequest {
474
+ readonly address: SessionAddress
475
+ /**
476
+ * Inclusive log cut; omission selects the observed log end. A follow opening
477
+ * reports the cut it covered so a caller can pin the same point.
478
+ */
479
+ readonly throughSeq?: number
480
+ readonly beforeSeq?: number
481
+ readonly maxMessages?: number
482
+ /** Stop at a Turn start after both minima, unless maxMessages or history exhaustion wins. */
483
+ readonly turnWindow?: {
484
+ /** Minimum append-origin user/assistant messages; must not exceed maxMessages. */
485
+ readonly minMessages: number
486
+ /** Minimum Turn starts crossed, including the partial Turn at beforeSeq. */
487
+ readonly minTurns: number
488
+ }
489
+ }
490
+
491
+ /** One live event request for a durable Session address. */
492
+ export interface SessionFollowRequest extends Pick<SessionPageRequest, 'maxMessages' | 'turnWindow'> {
493
+ readonly address: SessionAddress
494
+ /** Request background activation; omission leaves the read passive. */
495
+ readonly activate?: boolean
496
+ /** Include process-local assistant presentation frames for the Web client. */
497
+ readonly assistantStream?: true
498
+ }
499
+
500
+ /** One active assistant attempt in a reconnect opening snapshot. */
501
+ export interface SessionAssistantStreamAttempt {
502
+ readonly attemptId: LlmAttemptId
503
+ /** Last durable Session seq observed when this attempt started. */
504
+ readonly startedAfterSeq: SessionSeqCursor
505
+ readonly turn: number
506
+ readonly step: number
507
+ /** Dense position expected for the next live chunk frame. */
508
+ readonly nextIndex: number
509
+ /** Compact detached stream accumulated at this opening revision. */
510
+ readonly stream: readonly JsonValue[]
511
+ }
512
+
513
+ /** Complete process-local assistant state at one follow opening. */
514
+ export interface SessionAssistantStreamBaseline {
515
+ readonly revision: number
516
+ readonly activeAttempt?: SessionAssistantStreamAttempt
517
+ }
518
+
519
+ /** Browser wire form of one process-local assistant frame. */
520
+ export type SessionAssistantStreamFrame =
521
+ | {
522
+ readonly type: 'start'
523
+ readonly attemptId: LlmAttemptId
524
+ readonly revision: number
525
+ readonly startedAfterSeq: SessionSeqCursor
526
+ readonly turn: number
527
+ readonly step: number
528
+ }
529
+ | {
530
+ readonly type: 'chunk'
531
+ readonly attemptId: LlmAttemptId
532
+ readonly revision: number
533
+ readonly index: number
534
+ readonly time: number
535
+ readonly chunk: JsonValue
536
+ }
537
+ | {
538
+ readonly type: 'end'
539
+ readonly attemptId: LlmAttemptId
540
+ readonly revision: number
541
+ /** Number of chunk frames represented by this terminal marker. */
542
+ readonly index: number
543
+ readonly outcome:
544
+ | {
545
+ readonly kind: 'committed'
546
+ readonly eventType: 'assistant/message' | 'assistant/attempt'
547
+ readonly seq: number
548
+ }
549
+ | { readonly kind: 'abandoned' }
550
+ }
551
+
552
+ /** One contiguous backwards page of a Session log. */
553
+ export interface SessionPage {
554
+ readonly records: readonly SessionHistoryRecord[]
555
+ readonly hasMore: boolean
556
+ }
557
+
558
+ /** Complete opening window followed by ordered durable events and opted-in assistant frames. */
559
+ export type SessionFollowFrame =
560
+ | {
561
+ readonly type: 'snapshot'
562
+ readonly header: SessionWireHeader
563
+ readonly cursor: number
564
+ readonly records: readonly SessionHistoryRecord[]
565
+ readonly hasMore: boolean
566
+ readonly projections: SessionProjectionBaseline
567
+ readonly assistantStream?: SessionAssistantStreamBaseline
568
+ }
569
+ | SessionEventEntry
570
+ | { readonly type: 'assistant-stream'; readonly frame: SessionAssistantStreamFrame }
571
+
572
+ /** Complete live control baseline emitted once per control stream generation. */
573
+ export interface SessionControlBaseline {
574
+ readonly projections: Readonly<Record<SessionId, SessionProjectionBaseline>>
575
+ }
576
+
577
+ /**
578
+ * Projection changes caused by one committed Session event; the Host emits one
579
+ * update per event that changed at least one client-visible projection view.
580
+ */
581
+ export interface SessionProjectionUpdate {
582
+ readonly sessionId: SessionId
583
+ /** Seq of the committed event that caused every listed change. */
584
+ readonly seq: number
585
+ /**
586
+ * One entry per client-visible key whose view the event changed, in
587
+ * registration order without duplicate keys, with the key's new value as
588
+ * `val`. A key absent from `changes` is unchanged; unlike a baseline, absence
589
+ * does not mean an absent capability.
590
+ */
591
+ readonly changes: readonly { readonly key: string; readonly val: SessionProjectionValue }[]
592
+ }
593
+
594
+ /** Host-wide live state stream. Each generation starts with exactly one baseline. */
595
+ export type SessionControlFrame =
596
+ | { readonly type: 'baseline'; readonly value: SessionControlBaseline }
597
+ | ({ readonly type: 'projection' } & SessionProjectionUpdate)
598
+
599
+ /** One pending live-Agent inbox item, preserving placement and content order. */
600
+ export interface SessionQueuedItem {
601
+ readonly id: MessageId
602
+ readonly placement: 'queued' | 'steering' | 'context'
603
+ readonly rpcId?: SessionRequestId
604
+ readonly content: readonly JsonValue[]
605
+ }
606
+
607
+ /** State-owned classification of pending forwarded Remote events. */
608
+ export type SessionPendingInput = 'approval' | 'question' | 'other'
609
+
610
+ /** Passive Session state; a missing live Agent has no readable queue. */
611
+ export interface SessionState {
612
+ readonly cursor: number
613
+ readonly active: boolean
614
+ readonly running: boolean
615
+ readonly queue: readonly SessionQueuedItem[] | null
616
+ /**
617
+ * Pending Remote requests sampled when this state was read. A pending change alone does not
618
+ * trigger `observeState`; `wait` refreshes on its own interval.
619
+ */
620
+ readonly pendingInput: readonly SessionPendingInput[]
621
+ }
622
+
623
+ /** Session identity for a passive state read or subscription. */
624
+ export interface SessionStateRequest {
625
+ readonly sessionId: SessionId
626
+ }
627
+
628
+ /** Wait bounds and assistant output window; timeout omission uses the fixed 30-second default. */
629
+ export interface SessionWaitRequest extends SessionStateRequest {
630
+ readonly timeoutMs?: number
631
+ /** Exclusive output cursor; omission includes all available assistant records. */
632
+ readonly afterSeq?: number
633
+ /** Positive assistant-record limit; omission uses the history message budget. */
634
+ readonly maxMessages?: number
635
+ }
636
+
637
+ /** Assistant messages after afterSeq through the stopping state's cursor, newest first. */
638
+ export interface SessionWaitOutput {
639
+ readonly records: readonly SessionHistoryRecord[]
640
+ /** More eligible assistant messages exist in the selected interval. */
641
+ readonly truncated: boolean
642
+ }
643
+
644
+ /** A stopping condition, the last complete passive state and its bounded assistant output. */
645
+ export interface SessionWaitValue {
646
+ readonly reason: 'idle' | 'input-required' | 'timeout'
647
+ readonly state: SessionState
648
+ readonly output: SessionWaitOutput
649
+ }
650
+
651
+ /**
652
+ * One `session.events` page (or its deprecated `page` alias) with its inclusive cut:
653
+ * the supplied `throughSeq`, otherwise the log end it was read at.
654
+ */
655
+ export interface SessionEventsPage extends SessionPage {
656
+ readonly cursor: number
657
+ }
658
+
659
+ /** Address for a passive event subscription. */
660
+ export interface SessionObserveEventRequest {
661
+ readonly address: SessionAddress
662
+ }
663
+
664
+ /** Readiness confirms subscription only; event continuity starts with the first delivered event. */
665
+ export type SessionEventFrame =
666
+ | { readonly type: 'ready' }
667
+ | SessionEventEntry
668
+
669
+ /** Projection changes caused by one committed event of the observed Session. */
670
+ export type SessionProjectionChange = { readonly type: 'projection' } & Omit<SessionProjectionUpdate, 'sessionId'>
671
+
672
+ /** Subscription readiness without a baseline, followed by one change frame per committed event. */
673
+ export type SessionProjectionFrame =
674
+ | { readonly type: 'ready' }
675
+ | SessionProjectionChange
676
+
677
+ declare module '@unieai/cordis' {
678
+ interface Events {
679
+ /**
680
+ * A Session became visible or its Agent was created or disposed.
681
+ * Consumers upsert the summary and replace its current running and availability state.
682
+ * @mode emit
683
+ * @param summary - current list row for the Session.
684
+ */
685
+ 'api-session/added'(summary: SessionSummary): void
686
+ /**
687
+ * A Session left the live Host registry.
688
+ * @mode emit
689
+ * @param sessionId - removed Session identity.
690
+ */
691
+ 'api-session/removed'(sessionId: SessionId): void
692
+ /**
693
+ * One Agent changed running state.
694
+ * @mode emit
695
+ * @param sessionId - Agent and Session identity.
696
+ * @param running - whether the Agent is running.
697
+ */
698
+ 'api-session/status'(sessionId: SessionId, running: boolean): void
699
+ /**
700
+ * One user-authored durable message advanced Session list activity.
701
+ * @mode emit
702
+ * @param sessionId - addressed Session identity.
703
+ * @param updatedAt - durable message time used for list ordering.
704
+ */
705
+ 'api-session/activity'(sessionId: SessionId, updatedAt: number): void
706
+ /**
707
+ * One Agent failed outside a durable turn position.
708
+ * @mode emit
709
+ * @param sessionId - Agent and Session identity.
710
+ * @param message - user-safe failure chain.
711
+ */
712
+ 'api-session/error'(sessionId: SessionId, message: string): void
713
+ }
714
+ }
715
+
716
+ /** JSON-compatible projection value accepted by list consumers. */
717
+ export type SessionProjectionValue = JsonValue
718
+
719
+ /** Application metadata returned by the serving desktop for one file. */
720
+ export type SessionWorkspacePathApplication = NativeFileApplication