Add node selection functionality to InstanceSettingsCard and define Node API

This commit is contained in:
2025-10-02 23:18:33 +02:00
parent 670f8ff81b
commit a491f29483
3 changed files with 69 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState, useEffect } from 'react'
import type { CreateInstanceOptions } from '@/types/instance'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Label } from '@/components/ui/label'
@@ -7,6 +7,8 @@ import AutoRestartConfiguration from '@/components/instance/AutoRestartConfigura
import NumberInput from '@/components/form/NumberInput'
import CheckboxInput from '@/components/form/CheckboxInput'
import EnvironmentVariablesInput from '@/components/form/EnvironmentVariablesInput'
import SelectInput from '@/components/form/SelectInput'
import { nodesApi, type NodeResponse } from '@/lib/api'
interface InstanceSettingsCardProps {
instanceName: string
@@ -25,6 +27,42 @@ const InstanceSettingsCard: React.FC<InstanceSettingsCardProps> = ({
onNameChange,
onChange
}) => {
const [nodes, setNodes] = useState<NodeResponse[]>([])
const [loadingNodes, setLoadingNodes] = useState(true)
useEffect(() => {
const fetchNodes = async () => {
try {
const fetchedNodes = await nodesApi.list()
setNodes(fetchedNodes)
} catch (error) {
console.error('Failed to fetch nodes:', error)
} finally {
setLoadingNodes(false)
}
}
fetchNodes()
}, [])
const nodeOptions = [
{ value: '', label: 'Default (Main Node)' },
...nodes.map(node => ({
value: node.name,
label: node.name
}))
]
const handleNodeChange = (value: string | undefined) => {
if (value) {
onChange('nodes', [value])
} else {
onChange('nodes', undefined)
}
}
const selectedNode = formData.nodes && formData.nodes.length > 0 ? formData.nodes[0] : ''
return (
<Card>
<CardHeader>
@@ -50,6 +88,18 @@ const InstanceSettingsCard: React.FC<InstanceSettingsCardProps> = ({
</p>
</div>
{/* Node Selection */}
{!loadingNodes && nodes.length > 0 && (
<SelectInput
id="node"
label="Node"
value={selectedNode}
onChange={handleNodeChange}
options={nodeOptions}
description="Select the node where the instance will run (default: main node)"
/>
)}
{/* Auto Restart Configuration */}
<AutoRestartConfiguration
formData={formData}

View File

@@ -106,6 +106,21 @@ export const backendsApi = {
},
};
// Node API types
export interface NodeResponse {
name: string;
address: string;
}
// Node API functions
export const nodesApi = {
// GET /nodes
list: () => apiCall<NodeResponse[]>("/nodes"),
// GET /nodes/{name}
get: (name: string) => apiCall<NodeResponse>(`/nodes/${name}`),
};
// Instance API functions
export const instancesApi = {
// GET /instances

View File

@@ -39,6 +39,9 @@ export const CreateInstanceOptionsSchema = z.object({
// Backend configuration
backend_type: z.enum([BackendType.LLAMA_CPP, BackendType.MLX_LM, BackendType.VLLM]).optional(),
backend_options: BackendOptionsSchema.optional(),
// Node configuration
nodes: z.array(z.string()).optional(),
})
// Re-export types and schemas from backend files