@loomwork/plugin-durable-state 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +82 -2
- package/dist/InMemoryDurableStateStore.d.ts +17 -0
- package/dist/InMemoryDurableStateStore.d.ts.map +1 -0
- package/dist/InMemoryDurableStateStore.js +35 -0
- package/dist/InMemoryDurableStateStore.js.map +1 -0
- package/dist/canonical.d.ts +8 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +36 -0
- package/dist/canonical.js.map +1 -0
- package/dist/durableState.d.ts +10 -0
- package/dist/durableState.d.ts.map +1 -0
- package/dist/durableState.js +202 -0
- package/dist/durableState.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/sentinel.d.ts +33 -0
- package/dist/sentinel.d.ts.map +1 -0
- package/dist/sentinel.js +30 -0
- package/dist/sentinel.js.map +1 -0
- package/dist/types.d.ts +116 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -3
- package/src/InMemoryDurableStateStore.ts +39 -0
- package/src/canonical.ts +33 -0
- package/src/durableState.ts +281 -0
- package/src/errors.ts +49 -0
- package/src/index.ts +25 -0
- package/src/sentinel.ts +62 -0
- package/src/types.ts +122 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @loomwork/plugin-durable-state — typed, versioned state that survives between runs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keyed state that a bounded run loads at the start and saves at the end, for work that wakes on a
|
|
4
|
+
schedule and has to remember something between wakes (a cursor, a watermark, counters). Each value has
|
|
5
|
+
a zod schema and a contract version, older versions are migrated on load, and writes are
|
|
6
|
+
compare-and-set on a revision. `load`, `save` and `clear` run as recorded effects, so on replay the
|
|
7
|
+
recorded result is used and the store is not read again (ADR 0053). Use it directly for any
|
|
8
|
+
carried state, or through `sentinelState` for a `schedule$`-driven agent.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { defineConfig } from "@loomwork/app";
|
|
12
|
+
import { flow$ } from "@loomwork/core";
|
|
13
|
+
import { InMemoryDurableStateStore, durableState } from "@loomwork/plugin-durable-state";
|
|
14
|
+
import type { FlowRunner, RegisteredFlow } from "@loomwork/workflow-runtime";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
|
|
17
|
+
const watcher = durableState({
|
|
18
|
+
id: "watcher.state",
|
|
19
|
+
version: 2,
|
|
20
|
+
schema: z.object({ cursor: z.string(), failures: z.number() }),
|
|
21
|
+
// migrations[n] turns a version-n payload into version n+1
|
|
22
|
+
migrations: { 1: (old) => ({ ...(old as { cursor: string }), failures: 0 }) },
|
|
23
|
+
store: new InMemoryDurableStateStore(), // use SqliteDurableStateStore / PostgresDurableStateStore to persist
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const runner: FlowRunner<unknown, { cursor: string }> = async (ctx) => {
|
|
27
|
+
const loaded = await watcher.load(ctx, "tenant-1"); // { found, value, revision, migrated, ... }
|
|
28
|
+
const next = { cursor: "next-page", failures: loaded.value?.failures ?? 0 };
|
|
29
|
+
await watcher.save(ctx, "tenant-1", next, loaded.revision); // revision 0 means "create"
|
|
30
|
+
return { cursor: next.cursor };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const io = z.object({}).passthrough();
|
|
34
|
+
const flow: RegisteredFlow = {
|
|
35
|
+
definition: flow$({ id: "watch", name: "Watch", version: "1.0.0", inputSchema: io, outputSchema: z.any(), steps: [] }),
|
|
36
|
+
runner: runner as FlowRunner<unknown, unknown>,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const app = defineConfig({
|
|
40
|
+
storage: { kind: "memory" },
|
|
41
|
+
flows: [flow],
|
|
42
|
+
execution: { registerEffects: (effects) => watcher.register(effects) },
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Surface
|
|
47
|
+
|
|
48
|
+
- **`durableState(config)`** returns a handle with `load(ctx, key)`, `save(ctx, key, value, expectedRevision)`,
|
|
49
|
+
`clear(ctx, key)`, `register(effects)`, and the underlying `tasks`, `effects` and `toolIds`
|
|
50
|
+
(`<id>.load`, `<id>.save`, `<id>.clear`). Register the effects at the composition root before a flow
|
|
51
|
+
calls them. Pass `{ stepId }` for a second load or save of the same handle in one run.
|
|
52
|
+
- **`sentinelState(config)`** derives the key `sentinel:<scheduleId>` from a `schedule$` definition and
|
|
53
|
+
exposes `load(ctx)`, `save(ctx, value, expectedRevision)` and `clear(ctx)` without the key argument.
|
|
54
|
+
- **Stores.** `DurableStateStore` is the SPI: `load`, `save` with an expected revision, `clear`.
|
|
55
|
+
`InMemoryDurableStateStore` is here; durable ones are `SqliteDurableStateStore`
|
|
56
|
+
(`@loomwork/plugin-sqlite`) and `PostgresDurableStateStore` (`@loomwork/plugin-postgres`).
|
|
57
|
+
- **Errors.** `RevisionConflictError` and `StateContractMismatchError` (reasons: `no-migration-path`,
|
|
58
|
+
`migration-failed`, `future-version`, `validation-failed`).
|
|
59
|
+
|
|
60
|
+
## Behaviour that surprises people
|
|
61
|
+
|
|
62
|
+
- **A bad contract fails loudly.** A missing migration step, a migration that throws, a stored version
|
|
63
|
+
newer than yours, or a payload that fails the current schema all throw `StateContractMismatchError`;
|
|
64
|
+
state is never coerced. A `save` also validates against the schema before writing.
|
|
65
|
+
- **Migrating on load does not rewrite the stored value.** `load` reports `migrated: { from, to }`; the
|
|
66
|
+
stored envelope changes on your next `save`.
|
|
67
|
+
- **Conflicts are not retried for you.** A stale `expectedRevision` throws `RevisionConflictError`.
|
|
68
|
+
The exception is a crash-recovery re-run of a `save` that already committed, which is adopted when
|
|
69
|
+
the stored envelope equals what it tried to write.
|
|
70
|
+
- **This is not `memory$`.** It is journaled step output, so a read during replay returns what the
|
|
71
|
+
original run saw, even if the store has changed since.
|
|
72
|
+
|
|
73
|
+
## Status / See also
|
|
74
|
+
|
|
75
|
+
Unpublished for now: inside this repo use `workspace:*`; from a sibling checkout use a `link:` override
|
|
76
|
+
(see [AGENTS.md](../../AGENTS.md)).
|
|
77
|
+
|
|
78
|
+
- [ADR 0053](../../docs/adr/0053-durable-state-plugin.md) and
|
|
79
|
+
[ADR 0051](../../docs/adr/0051-perpetual-agents-placement-schedule-remodel.md): the design.
|
|
80
|
+
- `@loomwork/plugin-sentinel` bundles this with a schedule and claim-checked telemetry.
|
|
81
|
+
- API reference: section "`@loomwork/plugin-durable-state` — carry state across wakes" in
|
|
82
|
+
[docs/api-reference.org](../../docs/api-reference.org).
|
|
83
|
+
- Guides: [docs/plugins.md](../../docs/plugins.md), [docs/user-guide.md](../../docs/user-guide.md).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DurableStateRecord, DurableStateStore } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Reference in-memory backend — the conformance baseline, and the test/dev
|
|
4
|
+
* default. Deep-clones on both write and read so callers can never alias the
|
|
5
|
+
* stored record (matching the value semantics of the durable backends, where
|
|
6
|
+
* a JSON round-trip breaks aliasing anyway).
|
|
7
|
+
*/
|
|
8
|
+
export declare class InMemoryDurableStateStore implements DurableStateStore {
|
|
9
|
+
private readonly records;
|
|
10
|
+
load(key: string): Promise<DurableStateRecord | null>;
|
|
11
|
+
save(key: string, value: {
|
|
12
|
+
contractVersion: number;
|
|
13
|
+
payload: unknown;
|
|
14
|
+
}, expectedRevision: number): Promise<DurableStateRecord>;
|
|
15
|
+
clear(key: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=InMemoryDurableStateStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryDurableStateStore.d.ts","sourceRoot":"","sources":["../src/InMemoryDurableStateStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAErE;;;;;GAKG;AACH,qBAAa,yBAA0B,YAAW,iBAAiB;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IAE3D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAKrD,IAAI,CACR,GAAG,EAAE,MAAM,EACX,KAAK,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,EACpD,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,kBAAkB,CAAC;IAcxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryDurableStateStore = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
/**
|
|
6
|
+
* Reference in-memory backend — the conformance baseline, and the test/dev
|
|
7
|
+
* default. Deep-clones on both write and read so callers can never alias the
|
|
8
|
+
* stored record (matching the value semantics of the durable backends, where
|
|
9
|
+
* a JSON round-trip breaks aliasing anyway).
|
|
10
|
+
*/
|
|
11
|
+
class InMemoryDurableStateStore {
|
|
12
|
+
records = new Map();
|
|
13
|
+
async load(key) {
|
|
14
|
+
const record = this.records.get(key);
|
|
15
|
+
return record === undefined ? null : structuredClone(record);
|
|
16
|
+
}
|
|
17
|
+
async save(key, value, expectedRevision) {
|
|
18
|
+
const actual = this.records.get(key)?.revision ?? 0;
|
|
19
|
+
if (expectedRevision !== actual) {
|
|
20
|
+
throw new errors_1.RevisionConflictError(key, expectedRevision, actual);
|
|
21
|
+
}
|
|
22
|
+
const record = {
|
|
23
|
+
contractVersion: value.contractVersion,
|
|
24
|
+
revision: actual + 1,
|
|
25
|
+
payload: structuredClone(value.payload),
|
|
26
|
+
};
|
|
27
|
+
this.records.set(key, record);
|
|
28
|
+
return structuredClone(record);
|
|
29
|
+
}
|
|
30
|
+
async clear(key) {
|
|
31
|
+
this.records.delete(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.InMemoryDurableStateStore = InMemoryDurableStateStore;
|
|
35
|
+
//# sourceMappingURL=InMemoryDurableStateStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryDurableStateStore.js","sourceRoot":"","sources":["../src/InMemoryDurableStateStore.ts"],"names":[],"mappings":";;;AAAA,qCAAiD;AAGjD;;;;;GAKG;AACH,MAAa,yBAAyB;IACnB,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEjE,KAAK,CAAC,IAAI,CAAC,GAAW;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,IAAI,CACR,GAAW,EACX,KAAoD,EACpD,gBAAwB;QAExB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,IAAI,CAAC,CAAC;QACpD,IAAI,gBAAgB,KAAK,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,8BAAqB,CAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,MAAM,GAAuB;YACjC,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,QAAQ,EAAE,MAAM,GAAG,CAAC;YACpB,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC;SACxC,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC9B,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW;QACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AA7BD,8DA6BC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON serialization: object keys sorted, `undefined` properties
|
|
3
|
+
* skipped (JSON semantics). Used for the save effect's adopt-own-write check —
|
|
4
|
+
* value equality must not depend on property insertion order.
|
|
5
|
+
*/
|
|
6
|
+
export declare function stableStringify(value: unknown, depth?: number): string;
|
|
7
|
+
export declare function canonicalEqual(a: unknown, b: unknown): boolean;
|
|
8
|
+
//# sourceMappingURL=canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,MAAM,CAgBjE;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAE9D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stableStringify = stableStringify;
|
|
4
|
+
exports.canonicalEqual = canonicalEqual;
|
|
5
|
+
/**
|
|
6
|
+
* Depth cap for canonicalization. JSON nesting beyond this is pathological
|
|
7
|
+
* (and could stack-overflow the save path — audit W8); exceeding it throws a
|
|
8
|
+
* loud RangeError rather than crashing the process.
|
|
9
|
+
*/
|
|
10
|
+
const MAX_DEPTH = 256;
|
|
11
|
+
/**
|
|
12
|
+
* Canonical JSON serialization: object keys sorted, `undefined` properties
|
|
13
|
+
* skipped (JSON semantics). Used for the save effect's adopt-own-write check —
|
|
14
|
+
* value equality must not depend on property insertion order.
|
|
15
|
+
*/
|
|
16
|
+
function stableStringify(value, depth = 0) {
|
|
17
|
+
if (value === null || typeof value !== "object") {
|
|
18
|
+
return JSON.stringify(value) ?? "null";
|
|
19
|
+
}
|
|
20
|
+
if (depth >= MAX_DEPTH) {
|
|
21
|
+
throw new RangeError(`stableStringify: value nests deeper than ${MAX_DEPTH} levels`);
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return `[${value.map((item) => stableStringify(item, depth + 1)).join(",")}]`;
|
|
25
|
+
}
|
|
26
|
+
const entries = Object.keys(value)
|
|
27
|
+
.sort()
|
|
28
|
+
.map((key) => [key, value[key]])
|
|
29
|
+
.filter(([, v]) => v !== undefined)
|
|
30
|
+
.map(([key, v]) => `${JSON.stringify(key)}:${stableStringify(v, depth + 1)}`);
|
|
31
|
+
return `{${entries.join(",")}}`;
|
|
32
|
+
}
|
|
33
|
+
function canonicalEqual(a, b) {
|
|
34
|
+
return stableStringify(a) === stableStringify(b);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mapp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,CAAU;IACnD,OAAO,eAAe,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DurableStateConfig, DurableStateHandle } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* ADR 0051 D2 — typed, versioned, migratable keyed state as RECORDED effects.
|
|
4
|
+
* `load`/`save` run through `ctx.execute`, so results land in STEP_COMPLETED:
|
|
5
|
+
* replay folds the recorded value and never touches the backing store —
|
|
6
|
+
* replay-correct by construction (DS-1). This is deliberately NOT `memory$`,
|
|
7
|
+
* which is a non-replayable agent-layer side channel.
|
|
8
|
+
*/
|
|
9
|
+
export declare function durableState<T>(config: DurableStateConfig<T>): DurableStateHandle<T>;
|
|
10
|
+
//# sourceMappingURL=durableState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durableState.d.ts","sourceRoot":"","sources":["../src/durableState.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EAQnB,MAAM,SAAS,CAAC;AAsEjB;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CA0LpF"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.durableState = durableState;
|
|
4
|
+
const effect_runtime_1 = require("@loomwork/effect-runtime");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const canonical_1 = require("./canonical");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
/**
|
|
9
|
+
* DS-3 — bring a stored envelope to the current contract: apply the
|
|
10
|
+
* version-to-version migration chain, then validate against the current
|
|
11
|
+
* schema. Every failure mode is a loud, typed {@link StateContractMismatchError}
|
|
12
|
+
* (DS-2: a run never proceeds on unvalidated state).
|
|
13
|
+
*/
|
|
14
|
+
function migrateRecord(config, key, record) {
|
|
15
|
+
const from = record.contractVersion;
|
|
16
|
+
if (from > config.version) {
|
|
17
|
+
throw new errors_1.StateContractMismatchError(config.id, "future-version", from, config.version, `key "${key}" was written by a newer deployment`);
|
|
18
|
+
}
|
|
19
|
+
let payload = record.payload;
|
|
20
|
+
for (let v = from; v < config.version; v++) {
|
|
21
|
+
const step = config.migrations?.[v];
|
|
22
|
+
if (step === undefined) {
|
|
23
|
+
throw new errors_1.StateContractMismatchError(config.id, "no-migration-path", from, config.version, `key "${key}": no migration registered for v${v} → v${v + 1}`);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
payload = step(payload);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new errors_1.StateContractMismatchError(config.id, "migration-failed", from, config.version, `key "${key}": migration v${v} → v${v + 1} threw: ${String(err)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const parsed = config.schema.safeParse(payload);
|
|
33
|
+
if (!parsed.success) {
|
|
34
|
+
throw new errors_1.StateContractMismatchError(config.id, "validation-failed", from, config.version, `key "${key}": ${parsed.error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`).join("; ")}`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
value: parsed.data,
|
|
38
|
+
migrated: from < config.version ? { from, to: config.version } : null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function isRevisionConflict(err) {
|
|
42
|
+
return (err instanceof errors_1.RevisionConflictError ||
|
|
43
|
+
(typeof err === "object" && err !== null && err.name === "RevisionConflictError"));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* ADR 0051 D2 — typed, versioned, migratable keyed state as RECORDED effects.
|
|
47
|
+
* `load`/`save` run through `ctx.execute`, so results land in STEP_COMPLETED:
|
|
48
|
+
* replay folds the recorded value and never touches the backing store —
|
|
49
|
+
* replay-correct by construction (DS-1). This is deliberately NOT `memory$`,
|
|
50
|
+
* which is a non-replayable agent-layer side channel.
|
|
51
|
+
*/
|
|
52
|
+
function durableState(config) {
|
|
53
|
+
if (config.id.length === 0) {
|
|
54
|
+
throw new TypeError("durableState: config.id must be a non-empty string");
|
|
55
|
+
}
|
|
56
|
+
if (!Number.isInteger(config.version) || config.version < 1) {
|
|
57
|
+
throw new TypeError(`durableState "${config.id}": version must be an integer ≥ 1`);
|
|
58
|
+
}
|
|
59
|
+
const toolIds = {
|
|
60
|
+
load: `${config.id}.load`,
|
|
61
|
+
save: `${config.id}.save`,
|
|
62
|
+
clear: `${config.id}.clear`,
|
|
63
|
+
};
|
|
64
|
+
const loadOutputSchema = zod_1.z.object({
|
|
65
|
+
found: zod_1.z.boolean(),
|
|
66
|
+
value: config.schema.nullable(),
|
|
67
|
+
revision: zod_1.z.number().int().nonnegative(),
|
|
68
|
+
contractVersion: zod_1.z.number().int().positive(),
|
|
69
|
+
migrated: zod_1.z
|
|
70
|
+
.object({ from: zod_1.z.number().int().positive(), to: zod_1.z.number().int().positive() })
|
|
71
|
+
.nullable(),
|
|
72
|
+
});
|
|
73
|
+
const tasks = {
|
|
74
|
+
load: {
|
|
75
|
+
_tag: "TaskDefinition",
|
|
76
|
+
kind: "memory",
|
|
77
|
+
id: toolIds.load,
|
|
78
|
+
toolId: toolIds.load,
|
|
79
|
+
name: `${config.id} load`,
|
|
80
|
+
inputSchema: zod_1.z.object({ key: zod_1.z.string() }),
|
|
81
|
+
outputSchema: loadOutputSchema,
|
|
82
|
+
},
|
|
83
|
+
save: {
|
|
84
|
+
_tag: "TaskDefinition",
|
|
85
|
+
kind: "memory",
|
|
86
|
+
id: toolIds.save,
|
|
87
|
+
toolId: toolIds.save,
|
|
88
|
+
name: `${config.id} save`,
|
|
89
|
+
outputSchema: zod_1.z.object({ revision: zod_1.z.number().int().positive() }),
|
|
90
|
+
},
|
|
91
|
+
clear: {
|
|
92
|
+
_tag: "TaskDefinition",
|
|
93
|
+
kind: "memory",
|
|
94
|
+
id: toolIds.clear,
|
|
95
|
+
toolId: toolIds.clear,
|
|
96
|
+
name: `${config.id} clear`,
|
|
97
|
+
outputSchema: zod_1.z.object({ cleared: zod_1.z.literal(true) }),
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const loadEffect = new effect_runtime_1.ToolEffect(async ({ key }) => {
|
|
101
|
+
const record = await config.store.load(key);
|
|
102
|
+
if (record === null) {
|
|
103
|
+
return {
|
|
104
|
+
found: false,
|
|
105
|
+
value: null,
|
|
106
|
+
revision: 0,
|
|
107
|
+
contractVersion: config.version,
|
|
108
|
+
migrated: null,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const { value, migrated } = migrateRecord(config, key, record);
|
|
112
|
+
return {
|
|
113
|
+
found: true,
|
|
114
|
+
value,
|
|
115
|
+
revision: record.revision,
|
|
116
|
+
contractVersion: config.version,
|
|
117
|
+
migrated,
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
// ADR 0073 — deliberately NO `mode`. `load` is genuinely dual-seam: journaled
|
|
121
|
+
// inside a flow (where the recorded value is what replay folds), and a
|
|
122
|
+
// perfectly reasonable ambient read outside one — an operator dashboard
|
|
123
|
+
// peeking at a sentinel's carry state changes nothing and should not have to
|
|
124
|
+
// start an execution to look. Pinning it to either seam would forbid a
|
|
125
|
+
// legitimate caller, which is why the marker is opt-in rather than required.
|
|
126
|
+
{ idempotent: true });
|
|
127
|
+
// K9 — declared idempotent: the CAS makes a crash-recovery re-run safe. If the
|
|
128
|
+
// prior attempt committed, the re-run's expectedRevision now trails by exactly
|
|
129
|
+
// one; when the stored envelope is byte-equal to what we tried to write, adopt
|
|
130
|
+
// it as our own committed write. A genuinely concurrent writer either lands at
|
|
131
|
+
// a different revision or a different payload — both still conflict loudly.
|
|
132
|
+
const saveEffect = new effect_runtime_1.ToolEffect(async ({ key, value, expectedRevision }) => {
|
|
133
|
+
const parsed = config.schema.safeParse(value);
|
|
134
|
+
if (!parsed.success) {
|
|
135
|
+
throw new errors_1.StateContractMismatchError(config.id, "validation-failed", config.version, config.version, `key "${key}" (save): ${parsed.error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`).join("; ")}`);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const record = await config.store.save(key, { contractVersion: config.version, payload: parsed.data }, expectedRevision);
|
|
139
|
+
return { revision: record.revision };
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
if (isRevisionConflict(err) && err.actualRevision === expectedRevision + 1) {
|
|
143
|
+
const current = await config.store.load(key);
|
|
144
|
+
if (current !== null &&
|
|
145
|
+
current.revision === expectedRevision + 1 &&
|
|
146
|
+
current.contractVersion === config.version &&
|
|
147
|
+
(0, canonical_1.canonicalEqual)(current.payload, parsed.data)) {
|
|
148
|
+
return { revision: current.revision };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
idempotent: true,
|
|
155
|
+
// ADR 0073 — a mutation that MUST be recorded. The whole contract of this
|
|
156
|
+
// plugin is "RECORDED effects: replay folds the recorded value, never the
|
|
157
|
+
// store" (ADR 0053). A transient write would mutate the store while the log
|
|
158
|
+
// learns nothing, so replay would fold a state the run never produced —
|
|
159
|
+
// exactly the split-brain the recorded-effect design exists to prevent.
|
|
160
|
+
mode: "journaled",
|
|
161
|
+
});
|
|
162
|
+
const clearEffect = new effect_runtime_1.ToolEffect(async ({ key }) => {
|
|
163
|
+
await config.store.clear(key);
|
|
164
|
+
return { cleared: true };
|
|
165
|
+
}, {
|
|
166
|
+
idempotent: true,
|
|
167
|
+
// ADR 0073 — a mutation that MUST be recorded. The whole contract of this
|
|
168
|
+
// plugin is "RECORDED effects: replay folds the recorded value, never the
|
|
169
|
+
// store" (ADR 0053). A transient write would mutate the store while the log
|
|
170
|
+
// learns nothing, so replay would fold a state the run never produced —
|
|
171
|
+
// exactly the split-brain the recorded-effect design exists to prevent.
|
|
172
|
+
mode: "journaled",
|
|
173
|
+
});
|
|
174
|
+
const effects = {
|
|
175
|
+
load: loadEffect,
|
|
176
|
+
save: saveEffect,
|
|
177
|
+
clear: clearEffect,
|
|
178
|
+
};
|
|
179
|
+
const taskWith = (task, stepId) => (stepId === undefined ? task : { ...task, id: stepId });
|
|
180
|
+
return {
|
|
181
|
+
id: config.id,
|
|
182
|
+
version: config.version,
|
|
183
|
+
toolIds,
|
|
184
|
+
tasks,
|
|
185
|
+
effects,
|
|
186
|
+
register(runtime) {
|
|
187
|
+
runtime.register(toolIds.load, loadEffect);
|
|
188
|
+
runtime.register(toolIds.save, saveEffect);
|
|
189
|
+
runtime.register(toolIds.clear, clearEffect);
|
|
190
|
+
},
|
|
191
|
+
load(ctx, key, opts) {
|
|
192
|
+
return ctx.execute(taskWith(tasks.load, opts?.stepId), { key });
|
|
193
|
+
},
|
|
194
|
+
save(ctx, key, value, expectedRevision, opts) {
|
|
195
|
+
return ctx.execute(taskWith(tasks.save, opts?.stepId), { key, value, expectedRevision });
|
|
196
|
+
},
|
|
197
|
+
clear(ctx, key, opts) {
|
|
198
|
+
return ctx.execute(taskWith(tasks.clear, opts?.stepId), { key });
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=durableState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durableState.js","sourceRoot":"","sources":["../src/durableState.ts"],"names":[],"mappings":";;AA8FA,oCA0LC;AAvRD,6DAAsD;AACtD,6BAAwB;AACxB,2CAA6C;AAC7C,qCAA6E;AAe7E;;;;;GAKG;AACH,SAAS,aAAa,CACpB,MAA6B,EAC7B,GAAW,EACX,MAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,CAAC,eAAe,CAAC;IACpC,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,mCAA0B,CAClC,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