Skip to content

Commit 3cc2428

Browse files
refactor(frontend): extract parseModelString helper in useOpenCode hook
1 parent e959cc4 commit 3cc2428

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

frontend/src/hooks/useOpenCode.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ type SendPromptRequest = NonNullable<
2121
paths["/session/{sessionID}/message"]["post"]["requestBody"]
2222
>["content"]["application/json"];
2323

24+
const parseModelString = (model: string) => {
25+
const [providerID, ...rest] = model.split("/");
26+
const modelID = rest.join("/");
27+
if (!providerID || !modelID) return undefined;
28+
return { providerID, modelID };
29+
};
30+
2431
export const useOpenCodeClient = (opcodeUrl: string | null | undefined, directory?: string) => {
2532
return useMemo(
2633
() => (opcodeUrl ? new OpenCodeClient(opcodeUrl, directory) : null),
@@ -205,11 +212,11 @@ const createOptimisticUserMessageInfo = (
205212
} as Message;
206213

207214
if (model) {
208-
const [providerID, modelID] = model.split("/");
209-
if (providerID && modelID) {
215+
const parsedModel = parseModelString(model);
216+
if (parsedModel) {
210217
return {
211218
...message,
212-
model: { providerID, modelID },
219+
model: parsedModel,
213220
agent,
214221
variant,
215222
} as Message;
@@ -295,11 +302,11 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
295302
};
296303

297304
if (model) {
298-
const [providerID, modelID] = model.split("/");
299-
if (providerID && modelID) {
305+
const parsedModel = parseModelString(model);
306+
if (parsedModel) {
300307
requestData.model = {
301-
providerID,
302-
modelID,
308+
providerID: parsedModel.providerID,
309+
modelID: parsedModel.modelID,
303310
};
304311
}
305312
}

0 commit comments

Comments
 (0)