@skyhook-io/radar-app 1.22.1 → 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 (234) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +131 -38
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/RadarApp.tsx +5 -0
  6. package/src/api/agentSandbox.ts +259 -0
  7. package/src/api/client.autoPromConnect.test.tsx +43 -0
  8. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  9. package/src/api/client.ts +128 -25
  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/prometheusCharts.ts +5 -0
  15. package/src/api/radarFeatures.test.ts +9 -0
  16. package/src/api/radarFeatures.ts +13 -0
  17. package/src/api/substrateWorkspace.test.ts +72 -0
  18. package/src/api/substrateWorkspace.ts +1394 -0
  19. package/src/api/vulnerabilities.ts +207 -9
  20. package/src/api/workloadSource.test.tsx +1172 -0
  21. package/src/api/workloadSource.ts +408 -0
  22. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  23. package/src/components/APIUnreachableBanner.tsx +20 -0
  24. package/src/components/CloudConnectFlow.tsx +46 -7
  25. package/src/components/CloudFunnelButton.test.tsx +193 -7
  26. package/src/components/CloudFunnelButton.tsx +127 -32
  27. package/src/components/ConnectionErrorView.test.tsx +63 -2
  28. package/src/components/ConnectionErrorView.tsx +88 -68
  29. package/src/components/SelfManagedStart.tsx +12 -2
  30. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  31. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  32. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  33. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  34. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  35. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  36. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  37. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  38. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  39. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  40. package/src/components/agentsandbox/data.ts +135 -0
  41. package/src/components/agentsandbox/host.test.ts +27 -0
  42. package/src/components/agentsandbox/host.tsx +85 -0
  43. package/src/components/agentsandbox/labels.test.ts +42 -0
  44. package/src/components/agentsandbox/labels.ts +146 -0
  45. package/src/components/agentsandbox/listFilters.ts +85 -0
  46. package/src/components/agentsandbox/lists.ts +52 -0
  47. package/src/components/agentsandbox/routes.ts +23 -0
  48. package/src/components/agentsandbox/shared.tsx +321 -0
  49. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  50. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  51. package/src/components/agentsandbox/workspace.tsx +258 -0
  52. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  53. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  54. package/src/components/applications/ApplicationsView.tsx +156 -3
  55. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  56. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  57. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  58. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  59. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  60. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  61. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  62. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  63. package/src/components/cloudHints/cloudHints.ts +131 -0
  64. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  65. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  66. package/src/components/cloudHints/cloudLinks.ts +31 -0
  67. package/src/components/cloudHints/hintStorage.ts +28 -0
  68. package/src/components/cnpg/CNPGView.tsx +4 -7
  69. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  70. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  71. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  72. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  73. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  74. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  75. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  76. package/src/components/diagnose/Home.test.tsx +6 -0
  77. package/src/components/diagnose/Home.tsx +10 -3
  78. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  79. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  80. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  81. package/src/components/diagnose/InvestigationView.tsx +120 -23
  82. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  83. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  84. package/src/components/diagnose/investigationState.ts +9 -0
  85. package/src/components/diagnose/parts.test.tsx +11 -3
  86. package/src/components/diagnose/toolCallLabel.ts +3 -0
  87. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  88. package/src/components/home/ActivitySummary.tsx +3 -8
  89. package/src/components/home/ClusterHealthCard.tsx +91 -17
  90. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  91. package/src/components/home/HomeAgentBlock.tsx +2 -0
  92. package/src/components/home/HomeView.tsx +9 -29
  93. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  94. package/src/components/home/MCPSetupDialog.tsx +6 -2
  95. package/src/components/home/McpCloudLine.test.tsx +162 -0
  96. package/src/components/home/McpCloudLine.tsx +95 -0
  97. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  98. package/src/components/home/TopologyPreview.test.tsx +31 -30
  99. package/src/components/home/TopologyPreview.tsx +19 -28
  100. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  101. package/src/components/home/mcpToolCatalog.ts +7 -7
  102. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  103. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  104. package/src/components/issues/IssuesPane.tsx +181 -23
  105. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  106. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  107. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  108. package/src/components/issues/sinceLastVisit.ts +439 -0
  109. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  110. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  111. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  112. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  113. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  114. package/src/components/kagent/KagentLists.tsx +412 -0
  115. package/src/components/kagent/KagentOverview.tsx +234 -0
  116. package/src/components/kagent/KagentPages.tsx +690 -0
  117. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  118. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  119. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  120. package/src/components/kagent/KagentView.tsx +109 -0
  121. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  122. package/src/components/kagent/host.tsx +144 -0
  123. package/src/components/kagent/routes.ts +31 -0
  124. package/src/components/kagent/shared.tsx +336 -0
  125. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  126. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  127. package/src/components/kagent/workspace.fixtures.ts +108 -0
  128. package/src/components/kagent/workspaceRoute.ts +18 -0
  129. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  130. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  131. package/src/components/resource/PrometheusCharts.tsx +10 -1
  132. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  133. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  134. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  135. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  136. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  137. package/src/components/resources/ResourcesView.tsx +2 -6
  138. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  139. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  140. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  141. package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
  142. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  143. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  144. package/src/components/settings/SettingsDialog.tsx +84 -16
  145. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  146. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  147. package/src/components/settings/SubstrateSettings.tsx +544 -0
  148. package/src/components/settings/settings-state.test.ts +21 -3
  149. package/src/components/settings/settings-state.ts +13 -3
  150. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  151. package/src/components/share/ShareLinkButton.tsx +391 -0
  152. package/src/components/share/openShareInCloud.test.ts +29 -0
  153. package/src/components/share/openShareInCloud.ts +10 -0
  154. package/src/components/share/shareLink.test.ts +129 -0
  155. package/src/components/share/shareLink.ts +175 -0
  156. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  157. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  158. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  159. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  160. package/src/components/substrate/SubstrateActors.tsx +612 -0
  161. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  162. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  163. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  164. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  165. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  166. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  167. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  168. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  169. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  170. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  171. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  172. package/src/components/substrate/SubstrateView.tsx +173 -0
  173. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  174. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  175. package/src/components/substrate/attention.ts +81 -0
  176. package/src/components/substrate/contextPin.tsx +69 -0
  177. package/src/components/substrate/host.tsx +83 -0
  178. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  179. package/src/components/substrate/readings.test.ts +484 -0
  180. package/src/components/substrate/readings.ts +997 -0
  181. package/src/components/substrate/routes.ts +103 -0
  182. package/src/components/substrate/shared.tsx +426 -0
  183. package/src/components/substrate/substrate.fixtures.ts +325 -0
  184. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  185. package/src/components/substrate/workspaceRoute.ts +23 -0
  186. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  187. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  188. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  189. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  190. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  191. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  192. package/src/components/traffic/TrafficGraph.tsx +17 -14
  193. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  194. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  195. package/src/components/traffic/TrafficView.tsx +26 -56
  196. package/src/components/traffic/trafficFilters.test.ts +61 -1
  197. package/src/components/traffic/trafficFilters.ts +68 -8
  198. package/src/components/velero/VeleroOverview.tsx +2 -2
  199. package/src/components/velero/VeleroView.tsx +3 -6
  200. package/src/components/vulnerabilities/columns.tsx +132 -0
  201. package/src/components/vulnerabilities/filters.tsx +317 -0
  202. package/src/components/vulnerabilities/owner.test.ts +54 -0
  203. package/src/components/vulnerabilities/owner.tsx +163 -0
  204. package/src/components/vulnerabilities/parts.test.ts +126 -12
  205. package/src/components/vulnerabilities/parts.tsx +612 -52
  206. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  207. package/src/components/vulnerabilities/traffic.tsx +40 -0
  208. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  209. package/src/components/workload/WorkloadView.tsx +119 -14
  210. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  211. package/src/components/workspace/layout.tsx +13 -7
  212. package/src/components/workspace/sidebar.test.ts +48 -0
  213. package/src/components/workspace/sidebar.ts +73 -3
  214. package/src/components/workspace/table.ts +2 -1
  215. package/src/context/ConnectionContext.tsx +24 -5
  216. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  217. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  218. package/src/context/DiagnoseCustomization.tsx +20 -2
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/hooks/useEventSource.test.tsx +275 -4
  222. package/src/hooks/useEventSource.ts +278 -51
  223. package/src/index.ts +1 -0
  224. package/src/integrations/resourceHost.ts +12 -6
  225. package/src/integrations/resourceHosts.test.tsx +27 -1
  226. package/src/integrations/resourceHosts.tsx +15 -7
  227. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  228. package/src/integrations/sidebarWorkspaces.ts +41 -0
  229. package/src/integrations/workspaceRoute.ts +1 -1
  230. package/src/integrations/workspaceRoutes.ts +7 -1
  231. package/src/integrations/workspaceScreens.tsx +6 -0
  232. package/src/utils/navigation.test.ts +1 -6
  233. package/src/utils/navigation.ts +9 -44
  234. package/src/utils/network-policy-navigation.test.ts +21 -36
