@swirls/looms 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 00073ce: Open a run's store before its page renders. `preloadRunStore(runId, options)` from `@swirls/looms/react` works outside React, such as in a route loader, and resolves with the store once it has caught up to the log. Components that then call `useRunStore` for the same run get that store, already filled, so a page appears whole instead of connecting and replaying the log on screen. Pass it the same options the provider is given; `RunStoreOptions` names them. A `signal` stops the wait.
8
+
3
9
  ## 0.16.0
4
10
 
5
11
  ### Minor Changes
@@ -9,6 +9,32 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
9
9
  }[];
10
10
  readonly schema?: import("effect/Schema").Json | undefined;
11
11
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
12
+ readonly type: "approval.decided";
13
+ readonly payload: {
14
+ readonly approvalId: string;
15
+ readonly actionId: string;
16
+ readonly outcome: "approve" | "reject";
17
+ readonly payload?: import("effect/Schema").Json | undefined;
18
+ };
19
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
20
+ readonly type: "approval.requested";
21
+ readonly payload: {
22
+ readonly approvalId: string;
23
+ readonly title: string;
24
+ readonly description?: string | undefined;
25
+ readonly actions: readonly {
26
+ readonly id: string;
27
+ readonly label: string;
28
+ readonly outcome: "approve" | "reject";
29
+ }[];
30
+ readonly schema?: import("effect/Schema").Json | undefined;
31
+ };
32
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
33
+ readonly type: "approval.timed_out";
34
+ readonly payload: {
35
+ readonly approvalId: string;
36
+ };
37
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
12
38
  readonly type: "runtime.child.close.requested";
13
39
  readonly payload: {
14
40
  readonly policy: "terminate" | "wait";
@@ -254,30 +280,4 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
254
280
  readonly payload: import("effect/Schema").Json;
255
281
  };
256
282
  };
257
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
258
- readonly type: "approval.decided";
259
- readonly payload: {
260
- readonly approvalId: string;
261
- readonly actionId: string;
262
- readonly outcome: "approve" | "reject";
263
- readonly payload?: import("effect/Schema").Json | undefined;
264
- };
265
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
266
- readonly type: "approval.requested";
267
- readonly payload: {
268
- readonly approvalId: string;
269
- readonly title: string;
270
- readonly description?: string | undefined;
271
- readonly actions: readonly {
272
- readonly id: string;
273
- readonly label: string;
274
- readonly outcome: "approve" | "reject";
275
- }[];
276
- readonly schema?: import("effect/Schema").Json | undefined;
277
- };
278
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
279
- readonly type: "approval.timed_out";
280
- readonly payload: {
281
- readonly approvalId: string;
282
- };
283
283
  })>>;
@@ -32,6 +32,32 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
32
32
  }[];
33
33
  readonly schema?: import("effect/Schema").Json | undefined;
34
34
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
35
+ readonly type: "approval.decided";
36
+ readonly payload: {
37
+ readonly approvalId: string;
38
+ readonly actionId: string;
39
+ readonly outcome: "approve" | "reject";
40
+ readonly payload?: import("effect/Schema").Json | undefined;
41
+ };
42
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
43
+ readonly type: "approval.requested";
44
+ readonly payload: {
45
+ readonly approvalId: string;
46
+ readonly title: string;
47
+ readonly description?: string | undefined;
48
+ readonly actions: readonly {
49
+ readonly id: string;
50
+ readonly label: string;
51
+ readonly outcome: "approve" | "reject";
52
+ }[];
53
+ readonly schema?: import("effect/Schema").Json | undefined;
54
+ };
55
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
56
+ readonly type: "approval.timed_out";
57
+ readonly payload: {
58
+ readonly approvalId: string;
59
+ };
60
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
35
61
  readonly type: "runtime.child.close.requested";
36
62
  readonly payload: {
37
63
  readonly policy: "terminate" | "wait";
@@ -277,32 +303,6 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
277
303
  readonly payload: import("effect/Schema").Json;
278
304
  };
279
305
  };
280
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
281
- readonly type: "approval.decided";
282
- readonly payload: {
283
- readonly approvalId: string;
284
- readonly actionId: string;
285
- readonly outcome: "approve" | "reject";
286
- readonly payload?: import("effect/Schema").Json | undefined;
287
- };
288
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
289
- readonly type: "approval.requested";
290
- readonly payload: {
291
- readonly approvalId: string;
292
- readonly title: string;
293
- readonly description?: string | undefined;
294
- readonly actions: readonly {
295
- readonly id: string;
296
- readonly label: string;
297
- readonly outcome: "approve" | "reject";
298
- }[];
299
- readonly schema?: import("effect/Schema").Json | undefined;
300
- };
301
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
302
- readonly type: "approval.timed_out";
303
- readonly payload: {
304
- readonly approvalId: string;
305
- };
306
306
  })>;
