@skyhook-io/radar-app 1.22.2 → 1.23.1

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 (228) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +49 -13
  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 +151 -27
  9. package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/poll.ts +78 -0
  15. package/src/api/prometheusCharts.ts +5 -0
  16. package/src/api/radarFeatures.test.ts +9 -0
  17. package/src/api/radarFeatures.ts +16 -0
  18. package/src/api/substrateWorkspace.test.ts +72 -0
  19. package/src/api/substrateWorkspace.ts +1394 -0
  20. package/src/api/vulnerabilities.ts +207 -9
  21. package/src/api/workloadSource.test.tsx +315 -0
  22. package/src/api/workloadSource.ts +128 -12
  23. package/src/components/CloudConnectFlow.tsx +46 -7
  24. package/src/components/CloudFunnelButton.test.tsx +193 -7
  25. package/src/components/CloudFunnelButton.tsx +128 -32
  26. package/src/components/SelfManagedStart.tsx +12 -2
  27. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  28. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  29. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  30. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  31. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  32. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  33. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  34. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  35. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  36. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  37. package/src/components/agentsandbox/data.ts +135 -0
  38. package/src/components/agentsandbox/host.test.ts +27 -0
  39. package/src/components/agentsandbox/host.tsx +85 -0
  40. package/src/components/agentsandbox/labels.test.ts +42 -0
  41. package/src/components/agentsandbox/labels.ts +146 -0
  42. package/src/components/agentsandbox/listFilters.ts +85 -0
  43. package/src/components/agentsandbox/lists.ts +52 -0
  44. package/src/components/agentsandbox/routes.ts +23 -0
  45. package/src/components/agentsandbox/shared.tsx +321 -0
  46. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  47. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  48. package/src/components/agentsandbox/workspace.tsx +258 -0
  49. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  50. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  51. package/src/components/applications/ApplicationsView.tsx +156 -3
  52. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  53. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  54. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  55. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  56. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  57. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  58. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  59. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  60. package/src/components/cloudHints/cloudHints.ts +131 -0
  61. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  62. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  63. package/src/components/cloudHints/cloudLinks.ts +31 -0
  64. package/src/components/cloudHints/hintStorage.ts +28 -0
  65. package/src/components/cnpg/CNPGView.tsx +4 -7
  66. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  67. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  68. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  69. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  70. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  71. package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
  72. package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
  73. package/src/components/helm/HelmView.tsx +4 -3
  74. package/src/components/helm/ObservedHelmNotice.tsx +39 -17
  75. package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
  76. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
  77. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
  78. package/src/components/home/HomeAgentBlock.tsx +2 -0
  79. package/src/components/home/HomeView.tsx +3 -3
  80. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  81. package/src/components/home/MCPSetupDialog.tsx +6 -2
  82. package/src/components/home/McpCloudLine.test.tsx +162 -0
  83. package/src/components/home/McpCloudLine.tsx +95 -0
  84. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  85. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  86. package/src/components/home/mcpToolCatalog.ts +4 -4
  87. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  88. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  89. package/src/components/issues/IssuesPane.tsx +181 -23
  90. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  91. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  92. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  93. package/src/components/issues/sinceLastVisit.ts +439 -0
  94. package/src/components/issues/uncheckedSources.test.ts +8 -0
  95. package/src/components/issues/uncheckedSources.ts +3 -0
  96. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  97. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  98. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  99. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  100. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  101. package/src/components/kagent/KagentLists.tsx +412 -0
  102. package/src/components/kagent/KagentOverview.tsx +234 -0
  103. package/src/components/kagent/KagentPages.tsx +690 -0
  104. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  105. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  106. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  107. package/src/components/kagent/KagentView.tsx +109 -0
  108. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  109. package/src/components/kagent/host.tsx +144 -0
  110. package/src/components/kagent/routes.ts +31 -0
  111. package/src/components/kagent/shared.tsx +336 -0
  112. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  113. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  114. package/src/components/kagent/workspace.fixtures.ts +108 -0
  115. package/src/components/kagent/workspaceRoute.ts +18 -0
  116. package/src/components/nudges/activeNudges.test.ts +39 -0
  117. package/src/components/nudges/activeNudges.ts +76 -0
  118. package/src/components/poll/OssPoll.tsx +871 -0
  119. package/src/components/poll/mount.test.ts +12 -0
  120. package/src/components/poll/pollCloud.test.ts +23 -0
  121. package/src/components/poll/pollCloud.ts +6 -0
  122. package/src/components/poll/pollDefinition.ts +93 -0
  123. package/src/components/poll/pollFlow.test.ts +140 -0
  124. package/src/components/poll/pollFlow.ts +137 -0
  125. package/src/components/poll/pollSender.test.ts +137 -0
  126. package/src/components/poll/pollSender.ts +76 -0
  127. package/src/components/poll/pollStorage.test.ts +53 -0
  128. package/src/components/poll/pollStorage.ts +77 -0
  129. package/src/components/poll/round.json +350 -0
  130. package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
  131. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  132. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  133. package/src/components/resource/PrometheusCharts.tsx +10 -1
  134. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  135. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  136. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  137. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  138. package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
  139. package/src/components/resources/ImageFilesystemModal.tsx +42 -3
  140. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  141. package/src/components/resources/ResourcesView.tsx +24 -11
  142. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  143. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  144. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  145. package/src/components/settings/SettingsDialog.tsx +84 -16
  146. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  147. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  148. package/src/components/settings/SubstrateSettings.tsx +544 -0
  149. package/src/components/settings/settings-state.test.ts +21 -3
  150. package/src/components/settings/settings-state.ts +13 -3
  151. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  152. package/src/components/share/ShareLinkButton.tsx +391 -0
  153. package/src/components/share/openShareInCloud.test.ts +29 -0
  154. package/src/components/share/openShareInCloud.ts +10 -0
  155. package/src/components/share/shareLink.test.ts +129 -0
  156. package/src/components/share/shareLink.ts +175 -0
  157. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  158. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  159. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  160. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  161. package/src/components/substrate/SubstrateActors.tsx +612 -0
  162. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  163. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  164. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  165. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  166. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  167. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  168. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  169. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  170. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  171. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  172. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  173. package/src/components/substrate/SubstrateView.tsx +173 -0
  174. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  175. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  176. package/src/components/substrate/attention.ts +81 -0
  177. package/src/components/substrate/contextPin.tsx +69 -0
  178. package/src/components/substrate/host.tsx +83 -0
  179. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  180. package/src/components/substrate/readings.test.ts +484 -0
  181. package/src/components/substrate/readings.ts +997 -0
  182. package/src/components/substrate/routes.ts +103 -0
  183. package/src/components/substrate/shared.tsx +426 -0
  184. package/src/components/substrate/substrate.fixtures.ts +325 -0
  185. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  186. package/src/components/substrate/workspaceRoute.ts +23 -0
  187. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  188. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  189. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  190. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  191. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  192. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  193. package/src/components/traffic/TrafficGraph.tsx +17 -14
  194. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  195. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  196. package/src/components/traffic/TrafficView.tsx +26 -56
  197. package/src/components/traffic/trafficFilters.test.ts +61 -1
  198. package/src/components/traffic/trafficFilters.ts +68 -8
  199. package/src/components/ui/UpdateNotification.tsx +2 -0
  200. package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
  201. package/src/components/velero/VeleroOverview.tsx +2 -2
  202. package/src/components/velero/VeleroView.tsx +3 -6
  203. package/src/components/vulnerabilities/columns.tsx +132 -0
  204. package/src/components/vulnerabilities/filters.tsx +317 -0
  205. package/src/components/vulnerabilities/owner.test.ts +54 -0
  206. package/src/components/vulnerabilities/owner.tsx +163 -0
  207. package/src/components/vulnerabilities/parts.test.ts +126 -12
  208. package/src/components/vulnerabilities/parts.tsx +612 -52
  209. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  210. package/src/components/vulnerabilities/traffic.tsx +40 -0
  211. package/src/components/whats-new/WhatsNew.tsx +2 -0
  212. package/src/components/whats-new/releaseNotes.ts +75 -1
  213. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  214. package/src/components/workload/WorkloadView.tsx +52 -13
  215. package/src/components/workspace/layout.tsx +13 -7
  216. package/src/components/workspace/sidebar.test.ts +48 -0
  217. package/src/components/workspace/sidebar.ts +73 -3
  218. package/src/components/workspace/table.ts +2 -1
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/integrations/resourceHost.ts +12 -6
  222. package/src/integrations/resourceHosts.test.tsx +27 -1
  223. package/src/integrations/resourceHosts.tsx +15 -7
  224. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  225. package/src/integrations/sidebarWorkspaces.ts +41 -0
  226. package/src/integrations/workspaceRoute.ts +1 -1
  227. package/src/integrations/workspaceRoutes.ts +7 -1
  228. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -0,0 +1,103 @@