package/src/api/client.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { hasPrometheusCharts, metricsSourceUnavailable } from './prometheusCharts'
1
+ import { hasPrometheusCharts, metricsSourceChecking, metricsSourceUnavailable } from './prometheusCharts'
2
2
  import type { RightsizingRow, WorkloadRightsizingEvidence } from '@skyhook-io/k8s-ui/types/rightsizing'
3
3
  import { followSwitch, switchFinished, switchInProgress, type ContextSwitchOperation } from './contextSwitch'
4
4
  import { createListRefetchInterval, normalizeResourceList, type ResourceListBody, type ResourceListResult } from './resourceLists'
5
5
  import type { CascadeDetail } from '@skyhook-io/k8s-ui/components/ui/ForceDeleteConfirmDialog'
6
6
  import { canonicalResourceGroup } from '@skyhook-io/k8s-ui/utils/api-resources'
7
7
  import { pluralize } from '@skyhook-io/k8s-ui/utils/pluralize'
8
- import type { ReadGap, ReadGapSet } from '@skyhook-io/k8s-ui/types/read-coverage'
8
+ import type { ReadGap, ReadGapSet, ReadNameSet } from '@skyhook-io/k8s-ui/types/read-coverage'
9
9
  import type { ClusterScope } from '@skyhook-io/k8s-ui/types/cluster-scope'
10
10
  import type { WorkloadHistoryCoverage } from '@skyhook-io/k8s-ui/utils/workload-history-notes'
11
11
  import { knownKindForPluralWithGroup, pluralToKind } from '@skyhook-io/k8s-ui/utils/navigation'
@@ -38,7 +38,7 @@ import type {
38
38
  YamlDocumentIdentity,
39
39
  YamlSchemaLoadResult,
40
40
  } from '@skyhook-io/k8s-ui'
