asimov-construct 25.0.0.dev.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f09cf8be0e11508993dc700df0149b4312b251609797bcb8400562dfc9ae01b8
4
+ data.tar.gz: 8f98eb8c3f2cc0775ee6de54f2c3a233ed28ecc58a77a37012b9ca80e597d9ff
5
+ SHA512:
6
+ metadata.gz: 44adbfe80ee860e5f8c0e4898fb9136081cdc4f23d6c5b0623f89abef8e160418c73cb12ee631a37fd433951fb8c6f2be2c4948c8a40a6d10afd066575f83827
7
+ data.tar.gz: 36b0f7adfa50f580a023997e3562354d8cd85ceea3c95147d449cc2626194cf877476cb6d337581f7a496df76889315b4101fffcbbca649fa96eb75269c4bf44
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ * Arto Bendiken <arto@asimov.so>
data/CHANGES.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## 25.0.0.dev.4 - 2025-02-15
9
+
10
+ ## 25.0.0.dev.3 - 2025-02-15
11
+
12
+ ## 25.0.0.dev.2 - 2025-02-15
13
+
14
+ ## 25.0.0.dev.1 - 2025-02-12
15
+
16
+ ## 25.0.0.dev.0 - 2025-02-11
17
+
18
+ ## 24.0.0.dev.0 - 2024-06-26
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # ASIMOV Software Development Kit (SDK) for Ruby
2
+
3
+ [![License](https://img.shields.io/badge/license-Public%20Domain-blue.svg)](https://unlicense.org)
4
+ [![Compatibility](https://img.shields.io/badge/ruby-3.2%2B-blue)](https://rubygems.org/gems/asimov.rb)
5
+ [![Package](https://img.shields.io/gem/v/asimov.rb)](https://rubygems.org/gems/asimov.rb)
6
+ [![Documentation](https://img.shields.io/badge/rubydoc-latest-blue)](https://rubydoc.info/gems/asimov.rb)
7
+
8
+ 🚧 _We are building in public. This is presently under heavy construction._
9
+
10
+ ## ✨ Features
11
+
12
+ - 100% free and unencumbered public domain software.
13
+
14
+ ## 🛠️ Prerequisites
15
+
16
+ - [Ruby] 3.2+
17
+
18
+ ## ⬇️ Installation
19
+
20
+ ### Installation via RubyGems
21
+
22
+ ```bash
23
+ gem install asimov.rb --pre
24
+ ```
25
+
26
+ ## 👉 Examples
27
+
28
+ - [Importing the SDK](#importing-the-sdk)
29
+
30
+ ### Importing the SDK
31
+
32
+ ```ruby
33
+ require 'asimov'
34
+ ```
35
+
36
+ ## 📚 Reference
37
+
38
+ https://rubydoc.info/gems/asimov.rb
39
+
40
+ ## 👨‍💻 Development
41
+
42
+ ```bash
43
+ git clone https://github.com/asimov-platform/asimov.rb.git
44
+ ```
45
+
46
+ - - -
47
+
48
+ [![Share on Twitter](https://img.shields.io/badge/share%20on-twitter-03A9F4?logo=twitter)](https://twitter.com/share?url=https://github.com/asimov-platform/asimov.rb&text=ASIMOV%20Software%20Development%20Kit%20%28SDK%29%20for%20Ruby)
49
+ [![Share on Reddit](https://img.shields.io/badge/share%20on-reddit-red?logo=reddit)](https://reddit.com/submit?url=https://github.com/asimov-platform/asimov.rb&title=ASIMOV%20Software%20Development%20Kit%20%28SDK%29%20for%20Ruby)
50
+ [![Share on Hacker News](https://img.shields.io/badge/share%20on-hacker%20news-orange?logo=ycombinator)](https://news.ycombinator.com/submitlink?u=https://github.com/asimov-platform/asimov.rb&t=ASIMOV%20Software%20Development%20Kit%20%28SDK%29%20for%20Ruby)
51
+ [![Share on Facebook](https://img.shields.io/badge/share%20on-facebook-1976D2?logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/asimov-platform/asimov.rb)
52
+
53
+ [Ruby]: https://ruby-lang.org
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org/>
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 25.0.0.dev.4
@@ -0,0 +1,215 @@
1
+ # This is free and unencumbered software released into the public domain.
2
+
3
+ require "asimov/config"
4
+ require "kdl"
5
+ require "pathname"
6
+
7
+ class KDL::Document
8
+ def deconstruct
9
+ self.nodes
10
+ end
11
+
12
+ def deconstruct_keys(keys)
13
+ keys.inject({}) do |result, key|
14
+ result[key] = self[key]
15
+ result
16
+ end
17
+ end
18
+ end # KDL::Document
19
+
20
+ class KDL::Node
21
+ def deconstruct
22
+ self.children
23
+ end
24
+
25
+ def deconstruct_keys(keys)
26
+ {name:, arguments:, properties:, children:, type:}
27
+ end
28
+ end # KDL::Node
29
+
30
+ class ASIMOV::Construct
31
+ ##
32
+ # @example
33
+ # p ASIMOV::Construct.count
34
+ #
35
+ # @return [Integer]
36
+ def self.count
37
+ self.each.count
38
+ end
39
+
40
+ ##
41
+ # @example
42
+ # p ASIMOV::Construct.ids
43
+ #
44
+ # @return [Array<String>]
45
+ def self.ids
46
+ self.each.map(&:id).to_a
47
+ end
48
+
49
+ ##
50
+ # @example
51
+ # ASIMOV::Construct.list(prefix: "isaac") do |construct|
52
+ # puts construct.name
53
+ # end
54
+ #
55
+ # @example
56
+ # p ASIMOV::Construct.list(prefix: "isaac").to_a
57
+ #
58
+ # @param [String, #to_s] prefix
59
+ # @yield [construct]
60
+ # @yieldparam [ASIMOV::Construct] construct
61
+ # @yieldreturn [void]
62
+ # @return [Enumerator] if no block was given
63
+ def self.list(prefix: nil, &block)
64
+ return enum_for(__method__, prefix:) unless block_given?
65
+ result = self.each
66
+ result = result.filter { _1.id.start_with?(prefix.to_s) } if prefix
67
+ result.each(&block)
68
+ end
69
+
70
+ ##
71
+ # @example
72
+ # ASIMOV::Construct.each do |construct|
73
+ # puts construct.name
74
+ # end
75
+ #
76
+ # @yield [construct]
77
+ # @yieldparam [ASIMOV::Construct] construct
78
+ # @yieldreturn [void]
79
+ # @return [Enumerator] if no block was given
80
+ def self.each(&block)
81
+ return enum_for(__method__) unless block_given?
82
+ construct_dirs = ASIMOV::Config.each_construct_dir.to_a
83
+ construct_dirs.filter! { _1.join("construct.kdl").readable? }
84
+ construct_dirs.sort_by!(&:basename).each do |construct_path|
85
+ block.call(self.parse(construct_path))
86
+ end
87
+ end
88
+
89
+ ##
90
+ # @example
91
+ # ASIMOV::Construct.open("isaac.asimov") do |construct|
92
+ # puts construct.system_prompt
93
+ # end
94
+ #
95
+ # @param [String, #to_s] id
96
+ # @yield [construct]
97
+ # @yieldparam [ASIMOV::Construct] construct
98
+ # @yieldreturn [Object]
99
+ # @return [ASIMOV::Construct] or `nil` if the construct does not exist
100
+ def self.open(id, &block)
101
+ id = id.is_a?(self.class) ? id.id : id.to_s
102
+ result = self.parse(ASIMOV::Config.constructs_dir.join(id))
103
+ result = block.call(result) if block_given?
104
+ result
105
+ rescue Errno::ENOENT => error
106
+ nil
107
+ end
108
+
109
+ ##
110
+ # @example
111
+ # ASIMOV::Construct.parse("asimov-constructs/isaac.asimov")
112
+ #
113
+ # @param [Pathname, #to_s] path
114
+ # @return [ASIMOV::Construct]
115
+ def self.parse(path)
116
+ manifest_path = Pathname(path).join("construct.kdl")
117
+ manifest = KDL.load_file(manifest_path)
118
+ construct_kwargs = case manifest
119
+ in [{name: "construct", arguments: [construct_id], children:}]
120
+ children.inject({}) do |kwargs, node|
121
+ case node
122
+ in {name: "name", children:}
123
+ kwargs[:names] = children.inject({}) do |result, node|
124
+ result[node.name.to_sym] = node.arguments&.first&.value
125
+ result
126
+ end
127
+ in {name: "links", children:}
128
+ kwargs[:links] = children.inject({}) do |result, node|
129
+ result[node.name.to_sym] = node.arguments&.first&.value
130
+ result
131
+ end
132
+ end
133
+ kwargs
134
+ end
135
+ else
136
+ raise ArgumentError, "invalid construct manifest: #{manifest_path}"
137
+ end
138
+ self.new(construct_id, path:, **construct_kwargs)
139
+ end
140
+
141
+ ##
142
+ # @param [String, #to_s] id
143
+ # @param [Pathname] path
144
+ # @param [Hash{Symbol => String}, #to_h] names
145
+ # @param [Hash{Symbol => String}, #to_h] links
146
+ def initialize(id, path: nil, names: {}, links: {})
147
+ @id = id.to_s.freeze
148
+ @path = path ? Pathname(path).freeze : nil
149
+ @names = (names || {en: @id}).to_h.freeze
150
+ @links = (links || {}).to_h.freeze
151
+ end
152
+
153
+ ##
154
+ # @return [String]
155
+ attr_reader :id
156
+
157
+ ##
158
+ # @return [Pathname]
159
+ attr_reader :path
160
+
161
+ ##
162
+ # @return [String]
163
+ attr_reader :name
164
+ def name; self.names[:en]; end
165
+
166
+ ##
167
+ # @return [Hash{Symbol => String}]
168
+ attr_reader :names
169
+
170
+ ##
171
+ # @return [Hash{Symbol => String}]
172
+ attr_reader :links
173
+
174
+ ##
175
+ # @return [String]
176
+ def system_prompt
177
+ self.path.join("system.md").read.strip rescue nil
178
+ end
179
+
180
+ ##
181
+ # @return [String]
182
+ def to_h
183
+ {id:, names:, links:}
184
+ end
185
+
186
+ ##
187
+ # @return [KDL::Document]
188
+ def to_kdl
189
+ require "kdl"
190
+ KDL::Document.new([
191
+ KDL::Node.new("construct", arguments: [self.id], children: [
192
+ KDL::Node.new("name", children: self.names.map do |k, v|
193
+ KDL::Node.new(k.to_s, arguments: [v])
194
+ end),
195
+ KDL::Node.new("links", children: self.links.map do |k, v|
196
+ KDL::Node.new(k.to_s, arguments: [v])
197
+ end),
198
+ ]),
199
+ ])
200
+ end
201
+
202
+ ##
203
+ # @return [String]
204
+ def to_json
205
+ require "json"
206
+ JSON.pretty_generate(self.to_h)
207
+ end
208
+
209
+ ##
210
+ # @return [String]
211
+ def to_yaml
212
+ require "yaml"
213
+ YAML.dump(self.to_h, stringify_names: true)
214
+ end
215
+ end # ASIMOV::Construct
@@ -0,0 +1,3 @@
1
+ # This is free and unencumbered software released into the public domain.
2
+
3
+ require_relative "asimov/construct"
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asimov-construct
3
+ version: !ruby/object:Gem::Version
4
+ version: 25.0.0.dev.4
5
+ platform: ruby
6
+ authors:
7
+ - ASIMOV Protocol
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-02-15 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rake
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '13'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '13'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '3.12'
40
+ - !ruby/object:Gem::Dependency
41
+ name: yard
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ - !ruby/object:Gem::Dependency
55
+ name: asimov-config
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '='
59
+ - !ruby/object:Gem::Version
60
+ version: 25.0.0.dev.4
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '='
66
+ - !ruby/object:Gem::Version
67
+ version: 25.0.0.dev.4
68
+ - !ruby/object:Gem::Dependency
69
+ name: kdl
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.0'
82
+ description: ''
83
+ email: support@asimov.so
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - AUTHORS
89
+ - CHANGES.md
90
+ - README.md
91
+ - UNLICENSE
92
+ - VERSION
93
+ - lib/asimov-construct.rb
94
+ - lib/asimov/construct.rb
95
+ homepage: https://sdk.asimov.so
96
+ licenses:
97
+ - Unlicense
98
+ metadata:
99
+ bug_tracker_uri: https://github.com/asimov-platform/asimov.rb/issues
100
+ changelog_uri: https://github.com/asimov-platform/asimov.rb/blob/master/CHANGES.md
101
+ documentation_uri: https://rubydoc.info/gems/asimov-construct
102
+ homepage_uri: https://sdk.asimov.so
103
+ source_code_uri: https://github.com/asimov-platform/asimov.rb
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '3.2'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.6.2
119
+ specification_version: 4
120
+ summary: ASIMOV Software Development Kit (SDK) for Ruby
121
+ test_files: []