Skip to content

Commit 178712c

Browse files
feat(api): add since parameter to deployment logs endpoint
1 parent 73ff4fa commit 178712c

File tree

10 files changed

+64
-8
lines changed

10 files changed

+64
-8
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 16
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-b019e469425a59061f37c5fdc7a131a5291c66134ef0627db4f06bb1f4af0b15.yml
3-
openapi_spec_hash: f66a3c2efddb168db9539ba2507b10b8
4-
config_hash: aae6721b2be9ec8565dfc8f7eadfe105
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-2aec229ccf91f7c1ac95aa675ea2a59bd61af9e363a22c3b49677992f1eeb16a.yml
3+
openapi_spec_hash: c80cd5d52a79cd5366a76d4a825bd27a
4+
config_hash: b8e1fff080fbaa22656ab0a57b591777

api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Types:
55
- <code><a href="./src/resources/shared.ts">ErrorDetail</a></code>
66
- <code><a href="./src/resources/shared.ts">ErrorEvent</a></code>
77
- <code><a href="./src/resources/shared.ts">ErrorModel</a></code>
8+
- <code><a href="./src/resources/shared.ts">HeartbeatEvent</a></code>
89
- <code><a href="./src/resources/shared.ts">LogEvent</a></code>
910

1011
# Deployments
@@ -20,7 +21,7 @@ Methods:
2021

2122
- <code title="post /deployments">client.deployments.<a href="./src/resources/deployments.ts">create</a>({ ...params }) -> DeploymentCreateResponse</code>
2223
- <code title="get /deployments/{id}">client.deployments.<a href="./src/resources/deployments.ts">retrieve</a>(id) -> DeploymentRetrieveResponse</code>
23-
- <code title="get /deployments/{id}/events">client.deployments.<a href="./src/resources/deployments.ts">follow</a>(id) -> DeploymentFollowResponse</code>
24+
- <code title="get /deployments/{id}/events">client.deployments.<a href="./src/resources/deployments.ts">follow</a>(id, { ...params }) -> DeploymentFollowResponse</code>
2425

