mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
regenerate OpenAPI spec and add model selection components
This commit is contained in:
1 parent
9ed292af2a
commit
17ee96d316
12 files changed
+10266
-3453
No files matched your search
@@ -252,12 +252,14 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
|
||||
parts,
|
||||
model,
|
||||
agent,
|
||||
variant,
|
||||
}: {
|
||||
sessionID: string;
|
||||
prompt?: string;
|
||||
parts?: ContentPart[];
|
||||
model?: string;
|
||||
agent?: string;
|
||||
variant?: string;
|
||||
}) => {
|
||||
if (!client) throw new Error("No client available");
|
||||
|
||||
@@ -312,6 +314,10 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
|
||||
requestData.agent = agent;
|
||||
}
|
||||
|
||||
if (variant) {
|
||||
requestData.variant = variant;
|
||||
}
|
||||
|
||||
const response = await client.sendPrompt(sessionID, requestData);
|
||||
|
||||
return { optimisticUserID, response, userPromptText };
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { useMemo } from 'react'
|
||||
import { useModelSelection } from './useModelSelection'
|
||||
import { useModelStore } from '@/stores/modelStore'
|
||||
import { useOpenCodeClient } from './useOpenCode'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
export interface UseVariantsResult {
|
||||
availableVariants: string[]
|
||||
currentVariant: string | undefined
|
||||
setVariant: (variant: string | undefined) => void
|
||||
cycleVariant: () => void
|
||||
clearVariant: () => void
|
||||
hasVariants: boolean
|
||||
}
|
||||
|
||||
export function useVariants(
|
||||
opcodeUrl: string | null | undefined,
|
||||
directory?: string
|
||||
): UseVariantsResult {
|
||||
const { model } = useModelSelection(opcodeUrl, directory)
|
||||
const { setVariant: setStoreVariant, clearVariant: clearStoreVariant } = useModelStore()
|
||||
const client = useOpenCodeClient(opcodeUrl, directory)
|
||||
|
||||
const { data: providersData, isLoading } = useQuery({
|
||||
queryKey: ['opencode', 'providers', opcodeUrl, directory],
|
||||
queryFn: () => client!.getProviders(),
|
||||
enabled: !!client && !!model,
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const currentModel = useMemo(() => {
|
||||
if (!model || isLoading || !providersData?.all) return null
|
||||
for (const provider of providersData.all) {
|
||||
if (provider.id === model.providerID && provider.models) {
|
||||
const modelData = provider.models[model.modelID]
|
||||
if (modelData) {
|
||||
return modelData
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}, [model, providersData, isLoading])
|
||||
|
||||
const availableVariants = useMemo(() => {
|
||||
if (!currentModel?.variants) return []
|
||||
return Object.keys(currentModel.variants)
|
||||
}, [currentModel])
|
||||
|
||||
const currentVariant = useModelStore((state) =>
|
||||
model ? state.variants[`${model.providerID}/${model.modelID}`] : undefined
|
||||
)
|
||||
|
||||
const setVariant = useMemo(
|
||||
() => (variant: string | undefined) => {
|
||||
if (!model) return
|
||||
setStoreVariant(model, variant)
|
||||
},
|
||||
[model, setStoreVariant],
|
||||
)
|
||||
|
||||
const cycleVariant = useMemo(() => {
|
||||
return () => {
|
||||
if (!model || availableVariants.length === 0) return
|
||||
|
||||
if (!currentVariant) {
|
||||
setStoreVariant(model, availableVariants[0])
|
||||
} else {
|
||||
const currentIndex = availableVariants.indexOf(currentVariant)
|
||||
if (currentIndex === availableVariants.length - 1) {
|
||||
clearStoreVariant(model)
|
||||
} else {
|
||||
setStoreVariant(model, availableVariants[currentIndex + 1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [model, availableVariants, currentVariant, setStoreVariant, clearStoreVariant])
|
||||
|
||||
const clearVariant = useMemo(
|
||||
() => () => {
|
||||
if (!model) return
|
||||
clearStoreVariant(model)
|
||||
},
|
||||
[model, clearStoreVariant],
|
||||
)
|
||||
|
||||
return {
|
||||
availableVariants,
|
||||
currentVariant,
|
||||
setVariant,
|
||||
cycleVariant,
|
||||
clearVariant,
|
||||
hasVariants: availableVariants.length > 0,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user