@swirls/looms 0.6.1 → 0.7.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 (75) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/actor/cell.d.ts +1 -1
  3. package/dist/actor/routing.d.ts +5 -1
  4. package/dist/actor/routing.js +14 -3
  5. package/dist/agent/effects.d.ts +20 -2
  6. package/dist/agent/effects.js +2 -0
  7. package/dist/agent/module.d.ts +40 -4
  8. package/dist/approval/effects.d.ts +10 -1
  9. package/dist/approval/effects.js +1 -0
  10. package/dist/approval/module.d.ts +20 -2
  11. package/dist/client/client.d.ts +38 -10
  12. package/dist/client/client.js +2 -1
  13. package/dist/cloudflare/durable-object.d.ts +1 -1
  14. package/dist/cloudflare/index.d.ts +1 -1
  15. package/dist/cloudflare/index.js +1 -1
  16. package/dist/cloudflare/queue-consumer.d.ts +17 -10
  17. package/dist/cloudflare/queue-consumer.js +63 -27
  18. package/dist/cloudflare/queue-message.d.ts +4 -1
  19. package/dist/cloudflare/queue-message.js +4 -1
  20. package/dist/cloudflare/queue-worker.d.ts +7 -3
  21. package/dist/cloudflare/queue-worker.js +7 -2
  22. package/dist/cloudflare/queues.d.ts +1 -1
  23. package/dist/cloudflare/queues.js +1 -1
  24. package/dist/core/compose.d.ts +2 -1
  25. package/dist/core/compose.js +5 -0
  26. package/dist/core/effects.d.ts +84 -39
  27. package/dist/core/effects.js +29 -8
  28. package/dist/core/fold.js +34 -0
  29. package/dist/core/module-scope.d.ts +22 -8
  30. package/dist/core/module-scope.js +3 -0
  31. package/dist/core/module.d.ts +40 -9
  32. package/dist/core/module.js +25 -6
  33. package/dist/core/protocol.d.ts +12 -1
  34. package/dist/core/protocol.js +12 -0
  35. package/dist/core/published.d.ts +52 -0
  36. package/dist/core/published.js +45 -0
  37. package/dist/core/replay.d.ts +4 -2
  38. package/dist/core/state.d.ts +8 -2
  39. package/dist/core/state.js +2 -0
  40. package/dist/debugger/app/assets/{index-CUO1xyYW.js → index-CMRl_aWQ.js} +2 -2
  41. package/dist/debugger/app/assets/routes-CfXxKG45.js +47 -0
  42. package/dist/debugger/app/index.html +1 -1
  43. package/dist/debugger/events/protocol-summarize.js +2 -0
  44. package/dist/evaluator/effects.d.ts +10 -1
  45. package/dist/evaluator/effects.js +1 -0
  46. package/dist/evaluator/module.d.ts +20 -2
  47. package/dist/runtime/cancellation.js +1 -1
  48. package/dist/runtime/dispatch-effect.d.ts +2 -2
  49. package/dist/runtime/dispatch-effect.js +12 -4
  50. package/dist/runtime/effect-admission.d.ts +45 -0
  51. package/dist/runtime/effect-admission.js +70 -0
  52. package/dist/runtime/helpers.d.ts +6 -1
  53. package/dist/runtime/helpers.js +14 -5
  54. package/dist/runtime/index.d.ts +1 -0
  55. package/dist/runtime/index.js +1 -0
  56. package/dist/runtime/local-effect-executor.js +25 -3
  57. package/dist/runtime/retry-policy.js +6 -1
  58. package/dist/runtime/runtime.js +7 -2
  59. package/dist/runtime/server/routes/definitions.js +8 -1
  60. package/dist/runtime/types.d.ts +20 -5
  61. package/dist/runtime/wake-engine.js +20 -0
  62. package/dist/runtime/worker-callbacks.js +2 -2
  63. package/dist/runtime/worker-effect-dispatch.d.ts +35 -9
  64. package/dist/runtime/worker-effect-dispatch.js +105 -26
  65. package/dist/schedule/effects.d.ts +20 -2
  66. package/dist/schedule/effects.js +2 -0
  67. package/dist/schedule/module.d.ts +76 -40
  68. package/dist/testing/corpus-module.d.ts +2 -2
  69. package/dist/testing/corpus-module.js +27 -19
  70. package/dist/testing/index.js +12 -23
  71. package/dist/workflow/effects.d.ts +20 -2
  72. package/dist/workflow/effects.js +2 -0
  73. package/dist/workflow/module.d.ts +40 -4
  74. package/package.json +1 -1
  75. package/dist/debugger/app/assets/routes-lt_6J025.js +0 -47
