Skip to content

Commit 70cd6d6

Browse files
feat: Enhance AuthAgentInvocationCreateResponse to include already_authenti…
1 parent 4d6f1cd commit 70cd6d6

File tree

13 files changed

+533
-19
lines changed

13 files changed

+533
-19
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 82
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-dac11bdb857e700a8c39d183e753ddd1ebaaca69fd9fc5ee57d6b56b70b00e6e.yml
3-
openapi_spec_hash: 78fbc50dd0b61cdc87564fbea278ee23
4-
config_hash: a4b4d14bdf6af723b235a6981977627c
1+
configured_endpoints: 89
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-486d57f189abcec3a678ad4a619ee8a6b8aec3a3c2f3620c0423cb16cc755a13.yml
3+
openapi_spec_hash: affde047293fc74a8343a121d5e58a9c
4+
config_hash: 7225e7b7e4695c81d7be26c7108b5494

api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,15 @@ Types:
261261
- <code><a href="./src/resources/agents/auth/auth.ts">AuthAgentInvocationCreateRequest</a></code>
262262
- <code><a href="./src/resources/agents/auth/auth.ts">AuthAgentInvocationCreateResponse</a></code>
263263
- <code><a href="./src/resources/agents/auth/auth.ts">DiscoveredField</a></code>
264+
- <code><a href="./src/resources/agents/auth/auth.ts">ReauthResponse</a></code>
264265

265266
Methods:
266267

267268
- <code title="post /agents/auth">client.agents.auth.<a href="./src/resources/agents/auth/auth.ts">create</a>({ ...params }) -> AuthAgent</code>
268269
- <code title="get /agents/auth/{id}">client.agents.auth.<a href="./src/resources/agents/auth/auth.ts">retrieve</a>(id) -> AuthAgent</code>
269270
- <code title="get /agents/auth">client.agents.auth.<a href="./src/resources/agents/auth/auth.ts">list</a>({ ...params }) -> AuthAgentsOffsetPagination</code>
271+
- <code title="delete /agents/auth/{id}">client.agents.auth.<a href="./src/resources/agents/auth/auth.ts">delete</a>(id) -> void</code>
272+
- <code title="post /agents/auth/{id}/reauth">client.agents.auth.<a href="./src/resources/agents/auth/auth.ts">reauth</a>(id) -> ReauthResponse</code>
270273

271274
### Invocations
272275

@@ -281,3 +284,19 @@ Methods:
281284
- <code title="post /agents/auth/invocations/{invocation_id}/discover">client.agents.auth.invocations.<a href="./src/resources/agents/auth/invocations.ts">discover</a>(invocationID, { ...params }) -> AgentAuthDiscoverResponse</code>
282285
- <code title="post /agents/auth/invocations/{invocation_id}/exchange">client.agents.auth.invocations.<a href="./src/resources/agents/auth/invocations.ts">exchange</a>(invocationID, { ...params }) -> InvocationExchangeResponse</code>
283286
- <code title="post /agents/auth/invocations/{invocation_id}/submit">client.agents.auth.invocations.<a href="./src/resources/agents/auth/invocations.ts">submit</a>(invocationID, { ...params }) -> AgentAuthSubmitResponse</code>
287+
288+
# Credentials
289+
290+
Types:
291+
292+
- <code><a href="./src/resources/credentials.ts">CreateCredentialRequest</a></code>
293+
- <code><a href="./src/resources/credentials.ts">Credential</a></code>
294+
- <code><a href="./src/resources/credentials.ts">UpdateCredentialRequest</a></code>
295+
296+
Methods:
297+
298+
- <code title="post /credentials">client.credentials.<a href="./src/resources/credentials.ts">create</a>({ ...params }) -> Credential</code>
299+
- <code title="get /credentials/{id}">client.credentials.<a href="./src/resources/credentials.ts">retrieve</a>(id) -> Credential</code>
300+
- <code title="patch /credentials/{id}">client.credentials.<a href="./src/resources/credentials.ts">update</a>(id, { ...params }) -> Credential</code>
301+
- <code title="get /credentials">client.credentials.<a href="./src/resources/credentials.ts">list</a>({ ...params }) -> CredentialsOffsetPagination</code>
302+
- <code title="delete /credentials/{id}">client.credentials.<a href="./src/resources/credentials.ts">delete</a>(id) -> void</code>

