@rivetkit/workflow-engine 0.0.0-0-0-0-preview-guard-stops.9d82529

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.
@@ -0,0 +1,212 @@
1
+ # Workflow Engine BARE Schema v1
2
+ #
3
+ # This schema defines the binary encoding for workflow engine persistence.
4
+ # Types marked with `data` are arbitrary binary blobs (for user-provided data).
5
+
6
+ # Opaque user data (CBOR-encoded)
7
+ type Cbor data
8
+
9
+ # MARK: Location
10
+ # Index into the entry name registry
11
+ type NameIndex u32
12
+
13
+ # Marker for a loop iteration in a location path
14
+ type LoopIterationMarker struct {
15
+ loop: NameIndex
16
+ iteration: u32
17
+ }
18
+
19
+ # A segment in a location path - either a name index or a loop iteration marker
20
+ type PathSegment union {
21
+ NameIndex |
22
+ LoopIterationMarker
23
+ }
24
+
25
+ # Location identifies where an entry exists in the workflow execution tree
26
+ type Location list<PathSegment>
27
+
28
+ # MARK: Entry Status
29
+ type EntryStatus enum {
30
+ PENDING
31
+ RUNNING
32
+ COMPLETED
33
+ FAILED
34
+ EXHAUSTED
35
+ }
36
+
37
+ # MARK: Sleep State
38
+ type SleepState enum {
39
+ PENDING
40
+ COMPLETED
41
+ INTERRUPTED
42
+ }
43
+
44
+ # MARK: Branch Status
45
+ type BranchStatusType enum {
46
+ PENDING
47
+ RUNNING
48
+ COMPLETED
49
+ FAILED
50
+ CANCELLED
51
+ }
52
+
53
+ # MARK: Step Entry
54
+ type StepEntry struct {
55
+ # Output value (CBOR-encoded arbitrary data)
56
+ output: optional<Cbor>
57
+ # Error message if step failed
58
+ error: optional<str>
59
+ }
60
+
61
+ # MARK: Loop Entry
62
+ type LoopEntry struct {
63
+ # Loop state (CBOR-encoded arbitrary data)
64
+ state: Cbor
65
+ # Current iteration number
66
+ iteration: u32
67
+ # Output value if loop completed (CBOR-encoded arbitrary data)
68
+ output: optional<Cbor>
69
+ }
70
+
71
+ # MARK: Sleep Entry
72
+ type SleepEntry struct {
73
+ # Deadline timestamp in milliseconds
74
+ deadline: u64
75
+ # Current sleep state
76
+ state: SleepState
77
+ }
78
+
79
+ # MARK: Message Entry
80
+ type MessageEntry struct {
81
+ # Message name
82
+ name: str
83
+ # Message data (CBOR-encoded arbitrary data)
84
+ messageData: Cbor
85
+ }
86
+
87
+ # MARK: Rollback Checkpoint Entry
88
+ type RollbackCheckpointEntry struct {
89
+ # Checkpoint name
90
+ name: str
91
+ }
92
+
93
+ # MARK: Branch Status
94
+
95
+ type BranchStatus struct {
96
+ status: BranchStatusType
97
+ # Output value if completed (CBOR-encoded arbitrary data)
98
+ output: optional<Cbor>
99
+ # Error message if failed
100
+ error: optional<str>
101
+ }
102
+
103
+ # MARK: Join Entry
104
+ type JoinEntry struct {
105
+ # Map of branch name to status
106
+ branches: map<str><BranchStatus>
107
+ }
108
+
109
+ # MARK: Race Entry
110
+ type RaceEntry struct {
111
+ # Name of the winning branch, or null if no winner yet
112
+ winner: optional<str>
113
+ # Map of branch name to status
114
+ branches: map<str><BranchStatus>
115
+ }
116
+
117
+ # MARK: Removed Entry
118
+ type RemovedEntry struct {
119
+ # Original entry type before removal
120
+ originalType: str
121
+ # Original entry name
122
+ originalName: optional<str>
123
+ }
124
+
125
+ # MARK: Version Check Entry
126
+ type VersionCheckEntry struct {
127
+ # The version this instance resolved to at this location
128
+ resolved: u32
129
+ # The `latest` value seen when first resolved (diagnostics)
130
+ latest: u32
131
+ }
132
+
133
+ # MARK: Entry Kind
134
+ # Type-specific entry data
135
+ type EntryKind union {
136
+ StepEntry |
137
+ LoopEntry |
138
+ SleepEntry |
139
+ MessageEntry |
140
+ RollbackCheckpointEntry |
141
+ JoinEntry |
142
+ RaceEntry |
143
+ RemovedEntry |
144
+ VersionCheckEntry
145
+ }
146
+
147
+ # MARK: Entry
148
+ # An entry in the workflow history
149
+ type Entry struct {
150
+ # Unique entry ID
151
+ id: str
152
+ # Location in the workflow tree
153
+ location: Location
154
+ # Entry kind and data
155
+ kind: EntryKind
156
+ }
157
+
158
+ # MARK: Entry Metadata
159
+ # Metadata for an entry (stored separately, lazily loaded)
160
+ type EntryMetadata struct {
161
+ status: EntryStatus
162
+ # Error message if failed
163
+ error: optional<str>
164
+ # Number of execution attempts
165
+ attempts: u32
166
+ # Last attempt timestamp in milliseconds
167
+ lastAttemptAt: u64
168
+ # Creation timestamp in milliseconds
169
+ createdAt: u64
170
+ # Completion timestamp in milliseconds
171
+ completedAt: optional<u64>
172
+ # Rollback completion timestamp in milliseconds
173
+ rollbackCompletedAt: optional<u64>
174
+ # Rollback error message if failed
175
+ rollbackError: optional<str>
176
+ }
177
+
178
+ # MARK: Message
179
+ # A message in the queue
180
+ type Message struct {
181
+ # Unique message ID (used as KV key)
182
+ id: str
183
+ # Message name
184
+ name: str
185
+ # Message data (CBOR-encoded arbitrary data)
186
+ messageData: Cbor
187
+ # Timestamp when message was sent in milliseconds
188
+ sentAt: u64
189
+ }
190
+
191
+ # MARK: Workflow State
192
+ type WorkflowState enum {
193
+ PENDING
194
+ RUNNING
195
+ SLEEPING
196
+ FAILED
197
+ COMPLETED
198
+ ROLLING_BACK
199
+ }
200
+
201
+ # MARK: Workflow Metadata
202
+ # Workflow-level metadata stored separately from entries
203
+ type WorkflowMetadata struct {
204
+ # Current workflow state
205
+ state: WorkflowState
206
+ # Workflow output if completed (CBOR-encoded arbitrary data)
207
+ output: optional<Cbor>
208
+ # Error message if failed
209
+ error: optional<str>
210
+ # Workflow version hash for migration detection
211
+ version: optional<str>
212
+ }
@@ -0,0 +1,108 @@
1
+ import { createVersionedDataHandler } from "vbare";
2
+ import * as v1 from "../dist/schemas/v1.js";
3
+
4
+ export const CURRENT_VERSION = 1;
5
+
6
+ // Re-export generated types for convenience
7
+ export type {
8
+ BranchStatus,
9
+ Entry,
10
+ EntryKind,
11
+ EntryMetadata,
12
+ JoinEntry,
13
+ Location,
14
+ LoopEntry,
15
+ LoopIterationMarker,
16
+ MessageEntry,
17
+ PathSegment,
18
+ RaceEntry,
19
+ RemovedEntry,
20
+ SleepEntry,
21
+ StepEntry,
22
+ VersionCheckEntry,
23
+ WorkflowMetadata,
24
+ } from "../dist/schemas/v1.js";
25
+
26
+ export {
27
+ BranchStatusType,
28
+ EntryStatus,
29
+ SleepState,
30
+ WorkflowState,
31
+ } from "../dist/schemas/v1.js";
32
+
33
+ // === Entry Handler ===
34
+
35
+ export const ENTRY_VERSIONED = createVersionedDataHandler<v1.Entry>({
36
+ deserializeVersion: (bytes, version) => {
37
+ switch (version) {
38
+ case 1:
39
+ return v1.decodeEntry(bytes);
40
+ default:
41
+ throw new Error(`Unknown Entry version ${version}`);
42
+ }
43
+ },
44
+ serializeVersion: (data, version) => {
45
+ switch (version) {
46
+ case 1:
47
+ return v1.encodeEntry(data as v1.Entry);
48
+ default:
49
+ throw new Error(`Unknown Entry version ${version}`);
50
+ }
51
+ },
52
+ deserializeConverters: () => [],
53
+ serializeConverters: () => [],
54
+ });
55
+
56
+ // === Entry Metadata Handler ===
57
+
58
+ export const ENTRY_METADATA_VERSIONED =
59
+ createVersionedDataHandler<v1.EntryMetadata>({
60
+ deserializeVersion: (bytes, version) => {
61
+ switch (version) {
62
+ case 1:
63
+ return v1.decodeEntryMetadata(bytes);
64
+ default:
65
+ throw new Error(`Unknown EntryMetadata version ${version}`);
66
+ }
67
+ },
68
+ serializeVersion: (data, version) => {
69
+ switch (version) {
70
+ case 1:
71
+ return v1.encodeEntryMetadata(data as v1.EntryMetadata);
72
+ default:
73
+ throw new Error(`Unknown EntryMetadata version ${version}`);
74
+ }
75
+ },
76
+ deserializeConverters: () => [],
77
+ serializeConverters: () => [],
78
+ });
79
+
80
+ // === Workflow Metadata Handler ===
81
+
82
+ export const WORKFLOW_METADATA_VERSIONED =
83
+ createVersionedDataHandler<v1.WorkflowMetadata>({
84
+ deserializeVersion: (bytes, version) => {
85
+ switch (version) {
86
+ case 1:
87
+ return v1.decodeWorkflowMetadata(bytes);
88
+ default:
89
+ throw new Error(
90
+ `Unknown WorkflowMetadata version ${version}`,
91
+ );
92
+ }
93
+ },
94
+ serializeVersion: (data, version) => {
95
+ switch (version) {
96
+ case 1:
97
+ return v1.encodeWorkflowMetadata(
98
+ data as v1.WorkflowMetadata,
99
+ );
100
+ default:
101
+ throw new Error(
102
+ `Unknown WorkflowMetadata version ${version}`,
103
+ );
104
+ }
105
+ },
106
+ deserializeConverters: () => [],
107
+ serializeConverters: () => [],
108
+ });