@skyhook-io/radar-app 1.22.2 → 1.23.0

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 (196) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +35 -10
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/api/agentSandbox.ts +259 -0
  6. package/src/api/client.autoPromConnect.test.tsx +43 -0
  7. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  8. package/src/api/client.ts +122 -24
  9. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  10. package/src/api/diagnose.ts +4 -0
  11. package/src/api/kagent.test.ts +82 -0
  12. package/src/api/kagent.ts +230 -0
  13. package/src/api/prometheusCharts.ts +5 -0
  14. package/src/api/radarFeatures.test.ts +9 -0
  15. package/src/api/radarFeatures.ts +13 -0
  16. package/src/api/substrateWorkspace.test.ts +72 -0
  17. package/src/api/substrateWorkspace.ts +1394 -0
  18. package/src/api/vulnerabilities.ts +207 -9
  19. package/src/api/workloadSource.test.tsx +315 -0
  20. package/src/api/workloadSource.ts +128 -12
  21. package/src/components/CloudConnectFlow.tsx +46 -7
  22. package/src/components/CloudFunnelButton.test.tsx +193 -7
  23. package/src/components/CloudFunnelButton.tsx +127 -32
  24. package/src/components/SelfManagedStart.tsx +12 -2
  25. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  26. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  27. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  28. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  29. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  30. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  31. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  32. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  33. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  34. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  35. package/src/components/agentsandbox/data.ts +135 -0
  36. package/src/components/agentsandbox/host.test.ts +27 -0
  37. package/src/components/agentsandbox/host.tsx +85 -0
  38. package/src/components/agentsandbox/labels.test.ts +42 -0
  39. package/src/components/agentsandbox/labels.ts +146 -0
  40. package/src/components/agentsandbox/listFilters.ts +85 -0
  41. package/src/components/agentsandbox/lists.ts +52 -0
  42. package/src/components/agentsandbox/routes.ts +23 -0
  43. package/src/components/agentsandbox/shared.tsx +321 -0
  44. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  45. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  46. package/src/components/agentsandbox/workspace.tsx +258 -0
  47. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  48. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  49. package/src/components/applications/ApplicationsView.tsx +156 -3
  50. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  51. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  52. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  53. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  54. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  55. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  56. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  57. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  58. package/src/components/cloudHints/cloudHints.ts +131 -0
  59. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  60. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  61. package/src/components/cloudHints/cloudLinks.ts +31 -0
  62. package/src/components/cloudHints/hintStorage.ts +28 -0
  63. package/src/components/cnpg/CNPGView.tsx +4 -7
  64. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  65. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  66. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  67. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  68. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  69. package/src/components/home/HomeAgentBlock.tsx +2 -0
  70. package/src/components/home/HomeView.tsx +3 -3
  71. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  72. package/src/components/home/MCPSetupDialog.tsx +6 -2
  73. package/src/components/home/McpCloudLine.test.tsx +162 -0
  74. package/src/components/home/McpCloudLine.tsx +95 -0
  75. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  76. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  77. package/src/components/home/mcpToolCatalog.ts +4 -4
  78. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  79. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  80. package/src/components/issues/IssuesPane.tsx +181 -23
  81. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  82. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  83. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  84. package/src/components/issues/sinceLastVisit.ts +439 -0
  85. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  86. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  87. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  88. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  89. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  90. package/src/components/kagent/KagentLists.tsx +412 -0
  91. package/src/components/kagent/KagentOverview.tsx +234 -0
  92. package/src/components/kagent/KagentPages.tsx +690 -0
  93. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  94. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  95. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  96. package/src/components/kagent/KagentView.tsx +109 -0
  97. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  98. package/src/components/kagent/host.tsx +144 -0
  99. package/src/components/kagent/routes.ts +31 -0
  100. package/src/components/kagent/shared.tsx +336 -0
  101. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  102. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  103. package/src/components/kagent/workspace.fixtures.ts +108 -0
  104. package/src/components/kagent/workspaceRoute.ts +18 -0
  105. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  106. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  107. package/src/components/resource/PrometheusCharts.tsx +10 -1
  108. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  109. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  110. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  111. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  112. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  113. package/src/components/resources/ResourcesView.tsx +2 -6
  114. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  115. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  116. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  117. package/src/components/settings/SettingsDialog.tsx +84 -16
  118. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  119. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  120. package/src/components/settings/SubstrateSettings.tsx +544 -0
  121. package/src/components/settings/settings-state.test.ts +21 -3
  122. package/src/components/settings/settings-state.ts +13 -3
  123. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  124. package/src/components/share/ShareLinkButton.tsx +391 -0
  125. package/src/components/share/openShareInCloud.test.ts +29 -0
  126. package/src/components/share/openShareInCloud.ts +10 -0
  127. package/src/components/share/shareLink.test.ts +129 -0
  128. package/src/components/share/shareLink.ts +175 -0
  129. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  130. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  131. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  132. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  133. package/src/components/substrate/SubstrateActors.tsx +612 -0
  134. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  135. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  136. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  137. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  138. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  139. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  140. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  141. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  142. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  143. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  144. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  145. package/src/components/substrate/SubstrateView.tsx +173 -0
  146. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  147. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  148. package/src/components/substrate/attention.ts +81 -0
  149. package/src/components/substrate/contextPin.tsx +69 -0
  150. package/src/components/substrate/host.tsx +83 -0
  151. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  152. package/src/components/substrate/readings.test.ts +484 -0
  153. package/src/components/substrate/readings.ts +997 -0
  154. package/src/components/substrate/routes.ts +103 -0
  155. package/src/components/substrate/shared.tsx +426 -0
  156. package/src/components/substrate/substrate.fixtures.ts +325 -0
  157. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  158. package/src/components/substrate/workspaceRoute.ts +23 -0
  159. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  160. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  161. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  162. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  163. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  164. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  165. package/src/components/traffic/TrafficGraph.tsx +17 -14
  166. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  167. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  168. package/src/components/traffic/TrafficView.tsx +26 -56
  169. package/src/components/traffic/trafficFilters.test.ts +61 -1
  170. package/src/components/traffic/trafficFilters.ts +68 -8
  171. package/src/components/velero/VeleroOverview.tsx +2 -2
  172. package/src/components/velero/VeleroView.tsx +3 -6
  173. package/src/components/vulnerabilities/columns.tsx +132 -0
  174. package/src/components/vulnerabilities/filters.tsx +317 -0
  175. package/src/components/vulnerabilities/owner.test.ts +54 -0
  176. package/src/components/vulnerabilities/owner.tsx +163 -0
  177. package/src/components/vulnerabilities/parts.test.ts +126 -12
  178. package/src/components/vulnerabilities/parts.tsx +612 -52
  179. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  180. package/src/components/vulnerabilities/traffic.tsx +40 -0
  181. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  182. package/src/components/workload/WorkloadView.tsx +52 -13
  183. package/src/components/workspace/layout.tsx +13 -7
  184. package/src/components/workspace/sidebar.test.ts +48 -0
  185. package/src/components/workspace/sidebar.ts +73 -3
  186. package/src/components/workspace/table.ts +2 -1
  187. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  188. package/src/contexts/RegistryAccessMode.tsx +25 -0
  189. package/src/integrations/resourceHost.ts +12 -6
  190. package/src/integrations/resourceHosts.test.tsx +27 -1
  191. package/src/integrations/resourceHosts.tsx +15 -7
  192. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  193. package/src/integrations/sidebarWorkspaces.ts +41 -0
  194. package/src/integrations/workspaceRoute.ts +1 -1
  195. package/src/integrations/workspaceRoutes.ts +7 -1
  196. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -0,0 +1,612 @@
