@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,190 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import type { ExecutionConfig } from '@mondaydotcomorg/atp-protocol';
|
|
3
|
+
import {
|
|
4
|
+
ExecutionErrorCode,
|
|
5
|
+
validateExecutionConfig,
|
|
6
|
+
sanitizeInput,
|
|
7
|
+
MAX_CODE_SIZE,
|
|
8
|
+
} from '@mondaydotcomorg/atp-protocol';
|
|
9
|
+
import type { CodeValidator } from '../validator/index.js';
|
|
10
|
+
import type { SandboxExecutor } from '../executor/index.js';
|
|
11
|
+
import type { ExecutionStateManager } from '../execution-state/index.js';
|
|
12
|
+
import { nanoid } from 'nanoid';
|
|
13
|
+
import type { log } from '@mondaydotcomorg/atp-runtime';
|
|
14
|
+
|
|
15
|
+
interface StreamContext {
|
|
16
|
+
validator: CodeValidator;
|
|
17
|
+
executor: SandboxExecutor;
|
|
18
|
+
stateManager?: ExecutionStateManager;
|
|
19
|
+
auditConfig?: { enabled: boolean };
|
|
20
|
+
defaultTimeout: number;
|
|
21
|
+
defaultMemoryLimit: number;
|
|
22
|
+
defaultLLMCallLimit: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function handleExecuteStream(
|
|
26
|
+
req: IncomingMessage,
|
|
27
|
+
res: ServerResponse,
|
|
28
|
+
context: StreamContext,
|
|
29
|
+
body: string,
|
|
30
|
+
clientId: string | undefined,
|
|
31
|
+
logger: ReturnType<typeof log.child>
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
let request: { code: string; config?: Partial<ExecutionConfig> };
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
request = JSON.parse(body);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
logger.warn('Invalid request body', { error });
|
|
39
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
40
|
+
res.end(
|
|
41
|
+
JSON.stringify({
|
|
42
|
+
error: 'Invalid request body',
|
|
43
|
+
message: error instanceof Error ? error.message : 'Failed to parse request',
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
request.code = sanitizeInput(request.code, MAX_CODE_SIZE);
|
|
50
|
+
|
|
51
|
+
logger.info('Streaming code execution request', {
|
|
52
|
+
codeLength: request.code.length,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
res.writeHead(200, {
|
|
56
|
+
'Content-Type': 'text/event-stream',
|
|
57
|
+
'Cache-Control': 'no-cache',
|
|
58
|
+
Connection: 'keep-alive',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const sendEvent = (event: string, data: unknown) => {
|
|
62
|
+
res.write(`event: ${event}\n`);
|
|
63
|
+
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
if (request.config) {
|
|
68
|
+
try {
|
|
69
|
+
validateExecutionConfig(request.config);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
logger.warn('Invalid execution config', { error });
|
|
72
|
+
sendEvent('error', {
|
|
73
|
+
message: error instanceof Error ? error.message : 'Invalid configuration',
|
|
74
|
+
});
|
|
75
|
+
res.end();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const executionConfig: ExecutionConfig = {
|
|
81
|
+
timeout: request.config?.timeout ?? context.defaultTimeout,
|
|
82
|
+
maxMemory: request.config?.maxMemory ?? context.defaultMemoryLimit,
|
|
83
|
+
maxLLMCalls: request.config?.maxLLMCalls ?? context.defaultLLMCallLimit,
|
|
84
|
+
allowedAPIs: request.config?.allowedAPIs ?? [],
|
|
85
|
+
allowLLMCalls: request.config?.allowLLMCalls ?? true,
|
|
86
|
+
progressCallback: (message: string, fraction: number) => {
|
|
87
|
+
sendEvent('progress', { message, fraction });
|
|
88
|
+
},
|
|
89
|
+
clientServices: request.config?.clientServices,
|
|
90
|
+
provenanceMode: request.config?.provenanceMode,
|
|
91
|
+
securityPolicies: request.config?.securityPolicies,
|
|
92
|
+
provenanceHints: request.config?.provenanceHints,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
logger.info('Validating code for streaming execution', {
|
|
96
|
+
codeLength: request.code.length,
|
|
97
|
+
timeout: executionConfig.timeout,
|
|
98
|
+
clientServices: executionConfig.clientServices,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const validationResult = await context.validator.validate(request.code, executionConfig);
|
|
102
|
+
|
|
103
|
+
if (!validationResult.valid) {
|
|
104
|
+
logger.warn('Code validation failed', {
|
|
105
|
+
errors: validationResult.errors?.length,
|
|
106
|
+
securityIssues: validationResult.securityIssues?.length,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const hasSecurityIssues =
|
|
110
|
+
validationResult.securityIssues && validationResult.securityIssues.length > 0;
|
|
111
|
+
|
|
112
|
+
sendEvent('result', {
|
|
113
|
+
executionId: nanoid(),
|
|
114
|
+
status: hasSecurityIssues ? 'security_violation' : 'validation_failed',
|
|
115
|
+
error: {
|
|
116
|
+
message: 'Code validation failed',
|
|
117
|
+
code: hasSecurityIssues
|
|
118
|
+
? ExecutionErrorCode.SECURITY_VIOLATION
|
|
119
|
+
: ExecutionErrorCode.VALIDATION_FAILED,
|
|
120
|
+
context: {
|
|
121
|
+
errors: validationResult.errors,
|
|
122
|
+
securityIssues: validationResult.securityIssues,
|
|
123
|
+
},
|
|
124
|
+
retryable: false,
|
|
125
|
+
suggestion: hasSecurityIssues
|
|
126
|
+
? 'Remove forbidden operations and use only allowed APIs'
|
|
127
|
+
: 'Fix syntax errors and validation issues in your code',
|
|
128
|
+
},
|
|
129
|
+
stats: {
|
|
130
|
+
duration: 0,
|
|
131
|
+
memoryUsed: 0,
|
|
132
|
+
llmCallsCount: 0,
|
|
133
|
+
approvalCallsCount: 0,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
res.end();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
sendEvent('start', { message: 'Execution started' });
|
|
141
|
+
|
|
142
|
+
logger.info('Executing code in sandbox (streaming)');
|
|
143
|
+
const result = await context.executor.execute(request.code, executionConfig, clientId);
|
|
144
|
+
|
|
145
|
+
logger.info('Code execution completed (streaming)', {
|
|
146
|
+
executionId: result.executionId,
|
|
147
|
+
status: result.status,
|
|
148
|
+
duration: result.stats.duration,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
result.status === 'paused' &&
|
|
153
|
+
result.needsCallback &&
|
|
154
|
+
result.callbackHistory &&
|
|
155
|
+
context.stateManager
|
|
156
|
+
) {
|
|
157
|
+
if (!clientId) {
|
|
158
|
+
sendEvent('error', { message: 'Client ID required for paused executions' });
|
|
159
|
+
res.end();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await context.stateManager.pause({
|
|
164
|
+
executionId: result.executionId,
|
|
165
|
+
code: request.code,
|
|
166
|
+
config: executionConfig,
|
|
167
|
+
clientId,
|
|
168
|
+
callbackRequest: result.needsCallback,
|
|
169
|
+
pausedAt: Date.now(),
|
|
170
|
+
callbackHistory: result.callbackHistory,
|
|
171
|
+
currentCallbackIndex: result.callbackHistory.length - 1,
|
|
172
|
+
context: {},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
logger.info('Execution state saved (streaming)', {
|
|
176
|
+
executionId: result.executionId,
|
|
177
|
+
callbackType: result.needsCallback.type,
|
|
178
|
+
historyLength: result.callbackHistory.length,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
sendEvent('result', result);
|
|
183
|
+
res.end();
|
|
184
|
+
} catch (error) {
|
|
185
|
+
const err = error as Error;
|
|
186
|
+
logger.error('Streaming execution error', { error: err.message });
|
|
187
|
+
sendEvent('error', { message: err.message, stack: err.stack });
|
|
188
|
+
res.end();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CacheProvider,
|
|
3
|
+
AuthProvider,
|
|
4
|
+
AuditSink,
|
|
5
|
+
ProvenanceMode,
|
|
6
|
+
SecurityPolicy,
|
|
7
|
+
ScopeFilteringConfig,
|
|
8
|
+
} from '@mondaydotcomorg/atp-protocol';
|
|
9
|
+
|
|
10
|
+
export const MB = 1024 * 1024;
|
|
11
|
+
export const GB = 1024 * 1024 * 1024;
|
|
12
|
+
export const SECOND = 1000;
|
|
13
|
+
export const MINUTE = 60 * 1000;
|
|
14
|
+
export const HOUR = 60 * 60 * 1000;
|
|
15
|
+
export const DAY = 24 * 60 * 60 * 1000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Execution configuration
|
|
19
|
+
*/
|
|
20
|
+
export interface ExecutionConfig {
|
|
21
|
+
/** Timeout in milliseconds */
|
|
22
|
+
timeout: number;
|
|
23
|
+
/** Memory limit in bytes */
|
|
24
|
+
memory: number;
|
|
25
|
+
/** Maximum LLM calls allowed */
|
|
26
|
+
llmCalls: number;
|
|
27
|
+
/** Provenance tracking mode (none|proxy|ast) */
|
|
28
|
+
provenanceMode?: ProvenanceMode;
|
|
29
|
+
/** Security policies for provenance-based protection */
|
|
30
|
+
securityPolicies?: SecurityPolicy[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Client initialization configuration
|
|
35
|
+
*/
|
|
36
|
+
export interface ClientInitConfig {
|
|
37
|
+
/** Token time-to-live in milliseconds */
|
|
38
|
+
tokenTTL: number;
|
|
39
|
+
/** Token rotation interval in milliseconds */
|
|
40
|
+
tokenRotation: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Execution state configuration
|
|
45
|
+
*/
|
|
46
|
+
export interface ExecutionStateConfig {
|
|
47
|
+
/** TTL for paused execution state in seconds */
|
|
48
|
+
ttl: number;
|
|
49
|
+
/** Maximum allowed pause duration in seconds (default: 1 hour) */
|
|
50
|
+
maxPauseDuration: number;
|
|
51
|
+
/** Key prefix for execution state (defaults to 'atp:execution:') */
|
|
52
|
+
keyPrefix?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Discovery configuration
|
|
57
|
+
*/
|
|
58
|
+
export interface DiscoveryConfig {
|
|
59
|
+
/** Enable embeddings for semantic search */
|
|
60
|
+
embeddings: boolean;
|
|
61
|
+
/** Scope filtering configuration for search results */
|
|
62
|
+
scopeFiltering?: ScopeFilteringConfig;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* OpenTelemetry configuration
|
|
67
|
+
*/
|
|
68
|
+
export interface OpenTelemetryConfig {
|
|
69
|
+
/** Enable OpenTelemetry tracing and metrics */
|
|
70
|
+
enabled: boolean;
|
|
71
|
+
/** Service name for traces and metrics (defaults to 'agent-tool-protocol') */
|
|
72
|
+
serviceName?: string;
|
|
73
|
+
/** Service version for resource attributes */
|
|
74
|
+
serviceVersion?: string;
|
|
75
|
+
/** OTLP endpoint for traces (defaults to http://localhost:4318/v1/traces) */
|
|
76
|
+
traceEndpoint?: string;
|
|
77
|
+
/** OTLP endpoint for metrics (defaults to http://localhost:4318/v1/metrics) */
|
|
78
|
+
metricsEndpoint?: string;
|
|
79
|
+
/** Headers for OTLP exporter (e.g., for authentication) */
|
|
80
|
+
headers?: Record<string, string>;
|
|
81
|
+
/** Metrics export interval in milliseconds (defaults to 60000) */
|
|
82
|
+
metricsInterval?: number;
|
|
83
|
+
/** Additional resource attributes */
|
|
84
|
+
resourceAttributes?: Record<string, string>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Logger interface
|
|
89
|
+
*/
|
|
90
|
+
export interface Logger {
|
|
91
|
+
debug(message: string, meta?: unknown): void;
|
|
92
|
+
info(message: string, meta?: unknown): void;
|
|
93
|
+
warn(message: string, meta?: unknown): void;
|
|
94
|
+
error(message: string, meta?: unknown): void;
|
|
95
|
+
child?(meta: Record<string, unknown>): Logger;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Audit configuration
|
|
100
|
+
*/
|
|
101
|
+
export interface AuditConfig {
|
|
102
|
+
/** Enable audit logging */
|
|
103
|
+
enabled: boolean;
|
|
104
|
+
/** Audit sink(s) for logging events */
|
|
105
|
+
sinks?: AuditSink | AuditSink[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Provider configuration
|
|
110
|
+
*/
|
|
111
|
+
export interface ProvidersConfig {
|
|
112
|
+
/** Cache provider for storing execution state and data (defaults to MemoryCache) */
|
|
113
|
+
cache?: CacheProvider;
|
|
114
|
+
/** Token/credential store for managing client tokens (defaults to EnvAuthProvider) */
|
|
115
|
+
auth?: AuthProvider;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Server configuration (user input - all fields optional)
|
|
120
|
+
*/
|
|
121
|
+
export interface ServerConfig {
|
|
122
|
+
execution?: Partial<ExecutionConfig>;
|
|
123
|
+
clientInit?: Partial<ClientInitConfig>;
|
|
124
|
+
executionState?: Partial<ExecutionStateConfig>;
|
|
125
|
+
discovery?: Partial<DiscoveryConfig>;
|
|
126
|
+
/** Audit logging configuration */
|
|
127
|
+
audit?: Partial<AuditConfig>;
|
|
128
|
+
/** OpenTelemetry tracing and metrics configuration */
|
|
129
|
+
otel?: Partial<OpenTelemetryConfig>;
|
|
130
|
+
/** External providers (cache, auth) */
|
|
131
|
+
providers?: ProvidersConfig;
|
|
132
|
+
logger?: 'debug' | 'info' | 'warn' | 'error' | Logger;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Resolved server configuration with defaults applied
|
|
137
|
+
*/
|
|
138
|
+
export interface ResolvedServerConfig {
|
|
139
|
+
execution: ExecutionConfig;
|
|
140
|
+
clientInit: ClientInitConfig;
|
|
141
|
+
executionState: ExecutionStateConfig;
|
|
142
|
+
discovery: DiscoveryConfig;
|
|
143
|
+
audit: AuditConfig;
|
|
144
|
+
otel: OpenTelemetryConfig;
|
|
145
|
+
logger: 'debug' | 'info' | 'warn' | 'error' | Logger;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Request context passed through middleware
|
|
150
|
+
*/
|
|
151
|
+
export interface RequestContext {
|
|
152
|
+
method: string;
|
|
153
|
+
path: string;
|
|
154
|
+
query: Record<string, string>;
|
|
155
|
+
headers: Record<string, string>;
|
|
156
|
+
body: unknown;
|
|
157
|
+
clientId?: string;
|
|
158
|
+
clientToken?: string;
|
|
159
|
+
userId?: string;
|
|
160
|
+
user?: unknown;
|
|
161
|
+
executionId?: string;
|
|
162
|
+
code?: string;
|
|
163
|
+
validation?: unknown;
|
|
164
|
+
result?: unknown;
|
|
165
|
+
error?: Error;
|
|
166
|
+
cache?: CacheProvider;
|
|
167
|
+
auth?: AuthProvider;
|
|
168
|
+
audit?: AuditSink;
|
|
169
|
+
logger: Logger;
|
|
170
|
+
status: number;
|
|
171
|
+
responseBody: unknown;
|
|
172
|
+
throw(status: number, message: string): never;
|
|
173
|
+
assert(condition: boolean, message: string): asserts condition;
|
|
174
|
+
set(header: string, value: string): void;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Middleware function signature
|
|
179
|
+
*/
|
|
180
|
+
export type Middleware = (ctx: RequestContext, next: () => Promise<void>) => Promise<void>;
|
package/src/core/http.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IncomingMessage } from 'node:http';
|
|
2
|
+
import { readJsonBody } from '../utils/request.js';
|
|
3
|
+
|
|
4
|
+
export function parseBody(req: IncomingMessage): Promise<unknown> {
|
|
5
|
+
return readJsonBody(req);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function parseQuery(url: string): Record<string, string> {
|
|
9
|
+
const queryIndex = url.indexOf('?');
|
|
10
|
+
if (queryIndex === -1) return {};
|
|
11
|
+
|
|
12
|
+
const queryString = url.substring(queryIndex + 1);
|
|
13
|
+
const params = new URLSearchParams(queryString);
|
|
14
|
+
const result: Record<string, string> = {};
|
|
15
|
+
|
|
16
|
+
for (const [key, value] of params) {
|
|
17
|
+
result[key] = value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|