@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f2bef2f: Effects declare `placement: 'local' | 'worker'` on `m.effect`, `scope.effect`, or `defineEffect`. Local effects require `execute`; worker effects forbid it and implement the handler with `workerHandlers`. Queue routes take worker definitions, local and worker handlers get distinct context types, and `defineModule` rejects effects built outside the module's catalog. `GET /definitions/effects` publishes each declared effect, including placement, retry policy, and input schema.
8
+
9
+ ## Unreleased
10
+
11
+ ### Minor Changes
12
+
13
+ - **Breaking:** Effect placement is explicit. `m.effect`, `scope.effect`, and `defineEffect` require `placement: 'local' | 'worker'`. Local effects must define `execute`; worker effects must not, and their handlers go in `workerHandlers`. Worker definitions no longer carry a no-op `execute`, and `hasHandler` is removed; branch on `placement` instead. The old inferred `execution` / handler-less / string-`handles` overlap model is removed. `cloudflareQueueWorker` routes take `{ effects: [definition], queue }` instead of `handles` type strings. `onEffect` only accepts local definitions; `workerHandlers` only accepts worker definitions. Handlers receive `LocalEffectContext` or `WorkerEffectContext` (`placement` discriminant); worker `emit` stays buffered until complete.
14
+ - **Breaking:** `defineModule` rejects effects whose events fall outside the module's catalog and `observes`, such as an effect built with another module's scope or an unscoped `defineEffect` that returns untyped events. Build effects that live in their own file with `createModuleScope(...).effect`.
15
+ - Effect admission hooks (`admission` / `onAdmit`) run in the host before every local attempt and before every worker dispatch, so credit checks and feature flags cover both paths. `failEffect` from admission becomes `runtime.effect.failed`; a rejected worker admission never queues. Execution middleware remains local-only.
16
+ - `onAdmit` and `onEffect` decode the input with the definition's schema before the hook runs, so hooks see defaults and transforms. An input that fails to decode fails the attempt.
17
+ - Queue tasks carry `threadId`, `causingEventId`, and `attributes`. Secrets load through the worker callback before the handler runs. `GET /definitions/effects` lists declared effects, including placement, retry policy, and input schema. `runtime.effectPlacements` lists placements; `inspectRun` / effect status includes each outstanding effect's `placement`.
18
+ - Creating a runtime fails when worker-placed effects have no `EffectWorker`, or when a worker claims a local-placed effect type.
19
+ - Unacknowledged worker dispatch failures no longer park as `ambiguous` on the first push. The attempt enters `dispatch_wait` via `runtime.effect.dispatch.deferred`, and the wake engine retries the same attempt with dedicated outbox backoff. `ambiguous` remains for missing workers, cancellation timeouts, and exhausted relays. Acknowledged transports (Cloudflare Queues) are unchanged. `retryEffect` can target `dispatch_wait`.
20
+
3
21
  ## 0.6.1
4
22
 
5
23
  ### Patch Changes
@@ -20,7 +20,7 @@ export interface ActorCellOptions<TModules extends readonly AnyRuntimeModule[] =
20
20
  /** Starts runs from effect handlers. Required for schedules; there is no default inside a cell. */
21
21
  readonly launcher?: RunLauncher;
22
22
  /**
23
- * Dispatches `execution: 'worker'` effects out of the cell (for example a
23
+ * Dispatches worker-placed effects out of the cell (for example a
24
24
  * Cloudflare Queue producer). Without it, worker effects cannot leave the object.
25
25
  */
26
26
  readonly worker?: EffectWorker;
@@ -9,7 +9,11 @@ export declare function runIdFromRequest(req: Request): string | null;
9
9
  * runs needs a global index, and a fork writes a second run. `host` names the backend.
10
10
  */
11
11
  export declare function crossRunResponse(req: Request, host: string): Response | null;
