@rivetkit/workflow-engine 2.1.0-rc.1

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,203 @@
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: Entry Kind
126
+ # Type-specific entry data
127
+ type EntryKind union {
128
+ StepEntry |
129
+ LoopEntry |
130
+ SleepEntry |
131
+ MessageEntry |
132
+ RollbackCheckpointEntry |
133
+ JoinEntry |
134
+ RaceEntry |
135
+ RemovedEntry
136
+ }
137
+
138
+ # MARK: Entry
139
+ # An entry in the workflow history
140
+ type Entry struct {
141
+ # Unique entry ID
142
+ id: str
143
+ # Location in the workflow tree
144
+ location: Location
145
+ # Entry kind and data
146
+ kind: EntryKind
147
+ }
148
+
149
+ # MARK: Entry Metadata
150
+ # Metadata for an entry (stored separately, lazily loaded)
151
+ type EntryMetadata struct {
152
+ status: EntryStatus
153
+ # Error message if failed
154
+ error: optional<str>
155
+ # Number of execution attempts
156
+ attempts: u32
157
+ # Last attempt timestamp in milliseconds
158
+ lastAttemptAt: u64
159
+ # Creation timestamp in milliseconds
160
+ createdAt: u64
161
+ # Completion timestamp in milliseconds
162
+ completedAt: optional<u64>
163
+ # Rollback completion timestamp in milliseconds
164
+ rollbackCompletedAt: optional<u64>
165
+ # Rollback error message if failed
166
+ rollbackError: optional<str>
167
+ }
168
+
169
+ # MARK: Message
170
+ # A message in the queue
171
+ type Message struct {
172
+ # Unique message ID (used as KV key)
173
+ id: str
174
+ # Message name
175
+ name: str
176
+ # Message data (CBOR-encoded arbitrary data)
177
+ messageData: Cbor
178
+ # Timestamp when message was sent in milliseconds
179
+ sentAt: u64
180
+ }
181
+
182
+ # MARK: Workflow State
183
+ type WorkflowState enum {
184
+ PENDING
185
+ RUNNING
186
+ SLEEPING
187
+ FAILED
188
+ COMPLETED
189
+ ROLLING_BACK
190
+ }
191
+
192
+ # MARK: Workflow Metadata
193
+ # Workflow-level metadata stored separately from entries
194
+ type WorkflowMetadata struct {
195
+ # Current workflow state
196
+ state: WorkflowState
197
+ # Workflow output if completed (CBOR-encoded arbitrary data)
198
+ output: optional<Cbor>
199
+ # Error message if failed
200
+ error: optional<str>
201
+ # Workflow version hash for migration detection
202
+ version: optional<str>
203
+ }
@@ -0,0 +1,107 @@
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
+ WorkflowMetadata,
23
+ } from "../dist/schemas/v1.js";
24
+
25
+ export {
26
+ BranchStatusType,
27
+ EntryStatus,
28
+ SleepState,
29
+ WorkflowState,
30
+ } from "../dist/schemas/v1.js";
31
+
32
+ // === Entry Handler ===
33
+
34
+ export const ENTRY_VERSIONED = createVersionedDataHandler<v1.Entry>({
35
+ deserializeVersion: (bytes, version) => {
36
+ switch (version) {
37
+ case 1:
38
+ return v1.decodeEntry(bytes);
39
+ default:
40
+ throw new Error(`Unknown Entry version ${version}`);
41
+ }
42
+ },
43
+ serializeVersion: (data, version) => {
44
+ switch (version) {
45
+ case 1:
46
+ return v1.encodeEntry(data as v1.Entry);
47
+ default:
48
+ throw new Error(`Unknown Entry version ${version}`);
49
+ }
50
+ },
51
+ deserializeConverters: () => [],
52
+ serializeConverters: () => [],
53
+ });
54
+
55
+ // === Entry Metadata Handler ===
56
+
57
+ export const ENTRY_METADATA_VERSIONED =
58
+ createVersionedDataHandler<v1.EntryMetadata>({
59
+ deserializeVersion: (bytes, version) => {
60
+ switch (version) {
61
+ case 1:
62
+ return v1.decodeEntryMetadata(bytes);
63
+ default:
64
+ throw new Error(`Unknown EntryMetadata version ${version}`);
65
+ }
66
+ },
67
+ serializeVersion: (data, version) => {
68
+ switch (version) {
69
+ case 1:
70
+ return v1.encodeEntryMetadata(data as v1.EntryMetadata);
71
+ default:
72
+ throw new Error(`Unknown EntryMetadata version ${version}`);
73
+ }
74
+ },
75
+ deserializeConverters: () => [],
76
+ serializeConverters: () => [],
77
+ });
78
+
79
+ // === Workflow Metadata Handler ===
80
+
81
+ export const WORKFLOW_METADATA_VERSIONED =
82
+ createVersionedDataHandler<v1.WorkflowMetadata>({
83
+ deserializeVersion: (bytes, version) => {
84
+ switch (version) {
85
+ case 1:
86
+ return v1.decodeWorkflowMetadata(bytes);
87
+ default:
88
+ throw new Error(
89
+ `Unknown WorkflowMetadata version ${version}`,
90
+ );
91
+ }
92
+ },
93
+ serializeVersion: (data, version) => {
94
+ switch (version) {
95
+ case 1:
96
+ return v1.encodeWorkflowMetadata(
97
+ data as v1.WorkflowMetadata,
98
+ );
99
+ default:
100
+ throw new Error(
101
+ `Unknown WorkflowMetadata version ${version}`,
102
+ );
103
+ }
104
+ },
105
+ deserializeConverters: () => [],
106
+ serializeConverters: () => [],
107
+ });