1
/**2
* Exclusive named registration for the browser-use capability.3
* @module @deepseek-ai/dsh-browser-use4
*/6
import { Context, Service } from '@deepseek-ai/cordis'7
import type { BrowserUseProviderName } from './brand.ts'9
declare module '@deepseek-ai/cordis' {10
interface Context {11
browserUse: BrowserUseRegistry12
}13
}15
/** Owns one optional provider registration in the shared browser-use service. */16
export class BrowserUseRegistry extends Service {17
private registration: BrowserUseProviderName | undefined19
constructor(ctx: Context) {20
super(ctx, 'browserUse')21
}23
/** Name of the registered provider, including while its resources are closing. */24
get providerName(): BrowserUseProviderName | undefined {25
return this.registration26
}28
/**29
* Reserve the sole provider slot until the contribution is disposed.30
* A second registration fails even when it repeats the current name. Providers31
* must stop their tools and await owned work before releasing this registration.32
* @param name - provider-owned name used in registration diagnostics.33
* @returns the effect disposer for this exact registration.34
*/35
register(name: BrowserUseProviderName): () => Promise<void> {36
if (this.registration !== undefined) {37
throw new Error(`browser use provider "${this.registration}" is already registered`)38
}39
return this.ctx.effect(() => {40
this.registration = name41
return () => {42
this.registration = undefined43
}44
}, 'browserUse.register()')45
}46
}48
export default BrowserUseRegistry