@@ -14,6 +14,7 @@ import type {
1414 ServerSettings ,
1515 ServerSettingsPatch ,
1616} from "@t3tools/contracts" ;
17+ import { isModelSelectionProviderEnabled } from "@t3tools/shared/serverSettings" ;
1718import * as Equal from "effect/Equal" ;
1819import * as Struct from "effect/Struct" ;
1920
@@ -57,7 +58,25 @@ export function splitSharedServerPatch(patch: ServerSettingsPatch): {
5758export function filterSharedServerPatch (
5859 patch : ServerSettingsPatch ,
5960 capabilities : Pick < ExecutionEnvironmentCapabilities , "threadRestartContinuation" > | undefined ,
61+ settings ?: ServerSettings ,
62+ sourceSettings = settings ,
6063) : ServerSettingsPatch {
64+ const instanceId =
65+ patch . textGenerationModelSelection ?. instanceId ??
66+ sourceSettings ?. textGenerationModelSelection . instanceId ;
67+ if (
68+ patch . textGenerationModelSelection &&
69+ ( ! settings ||
70+ ( instanceId !== undefined &&
71+ ( sourceSettings ?. providerInstances [ instanceId ] ?. driver ?? instanceId ) !==
72+ ( settings . providerInstances [ instanceId ] ?. driver ?? instanceId ) ) ||
73+ ! isModelSelectionProviderEnabled ( settings , {
74+ ...settings . textGenerationModelSelection ,
75+ ...patch . textGenerationModelSelection ,
76+ } ) )
77+ ) {
78+ patch = Struct . omit ( patch , [ "textGenerationModelSelection" ] ) ;
79+ }
6180 return capabilities ?. threadRestartContinuation === true
6281 ? patch
6382 : Struct . omit ( patch , [ "continueThreadsAfterServerUpdate" ] ) ;
@@ -68,7 +87,11 @@ export function pickSharedServerSettings(
6887 settings : ServerSettings ,
6988 capabilities ?: Pick < ExecutionEnvironmentCapabilities , "threadRestartContinuation" > ,
7089) : ServerSettingsPatch {
71- return filterSharedServerPatch ( Struct . pick ( settings , SHARED_SERVER_SETTING_KEYS ) , capabilities ) ;
90+ return filterSharedServerPatch (
91+ Struct . pick ( settings , SHARED_SERVER_SETTING_KEYS ) ,
92+ capabilities ,
93+ settings ,
94+ ) ;
7295}
7396
7497/**
@@ -130,11 +153,20 @@ export function findSharedSettingsMismatches(input: {
130153 ) {
131154 return [ ] ;
132155 }
133- const expected = filterSharedServerPatch ( primarySettings , environment . capabilities ) ;
134- const actual = filterSharedServerPatch (
156+ const expected = filterSharedServerPatch (
157+ primarySettings ,
158+ environment . capabilities ,
159+ environment . settings ,
160+ input . primarySettings ?? undefined ,
161+ ) ;
162+ let actual = filterSharedServerPatch (
135163 pickSharedServerSettings ( environment . settings , environment . capabilities ) ,
136164 input . primaryCapabilities ,
165+ environment . settings ,
137166 ) ;
167+ if ( ! expected . textGenerationModelSelection ) {
168+ actual = Struct . omit ( actual , [ "textGenerationModelSelection" ] ) ;
169+ }
138170 return Equal . equals ( actual , expected )
139171 ? [ ]
140172 : [ { environmentId : environment . environmentId , label : environment . label } ] ;
0 commit comments