ad-agent_architecture 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -1
- data/CHANGELOG.md +14 -0
- data/lib/ad/agent_architecture/{db → database}/models.rb +2 -2
- data/lib/ad/agent_architecture/database/save_workflow_graph.rb +54 -0
- data/lib/ad/agent_architecture/database/sql_query.rb +22 -0
- data/lib/ad/agent_architecture/dsl/agent_workflow_dsl.rb +97 -0
- data/lib/ad/agent_architecture/report/workflow_detail_report.rb +32 -0
- data/lib/ad/agent_architecture/report/workflow_list_report.rb +27 -0
- data/lib/ad/agent_architecture/sql/workflow_details.sql +35 -0
- data/lib/ad/agent_architecture/version.rb +1 -1
- data/lib/ad/agent_architecture.rb +8 -2
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +10 -4
- /data/lib/ad/agent_architecture/{db → database}/create_schema.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f028f265371e8a636e96ebbd94eb147d157133faac830fb212e6d7863cff2e0
|
4
|
+
data.tar.gz: cb6231c112e8788b82f19325ad54716b03fed23905435716aa1592967b9f8f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 873afb3fa43cfba38266711436db58c76b8d83202f7926c6be23be7799c059b8de94715a8f68df3ef71c20a519215e1173bcd8eb3ddfb8c0cffe70d958270fb4
|
7
|
+
data.tar.gz: 794d569604a03b43a85aeadcfd42f566c7bba8e746445d69d30cae7bf6362c2d1a2e48a2967d8018b3fe3ce0aa9d1b539787f7a73a7d908a12a6d2343b5429a4
|
data/.rubocop.yml
CHANGED
@@ -14,7 +14,7 @@ AllCops:
|
|
14
14
|
Exclude:
|
15
15
|
- ".builders/**/*"
|
16
16
|
- "spec/samples/**/*"
|
17
|
-
- "lib/ad/agent_architecture/
|
17
|
+
- "lib/ad/agent_architecture/database/*"
|
18
18
|
|
19
19
|
Metrics/BlockLength:
|
20
20
|
Exclude:
|
@@ -42,6 +42,9 @@ Metrics/BlockLength:
|
|
42
42
|
|
43
43
|
Metrics/MethodLength:
|
44
44
|
Max: 25
|
45
|
+
Exclude:
|
46
|
+
- "lib/ad/agent_architecture/dsl/*"
|
47
|
+
- "lib/ad/agent_architecture/database/*"
|
45
48
|
|
46
49
|
Layout/LineLength:
|
47
50
|
Max: 200
|
@@ -87,6 +90,14 @@ Lint/AmbiguousBlockAssociation:
|
|
87
90
|
|
88
91
|
Style/AccessorGrouping:
|
89
92
|
Enabled: false
|
93
|
+
Metrics/AbcSize:
|
94
|
+
Exclude:
|
95
|
+
- "lib/ad/agent_architecture/dsl/*"
|
96
|
+
- "lib/ad/agent_architecture/database/*"
|
97
|
+
- "lib/ad/agent_architecture/report/*"
|
98
|
+
Metrics/NoExpectationExample:
|
99
|
+
Exclude:
|
100
|
+
- "spec/ad/agent_architecture/dsl/*"
|
90
101
|
|
91
102
|
Layout/SpaceBeforeComma:
|
92
103
|
Enabled: false
|
@@ -105,3 +116,7 @@ RSpec/SpecFilePathSuffix:
|
|
105
116
|
RSpec/NamedSubject:
|
106
117
|
Exclude:
|
107
118
|
- "**/spec/**/*"
|
119
|
+
|
120
|
+
RSpec/ExampleLength:
|
121
|
+
Exclude:
|
122
|
+
- "**/spec/**/*"
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.0.7](https://github.com/appydave/ad-agent_architecture/compare/v0.0.6...v0.0.7) (2024-06-29)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* add basic support for database persistence to DSL ([632c815](https://github.com/appydave/ad-agent_architecture/commit/632c815133b2cd31ab95dccb3c0b8564e25aa605))
|
7
|
+
|
8
|
+
## [0.0.6](https://github.com/appydave/ad-agent_architecture/compare/v0.0.5...v0.0.6) (2024-06-28)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* update requirements documentation ([e80d072](https://github.com/appydave/ad-agent_architecture/commit/e80d0728652c7a4fdeb014324f196e0044cb13af))
|
14
|
+
|
1
15
|
## [0.0.5](https://github.com/appydave/ad-agent_architecture/compare/v0.0.4...v0.0.5) (2024-06-28)
|
2
16
|
|
3
17
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'sequel'
|
4
|
-
|
5
3
|
module Ad
|
6
4
|
module AgentArchitecture
|
7
5
|
module Database
|
8
6
|
# Workflow model represents a workflow entity in the database.
|
9
7
|
class Workflow < Sequel::Model
|
8
|
+
set_primary_key :id
|
9
|
+
|
10
10
|
one_to_many :sections, class: 'Ad::AgentArchitecture::Database::Section'
|
11
11
|
one_to_many :attributes, class: 'Ad::AgentArchitecture::Database::Attribute'
|
12
12
|
one_to_many :workflow_runs, class: 'Ad::AgentArchitecture::Database::WorkflowRun'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ad
|
4
|
+
module AgentArchitecture
|
5
|
+
module Database
|
6
|
+
# Save workflow graph to database
|
7
|
+
class SaveWorkflowGraph
|
8
|
+
def initialize(workflow_hash)
|
9
|
+
@workflow_hash = workflow_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def save
|
13
|
+
DB.transaction do
|
14
|
+
# Save workflow
|
15
|
+
workflow_record = Ad::AgentArchitecture::Database::Workflow.create(name: @workflow_hash[:name])
|
16
|
+
|
17
|
+
# Save attributes
|
18
|
+
attribute_records = @workflow_hash[:attributes].map do |_name, attr|
|
19
|
+
Ad::AgentArchitecture::Database::Attribute.create(
|
20
|
+
name: attr[:name], type: attr[:type], is_array: attr[:is_array], workflow: workflow_record
|
21
|
+
)
|
22
|
+
end
|
23
|
+
attribute_map = attribute_records.to_h { |ar| [ar.name.to_sym, ar] }
|
24
|
+
|
25
|
+
# Save sections and steps
|
26
|
+
@workflow_hash[:sections].each do |section|
|
27
|
+
section_record = Ad::AgentArchitecture::Database::Section.create(
|
28
|
+
name: section[:name], order: section[:order], workflow: workflow_record
|
29
|
+
)
|
30
|
+
|
31
|
+
section[:steps].each do |step|
|
32
|
+
step_record = Ad::AgentArchitecture::Database::Step.create(
|
33
|
+
name: step[:name], order: step[:order], prompt: step[:prompt], section: section_record
|
34
|
+
)
|
35
|
+
|
36
|
+
step[:input_attributes].each do |attr_name|
|
37
|
+
Ad::AgentArchitecture::Database::InputAttribute.create(
|
38
|
+
step: step_record, attribute: attribute_map[attr_name.to_sym]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
step[:output_attributes].each do |attr_name|
|
43
|
+
Ad::AgentArchitecture::Database::OutputAttribute.create(
|
44
|
+
step: step_record, attribute: attribute_map[attr_name.to_sym]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ad
|
4
|
+
module AgentArchitecture
|
5
|
+
module Database
|
6
|
+
class SQLQuery
|
7
|
+
SQL_DIR = File.expand_path('../sql', __dir__)
|
8
|
+
|
9
|
+
def self.query(sql_filename, params = {})
|
10
|
+
sql_path = File.join(SQL_DIR, "#{sql_filename}.sql")
|
11
|
+
|
12
|
+
# puts "SQL_DIR: #{SQL_DIR}"
|
13
|
+
# puts "SQL Path: #{sql_path}"
|
14
|
+
raise "SQL file not found: #{sql_path}" unless File.exist?(sql_path)
|
15
|
+
|
16
|
+
sql = File.read(sql_path)
|
17
|
+
DB.fetch(sql, params)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ad
|
4
|
+
module AgentArchitecture
|
5
|
+
module Dsl
|
6
|
+
# DSL for defining agent workflows
|
7
|
+
class AgentWorkflowDsl
|
8
|
+
def self.create(name:, &block)
|
9
|
+
new(name).tap do |dsl|
|
10
|
+
dsl.instance_eval(&block) if block_given?
|
11
|
+
dsl.save
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(name)
|
16
|
+
@workflow = { name: name, sections: [], attributes: {} }
|
17
|
+
@current_section_order = 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def attributes(&block)
|
21
|
+
instance_eval(&block) if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def attribute(name, type:, is_array: false)
|
25
|
+
@workflow[:attributes][name] = { name: name, type: type, is_array: is_array }
|
26
|
+
end
|
27
|
+
|
28
|
+
def section(name:, &block)
|
29
|
+
@current_step_order = 1
|
30
|
+
@current_section = { name: name, order: @current_section_order, steps: [] }
|
31
|
+
@current_section_order += 1
|
32
|
+
instance_eval(&block) if block_given?
|
33
|
+
@workflow[:sections] << @current_section
|
34
|
+
end
|
35
|
+
|
36
|
+
def step(name:, &block)
|
37
|
+
@current_step = { name: name, order: @current_step_order, input_attributes: [], output_attributes: [] }
|
38
|
+
@current_step_order += 1
|
39
|
+
instance_eval(&block) if block_given?
|
40
|
+
@current_section[:steps] << @current_step
|
41
|
+
end
|
42
|
+
|
43
|
+
def input(attr_name, **_opts)
|
44
|
+
@current_step[:input_attributes] << attr_name
|
45
|
+
end
|
46
|
+
|
47
|
+
def output(attr_name, **_opts)
|
48
|
+
@current_step[:output_attributes] << attr_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def prompt(prompt_text, **_opts)
|
52
|
+
@current_step[:prompt] = prompt_text
|
53
|
+
end
|
54
|
+
|
55
|
+
def save
|
56
|
+
DB.transaction do
|
57
|
+
# Save workflow
|
58
|
+
workflow_record = Ad::AgentArchitecture::Database::Workflow.create(name: @workflow[:name])
|
59
|
+
|
60
|
+
# Save attributes
|
61
|
+
attribute_records = @workflow[:attributes].map do |_name, attr|
|
62
|
+
Ad::AgentArchitecture::Database::Attribute.create(
|
63
|
+
name: attr[:name], type: attr[:type], is_array: attr[:is_array], workflow: workflow_record
|
64
|
+
)
|
65
|
+
end
|
66
|
+
attribute_map = attribute_records.to_h { |ar| [ar.name.to_sym, ar] }
|
67
|
+
|
68
|
+
# Save sections and steps
|
69
|
+
@workflow[:sections].each do |section|
|
70
|
+
section_record = Ad::AgentArchitecture::Database::Section.create(
|
71
|
+
name: section[:name], order: section[:order], workflow: workflow_record
|
72
|
+
)
|
73
|
+
|
74
|
+
section[:steps].each do |step|
|
75
|
+
step_record = Ad::AgentArchitecture::Database::Step.create(
|
76
|
+
name: step[:name], order: step[:order], prompt: step[:prompt], section: section_record
|
77
|
+
)
|
78
|
+
|
79
|
+
step[:input_attributes].each do |attr_name|
|
80
|
+
Ad::AgentArchitecture::Database::InputAttribute.create(
|
81
|
+
step: step_record, attribute: attribute_map[attr_name.to_sym]
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
step[:output_attributes].each do |attr_name|
|
86
|
+
Ad::AgentArchitecture::Database::OutputAttribute.create(
|
87
|
+
step: step_record, attribute: attribute_map[attr_name.to_sym]
|
88
|
+
)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'k_log'
|
4
|
+
|
5
|
+
module Ad
|
6
|
+
module AgentArchitecture
|
7
|
+
module Report
|
8
|
+
# Print workflow details
|
9
|
+
class WorkflowDetailReport
|
10
|
+
include KLog::Logging
|
11
|
+
|
12
|
+
def print(workflow)
|
13
|
+
log.section_heading 'Workflow Details Report'
|
14
|
+
log.kv 'Name', workflow.name
|
15
|
+
log.kv 'Description', workflow.description
|
16
|
+
|
17
|
+
workflow.sections.each do |section|
|
18
|
+
log.section_heading "Section: #{section.name}"
|
19
|
+
log.kv 'Order', section.order
|
20
|
+
section.steps.each do |step|
|
21
|
+
log.section_heading "Step: #{step.name}"
|
22
|
+
log.kv 'Order', step.order
|
23
|
+
log.kv 'Prompt', step.prompt
|
24
|
+
log.kv 'Input Attributes', step.input_attributes.map { |ia| ia.attribute.name }.join(', ')
|
25
|
+
log.kv 'Output Attributes', step.output_attributes.map { |oa| oa.attribute.name }.join(', ')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'k_log'
|
4
|
+
|
5
|
+
module Ad
|
6
|
+
module AgentArchitecture
|
7
|
+
module Report
|
8
|
+
# Print workflow details
|
9
|
+
class WorkflowListReport
|
10
|
+
include KLog::Logging
|
11
|
+
|
12
|
+
def print
|
13
|
+
# tp query, :workflow_name, :workflow_description, :section_name, :section_description, :section_order, :step_name, :step_order, :step_prompt, :inputs, :outputs
|
14
|
+
tp query, :workflow_name, :workflow_description, :section_name, :step_name, :step_prompt, :inputs, :outputs
|
15
|
+
end
|
16
|
+
|
17
|
+
def query
|
18
|
+
Ad::AgentArchitecture::Database::SQLQuery.query(:workflow_details).map do |row|
|
19
|
+
row[:inputs] = JSON.parse(row[:inputs]) if row[:inputs]
|
20
|
+
row[:outputs] = JSON.parse(row[:outputs]) if row[:outputs]
|
21
|
+
row
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
SELECT
|
2
|
+
workflows.id AS workflow_id,
|
3
|
+
workflows.name AS workflow_name,
|
4
|
+
workflows.description AS workflow_description,
|
5
|
+
sections.id AS section_id,
|
6
|
+
sections.name AS section_name,
|
7
|
+
sections.description AS section_description,
|
8
|
+
sections."order" AS section_order,
|
9
|
+
steps.id AS step_id,
|
10
|
+
steps.name AS step_name,
|
11
|
+
steps."order" AS step_order,
|
12
|
+
steps.prompt AS step_prompt,
|
13
|
+
json_group_array(
|
14
|
+
json_object(
|
15
|
+
'name', input_attr.name,
|
16
|
+
'type', input_attr.type,
|
17
|
+
'is_array', input_attr.is_array
|
18
|
+
)
|
19
|
+
) AS inputs,
|
20
|
+
json_group_array(
|
21
|
+
json_object(
|
22
|
+
'name', output_attr.name,
|
23
|
+
'type', output_attr.type,
|
24
|
+
'is_array', output_attr.is_array
|
25
|
+
)
|
26
|
+
) AS outputs
|
27
|
+
FROM workflows
|
28
|
+
LEFT JOIN sections ON workflows.id = sections.workflow_id
|
29
|
+
LEFT JOIN steps ON sections.id = steps.section_id
|
30
|
+
LEFT JOIN input_attributes ON steps.id = input_attributes.step_id
|
31
|
+
LEFT JOIN attributes AS input_attr ON input_attributes.attribute_id = input_attr.id
|
32
|
+
LEFT JOIN output_attributes ON steps.id = output_attributes.step_id
|
33
|
+
LEFT JOIN attributes AS output_attr ON output_attributes.attribute_id = output_attr.id
|
34
|
+
GROUP BY workflows.id, sections.id, steps.id
|
35
|
+
ORDER BY workflows.name, sections."order", steps."order";
|
@@ -2,15 +2,21 @@
|
|
2
2
|
|
3
3
|
require 'sequel'
|
4
4
|
require 'sqlite3'
|
5
|
+
require 'k_log'
|
5
6
|
|
6
7
|
require 'ad/agent_architecture/version'
|
7
|
-
require 'ad/agent_architecture/
|
8
|
+
require 'ad/agent_architecture/database/create_schema'
|
8
9
|
|
9
10
|
DB = Sequel.sqlite
|
10
11
|
|
11
12
|
Ad::AgentArchitecture::Database::CreateSchema.new(DB).execute
|
12
13
|
|
13
|
-
require 'ad/agent_architecture/
|
14
|
+
require 'ad/agent_architecture/database/models'
|
15
|
+
require 'ad/agent_architecture/database/sql_query'
|
16
|
+
require 'ad/agent_architecture/database/save_workflow_graph'
|
17
|
+
require 'ad/agent_architecture/dsl/agent_workflow_dsl'
|
18
|
+
require 'ad/agent_architecture/report/workflow_detail_report'
|
19
|
+
require 'ad/agent_architecture/report/workflow_list_report'
|
14
20
|
|
15
21
|
module Ad
|
16
22
|
module AgentArchitecture
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "ad-agent_architecture",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"lockfileVersion": 3,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "ad-agent_architecture",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.8",
|
10
10
|
"devDependencies": {
|
11
11
|
"@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
|
12
12
|
"@semantic-release/changelog": "^6.0.3",
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ad-agent_architecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: k_log
|
@@ -80,8 +80,14 @@ files:
|
|
80
80
|
- docs/requirements.md
|
81
81
|
- docs/structure-youtube-script.yaml
|
82
82
|
- lib/ad/agent_architecture.rb
|
83
|
-
- lib/ad/agent_architecture/
|
84
|
-
- lib/ad/agent_architecture/
|
83
|
+
- lib/ad/agent_architecture/database/create_schema.rb
|
84
|
+
- lib/ad/agent_architecture/database/models.rb
|
85
|
+
- lib/ad/agent_architecture/database/save_workflow_graph.rb
|
86
|
+
- lib/ad/agent_architecture/database/sql_query.rb
|
87
|
+
- lib/ad/agent_architecture/dsl/agent_workflow_dsl.rb
|
88
|
+
- lib/ad/agent_architecture/report/workflow_detail_report.rb
|
89
|
+
- lib/ad/agent_architecture/report/workflow_list_report.rb
|
90
|
+
- lib/ad/agent_architecture/sql/workflow_details.sql
|
85
91
|
- lib/ad/agent_architecture/version.rb
|
86
92
|
- package-lock.json
|
87
93
|
- package.json
|
File without changes
|