12
- /** Answers `GET /definitions` from a module list or lazy factory without touching any run cell. */
12
+ /**
13
+ * Answers definition catalogs from a module list or lazy factory without touching any run cell.
14
+ * `GET /definitions` is the thread-definition catalog. `GET /definitions/effects` is each declared
15
+ * effect, including placement.
16
+ */
13
17
  export declare function definitionsResponse(req: Request, modules: readonly AnyRuntimeModule[] | (() => readonly AnyRuntimeModule[]) | undefined): Response | null;
14
18
  export interface ResolvedRunTarget {
15
19
  readonly runId: string;
@@ -1,5 +1,5 @@
1
1
  import { Data, Effect, Option, Predicate, Schema } from 'effect';
2
- import { composeModules, createRunId, isJsonObject, publishDefinition, stringifyJson, } from '@swirls/looms/core';
2
+ import { composeModules, createRunId, isJsonObject, publishDefinition, publishEffects, stringifyJson, } from '@swirls/looms/core';
3
3
  const RunTargetBodySchema = Schema.Struct({
4
4
  runId: Schema.optional(Schema.NonEmptyString),
5
5
  });
@@ -36,12 +36,23 @@ export function crossRunResponse(req, host) {
36
36
  }
37
37
  return null;
38
38
  }
39
- /** Answers `GET /definitions` from a module list or lazy factory without touching any run cell. */
39
+ /**
40
+ * Answers definition catalogs from a module list or lazy factory without touching any run cell.
41
+ * `GET /definitions` is the thread-definition catalog. `GET /definitions/effects` is each declared
42
+ * effect, including placement.
43
+ */
40
44
  export function definitionsResponse(req, modules) {
41
- if (!modules || req.method !== 'GET' || new URL(req.url).pathname !== '/definitions') {
45
+ if (!modules || req.method !== 'GET') {
46
+ return null;
47
+ }
48
+ const pathname = new URL(req.url).pathname;
49
+ if (pathname !== '/definitions' && pathname !== '/definitions/effects') {
42
50
  return null;
43
51
  }
44
52
  const registry = composeModules(Predicate.isFunction(modules) ? modules() : modules);
53
+ if (pathname === '/definitions/effects') {
54
+ return Response.json({ effects: publishEffects(registry.effects.values()) });
55
+ }
45
56
  return Response.json({
46
57
  definitions: registry.definitions.map(publishDefinition),
47
58
  projections: [...registry.projections.keys()],
@@ -3,7 +3,7 @@ import { type JsonValue } from '@swirls/looms/core';
3
3
  import { AgentDefinitionsTag } from './definitions-store';
4
4
  import { LlmTag } from './llm';
5
5
  import { type ToolCall } from './types';
6
- export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
6
+ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
7
7
  readonly turn: number;
8
8
  readonly definitionName?: string | undefined;
9
9
  readonly definitionVersion: string;
@@ -309,6 +309,15 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").EffectD
309
309
  readonly effectId: string;
310
310
  readonly attempt: number;
311
311
  };
312
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
313
+ readonly type: "runtime.effect.dispatch.deferred";
314
+ readonly payload: {
315
+ readonly effectId: string;
316
+ readonly attempt: number;
317
+ readonly retryAt: number;
318
+ readonly error: string;
319
+ readonly try: number;
320
+ };
312
321
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
313
322
  readonly type: "runtime.effect.dispatched";
314
323
  readonly payload: {
@@ -502,7 +511,7 @@ export declare const callLlmEffect: NoInfer<import("@swirls/looms/core").EffectD
502
511
  };
503
512
  };
504
513
  })>>;
505
- export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
514
+ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
506
515
  readonly turn: number;
507
516
  readonly definitionName?: string | undefined;
508
517
  readonly definitionVersion: string;
@@ -800,6 +809,15 @@ export declare const executeToolEffect: NoInfer<import("@swirls/looms/core").Eff
800
809
  readonly effectId: string;
801
810
  readonly attempt: number;
802
811
  };
812
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
813
+ readonly type: "runtime.effect.dispatch.deferred";
814
+ readonly payload: {
815
+ readonly effectId: string;
816
+ readonly attempt: number;
817
+ readonly retryAt: number;
818
+ readonly error: string;
819
+ readonly try: number;
820
+ };
803
821
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
804
822
  readonly type: "runtime.effect.dispatched";
