1- import { useAtomValue } from "@effect/atom-react" ;
1+ import { useAtomRefresh , useAtomValue } from "@effect/atom-react" ;
22import type { MenuAction } from "@react-native-menu/menu" ;
33import {
44 isManagedSettingPath ,
@@ -16,10 +16,9 @@ import {
1616 modelEvaluationSelectionLabel ,
1717 isModelEvaluationJudge ,
1818} from "@t3tools/client-runtime/modelEvaluations" ;
19- import { runAtomCommand , squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime" ;
20- import * as Effect from "effect/Effect" ;
19+ import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime" ;
2120import * as Hash from "effect/Hash" ;
22- import { AsyncResult , Atom } from "effect/reactivity" ;
21+ import { AsyncResult } from "effect/reactivity" ;
2322import { useState } from "react" ;
2423import { View } from "react-native" ;
2524
@@ -41,6 +40,7 @@ import { serverEnvironment } from "../../state/server";
4140import { useAtomCommand } from "../../state/use-atom-command" ;
4241import { SettingsSection } from "./components/SettingsSection" ;
4342import { SettingsSwitchRow } from "./components/SettingsSwitchRow" ;
43+ import { apiJudgeModelsAtom } from "./modelEvaluationApiModels" ;
4444import { useSettingsEnvironmentFilter } from "./settings-environment-filter" ;
4545
4646export function ModelEvaluationSettings ( ) {
@@ -77,27 +77,6 @@ export function ModelEvaluationSettings() {
7777 ) ;
7878}
7979
80- const apiJudgeModelsAtom = Atom . family ( ( key : string ) => {
81- const apis = JSON . parse ( key ) as ReadonlyArray <
82- readonly [ EnvironmentId , ProviderInstanceId , number ]
83- > ;
84- return Atom . make ( ( get ) =>
85- Effect . forEach (
86- apis ,
87- ( [ environmentId , id ] ) =>
88- Effect . promise ( ( ) =>
89- runAtomCommand (
90- get . registry ,
91- serverEnvironment . listTextGeneratorModels ,
92- { environmentId, input : { id } } ,
93- { reportFailure : false } ,
94- ) ,
95- ) . pipe ( Effect . map ( ( result ) => ( result . _tag === "Success" ? result . value . models : [ ] ) ) ) ,
96- { concurrency : "unbounded" } ,
97- ) ,
98- ) . pipe ( Atom . setIdleTTL ( 5 * 60_000 ) , Atom . withLabel ( "model-evaluation-api-judges" ) ) ;
99- } ) ;
100-
10180function EnvironmentEvaluationSettings ( props : {
10281 environmentId : EnvironmentId ;
10382 label : string ;
@@ -121,15 +100,15 @@ function EnvironmentEvaluationSettings(props: {
121100 > )
122101 : [ ]
123102 ) . filter ( ( [ , generator ] ) => generator . enabled ) ;
124- const apiModelLists = useAtomValue (
125- apiJudgeModelsAtom (
126- JSON . stringify (
127- apiJudges . map (
128- ( [ id , generator ] ) => [ environmentId , id , Hash . string ( JSON . stringify ( generator ) ) ] as const ,
129- ) ,
103+ const apiModelsAtom = apiJudgeModelsAtom (
104+ JSON . stringify (
105+ apiJudges . map (
106+ ( [ id , generator ] ) => [ environmentId , id , Hash . string ( JSON . stringify ( generator ) ) ] as const ,
130107 ) ,
131108 ) ,
132109 ) ;
110+ const apiModelLists = useAtomValue ( apiModelsAtom ) ;
111+ const refreshApiModels = useAtomRefresh ( apiModelsAtom ) ;
133112 if ( config === null ) return null ;
134113 const readOnly = saving || ! canWrite || props . projectSelected ;
135114 const project =
@@ -141,7 +120,11 @@ function EnvironmentEvaluationSettings(props: {
141120 const capable = new Set (
142121 config . providers . filter ( isModelEvaluationJudge ) . map ( ( provider ) => provider . instanceId ) ,
143122 ) ;
144- const listedApiModels = AsyncResult . getOrElse ( apiModelLists , ( ) => [ ] ) ;
123+ const listedApiModels = apiModelLists . map ( ( result ) => AsyncResult . getOrElse ( result , ( ) => [ ] ) ) ;
124+ const apiModelsLoading = apiModelLists . some ( ( result ) => result . waiting ) ;
125+ const failedApis = apiJudges . flatMap ( ( [ , generator ] , index ) =>
126+ apiModelLists [ index ] ?. _tag === "Failure" ? [ generator . label || generator . baseUrl ] : [ ] ,
127+ ) ;
145128 const models = [
146129 ...buildModelOptions ( config , selection , undefined , null ) . filter (
147130 ( model ) =>
@@ -230,6 +213,21 @@ function EnvironmentEvaluationSettings(props: {
230213 if ( model ) void write ( { modelEvaluationModelSelection : model . selection } ) ;
231214 } }
232215 />
216+ { apiJudges . length > 0 ? (
217+ < View className = "gap-2 px-4 py-2" >
218+ { failedApis . length > 0 ? (
219+ < Text className = "text-sm text-foreground-muted" >
220+ Could not load models from { failedApis . join ( ", " ) } .
221+ </ Text >
222+ ) : null }
223+ < Button
224+ label = { apiModelsLoading ? "Loading API models…" : "Refresh API models" }
225+ tone = "text"
226+ disabled = { apiModelsLoading }
227+ onPress = { refreshApiModels }
228+ />
229+ </ View >
230+ ) : null }
233231 { ! judgeAvailable ? (
234232 < Text className = "px-4 py-2 text-sm text-foreground-muted" >
235233 Choose an available judge before enabling.
0 commit comments