1
+ import type { RadarFeatureSupport } from '../../api/radarFeatures'
2
+ import type { SubstratePoolRef, SubstrateRef } from '../../api/substrateWorkspace'
3
+
4
+ export const SUBSTRATE_GROUP = 'ate.dev'
5
+
6
+ export const SUBSTRATE_PATH = '/substrate'
7
+
8
+ /** The namespace picker's tooltip on every Substrate screen: actors live in atespaces, which are not namespaces. */
9
+ export const SUBSTRATE_NAMESPACE_FILTER_TOOLTIP = 'Agent Substrate keeps actors in atespaces, not namespaces — the namespace filter doesn’t apply here. Use the Atespace filter instead.'
10
+
11
+ export const SUBSTRATE_WORKERPOOL_KIND = { name: 'workerpools', kind: 'WorkerPool', group: SUBSTRATE_GROUP }
12
+ export const SUBSTRATE_POOLS_PATH = `/resources/workerpools?apiGroup=${SUBSTRATE_GROUP}`
13
+
14
+ export type SubstrateScreen = 'overview' | 'actors' | 'templates' | 'workers'
15
+
16
+ export const SUBSTRATE_SCREENS: Record<SubstrateScreen, { label: string; title: string; path: string }> = {
17
+ overview: { label: 'Overview', title: 'Agent Substrate overview', path: SUBSTRATE_PATH },
18
+ actors: { label: 'Actors', title: 'Agent Substrate actors', path: `${SUBSTRATE_PATH}/actors` },
19
+ templates: { label: 'Templates', title: 'Agent Substrate templates', path: `${SUBSTRATE_PATH}/templates` },
20
+ workers: { label: 'Workers', title: 'Agent Substrate workers', path: `${SUBSTRATE_PATH}/workers` },
21
+ }
22
+
23
+ export interface SubstrateRoute {
24
+ screen: SubstrateScreen
25
+ /** An actor's page: /substrate/actors/<atespace>/<name>. */
26
+ actor?: SubstrateRef
27
+ /** A template's page: /substrate/templates/<atespace>/<name>. */
28
+ template?: SubstrateRef
29
+ /** A WorkerPool's page: /substrate/workerpools/<namespace>/<name>. */
30
+ pool?: SubstratePoolRef
31
+ }
32
+
33
+ function segments(pathname: string): string[] {
34
+ return pathname.replace(/^\/+/, '').replace(/\/+$/, '').split('/').map((s) => {
35
+ try {
36
+ return decodeURIComponent(s)
37
+ } catch {
38
+ return s
39
+ }
40
+ })
41
+ }
42
+
43
+ export function parseSubstrateRoute(pathname: string): SubstrateRoute {
44
+ const seg = segments(pathname)
45
+ if (seg[0] !== 'substrate') return { screen: 'overview' }
46
+ const [, screen, a, b] = seg
47
+ if (screen === 'actors') return a && b ? { screen: 'actors', actor: { atespace: a, name: b } } : { screen: 'actors' }
48
+ if (screen === 'templates') return a && b ? { screen: 'templates', template: { atespace: a, name: b } } : { screen: 'templates' }
49
+ if (screen === 'workers') return { screen: 'workers' }
50
+ if (screen === 'workerpools' && a && b) return { screen: 'overview', pool: { namespace: a, name: b } }
51
+ return { screen: 'overview' }
52
+ }
53
+
54
+ function withParams(path: string, params: Record<string, string | undefined>): string {
55
+ const qs = new URLSearchParams()
56
+ for (const [k, v] of Object.entries(params)) if (v) qs.set(k, v)
57
+ const s = qs.toString()
58
+ return s ? `${path}?${s}` : path
59
+ }
60
+
61
+ const enc = encodeURIComponent
62
+
63
+ /** An actor's page; `ctx` pins the Kubernetes context it was read through. */
64
+ export function substrateActorPath(ref: SubstrateRef, ctx?: string, tab?: string): string {
65
+ return withParams(`${SUBSTRATE_PATH}/actors/${enc(ref.atespace)}/${enc(ref.name)}`, { ctx, tab })
66
+ }
67
+
68
+ export function substrateTemplatePath(ref: SubstrateRef, ctx?: string): string {
69
+ return withParams(`${SUBSTRATE_PATH}/templates/${enc(ref.atespace)}/${enc(ref.name)}`, { ctx })
70
+ }
71
+
72
+ export function substratePoolPath(ref: SubstratePoolRef, ctx?: string, tab?: string): string {
73
+ return withParams(`${SUBSTRATE_PATH}/workerpools/${enc(ref.namespace)}/${enc(ref.name)}`, { ctx, tab })
74
+ }
75
+
76
+ /** The Actors screen narrowed by the /actors query parameters (state, atespace, template, pool, worker, q). */
77
+ export function substrateActorsPath(filter: Record<string, string | undefined> = {}): string {
78
+ return withParams(SUBSTRATE_SCREENS.actors.path, filter)
79
+ }
80
+
81
+ /**
82
+ * What the WorkerPool kind's Resources route shows: Radar's pool table when
83
+ * this Radar serves the Substrate views; a loader while capabilities load for
84
+ * the first time; otherwise the generic table.
85
+ */
86
+ export function substrateKindListMode(support: RadarFeatureSupport, capabilitiesPending: boolean): 'view' | 'wait' | 'table' {
87
+ if (support === 'supported') return 'view'
88
+ return support === 'unknown' && capabilitiesPending ? 'wait' : 'table'
89
+ }
90
+
91
+ /** The drawer's search parameter for an actor: `<atespace>/<name>`. Actors are not Kubernetes objects, so they have their own drawer. */
92
+ export const ACTOR_DRAWER_PARAM = 'actor'
93
+
94
+ export function encodeActorParam(ref: SubstrateRef): string {
95
+ return `${ref.atespace}/${ref.name}`
96
+ }
97
+
98
+ export function decodeActorParam(value: string | null): SubstrateRef | null {
99
+ if (!value) return null
100
+ const i = value.indexOf('/')
101
+ if (i <= 0 || i === value.length - 1) return null
102
+ return { atespace: value.slice(0, i), name: value.slice(i + 1) }
103
+ }
@@ -0,0 +1,426 @@
1
+ import { createContext, useContext, type ReactNode } from 'react'
2
+ import { shellWord } from '@skyhook-io/k8s-ui/utils/shell'
3
+ import type { UseQueryResult } from '@tanstack/react-query'
4
+ import { Bot, Info } from 'lucide-react'
5
+ import {
6
+ Badge,
7
+ PaneLoader,
8
+ RadarUpgradeAction,
9
+ StatusDot,
10
+ Tooltip,
11
+ formatAge,
12
+ getRadarUpgradeRequirement,
13
+ radarUpgradeDetail,
14
+ radarUpgradeHeadline,
15
+ toneTextClass,
16
+ type StatusTone,
17
+ } from '@skyhook-io/k8s-ui'
18
+ import type {
19
+ SubstrateAPITier,
20
+ SubstrateConnection,
21
+ SubstratePoolRef,
22
+ SubstrateWorkspace,
23
+ SubstrateActorState,
24
+ SubstrateSnapshotCoverage,
25
+ SubstratePoolsCoverage,
26
+ SubstrateStatus,
27
+ SubstrateWorkerImpact,
28
+ SubstrateWorkerRow,
29
+ } from '../../api/substrateWorkspace'
30
+ import { useConnection } from '../../context/ConnectionContext'
31
+ import { CopyButton } from '../diagnose/AgentSetupNotice'
32
+ import { usePrometheusStatus } from '../../api/client'
33
+ import { BreakText, Notice, RefreshFailedNotice, ScreenEmptyState } from '../workspace/layout'
34
+ import { INCOMPLETE_COVERAGE_STATES, coverageLabel } from '../workspace/coverage'
35
+ import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
36
+ import { IMPACT_LABEL, actorStateReading, coverageInPart, coverageReason, localTime, poolReading, relativeTime, tierReading, workerStateReading } from './readings'
37
+ import { SUBSTRATE_PATH, SUBSTRATE_SCREENS, substratePoolPath } from './routes'
38
+
39
+ /** Substrate's terms, defined where they first appear on a screen. */
40
+ export const SUBSTRATE_TERMS = {
41
+ atespace: 'Substrate’s own scope for actors and templates; not a Kubernetes namespace.',
42
+ golden: 'The prepared starting snapshot a template builds for new actors. Without it, they boot cold.',
43
+ slot: 'A place for one actor on a worker; a worker’s actor limit is its number of slots. A free slot takes an actor only when the worker also has the CPU and memory the actor’s template asks.',
44
+ } as const
45
+
46
+ export type SubstrateTerm = keyof typeof SUBSTRATE_TERMS
47
+
48
+ /** A Substrate term with its definition on hover. */
49
+ export function Term({ term, children }: { term: SubstrateTerm; children: ReactNode }) {
50
+ return (
51
+ <Tooltip content={SUBSTRATE_TERMS[term]}>
52
+ <span tabIndex={0} className="cursor-help underline decoration-dotted underline-offset-2">{children}</span>
53
+ </Tooltip>
54
+ )
55
+ }
56
+
57
+ export { IMPACT_LABEL }
58
+
59
+ /**
60
+ * An actor's state chip (actorStateReading). Pass `updateTime` wherever the
61
+ * actor's last change is known: a transition held past the stuck threshold
62
+ * then says "stuck" in amber, and one in flight stays quiet.
63
+ */
64
+ export function ActorStateBadge({ state, impact, updateTime, wrap = false }: { state: SubstrateActorState; impact?: SubstrateWorkerImpact; updateTime?: string; wrap?: boolean }) {
65
+ const r = actorStateReading(state, { impact, updateTime })
66
+ const badge = <Badge severity={r.severity} size="sm" className={wrap ? 'whitespace-normal' : 'whitespace-nowrap'}>{r.label}</Badge>
67
+ return r.title ? <Tooltip content={r.title}><span className="min-w-0">{badge}</span></Tooltip> : badge
68
+ }
69
+
70
+ /** What the workspace is, in one line, at the top of its Overview. */
71
+
72
+ /** The crumb and title every Substrate screen starts with; `intro` is a line under it, `children` sit below (filters). */
73
+ export function SubstrateHeader({ title, intro, children }: { title: string; intro?: ReactNode; children?: ReactNode }) {
74
+ const navigate = useWorkspaceNavigate()
75
+ return (
76
+ <div className="px-5 pt-4 xl:px-7">
77
+ <div className="flex flex-wrap items-center gap-x-2">
78
+ <nav aria-label="Location" className="flex items-center gap-1.5 text-sm text-theme-text-tertiary">
79
+ <Bot className="h-3.5 w-3.5" />
80
+ {title === 'Overview' ? 'Agent Substrate' : <button type="button" onClick={() => navigate(SUBSTRATE_PATH)} className="hover:text-theme-text-primary hover:underline">Agent Substrate</button>}
81
+ <span>/</span>
82
+ </nav>
83
+ <h1 className="text-lg font-semibold text-theme-text-primary">{title}</h1>
84
+ </div>
85
+ {intro && <p className="mt-0.5 text-sm text-theme-text-secondary">{intro}</p>}
86
+ {children && <div className="mt-2.5 flex flex-wrap items-center gap-2">{children}</div>}
87
+ </div>
88
+ )
89
+ }
90
+
91
+ function SourcePart({ tone, label, children }: { tone: StatusTone; label: string; children: ReactNode }) {
92
+ return (
93
+ <span className="inline-flex items-center gap-1.5">
94
+ <StatusDot tone={tone} />
95
+ <span className="text-theme-text-tertiary">{label}</span>
96
+ <span className="text-theme-text-secondary">{children}</span>
97
+ </span>
98
+ )
99
+ }
100
+
101
+ /** Who Radar reads Substrate as, and the endpoint, in a few words. */
102
+ export function identityText(tier: SubstrateAPITier): string {
103
+ return tier.identity?.mode === 'tokenFile' ? 'a token file' : tier.identity?.principal ?? 'the shared identity'
104
+ }
105
+
106
+ /**
107
+ * In-cluster Radar with sign-in and Radar Hub: Radar reads as Substrate's
108
+ * shared client identity, with a token minted with the signed-in person's own
109
+ * Kubernetes access, and there is nothing to connect.
110
+ */
111
+ function SharedAsCallerIdentity() {
112
+ return (
113
+ <>
114
+ as Substrate’s shared client identity (<span className="font-mono">ate-system/ate-client</span>), minted with your Kubernetes access
115
+ <Tooltip
116
+ content="ate-client is usually one of Substrate’s global owners, so it can see every atespace. Radar only reads with it: it lists actors, templates and workers and never changes them. The token is minted with your own Kubernetes access, so it works only while you may create tokens for ate-system/ate-client. This may change to reading with your own Substrate access."
117
+ wrapperClassName="ml-1 align-middle"
118
+ >
119
+ <span tabIndex={0} aria-label="About this identity" className="inline-flex text-theme-text-tertiary hover:text-theme-text-secondary">
120
+ <Info className="h-3.5 w-3.5" />
121
+ </span>
122
+ </Tooltip>
123
+ </>
124
+ )
125
+ }
126
+
127
+ /**
128
+ * Where the screen's values come from: Substrate's API (endpoint, identity,
129
+ * read age), Prometheus, and Kubernetes, which Radar always reads.
130
+ */
131
+ export function SubstrateSourceLine({ tier, status, showRefreshFailure = true }: { tier: SubstrateAPITier; status?: SubstrateStatus; showRefreshFailure?: boolean }) {
132
+ const { data: prometheus } = usePrometheusStatus()
133
+ const service = status?.apiService
134
+ const endpoint = tier.endpoint ?? (service ? `${service.namespace}/${service.name}:${service.port}` : undefined)
135
+ const reading = tierReading(tier)
136
+ return (
137
+ <div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs" aria-label="Sources">
138
+ {tier.state === 'connected' ? (
139
+ <SourcePart tone="healthy" label="Substrate API">
140
+ {tier.identity?.mode === 'sharedAsCaller' ? (
141
+ <>
142
+ {endpoint && <><span className="font-mono">{endpoint}</span> </>}
143
+ <SharedAsCallerIdentity />
144
+ </>
145
+ ) : (
146
+ <>
147
+ {endpoint && <span className="font-mono">{endpoint}</span>} as{' '}
148
+ <span className={tier.identity?.mode === 'tokenFile' ? undefined : 'font-mono'}>{identityText(tier)}</span>
149
+ </>
150
+ )}
151
+ {tier.readAt && (
152
+ <>
153
+ {' · '}
154
+ <Tooltip content={tier.readStartedAt ? `Read from ${localTime(tier.readStartedAt)} to ${localTime(tier.readAt)}: the counts were observed over that interval, not at one instant.` : `The read finished ${localTime(tier.readAt)}.`}>
155
+ <span>read {relativeTime(tier.readAt)}</span>
156
+ </Tooltip>
157
+ </>
158
+ )}
159
+ {tier.refreshing && !tier.lastError && <> · refreshing…</>}
160
+ </SourcePart>
161
+ ) : tier.state === 'connecting' ? (
162
+ <SourcePart tone="unknown" label="Substrate API">connecting…</SourcePart>
163
+ ) : (
164
+ <SourcePart tone={reading.tone} label="Substrate API">{reading.title.toLowerCase()}</SourcePart>
165
+ )}
166
+ {showRefreshFailure && <SubstrateRefreshFailure tier={tier} />}
167
+ <SourcePart tone={prometheus?.connected ? 'healthy' : 'unknown'} label="Prometheus">
168
+ {prometheus === undefined ? 'unknown' : prometheus.connected ? 'connected' : 'not connected'}
169
+ </SourcePart>
170
+ <SourcePart tone="healthy" label="Kubernetes">WorkerPools and worker Pods</SourcePart>
171
+ </div>
172
+ )
173
+ }
174
+
175
+ export function SubstrateRefreshFailure({ tier, notice = false }: { tier: SubstrateAPITier; notice?: boolean }) {
176
+ if (!tier.lastError) return null
177
+ const summary = `Last Substrate API read failed ${relativeTime(tier.lastError.at)}. Showing the previous read.`
178
+ if (notice) return <Notice><div role="status">{summary} {tier.lastError.message}</div></Notice>
179
+ return (
180
+ <Tooltip content={tier.lastError.message}>
181
+ <span role="status" className={`text-xs ${toneTextClass('degraded')}`}>{summary}</span>
182
+ </Tooltip>
183
+ )
184
+ }
185
+
186
+ export function PoolMatchLinks({ pools, workspace }: { pools: SubstratePoolRef[]; workspace?: SubstrateWorkspace }) {
187
+ const navigate = useWorkspaceNavigate()
188
+ const { connection } = useConnection()
189
+ return (
190
+ <div className="mt-1 flex flex-wrap gap-1.5">
191
+ {pools.map((p) => {
192
+ const key = `${p.namespace}/${p.name}`
193
+ const row = workspace?.pools.find((q) => q.name === p.name && q.namespace === p.namespace)
194
+ const finding = workspace?.needsAttention.find((f) => f.subject.kind === 'WorkerPool' && f.subject.name === p.name && f.subject.namespace === p.namespace)
195
+ const reading = row && poolReading(row, finding)
196
+ const tone = reading?.severity === 'error' ? 'unhealthy' : reading?.severity === 'alert' ? 'alert'
197
+ : reading?.severity === 'warning' ? 'degraded' : reading?.severity === 'success' ? 'healthy' : 'unknown'
198
+ const open = () => navigate(row && !row.kubernetes
199
+ ? `${SUBSTRATE_SCREENS.workers.path}?${new URLSearchParams({ pool: key })}`
200
+ : substratePoolPath(p, connection.context || undefined))
201
+ const verdict = `${key} · ${reading?.label ?? 'Capacity unknown'}`
202
+ return (
203
+ <Tooltip key={key} content={verdict}>
204
+ <button type="button" aria-label={verdict} onClick={open} className="btn-secondary inline-flex items-center gap-1.5 px-2 py-0.5 text-xs font-mono"><StatusDot tone={tone} />{p.name}</button>
205
+ </Tooltip>
206
+ )
207
+ })}
208
+ </div>
209
+ )
210
+ }
211
+
212
+ const COVERAGE_NOUN: Record<keyof SubstrateSnapshotCoverage, string> = {
213
+ actors: 'actors',
214
+ templates: 'templates',
215
+ workers: 'workers',
216
+ atespaces: 'atespaces',
217
+ }
218
+
219
+ /** Says which kinds this screen reads were not read in full, and why. */
220
+ export function SubstrateCoverageNotice({
221
+ coverage,
222
+ kinds,
223
+ }: {
224
+ coverage: Partial<SubstrateSnapshotCoverage> & { pools?: SubstratePoolsCoverage }
225
+ kinds: readonly (keyof SubstrateSnapshotCoverage)[]
226
+ }) {
227
+ const parts: string[] = []
228
+ // An absent API-tier kind was not read because the tier is down; the tier banner says that.
229
+ for (const k of kinds) {
230
+ const cov = coverage[k]
231
+ if (cov && coverageInPart(cov)) parts.push(`${COVERAGE_NOUN[k]}: ${coverageReason(cov, COVERAGE_NOUN[k])}`)
232
+ }
233
+ const pools = coverage.pools
234
+ if (pools && INCOMPLETE_COVERAGE_STATES.has(pools.state)) parts.push(`WorkerPools: ${coverageLabel(pools)}`)
235
+ if (parts.length === 0) return null
236
+ return <Notice>Radar couldn’t read all of what this screen shows — {parts.join('; ')}. Counts over it are lower bounds, and what it couldn’t read shows as unknown.</Notice>
237
+ }
238
+
239
+ type GateQuery<T> = Pick<UseQueryResult<T>, 'data' | 'error' | 'isLoading' | 'isFetching' | 'refetch' | 'isRefetchError' | 'dataUpdatedAt'>
240
+
241
+ /**
242
+ * Loading, error, needs-newer-Radar and not-installed states every Substrate
243
+ * screen shares. Renders the screen only once its data is there.
244
+ */
245
+ export function SubstrateScreenGate<T>({
246
+ query,
247
+ discoveryPending,
248
+ discovered,
249
+ label = 'Agent Substrate',
250
+ children,
251
+ }: {
252
+ query: GateQuery<T>
253
+ discoveryPending: boolean
254
+ /** Discovery serves ate.dev, or could not be read (the server is asked then). */
255
+ discovered: boolean
256
+ label?: string
257
+ children: (data: T) => ReactNode
258
+ }) {
259
+ const { connection } = useConnection()
260
+ const data = query.data
261
+ if (!data && (query.isLoading || discoveryPending)) return <PaneLoader label={`Loading ${label}…`} className="flex-1" />
262
+ if (!data && !discovered) {
263
+ return <ScreenEmptyState icon={Bot} title="Agent Substrate is not installed" detail={`No ate.dev resources are served in ${connection.context || 'this cluster'}.`} />
264
+ }
265
+ if (!data) {
266
+ const upgrade = getRadarUpgradeRequirement(query.error)
267
+ if (upgrade) {
268
+ return (
269
+ <ScreenEmptyState
270
+ icon={Bot}
271
+ title={radarUpgradeHeadline('Agent Substrate')}
272
+ detail={radarUpgradeDetail(upgrade)}
273
+ action={<div className="mt-3 text-sm"><RadarUpgradeAction requirement={upgrade} /></div>}
274
+ />
275
+ )
276
+ }
277
+ return (
278
+ <ScreenEmptyState
279
+ icon={Bot}
280
+ title={`${label} unavailable`}
281
+ detail={query.error instanceof Error ? query.error.message : `Radar could not load ${label}.`}
282
+ action={
283
+ <button type="button" onClick={() => void query.refetch()} disabled={query.isFetching} className="btn-secondary mt-3 px-3 py-1.5 text-sm">
284
+ {query.isFetching ? 'Retrying…' : 'Retry'}
285
+ </button>
286
+ }
287
+ />
288
+ )
289
+ }
290
+ return <><RefreshFailedNotice queries={[query]} className="px-5 pt-3 xl:px-7" />{children(data)}</>
291
+ }
292
+
293
+ /** A value Radar could not read: its reason, never a zero. */
294
+ export function Unread({ children = 'Not connected', title }: { children?: ReactNode; title?: string }) {
295
+ const body = <span className="text-theme-text-tertiary">{children}</span>
296
+ return title ? <Tooltip content={title}><span>{body}</span></Tooltip> : body
297
+ }
298
+
299
+ /**
300
+ * The window width every Substrate table shows all its columns at: the
301
+ * Resources sidebar leaves the table about 1000px there. Below it each table
302
+ * folds its secondary columns into the cell they qualify, so names keep their
303
+ * room.
304
+ */
305
+ export const SUBSTRATE_WIDE = '(min-width: 1400px)'
306
+
307
+ /**
308
+ * An object's name in a table or card: mono and whole. Columns are sized so
309
+ * names fit on one line; a longer one wraps after a hyphen, and only a single
310
+ * segment wider than the column is cut (whole on hover).
311
+ */
312
+ export function Name({ name, className }: { name: string; className?: string }) {
313
+ // Wraps only after a hyphen, never mid-word: a generated name (a UUID) stays readable.
314
+ return <BreakText value={name} after="-" className={`font-mono ${className ?? 'text-sm'}`} />
315
+ }
316
+
317
+ export { WholeNames } from '../velero/shared'
318
+
319
+ export const NOT_CONNECTED_TITLE = 'Kept in Substrate’s API, not Kubernetes. Radar reads it once it is connected to that API.'
320
+
321
+ /**
322
+ * A time as this workspace shows every time: relative ("12m ago", "in 4m"),
323
+ * with the local date and time on hover, after `hint` when there is one.
324
+ */
325
+ export function When({ iso, hint, prefix, held }: { iso: string; hint?: string; prefix?: string; held?: boolean }) {
326
+ // Held: how long since then ("for at least 1h"), never a time with "since" ("since 1h ago" says it twice).
327
+ return (
328
+ <Tooltip content={hint ? `${hint} ${localTime(iso)}.` : localTime(iso)}>
329
+ <span className="whitespace-nowrap">{prefix ? `${prefix} ` : ''}{held ? formatAge(iso) : relativeTime(iso)}</span>
330
+ </Tooltip>
331
+ )
332
+ }
333
+
334
+ type KubectlTarget =
335
+ | { context: string; kubeconfig: string; endpoint?: string; tokenFile?: string }
336
+ | { guidance: string }
337
+
338
+ export const KubectlTargetContext = createContext<KubectlTarget | undefined>(undefined)
339
+
340
+ export function substrateKubectlTarget(view: SubstrateConnection | undefined, activeContext: string): KubectlTarget | undefined {
341
+ if (!view) return undefined
342
+ if (view.view === 'managed') {
343
+ const { endpoint, trust, serverName } = view.managed
344
+ if (endpoint && (endpoint !== 'api.ate-system.svc:443' || trust === 'caFile' || serverName !== 'api.ate-system.svc')) {
345
+ return { guidance: `Use a Substrate client configured for ${endpoint} from a machine that can reach it, with the installation’s TLS settings.` }
346
+ }
347
+ return { guidance: 'Use kubectl ate with a kubeconfig for this cluster. It port-forwards to the ate-system/api Service.' }
348
+ }
349
+
350
+ const { target, settings } = view
351
+ if (target.context !== activeContext) return undefined
352
+ if (!settings || view.targetChanged) {
353
+ return { guidance: 'Use a client configured for the Substrate instance on this cluster. Check the connection target in Settings → Agent Substrate.' }
354
+ }
355
+ if (settings.caFile || settings.serverName) {
356
+ return { guidance: `Use a Substrate client configured for ${settings.endpoint} with the CA and server name from Settings → Agent Substrate.` }
357
+ }
358
+ if (settings.endpoint && /\.svc(?:\.|:)/i.test(settings.endpoint)) {
359
+ return { guidance: `Use a Substrate client from a machine that can resolve and reach ${settings.endpoint}.` }
360
+ }
361
+ if (!target.inFileName || !target.source || !/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(target.source)) {
362
+ return { guidance: 'Use kubectl ate with a kubeconfig and context for the cluster shown here.' }
363
+ }
364
+ return {
365
+ context: target.inFileName,
366
+ kubeconfig: target.source,
367
+ endpoint: settings.endpoint,
368
+ tokenFile: settings.identity === 'tokenFile' ? settings.tokenFile : undefined,
369
+ }
370
+ }
371
+
372
+ const KUBECTL_ATE = /^kubectl ate /
373
+
374
+ function withKubectlTarget(command: string, target: Extract<KubectlTarget, { context: string }>): string {
375
+ const flags = [
376
+ `--kubeconfig ${shellWord(target.kubeconfig)}`,
377
+ `--context ${shellWord(target.context)}`,
378
+ ...(target.endpoint ? [`--endpoint ${shellWord(target.endpoint)}`] : []),
379
+ ...(target.tokenFile ? [`--token-file ${shellWord(target.tokenFile)}`] : []),
380
+ ]
381
+ return `${command} ${flags.join(' ')}`
382
+ }
383
+
384
+ /**
385
+ * A shell command a next step names, as a code chip with a copy button, on a
386
+ * line of its own under the step: it never wraps, inside itself or into the
387
+ * sentence; a command wider than its container scrolls. A command with
388
+ * <placeholders> is a template to fill in, and says so after it.
389
+ */
390
+ export function CommandChip({ command: written }: { command: string }) {
391
+ const target = useContext(KubectlTargetContext)
392
+ const isAte = KUBECTL_ATE.test(written)
393
+ if (isAte && !target) return null
394
+ if (isAte && target && 'guidance' in target) {
395
+ return <p className="mt-1 text-xs text-theme-text-secondary">{target.guidance}</p>
396
+ }
397
+ const command = isAte && target && 'context' in target ? withKubectlTarget(written, target) : written
398
+ const holes = [...new Set(command.match(/<[^<>\s]+>/g) ?? [])]
399
+ return (
400
+ <div className="mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5" data-command-line>
401
+ <span className="flex min-w-0 max-w-full items-center gap-1 rounded-md border border-theme-border bg-theme-elevated py-px pl-2 pr-0.5">
402
+ <code className="min-w-0 select-all overflow-x-auto whitespace-pre font-mono text-[11.5px] text-theme-text-primary">{command}</code>
403
+ <CopyButton text={command} label="Copy command" />
404
+ </span>
405
+ {holes.length > 0 && <span className="text-[11px] text-theme-text-tertiary">fill in {holes.join(', ')}</span>}
406
+ </div>
407
+ )
408
+ }
409
+
410
+ /** A worker's state chip, the same on Workers and on a pool's placement cards. */
411
+ export function WorkerStateChip({ w }: { w: Pick<SubstrateWorkerRow, 'state' | 'workerState' | 'attentionSeverity'> }) {
412
+ const r = workerStateReading(w)
413
+ return (
414
+ <Tooltip content={r.title}>
415
+ <span className="max-w-full"><Badge severity={r.severity} size="sm" className="whitespace-nowrap">{r.label}</Badge></span>
416
+ </Tooltip>
417
+ )
418
+ }
419
+
420
+ /**
421
+ * Text whose words are identifiers (a command, a node or Pod name, "atespace /
422
+ * name"): it wraps between words, never inside one, not even at a hyphen.
423
+ */
424
+ export function Tokens({ text }: { text: string }) {
425
+ return <>{text.split(/(\s+)/).map((part, i) => (/\s+/.test(part) ? part : <span key={i} className="inline-block whitespace-nowrap">{part}</span>))}</>
426
+ }