@ultrst-armada/kloks 2.2.3 → 2.2.5
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 +14 -2
- package/packages/aiko/dist/index.d.ts +95 -2
- package/packages/aiko/dist/index.js +277 -45
- package/packages/backend/dist/ai-inference/index.js +1 -1
- package/packages/backend/dist/ai-inference/inferenceExecutor.test.d.ts +1 -0
- package/packages/backend/dist/ai-models/index.js +2 -2
- package/packages/backend/dist/ai-routing/index.js +3 -3
- package/packages/backend/dist/auth/OidcBff.d.ts +50 -0
- package/packages/backend/dist/auth/OidcBff.test.d.ts +1 -0
- package/packages/backend/dist/auth/OidcBffEnv.d.ts +23 -0
- package/packages/backend/dist/auth/index.d.ts +2 -0
- package/packages/backend/dist/auth/index.js +6 -1
- package/packages/backend/dist/{chunk-RFPGUJAZ.js → chunk-26NAKO4V.js} +7 -7
- package/packages/backend/dist/{chunk-NIP22V2G.js → chunk-E2I7D52V.js} +22 -1
- package/packages/backend/dist/{chunk-5E6JRFUH.js → chunk-HX5TN27Y.js} +294 -4
- package/packages/backend/dist/{chunk-GCTQY24J.js → chunk-MK4ZRBFI.js} +7 -6
- package/packages/backend/dist/{chunk-LMAU62ZG.js → chunk-PT6J6UEU.js} +4 -4
- package/packages/backend/dist/chunk-SEKPSCWP.js +350 -0
- package/packages/backend/dist/{chunk-N7OUR5R5.js → chunk-YDGW7PXM.js} +1 -1
- package/packages/backend/dist/client/index.js +2 -2
- package/packages/backend/dist/connectivity/FrontendSession.d.ts +1 -0
- package/packages/backend/dist/connectivity/FrontendSession.dispose.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/HTTPTransport.d.ts +1 -0
- package/packages/backend/dist/connectivity/HTTPTransport.operation.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/InProcessExecutor.session.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/RemoteExecutor.error.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/facadeInvocation.adversarial_replay.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/facadeInvocation.d.ts +101 -0
- package/packages/backend/dist/connectivity/facadeInvocation.oneUseLuthContract.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/facadeInvocation.test.d.ts +1 -0
- package/packages/backend/dist/connectivity/index.d.ts +2 -0
- package/packages/backend/dist/connectivity/index.js +8 -4
- package/packages/backend/dist/index.js +7 -3
- package/packages/backend/dist/krnl-ai-services.js +6 -6
- package/packages/backend/dist/node.js +34 -25
- package/packages/backend/package.json +1 -1
- package/packages/client/dist/auth.d.ts +1 -1
- package/packages/client/dist/auth.js +5 -1
- package/packages/client/dist/{chunk-ATLIA7AJ.js → chunk-WYC7RG32.js} +5 -1
- package/packages/client/dist/index.d.ts +1 -1
- package/packages/client/dist/index.js +5 -1
- package/packages/client/package.json +1 -1
- package/packages/fod/dist/chunk-Q4OLPORH.js +111 -0
- package/packages/fod/dist/chunk-SMWRWNEW.js +81 -0
- package/packages/fod/dist/index.d.ts +12 -95
- package/packages/fod/dist/index.js +34 -11
- package/packages/fod/dist/quickJsAdapter-BRj8ixha.d.ts +34 -0
- package/packages/fod/dist/quickjs-node.d.ts +6 -0
- package/packages/fod/dist/quickjs-node.js +73 -0
- package/packages/fod/dist/quickjs-worker.d.ts +8 -0
- package/packages/fod/dist/quickjs-worker.js +51 -0
- package/packages/fod/dist/smallScript-wzJ-VayJ.d.ts +130 -0
- package/packages/fod/package.json +11 -3
- package/packages/backend/dist/chunk-JQKKMUCT.js +0 -0
- package/packages/backend/dist/{chunk-EREYT3WJ.js → chunk-LMWXONZG.js} +3 -3
|
@@ -85,17 +85,20 @@ import {
|
|
|
85
85
|
import {
|
|
86
86
|
CanonicalStorageProviderService
|
|
87
87
|
} from "./chunk-K5LKAEBJ.js";
|
|
88
|
-
import "./chunk-
|
|
88
|
+
import "./chunk-UU6M3L3O.js";
|
|
89
89
|
import "./chunk-WVDSMTW3.js";
|
|
90
90
|
import {
|
|
91
91
|
validateToolInput
|
|
92
92
|
} from "./chunk-6GQNYRD6.js";
|
|
93
|
-
import
|
|
93
|
+
import {
|
|
94
|
+
createCanonicalApplicationOAuthBff,
|
|
95
|
+
createOAuthBff
|
|
96
|
+
} from "./chunk-SEKPSCWP.js";
|
|
94
97
|
import {
|
|
95
98
|
BackendProvider,
|
|
96
99
|
useBackend,
|
|
97
100
|
useBackendClient
|
|
98
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-YDGW7PXM.js";
|
|
99
102
|
import "./chunk-DAG2L4RN.js";
|
|
100
103
|
import {
|
|
101
104
|
isSecretMasked,
|
|
@@ -142,6 +145,7 @@ import {
|
|
|
142
145
|
BackendRegistry,
|
|
143
146
|
ConcurrencyConflictError,
|
|
144
147
|
ConcurrencyManager,
|
|
148
|
+
FacadeInvocationDenied,
|
|
145
149
|
HealthMonitor,
|
|
146
150
|
IdempotencyManager,
|
|
147
151
|
InProcessExecutor,
|
|
@@ -149,8 +153,9 @@ import {
|
|
|
149
153
|
LoadBalancer,
|
|
150
154
|
LockManager,
|
|
151
155
|
RemoteExecutor,
|
|
152
|
-
createEmptyContract
|
|
153
|
-
|
|
156
|
+
createEmptyContract,
|
|
157
|
+
createFacadeInvocationBoundary
|
|
158
|
+
} from "./chunk-HX5TN27Y.js";
|
|
154
159
|
import {
|
|
155
160
|
BackendClient,
|
|
156
161
|
BackendResolver,
|
|
@@ -161,7 +166,7 @@ import {
|
|
|
161
166
|
SequenceTracker,
|
|
162
167
|
WebSocketTransport,
|
|
163
168
|
createBackendClient
|
|
164
|
-
} from "./chunk-
|
|
169
|
+
} from "./chunk-E2I7D52V.js";
|
|
165
170
|
import {
|
|
166
171
|
AIInferenceServiceDefinition,
|
|
167
172
|
AIInferenceServiceFacade,
|
|
@@ -175,7 +180,7 @@ import {
|
|
|
175
180
|
AIRoutingServiceFacade,
|
|
176
181
|
AIToolServiceDefinition,
|
|
177
182
|
AIToolServiceFacade
|
|
178
|
-
} from "./chunk-
|
|
183
|
+
} from "./chunk-26NAKO4V.js";
|
|
179
184
|
import {
|
|
180
185
|
FailoverExecutionEngine,
|
|
181
186
|
HealthCheckService,
|
|
@@ -183,11 +188,16 @@ import {
|
|
|
183
188
|
failoverExecutionEngine,
|
|
184
189
|
healthCheckService,
|
|
185
190
|
metricsLogger
|
|
186
|
-
} from "./chunk-
|
|
191
|
+
} from "./chunk-PT6J6UEU.js";
|
|
187
192
|
import {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
193
|
+
EndpointRefresher,
|
|
194
|
+
ModelCatalogService,
|
|
195
|
+
ModelHealthService,
|
|
196
|
+
STATIC_MODELS_CATALOG,
|
|
197
|
+
endpointRefresher,
|
|
198
|
+
modelCatalog,
|
|
199
|
+
modelHealthService
|
|
200
|
+
} from "./chunk-LMWXONZG.js";
|
|
191
201
|
import {
|
|
192
202
|
MCPEngine,
|
|
193
203
|
ToolManagerService,
|
|
@@ -330,21 +340,8 @@ import {
|
|
|
330
340
|
inferenceExecutor,
|
|
331
341
|
parseErrorJson,
|
|
332
342
|
performInference
|
|
333
|
-
} from "./chunk-
|
|
343
|
+
} from "./chunk-MK4ZRBFI.js";
|
|
334
344
|
import "./chunk-IN3WRHXE.js";
|
|
335
|
-
import "./chunk-UU6M3L3O.js";
|
|
336
|
-
import {
|
|
337
|
-
EndpointRefresher,
|
|
338
|
-
ModelCatalogService,
|
|
339
|
-
ModelHealthService,
|
|
340
|
-
STATIC_MODELS_CATALOG,
|
|
341
|
-
endpointRefresher,
|
|
342
|
-
modelCatalog,
|
|
343
|
-
modelHealthService
|
|
344
|
-
} from "./chunk-EREYT3WJ.js";
|
|
345
|
-
import {
|
|
346
|
-
AITransportClient
|
|
347
|
-
} from "./chunk-MAMK4GDH.js";
|
|
348
345
|
import {
|
|
349
346
|
KeyStoreService,
|
|
350
347
|
KeysStorage,
|
|
@@ -352,6 +349,14 @@ import {
|
|
|
352
349
|
keysStorage,
|
|
353
350
|
validateApiKey
|
|
354
351
|
} from "./chunk-P7H6TIEA.js";
|
|
352
|
+
import "./chunk-LV55WKZR.js";
|
|
353
|
+
import {
|
|
354
|
+
AIProviderService,
|
|
355
|
+
aiProviderService
|
|
356
|
+
} from "./chunk-SLR6SIEU.js";
|
|
357
|
+
import {
|
|
358
|
+
AITransportClient
|
|
359
|
+
} from "./chunk-MAMK4GDH.js";
|
|
355
360
|
import {
|
|
356
361
|
PROVIDERS_META,
|
|
357
362
|
PROVIDER_COLORS,
|
|
@@ -4632,6 +4637,7 @@ export {
|
|
|
4632
4637
|
EndpointGenerator,
|
|
4633
4638
|
EndpointRefresher,
|
|
4634
4639
|
EventBus,
|
|
4640
|
+
FacadeInvocationDenied,
|
|
4635
4641
|
FailoverExecutionEngine,
|
|
4636
4642
|
FrontendSession,
|
|
4637
4643
|
FunctionalityTable,
|
|
@@ -4727,10 +4733,12 @@ export {
|
|
|
4727
4733
|
createBackblazeStorageConnection,
|
|
4728
4734
|
createBackend,
|
|
4729
4735
|
createBackendClient,
|
|
4736
|
+
createCanonicalApplicationOAuthBff,
|
|
4730
4737
|
createLuthAuthClient2 as createCanonicalAuthClient,
|
|
4731
4738
|
createCompositeService,
|
|
4732
4739
|
createCredential,
|
|
4733
4740
|
createEmptyContract,
|
|
4741
|
+
createFacadeInvocationBoundary,
|
|
4734
4742
|
createGoogleDriveAuthorizationRequest,
|
|
4735
4743
|
createGoogleDriveWorkspaceClient,
|
|
4736
4744
|
createGraphAssetFolder,
|
|
@@ -4738,6 +4746,7 @@ export {
|
|
|
4738
4746
|
createGraphPackage,
|
|
4739
4747
|
createLocalService,
|
|
4740
4748
|
createLuthAuthClient,
|
|
4749
|
+
createOAuthBff,
|
|
4741
4750
|
createRemoteService,
|
|
4742
4751
|
createSSEResponse,
|
|
4743
4752
|
createSrklClient,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeploymentEnvironment } from '@dinilmusick/gutts/auth';
|
|
2
|
-
export { LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
|
|
2
|
+
export { ApplicationAuthClient, ApplicationAuthClientConfig, LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createApplicationAuthClient, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
|
|
3
3
|
|
|
4
4
|
interface LuthPrincipal {
|
|
5
5
|
id: string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ApplicationAuthClient,
|
|
2
3
|
CANONICAL_PUBLIC_ROUTES,
|
|
3
4
|
DEFAULT_LUTH_URL,
|
|
4
5
|
LuthAuthClient,
|
|
5
6
|
LuthAuthClient2,
|
|
6
7
|
LuthAuthError,
|
|
8
|
+
createApplicationAuthClient,
|
|
7
9
|
createLuthAuthClient,
|
|
8
10
|
createLuthAuthClient2,
|
|
9
11
|
createUniversalAuthFetch,
|
|
@@ -13,13 +15,15 @@ import {
|
|
|
13
15
|
resolveClientEnvironment,
|
|
14
16
|
resolveClientOrigin,
|
|
15
17
|
verifyLuthRequest
|
|
16
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-WYC7RG32.js";
|
|
17
19
|
export {
|
|
20
|
+
ApplicationAuthClient,
|
|
18
21
|
CANONICAL_PUBLIC_ROUTES,
|
|
19
22
|
LuthAuthClient2 as CanonicalAuthClient,
|
|
20
23
|
DEFAULT_LUTH_URL,
|
|
21
24
|
LuthAuthClient,
|
|
22
25
|
LuthAuthError,
|
|
26
|
+
createApplicationAuthClient,
|
|
23
27
|
createLuthAuthClient2 as createCanonicalAuthClient,
|
|
24
28
|
createLuthAuthClient,
|
|
25
29
|
createUniversalAuthFetch,
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
resolveClientOrigin,
|
|
7
7
|
resolveClientEnvironment,
|
|
8
8
|
LuthAuthError,
|
|
9
|
-
DEFAULT_LUTH_URL as DEFAULT_LUTH_URL2
|
|
9
|
+
DEFAULT_LUTH_URL as DEFAULT_LUTH_URL2,
|
|
10
|
+
ApplicationAuthClient,
|
|
11
|
+
createApplicationAuthClient
|
|
10
12
|
} from "@dinilmusick/gutts/auth";
|
|
11
13
|
import {
|
|
12
14
|
LuthAuthClient as LuthAuthClient2,
|
|
@@ -138,6 +140,8 @@ export {
|
|
|
138
140
|
resolveClientEnvironment,
|
|
139
141
|
LuthAuthError,
|
|
140
142
|
DEFAULT_LUTH_URL2 as DEFAULT_LUTH_URL,
|
|
143
|
+
ApplicationAuthClient,
|
|
144
|
+
createApplicationAuthClient,
|
|
141
145
|
LuthAuthClient2,
|
|
142
146
|
createLuthAuthClient2
|
|
143
147
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CANONICAL_PUBLIC_ROUTES, LuthDeploymentRecord, LuthPrincipal, createUniversalAuthFetch, extractLuthToken, isPublicRoute, verifyLuthRequest } from './auth.js';
|
|
2
|
-
export { LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
|
|
2
|
+
export { ApplicationAuthClient, ApplicationAuthClientConfig, LuthAuthClient as CanonicalAuthClient, DEFAULT_LUTH_URL, DeploymentEnvironment, EmailSignInCredentials, EmailSignUpData, GoogleSignInOptions, LuthAuthClient, LuthAuthClientConfig, LuthAuthError, LuthAuthTokenStore, LuthSession, LuthSessionResult, LuthUser, RegisterApplicationResult, createApplicationAuthClient, createLuthAuthClient as createCanonicalAuthClient, createLuthAuthClient, hydrateLuthTokenFromUrl, resolveClientEnvironment, resolveClientOrigin } from '@dinilmusick/gutts/auth';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @file queueContracts.ts
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ApplicationAuthClient,
|
|
2
3
|
CANONICAL_PUBLIC_ROUTES,
|
|
3
4
|
DEFAULT_LUTH_URL,
|
|
4
5
|
LuthAuthClient,
|
|
5
6
|
LuthAuthClient2,
|
|
6
7
|
LuthAuthError,
|
|
8
|
+
createApplicationAuthClient,
|
|
7
9
|
createLuthAuthClient,
|
|
8
10
|
createLuthAuthClient2,
|
|
9
11
|
createUniversalAuthFetch,
|
|
@@ -13,7 +15,7 @@ import {
|
|
|
13
15
|
resolveClientEnvironment,
|
|
14
16
|
resolveClientOrigin,
|
|
15
17
|
verifyLuthRequest
|
|
16
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-WYC7RG32.js";
|
|
17
19
|
|
|
18
20
|
// src/browserExecutionClient.ts
|
|
19
21
|
var BrowserExecutionClient = class {
|
|
@@ -188,6 +190,7 @@ var OPFSWorkspaceStorage = class {
|
|
|
188
190
|
}
|
|
189
191
|
};
|
|
190
192
|
export {
|
|
193
|
+
ApplicationAuthClient,
|
|
191
194
|
BrowserExecutionClient,
|
|
192
195
|
CANONICAL_PUBLIC_ROUTES,
|
|
193
196
|
LuthAuthClient2 as CanonicalAuthClient,
|
|
@@ -196,6 +199,7 @@ export {
|
|
|
196
199
|
LuthAuthError,
|
|
197
200
|
OPFSWorkspaceStorage,
|
|
198
201
|
WorkspaceAutosaveController,
|
|
202
|
+
createApplicationAuthClient,
|
|
199
203
|
createBrowserExecutionClient,
|
|
200
204
|
createLuthAuthClient2 as createCanonicalAuthClient,
|
|
201
205
|
createLuthAuthClient,
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SmallScriptLimitError
|
|
3
|
+
} from "./chunk-SMWRWNEW.js";
|
|
4
|
+
|
|
5
|
+
// src/quickJsAdapter.ts
|
|
6
|
+
var LOCK_DOWN = `
|
|
7
|
+
for (const fn of [function () {}, async function () {}, function* () {}, async function* () {}]) {
|
|
8
|
+
Object.defineProperty(Object.getPrototypeOf(fn), 'constructor', {
|
|
9
|
+
value: undefined, writable: false, configurable: false,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
for (const name of ['eval', 'Function']) {
|
|
13
|
+
Object.defineProperty(globalThis, name, {
|
|
14
|
+
value: undefined, writable: false, configurable: false,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
function createQuickJsSmallScriptExecutor(load, now = () => performance.now()) {
|
|
19
|
+
return {
|
|
20
|
+
async execute({ code, inputs, limits, signal }) {
|
|
21
|
+
checkCancellation(signal);
|
|
22
|
+
let quickjs;
|
|
23
|
+
try {
|
|
24
|
+
quickjs = await load();
|
|
25
|
+
} catch {
|
|
26
|
+
checkCancellation(signal);
|
|
27
|
+
throw new SmallScriptLimitError("EXECUTOR_UNAVAILABLE", "Isolated JavaScript interpreter could not be loaded.");
|
|
28
|
+
}
|
|
29
|
+
checkCancellation(signal);
|
|
30
|
+
const started = now();
|
|
31
|
+
const runtime = quickjs.newRuntime();
|
|
32
|
+
let checks = 0;
|
|
33
|
+
let interrupted = false;
|
|
34
|
+
let vm;
|
|
35
|
+
const checkBudget = () => {
|
|
36
|
+
checkCancellation(signal);
|
|
37
|
+
if (interrupted || now() - started >= limits.wallMs) {
|
|
38
|
+
throw new SmallScriptLimitError("SCRIPT_INTERRUPTED", "JavaScript execution budget exhausted.");
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
runtime.setMemoryLimit(limits.heapBytes);
|
|
43
|
+
runtime.setMaxStackSize(256 * 1024);
|
|
44
|
+
runtime.setInterruptHandler(() => {
|
|
45
|
+
checks += 1;
|
|
46
|
+
interrupted ||= Boolean(signal?.aborted) || checks >= limits.maxInterruptChecks || now() - started >= limits.wallMs;
|
|
47
|
+
return interrupted;
|
|
48
|
+
});
|
|
49
|
+
vm = runtime.newContext();
|
|
50
|
+
const setup = vm.evalCode(LOCK_DOWN);
|
|
51
|
+
try {
|
|
52
|
+
checkBudget();
|
|
53
|
+
if (setup.error || !setup.value) {
|
|
54
|
+
throw new SmallScriptLimitError("EXECUTOR_UNAVAILABLE", "JavaScript sandbox initialization failed.");
|
|
55
|
+
}
|
|
56
|
+
} finally {
|
|
57
|
+
setup.error?.dispose();
|
|
58
|
+
setup.value?.dispose();
|
|
59
|
+
}
|
|
60
|
+
const wrapper = [
|
|
61
|
+
'(function () { "use strict";',
|
|
62
|
+
"const stringify = JSON.stringify;",
|
|
63
|
+
"const inputs = JSON.parse(" + JSON.stringify(JSON.stringify(inputs)) + ");",
|
|
64
|
+
"const result = (function () {",
|
|
65
|
+
code,
|
|
66
|
+
"})();",
|
|
67
|
+
'if (result && typeof result.then === "function") return undefined;',
|
|
68
|
+
"return stringify(result, (_key, value) => {",
|
|
69
|
+
' if (value === undefined || typeof value === "function" || typeof value === "symbol" ||',
|
|
70
|
+
' (typeof value === "number" && !Number.isFinite(value))) throw new TypeError();',
|
|
71
|
+
" return value;",
|
|
72
|
+
"});",
|
|
73
|
+
"})()"
|
|
74
|
+
].join("\n");
|
|
75
|
+
const result = vm.evalCode(wrapper);
|
|
76
|
+
try {
|
|
77
|
+
checkBudget();
|
|
78
|
+
if (result.error) {
|
|
79
|
+
throw new SmallScriptLimitError("SCRIPT_ERROR", "JavaScript execution failed.");
|
|
80
|
+
}
|
|
81
|
+
if (!result.value || vm.typeof(result.value) !== "string") {
|
|
82
|
+
throw new SmallScriptLimitError("INVALID_JSON", "JavaScript must return synchronous JSON data.");
|
|
83
|
+
}
|
|
84
|
+
const encoded = vm.getString(result.value);
|
|
85
|
+
checkBudget();
|
|
86
|
+
if (new TextEncoder().encode(encoded).byteLength > limits.outputBytes) {
|
|
87
|
+
throw new SmallScriptLimitError("PAYLOAD_TOO_LARGE", "JavaScript output exceeds its byte budget.");
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(encoded);
|
|
91
|
+
} catch {
|
|
92
|
+
throw new SmallScriptLimitError("INVALID_JSON", "JavaScript returned invalid JSON.");
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
result.error?.dispose();
|
|
96
|
+
result.value?.dispose();
|
|
97
|
+
}
|
|
98
|
+
} finally {
|
|
99
|
+
vm?.dispose();
|
|
100
|
+
runtime.dispose();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function checkCancellation(signal) {
|
|
106
|
+
if (signal?.aborted) throw new SmallScriptLimitError("CANCELLED", "Execution was cancelled.");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
createQuickJsSmallScriptExecutor
|
|
111
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/smallScript.ts
|
|
2
|
+
var DEFAULT_SMALL_SCRIPT_LIMITS = Object.freeze({
|
|
3
|
+
sourceBytes: 8 * 1024,
|
|
4
|
+
inputBytes: 64 * 1024,
|
|
5
|
+
outputBytes: 64 * 1024,
|
|
6
|
+
heapBytes: 32 * 1024 * 1024,
|
|
7
|
+
wallMs: 100,
|
|
8
|
+
// QuickJS interrupt callbacks are not one callback per JS instruction.
|
|
9
|
+
maxInterruptChecks: 1e5,
|
|
10
|
+
maxAttempts: 1
|
|
11
|
+
});
|
|
12
|
+
var SmallScriptLimitError = class extends Error {
|
|
13
|
+
constructor(code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.name = "SmallScriptLimitError";
|
|
17
|
+
}
|
|
18
|
+
code;
|
|
19
|
+
};
|
|
20
|
+
function utf8Length(text) {
|
|
21
|
+
return new TextEncoder().encode(text).byteLength;
|
|
22
|
+
}
|
|
23
|
+
function jsonBoundary(value, maxBytes, label) {
|
|
24
|
+
let encoded;
|
|
25
|
+
try {
|
|
26
|
+
encoded = JSON.stringify(value, (_key, item) => {
|
|
27
|
+
if (item === void 0 || typeof item === "function" || typeof item === "symbol" || typeof item === "number" && !Number.isFinite(item)) {
|
|
28
|
+
throw new TypeError("Invalid JSON value");
|
|
29
|
+
}
|
|
30
|
+
return item;
|
|
31
|
+
});
|
|
32
|
+
} catch {
|
|
33
|
+
throw new SmallScriptLimitError("INVALID_JSON", label + " must be valid JSON.");
|
|
34
|
+
}
|
|
35
|
+
if (encoded === void 0) throw new SmallScriptLimitError("INVALID_JSON", label + " must be JSON serializable.");
|
|
36
|
+
if (utf8Length(encoded) > maxBytes) {
|
|
37
|
+
throw new SmallScriptLimitError("PAYLOAD_TOO_LARGE", label + " exceeds " + maxBytes + " bytes.");
|
|
38
|
+
}
|
|
39
|
+
const decoded = JSON.parse(encoded);
|
|
40
|
+
return decoded;
|
|
41
|
+
}
|
|
42
|
+
async function executeSmallScript(executor, code, input, signal, limits = DEFAULT_SMALL_SCRIPT_LIMITS) {
|
|
43
|
+
if (!executor) throw new SmallScriptLimitError("EXECUTOR_UNAVAILABLE", "Isolated JavaScript executor is not configured.");
|
|
44
|
+
for (const key of ["sourceBytes", "inputBytes", "outputBytes", "heapBytes", "wallMs", "maxInterruptChecks"]) {
|
|
45
|
+
if (!Number.isSafeInteger(limits[key]) || limits[key] < 1 || limits[key] > DEFAULT_SMALL_SCRIPT_LIMITS[key]) {
|
|
46
|
+
throw new SmallScriptLimitError("INVALID_LIMITS", "Invalid JavaScript execution budget for " + key + ".");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (limits.maxAttempts !== 1) throw new SmallScriptLimitError("INVALID_LIMITS", "JavaScript execution allows one attempt.");
|
|
50
|
+
if (typeof code !== "string" || !code.trim()) {
|
|
51
|
+
throw new SmallScriptLimitError("INVALID_SCRIPT", "JavaScript source must be a non-empty string.");
|
|
52
|
+
}
|
|
53
|
+
if (utf8Length(code) > limits.sourceBytes) {
|
|
54
|
+
throw new SmallScriptLimitError("SCRIPT_TOO_LARGE", "JavaScript source exceeds " + limits.sourceBytes + " UTF-8 bytes.");
|
|
55
|
+
}
|
|
56
|
+
if (signal?.aborted) throw new SmallScriptLimitError("CANCELLED", "Execution was cancelled.");
|
|
57
|
+
const cleanInputs = jsonBoundary(input, limits.inputBytes, "JavaScript input");
|
|
58
|
+
if (!cleanInputs || typeof cleanInputs !== "object" || Array.isArray(cleanInputs)) {
|
|
59
|
+
throw new SmallScriptLimitError("INVALID_JSON", "JavaScript input must be a JSON object.");
|
|
60
|
+
}
|
|
61
|
+
const output = await executor.execute({ code, inputs: cleanInputs, limits, signal });
|
|
62
|
+
return jsonBoundary(output, limits.outputBytes, "JavaScript output");
|
|
63
|
+
}
|
|
64
|
+
var SMALL_SCRIPT_NODE = {
|
|
65
|
+
type: "system/javascript",
|
|
66
|
+
label: "JavaScript",
|
|
67
|
+
description: "Run a small, bounded JavaScript transform using an isolated executor.",
|
|
68
|
+
category: "system",
|
|
69
|
+
group: "Code",
|
|
70
|
+
inputs: [{ id: "input", name: "Input", direction: "input", dataType: "any" }],
|
|
71
|
+
outputs: [{ id: "result", name: "Result", direction: "output", dataType: "any" }],
|
|
72
|
+
metadata: { requiresIsolatedExecutor: true, maxSourceBytes: DEFAULT_SMALL_SCRIPT_LIMITS.sourceBytes }
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
DEFAULT_SMALL_SCRIPT_LIMITS,
|
|
77
|
+
SmallScriptLimitError,
|
|
78
|
+
jsonBoundary,
|
|
79
|
+
executeSmallScript,
|
|
80
|
+
SMALL_SCRIPT_NODE
|
|
81
|
+
};
|
|
@@ -1,97 +1,8 @@
|
|
|
1
1
|
import * as _ultrst_armada_krnl from '@ultrst-armada/krnl';
|
|
2
2
|
import { ServiceDefinition } from '@ultrst-armada/krnl';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface FodPort {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
direction: FodPortDirection;
|
|
10
|
-
dataType: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
description?: string;
|
|
13
|
-
schema?: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
interface FodNodeDefinition {
|
|
16
|
-
type: string;
|
|
17
|
-
label: string;
|
|
18
|
-
description: string;
|
|
19
|
-
category: FodNodeCategory;
|
|
20
|
-
group: string;
|
|
21
|
-
inputs: FodPort[];
|
|
22
|
-
outputs: FodPort[];
|
|
23
|
-
metadata?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
interface FodEndpointDescriptor {
|
|
26
|
-
id: string;
|
|
27
|
-
serviceId: string;
|
|
28
|
-
serviceName: string;
|
|
29
|
-
operationId: string;
|
|
30
|
-
operationName: string;
|
|
31
|
-
description?: string;
|
|
32
|
-
runtime?: string;
|
|
33
|
-
deployment?: string;
|
|
34
|
-
inputSchema?: Record<string, unknown>;
|
|
35
|
-
outputSchema?: Record<string, unknown>;
|
|
36
|
-
invoke: (input: unknown) => Promise<unknown>;
|
|
37
|
-
}
|
|
38
|
-
interface FodFlowNode {
|
|
39
|
-
id: string;
|
|
40
|
-
type: string;
|
|
41
|
-
position: {
|
|
42
|
-
x: number;
|
|
43
|
-
y: number;
|
|
44
|
-
};
|
|
45
|
-
data: Record<string, unknown>;
|
|
46
|
-
}
|
|
47
|
-
interface FodFlowEdge {
|
|
48
|
-
id: string;
|
|
49
|
-
source: string;
|
|
50
|
-
sourceHandle?: string;
|
|
51
|
-
target: string;
|
|
52
|
-
targetHandle?: string;
|
|
53
|
-
}
|
|
54
|
-
interface FodFlow {
|
|
55
|
-
id: string;
|
|
56
|
-
name: string;
|
|
57
|
-
description?: string;
|
|
58
|
-
version: number;
|
|
59
|
-
createdAt: string;
|
|
60
|
-
updatedAt: string;
|
|
61
|
-
nodes: FodFlowNode[];
|
|
62
|
-
edges: FodFlowEdge[];
|
|
63
|
-
viewport?: {
|
|
64
|
-
x: number;
|
|
65
|
-
y: number;
|
|
66
|
-
zoom: number;
|
|
67
|
-
};
|
|
68
|
-
metadata?: Record<string, unknown>;
|
|
69
|
-
}
|
|
70
|
-
interface FodExecutionEvent {
|
|
71
|
-
type: 'flow-started' | 'node-started' | 'node-completed' | 'node-failed' | 'flow-completed';
|
|
72
|
-
timestamp: number;
|
|
73
|
-
flowId: string;
|
|
74
|
-
nodeId?: string;
|
|
75
|
-
data?: unknown;
|
|
76
|
-
}
|
|
77
|
-
interface FodExecutionResult {
|
|
78
|
-
success: boolean;
|
|
79
|
-
flowId: string;
|
|
80
|
-
output: unknown;
|
|
81
|
-
outputs: Record<string, unknown>;
|
|
82
|
-
errors: Array<{
|
|
83
|
-
nodeId?: string;
|
|
84
|
-
message: string;
|
|
85
|
-
}>;
|
|
86
|
-
events: FodExecutionEvent[];
|
|
87
|
-
}
|
|
88
|
-
interface FodRuntimeOptions {
|
|
89
|
-
workspaceId: string;
|
|
90
|
-
workspaceService: any;
|
|
91
|
-
endpoints?: FodEndpointDescriptor[];
|
|
92
|
-
nodes?: FodNodeDefinition[];
|
|
93
|
-
onEvent?: (event: FodExecutionEvent) => void;
|
|
94
|
-
}
|
|
3
|
+
import { F as FodEndpointDescriptor, a as FodNodeDefinition, b as FodFlow, c as FodExecutionEvent, S as SmallScriptExecutor, d as FodExecutionResult } from './smallScript-wzJ-VayJ.js';
|
|
4
|
+
export { D as DEFAULT_SMALL_SCRIPT_LIMITS, e as FodFlowEdge, f as FodFlowNode, g as FodNodeCategory, h as FodPort, i as FodPortDirection, j as FodRuntimeOptions, k as SMALL_SCRIPT_NODE, l as SmallScriptLimitError, m as SmallScriptLimits, n as SmallScriptRequest, o as executeSmallScript, p as jsonBoundary } from './smallScript-wzJ-VayJ.js';
|
|
5
|
+
export { Q as QuickJsModule, c as createQuickJsSmallScriptExecutor } from './quickJsAdapter-BRj8ixha.js';
|
|
95
6
|
|
|
96
7
|
declare function scanBackendFacade(facade: Record<string, unknown>): FodEndpointDescriptor[];
|
|
97
8
|
declare function endpointToNode(endpoint: FodEndpointDescriptor): FodNodeDefinition;
|
|
@@ -109,7 +20,10 @@ declare class FodFlowStore {
|
|
|
109
20
|
delete(workspaceId: string, flowId: string): Promise<boolean>;
|
|
110
21
|
}
|
|
111
22
|
|
|
112
|
-
declare function executeFodFlow(flow: FodFlow, endpoints: Map<string, FodEndpointDescriptor>, onEvent?: (event: FodExecutionEvent) => void, initialInput?: unknown
|
|
23
|
+
declare function executeFodFlow(flow: FodFlow, endpoints: Map<string, FodEndpointDescriptor>, onEvent?: (event: FodExecutionEvent) => void, initialInput?: unknown, options?: {
|
|
24
|
+
scriptExecutor?: SmallScriptExecutor;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}): Promise<FodExecutionResult>;
|
|
113
27
|
|
|
114
28
|
declare class FodRuntime {
|
|
115
29
|
private readonly options;
|
|
@@ -120,6 +34,7 @@ declare class FodRuntime {
|
|
|
120
34
|
workspaceId: string;
|
|
121
35
|
workspaceService: any;
|
|
122
36
|
onEvent?: (event: any) => void;
|
|
37
|
+
scriptExecutor?: SmallScriptExecutor;
|
|
123
38
|
});
|
|
124
39
|
setEndpoints(endpoints: FodEndpointDescriptor[], nodes?: FodNodeDefinition[]): void;
|
|
125
40
|
getNodeDefinitions(): FodNodeDefinition[];
|
|
@@ -128,7 +43,9 @@ declare class FodRuntime {
|
|
|
128
43
|
getFlow(flowId: string): Promise<FodFlow | null>;
|
|
129
44
|
saveFlow(flow: FodFlow): Promise<FodFlow>;
|
|
130
45
|
deleteFlow(flowId: string): Promise<boolean>;
|
|
131
|
-
executeFlow(flowId: string, input?: unknown
|
|
46
|
+
executeFlow(flowId: string, input?: unknown, options?: {
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}): Promise<FodExecutionResult>;
|
|
132
49
|
}
|
|
133
50
|
|
|
134
51
|
declare function createFodServiceFacade(runtime: FodRuntime): {
|
|
@@ -162,4 +79,4 @@ declare const FodServiceFacade: {
|
|
|
162
79
|
execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
|
|
163
80
|
};
|
|
164
81
|
|
|
165
|
-
export {
|
|
82
|
+
export { FodEndpointDescriptor, FodExecutionEvent, FodExecutionResult, FodFlow, FodFlowStore, FodNodeDefinition, FodRuntime, FodServiceFacade, SmallScriptExecutor, createFodServiceFacade, createFodServiceFacadeForWorkspace, endpointToNode, executeFodFlow, scanBackendFacade, scanBackendFacadeToNodes };
|