src/client.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ import {
3434
BrowserPoolUpdateRequest,
3535
BrowserPools,
3636
} from './resources/browser-pools';
37+
import {
38+
CreateCredentialRequest,
39+
Credential,
40+
CredentialCreateParams,
41+
CredentialListParams,
42+
CredentialUpdateParams,
43+
Credentials,
44+
CredentialsOffsetPagination,
45+
UpdateCredentialRequest,
46+
} from './resources/credentials';
3747
import {
3848
DeploymentCreateParams,
3949
DeploymentCreateResponse,
@@ -861,6 +871,7 @@ export class Kernel {
861871
extensions: API.Extensions = new API.Extensions(this);
862872
browserPools: API.BrowserPools = new API.BrowserPools(this);
863873
agents: API.Agents = new API.Agents(this);
874+
credentials: API.Credentials = new API.Credentials(this);
864875
}
865876

866877
Kernel.Deployments = Deployments;
@@ -872,6 +883,7 @@ Kernel.Proxies = Proxies;
872883
Kernel.Extensions = Extensions;
873884
Kernel.BrowserPools = BrowserPools;
874885
Kernel.Agents = Agents;
886+
Kernel.Credentials = Credentials;
875887

876888
export declare namespace Kernel {
877889
export type RequestOptions = Opts.RequestOptions;
@@ -971,6 +983,17 @@ export declare namespace Kernel {
971983

972984
export { Agents as Agents };
973985

986+
export {
987+
Credentials as Credentials,
988+
type CreateCredentialRequest as CreateCredentialRequest,
989+
type Credential as Credential,
990+
type UpdateCredentialRequest as UpdateCredentialRequest,
991+
type CredentialsOffsetPagination as CredentialsOffsetPagination,
992+
type CredentialCreateParams as CredentialCreateParams,
993+
type CredentialUpdateParams as CredentialUpdateParams,
994+
type CredentialListParams as CredentialListParams,
995+
};
996+
974997
export type AppAction = API.AppAction;
975998
export type BrowserExtension = API.BrowserExtension;
976999
export type BrowserProfile = API.BrowserProfile;

src/resources/agents/agents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
AuthCreateParams,
1616
AuthListParams,
1717
DiscoveredField,
18+
ReauthResponse,
1819
} from './auth/auth';
1920

2021
export class Agents extends APIResource {
@@ -34,6 +35,7 @@ export declare namespace Agents {
3435
type AuthAgentInvocationCreateRequest as AuthAgentInvocationCreateRequest,
3536
type AuthAgentInvocationCreateResponse as AuthAgentInvocationCreateResponse,
3637
type DiscoveredField as DiscoveredField,
38+
type ReauthResponse as ReauthResponse,
3739
type AuthAgentsOffsetPagination as AuthAgentsOffsetPagination,
3840
type AuthCreateParams as AuthCreateParams,
3941
type AuthListParams as AuthListParams,

src/resources/agents/auth/auth.ts

Lines changed: 138 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from './invocations';
1313
import { APIPromise } from '../../../core/api-promise';
1414
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../../../core/pagination';
15+
import { buildHeaders } from '../../../internal/headers';
1516
import { RequestOptions } from '../../../internal/request-options';
1617
import { 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

71108
export 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+
313429
export 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,

src/resources/agents/auth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
type AuthAgentInvocationCreateRequest,
1111
type AuthAgentInvocationCreateResponse,
1212
type DiscoveredField,
13+
type ReauthResponse,
1314
type AuthCreateParams,
1415
type AuthListParams,
1516
type AuthAgentsOffsetPagination,

src/resources/agents/auth/invocations.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ export interface InvocationCreateParams {
132132
* ID of the auth agent to create an invocation for
133133
*/
134134
auth_agent_id: string;
135+
136+
/**
137+
* If provided, saves the submitted credentials under this name upon successful
138+
* login. The credential will be linked to the auth agent for automatic
139+
* re-authentication.
140+
*/
141+
save_credential_as?: string;
135142
}
136143

137144
export interface InvocationDiscoverParams {

src/resources/agents/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
type AuthAgentInvocationCreateRequest,
1212
type AuthAgentInvocationCreateResponse,
1313
type DiscoveredField,
14+
type ReauthResponse,
1415
type AuthCreateParams,
1516
type AuthListParams,
1617
type AuthAgentsOffsetPagination,

0 commit comments

Comments
 (0)