@@ -12,6 +12,7 @@ import {
1212} from './invocations' ;
1313import { APIPromise } from '../../../core/api-promise' ;
1414import { OffsetPagination , type OffsetPaginationParams , PagePromise } from '../../../core/pagination' ;
15+ import { buildHeaders } from '../../../internal/headers' ;
1516import { RequestOptions } from '../../../internal/request-options' ;
1617import { path } from '../../../internal/utils/path' ;
1718
@@ -66,6 +67,42 @@ export class Auth extends APIResource {
6667 ) : PagePromise < AuthAgentsOffsetPagination , AuthAgent > {
6768 return this . _client . getAPIList ( '/agents/auth' , OffsetPagination < AuthAgent > , { query, ...options } ) ;
6869 }
70+
71+ /**
72+ * Deletes an auth agent and terminates its workflow. This will:
73+ *
74+ * - Soft delete the auth agent record
75+ * - Gracefully terminate the agent's Temporal workflow
76+ * - Cancel any in-progress invocations
77+ *
78+ * @example
79+ * ```ts
80+ * await client.agents.auth.delete('id');
81+ * ```
82+ */
83+ delete ( id : string , options ?: RequestOptions ) : APIPromise < void > {
84+ return this . _client . delete ( path `/agents/auth/${ id } ` , {
85+ ...options ,
86+ headers : buildHeaders ( [ { Accept : '*/*' } , options ?. headers ] ) ,
87+ } ) ;
88+ }
89+
90+ /**
91+ * Triggers automatic re-authentication for an auth agent using stored credentials.
92+ * Requires the auth agent to have a linked credential, stored selectors, and
93+ * login_url. Returns immediately with status indicating whether re-auth was
94+ * started.
95+ *
96+ * @example
97+ * ```ts
98+ * const reauthResponse = await client.agents.auth.reauth(
99+ * 'id',
100+ * );
101+ * ```
102+ */
103+ reauth ( id : string , options ?: RequestOptions ) : APIPromise < ReauthResponse > {
104+ return this . _client . post ( path `/agents/auth/${ id } /reauth` , options ) ;
105+ }
69106}
70107
71108export type AuthAgentsOffsetPagination = OffsetPagination < AuthAgent > ;
@@ -196,6 +233,27 @@ export interface AuthAgent {
196233 */
197234 status : 'AUTHENTICATED' | 'NEEDS_AUTH' ;
198235
236+ /**
237+ * Whether automatic re-authentication is possible (has credential_id, selectors,
238+ * and login_url)
239+ */
240+ can_reauth ?: boolean ;
241+
242+ /**
243+ * ID of the linked credential for automatic re-authentication
244+ */
245+ credential_id ?: string ;
246+
247+ /**
248+ * Name of the linked credential for automatic re-authentication
249+ */
250+ credential_name ?: string ;
251+
252+ /**
253+ * Whether this auth agent has stored selectors for deterministic re-authentication
254+ */
255+ has_selectors ?: boolean ;
256+
199257 /**
200258 * When the last authentication check was performed
201259 */
@@ -216,6 +274,13 @@ export interface AuthAgentCreateRequest {
216274 */
217275 target_domain : string ;
218276
277+ /**
278+ * Optional name of an existing credential to use for this auth agent. If provided,
279+ * the credential will be linked to the agent and its values will be used to
280+ * auto-fill the login form on invocation.
281+ */
282+ credential_name ?: string ;
283+
219284 /**
220285 * Optional login page URL. If provided, will be stored on the agent and used to
221286 * skip discovery in future invocations.
@@ -248,31 +313,62 @@ export interface AuthAgentInvocationCreateRequest {
248313 * ID of the auth agent to create an invocation for
249314 */
250315 auth_agent_id : string ;
316+
317+ /**
318+ * If provided, saves the submitted credentials under this name upon successful
319+ * login. The credential will be linked to the auth agent for automatic
320+ * re-authentication.
321+ */
322+ save_credential_as ?: string ;
251323}
252324
253325/**
254- * Response from creating an auth agent invocation
326+ * Response when the agent is already authenticated.
255327 */
256- export interface AuthAgentInvocationCreateResponse {
257- /**
258- * When the handoff code expires
259- */
260- expires_at : string ;
328+ export type AuthAgentInvocationCreateResponse =
329+ | AuthAgentInvocationCreateResponse . AuthAgentAlreadyAuthenticated
330+ | AuthAgentInvocationCreateResponse . AuthAgentInvocationCreated ;
261331
332+ export namespace AuthAgentInvocationCreateResponse {
262333 /**
263- * One-time code for handoff
334+ * Response when the agent is already authenticated.
264335 */
265- handoff_code : string ;
336+ export interface AuthAgentAlreadyAuthenticated {
337+ /**
338+ * Indicates the agent is already authenticated and no invocation was created.
339+ */
340+ status : 'already_authenticated' ;
341+ }
266342
267343 /**
268- * URL to redirect user to
344+ * Response when a new invocation was created.
269345 */
270- hosted_url : string ;
346+ export interface AuthAgentInvocationCreated {
347+ /**
348+ * When the handoff code expires.
349+ */
350+ expires_at : string ;
271351
272- /**
273- * Unique identifier for the invocation
274- */
275- invocation_id : string ;
352+ /**
353+ * One-time code for handoff.
354+ */
355+ handoff_code : string ;
356+
357+ /**
358+ * URL to redirect user to.
359+ */
360+ hosted_url : string ;
361+
362+ /**
363+ * Unique identifier for the invocation.
364+ */
365+ invocation_id : string ;
366+
367+ /**
368+ * Indicates an invocation was created.
369+ */
370+ status : 'invocation_created' ;
371+ }
276372}
277373
278374/**
@@ -310,6 +406,26 @@ export interface DiscoveredField {
310406 required ?: boolean ;
311407}
312408
409+ /**
410+ * Response from triggering re-authentication
411+ */
412+ export interface ReauthResponse {
413+ /**
414+ * Result of the re-authentication attempt
415+ */
416+ status : 'reauth_started' | 'already_authenticated' | 'cannot_reauth' ;
417+
418+ /**
419+ * ID of the re-auth invocation if one was created
420+ */
421+ invocation_id ?: string ;
422+
423+ /**
424+ * Human-readable description of the result
425+ */
426+ message ?: string ;
427+ }
428+
313429export interface AuthCreateParams {
314430 /**
315431 * Name of the profile to use for this auth agent
@@ -321,6 +437,13 @@ export interface AuthCreateParams {
321437 */
322438 target_domain : string ;
323439
440+ /**
441+ * Optional name of an existing credential to use for this auth agent. If provided,
442+ * the credential will be linked to the agent and its values will be used to
443+ * auto-fill the login form on invocation.
444+ */
445+ credential_name ?: string ;
446+
324447 /**
325448 * Optional login page URL. If provided, will be stored on the agent and used to
326449 * skip discovery in future invocations.
@@ -369,6 +492,7 @@ export declare namespace Auth {
369492 type AuthAgentInvocationCreateRequest as AuthAgentInvocationCreateRequest ,
370493 type AuthAgentInvocationCreateResponse as AuthAgentInvocationCreateResponse ,
371494 type DiscoveredField as DiscoveredField ,
495+ type ReauthResponse as ReauthResponse ,
372496 type AuthAgentsOffsetPagination as AuthAgentsOffsetPagination ,
373497 type AuthCreateParams as AuthCreateParams ,
374498 type AuthListParams as AuthListParams ,
0 commit comments