@onkernel/sdk 0.1.0-alpha.1 → 0.1.0-alpha.11

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 (117) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +34 -45
  3. package/client.d.mts +28 -6
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +28 -6
  6. package/client.d.ts.map +1 -1
  7. package/client.js +28 -8
  8. package/client.js.map +1 -1
  9. package/client.mjs +28 -8
  10. package/client.mjs.map +1 -1
  11. package/core/app-framework.d.mts +49 -0
  12. package/core/app-framework.d.mts.map +1 -0
  13. package/core/app-framework.d.ts +49 -0
  14. package/core/app-framework.d.ts.map +1 -0
  15. package/core/app-framework.js +105 -0
  16. package/core/app-framework.js.map +1 -0
  17. package/core/app-framework.mjs +101 -0
  18. package/core/app-framework.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/headers.js +1 -1
  28. package/internal/headers.js.map +1 -1
  29. package/internal/headers.mjs +1 -1
  30. package/internal/headers.mjs.map +1 -1
  31. package/internal/tslib.js +17 -17
  32. package/package.json +1 -4
  33. package/resources/apps/apps.d.mts +14 -0
  34. package/resources/apps/apps.d.mts.map +1 -0
  35. package/resources/apps/apps.d.ts +14 -0
  36. package/resources/apps/apps.d.ts.map +1 -0
  37. package/resources/apps/apps.js +21 -0
  38. package/resources/apps/apps.js.map +1 -0
  39. package/resources/apps/apps.mjs +16 -0
  40. package/resources/apps/apps.mjs.map +1 -0
  41. package/resources/apps/deployments.d.mts +82 -0
  42. package/resources/apps/deployments.d.mts.map +1 -0
  43. package/resources/apps/deployments.d.ts +82 -0
  44. package/resources/apps/deployments.d.ts.map +1 -0
  45. package/resources/apps/deployments.js +24 -0
  46. package/resources/apps/deployments.js.map +1 -0
  47. package/resources/apps/deployments.mjs +20 -0
  48. package/resources/apps/deployments.mjs.map +1 -0
  49. package/resources/apps/index.d.mts +4 -0
  50. package/resources/apps/index.d.mts.map +1 -0
  51. package/resources/apps/index.d.ts +4 -0
  52. package/resources/apps/index.d.ts.map +1 -0
  53. package/resources/apps/index.js +11 -0
  54. package/resources/apps/index.js.map +1 -0
  55. package/resources/apps/index.mjs +5 -0
  56. package/resources/apps/index.mjs.map +1 -0
  57. package/resources/apps/invocations.d.mts +110 -0
  58. package/resources/apps/invocations.d.mts.map +1 -0
  59. package/resources/apps/invocations.d.ts +110 -0
  60. package/resources/apps/invocations.d.ts.map +1 -0
  61. package/resources/apps/invocations.js +38 -0
  62. package/resources/apps/invocations.js.map +1 -0
  63. package/resources/apps/invocations.mjs +34 -0
  64. package/resources/apps/invocations.mjs.map +1 -0
  65. package/resources/apps.d.mts +1 -111
  66. package/resources/apps.d.mts.map +1 -1
  67. package/resources/apps.d.ts +1 -111
  68. package/resources/apps.d.ts.map +1 -1
  69. package/resources/apps.js +2 -50
  70. package/resources/apps.js.map +1 -1
  71. package/resources/apps.mjs +1 -48
  72. package/resources/apps.mjs.map +1 -1
  73. package/resources/browsers.d.mts +65 -0
  74. package/resources/browsers.d.mts.map +1 -0
  75. package/resources/browsers.d.ts +65 -0
  76. package/resources/browsers.d.ts.map +1 -0
  77. package/resources/browsers.js +36 -0
  78. package/resources/browsers.js.map +1 -0
  79. package/resources/browsers.mjs +32 -0
  80. package/resources/browsers.mjs.map +1 -0
  81. package/resources/index.d.mts +2 -2
  82. package/resources/index.d.mts.map +1 -1
  83. package/resources/index.d.ts +2 -2
  84. package/resources/index.d.ts.map +1 -1
  85. package/resources/index.js +4 -4
  86. package/resources/index.js.map +1 -1
  87. package/resources/index.mjs +2 -2
  88. package/resources/index.mjs.map +1 -1
  89. package/src/client.ts +53 -22
  90. package/src/core/app-framework.ts +137 -0
  91. package/src/index.ts +2 -0
  92. package/src/internal/headers.ts +1 -1
  93. package/src/resources/apps/apps.ts +35 -0
  94. package/src/resources/apps/deployments.ts +103 -0
  95. package/src/resources/apps/index.ts +10 -0
  96. package/src/resources/apps/invocations.ts +140 -0
  97. package/src/resources/apps.ts +1 -148
  98. package/src/resources/browsers.ts +85 -0
  99. package/src/resources/index.ts +6 -8
  100. package/src/version.ts +1 -1
  101. package/version.d.mts +1 -1
  102. package/version.d.mts.map +1 -1
  103. package/version.d.ts +1 -1
  104. package/version.d.ts.map +1 -1
  105. package/version.js +1 -1
  106. package/version.js.map +1 -1
  107. package/version.mjs +1 -1
  108. package/version.mjs.map +1 -1
  109. package/resources/browser.d.mts +0 -27
  110. package/resources/browser.d.mts.map +0 -1
  111. package/resources/browser.d.ts +0 -27
  112. package/resources/browser.d.ts.map +0 -1
  113. package/resources/browser.js +0 -15
  114. package/resources/browser.js.map +0 -1
  115. package/resources/browser.mjs +0 -11
  116. package/resources/browser.mjs.map +0 -1
  117. package/src/resources/browser.ts +0 -35
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EACL,IAAI,EACJ,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,6BAA6B,EAClC,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB;OACM,EAAE,OAAO,EAAE,KAAK,4BAA4B,EAAE"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EAAE,IAAI,EAAE;OACR,EACL,QAAQ,EACR,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,GACzB"}
@@ -1,3 +1,3 @@
1
- export { Apps, type AppDeployResponse, type AppInvokeResponse, type AppRetrieveInvocationResponse, type AppDeployParams, type AppInvokeParams, } from "./apps.js";
2
- export { Browser, type BrowserCreateSessionResponse } from "./browser.js";
1
+ export { Apps } from "./apps/apps.js";
2
+ export { Browsers, type BrowserCreateResponse, type BrowserRetrieveResponse, type BrowserCreateParams, } from "./browsers.js";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EACL,IAAI,EACJ,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,6BAA6B,EAClC,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB;OACM,EAAE,OAAO,EAAE,KAAK,4BAA4B,EAAE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EAAE,IAAI,EAAE;OACR,EACL,QAAQ,EACR,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,GACzB"}
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Browser = exports.Apps = void 0;
5
- var apps_1 = require("./apps.js");
4
+ exports.Browsers = exports.Apps = void 0;
5
+ var apps_1 = require("./apps/apps.js");
6
6
  Object.defineProperty(exports, "Apps", { enumerable: true, get: function () { return apps_1.Apps; } });