@@ -17,25 +17,33 @@ const CheckoutInputSchema = Schema.Finite;
17
17
  const decodeApproved = Schema.decodeUnknownOption(ApprovedPayloadSchema);
18
18
  const decodeCheckoutInput = Schema.decodeUnknownOption(CheckoutInputSchema);
19
19
  export function corpusModule(options) {
20
- const charge = defineEffect({
21
- type: corpusChargeV1,
22
- retry: {
23
- maxAttempts: 3,
24
- backoffMs: 1,
25
- scheduleToStartTimeoutMs: 60_000,
26
- startToCloseTimeoutMs: 60_000,
27
- },
28
- execute: options?.charge,
29
- });
30
- const chargeV2 = defineEffect({
31
- type: corpusChargeV2,
32
- retry: {
33
- maxAttempts: 1,
34
- scheduleToStartTimeoutMs: 60_000,
35
- startToCloseTimeoutMs: 60_000,
36
- },
37
- execute: options?.charge,
38
- });
20
+ const chargeRetry = {
21
+ maxAttempts: 3,
22
+ backoffMs: 1,
23
+ scheduleToStartTimeoutMs: 60_000,
24
+ startToCloseTimeoutMs: 60_000,
25
+ };
26
+ const charge = options?.charge
27
+ ? defineEffect({
28
+ type: corpusChargeV1,
29
+ placement: 'local',
30
+ retry: chargeRetry,
31
+ execute: options.charge,
32
+ })
33
+ : defineEffect({ type: corpusChargeV1, placement: 'worker', retry: chargeRetry });
34
+ const chargeV2Retry = {
35
+ maxAttempts: 1,
36
+ scheduleToStartTimeoutMs: 60_000,
37
+ startToCloseTimeoutMs: 60_000,
38
+ };
39
+ const chargeV2 = options?.charge
40
+ ? defineEffect({
41
+ type: corpusChargeV2,
42
+ placement: 'local',
43
+ retry: chargeV2Retry,
44
+ execute: options.charge,
45
+ })
46
+ : defineEffect({ type: corpusChargeV2, placement: 'worker', retry: chargeV2Retry });
39
47
  return defineRuntimeModule({
40
48
  namespace: 'corpus',
41
49
  protocolVersion: '1.0.0',
@@ -1,21 +1,7 @@
1
- import { Effect, Predicate } from 'effect';
1
+ import { Effect } from 'effect';
2
2
  import { composeModules, EventStoreTag, makeMemoryEventStore, ModuleCompositionError, EventStoreError, snapshotStoreOf, withSnapshotStore, } from '@swirls/looms/core';
3
3
  import { createRuntime } from '@swirls/looms/runtime';
4
4
  import { assertReplayDeterministicEvents } from './replay-corpus.js';
5
- function namedEffects(effects) {
6
- const listed = [];
7
- for (const key of Object.keys(effects)) {
8
- const value = effects[key];
9
- if (!value || !Predicate.isString(value.type)) {
10
- continue;
11
- }
12
- listed.push({
13
- type: value.type,
14
- hasExecute: 'execute' in value,
15
- });
16
- }
17
- return listed;
18
- }
19
5
  export function createTestRuntime(modules) {
20
6
  return Effect.runPromise(makeMemoryEventStore.pipe(Effect.map((store) => {
21
7
  const runtime = createRuntime({ modules, store });
@@ -44,14 +30,17 @@ export function moduleConformance(module) {
44
30
  if (module.events && module.events.namespace !== module.namespace) {
45
31
  errors.push(`catalog namespace ${module.events.namespace} !== module ${module.namespace}`);
46
32
  }
47
- if (module.effects) {
48
- for (const effect of namedEffects(module.effects)) {
49
- if (!effect.type.startsWith(`${module.namespace}.`)) {
50
- errors.push(`effect ${effect.type} is not namespaced under ${module.namespace}`);
51
- }
52
- if (!effect.hasExecute) {
53
- errors.push(`effect ${effect.type} is missing execute`);
54
- }
33
+ for (const effect of Object.values(module.effects ?? {})) {
34
+ const { type, placement } = effect;
35
+ const hasExecute = 'execute' in effect;
36
+ if (!type.startsWith(`${module.namespace}.`)) {
37
+ errors.push(`effect ${type} is not namespaced under ${module.namespace}`);
38
+ }
39
+ if (placement === 'local' && !hasExecute) {
40
+ errors.push(`local effect ${type} is missing execute`);
41
+ }
42
+ if (placement === 'worker' && hasExecute) {
43
+ errors.push(`worker effect ${type} must not define execute`);
55
44
  }
56
45
  }
57
46
  try {
@@ -4,7 +4,7 @@ import { type NodeState, type WorkflowDefinition } from './definitions';
4
4
  import { WorkflowDefinitionsTag } from './definitions-store';
5
5
  import { type WorkflowEvent } from './scope';
6
6
  type WorkflowEvents = EventInputOf<WorkflowEvent>[];
7
- export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
7
+ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
8
8
  readonly definitionName?: string | undefined;
9
9
  readonly definitionVersion: string;
10
10
  readonly nodes?: {
@@ -67,6 +67,15 @@ export declare const scheduleEffect: NoInfer<import("@swirls/looms/core").Effect
67
67
  readonly effectId: string;
68
68
  readonly attempt: number;
69
69
  };
70
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
71
+ readonly type: "runtime.effect.dispatch.deferred";
72
+ readonly payload: {
73
+ readonly effectId: string;
74
+ readonly attempt: number;
75
+ readonly retryAt: number;
76
+ readonly error: string;
77
+ readonly try: number;
78
+ };
70
79
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
71
80
  readonly type: "runtime.effect.dispatched";
72
81
  readonly payload: {
@@ -398,7 +407,7 @@ export declare function scheduleEvents(definition: WorkflowDefinition, binding:
398
407
  nodes: Record<string, NodeState>;
399
408
  input: JsonValue;
400
409
  }, threadId: string): Effect.Effect<WorkflowEvents>;
401
- export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
410
+ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
402
411
  readonly definitionName?: string | undefined;
403
412
  readonly definitionVersion: string;
404
413
  readonly nodeId: string;
@@ -467,6 +476,15 @@ export declare const runNodeEffect: NoInfer<import("@swirls/looms/core").EffectD
467
476
  readonly effectId: string;
468
477
  readonly attempt: number;
469
478
  };
479
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
480
+ readonly type: "runtime.effect.dispatch.deferred";
481
+ readonly payload: {
482
+ readonly effectId: string;
483
+ readonly attempt: number;
484
+ readonly retryAt: number;
485
+ readonly error: string;
486
+ readonly try: number;
487
+ };
470
488
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
471
489
  readonly type: "runtime.effect.dispatched";
472
490
  readonly payload: {
@@ -45,6 +45,7 @@ function threadFailed(threadId, error) {
45
45
  }
46
46
  export const scheduleEffect = workflowModule.effect({
47
47
  type: 'workflow.schedule',
48
+ placement: 'local',
48
49
  input: ScheduleInput,
49
50
  deterministic: true,
50
51
  execute: (input, ctx) => Effect.gen(function* () {
@@ -148,6 +149,7 @@ export function scheduleEvents(definition, binding, threadId) {
148
149
  }
149
150
  export const runNodeEffect = workflowModule.effect({
150
151
  type: 'workflow.runNode',
152
+ placement: 'local',
151
153
  input: RunNodeInput,
152
154
  execute: (input, ctx) => Effect.gen(function* () {
153
155
  const workflows = yield* WorkflowDefinitionsTag;
@@ -124,7 +124,7 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
124
124
  }>]>>;
125
125
  }>;
126
126
  }>, {
127
- schedule: import("@swirls/looms/core").EffectDefinition<{
127
+ schedule: import("@swirls/looms/core").LocalEffectDefinition<{
128
128
  readonly definitionName?: string | undefined;
129
129
  readonly definitionVersion: string;
130
130
  readonly nodes?: {
@@ -187,6 +187,15 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
187
187
  readonly effectId: string;
188
188
  readonly attempt: number;
189
189
  };
190
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
191
+ readonly type: "runtime.effect.dispatch.deferred";
192
+ readonly payload: {
193
+ readonly effectId: string;
194
+ readonly attempt: number;
195
+ readonly retryAt: number;
196
+ readonly error: string;
197
+ readonly try: number;
198
+ };
190
199
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
191
200
  readonly type: "runtime.effect.dispatched";
192
201
  readonly payload: {
@@ -514,7 +523,7 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
514
523
  readonly close: "terminate" | "wait";
515
524
  };
516
525
  })>;
517
- runNode: import("@swirls/looms/core").EffectDefinition<{
526
+ runNode: import("@swirls/looms/core").LocalEffectDefinition<{
518
527
  readonly definitionName?: string | undefined;
519
528
  readonly definitionVersion: string;
520
529
  readonly nodeId: string;
@@ -583,6 +592,15 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
583
592
  readonly effectId: string;
584
593
  readonly attempt: number;
585
594
  };
595
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
596
+ readonly type: "runtime.effect.dispatch.deferred";
597
+ readonly payload: {
598
+ readonly effectId: string;
599
+ readonly attempt: number;
600
+ readonly retryAt: number;
601
+ readonly error: string;
602
+ readonly try: number;
603
+ };
586
604
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
587
605
  readonly type: "runtime.effect.dispatched";
588
606
  readonly payload: {
@@ -1094,7 +1112,7 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1094
1112
  }>;
1095
1113
  }, import("effect/Context").Service.Any> & {
1096
1114
  readonly effects: {
1097
- schedule: import("@swirls/looms/core").EffectDefinition<{
1115
+ schedule: import("@swirls/looms/core").LocalEffectDefinition<{
1098
1116
  readonly definitionName?: string | undefined;
1099
1117
  readonly definitionVersion: string;
1100
1118
  readonly nodes?: {
@@ -1157,6 +1175,15 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1157
1175
  readonly effectId: string;
1158
1176
  readonly attempt: number;
1159
1177
  };
1178
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1179
+ readonly type: "runtime.effect.dispatch.deferred";
1180
+ readonly payload: {
1181
+ readonly effectId: string;
1182
+ readonly attempt: number;
1183
+ readonly retryAt: number;
1184
+ readonly error: string;
1185
+ readonly try: number;
1186
+ };
1160
1187
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1161
1188
  readonly type: "runtime.effect.dispatched";
1162
1189
  readonly payload: {
@@ -1484,7 +1511,7 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1484
1511
  readonly close: "terminate" | "wait";
1485
1512
  };
1486
1513
  })>;
1487
- runNode: import("@swirls/looms/core").EffectDefinition<{
1514
+ runNode: import("@swirls/looms/core").LocalEffectDefinition<{
1488
1515
  readonly definitionName?: string | undefined;
1489
1516
  readonly definitionVersion: string;
1490
1517
  readonly nodeId: string;
@@ -1553,6 +1580,15 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1553
1580
  readonly effectId: string;
1554
1581
  readonly attempt: number;
1555
1582
  };
1583
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1584
+ readonly type: "runtime.effect.dispatch.deferred";
1585
+ readonly payload: {
1586
+ readonly effectId: string;
1587
+ readonly attempt: number;
1588
+ readonly retryAt: number;
1589
+ readonly error: string;
1590
+ readonly try: number;
1591
+ };
1556
1592
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1557
1593
  readonly type: "runtime.effect.dispatched";
1558
1594
  readonly payload: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/looms",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Pluggable event-sourced runtime for durable agents and workflows",
5
5
  "homepage": "https://github.com/ByteSliceHQ/looms#readme",
6
6
  "bugs": {