(model: ModelOption)
| 32 | const { closeCurrentScreen } = useNavigation(); |
| 33 | |
| 34 | const handleModelSelect = async (model: ModelOption) => { |
| 35 | closeCurrentScreen(); |
| 36 | |
| 37 | try { |
| 38 | await services.model.switchModel(model.index); |
| 39 | const modelInfo = services.model.getModelInfo(); |
| 40 | |
| 41 | // Update the service container to trigger re-renders |
| 42 | const currentState = services.model.getState(); |
| 43 | serviceContainer.set<ModelServiceState>( |
| 44 | SERVICE_NAMES.MODEL, |
| 45 | currentState, |
| 46 | ); |
| 47 | |
| 48 | // Persist the model choice using the actual model name |
| 49 | // and update the auth service state to reflect the change |
| 50 | if (modelInfo?.name) { |
| 51 | const updatedAuthConfig = updateModelName(modelInfo.name); |
| 52 | |
| 53 | // Update the AUTH service state in the container with the new config |
| 54 | // This ensures that when MODEL service is reloaded, it gets the updated auth config |
| 55 | const currentAuthState = services.auth.getState(); |
| 56 | serviceContainer.set<AuthServiceState>(SERVICE_NAMES.AUTH, { |
| 57 | ...currentAuthState, |
| 58 | authConfig: updatedAuthConfig, |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | onMessage({ |
| 63 | role: "system", |
| 64 | content: `Switched to model: ${modelInfo?.name}`, |
| 65 | messageType: "system", |
| 66 | }); |
| 67 | |
| 68 | // Trigger any additional actions after model switch |
| 69 | if (onModelSwitch) { |
| 70 | onModelSwitch(); |
| 71 | } |
| 72 | |
| 73 | // Force UI refresh to update the IntroMessage with new model |
| 74 | if (onRefreshUI) { |
| 75 | onRefreshUI(); |
| 76 | } |
| 77 | } catch (error: any) { |
| 78 | onMessage({ |
| 79 | role: "system", |
| 80 | content: `Failed to switch model: ${error.message}`, |
| 81 | messageType: "system", |
| 82 | }); |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | return { |
| 87 | handleModelSelect, |
nothing calls this directly
no test coverage detected