1
+ import { SlidersHorizontal } from 'lucide-react'
2
+ import { SubstrateStateBar } from './SubstrateStateBar'
3
+ import { shortRevision } from '@skyhook-io/k8s-ui/components/resources/resource-utils-kagent'
4
+ import { useEffect, useMemo, useState, type ReactNode } from 'react'
5
+ import { clsx } from 'clsx'
6
+ import { useSearchParams } from 'react-router-dom'
7
+ import { Collapse, Input, SelectMenu, Tooltip, TruncatedText, WorkspaceCard, toneTextClass, useDisclosure, type SelectMenuOption } from '@skyhook-io/k8s-ui'
8
+ import { useRadarFeature } from '../../api/client'
9
+ import {
10
+ useSubstrateActors,
11
+ useSubstrateTemplates,
12
+ type KagentActor,
13
+ type KagentAgentRef,
14
+ type KagentAttribution,
15
+ type SubstrateAPITier,
16
+ type SubstrateActorRow,
17
+ type SubstratePoolsCoverage,
18
+ type SubstrateActorState,
19
+ type SubstrateActors as SubstrateActorsResponse,
20
+ type SubstrateStatus,
21
+ type SubstrateWorkspace,
22
+ type SubstrateRef,
23
+ substrateErrorCode,
24
+ } from '../../api/substrateWorkspace'
25
+ import type { SelectedResource } from '../../types'
26
+ import { FilterChips, Notice, RefreshFailedNotice, ScreenBody, Segments, SectionTable, Sub, type TableColumn } from '../workspace/layout'
27
+ import {
28
+ ACTOR_SEGMENTS,
29
+ ACTOR_STATE_LABEL,
30
+ agentFilterValue,
31
+ agentText,
32
+ kagentCellText,
33
+ kagentUnreadText,
34
+ kagentUnattributedText,
35
+ shortSessionId,
36
+ coverageInPart,
37
+ coverageReason,
38
+ definitiveFailure,
39
+ durableText,
40
+ fidelityLabel,
41
+ resumeSentence,
42
+ stateExtra,
43
+ segmentCount,
44
+ segmentOfState,
45
+ templateFilterValue,
46
+ type ActorSegment,
47
+ } from './readings'
48
+ import { SubstrateConnectNotice, SubstrateTierBanner } from './SubstrateConnect'
49
+ import { ActorStateBadge, Name, SUBSTRATE_WIDE, SubstrateHeader, SubstrateSourceLine, Unread, When } from './shared'
50
+ import { useMediaQuery } from '../../hooks/useMediaQuery'
51
+
52
+ export const ACTORS_PAGE_SIZE = 50
53
+
54
+ export type ActorSort = 'attention' | 'updated' | 'name'
55
+
56
+ const SORT_OPTIONS = [
57
+ { value: 'attention', label: 'Needs attention first', description: 'Crashed, then worker disruptions and stuck transitions' },
58
+ { value: 'updated', label: 'Newest change first' },
59
+ { value: 'name', label: 'By name' },
60
+ ]
61
+
62
+ export const SORT_LABEL: Record<ActorSort, string> = { attention: 'needs attention first', updated: 'newest change first', name: 'by atespace and name' }
63
+
64
+ export type NodeHas = 'running' | 'localSnapshot'
65
+
66
+ /** What each node mode lists: what a node's loss stops, and what it could lose. */
67
+ export const NODE_HAS_MEANING: Record<NodeHas, string> = {
68
+ running: 'Actors whose worker is on this node: losing the node stops them.',
69
+ localSnapshot: 'Actors whose newest snapshot is stored only on this node: losing the node loses that state. Deleting the worker Pod alone doesn’t.',
70
+ }
71
+
72
+ /** Where the rows came from when the shared read didn't hold them all. */
73
+ export function sourcesNote(sources: ('snapshot' | 'atespace' | 'actor')[]): string {
74
+ if (sources.includes('actor')) return 'Read directly by name from Substrate: the shared read and the atespace read stopped at their limit before this actor.'
75
+ if (sources.includes('atespace')) return 'Read directly from this atespace: the shared read does not hold all of it.'
76
+ return ''
77
+ }
78
+
79
+ /** The kagent filter's choices: which kagent sessions to list. */
80
+ const KAGENT_FILTER_LABEL: Record<KagentAttribution['kind'] | 'sessions', string> = {
81
+ sessions: 'kagent sessions',
82
+ agentSession: 'Agent sessions',
83
+ sandbox: 'kagent sandboxes',
84
+ unattributed: 'Not tied to an Agent',
85
+ }
86
+ const KAGENT_OPTIONS: SelectMenuOption[] = [
87
+ { value: '', label: 'Any kagent link' },
88
+ ...(Object.keys(KAGENT_FILTER_LABEL) as (KagentAttribution['kind'] | 'sessions')[]).map((k) => ({ value: k, label: KAGENT_FILTER_LABEL[k] })),
89
+ ]
90
+
91
+ /**
92
+ * Why a kagent-filtered list isn't asked for: support is still being checked (capabilities loading), the
93
+ * check failed (support unknown with an upgrade note, as useRadarFeature reports a failed check), or this
94
+ * Radar is too old. failed: the capabilities read settled without an answer.
95
+ */
96
+ export function kagentSupportText(support: 'supported' | 'unsupported' | 'unknown', failed: boolean): string {
97
+ if (support === 'unsupported') return 'Listing actors by kagent Agent needs a newer Radar in this cluster.'
98
+ return failed
99
+ ? 'Radar couldn’t check whether this Radar supports kagent filters, so it doesn’t apply them.'
100
+ : 'Checking whether this Radar supports kagent filters…'
101
+ }
102
+
103
+ /** The support check is over, so the filters stay unapplied and can only be cleared. */
104
+ export function kagentSupportSettled(support: 'supported' | 'unsupported' | 'unknown', failed: boolean): boolean {
105
+ return support === 'unsupported' || (support === 'unknown' && failed)
106
+ }
107
+
108
+ /**
109
+ * A row's kagent Agent: a button that lists that Agent's sessions, or what the session is instead.
110
+ * Only exact attributions name an Agent; a hint stays in the hover. The Agent's namespace is the
111
+ * actor's atespace, shown under its name, so the cell names the Agent alone.
112
+ */
113
+ function AgentCell({ row, onAgent, coverage }: { row: SubstrateActorRow; onAgent?: (agent: KagentAgentRef) => void; coverage?: SubstratePoolsCoverage }) {
114
+ const k: KagentActor | undefined = row.kagent
115
+ if (!k) return <span className="text-theme-text-tertiary">—</span>
116
+ const session = `kagent session ${shortSessionId(k.sessionId)}`
117
+ if (k.kind === 'agentSession') {
118
+ const agent = k.agent
119
+ // Wraps after a hyphen, never mid-word, as the template column does.
120
+ const label = <Name name={agent.name} className="text-[12px]" />
121
+ const hover = `${session} of Agent ${agentText(agent)}${k.earlierRevision ? `, on an earlier revision (${k.revision}) than the one new sessions start on` : ''}.${onAgent ? ' Click to list its sessions.' : ''}`
122
+ return (
123
+ <Tooltip content={hover} wrapperClassName="min-w-0 w-full">
124
+ <span className="block min-w-0">
125
+ {onAgent ? (
126
+ <button type="button" onClick={(e) => { e.stopPropagation(); onAgent(agent) }} className="text-left text-accent-text hover:underline">{label}</button>
127
+ ) : label}
128
+ <span className="block text-xs leading-4 text-theme-text-tertiary">{k.newSessions ? 'new sessions' : k.earlierRevision ? 'earlier revision' : k.desired ? 'desired revision' : 'revision'} · {shortRevision(k.revision) || 'not reported'}</span>
129
+ </span>
130
+ </Tooltip>
131
+ )
132
+ }
133
+ return (
134
+ <Line title={k.kind === 'sandbox' ? `${session}: a kagent sandbox, not an Agent’s chat.` : `${session}. ${kagentUnattributedText(k, row.atespace, coverage)}`} className="text-xs text-theme-text-tertiary">
135
+ {kagentCellText(k)}
136
+ </Line>
137
+ )
138
+ }
139
+
140
+ /** An actor as the workspace tables' row identity. Actors are not Kubernetes objects; the drawer this opens is Substrate's own. */
141
+ export const ACTOR_ROW_KIND = 'SubstrateActor'
142
+
143
+ export function actorRowResource(ref: SubstrateRef): SelectedResource {
144
+ return { kind: ACTOR_ROW_KIND, namespace: ref.atespace, name: ref.name }
145
+ }
146
+
147
+ /** The states a segment asks /actors for; undefined for every state. */
148
+ export function segmentStates(segment: ActorSegment, linked: string | null): SubstrateActorState[] | undefined {
149
+ // A link to one transitional state ("Resuming 6") keeps that state inside the In progress segment.
150
+ if (linked && linked in ACTOR_STATE_LABEL) return [linked as SubstrateActorState]
151
+ const states = ACTOR_SEGMENTS.find((s) => s.id === segment)!.states
152
+ return states.length ? [...states] : undefined
153
+ }
154
+
155
+ /** One line in a dense list: truncated, with the whole text on hover. */
156
+ function Line({ children, title, className }: { children: ReactNode; title?: ReactNode; className?: string }) {
157
+ const line = <span className={clsx('block min-w-0 truncate', className)}>{children}</span>
158
+ return title ? <Tooltip content={title} wrapperClassName="min-w-0 w-full">{line}</Tooltip> : line
159
+ }
160
+
161
+ function SnapshotCell({ row, session = false }: { row: SubstrateActorRow; session?: boolean }) {
162
+ const s = row.newestSnapshot
163
+ if (!s) return <Line title="No snapshot yet: it boots fresh." className="text-theme-text-tertiary">none yet · boots fresh</Line>
164
+ const d = durableText(s)
165
+ const short = s.durable === 'none' && s.locality ? 'only on its node' : d.text
166
+ // Stored is the expected case; a snapshot at risk says so on a second line, so the warning is never cut off.
167
+ return (
168
+ <Tooltip content={`Generation ${s.generation}, ${session && s.fidelity === 'volumes' ? 'saved files on attached volumes, without process memory' : fidelityLabel(s.fidelity)}: ${d.title} ${resumeSentence(row)}`} wrapperClassName="min-w-0 w-full">
169
+ <span className="block min-w-0 text-[12.5px]">
170
+ <span className="block">{session ? `Snapshot generation ${s.generation}` : <>gen {s.generation} · {s.fidelity === 'rootfs' ? 'root fs' : fidelityLabel(s.fidelity)}</>}</span>
171
+ {d.tone !== 'healthy' && <span className={clsx('block text-xs leading-4', toneTextClass(d.tone))}>{short}</span>}
172
+ </span>
173
+ </Tooltip>
174
+ )
175
+ }
176
+
177
+ /**
178
+ * An actor's name in a row. A kagent session's is session-<UUID>, which would wrap over several lines:
179
+ * it reads "session <random tail>" (shortSessionId), the whole name on hover. Search still matches the
180
+ * whole name.
181
+ */
182
+ function ActorName({ row }: { row: SubstrateActorRow }) {
183
+ if (row.kagent) {
184
+ return <TruncatedText text={`session ${shortSessionId(row.kagent.sessionId)}`} tooltip={row.name} className="font-mono text-[12.5px]" />
185
+ }
186
+ return <TruncatedText text={row.name} className="font-mono text-xs font-medium" />
187
+ }
188
+
189
+ /** The worker-impact filter a link can carry, as its chip reads. */
190
+ const IMPACT_FILTER_LABEL: Record<NonNullable<SubstrateActorRow['workerImpact']>['kind'], string> = {
191
+ restarted: 'Sandbox lost',
192
+ unavailable: 'Worker unavailable',
193
+ draining: 'Worker draining',
194
+ }
195
+
196
+ const WAITING_SHORT: Record<NonNullable<SubstrateActorRow['waitingOn']>['on'], string> = {
197
+ restore: 'restoring on its worker',
198
+ checkpoint: 'checkpointing on its worker',
199
+ revert: 'reverting in the API server',
200
+ delete: 'deleting in the API server',
201
+ unrecorded: 'no worker recorded',
202
+ }
203
+
204
+ /** A crash cause's label in a table cell: short, the same on every row it covers; Substrate's message is on hover. */
205
+ const CAUSE_LABEL: Record<NonNullable<SubstrateActorRow['cause']>, string> = { memoryLimit: 'Memory-limit kill' }
206
+
207
+ /**
208
+ * What a state cell says beside its chip, and on hover: a crash's cause label
209
+ * or message, how long, where it waits. A named cause reads in a few words,
210
+ * the same on every row; Substrate's whole message is on hover.
211
+ */
212
+ export function stateCellReading(row: SubstrateActorRow): { text: string; hover: string } {
213
+ // A pending upload shows in the snapshot column; the state cell doesn't say it twice.
214
+ const raw = row.state === 'crashed' && row.cause ? CAUSE_LABEL[row.cause] : stateExtra(row.state, row.reason)
215
+ // The badge says "stuck" past Substrate's threshold; this line says only how long.
216
+ const extra = row.state === 'suspended' && raw?.startsWith('upload pending') ? undefined : raw
217
+ const waiting = row.waitingOn ? WAITING_SHORT[row.waitingOn.on] : undefined
218
+ // Where it waits is what the In progress tab is for, so it comes before how long.
219
+ const text = [waiting, extra].filter(Boolean).join(' · ')
220
+ const message = row.state === 'crashed' && row.cause && row.reason ? `Substrate’s message: ${row.reason}.` : row.reason
221
+ return { text, hover: [message, row.waitingOn?.reading].filter(Boolean).join(' ') }
222
+ }
223
+
224
+ function StateCell({ row }: { row: SubstrateActorRow }) {
225
+ const { text, hover } = stateCellReading(row)
226
+ const line = text ? <span className={clsx('line-clamp-2 min-w-0 text-xs leading-4', row.state === 'crashed' ? 'text-theme-text-secondary' : 'text-theme-text-tertiary')}>{text}</span> : null
227
+ const place = 'min-w-0 basis-full pt-0.5'
228
+ return (
229
+ <span className="flex min-w-0 flex-wrap items-start gap-x-1.5 gap-y-0.5">
230
+ <span className="min-w-0 basis-full"><ActorStateBadge state={row.state} impact={row.workerImpact} updateTime={row.updateTime} wrap /></span>
231
+ {line && (hover ? <Tooltip content={hover} wrapperClassName={place}>{line}</Tooltip> : <span className={place}>{line}</span>)}
232
+ </span>
233
+ )
234
+ }
235
+
236
+ function WorkerCell({ row }: { row: SubstrateActorRow }) {
237
+ if (row.worker) {
238
+ return <><Line title={row.worker.pod} className="font-mono text-[11.5px]">{row.worker.pod}</Line><Sub>Assigned worker</Sub></>
239
+ }
240
+ if (!row.node) return <span className="text-theme-text-tertiary">none</span>
241
+ // A node's DNS suffix is the same on every row; the hover has it whole.
242
+ return (
243
+ <><Line title={`No worker now. It last ran on node ${row.node}, or its snapshot is there.`} className="font-mono text-[12.5px] text-theme-text-tertiary">
244
+ {row.node.split('.')[0]}
245
+ </Line><Sub>Last known node</Sub></>
246
+ )
247
+ }
248
+
249
+ /**
250
+ * Identity takes the space left after the other columns and the fixed Open
251
+ * action. Narrow folds the atespace and template under the name.
252
+ */
253
+ function actorColumns(wide: boolean, onOpen: (ref: SubstrateRef) => void, agent?: { onAgent?: (agent: KagentAgentRef) => void; coverage?: SubstratePoolsCoverage; revisionOnly?: boolean }): TableColumn<SubstrateActorRow>[] {
254
+ return [
255
+ {
256
+ header: agent?.revisionOnly ? 'Session' : 'Actor',
257
+ cell: (r) => (
258
+ <>
259
+ <ActorName row={r} />
260
+ {!agent?.revisionOnly && <Sub>{r.atespace}{!wide && <> · {r.template.name}</>}</Sub>}
261
+ </>
262
+ ),
263
+ },
264
+ { header: 'State', width: wide ? (agent?.revisionOnly ? '19%' : agent ? '16%' : '24%') : (agent ? '23%' : '28%'), cell: (r) => <StateCell row={r} /> },
265
+ ...(wide && !agent?.revisionOnly ? [{ header: 'Template', width: agent ? '11%' : '17%', cell: (r: SubstrateActorRow) => <Line title={r.template.name} className="font-mono text-[12px]">{r.template.name}</Line> }] : []),
266
+ ...(agent ? [{ header: agent.revisionOnly ? 'Revision' : 'kagent Agent', width: wide ? (agent.revisionOnly ? '14%' : '12%') : '15%', cell: (r: SubstrateActorRow) => agent.revisionOnly ? (
267
+ <span className="text-xs">{r.kagent?.kind === 'agentSession' ? <>{r.kagent.newSessions ? 'Current' : r.kagent.earlierRevision ? 'Earlier' : 'Latest change'}<span className="block break-words font-mono text-theme-text-tertiary">{shortRevision(r.kagent.revision)}</span></> : 'Unattributed'}</span>
268
+ ) : <AgentCell row={r} onAgent={agent.onAgent} coverage={agent.coverage} /> }] : []),
269
+ { header: 'Worker or last node', width: wide ? '13%' : '18%', cell: (r) => <WorkerCell row={r} /> },
270
+ { header: agent?.revisionOnly ? 'Saved session state' : 'Newest snapshot', width: wide ? (agent?.revisionOnly ? '18%' : '13%') : '19%', cell: (r) => <SnapshotCell row={r} session={agent?.revisionOnly} /> },
271
+ ...(wide
272
+ ? [{
273
+ header: agent?.revisionOnly ? 'Updated' : 'Last updated',
274
+ width: '9%',
275
+ cell: (r: SubstrateActorRow) =>
276
+ r.updateTime ? (
277
+ <span className="text-xs"><When iso={r.updateTime} hint="Substrate’s last change to the actor: the current state has held at least since" /></span>
278
+ ) : (
279
+ <Unread>unknown</Unread>
280
+ ),
281
+ }]
282
+ : []),
283
+ {
284
+ header: <span className="sr-only">Open actor</span>,
285
+ width: '76px',
286
+ cell: (r) => <button type="button" aria-label={`Open actor ${r.name}`} className="whitespace-nowrap text-xs text-accent-text hover:underline" onClick={(e) => { e.stopPropagation(); onOpen(r) }}>Open →</button>,
287
+ },
288
+ ]
289
+ }
290
+
291
+ export interface SubstrateActorsProps {
292
+ workspace?: SubstrateWorkspace
293
+ status?: SubstrateStatus
294
+ onOpenActor: (ref: SubstrateRef) => void
295
+ openActor: SubstrateRef | null
296
+ }
297
+
298
+ /** The Actors list, filtered and paged by the server; counts per state come from Substrate's full read, not the page. */
299
+ export function SubstrateActorsScreen({ workspace, status, onOpenActor, openActor }: SubstrateActorsProps) {
300
+ const [params, setParams] = useSearchParams()
301
+ const linkedState = params.get('state')
302
+ const attentionOnly = params.get('attention') === '1'
303
+ const phase = segmentOfState(linkedState)
304
+ const segment = attentionOnly ? 'attention' : phase
305
+ const atespace = params.get('atespace') ?? ''
306
+ const template = params.get('template') ?? ''
307
+ const pool = params.get('pool') ?? ''
308
+ const q = params.get('q') ?? ''
309
+ const worker = params.get('worker') ?? ''
310
+ const rawImpact = params.get('impact')
311
+ const impact = rawImpact && rawImpact in IMPACT_FILTER_LABEL ? (rawImpact as keyof typeof IMPACT_FILTER_LABEL) : undefined
312
+ const node = params.get('node') ?? ''
313
+ const agent = params.get('agent') ?? ''
314
+ const rawKagent = params.get('kagent')
315
+ const kagentKind = rawKagent && rawKagent in KAGENT_FILTER_LABEL ? (rawKagent as KagentAttribution['kind'] | 'sessions') : undefined
316
+ const sessionAtespaces = kagentKind === 'sessions' || kagentKind === 'agentSession' ? params.get('atespaces') || undefined : undefined
317
+ // An older Radar ignores the agent and kagent filters and lists every actor, so they are sent only to one that serves them.
318
+ const attributionFeature = useRadarFeature('kagentAttribution')
319
+ const summaryFeature = useRadarFeature('kagentWorkspace')
320
+ const kagentFeature = kagentKind === 'sessions' || sessionAtespaces ? summaryFeature : attributionFeature
321
+ const kagentFilters = kagentFeature.support === 'supported'
322
+ const kagentRequested = !!(agent || kagentKind)
323
+ const sort = (params.get('sort') as ActorSort | null) ?? 'attention'
324
+ const nodeHas: NodeHas = params.get('nodeHas') === 'localSnapshot' ? 'localSnapshot' : 'running'
325
+ // One write per change: filters reset the page, and the drawer's ?actor= stays.
326
+ const update = (patch: Record<string, string>) => {
327
+ const p = new URLSearchParams(params)
328
+ for (const [k, v] of Object.entries(patch)) {
329
+ if (v) p.set(k, v)
330
+ else p.delete(k)
331
+ }
332
+ p.delete('page')
333
+ setParams(p, { replace: true })
334
+ }
335
+ const setQ = (v: string) => update({ q: v })
336
+ const page = Math.max(0, Number(params.get('page') ?? 0) || 0)
337
+ const [search, setSearch] = useState(q)
338
+ const [filtersOpen, setFiltersOpen] = useState(false)
339
+ const filterDisclosure = useDisclosure(filtersOpen)
340
+ const filterCount = [atespace, template, pool, kagentKind, sort !== 'attention'].filter(Boolean).length
341
+ useEffect(() => setSearch(q), [q])
342
+ useEffect(() => {
343
+ if (search === q) return
344
+ // Debounced: every keystroke would be a request.
345
+ const t = setTimeout(() => setQ(search), 250)
346
+ return () => clearTimeout(t)
347
+ }, [search]) // eslint-disable-line react-hooks/exhaustive-deps
348
+
349
+ const states = segmentStates(phase, linkedState)
350
+ const actorsEnabled = (!workspace || workspace.apiTier.state === 'connected') && (!kagentRequested || kagentFilters)
351
+ const query = useSubstrateActors({
352
+ atespace: atespace || undefined,
353
+ template: template || undefined,
354
+ pool: pool || undefined,
355
+ worker: worker || undefined,
356
+ impact,
357
+ node: node || undefined,
358
+ nodeHas: node ? nodeHas : undefined,
359
+ state: states,
360
+ attention: attentionOnly ? 1 : undefined,
361
+ q: q || undefined,
362
+ agent: kagentFilters ? agent || undefined : undefined,
363
+ kagent: kagentFilters ? kagentKind : undefined,
364
+ namespaces: kagentFilters ? sessionAtespaces : undefined,
365
+ sort,
366
+ limit: ACTORS_PAGE_SIZE,
367
+ offset: page * ACTORS_PAGE_SIZE,
368
+ }, actorsEnabled)
369
+ const code = actorsEnabled ? substrateErrorCode(query.error) : undefined
370
+ const data = actorsEnabled && !definitiveFailure(code) ? query.data : undefined
371
+ // A refused read says why in its code; that wins over the workspace's older tier.
372
+ const tier: SubstrateAPITier | undefined = !data && code
373
+ ? { state: code === 'notConfigured' || code === 'targetChanged' ? 'notConfigured' : code === 'sharedRadar' || code === 'apiDisabled' ? 'disabled' : 'failed', code, reason: query.error instanceof Error ? query.error.message : undefined }
374
+ : data?.apiTier ?? workspace?.apiTier
375
+ const notConnected = !data && !!tier && tier.state !== 'connected'
376
+ const templates = useSubstrateTemplates(tier?.state === 'connected')
377
+
378
+ const setSegment = (id: ActorSegment | 'attention') => {
379
+ const p = new URLSearchParams(params)
380
+ if (id === 'attention') p.set('attention', '1')
381
+ else p.delete('attention')
382
+ const next = id === 'attention' ? undefined : segmentStates(id, null)
383
+ if (id === 'all' || !next) p.delete('state')
384
+ else p.set('state', id === 'inProgress' ? 'inProgress' : next.join(','))
385
+ p.delete('page')
386
+ setParams(p, { replace: true })
387
+ }
388
+ const setPage = (n: number) => {
389
+ const p = new URLSearchParams(params)
390
+ if (n > 0) p.set('page', String(n))
391
+ else p.delete('page')
392
+ setParams(p, { replace: true })
393
+ }
394
+
395
+ const atespaceOptions: SelectMenuOption[] = useMemo(
396
+ () => [{ value: '', label: 'All atespaces' }, ...(workspace?.atespaces ?? []).map((a) => ({ value: a.name, label: a.name, description: a.actorsRead === 'denied' ? 'no access' : a.actorsRead === 'unread' ? 'not read' : undefined }))],
397
+ [workspace?.atespaces],
398
+ )
399
+ const templateOptions: SelectMenuOption[] = useMemo(
400
+ () => [
401
+ { value: '', label: 'Any template' },
402
+ ...(templates.data?.templates ?? [])
403
+ .filter((t) => !atespace || t.atespace === atespace)
404
+ .map((t) => ({ value: templateFilterValue(t), label: `${t.atespace} / ${t.name}` })),
405
+ ],
406
+ [templates.data, atespace],
407
+ )
408
+ const poolOptions: SelectMenuOption[] = useMemo(
409
+ () => [{ value: '', label: 'Any pool' }, ...(workspace?.pools ?? []).map((p) => ({ value: `${p.namespace}/${p.name}`, label: `${p.namespace} / ${p.name}` }))],
410
+ [workspace?.pools],
411
+ )
412
+ // A filter from a link that the menus don't list still shows, and can be cleared.
413
+ const extra = (options: SelectMenuOption[], value: string) => (value && !options.some((o) => o.value === value) ? [...options, { value, label: value }] : options)
414
+
415
+ const showKagent = !!data?.kagentAgents || !!data?.rows.some((r) => r.kagent)
416
+ const actorsPartial = coverageInPart(data?.coverage) || !!data?.kagentUnread?.length || !!data?.kagentTemplatesPartial
417
+ const kagentUnread = kagentUnreadText(data?.kagentUnread, data?.kagentAgents)
418
+ const chips = [
419
+ ...(worker ? [{ label: `Worker: ${worker}`, onClear: () => update({ worker: '' }) }] : []),
420
+ ...(impact ? [{ label: IMPACT_FILTER_LABEL[impact], onClear: () => update({ impact: '' }) }] : []),
421
+ ...(node ? [{ label: `Node: ${node}`, onClear: () => update({ node: '', nodeHas: '' }) }] : []),
422
+ ...(kagentKind ? [{ label: `kagent: ${KAGENT_FILTER_LABEL[kagentKind]}`, onClear: () => update({ kagent: '', atespaces: '' }) }] : []),
423
+ ...(sessionAtespaces ? [{ label: `Atespaces: ${sessionAtespaces}`, onClear: () => update({ atespaces: '' }) }] : []),
424
+ ...(agent ? [{ label: `kagent Agent: ${agent}`, onClear: () => update({ agent: '' }) }] : []),
425
+ ...(linkedState && linkedState in ACTOR_STATE_LABEL && (phase === 'inProgress' || phase === 'all') ? [{ label: `Phase: ${ACTOR_STATE_LABEL[linkedState as SubstrateActorState]}`, onClear: () => setSegment(phase) }] : []),
426
+ ]
427
+
428
+ return (
429
+ <div className="flex min-h-0 flex-1 flex-col">
430
+ <SubstrateHeader title="Actors" intro={atespace ? <>Atespace: {atespace}</> : sessionAtespaces ? <>Atespaces: {sessionAtespaces}</> : 'Cluster-wide · all atespaces'} />
431
+ <ScreenBody>
432
+ {!notConnected && data?.counts && (
433
+ <WorkspaceCard title="Reported phases">
434
+ <SubstrateStateBar counts={data.counts} partial={actorsPartial} onSelectState={(state) => update({ state, attention: '' })} />
435
+ </WorkspaceCard>
436
+ )}
437
+ {node && !notConnected && (
438
+ <div className="flex flex-wrap items-center gap-3 text-sm text-theme-text-secondary">
439
+ <Segments
440
+ label="What the node holds"
441
+ value={nodeHas}
442
+ onChange={(v) => update({ nodeHas: v })}
443
+ options={[
444
+ { id: 'running', label: 'Running here' },
445
+ { id: 'localSnapshot', label: 'Snapshots only on this node' },
446
+ ]}
447
+ />
448
+ <span className="text-xs">{NODE_HAS_MEANING[nodeHas]}</span>
449
+ </div>
450
+ )}
451
+ {data && data.sources.some((s) => s !== 'snapshot') && (
452
+ <p className="text-xs text-theme-text-tertiary">{sourcesNote(data.sources)}</p>
453
+ )}
454
+ {!notConnected && <div>
455
+ <div className="flex flex-wrap items-center gap-2">
456
+ <Segments
457
+ label="Actor filter"
458
+ value={segment}
459
+ onChange={setSegment}
460
+ options={[
461
+ ...ACTOR_SEGMENTS.slice(0, 1).map((s) => ({ id: s.id, label: s.label })),
462
+ { id: 'attention' as const, label: 'Needs attention' },
463
+ ...ACTOR_SEGMENTS.slice(1).map((s) => ({ id: s.id, label: s.label })),
464
+ ].map((s) => {
465
+ const n = s.id === 'attention' ? data?.attentionCount : segmentCount(data?.counts, s.id)
466
+ const partial = actorsPartial || (s.id === 'attention' && coverageInPart(data?.workerCoverage))
467
+ return { ...s, count: n === undefined ? undefined : partial ? (n > 0 ? `≥${n.toLocaleString('en-US')}` : undefined) : n.toLocaleString('en-US') }
468
+ })}
469
+ />
470
+ <Input
471
+ aria-label="Search actor names"
472
+ value={search}
473
+ onChange={(e) => setSearch(e.target.value)}
474
+ placeholder="Search actor name…"
475
+ className="h-8 w-44 rounded-md border border-theme-border bg-theme-elevated px-3 text-sm text-theme-text-primary placeholder:text-theme-text-tertiary focus:border-skyhook-500 focus:outline-none"
476
+ spellCheck={false}
477
+ />
478
+ <button type="button" {...filterDisclosure.buttonProps} onClick={() => setFiltersOpen((open) => !open)} className="btn-secondary inline-flex items-center gap-1.5 px-3 py-1.5 text-xs">
479
+ <SlidersHorizontal size={14} /> Filters{filterCount > 0 && ` · ${filterCount}`}
480
+ </button>
481
+ </div>
482
+ <Collapse open={filtersOpen} id={filterDisclosure.panelId}>
483
+ <div className="flex flex-wrap items-center gap-2 pt-2">
484
+ <SelectMenu ariaLabel="Atespace" value={atespace} options={extra(atespaceOptions, atespace)} onChange={(v) => update({ atespace: v, ...(template && v && !template.startsWith(`${v}/`) ? { template: '' } : {}) })} className="min-w-[10rem]" />
485
+ <SelectMenu ariaLabel="Template" value={template} options={extra(templateOptions, template)} onChange={(v) => update({ template: v })} className="min-w-[12rem]" searchPlaceholder="Search templates" />
486
+ <SelectMenu ariaLabel="Pool" value={pool} options={extra(poolOptions, pool)} onChange={(v) => update({ pool: v })} className="min-w-[10rem]" />
487
+ {(showKagent || kagentRequested) && kagentFilters && (
488
+ <SelectMenu ariaLabel="kagent" value={kagentKind ?? ''} options={KAGENT_OPTIONS.filter(o => o.value !== 'sessions' || summaryFeature.support === 'supported')} onChange={(v) => update({ kagent: v, agent: '', atespaces: v === 'sessions' || v === 'agentSession' ? sessionAtespaces ?? '' : '' })} className="min-w-[12rem]" />
489
+ )}
490
+ <SelectMenu ariaLabel="Sort" value={sort} options={SORT_OPTIONS} onChange={(v) => update({ sort: v === 'attention' ? '' : v })} className="min-w-[11rem]" />
491
+ </div>
492
+ </Collapse>
493
+ <FilterChips chips={chips} />
494
+ </div>}
495
+ {kagentUnread && (
496
+ <p className="text-xs text-theme-text-secondary">{kagentUnread}</p>
497
+ )}
498
+ {data?.kagentTemplatesPartial && (
499
+ <p className="text-xs text-theme-text-secondary">Some templates were unread. More sessions may belong to an Agent’s earlier revisions.</p>
500
+ )}
501
+ {kagentRequested && !kagentFilters ? (
502
+ <Notice>
503
+ {kagentSupportText(kagentFeature.support, !!kagentFeature.upgrade)}
504
+ {kagentSupportSettled(kagentFeature.support, !!kagentFeature.upgrade) && (
505
+ <>{' '}<button type="button" onClick={() => update({ agent: '', kagent: '' })} className="text-accent-text hover:underline">Clear kagent filters</button></>
506
+ )}
507
+ </Notice>
508
+ ) : attentionOnly && data && data.attentionCount === undefined ? (
509
+ <Notice>Filtering actors that need attention requires a newer Radar.</Notice>
510
+ ) : notConnected && tier ? (
511
+ <>
512
+ <SubstrateTierBanner tier={tier} />
513
+ <SubstrateConnectNotice status={status} tier={tier} />
514
+ </>
515
+ ) : query.error && !data ? (
516
+ <Notice>Radar couldn’t read the actors: {query.error instanceof Error ? query.error.message : 'unknown error'}.</Notice>
517
+ ) : (
518
+ <>
519
+ <RefreshFailedNotice queries={[query]} />
520
+ <ActorsTable sort={sort} data={data} workerFilterPartial={(attentionOnly || !!impact) && coverageInPart(data?.workerCoverage)} loading={query.isLoading} placeholder={query.isPlaceholderData} page={page} onPage={setPage} onOpenActor={onOpenActor} openActor={openActor} onAgent={kagentFilters ? (a) => update({ agent: agentFilterValue(a), kagent: '', atespaces: '' }) : undefined} />
521
+ </>
522
+ )}
523
+ {attentionOnly && <p className="text-xs text-theme-text-tertiary">Includes reported crashes, lost sandboxes, unavailable workers and stuck transitions. Failed golden builds also have a template finding.</p>}
524
+ {tier && <SubstrateSourceLine tier={tier} status={status} />}
525
+ </ScreenBody>
526
+ </div>
527
+ )
528
+ }
529
+
530
+ export function ActorsTable({
531
+ sort = 'attention',
532
+ data,
533
+ workerFilterPartial,
534
+ loading,
535
+ placeholder,
536
+ page,
537
+ onPage,
538
+ onOpenActor,
539
+ openActor,
540
+ onAgent,
541
+ revisionOnly,
542
+ }: {
543
+ sort?: ActorSort
544
+ workerFilterPartial?: boolean
545
+ data?: SubstrateActorsResponse
546
+ loading?: boolean
547
+ /** The rows are the page before, kept while this page loads. */
548
+ placeholder?: boolean
549
+ page: number
550
+ onPage: (page: number) => void
551
+ onOpenActor: (ref: SubstrateRef) => void
552
+ openActor: SubstrateRef | null
553
+ /** Lists an Agent's sessions; absent where the Radar can't filter by Agent. */
554
+ onAgent?: (agent: KagentAgentRef) => void
555
+ revisionOnly?: boolean
556
+ }) {
557
+ const wide = useMediaQuery(SUBSTRATE_WIDE)
558
+ const rows = data?.rows ?? []
559
+ const total = data?.total
560
+ const from = (data?.offset ?? page * ACTORS_PAGE_SIZE) + 1
561
+ const to = (data?.offset ?? 0) + rows.length
562
+ const cov = data?.coverage
563
+ // A kagent filter judged where the Agents weren't read: an Agent's count is a lower bound.
564
+ const agentsUnread = !!data?.kagentUnread?.length
565
+ const partial = coverageInPart(cov) || workerFilterPartial || agentsUnread || data?.kagentTemplatesPartial
566
+ const empty = loading
567
+ ? 'Loading actors…'
568
+ : !data
569
+ ? 'Actors were not read.'
570
+ : cov && (cov.state === 'denied' || cov.state === 'failed')
571
+ ? `No actors: ${coverageReason(cov, 'actors')}.`
572
+ : workerFilterPartial
573
+ ? 'No matching actors observed. Some worker disruptions could not be assessed.'
574
+ : coverageInPart(cov)
575
+ ? `No actors match in what Radar could read (${coverageReason(cov, 'actors')}).`
576
+ : agentsUnread
577
+ ? `No actors match where Radar could read kagent’s Agents; it couldn’t read them in ${data!.kagentUnread!.join(', ')}.`
578
+ : data.kagentTemplatesPartial ? 'No matching sessions observed. More may match once their templates are read.' : 'No actors match.'
579
+ const pages = total !== undefined ? Math.ceil(total / ACTORS_PAGE_SIZE) : undefined
580
+ return (
581
+ <div aria-busy={placeholder || undefined} className={placeholder ? 'opacity-60' : undefined}>
582
+ <SectionTable
583
+ columns={actorColumns(wide, onOpenActor, revisionOnly || data?.kagentAgents || rows.some((r) => r.kagent) ? { onAgent, coverage: data?.kagentAgents, revisionOnly } : undefined)}
584
+ rows={rows}
585
+ rowKey={(r) => `${r.atespace}/${r.name}`}
586
+ rowResource={(r) => actorRowResource(r)}
587
+ onInspect={(res) => onOpenActor({ atespace: res.namespace, name: res.name })}
588
+ inspected={openActor ? actorRowResource(openActor) : null}
589
+ empty={empty}
590
+ minWidth={wide ? 900 : 720}
591
+ wrapHeaders
592
+ footer={
593
+ total !== undefined && total > 0 ? (
594
+ <div className="flex flex-wrap items-center gap-3">
595
+ <span>
596
+ {placeholder
597
+ ? `Loading page ${page + 1}… showing the page before until it arrives`
598
+ : <>{from.toLocaleString('en-US')}–{to.toLocaleString('en-US')} of {partial ? 'at least ' : ''}{total.toLocaleString('en-US')} · {SORT_LABEL[sort]}</>}
599
+ </span>
600
+ {pages !== undefined && pages > 1 && (
601
+ <span className="flex items-center gap-1.5">
602
+ <button type="button" disabled={page === 0} onClick={() => onPage(page - 1)} className="btn-secondary px-2 py-0.5 text-xs">Previous</button>
603
+ <button type="button" disabled={page + 1 >= pages} onClick={() => onPage(page + 1)} className="btn-secondary px-2 py-0.5 text-xs">Next</button>
604
+ </span>
605
+ )}
606
+ </div>
607
+ ) : undefined
608
+ }
609
+ />
610
+ </div>
611
+ )
612
+ }