@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
@@ -0,0 +1,78 @@
1
+ /** Web opening aggregation over one observation and a shared transforming buffer. */
2
+
3
+ import type { Context } from '@unieai/cordis'
4
+ import { remoteErrorOf } from '@unieai/rabi-typert-protocol'
5
+ import type { SessionObservation } from '@unieai/rabi-session-query'
6
+ import type { HistoryController } from '../history/controller.ts'
7
+ import { addressId, rejectNotFound } from '../history.ts'
8
+ import { EventListener, ListenerBuffer } from '../history/listener.ts'
9
+ import { history, projections, resolveHistoryRequest, validateObservationAddress } from '../history/controller.ts'
10
+ import type { SessionFollowFrame, SessionFollowRequest } from '../types.ts'
11
+
12
+ /** Combines opening data and consumes transformed listener output from one queue. */
13
+ export class WebController {
14
+
15
+ /**
16
+ * @param ctx - Host context carrying Session queries and identity projections.
17
+ * @param historyController - passive reading and listener construction.
18
+ * @param promote - background activation requested before an opening snapshot is delivered.
19
+ */
20
+ constructor(
21
+ private readonly ctx: Context,
22
+ private readonly historyController: HistoryController,
23
+ private readonly promote: (observation: SessionObservation) => void,
24
+ ) {}
25
+
26
+ /**
27
+ * Open a history snapshot and follow uncovered history and assistant notifications.
28
+ * @param request - Session identity, page budget, assistant output and optional activation (default false).
29
+ * @param signal - cancellation for opening and streaming.
30
+ * @returns an opening snapshot followed by uncovered queued increments.
31
+ */
32
+ async *follow(request: SessionFollowRequest, signal: AbortSignal): AsyncIterable<SessionFollowFrame> {
33
+ const sessionId = addressId(request.address)
34
+ const spec = resolveHistoryRequest(request)
35
+ using queue = new ListenerBuffer<SessionFollowFrame>(this.ctx, signal)
36
+ using listener = new EventListener(this.ctx, sessionId, signal, queue)
37
+ const streams = this.historyController.streamsListener
38
+ using assistantListener = request.assistantStream === true
39
+ ? streams.bind(sessionId, signal, queue)
40
+ : undefined
41
+ using observation = await this.historyController.usingObservation({ sessionId, projection: true }, signal)
42
+ .catch((error: unknown) => {
43
+ if (remoteErrorOf(error)?.code === 'session/not-found') rejectNotFound(request.address)
44
+ throw error
45
+ })
46
+ validateObservationAddress(request.address, observation)
47
+ let opening: SessionFollowFrame = {
48
+ type: 'snapshot',
49
+ header: { ...observation.header },
50
+ projections: projections(observation),
51
+ ...history(observation, spec),
52
+ }
53
+ listener.setCursor(opening.cursor)
54
+ if (assistantListener !== undefined) {
55
+ const { baseline: assistantStream, ordinal } = assistantListener.snapshot()
56
+ opening = { ...opening, assistantStream }
57
+ assistantListener.setOrdinalCut(ordinal)
58
+ }
59
+ // Increments come from the queue, so the opening ends this lease in every branch;
60
+ // activation continues on its own retained lease. Promotion starts before the opening is
61
+ // delivered, so a consumer that stops after the snapshot still gets the activation it asked for.
62
+ if (request.activate === true && !signal.aborted
63
+ && observation.header.origin !== 'subagent' && observation.source === 'prepared') {
64
+ const promotion = observation.retain()
65
+ observation[Symbol.dispose]()
66
+ try {
67
+ this.promote(promotion)
68
+ } catch (error: unknown) {
69
+ promotion[Symbol.dispose]()
70
+ throw error
71
+ }
72
+ } else {
73
+ observation[Symbol.dispose]()
74
+ }
75
+ yield opening
76
+ yield* queue.items()
77
+ }
78
+ }