mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
refactor(frontend): extract parseModelString helper in useOpenCode hook
This commit is contained in:
1 parent
e959cc409f
commit
3cc24288a6
1 file changed
+14
-7
@@ -21,6 +21,13 @@ type SendPromptRequest = NonNullable<
|
||||
paths["/session/{sessionID}/message"]["post"]["requestBody"]
|
||||
>["content"]["application/json"];
|
||||
|
||||
const parseModelString = (model: string) => {
|
||||
const [providerID, ...rest] = model.split("/");
|
||||
const modelID = rest.join("/");
|
||||
if (!providerID || !modelID) return undefined;
|
||||
return { providerID, modelID };
|
||||
};
|
||||
|
||||
export const useOpenCodeClient = (opcodeUrl: string | null | undefined, directory?: string) => {
|
||||
return useMemo(
|
||||
() => (opcodeUrl ? new OpenCodeClient(opcodeUrl, directory) : null),
|
||||
@@ -205,11 +212,11 @@ const createOptimisticUserMessageInfo = (
|
||||
} as Message;
|
||||
|
||||
if (model) {
|
||||
const [providerID, modelID] = model.split("/");
|
||||
if (providerID && modelID) {
|
||||
const parsedModel = parseModelString(model);
|
||||
if (parsedModel) {
|
||||
return {
|
||||
...message,
|
||||
model: { providerID, modelID },
|
||||
model: parsedModel,
|
||||
agent,
|
||||
variant,
|
||||
} as Message;
|
||||
@@ -295,11 +302,11 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
|
||||
};
|
||||
|
||||
if (model) {
|
||||
const [providerID, modelID] = model.split("/");
|
||||
if (providerID && modelID) {
|
||||
const parsedModel = parseModelString(model);
|
||||
if (parsedModel) {
|
||||
requestData.model = {
|
||||
providerID,
|
||||
modelID,
|
||||
providerID: parsedModel.providerID,
|
||||
modelID: parsedModel.modelID,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user