@onkernel/sdk 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +1 -1
  3. package/client.d.mts +15 -5
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +15 -5
  6. package/client.d.ts.map +1 -1
  7. package/client.js +31 -22
  8. package/client.js.map +1 -1
  9. package/client.mjs +20 -11
  10. package/client.mjs.map +1 -1
  11. package/core/resource.d.mts +1 -1
  12. package/core/resource.d.mts.map +1 -1
  13. package/core/resource.d.ts +1 -1
  14. package/core/resource.d.ts.map +1 -1
  15. package/core/resource.js.map +1 -1
  16. package/core/resource.mjs.map +1 -1
  17. package/internal/headers.d.mts.map +1 -1
  18. package/internal/headers.d.ts.map +1 -1
  19. package/internal/headers.js +4 -4
  20. package/internal/headers.js.map +1 -1
  21. package/internal/headers.mjs +4 -4
  22. package/internal/headers.mjs.map +1 -1
  23. package/internal/request-options.d.mts +1 -0
  24. package/internal/request-options.d.mts.map +1 -1
  25. package/internal/request-options.d.ts +1 -0
  26. package/internal/request-options.d.ts.map +1 -1
  27. package/internal/request-options.js.map +1 -1
  28. package/internal/request-options.mjs.map +1 -1
  29. package/internal/uploads.js +1 -1
  30. package/internal/uploads.js.map +1 -1
  31. package/internal/uploads.mjs +1 -1
  32. package/internal/uploads.mjs.map +1 -1
  33. package/internal/utils/log.js +1 -1
  34. package/internal/utils/log.js.map +1 -1
  35. package/internal/utils/log.mjs +1 -1
  36. package/internal/utils/log.mjs.map +1 -1
  37. package/internal/utils/path.d.mts.map +1 -1
  38. package/internal/utils/path.d.ts.map +1 -1
  39. package/internal/utils/path.js.map +1 -1
  40. package/internal/utils/path.mjs +1 -1
  41. package/internal/utils/path.mjs.map +1 -1
  42. package/internal/utils/values.d.mts +2 -0
  43. package/internal/utils/values.d.mts.map +1 -1
  44. package/internal/utils/values.d.ts +2 -0
  45. package/internal/utils/values.d.ts.map +1 -1
  46. package/internal/utils/values.js +4 -1
  47. package/internal/utils/values.js.map +1 -1
  48. package/internal/utils/values.mjs +2 -0
  49. package/internal/utils/values.mjs.map +1 -1
  50. package/package.json +1 -1
  51. package/resources/apps/apps.d.mts +1 -5
  52. package/resources/apps/apps.d.mts.map +1 -1
  53. package/resources/apps/apps.d.ts +1 -5
  54. package/resources/apps/apps.d.ts.map +1 -1
  55. package/resources/apps/apps.js +0 -4
  56. package/resources/apps/apps.js.map +1 -1
  57. package/resources/apps/apps.mjs +0 -4
  58. package/resources/apps/apps.mjs.map +1 -1
  59. package/resources/apps/deployments.d.mts +2 -18
  60. package/resources/apps/deployments.d.mts.map +1 -1
  61. package/resources/apps/deployments.d.ts +2 -18
  62. package/resources/apps/deployments.d.ts.map +1 -1
  63. package/resources/apps/deployments.js.map +1 -1
  64. package/resources/apps/deployments.mjs.map +1 -1
  65. package/resources/apps/index.d.mts +0 -1
  66. package/resources/apps/index.d.mts.map +1 -1
  67. package/resources/apps/index.d.ts +0 -1
  68. package/resources/apps/index.d.ts.map +1 -1
  69. package/resources/apps/index.js +1 -3
  70. package/resources/apps/index.js.map +1 -1
  71. package/resources/apps/index.mjs +0 -1
  72. package/resources/apps/index.mjs.map +1 -1
  73. package/resources/deployments.d.mts +255 -0
  74. package/resources/deployments.d.mts.map +1 -0
  75. package/resources/deployments.d.ts +255 -0
  76. package/resources/deployments.d.ts.map +1 -0
  77. package/resources/deployments.js +54 -0
  78. package/resources/deployments.js.map +1 -0
  79. package/resources/deployments.mjs +50 -0
  80. package/resources/deployments.mjs.map +1 -0
  81. package/resources/index.d.mts +3 -0
  82. package/resources/index.d.mts.map +1 -1
  83. package/resources/index.d.ts +3 -0
  84. package/resources/index.d.ts.map +1 -1
  85. package/resources/index.js +7 -1
  86. package/resources/index.js.map +1 -1
  87. package/resources/index.mjs +3 -0
  88. package/resources/index.mjs.map +1 -1
  89. package/resources/{apps/invocations.d.mts → invocations.d.mts} +91 -10
  90. package/resources/invocations.d.mts.map +1 -0
  91. package/resources/{apps/invocations.d.ts → invocations.d.ts} +91 -10
  92. package/resources/invocations.d.ts.map +1 -0
  93. package/resources/invocations.js +83 -0
  94. package/resources/invocations.js.map +1 -0
  95. package/resources/invocations.mjs +79 -0
  96. package/resources/invocations.mjs.map +1 -0
  97. package/resources/shared.d.mts +57 -0
  98. package/resources/shared.d.mts.map +1 -0
  99. package/resources/shared.d.ts +57 -0
  100. package/resources/shared.d.ts.map +1 -0
  101. package/resources/shared.js +4 -0
  102. package/resources/shared.js.map +1 -0
  103. package/resources/shared.mjs +3 -0
  104. package/resources/shared.mjs.map +1 -0
  105. package/src/client.ts +75 -11
  106. package/src/core/resource.ts +1 -1
  107. package/src/internal/headers.ts +5 -5
  108. package/src/internal/request-options.ts +1 -0
  109. package/src/internal/uploads.ts +2 -2
  110. package/src/internal/utils/log.ts +1 -1
  111. package/src/internal/utils/path.ts +1 -1
  112. package/src/internal/utils/values.ts +3 -0
  113. package/src/resources/apps/apps.ts +1 -21
  114. package/src/resources/apps/deployments.ts +2 -21
  115. package/src/resources/apps/index.ts +0 -8
  116. package/src/resources/deployments.ts +326 -0
  117. package/src/resources/index.ts +19 -0
  118. package/src/resources/{apps/invocations.ts → invocations.ts} +120 -10
  119. package/src/resources/shared.ts +69 -0
  120. package/src/version.ts +1 -1
  121. package/version.d.mts +1 -1
  122. package/version.d.ts +1 -1
  123. package/version.js +1 -1
  124. package/version.mjs +1 -1
  125. package/resources/apps/invocations.d.mts.map +0 -1
  126. package/resources/apps/invocations.d.ts.map +0 -1
  127. package/resources/apps/invocations.js +0 -52
  128. package/resources/apps/invocations.js.map +0 -1
  129. package/resources/apps/invocations.mjs +0 -48
  130. package/resources/apps/invocations.mjs.map +0 -1
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
90
90
  return { ...opts, body: await createForm(opts.body, fetch) };
