@unson/brainbase-mcp 0.50.31 → 0.51.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/contracts/canonical-task/store-schema.sql +3 -0
- package/dist/automation-run.js +3 -2
- package/dist/canonical-task-postgres.js +3 -0
- package/dist/canonical-task-service.d.ts +6 -0
- package/dist/canonical-task-service.js +40 -1
- package/dist/company-os-learning-adoption.d.ts +9 -0
- package/dist/company-os-learning-adoption.js +50 -1
- package/dist/durable-waits.d.ts +30 -0
- package/dist/durable-waits.js +100 -94
- package/dist/foundation-public-provider.d.ts +3 -1
- package/dist/foundation-public-provider.js +2 -2
- package/dist/graph-corrections.d.ts +46 -1
- package/dist/graph-corrections.js +172 -1
- package/dist/judgment-event-outbox.d.ts +24 -2
- package/dist/judgment-event-outbox.js +92 -10
- package/dist/judgment-frame.js +2 -2
- package/dist/judgment-host.d.ts +4 -1
- package/dist/judgment-host.js +126 -14
- package/dist/judgment-task-progress.d.ts +41 -0
- package/dist/judgment-task-progress.js +18 -0
- package/dist/knowledge-continuation.js +7 -1
- package/dist/knowledge-lookup.js +43 -58
- package/dist/mcp-runtime.d.ts +9 -0
- package/dist/mcp-runtime.js +12 -4
- package/dist/meeting-automation-runtime.d.ts +52 -0
- package/dist/meeting-automation-runtime.js +46 -0
- package/dist/queue-task-tools.js +2 -2
- package/dist/routine-liveness.js +0 -1
- package/dist/routine-runtime.js +1 -1
- package/dist/server.d.ts +59 -85
- package/dist/server.js +44 -36
- package/dist/ssot.js +1 -1
- package/dist/testing/queue-task-tools-contract.js +1 -1
- package/dist/world-model-impact-index.d.ts +132 -0
- package/dist/world-model-impact-index.js +901 -0
- package/package.json +6 -18
- package/ui/judgment-history.css +13 -0
- package/ui/objective-editor.css +19 -2
- package/ui/objective-editor.js +6 -3
- package/ui/project-workspace.css +33 -26
- package/ui/workspace-kit.js +9 -7
- package/ui/world/world-view.css +65 -46
- package/ui/world/world-view.js +27 -18
- package/dist/execution-authority-http.d.ts +0 -30
- package/dist/execution-authority-http.js +0 -454
- package/dist/execution-authority.d.ts +0 -282
- package/dist/execution-authority.js +0 -867
- package/dist/resource-reservation-http.d.ts +0 -31
- package/dist/resource-reservation-http.js +0 -371
- package/dist/resource-reservations.d.ts +0 -221
- package/dist/resource-reservations.js +0 -577
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { ExecutionAuthorityError, } from './execution-authority.js';
|
|
3
|
-
const DEFAULT_BODY_LIMIT_BYTES = 1024 * 1024;
|
|
4
|
-
const DEFAULT_BASE_PATH = '/execution-authority';
|
|
5
|
-
const snapshotIdPattern = /^sha256:[0-9a-f]{64}$/u;
|
|
6
|
-
const boundedText = z.string().min(1).max(512).refine((value) => !/[\u0000-\u001f\u007f]/u.test(value), 'must be a bounded text value');
|
|
7
|
-
const problemSchema = z.object({
|
|
8
|
-
problem_snapshot_id: z.string().min(1).max(512).regex(snapshotIdPattern),
|
|
9
|
-
problem_id: boundedText,
|
|
10
|
-
revision: boundedText,
|
|
11
|
-
}).strict();
|
|
12
|
-
const startRequestSchema = z.object({
|
|
13
|
-
operationId: boundedText,
|
|
14
|
-
tenantId: boundedText,
|
|
15
|
-
principal: boundedText,
|
|
16
|
-
scopeId: boundedText,
|
|
17
|
-
runId: boundedText,
|
|
18
|
-
reservationId: boundedText,
|
|
19
|
-
approvalId: boundedText,
|
|
20
|
-
authorityRef: boundedText,
|
|
21
|
-
constraintRefs: z.array(boundedText).max(128),
|
|
22
|
-
problem: problemSchema,
|
|
23
|
-
}).strict();
|
|
24
|
-
const attributionSchema = z.object({
|
|
25
|
-
mode: z.enum(['person', 'delegated_service', 'service']),
|
|
26
|
-
servicePrincipal: boundedText.optional(),
|
|
27
|
-
delegationRef: boundedText.optional(),
|
|
28
|
-
correlationId: boundedText.optional(),
|
|
29
|
-
}).strict();
|
|
30
|
-
const effectReportSchema = z.object({
|
|
31
|
-
tenantId: boundedText,
|
|
32
|
-
principal: boundedText,
|
|
33
|
-
scopeId: boundedText,
|
|
34
|
-
status: z.enum(['started', 'unknown']),
|
|
35
|
-
capabilityDigest: boundedText,
|
|
36
|
-
}).strict();
|
|
37
|
-
class HttpInputError extends Error {
|
|
38
|
-
constructor(message) {
|
|
39
|
-
super(message);
|
|
40
|
-
this.name = 'HttpInputError';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class BodyLimitError extends Error {
|
|
44
|
-
constructor() {
|
|
45
|
-
super('Request body exceeds the configured limit');
|
|
46
|
-
this.name = 'BodyLimitError';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
class BodyReadError extends Error {
|
|
50
|
-
constructor(message) {
|
|
51
|
-
super(message);
|
|
52
|
-
this.name = 'BodyReadError';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function requestPath(request) {
|
|
56
|
-
try {
|
|
57
|
-
return new URL(request.url ?? '/', 'http://localhost').pathname;
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return '/';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function headerValue(request, name) {
|
|
64
|
-
const value = request.headers[name.toLowerCase()];
|
|
65
|
-
return Array.isArray(value) ? value[0] : value;
|
|
66
|
-
}
|
|
67
|
-
function writeJson(response, statusCode, body, headers = {}) {
|
|
68
|
-
if (response.headersSent)
|
|
69
|
-
return;
|
|
70
|
-
response.statusCode = statusCode;
|
|
71
|
-
response.setHeader('Content-Type', 'application/json');
|
|
72
|
-
for (const [name, value] of Object.entries(headers))
|
|
73
|
-
response.setHeader(name, value);
|
|
74
|
-
response.end(JSON.stringify(body));
|
|
75
|
-
}
|
|
76
|
-
async function readJsonBody(request, limitBytes) {
|
|
77
|
-
const contentLengthHeader = headerValue(request, 'content-length');
|
|
78
|
-
if (contentLengthHeader !== undefined) {
|
|
79
|
-
const contentLength = Number(contentLengthHeader);
|
|
80
|
-
if (Number.isFinite(contentLength) && contentLength > limitBytes) {
|
|
81
|
-
request.resume();
|
|
82
|
-
throw new BodyLimitError();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const chunks = [];
|
|
86
|
-
let totalBytes = 0;
|
|
87
|
-
await new Promise((resolve, reject) => {
|
|
88
|
-
let settled = false;
|
|
89
|
-
const cleanup = () => {
|
|
90
|
-
request.removeListener('data', onData);
|
|
91
|
-
request.removeListener('end', onEnd);
|
|
92
|
-
request.removeListener('error', onError);
|
|
93
|
-
request.removeListener('aborted', onAborted);
|
|
94
|
-
};
|
|
95
|
-
const finish = (error) => {
|
|
96
|
-
if (settled)
|
|
97
|
-
return;
|
|
98
|
-
settled = true;
|
|
99
|
-
cleanup();
|
|
100
|
-
if (error)
|
|
101
|
-
reject(error);
|
|
102
|
-
else
|
|
103
|
-
resolve();
|
|
104
|
-
};
|
|
105
|
-
const onData = (chunk) => {
|
|
106
|
-
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
107
|
-
totalBytes += buffer.byteLength;
|
|
108
|
-
if (totalBytes > limitBytes) {
|
|
109
|
-
request.resume();
|
|
110
|
-
finish(new BodyLimitError());
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
chunks.push(buffer);
|
|
114
|
-
};
|
|
115
|
-
const onEnd = () => finish();
|
|
116
|
-
const onError = () => finish(new BodyReadError('Request body could not be read'));
|
|
117
|
-
const onAborted = () => finish(new BodyReadError('Request was aborted'));
|
|
118
|
-
request.on('data', onData);
|
|
119
|
-
request.once('end', onEnd);
|
|
120
|
-
request.once('error', onError);
|
|
121
|
-
request.once('aborted', onAborted);
|
|
122
|
-
});
|
|
123
|
-
if (chunks.length === 0)
|
|
124
|
-
throw new HttpInputError('Request body must be a JSON object');
|
|
125
|
-
try {
|
|
126
|
-
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
throw new HttpInputError('Request body must contain valid JSON');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function normalizeBasePath(basePath) {
|
|
133
|
-
const value = basePath ?? DEFAULT_BASE_PATH;
|
|
134
|
-
if (typeof value !== 'string' || !value.startsWith('/') || value === '/' || /[\u0000-\u001f\u007f]/u.test(value)) {
|
|
135
|
-
throw new TypeError('basePath must be an absolute URL path');
|
|
136
|
-
}
|
|
137
|
-
const normalized = value.replace(/\/+$/u, '');
|
|
138
|
-
if (normalized.length === 0)
|
|
139
|
-
throw new TypeError('basePath must not be root');
|
|
140
|
-
return normalized;
|
|
141
|
-
}
|
|
142
|
-
function normalizePath(path) {
|
|
143
|
-
if (path.length > 1)
|
|
144
|
-
return path.replace(/\/+$/u, '');
|
|
145
|
-
return path;
|
|
146
|
-
}
|
|
147
|
-
function matchRoute(path, basePath) {
|
|
148
|
-
const normalized = normalizePath(path);
|
|
149
|
-
if (normalized === basePath)
|
|
150
|
-
return { operation: 'unknown' };
|
|
151
|
-
const prefix = `${basePath}/`;
|
|
152
|
-
if (!normalized.startsWith(prefix))
|
|
153
|
-
return null;
|
|
154
|
-
const suffix = normalized.slice(prefix.length);
|
|
155
|
-
if (suffix === 'start')
|
|
156
|
-
return { operation: 'start' };
|
|
157
|
-
if (suffix === 'register')
|
|
158
|
-
return { operation: 'register' };
|
|
159
|
-
const intentPrefix = 'intents/';
|
|
160
|
-
if (suffix.startsWith(intentPrefix)) {
|
|
161
|
-
const rest = suffix.slice(intentPrefix.length);
|
|
162
|
-
const reportSuffix = '/effect';
|
|
163
|
-
const operation = rest.endsWith(reportSuffix) ? 'report_effect' : 'read';
|
|
164
|
-
const encodedOperationId = operation === 'report_effect' ? rest.slice(0, -reportSuffix.length) : rest;
|
|
165
|
-
if (encodedOperationId.length === 0 || encodedOperationId.includes('/'))
|
|
166
|
-
return { operation: 'unknown' };
|
|
167
|
-
try {
|
|
168
|
-
return { operation, operationId: decodeURIComponent(encodedOperationId) };
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
return { operation, operationId: undefined };
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return { operation: 'unknown' };
|
|
175
|
-
}
|
|
176
|
-
function isRecord(value) {
|
|
177
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
178
|
-
}
|
|
179
|
-
function hasOwn(value, key) {
|
|
180
|
-
return Object.prototype.hasOwnProperty.call(value, key);
|
|
181
|
-
}
|
|
182
|
-
function assertContext(context) {
|
|
183
|
-
if (!context
|
|
184
|
-
|| !boundedText.safeParse(context.tenantId).success
|
|
185
|
-
|| !boundedText.safeParse(context.principal).success
|
|
186
|
-
|| !boundedText.safeParse(context.scopeId).success) {
|
|
187
|
-
throw new HttpInputError('Authenticated execution authority context is required');
|
|
188
|
-
}
|
|
189
|
-
if (context.attribution !== undefined && !attributionIsConsistent(context.attribution, context.principal)) {
|
|
190
|
-
throw new HttpInputError('Authenticated execution attribution is inconsistent');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/** Mirrors the service rules so an inconsistent host context is an authentication failure. */
|
|
194
|
-
function attributionIsConsistent(value, principal) {
|
|
195
|
-
const parsed = attributionSchema.safeParse(value);
|
|
196
|
-
if (!parsed.success)
|
|
197
|
-
return false;
|
|
198
|
-
const { mode, servicePrincipal, delegationRef } = parsed.data;
|
|
199
|
-
if (mode === 'person')
|
|
200
|
-
return servicePrincipal === undefined && delegationRef === undefined;
|
|
201
|
-
if (servicePrincipal === undefined || delegationRef === undefined)
|
|
202
|
-
return false;
|
|
203
|
-
return mode === 'delegated_service' ? servicePrincipal !== principal : servicePrincipal === principal;
|
|
204
|
-
}
|
|
205
|
-
function bindTrustedIdentity(body, context) {
|
|
206
|
-
if (!isRecord(body))
|
|
207
|
-
throw new HttpInputError('Request body must be a JSON object');
|
|
208
|
-
const input = { ...body };
|
|
209
|
-
if (hasOwn(input, 'authority') || hasOwn(input, 'authorities')) {
|
|
210
|
-
throw new HttpInputError('authority is not accepted in the request body');
|
|
211
|
-
}
|
|
212
|
-
const identityFields = [
|
|
213
|
-
['tenantId', ['tenantId', 'tenant_id', 'tenant'], context.tenantId],
|
|
214
|
-
['principal', ['principal', 'actorId', 'actor_id', 'actor'], context.principal],
|
|
215
|
-
['scopeId', ['scopeId', 'scope_id'], context.scopeId],
|
|
216
|
-
];
|
|
217
|
-
for (const [canonical, aliases, expected] of identityFields) {
|
|
218
|
-
for (const alias of aliases) {
|
|
219
|
-
if (!hasOwn(input, alias))
|
|
220
|
-
continue;
|
|
221
|
-
if (typeof input[alias] !== 'string' || input[alias] !== expected) {
|
|
222
|
-
throw new HttpInputError(`${canonical} does not match the trusted request context`);
|
|
223
|
-
}
|
|
224
|
-
delete input[alias];
|
|
225
|
-
}
|
|
226
|
-
input[canonical] = expected;
|
|
227
|
-
}
|
|
228
|
-
return input;
|
|
229
|
-
}
|
|
230
|
-
function parseStartBody(body, context) {
|
|
231
|
-
const bound = bindTrustedIdentity(body, context);
|
|
232
|
-
const parsed = startRequestSchema.safeParse(bound);
|
|
233
|
-
if (!parsed.success)
|
|
234
|
-
throw new HttpInputError(parsed.error.issues[0]?.message ?? 'Request body is invalid');
|
|
235
|
-
return parsed.data;
|
|
236
|
-
}
|
|
237
|
-
function parseEffectReportBody(body, context, operationId) {
|
|
238
|
-
const bound = bindTrustedIdentity(body, context);
|
|
239
|
-
if (hasOwn(bound, 'operationId')) {
|
|
240
|
-
if (bound.operationId !== operationId)
|
|
241
|
-
throw new HttpInputError('operationId does not match the request path');
|
|
242
|
-
delete bound.operationId;
|
|
243
|
-
}
|
|
244
|
-
const parsed = effectReportSchema.safeParse(bound);
|
|
245
|
-
if (!parsed.success)
|
|
246
|
-
throw new HttpInputError(parsed.error.issues[0]?.message ?? 'Request body is invalid');
|
|
247
|
-
return { ...parsed.data, operationId };
|
|
248
|
-
}
|
|
249
|
-
function serviceError(error) {
|
|
250
|
-
if (!(error instanceof ExecutionAuthorityError)) {
|
|
251
|
-
return { status: 500, code: 'internal_error', message: 'Execution authority operation failed' };
|
|
252
|
-
}
|
|
253
|
-
const status = (() => {
|
|
254
|
-
switch (error.code) {
|
|
255
|
-
case 'scope_mismatch':
|
|
256
|
-
case 'capability_mismatch':
|
|
257
|
-
case 'authority_revoked':
|
|
258
|
-
case 'authority_expired':
|
|
259
|
-
case 'approval_revoked':
|
|
260
|
-
case 'approval_expired':
|
|
261
|
-
case 'constraint_revoked':
|
|
262
|
-
case 'constraint_expired':
|
|
263
|
-
case 'reservation_revoked':
|
|
264
|
-
case 'reservation_expired':
|
|
265
|
-
case 'read_revoked':
|
|
266
|
-
case 'read_expired':
|
|
267
|
-
return 403;
|
|
268
|
-
case 'read_unknown':
|
|
269
|
-
case 'authority_unknown':
|
|
270
|
-
case 'approval_unknown':
|
|
271
|
-
case 'constraint_unknown':
|
|
272
|
-
case 'reservation_unknown':
|
|
273
|
-
case 'store_unavailable':
|
|
274
|
-
return 503;
|
|
275
|
-
case 'intent_not_found':
|
|
276
|
-
return 404;
|
|
277
|
-
case 'effect_unconfigured':
|
|
278
|
-
return 501;
|
|
279
|
-
case 'operation_conflict':
|
|
280
|
-
case 'revision_conflict':
|
|
281
|
-
case 'fencing_unsupported':
|
|
282
|
-
case 'capability_expired':
|
|
283
|
-
case 'recovery_required':
|
|
284
|
-
case 'reservation_mark_unknown':
|
|
285
|
-
case 'effect_unknown':
|
|
286
|
-
return 409;
|
|
287
|
-
case 'validation_error':
|
|
288
|
-
return 400;
|
|
289
|
-
case 'ledger_invalid':
|
|
290
|
-
return 500;
|
|
291
|
-
default:
|
|
292
|
-
return 500;
|
|
293
|
-
}
|
|
294
|
-
})();
|
|
295
|
-
return { status, code: error.code, message: error.message };
|
|
296
|
-
}
|
|
297
|
-
function writeError(response, status, code, message, headers = {}) {
|
|
298
|
-
writeJson(response, status, { error: { code, message } }, headers);
|
|
299
|
-
}
|
|
300
|
-
function methodAllowed(operation, method) {
|
|
301
|
-
if (operation === 'read')
|
|
302
|
-
return method === 'GET';
|
|
303
|
-
return operation === 'unknown' ? false : method === 'POST';
|
|
304
|
-
}
|
|
305
|
-
async function verifyMutationRequest(options, request, context) {
|
|
306
|
-
if (typeof context.verifiedMutationOrigin === 'string' && context.verifiedMutationOrigin.trim().length > 0)
|
|
307
|
-
return true;
|
|
308
|
-
if (!options.verifyMutationRequest)
|
|
309
|
-
return false;
|
|
310
|
-
try {
|
|
311
|
-
return (await options.verifyMutationRequest({ request, context })) === true;
|
|
312
|
-
}
|
|
313
|
-
catch {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
export function createExecutionAuthorityHttpHandler(options) {
|
|
318
|
-
if (!options || typeof options !== 'object' || typeof options.serviceFactory !== 'function') {
|
|
319
|
-
throw new TypeError('serviceFactory is required');
|
|
320
|
-
}
|
|
321
|
-
const basePath = normalizeBasePath(options.basePath);
|
|
322
|
-
const bodyLimitBytes = options.bodyLimitBytes ?? DEFAULT_BODY_LIMIT_BYTES;
|
|
323
|
-
if (!Number.isInteger(bodyLimitBytes) || bodyLimitBytes <= 0) {
|
|
324
|
-
throw new TypeError('bodyLimitBytes must be a positive integer');
|
|
325
|
-
}
|
|
326
|
-
return async (request, response, context) => {
|
|
327
|
-
const route = matchRoute(requestPath(request), basePath);
|
|
328
|
-
if (!route)
|
|
329
|
-
return false;
|
|
330
|
-
if (!context) {
|
|
331
|
-
writeError(response, 401, 'unauthorized', 'Authenticated execution authority context is required');
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
assertContext(context);
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
writeError(response, 401, 'unauthorized', error instanceof Error ? error.message : 'Authenticated execution authority context is required');
|
|
339
|
-
return true;
|
|
340
|
-
}
|
|
341
|
-
if (route.operation === 'unknown') {
|
|
342
|
-
writeError(response, 404, 'not_found', 'Execution authority route was not found');
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
const method = (request.method ?? 'GET').toUpperCase();
|
|
346
|
-
if (!methodAllowed(route.operation, method)) {
|
|
347
|
-
writeError(response, 405, 'method_not_allowed', 'Method is not allowed for this execution authority route', { Allow: route.operation === 'read' ? 'GET' : 'POST' });
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
if (route.operation === 'read') {
|
|
351
|
-
const parsedOperationId = boundedText.safeParse(route.operationId);
|
|
352
|
-
if (!parsedOperationId.success) {
|
|
353
|
-
writeError(response, 400, 'invalid_request', 'operationId is invalid');
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
try {
|
|
357
|
-
const service = await options.serviceFactory(context);
|
|
358
|
-
const result = await service.readIntent({
|
|
359
|
-
operationId: parsedOperationId.data,
|
|
360
|
-
tenantId: context.tenantId,
|
|
361
|
-
principal: context.principal,
|
|
362
|
-
scopeId: context.scopeId,
|
|
363
|
-
});
|
|
364
|
-
if (!result) {
|
|
365
|
-
writeError(response, 404, 'not_found', 'Execution intent was not found');
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
writeJson(response, 200, { action: 'read', operationId: parsedOperationId.data, result });
|
|
369
|
-
}
|
|
370
|
-
catch (error) {
|
|
371
|
-
const failure = serviceError(error);
|
|
372
|
-
writeError(response, failure.status, failure.code, failure.message);
|
|
373
|
-
}
|
|
374
|
-
return true;
|
|
375
|
-
}
|
|
376
|
-
let body;
|
|
377
|
-
try {
|
|
378
|
-
body = await readJsonBody(request, bodyLimitBytes);
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
if (error instanceof BodyLimitError) {
|
|
382
|
-
writeError(response, 413, 'body_too_large', error.message);
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
writeError(response, 400, 'invalid_request', error instanceof Error ? error.message : 'Request body is invalid');
|
|
386
|
-
}
|
|
387
|
-
return true;
|
|
388
|
-
}
|
|
389
|
-
const requestOptions = context.attribution ? { attribution: context.attribution } : {};
|
|
390
|
-
if (route.operation === 'report_effect') {
|
|
391
|
-
const parsedOperationId = boundedText.safeParse(route.operationId);
|
|
392
|
-
let report;
|
|
393
|
-
try {
|
|
394
|
-
if (!parsedOperationId.success)
|
|
395
|
-
throw new HttpInputError('operationId is invalid');
|
|
396
|
-
report = parseEffectReportBody(body, context, parsedOperationId.data);
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
writeError(response, 400, 'invalid_request', error instanceof Error ? error.message : 'Request body is invalid');
|
|
400
|
-
return true;
|
|
401
|
-
}
|
|
402
|
-
if (!await verifyMutationRequest(options, request, context)) {
|
|
403
|
-
writeError(response, 403, 'mutation_origin_unverified', 'Mutation origin could not be verified');
|
|
404
|
-
return true;
|
|
405
|
-
}
|
|
406
|
-
try {
|
|
407
|
-
const service = await options.serviceFactory(context);
|
|
408
|
-
if (typeof service.reportEffect !== 'function') {
|
|
409
|
-
writeError(response, 501, 'operation_unconfigured', 'This host does not accept effect reports');
|
|
410
|
-
return true;
|
|
411
|
-
}
|
|
412
|
-
const intent = await service.reportEffect(report);
|
|
413
|
-
writeJson(response, 200, { action: 'report_effect', operationId: report.operationId, result: { intent } });
|
|
414
|
-
}
|
|
415
|
-
catch (error) {
|
|
416
|
-
const failure = serviceError(error);
|
|
417
|
-
writeError(response, failure.status, failure.code, failure.message);
|
|
418
|
-
}
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
let parsed;
|
|
422
|
-
try {
|
|
423
|
-
parsed = parseStartBody(body, context);
|
|
424
|
-
}
|
|
425
|
-
catch (error) {
|
|
426
|
-
writeError(response, 400, 'invalid_request', error instanceof Error ? error.message : 'Request body is invalid');
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
if (!await verifyMutationRequest(options, request, context)) {
|
|
430
|
-
writeError(response, 403, 'mutation_origin_unverified', 'Mutation origin could not be verified');
|
|
431
|
-
return true;
|
|
432
|
-
}
|
|
433
|
-
try {
|
|
434
|
-
const service = await options.serviceFactory(context);
|
|
435
|
-
if (route.operation === 'register') {
|
|
436
|
-
if (typeof service.register !== 'function') {
|
|
437
|
-
writeError(response, 501, 'operation_unconfigured', 'This host does not register executions');
|
|
438
|
-
return true;
|
|
439
|
-
}
|
|
440
|
-
const result = await service.register(parsed, requestOptions);
|
|
441
|
-
writeJson(response, 200, { action: 'register', operationId: parsed.operationId, result });
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
const result = await service.start(parsed, requestOptions);
|
|
445
|
-
writeJson(response, 200, { action: 'start', operationId: parsed.operationId, result });
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
catch (error) {
|
|
449
|
-
const failure = serviceError(error);
|
|
450
|
-
writeError(response, failure.status, failure.code, failure.message);
|
|
451
|
-
}
|
|
452
|
-
return true;
|
|
453
|
-
};
|
|
454
|
-
}
|