805
823
  readonly payload: {
@@ -74,6 +74,7 @@ function toolError(input, threadId, error) {
74
74
  }
75
75
  export const callLlmEffect = agentModule.effect({
76
76
  type: 'agent.callLLM',
77
+ placement: 'local',
77
78
  input: CallLlmInput,
78
79
  execute: (input, ctx) => runCallLlm({
79
80
  turn: input.turn,
@@ -263,6 +264,7 @@ function runCallLlm(args) {
263
264
  }
264
265
  export const executeToolEffect = agentModule.effect({
265
266
  type: 'agent.executeTool',
267
+ placement: 'local',
266
268
  input: ExecuteToolInput,
267
269
  execute: (input, ctx) => Effect.gen(function* () {
268
270
  const threadId = ctx.threadId;
@@ -215,7 +215,7 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
215
215
  readonly output: import("effect/Schema").Finite;
216
216
  }>;
217
217
  }>, {
218
- callLLM: import("@swirls/looms/core").EffectDefinition<{
218
+ callLLM: import("@swirls/looms/core").LocalEffectDefinition<{
219
219
  readonly turn: number;
220
220
  readonly definitionName?: string | undefined;
221
221
  readonly definitionVersion: string;
@@ -521,6 +521,15 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
521
521
  readonly effectId: string;
522
522
  readonly attempt: number;
523
523
  };
524
+ }) | (Omit<EventInput, "payload" | "type"> & {
525
+ readonly type: "runtime.effect.dispatch.deferred";
526
+ readonly payload: {
527
+ readonly effectId: string;
528
+ readonly attempt: number;
529
+ readonly retryAt: number;
530
+ readonly error: string;
531
+ readonly try: number;
532
+ };
524
533
  }) | (Omit<EventInput, "payload" | "type"> & {
525
534
  readonly type: "runtime.effect.dispatched";
526
535
  readonly payload: {
@@ -714,7 +723,7 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
714
723
  };
715
724
  };
716
725
  })>;
717
- executeTool: import("@swirls/looms/core").EffectDefinition<{
726
+ executeTool: import("@swirls/looms/core").LocalEffectDefinition<{
718
727
  readonly turn: number;
719
728
  readonly definitionName?: string | undefined;
720
729
  readonly definitionVersion: string;
@@ -1012,6 +1021,15 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
1012
1021
  readonly effectId: string;
1013
1022
  readonly attempt: number;
1014
1023
  };
1024
+ }) | (Omit<EventInput, "payload" | "type"> & {
1025
+ readonly type: "runtime.effect.dispatch.deferred";
1026
+ readonly payload: {
1027
+ readonly effectId: string;
1028
+ readonly attempt: number;
1029
+ readonly retryAt: number;
1030
+ readonly error: string;
1031
+ readonly try: number;
1032
+ };
1015
1033
  }) | (Omit<EventInput, "payload" | "type"> & {
1016
1034
  readonly type: "runtime.effect.dispatched";
1017
1035
  readonly payload: {
@@ -1232,7 +1250,7 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
1232
1250
  }>;
1233
1251
  }, import("effect/Context").Service.Any> & {
1234
1252
  readonly effects: {
1235
- callLLM: import("@swirls/looms/core").EffectDefinition<{
1253
+ callLLM: import("@swirls/looms/core").LocalEffectDefinition<{
1236
1254
  readonly turn: number;
1237
1255
  readonly definitionName?: string | undefined;
1238
1256
  readonly definitionVersion: string;
@@ -1538,6 +1556,15 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
1538
1556
  readonly effectId: string;
1539
1557
  readonly attempt: number;
1540
1558
  };
1559
+ }) | (Omit<EventInput, "payload" | "type"> & {
1560
+ readonly type: "runtime.effect.dispatch.deferred";
1561
+ readonly payload: {
1562
+ readonly effectId: string;
1563
+ readonly attempt: number;
1564
+ readonly retryAt: number;
1565
+ readonly error: string;
1566
+ readonly try: number;
1567
+ };
1541
1568
  }) | (Omit<EventInput, "payload" | "type"> & {
1542
1569
  readonly type: "runtime.effect.dispatched";
1543
1570
  readonly payload: {
@@ -1731,7 +1758,7 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
1731
1758
  };
1732
1759
  };
1733
1760
  })>;
1734
- executeTool: import("@swirls/looms/core").EffectDefinition<{
1761
+ executeTool: import("@swirls/looms/core").LocalEffectDefinition<{
1735
1762
  readonly turn: number;
1736
1763
  readonly definitionName?: string | undefined;
1737
1764
  readonly definitionVersion: string;
@@ -2029,6 +2056,15 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
2029
2056
  readonly effectId: string;
2030
2057
  readonly attempt: number;
2031
2058
  };
2059
+ }) | (Omit<EventInput, "payload" | "type"> & {
2060
+ readonly type: "runtime.effect.dispatch.deferred";
2061
+ readonly payload: {
2062
+ readonly effectId: string;
2063
+ readonly attempt: number;
2064
+ readonly retryAt: number;
2065
+ readonly error: string;
2066
+ readonly try: number;
2067
+ };
2032
2068
  }) | (Omit<EventInput, "payload" | "type"> & {
2033
2069
  readonly type: "runtime.effect.dispatched";
2034
2070
  readonly payload: {
@@ -1,4 +1,4 @@
1
- export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core").EffectDefinition<{
1
+ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core").LocalEffectDefinition<{
2
2
  readonly approvalId: string;
3
3
  readonly title: string;
4
4
  readonly description?: string | undefined;
@@ -79,6 +79,15 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
79
79
  readonly effectId: string;
80
80
  readonly attempt: number;
81
81
  };
82
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
83
+ readonly type: "runtime.effect.dispatch.deferred";
84
+ readonly payload: {
85
+ readonly effectId: string;
86
+ readonly attempt: number;
87
+ readonly retryAt: number;
88
+ readonly error: string;
89
+ readonly try: number;
90
+ };
82
91
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
83
92
  readonly type: "runtime.effect.dispatched";
84
93
  readonly payload: {
@@ -2,6 +2,7 @@ import { ApprovalRequestedPayloadSchema } from './events.js';
2
2
  import { approvalModule } from './scope.js';
3
3
  export const requestApprovalEffect = approvalModule.effect({
4
4
  type: 'approval.request',
5
+ placement: 'local',
5
6
  input: ApprovalRequestedPayloadSchema,
6
7
  execute: (input, ctx) => [
7
8
  {
@@ -20,7 +20,7 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
20
20
  readonly approvalId: import("effect/Schema").String;
21
21
  }>;
22
22
  }>, {
23
- request: import("@swirls/looms/core").EffectDefinition<{
23
+ request: import("@swirls/looms/core").LocalEffectDefinition<{
24
24
  readonly approvalId: string;
25
25
  readonly title: string;
26
26
  readonly description?: string | undefined;
@@ -101,6 +101,15 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
101
101
  readonly effectId: string;
102
102
  readonly attempt: number;
103
103
  };
104
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
105
+ readonly type: "runtime.effect.dispatch.deferred";
106
+ readonly payload: {
107
+ readonly effectId: string;
108
+ readonly attempt: number;
109
+ readonly retryAt: number;
110
+ readonly error: string;
111
+ readonly try: number;
112
+ };
104
113
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
105
114
  readonly type: "runtime.effect.dispatched";
106
115
  readonly payload: {
@@ -306,7 +315,7 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
306
315
  }>;
307
316
  }, import("effect/Context").Service.Any> & {
308
317
  readonly effects: {
309
- request: import("@swirls/looms/core").EffectDefinition<{
318
+ request: import("@swirls/looms/core").LocalEffectDefinition<{
310
319
  readonly approvalId: string;
311
320
  readonly title: string;
312
321
  readonly description?: string | undefined;
@@ -387,6 +396,15 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
387
396
  readonly effectId: string;
388
397
  readonly attempt: number;
389
398
  };
399
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
400
+ readonly type: "runtime.effect.dispatch.deferred";
401
+ readonly payload: {
402
+ readonly effectId: string;
403
+ readonly attempt: number;
404
+ readonly retryAt: number;
405
+ readonly error: string;
406
+ readonly try: number;
407
+ };
390
408
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
391
409
  readonly type: "runtime.effect.dispatched";
392
410
  readonly payload: {
@@ -179,13 +179,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
179
179
  readonly [x: string]: {
180
180
  readonly effectId: string;
181
181
  readonly attempt: number;
182
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
182
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
183
183
  readonly nextAttemptAt: number | null;
184
184
  readonly deadlineAt: number | null;
185
185
  readonly startedAt: number | null;
186
186
  readonly lastHeartbeatAt: number | null;
187
187
  readonly heartbeatDetails: Schema.Json;
188
188
  readonly lastError: string | null;
189
+ readonly dispatchTry: number;
189
190
  };
190
191
  };
191
192
  readonly completedEffectIds: readonly string[];
@@ -348,13 +349,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
348
349
  readonly [x: string]: {
349
350
  readonly effectId: string;
350
351
  readonly attempt: number;
351
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
352
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
352
353
  readonly nextAttemptAt: number | null;
353
354
  readonly deadlineAt: number | null;
354
355
  readonly startedAt: number | null;
355
356
  readonly lastHeartbeatAt: number | null;
356
357
  readonly heartbeatDetails: Schema.Json;
357
358
  readonly lastError: string | null;
359
+ readonly dispatchTry: number;
358
360
  };
359
361
  };
360
362
  readonly completedEffectIds: readonly string[];
@@ -515,13 +517,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
515
517
  readonly [x: string]: {
516
518
  readonly effectId: string;
517
519
  readonly attempt: number;
518
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
520
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
519
521
  readonly nextAttemptAt: number | null;
520
522
  readonly deadlineAt: number | null;
521
523
  readonly startedAt: number | null;
522
524
  readonly lastHeartbeatAt: number | null;
523
525
  readonly heartbeatDetails: Schema.Json;
524
526
  readonly lastError: string | null;
527
+ readonly dispatchTry: number;
525
528
  };
526
529
  };
527
530
  readonly completedEffectIds: readonly string[];
@@ -682,13 +685,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
682
685
  readonly [x: string]: {
683
686
  readonly effectId: string;
684
687
  readonly attempt: number;
685
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
688
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
686
689
  readonly nextAttemptAt: number | null;
687
690
  readonly deadlineAt: number | null;
688
691
  readonly startedAt: number | null;
689
692
  readonly lastHeartbeatAt: number | null;
690
693
  readonly heartbeatDetails: Schema.Json;
691
694
  readonly lastError: string | null;
695
+ readonly dispatchTry: number;
692
696
  };
693
697
  };
694
698
  readonly completedEffectIds: readonly string[];
@@ -882,13 +886,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
882
886
  readonly [x: string]: {
883
887
  readonly effectId: string;
884
888
  readonly attempt: number;
885
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
889
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
886
890
  readonly nextAttemptAt: number | null;
887
891
  readonly deadlineAt: number | null;
888
892
  readonly startedAt: number | null;
889
893
  readonly lastHeartbeatAt: number | null;
890
894
  readonly heartbeatDetails: Schema.Json;
891
895
  readonly lastError: string | null;
896
+ readonly dispatchTry: number;
892
897
  };
893
898
  };
894
899
  readonly completedEffectIds: readonly string[];
@@ -1049,13 +1054,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
1049
1054
  readonly [x: string]: {
1050
1055
  readonly effectId: string;
1051
1056
  readonly attempt: number;
1052
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1057
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1053
1058
  readonly nextAttemptAt: number | null;
1054
1059
  readonly deadlineAt: number | null;
1055
1060
  readonly startedAt: number | null;
1056
1061
  readonly lastHeartbeatAt: number | null;
1057
1062
  readonly heartbeatDetails: Schema.Json;
1058
1063
  readonly lastError: string | null;
1064
+ readonly dispatchTry: number;
1059
1065
  };
1060
1066
  };
1061
1067
  readonly completedEffectIds: readonly string[];
@@ -1218,13 +1224,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
1218
1224
  readonly [x: string]: {
1219
1225
  readonly effectId: string;
1220
1226
  readonly attempt: number;
1221
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1227
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1222
1228
  readonly nextAttemptAt: number | null;
1223
1229
  readonly deadlineAt: number | null;
1224
1230
  readonly startedAt: number | null;
1225
1231
  readonly lastHeartbeatAt: number | null;
1226
1232
  readonly heartbeatDetails: Schema.Json;
1227
1233
  readonly lastError: string | null;
1234
+ readonly dispatchTry: number;
1228
1235
  };
1229
1236
  };
1230
1237
  readonly completedEffectIds: readonly string[];
@@ -1389,13 +1396,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
1389
1396
  readonly [x: string]: {
1390
1397
  readonly effectId: string;
1391
1398
  readonly attempt: number;
1392
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1399
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1393
1400
  readonly nextAttemptAt: number | null;
1394
1401
  readonly deadlineAt: number | null;
1395
1402
  readonly startedAt: number | null;
1396
1403
  readonly lastHeartbeatAt: number | null;
1397
1404
  readonly heartbeatDetails: Schema.Json;
1398
1405
  readonly lastError: string | null;
1406
+ readonly dispatchTry: number;
1399
1407
  };
1400
1408
  };
1401
1409
  readonly completedEffectIds: readonly string[];
@@ -1431,6 +1439,24 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
1431
1439
  }[];
1432
1440
  readonly projections: readonly string[];
1433
1441
  }>;
1442
+ listEffects: () => Promise<{
1443
+ readonly effects: readonly {
1444
+ readonly type: string;
1445
+ readonly placement: "local" | "worker";
1446
+ readonly deterministic?: boolean | undefined;
1447
+ readonly retry?: {
1448
+ readonly maxAttempts: number;
1449
+ readonly backoffMs?: number | undefined;
1450
+ readonly maxBackoffMs?: number | undefined;
1451
+ readonly backoffMultiplier?: number | undefined;
1452
+ readonly scheduleToStartTimeoutMs?: number | undefined;
1453
+ readonly startToCloseTimeoutMs?: number | undefined;
1454
+ readonly heartbeatTimeoutMs?: number | undefined;
1455
+ readonly cancellationTimeoutMs?: number | undefined;
1456
+ } | undefined;
1457
+ readonly inputSchema?: Schema.Json | undefined;
1458
+ }[];
1459
+ }>;
1434
1460
  replayTo: (runId: string, seq: number) => Promise<{
1435
1461
  readonly runId: string;
1436
1462
  readonly step: {
@@ -1608,13 +1634,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
1608
1634
  readonly [x: string]: {
1609
1635
  readonly effectId: string;
1610
1636
  readonly attempt: number;
1611
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1637
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1612
1638
  readonly nextAttemptAt: number | null;
1613
1639
  readonly deadlineAt: number | null;
1614
1640
  readonly startedAt: number | null;
1615
1641
  readonly lastHeartbeatAt: number | null;
1616
1642
  readonly heartbeatDetails: Schema.Json;
1617
1643
  readonly lastError: string | null;
1644
+ readonly dispatchTry: number;
1618
1645
  };
1619
1646
  };
1620
1647
  readonly completedEffectIds: readonly string[];
@@ -1772,13 +1799,14 @@ export declare function createLoomsClient(options?: LoomsClientOptions): {
1772
1799
  readonly [x: string]: {
1773
1800
  readonly effectId: string;
1774
1801
  readonly attempt: number;
1775
- readonly status: "ambiguous" | "cancel_requested" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1802
+ readonly status: "ambiguous" | "cancel_requested" | "dispatch_wait" | "dispatched" | "heartbeat" | "queued" | "retry_wait" | "running" | "started" | "timed_out";
1776
1803
  readonly nextAttemptAt: number | null;
1777
1804
  readonly deadlineAt: number | null;
1778
1805
  readonly startedAt: number | null;
1779
1806
  readonly lastHeartbeatAt: number | null;
1780
1807
  readonly heartbeatDetails: Schema.Json;
1781
1808
  readonly lastError: string | null;
1809
+ readonly dispatchTry: number;
1782
1810
  };
1783
1811
  };
1784
1812
  readonly completedEffectIds: readonly string[];
@@ -1,5 +1,5 @@
1
1
  import { Data, Effect, Option, Predicate, Schema, Stream } from 'effect';
2
- import { createRunId, DefinitionCatalogSchema, EventEnvelopeSchema, readSubscriptionData, ReplayStepSchema, RunStateSchema, RunSummariesSchema, SecretContextSchema, stringifyJson, traceHeaders, } from '@swirls/looms/core';
2
+ import { createRunId, DefinitionCatalogSchema, EffectCatalogSchema, EventEnvelopeSchema, readSubscriptionData, ReplayStepSchema, RunStateSchema, RunSummariesSchema, SecretContextSchema, stringifyJson, traceHeaders, } from '@swirls/looms/core';
3
3
  import { consumeSseStreamEffect, eventsFromSseData, sseFrames } from './sse.js';
4
4
  class LoomsClientError extends Data.TaggedError('LoomsClientError') {
5
5
  constructor(message, cause) {
@@ -254,6 +254,7 @@ export function createLoomsClient(options = {}) {
254
254
  workerSecrets,
255
255
  listRunSummaries: () => request('/runs/summaries', RunSummariesSchema),
256
256
  listDefinitions: () => request('/definitions', DefinitionCatalogSchema),
257
+ listEffects: () => request('/definitions/effects', EffectCatalogSchema),
257
258
  replayTo: (runId, seq) => request(`/runs/${encodeURIComponent(runId)}/replay?seq=${seq}`, ReplayResultSchema),
258
259
  project: (runId, name) => request(`/runs/${encodeURIComponent(runId)}/projections/${encodeURIComponent(name)}`, ProjectionResultSchema),
259
260
  subscribeEvents,
@@ -24,7 +24,7 @@ export interface LoomsDurableObjectConfig {
24
24
  */
25
25
  readonly launcher?: RunLauncher;
26
26
  /**
27
- * Dispatches `execution: 'worker'` effects out of this object (typically a
27
+ * Dispatches worker-placed effects out of this object (typically a
28
28
  * Cloudflare Queue producer via `cloudflareQueueWorker`). Without it, worker
29
29
  * effects cannot leave the Durable Object.
30
30
  */
@@ -4,7 +4,7 @@ export { durableObjectLauncher, durableObjectScheduleHost, LoomsDurableObject, t
4
4
  export { r2BlobStore, type R2BucketLike, type R2ListResult, type R2ObjectBodyLike, type R2StoredObject, } from './r2-blob-store';
5
5
  export { routeToDurableObject, type DurableObjectNamespaceLike, type DurableObjectStubLike, } from './router';
6
6
  export { createMemoryQueue, type MemoryQueue, type MemoryQueueOptions } from './memory-queue';
7
- export { processQueueMessage, queueConsumer, QueueTaskError, type QueueBatchLike, type QueueConsumerOptions, type QueueTask, type QueueTaskContext, type QueueTaskHandler, type WorkerCallbackClient, } from './queue-consumer';
7
+ export { processQueueMessage, queueConsumer, QueueTaskError, workerHandlers, type QueueBatchLike, type QueueConsumerOptions, type QueueTask, type QueueTaskHandler, type WorkerCallbackClient, } from './queue-consumer';
8
8
  export { readQueueEffectMessage, type QueueEffectMessage, type QueueMessageLike, } from './queue-message';
9
9
  export { cloudflareQueuePullSource, createQueuePullConsumer, QueuePullError, type CloudflareQueuePullSourceOptions, type PulledQueueMessage, type QueueLeaseRetry, type QueuePullConsumer, type QueuePullConsumerOptions, type QueuePullResult, type QueuePullSource, } from './queue-pull';
10
10
  export { cloudflareQueueWorker, DEFAULT_MAX_QUEUE_MESSAGE_BYTES, QueueDispatchError, type CloudflareQueueWorkerOptions, type QueueProducer, type QueueRoute, } from './queue-worker';
@@ -4,7 +4,7 @@ export { durableObjectLauncher, durableObjectScheduleHost, LoomsDurableObject, }
4
4
  export { r2BlobStore, } from './r2-blob-store.js';
5
5
  export { routeToDurableObject, } from './router.js';
6
6
  export { createMemoryQueue } from './memory-queue.js';
7
- export { processQueueMessage, queueConsumer, QueueTaskError, } from './queue-consumer.js';
7
+ export { processQueueMessage, queueConsumer, QueueTaskError, workerHandlers, } from './queue-consumer.js';
8
8
  export { readQueueEffectMessage, } from './queue-message.js';
9
9
  export { cloudflareQueuePullSource, createQueuePullConsumer, QueuePullError, } from './queue-pull.js';
10
10
  export { cloudflareQueueWorker, DEFAULT_MAX_QUEUE_MESSAGE_BYTES, QueueDispatchError, } from './queue-worker.js';
@@ -1,5 +1,5 @@
1
1
  import { Effect } from 'effect';
2
- import { type BlobStore, type EventInput, type JsonValue, type SecretContext, type WorkerCallback, type WorkerCallbackInput, type WorkerCallbackResult, type WorkerSecretsResult } from '@swirls/looms/core';
2
+ import { type BlobStore, type EventInput, type JsonValue, type WorkerCallback, type WorkerCallbackInput, type WorkerCallbackResult, type WorkerEffectContext, type WorkerEffectDefinition, type WorkerSecretsResult } from '@swirls/looms/core';
3
3
  import { type QueueEffectMessage, type QueueMessageLike } from './queue-message';
4
4
  /** The worker half of the Looms HTTP API. `createLoomsClient({ baseUrl, workerCallbackToken })` is one. */
5
5
  export interface WorkerCallbackClient {
@@ -10,15 +10,22 @@ export interface WorkerCallbackClient {
10
10
  export interface QueueTask extends Omit<QueueEffectMessage, 'v' | 'input' | 'inputRef'> {
11
11
  readonly input: JsonValue;
12
12
  }
13
- export interface QueueTaskContext {
14
- /** Aborts once Looms asks the attempt to stop or no longer counts it as running. */
15
- readonly signal: AbortSignal;
16
- /** Report progress. A later attempt receives the last `details` as `task.details`. */
17
- heartbeat(details?: JsonValue): Promise<void>;
18
- /** The run's secret context. Rejects once the attempt is no longer running. */
19
- secrets(): Promise<SecretContext>;
20
- }
21
- export type QueueTaskHandler = (task: QueueTask, ctx: QueueTaskContext) => Promise<ReadonlyArray<EventInput>> | ReadonlyArray<EventInput>;
13
+ export type QueueTaskHandler = (task: QueueTask, ctx: WorkerEffectContext) => Promise<ReadonlyArray<EventInput>> | ReadonlyArray<EventInput>;
14
+ type WorkerHandlerFn<TInput> = (input: TInput, ctx: WorkerEffectContext) => Promise<ReadonlyArray<EventInput>> | ReadonlyArray<EventInput>;
15
+ type WorkerHandlerBinding<TInput> = readonly [
16
+ WorkerEffectDefinition<TInput>,
17
+ WorkerHandlerFn<TInput>
18
+ ];
19
+ /**
20
+ * Build a `handlers` map from **worker-placed** effect definitions. Input is validated with each
21
+ * definition's schema before the typed handler runs. Passing a local definition is a type error.
22
+ */
23
+ export declare function workerHandlers<const Entries extends ReadonlyArray<WorkerHandlerBinding<any>>>(entries: {
24
+ readonly [K in keyof Entries]: Entries[K] extends readonly [
25
+ WorkerEffectDefinition<infer TInput>,
26
+ unknown
27
+ ] ? WorkerHandlerBinding<TInput> : Entries[K];
28
+ }): Readonly<Record<string, QueueTaskHandler>>;
22
29
  declare const QueueTaskError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
23
30
  readonly _tag: "QueueTaskError";
24
31
  } & Readonly<A>;