@onkernel/sdk 0.1.0-alpha.1 → 0.1.0-alpha.10
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.
- package/CHANGELOG.md +76 -0
- package/README.md +17 -29
- package/client.d.mts +25 -3
- package/client.d.mts.map +1 -1
- package/client.d.ts +25 -3
- package/client.d.ts.map +1 -1
- package/client.js +24 -4
- package/client.js.map +1 -1
- package/client.mjs +24 -4
- package/client.mjs.map +1 -1
- package/core/app-framework.d.mts +49 -0
- package/core/app-framework.d.mts.map +1 -0
- package/core/app-framework.d.ts +49 -0
- package/core/app-framework.d.ts.map +1 -0
- package/core/app-framework.js +105 -0
- package/core/app-framework.js.map +1 -0
- package/core/app-framework.mjs +101 -0
- package/core/app-framework.mjs.map +1 -0
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/internal/headers.js +1 -1
- package/internal/headers.js.map +1 -1
- package/internal/headers.mjs +1 -1
- package/internal/headers.mjs.map +1 -1
- package/package.json +1 -4
- package/resources/apps.d.mts +45 -15
- package/resources/apps.d.mts.map +1 -1
- package/resources/apps.d.ts +45 -15
- package/resources/apps.d.ts.map +1 -1
- package/resources/apps.js +3 -3
- package/resources/apps.js.map +1 -1
- package/resources/apps.mjs +3 -3
- package/resources/apps.mjs.map +1 -1
- package/resources/browser.d.mts +8 -2
- package/resources/browser.d.mts.map +1 -1
- package/resources/browser.d.ts +8 -2
- package/resources/browser.d.ts.map +1 -1
- package/resources/browser.js +2 -2
- package/resources/browser.js.map +1 -1
- package/resources/browser.mjs +2 -2
- package/resources/browser.mjs.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/src/client.ts +45 -6
- package/src/core/app-framework.ts +137 -0
- package/src/index.ts +2 -0
- package/src/internal/headers.ts +1 -1
- package/src/resources/apps.ts +52 -15
- package/src/resources/browser.ts +16 -3
- package/src/resources/index.ts +1 -1
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
|
@@ -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
package/src/internal/headers.ts
CHANGED
|
@@ -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)) {
|
package/src/resources/apps.ts
CHANGED
|
@@ -14,9 +14,8 @@ export class Apps extends APIResource {
|
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
16
|
* const response = await client.apps.deploy({
|
|
17
|
-
*
|
|
17
|
+
* entrypointRelPath: 'app.py',
|
|
18
18
|
* file: fs.createReadStream('path/to/file'),
|
|
19
|
-
* version: '1.0.0',
|
|
20
19
|
* });
|
|
21
20
|
* ```
|
|
22
21
|
*/
|
|
@@ -30,8 +29,9 @@ export class Apps extends APIResource {
|
|
|
30
29
|
* @example
|
|
31
30
|
* ```ts
|
|
32
31
|
* const response = await client.apps.invoke({
|
|
32
|
+
* actionName: 'analyze',
|
|
33
33
|
* appName: 'my-awesome-app',
|
|
34
|
-
* payload:
|
|
34
|
+
* payload: { data: 'example input' },
|
|
35
35
|
* version: '1.0.0',
|
|
36
36
|
* });
|
|
37
37
|
* ```
|
|
@@ -56,10 +56,7 @@ export class Apps extends APIResource {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export interface AppDeployResponse {
|
|
59
|
-
|
|
60
|
-
* ID of the deployed app version
|
|
61
|
-
*/
|
|
62
|
-
id: string;
|
|
59
|
+
apps: Array<AppDeployResponse.App>;
|
|
63
60
|
|
|
64
61
|
/**
|
|
65
62
|
* Success message
|
|
@@ -72,6 +69,31 @@ export interface AppDeployResponse {
|
|
|
72
69
|
success: boolean;
|
|
73
70
|
}
|
|
74
71
|
|
|
72
|
+
export namespace AppDeployResponse {
|
|
73
|
+
export interface App {
|
|
74
|
+
/**
|
|
75
|
+
* ID for the app version deployed
|
|
76
|
+
*/
|
|
77
|
+
id: string;
|
|
78
|
+
|
|
79
|
+
actions: Array<App.Action>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Name of the app
|
|
83
|
+
*/
|
|
84
|
+
name: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export namespace App {
|
|
88
|
+
export interface Action {
|
|
89
|
+
/**
|
|
90
|
+
* Name of the action
|
|
91
|
+
*/
|
|
92
|
+
name: string;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
75
97
|
export interface AppInvokeResponse {
|
|
76
98
|
/**
|
|
77
99
|
* ID of the invocation
|
|
@@ -81,7 +103,12 @@ export interface AppInvokeResponse {
|
|
|
81
103
|
/**
|
|
82
104
|
* Status of the invocation
|
|
83
105
|
*/
|
|
84
|
-
status:
|
|
106
|
+
status: 'QUEUED' | 'RUNNING' | 'SUCCEEDED' | 'FAILED';
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Output from the invocation (if available)
|
|
110
|
+
*/
|
|
111
|
+
output?: string;
|
|
85
112
|
}
|
|
86
113
|
|
|
87
114
|
export interface AppRetrieveInvocationResponse {
|
|
@@ -102,27 +129,37 @@ export interface AppRetrieveInvocationResponse {
|
|
|
102
129
|
|
|
103
130
|
export interface AppDeployParams {
|
|
104
131
|
/**
|
|
105
|
-
*
|
|
132
|
+
* Relative path to the entrypoint of the application
|
|
106
133
|
*/
|
|
107
|
-
|
|
134
|
+
entrypointRelPath: string;
|
|
108
135
|
|
|
109
136
|
/**
|
|
110
|
-
* ZIP file containing the application
|
|
137
|
+
* ZIP file containing the application source directory
|
|
111
138
|
*/
|
|
112
139
|
file: Uploadable;
|
|
113
140
|
|
|
114
141
|
/**
|
|
115
|
-
*
|
|
142
|
+
* Allow overwriting an existing app version
|
|
116
143
|
*/
|
|
117
|
-
|
|
144
|
+
force?: 'true' | 'false';
|
|
118
145
|
|
|
119
146
|
/**
|
|
120
|
-
*
|
|
147
|
+
* Region for deployment. Currently we only support "aws.us-east-1a"
|
|
121
148
|
*/
|
|
122
|
-
region?:
|
|
149
|
+
region?: 'aws.us-east-1a';
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Version of the application. Can be any string.
|
|
153
|
+
*/
|
|
154
|
+
version?: string;
|
|
123
155
|
}
|
|
124
156
|
|
|
125
157
|
export interface AppInvokeParams {
|
|
158
|
+
/**
|
|
159
|
+
* Name of the action to invoke
|
|
160
|
+
*/
|
|
161
|
+
actionName: string;
|
|
162
|
+
|
|
126
163
|
/**
|
|
127
164
|
* Name of the application
|
|
128
165
|
*/
|
package/src/resources/browser.ts
CHANGED
|
@@ -8,8 +8,11 @@ export class Browser extends APIResource {
|
|
|
8
8
|
/**
|
|
9
9
|
* Create Browser Session
|
|
10
10
|
*/
|
|
11
|
-
createSession(
|
|
12
|
-
|
|
11
|
+
createSession(
|
|
12
|
+
body: BrowserCreateSessionParams,
|
|
13
|
+
options?: RequestOptions,
|
|
14
|
+
): APIPromise<BrowserCreateSessionResponse> {
|
|
15
|
+
return this._client.post('/browser', { body, ...options });
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
|
|
@@ -30,6 +33,16 @@ export interface BrowserCreateSessionResponse {
|
|
|
30
33
|
sessionId: string;
|
|
31
34
|
}
|
|
32
35
|
|
|
36
|
+
export interface BrowserCreateSessionParams {
|
|
37
|
+
/**
|
|
38
|
+
* Kernel App invocation ID
|
|
39
|
+
*/
|
|
40
|
+
invocationId: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
export declare namespace Browser {
|
|
34
|
-
export {
|
|
44
|
+
export {
|
|
45
|
+
type BrowserCreateSessionResponse as BrowserCreateSessionResponse,
|
|
46
|
+
type BrowserCreateSessionParams as BrowserCreateSessionParams,
|
|
47
|
+
};
|
|
35
48
|
}
|
package/src/resources/index.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.0-alpha.
|
|
1
|
+
export const VERSION = '0.1.0-alpha.10'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.1.0-alpha.10";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.mts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.mts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-alpha.
|
|
1
|
+
export declare const VERSION = "0.1.0-alpha.10";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
|
-
exports.VERSION = '0.1.0-alpha.
|
|
4
|
+
exports.VERSION = '0.1.0-alpha.10'; // x-release-please-version
|
|
5
5
|
//# sourceMappingURL=version.js.map
|
package/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,gBAAgB,CAAC,CAAC,2BAA2B"}
|
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.0-alpha.
|
|
1
|
+
export const VERSION = '0.1.0-alpha.10'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|
package/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC,CAAC,2BAA2B"}
|