@@ -86,15 +86,30 @@ function toRuntimeStatus(session: ProviderSession): "starting" | "running" | "st
8686 }
8787}
8888
89- function toRuntimePayloadFromSession ( session : ProviderSession ) : Record < string , unknown > {
89+ function toRuntimePayloadFromSession (
90+ session : ProviderSession ,
91+ extra ?: { readonly providerOptions ?: unknown } ,
92+ ) : Record < string , unknown > {
9093 return {
9194 cwd : session . cwd ?? null ,
9295 model : session . model ?? null ,
9396 activeTurnId : session . activeTurnId ?? null ,
9497 lastError : session . lastError ?? null ,
98+ ...( extra ?. providerOptions !== undefined ? { providerOptions : extra . providerOptions } : { } ) ,
9599 } ;
96100}
97101
102+ function readPersistedProviderOptions (
103+ runtimePayload : ProviderRuntimeBinding [ "runtimePayload" ] ,
104+ ) : Record < string , unknown > | undefined {
105+ if ( ! runtimePayload || typeof runtimePayload !== "object" || Array . isArray ( runtimePayload ) ) {
106+ return undefined ;
107+ }
108+ const raw = "providerOptions" in runtimePayload ? runtimePayload . providerOptions : undefined ;
109+ if ( ! raw || typeof raw !== "object" || Array . isArray ( raw ) ) return undefined ;
110+ return raw as Record < string , unknown > ;
111+ }
112+
98113function readPersistedCwd (
99114 runtimePayload : ProviderRuntimeBinding [ "runtimePayload" ] ,
100115) : string | undefined {
@@ -137,14 +152,15 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
137152 const upsertSessionBinding = (
138153 session : ProviderSession ,
139154 threadId : ThreadId ,
155+ extra ?: { readonly providerOptions ?: unknown } ,
140156 ) =>
141157 directory . upsert ( {
142158 threadId,
143159 provider : session . provider ,
144160 runtimeMode : session . runtimeMode ,
145161 status : toRuntimeStatus ( session ) ,
146162 ...( session . resumeCursor !== undefined ? { resumeCursor : session . resumeCursor } : { } ) ,
147- runtimePayload : toRuntimePayloadFromSession ( session ) ,
163+ runtimePayload : toRuntimePayloadFromSession ( session , extra ) ,
148164 } ) ;
149165
150166 const providers = yield * registry . listProviders ( ) ;
@@ -197,11 +213,13 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
197213 }
198214
199215 const persistedCwd = readPersistedCwd ( input . binding . runtimePayload ) ;
216+ const persistedProviderOptions = readPersistedProviderOptions ( input . binding . runtimePayload ) ;
200217
201218 const resumed = yield * adapter . startSession ( {
202219 threadId : input . binding . threadId ,
203220 provider : input . binding . provider ,
204221 ...( persistedCwd ? { cwd : persistedCwd } : { } ) ,
222+ ...( persistedProviderOptions ? { providerOptions : persistedProviderOptions } : { } ) ,
205223 ...( hasResumeCursor ? { resumeCursor : input . binding . resumeCursor } : { } ) ,
206224 runtimeMode : input . binding . runtimeMode ?? "full-access" ,
207225 } ) ;
@@ -273,7 +291,9 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
273291 ) ;
274292 }
275293
276- yield * upsertSessionBinding ( session , threadId ) ;
294+ yield * upsertSessionBinding ( session , threadId , {
295+ ...( input . providerOptions !== undefined ? { providerOptions : input . providerOptions } : { } ) ,
296+ } ) ;
277297 yield * analytics . record ( "provider.session.started" , {
278298 provider : session . provider ,
279299 runtimeMode : input . runtimeMode ,
0 commit comments