mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 17:14:28 +00:00
Fix some typescript issues
This commit is contained in:
@@ -12,13 +12,13 @@ interface BackendFormFieldProps {
|
|||||||
|
|
||||||
const BackendFormField: React.FC<BackendFormFieldProps> = ({ fieldKey, value, onChange }) => {
|
const BackendFormField: React.FC<BackendFormFieldProps> = ({ fieldKey, value, onChange }) => {
|
||||||
// Get configuration for basic fields, or use field name for advanced fields
|
// Get configuration for basic fields, or use field name for advanced fields
|
||||||
const config = basicBackendFieldsConfig[fieldKey as string] || { label: fieldKey }
|
const config = basicBackendFieldsConfig[fieldKey] || { label: fieldKey }
|
||||||
|
|
||||||
// Get type from Zod schema
|
// Get type from Zod schema
|
||||||
const fieldType = getBackendFieldType(fieldKey)
|
const fieldType = getBackendFieldType(fieldKey)
|
||||||
|
|
||||||
const handleChange = (newValue: string | number | boolean | string[] | undefined) => {
|
const handleChange = (newValue: string | number | boolean | string[] | undefined) => {
|
||||||
onChange(fieldKey as string, newValue)
|
onChange(fieldKey, newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderField = () => {
|
const renderField = () => {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { BackendType, type CreateInstanceOptions, type Instance } from "@/types/instance";
|
import { BackendType, type CreateInstanceOptions, type Instance } from "@/types/instance";
|
||||||
|
import type { BackendOptions } from "@/schemas/instanceOptions";
|
||||||
import ParseCommandDialog from "@/components/ParseCommandDialog";
|
import ParseCommandDialog from "@/components/ParseCommandDialog";
|
||||||
import InstanceSettingsCard from "@/components/instance/InstanceSettingsCard";
|
import InstanceSettingsCard from "@/components/instance/InstanceSettingsCard";
|
||||||
import BackendConfigurationCard from "@/components/instance/BackendConfigurationCard";
|
import BackendConfigurationCard from "@/components/instance/BackendConfigurationCard";
|
||||||
@@ -56,13 +57,13 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
}
|
}
|
||||||
}, [open, instance]);
|
}, [open, instance]);
|
||||||
|
|
||||||
const handleFieldChange = (key: keyof CreateInstanceOptions, value: any) => {
|
const handleFieldChange = (key: keyof CreateInstanceOptions, value: unknown) => {
|
||||||
setFormData((prev) => {
|
setFormData((prev) => {
|
||||||
// If backend_type is changing, clear backend_options
|
// If backend_type is changing, clear backend_options
|
||||||
if (key === 'backend_type' && prev.backend_type !== value) {
|
if (key === 'backend_type' && prev.backend_type !== value) {
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
[key]: value,
|
backend_type: value as CreateInstanceOptions['backend_type'],
|
||||||
backend_options: {}, // Clear backend options when backend type changes
|
backend_options: {}, // Clear backend options when backend type changes
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -70,17 +71,17 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
};
|
} as CreateInstanceOptions;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBackendFieldChange = (key: string, value: any) => {
|
const handleBackendFieldChange = (key: string, value: unknown) => {
|
||||||
setFormData((prev) => ({
|
setFormData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
backend_options: {
|
backend_options: {
|
||||||
...prev.backend_options,
|
...prev.backend_options,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
} as any,
|
} as BackendOptions,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,11 +107,13 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean up undefined values to avoid sending empty fields
|
// Clean up undefined values to avoid sending empty fields
|
||||||
const cleanOptions: CreateInstanceOptions = {};
|
const cleanOptions: CreateInstanceOptions = {} as CreateInstanceOptions;
|
||||||
Object.entries(formData).forEach(([key, value]) => {
|
Object.entries(formData).forEach(([key, value]) => {
|
||||||
|
const typedKey = key as keyof CreateInstanceOptions;
|
||||||
|
|
||||||
if (key === 'backend_options' && value && typeof value === 'object' && !Array.isArray(value)) {
|
if (key === 'backend_options' && value && typeof value === 'object' && !Array.isArray(value)) {
|
||||||
// Handle backend_options specially - clean nested object
|
// Handle backend_options specially - clean nested object
|
||||||
const cleanBackendOptions: any = {};
|
const cleanBackendOptions: Record<string, unknown> = {};
|
||||||
Object.entries(value).forEach(([backendKey, backendValue]) => {
|
Object.entries(value).forEach(([backendKey, backendValue]) => {
|
||||||
if (backendValue !== undefined && backendValue !== null && (typeof backendValue !== 'string' || backendValue.trim() !== "")) {
|
if (backendValue !== undefined && backendValue !== null && (typeof backendValue !== 'string' || backendValue.trim() !== "")) {
|
||||||
// Handle arrays - don't include empty arrays
|
// Handle arrays - don't include empty arrays
|
||||||
@@ -123,7 +126,7 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
|
|
||||||
// Only include backend_options if it has content
|
// Only include backend_options if it has content
|
||||||
if (Object.keys(cleanBackendOptions).length > 0) {
|
if (Object.keys(cleanBackendOptions).length > 0) {
|
||||||
(cleanOptions as any)[key] = cleanBackendOptions;
|
(cleanOptions as Record<string, unknown>)[typedKey] = cleanBackendOptions as BackendOptions;
|
||||||
}
|
}
|
||||||
} else if (value !== undefined && value !== null) {
|
} else if (value !== undefined && value !== null) {
|
||||||
// Skip empty strings
|
// Skip empty strings
|
||||||
@@ -134,7 +137,7 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
if (Array.isArray(value) && value.length === 0) {
|
if (Array.isArray(value) && value.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(cleanOptions as any)[key] = value;
|
(cleanOptions as Record<string, unknown>)[typedKey] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -167,7 +170,7 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
try {
|
try {
|
||||||
const content = e.target?.result as string;
|
const content = e.target?.result as string;
|
||||||
const importedData = JSON.parse(content);
|
const importedData = JSON.parse(content) as { name?: string; options?: CreateInstanceOptions };
|
||||||
|
|
||||||
// Validate that it's an instance export
|
// Validate that it's an instance export
|
||||||
if (!importedData.name || !importedData.options) {
|
if (!importedData.name || !importedData.options) {
|
||||||
@@ -176,7 +179,7 @@ const InstanceDialog: React.FC<InstanceDialogProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the instance name (only for new instances, not editing)
|
// Set the instance name (only for new instances, not editing)
|
||||||
if (!isEditing) {
|
if (!isEditing && typeof importedData.name === 'string') {
|
||||||
handleNameChange(importedData.name);
|
handleNameChange(importedData.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ function InstanceList({ editInstance }: InstanceListProps) {
|
|||||||
<MemoizedInstanceCard
|
<MemoizedInstanceCard
|
||||||
key={instance.name}
|
key={instance.name}
|
||||||
instance={instance}
|
instance={instance}
|
||||||
startInstance={startInstance}
|
startInstance={() => { void startInstance(instance.name) }}
|
||||||
stopInstance={stopInstance}
|
stopInstance={() => { void stopInstance(instance.name) }}
|
||||||
deleteInstance={deleteInstance}
|
deleteInstance={() => { void deleteInstance(instance.name) }}
|
||||||
editInstance={editInstance}
|
editInstance={editInstance}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const ParseCommandDialog: React.FC<ParseCommandDialogProps> = ({
|
|||||||
options = await backendsApi.vllm.parseCommand(command);
|
options = await backendsApi.vllm.parseCommand(command);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported backend type: ${backendType}`);
|
throw new Error(`Unsupported backend type: ${String(backendType)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
onParsed(options);
|
onParsed(options);
|
||||||
|
|||||||
Reference in New Issue
Block a user