2526
# Apps
2627

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import {
2929
DeploymentCreateParams,
3030
DeploymentCreateResponse,
31+
DeploymentFollowParams,
3132
DeploymentFollowResponse,
3233
DeploymentRetrieveResponse,
3334
DeploymentStateEvent,
@@ -790,6 +791,7 @@ export declare namespace Kernel {
790791
type DeploymentRetrieveResponse as DeploymentRetrieveResponse,
791792
type DeploymentFollowResponse as DeploymentFollowResponse,
792793
type DeploymentCreateParams as DeploymentCreateParams,
794+
type DeploymentFollowParams as DeploymentFollowParams,
793795
};
794796

795797
export { Apps as Apps, type AppListResponse as AppListResponse, type AppListParams as AppListParams };
@@ -818,5 +820,6 @@ export declare namespace Kernel {
818820
export type ErrorDetail = API.ErrorDetail;
819821
export type ErrorEvent = API.ErrorEvent;
820822
export type ErrorModel = API.ErrorModel;
823+
export type HeartbeatEvent = API.HeartbeatEvent;
821824
export type LogEvent = API.LogEvent;
822825
}

src/resources/apps/apps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export namespace AppListResponse {
4444
*/
4545
app_name: string;
4646

47+
/**
48+
* Deployment ID
49+
*/
50+
deployment: string;
51+
4752
/**
4853
* Deployment region code
4954
*/

src/resources/apps/deployments.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export namespace DeploymentCreateResponse {
9797
export type DeploymentFollowResponse =
9898
| DeploymentFollowResponse.StateEvent
9999
| DeploymentFollowResponse.StateUpdateEvent
100-
| Shared.LogEvent;
100+
| Shared.LogEvent
101+
| Shared.HeartbeatEvent;
101102

102103
export namespace DeploymentFollowResponse {
103104
/**

src/resources/deployments.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ export class Deployments extends APIResource {
4848
* const response = await client.deployments.follow('id');
4949
* ```
5050
*/
51-
follow(id: string, options?: RequestOptions): APIPromise<Stream<DeploymentFollowResponse>> {
51+
follow(
52+
id: string,
53+
query: DeploymentFollowParams | undefined = {},
54+
options?: RequestOptions,
55+
): APIPromise<Stream<DeploymentFollowResponse>> {
5256
return this._client.get(path`/deployments/${id}/events`, {
57+
query,
5358
...options,
5459
headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]),
5560
stream: true,
@@ -221,7 +226,8 @@ export type DeploymentFollowResponse =
221226
| Shared.LogEvent
222227
| DeploymentStateEvent
223228
| DeploymentFollowResponse.AppVersionSummaryEvent
224-
| Shared.ErrorEvent;
229+
| Shared.ErrorEvent
230+
| Shared.HeartbeatEvent;
225231

226232
export namespace DeploymentFollowResponse {
227233
/**
@@ -315,12 +321,20 @@ export interface DeploymentCreateParams {
315321
version?: string;
316322
}
317323

324+
export interface DeploymentFollowParams {
325+
/**
326+
* Show logs since the given time (RFC timestamps or durations like 5m).
327+
*/
328+
since?: string;
329+
}
330+
318331
export declare namespace Deployments {
319332
export {
320333
type DeploymentStateEvent as DeploymentStateEvent,
321334
type DeploymentCreateResponse as DeploymentCreateResponse,
322335
type DeploymentRetrieveResponse as DeploymentRetrieveResponse,
323336
type DeploymentFollowResponse as DeploymentFollowResponse,
324337
type DeploymentCreateParams as DeploymentCreateParams,
338+
type DeploymentFollowParams as DeploymentFollowParams,
325339
};
326340
}

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export {
1818
type DeploymentRetrieveResponse,
1919
type DeploymentFollowResponse,
2020
type DeploymentCreateParams,
21+
type DeploymentFollowParams,
2122
} from './deployments';
2223
export {
2324
Invocations,

src/resources/invocations.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ export interface InvocationUpdateResponse {
283283
/**
284284
* Union type representing any invocation event.
285285
*/
286-
export type InvocationFollowResponse = Shared.LogEvent | InvocationStateEvent | Shared.ErrorEvent;
286+
export type InvocationFollowResponse =
287+
| Shared.LogEvent
288+
| InvocationStateEvent
289+
| Shared.ErrorEvent
290+
| Shared.HeartbeatEvent;
287291

288292
export interface InvocationCreateParams {
289293
/**

src/resources/shared.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ export interface ErrorModel {
4848
inner_error?: ErrorDetail;
4949
}
5050

51+
/**
52+
* Heartbeat event sent periodically to keep SSE connection alive.
53+
*/
54+
export interface HeartbeatEvent {
55+
/**
56+
* Event type identifier (always "sse_heartbeat").
57+
*/
58+
event: 'sse_heartbeat';
59+
60+
/**
61+
* Time the heartbeat was sent.
62+
*/
63+
timestamp: string;
64+
}
65+
5166
/**
5267
* A log entry from the application.
5368
*/

tests/api-resources/deployments.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ describe('resource deployments', () => {
5858
expect(dataAndResponse.data).toBe(response);
5959
expect(dataAndResponse.response).toBe(rawResponse);
6060
});
61+
62+
// skipped: currently no good way to test endpoints with content type text/event-stream, Prism mock server will fail
63+
test.skip('follow: request options and params are passed correctly', async () => {
64+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
65+
await expect(
66+
client.deployments.follow(
67+
'id',
68+
{ since: '2025-06-20T12:00:00Z' },
69+
{ path: '/_stainless_unknown_path' },
70+
),
71+
).rejects.toThrow(Kernel.NotFoundError);
72+
});
6173
});

0 commit comments

Comments
 (0)