7
- var browser_1 = require("./browser.js");
8
- Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return browser_1.Browser; } });
7
+ var browsers_1 = require("./browsers.js");
8
+ Object.defineProperty(exports, "Browsers", { enumerable: true, get: function () { return browsers_1.Browsers; } });
9
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kCAOgB;AANd,4FAAA,IAAI,OAAA;AAON,wCAAuE;AAA9D,kGAAA,OAAO,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,uCAAmC;AAA1B,4FAAA,IAAI,OAAA;AACb,0CAKoB;AAJlB,oGAAA,QAAQ,OAAA"}
@@ -1,4 +1,4 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
- export { Apps, } from "./apps.mjs";
3
- export { Browser } from "./browser.mjs";
2
+ export { Apps } from "./apps/apps.mjs";
3
+ export { Browsers, } from "./browsers.mjs";
4
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EACL,IAAI,GAML;OACM,EAAE,OAAO,EAAqC"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,IAAI,EAAE;OACR,EACL,QAAQ,GAIT"}
package/src/client.ts CHANGED
@@ -21,17 +21,22 @@ import { type Fetch } from './internal/builtin-types';
21
21
  import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
22
22
  import { FinalRequestOptions, RequestOptions } from './internal/request-options';
23
23
  import {
24
- AppDeployParams,
25
- AppDeployResponse,
26
- AppInvokeParams,
27
- AppInvokeResponse,
28
- AppRetrieveInvocationResponse,
29
- Apps,
30
- } from './resources/apps';
31
- import { Browser, BrowserCreateSessionResponse } from './resources/browser';
24
+ BrowserCreateParams,
25
+ BrowserCreateResponse,
26
+ BrowserRetrieveResponse,
27
+ Browsers,
28
+ } from './resources/browsers';
32
29
  import { readEnv } from './internal/utils/env';
