@mondaydotcomorg/atp-server 0.17.14
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 +489 -0
- package/dist/aggregator/index.d.ts +59 -0
- package/dist/aggregator/index.d.ts.map +1 -0
- package/dist/aggregator/index.js +171 -0
- package/dist/aggregator/index.js.map +1 -0
- package/dist/callback/index.d.ts +98 -0
- package/dist/callback/index.d.ts.map +1 -0
- package/dist/callback/index.js +136 -0
- package/dist/callback/index.js.map +1 -0
- package/dist/client-sessions.d.ts +82 -0
- package/dist/client-sessions.d.ts.map +1 -0
- package/dist/client-sessions.js +174 -0
- package/dist/client-sessions.js.map +1 -0
- package/dist/controllers/definitions.controller.d.ts +4 -0
- package/dist/controllers/definitions.controller.d.ts.map +1 -0
- package/dist/controllers/definitions.controller.js +11 -0
- package/dist/controllers/definitions.controller.js.map +1 -0
- package/dist/controllers/execute.controller.d.ts +18 -0
- package/dist/controllers/execute.controller.d.ts.map +1 -0
- package/dist/controllers/execute.controller.js +122 -0
- package/dist/controllers/execute.controller.js.map +1 -0
- package/dist/controllers/info.controller.d.ts +3 -0
- package/dist/controllers/info.controller.d.ts.map +1 -0
- package/dist/controllers/info.controller.js +13 -0
- package/dist/controllers/info.controller.js.map +1 -0
- package/dist/controllers/resume.controller.d.ts +11 -0
- package/dist/controllers/resume.controller.d.ts.map +1 -0
- package/dist/controllers/resume.controller.js +61 -0
- package/dist/controllers/resume.controller.js.map +1 -0
- package/dist/controllers/search.controller.d.ts +4 -0
- package/dist/controllers/search.controller.d.ts.map +1 -0
- package/dist/controllers/search.controller.js +7 -0
- package/dist/controllers/search.controller.js.map +1 -0
- package/dist/controllers/stream.controller.d.ts +19 -0
- package/dist/controllers/stream.controller.d.ts.map +1 -0
- package/dist/controllers/stream.controller.js +141 -0
- package/dist/controllers/stream.controller.js.map +1 -0
- package/dist/core/config.d.ts +161 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +7 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/http.d.ts +4 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +17 -0
- package/dist/core/http.js.map +1 -0
- package/dist/create-server.d.ts +120 -0
- package/dist/create-server.d.ts.map +1 -0
- package/dist/create-server.js +423 -0
- package/dist/create-server.js.map +1 -0
- package/dist/execution-state/index.d.ts +95 -0
- package/dist/execution-state/index.d.ts.map +1 -0
- package/dist/execution-state/index.js +128 -0
- package/dist/execution-state/index.js.map +1 -0
- package/dist/executor/ast-provenance-bridge.d.ts +12 -0
- package/dist/executor/ast-provenance-bridge.d.ts.map +1 -0
- package/dist/executor/ast-provenance-bridge.js +66 -0
- package/dist/executor/ast-provenance-bridge.js.map +1 -0
- package/dist/executor/ast-tracking-runtime.d.ts +7 -0
- package/dist/executor/ast-tracking-runtime.d.ts.map +1 -0
- package/dist/executor/ast-tracking-runtime.js +559 -0
- package/dist/executor/ast-tracking-runtime.js.map +1 -0
- package/dist/executor/bootstrap-generated.d.ts +32 -0
- package/dist/executor/bootstrap-generated.d.ts.map +1 -0
- package/dist/executor/bootstrap-generated.js +90 -0
- package/dist/executor/bootstrap-generated.js.map +1 -0
- package/dist/executor/compiler-config.d.ts +32 -0
- package/dist/executor/compiler-config.d.ts.map +1 -0
- package/dist/executor/compiler-config.js +99 -0
- package/dist/executor/compiler-config.js.map +1 -0
- package/dist/executor/constants.d.ts +4 -0
- package/dist/executor/constants.d.ts.map +1 -0
- package/dist/executor/constants.js +4 -0
- package/dist/executor/constants.js.map +1 -0
- package/dist/executor/error-handler.d.ts +9 -0
- package/dist/executor/error-handler.d.ts.map +1 -0
- package/dist/executor/error-handler.js +95 -0
- package/dist/executor/error-handler.js.map +1 -0
- package/dist/executor/execution-error-handler.d.ts +7 -0
- package/dist/executor/execution-error-handler.d.ts.map +1 -0
- package/dist/executor/execution-error-handler.js +136 -0
- package/dist/executor/execution-error-handler.js.map +1 -0
- package/dist/executor/executor.d.ts +20 -0
- package/dist/executor/executor.d.ts.map +1 -0
- package/dist/executor/executor.js +452 -0
- package/dist/executor/executor.js.map +1 -0
- package/dist/executor/index.d.ts +4 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +3 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/resume-handler.d.ts +9 -0
- package/dist/executor/resume-handler.d.ts.map +1 -0
- package/dist/executor/resume-handler.js +22 -0
- package/dist/executor/resume-handler.js.map +1 -0
- package/dist/executor/sandbox-builder.d.ts +29 -0
- package/dist/executor/sandbox-builder.d.ts.map +1 -0
- package/dist/executor/sandbox-builder.js +538 -0
- package/dist/executor/sandbox-builder.js.map +1 -0
- package/dist/executor/sandbox-injector.d.ts +7 -0
- package/dist/executor/sandbox-injector.d.ts.map +1 -0
- package/dist/executor/sandbox-injector.js +293 -0
- package/dist/executor/sandbox-injector.js.map +1 -0
- package/dist/executor/types.d.ts +21 -0
- package/dist/executor/types.d.ts.map +1 -0
- package/dist/executor/types.js +2 -0
- package/dist/executor/types.js.map +1 -0
- package/dist/explorer/index.d.ts +69 -0
- package/dist/explorer/index.d.ts.map +1 -0
- package/dist/explorer/index.js +228 -0
- package/dist/explorer/index.js.map +1 -0
- package/dist/handlers/definitions.handler.d.ts +3 -0
- package/dist/handlers/definitions.handler.d.ts.map +1 -0
- package/dist/handlers/definitions.handler.js +11 -0
- package/dist/handlers/definitions.handler.js.map +1 -0
- package/dist/handlers/execute.handler.d.ts +7 -0
- package/dist/handlers/execute.handler.d.ts.map +1 -0
- package/dist/handlers/execute.handler.js +225 -0
- package/dist/handlers/execute.handler.js.map +1 -0
- package/dist/handlers/explorer.handler.d.ts +4 -0
- package/dist/handlers/explorer.handler.d.ts.map +1 -0
- package/dist/handlers/explorer.handler.js +10 -0
- package/dist/handlers/explorer.handler.js.map +1 -0
- package/dist/handlers/init.handler.d.ts +5 -0
- package/dist/handlers/init.handler.d.ts.map +1 -0
- package/dist/handlers/init.handler.js +41 -0
- package/dist/handlers/init.handler.js.map +1 -0
- package/dist/handlers/resume.handler.d.ts +6 -0
- package/dist/handlers/resume.handler.d.ts.map +1 -0
- package/dist/handlers/resume.handler.js +256 -0
- package/dist/handlers/resume.handler.js.map +1 -0
- package/dist/handlers/search.handler.d.ts +5 -0
- package/dist/handlers/search.handler.d.ts.map +1 -0
- package/dist/handlers/search.handler.js +11 -0
- package/dist/handlers/search.handler.js.map +1 -0
- package/dist/http/request-handler.d.ts +15 -0
- package/dist/http/request-handler.d.ts.map +1 -0
- package/dist/http/request-handler.js +94 -0
- package/dist/http/request-handler.js.map +1 -0
- package/dist/http/router.d.ts +4 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +32 -0
- package/dist/http/router.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/index.d.ts +5 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/index.js +5 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/serializer.d.ts +61 -0
- package/dist/instrumentation/serializer.d.ts.map +1 -0
- package/dist/instrumentation/serializer.js +334 -0
- package/dist/instrumentation/serializer.js.map +1 -0
- package/dist/instrumentation/state-manager.d.ts +61 -0
- package/dist/instrumentation/state-manager.d.ts.map +1 -0
- package/dist/instrumentation/state-manager.js +205 -0
- package/dist/instrumentation/state-manager.js.map +1 -0
- package/dist/instrumentation/transformer.d.ts +9 -0
- package/dist/instrumentation/transformer.d.ts.map +1 -0
- package/dist/instrumentation/transformer.js +70 -0
- package/dist/instrumentation/transformer.js.map +1 -0
- package/dist/instrumentation/types.d.ts +59 -0
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/instrumentation/types.js +5 -0
- package/dist/instrumentation/types.js.map +1 -0
- package/dist/middleware/audit.d.ts +18 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/audit.js +76 -0
- package/dist/middleware/audit.js.map +1 -0
- package/dist/openapi/index.d.ts +133 -0
- package/dist/openapi/index.d.ts.map +1 -0
- package/dist/openapi/index.js +235 -0
- package/dist/openapi/index.js.map +1 -0
- package/dist/openapi-loader.d.ts +87 -0
- package/dist/openapi-loader.d.ts.map +1 -0
- package/dist/openapi-loader.js +491 -0
- package/dist/openapi-loader.js.map +1 -0
- package/dist/routes/index.d.ts +21 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +47 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/search/index.d.ts +48 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +156 -0
- package/dist/search/index.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +2 -0
- package/dist/security/index.js.map +1 -0
- package/dist/shutdown.d.ts +19 -0
- package/dist/shutdown.d.ts.map +1 -0
- package/dist/shutdown.js +87 -0
- package/dist/shutdown.js.map +1 -0
- package/dist/utils/banner.d.ts +12 -0
- package/dist/utils/banner.d.ts.map +1 -0
- package/dist/utils/banner.js +18 -0
- package/dist/utils/banner.js.map +1 -0
- package/dist/utils/context.d.ts +16 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +44 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +17 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/hint-based-instrumentation.d.ts +14 -0
- package/dist/utils/hint-based-instrumentation.d.ts.map +1 -0
- package/dist/utils/hint-based-instrumentation.js +84 -0
- package/dist/utils/hint-based-instrumentation.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/info.d.ts +20 -0
- package/dist/utils/info.d.ts.map +1 -0
- package/dist/utils/info.js +15 -0
- package/dist/utils/info.js.map +1 -0
- package/dist/utils/provenance-reattachment.d.ts +32 -0
- package/dist/utils/provenance-reattachment.d.ts.map +1 -0
- package/dist/utils/provenance-reattachment.js +115 -0
- package/dist/utils/provenance-reattachment.js.map +1 -0
- package/dist/utils/request.d.ts +21 -0
- package/dist/utils/request.d.ts.map +1 -0
- package/dist/utils/request.js +44 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/response.d.ts +30 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +53 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/utils/runtime-types.d.ts +6 -0
- package/dist/utils/runtime-types.d.ts.map +1 -0
- package/dist/utils/runtime-types.js +14 -0
- package/dist/utils/runtime-types.js.map +1 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +13 -0
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/token-emitter.d.ts +21 -0
- package/dist/utils/token-emitter.d.ts.map +1 -0
- package/dist/utils/token-emitter.js +129 -0
- package/dist/utils/token-emitter.js.map +1 -0
- package/dist/validator/index.d.ts +36 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +224 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +68 -0
- package/src/aggregator/index.ts +207 -0
- package/src/callback/index.ts +191 -0
- package/src/client-sessions.ts +234 -0
- package/src/controllers/definitions.controller.ts +19 -0
- package/src/controllers/execute.controller.ts +166 -0
- package/src/controllers/info.controller.ts +14 -0
- package/src/controllers/resume.controller.ts +92 -0
- package/src/controllers/search.controller.ts +16 -0
- package/src/controllers/stream.controller.ts +190 -0
- package/src/core/config.ts +180 -0
- package/src/core/http.ts +21 -0
- package/src/create-server.ts +536 -0
- package/src/execution-state/index.ts +204 -0
- package/src/executor/ast-provenance-bridge.ts +80 -0
- package/src/executor/ast-tracking-runtime.ts +558 -0
- package/src/executor/bootstrap-generated.ts +90 -0
- package/src/executor/compiler-config.ts +146 -0
- package/src/executor/constants.ts +5 -0
- package/src/executor/error-handler.ts +118 -0
- package/src/executor/execution-error-handler.ts +178 -0
- package/src/executor/executor.ts +631 -0
- package/src/executor/index.ts +3 -0
- package/src/executor/resume-handler.ts +39 -0
- package/src/executor/sandbox-builder.ts +684 -0
- package/src/executor/sandbox-injector.ts +345 -0
- package/src/executor/types.ts +22 -0
- package/src/explorer/index.ts +297 -0
- package/src/handlers/definitions.handler.ts +13 -0
- package/src/handlers/execute.handler.ts +286 -0
- package/src/handlers/explorer.handler.ts +18 -0
- package/src/handlers/init.handler.ts +53 -0
- package/src/handlers/resume.handler.ts +316 -0
- package/src/handlers/search.handler.ts +32 -0
- package/src/http/request-handler.ts +117 -0
- package/src/http/router.ts +29 -0
- package/src/index.ts +60 -0
- package/src/instrumentation/index.ts +4 -0
- package/src/instrumentation/serializer.ts +421 -0
- package/src/instrumentation/state-manager.ts +237 -0
- package/src/instrumentation/transformer.ts +84 -0
- package/src/instrumentation/types.ts +76 -0
- package/src/middleware/audit.ts +101 -0
- package/src/openapi/index.ts +378 -0
- package/src/openapi-loader.ts +744 -0
- package/src/routes/index.ts +93 -0
- package/src/search/index.ts +216 -0
- package/src/security/index.ts +1 -0
- package/src/shutdown.ts +108 -0
- package/src/utils/banner.ts +25 -0
- package/src/utils/context.ts +58 -0
- package/src/utils/error.ts +25 -0
- package/src/utils/hint-based-instrumentation.ts +99 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/info.ts +31 -0
- package/src/utils/provenance-reattachment.ts +144 -0
- package/src/utils/request.ts +53 -0
- package/src/utils/response.ts +69 -0
- package/src/utils/runtime-types.ts +14 -0
- package/src/utils/schema.ts +18 -0
- package/src/utils/token-emitter.ts +182 -0
- package/src/validator/index.ts +253 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Logger } from '@mondaydotcomorg/atp-runtime';
|
|
2
|
+
import type { CacheProvider } from '@mondaydotcomorg/atp-protocol';
|
|
3
|
+
import {
|
|
4
|
+
ATPCompiler,
|
|
5
|
+
initializeRuntime as initializeCompilerRuntime,
|
|
6
|
+
resumableForOf,
|
|
7
|
+
resumableWhile,
|
|
8
|
+
resumableForLoop,
|
|
9
|
+
resumableMap,
|
|
10
|
+
resumableForEach,
|
|
11
|
+
resumableFilter,
|
|
12
|
+
resumableReduce,
|
|
13
|
+
resumableFind,
|
|
14
|
+
resumableSome,
|
|
15
|
+
resumableEvery,
|
|
16
|
+
resumableFlatMap,
|
|
17
|
+
resumablePromiseAll,
|
|
18
|
+
resumablePromiseAllSettled,
|
|
19
|
+
batchParallel,
|
|
20
|
+
} from '@mondaydotcomorg/atp-compiler';
|
|
21
|
+
import { ATP_COMPILER_ENABLED, ATP_BATCH_SIZE_THRESHOLD } from './constants.js';
|
|
22
|
+
|
|
23
|
+
const transformCache = new Map<string, string>();
|
|
24
|
+
|
|
25
|
+
function getCodeHash(code: string): string {
|
|
26
|
+
let hash = 0;
|
|
27
|
+
for (let i = 0; i < code.length; i++) {
|
|
28
|
+
const char = code.charCodeAt(i);
|
|
29
|
+
hash = (hash << 5) - hash + char;
|
|
30
|
+
hash = hash & hash;
|
|
31
|
+
}
|
|
32
|
+
return hash.toString(36);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface CompilerResult {
|
|
36
|
+
code: string;
|
|
37
|
+
useCompiler: boolean;
|
|
38
|
+
metadata?: {
|
|
39
|
+
patterns?: string[];
|
|
40
|
+
batchable?: boolean;
|
|
41
|
+
loopCount?: number;
|
|
42
|
+
arrayMethodCount?: number;
|
|
43
|
+
parallelCallCount?: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getCompilerRuntime() {
|
|
48
|
+
return {
|
|
49
|
+
resumableForOf,
|
|
50
|
+
resumableWhile,
|
|
51
|
+
resumableForLoop,
|
|
52
|
+
resumableMap,
|
|
53
|
+
resumableForEach,
|
|
54
|
+
resumableFilter,
|
|
55
|
+
resumableReduce,
|
|
56
|
+
resumableFind,
|
|
57
|
+
resumableSome,
|
|
58
|
+
resumableEvery,
|
|
59
|
+
resumableFlatMap,
|
|
60
|
+
resumablePromiseAll,
|
|
61
|
+
resumablePromiseAllSettled,
|
|
62
|
+
batchParallel,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function transformCodeWithCompiler(
|
|
67
|
+
code: string,
|
|
68
|
+
executionId: string,
|
|
69
|
+
cacheProvider: CacheProvider,
|
|
70
|
+
executionLogger: Logger
|
|
71
|
+
): Promise<CompilerResult> {
|
|
72
|
+
if (!ATP_COMPILER_ENABLED) {
|
|
73
|
+
return { code, useCompiler: false };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const compiler = new ATPCompiler({
|
|
78
|
+
enableBatchParallel: true,
|
|
79
|
+
batchSizeThreshold: ATP_BATCH_SIZE_THRESHOLD,
|
|
80
|
+
});
|
|
81
|
+
const detection = compiler.detect(code);
|
|
82
|
+
|
|
83
|
+
executionLogger.info('ATP Compiler detection result', {
|
|
84
|
+
needsTransform: detection.needsTransform,
|
|
85
|
+
patterns: detection.patterns,
|
|
86
|
+
batchable: detection.batchableParallel,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (detection.needsTransform) {
|
|
90
|
+
const codeHash = getCodeHash(code);
|
|
91
|
+
const cached = transformCache.get(codeHash);
|
|
92
|
+
if (cached) {
|
|
93
|
+
executionLogger.debug('Using cached transformed code', { codeHash });
|
|
94
|
+
initializeCompilerRuntime({
|
|
95
|
+
executionId,
|
|
96
|
+
cache: cacheProvider,
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
code: cached,
|
|
100
|
+
useCompiler: true,
|
|
101
|
+
metadata: {
|
|
102
|
+
patterns: detection.patterns,
|
|
103
|
+
batchable: detection.batchableParallel,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
initializeCompilerRuntime({
|
|
109
|
+
executionId,
|
|
110
|
+
cache: cacheProvider,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const transformed = compiler.transform(code);
|
|
114
|
+
|
|
115
|
+
transformCache.set(codeHash, transformed.code);
|
|
116
|
+
|
|
117
|
+
executionLogger.info('Code transformed by ATP compiler', {
|
|
118
|
+
patterns: detection.patterns,
|
|
119
|
+
batchable: detection.batchableParallel,
|
|
120
|
+
loopCount: transformed.metadata.loopCount,
|
|
121
|
+
arrayMethodCount: transformed.metadata.arrayMethodCount,
|
|
122
|
+
parallelCallCount: transformed.metadata.parallelCallCount,
|
|
123
|
+
batchSizeThreshold: ATP_BATCH_SIZE_THRESHOLD,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
code: transformed.code,
|
|
128
|
+
useCompiler: true,
|
|
129
|
+
metadata: {
|
|
130
|
+
patterns: detection.patterns,
|
|
131
|
+
batchable: detection.batchableParallel,
|
|
132
|
+
loopCount: transformed.metadata.loopCount,
|
|
133
|
+
arrayMethodCount: transformed.metadata.arrayMethodCount,
|
|
134
|
+
parallelCallCount: transformed.metadata.parallelCallCount,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
executionLogger.error('ATP compiler transformation failed, falling back', {
|
|
140
|
+
error: error instanceof Error ? error.message : String(error),
|
|
141
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return { code, useCompiler: false };
|
|
146
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ExecutionStatus, ExecutionErrorCode } from '@mondaydotcomorg/atp-protocol';
|
|
2
|
+
|
|
3
|
+
export interface ErrorCategory {
|
|
4
|
+
status: ExecutionStatus;
|
|
5
|
+
code: ExecutionErrorCode;
|
|
6
|
+
retryable: boolean;
|
|
7
|
+
suggestion?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function categorizeError(error: Error): ErrorCategory {
|
|
11
|
+
const message = error.message.toLowerCase();
|
|
12
|
+
|
|
13
|
+
if (message.includes('timed out') || message.includes('timeout')) {
|
|
14
|
+
return {
|
|
15
|
+
status: ExecutionStatus.TIMEOUT,
|
|
16
|
+
code: ExecutionErrorCode.TIMEOUT_ERROR,
|
|
17
|
+
retryable: true,
|
|
18
|
+
suggestion:
|
|
19
|
+
'Consider breaking down the operation into smaller steps or increasing the timeout',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (message.includes('memory') || message.includes('heap')) {
|
|
24
|
+
return {
|
|
25
|
+
status: ExecutionStatus.MEMORY_EXCEEDED,
|
|
26
|
+
code: ExecutionErrorCode.MEMORY_LIMIT_EXCEEDED,
|
|
27
|
+
retryable: false,
|
|
28
|
+
suggestion: 'Reduce data size, use streaming, or request higher memory limits',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (message.includes('exceeded max llm calls') || message.includes('llm call')) {
|
|
33
|
+
return {
|
|
34
|
+
status: ExecutionStatus.LLM_CALLS_EXCEEDED,
|
|
35
|
+
code: ExecutionErrorCode.LLM_CALL_LIMIT_EXCEEDED,
|
|
36
|
+
retryable: false,
|
|
37
|
+
suggestion: 'Reduce LLM calls, cache results, or request higher limits',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (
|
|
42
|
+
message.includes('not allowed') ||
|
|
43
|
+
message.includes('forbidden') ||
|
|
44
|
+
message.includes('security')
|
|
45
|
+
) {
|
|
46
|
+
return {
|
|
47
|
+
status: ExecutionStatus.SECURITY_VIOLATION,
|
|
48
|
+
code: ExecutionErrorCode.SECURITY_VIOLATION,
|
|
49
|
+
retryable: false,
|
|
50
|
+
suggestion: 'Remove forbidden operations or use allowed APIs',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (message.includes('syntaxerror') || message.includes('unexpected token')) {
|
|
55
|
+
return {
|
|
56
|
+
status: ExecutionStatus.PARSE_ERROR,
|
|
57
|
+
code: ExecutionErrorCode.SYNTAX_ERROR,
|
|
58
|
+
retryable: false,
|
|
59
|
+
suggestion: 'Check code syntax and fix any errors',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (message.includes('typeerror') || message.includes('is not a function')) {
|
|
64
|
+
return {
|
|
65
|
+
status: ExecutionStatus.FAILED,
|
|
66
|
+
code: ExecutionErrorCode.TYPE_ERROR,
|
|
67
|
+
retryable: false,
|
|
68
|
+
suggestion: 'Check types and ensure methods are called correctly',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (message.includes('referenceerror') || message.includes('is not defined')) {
|
|
73
|
+
return {
|
|
74
|
+
status: ExecutionStatus.FAILED,
|
|
75
|
+
code: ExecutionErrorCode.REFERENCE_ERROR,
|
|
76
|
+
retryable: false,
|
|
77
|
+
suggestion: 'Check variable names and ensure all are defined before use',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
message.includes('network') ||
|
|
83
|
+
message.includes('fetch') ||
|
|
84
|
+
message.includes('econnrefused')
|
|
85
|
+
) {
|
|
86
|
+
return {
|
|
87
|
+
status: ExecutionStatus.NETWORK_ERROR,
|
|
88
|
+
code: ExecutionErrorCode.NETWORK_ERROR,
|
|
89
|
+
retryable: true,
|
|
90
|
+
suggestion: 'Check network connectivity and try again',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (message.includes('loop') || message.includes('infinite')) {
|
|
95
|
+
return {
|
|
96
|
+
status: ExecutionStatus.LOOP_DETECTED,
|
|
97
|
+
code: ExecutionErrorCode.INFINITE_LOOP_DETECTED,
|
|
98
|
+
retryable: false,
|
|
99
|
+
suggestion: 'Review loops and add proper exit conditions',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (message.includes('isolate was disposed')) {
|
|
104
|
+
return {
|
|
105
|
+
status: ExecutionStatus.TIMEOUT,
|
|
106
|
+
code: ExecutionErrorCode.TIMEOUT_ERROR,
|
|
107
|
+
retryable: true,
|
|
108
|
+
suggestion: 'The execution was terminated. Consider increasing timeout or optimizing code',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
status: ExecutionStatus.FAILED,
|
|
114
|
+
code: ExecutionErrorCode.EXECUTION_FAILED,
|
|
115
|
+
retryable: false,
|
|
116
|
+
suggestion: 'Review error message and stack trace for details',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import ivm from 'isolated-vm';
|
|
2
|
+
import { ExecutionStatus } from '@mondaydotcomorg/atp-protocol';
|
|
3
|
+
import type { ExecutionResult } from '@mondaydotcomorg/atp-protocol';
|
|
4
|
+
import type { Logger } from '@mondaydotcomorg/atp-runtime';
|
|
5
|
+
import {
|
|
6
|
+
isPauseError,
|
|
7
|
+
getCallSequenceNumber,
|
|
8
|
+
setPauseForClient,
|
|
9
|
+
setReplayMode,
|
|
10
|
+
type PauseExecutionError,
|
|
11
|
+
} from '@mondaydotcomorg/atp-runtime';
|
|
12
|
+
import {
|
|
13
|
+
isBatchPauseError,
|
|
14
|
+
type BatchPauseExecutionError,
|
|
15
|
+
} from '@mondaydotcomorg/atp-compiler';
|
|
16
|
+
import { nanoid } from 'nanoid';
|
|
17
|
+
import type { CallbackRecord } from '../execution-state/index.js';
|
|
18
|
+
import type { RuntimeContext } from './types.js';
|
|
19
|
+
import { categorizeError } from './error-handler.js';
|
|
20
|
+
import { PAUSE_EXECUTION_MARKER } from './constants.js';
|
|
21
|
+
|
|
22
|
+
export function handleExecutionError(
|
|
23
|
+
error: unknown,
|
|
24
|
+
pauseError: unknown,
|
|
25
|
+
context: RuntimeContext,
|
|
26
|
+
executionId: string,
|
|
27
|
+
callbackHistory: CallbackRecord[],
|
|
28
|
+
memoryBefore: number,
|
|
29
|
+
executionLogger: Logger,
|
|
30
|
+
isolate: ivm.Isolate,
|
|
31
|
+
transformedCode?: string
|
|
32
|
+
): ExecutionResult {
|
|
33
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
34
|
+
|
|
35
|
+
if (errMsg.includes(PAUSE_EXECUTION_MARKER) && pauseError) {
|
|
36
|
+
error = pauseError;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isBatchPauseError(error)) {
|
|
40
|
+
const batchErr = error as BatchPauseExecutionError;
|
|
41
|
+
|
|
42
|
+
executionLogger.info('Execution paused for batch callbacks', {
|
|
43
|
+
batchId: batchErr.batchId,
|
|
44
|
+
callCount: batchErr.calls.length,
|
|
45
|
+
sequenceNumber: batchErr.sequenceNumber,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const batchCallbackRecord: CallbackRecord = {
|
|
49
|
+
type: (batchErr.calls[0]?.type as any) || 'llm',
|
|
50
|
+
operation: 'batch_parallel',
|
|
51
|
+
payload: {
|
|
52
|
+
batchId: batchErr.batchId,
|
|
53
|
+
calls: batchErr.calls,
|
|
54
|
+
},
|
|
55
|
+
sequenceNumber: batchErr.sequenceNumber,
|
|
56
|
+
result: undefined,
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
};
|
|
59
|
+
callbackHistory.push(batchCallbackRecord);
|
|
60
|
+
|
|
61
|
+
const memoryAfter = process.memoryUsage().heapUsed;
|
|
62
|
+
const memoryUsed = Math.max(0, memoryAfter - memoryBefore);
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
isolate.dispose();
|
|
66
|
+
} catch (e) {}
|
|
67
|
+
|
|
68
|
+
setPauseForClient(false);
|
|
69
|
+
setReplayMode(undefined);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
executionId,
|
|
73
|
+
status: ExecutionStatus.PAUSED,
|
|
74
|
+
needsCallbacks: batchErr.calls.map((call: any) => ({
|
|
75
|
+
id: nanoid(),
|
|
76
|
+
type: call.type as any,
|
|
77
|
+
operation: call.operation,
|
|
78
|
+
payload: call.payload,
|
|
79
|
+
})),
|
|
80
|
+
callbackHistory,
|
|
81
|
+
stats: {
|
|
82
|
+
duration: Date.now() - context.startTime,
|
|
83
|
+
memoryUsed,
|
|
84
|
+
llmCallsCount: context.llmCallCount,
|
|
85
|
+
approvalCallsCount: context.approvalCallCount,
|
|
86
|
+
},
|
|
87
|
+
transformedCode,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isPauseError(error)) {
|
|
92
|
+
const pauseErr = error as PauseExecutionError;
|
|
93
|
+
|
|
94
|
+
const currentSequence = getCallSequenceNumber() - 1;
|
|
95
|
+
const callbackRecord: CallbackRecord = {
|
|
96
|
+
type: pauseErr.type,
|
|
97
|
+
operation: pauseErr.operation,
|
|
98
|
+
payload: pauseErr.payload,
|
|
99
|
+
result: undefined,
|
|
100
|
+
timestamp: Date.now(),
|
|
101
|
+
sequenceNumber: currentSequence,
|
|
102
|
+
};
|
|
103
|
+
callbackHistory.push(callbackRecord);
|
|
104
|
+
|
|
105
|
+
executionLogger.info('Execution paused for client callback', {
|
|
106
|
+
type: pauseErr.type,
|
|
107
|
+
operation: pauseErr.operation,
|
|
108
|
+
sequenceNumber: currentSequence,
|
|
109
|
+
historyLength: callbackHistory.length,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const memoryAfter = process.memoryUsage().heapUsed;
|
|
113
|
+
const memoryUsed = Math.max(0, memoryAfter - memoryBefore);
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
isolate.dispose();
|
|
117
|
+
} catch (e) {}
|
|
118
|
+
|
|
119
|
+
setPauseForClient(false);
|
|
120
|
+
setReplayMode(undefined);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
executionId,
|
|
124
|
+
status: ExecutionStatus.PAUSED,
|
|
125
|
+
needsCallback: {
|
|
126
|
+
type: pauseErr.type,
|
|
127
|
+
operation: pauseErr.operation,
|
|
128
|
+
payload: pauseErr.payload,
|
|
129
|
+
},
|
|
130
|
+
callbackHistory,
|
|
131
|
+
stats: {
|
|
132
|
+
duration: Date.now() - context.startTime,
|
|
133
|
+
memoryUsed,
|
|
134
|
+
llmCallsCount: context.llmCallCount,
|
|
135
|
+
approvalCallsCount: context.approvalCallCount,
|
|
136
|
+
},
|
|
137
|
+
transformedCode,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const err = error as Error;
|
|
142
|
+
const errorInfo = categorizeError(err);
|
|
143
|
+
|
|
144
|
+
executionLogger.error('Code execution failed', {
|
|
145
|
+
error: err.message,
|
|
146
|
+
status: errorInfo.status,
|
|
147
|
+
code: errorInfo.code,
|
|
148
|
+
retryable: errorInfo.retryable,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const memoryAfter = process.memoryUsage().heapUsed;
|
|
152
|
+
const memoryUsed = Math.max(0, memoryAfter - memoryBefore);
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
isolate.dispose();
|
|
156
|
+
} catch (e) {}
|
|
157
|
+
|
|
158
|
+
setPauseForClient(false);
|
|
159
|
+
setReplayMode(undefined);
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
executionId,
|
|
163
|
+
status: errorInfo.status,
|
|
164
|
+
error: {
|
|
165
|
+
message: err.message,
|
|
166
|
+
code: errorInfo.code,
|
|
167
|
+
stack: err.stack,
|
|
168
|
+
retryable: errorInfo.retryable,
|
|
169
|
+
suggestion: errorInfo.suggestion,
|
|
170
|
+
},
|
|
171
|
+
stats: {
|
|
172
|
+
duration: Date.now() - context.startTime,
|
|
173
|
+
memoryUsed,
|
|
174
|
+
llmCallsCount: context.llmCallCount,
|
|
175
|
+
approvalCallsCount: context.approvalCallCount,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|