@onkernel/sdk 0.0.1-alpha.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.
- package/README.md +15 -0
- package/dist/index.cjs +71 -0
- package/dist/index.d.cts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +68 -0
- package/package.json +51 -0
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
var KernelRegistry = class {
|
|
5
|
+
registry = /* @__PURE__ */ new Map();
|
|
6
|
+
register(item) {
|
|
7
|
+
this.registry.set(item.name, item);
|
|
8
|
+
}
|
|
9
|
+
getAll() {
|
|
10
|
+
return Array.from(this.registry.values());
|
|
11
|
+
}
|
|
12
|
+
getByName(name) {
|
|
13
|
+
return this.registry.get(name);
|
|
14
|
+
}
|
|
15
|
+
getByType(type) {
|
|
16
|
+
return this.getAll().filter((item) => item.type === type);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var registry = new KernelRegistry();
|
|
20
|
+
var Kernel = {
|
|
21
|
+
/**
|
|
22
|
+
* Define a scheduled function
|
|
23
|
+
*/
|
|
24
|
+
schedule: (cronExpression, fn) => {
|
|
25
|
+
registry.register({
|
|
26
|
+
type: "schedule",
|
|
27
|
+
name: fn.name || `schedule_${cronExpression.replace(/\s+/g, "_")}`,
|
|
28
|
+
cron: cronExpression,
|
|
29
|
+
handler: fn
|
|
30
|
+
});
|
|
31
|
+
return fn;
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Define an HTTP endpoint
|
|
35
|
+
*/
|
|
36
|
+
endpoint: (options, handler) => {
|
|
37
|
+
registry.register({
|
|
38
|
+
type: "http",
|
|
39
|
+
name: handler.name || `endpoint_${options.method.toLowerCase()}_${options.path.replace(/\//g, "_")}`,
|
|
40
|
+
path: options.path,
|
|
41
|
+
method: options.method,
|
|
42
|
+
handler
|
|
43
|
+
});
|
|
44
|
+
return handler;
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* Use a browser for automation
|
|
48
|
+
* The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
49
|
+
* const browser = await chromium.connectOverCDP(cdp_ws_url);
|
|
50
|
+
*/
|
|
51
|
+
useBrowser: (fn) => {
|
|
52
|
+
return fn({
|
|
53
|
+
cdp_ws_url: "ws://localhost:9222"
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Define a function
|
|
58
|
+
*/
|
|
59
|
+
func: (fn) => {
|
|
60
|
+
const name = fn.name || "default";
|
|
61
|
+
registry.register({
|
|
62
|
+
type: "function",
|
|
63
|
+
name,
|
|
64
|
+
handler: fn
|
|
65
|
+
});
|
|
66
|
+
return fn;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.Kernel = Kernel;
|
|
71
|
+
exports.registry = registry;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface Request {
|
|
2
|
+
query: Record<string, string>;
|
|
3
|
+
body?: any;
|
|
4
|
+
}
|
|
5
|
+
interface Browser {
|
|
6
|
+
cdp_ws_url: string;
|
|
7
|
+
}
|
|
8
|
+
interface KernelFunction {
|
|
9
|
+
type: 'function';
|
|
10
|
+
name: string;
|
|
11
|
+
handler: (...args: any[]) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
interface KernelSchedule {
|
|
14
|
+
type: 'schedule';
|
|
15
|
+
name: string;
|
|
16
|
+
cron: string;
|
|
17
|
+
handler: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
interface KernelEndpoint {
|
|
20
|
+
type: 'http';
|
|
21
|
+
name: string;
|
|
22
|
+
path: string;
|
|
23
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
24
|
+
handler: (req: Request) => Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
type KernelRegistryItem = KernelFunction | KernelSchedule | KernelEndpoint;
|
|
27
|
+
declare class KernelRegistry {
|
|
28
|
+
private registry;
|
|
29
|
+
register(item: KernelRegistryItem): void;
|
|
30
|
+
getAll(): KernelRegistryItem[];
|
|
31
|
+
getByName(name: string): KernelRegistryItem | undefined;
|
|
32
|
+
getByType(type: 'function' | 'schedule' | 'http'): KernelRegistryItem[];
|
|
33
|
+
}
|
|
34
|
+
declare const registry: KernelRegistry;
|
|
35
|
+
declare const Kernel: {
|
|
36
|
+
/**
|
|
37
|
+
* Define a scheduled function
|
|
38
|
+
*/
|
|
39
|
+
schedule: (cronExpression: string, fn: () => Promise<void>) => () => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Define an HTTP endpoint
|
|
42
|
+
*/
|
|
43
|
+
endpoint: <T>(options: {
|
|
44
|
+
path: string;
|
|
45
|
+
method: string;
|
|
46
|
+
}, handler: (req: Request) => Promise<T>) => (req: Request) => Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Use a browser for automation
|
|
49
|
+
* The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
50
|
+
* const browser = await chromium.connectOverCDP(cdp_ws_url);
|
|
51
|
+
*/
|
|
52
|
+
useBrowser: <T>(fn: (browser: Browser) => Promise<T>) => Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Define a function
|
|
55
|
+
*/
|
|
56
|
+
func: <T, R>(fn: (input: T) => Promise<R>) => (input: T) => Promise<R>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { type Browser, Kernel, type KernelEndpoint, type KernelFunction, type KernelRegistryItem, type KernelSchedule, type Request, registry };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface Request {
|
|
2
|
+
query: Record<string, string>;
|
|
3
|
+
body?: any;
|
|
4
|
+
}
|
|
5
|
+
interface Browser {
|
|
6
|
+
cdp_ws_url: string;
|
|
7
|
+
}
|
|
8
|
+
interface KernelFunction {
|
|
9
|
+
type: 'function';
|
|
10
|
+
name: string;
|
|
11
|
+
handler: (...args: any[]) => Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
interface KernelSchedule {
|
|
14
|
+
type: 'schedule';
|
|
15
|
+
name: string;
|
|
16
|
+
cron: string;
|
|
17
|
+
handler: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
interface KernelEndpoint {
|
|
20
|
+
type: 'http';
|
|
21
|
+
name: string;
|
|
22
|
+
path: string;
|
|
23
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
24
|
+
handler: (req: Request) => Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
type KernelRegistryItem = KernelFunction | KernelSchedule | KernelEndpoint;
|
|
27
|
+
declare class KernelRegistry {
|
|
28
|
+
private registry;
|
|
29
|
+
register(item: KernelRegistryItem): void;
|
|
30
|
+
getAll(): KernelRegistryItem[];
|
|
31
|
+
getByName(name: string): KernelRegistryItem | undefined;
|
|
32
|
+
getByType(type: 'function' | 'schedule' | 'http'): KernelRegistryItem[];
|
|
33
|
+
}
|
|
34
|
+
declare const registry: KernelRegistry;
|
|
35
|
+
declare const Kernel: {
|
|
36
|
+
/**
|
|
37
|
+
* Define a scheduled function
|
|
38
|
+
*/
|
|
39
|
+
schedule: (cronExpression: string, fn: () => Promise<void>) => () => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Define an HTTP endpoint
|
|
42
|
+
*/
|
|
43
|
+
endpoint: <T>(options: {
|
|
44
|
+
path: string;
|
|
45
|
+
method: string;
|
|
46
|
+
}, handler: (req: Request) => Promise<T>) => (req: Request) => Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Use a browser for automation
|
|
49
|
+
* The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
50
|
+
* const browser = await chromium.connectOverCDP(cdp_ws_url);
|
|
51
|
+
*/
|
|
52
|
+
useBrowser: <T>(fn: (browser: Browser) => Promise<T>) => Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Define a function
|
|
55
|
+
*/
|
|
56
|
+
func: <T, R>(fn: (input: T) => Promise<R>) => (input: T) => Promise<R>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { type Browser, Kernel, type KernelEndpoint, type KernelFunction, type KernelRegistryItem, type KernelSchedule, type Request, registry };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var KernelRegistry = class {
|
|
3
|
+
registry = /* @__PURE__ */ new Map();
|
|
4
|
+
register(item) {
|
|
5
|
+
this.registry.set(item.name, item);
|
|
6
|
+
}
|
|
7
|
+
getAll() {
|
|
8
|
+
return Array.from(this.registry.values());
|
|
9
|
+
}
|
|
10
|
+
getByName(name) {
|
|
11
|
+
return this.registry.get(name);
|
|
12
|
+
}
|
|
13
|
+
getByType(type) {
|
|
14
|
+
return this.getAll().filter((item) => item.type === type);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var registry = new KernelRegistry();
|
|
18
|
+
var Kernel = {
|
|
19
|
+
/**
|
|
20
|
+
* Define a scheduled function
|
|
21
|
+
*/
|
|
22
|
+
schedule: (cronExpression, fn) => {
|
|
23
|
+
registry.register({
|
|
24
|
+
type: "schedule",
|
|
25
|
+
name: fn.name || `schedule_${cronExpression.replace(/\s+/g, "_")}`,
|
|
26
|
+
cron: cronExpression,
|
|
27
|
+
handler: fn
|
|
28
|
+
});
|
|
29
|
+
return fn;
|
|
30
|
+
},
|
|
31
|
+
/**
|
|
32
|
+
* Define an HTTP endpoint
|
|
33
|
+
*/
|
|
34
|
+
endpoint: (options, handler) => {
|
|
35
|
+
registry.register({
|
|
36
|
+
type: "http",
|
|
37
|
+
name: handler.name || `endpoint_${options.method.toLowerCase()}_${options.path.replace(/\//g, "_")}`,
|
|
38
|
+
path: options.path,
|
|
39
|
+
method: options.method,
|
|
40
|
+
handler
|
|
41
|
+
});
|
|
42
|
+
return handler;
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Use a browser for automation
|
|
46
|
+
* The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
47
|
+
* const browser = await chromium.connectOverCDP(cdp_ws_url);
|
|
48
|
+
*/
|
|
49
|
+
useBrowser: (fn) => {
|
|
50
|
+
return fn({
|
|
51
|
+
cdp_ws_url: "ws://localhost:9222"
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* Define a function
|
|
56
|
+
*/
|
|
57
|
+
func: (fn) => {
|
|
58
|
+
const name = fn.name || "default";
|
|
59
|
+
registry.register({
|
|
60
|
+
type: "function",
|
|
61
|
+
name,
|
|
62
|
+
handler: fn
|
|
63
|
+
});
|
|
64
|
+
return fn;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { Kernel, registry };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onkernel/sdk",
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"module": "index.ts",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/index.d.cts",
|
|
19
|
+
"default": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup --config tsup.config.ts --format esm,cjs"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.4.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"kernel",
|
|
35
|
+
"cli",
|
|
36
|
+
"ai",
|
|
37
|
+
"llm",
|
|
38
|
+
"llms",
|
|
39
|
+
"agent",
|
|
40
|
+
"agents",
|
|
41
|
+
"dev",
|
|
42
|
+
"development",
|
|
43
|
+
"deploy",
|
|
44
|
+
"deployment",
|
|
45
|
+
"build",
|
|
46
|
+
"workflow",
|
|
47
|
+
"typescript",
|
|
48
|
+
"command-line",
|
|
49
|
+
"devtools"
|
|
50
|
+
]
|
|
51
|
+
}
|