@abyss-project/runtime 3.12.0 → 3.13.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.
Files changed (69) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/README.md +88 -88
  4. package/dist/definition/definition.schema.js +6 -0
  5. package/dist/definition/definition.schema.js.map +1 -1
  6. package/dist/definition/definition.types.d.ts +11 -0
  7. package/dist/definition/definition.types.js +6 -1
  8. package/dist/definition/definition.types.js.map +1 -1
  9. package/dist/discord/discord.types.d.ts +2 -34
  10. package/dist/discord/discord.types.js +1 -9
  11. package/dist/discord/discord.types.js.map +1 -1
  12. package/dist/engine/engine-source.js +1 -1
  13. package/dist/errors/runtime-error-code.enum.d.ts +1 -0
  14. package/dist/errors/runtime-error-code.enum.js +1 -0
  15. package/dist/errors/runtime-error-code.enum.js.map +1 -1
  16. package/dist/runner-protocol/evaluation.types.d.ts +1 -0
  17. package/dist/steps/global-references.js +7 -0
  18. package/dist/steps/global-references.js.map +1 -1
  19. package/dist/steps/step-fields.js +10 -0
  20. package/dist/steps/step-fields.js.map +1 -1
  21. package/jest.config.ts +11 -11
  22. package/package.json +1 -1
  23. package/scripts/build-engine.cjs +70 -70
  24. package/src/__tests__/engine-bundle.test.ts +121 -121
  25. package/src/__tests__/surface.test.ts +81 -88
  26. package/src/access/__tests__/host-match.test.ts +24 -24
  27. package/src/access/access.types.ts +25 -25
  28. package/src/access/host-match.ts +13 -13
  29. package/src/cost/__tests__/execution-cost.test.ts +249 -249
  30. package/src/cost/execution-cost.ts +203 -203
  31. package/src/definition/__tests__/code-step.test.ts +56 -0
  32. package/src/definition/__tests__/validate-definition.test.ts +354 -354
  33. package/src/definition/definition.limits.ts +9 -9
  34. package/src/definition/definition.schema.ts +7 -0
  35. package/src/definition/definition.types.ts +21 -1
  36. package/src/definition/validate-definition.ts +206 -206
  37. package/src/definition/walk-steps.ts +44 -44
  38. package/src/discord/__tests__/discord-event-input.test.ts +90 -108
  39. package/src/discord/discord.types.ts +696 -738
  40. package/src/engine/__tests__/run-in-isolate.test.ts +519 -519
  41. package/src/engine/engine-entry.ts +3 -3
  42. package/src/engine/engine-global.ts +2 -2
  43. package/src/engine/run-in-isolate.ts +462 -462
  44. package/src/errors/runtime-error-code.enum.ts +5 -0
  45. package/src/index.ts +32 -32
  46. package/src/interpreter/__tests__/interpreter.test.ts +854 -854
  47. package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -271
  48. package/src/interpreter/interpreter-error.ts +12 -12
  49. package/src/interpreter/interpreter.ts +483 -483
  50. package/src/interpreter/interpreter.types.ts +204 -204
  51. package/src/interpreter/sequence-path.ts +67 -67
  52. package/src/interpreter/test-host.ts +85 -85
  53. package/src/runner-protocol/__tests__/file-payload.test.ts +26 -26
  54. package/src/runner-protocol/evaluation.types.ts +2 -0
  55. package/src/runner-protocol/execution-protocol.types.ts +297 -297
  56. package/src/schedule/schedule.types.ts +100 -100
  57. package/src/server/__tests__/code-runner-session.test.ts +311 -311
  58. package/src/server/code-runner-error.ts +12 -12
  59. package/src/server/code-runner-session.ts +310 -310
  60. package/src/server/index.ts +11 -11
  61. package/src/steps/__tests__/global-references.test.ts +140 -124
  62. package/src/steps/__tests__/step-fields.test.ts +58 -0
  63. package/src/steps/execute-step.ts +186 -186
  64. package/src/steps/global-references.ts +56 -48
  65. package/src/steps/step-access.ts +56 -56
  66. package/src/steps/step-fields.ts +10 -0
  67. package/src/steps/value-source.ts +69 -69
  68. package/tsconfig.check.json +15 -15
  69. package/tsconfig.json +35 -35
