durable_workflow 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.
- checksums.yaml +7 -0
- data/.claude/todo/01.amend.md +133 -0
- data/.claude/todo/02.amend.md +444 -0
- data/.claude/todo/phase-1-core/01-GEMSPEC.md +193 -0
- data/.claude/todo/phase-1-core/02-TYPES.md +462 -0
- data/.claude/todo/phase-1-core/03-EXECUTION.md +551 -0
- data/.claude/todo/phase-1-core/04-STEPS.md +603 -0
- data/.claude/todo/phase-1-core/05-PARSER.md +719 -0
- data/.claude/todo/phase-1-core/todo.md +574 -0
- data/.claude/todo/phase-2-runtime/01-STORAGE.md +641 -0
- data/.claude/todo/phase-2-runtime/02-RUNNERS.md +511 -0
- data/.claude/todo/phase-3-extensions/01-EXTENSION-SYSTEM.md +298 -0
- data/.claude/todo/phase-3-extensions/02-AI-PLUGIN.md +936 -0
- data/.claude/todo/phase-3-extensions/todo.md +262 -0
- data/.claude/todo/phase-4-ai-rework/01-DEPENDENCIES.md +107 -0
- data/.claude/todo/phase-4-ai-rework/02-CONFIGURATION.md +123 -0
- data/.claude/todo/phase-4-ai-rework/03-TOOL-REGISTRY.md +237 -0
- data/.claude/todo/phase-4-ai-rework/04-MCP-SERVER.md +432 -0
- data/.claude/todo/phase-4-ai-rework/05-MCP-CLIENT.md +333 -0
- data/.claude/todo/phase-4-ai-rework/06-EXECUTORS.md +397 -0
- data/.claude/todo/phase-4-ai-rework/todo.md +265 -0
- data/.claude/todo/phase-5-validation/.DS_Store +0 -0
- data/.claude/todo/phase-5-validation/01-TEST-GAPS.md +615 -0
- data/.claude/todo/phase-5-validation/01-TESTS.md +2378 -0
- data/.claude/todo/phase-5-validation/02-EXAMPLES-SIMPLE.md +744 -0
- data/.claude/todo/phase-5-validation/02-EXAMPLES.md +1857 -0
- data/.claude/todo/phase-5-validation/03-EXAMPLE-SUPPORT-AGENT.md +95 -0
- data/.claude/todo/phase-5-validation/04-EXAMPLE-ORDER-FULFILLMENT.md +94 -0
- data/.claude/todo/phase-5-validation/05-EXAMPLE-DATA-PIPELINE.md +145 -0
- data/.env.example +3 -0
- data/.rubocop.yml +64 -0
- data/0.3.amend.md +89 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +192 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +16 -0
- data/durable_workflow.gemspec +43 -0
- data/examples/approval_request.rb +106 -0
- data/examples/calculator.rb +154 -0
- data/examples/file_search_demo.rb +77 -0
- data/examples/hello_workflow.rb +57 -0
- data/examples/item_processor.rb +96 -0
- data/examples/order_fulfillment/Gemfile +6 -0
- data/examples/order_fulfillment/README.md +84 -0
- data/examples/order_fulfillment/run.rb +85 -0
- data/examples/order_fulfillment/services.rb +146 -0
- data/examples/order_fulfillment/workflow.yml +188 -0
- data/examples/parallel_fetch.rb +102 -0
- data/examples/service_integration.rb +137 -0
- data/examples/support_agent/Gemfile +6 -0
- data/examples/support_agent/README.md +91 -0
- data/examples/support_agent/config/claude_desktop.json +12 -0
- data/examples/support_agent/mcp_server.rb +49 -0
- data/examples/support_agent/run.rb +67 -0
- data/examples/support_agent/services.rb +113 -0
- data/examples/support_agent/workflow.yml +286 -0
- data/lib/durable_workflow/core/condition.rb +45 -0
- data/lib/durable_workflow/core/engine.rb +145 -0
- data/lib/durable_workflow/core/executors/approval.rb +51 -0
- data/lib/durable_workflow/core/executors/assign.rb +18 -0
- data/lib/durable_workflow/core/executors/base.rb +90 -0
- data/lib/durable_workflow/core/executors/call.rb +76 -0
- data/lib/durable_workflow/core/executors/end.rb +19 -0
- data/lib/durable_workflow/core/executors/halt.rb +24 -0
- data/lib/durable_workflow/core/executors/loop.rb +118 -0
- data/lib/durable_workflow/core/executors/parallel.rb +77 -0
- data/lib/durable_workflow/core/executors/registry.rb +34 -0
- data/lib/durable_workflow/core/executors/router.rb +26 -0
- data/lib/durable_workflow/core/executors/start.rb +61 -0
- data/lib/durable_workflow/core/executors/transform.rb +71 -0
- data/lib/durable_workflow/core/executors/workflow.rb +32 -0
- data/lib/durable_workflow/core/parser.rb +189 -0
- data/lib/durable_workflow/core/resolver.rb +61 -0
- data/lib/durable_workflow/core/schema_validator.rb +47 -0
- data/lib/durable_workflow/core/types/base.rb +41 -0
- data/lib/durable_workflow/core/types/condition.rb +25 -0
- data/lib/durable_workflow/core/types/configs.rb +103 -0
- data/lib/durable_workflow/core/types/entry.rb +26 -0
- data/lib/durable_workflow/core/types/results.rb +41 -0
- data/lib/durable_workflow/core/types/state.rb +95 -0
- data/lib/durable_workflow/core/types/step_def.rb +15 -0
- data/lib/durable_workflow/core/types/workflow_def.rb +43 -0
- data/lib/durable_workflow/core/types.rb +29 -0
- data/lib/durable_workflow/core/validator.rb +318 -0
- data/lib/durable_workflow/extensions/ai/ai.rb +149 -0
- data/lib/durable_workflow/extensions/ai/configuration.rb +41 -0
- data/lib/durable_workflow/extensions/ai/executors/agent.rb +150 -0
- data/lib/durable_workflow/extensions/ai/executors/file_search.rb +52 -0
- data/lib/durable_workflow/extensions/ai/executors/guardrail.rb +152 -0
- data/lib/durable_workflow/extensions/ai/executors/handoff.rb +33 -0
- data/lib/durable_workflow/extensions/ai/executors/mcp.rb +47 -0
- data/lib/durable_workflow/extensions/ai/mcp/adapter.rb +73 -0
- data/lib/durable_workflow/extensions/ai/mcp/client.rb +77 -0
- data/lib/durable_workflow/extensions/ai/mcp/rack_app.rb +66 -0
- data/lib/durable_workflow/extensions/ai/mcp/server.rb +122 -0
- data/lib/durable_workflow/extensions/ai/tool_registry.rb +63 -0
- data/lib/durable_workflow/extensions/ai/types.rb +213 -0
- data/lib/durable_workflow/extensions/ai.rb +6 -0
- data/lib/durable_workflow/extensions/base.rb +77 -0
- data/lib/durable_workflow/runners/adapters/inline.rb +42 -0
- data/lib/durable_workflow/runners/adapters/sidekiq.rb +69 -0
- data/lib/durable_workflow/runners/async.rb +100 -0
- data/lib/durable_workflow/runners/stream.rb +126 -0
- data/lib/durable_workflow/runners/sync.rb +40 -0
- data/lib/durable_workflow/storage/active_record.rb +148 -0
- data/lib/durable_workflow/storage/redis.rb +133 -0
- data/lib/durable_workflow/storage/sequel.rb +144 -0
- data/lib/durable_workflow/storage/store.rb +43 -0
- data/lib/durable_workflow/utils.rb +25 -0
- data/lib/durable_workflow/version.rb +5 -0
- data/lib/durable_workflow.rb +70 -0
- data/sig/durable_workflow.rbs +4 -0
- metadata +275 -0
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
durable_workflow (0.1.0)
|
|
5
|
+
async (~> 2.21)
|
|
6
|
+
dry-struct (~> 1.6)
|
|
7
|
+
dry-types (~> 1.7)
|
|
8
|
+
faraday (>= 2.0)
|
|
9
|
+
json_schemer (~> 2.0)
|
|
10
|
+
mcp (~> 0.1)
|
|
11
|
+
rack (>= 2.0)
|
|
12
|
+
ruby_llm (~> 1.0)
|
|
13
|
+
|
|
14
|
+
GEM
|
|
15
|
+
remote: https://rubygems.org/
|
|
16
|
+
specs:
|
|
17
|
+
activemodel (7.2.3)
|
|
18
|
+
activesupport (= 7.2.3)
|
|
19
|
+
activerecord (7.2.3)
|
|
20
|
+
activemodel (= 7.2.3)
|
|
21
|
+
activesupport (= 7.2.3)
|
|
22
|
+
timeout (>= 0.4.0)
|
|
23
|
+
activesupport (7.2.3)
|
|
24
|
+
base64
|
|
25
|
+
benchmark (>= 0.3)
|
|
26
|
+
bigdecimal
|
|
27
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
28
|
+
connection_pool (>= 2.2.5)
|
|
29
|
+
drb
|
|
30
|
+
i18n (>= 1.6, < 2)
|
|
31
|
+
logger (>= 1.4.2)
|
|
32
|
+
minitest (>= 5.1)
|
|
33
|
+
securerandom (>= 0.3)
|
|
34
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
35
|
+
addressable (2.8.8)
|
|
36
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
37
|
+
ast (2.4.3)
|
|
38
|
+
async (2.34.0)
|
|
39
|
+
console (~> 1.29)
|
|
40
|
+
fiber-annotation
|
|
41
|
+
io-event (~> 1.11)
|
|
42
|
+
metrics (~> 0.12)
|
|
43
|
+
traces (~> 0.18)
|
|
44
|
+
base64 (0.3.0)
|
|
45
|
+
benchmark (0.5.0)
|
|
46
|
+
bigdecimal (3.3.1)
|
|
47
|
+
concurrent-ruby (1.3.5)
|
|
48
|
+
connection_pool (2.5.5)
|
|
49
|
+
console (1.34.2)
|
|
50
|
+
fiber-annotation
|
|
51
|
+
fiber-local (~> 1.1)
|
|
52
|
+
json
|
|
53
|
+
dotenv (3.1.8)
|
|
54
|
+
drb (2.2.3)
|
|
55
|
+
dry-core (1.1.0)
|
|
56
|
+
concurrent-ruby (~> 1.0)
|
|
57
|
+
logger
|
|
58
|
+
zeitwerk (~> 2.6)
|
|
59
|
+
dry-inflector (1.2.0)
|
|
60
|
+
dry-logic (1.6.0)
|
|
61
|
+
bigdecimal
|
|
62
|
+
concurrent-ruby (~> 1.0)
|
|
63
|
+
dry-core (~> 1.1)
|
|
64
|
+
zeitwerk (~> 2.6)
|
|
65
|
+
dry-struct (1.8.0)
|
|
66
|
+
dry-core (~> 1.1)
|
|
67
|
+
dry-types (~> 1.8, >= 1.8.2)
|
|
68
|
+
ice_nine (~> 0.11)
|
|
69
|
+
zeitwerk (~> 2.6)
|
|
70
|
+
dry-types (1.8.3)
|
|
71
|
+
bigdecimal (~> 3.0)
|
|
72
|
+
concurrent-ruby (~> 1.0)
|
|
73
|
+
dry-core (~> 1.0)
|
|
74
|
+
dry-inflector (~> 1.0)
|
|
75
|
+
dry-logic (~> 1.4)
|
|
76
|
+
zeitwerk (~> 2.6)
|
|
77
|
+
event_stream_parser (1.0.0)
|
|
78
|
+
faraday (2.14.0)
|
|
79
|
+
faraday-net_http (>= 2.0, < 3.5)
|
|
80
|
+
json
|
|
81
|
+
logger
|
|
82
|
+
faraday-multipart (1.1.1)
|
|
83
|
+
multipart-post (~> 2.0)
|
|
84
|
+
faraday-net_http (3.4.2)
|
|
85
|
+
net-http (~> 0.5)
|
|
86
|
+
faraday-retry (2.3.2)
|
|
87
|
+
faraday (~> 2.0)
|
|
88
|
+
fiber-annotation (0.2.0)
|
|
89
|
+
fiber-local (1.1.0)
|
|
90
|
+
fiber-storage
|
|
91
|
+
fiber-storage (1.0.1)
|
|
92
|
+
hana (1.3.7)
|
|
93
|
+
i18n (1.14.7)
|
|
94
|
+
concurrent-ruby (~> 1.0)
|
|
95
|
+
ice_nine (0.11.2)
|
|
96
|
+
io-event (1.11.2)
|
|
97
|
+
json (2.16.0)
|
|
98
|
+
json-schema (6.0.0)
|
|
99
|
+
addressable (~> 2.8)
|
|
100
|
+
bigdecimal (~> 3.1)
|
|
101
|
+
json_rpc_handler (0.1.1)
|
|
102
|
+
json_schemer (2.4.0)
|
|
103
|
+
bigdecimal
|
|
104
|
+
hana (~> 1.3)
|
|
105
|
+
regexp_parser (~> 2.0)
|
|
106
|
+
simpleidn (~> 0.2)
|
|
107
|
+
language_server-protocol (3.17.0.5)
|
|
108
|
+
lint_roller (1.1.0)
|
|
109
|
+
logger (1.7.0)
|
|
110
|
+
marcel (1.1.0)
|
|
111
|
+
mcp (0.4.0)
|
|
112
|
+
json-schema (>= 4.1)
|
|
113
|
+
json_rpc_handler (~> 0.1)
|
|
114
|
+
metrics (0.15.0)
|
|
115
|
+
minitest (5.26.2)
|
|
116
|
+
multipart-post (2.4.1)
|
|
117
|
+
net-http (0.8.0)
|
|
118
|
+
uri (>= 0.11.1)
|
|
119
|
+
parallel (1.27.0)
|
|
120
|
+
parser (3.3.10.0)
|
|
121
|
+
ast (~> 2.4.1)
|
|
122
|
+
racc
|
|
123
|
+
prism (1.6.0)
|
|
124
|
+
public_suffix (7.0.0)
|
|
125
|
+
racc (1.8.1)
|
|
126
|
+
rack (3.2.4)
|
|
127
|
+
rainbow (3.1.1)
|
|
128
|
+
rake (13.3.1)
|
|
129
|
+
redis (5.4.1)
|
|
130
|
+
redis-client (>= 0.22.0)
|
|
131
|
+
redis-client (0.26.1)
|
|
132
|
+
connection_pool
|
|
133
|
+
regexp_parser (2.11.3)
|
|
134
|
+
rubocop (1.81.7)
|
|
135
|
+
json (~> 2.3)
|
|
136
|
+
language_server-protocol (~> 3.17.0.2)
|
|
137
|
+
lint_roller (~> 1.1.0)
|
|
138
|
+
parallel (~> 1.10)
|
|
139
|
+
parser (>= 3.3.0.2)
|
|
140
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
141
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
142
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
143
|
+
ruby-progressbar (~> 1.7)
|
|
144
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
145
|
+
rubocop-ast (1.48.0)
|
|
146
|
+
parser (>= 3.3.7.2)
|
|
147
|
+
prism (~> 1.4)
|
|
148
|
+
ruby-progressbar (1.13.0)
|
|
149
|
+
ruby_llm (1.9.1)
|
|
150
|
+
base64
|
|
151
|
+
event_stream_parser (~> 1)
|
|
152
|
+
faraday (>= 1.10.0)
|
|
153
|
+
faraday-multipart (>= 1)
|
|
154
|
+
faraday-net_http (>= 1)
|
|
155
|
+
faraday-retry (>= 1)
|
|
156
|
+
marcel (~> 1.0)
|
|
157
|
+
ruby_llm-schema (~> 0.2.1)
|
|
158
|
+
zeitwerk (~> 2)
|
|
159
|
+
ruby_llm-schema (0.2.5)
|
|
160
|
+
securerandom (0.4.1)
|
|
161
|
+
sequel (5.98.0)
|
|
162
|
+
bigdecimal
|
|
163
|
+
simpleidn (0.2.3)
|
|
164
|
+
sqlite3 (1.7.3-arm64-darwin)
|
|
165
|
+
sqlite3 (1.7.3-x86_64-linux)
|
|
166
|
+
timeout (0.4.4)
|
|
167
|
+
traces (0.18.2)
|
|
168
|
+
tzinfo (2.0.6)
|
|
169
|
+
concurrent-ruby (~> 1.0)
|
|
170
|
+
unicode-display_width (3.2.0)
|
|
171
|
+
unicode-emoji (~> 4.1)
|
|
172
|
+
unicode-emoji (4.1.0)
|
|
173
|
+
uri (1.1.1)
|
|
174
|
+
zeitwerk (2.7.3)
|
|
175
|
+
|
|
176
|
+
PLATFORMS
|
|
177
|
+
arm64-darwin-24
|
|
178
|
+
x86_64-linux
|
|
179
|
+
|
|
180
|
+
DEPENDENCIES
|
|
181
|
+
activerecord (~> 7.0)
|
|
182
|
+
dotenv (~> 3.0)
|
|
183
|
+
durable_workflow!
|
|
184
|
+
minitest (~> 5.0)
|
|
185
|
+
rake (~> 13.0)
|
|
186
|
+
redis (~> 5.0)
|
|
187
|
+
rubocop (~> 1.21)
|
|
188
|
+
sequel (~> 5.0)
|
|
189
|
+
sqlite3 (~> 1.6)
|
|
190
|
+
|
|
191
|
+
BUNDLED WITH
|
|
192
|
+
2.4.19
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ben
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# DurableWorkflow
|
|
2
|
+
|
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
|
4
|
+
|
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/durable_workflow`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
10
|
+
|
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
12
|
+
|
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
|
14
|
+
|
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
16
|
+
|
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Development
|
|
24
|
+
|
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
26
|
+
|
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/durable_workflow. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/durable_workflow/blob/master/CODE_OF_CONDUCT.md).
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
36
|
+
|
|
37
|
+
## Code of Conduct
|
|
38
|
+
|
|
39
|
+
Everyone interacting in the DurableWorkflow project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/durable_workflow/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << 'test'
|
|
8
|
+
t.libs << 'lib'
|
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'rubocop/rake_task'
|
|
13
|
+
|
|
14
|
+
RuboCop::RakeTask.new
|
|
15
|
+
|
|
16
|
+
task default: %i[test rubocop]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/durable_workflow/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'durable_workflow'
|
|
7
|
+
spec.version = DurableWorkflow::VERSION
|
|
8
|
+
spec.authors = ['Ben']
|
|
9
|
+
spec.email = ['ben@dee.mx']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Durable workflow engine with YAML-defined steps and pluggable executors'
|
|
12
|
+
spec.description = 'A workflow engine supporting loops, parallel execution, approvals, halts, and extensible step types. Designed for durable, resumable execution with optional AI capabilities.'
|
|
13
|
+
spec.homepage = 'https://github.com/your-org/durable_workflow'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
19
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
21
|
+
|
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github .circleci appveyor])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = 'exe'
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ['lib']
|
|
31
|
+
|
|
32
|
+
# Core dependencies
|
|
33
|
+
spec.add_dependency 'dry-types', '~> 1.7'
|
|
34
|
+
spec.add_dependency 'dry-struct', '~> 1.6'
|
|
35
|
+
spec.add_dependency 'json_schemer', '~> 2.0'
|
|
36
|
+
spec.add_dependency 'async', '~> 2.21'
|
|
37
|
+
|
|
38
|
+
# AI extension dependencies
|
|
39
|
+
spec.add_dependency 'ruby_llm', '~> 1.0'
|
|
40
|
+
spec.add_dependency 'mcp', '~> 0.1'
|
|
41
|
+
spec.add_dependency 'faraday', '>= 2.0'
|
|
42
|
+
spec.add_dependency 'rack', '>= 2.0'
|
|
43
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Approval Request - Workflow that halts for human input
|
|
5
|
+
#
|
|
6
|
+
# Demonstrates: Halt step, resume, human-in-the-loop
|
|
7
|
+
#
|
|
8
|
+
# Run: ruby examples/approval_request.rb
|
|
9
|
+
# Requires: Redis running on localhost:6379
|
|
10
|
+
|
|
11
|
+
require "bundler/setup"
|
|
12
|
+
require "durable_workflow"
|
|
13
|
+
require "durable_workflow/storage/redis"
|
|
14
|
+
|
|
15
|
+
DurableWorkflow.configure do |c|
|
|
16
|
+
c.store = DurableWorkflow::Storage::Redis.new(url: "redis://localhost:6379")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
workflow = DurableWorkflow::Core::Parser.parse(<<~YAML)
|
|
20
|
+
id: expense_approval
|
|
21
|
+
name: Expense Approval
|
|
22
|
+
version: "1.0"
|
|
23
|
+
|
|
24
|
+
inputs:
|
|
25
|
+
requester:
|
|
26
|
+
type: string
|
|
27
|
+
required: true
|
|
28
|
+
amount:
|
|
29
|
+
type: number
|
|
30
|
+
required: true
|
|
31
|
+
description:
|
|
32
|
+
type: string
|
|
33
|
+
required: true
|
|
34
|
+
|
|
35
|
+
steps:
|
|
36
|
+
- id: start
|
|
37
|
+
type: start
|
|
38
|
+
next: check_amount
|
|
39
|
+
|
|
40
|
+
- id: check_amount
|
|
41
|
+
type: router
|
|
42
|
+
routes:
|
|
43
|
+
- when:
|
|
44
|
+
field: input.amount
|
|
45
|
+
op: gt
|
|
46
|
+
value: 100
|
|
47
|
+
then: require_approval
|
|
48
|
+
default: auto_approve
|
|
49
|
+
|
|
50
|
+
- id: auto_approve
|
|
51
|
+
type: assign
|
|
52
|
+
set:
|
|
53
|
+
approved: true
|
|
54
|
+
approved_by: system
|
|
55
|
+
reason: "Amount under threshold"
|
|
56
|
+
next: end
|
|
57
|
+
|
|
58
|
+
- id: require_approval
|
|
59
|
+
type: approval
|
|
60
|
+
prompt: "Please approve expense request"
|
|
61
|
+
context:
|
|
62
|
+
requester: "$input.requester"
|
|
63
|
+
amount: "$input.amount"
|
|
64
|
+
description: "$input.description"
|
|
65
|
+
on_reject: rejected
|
|
66
|
+
next: approved
|
|
67
|
+
|
|
68
|
+
- id: approved
|
|
69
|
+
type: assign
|
|
70
|
+
set:
|
|
71
|
+
approved: true
|
|
72
|
+
approved_by: manager
|
|
73
|
+
next: end
|
|
74
|
+
|
|
75
|
+
- id: rejected
|
|
76
|
+
type: assign
|
|
77
|
+
set:
|
|
78
|
+
approved: false
|
|
79
|
+
approved_by: manager
|
|
80
|
+
reason: "Request rejected"
|
|
81
|
+
next: end
|
|
82
|
+
|
|
83
|
+
- id: end
|
|
84
|
+
type: end
|
|
85
|
+
result:
|
|
86
|
+
approved: "$approved"
|
|
87
|
+
approved_by: "$approved_by"
|
|
88
|
+
reason: "$reason"
|
|
89
|
+
YAML
|
|
90
|
+
|
|
91
|
+
runner = DurableWorkflow::Runners::Sync.new(workflow)
|
|
92
|
+
|
|
93
|
+
# Small expense - auto-approved
|
|
94
|
+
result = runner.run(input: { requester: "Alice", amount: 50, description: "Office supplies" })
|
|
95
|
+
puts "Small expense: #{result.output}"
|
|
96
|
+
# => Small expense: {:approved=>true, :approved_by=>"system", :reason=>"Amount under threshold"}
|
|
97
|
+
|
|
98
|
+
# Large expense - requires approval
|
|
99
|
+
result = runner.run(input: { requester: "Bob", amount: 500, description: "Conference ticket" })
|
|
100
|
+
puts "\nLarge expense halted: #{result.status}"
|
|
101
|
+
puts "Halt data: #{result.halt&.data}"
|
|
102
|
+
|
|
103
|
+
# Simulate manager approval
|
|
104
|
+
if result.status == :halted
|
|
105
|
+
puts "Workflow halted for approval - would resume with approved: true/false"
|
|
106
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Calculator Workflow - Routing based on input
|
|
5
|
+
#
|
|
6
|
+
# Demonstrates: Router step, conditional branching, service calls
|
|
7
|
+
#
|
|
8
|
+
# Run: ruby examples/calculator.rb
|
|
9
|
+
# Requires: Redis running on localhost:6379
|
|
10
|
+
|
|
11
|
+
require "bundler/setup"
|
|
12
|
+
require "durable_workflow"
|
|
13
|
+
require "durable_workflow/storage/redis"
|
|
14
|
+
|
|
15
|
+
# Calculator service for arithmetic operations (must be globally accessible)
|
|
16
|
+
module Calculator
|
|
17
|
+
def self.add(a:, b:)
|
|
18
|
+
{ result: a + b, operation: "addition" }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.subtract(a:, b:)
|
|
22
|
+
{ result: a - b, operation: "subtraction" }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.multiply(a:, b:)
|
|
26
|
+
{ result: a * b, operation: "multiplication" }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.divide(a:, b:)
|
|
30
|
+
{ result: a.to_f / b, operation: "division" }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
DurableWorkflow.configure do |c|
|
|
35
|
+
c.store = DurableWorkflow::Storage::Redis.new(url: "redis://localhost:6379")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
workflow = DurableWorkflow::Core::Parser.parse(<<~YAML)
|
|
39
|
+
id: calculator
|
|
40
|
+
name: Calculator
|
|
41
|
+
version: "1.0"
|
|
42
|
+
|
|
43
|
+
inputs:
|
|
44
|
+
operation:
|
|
45
|
+
type: string
|
|
46
|
+
required: true
|
|
47
|
+
a:
|
|
48
|
+
type: number
|
|
49
|
+
required: true
|
|
50
|
+
b:
|
|
51
|
+
type: number
|
|
52
|
+
required: true
|
|
53
|
+
|
|
54
|
+
steps:
|
|
55
|
+
- id: start
|
|
56
|
+
type: start
|
|
57
|
+
next: route
|
|
58
|
+
|
|
59
|
+
- id: route
|
|
60
|
+
type: router
|
|
61
|
+
routes:
|
|
62
|
+
- when:
|
|
63
|
+
field: input.operation
|
|
64
|
+
op: eq
|
|
65
|
+
value: "add"
|
|
66
|
+
then: add
|
|
67
|
+
- when:
|
|
68
|
+
field: input.operation
|
|
69
|
+
op: eq
|
|
70
|
+
value: "subtract"
|
|
71
|
+
then: subtract
|
|
72
|
+
- when:
|
|
73
|
+
field: input.operation
|
|
74
|
+
op: eq
|
|
75
|
+
value: "multiply"
|
|
76
|
+
then: multiply
|
|
77
|
+
- when:
|
|
78
|
+
field: input.operation
|
|
79
|
+
op: eq
|
|
80
|
+
value: "divide"
|
|
81
|
+
then: divide
|
|
82
|
+
default: error
|
|
83
|
+
|
|
84
|
+
- id: add
|
|
85
|
+
type: call
|
|
86
|
+
service: Calculator
|
|
87
|
+
method: add
|
|
88
|
+
input:
|
|
89
|
+
a: "$input.a"
|
|
90
|
+
b: "$input.b"
|
|
91
|
+
output: calc_result
|
|
92
|
+
next: end
|
|
93
|
+
|
|
94
|
+
- id: subtract
|
|
95
|
+
type: call
|
|
96
|
+
service: Calculator
|
|
97
|
+
method: subtract
|
|
98
|
+
input:
|
|
99
|
+
a: "$input.a"
|
|
100
|
+
b: "$input.b"
|
|
101
|
+
output: calc_result
|
|
102
|
+
next: end
|
|
103
|
+
|
|
104
|
+
- id: multiply
|
|
105
|
+
type: call
|
|
106
|
+
service: Calculator
|
|
107
|
+
method: multiply
|
|
108
|
+
input:
|
|
109
|
+
a: "$input.a"
|
|
110
|
+
b: "$input.b"
|
|
111
|
+
output: calc_result
|
|
112
|
+
next: end
|
|
113
|
+
|
|
114
|
+
- id: divide
|
|
115
|
+
type: call
|
|
116
|
+
service: Calculator
|
|
117
|
+
method: divide
|
|
118
|
+
input:
|
|
119
|
+
a: "$input.a"
|
|
120
|
+
b: "$input.b"
|
|
121
|
+
output: calc_result
|
|
122
|
+
next: end
|
|
123
|
+
|
|
124
|
+
- id: error
|
|
125
|
+
type: assign
|
|
126
|
+
set:
|
|
127
|
+
calc_result:
|
|
128
|
+
error: "Unknown operation"
|
|
129
|
+
next: end
|
|
130
|
+
|
|
131
|
+
- id: end
|
|
132
|
+
type: end
|
|
133
|
+
result:
|
|
134
|
+
result: "$calc_result.result"
|
|
135
|
+
operation: "$calc_result.operation"
|
|
136
|
+
error: "$calc_result.error"
|
|
137
|
+
YAML
|
|
138
|
+
|
|
139
|
+
runner = DurableWorkflow::Runners::Sync.new(workflow)
|
|
140
|
+
|
|
141
|
+
# Test all operations
|
|
142
|
+
[
|
|
143
|
+
{ operation: "add", a: 10, b: 5 },
|
|
144
|
+
{ operation: "subtract", a: 10, b: 5 },
|
|
145
|
+
{ operation: "multiply", a: 10, b: 5 },
|
|
146
|
+
{ operation: "divide", a: 10, b: 5 }
|
|
147
|
+
].each do |calc_input|
|
|
148
|
+
result = runner.run(input: calc_input)
|
|
149
|
+
puts "#{calc_input[:a]} #{calc_input[:operation]} #{calc_input[:b]} = #{result.output[:result]}"
|
|
150
|
+
end
|
|
151
|
+
# => 10 add 5 = 15
|
|
152
|
+
# => 10 subtract 5 = 5
|
|
153
|
+
# => 10 multiply 5 = 50
|
|
154
|
+
# => 10 divide 5 = 2.0
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# File Search Demo
|
|
5
|
+
# Demonstrates the file_search step type with dummy results
|
|
6
|
+
|
|
7
|
+
require "bundler/setup"
|
|
8
|
+
require "durable_workflow"
|
|
9
|
+
require "durable_workflow/extensions/ai"
|
|
10
|
+
require "durable_workflow/storage/redis"
|
|
11
|
+
|
|
12
|
+
DurableWorkflow.configure do |c|
|
|
13
|
+
c.store = DurableWorkflow::Storage::Redis.new(url: "redis://localhost:6379")
|
|
14
|
+
c.logger = Logger.new($stdout, level: Logger::INFO)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Define workflow inline using YAML
|
|
18
|
+
workflow_yaml = <<~YAML
|
|
19
|
+
id: file_search_demo
|
|
20
|
+
name: File Search Demo
|
|
21
|
+
version: "1.0"
|
|
22
|
+
description: Search documentation files
|
|
23
|
+
|
|
24
|
+
inputs:
|
|
25
|
+
query:
|
|
26
|
+
type: string
|
|
27
|
+
required: true
|
|
28
|
+
description: Search query
|
|
29
|
+
|
|
30
|
+
steps:
|
|
31
|
+
- id: start
|
|
32
|
+
type: start
|
|
33
|
+
next: search_docs
|
|
34
|
+
|
|
35
|
+
- id: search_docs
|
|
36
|
+
type: file_search
|
|
37
|
+
query: "$input.query"
|
|
38
|
+
files:
|
|
39
|
+
- docs/getting_started.md
|
|
40
|
+
- docs/configuration.md
|
|
41
|
+
- docs/api_reference.md
|
|
42
|
+
- docs/troubleshooting.md
|
|
43
|
+
max_results: 3
|
|
44
|
+
output: search_results
|
|
45
|
+
next: format_results
|
|
46
|
+
|
|
47
|
+
- id: format_results
|
|
48
|
+
type: assign
|
|
49
|
+
set:
|
|
50
|
+
summary: "Found results for query"
|
|
51
|
+
next: end
|
|
52
|
+
|
|
53
|
+
- id: end
|
|
54
|
+
type: end
|
|
55
|
+
result:
|
|
56
|
+
query: "$input.query"
|
|
57
|
+
results: "$search_results.results"
|
|
58
|
+
total: "$search_results.total"
|
|
59
|
+
summary: "$summary"
|
|
60
|
+
YAML
|
|
61
|
+
|
|
62
|
+
workflow = DurableWorkflow.load(workflow_yaml)
|
|
63
|
+
runner = DurableWorkflow::Runners::Sync.new(workflow)
|
|
64
|
+
|
|
65
|
+
puts "=" * 60
|
|
66
|
+
puts "File Search Demo"
|
|
67
|
+
puts "=" * 60
|
|
68
|
+
|
|
69
|
+
result = runner.run(input: { query: "how to configure logging" })
|
|
70
|
+
|
|
71
|
+
puts "\nSearch Query: #{result.output[:query]}"
|
|
72
|
+
puts "Total Results: #{result.output[:total]}"
|
|
73
|
+
puts "\nResults:"
|
|
74
|
+
result.output[:results].each_with_index do |r, idx|
|
|
75
|
+
puts " #{idx + 1}. #{r[:file]} (score: #{r[:score]})"
|
|
76
|
+
puts " #{r[:snippet]}"
|
|
77
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Hello Workflow - Simplest possible durable workflow
|
|
5
|
+
#
|
|
6
|
+
# Demonstrates: Basic workflow structure, assign step, input/output
|
|
7
|
+
#
|
|
8
|
+
# Run: ruby examples/hello_workflow.rb
|
|
9
|
+
# Requires: Redis running on localhost:6379
|
|
10
|
+
|
|
11
|
+
require "bundler/setup"
|
|
12
|
+
require "durable_workflow"
|
|
13
|
+
require "durable_workflow/storage/redis"
|
|
14
|
+
|
|
15
|
+
# Configure storage
|
|
16
|
+
DurableWorkflow.configure do |c|
|
|
17
|
+
c.store = DurableWorkflow::Storage::Redis.new(url: "redis://localhost:6379")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Define workflow inline
|
|
21
|
+
workflow = DurableWorkflow::Core::Parser.parse(<<~YAML)
|
|
22
|
+
id: hello_world
|
|
23
|
+
name: Hello World
|
|
24
|
+
version: "1.0"
|
|
25
|
+
|
|
26
|
+
inputs:
|
|
27
|
+
name:
|
|
28
|
+
type: string
|
|
29
|
+
required: true
|
|
30
|
+
|
|
31
|
+
steps:
|
|
32
|
+
- id: start
|
|
33
|
+
type: start
|
|
34
|
+
next: greet
|
|
35
|
+
|
|
36
|
+
- id: greet
|
|
37
|
+
type: assign
|
|
38
|
+
set:
|
|
39
|
+
greeting: "Hello, $input.name!"
|
|
40
|
+
timestamp: "$now"
|
|
41
|
+
next: end
|
|
42
|
+
|
|
43
|
+
- id: end
|
|
44
|
+
type: end
|
|
45
|
+
result:
|
|
46
|
+
message: "$greeting"
|
|
47
|
+
generated_at: "$timestamp"
|
|
48
|
+
YAML
|
|
49
|
+
|
|
50
|
+
# Run it
|
|
51
|
+
runner = DurableWorkflow::Runners::Sync.new(workflow)
|
|
52
|
+
result = runner.run(input: { name: "World" })
|
|
53
|
+
|
|
54
|
+
puts "Status: #{result.status}"
|
|
55
|
+
puts "Output: #{result.output}"
|
|
56
|
+
# => Status: completed
|
|
57
|
+
# => Output: {:message=>"Hello, World!", :generated_at=>"2024-..."}
|