@onkernel/sdk 0.11.0 → 0.11.2

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 (92) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +31 -0
  3. package/client.d.mts +11 -2
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +11 -2
  6. package/client.d.ts.map +1 -1
  7. package/client.js +11 -0
  8. package/client.js.map +1 -1
  9. package/client.mjs +11 -0
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +53 -0
  12. package/core/pagination.d.mts.map +1 -0
  13. package/core/pagination.d.ts +53 -0
  14. package/core/pagination.d.ts.map +1 -0
  15. package/core/pagination.js +110 -0
  16. package/core/pagination.js.map +1 -0
  17. package/core/pagination.mjs +104 -0
  18. package/core/pagination.mjs.map +1 -0
  19. package/index.d.mts +1 -0
  20. package/index.d.mts.map +1 -1
  21. package/index.d.ts +1 -0
  22. package/index.d.ts.map +1 -1
  23. package/index.js +3 -1
  24. package/index.js.map +1 -1
  25. package/index.mjs +1 -0
  26. package/index.mjs.map +1 -1
  27. package/internal/utils/values.js +3 -3
  28. package/internal/utils/values.js.map +1 -1
  29. package/internal/utils/values.mjs +3 -3
  30. package/internal/utils/values.mjs.map +1 -1
  31. package/package.json +11 -1
  32. package/pagination.d.mts +2 -0
  33. package/pagination.d.mts.map +1 -0
  34. package/pagination.d.ts +2 -0
  35. package/pagination.d.ts.map +1 -0
  36. package/pagination.js +6 -0
  37. package/pagination.js.map +1 -0
  38. package/pagination.mjs +2 -0
  39. package/pagination.mjs.map +1 -0
  40. package/resources/browsers/browsers.d.mts +9 -1
  41. package/resources/browsers/browsers.d.mts.map +1 -1
  42. package/resources/browsers/browsers.d.ts +9 -1
  43. package/resources/browsers/browsers.d.ts.map +1 -1
  44. package/resources/browsers/browsers.js.map +1 -1
  45. package/resources/browsers/browsers.mjs.map +1 -1
  46. package/resources/deployments.d.mts +45 -43
  47. package/resources/deployments.d.mts.map +1 -1
  48. package/resources/deployments.d.ts +45 -43
  49. package/resources/deployments.d.ts.map +1 -1
  50. package/resources/deployments.js +9 -2
  51. package/resources/deployments.js.map +1 -1
  52. package/resources/deployments.mjs +9 -2
  53. package/resources/deployments.mjs.map +1 -1
  54. package/resources/index.d.mts +2 -1
  55. package/resources/index.d.mts.map +1 -1
  56. package/resources/index.d.ts +2 -1
  57. package/resources/index.d.ts.map +1 -1
  58. package/resources/index.js +3 -1
  59. package/resources/index.js.map +1 -1
  60. package/resources/index.mjs +1 -0
  61. package/resources/index.mjs.map +1 -1
  62. package/resources/invocations.d.mts +2 -1
  63. package/resources/invocations.d.mts.map +1 -1
  64. package/resources/invocations.d.ts +2 -1
  65. package/resources/invocations.d.ts.map +1 -1
  66. package/resources/invocations.js +2 -1
  67. package/resources/invocations.js.map +1 -1
  68. package/resources/invocations.mjs +2 -1
  69. package/resources/invocations.mjs.map +1 -1
  70. package/resources/proxies.d.mts +512 -0
  71. package/resources/proxies.d.mts.map +1 -0
  72. package/resources/proxies.d.ts +512 -0
  73. package/resources/proxies.d.ts.map +1 -0
  74. package/resources/proxies.js +38 -0
  75. package/resources/proxies.js.map +1 -0
  76. package/resources/proxies.mjs +34 -0
  77. package/resources/proxies.mjs.map +1 -0
  78. package/src/client.ts +46 -0
  79. package/src/core/pagination.ts +167 -0
  80. package/src/index.ts +1 -0
  81. package/src/internal/utils/values.ts +3 -3
  82. package/src/pagination.ts +2 -0
  83. package/src/resources/browsers/browsers.ts +10 -1
  84. package/src/resources/deployments.ts +48 -42
  85. package/src/resources/index.ts +8 -0
  86. package/src/resources/invocations.ts +2 -1
  87. package/src/resources/proxies.ts +876 -0
  88. package/src/version.ts +1 -1
  89. package/version.d.mts +1 -1
  90. package/version.d.ts +1 -1
  91. package/version.js +1 -1
  92. package/version.mjs +1 -1