@@ -1,519 +1,519 @@
1
- import { AccessKind } from '../../access/access.types';
2
- import {
3
- CURRENT_FORMAT_VERSION,
4
- HttpMethod,
5
- LogLevel,
6
- StepType,
7
- StopStatus,
8
- } from '../../definition/definition.types';
9
- import type { RuntimeDefinition } from '../../definition/definition.types';
10
- import { RuntimeErrorCode } from '../../errors/runtime-error-code.enum';
11
- import { CURRENT_STATE_VERSION, RunStatus } from '../../interpreter/interpreter.types';
12
- import type { RunState } from '../../interpreter/interpreter.types';
13
- import type { EvaluationItem, EvaluationResult } from '../../runner-protocol/evaluation.types';
14
- import {
15
- CoreCapability,
16
- ExecutionStatus,
17
- MAX_PROGRESS_OUTPUT_BYTES,
18
- MAX_PROGRESS_OUTPUT_CHARS,
19
- StepPhase,
20
- StepStatus,
21
- } from '../../runner-protocol/execution-protocol.types';
22
- import type { ExecutionOutcome, JSONValue } from '../../runner-protocol/execution-protocol.types';
23
- import { EngineResultKind, runInIsolate } from '../run-in-isolate';
24
- import type {
25
- EngineHost,
26
- EngineProgress,
27
- EngineRequest,
28
- EngineResult,
29
- HostCallAnswer,
30
- } from '../run-in-isolate';
31
-
32
- const ALL_CAPABILITIES = [
33
- CoreCapability.HTTP_FETCH,
34
- CoreCapability.WAIT,
35
- CoreCapability.LOG_WRITE,
36
- CoreCapability.HTTP_RESPOND,
37
- 'store.set',
38
- ];
39
-
40
- const definition: RuntimeDefinition = {
41
- formatVersion: CURRENT_FORMAT_VERSION,
42
- accesses: [
43
- { kind: AccessKind.HTTP, hosts: ['api.example.com'] },
44
- { kind: AccessKind.HOST_ACTION, action: 'store.set' },
45
- ],
46
- steps: [
47
- { id: 'name', type: StepType.SET, variable: 'name', value: { $expression: 'input.name' } },
48
- { id: 'fetch', type: StepType.HTTP, method: HttpMethod.GET, url: 'https://api.example.com/x' },
49
- { id: 'save', type: StepType.HOST, action: 'store.set', input: { key: 'k', value: 1 } },
50
- { id: 'note', type: StepType.LOG, level: LogLevel.INFO, message: 'hello' },
51
- { id: 'reply', type: StepType.RESPOND, status: 200, body: 'ok' },
52
- { id: 'pause', type: StepType.WAIT, durationMs: 50 },
53
- { id: 'end', type: StepType.STOP, status: StopStatus.SUCCEEDED, output: { done: true } },
54
- ],
55
- };
56
-
57
- interface Call {
58
- stepId: string;
59
- capability: string;
60
- args: unknown;
61
- }
62
-
63
- interface FakeHost extends EngineHost {
64
- calls: Call[];
65
- progress: EngineProgress[];
66
- evaluations: EvaluationItem[][];
67
- globalsSeen: Array<Record<string, JSONValue> | undefined>;
68
- }
69
-
70
- const fakeHost = (
71
- answer: (call: Call) => HostCallAnswer = () => ({ ok: true, value: null }),
72
- values: Record<string, unknown> = { 'input.name': 'Ada' },
73
- ): FakeHost => {
74
- let clock = 1_000;
75
- const host: FakeHost = {
76
- calls: [],
77
- progress: [],
78
- evaluations: [],
79
- globalsSeen: [],
80
- evaluate: async (items, _context, _stepId, globals) => {
81
- host.evaluations.push(items);
82
- host.globalsSeen.push(globals);
83
- return items.map(
84
- (item): EvaluationResult =>
85
- item.source in values
86
- ? { id: item.id, ok: true, value: values[item.source] }
87
- : {
88
- id: item.id,
89
- ok: false,
90
- error: { code: RuntimeErrorCode.EXPRESSION_ERROR, message: 'unknown' },
91
- },
92
- );
93
- },
94
- callHost: async (stepId, capability, args) => {
95
- const call = { stepId, capability, args };
96
- host.calls.push(call);
97
- return answer(call);
98
- },
99
- onProgress: (progress) => host.progress.push(progress),
100
- now: () => (clock += 5),
101
- };
102
- return host;
103
- };
104
-
105
- const request = (overrides: Partial<EngineRequest> = {}): EngineRequest => ({
106
- definition,
107
- input: { name: 'Ada' },
108
- capabilities: ALL_CAPABILITIES,
109
- budget: { maxSteps: 50, maxEffects: 50 },
110
- ...overrides,
111
- });
112
-
113
- const outcomeOf = (result: EngineResult): ExecutionOutcome => {
114
- if (result.kind !== EngineResultKind.FINISHED) {
115
- throw new Error(`expected a finished execution, got ${result.kind}`);
116
- }
117
- return result.outcome;
118
- };
119
-
120
- const roundTrip = (state: RunState | undefined): RunState => JSON.parse(JSON.stringify(state));
121
-
122
- describe('runInIsolate', () => {
123
- it('runs every step, relaying each effect as a call of its capability', async () => {
124
- const host = fakeHost(({ capability }) =>
125
- capability === CoreCapability.HTTP_FETCH
126
- ? { ok: true, value: { status: 200, headers: {}, body: 'x' } }
127
- : { ok: true, value: null },
128
- );
129
- const outcome = outcomeOf(await runInIsolate(request(), host));
130
- expect(outcome).toEqual({ status: ExecutionStatus.SUCCEEDED, output: { done: true } });
131
- expect(host.calls).toEqual([
132
- {
133
- stepId: 'fetch',
134
- capability: CoreCapability.HTTP_FETCH,
135
- args: { method: HttpMethod.GET, url: 'https://api.example.com/x', headers: {} },
136
- },
137
- { stepId: 'save', capability: 'store.set', args: { key: 'k', value: 1 } },
138
- {
139
- stepId: 'note',
140
- capability: CoreCapability.LOG_WRITE,
141
- args: { level: LogLevel.INFO, message: 'hello' },
142
- },
143
- {
144
- stepId: 'reply',
145
- capability: CoreCapability.HTTP_RESPOND,
146
- args: { status: 200, headers: {}, body: 'ok' },
147
- },
148
- { stepId: 'pause', capability: CoreCapability.WAIT, args: { durationMs: 50 } },
149
- ]);
150
- });
151
-
152
- it('passes the request globals to every evaluation, and nothing when there are none', async () => {
153
- const globals = { secrets: { API_KEY: 'k' } };
154
- const withGlobals = fakeHost();
155
- await runInIsolate(request({ globals }), withGlobals);
156
- expect(withGlobals.globalsSeen).toEqual([globals]);
157
- const without = fakeHost();
158
- await runInIsolate(request(), without);
159
- expect(without.globalsSeen).toEqual([undefined]);
160
- });
161
-
162
- it('reports the start and the end of each step, with its duration and output', async () => {
163
- const host = fakeHost();
164
- await runInIsolate(request(), host);
165
- const ids = definition.steps.map((step) => step.id);
166
- expect(host.progress.map((p) => `${p.stepId}:${p.phase}`)).toEqual(
167
- ids.flatMap((id) => [`${id}:${StepPhase.STARTED}`, `${id}:${StepPhase.FINISHED}`]),
168
- );
169
- const finishedName = host.progress.find(
170
- (p) => p.stepId === 'name' && p.phase === StepPhase.FINISHED,
171
- );
172
- expect(finishedName).toEqual({
173
- stepId: 'name',
174
- phase: StepPhase.FINISHED,
175
- status: StepStatus.SUCCEEDED,
176
- durationMs: expect.any(Number),
177
- output: 'Ada',
178
- });
179
- expect(finishedName?.durationMs).toBeGreaterThan(0);
180
- });
181
-
182
- /** Runs the first step with `value` as its output and returns the progress of its end. */
183
- const finishedProgressOf = async (value: unknown) => {
184
- const host = fakeHost(undefined, { 'input.name': value });
185
- const outcome = outcomeOf(
186
- await runInIsolate(
187
- request({ definition: { ...definition, steps: [definition.steps[0]] } }),
188
- host,
189
- ),
190
- );
191
- expect(outcome.status).toBe(ExecutionStatus.SUCCEEDED);
192
- return host.progress.find((p) => p.phase === StepPhase.FINISHED);
193
- };
194
-
195
- // JSON of a string adds its two quotes: `jsonBytes` bytes of JSON hold `jsonBytes - 2` ASCII characters.
196
- const asciiOfJsonBytes = (jsonBytes: number): string => 'x'.repeat(jsonBytes - 2);
197
-
198
- it('keeps an output of exactly 64 KB of JSON whole', async () => {
199
- const output = asciiOfJsonBytes(MAX_PROGRESS_OUTPUT_BYTES);
200
- expect(Buffer.byteLength(JSON.stringify(output))).toBe(65_536);
201
- const finished = await finishedProgressOf(output);
202
- expect(finished?.output).toBe(output);
203
- expect(finished?.outputTruncated).toBeUndefined();
204
- expect(finished?.outputSizeBytes).toBeUndefined();
205
- });
206
-
207
- it('cuts an output of 64 KB + 1 byte to a 4 KB preview with its real size, never in the run', async () => {
208
- const output = asciiOfJsonBytes(MAX_PROGRESS_OUTPUT_BYTES + 1);
209
- const finished = await finishedProgressOf(output);
210
- expect(finished?.outputTruncated).toBe(true);
211
- expect(finished?.outputSizeBytes).toBe(65_537);
212
- expect(finished?.output).toBe(JSON.stringify(output).slice(0, MAX_PROGRESS_OUTPUT_CHARS));
213
- expect(Buffer.byteLength(finished?.output as string)).toBe(4_096);
214
- });
215
-
216
- it('keeps a 4 KB to 64 KB output whole, where it used to be cut at 4096 characters', async () => {
217
- const output = { rows: 'y'.repeat(30_000) };
218
- const finished = await finishedProgressOf(output);
219
- expect(finished?.output).toEqual(output);
220
- expect(finished?.outputTruncated).toBeUndefined();
221
- });
222
-
223
- it('measures the preview and the real size in bytes, never cutting a multibyte character', async () => {
224
- // Each "€" is 3 bytes: the 4 096-byte boundary falls inside one.
225
- const output = `a${'€'.repeat(30_000)}`;
226
- const json = JSON.stringify(output);
227
- const finished = await finishedProgressOf(output);
228
- expect(finished?.outputSizeBytes).toBe(Buffer.byteLength(json));
229
- const preview = finished?.output as string;
230
- expect(json.startsWith(preview)).toBe(true);
231
- expect(preview).not.toContain('�');
232
- // Quote + "a" + 1 364 whole "€" = 4 094 bytes; a 1 365th would end at 4 097.
233
- expect(Buffer.byteLength(preview)).toBe(4_094);
234
- });
235
-
236
- it('counts a character outside the BMP as 4 bytes and keeps its two units together', async () => {
237
- const output = '😀'.repeat(20_000);
238
- const json = JSON.stringify(output);
239
- const finished = await finishedProgressOf(output);
240
- expect(finished?.outputSizeBytes).toBe(Buffer.byteLength(json));
241
- const preview = finished?.output as string;
242
- expect(json.startsWith(preview)).toBe(true);
243
- // Quote + 1 023 whole emoji = 4 093 bytes; a 1 024th would end at 4 097.
244
- expect(Buffer.byteLength(preview)).toBe(4_093);
245
- });
246
-
247
- it('refuses a capability the host did not expose, without calling it', async () => {
248
- const host = fakeHost();
249
- const outcome = outcomeOf(
250
- await runInIsolate(
251
- request({ capabilities: ALL_CAPABILITIES.filter((c) => c !== CoreCapability.LOG_WRITE) }),
252
- host,
253
- ),
254
- );
255
- expect(outcome).toEqual({
256
- status: ExecutionStatus.FAILED,
257
- errorCode: RuntimeErrorCode.ACCESS_DENIED,
258
- errorMessage: expect.stringContaining('log.write'),
259
- stepId: 'note',
260
- });
261
- expect(host.calls.map((c) => c.capability)).not.toContain(CoreCapability.LOG_WRITE);
262
- expect(host.progress).toContainEqual({
263
- stepId: 'note',
264
- phase: StepPhase.FINISHED,
265
- status: StepStatus.FAILED,
266
- durationMs: expect.any(Number),
267
- errorCode: RuntimeErrorCode.ACCESS_DENIED,
268
- });
269
- });
270
-
271
- it('refuses a host action that is declared but not exposed, and one not declared', async () => {
272
- const notExposed = outcomeOf(
273
- await runInIsolate(
274
- request({ capabilities: ALL_CAPABILITIES.filter((c) => c !== 'store.set') }),
275
- fakeHost(),
276
- ),
277
- );
278
- expect(notExposed).toEqual(
279
- expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'save' }),
280
- );
281
- const undeclared = outcomeOf(
282
- await runInIsolate(
283
- request({
284
- definition: {
285
- ...definition,
286
- accesses: definition.accesses.filter((a) => a.kind === AccessKind.HTTP),
287
- },
288
- }),
289
- fakeHost(),
290
- ),
291
- );
292
- expect(undeclared).toEqual(
293
- expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'save' }),
294
- );
295
- });
296
-
297
- it('refuses an HTTP step when http.fetch is not exposed', async () => {
298
- const host = fakeHost();
299
- const outcome = outcomeOf(
300
- await runInIsolate(
301
- request({ capabilities: ALL_CAPABILITIES.filter((c) => c !== CoreCapability.HTTP_FETCH) }),
302
- host,
303
- ),
304
- );
305
- expect(outcome).toEqual(
306
- expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'fetch' }),
307
- );
308
- expect(host.calls).toEqual([]);
309
- });
310
-
311
- it('fails the step with the code the host gives, or the capability default', async () => {
312
- const coded = outcomeOf(
313
- await runInIsolate(
314
- request(),
315
- fakeHost(({ capability }) =>
316
- capability === 'store.set'
317
- ? { ok: false, error: { code: RuntimeErrorCode.ACCESS_DENIED, message: 'no' } }
318
- : { ok: true, value: null },
319
- ),
320
- ),
321
- );
322
- expect(coded).toEqual(
323
- expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'save' }),
324
- );
325
- const uncoded = outcomeOf(
326
- await runInIsolate(
327
- request(),
328
- fakeHost(() => ({ ok: false, error: { message: 'network down' } })),
329
- ),
330
- );
331
- expect(uncoded).toEqual({
332
- status: ExecutionStatus.FAILED,
333
- errorCode: RuntimeErrorCode.HTTP_ERROR,
334
- errorMessage: 'network down',
335
- stepId: 'fetch',
336
- });
337
- });
338
-
339
- it('reports a STOP that chose FAILED with its output and no error code', async () => {
340
- const outcome = outcomeOf(
341
- await runInIsolate(
342
- request({
343
- definition: {
344
- ...definition,
345
- steps: [{ id: 'stop', type: StepType.STOP, status: StopStatus.FAILED, output: 'no' }],
346
- },
347
- }),
348
- fakeHost(),
349
- ),
350
- );
351
- expect(outcome).toEqual({ status: ExecutionStatus.FAILED, output: 'no' });
352
- });
353
-
354
- it('fails with INVALID_REQUEST when the evaluation does not cover the step', async () => {
355
- const host = fakeHost();
356
- host.evaluate = async () => [];
357
- const outcome = outcomeOf(await runInIsolate(request(), host));
358
- expect(outcome).toEqual(
359
- expect.objectContaining({
360
- status: ExecutionStatus.FAILED,
361
- errorCode: RuntimeErrorCode.INVALID_REQUEST,
362
- }),
363
- );
364
- });
365
-
366
- describe('suspension', () => {
367
- const longWait: RuntimeDefinition = {
368
- ...definition,
369
- steps: [
370
- { id: 'pause', type: StepType.WAIT, durationMs: 60_000 },
371
- { id: 'after', type: StepType.SET, variable: 'v', value: { $expression: 'input.name' } },
372
- { id: 'end', type: StepType.STOP, status: StopStatus.SUCCEEDED, output: 'finished' },
373
- ],
374
- };
375
-
376
- it('suspends on a WAIT above the threshold without calling wait, then resumes', async () => {
377
- const host = fakeHost();
378
- const first = outcomeOf(
379
- await runInIsolate(request({ definition: longWait, suspendWaitAboveMs: 1_000 }), host),
380
- );
381
- expect(first.status).toBe(ExecutionStatus.SUSPENDED);
382
- expect(first.state?.stateVersion).toBe(CURRENT_STATE_VERSION);
383
- expect(host.calls).toEqual([]);
384
- expect(host.progress[host.progress.length - 1]).toEqual({
385
- stepId: 'pause',
386
- phase: StepPhase.FINISHED,
387
- status: StepStatus.SUSPENDED,
388
- durationMs: expect.any(Number),
389
- });
390
-
391
- const resumedHost = fakeHost();
392
- const resumed = outcomeOf(
393
- await runInIsolate(
394
- request({
395
- definition: longWait,
396
- state: roundTrip(first.state),
397
- suspendWaitAboveMs: 1_000,
398
- }),
399
- resumedHost,
400
- ),
401
- );
402
- expect(resumed).toEqual({ status: ExecutionStatus.SUCCEEDED, output: 'finished' });
403
- expect(resumedHost.progress.slice(0, 2)).toEqual([
404
- { stepId: 'pause', phase: StepPhase.STARTED },
405
- expect.objectContaining({ stepId: 'pause', status: StepStatus.SUCCEEDED, output: null }),
406
- ]);
407
-
408
- // Same outcome as a run in one go, where the host serves the wait.
409
- const inOneGo = outcomeOf(await runInIsolate(request({ definition: longWait }), fakeHost()));
410
- expect(inOneGo).toEqual(resumed);
411
- });
412
-
413
- it('suspends on a WAIT until a date further than the threshold', async () => {
414
- const host = fakeHost();
415
- const farUntil = new Date(Date.now() + 3_600_000).toISOString();
416
- const outcome = outcomeOf(
417
- await runInIsolate(
418
- request({
419
- definition: {
420
- ...definition,
421
- steps: [{ id: 'later', type: StepType.WAIT, until: farUntil }],
422
- },
423
- suspendWaitAboveMs: 1_000,
424
- }),
425
- { ...host, now: () => Date.now() },
426
- ),
427
- );
428
- expect(outcome.status).toBe(ExecutionStatus.SUSPENDED);
429
- });
430
-
431
- it('suspends when the host answers suspend, and gives resumeInput to that step', async () => {
432
- const approval: RuntimeDefinition = {
433
- ...definition,
434
- steps: [
435
- { id: 'save', type: StepType.HOST, action: 'store.set', input: { key: 'k' } },
436
- {
437
- id: 'end',
438
- type: StepType.STOP,
439
- status: StopStatus.SUCCEEDED,
440
- output: { $expression: 'steps.save.output' },
441
- },
442
- ],
443
- };
444
- const first = outcomeOf(
445
- await runInIsolate(
446
- request({ definition: approval }),
447
- fakeHost(() => ({ ok: true, suspend: true })),
448
- ),
449
- );
450
- expect(first.status).toBe(ExecutionStatus.SUSPENDED);
451
-
452
- const resumedHost = fakeHost();
453
- resumedHost.evaluate = async (items, context) =>
454
- items.map((item) => ({ id: item.id, ok: true, value: context.steps.save.output }));
455
- const resumed = outcomeOf(
456
- await runInIsolate(
457
- request({
458
- definition: approval,
459
- state: roundTrip(first.state),
460
- resumeInput: { approved: true },
461
- }),
462
- resumedHost,
463
- ),
464
- );
465
- expect(resumed).toEqual({ status: ExecutionStatus.SUCCEEDED, output: { approved: true } });
466
- expect(resumedHost.calls).toEqual([]);
467
- });
468
-
469
- it('refuses a state of an unknown version before running anything', async () => {
470
- const host = fakeHost();
471
- const first = outcomeOf(
472
- await runInIsolate(
473
- request({ definition: longWait, suspendWaitAboveMs: 1_000 }),
474
- fakeHost(),
475
- ),
476
- );
477
- const result = await runInIsolate(
478
- request({
479
- definition: longWait,
480
- state: { ...roundTrip(first.state), stateVersion: CURRENT_STATE_VERSION + 1 },
481
- }),
482
- host,
483
- );
484
- expect(result).toEqual({
485
- kind: EngineResultKind.REJECTED,
486
- code: RuntimeErrorCode.STATE_VERSION_UNSUPPORTED,
487
- message: expect.any(String),
488
- });
489
- expect(host.progress).toEqual([]);
490
- expect(host.calls).toEqual([]);
491
- });
492
-
493
- it('refuses to resume a state that is not suspended', async () => {
494
- const done = outcomeOf(await runInIsolate(request({ definition: longWait }), fakeHost()));
495
- expect(done.status).toBe(ExecutionStatus.SUCCEEDED);
496
- const ended: RunState = {
497
- stateVersion: CURRENT_STATE_VERSION,
498
- formatVersion: CURRENT_FORMAT_VERSION,
499
- status: RunStatus.SUCCEEDED,
500
- input: null,
501
- stack: [],
502
- outputs: {},
503
- vars: {},
504
- pending: null,
505
- counters: { steps: 1, effects: 0 },
506
- };
507
- const result = await runInIsolate(
508
- request({ definition: longWait, state: ended }),
509
- fakeHost(),
510
- );
511
- expect(result).toEqual(
512
- expect.objectContaining({
513
- kind: EngineResultKind.REJECTED,
514
- code: RuntimeErrorCode.INVALID_REQUEST,
515
- }),
516
- );
517
- });
518
- });
519
- });
1
+ import { AccessKind } from '../../access/access.types';
2
+ import {
3
+ CURRENT_FORMAT_VERSION,
4
+ HttpMethod,
5
+ LogLevel,
6
+ StepType,
7
+ StopStatus,
8
+ } from '../../definition/definition.types';
9
+ import type { RuntimeDefinition } from '../../definition/definition.types';
10
+ import { RuntimeErrorCode } from '../../errors/runtime-error-code.enum';
11
+ import { CURRENT_STATE_VERSION, RunStatus } from '../../interpreter/interpreter.types';
12
+ import type { RunState } from '../../interpreter/interpreter.types';
13
+ import type { EvaluationItem, EvaluationResult } from '../../runner-protocol/evaluation.types';
14
+ import {
15
+ CoreCapability,
16
+ ExecutionStatus,
17
+ MAX_PROGRESS_OUTPUT_BYTES,
18
+ MAX_PROGRESS_OUTPUT_CHARS,
19
+ StepPhase,
20
+ StepStatus,
21
+ } from '../../runner-protocol/execution-protocol.types';
22
+ import type { ExecutionOutcome, JSONValue } from '../../runner-protocol/execution-protocol.types';
23
+ import { EngineResultKind, runInIsolate } from '../run-in-isolate';
24
+ import type {
25
+ EngineHost,
26
+ EngineProgress,
27
+ EngineRequest,
28
+ EngineResult,
29
+ HostCallAnswer,
30
+ } from '../run-in-isolate';
31
+
32
+ const ALL_CAPABILITIES = [
33
+ CoreCapability.HTTP_FETCH,
34
+ CoreCapability.WAIT,
35
+ CoreCapability.LOG_WRITE,
36
+ CoreCapability.HTTP_RESPOND,
37
+ 'store.set',
38
+ ];
39
+
40
+ const definition: RuntimeDefinition = {
41
+ formatVersion: CURRENT_FORMAT_VERSION,
42
+ accesses: [
43
+ { kind: AccessKind.HTTP, hosts: ['api.example.com'] },
44
+ { kind: AccessKind.HOST_ACTION, action: 'store.set' },
45
+ ],
46
+ steps: [
47
+ { id: 'name', type: StepType.SET, variable: 'name', value: { $expression: 'input.name' } },
48
+ { id: 'fetch', type: StepType.HTTP, method: HttpMethod.GET, url: 'https://api.example.com/x' },
49
+ { id: 'save', type: StepType.HOST, action: 'store.set', input: { key: 'k', value: 1 } },
50
+ { id: 'note', type: StepType.LOG, level: LogLevel.INFO, message: 'hello' },
51
+ { id: 'reply', type: StepType.RESPOND, status: 200, body: 'ok' },
52
+ { id: 'pause', type: StepType.WAIT, durationMs: 50 },
53
+ { id: 'end', type: StepType.STOP, status: StopStatus.SUCCEEDED, output: { done: true } },
54
+ ],
55
+ };
56
+
57
+ interface Call {
58
+ stepId: string;
59
+ capability: string;
60
+ args: unknown;
61
+ }
62
+
63
+ interface FakeHost extends EngineHost {
64
+ calls: Call[];
65
+ progress: EngineProgress[];
66
+ evaluations: EvaluationItem[][];
67
+ globalsSeen: Array<Record<string, JSONValue> | undefined>;
68
+ }
69
+
70
+ const fakeHost = (
71
+ answer: (call: Call) => HostCallAnswer = () => ({ ok: true, value: null }),
72
+ values: Record<string, unknown> = { 'input.name': 'Ada' },
73
+ ): FakeHost => {
74
+ let clock = 1_000;
75
+ const host: FakeHost = {
76
+ calls: [],
77
+ progress: [],
78
+ evaluations: [],
79
+ globalsSeen: [],
80
+ evaluate: async (items, _context, _stepId, globals) => {
81
+ host.evaluations.push(items);
82
+ host.globalsSeen.push(globals);
83
+ return items.map(
84
+ (item): EvaluationResult =>
85
+ item.source in values
86
+ ? { id: item.id, ok: true, value: values[item.source] }
87
+ : {
88
+ id: item.id,
89
+ ok: false,
90
+ error: { code: RuntimeErrorCode.EXPRESSION_ERROR, message: 'unknown' },
91
+ },
92
+ );
93
+ },
94
+ callHost: async (stepId, capability, args) => {
95
+ const call = { stepId, capability, args };
96
+ host.calls.push(call);
97
+ return answer(call);
98
+ },
99
+ onProgress: (progress) => host.progress.push(progress),
100
+ now: () => (clock += 5),
101
+ };
102
+ return host;
103
+ };
104
+
105
+ const request = (overrides: Partial<EngineRequest> = {}): EngineRequest => ({
106
+ definition,
107
+ input: { name: 'Ada' },
108
+ capabilities: ALL_CAPABILITIES,
109
+ budget: { maxSteps: 50, maxEffects: 50 },
110
+ ...overrides,
111
+ });
112
+
113
+ const outcomeOf = (result: EngineResult): ExecutionOutcome => {
114
+ if (result.kind !== EngineResultKind.FINISHED) {
115
+ throw new Error(`expected a finished execution, got ${result.kind}`);
116
+ }
117
+ return result.outcome;
118
+ };
119
+
120
+ const roundTrip = (state: RunState | undefined): RunState => JSON.parse(JSON.stringify(state));
121
+
122
+ describe('runInIsolate', () => {
123
+ it('runs every step, relaying each effect as a call of its capability', async () => {
124
+ const host = fakeHost(({ capability }) =>
125
+ capability === CoreCapability.HTTP_FETCH
126
+ ? { ok: true, value: { status: 200, headers: {}, body: 'x' } }
127
+ : { ok: true, value: null },
128
+ );
129
+ const outcome = outcomeOf(await runInIsolate(request(), host));
130
+ expect(outcome).toEqual({ status: ExecutionStatus.SUCCEEDED, output: { done: true } });
131
+ expect(host.calls).toEqual([
132
+ {
133
+ stepId: 'fetch',
134
+ capability: CoreCapability.HTTP_FETCH,
135
+ args: { method: HttpMethod.GET, url: 'https://api.example.com/x', headers: {} },
136
+ },
137
+ { stepId: 'save', capability: 'store.set', args: { key: 'k', value: 1 } },
138
+ {
139
+ stepId: 'note',
140
+ capability: CoreCapability.LOG_WRITE,
141
+ args: { level: LogLevel.INFO, message: 'hello' },
142
+ },
143
+ {
144
+ stepId: 'reply',
145
+ capability: CoreCapability.HTTP_RESPOND,
146
+ args: { status: 200, headers: {}, body: 'ok' },
147
+ },
148
+ { stepId: 'pause', capability: CoreCapability.WAIT, args: { durationMs: 50 } },
149
+ ]);
150
+ });
151
+
152
+ it('passes the request globals to every evaluation, and nothing when there are none', async () => {
153
+ const globals = { secrets: { API_KEY: 'k' } };
154
+ const withGlobals = fakeHost();
155
+ await runInIsolate(request({ globals }), withGlobals);
156
+ expect(withGlobals.globalsSeen).toEqual([globals]);
157
+ const without = fakeHost();
158
+ await runInIsolate(request(), without);
159
+ expect(without.globalsSeen).toEqual([undefined]);
160
+ });
161
+
162
+ it('reports the start and the end of each step, with its duration and output', async () => {
163
+ const host = fakeHost();
164
+ await runInIsolate(request(), host);
165
+ const ids = definition.steps.map((step) => step.id);
166
+ expect(host.progress.map((p) => `${p.stepId}:${p.phase}`)).toEqual(
167
+ ids.flatMap((id) => [`${id}:${StepPhase.STARTED}`, `${id}:${StepPhase.FINISHED}`]),
168
+ );
169
+ const finishedName = host.progress.find(
170
+ (p) => p.stepId === 'name' && p.phase === StepPhase.FINISHED,
171
+ );
172
+ expect(finishedName).toEqual({
173
+ stepId: 'name',
174
+ phase: StepPhase.FINISHED,
175
+ status: StepStatus.SUCCEEDED,
176
+ durationMs: expect.any(Number),
177
+ output: 'Ada',
178
+ });
179
+ expect(finishedName?.durationMs).toBeGreaterThan(0);
180
+ });
181
+
182
+ /** Runs the first step with `value` as its output and returns the progress of its end. */
183
+ const finishedProgressOf = async (value: unknown) => {
184
+ const host = fakeHost(undefined, { 'input.name': value });
185
+ const outcome = outcomeOf(
186
+ await runInIsolate(
187
+ request({ definition: { ...definition, steps: [definition.steps[0]] } }),
188
+ host,
189
+ ),
190
+ );
191
+ expect(outcome.status).toBe(ExecutionStatus.SUCCEEDED);
192
+ return host.progress.find((p) => p.phase === StepPhase.FINISHED);
193
+ };
194
+
195
+ // JSON of a string adds its two quotes: `jsonBytes` bytes of JSON hold `jsonBytes - 2` ASCII characters.
196
+ const asciiOfJsonBytes = (jsonBytes: number): string => 'x'.repeat(jsonBytes - 2);
197
+
198
+ it('keeps an output of exactly 64 KB of JSON whole', async () => {
199
+ const output = asciiOfJsonBytes(MAX_PROGRESS_OUTPUT_BYTES);
200
+ expect(Buffer.byteLength(JSON.stringify(output))).toBe(65_536);
201
+ const finished = await finishedProgressOf(output);
202
+ expect(finished?.output).toBe(output);
203
+ expect(finished?.outputTruncated).toBeUndefined();
204
+ expect(finished?.outputSizeBytes).toBeUndefined();
205
+ });
206
+
207
+ it('cuts an output of 64 KB + 1 byte to a 4 KB preview with its real size, never in the run', async () => {
208
+ const output = asciiOfJsonBytes(MAX_PROGRESS_OUTPUT_BYTES + 1);
209
+ const finished = await finishedProgressOf(output);
210
+ expect(finished?.outputTruncated).toBe(true);
211
+ expect(finished?.outputSizeBytes).toBe(65_537);
212
+ expect(finished?.output).toBe(JSON.stringify(output).slice(0, MAX_PROGRESS_OUTPUT_CHARS));
213
+ expect(Buffer.byteLength(finished?.output as string)).toBe(4_096);
214
+ });
215
+
216
+ it('keeps a 4 KB to 64 KB output whole, where it used to be cut at 4096 characters', async () => {
217
+ const output = { rows: 'y'.repeat(30_000) };
218
+ const finished = await finishedProgressOf(output);
219
+ expect(finished?.output).toEqual(output);
220
+ expect(finished?.outputTruncated).toBeUndefined();
221
+ });
222
+
223
+ it('measures the preview and the real size in bytes, never cutting a multibyte character', async () => {
224
+ // Each "€" is 3 bytes: the 4 096-byte boundary falls inside one.
225
+ const output = `a${'€'.repeat(30_000)}`;
226
+ const json = JSON.stringify(output);
227
+ const finished = await finishedProgressOf(output);
228
+ expect(finished?.outputSizeBytes).toBe(Buffer.byteLength(json));
229
+ const preview = finished?.output as string;
230
+ expect(json.startsWith(preview)).toBe(true);
231
+ expect(preview).not.toContain('�');
232
+ // Quote + "a" + 1 364 whole "€" = 4 094 bytes; a 1 365th would end at 4 097.
233
+ expect(Buffer.byteLength(preview)).toBe(4_094);
234
+ });
235
+
236
+ it('counts a character outside the BMP as 4 bytes and keeps its two units together', async () => {
237
+ const output = '😀'.repeat(20_000);
238
+ const json = JSON.stringify(output);
239
+ const finished = await finishedProgressOf(output);
240
+ expect(finished?.outputSizeBytes).toBe(Buffer.byteLength(json));
241
+ const preview = finished?.output as string;
242
+ expect(json.startsWith(preview)).toBe(true);
243
+ // Quote + 1 023 whole emoji = 4 093 bytes; a 1 024th would end at 4 097.
244
+ expect(Buffer.byteLength(preview)).toBe(4_093);
245
+ });
246
+
247
+ it('refuses a capability the host did not expose, without calling it', async () => {
248
+ const host = fakeHost();
249
+ const outcome = outcomeOf(
250
+ await runInIsolate(
251
+ request({ capabilities: ALL_CAPABILITIES.filter((c) => c !== CoreCapability.LOG_WRITE) }),
252
+ host,
253
+ ),
254
+ );
255
+ expect(outcome).toEqual({
256
+ status: ExecutionStatus.FAILED,
257
+ errorCode: RuntimeErrorCode.ACCESS_DENIED,
258
+ errorMessage: expect.stringContaining('log.write'),
259
+ stepId: 'note',
260
+ });
261
+ expect(host.calls.map((c) => c.capability)).not.toContain(CoreCapability.LOG_WRITE);
262
+ expect(host.progress).toContainEqual({
263
+ stepId: 'note',
264
+ phase: StepPhase.FINISHED,
265
+ status: StepStatus.FAILED,
266
+ durationMs: expect.any(Number),
267
+ errorCode: RuntimeErrorCode.ACCESS_DENIED,
268
+ });
269
+ });
270
+
271
+ it('refuses a host action that is declared but not exposed, and one not declared', async () => {
272
+ const notExposed = outcomeOf(
273
+ await runInIsolate(
274
+ request({ capabilities: ALL_CAPABILITIES.filter((c) => c !== 'store.set') }),
275
+ fakeHost(),
276
+ ),
277
+ );
278
+ expect(notExposed).toEqual(
279
+ expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'save' }),
280
+ );
281
+ const undeclared = outcomeOf(
282
+ await runInIsolate(
283
+ request({
284
+ definition: {
285
+ ...definition,
286
+ accesses: definition.accesses.filter((a) => a.kind === AccessKind.HTTP),
287
+ },
288
+ }),
289
+ fakeHost(),
290
+ ),
291
+ );
292
+ expect(undeclared).toEqual(
293
+ expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'save' }),
294
+ );
295
+ });
296
+
297
+ it('refuses an HTTP step when http.fetch is not exposed', async () => {
298
+ const host = fakeHost();
299
+ const outcome = outcomeOf(
300
+ await runInIsolate(
301
+ request({ capabilities: ALL_CAPABILITIES.filter((c) => c !== CoreCapability.HTTP_FETCH) }),
302
+ host,
303
+ ),
304
+ );
305
+ expect(outcome).toEqual(
306
+ expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'fetch' }),
307
+ );
308
+ expect(host.calls).toEqual([]);
309
+ });
310
+
311
+ it('fails the step with the code the host gives, or the capability default', async () => {
312
+ const coded = outcomeOf(
313
+ await runInIsolate(
314
+ request(),
315
+ fakeHost(({ capability }) =>
316
+ capability === 'store.set'
317
+ ? { ok: false, error: { code: RuntimeErrorCode.ACCESS_DENIED, message: 'no' } }
318
+ : { ok: true, value: null },
319
+ ),
320
+ ),
321
+ );
322
+ expect(coded).toEqual(
323
+ expect.objectContaining({ errorCode: RuntimeErrorCode.ACCESS_DENIED, stepId: 'save' }),
324
+ );
325
+ const uncoded = outcomeOf(
326
+ await runInIsolate(
327
+ request(),
328
+ fakeHost(() => ({ ok: false, error: { message: 'network down' } })),
329
+ ),
330
+ );
331
+ expect(uncoded).toEqual({
332
+ status: ExecutionStatus.FAILED,
333
+ errorCode: RuntimeErrorCode.HTTP_ERROR,
334
+ errorMessage: 'network down',
335
+ stepId: 'fetch',
336
+ });
337
+ });
338
+
339
+ it('reports a STOP that chose FAILED with its output and no error code', async () => {
340
+ const outcome = outcomeOf(
341
+ await runInIsolate(
342
+ request({
343
+ definition: {
344
+ ...definition,
345
+ steps: [{ id: 'stop', type: StepType.STOP, status: StopStatus.FAILED, output: 'no' }],
346
+ },
347
+ }),
348
+ fakeHost(),
349
+ ),
350
+ );
351
+ expect(outcome).toEqual({ status: ExecutionStatus.FAILED, output: 'no' });
352
+ });
353
+
354
+ it('fails with INVALID_REQUEST when the evaluation does not cover the step', async () => {
355
+ const host = fakeHost();
356
+ host.evaluate = async () => [];
357
+ const outcome = outcomeOf(await runInIsolate(request(), host));
358
+ expect(outcome).toEqual(
359
+ expect.objectContaining({
360
+ status: ExecutionStatus.FAILED,
361
+ errorCode: RuntimeErrorCode.INVALID_REQUEST,
362
+ }),
363
+ );
364
+ });
365
+
366
+ describe('suspension', () => {
367
+ const longWait: RuntimeDefinition = {
368
+ ...definition,
369
+ steps: [
370
+ { id: 'pause', type: StepType.WAIT, durationMs: 60_000 },
371
+ { id: 'after', type: StepType.SET, variable: 'v', value: { $expression: 'input.name' } },
372
+ { id: 'end', type: StepType.STOP, status: StopStatus.SUCCEEDED, output: 'finished' },
373
+ ],
374
+ };
375
+
376
+ it('suspends on a WAIT above the threshold without calling wait, then resumes', async () => {
377
+ const host = fakeHost();
378
+ const first = outcomeOf(
379
+ await runInIsolate(request({ definition: longWait, suspendWaitAboveMs: 1_000 }), host),
380
+ );
381
+ expect(first.status).toBe(ExecutionStatus.SUSPENDED);
382
+ expect(first.state?.stateVersion).toBe(CURRENT_STATE_VERSION);
383
+ expect(host.calls).toEqual([]);
384
+ expect(host.progress[host.progress.length - 1]).toEqual({
385
+ stepId: 'pause',
386
+ phase: StepPhase.FINISHED,
387
+ status: StepStatus.SUSPENDED,
388
+ durationMs: expect.any(Number),
389
+ });
390
+
391
+ const resumedHost = fakeHost();
392
+ const resumed = outcomeOf(
393
+ await runInIsolate(
394
+ request({
395
+ definition: longWait,
396
+ state: roundTrip(first.state),
397
+ suspendWaitAboveMs: 1_000,
398
+ }),
399
+ resumedHost,
400
+ ),
401
+ );
402
+ expect(resumed).toEqual({ status: ExecutionStatus.SUCCEEDED, output: 'finished' });
403
+ expect(resumedHost.progress.slice(0, 2)).toEqual([
404
+ { stepId: 'pause', phase: StepPhase.STARTED },
405
+ expect.objectContaining({ stepId: 'pause', status: StepStatus.SUCCEEDED, output: null }),
406
+ ]);
407
+
408
+ // Same outcome as a run in one go, where the host serves the wait.
409
+ const inOneGo = outcomeOf(await runInIsolate(request({ definition: longWait }), fakeHost()));
410
+ expect(inOneGo).toEqual(resumed);
411
+ });
412
+
413
+ it('suspends on a WAIT until a date further than the threshold', async () => {
414
+ const host = fakeHost();
415
+ const farUntil = new Date(Date.now() + 3_600_000).toISOString();
416
+ const outcome = outcomeOf(
417
+ await runInIsolate(
418
+ request({
419
+ definition: {
420
+ ...definition,
421
+ steps: [{ id: 'later', type: StepType.WAIT, until: farUntil }],
422
+ },
423
+ suspendWaitAboveMs: 1_000,
424
+ }),
425
+ { ...host, now: () => Date.now() },
426
+ ),
427
+ );
428
+ expect(outcome.status).toBe(ExecutionStatus.SUSPENDED);
429
+ });
430
+
431
+ it('suspends when the host answers suspend, and gives resumeInput to that step', async () => {
432
+ const approval: RuntimeDefinition = {
433
+ ...definition,
434
+ steps: [
435
+ { id: 'save', type: StepType.HOST, action: 'store.set', input: { key: 'k' } },
436
+ {
437
+ id: 'end',
438
+ type: StepType.STOP,
439
+ status: StopStatus.SUCCEEDED,
440
+ output: { $expression: 'steps.save.output' },
441
+ },
442
+ ],
443
+ };
444
+ const first = outcomeOf(
445
+ await runInIsolate(
446
+ request({ definition: approval }),
447
+ fakeHost(() => ({ ok: true, suspend: true })),
448
+ ),
449
+ );
450
+ expect(first.status).toBe(ExecutionStatus.SUSPENDED);
451
+
452
+ const resumedHost = fakeHost();
453
+ resumedHost.evaluate = async (items, context) =>
454
+ items.map((item) => ({ id: item.id, ok: true, value: context.steps.save.output }));
455
+ const resumed = outcomeOf(
456
+ await runInIsolate(
457
+ request({
458
+ definition: approval,
459
+ state: roundTrip(first.state),
460
+ resumeInput: { approved: true },
461
+ }),
462
+ resumedHost,
463
+ ),
464
+ );
465
+ expect(resumed).toEqual({ status: ExecutionStatus.SUCCEEDED, output: { approved: true } });
466
+ expect(resumedHost.calls).toEqual([]);
467
+ });
468
+
469
+ it('refuses a state of an unknown version before running anything', async () => {
470
+ const host = fakeHost();
471
+ const first = outcomeOf(
472
+ await runInIsolate(
473
+ request({ definition: longWait, suspendWaitAboveMs: 1_000 }),
474
+ fakeHost(),
475
+ ),
476
+ );
477
+ const result = await runInIsolate(
478
+ request({
479
+ definition: longWait,
480
+ state: { ...roundTrip(first.state), stateVersion: CURRENT_STATE_VERSION + 1 },
481
+ }),
482
+ host,
483
+ );
484
+ expect(result).toEqual({
485
+ kind: EngineResultKind.REJECTED,
486
+ code: RuntimeErrorCode.STATE_VERSION_UNSUPPORTED,
487
+ message: expect.any(String),
488
+ });
489
+ expect(host.progress).toEqual([]);
490
+ expect(host.calls).toEqual([]);
491
+ });
492
+
493
+ it('refuses to resume a state that is not suspended', async () => {
494
+ const done = outcomeOf(await runInIsolate(request({ definition: longWait }), fakeHost()));
495
+ expect(done.status).toBe(ExecutionStatus.SUCCEEDED);
496
+ const ended: RunState = {
497
+ stateVersion: CURRENT_STATE_VERSION,
498
+ formatVersion: CURRENT_FORMAT_VERSION,
499
+ status: RunStatus.SUCCEEDED,
500
+ input: null,
501
+ stack: [],
502
+ outputs: {},
503
+ vars: {},
504
+ pending: null,
505
+ counters: { steps: 1, effects: 0 },
506
+ };
507
+ const result = await runInIsolate(
508
+ request({ definition: longWait, state: ended }),
509
+ fakeHost(),
510
+ );
511
+ expect(result).toEqual(
512
+ expect.objectContaining({
513
+ kind: EngineResultKind.REJECTED,
514
+ code: RuntimeErrorCode.INVALID_REQUEST,
515
+ }),
516
+ );
517
+ });
518
+ });
519
+ });