@@ -65,12 +65,21 @@ export class AgentAuthClient {
6565 private readonly onApprovalStatusChange : ( ( status : AgentStatus ) => void | Promise < void > ) | null ;
6666 private readonly approvalTimeoutMs : number ;
6767 private readonly abortController : AbortController ;
68+ private readonly urls : string [ ] | null ;
6869
6970 constructor ( opts : AgentAuthClientOptions = { } ) {
7071 this . storage = opts . storage ?? new MemoryStorage ( ) ;
7172 this . fetchFn = opts . fetch ?? globalThis . fetch . bind ( globalThis ) ;
72- this . directoryUrl = opts . directoryUrl ?? "https://agent-auth.directory" ;
73- this . allowDirectDiscovery = opts . allowDirectDiscovery ?? ! this . directoryUrl ;
73+ const urlMode = ( opts . urls ?. length ?? 0 ) > 0 ;
74+ this . urls = urlMode ? opts . urls ! : null ;
75+ this . directoryUrl =
76+ opts . directoryUrl !== undefined
77+ ? opts . directoryUrl
78+ : urlMode
79+ ? null
80+ : "https://agent-auth.directory" ;
81+ this . allowDirectDiscovery =
82+ opts . allowDirectDiscovery ?? ( urlMode ? true : ! this . directoryUrl ) ;
7483 this . jwtExpirySeconds = opts . jwtExpirySeconds ?? 60 ;
7584 this . hostName = opts . hostName ?? detectHostName ( ) ;
7685 this . onApprovalRequired = opts . onApprovalRequired ?? null ;
@@ -85,6 +94,32 @@ export class AgentAuthClient {
8594 }
8695 }
8796
97+ /**
98+ * Initialize the client — discovers any URLs passed via the `urls`
99+ * option. Call this once after construction when using URL-only mode.
100+ * Returns the discovered provider configs (failures are logged, not thrown).
101+ */
102+ async init ( ) : Promise < ProviderConfig [ ] > {
103+ if ( ! this . urls ?. length ) return [ ] ;
104+ const results = await Promise . allSettled (
105+ this . urls . map ( ( url ) => this . discoverProvider ( url ) ) ,
106+ ) ;
107+ const configs : ProviderConfig [ ] = [ ] ;
108+ for ( const r of results ) {
109+ if ( r . status === "fulfilled" ) {
110+ configs . push ( r . value ) ;
111+ }
112+ }
113+ return configs ;
114+ }
115+
116+ /**
117+ * Whether the client is in URL-only mode (no directory).
118+ */
119+ get isUrlMode ( ) : boolean {
120+ return this . urls !== null && this . urls . length > 0 ;
121+ }
122+
88123 /**
89124 * Cancel all in-flight polling loops (approval, async execution)
90125 * and prevent new ones from starting. Call this when tearing down
0 commit comments