|
1 | 1 | import { APIOptions } from '~/shared/api/types'; |
2 | 2 | import { handleRestFailures } from '~/shared/api/errorUtils'; |
3 | | -import { isModelRegistryResponse, restGET } from '~/shared/api/apiUtils'; |
| 3 | +import { |
| 4 | + assembleModelRegistryBody, |
| 5 | + isModelRegistryResponse, |
| 6 | + restCREATE, |
| 7 | + restDELETE, |
| 8 | + restGET, |
| 9 | + restPATCH, |
| 10 | +} from '~/shared/api/apiUtils'; |
4 | 11 | import { ModelRegistry } from '~/app/types'; |
5 | 12 | import { BFF_API_VERSION } from '~/app/const'; |
6 | 13 | import { URL_PREFIX } from '~/shared/utilities/const'; |
7 | 14 | import { Namespace, UserSettings } from '~/shared/types'; |
| 15 | +import { ModelRegistryKind } from '~/shared/k8sTypes'; |
8 | 16 |
|
9 | 17 | export const getListModelRegistries = |
10 | 18 | (hostPath: string, queryParams: Record<string, unknown> = {}) => |
@@ -41,3 +49,99 @@ export const getNamespaces = |
41 | 49 | } |
42 | 50 | throw new Error('Invalid response format'); |
43 | 51 | }); |
| 52 | + |
| 53 | +export const getModelRegistrySettings = |
| 54 | + (hostPath: string, queryParams: Record<string, unknown> = {}) => |
| 55 | + (opts: APIOptions, modelRegistryId: string): Promise<ModelRegistryKind> => |
| 56 | + handleRestFailures( |
| 57 | + restGET( |
| 58 | + hostPath, |
| 59 | + `${URL_PREFIX}/api/${BFF_API_VERSION}/settings/model_registry/${modelRegistryId}`, |
| 60 | + queryParams, |
| 61 | + opts, |
| 62 | + ), |
| 63 | + ).then((response) => { |
| 64 | + if (isModelRegistryResponse<ModelRegistryKind>(response)) { |
| 65 | + return response.data; |
| 66 | + } |
| 67 | + throw new Error('Invalid response format'); |
| 68 | + }); |
| 69 | + |
| 70 | +export const listModelRegistrySettings = |
| 71 | + (hostPath: string, queryParams: Record<string, unknown> = {}) => |
| 72 | + (opts: APIOptions): Promise<ModelRegistryKind[]> => |
| 73 | + handleRestFailures( |
| 74 | + restGET( |
| 75 | + hostPath, |
| 76 | + `${URL_PREFIX}/api/${BFF_API_VERSION}/settings/model_registry`, |
| 77 | + queryParams, |
| 78 | + opts, |
| 79 | + ), |
| 80 | + ).then((response) => { |
| 81 | + if (isModelRegistryResponse<ModelRegistryKind[]>(response)) { |
| 82 | + return response.data; |
| 83 | + } |
| 84 | + throw new Error('Invalid response format'); |
| 85 | + }); |
| 86 | + |
| 87 | +export const createModelRegistrySettings = |
| 88 | + (hostPath: string, queryParams: Record<string, unknown> = {}) => |
| 89 | + (opts: APIOptions, data: ModelRegistryKind): Promise<ModelRegistryKind[]> => |
| 90 | + handleRestFailures( |
| 91 | + restCREATE( |
| 92 | + hostPath, |
| 93 | + `${URL_PREFIX}/api/${BFF_API_VERSION}/settings/model_registry`, |
| 94 | + assembleModelRegistryBody(data), |
| 95 | + queryParams, |
| 96 | + opts, |
| 97 | + ), |
| 98 | + ).then((response) => { |
| 99 | + if (isModelRegistryResponse<ModelRegistryKind[]>(response)) { |
| 100 | + return response.data; |
| 101 | + } |
| 102 | + throw new Error('Invalid response format'); |
| 103 | + }); |
| 104 | + |
| 105 | +export const deleteModelRegistrySettings = |
| 106 | + (hostPath: string, queryParams: Record<string, unknown> = {}) => |
| 107 | + ( |
| 108 | + opts: APIOptions, |
| 109 | + data: ModelRegistryKind, |
| 110 | + modelRegistryId: string, |
| 111 | + ): Promise<ModelRegistryKind[]> => |
| 112 | + handleRestFailures( |
| 113 | + restDELETE( |
| 114 | + hostPath, |
| 115 | + `${URL_PREFIX}/api/${BFF_API_VERSION}/settings/model_registry/${modelRegistryId}`, |
| 116 | + assembleModelRegistryBody(data), |
| 117 | + queryParams, |
| 118 | + opts, |
| 119 | + ), |
| 120 | + ).then((response) => { |
| 121 | + if (isModelRegistryResponse<ModelRegistryKind[]>(response)) { |
| 122 | + return response.data; |
| 123 | + } |
| 124 | + throw new Error('Invalid response format'); |
| 125 | + }); |
| 126 | + |
| 127 | +export const patchModelRegistrySettings = |
| 128 | + (hostPath: string, queryParams: Record<string, unknown> = {}) => |
| 129 | + ( |
| 130 | + opts: APIOptions, |
| 131 | + data: ModelRegistryKind, |
| 132 | + modelRegistryId: string, |
| 133 | + ): Promise<ModelRegistryKind[]> => |
| 134 | + handleRestFailures( |
| 135 | + restPATCH( |
| 136 | + hostPath, |
| 137 | + `${URL_PREFIX}/api/${BFF_API_VERSION}/settings/model_registry/${modelRegistryId}`, |
| 138 | + assembleModelRegistryBody(data), |
| 139 | + queryParams, |
| 140 | + opts, |
| 141 | + ), |
| 142 | + ).then((response) => { |
| 143 | + if (isModelRegistryResponse<ModelRegistryKind[]>(response)) { |
| 144 | + return response.data; |
| 145 | + } |
| 146 | + throw new Error('Invalid response format'); |
| 147 | + }); |
0 commit comments