lex-cloudflare 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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +34 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +66 -0
  6. data/CHANGELOG.md +14 -0
  7. data/CLAUDE.md +119 -0
  8. data/Dockerfile +6 -0
  9. data/Gemfile +12 -0
  10. data/LICENSE +21 -0
  11. data/README.md +98 -0
  12. data/lex-cloudflare.gemspec +30 -0
  13. data/lib/legion/extensions/cloudflare/ai/client.rb +29 -0
  14. data/lib/legion/extensions/cloudflare/ai/helpers/client.rb +24 -0
  15. data/lib/legion/extensions/cloudflare/ai/runners/finetunes.rb +40 -0
  16. data/lib/legion/extensions/cloudflare/ai/runners/models.rb +44 -0
  17. data/lib/legion/extensions/cloudflare/ai.rb +15 -0
  18. data/lib/legion/extensions/cloudflare/ai_gateway/client.rb +33 -0
  19. data/lib/legion/extensions/cloudflare/ai_gateway/helpers/client.rb +24 -0
  20. data/lib/legion/extensions/cloudflare/ai_gateway/runners/datasets.rb +44 -0
  21. data/lib/legion/extensions/cloudflare/ai_gateway/runners/evaluations.rb +39 -0
  22. data/lib/legion/extensions/cloudflare/ai_gateway/runners/gateways.rb +44 -0
  23. data/lib/legion/extensions/cloudflare/ai_gateway/runners/logs.rb +49 -0
  24. data/lib/legion/extensions/cloudflare/ai_gateway.rb +17 -0
  25. data/lib/legion/extensions/cloudflare/custom_nameservers/client.rb +27 -0
  26. data/lib/legion/extensions/cloudflare/custom_nameservers/helpers/client.rb +24 -0
  27. data/lib/legion/extensions/cloudflare/custom_nameservers/runners/nameservers.rb +34 -0
  28. data/lib/legion/extensions/cloudflare/custom_nameservers.rb +14 -0
  29. data/lib/legion/extensions/cloudflare/dns/client.rb +29 -0
  30. data/lib/legion/extensions/cloudflare/dns/helpers/client.rb +24 -0
  31. data/lib/legion/extensions/cloudflare/dns/runners/dnssec.rb +33 -0
  32. data/lib/legion/extensions/cloudflare/dns/runners/records.rb +44 -0
  33. data/lib/legion/extensions/cloudflare/dns.rb +15 -0
  34. data/lib/legion/extensions/cloudflare/dns_firewall/client.rb +29 -0
  35. data/lib/legion/extensions/cloudflare/dns_firewall/helpers/client.rb +24 -0
  36. data/lib/legion/extensions/cloudflare/dns_firewall/runners/analytics.rb +42 -0
  37. data/lib/legion/extensions/cloudflare/dns_firewall/runners/clusters.rb +45 -0
  38. data/lib/legion/extensions/cloudflare/dns_firewall.rb +15 -0
  39. data/lib/legion/extensions/cloudflare/ssl/client.rb +29 -0
  40. data/lib/legion/extensions/cloudflare/ssl/helpers/client.rb +24 -0
  41. data/lib/legion/extensions/cloudflare/ssl/runners/certificate_packs.rb +48 -0
  42. data/lib/legion/extensions/cloudflare/ssl/runners/universal.rb +44 -0
  43. data/lib/legion/extensions/cloudflare/ssl.rb +15 -0
  44. data/lib/legion/extensions/cloudflare/vectorize/client.rb +29 -0
  45. data/lib/legion/extensions/cloudflare/vectorize/helpers/client.rb +24 -0
  46. data/lib/legion/extensions/cloudflare/vectorize/runners/indexes.rb +61 -0
  47. data/lib/legion/extensions/cloudflare/vectorize/runners/vectors.rb +49 -0
  48. data/lib/legion/extensions/cloudflare/vectorize.rb +15 -0
  49. data/lib/legion/extensions/cloudflare/version.rb +9 -0
  50. data/lib/legion/extensions/cloudflare/zero_trust/client.rb +33 -0
  51. data/lib/legion/extensions/cloudflare/zero_trust/helpers/client.rb +24 -0
  52. data/lib/legion/extensions/cloudflare/zero_trust/runners/devices.rb +39 -0
  53. data/lib/legion/extensions/cloudflare/zero_trust/runners/dex_tests.rb +44 -0
  54. data/lib/legion/extensions/cloudflare/zero_trust/runners/ip_profiles.rb +44 -0
  55. data/lib/legion/extensions/cloudflare/zero_trust/runners/registrations.rb +44 -0
  56. data/lib/legion/extensions/cloudflare/zero_trust.rb +17 -0
  57. data/lib/legion/extensions/cloudflare.rb +19 -0
  58. metadata +116 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 10d4ff73d6d43881671371d6bd41e48eb3ce5b5d27da18df726acfdbe326125d
