Skip to content

Commit 5166b00

Browse files
feat: getInvocations endpoint
1 parent 4e1d5ce commit 5166b00

File tree

6 files changed

+151
-4
lines changed

6 files changed

+151
-4
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: 50
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-5ee2116982adf46664acf84b8ba4b56ba65780983506c63d9b005dab49def757.yml
3-
openapi_spec_hash: 42a3a519301d0e2bb2b5a71018915b55
4-
config_hash: 0d150b61cae2dc57d3648ceae7784966
1+
configured_endpoints: 51
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-8b5a722e4964d2d1dcdc34afccb6d742e1c927cbbd622264c8734f132e31a0f5.yml
3+
openapi_spec_hash: ed101ff177c2e962653ca65acf939336
4+
config_hash: 49c2ff978aaa5ccb4ce324a72f116010

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ Types:
4444
- <code><a href="./src/resources/invocations.ts">InvocationCreateResponse</a></code>
4545
- <code><a href="./src/resources/invocations.ts">InvocationRetrieveResponse</a></code>
4646
- <code><a href="./src/resources/invocations.ts">InvocationUpdateResponse</a></code>
47+
- <code><a href="./src/resources/invocations.ts">InvocationListResponse</a></code>
4748
- <code><a href="./src/resources/invocations.ts">InvocationFollowResponse</a></code>
4849

4950
Methods:
5051

5152
- <code title="post /invocations">client.invocations.<a href="./src/resources/invocations.ts">create</a>({ ...params }) -> InvocationCreateResponse</code>
5253
- <code title="get /invocations/{id}">client.invocations.<a href="./src/resources/invocations.ts">retrieve</a>(id) -> InvocationRetrieveResponse</code>
5354
- <code title="patch /invocations/{id}">client.invocations.<a href="./src/resources/invocations.ts">update</a>(id, { ...params }) -> InvocationUpdateResponse</code>
55+
- <code title="get /invocations">client.invocations.<a href="./src/resources/invocations.ts">list</a>({ ...params }) -> InvocationListResponsesOffsetPagination</code>
5456
- <code title="delete /invocations/{id}/browsers">client.invocations.<a href="./src/resources/invocations.ts">deleteBrowsers</a>(id) -> void</code>
5557
- <code title="get /invocations/{id}/events">client.invocations.<a href="./src/resources/invocations.ts">follow</a>(id, { ...params }) -> InvocationFollowResponse</code>
5658

