@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,96 @@
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
+ import type { SessionId } from '@unieai/rabi-session/types'
6
+ import type { SessionProjectionSummaryValues } from '@unieai/rabi-session-projection/types'
7
+ import type { SessionSummary } from '../../types.ts'
8
+
9
+ /** Host list summary enriched with the latest Session Controller title projection. */
10
+ export interface TitledSessionSummary extends SessionSummary {
11
+ title?: string
12
+ /**
13
+ * The row's summary projection values, never the full projection set. A
14
+ * connected Session's client store may hold more values from its
15
+ * control/follow baseline; those are outside the list contract and must not
16
+ * be read here.
17
+ */
18
+ projectionValues?: Readonly<Partial<SessionProjectionSummaryValues>>
19
+ }
20
+
21
+ /** One flattened session-list row with lineage depth. */
22
+ export interface SessionListEntry {
23
+ sessionId: SessionId
24
+ title?: string
25
+ updatedAt: number
26
+ running: boolean
27
+ /**
28
+ * New Session presentation and reuse eligibility, reconciled with
29
+ * `sessionListMetadata`; lists hide blank sessions (filtering stays with the consumer).
30
+ */
31
+ blank: boolean
32
+ parentSessionId?: SessionId
33
+ /** Coarse durable origin for navigation filtering; not a continuation capability. */
34
+ origin?: 'subagent'
35
+ /** Format classification supplied by the Host list. */
36
+ formatStatus?: SessionSummary['formatStatus']
37
+ cwd?: string
38
+ /**
39
+ * The row's summary projection values, never the full projection set; see
40
+ * `TitledSessionSummary.projectionValues`.
41
+ */
42
+ projectionValues?: Readonly<Partial<SessionProjectionSummaryValues>>
43
+ /** Lineage indent depth: root = 0; the UI just multiplies by the indent width. */
44
+ depth: number
45
+ }
46
+
47
+ /**
48
+ * Summaries -> flat list with lineage indentation. Root and sibling order
49
+ * follows the established input order; this projection never re-sorts a
50
+ * hydrated list from mutable timestamps.
51
+ * @param summaries - the host's session.list items.
52
+ * @returns display rows in render order.
53
+ */
54
+ export function flattenLineage(
55
+ summaries: readonly TitledSessionSummary[],
56
+ ): SessionListEntry[] {
57
+ const byId = new Map<SessionId, TitledSessionSummary>()
58
+ for (const s of summaries) byId.set(s.sessionId, s)
59
+
60
+ const children = new Map<SessionId, TitledSessionSummary[]>()
61
+ const roots: TitledSessionSummary[] = []
62
+ for (const s of summaries) {
63
+ // Historical ordinary forks may retain a parent id without being subagents.
64
+ if (s.origin === 'subagent' && s.parentSessionId !== undefined && byId.has(s.parentSessionId)) {
65
+ const list = children.get(s.parentSessionId) ?? []
66
+ list.push(s)
67
+ children.set(s.parentSessionId, list)
68
+ } else {
69
+ roots.push(s) // root, or an orphan whose parent is absent from summaries (degrade to root, never drop)
70
+ }
71
+ }
72
+
73
+ const out: SessionListEntry[] = []
74
+ const visited = new Set<SessionId>()
75
+ const walk = (s: TitledSessionSummary, depth: number): void => {
76
+ if (visited.has(s.sessionId)) {
77
+ console.warn(`[session-controller] lineage cycle at ${s.sessionId}; emitting as root`)
78
+ return
79
+ }
80
+ visited.add(s.sessionId)
81
+ const { agentAvailable: _agentAvailable, ...row } = s
82
+ out.push({
83
+ ...row,
84
+ depth,
85
+ })
86
+ const kids = children.get(s.sessionId)
87
+ if (kids === undefined) return
88
+ for (const kid of kids) walk(kid, depth + 1)
89
+ }
90
+ for (const root of roots) walk(root, 0)
91
+ // Cycle members (unreachable from any root): emit as roots so no entry is lost.
92
+ for (const s of summaries) {
93
+ if (!visited.has(s.sessionId)) walk(s, 0)
94
+ }
95
+ return out
96
+ }