55 EventId ,
66 type ModelSelection ,
77 type OrchestrationEvent ,
8- type ProviderModelOptions ,
98 ProviderKind ,
109 type ProviderStartOptions ,
1110 type OrchestrationSession ,
@@ -16,7 +15,6 @@ import {
1615} from "@t3tools/contracts" ;
1716import { Cache , Cause , Duration , Effect , Layer , Option , Schema , Stream } from "effect" ;
1817import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker" ;
19- import { toProviderModelOptions } from "@t3tools/shared/model" ;
2018
2119import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts" ;
2220import { GitCore } from "../../git/Services/GitCore.ts" ;
@@ -77,9 +75,9 @@ const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
7775const WORKTREE_BRANCH_PREFIX = "t3code" ;
7876const TEMP_WORKTREE_BRANCH_PATTERN = new RegExp ( `^${ WORKTREE_BRANCH_PREFIX } \\/[0-9a-f]{8}$` ) ;
7977
80- const sameModelOptions = (
81- left : ProviderModelOptions | undefined ,
82- right : ProviderModelOptions | undefined ,
78+ const sameModelSelectionOptions = (
79+ left : ModelSelection | undefined ,
80+ right : ModelSelection | undefined ,
8381) : boolean => JSON . stringify ( left ?? null ) === JSON . stringify ( right ?? null ) ;
8482
8583function isUnknownPendingApprovalRequestError ( cause : Cause . Cause < ProviderServiceError > ) : boolean {
@@ -159,7 +157,7 @@ const make = Effect.gen(function* () {
159157 ) ;
160158
161159 const threadProviderOptions = new Map < string , ProviderStartOptions > ( ) ;
162- const threadModelOptions = new Map < string , ProviderModelOptions > ( ) ;
160+ const threadModelSelections = new Map < string , ModelSelection > ( ) ;
163161
164162 const appendProviderFailureActivity = ( input : {
165163 readonly threadId : ThreadId ;
@@ -217,7 +215,6 @@ const make = Effect.gen(function* () {
217215 createdAt : string ,
218216 options ?: {
219217 readonly modelSelection ?: ModelSelection ;
220- readonly modelOptions ?: ProviderModelOptions ;
221218 readonly providerOptions ?: ProviderStartOptions ;
222219 } ,
223220 ) {
@@ -247,9 +244,6 @@ const make = Effect.gen(function* () {
247244 }
248245 const preferredProvider : ProviderKind = currentProvider ?? threadProvider ;
249246 const desiredModelSelection = requestedModelSelection ?? thread . modelSelection ;
250- const desiredModel = desiredModelSelection . model ;
251- const desiredModelOptions =
252- options ?. modelOptions ?? toProviderModelOptions ( desiredModelSelection ) ;
253247 const effectiveCwd = resolveThreadWorkspaceCwd ( {
254248 thread,
255249 projects : readModel . projects ,
@@ -268,8 +262,7 @@ const make = Effect.gen(function* () {
268262 threadId,
269263 ...( preferredProvider ? { provider : preferredProvider } : { } ) ,
270264 ...( effectiveCwd ? { cwd : effectiveCwd } : { } ) ,
271- ...( desiredModel ? { model : desiredModel } : { } ) ,
272- ...( desiredModelOptions !== undefined ? { modelOptions : desiredModelOptions } : { } ) ,
265+ modelSelection : desiredModelSelection ,
273266 ...( options ?. providerOptions !== undefined
274267 ? { providerOptions : options . providerOptions }
275268 : { } ) ,
@@ -309,17 +302,17 @@ const make = Effect.gen(function* () {
309302 requestedModelSelection !== undefined &&
310303 requestedModelSelection . model !== activeSession ?. model ;
311304 const shouldRestartForModelChange = modelChanged && sessionModelSwitch === "restart-session" ;
312- const previousModelOptions = threadModelOptions . get ( threadId ) ;
313- const shouldRestartForModelOptionsChange =
305+ const previousModelSelection = threadModelSelections . get ( threadId ) ;
306+ const shouldRestartForModelSelectionChange =
314307 currentProvider === "claudeAgent" &&
315- options ?. modelOptions !== undefined &&
316- ! sameModelOptions ( previousModelOptions , options . modelOptions ) ;
308+ requestedModelSelection !== undefined &&
309+ ! sameModelSelectionOptions ( previousModelSelection , requestedModelSelection ) ;
317310
318311 if (
319312 ! runtimeModeChanged &&
320313 ! providerChanged &&
321314 ! shouldRestartForModelChange &&
322- ! shouldRestartForModelOptionsChange
315+ ! shouldRestartForModelSelectionChange
323316 ) {
324317 return existingSessionThreadId ;
325318 }
@@ -339,7 +332,7 @@ const make = Effect.gen(function* () {
339332 providerChanged,
340333 modelChanged,
341334 shouldRestartForModelChange,
342- shouldRestartForModelOptionsChange ,
335+ shouldRestartForModelSelectionChange ,
343336 hasResumeCursor : resumeCursor !== undefined ,
344337 } ) ;
345338 const restartedSession = yield * startProviderSession (
@@ -366,7 +359,6 @@ const make = Effect.gen(function* () {
366359 readonly messageText : string ;
367360 readonly attachments ?: ReadonlyArray < ChatAttachment > ;
368361 readonly modelSelection ?: ModelSelection ;
369- readonly modelOptions ?: ProviderModelOptions ;
370362 readonly providerOptions ?: ProviderStartOptions ;
371363 readonly interactionMode ?: "default" | "plan" ;
372364 readonly createdAt : string ;
@@ -377,14 +369,13 @@ const make = Effect.gen(function* () {
377369 }
378370 yield * ensureSessionForThread ( input . threadId , input . createdAt , {
379371 ...( input . modelSelection !== undefined ? { modelSelection : input . modelSelection } : { } ) ,
380- ...( input . modelOptions !== undefined ? { modelOptions : input . modelOptions } : { } ) ,
381372 ...( input . providerOptions !== undefined ? { providerOptions : input . providerOptions } : { } ) ,
382373 } ) ;
383374 if ( input . providerOptions !== undefined ) {
384375 threadProviderOptions . set ( input . threadId , input . providerOptions ) ;
385376 }
386- if ( input . modelOptions !== undefined ) {
387- threadModelOptions . set ( input . threadId , input . modelOptions ) ;
377+ if ( input . modelSelection !== undefined ) {
378+ threadModelSelections . set ( input . threadId , input . modelSelection ) ;
388379 }
389380 const normalizedInput = toNonEmptyProviderInput ( input . messageText ) ;
390381 const normalizedAttachments = input . attachments ?? [ ] ;
@@ -398,14 +389,20 @@ const make = Effect.gen(function* () {
398389 ? "in-session"
399390 : ( yield * providerService . getCapabilities ( activeSession . provider ) ) . sessionModelSwitch ;
400391 const modelForTurn =
401- sessionModelSwitch === "unsupported" ? activeSession ?. model : input . modelSelection ?. model ;
392+ sessionModelSwitch === "unsupported"
393+ ? input . modelSelection
394+ ? {
395+ ...input . modelSelection ,
396+ model : activeSession ?. model ?? input . modelSelection . model ,
397+ }
398+ : undefined
399+ : input . modelSelection ;
402400
403401 yield * providerService . sendTurn ( {
404402 threadId : input . threadId ,
405403 ...( normalizedInput ? { input : normalizedInput } : { } ) ,
406404 ...( normalizedAttachments . length > 0 ? { attachments : normalizedAttachments } : { } ) ,
407- ...( modelForTurn !== undefined ? { model : modelForTurn } : { } ) ,
408- ...( input . modelOptions !== undefined ? { modelOptions : input . modelOptions } : { } ) ,
405+ ...( modelForTurn !== undefined ? { modelSelection : modelForTurn } : { } ) ,
409406 ...( input . interactionMode !== undefined ? { interactionMode : input . interactionMode } : { } ) ,
410407 } ) ;
411408 } ) ;
@@ -514,18 +511,13 @@ const make = Effect.gen(function* () {
514511 ...( message . attachments !== undefined ? { attachments : message . attachments } : { } ) ,
515512 } ) . pipe ( Effect . forkScoped ) ;
516513
517- const requestedModelOptions = event . payload . modelSelection
518- ? toProviderModelOptions ( event . payload . modelSelection )
519- : undefined ;
520-
521514 yield * sendTurnForThread ( {
522515 threadId : event . payload . threadId ,
523516 messageText : message . text ,
524517 ...( message . attachments !== undefined ? { attachments : message . attachments } : { } ) ,
525518 ...( event . payload . modelSelection !== undefined
526519 ? { modelSelection : event . payload . modelSelection }
527520 : { } ) ,
528- ...( requestedModelOptions !== undefined ? { modelOptions : requestedModelOptions } : { } ) ,
529521 ...( event . payload . providerOptions !== undefined
530522 ? { providerOptions : event . payload . providerOptions }
531523 : { } ) ,
@@ -695,12 +687,12 @@ const make = Effect.gen(function* () {
695687 return ;
696688 }
697689 const cachedProviderOptions = threadProviderOptions . get ( event . payload . threadId ) ;
698- const cachedModelOptions = threadModelOptions . get ( event . payload . threadId ) ;
690+ const cachedModelSelection = threadModelSelections . get ( event . payload . threadId ) ;
699691 yield * ensureSessionForThread ( event . payload . threadId , event . occurredAt , {
700692 ...( cachedProviderOptions !== undefined
701693 ? { providerOptions : cachedProviderOptions }
702694 : { } ) ,
703- ...( cachedModelOptions !== undefined ? { modelOptions : cachedModelOptions } : { } ) ,
695+ ...( cachedModelSelection !== undefined ? { modelSelection : cachedModelSelection } : { } ) ,
704696 } ) ;
705697 return ;
706698 }
0 commit comments