Skip to content

Commit 4e9b13e

Browse files
committed
feat: renterd autopilot config evaluation api
1 parent 7416ee6 commit 4e9b13e

File tree

9 files changed

+77
-6
lines changed

9 files changed

+77
-6
lines changed

.changeset/famous-lemons-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@siafoundation/renterd-js': patch
3+
---
4+
5+
Fixed a typo in the naming of the config method.

.changeset/new-bananas-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@siafoundation/request': minor
3+
---
4+
5+
Updated axios imports.

.changeset/nine-crabs-try.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@siafoundation/renterd-js': minor
3+
'@siafoundation/renterd-react': minor
4+
'@siafoundation/renterd-types': minor
5+
---
6+
7+
Added support for autopilot config evaluation.

libs/renterd-js/src/autopilot.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {
2+
AutopilotConfigEvaluateParams,
3+
AutopilotConfigEvaluatePayload,
4+
AutopilotConfigEvaluateResponse,
25
AutopilotConfigParams,
36
AutopilotConfigPayload,
47
AutopilotConfigResponse,
@@ -36,7 +39,7 @@ export function Autopilot({
3639
AutopilotStatePayload,
3740
AutopilotStateResponse
3841
>(axios, 'get', autopilotStateRoute),
39-
confg: buildRequestHandler<
42+
config: buildRequestHandler<
4043
AutopilotConfigParams,
4144
AutopilotConfigPayload,
4245
AutopilotConfigResponse
@@ -46,6 +49,11 @@ export function Autopilot({
4649
AutopilotConfigUpdatePayload,
4750
AutopilotConfigUpdateResponse
4851
>(axios, 'put', autopilotConfigRoute),
52+
configEvaluate: buildRequestHandler<
53+
AutopilotConfigEvaluateParams,
54+
AutopilotConfigEvaluatePayload,
55+
AutopilotConfigEvaluateResponse
56+
>(axios, 'post', autopilotConfigRoute),
4957
hostsSearch: buildRequestHandler<
5058
AutopilotHostsSearchParams,
5159
AutopilotHostsSearchPayload,

libs/renterd-js/src/bus.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ import {
137137
ObjectsStatsParams,
138138
ObjectsStatsPayload,
139139
ObjectsStatsResponse,
140-
Setting,
141140
SettingParams,
142141
SettingPayload,
143142
SettingResponse,
@@ -537,7 +536,7 @@ export function Bus({ api, password }: { api: string; password?: string }) {
537536
setting: buildRequestHandler<
538537
SettingParams,
539538
SettingPayload,
540-
SettingResponse<Setting>
539+
SettingResponse
541540
>(axios, 'get', busSettingKeyRoute),
542541
settingUpdate: buildRequestHandler<
543542
SettingUpdateParams,

libs/renterd-react/src/autopilot.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
AutopilotConfigUpdateParams,
1515
AutopilotConfigUpdatePayload,
1616
AutopilotConfigUpdateResponse,
17+
AutopilotConfigEvaluateParams,
18+
AutopilotConfigEvaluatePayload,
19+
AutopilotConfigEvaluateResponse,
1720
AutopilotHostsSearchParams,
1821
AutopilotHostsSearchPayload,
1922
AutopilotHostsSearchResponse,
@@ -68,6 +71,16 @@ export function useAutopilotConfigUpdate(
6871
)
6972
}
7073

74+
export function useAutopilotConfigEvaluate(
75+
args?: HookArgsCallback<
76+
AutopilotConfigEvaluateParams,
77+
AutopilotConfigEvaluatePayload,
78+
AutopilotConfigEvaluateResponse
79+
>
80+
) {
81+
return usePostFunc({ ...args, route: autopilotConfigRoute })
82+
}
83+
7184
export function useAutopilotHostsSearch(
7285
args?: HookArgsWithPayloadSwr<
7386
AutopilotHostsSearchParams,

libs/renterd-types/src/autopilot.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { AutopilotConfig, Host } from './types'
1+
import {
2+
AutopilotConfig,
3+
GougingSettings,
4+
Host,
5+
RedundancySettings,
6+
} from './types'
27
import { HostsSearchPayload, BusStateResponse } from './bus'
38

49
export const autopilotStateRoute = '/autopilot/state'
@@ -30,6 +35,34 @@ export type AutopilotConfigUpdateParams = void
3035
export type AutopilotConfigUpdatePayload = AutopilotConfig
3136
export type AutopilotConfigUpdateResponse = void
3237

38+
export type ConfigRecommendation = {
39+
gougingSettings: GougingSettings
40+
}
41+
42+
export type AutopilotConfigEvaluateParams = void
43+
export type AutopilotConfigEvaluatePayload = {
44+
autopilotConfig: AutopilotConfig
45+
gougingSettings: GougingSettings
46+
redundancySettings: RedundancySettings
47+
}
48+
export type AutopilotConfigEvaluateResponse = {
49+
hosts: number
50+
usable: number
51+
unusable: {
52+
blocked: number
53+
gouging: {
54+
contract: number
55+
download: number
56+
gouging: number
57+
pruning: number
58+
upload: number
59+
}
60+
notAcceptingContracts: number
61+
notScanned: number
62+
}
63+
recommendation?: ConfigRecommendation
64+
}
65+
3366
export type AutopilotHost = {
3467
host: Host
3568
checks?: {

libs/renterd-types/src/bus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ export type SettingsResponse = string[]
487487

488488
export type SettingParams = { key: string }
489489
export type SettingPayload = void
490-
export type SettingResponse<T extends Setting> = T
490+
export type SettingResponse = Setting
491491

492492
export type SettingUpdateParams = { key: string }
493493
export type SettingUpdatePayload = Setting

libs/request/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { merge } from '@technically/lodash'
2-
import axios, {
2+
import axios from 'axios'
3+
import type {
34
AxiosError,
45
AxiosInstance,
56
AxiosRequestConfig,

0 commit comments

Comments
 (0)