Skip to content

Commit

Permalink
feat: renterd autopilot config evaluation api
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 18, 2024
1 parent 7416ee6 commit 642e79a
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-lemons-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/renterd-js': patch
---

Fixed a typo in the naming of the config method.
7 changes: 7 additions & 0 deletions .changeset/nine-crabs-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added support for autopilot config evaluation.
10 changes: 9 additions & 1 deletion libs/renterd-js/src/autopilot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse,
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse,
Expand Down Expand Up @@ -36,7 +39,7 @@ export function Autopilot({
AutopilotStatePayload,
AutopilotStateResponse
>(axios, 'get', autopilotStateRoute),
confg: buildRequestHandler<
config: buildRequestHandler<
AutopilotConfigParams,
AutopilotConfigPayload,
AutopilotConfigResponse
Expand All @@ -46,6 +49,11 @@ export function Autopilot({
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse
>(axios, 'put', autopilotConfigRoute),
configEvaluate: buildRequestHandler<
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse
>(axios, 'post', autopilotConfigRoute),
hostsSearch: buildRequestHandler<
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
Expand Down
2 changes: 1 addition & 1 deletion libs/renterd-js/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export function Bus({ api, password }: { api: string; password?: string }) {
setting: buildRequestHandler<
SettingParams,
SettingPayload,
SettingResponse<Setting>
SettingResponse
>(axios, 'get', busSettingKeyRoute),
settingUpdate: buildRequestHandler<
SettingUpdateParams,
Expand Down
13 changes: 13 additions & 0 deletions libs/renterd-react/src/autopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
AutopilotConfigUpdateParams,
AutopilotConfigUpdatePayload,
AutopilotConfigUpdateResponse,
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse,
AutopilotHostsSearchParams,
AutopilotHostsSearchPayload,
AutopilotHostsSearchResponse,
Expand Down Expand Up @@ -68,6 +71,16 @@ export function useAutopilotConfigUpdate(
)
}

export function useAutopilotConfigEvaluate(
args?: HookArgsCallback<
AutopilotConfigEvaluateParams,
AutopilotConfigEvaluatePayload,
AutopilotConfigEvaluateResponse
>
) {
return usePostFunc({ ...args, route: autopilotConfigRoute })
}

export function useAutopilotHostsSearch(
args?: HookArgsWithPayloadSwr<
AutopilotHostsSearchParams,
Expand Down
35 changes: 34 additions & 1 deletion libs/renterd-types/src/autopilot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { AutopilotConfig, Host } from './types'
import {
AutopilotConfig,
GougingSettings,
Host,
RedundancySettings,
} from './types'
import { HostsSearchPayload, BusStateResponse } from './bus'

export const autopilotStateRoute = '/autopilot/state'
Expand Down Expand Up @@ -30,6 +35,34 @@ export type AutopilotConfigUpdateParams = void
export type AutopilotConfigUpdatePayload = AutopilotConfig
export type AutopilotConfigUpdateResponse = void

export type ConfigRecommendation = {
gougingSettings: GougingSettings
}

export type AutopilotConfigEvaluateParams = void
export type AutopilotConfigEvaluatePayload = {
autopilotConfig: AutopilotConfig
gougingSettings: GougingSettings
redundancySettings: RedundancySettings
}
export type AutopilotConfigEvaluateResponse = {
hosts: number
usable: number
unusable: {
blocked: number
gouging: {
contract: number
download: number
gouging: number
pruning: number
upload: number
}
notAcceptingContracts: number
notScanned: number
}
recommendation?: ConfigRecommendation
}

export type AutopilotHost = {
host: Host
checks?: {
Expand Down
2 changes: 1 addition & 1 deletion libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export type SettingsResponse = string[]

export type SettingParams = { key: string }
export type SettingPayload = void
export type SettingResponse<T extends Setting> = T
export type SettingResponse = Setting

export type SettingUpdateParams = { key: string }
export type SettingUpdatePayload = Setting
Expand Down

0 comments on commit 642e79a

Please sign in to comment.