41
- import { focusManager, onlineManager, useInfiniteQuery, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
41
+ import { focusManager, onlineManager, useInfiniteQuery, useIsFetching, useQuery, useMutation, useQueryClient, skipToken, type QueryClient } from '@tanstack/react-query'
42
42
  import { showApiError, showApiSuccess, showApiNotice } from '../components/ui/Toast'
43
43
  import { useIsAuthEnabled, useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
44
44
  import { applyTabPick, cleanPick, ownsTabPick, pruneTabPick, withActives, writeTabPick } from '../utils/namespacePick'
@@ -100,6 +100,7 @@ import {
100
100
  import { useRadarUpgradeHost } from '../context/RadarUpgradeHost'
101
101
  import { isGitOpsActionTarget, gitOpsActionPermissions, gitOpsDisabledReasons, type GitOpsActionCapabilities } from './gitOpsPermissions'
102
102
  import { apiVersionToGroup } from '../utils/navigation'
103
+ import type { CloudHintEntry } from '../components/cloudHints/cloudHints'
103
104
  import { isBadgeWorthy } from '../utils/auditBadges'
104
105
  import type { DeploymentMode } from '../types'
105
106
 
@@ -502,6 +503,9 @@ export interface DashboardMetrics {
502
503
  // When false, only requests/capacity are meaningful — live usage (from
503
504
  // metrics-server) is unavailable and usage fields are zero.
504
505
  usageAvailable: boolean;
506
+ // Namespaces whose pods were summed into requestsMillis/requestPercent.
507
+ // Omitted when requests cover the whole cluster or from an older Radar.
508
+ requestsNamespaces?: ReadNameSet;
505
509
  }
506
510
 
507
511
  export interface MetricSummary {
@@ -596,6 +600,7 @@ import type {
596
600
  Check,
597
601
  Issue,
598
602
  IssueRecentChange,
603
+ SchedulingBlockerSummary,
599
604
  } from "@skyhook-io/k8s-ui";
600
605
  export type DashboardAudit = AuditCardData;
601
606
  export type { AuditFinding, ResourceGroup, CheckMeta, Check };
@@ -695,6 +700,8 @@ export interface DashboardNetworkPolicyCoverage {
695
700
  // Workloads left out of totalWorkloads.
696
701
  ignoredNamespaceWorkloads?: number;
697
702
  hostNetworkWorkloads?: number;
703
+ // Kubernetes kind and API group of the counted policies. Older Radars omit it.
704
+ policyKinds?: { kind: string; group: string }[];
698
705
  }
699
706
 
700
707
  export interface DashboardGitOpsControllers {
@@ -865,6 +872,9 @@ export function useUpgradeReadiness(target?: string) {
865
872
  // that honestly rather than presenting a capped list as if it were complete.
866
873
  export interface IssuesResponse {
867
874
  issues: Issue[]
875
+ scheduling_blockers?: SchedulingBlockerSummary[]
876
+ scheduling_node_gap?: string
877
+ next_member_after?: string
868
878
  total?: number
869
879
  total_matched?: number
870
880
  recent_changes?: IssueRecentChange[]
@@ -903,20 +913,38 @@ export interface UncheckedSource {
903
913
  namespaces?: string[];
904
914
  }
905
915
 
906
- export function useIssues(namespaces: string[] = [], enabled = true, kind?: string) {
916
+ export function useIssues(namespaces: string[] = [], enabled = true, kind?: string, view?: 'blockers') {
907
917
  const params = new URLSearchParams();
908
918
  if (namespaces.length) params.set('namespaces', namespaces.join(','));
909
919
  if (kind) { params.set('kind', kind); params.set('limit', '1000'); }
920
+ if (view) params.set('view', view);
910
921
  const query = params.toString();
922
+ const key = kind ? ["issues", namespaces, kind] : ["issues", namespaces];
911
923
  return useQuery<IssuesResponse>({
912
- queryKey: kind ? ["issues", namespaces, kind] : ["issues", namespaces],
913
- queryFn: () => fetchJSON(`/issues${query ? `?${query}` : ''}`),
924
+ queryKey: view ? [...key, view] : key,
925
+ queryFn: ({ signal }) => fetchJSON(`/issues${query ? `?${query}` : ''}`, signal),
914
926
  staleTime: 30000,
915
927
  refetchInterval: ISSUES_REFRESH_INTERVAL_MS,
916
928
  enabled,
917
929
  });
918
930
  }
919
931
 
932
+ export function useSchedulingBlockerMembers(blocker: SchedulingBlockerSummary, namespaces: string[], enabled: boolean) {
933
+ return useInfiniteQuery({
934
+ queryKey: ["issues", namespaces, "blockers", blocker.id, blocker.affected_workloads],
935
+ queryFn: ({ pageParam, signal }) => {
936
+ const params = new URLSearchParams({ view: "blockers", blocker: blocker.id, limit: "25" });
937
+ if (namespaces.length) params.set("namespaces", namespaces.join(","));
938
+ if (pageParam) params.set("after", pageParam);
939
+ return fetchJSON<IssuesResponse>(`/issues?${params}`, signal);
940
+ },
941
+ initialPageParam: "",
942
+ getNextPageParam: (page) => page.next_member_after,
943
+ staleTime: ISSUES_REFRESH_INTERVAL_MS,
944
+ enabled,
945
+ });
946
+ }
947
+
920
948
  export function useResourceAudit(
921
949
  kind: string,
922
950
  namespace: string,
@@ -2165,6 +2193,13 @@ function versionCheckQueryOptions(apiBase: string) {
2165
2193
  };
2166
2194
  }
2167
2195
 
2196
+ /** The connected Radar's version, from the version check the app already runs; undefined until known. */
2197
+ export function useRadarVersion(): string | undefined {
2198
+ const { data } = useQuery<VersionInfo>(versionCheckQueryOptions(getApiBase()))
2199
+ const { radarVersion } = useRadarUpgradeHost()
2200
+ return data?.currentVersion || radarVersion || undefined
2201
+ }
2202
+
2168
2203
  export function useVersionCheck() {
2169
2204
  const capabilities = useCapabilities()
2170
2205
  const apiBase = getApiBase()
@@ -2564,19 +2599,21 @@ export interface CloudConnectInfo {
2564
2599
 
2565
2600
  // Deliberately a bare cross-origin GET: no credentials, no identifiers. The
2566
2601
  // Hub learns what any HTTP request reveals plus `about`, below: the lane the
2567
- // footer renders and this deployment's mode, both closed enums, so nothing
2568
- // about the cluster or the person rides along. Part of the query key so a
2569
- // lane change (a driver install that just became tunneled, say) refetches
2570
- // instead of reusing the other lane's copy.
2602
+ // footer renders, this deployment's mode, and which in-app hint opened the
2603
+ // dialog, all closed enums, so nothing about the cluster or the person rides
2604
+ // along. Part of the query key so a lane change (a driver install that just
2605
+ // became tunneled, say) or a different hint refetches instead of reusing the
2606
+ // other's copy.
2571
2607
  export function useCloudConnectInfo(
2572
2608
  apiUrl: string | undefined,
2573
2609
  enabled: boolean,
2574
- about: { lane: "driver" | "wizard"; mode?: DeploymentMode },
2610
+ about: { lane: "driver" | "wizard"; mode?: DeploymentMode; entry?: CloudHintEntry | null },
2575
2611
  ) {
2576
2612
  const params = new URLSearchParams({ lane: about.lane });
2577
2613
  if (about.mode) params.set("mode", about.mode);
2614
+ if (about.entry) params.set("entry", about.entry);
2578
2615
  return useQuery<CloudConnectInfo>({
2579
- queryKey: ["cloud-connect-info", apiUrl, about.lane, about.mode],
2616
+ queryKey: ["cloud-connect-info", apiUrl, about.lane, about.mode, about.entry ?? null],
2580
2617
  queryFn: async () => {
2581
2618
  const res = await fetch(`${apiUrl}/api/connect/info?${params}`, {
2582
2619
  credentials: "omit",
@@ -2662,14 +2699,22 @@ export interface CloudInstallDiscovered {
2662
2699
  partialScan: boolean
2663
2700
  }
2664
2701
 
2665
- // Keyed by context: a switch must not describe the previous cluster.
2666
- export function useCloudInstallDiscover(enabled: boolean, contextName: string | undefined) {
2702
+ // Keyed by context: a switch must not describe the previous cluster. The
2703
+ // lookup lists Deployments across the cluster, so a caller that only words a
2704
+ // hint can reuse an answer up to maxAgeMs old. Those answers are cached under
2705
+ // their own key: the Cloud dialog passes none and must never show an old
2706
+ // answer while it asks again.
2707
+ export function useCloudInstallDiscover(
2708
+ enabled: boolean,
2709
+ contextName: string | undefined,
2710
+ { maxAgeMs = 0 }: { maxAgeMs?: number } = {},
2711
+ ) {
2667
2712
  return useQuery<CloudInstallDiscovered>({
2668
- queryKey: ['cloud-install-discover', contextName],
2713
+ queryKey: maxAgeMs > 0 ? ['cloud-install-discover', contextName, 'reusable'] : ['cloud-install-discover', contextName],
2669
2714
  queryFn: () => fetchJSON('/cloud/install/discover'),
2670
2715
  enabled,
2671
- staleTime: 0,
2672
- gcTime: 0,
2716
+ staleTime: maxAgeMs,
2717
+ gcTime: maxAgeMs,
2673
2718
  retry: false,
2674
2719
  })
2675
2720
  }
@@ -4394,6 +4439,48 @@ export function usePrometheusStatus(enabled = true) {
4394
4439
  });
4395
4440
  }
4396
4441
 
4442
+ const PROM_STATUS_CHECK_KEY = ["prometheus-status-check"];
4443
+
4444
+ /**
4445
+ * Settings opening on a metrics relay (OpenObserve) asks Radar to send it one
4446
+ * query and wait, so a backend that went down while nothing queried it reads
4447
+ * as unavailable rather than connected. Radar never queries it on its own.
4448
+ */
4449
+ export function useMetricsRelayCheck(open: boolean) {
4450
+ const queryClient = useQueryClient();
4451
+ const { data: status } = usePrometheusStatus(open);
4452
+ const relay = status?.source?.kind === "openobserve" && !!(status.source.matchedBy || status.source.unavailable);
4453
+ const checked = useRef(false);
4454
+ useEffect(() => {
4455
+ if (!open) {
4456
+ checked.current = false;
4457
+ void queryClient.cancelQueries({ queryKey: PROM_STATUS_CHECK_KEY });
4458
+ return;
4459
+ }
4460
+ if (checked.current || !relay) return;
4461
+ checked.current = true;
4462
+ queryClient
4463
+ .fetchQuery({
4464
+ queryKey: PROM_STATUS_CHECK_KEY,
4465
+ // The check only updates what Radar knows. The status is read after
4466
+ // it rather than taken from its reply, so a newer status this tab
4467
+ // received meanwhile is never replaced by an older one.
4468
+ queryFn: async ({ signal }) => {
4469
+ await fetchJSON("/prometheus/status?check=true", signal);
4470
+ await queryClient.refetchQueries({ queryKey: ["prometheus-status"], exact: true });
4471
+ return true;
4472
+ },
4473
+ staleTime: 0,
4474
+ })
4475
+ .catch(() => {});
4476
+ }, [open, relay, queryClient]);
4477
+ }
4478
+
4479
+ /** A metrics relay check Settings asked for is waiting on its answer. */
4480
+ export function useMetricsRelayChecking(): boolean {
4481
+ return useIsFetching({ queryKey: PROM_STATUS_CHECK_KEY }) > 0;
4482
+ }
4483
+
4397
4484
  export interface ArgoStatus {
4398
4485
  // configured = a URL or token is set; connected = a probe has landed and the
4399
4486
  // client is live. The two differ right after a restart (configured, reconnecting).
@@ -4516,6 +4603,7 @@ export function useAutoPromConnect(): void {
4516
4603
  const { data: status, isLoading: statusLoading } = usePrometheusStatus();
4517
4604
  const chartsAvailable = hasPrometheusCharts(status);
4518
4605
  const sourceUnavailable = metricsSourceUnavailable(status);
4606
+ const sourceChecking = metricsSourceChecking(status);
4519
4607
  const attemptedRef = useRef<string | null>(null);
4520
4608
 
4521
4609
  useEffect(() => {
@@ -4536,6 +4624,9 @@ export function useAutoPromConnect(): void {
4536
4624
  // An OpenObserve connection that can't answer is the source in use;
4537
4625
  // discovering Prometheus would not stand in for it.
4538
4626
  if (sourceUnavailable) return;
4627
+ // Until Radar knows whether OpenObserve serves this cluster, discovering
4628
+ // Prometheus would race the answer.
4629
+ if (sourceChecking) return;
4539
4630
  if (attemptedRef.current === context) return;
4540
4631
  let cached: string | null = null;
4541
4632
  try {
@@ -4549,13 +4640,15 @@ export function useAutoPromConnect(): void {
4549
4640
  // Cached path probes immediately; first-time path defers briefly so the
4550
4641
  // initial UI render isn't competing with the cluster network call.
4551
4642
  const delay = cached === "1" ? 0 : PROM_FIRSTLAUNCH_PROBE_DELAY_MS;
4643
+ // The server only reports discovering once the run has started; mark it
4644
+ // now so the view shows progress from the start instead of the manual CTA
4645
+ // until the request lands.
4646
+ queryClient.setQueryData<PrometheusStatus>(["prometheus-status"], (prev) =>
4647
+ prev ? { ...prev, discovering: true } : prev,
4648
+ );
4649
+ let sent = false;
4552
4650
  const timeout = window.setTimeout(() => {
4553
- // The server only reports discovering once the run has started; mark it
4554
- // here first so the view shows progress instead of the manual CTA for the
4555
- // whole duration of this request.
4556
- queryClient.setQueryData<PrometheusStatus>(["prometheus-status"], (prev) =>
4557
- prev ? { ...prev, discovering: true } : prev,
4558
- );
4651
+ sent = true;
4559
4652
  // Direct apiFetch (not via the usePrometheusConnect mutation) so the
4560
4653
  // meta-driven toast handler stays silent — the user didn't click anything.
4561
4654
  apiFetch(`${getApiBase()}/prometheus/connect?optional=true`, {
@@ -4587,8 +4680,18 @@ export function useAutoPromConnect(): void {
4587
4680
  attemptedRef.current = null;
4588
4681
  });
4589
4682
  }, delay);
4590
- return () => window.clearTimeout(timeout);
4591
- }, [clusterInfo?.context, chartsAvailable, sourceUnavailable, statusLoading, queryClient]);
4683
+ return () => {
4684
+ window.clearTimeout(timeout);
4685
+ if (sent) return;
4686
+ // Canceled before it was sent (an OpenObserve check began, say): forget
4687
+ // the attempt so the probe runs once this context is eligible again.
4688
+ attemptedRef.current = null;
4689
+ queryClient.setQueryData<PrometheusStatus>(
4690
+ ["prometheus-status"],
4691
+ (prev) => (prev?.discovering ? { ...prev, discovering: false } : prev),
4692
+ );
4693
+ };
4694
+ }, [clusterInfo?.context, chartsAvailable, sourceUnavailable, sourceChecking, statusLoading, queryClient]);
4592
4695
  }
4593
4696
 
4594
4697
  // Fetch Prometheus metrics for a resource
@@ -0,0 +1,76 @@
1
+ // @vitest-environment jsdom
2
+ import { act, useRef } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
6
+ import { useCloudInstallDiscover } from './client'
7
+
8
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
9
+ let root: Root
10
+ let host: HTMLDivElement
11
+ let client: QueryClient
12
+ let calls = 0
13
+
14
+ const firstRenders: string[] = []
15
+
16
+ function Probe({ maxAgeMs }: { maxAgeMs?: number }) {
17
+ const q = useCloudInstallDiscover(true, 'kind-dev', maxAgeMs === undefined ? undefined : { maxAgeMs })
18
+ const shown = q.data ? 'ready' : 'pending'
19
+ // Recorded during the first render itself: read after act() instead, the
20
+ // fetch may already have resolved, depending on how busy the machine is.
21
+ const recorded = useRef(false)
22
+ if (!recorded.current) {
23
+ recorded.current = true
24
+ firstRenders.push(shown)
25
+ }
26
+ return <span>{shown}</span>
27
+ }
28
+
29
+ async function mountProbe(maxAgeMs?: number) {
30
+ await act(async () => {
31
+ root.render(<QueryClientProvider client={client}><Probe maxAgeMs={maxAgeMs} /></QueryClientProvider>)
32
+ })
33
+ await vi.waitFor(() => expect(host.textContent).toBe('ready'))
34
+ await act(async () => root.unmount())
35
+ root = createRoot(host)
36
+ }
37
+
38
+ beforeEach(() => {
39
+ calls = 0
40
+ client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
41
+ host = document.createElement('div')
42
+ document.body.appendChild(host)
43
+ root = createRoot(host)
44
+ vi.stubGlobal('fetch', vi.fn(async () => {
45
+ calls++
46
+ return new Response(JSON.stringify({ connected: [], partialScan: false }), { status: 200 })
47
+ }))
48
+ })
49
+
50
+ afterEach(() => {
51
+ client.clear()
52
+ host.remove()
53
+ vi.unstubAllGlobals()
54
+ })
55
+
56
+ describe('useCloudInstallDiscover', () => {
57
+ it('reuses a recent answer when the caller allows one', async () => {
58
+ await mountProbe(5 * 60_000)
59
+ await mountProbe(5 * 60_000)
60
+ expect(calls).toBe(1)
61
+ })
62
+
63
+ it('asks again on every mount by default, as the Cloud dialog needs', async () => {
64
+ await mountProbe()
65
+ await mountProbe()
66
+ expect(calls).toBe(2)
67
+ })
68
+
69
+ it('never shows a default caller the cached answer while it asks again', async () => {
70
+ firstRenders.length = 0
71
+ await mountProbe(5 * 60_000)
72
+ await mountProbe()
73
+ expect(calls).toBe(2)
74
+ expect(firstRenders[1]).toBe('pending')
75
+ })
76
+ })
@@ -35,6 +35,10 @@ export interface AgentsResponse {
35
35
  // "install an agent to enable this" (eligible && !enabled) apart from "not
36
36
  // available here" (auth/cloud/--no-mcp). Absent on older servers / embed hosts.
37
37
  eligible?: boolean;
38
+ // Why investigations can't run here when not eligible: "shared" for a team
39
+ // installation (auth or operator-managed config), "no-mcp" when the MCP
40
+ // mount is off. Empty when eligible; absent on older servers.
41
+ unavailableReason?: "" | "shared" | "no-mcp";
38
42
  // cliOverride: RADAR_AI_CLI_BIN is set, pinning the engine to one CLI. With
39
43
  // CLIs detected and investigations still off, that variable is what's broken.
40
44
  // Absent on older servers and embed hosts.
@@ -0,0 +1,82 @@
1
+ import { beforeEach, expect, it, vi } from 'vitest'
2
+ import { QueryClient, useInfiniteQuery, useQuery } from '@tanstack/react-query'
3
+ import { ApiError, fetchJSON } from './client'
4
+ import { useKagentSessionSummary, useKagentWorkspace } from './kagent'
5
+ const state = vi.hoisted(() => ({ workspace: 'supported', context: 'one', base: '/api' }))
6
+ vi.mock('@tanstack/react-query', async (original) => ({ ...(await original<typeof import('@tanstack/react-query')>()), useQuery: vi.fn(() => ({})), useInfiniteQuery: vi.fn(() => ({})) }))
7
+ vi.mock('./config', () => ({ getApiBase: () => state.base }))
8
+ vi.mock('./client', async (original) => ({
9
+ ...(await original<typeof import('./client')>()),
10
+ fetchJSON: vi.fn(),
11
+ useClusterInfo: () => ({ data: { context: state.context } }),
12
+ useRadarFeature: (feature: string) => ({
13
+ support: feature === 'kagentWorkspace' ? state.workspace : 'unsupported',
14
+ gatedKey: [],
15
+ guard: (fn: () => unknown) => fn(),
16
+ }),
17
+ }))
18
+ beforeEach(() => {
19
+ vi.clearAllMocks()
20
+ state.workspace = 'supported'
21
+ state.context = 'one'
22
+ state.base = '/api'
23
+ })
24
+ it.each(['unsupported', 'unknown'])('gates configuration and runtime on the workspace capability while it is %s', (support) => {
25
+ state.workspace = support
26
+ useKagentWorkspace([])
27
+ expect(vi.mocked(useQuery).mock.calls.at(-1)![0].enabled).toBe(false)
28
+ useKagentSessionSummary([])
29
+ expect(vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].enabled).toBe(false)
30
+ })
31
+ it('keeps retrying pending discovery and keeps the ordinary error budget', () => {
32
+ useKagentWorkspace([])
33
+ const options = vi.mocked(useQuery).mock.calls.at(-1)![0]
34
+ const retry = options.retry as (count: number, error: unknown) => boolean
35
+ const delay = options.retryDelay as (count: number, error: unknown) => number
36
+ const pending = new ApiError('discovery is running', 503, { error_code: 'kind_sync_pending' })
37
+ expect(retry(10, pending)).toBe(true)
38
+ expect(delay(10, pending)).toBe(2000)
39
+ expect(retry(1, new ApiError('unavailable', 503))).toBe(false)
40
+ })
41
+ it('separates namespaces, contexts and API hosts and carries cancellation', async () => {
42
+ useKagentWorkspace(['b', 'a'])
43
+ const first = vi.mocked(useQuery).mock.calls.at(-1)![0]
44
+ await (first.queryFn as (context: { signal: AbortSignal }) => Promise<unknown>)({ signal: new AbortController().signal })
45
+ expect(fetchJSON).toHaveBeenCalledWith('/kagent/workspace?namespaces=a%2Cb', expect.any(AbortSignal))
46
+ state.context = 'two'
47
+ useKagentWorkspace(['a', 'b'])
48
+ expect(vi.mocked(useQuery).mock.calls.at(-1)![0].queryKey).not.toEqual(first.queryKey)
49
+ state.base = '/other'
50
+ useKagentWorkspace(['a', 'b'])
51
+ expect(vi.mocked(useQuery).mock.calls.at(-1)![0].queryKey).not.toEqual(first.queryKey)
52
+ expect(first.placeholderData).toBeUndefined()
53
+ })
54
+ it('pages the fleet summary instead of treating its first 1000 Agents as the fleet', () => {
55
+ useKagentSessionSummary([])
56
+ const options = vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0]
57
+ const next = options.getNextPageParam as (lastPage: { offset: number; rows: unknown[]; total: number }) => number | undefined
58
+ expect(next({ offset: 0, rows: Array(1000), total: 1001 })).toBe(1000)
59
+ expect(next({ offset: 1000, rows: [1], total: 1001 })).toBeUndefined()
60
+ expect(next({ offset: 0, rows: [], total: 1001 })).toBeUndefined()
61
+ })
62
+
63
+ it('invalidates session summaries with the saved Substrate connection, only for that API host', async () => {
64
+ const client = new QueryClient()
65
+ useKagentSessionSummary([])
66
+ const first = vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].queryKey
67
+ state.base = '/other'
68
+ useKagentSessionSummary([])
69
+ const other = vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].queryKey
70
+ client.setQueryData(first, { rows: [] })
71
+ client.setQueryData(other, { rows: [] })
72
+ await client.invalidateQueries({ queryKey: ['substrate', '/api'] })
73
+ expect(client.getQueryState(first)?.isInvalidated).toBe(true)
74
+ expect(client.getQueryState(other)?.isInvalidated).toBe(false)
75
+ client.clear()
76
+ })
77
+ it('enables both workspace endpoints when Radar advertises kagentWorkspace', () => {
78
+ useKagentWorkspace([])
79
+ useKagentSessionSummary([])
80
+ expect(vi.mocked(useQuery).mock.calls.at(-1)![0].enabled).toBe(true)
81
+ expect(vi.mocked(useInfiniteQuery).mock.calls.at(-1)![0].enabled).toBe(true)
82
+ })
@@ -0,0 +1,230 @@
1
+ import { useInfiniteQuery, useQuery } from '@tanstack/react-query'
2
+ import type { HealthLevel } from '@skyhook-io/k8s-ui'
3
+ import { fetchJSON, isStillLoadingError, useClusterInfo, useRadarFeature } from './client'
4
+ import { getApiBase } from './config'
5
+ import { shouldRetryRadarQuery } from './radarFeatures'
6
+ import type { WorkspaceKindCoverage } from '../components/workspace/coverage'
7
+ import type {
8
+ KagentAgentSessions,
9
+ SubstrateAPITier,
10
+ SubstrateCoverage,
11
+ SubstratePoolRef,
12
+ SubstrateRef,
13
+ } from './substrateWorkspace'
14
+
15
+ export interface KagentRef {
16
+ group: string
17
+ kind: string
18
+ namespace: string
19
+ name: string
20
+ }
21
+ export interface KagentReading {
22
+ state: string
23
+ tone: HealthLevel
24
+ text: string
25
+ summary: string
26
+ condition?: string
27
+ reason?: string
28
+ message?: string
29
+ since?: string
30
+ egress?: string
31
+ }
32
+ export interface KagentDependency {
33
+ ref: KagentRef
34
+ state: string
35
+ unread?: string
36
+ reading?: KagentReading
37
+ }
38
+ export interface KagentReference {
39
+ role: string
40
+ target: KagentRef
41
+ from: KagentRef
42
+ field: string
43
+ state: string
44
+ unread?: string
45
+ reading?: KagentReading
46
+ policyUnknown?: boolean
47
+ tools?: string[]
48
+ key?: string
49
+ fallback?: boolean
50
+ }
51
+ export interface KagentToolAsk {
52
+ server: KagentRef
53
+ tool: string
54
+ agents?: KagentRef[]
55
+ }
56
+ export interface KagentAgent {
57
+ ref: KagentRef
58
+ reading: KagentReading
59
+ latestChange: { state: string; message?: string }
60
+ newSessionsRevision?: string
61
+ desiredRevision?: string
62
+ created?: string
63
+ description?: string
64
+ inlineTemplate: boolean
65
+ harnessType?: string
66
+ model?: KagentDependency
67
+ mcpServers: { declared: number; failing: number; absent: number; unread: number; notPermitted: number }
68
+ references: KagentReference[]
69
+ toolsNotOffered?: KagentToolAsk[]
70
+ incomplete?: boolean
71
+ cycle?: string[]
72
+ }
73
+ export interface KagentAffected {
74
+ agent: KagentRef
75
+ effect: 'blocked' | 'mayRunWithoutTools' | 'usesIt'
76
+ roles: string[]
77
+ through?: string[]
78
+ }
79
+ export interface KagentImpact {
80
+ agents: KagentAffected[]
81
+ count: number
82
+ lowerBound: boolean
83
+ consumers: 'seen' | 'none' | 'noneSeen'
84
+ byRole?: Record<string, number>
85
+ }
86
+ export interface KagentFinding {
87
+ id: string
88
+ subject: KagentRef
89
+ severity: 'critical' | 'warning'
90
+ reason: string
91
+ kagentReason?: string
92
+ message: string
93
+ action: string
94
+ since?: string
95
+ secret?: KagentRef
96
+ cause?: { target: KagentRef; role: string; form: string }
97
+ affects?: KagentImpact
98
+ }
99
+ export interface KagentGroup {
100
+ id: string
101
+ severity: 'critical' | 'warning'
102
+ secret?: KagentRef
103
+ findings: string[]
104
+ folded?: { finding: string; under: string }[]
105
+ }
106
+ export interface KagentMCPServer {
107
+ ref: KagentRef
108
+ reading: KagentReading
109
+ url?: string
110
+ protocol?: string
111
+ toolsOffered: string[]
112
+ toolsOfferedKnown: boolean
113
+ failing: boolean
114
+ headers?: { name: string; from?: KagentRef; key?: string; inline?: boolean }[]
115
+ usedBy: KagentImpact
116
+ askedNotOffered?: KagentToolAsk[]
117
+ }
118
+ export interface KagentCredential {
119
+ mode: string
120
+ secret?: KagentRef
121
+ key?: string
122
+ }
123
+ export interface KagentModel {
124
+ ref: KagentRef
125
+ reading: KagentReading
126
+ provider?: string
127
+ model?: string
128
+ credential: KagentCredential
129
+ usedBy: KagentImpact
130
+ }
131
+ export interface KagentCount {
132
+ n: number
133
+ lowerBound: boolean
134
+ }
135
+ export type KagentCoverageKey =
136
+ 'agents' | 'agentTemplates' | 'harnesses' | 'models' | 'mcpServers' | 'egressPolicies' | 'modelProviders' | 'sandboxTemplates'
137
+ export interface KagentWorkspace {
138
+ context: string
139
+ installed: boolean
140
+ namespaces: string[]
141
+ forcedNamespace?: string
142
+ coverage: Record<KagentCoverageKey, WorkspaceKindCoverage>
143
+ referenceCoverage: Record<KagentCoverageKey, WorkspaceKindCoverage>
144
+ agents: KagentAgent[]
145
+ models: KagentModel[]
146
+ mcpServers: KagentMCPServer[]
147
+ modelProviders: { ref: KagentRef; reading: KagentReading; provider?: string }[]
148
+ findings: KagentFinding[]
149
+ groups: KagentGroup[]
150
+ counts: Record<
151
+ 'findings' | 'critical' | 'agents' | 'agentsAffected' | 'mcpServers' | 'mcpServersFailing' | 'models' | 'modelsWithProblems',
152
+ KagentCount
153
+ > & { groups: { n: number; incomplete: boolean }; agentsByLatestChange: Record<string, number> }
154
+ }
155
+ export interface KagentSessionRow extends Pick<
156
+ KagentAgentSessions,
157
+ | 'agent'
158
+ | 'revisions'
159
+ | 'sessions'
160
+ | 'onEarlierRevisions'
161
+ | 'complete'
162
+ | 'needAttention'
163
+ | 'attention'
164
+ | 'hintedEarlierRevisions'
165
+ | 'hintShared'
166
+ > {
167
+ crashed: number
168
+ onNewSessionsRevision: number
169
+ onOtherRevisions: number
170
+ placement: {
171
+ state: 'unknown' | 'mayFit' | 'noActiveWorkers' | 'full' | 'noRoom'
172
+ reading: string
173
+ template?: SubstrateRef
174
+ pools: SubstratePoolRef[]
175
+ complete: boolean
176
+ }
177
+ }
178
+ export interface KagentSessionSummary {
179
+ apiTier: SubstrateAPITier
180
+ coverage: {
181
+ actors: SubstrateCoverage
182
+ templates: SubstrateCoverage
183
+ workers: SubstrateCoverage
184
+ atespaces: SubstrateCoverage
185
+ }
186
+ rows: KagentSessionRow[]
187
+ total: number
188
+ lowerBound: boolean
189
+ limit: number
190
+ offset: number
191
+ }
192
+
193
+ export function useKagentWorkspace(namespaces: string[], enabled = true) {
194
+ const feature = useRadarFeature('kagentWorkspace')
195
+ const { data: cluster } = useClusterInfo()
196
+ const params = new URLSearchParams()
197
+ if (namespaces.length) params.set('namespaces', [...namespaces].sort().join(','))
198
+ return useQuery<KagentWorkspace>({
199
+ queryKey: ['kagent', 'workspace', getApiBase(), cluster?.context, params.toString(), ...feature.gatedKey],
200
+ queryFn: ({ signal }) => feature.guard(() => fetchJSON<KagentWorkspace>(`/kagent/workspace?${params}`, signal)),
201
+ enabled: enabled && feature.support === 'supported',
202
+ staleTime: 10_000,
203
+ refetchInterval: 30_000,
204
+ retry: (count, error) => isStillLoadingError(error) || shouldRetryRadarQuery(count, error),
205
+ retryDelay: (count, error) => isStillLoadingError(error) ? 2000 : Math.min(1000 * 2 ** count, 30_000),
206
+ })
207
+ }
208
+
209
+ export function useKagentSessionSummary(namespaces: string[], enabled = true) {
210
+ const feature = useRadarFeature('kagentWorkspace')
211
+ const { data: cluster } = useClusterInfo()
212
+ const scope = [...namespaces].sort().join(',')
213
+ return useInfiniteQuery({
214
+ queryKey: ['substrate', getApiBase(), cluster?.context, 'kagent-summary', scope, ...feature.gatedKey],
215
+ initialPageParam: 0,
216
+ queryFn: ({ signal, pageParam }) =>
217
+ feature.guard(() =>
218
+ fetchJSON<KagentSessionSummary>(
219
+ `/substrate/kagent/summary?${new URLSearchParams({ namespaces: scope, offset: String(pageParam), limit: '1000' })}`,
220
+ signal,
221
+ ),
222
+ ),
223
+ getNextPageParam: (last) =>
224
+ last.offset + last.rows.length < last.total && last.rows.length > 0 ? last.offset + last.rows.length : undefined,
225
+ enabled: enabled && feature.support === 'supported',
226
+ staleTime: 5_000,
227
+ refetchInterval: 15_000,
228
+ retry: false,
229
+ })
230
+ }