307
307
  }, {}, {
308
308
  pendingApprovals: import("@swirls/looms/core").ProjectionDefinition<{
@@ -346,6 +346,32 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
346
346
  }[];
347
347
  readonly schema?: import("effect/Schema").Json | undefined;
348
348
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
+ readonly type: "approval.decided";
350
+ readonly payload: {
351
+ readonly approvalId: string;
352
+ readonly actionId: string;
353
+ readonly outcome: "approve" | "reject";
354
+ readonly payload?: import("effect/Schema").Json | undefined;
355
+ };
356
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
357
+ readonly type: "approval.requested";
358
+ readonly payload: {
359
+ readonly approvalId: string;
360
+ readonly title: string;
361
+ readonly description?: string | undefined;
362
+ readonly actions: readonly {
363
+ readonly id: string;
364
+ readonly label: string;
365
+ readonly outcome: "approve" | "reject";
366
+ }[];
367
+ readonly schema?: import("effect/Schema").Json | undefined;
368
+ };
369
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
370
+ readonly type: "approval.timed_out";
371
+ readonly payload: {
372
+ readonly approvalId: string;
373
+ };
374
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
375
  readonly type: "runtime.child.close.requested";
350
376
  readonly payload: {
351
377
  readonly policy: "terminate" | "wait";
@@ -591,32 +617,6 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
591
617
  readonly payload: import("effect/Schema").Json;
592
618
  };
593
619
  };
594
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
595
- readonly type: "approval.decided";
596
- readonly payload: {
597
- readonly approvalId: string;
598
- readonly actionId: string;
599
- readonly outcome: "approve" | "reject";
600
- readonly payload?: import("effect/Schema").Json | undefined;
601
- };
602
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
603
- readonly type: "approval.requested";
604
- readonly payload: {
605
- readonly approvalId: string;
606
- readonly title: string;
607
- readonly description?: string | undefined;
608
- readonly actions: readonly {
609
- readonly id: string;
610
- readonly label: string;
611
- readonly outcome: "approve" | "reject";
612
- }[];
613
- readonly schema?: import("effect/Schema").Json | undefined;
614
- };
615
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
616
- readonly type: "approval.timed_out";
617
- readonly payload: {
618
- readonly approvalId: string;
619
- };
620
620
  })>;
621
621
  };
622
622
  readonly threads: {};
@@ -5,4 +5,4 @@ export type { StoreObservation, StoreObserver } from './observer';
5
5
  export { materializeEvents } from './materialize';
6
6
  export { emptyTables, type MaterializedTables, type RunRow, type ThreadRow } from './tables';
7
7
  export type { LoomsRegister, RegisteredEvent, AnyEventEnvelope } from '@swirls/looms/core';
8
- export { LoomsProvider, useRunStore, useProjection, useRunSelector, useRunSummary, useRunEvents, useThreadTree, useEventCounts, useEventBySeq, useLatestEvent, useLiveFold, type LoomsProviderProps, type UseRunStoreOptions, type RunSummary, } from './react';
8
+ export { LoomsProvider, preloadRunStore, useRunStore, useProjection, useRunSelector, useRunSummary, useRunEvents, useThreadTree, useEventCounts, useEventBySeq, useLatestEvent, useLiveFold, type LoomsProviderProps, type PreloadRunStoreOptions, type RunStoreOptions, type UseRunStoreOptions, type RunSummary, } from './react';
@@ -3,4 +3,4 @@ export { defineLiveFold, foldLive, EventIndex, eventThreadKey, } from './derived
3
3
  export { indexedDbEventCache, memoryEventCache, } from './cache.js';
4
4
  export { materializeEvents } from './materialize.js';
5
5
  export { emptyTables } from './tables.js';
6
- export { LoomsProvider, useRunStore, useProjection, useRunSelector, useRunSummary, useRunEvents, useThreadTree, useEventCounts, useEventBySeq, useLatestEvent, useLiveFold, } from './react.js';
6
+ export { LoomsProvider, preloadRunStore, useRunStore, useProjection, useRunSelector, useRunSummary, useRunEvents, useThreadTree, useEventCounts, useEventBySeq, useLatestEvent, useLiveFold, } from './react.js';
@@ -41,6 +41,39 @@ export interface UseRunStoreOptions {
41
41
  fromSeq?: number;
42
42
  retainMs?: number;
43
43
  }