src/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import {
3737
InvocationCreateResponse,
3838
InvocationFollowParams,
3939
InvocationFollowResponse,
40+
InvocationListParams,
41+
InvocationListResponse,
42+
InvocationListResponsesOffsetPagination,
4043
InvocationRetrieveResponse,
4144
InvocationStateEvent,
4245
InvocationUpdateParams,
@@ -868,9 +871,12 @@ export declare namespace Kernel {
868871
type InvocationCreateResponse as InvocationCreateResponse,
869872
type InvocationRetrieveResponse as InvocationRetrieveResponse,
870873
type InvocationUpdateResponse as InvocationUpdateResponse,
874+
type InvocationListResponse as InvocationListResponse,
871875
type InvocationFollowResponse as InvocationFollowResponse,
876+
type InvocationListResponsesOffsetPagination as InvocationListResponsesOffsetPagination,
872877
type InvocationCreateParams as InvocationCreateParams,
873878
type InvocationUpdateParams as InvocationUpdateParams,
879+
type InvocationListParams as InvocationListParams,
874880
type InvocationFollowParams as InvocationFollowParams,
875881
};
876882

src/resources/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ export {
3030
type InvocationCreateResponse,
3131
type InvocationRetrieveResponse,
3232
type InvocationUpdateResponse,
33+
type InvocationListResponse,
3334
type InvocationFollowResponse,
3435
type InvocationCreateParams,
3536
type InvocationUpdateParams,
37+
type InvocationListParams,
3638
type InvocationFollowParams,
39+
type InvocationListResponsesOffsetPagination,
3740
} from './invocations';
3841
export { Profiles, type ProfileListResponse, type ProfileCreateParams } from './profiles';
3942
export {

src/resources/invocations.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { APIResource } from '../core/resource';
44
import * as Shared from './shared';
55
import { APIPromise } from '../core/api-promise';
6+
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../core/pagination';
67
import { Stream } from '../core/streaming';
78
import { buildHeaders } from '../internal/headers';
89
import { RequestOptions } from '../internal/request-options';
@@ -58,6 +59,28 @@ export class Invocations extends APIResource {
5859
return this._client.patch(path`/invocations/${id}`, { body, ...options });
5960
}
6061

62+
/**
63+
* List invocations. Optionally filter by application name, action name, status,
64+
* deployment ID, or start time.
65+
*
66+
* @example
67+
* ```ts
68+
* // Automatically fetches more pages as needed.
69+
* for await (const invocationListResponse of client.invocations.list()) {
70+
* // ...
71+
* }
72+
* ```
73+
*/
74+
list(
75+
query: InvocationListParams | null | undefined = {},
76+
options?: RequestOptions,
77+
): PagePromise<InvocationListResponsesOffsetPagination, InvocationListResponse> {
78+
return this._client.getAPIList('/invocations', OffsetPagination<InvocationListResponse>, {
79+
query,
80+
...options,
81+
});
82+
}
83+
6184
/**
6285
* Delete all browser sessions created within the specified invocation.
6386
*
@@ -97,6 +120,8 @@ export class Invocations extends APIResource {
97120
}
98121
}
99122

123+
export type InvocationListResponsesOffsetPagination = OffsetPagination<InvocationListResponse>;
124+
100125
/**
101126
* An event representing the current state of an invocation.
102127
*/
@@ -291,6 +316,55 @@ export interface InvocationUpdateResponse {
291316
status_reason?: string;
292317
}
293318

319+
export interface InvocationListResponse {
320+
/**
321+
* ID of the invocation
322+
*/
323+
id: string;
324+
325+
/**
326+
* Name of the action invoked
327+
*/
328+
action_name: string;
329+
330+
/**
331+
* Name of the application
332+
*/
333+
app_name: string;
334+
335+
/**
336+
* RFC 3339 Nanoseconds timestamp when the invocation started
337+
*/
338+
started_at: string;
339+
340+
/**
341+
* Status of the invocation
342+
*/
343+
status: 'queued' | 'running' | 'succeeded' | 'failed';
344+
345+
/**
346+
* RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
347+
* running)
348+
*/
349+
finished_at?: string | null;
350+
351+
/**
352+
* Output produced by the action, rendered as a JSON string. This could be: string,
353+
* number, boolean, array, object, or null.
354+
*/
355+
output?: string;
356+
357+
/**
358+
* Payload provided to the invocation. This is a string that can be parsed as JSON.
359+
*/
360+
payload?: string;
361+
362+
/**
363+
* Status reason
364+
*/
365+
status_reason?: string;
366+
}
367+
294368
/**
295369
* Union type representing any invocation event.
296370
*/
@@ -340,6 +414,34 @@ export interface InvocationUpdateParams {
340414
output?: string;
341415
}
342416

417+
export interface InvocationListParams extends OffsetPaginationParams {
418+
/**
419+
* Filter results by action name.
420+
*/
421+
action_name?: string;
422+
423+
/**
424+
* Filter results by application name.
425+
*/
426+
app_name?: string;
427+
428+
/**
429+
* Filter results by deployment ID.
430+
*/
431+
deployment_id?: string;
432+
433+
/**
434+
* Show invocations that have started since the given time (RFC timestamps or
435+
* durations like 5m).
436+
*/
437+
since?: string;
438+
439+
/**
440+
* Filter results by invocation status.
441+
*/
442+
status?: 'queued' | 'running' | 'succeeded' | 'failed';
443+
}
444+
343445
export interface InvocationFollowParams {
344446
/**
345447
* Show logs since the given time (RFC timestamps or durations like 5m).
@@ -353,9 +455,12 @@ export declare namespace Invocations {
353455
type InvocationCreateResponse as InvocationCreateResponse,
354456
type InvocationRetrieveResponse as InvocationRetrieveResponse,
355457
type InvocationUpdateResponse as InvocationUpdateResponse,
458+
type InvocationListResponse as InvocationListResponse,
356459
type InvocationFollowResponse as InvocationFollowResponse,
460+
type InvocationListResponsesOffsetPagination as InvocationListResponsesOffsetPagination,
357461
type InvocationCreateParams as InvocationCreateParams,
358462
type InvocationUpdateParams as InvocationUpdateParams,
463+
type InvocationListParams as InvocationListParams,
359464
type InvocationFollowParams as InvocationFollowParams,
360465
};
361466
}

tests/api-resources/invocations.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ describe('resource invocations', () => {
6464
const response = await client.invocations.update('id', { status: 'succeeded', output: 'output' });
6565
});
6666

67+
// Prism tests are disabled
68+
test.skip('list', async () => {
69+
const responsePromise = client.invocations.list();
70+
const rawResponse = await responsePromise.asResponse();
71+
expect(rawResponse).toBeInstanceOf(Response);
72+
const response = await responsePromise;
73+
expect(response).not.toBeInstanceOf(Response);
74+
const dataAndResponse = await responsePromise.withResponse();
75+
expect(dataAndResponse.data).toBe(response);
76+
expect(dataAndResponse.response).toBe(rawResponse);
77+
});
78+
79+
// Prism tests are disabled
80+
test.skip('list: request options and params are passed correctly', async () => {
81+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
82+
await expect(
83+
client.invocations.list(
84+
{
85+
action_name: 'action_name',
86+
app_name: 'app_name',
87+
deployment_id: 'deployment_id',
88+
limit: 1,
89+
offset: 0,
90+
since: '2025-06-20T12:00:00Z',
91+
status: 'queued',
92+
},
93+
{ path: '/_stainless_unknown_path' },
94+
),
95+
).rejects.toThrow(Kernel.NotFoundError);
96+
});
97+
6798
// Prism tests are disabled
6899
test.skip('deleteBrowsers', async () => {
69100
const responsePromise = client.invocations.deleteBrowsers('id');

0 commit comments

Comments
 (0)