mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 17:14:28 +00:00
Add node selection functionality to InstanceSettingsCard and define Node API
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import type { CreateInstanceOptions } from '@/types/instance'
|
import type { CreateInstanceOptions } from '@/types/instance'
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
@@ -7,6 +7,8 @@ import AutoRestartConfiguration from '@/components/instance/AutoRestartConfigura
|
|||||||
import NumberInput from '@/components/form/NumberInput'
|
import NumberInput from '@/components/form/NumberInput'
|
||||||
import CheckboxInput from '@/components/form/CheckboxInput'
|
import CheckboxInput from '@/components/form/CheckboxInput'
|
||||||
import EnvironmentVariablesInput from '@/components/form/EnvironmentVariablesInput'
|
import EnvironmentVariablesInput from '@/components/form/EnvironmentVariablesInput'
|
||||||
|
import SelectInput from '@/components/form/SelectInput'
|
||||||
|
import { nodesApi, type NodeResponse } from '@/lib/api'
|
||||||
|
|
||||||
interface InstanceSettingsCardProps {
|
interface InstanceSettingsCardProps {
|
||||||
instanceName: string
|
instanceName: string
|
||||||
@@ -25,6 +27,42 @@ const InstanceSettingsCard: React.FC<InstanceSettingsCardProps> = ({
|
|||||||
onNameChange,
|
onNameChange,
|
||||||
onChange
|
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 (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -50,6 +88,18 @@ const InstanceSettingsCard: React.FC<InstanceSettingsCardProps> = ({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</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 */}
|
{/* Auto Restart Configuration */}
|
||||||
<AutoRestartConfiguration
|
<AutoRestartConfiguration
|
||||||
formData={formData}
|
formData={formData}
|
||||||
|
|||||||
@@ -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
|
// Instance API functions
|
||||||
export const instancesApi = {
|
export const instancesApi = {
|
||||||
// GET /instances
|
// GET /instances
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ export const CreateInstanceOptionsSchema = z.object({
|
|||||||
// Backend configuration
|
// Backend configuration
|
||||||
backend_type: z.enum([BackendType.LLAMA_CPP, BackendType.MLX_LM, BackendType.VLLM]).optional(),
|
backend_type: z.enum([BackendType.LLAMA_CPP, BackendType.MLX_LM, BackendType.VLLM]).optional(),
|
||||||
backend_options: BackendOptionsSchema.optional(),
|
backend_options: BackendOptionsSchema.optional(),
|
||||||
|
|
||||||
|
// Node configuration
|
||||||
|
nodes: z.array(z.string()).optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Re-export types and schemas from backend files
|
// Re-export types and schemas from backend files
|
||||||
|
|||||||
Reference in New Issue
Block a user