44
+ /**
45
+ * Everything that decides which store a run gets when there is no provider to supply part of
46
+ * it. Inside React the provider gives `endpoint`, `coalesce`, `transport`, `retainMs`, `cache`
47
+ * and `observer`; outside it the caller passes them.
48
+ */
49
+ export interface RunStoreOptions extends UseRunStoreOptions {
50
+ /** Keeps the run's durable events on the device. See `indexedDbEventCache`. */
51
+ cache?: EventCache;
52
+ /** Told how long the run took to show and how long each commit took. */
53
+ observer?: StoreObserver;
54
+ }
55
+ export interface PreloadRunStoreOptions extends RunStoreOptions {
56
+ /** Stops waiting. The promise rejects with the signal's reason and the store is let go. */
57
+ signal?: AbortSignal;
58
+ }
59
+ /**
60
+ * Opens a run's store outside React and resolves with it once it has caught up to the log,
61
+ * which is when `store.synced()` turns true.
62
+ *
63
+ * This is for code that runs before a page renders, such as a route loader: await it, and the
64
+ * components that then call `useRunStore` for the same run get this store, already filled,
65
+ * instead of connecting and replaying the log on screen.
66
+ *
67
+ * A store is found by its endpoint, run, transport, thread and `includeEphemeral`, so pass the
68
+ * same values the provider is given, or the hook will open a second store. Sharing one options
69
+ * object between `LoomsProvider` and this call is the simplest way. `cache`, `observer` and
70
+ * `fromSeq` are taken from whichever of the two opens the store first.
71
+ *
72
+ * The store is held while this waits and then kept for `retainMs`, like one whose last
73
+ * component unmounted, so a page has that long to take it over. With no `signal` it waits for
74
+ * as long as the log takes to arrive.
75
+ */
76
+ export declare function preloadRunStore(runId: string, options?: PreloadRunStoreOptions): Promise<LoomsClientStore>;
44
77
  /**
45
78
  * Acquires a non-subscribing handle to the run store.
46
79
  * Retains the store in memory while mounted; does NOT trigger component re-renders.
@@ -83,6 +83,57 @@ export function LoomsProvider({ children, endpoint = '', coalesce, transport, re
83
83
  const value = useMemo(() => ({ endpoint, coalesce, transport, retainMs, cache, observer }), [endpoint, coalesce, transport, retainMs, cache, observer]);
84
84
  return createElement(LoomsContext.Provider, { value, children });
85
85
  }
86
+ /**
87
+ * Opens a run's store outside React and resolves with it once it has caught up to the log,
88
+ * which is when `store.synced()` turns true.
89
+ *
90
+ * This is for code that runs before a page renders, such as a route loader: await it, and the
91
+ * components that then call `useRunStore` for the same run get this store, already filled,
92
+ * instead of connecting and replaying the log on screen.
93
+ *
94
+ * A store is found by its endpoint, run, transport, thread and `includeEphemeral`, so pass the
95
+ * same values the provider is given, or the hook will open a second store. Sharing one options
96
+ * object between `LoomsProvider` and this call is the simplest way. `cache`, `observer` and
97
+ * `fromSeq` are taken from whichever of the two opens the store first.
98
+ *
99
+ * The store is held while this waits and then kept for `retainMs`, like one whose last
100
+ * component unmounted, so a page has that long to take it over. With no `signal` it waits for
101
+ * as long as the log takes to arrive.
102
+ */
103
+ export function preloadRunStore(runId, options = {}) {
104
+ const { signal, ...rest } = options;
105
+ const identity = { ...rest, endpoint: rest.endpoint ?? '' };
106
+ if (signal?.aborted) {
107
+ return Promise.reject(signal.reason);
108
+ }
109
+ const { promise, resolve, reject } = Promise.withResolvers();
110
+ retainStore(runId, identity);
111
+ const store = peekStore(runId, identity);
112
+ let done = false;
113
+ // A store calls a new listener at once, which is before there is anything to unsubscribe.
114
+ let unsubscribe;
115
+ const finish = (settle) => {
116
+ if (done) {
117
+ return;
118
+ }
119
+ done = true;
120
+ unsubscribe?.();
121
+ signal?.removeEventListener('abort', onAbort);
122
+ releaseStore(runId, identity);
123
+ settle();
124
+ };
125
+ const onAbort = () => finish(() => reject(signal?.reason));
126
+ unsubscribe = store.subscribe(() => {
127
+ if (store.synced()) {
128
+ finish(() => resolve(store));
129
+ }
130
+ });
131
+ if (done) {
132
+ unsubscribe();
133
+ }
134
+ signal?.addEventListener('abort', onAbort, { once: true });
135
+ return promise;
136
+ }
86
137
  /**
87
138
  * Acquires a non-subscribing handle to the run store.
88
139
  * Retains the store in memory while mounted; does NOT trigger component re-renders.
@@ -143,6 +143,14 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
143
143
  } | undefined;
144
144
  readonly input?: import("effect/Schema").Json | undefined;
145
145
  }, import("./definitions-store").WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
146
+ readonly type: "runtime.effect.retry.scheduled";
147
+ readonly payload: {
148
+ readonly effectId: string;
149
+ readonly attempt: number;
150
+ readonly nextAttemptAt: number;
151
+ readonly error: string;
152
+ };
153
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
146
154
  readonly type: "runtime.child.close.requested";
147
155
  readonly payload: {
148
156
  readonly policy: "terminate" | "wait";
@@ -227,14 +235,6 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
227
235
  readonly attempt: number;
228
236
  readonly deadlineAt: number | null;
229
237
  };
230
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
231
- readonly type: "runtime.effect.retry.scheduled";
232
- readonly payload: {
233
- readonly effectId: string;
234
- readonly attempt: number;
235
- readonly nextAttemptAt: number;
236
- readonly error: string;
237
- };
238
238
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
239
239
  readonly type: "runtime.effect.timed_out";
240
240
  readonly payload: {
@@ -548,6 +548,14 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
548
548
  };
549
549
  } | undefined;
550
550
  }, import("./definitions-store").WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
551
+ readonly type: "runtime.effect.retry.scheduled";
552
+ readonly payload: {
553
+ readonly effectId: string;
554
+ readonly attempt: number;
555
+ readonly nextAttemptAt: number;
556
+ readonly error: string;
557
+ };
558
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
551
559
  readonly type: "runtime.child.close.requested";
552
560
  readonly payload: {
553
561
  readonly policy: "terminate" | "wait";
@@ -632,14 +640,6 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
632
640
  readonly attempt: number;
633
641
  readonly deadlineAt: number | null;
634
642
  };
635
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
636
- readonly type: "runtime.effect.retry.scheduled";
637
- readonly payload: {
638
- readonly effectId: string;
639
- readonly attempt: number;
640
- readonly nextAttemptAt: number;
641
- readonly error: string;
642
- };
643
643
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
644
644
  readonly type: "runtime.effect.timed_out";
645
645
  readonly payload: {
@@ -1131,6 +1131,14 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1131
1131
  } | undefined;
1132
1132
  readonly input?: import("effect/Schema").Json | undefined;
1133
1133
  }, import("./definitions-store").WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1134
+ readonly type: "runtime.effect.retry.scheduled";
1135
+ readonly payload: {
1136
+ readonly effectId: string;
1137
+ readonly attempt: number;
1138
+ readonly nextAttemptAt: number;
1139
+ readonly error: string;
1140
+ };
1141
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1134
1142
  readonly type: "runtime.child.close.requested";
1135
1143
  readonly payload: {
1136
1144
  readonly policy: "terminate" | "wait";
@@ -1215,14 +1223,6 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1215
1223
  readonly attempt: number;
1216
1224
  readonly deadlineAt: number | null;
1217
1225
  };
1218
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1219
- readonly type: "runtime.effect.retry.scheduled";
1220
- readonly payload: {
1221
- readonly effectId: string;
1222
- readonly attempt: number;
1223
- readonly nextAttemptAt: number;
1224
- readonly error: string;
1225
- };
1226
1226
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1227
1227
  readonly type: "runtime.effect.timed_out";
1228
1228
  readonly payload: {
@@ -1536,6 +1536,14 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1536
1536
  };
1537
1537
  } | undefined;
1538
1538
  }, import("./definitions-store").WorkflowDefinitionsTag, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1539
+ readonly type: "runtime.effect.retry.scheduled";
1540
+ readonly payload: {
1541
+ readonly effectId: string;
1542
+ readonly attempt: number;
1543
+ readonly nextAttemptAt: number;
1544
+ readonly error: string;
1545
+ };
1546
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1539
1547
  readonly type: "runtime.child.close.requested";
1540
1548
  readonly payload: {
1541
1549
  readonly policy: "terminate" | "wait";
@@ -1620,14 +1628,6 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1620
1628
  readonly attempt: number;
1621
1629
  readonly deadlineAt: number | null;
1622
1630
  };
1623
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1624
- readonly type: "runtime.effect.retry.scheduled";
1625
- readonly payload: {
1626
- readonly effectId: string;
1627
- readonly attempt: number;
1628
- readonly nextAttemptAt: number;
1629
- readonly error: string;
1630
- };
1631
1631
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1632
1632
  readonly type: "runtime.effect.timed_out";
1633
1633
  readonly payload: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/looms",
3
- "version": "0.16.0",
3
+ "version": "0.17.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": {