91
91
  };
92
92
 
93
- const supportsFormDataMap = new WeakMap<Fetch, Promise<boolean>>();
93
+ const supportsFormDataMap = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
94
94
 
95
95
  /**
96
96
  * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
@@ -138,7 +138,7 @@ export const createForm = async <T = Record<string, unknown>>(
138
138
 
139
139
  // We check for Blob not File because Bun.File doesn't inherit from File,
140
140
  // but they both inherit from Blob and have a `name` property at runtime.
141
- const isNamedBlob = (value: object) => value instanceof Blob && 'name' in value;
141
+ const isNamedBlob = (value: unknown) => value instanceof Blob && 'name' in value;
142
142
 
143
143
  const isUploadable = (value: unknown) =>
144
144
  typeof value === 'object' &&
@@ -58,7 +58,7 @@ const noopLogger = {
58
58
  debug: noop,
59
59
  };
60
60
 
61
- let cachedLoggers = new WeakMap<Logger, [LogLevel, Logger]>();
61
+ let cachedLoggers = /** @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
62
62
 
63
63
  export function loggerFor(client: Kernel): Logger {
64
64
  const logger = client.logger;
@@ -60,4 +60,4 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
60
60
  /**
61
61
  * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
62
62
  */
63
- export const path = createPathTagFunction(encodeURIPath);
63
+ export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
@@ -9,6 +9,9 @@ export const isAbsoluteURL = (url: string): boolean => {
9
9
  return startsWithSchemeRegexp.test(url);
10
10
  };
