@@ -77,6 +77,8 @@ const PROVIDER_MODES = new Set<WorkspaceProviderMode>(['platform_credits', 'pers
7777interface VelaWorkspaceContextOptions {
7878 /** Injectable for tests. */
7979 fetch ?: typeof fetch ;
80+ /** Reuse the daemon's account-scoped directory authority broker. */
81+ fetchWorkspaceDirectory ?: ( ) => Promise < WorkspaceDirectoryFetchResult > ;
8082 /** Injectable for tests; defaults to reading ~/.amr/config.json + env. */
8183 readSession ?: typeof readVelaControlApiContext ;
8284 /** Settings-backed AMR environment used by the daemon's agent launcher. */
@@ -230,9 +232,19 @@ export function createVelaWorkspaceContextProvider(
230232 const fetchImpl = options . fetch ?? fetch ;
231233 const readSession = options . readSession ?? readVelaControlApiContext ;
232234 const timeoutMs = options . timeoutMs ?? DEFAULT_TIMEOUT_MS ;
235+ type VelaSession = NonNullable < ReturnType < typeof readVelaControlApiContext > > ;
233236 const configuredEnv = ( ) => typeof options . configuredEnv === 'function'
234237 ? options . configuredEnv ( )
235238 : ( options . configuredEnv ?? { } ) ;
239+ const readWorkspaceDirectory = (
240+ session : VelaSession ,
241+ selectedEnv : Record < string , string > ,
242+ ) => options . fetchWorkspaceDirectory ?.( ) ?? fetchVelaWorkspaceDirectory ( {
243+ fetch : fetchImpl ,
244+ readSession : ( ) => session ,
245+ configuredEnv : selectedEnv ,
246+ timeoutMs,
247+ } ) ;
236248
237249 /** Pick the best default membership out of an already-fetched directory list. */
238250 function selectDefaultCandidate (
@@ -269,12 +281,7 @@ export function createVelaWorkspaceContextProvider(
269281 const session = readSession ( process . env , selectedEnv ) ;
270282 if ( ! session || ! session . controlKey || ! session . apiUrl ) return null ;
271283 try {
272- const directory = await fetchVelaWorkspaceDirectory ( {
273- fetch : fetchImpl ,
274- readSession : ( ) => session ,
275- configuredEnv : selectedEnv ,
276- timeoutMs,
277- } ) ;
284+ const directory = await readWorkspaceDirectory ( session , selectedEnv ) ;
278285 // A failed directory read confirms nothing. In particular, never evict
279286 // the local pin on a timeout, auth outage, or non-2xx response.
280287 if ( ! directory . ok ) return null ;
@@ -323,12 +330,7 @@ export function createVelaWorkspaceContextProvider(
323330 const workspaceId = req . workspaceId . trim ( ) ;
324331 if ( ! session || ! session . controlKey || ! session . apiUrl || ! workspaceId ) return null ;
325332 try {
326- const directory = await fetchVelaWorkspaceDirectory ( {
327- fetch : fetchImpl ,
328- readSession : ( ) => session ,
329- configuredEnv : selectedEnv ,
330- timeoutMs,
331- } ) ;
333+ const directory = await readWorkspaceDirectory ( session , selectedEnv ) ;
332334 if ( ! directory . ok ) return null ;
333335 const item = directory . items . find (
334336 ( entry ) =>
@@ -906,7 +908,11 @@ export function createWorkspaceContextProviderFromEnv(
906908 env : NodeJS . ProcessEnv = process . env ,
907909 options : Pick <
908910 VelaWorkspaceContextOptions ,
909- 'configuredEnv' | 'getActiveWorkspaceId' | 'setLocalSelection' | 'clearLocalSelection'
911+ | 'configuredEnv'
912+ | 'fetchWorkspaceDirectory'
913+ | 'getActiveWorkspaceId'
914+ | 'setLocalSelection'
915+ | 'clearLocalSelection'
910916 > = { } ,
911917) : WorkspaceContextProvider {
912918 if ( env . OD_WORKSPACE_CONTEXT_SOURCE ?. trim ( ) === 'vela' ) {
0 commit comments