@ultrst-armada/kloks 1.2.1 → 1.4.0
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/package.json +44 -1
- package/packages/backend/dist/chunk-BM4QMVPA.js +338 -0
- package/packages/backend/dist/chunk-DZ4ZGIZM.js +1323 -0
- package/packages/backend/dist/{chunk-MN54ZIKZ.js → chunk-KX3OTBQ3.js} +309 -4
- package/packages/backend/dist/index.d.ts +145 -4
- package/packages/backend/dist/index.js +447 -1398
- package/packages/backend/dist/krnl-services.js +2 -2
- package/packages/backend/dist/services/index.d.ts +168 -1
- package/packages/backend/dist/services/index.js +15 -3
- package/packages/backend/dist/srkl/index.d.ts +108 -1
- package/packages/backend/dist/srkl/index.js +15 -1
- package/packages/backend/dist/workspace/index.d.ts +119 -1
- package/packages/backend/dist/workspace/index.js +11 -3
- package/packages/client/dist/index.d.ts +154 -0
- package/packages/client/dist/index.js +62 -0
- package/packages/client/package.json +41 -0
- package/packages/state-graph/dist/index.js +14 -14
- package/packages/backend/dist/chunk-KTLD7Z4L.js +0 -124
- package/packages/backend/dist/chunk-P4HL4C6V.js +0 -149
- package/packages/backend/dist/{chunk-OYQKQAEF.js → chunk-CU7RZBMF.js} +4 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/browserExecutionClient.ts
|
|
2
|
+
var BrowserExecutionClient = class {
|
|
3
|
+
gatewayUrl;
|
|
4
|
+
headers;
|
|
5
|
+
timeoutMs;
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.gatewayUrl = options.gatewayUrl || "/api/queue";
|
|
8
|
+
this.headers = options.headers || { "Content-Type": "application/json" };
|
|
9
|
+
this.timeoutMs = options.timeoutMs || 15e3;
|
|
10
|
+
}
|
|
11
|
+
createCommand(type, payload, options = {}) {
|
|
12
|
+
const correlationId = options.correlationId || `corr_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
13
|
+
return {
|
|
14
|
+
id: `cmd_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
|
|
15
|
+
type,
|
|
16
|
+
payload,
|
|
17
|
+
metadata: options.metadata,
|
|
18
|
+
correlationId,
|
|
19
|
+
idempotencyKey: options.idempotencyKey,
|
|
20
|
+
createdAt: Date.now()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async enqueue(command) {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
26
|
+
try {
|
|
27
|
+
const res = await fetch(`${this.gatewayUrl}/enqueue`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: this.headers,
|
|
30
|
+
body: JSON.stringify(command),
|
|
31
|
+
signal: controller.signal
|
|
32
|
+
});
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(`[BrowserExecutionClient] Enqueue failed: HTTP ${res.status}`);
|
|
35
|
+
}
|
|
36
|
+
const data = await res.json();
|
|
37
|
+
return {
|
|
38
|
+
jobId: data.jobId || command.id,
|
|
39
|
+
correlationId: command.correlationId
|
|
40
|
+
};
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async checkStatus(jobId) {
|
|
46
|
+
const res = await fetch(`${this.gatewayUrl}/status/${encodeURIComponent(jobId)}`, {
|
|
47
|
+
method: "GET",
|
|
48
|
+
headers: this.headers
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
throw new Error(`[BrowserExecutionClient] Check status failed: HTTP ${res.status}`);
|
|
52
|
+
}
|
|
53
|
+
return await res.json();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function createBrowserExecutionClient(options) {
|
|
57
|
+
return new BrowserExecutionClient(options);
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
BrowserExecutionClient,
|
|
61
|
+
createBrowserExecutionClient
|
|
62
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kloks/client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Kloks Browser-Safe Execution Client & Shared Contracts with Zero Server Closure",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"skipoManifest": "./kloks.manifest.json",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/index.ts --format esm --dts --clean --external react --external zod",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"clean": "rm -rf dist"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"zod": "^3.24.1"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependenciesMeta": {
|
|
34
|
+
"react": {
|
|
35
|
+
"optional": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@ultrst-armada/krnl": "^1.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -14,6 +14,20 @@ import {
|
|
|
14
14
|
useCommand
|
|
15
15
|
} from "./chunk-ZTHBPV24.js";
|
|
16
16
|
import "./chunk-RHRXPY2U.js";
|
|
17
|
+
import {
|
|
18
|
+
CommandApi,
|
|
19
|
+
GhostStore,
|
|
20
|
+
GraphStore
|
|
21
|
+
} from "./chunk-4UVGXFEM.js";
|
|
22
|
+
import {
|
|
23
|
+
BaseGraph,
|
|
24
|
+
BaseNode,
|
|
25
|
+
BaseViewWindow,
|
|
26
|
+
CustomGraph,
|
|
27
|
+
CustomNode,
|
|
28
|
+
CustomViewWindow,
|
|
29
|
+
DEFAULT_GRAPH_SETTINGS
|
|
30
|
+
} from "./chunk-KG6QYS26.js";
|
|
17
31
|
import {
|
|
18
32
|
AttractionEngine,
|
|
19
33
|
GhostInferenceEngine,
|
|
@@ -29,20 +43,6 @@ import {
|
|
|
29
43
|
WireTypeRegistry,
|
|
30
44
|
initializeDefaultGraphRules
|
|
31
45
|
} from "./chunk-TZOL3RN7.js";
|
|
32
|
-
import {
|
|
33
|
-
CommandApi,
|
|
34
|
-
GhostStore,
|
|
35
|
-
GraphStore
|
|
36
|
-
} from "./chunk-4UVGXFEM.js";
|
|
37
|
-
import {
|
|
38
|
-
BaseGraph,
|
|
39
|
-
BaseNode,
|
|
40
|
-
BaseViewWindow,
|
|
41
|
-
CustomGraph,
|
|
42
|
-
CustomNode,
|
|
43
|
-
CustomViewWindow,
|
|
44
|
-
DEFAULT_GRAPH_SETTINGS
|
|
45
|
-
} from "./chunk-KG6QYS26.js";
|
|
46
46
|
import {
|
|
47
47
|
AutoSolidify,
|
|
48
48
|
SpatialEngine,
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// src/workspace/WorkspaceFS.ts
|
|
2
|
-
import { SkipoBase } from "@ultrst-armada/kloks/functions";
|
|
3
|
-
var WorkspaceFS = class extends SkipoBase {
|
|
4
|
-
primary;
|
|
5
|
-
syncEngine;
|
|
6
|
-
config;
|
|
7
|
-
constructor(primary, config, syncEngine) {
|
|
8
|
-
super();
|
|
9
|
-
this.primary = primary;
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.syncEngine = syncEngine;
|
|
12
|
-
}
|
|
13
|
-
setPrimary(newPrimary) {
|
|
14
|
-
this.primary = newPrimary;
|
|
15
|
-
}
|
|
16
|
-
setSyncEngine(engine) {
|
|
17
|
-
this.syncEngine = engine;
|
|
18
|
-
}
|
|
19
|
-
async exists(pathStr) {
|
|
20
|
-
return this.primary.exists(pathStr);
|
|
21
|
-
}
|
|
22
|
-
async stat(pathStr) {
|
|
23
|
-
return this.primary.stat(pathStr);
|
|
24
|
-
}
|
|
25
|
-
async list(pathStr = "") {
|
|
26
|
-
return this.primary.list(pathStr);
|
|
27
|
-
}
|
|
28
|
-
async read(pathStr) {
|
|
29
|
-
return this.primary.read(pathStr);
|
|
30
|
-
}
|
|
31
|
-
async readText(pathStr) {
|
|
32
|
-
const data = await this.read(pathStr);
|
|
33
|
-
return Buffer.from(data).toString("utf8");
|
|
34
|
-
}
|
|
35
|
-
async write(pathStr, data) {
|
|
36
|
-
await this.primary.write(pathStr, data);
|
|
37
|
-
if (this.syncEngine && this.config.sync?.enabled && this.config.sync.mode === "on_write") {
|
|
38
|
-
this.syncEngine.syncFile(pathStr).catch((err) => {
|
|
39
|
-
console.warn(`[WorkspaceFS] Async backup sync warning for '${pathStr}':`, err.message);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async mkdir(pathStr) {
|
|
44
|
-
await this.primary.mkdir(pathStr);
|
|
45
|
-
}
|
|
46
|
-
async delete(pathStr) {
|
|
47
|
-
await this.primary.delete(pathStr);
|
|
48
|
-
if (this.syncEngine && this.config.sync?.enabled && this.config.sync.deletePropagation) {
|
|
49
|
-
this.syncEngine.deleteFile(pathStr).catch((err) => {
|
|
50
|
-
console.warn(`[WorkspaceFS] Async delete sync warning for '${pathStr}':`, err.message);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/workspace/SyncEngine.ts
|
|
57
|
-
import { SkipoBase as SkipoBase2 } from "@ultrst-armada/kloks/functions";
|
|
58
|
-
var SyncEngine = class extends SkipoBase2 {
|
|
59
|
-
primary;
|
|
60
|
-
backups;
|
|
61
|
-
config;
|
|
62
|
-
constructor(primary, backups, config) {
|
|
63
|
-
super({ name: "SyncEngine" });
|
|
64
|
-
this.primary = primary;
|
|
65
|
-
this.backups = backups;
|
|
66
|
-
this.config = config;
|
|
67
|
-
}
|
|
68
|
-
async syncFile(pathStr) {
|
|
69
|
-
const data = await this.primary.read(pathStr);
|
|
70
|
-
for (const backup of this.backups) {
|
|
71
|
-
try {
|
|
72
|
-
await backup.write(pathStr, data);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
console.error(`[SyncEngine] Failed to sync ${pathStr} to backup:`, e.message);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async deleteFile(pathStr) {
|
|
79
|
-
for (const backup of this.backups) {
|
|
80
|
-
try {
|
|
81
|
-
await backup.delete(pathStr);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error(`[SyncEngine] Failed to delete ${pathStr} on backup:`, e.message);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// src/workspace/WorkspaceCloneSyncEngine.ts
|
|
90
|
-
import { SkipoBase as SkipoBase3 } from "@ultrst-armada/kloks/functions";
|
|
91
|
-
var WorkspaceCloneSyncEngine = class extends SkipoBase3 {
|
|
92
|
-
constructor() {
|
|
93
|
-
super({ name: "WorkspaceCloneSyncEngine" });
|
|
94
|
-
}
|
|
95
|
-
async replicateToClones(files, clones, uploadFn) {
|
|
96
|
-
const results = [];
|
|
97
|
-
let totalSynced = 0;
|
|
98
|
-
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
99
|
-
for (const clone of clones) {
|
|
100
|
-
try {
|
|
101
|
-
let count = 0;
|
|
102
|
-
for (const file of files) {
|
|
103
|
-
await uploadFn(clone, file.relPath, file.content, file.contentType);
|
|
104
|
-
count++;
|
|
105
|
-
}
|
|
106
|
-
clone.lastSyncedAt = nowIso;
|
|
107
|
-
clone.filesSynced = count;
|
|
108
|
-
clone.status = "SYNCED";
|
|
109
|
-
results.push({ cloneId: clone.id, label: clone.label, provider: clone.provider, filesSynced: count, status: "SYNCED" });
|
|
110
|
-
totalSynced += count;
|
|
111
|
-
} catch (err) {
|
|
112
|
-
clone.status = "ERROR";
|
|
113
|
-
results.push({ cloneId: clone.id, label: clone.label, provider: clone.provider, filesSynced: 0, status: "ERROR", error: err.message });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return { results, totalSynced };
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export {
|
|
121
|
-
WorkspaceFS,
|
|
122
|
-
SyncEngine,
|
|
123
|
-
WorkspaceCloneSyncEngine
|
|
124
|
-
};
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createService,
|
|
3
|
-
createServiceDefinition,
|
|
4
|
-
createServiceProxy
|
|
5
|
-
} from "./chunk-IPP4VURQ.js";
|
|
6
|
-
|
|
7
|
-
// src/services/ServiceBoundary.ts
|
|
8
|
-
function createLocalService(definition) {
|
|
9
|
-
return createService(createServiceDefinition(definition));
|
|
10
|
-
}
|
|
11
|
-
function createRemoteService(definition, adapter, endpoint) {
|
|
12
|
-
return createServiceProxy(definition, adapter, endpoint);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/services/CompositeBackend.ts
|
|
16
|
-
var CompositeBackend = class {
|
|
17
|
-
id;
|
|
18
|
-
name;
|
|
19
|
-
version;
|
|
20
|
-
services = /* @__PURE__ */ new Map();
|
|
21
|
-
capabilitiesList = [];
|
|
22
|
-
constructor(name, version = "1.0.0") {
|
|
23
|
-
this.name = name;
|
|
24
|
-
this.id = `backend-${name}`;
|
|
25
|
-
this.version = version;
|
|
26
|
-
}
|
|
27
|
-
registerService(service) {
|
|
28
|
-
this.services.set(service.name, service);
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
getService(name) {
|
|
32
|
-
return this.services.get(name);
|
|
33
|
-
}
|
|
34
|
-
getServices() {
|
|
35
|
-
return Array.from(this.services.values());
|
|
36
|
-
}
|
|
37
|
-
registerCapability(capability) {
|
|
38
|
-
if (!this.capabilitiesList.includes(capability)) {
|
|
39
|
-
this.capabilitiesList.push(capability);
|
|
40
|
-
}
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
async start() {
|
|
44
|
-
for (const service of this.services.values()) {
|
|
45
|
-
await service.start();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async stop() {
|
|
49
|
-
for (const service of this.services.values()) {
|
|
50
|
-
await service.stop();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async call(op, input, ctx) {
|
|
54
|
-
const firstDot = op.indexOf(".");
|
|
55
|
-
if (firstDot === -1) {
|
|
56
|
-
throw new Error(`[CompositeBackend] Invalid operation '${op}'. Expected 'service.operation'.`);
|
|
57
|
-
}
|
|
58
|
-
const serviceName = op.slice(0, firstDot);
|
|
59
|
-
const operationName = op.slice(firstDot + 1);
|
|
60
|
-
const service = this.services.get(serviceName);
|
|
61
|
-
if (!service) {
|
|
62
|
-
throw new Error(`[CompositeBackend] Service '${serviceName}' not registered in '${this.name}'.`);
|
|
63
|
-
}
|
|
64
|
-
return await service.call(operationName, input, ctx);
|
|
65
|
-
}
|
|
66
|
-
getState() {
|
|
67
|
-
const aggregated = {};
|
|
68
|
-
for (const [name, service] of this.services) {
|
|
69
|
-
aggregated[name] = service.getState();
|
|
70
|
-
}
|
|
71
|
-
return Object.freeze(aggregated);
|
|
72
|
-
}
|
|
73
|
-
setState(_mutation) {
|
|
74
|
-
}
|
|
75
|
-
on(event, handler) {
|
|
76
|
-
const [serviceName, eventName] = event.split(".");
|
|
77
|
-
const service = this.services.get(serviceName);
|
|
78
|
-
if (!service) return () => {
|
|
79
|
-
};
|
|
80
|
-
return service.on(eventName, handler);
|
|
81
|
-
}
|
|
82
|
-
emit(event, payload) {
|
|
83
|
-
const [serviceName, eventName] = event.split(".");
|
|
84
|
-
const service = this.services.get(serviceName);
|
|
85
|
-
if (service) {
|
|
86
|
-
service.emit(eventName, payload);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
getDefinition() {
|
|
90
|
-
const ops = {};
|
|
91
|
-
for (const service of this.services.values()) {
|
|
92
|
-
const def = service.getDefinition();
|
|
93
|
-
for (const [opKey, opDef] of Object.entries(def.operations)) {
|
|
94
|
-
ops[`${service.name}.${opKey}`] = opDef;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
id: this.id,
|
|
99
|
-
name: this.name,
|
|
100
|
-
version: this.version,
|
|
101
|
-
operations: ops,
|
|
102
|
-
capabilities: this.capabilitiesList.map((c) => ({
|
|
103
|
-
id: c,
|
|
104
|
-
name: c,
|
|
105
|
-
protocols: ["http", "ws", "udp", "p2p"]
|
|
106
|
-
})),
|
|
107
|
-
protocols: ["http", "ws", "udp", "p2p"]
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// src/services/EndpointGenerator.ts
|
|
113
|
-
var EndpointGenerator = class {
|
|
114
|
-
static generateEndpoints(backend, basePort = 8e3) {
|
|
115
|
-
const def = backend.getDefinition();
|
|
116
|
-
const ops = Object.keys(def.operations);
|
|
117
|
-
return {
|
|
118
|
-
httpRoutes: ops.map((op) => `/api/${op.replace(".", "/")}`),
|
|
119
|
-
wsChannels: ops.map((op) => `channel:${op}`),
|
|
120
|
-
udpEndpoints: [`udp://127.0.0.1:${basePort}`],
|
|
121
|
-
p2pBindings: ops.map((op) => `p2p://${backend.name}/${op}`)
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
static generateDescriptors(backend, host = "127.0.0.1", port = 8080) {
|
|
125
|
-
return [
|
|
126
|
-
{ protocol: "http", address: host, port, capabilities: ["requestResponse"] },
|
|
127
|
-
{ protocol: "ws", address: host, port, capabilities: ["requestResponse", "pubSub"] },
|
|
128
|
-
{ protocol: "udp", address: host, port, capabilities: ["datagram"] },
|
|
129
|
-
{ protocol: "p2p", address: `p2p://${backend.name}`, capabilities: ["peerToPeer"] }
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// src/services/ServiceGenerators.ts
|
|
135
|
-
function createBackend(name) {
|
|
136
|
-
return new CompositeBackend(name);
|
|
137
|
-
}
|
|
138
|
-
function createCompositeService(name) {
|
|
139
|
-
return new CompositeBackend(name);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export {
|
|
143
|
-
createLocalService,
|
|
144
|
-
createRemoteService,
|
|
145
|
-
CompositeBackend,
|
|
146
|
-
EndpointGenerator,
|
|
147
|
-
createBackend,
|
|
148
|
-
createCompositeService
|
|
149
|
-
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createService,
|
|
3
|
+
createServiceDefinition
|
|
4
|
+
} from "./chunk-IPP4VURQ.js";
|
|
1
5
|
import {
|
|
2
6
|
StorageAdapterFactory
|
|
3
7
|
} from "./chunk-J2J24JVC.js";
|
|
@@ -13,10 +17,6 @@ import {
|
|
|
13
17
|
ExecutableBackendFacade,
|
|
14
18
|
WorkerExecutionBoundary
|
|
15
19
|
} from "./chunk-QGHDJGYS.js";
|
|
16
|
-
import {
|
|
17
|
-
createService,
|
|
18
|
-
createServiceDefinition
|
|
19
|
-
} from "./chunk-IPP4VURQ.js";
|
|
20
20
|
|
|
21
21
|
// src/krnl-services.ts
|
|
22
22
|
var AuthServiceDefinition = createServiceDefinition({
|