package/src/client.ts CHANGED
@@ -13,6 +13,8 @@ import * as Shims from './internal/shims';
13
13
  import * as Opts from './internal/request-options';
14
14
  import { VERSION } from './version';
15
15
  import * as Errors from './core/error';
16
+ import * as Pagination from './core/pagination';
17
+ import { AbstractPage, type OffsetPaginationParams, OffsetPaginationResponse } from './core/pagination';
16
18
  import * as Uploads from './core/uploads';
17
19
  import * as API from './resources/index';
18
20
  import { APIPromise } from './core/api-promise';
@@ -24,6 +26,7 @@ import {
24
26
  DeploymentFollowResponse,
25
27
  DeploymentListParams,
26
28
  DeploymentListResponse,
29
+ DeploymentListResponsesOffsetPagination,
27
30
  DeploymentRetrieveResponse,
28
31
  DeploymentStateEvent,
29
32
  Deployments,
@@ -40,6 +43,13 @@ import {
40
43
  Invocations,
41
44
  } from './resources/invocations';
42
45
  import { ProfileCreateParams, ProfileListResponse, Profiles } from './resources/profiles';
46
+ import {
47
+ Proxies,
48
+ ProxyCreateParams,
49
+ ProxyCreateResponse,
50
+ ProxyListResponse,
51
+ ProxyRetrieveResponse,
52
+ } from './resources/proxies';
43
53
  import {
44
54
  BrowserCreateParams,
45
55
  BrowserCreateResponse,
@@ -551,6 +561,25 @@ export class Kernel {
551
561
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
552
562
  }
553
563
 
564
+ getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
565
+ path: string,
566
+ Page: new (...args: any[]) => PageClass,
567
+ opts?: RequestOptions,
568
+ ): Pagination.PagePromise<PageClass, Item> {
569
+ return this.requestAPIList(Page, { method: 'get', path, ...opts });
570
+ }
571
+
572
+ requestAPIList<
573
+ Item = unknown,
574
+ PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
575
+ >(
576
+ Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
577
+ options: FinalRequestOptions,
578
+ ): Pagination.PagePromise<PageClass, Item> {
579
+ const request = this.makeRequest(options, null, undefined);
580
+ return new Pagination.PagePromise<PageClass, Item>(this as any as Kernel, request, Page);
581
+ }
582
+
554
583
  async fetchWithTimeout(
555
584
  url: RequestInfo,
556
585
  init: RequestInit | undefined,
@@ -798,6 +827,7 @@ export class Kernel {
798
827
  invocations: API.Invocations = new API.Invocations(this);
799
828
  browsers: API.Browsers = new API.Browsers(this);
800
829
  profiles: API.Profiles = new API.Profiles(this);
830
+ proxies: API.Proxies = new API.Proxies(this);
801
831
  }
802
832
 
803
833
  Kernel.Deployments = Deployments;
@@ -805,10 +835,17 @@ Kernel.Apps = Apps;
805
835
  Kernel.Invocations = Invocations;
806
836
  Kernel.Browsers = Browsers;
807
837
  Kernel.Profiles = Profiles;
838
+ Kernel.Proxies = Proxies;
808
839
 
809
840
  export declare namespace Kernel {
810
841
  export type RequestOptions = Opts.RequestOptions;
811
842
 
843
+ export import OffsetPagination = Pagination.OffsetPagination;
844
+ export {
845
+ type OffsetPaginationParams as OffsetPaginationParams,
846
+ type OffsetPaginationResponse as OffsetPaginationResponse,
847
+ };
848
+
812
849
  export {
813
850
  Deployments as Deployments,
814
851
  type DeploymentStateEvent as DeploymentStateEvent,
@@ -816,6 +853,7 @@ export declare namespace Kernel {
816
853
  type DeploymentRetrieveResponse as DeploymentRetrieveResponse,
817
854
  type DeploymentListResponse as DeploymentListResponse,
818
855
  type DeploymentFollowResponse as DeploymentFollowResponse,
856
+ type DeploymentListResponsesOffsetPagination as DeploymentListResponsesOffsetPagination,
819
857
  type DeploymentCreateParams as DeploymentCreateParams,
820
858
  type DeploymentListParams as DeploymentListParams,
821
859
  type DeploymentFollowParams as DeploymentFollowParams,
@@ -851,6 +889,14 @@ export declare namespace Kernel {
851
889
  type ProfileCreateParams as ProfileCreateParams,
852
890
  };
853
891
 
892
+ export {
893
+ Proxies as Proxies,
894
+ type ProxyCreateResponse as ProxyCreateResponse,
895
+ type ProxyRetrieveResponse as ProxyRetrieveResponse,
896
+ type ProxyListResponse as ProxyListResponse,
897
+ type ProxyCreateParams as ProxyCreateParams,
898
+ };
899
+
854
900
  export type AppAction = API.AppAction;
855
901
  export type ErrorDetail = API.ErrorDetail;
856
902
  export type ErrorEvent = API.ErrorEvent;
@@ -0,0 +1,167 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { KernelError } from './error';
4
+ import { FinalRequestOptions } from '../internal/request-options';
5
+ import { defaultParseResponse } from '../internal/parse';
6
+ import { type Kernel } from '../client';
7
+ import { APIPromise } from './api-promise';
8
+ import { type APIResponseProps } from '../internal/parse';
9
+ import { maybeCoerceBoolean, maybeCoerceInteger, maybeObj } from '../internal/utils/values';
10
+
11
+ export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
12
+
13
+ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
14
+ #client: Kernel;
15
+ protected options: FinalRequestOptions;
16
+
17
+ protected response: Response;
18
+ protected body: unknown;
19
+
20
+ constructor(client: Kernel, response: Response, body: unknown, options: FinalRequestOptions) {
21
+ this.#client = client;
22
+ this.options = options;
23
+ this.response = response;
24
+ this.body = body;
25
+ }
26
+
27
+ abstract nextPageRequestOptions(): PageRequestOptions | null;
28
+
29
+ abstract getPaginatedItems(): Item[];
30
+
31
+ hasNextPage(): boolean {
32
+ const items = this.getPaginatedItems();
33
+ if (!items.length) return false;
34
+ return this.nextPageRequestOptions() != null;
35
+ }
36
+
37
+ async getNextPage(): Promise<this> {
38
+ const nextOptions = this.nextPageRequestOptions();
39
+ if (!nextOptions) {
40
+ throw new KernelError(
41
+ 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
42
+ );
43
+ }
44
+
45
+ return await this.#client.requestAPIList(this.constructor as any, nextOptions);
46
+ }
47
+
48
+ async *iterPages(): AsyncGenerator<this> {
49
+ let page: this = this;
50
+ yield page;
51
+ while (page.hasNextPage()) {
52
+ page = await page.getNextPage();
53
+ yield page;
54
+ }
55
+ }
56
+
57
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
58
+ for await (const page of this.iterPages()) {
59
+ for (const item of page.getPaginatedItems()) {
60
+ yield item;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * This subclass of Promise will resolve to an instantiated Page once the request completes.
68
+ *
69
+ * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
70
+ *
71
+ * for await (const item of client.items.list()) {
72
+ * console.log(item)
73
+ * }
74
+ */
75
+ export class PagePromise<
76
+ PageClass extends AbstractPage<Item>,
77
+ Item = ReturnType<PageClass['getPaginatedItems']>[number],
78
+ >
79
+ extends APIPromise<PageClass>
80
+ implements AsyncIterable<Item>
81
+ {
82
+ constructor(
83
+ client: Kernel,
84
+ request: Promise<APIResponseProps>,
85
+ Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
86
+ ) {
87
+ super(
88
+ client,
89
+ request,
90
+ async (client, props) =>
91
+ new Page(client, props.response, await defaultParseResponse(client, props), props.options),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Allow auto-paginating iteration on an unawaited list call, eg:
97
+ *
98
+ * for await (const item of client.items.list()) {
99
+ * console.log(item)
100
+ * }
101
+ */
102
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
103
+ const page = await this;
104
+ for await (const item of page) {
105
+ yield item;
106
+ }
107
+ }
108
+ }
109
+
110
+ export type OffsetPaginationResponse<Item> = Item[];
111
+
112
+ export interface OffsetPaginationParams {
113
+ offset?: number;
114
+
115
+ limit?: number;
116
+ }
117
+
118
+ export class OffsetPagination<Item> extends AbstractPage<Item> {
119
+ items: Array<Item>;
120
+
121
+ has_more: boolean | null;
122
+
123
+ next_offset: number | null;
124
+
125
+ constructor(
126
+ client: Kernel,
127
+ response: Response,
128
+ body: OffsetPaginationResponse<Item>,
129
+ options: FinalRequestOptions,
130
+ ) {
131
+ super(client, response, body, options);
132
+
133
+ this.items = body || [];
134
+ this.has_more = maybeCoerceBoolean(this.response.headers.get('x-has-more')) ?? null;
135
+ this.next_offset = maybeCoerceInteger(this.response.headers.get('x-next-offset')) ?? null;
136
+ }
137
+
138
+ getPaginatedItems(): Item[] {
139
+ return this.items ?? [];
140
+ }
141
+
142
+ override hasNextPage(): boolean {
143
+ if (this.has_more === false) {
144
+ return false;
145
+ }
146
+
147
+ return super.hasNextPage();
148
+ }
149
+
150
+ nextPageRequestOptions(): PageRequestOptions | null {
151
+ const offset = this.next_offset;
152
+ if (!offset) {
153
+ return null;
154
+ }
155
+
156
+ const length = this.getPaginatedItems().length;
157
+ const currentCount = offset + length;
158
+
159
+ return {
160
+ ...this.options,
161
+ query: {
162
+ ...maybeObj(this.options.query),
163
+ offset: currentCount,
164
+ },
165
+ };
166
+ }
167
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export { Kernel as default } from './client';
5
5
  export { type Uploadable, toFile } from './core/uploads';
6
6
  export { APIPromise } from './core/api-promise';
7
7
  export { Kernel, type ClientOptions } from './client';
8
+ export { PagePromise } from './core/pagination';
8
9
  export {
9
10
  KernelError,
10
11
  APIError,
@@ -76,21 +76,21 @@ export const coerceBoolean = (value: unknown): boolean => {
76
76
  };
77
77
 
78
78
  export const maybeCoerceInteger = (value: unknown): number | undefined => {
79
- if (value === undefined) {
79
+ if (value == null) {
80
80
  return undefined;
81
81
  }
82
82
  return coerceInteger(value);
83
83
  };
84
84
 
85
85
  export const maybeCoerceFloat = (value: unknown): number | undefined => {
86
- if (value === undefined) {
86
+ if (value == null) {
87
87
  return undefined;
88
88
  }
89
89
  return coerceFloat(value);
90
90
  };
91
91
 
92
92
  export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
93
- if (value === undefined) {
93
+ if (value == null) {
94
94
  return undefined;
95
95
  }
96
96
  return coerceBoolean(value);
@@ -0,0 +1,2 @@
1
+ /** @deprecated Import from ./core/pagination instead */
2
+ export * from './core/pagination';
@@ -348,6 +348,12 @@ export interface BrowserCreateParams {
348
348
  */
349
349
  profile?: BrowserCreateParams.Profile;
350
350
 
351
+ /**
352
+ * Optional proxy to associate to the browser session. Must reference a proxy
353
+ * belonging to the caller's org.
354
+ */
355
+ proxy_id?: string;
356
+
351
357
  /**
352
358
  * If true, launches the browser in stealth mode to reduce detection by anti-bot
353
359
  * mechanisms.
@@ -357,7 +363,10 @@ export interface BrowserCreateParams {
357
363
  /**
358
364
  * The number of seconds of inactivity before the browser session is terminated.
359
365
  * Only applicable to non-persistent browsers. Activity includes CDP connections
360
- * and live view connections. Defaults to 60 seconds.
366
+ * and live view connections. Defaults to 60 seconds. Minimum allowed is 10
367
+ * seconds. Maximum allowed is 86400 (24 hours). We check for inactivity every 5
368
+ * seconds, so the actual timeout behavior you will see is +/- 5 seconds around the
369
+ * specified value.
361
370
  */
362
371
  timeout_seconds?: number;
363
372
  }
@@ -3,6 +3,7 @@
3
3
  import { APIResource } from '../core/resource';
4
4
  import * as Shared from './shared';
5
5
  import { APIPromise } from '../core/api-promise';
6
+ import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../core/pagination';
6
7
  import { Stream } from '../core/streaming';
7
8
  import { type Uploadable } from '../core/uploads';
8
9
  import { buildHeaders } from '../internal/headers';
@@ -43,14 +44,20 @@ export class Deployments extends APIResource {
43
44
  *
44
45
  * @example
45
46
  * ```ts
46
- * const deployments = await client.deployments.list();
47
+ * // Automatically fetches more pages as needed.
48
+ * for await (const deploymentListResponse of client.deployments.list()) {
49
+ * // ...
50
+ * }
47
51
  * ```
48
52
  */
49
53
  list(
50
54
  query: DeploymentListParams | null | undefined = {},
51
55
  options?: RequestOptions,
52
- ): APIPromise<DeploymentListResponse> {
53
- return this._client.get('/deployments', { query, ...options });
56
+ ): PagePromise<DeploymentListResponsesOffsetPagination, DeploymentListResponse> {
57
+ return this._client.getAPIList('/deployments', OffsetPagination<DeploymentListResponse>, {
58
+ query,
59
+ ...options,
60
+ });
54
61
  }
55
62
 
56
63
  /**
@@ -77,6 +84,8 @@ export class Deployments extends APIResource {
77
84
  }
78
85
  }
79
86
 
87
+ export type DeploymentListResponsesOffsetPagination = OffsetPagination<DeploymentListResponse>;
88
+
80
89
  /**
81
90
  * An event representing the current state of a deployment.
82
91
  */
@@ -234,53 +243,49 @@ export interface DeploymentRetrieveResponse {
234
243
  updated_at?: string | null;
235
244
  }
236
245
 
237
- export type DeploymentListResponse = Array<DeploymentListResponse.DeploymentListResponseItem>;
238
-
239
- export namespace DeploymentListResponse {
246
+ /**
247
+ * Deployment record information.
248
+ */
249
+ export interface DeploymentListResponse {
240
250
  /**
241
- * Deployment record information.
251
+ * Unique identifier for the deployment
242
252
  */
243
- export interface DeploymentListResponseItem {
244
- /**
245
- * Unique identifier for the deployment
246
- */
247
- id: string;
253
+ id: string;
248
254
 
249
- /**
250
- * Timestamp when the deployment was created
251
- */
252
- created_at: string;
255
+ /**
256
+ * Timestamp when the deployment was created
257
+ */
258
+ created_at: string;
253
259
 
254
- /**
255
- * Deployment region code
256
- */
257
- region: 'aws.us-east-1a';
260
+ /**
261
+ * Deployment region code
262
+ */
263
+ region: 'aws.us-east-1a';
258
264
 
259
- /**
260
- * Current status of the deployment
261
- */
262
- status: 'queued' | 'in_progress' | 'running' | 'failed' | 'stopped';
265
+ /**
266
+ * Current status of the deployment
267
+ */
268
+ status: 'queued' | 'in_progress' | 'running' | 'failed' | 'stopped';
263
269
 
264
- /**
265
- * Relative path to the application entrypoint
266
- */
267
- entrypoint_rel_path?: string;
270
+ /**
271
+ * Relative path to the application entrypoint
272
+ */
273
+ entrypoint_rel_path?: string;
268
274
 
269
- /**
270
- * Environment variables configured for this deployment
271
- */
272
- env_vars?: { [key: string]: string };
275
+ /**
276
+ * Environment variables configured for this deployment
277
+ */
278
+ env_vars?: { [key: string]: string };
273
279
 
274
- /**
275
- * Status reason
276
- */
277
- status_reason?: string;
280
+ /**
281
+ * Status reason
282
+ */
283
+ status_reason?: string;
278
284
 
279
- /**
280
- * Timestamp when the deployment was last updated
281
- */
282
- updated_at?: string | null;
283
- }
285
+ /**
286
+ * Timestamp when the deployment was last updated
287
+ */
288
+ updated_at?: string | null;
284
289
  }
285
290
 
286
291
  /**
@@ -373,7 +378,7 @@ export interface DeploymentCreateParams {
373
378
  version?: string;
374
379
  }
375
380
 
376
- export interface DeploymentListParams {
381
+ export interface DeploymentListParams extends OffsetPaginationParams {
377
382
  /**
378
383
  * Filter results by application name.
379
384
  */
@@ -394,6 +399,7 @@ export declare namespace Deployments {
394
399
  type DeploymentRetrieveResponse as DeploymentRetrieveResponse,
395
400
  type DeploymentListResponse as DeploymentListResponse,
396
401
  type DeploymentFollowResponse as DeploymentFollowResponse,
402
+ type DeploymentListResponsesOffsetPagination as DeploymentListResponsesOffsetPagination,
397
403
  type DeploymentCreateParams as DeploymentCreateParams,
398
404
  type DeploymentListParams as DeploymentListParams,
399
405
  type DeploymentFollowParams as DeploymentFollowParams,
@@ -22,6 +22,7 @@ export {
22
22
  type DeploymentCreateParams,
23
23
  type DeploymentListParams,
24
24
  type DeploymentFollowParams,
25
+ type DeploymentListResponsesOffsetPagination,
25
26
  } from './deployments';
26
27
  export {
27
28
  Invocations,
@@ -34,3 +35,10 @@ export {
34
35
  type InvocationUpdateParams,
35
36
  } from './invocations';
36
37
  export { Profiles, type ProfileListResponse, type ProfileCreateParams } from './profiles';
38
+ export {
39
+ Proxies,
40
+ type ProxyCreateResponse,
41
+ type ProxyRetrieveResponse,
42
+ type ProxyListResponse,
43
+ type ProxyCreateParams,
44
+ } from './proxies';
@@ -40,7 +40,8 @@ export class Invocations extends APIResource {
40
40
  }
41
41
 
42
42
  /**
43
- * Update an invocation's status or output.
43
+ * Update an invocation's status or output. This can used to cancel an invocation
44
+ * by setting the status to "failed".
44
45
  *
45
46
  * @example
46
47
  * ```ts