4
+ data.tar.gz: e61614b205cf48ac8424c142a56c39cb911e55cf01f7c5a8bf758741044de31a
5
+ SHA512:
6
+ metadata.gz: 81e7b0e09e2e607f0e02a0b9d1e7b4f8232faf1ad2910ebb26505ca273821691d92d2c98f7bf44f57ffaa53e5bb252ab0cba1420a6708ccbe2489da58a8d8223
7
+ data.tar.gz: a8364cf22071c1f4b06a084918161212987eaec0501e4d828dc7c5ee7175b9a1da36498f5bb81982f593fe12dc4e9b092f13858ad7c2afcc3fc13216f5f3204a
@@ -0,0 +1,34 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ schedule:
7
+ - cron: '0 9 * * 1'
8
+
9
+ jobs:
10
+ ci:
11
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
12
+
13
+ lint:
14
+ uses: LegionIO/.github/.github/workflows/lint-patterns.yml@main
15
+
16
+ security:
17
+ uses: LegionIO/.github/.github/workflows/security-scan.yml@main
18
+
19
+ version-changelog:
20
+ uses: LegionIO/.github/.github/workflows/version-changelog.yml@main
21
+
22
+ dependency-review:
23
+ uses: LegionIO/.github/.github/workflows/dependency-review.yml@main
24
+
25
+ stale:
26
+ if: github.event_name == 'schedule'
27
+ uses: LegionIO/.github/.github/workflows/stale.yml@main
28
+
29
+ release:
30
+ needs: [ci, lint]
31
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
32
+ uses: LegionIO/.github/.github/workflows/release.yml@main
33
+ secrets:
34
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,66 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/AbcSize:
31
+ Max: 60
32
+
33
+ Metrics/CyclomaticComplexity:
34
+ Max: 15
35
+
36
+ Metrics/PerceivedComplexity:
37
+ Max: 17
38
+
39
+ Metrics/ParameterLists:
40
+ Max: 10
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
54
+
55
+ Naming/PredicateMethod:
56
+ Enabled: false
57
+
58
+ Naming/PredicatePrefix:
59
+ Enabled: false
60
+
61
+ Gemspec/DevelopmentDependencies:
62
+ Enabled: false
63
+
64
+ Lint/EmptyClass:
65
+ Exclude:
66
+ - 'spec/**/*'
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+ - Initial implementation with Dns, DnsFirewall, CustomNameservers, ZeroTrust, Ssl, Vectorize, AiGateway, and Ai sub-modules
7
+ - Dns: DNS records CRUD and DNSSEC management (zone-scoped)
8
+ - DnsFirewall: cluster CRUD, analytics reports, and reverse DNS (account-scoped)
9
+ - CustomNameservers: account-level custom nameserver management
10
+ - ZeroTrust: devices, registrations, DEX tests, and IP profiles
11
+ - Ssl: certificate packs, universal SSL settings, and verification
12
+ - Vectorize: vector index CRUD, vector operations, and metadata indexing
13
+ - AiGateway: gateway CRUD, log management, datasets, and evaluations
14
+ - Ai: model execution, finetune management, model search, and markdown conversion
data/CLAUDE.md ADDED
@@ -0,0 +1,119 @@
1
+ # lex-cloudflare: Cloudflare Integration for LegionIO
2
+
3
+ **Repository Level 3 Documentation**
4
+ - **Parent**: `/Users/miverso2/rubymine/legion/extensions-other/CLAUDE.md`
5
+ - **Grandparent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
6
+
7
+ ## Purpose
8
+
9
+ Monolith Legion Extension connecting LegionIO to Cloudflare services. Implements 8 sub-modules covering DNS, network security, Zero Trust, SSL, Vectorize, and AI via the Cloudflare REST API v4.
10
+
11
+ **GitHub**: https://github.com/LegionIO/lex-cloudflare
12
+ **License**: MIT
13
+ **Version**: 0.1.0
14
+
15
+ ## Architecture
16
+
17
+ ```
18
+ Legion::Extensions::Cloudflare
19
+ ├── Dns/ # Zone-scoped DNS management
20
+ │ ├── Helpers::Client # Bearer token auth, base URL
21
+ │ ├── Runners::Records # DNS record CRUD (21 types: A, AAAA, CNAME, MX, etc.)
22
+ │ ├── Runners::Dnssec # DNSSEC get/edit/delete
23
+ │ └── Client # initialize(api_token:)
24
+ ├── DnsFirewall/ # Account-scoped DNS Firewall cluster management
25
+ │ ├── Helpers::Client
26
+ │ ├── Runners::Clusters # Cluster CRUD
27
+ │ ├── Runners::Analytics # Report, by-time report, reverse DNS
28
+ │ └── Client
29
+ ├── CustomNameservers/ # Account-scoped custom nameserver management
30
+ │ ├── Helpers::Client
31
+ │ ├── Runners::Nameservers # List, add, delete
32
+ │ └── Client
33
+ ├── ZeroTrust/ # Account-scoped Zero Trust device management
34
+ │ ├── Helpers::Client
35
+ │ ├── Runners::Devices # Physical device list/get/delete/revoke
36
+ │ ├── Runners::Registrations # WARP registration management
37
+ │ ├── Runners::DexTests # DEX test CRUD
38
+ │ ├── Runners::IpProfiles # IP profile CRUD
39
+ │ └── Client
40
+ ├── Ssl/ # Zone-scoped SSL/TLS certificate management
41
+ │ ├── Helpers::Client
42
+ │ ├── Runners::CertificatePacks # Pack CRUD, order, quota
43
+ │ ├── Runners::Universal # Universal SSL settings, recommendations, verification
44
+ │ └── Client
45
+ ├── Vectorize/ # Account-scoped Vectorize index management
46
+ │ ├── Helpers::Client
47
+ │ ├── Runners::Indexes # Index CRUD, info, metadata indexing
48
+ │ ├── Runners::Vectors # Insert, upsert, query, get_by_ids, delete_by_ids
49
+ │ └── Client
50
+ ├── AiGateway/ # Account-scoped AI Gateway management
51
+ │ ├── Helpers::Client
52
+ │ ├── Runners::Gateways # Gateway CRUD
53
+ │ ├── Runners::Logs # Log list/get/patch/delete, request/response retrieval
54
+ │ ├── Runners::Datasets # Dataset CRUD
55
+ │ ├── Runners::Evaluations # Evaluation CRUD
56
+ │ └── Client
57
+ └── Ai/ # Account-scoped Workers AI
58
+ ├── Helpers::Client
59
+ ├── Runners::Models # Model execution, search, schema, markdown conversion
60
+ ├── Runners::Finetunes # Finetune management, public listing
61
+ └── Client
62
+ ```
63
+
64
+ ## Key Files
65
+
66
+ | Path | Purpose |
67
+ |------|---------|
68
+ | `lib/legion/extensions/cloudflare.rb` | Entry point, loads all sub-modules |
69
+ | `lib/legion/extensions/cloudflare/dns/client.rb` | DNS client: `initialize(api_token:)` |
70
+ | `lib/legion/extensions/cloudflare/vectorize/client.rb` | Vectorize client: `initialize(api_token:)` |
71
+ | `lib/legion/extensions/cloudflare/ai/client.rb` | AI client: `initialize(api_token:)` |
72
+
73
+ ## Auth Pattern
74
+
75
+ All sub-modules use Bearer token authentication:
76
+ ```ruby
77
+ conn.headers['Authorization'] = "Bearer #{api_token}"
78
+ ```
79
+ Base URL: `https://api.cloudflare.com/client/v4`
80
+
81
+ ## Resource Scoping
82
+
83
+ | Scope | Sub-modules | Path pattern |
84
+ |-------|-------------|--------------|
85
+ | Zone | Dns, Ssl | `/zones/{zone_id}/...` |
86
+ | Account | DnsFirewall, CustomNameservers, ZeroTrust, Vectorize, AiGateway, Ai | `/accounts/{account_id}/...` |
87
+
88
+ ## API Coverage
89
+
90
+ | Sub-module | Runners | Key Methods |
91
+ |-----------|---------|-------------|
92
+ | Dns | Records, Dnssec | `list`, `get`, `create`, `update`, `delete`, `get_dnssec`, `edit_dnssec` |
93
+ | DnsFirewall | Clusters, Analytics | `list`, `get`, `create`, `update`, `delete`, `report`, `report_by_time`, `get_reverse_dns` |
94
+ | CustomNameservers | Nameservers | `list`, `add`, `delete` |
95
+ | ZeroTrust | Devices, Registrations, DexTests, IpProfiles | `list_devices`, `revoke_device`, `list_registrations`, `list_dex_tests`, `list_ip_profiles` |
96
+ | Ssl | CertificatePacks, Universal | `list_packs`, `order_pack`, `quota`, `get_universal_settings`, `list_verification` |
97
+ | Vectorize | Indexes, Vectors | `list_indexes`, `create_index`, `query`, `insert`, `upsert`, `get_by_ids`, `list_metadata_indexes` |
98
+ | AiGateway | Gateways, Logs, Datasets, Evaluations | `list_gateways`, `create_gateway`, `list_logs`, `patch_log`, `list_datasets`, `list_evaluations` |
99
+ | Ai | Models, Finetunes | `run`, `search_models`, `model_schema`, `to_markdown`, `list_finetunes`, `create_finetune` |
100
+
101
+ ## Dependencies
102
+
103
+ | Gem | Purpose |
104
+ |-----|---------|
105
+ | `faraday` (>= 2.0) | HTTP client for all Cloudflare REST API calls |
106
+
107
+ ## Development
108
+
109
+ 120 specs total (0 failures).
110
+
111
+ ```bash
112
+ bundle install
113
+ bundle exec rspec
114
+ bundle exec rubocop
115
+ ```
116
+
117
+ ---
118
+
119
+ **Maintained By**: Matthew Iverson (@Esity)
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM legionio/legion
2
+
3
+ COPY . /usr/src/app/lex-cloudflare
4
+
5
+ WORKDIR /usr/src/app/lex-cloudflare
6
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'simplecov'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Esity
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,98 @@
1
+ # lex-cloudflare
2
+
3
+ Cloudflare integration for [LegionIO](https://github.com/LegionIO/LegionIO). Provides runners for DNS, DNS Firewall, Custom Nameservers, Zero Trust, SSL, Vectorize, AI Gateway, and Workers AI via the Cloudflare REST API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install lex-cloudflare
9
+ ```
10
+
11
+ ## Sub-modules
12
+
13
+ ### Dns
14
+ DNS records and DNSSEC management for a zone.
15
+
16
+ ```ruby
17
+ client = Legion::Extensions::Cloudflare::Dns::Client.new(api_token: 'your-token')
18
+ client.list(zone_id: 'abc123')
19
+ client.create(zone_id: 'abc123', body: { type: 'A', name: 'example.com', content: '1.2.3.4', ttl: 3600 })
20
+ client.get_dnssec(zone_id: 'abc123')
21
+ ```
22
+
23
+ ### DnsFirewall
24
+ DNS Firewall cluster management and analytics (account-scoped).
25
+
26
+ ```ruby
27
+ client = Legion::Extensions::Cloudflare::DnsFirewall::Client.new(api_token: 'your-token')
28
+ client.list(account_id: 'acct123')
29
+ client.create(account_id: 'acct123', name: 'my-cluster', upstream_ips: ['1.2.3.4'])
30
+ client.report(account_id: 'acct123', dns_firewall_id: 'fw123')
31
+ ```
32
+
33
+ ### CustomNameservers
34
+ Account-level custom nameserver management.
35
+
36
+ ```ruby
37
+ client = Legion::Extensions::Cloudflare::CustomNameservers::Client.new(api_token: 'your-token')
38
+ client.list(account_id: 'acct123')
39
+ client.add(account_id: 'acct123', ns_name: 'ns1.example.com')
40
+ ```
41
+
42
+ ### ZeroTrust
43
+ Devices, registrations, DEX tests, and IP profiles.
44
+
45
+ ```ruby
46
+ client = Legion::Extensions::Cloudflare::ZeroTrust::Client.new(api_token: 'your-token')
47
+ client.list_devices(account_id: 'acct123')
48
+ client.list_registrations(account_id: 'acct123')
49
+ client.list_dex_tests(account_id: 'acct123')
50
+ ```
51
+
52
+ ### Ssl
53
+ Certificate packs, universal SSL settings, and verification.
54
+
55
+ ```ruby
56
+ client = Legion::Extensions::Cloudflare::Ssl::Client.new(api_token: 'your-token')
57
+ client.list_packs(zone_id: 'zone123')
58
+ client.get_universal_settings(zone_id: 'zone123')
59
+ ```
60
+
61
+ ### Vectorize
62
+ Vector index management and vector operations.
63
+
64
+ ```ruby
65
+ client = Legion::Extensions::Cloudflare::Vectorize::Client.new(api_token: 'your-token')
66
+ client.list_indexes(account_id: 'acct123')
67
+ client.create_index(account_id: 'acct123', name: 'my-index', config: { dimensions: 1536, metric: 'cosine' })
68
+ client.query(account_id: 'acct123', index_name: 'my-index', vector: [0.1, 0.2, ...], top_k: 5)
69
+ ```
70
+
71
+ ### AiGateway
72
+ AI Gateway management, log inspection, datasets, and evaluations.
73
+
74
+ ```ruby
75
+ client = Legion::Extensions::Cloudflare::AiGateway::Client.new(api_token: 'your-token')
76
+ client.list_gateways(account_id: 'acct123')
77
+ client.list_logs(account_id: 'acct123', gateway_id: 'gw123')
78
+ ```
79
+
80
+ ### Ai
81
+ Workers AI model execution, finetune management, and model search.
82
+
83
+ ```ruby
84
+ client = Legion::Extensions::Cloudflare::Ai::Client.new(api_token: 'your-token')
85
+ client.run(account_id: 'acct123', model_name: '@cf/meta/llama-3-8b-instruct', body: { prompt: 'Hello' })
86
+ client.list_finetunes(account_id: 'acct123')
87
+ client.search_models(account_id: 'acct123', search: 'llama')
88
+ ```
89
+
90
+ ## Requirements
91
+
92
+ - Ruby >= 3.4
93
+ - [LegionIO](https://github.com/LegionIO/LegionIO) framework
94
+ - Cloudflare API token with appropriate permissions
95
+
96
+ ## License
97
+
98
+ MIT
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/cloudflare/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-cloudflare'
7
+ spec.version = Legion::Extensions::Cloudflare::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX Cloudflare'
12
+ spec.description = 'Connects LegionIO to Cloudflare services'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-cloudflare'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-cloudflare'
19
+ spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-cloudflare'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-cloudflare/blob/main/CHANGELOG.md'
21
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-cloudflare/issues'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '>= 2.0'
30
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers/client'
4
+ require_relative 'runners/models'
5
+ require_relative 'runners/finetunes'
6
+
7
+ module Legion
8
+ module Extensions
9
+ module Cloudflare
10
+ module Ai
11
+ class Client
12
+ include Helpers::Client
13
+ include Runners::Models
14
+ include Runners::Finetunes
15
+
16
+ attr_reader :opts
17
+
18
+ def initialize(api_token:, **extra)
19
+ @opts = { api_token: api_token, **extra }.compact
20
+ end
21
+
22
+ def client(**override)
23
+ super(**@opts, **override)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Cloudflare
8
+ module Ai
9
+ module Helpers
10
+ module Client
11
+ def client(api_token:, **)
12
+ Faraday.new(url: 'https://api.cloudflare.com/client/v4') do |conn|
13
+ conn.request :json
14
+ conn.response :json, content_type: /\bjson$/
15
+ conn.headers['Content-Type'] = 'application/json'
16
+ conn.headers['Authorization'] = "Bearer #{api_token}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Cloudflare
6
+ module Ai
7
+ module Runners
8
+ module Finetunes
9
+ extend Legion::Extensions::Cloudflare::Ai::Helpers::Client
10
+
11
+ def list_finetunes(account_id:, **)
12
+ response = client(**).get("/accounts/#{account_id}/ai/finetunes")
13
+ { result: response.body, status: response.status }
14
+ end
15
+
16
+ def create_finetune(account_id:, model:, name:, description: nil, public: nil, **)
17
+ body = { model: model, name: name, description: description, public: public }.compact
18
+ response = client(**).post("/accounts/#{account_id}/ai/finetunes", body)
19
+ { result: response.body, status: response.status }
20
+ end
21
+
22
+ def upload_finetune_asset(account_id:, finetune_id:, body:, **)
23
+ response = client(**).post("/accounts/#{account_id}/ai/finetunes/#{finetune_id}/finetune-assets", body)
24
+ { result: response.body, status: response.status }
25
+ end
26
+
27
+ def list_public_finetunes(account_id:, limit: nil, offset: nil, **)
28
+ params = { limit: limit, offset: offset }.compact
29
+ response = client(**).get("/accounts/#{account_id}/ai/finetunes/public", params)
30
+ { result: response.body, status: response.status }
31
+ end
32
+
33
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
34
+ Legion::Extensions::Helpers.const_defined?(:Lex)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Cloudflare
6
+ module Ai
7
+ module Runners
8
+ module Models
9
+ extend Legion::Extensions::Cloudflare::Ai::Helpers::Client
10
+
11
+ def run(account_id:, model_name:, body:, **)
12
+ response = client(**).post("/accounts/#{account_id}/ai/run/#{model_name}", body)
13
+ { result: response.body, status: response.status }
14
+ end
15
+
16
+ def search_models(account_id:, search: nil, author: nil, task: nil, page: nil, per_page: nil, **)
17
+ params = { search: search, author: author, task: task, page: page, per_page: per_page }.compact
18
+ response = client(**).get("/accounts/#{account_id}/ai/models/search", params)
19
+ { result: response.body, status: response.status }
20
+ end
21
+
22
+ def model_schema(account_id:, model:, **)
23
+ response = client(**).get("/accounts/#{account_id}/ai/models/schema", { model: model })
24
+ { result: response.body, status: response.status }
25
+ end
26
+
27
+ def to_markdown(account_id:, body:, **)
28
+ response = client(**).post("/accounts/#{account_id}/ai/tomarkdown", body)
29
+ { result: response.body, status: response.status }
30
+ end
31
+
32
+ def supported_markdown_formats(account_id:, **)
33
+ response = client(**).get("/accounts/#{account_id}/ai/tomarkdown/supported")
34
+ { result: response.body, status: response.status }
35
+ end
36
+
37
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
38
+ Legion::Extensions::Helpers.const_defined?(:Lex)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/cloudflare/ai/helpers/client'
4
+ require 'legion/extensions/cloudflare/ai/runners/models'
5
+ require 'legion/extensions/cloudflare/ai/runners/finetunes'
6
+ require 'legion/extensions/cloudflare/ai/client'
7
+
8
+ module Legion
9
+ module Extensions
10
+ module Cloudflare
11
+ module Ai
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers/client'
4
+ require_relative 'runners/gateways'
5
+ require_relative 'runners/logs'
6
+ require_relative 'runners/datasets'
7
+ require_relative 'runners/evaluations'
8
+
9
+ module Legion
10
+ module Extensions
11
+ module Cloudflare
12
+ module AiGateway
13
+ class Client
14
+ include Helpers::Client
15
+ include Runners::Gateways
16
+ include Runners::Logs
17
+ include Runners::Datasets
18
+ include Runners::Evaluations
19
+
20
+ attr_reader :opts
21
+
22
+ def initialize(api_token:, **extra)
23
+ @opts = { api_token: api_token, **extra }.compact
24
+ end
25
+
26
+ def client(**override)
27
+ super(**@opts, **override)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Cloudflare
8
+ module AiGateway
9
+ module Helpers
10
+ module Client
11
+ def client(api_token:, **)
12
+ Faraday.new(url: 'https://api.cloudflare.com/client/v4') do |conn|
13
+ conn.request :json
14
+ conn.response :json, content_type: /\bjson$/
15
+ conn.headers['Content-Type'] = 'application/json'
16
+ conn.headers['Authorization'] = "Bearer #{api_token}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end