@@ -132,6 +132,7 @@ export class ServerOptions {
132132 initializeProcessTimeout : number ;
133133 permissions : WorkerPermissions ;
134134 agentName : string ;
135+ agentNameIsEnv : boolean ;
135136 serverType : JobType ;
136137 maxRetry : number ;
137138 wsURL : string ;
@@ -156,6 +157,7 @@ export class ServerOptions {
156157 initializeProcessTimeout = 10 * 1000 ,
157158 permissions = new WorkerPermissions ( ) ,
158159 agentName = '' ,
160+ agentNameIsEnv = undefined ,
159161 serverType = JobType . JT_ROOM ,
160162 maxRetry = MAX_RECONNECT_ATTEMPTS ,
161163 wsURL = 'ws://localhost:7880' ,
@@ -183,7 +185,20 @@ export class ServerOptions {
183185 shutdownProcessTimeout ?: number ;
184186 initializeProcessTimeout ?: number ;
185187 permissions ?: WorkerPermissions ;
188+ /**
189+ * Set agentName to enable explicit dispatch. When explicit dispatch is enabled, jobs will not
190+ * be dispatched to rooms automatically. Instead, you can either specify the agent(s) to be
191+ * dispatched in the end-user's token, or use the AgentDispatch.createDispatch API.
192+ *
193+ * By default it uses `LIVEKIT_AGENT_NAME` from environment.
194+ */
186195 agentName ?: string ;
196+ /**
197+ * Internal flag indicating that `agentName` was resolved from `LIVEKIT_AGENT_NAME`. Forwarded
198+ * through ServerOptions re-construction (e.g. cli.ts spread) so the env-source signal isn't
199+ * lost.
200+ */
201+ agentNameIsEnv ?: boolean ;
187202 serverType ?: JobType ;
188203 maxRetry ?: number ;
189204 wsURL ?: string ;
@@ -208,7 +223,18 @@ export class ServerOptions {
208223 this . shutdownProcessTimeout = shutdownProcessTimeout ;
209224 this . initializeProcessTimeout = initializeProcessTimeout ;
210225 this . permissions = permissions ;
211- this . agentName = agentName ;
226+ // agentNameIsEnv may be passed explicitly when ServerOptions is re-constructed (e.g.
227+ // cli.ts spreads an existing ServerOptions instance), so prefer it when defined.
228+ if ( agentName ) {
229+ this . agentName = agentName ;
230+ this . agentNameIsEnv = agentNameIsEnv ?? false ;
231+ } else if ( process . env . LIVEKIT_AGENT_NAME ) {
232+ this . agentName = process . env . LIVEKIT_AGENT_NAME ;
233+ this . agentNameIsEnv = agentNameIsEnv ?? true ;
234+ } else {
235+ this . agentName = '' ;
236+ this . agentNameIsEnv = agentNameIsEnv ?? false ;
237+ }
212238 this . serverType = serverType ;
213239 this . maxRetry = maxRetry ;
214240 this . wsURL = wsURL ;
@@ -341,6 +367,7 @@ export class AgentServer {
341367
342368 const getWorkerInfo = ( ) => ( {
343369 agent_name : opts . agentName ,
370+ agent_name_is_env : opts . agentNameIsEnv ,
344371 worker_type : JobType [ opts . serverType ] ,
345372 active_jobs : this . activeJobs . length ,
346373 sdk_version : version ,
0 commit comments