11
11
 
12
+ export let isArray = (val: unknown): val is unknown[] => ((isArray = Array.isArray), isArray(val));
13
+ export let isReadonlyArray = isArray as (val: unknown) => val is readonly unknown[];
14
+
12
15
  /** Returns an object if the given value isn't an object, otherwise returns as-is */
13
16
  export function maybeObj(x: unknown): object {
14
17
  if (typeof x !== 'object') {
@@ -8,21 +8,11 @@ import {
8
8
  DeploymentFollowResponse,
9
9
  Deployments,
10
10
  } from './deployments';
11
- import * as InvocationsAPI from './invocations';
12
- import {
13
- InvocationCreateParams,
14
- InvocationCreateResponse,
15
- InvocationRetrieveResponse,
16
- InvocationUpdateParams,
17
- InvocationUpdateResponse,
18
- Invocations,
19
- } from './invocations';
20
11
  import { APIPromise } from '../../core/api-promise';
21
12
  import { RequestOptions } from '../../internal/request-options';
22
13
 
23
14
  export class Apps extends APIResource {
24
15
  deployments: DeploymentsAPI.Deployments = new DeploymentsAPI.Deployments(this._client);
25
- invocations: InvocationsAPI.Invocations = new InvocationsAPI.Invocations(this._client);
26
16
 
27
17
  /**
28
18
  * List applications. Optionally filter by app name and/or version label.
@@ -57,7 +47,7 @@ export namespace AppListResponse {
57
47
  /**
58
48
  * Deployment region code
59
49
  */
60
- region: string;
50
+ region: 'aws.us-east-1a';
61
51
 
62
52
  /**
63
53
  * Version label for the application
@@ -84,7 +74,6 @@ export interface AppListParams {
84
74
  }
85
75
 
86
76
  Apps.Deployments = Deployments;
87
- Apps.Invocations = Invocations;
88
77
 
89
78
  export declare namespace Apps {
90
79
  export { type AppListResponse as AppListResponse, type AppListParams as AppListParams };
@@ -95,13 +84,4 @@ export declare namespace Apps {
95
84
  type DeploymentFollowResponse as DeploymentFollowResponse,
96
85
  type DeploymentCreateParams as DeploymentCreateParams,
97
86
  };
98
-
99
- export {
100
- Invocations as Invocations,
101
- type InvocationCreateResponse as InvocationCreateResponse,
102
- type InvocationRetrieveResponse as InvocationRetrieveResponse,
103
- type InvocationUpdateResponse as InvocationUpdateResponse,
104
- type InvocationCreateParams as InvocationCreateParams,
105
- type InvocationUpdateParams as InvocationUpdateParams,
106
- };
107
87
  }
@@ -1,6 +1,7 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  import { APIResource } from '../../core/resource';
4
+ import * as Shared from '../shared';
4
5
  import { APIPromise } from '../../core/api-promise';
5
6
  import { Stream } from '../../core/streaming';
6
7
  import { type Uploadable } from '../../core/uploads';
@@ -96,7 +97,7 @@ export namespace DeploymentCreateResponse {
96
97
  export type DeploymentFollowResponse =
97
98
  | DeploymentFollowResponse.StateEvent
98
99
  | DeploymentFollowResponse.StateUpdateEvent
99
- | DeploymentFollowResponse.LogEvent;
100
+ | Shared.LogEvent;
100
101
 
101
102
  export namespace DeploymentFollowResponse {
102
103
  /**
@@ -138,26 +139,6 @@ export namespace DeploymentFollowResponse {
138
139
  */
139
140
  timestamp?: string;
140
141
  }
141
-
142
- /**
143
- * A log entry from the application.
144
- */
145
- export interface LogEvent {
146
- /**
147
- * Event type identifier (always "log").
148
- */
149
- event: 'log';
150
-
151
- /**
152
- * Log message text.
153
- */
154
- message: string;
155
-
156
- /**
157
- * Time the log entry was produced.
158
- */
159
- timestamp?: string;
160
- }
161
142
  }
162
143
 
163
144
  export interface DeploymentCreateParams {
@@ -7,11 +7,3 @@ export {
7
7
  type DeploymentFollowResponse,
8
8
  type DeploymentCreateParams,
9
9
  } from './deployments';
10
- export {
11
- Invocations,
12
- type InvocationCreateResponse,
13
- type InvocationRetrieveResponse,
14
- type InvocationUpdateResponse,
15
- type InvocationCreateParams,
16
- type InvocationUpdateParams,
17
- } from './invocations';
@@ -0,0 +1,326 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import * as Shared from './shared';
5
+ import { APIPromise } from '../core/api-promise';
6
+ import { Stream } from '../core/streaming';
7
+ import { type Uploadable } from '../core/uploads';
8
+ import { buildHeaders } from '../internal/headers';
9
+ import { RequestOptions } from '../internal/request-options';
10
+ import { multipartFormRequestOptions } from '../internal/uploads';
11
+ import { path } from '../internal/utils/path';
12
+
13
+ export class Deployments extends APIResource {
14
+ /**
15
+ * Create a new deployment.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const deployment = await client.deployments.create({
20
+ * entrypoint_rel_path: 'src/app.py',
21
+ * file: fs.createReadStream('path/to/file'),
22
+ * });
23
+ * ```
24
+ */
25
+ create(body: DeploymentCreateParams, options?: RequestOptions): APIPromise<DeploymentCreateResponse> {
26
+ return this._client.post('/deployments', multipartFormRequestOptions({ body, ...options }, this._client));
27
+ }
28
+
29
+ /**
30
+ * Get information about a deployment's status.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const deployment = await client.deployments.retrieve('id');
35
+ * ```
36
+ */
37
+ retrieve(id: string, options?: RequestOptions): APIPromise<DeploymentRetrieveResponse> {
38
+ return this._client.get(path`/deployments/${id}`, options);
39
+ }
40
+
41
+ /**
42
+ * Establishes a Server-Sent Events (SSE) stream that delivers real-time logs and
43
+ * status updates for a deployment. The stream terminates automatically once the
44
+ * deployment reaches a terminal state.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const response = await client.deployments.follow('id');
49
+ * ```
50
+ */
51
+ follow(id: string, options?: RequestOptions): APIPromise<Stream<DeploymentFollowResponse>> {
52
+ return this._client.get(path`/deployments/${id}/events`, {
53
+ ...options,
54
+ headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]),
55
+ stream: true,
56
+ }) as APIPromise<Stream<DeploymentFollowResponse>>;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * An event representing the current state of a deployment.
62
+ */
63
+ export interface DeploymentStateEvent {
64
+ /**
65
+ * Deployment record information.
66
+ */
67
+ deployment: DeploymentStateEvent.Deployment;
68
+
69
+ /**
70
+ * Event type identifier (always "deployment_state").
71
+ */
72
+ event: 'deployment_state';
73
+
74
+ /**
75
+ * Time the state was reported.
76
+ */
77
+ timestamp: string;
78
+ }
79
+
80
+ export namespace DeploymentStateEvent {
81
+ /**
82
+ * Deployment record information.
83
+ */
84
+ export interface Deployment {
85
+ /**
86
+ * Unique identifier for the deployment
87
+ */
88
+ id: string;
89
+
90
+ /**
91
+ * Timestamp when the deployment was created
92
+ */
93
+ created_at: string;
94
+
95
+ /**
96
+ * Deployment region code
97
+ */
98
+ region: 'aws.us-east-1a';
99
+
100
+ /**
101
+ * Current status of the deployment
102
+ */
103
+ status: 'queued' | 'in_progress' | 'running' | 'failed' | 'stopped';
104
+
105
+ /**
106
+ * Relative path to the application entrypoint
107
+ */
108
+ entrypoint_rel_path?: string;
109
+
110
+ /**
111
+ * Environment variables configured for this deployment
112
+ */
113
+ env_vars?: Record<string, string>;
114
+
115
+ /**
116
+ * Status reason
117
+ */
118
+ status_reason?: string;
119
+
120
+ /**
121
+ * Timestamp when the deployment was last updated
122
+ */
123
+ updated_at?: string | null;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Deployment record information.
129
+ */
130
+ export interface DeploymentCreateResponse {
131
+ /**
132
+ * Unique identifier for the deployment
133
+ */
134
+ id: string;
135
+
136
+ /**
137
+ * Timestamp when the deployment was created
138
+ */
139
+ created_at: string;
140
+
141
+ /**
142
+ * Deployment region code
143
+ */
144
+ region: 'aws.us-east-1a';
145
+
146
+ /**
147
+ * Current status of the deployment
148
+ */
149
+ status: 'queued' | 'in_progress' | 'running' | 'failed' | 'stopped';
150
+
151
+ /**
152
+ * Relative path to the application entrypoint
153
+ */
154
+ entrypoint_rel_path?: string;
155
+
156
+ /**
157
+ * Environment variables configured for this deployment
158
+ */
159
+ env_vars?: Record<string, string>;
160
+
161
+ /**
162
+ * Status reason
163
+ */
164
+ status_reason?: string;
165
+
166
+ /**
167
+ * Timestamp when the deployment was last updated
168
+ */
169
+ updated_at?: string | null;
170
+ }
171
+
172
+ /**
173
+ * Deployment record information.
174
+ */
175
+ export interface DeploymentRetrieveResponse {
176
+ /**
177
+ * Unique identifier for the deployment
178
+ */
179
+ id: string;
180
+
181
+ /**
182
+ * Timestamp when the deployment was created
183
+ */
184
+ created_at: string;
185
+
186
+ /**
187
+ * Deployment region code
188
+ */
189
+ region: 'aws.us-east-1a';
190
+
191
+ /**
192
+ * Current status of the deployment
193
+ */
194
+ status: 'queued' | 'in_progress' | 'running' | 'failed' | 'stopped';
195
+
196
+ /**
197
+ * Relative path to the application entrypoint
198
+ */
199
+ entrypoint_rel_path?: string;
200
+
201
+ /**
202
+ * Environment variables configured for this deployment
203
+ */
204
+ env_vars?: Record<string, string>;
205
+
206
+ /**
207
+ * Status reason
208
+ */
209
+ status_reason?: string;
210
+
211
+ /**
212
+ * Timestamp when the deployment was last updated
213
+ */
214
+ updated_at?: string | null;
215
+ }
216
+
217
+ /**
218
+ * Union type representing any deployment event.
219
+ */
220
+ export type DeploymentFollowResponse =
221
+ | Shared.LogEvent
222
+ | DeploymentStateEvent
223
+ | DeploymentFollowResponse.AppVersionSummaryEvent
224
+ | Shared.ErrorEvent;
225
+
226
+ export namespace DeploymentFollowResponse {
227
+ /**
228
+ * Summary of an application version.
229
+ */
230
+ export interface AppVersionSummaryEvent {
231
+ /**
232
+ * Unique identifier for the app version
233
+ */
234
+ id: string;
235
+
236
+ /**
237
+ * List of actions available on the app
238
+ */
239
+ actions: Array<AppVersionSummaryEvent.Action>;
240
+
241
+ /**
242
+ * Name of the application
243
+ */
244
+ app_name: string;
245
+
246
+ /**
247
+ * Event type identifier (always "app_version_summary").
248
+ */
249
+ event: 'app_version_summary';
250
+
251
+ /**
252
+ * Deployment region code
253
+ */
254
+ region: 'aws.us-east-1a';
255
+
256
+ /**
257
+ * Time the state was reported.
258
+ */
259
+ timestamp: string;
260
+
261
+ /**
262
+ * Version label for the application
263
+ */
264
+ version: string;
265
+
266
+ /**
267
+ * Environment variables configured for this app version
268
+ */
269
+ env_vars?: Record<string, string>;
270
+ }
271
+
272
+ export namespace AppVersionSummaryEvent {
273
+ /**
274
+ * An action available on the app
275
+ */
276
+ export interface Action {
277
+ /**
278
+ * Name of the action
279
+ */
280
+ name: string;
281
+ }
282
+ }
283
+ }
284
+
285
+ export interface DeploymentCreateParams {
286
+ /**
287
+ * Relative path to the entrypoint of the application
288
+ */
289
+ entrypoint_rel_path: string;
290
+
291
+ /**
292
+ * ZIP file containing the application source directory
293
+ */
294
+ file: Uploadable;
295
+
296
+ /**
297
+ * Map of environment variables to set for the deployed application. Each key-value
298
+ * pair represents an environment variable.
299
+ */
300
+ env_vars?: Record<string, string>;
301
+
302
+ /**
303
+ * Allow overwriting an existing app version
304
+ */
305
+ force?: boolean;
306
+
307
+ /**
308
+ * Region for deployment. Currently we only support "aws.us-east-1a"
309
+ */
310
+ region?: 'aws.us-east-1a';
311
+
312
+ /**
313
+ * Version of the application. Can be any string.
314
+ */
315
+ version?: string;
316
+ }
317
+
318
+ export declare namespace Deployments {
319
+ export {
320
+ type DeploymentStateEvent as DeploymentStateEvent,
321
+ type DeploymentCreateResponse as DeploymentCreateResponse,
322
+ type DeploymentRetrieveResponse as DeploymentRetrieveResponse,
323
+ type DeploymentFollowResponse as DeploymentFollowResponse,
324
+ type DeploymentCreateParams as DeploymentCreateParams,
325
+ };
326
+ }
@@ -1,5 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
+ export * from './shared';
3
4
  export { Apps, type AppListResponse, type AppListParams } from './apps/apps';
4
5
  export {
5
6
  Browsers,
@@ -10,3 +11,21 @@ export {
10
11
  type BrowserCreateParams,
11
12
  type BrowserDeleteParams,
12
13
  } from './browsers';
14
+ export {
15
+ Deployments,
16
+ type DeploymentStateEvent,
17
+ type DeploymentCreateResponse,
18
+ type DeploymentRetrieveResponse,
19
+ type DeploymentFollowResponse,
20
+ type DeploymentCreateParams,
21
+ } from './deployments';
22
+ export {
23
+ Invocations,
24
+ type InvocationStateEvent,
25
+ type InvocationCreateResponse,
26
+ type InvocationRetrieveResponse,
27
+ type InvocationUpdateResponse,
28
+ type InvocationFollowResponse,
29
+ type InvocationCreateParams,
30
+ type InvocationUpdateParams,
31
+ } from './invocations';
@@ -1,9 +1,12 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { APIResource } from '../../core/resource';
4
- import { APIPromise } from '../../core/api-promise';
5
- import { RequestOptions } from '../../internal/request-options';
6
- import { path } from '../../internal/utils/path';
3
+ import { APIResource } from '../core/resource';
4
+ import * as Shared from './shared';
5
+ import { APIPromise } from '../core/api-promise';
6
+ import { Stream } from '../core/streaming';
7
+ import { buildHeaders } from '../internal/headers';
8
+ import { RequestOptions } from '../internal/request-options';
9
+ import { path } from '../internal/utils/path';
7
10
 
8
11
  export class Invocations extends APIResource {
9
12
  /**
@@ -11,7 +14,7 @@ export class Invocations extends APIResource {
11
14
  *
12
15
  * @example
13
16
  * ```ts
14
- * const invocation = await client.apps.invocations.create({
17
+ * const invocation = await client.invocations.create({
15
18
  * action_name: 'analyze',
16
19
  * app_name: 'my-app',
17
20
  * version: '1.0.0',
@@ -27,7 +30,7 @@ export class Invocations extends APIResource {
27
30
  *
28
31
  * @example
29
32
  * ```ts
30
- * const invocation = await client.apps.invocations.retrieve(
33
+ * const invocation = await client.invocations.retrieve(
31
34
  * 'rr33xuugxj9h0bkf1rdt2bet',
32
35
  * );
33
36
  * ```
@@ -41,10 +44,9 @@ export class Invocations extends APIResource {
41
44
  *
42
45
  * @example
43
46
  * ```ts
44
- * const invocation = await client.apps.invocations.update(
45
- * 'id',
46
- * { status: 'succeeded' },
47
- * );
47
+ * const invocation = await client.invocations.update('id', {
48
+ * status: 'succeeded',
49
+ * });
48
50
  * ```
49
51
  */
50
52
  update(
@@ -54,6 +56,107 @@ export class Invocations extends APIResource {
54
56
  ): APIPromise<InvocationUpdateResponse> {
55
57
  return this._client.patch(path`/invocations/${id}`, { body, ...options });
56
58
  }
59
+
60
+ /**
61
+ * Delete all browser sessions created within the specified invocation.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * await client.invocations.deleteBrowsers('id');
66
+ * ```
67
+ */
68
+ deleteBrowsers(id: string, options?: RequestOptions): APIPromise<void> {
69
+ return this._client.delete(path`/invocations/${id}/browsers`, {
70
+ ...options,
71
+ headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Establishes a Server-Sent Events (SSE) stream that delivers real-time logs and
77
+ * status updates for an invocation. The stream terminates automatically once the
78
+ * invocation reaches a terminal state.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const response = await client.invocations.follow('id');
83
+ * ```
84
+ */
85
+ follow(id: string, options?: RequestOptions): APIPromise<Stream<InvocationFollowResponse>> {
86
+ return this._client.get(path`/invocations/${id}/events`, {
87
+ ...options,
88
+ headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]),
89
+ stream: true,
90
+ }) as APIPromise<Stream<InvocationFollowResponse>>;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * An event representing the current state of an invocation.
96
+ */
97
+ export interface InvocationStateEvent {
98
+ /**
99
+ * Event type identifier (always "invocation_state").
100
+ */
101
+ event: 'invocation_state';
102
+
103
+ invocation: InvocationStateEvent.Invocation;
104
+
105
+ /**
106
+ * Time the state was reported.
107
+ */
108
+ timestamp: string;
109
+ }
110
+
111
+ export namespace InvocationStateEvent {
112
+ export interface Invocation {
113
+ /**
114
+ * ID of the invocation
115
+ */
116
+ id: string;
117
+
118
+ /**
119
+ * Name of the action invoked
120
+ */
121
+ action_name: string;
122
+
123
+ /**
124
+ * Name of the application
125
+ */
126
+ app_name: string;
127
+
128
+ /**
129
+ * RFC 3339 Nanoseconds timestamp when the invocation started
130
+ */
131
+ started_at: string;
132
+
133
+ /**
134
+ * Status of the invocation
135
+ */
136
+ status: 'queued' | 'running' | 'succeeded' | 'failed';
137
+
138
+ /**
139
+ * RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
140
+ * running)
141
+ */
142
+ finished_at?: string | null;
143
+
144
+ /**
145
+ * Output produced by the action, rendered as a JSON string. This could be: string,
146
+ * number, boolean, array, object, or null.
147
+ */
148
+ output?: string;
149
+
150
+ /**
151
+ * Payload provided to the invocation. This is a string that can be parsed as JSON.
152
+ */
153
+ payload?: string;
154
+
155
+ /**
156
+ * Status reason
157
+ */
158
+ status_reason?: string;
159
+ }
57
160
  }
58
161
 
59
162
  export interface InvocationCreateResponse {
@@ -177,6 +280,11 @@ export interface InvocationUpdateResponse {
177
280
  status_reason?: string;
178
281
  }
179
282
 
283
+ /**
284
+ * Union type representing any invocation event.
285
+ */
286
+ export type InvocationFollowResponse = Shared.LogEvent | InvocationStateEvent | Shared.ErrorEvent;
287
+
180
288
  export interface InvocationCreateParams {
181
289
  /**
182
290
  * Name of the action to invoke
@@ -219,9 +327,11 @@ export interface InvocationUpdateParams {
219
327
 
220
328
  export declare namespace Invocations {
221
329
  export {
330
+ type InvocationStateEvent as InvocationStateEvent,
222
331
  type InvocationCreateResponse as InvocationCreateResponse,
223
332
  type InvocationRetrieveResponse as InvocationRetrieveResponse,
224
333
  type InvocationUpdateResponse as InvocationUpdateResponse,
334
+ type InvocationFollowResponse as InvocationFollowResponse,
225
335
  type InvocationCreateParams as InvocationCreateParams,
226
336
  type InvocationUpdateParams as InvocationUpdateParams,
227
337
  };