33
30
  import { formatRequestDetails, loggerFor } from './internal/utils/log';
34
31
  import { isEmptyObj } from './internal/utils/values';
32
+ import { KernelApp } from './core/app-framework';
33
+ import { Apps } from './resources/apps/apps';
34
+
35
+ const environments = {
36
+ production: 'https://api.onkernel.com/',
37
+ development: 'https://localhost:3001/',
38
+ };
39
+ type Environment = keyof typeof environments;
35
40
 
36
41
  export interface ClientOptions {
37
42
  /**
@@ -39,6 +44,15 @@ export interface ClientOptions {
39
44
  */
40
45
  apiKey?: string | undefined;
41
46
 
47
+ /**
48
+ * Specifies the environment to use for the API.
49
+ *
50
+ * Each environment maps to a different base URL:
51
+ * - `production` corresponds to `https://api.onkernel.com/`
52
+ * - `development` corresponds to `https://localhost:3001/`
53
+ */
54
+ environment?: Environment | undefined;
55
+
42
56
  /**
43
57
  * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
44
58
  *
@@ -128,7 +142,8 @@ export class Kernel {
128
142
  * API Client for interfacing with the Kernel API.
129
143
  *
130
144
  * @param {string | undefined} [opts.apiKey=process.env['KERNEL_API_KEY'] ?? undefined]
131
- * @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? http://localhost:3001] - Override the default base URL for the API.
145
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
146
+ * @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? https://api.onkernel.com/] - Override the default base URL for the API.
132
147
  * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
133
148
  * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
134
149
  * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
@@ -150,10 +165,17 @@ export class Kernel {
150
165
  const options: ClientOptions = {
151
166
  apiKey,
152
167
  ...opts,
153
- baseURL: baseURL || `http://localhost:3001`,
168
+ baseURL,
169
+ environment: opts.environment ?? 'production',
154
170
  };
155
171
 
156
- this.baseURL = options.baseURL!;
172
+ if (baseURL && opts.environment) {
173
+ throw new Errors.KernelError(
174
+ 'Ambiguous URL; The `baseURL` option (or KERNEL_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
175
+ );
176
+ }
177
+
178
+ this.baseURL = options.baseURL || environments[options.environment || 'production'];
157
179
  this.timeout = options.timeout ?? Kernel.DEFAULT_TIMEOUT /* 1 minute */;
158
180
  this.logger = options.logger ?? console;
159
181
  const defaultLogLevel = 'warn';
@@ -179,7 +201,8 @@ export class Kernel {
179
201
  withOptions(options: Partial<ClientOptions>): this {
180
202
  return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
181
203
  ...this._options,
182
- baseURL: this.baseURL,
204
+ environment: options.environment ? options.environment : undefined,
205
+ baseURL: options.environment ? undefined : this.baseURL,
183
206
  maxRetries: this.maxRetries,
184
207
  timeout: this.timeout,
185
208
  logger: this.logger,
@@ -680,6 +703,16 @@ export class Kernel {
680
703
  }
681
704
  }
682
705
 
706
+ /**
707
+ * Create a new KernelApp instance.
708
+ *
709
+ * @param name - The name of the app to create.
710
+ * @returns A new KernelApp instance you can attach actions to.
711
+ */
712
+ public app(name: string): KernelApp {
713
+ return new KernelApp(name);
714
+ }
715
+
683
716
  static Kernel = this;
684
717
  static DEFAULT_TIMEOUT = 60000; // 1 minute
685
718
 
@@ -700,21 +733,19 @@ export class Kernel {
700
733
  static toFile = Uploads.toFile;
701
734
 
702
735
  apps: API.Apps = new API.Apps(this);
703
- browser: API.Browser = new API.Browser(this);
736
+ browsers: API.Browsers = new API.Browsers(this);
704
737
  }
705
738
  Kernel.Apps = Apps;
706
- Kernel.Browser = Browser;
739
+ Kernel.Browsers = Browsers;
707
740
  export declare namespace Kernel {
708
741
  export type RequestOptions = Opts.RequestOptions;
709
742
 
743
+ export { Apps as Apps };
744
+
710
745
  export {
711
- Apps as Apps,
712
- type AppDeployResponse as AppDeployResponse,
713
- type AppInvokeResponse as AppInvokeResponse,
714
- type AppRetrieveInvocationResponse as AppRetrieveInvocationResponse,
715
- type AppDeployParams as AppDeployParams,
716
- type AppInvokeParams as AppInvokeParams,
746
+ Browsers as Browsers,
747
+ type BrowserCreateResponse as BrowserCreateResponse,
748
+ type BrowserRetrieveResponse as BrowserRetrieveResponse,
749
+ type BrowserCreateParams as BrowserCreateParams,
717
750
  };
718
-
719
- export { Browser as Browser, type BrowserCreateSessionResponse as BrowserCreateSessionResponse };
720
751
  }
@@ -0,0 +1,137 @@
1
+ export interface KernelContext {
2
+ invocationId: string;
3
+ }
4
+
5
+ export interface KernelAction {
6
+ name: string;
7
+ handler: (context: KernelContext, input: any) => Promise<any>;
8
+ }
9
+
10
+ export interface KernelJson {
11
+ apps: KernelAppJson[];
12
+ }
13
+
14
+ export interface KernelAppJson {
15
+ name: string;
16
+ actions: KernelActionJson[];
17
+ }
18
+
19
+ export interface KernelActionJson {
20
+ name: string;
21
+ }
22
+
23
+ export class KernelApp {
24
+ name: string;
25
+ actions: Map<string, KernelAction> = new Map();
26
+
27
+ constructor(name: string) {
28
+ this.name = name;
29
+ // Register this app in the global registry
30
+ appRegistry.registerApp(this);
31
+ }
32
+
33
+ /**
34
+ * Define an action
35
+ */
36
+ action<T, R>(
37
+ nameOrHandler: string | ((input: T) => Promise<R>) | ((context: KernelContext, input: T) => Promise<R>),
38
+ handler?: ((input: T) => Promise<R>) | ((context: KernelContext, input: T) => Promise<R>),
39
+ ) {
40
+ let actionName: string;
41
+ let actionHandler: (context: KernelContext, input: T) => Promise<R>;
42
+
43
+ if (typeof nameOrHandler === 'string' && handler) {
44
+ // Case: app.action("name", handler)
45
+ actionName = nameOrHandler;
46
+
47
+ // Create a handler that accepts context and input, adapting if needed
48
+ if (handler.length === 1) {
49
+ // Original handler only takes input, so we adapt it to the new signature
50
+ const singleArgHandler = handler as (input: T) => Promise<R>;
51
+ actionHandler = async (context: KernelContext, input: T) => singleArgHandler(input);
52
+ } else {
53
+ // Handler takes both context and input
54
+ actionHandler = handler as (context: KernelContext, input: T) => Promise<R>;
55
+ }
56
+ } else if (typeof nameOrHandler === 'function') {
57
+ // Case: app.action(handler)
58
+ actionName = nameOrHandler.name || 'default';
59
+
60
+ // Create a handler that accepts context and input, adapting if needed
61
+ if (nameOrHandler.length === 1) {
62
+ // Original handler only takes input, so we adapt it to the new signature
63
+ const singleArgHandler = nameOrHandler as (input: T) => Promise<R>;
64
+ actionHandler = async (context: KernelContext, input: T) => singleArgHandler(input);
65
+ } else {
66
+ // Handler takes both context and input
67
+ actionHandler = nameOrHandler as (context: KernelContext, input: T) => Promise<R>;
68
+ }
69
+ } else {
70
+ throw new Error('Invalid action definition');
71
+ }
72
+
73
+ // Register the action
74
+ this.actions.set(actionName, {
75
+ name: actionName,
76
+ handler: actionHandler,
77
+ });
78
+
79
+ return actionHandler;
80
+ }
81
+
82
+ /**
83
+ * Get all actions for this app
84
+ */
85
+ getActions(): KernelAction[] {
86
+ return Array.from(this.actions.values());
87
+ }
88
+
89
+ /**
90
+ * Get an action by name
91
+ */
92
+ getAction(name: string): KernelAction | undefined {
93
+ return this.actions.get(name);
94
+ }
95
+
96
+ /**
97
+ * Export app information without handlers
98
+ */
99
+ toJSON(): KernelAppJson {
100
+ return {
101
+ name: this.name,
102
+ actions: this.getActions().map((action) => ({
103
+ name: action.name,
104
+ })),
105
+ };
106
+ }
107
+ }
108
+
109
+ // Registry for storing all Kernel apps
110
+ class KernelAppRegistry {
111
+ private apps: Map<string, KernelApp> = new Map();
112
+
113
+ registerApp(app: KernelApp): void {
114
+ this.apps.set(app.name, app);
115
+ }
116
+
117
+ getApps(): KernelApp[] {
118
+ return Array.from(this.apps.values());
119
+ }
120
+
121
+ getAppByName(name: string): KernelApp | undefined {
122
+ return this.apps.get(name);
123
+ }
124
+
125
+ export(): KernelJson {
126
+ return {
127
+ apps: this.getApps().map((app) => app.toJSON()),
128
+ };
129
+ }
130
+
131
+ exportJSON(): string {
132
+ return JSON.stringify(this.export(), null, 2);
133
+ }
134
+ }
135
+
136
+ // Create a singleton registry for apps
137
+ export const appRegistry = new KernelAppRegistry();
package/src/index.ts CHANGED
@@ -20,3 +20,5 @@ export {
20
20
  PermissionDeniedError,
21
21
  UnprocessableEntityError,
22
22
  } from './core/error';
23
+
24
+ export { KernelAction, KernelContext, KernelJson, appRegistry } from './core/app-framework';
@@ -71,8 +71,8 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
71
71
  export const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {
72
72
  const targetHeaders = new Headers();
73
73
  const nullHeaders = new Set<string>();
74
- const seenHeaders = new Set<string>();
75
74
  for (const headers of newHeaders) {
75
+ const seenHeaders = new Set<string>();
76
76
  for (const [name, value] of iterateHeaders(headers)) {
77
77
  const lowerName = name.toLowerCase();
78
78
  if (!seenHeaders.has(lowerName)) {
@@ -0,0 +1,35 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+ import * as DeploymentsAPI from './deployments';
5
+ import { DeploymentCreateParams, DeploymentCreateResponse, Deployments } from './deployments';
6
+ import * as InvocationsAPI from './invocations';
7
+ import {
8
+ InvocationCreateParams,
9
+ InvocationCreateResponse,
10
+ InvocationRetrieveResponse,
11
+ Invocations,
12
+ } from './invocations';
13
+
14
+ export class Apps extends APIResource {
15
+ deployments: DeploymentsAPI.Deployments = new DeploymentsAPI.Deployments(this._client);
16
+ invocations: InvocationsAPI.Invocations = new InvocationsAPI.Invocations(this._client);
17
+ }
18
+
19
+ Apps.Deployments = Deployments;
20
+ Apps.Invocations = Invocations;
21
+
22
+ export declare namespace Apps {
23
+ export {
24
+ Deployments as Deployments,
25
+ type DeploymentCreateResponse as DeploymentCreateResponse,
26
+ type DeploymentCreateParams as DeploymentCreateParams,
27
+ };
28
+
29
+ export {
30
+ Invocations as Invocations,
31
+ type InvocationCreateResponse as InvocationCreateResponse,
32
+ type InvocationRetrieveResponse as InvocationRetrieveResponse,
33
+ type InvocationCreateParams as InvocationCreateParams,
34
+ };
35
+ }
@@ -0,0 +1,103 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../core/resource';
4
+ import { APIPromise } from '../../core/api-promise';
5
+ import { type Uploadable } from '../../core/uploads';
6
+ import { RequestOptions } from '../../internal/request-options';
7
+ import { multipartFormRequestOptions } from '../../internal/uploads';
8
+
9
+ export class Deployments extends APIResource {
10
+ /**
11
+ * Deploy a new application
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const deployment = await client.apps.deployments.create({
16
+ * entrypoint_rel_path: 'src/app.py',
17
+ * file: fs.createReadStream('path/to/file'),
18
+ * });
19
+ * ```
20
+ */
21
+ create(body: DeploymentCreateParams, options?: RequestOptions): APIPromise<DeploymentCreateResponse> {
22
+ return this._client.post('/deploy', multipartFormRequestOptions({ body, ...options }, this._client));
23
+ }
24
+ }
25
+
26
+ export interface DeploymentCreateResponse {
27
+ /**
28
+ * List of apps deployed
29
+ */
30
+ apps: Array<DeploymentCreateResponse.App>;
31
+
32
+ /**
33
+ * Current status of the deployment
34
+ */
35
+ status: 'queued' | 'deploying' | 'succeeded' | 'failed';
36
+
37
+ /**
38
+ * Status reason
39
+ */
40
+ status_reason?: string;
41
+ }
42
+
43
+ export namespace DeploymentCreateResponse {
44
+ export interface App {
45
+ /**
46
+ * ID for the app version deployed
47
+ */
48
+ id: string;
49
+
50
+ /**
51
+ * List of actions available on the app
52
+ */
53
+ actions: Array<App.Action>;
54
+
55
+ /**
56
+ * Name of the app
57
+ */
58
+ name: string;
59
+ }
60
+
61
+ export namespace App {
62
+ export interface Action {
63
+ /**
64
+ * Name of the action
65
+ */
66
+ name: string;
67
+ }
68
+ }
69
+ }
70
+
71
+ export interface DeploymentCreateParams {
72
+ /**
73
+ * Relative path to the entrypoint of the application
74
+ */
75
+ entrypoint_rel_path: string;
76
+
77
+ /**
78
+ * ZIP file containing the application source directory
79
+ */
80
+ file: Uploadable;
81
+
82
+ /**
83
+ * Allow overwriting an existing app version
84
+ */
85
+ force?: boolean;
86
+
87
+ /**
88
+ * Region for deployment. Currently we only support "aws.us-east-1a"
89
+ */
90
+ region?: 'aws.us-east-1a';
91
+
92
+ /**
93
+ * Version of the application. Can be any string.
94
+ */
95
+ version?: string;
96
+ }
97
+
98
+ export declare namespace Deployments {
99
+ export {
100
+ type DeploymentCreateResponse as DeploymentCreateResponse,
101
+ type DeploymentCreateParams as DeploymentCreateParams,
102
+ };
103
+ }
@@ -0,0 +1,10 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Apps } from './apps';
4
+ export { Deployments, type DeploymentCreateResponse, type DeploymentCreateParams } from './deployments';
5
+ export {
6
+ Invocations,
7
+ type InvocationCreateResponse,
8
+ type InvocationRetrieveResponse,
9
+ type InvocationCreateParams,
10
+ } from './invocations';
@@ -0,0 +1,140 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
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';
7
+
8
+ export class Invocations extends APIResource {
9
+ /**
10
+ * Invoke an application
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const invocation = await client.apps.invocations.create({
15
+ * action_name: 'analyze',
16
+ * app_name: 'my-app',
17
+ * version: '1.0.0',
18
+ * });
19
+ * ```
20
+ */
21
+ create(body: InvocationCreateParams, options?: RequestOptions): APIPromise<InvocationCreateResponse> {
22
+ return this._client.post('/invocations', { body, ...options });
23
+ }
24
+
25
+ /**
26
+ * Get an app invocation by id
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const invocation = await client.apps.invocations.retrieve(
31
+ * 'ckqwer3o20000jb9s7abcdef',
32
+ * );
33
+ * ```
34
+ */
35
+ retrieve(id: string, options?: RequestOptions): APIPromise<InvocationRetrieveResponse> {
36
+ return this._client.get(path`/invocations/${id}`, options);
37
+ }
38
+ }
39
+
40
+ export interface InvocationCreateResponse {
41
+ /**
42
+ * ID of the invocation
43
+ */
44
+ id: string;
45
+
46
+ /**
47
+ * Status of the invocation
48
+ */
49
+ status: 'queued' | 'running' | 'succeeded' | 'failed';
50
+
51
+ /**
52
+ * The return value of the action that was invoked, rendered as a JSON string. This
53
+ * could be: string, number, boolean, array, object, or null.
54
+ */
55
+ output?: string;
56
+
57
+ /**
58
+ * Status reason
59
+ */
60
+ status_reason?: string;
61
+ }
62
+
63
+ export interface InvocationRetrieveResponse {
64
+ /**
65
+ * ID of the invocation
66
+ */
67
+ id: string;
68
+
69
+ /**
70
+ * Name of the action invoked
71
+ */
72
+ action_name: string;
73
+
74
+ /**
75
+ * Name of the application
76
+ */
77
+ app_name: string;
78
+
79
+ /**
80
+ * RFC 3339 Nanoseconds timestamp when the invocation started
81
+ */
82
+ started_at: string;
83
+
84
+ /**
85
+ * Status of the invocation
86
+ */
87
+ status: 'queued' | 'running' | 'succeeded' | 'failed';
88
+
89
+ /**
90
+ * RFC 3339 Nanoseconds timestamp when the invocation finished (null if still
91
+ * running)
92
+ */
93
+ finished_at?: string | null;
94
+
95
+ /**
96
+ * Output produced by the action, rendered as a JSON string. This could be: string,
97
+ * number, boolean, array, object, or null.
98
+ */
99
+ output?: string;
100
+
101
+ /**
102
+ * Payload provided to the invocation. This is a string that can be parsed as JSON.
103
+ */
104
+ payload?: string;
105
+
106
+ /**
107
+ * Status reason
108
+ */
109
+ status_reason?: string;
110
+ }
111
+
112
+ export interface InvocationCreateParams {
113
+ /**
114
+ * Name of the action to invoke
115
+ */
116
+ action_name: string;
117
+
118
+ /**
119
+ * Name of the application
120
+ */
121
+ app_name: string;
122
+
123
+ /**
124
+ * Version of the application
125
+ */
126
+ version: string;
127
+
128
+ /**
129
+ * Input data for the action, sent as a JSON string.
130
+ */
131
+ payload?: string;
132
+ }
133
+
134
+ export declare namespace Invocations {
135
+ export {
136
+ type InvocationCreateResponse as InvocationCreateResponse,
137
+ type InvocationRetrieveResponse as InvocationRetrieveResponse,
138
+ type InvocationCreateParams as InvocationCreateParams,
139
+ };
140
+ }