feat: dynamic backends

This commit is contained in:
jialin
2025-10-13 14:40:26 +08:00
parent ee95fabc47
commit bca1e8140e
19 changed files with 325 additions and 177 deletions
+22 -3
View File
@@ -1,15 +1,16 @@
import { PageActionType } from '@/config/types';
import React from 'react';
import { DeployFormKey } from './types';
import { BackendOption, DeployFormKey } from './types';
interface FormContextProps {
isGGUF?: boolean;
formKey: DeployFormKey;
source?: string;
source: string;
pageAction: PageActionType;
gpuOptions?: any[];
backendOptions: BackendOption[];
onValuesChange?: (changedValues: any, allValues: any) => void;
onBackendChange?: (backend: string) => void;
onBackendChange: (backend: string) => void;
}
interface CatalogFormContextProps {
@@ -19,6 +20,10 @@ interface CatalogFormContextProps {
onQuantizationChange: (val: string) => void;
}
interface FormOuterContextProps {
sourceList?: Global.BaseOption<string>[];
}
export const FormContext = React.createContext<FormContextProps>(
{} as FormContextProps
);
@@ -27,6 +32,10 @@ export const CatalogFormContext = React.createContext<CatalogFormContextProps>(
{} as CatalogFormContextProps
);
export const FormOuterContext = React.createContext<FormOuterContextProps>(
{} as FormOuterContextProps
);
export const useFormContext = () => {
const context = React.useContext(FormContext);
if (!context) {
@@ -44,3 +53,13 @@ export const useCatalogFormContext = () => {
}
return context;
};
export const useFormOuterContext = () => {
const context = React.useContext(FormOuterContext);
if (!context) {
throw new Error(
'useFormOuterContext must be used within a FormOuterProvider'
);
}
return context;
};