meta_workflows 0.9.26 → 0.9.27
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e7c5610d3502a37e016166f1bdc387aba3fd75873372a1900e8cfc680cdde10
|
4
|
+
data.tar.gz: 19a53e7916c5793a928b324a76381d9042c7247d83e5282995d151f40db027cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91d3eff2f6801a95e1cd66eb2f62afcc682d69ca59b169071cc2635ee31c92066029efa09f8b634b16d5aa76c625a03f73d2c1338a5b16b08019891c66a40515
|
7
|
+
data.tar.gz: a288d9b2d9d0f8626174b95f7f870b5f6e0360fbe3cb86f85f18bededddd14c49f4add815afa466b666a7e6d1cf54e36567a555caa84c7c063a83138d4d0fa37
|
data/README.md
CHANGED
@@ -347,6 +347,39 @@ steps:
|
|
347
347
|
redirect_path: "/your/completion/path"
|
348
348
|
```
|
349
349
|
|
350
|
+
### Workflow Parameters vs Inputs
|
351
|
+
|
352
|
+
MetaWorkflows supports two ways to pass data into workflows: `inputs` and `workflow_params`. Understanding the difference is crucial for proper workflow design.
|
353
|
+
|
354
|
+
#### `inputs` Hash from Service Instantiation
|
355
|
+
- **Scope**: Only available to the **very next step** of the workflow
|
356
|
+
- **Use Case**: Initial data needed to start the workflow
|
357
|
+
- **Lifetime**: Single-step only - not passed to subsequent steps
|
358
|
+
|
359
|
+
#### `workflow_params` Hash
|
360
|
+
- **Scope**: Available to **all steps** throughout the entire workflow execution
|
361
|
+
- **Use Case**: Data that needs to persist and be accessible across multiple workflow steps
|
362
|
+
- **Lifetime**: Entire workflow execution - accessible in every step
|
363
|
+
|
364
|
+
#### Priority and Conflicts
|
365
|
+
|
366
|
+
When both `inputs` and `workflow_params` contain the same attribute name:
|
367
|
+
- **`inputs` takes precedence** for the first step, but workflow params are still passed
|
368
|
+
- **This is not ideal** - avoid having duplicate keys in both hashes
|
369
|
+
- Choose one approach based on whether the data needs to persist throughout the workflow
|
370
|
+
|
371
|
+
#### When to Use Each
|
372
|
+
|
373
|
+
**Use `inputs` when:**
|
374
|
+
- Data is only needed for workflow initialization
|
375
|
+
- You want to pass temporary parameters to start the process
|
376
|
+
- The data doesn't need to be available in later steps
|
377
|
+
|
378
|
+
**Use `workflow_params` when:**
|
379
|
+
- Data needs to be available across multiple workflow steps
|
380
|
+
- You want to maintain state throughout the entire execution
|
381
|
+
- The information is core to the workflow's purpose
|
382
|
+
|
350
383
|
### Executing Workflows
|
351
384
|
|
352
385
|
#### From Controller Actions
|
@@ -362,8 +395,13 @@ class YourController < ApplicationController
|
|
362
395
|
record_id: @record.id,
|
363
396
|
user_id: current_user.id,
|
364
397
|
inputs: {
|
365
|
-
|
366
|
-
# other initial parameters
|
398
|
+
initial_title: @record.title, # Only available to first step
|
399
|
+
# other initial parameters for first step only
|
400
|
+
},
|
401
|
+
workflow_params: {
|
402
|
+
organization_id: @record.organization_id, # Available to all steps
|
403
|
+
user_role: current_user.role, # Available to all steps
|
404
|
+
# other parameters needed throughout workflow
|
367
405
|
}
|
368
406
|
)
|
369
407
|
|
@@ -372,6 +410,40 @@ class YourController < ApplicationController
|
|
372
410
|
end
|
373
411
|
```
|
374
412
|
|
413
|
+
#### Example: Workflow Definition Using Both
|
414
|
+
|
415
|
+
```yaml
|
416
|
+
name: "content_creation_workflow"
|
417
|
+
steps:
|
418
|
+
- name: "initial_analysis"
|
419
|
+
action: "agent"
|
420
|
+
prompt_id: "analyze_content"
|
421
|
+
input:
|
422
|
+
# This step can access both inputs (first step only) and workflow_params
|
423
|
+
- initial_title: "Starting title from inputs hash"
|
424
|
+
type: "string"
|
425
|
+
- organization_id: "Organization context from workflow_params"
|
426
|
+
type: "string"
|
427
|
+
|
428
|
+
- name: "content_generation"
|
429
|
+
action: "agent"
|
430
|
+
prompt_id: "generate_content"
|
431
|
+
input:
|
432
|
+
# This step can only access workflow_params (inputs not available)
|
433
|
+
- organization_id: "Organization context from workflow_params"
|
434
|
+
type: "string"
|
435
|
+
- user_role: "User role from workflow_params"
|
436
|
+
type: "string"
|
437
|
+
|
438
|
+
- name: "final_review"
|
439
|
+
action: "human"
|
440
|
+
prompt_id: "review_content"
|
441
|
+
input:
|
442
|
+
# This step can also only access workflow_params
|
443
|
+
- organization_id: "Organization context from workflow_params"
|
444
|
+
type: "string"
|
445
|
+
```
|
446
|
+
|
375
447
|
### Using Meta Workflow UI Components
|
376
448
|
|
377
449
|
Instead of creating custom views from scratch, use the provided Meta Workflow partials. The system now uses in-chat messaging for loader states and error handling, providing a seamless conversational experience:
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MetaWorkflows
|
4
|
+
module Concerns
|
5
|
+
module WorkflowParamsMergeable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def merge_matching_workflow_params(workflow_execution, execution_step, inputs = {})
|
9
|
+
merged_inputs = inputs.deep_symbolize_keys
|
10
|
+
return merged_inputs if workflow_execution.workflow_params.blank?
|
11
|
+
|
12
|
+
step_input_names = extract_input_variable_names(execution_step['input'] || [])
|
13
|
+
|
14
|
+
workflow_execution.workflow_params.each do |param_name, param_value|
|
15
|
+
param_string = param_name.to_s
|
16
|
+
param_symbol = param_name.to_sym
|
17
|
+
|
18
|
+
next unless step_input_names.include?(param_string) &&
|
19
|
+
!merged_inputs.key?(param_symbol) &&
|
20
|
+
!merged_inputs.key?(param_string)
|
21
|
+
|
22
|
+
merged_inputs[param_symbol] = param_value
|
23
|
+
end
|
24
|
+
|
25
|
+
merged_inputs
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def extract_input_variable_names(input_definitions)
|
31
|
+
input_definitions.filter_map do |input_def|
|
32
|
+
input_def.keys.find { |key| key != 'type' }&.to_s if input_def.is_a?(Hash) && input_def.keys.any?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -4,6 +4,7 @@ module MetaWorkflows
|
|
4
4
|
class MetaJob < MetaWorkflows::ApplicationJob
|
5
5
|
include MetaWorkflows::Concerns::ErrorHandling
|
6
6
|
include MetaWorkflows::Streamable
|
7
|
+
include MetaWorkflows::Concerns::WorkflowParamsMergeable
|
7
8
|
|
8
9
|
attr_accessor :chat, :inputs, :full_response, :user_id, :record, :auto_advancing, :manual_advancing,
|
9
10
|
:workflow_execution
|
@@ -33,8 +34,12 @@ module MetaWorkflows
|
|
33
34
|
current_step = workflow_execution.workflow_steps&.find_by(step: workflow_execution.current_step)
|
34
35
|
@chat = current_step&.chat
|
35
36
|
|
37
|
+
current_step_data = workflow_execution.step_data(workflow_execution.current_step)
|
38
|
+
merged_inputs = merge_matching_workflow_params(workflow_execution, current_step_data, inputs)
|
39
|
+
|
36
40
|
conversation = RubyConversations::Conversation.new(chat:)
|
37
|
-
conversation.with_prompt(params[:prompt_id], inputs:
|
41
|
+
conversation.with_prompt(params[:prompt_id], inputs: merged_inputs,
|
42
|
+
description: "Running #{params[:prompt_id]} process")
|
38
43
|
end
|
39
44
|
|
40
45
|
def continue_existing_conversation(params)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module MetaWorkflows
|
4
4
|
MAJOR = 0
|
5
5
|
MINOR = 9
|
6
|
-
PATCH =
|
6
|
+
PATCH = 27 # this is automatically incremented by the build process
|
7
7
|
|
8
8
|
VERSION = "#{MetaWorkflows::MAJOR}.#{MetaWorkflows::MINOR}.#{MetaWorkflows::PATCH}".freeze
|
9
9
|
end
|
@@ -5,6 +5,7 @@ module Services
|
|
5
5
|
class MetaWorkflowService
|
6
6
|
include ::MetaWorkflows::MetaWorkflowsHelper
|
7
7
|
include ::MetaWorkflows::Streamable
|
8
|
+
include ::MetaWorkflows::Concerns::WorkflowParamsMergeable
|
8
9
|
|
9
10
|
ACTIONS_WITHOUT_CONVERSATION = %w[record_redirect collection_create record_update].freeze
|
10
11
|
|
@@ -124,11 +125,13 @@ module Services
|
|
124
125
|
end
|
125
126
|
|
126
127
|
def process_human_action(execution_step, workflow_execution)
|
128
|
+
merged_inputs = merge_matching_workflow_params(workflow_execution, execution_step, inputs)
|
129
|
+
|
127
130
|
::MetaWorkflows::HumanInputJob.perform_later(
|
128
131
|
user_id: user&.id,
|
129
132
|
record: workflow_execution.record,
|
130
133
|
params: {
|
131
|
-
inputs:
|
134
|
+
inputs: merged_inputs,
|
132
135
|
prompt_id: execution_step['prompt_id']
|
133
136
|
}
|
134
137
|
)
|
@@ -136,11 +139,13 @@ module Services
|
|
136
139
|
end
|
137
140
|
|
138
141
|
def process_structured_human_action(execution_step, workflow_execution)
|
142
|
+
merged_inputs = merge_matching_workflow_params(workflow_execution, execution_step, inputs)
|
143
|
+
|
139
144
|
::MetaWorkflows::HumanInputJob.perform_later(
|
140
145
|
user_id: user&.id,
|
141
146
|
record: workflow_execution.record,
|
142
147
|
params: {
|
143
|
-
inputs:
|
148
|
+
inputs: merged_inputs,
|
144
149
|
prompt_id: execution_step['prompt_id']
|
145
150
|
}
|
146
151
|
)
|
@@ -235,9 +240,12 @@ module Services
|
|
235
240
|
def create_and_configure_conversation(chat, workflow_execution, execution_output, execution_step)
|
236
241
|
conversation = RubyConversations::Conversation.new(chat: chat)
|
237
242
|
conversation.tool = ::MetaWorkflows::Tools::MetaWorkflowTool.build(workflow_execution, execution_output)
|
243
|
+
|
244
|
+
merged_inputs = merge_matching_workflow_params(workflow_execution, execution_step, inputs)
|
245
|
+
|
238
246
|
conversation.with_prompt(
|
239
247
|
execution_step['prompt_id'],
|
240
|
-
inputs:
|
248
|
+
inputs: merged_inputs,
|
241
249
|
description: "Executing step #{workflow_execution.current_step} of " \
|
242
250
|
"workflow #{workflow_execution.workflow.name}"
|
243
251
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_workflows
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leonid Medovyy
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- app/helpers/meta_workflows/status_badge_helper.rb
|
147
147
|
- app/jobs/meta_workflows/application_job.rb
|
148
148
|
- app/jobs/meta_workflows/concerns/error_handling.rb
|
149
|
+
- app/jobs/meta_workflows/concerns/workflow_params_mergeable.rb
|
149
150
|
- app/jobs/meta_workflows/human_input_job.rb
|
150
151
|
- app/jobs/meta_workflows/meta_job.rb
|
151
152
|
- app/jobs/meta_workflows/meta_workflow_job.rb
|