elelem-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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bc02a2f7ad2f91c310c988b3a6c45f5872a1e51f23495bc54a660ff0e1efd641
4
+ data.tar.gz: 0a17f88abb1b82426ca2707fad572174a24e16d9b5e9d8da5c8ed0e7d99685ad
5
+ SHA512:
6
+ metadata.gz: 5890629e4a145168cecd9ba092c2eda66ba54a3078820e987745103556ac157d88d23e84ded1a30c4c52dd7b6bcd9eabb79c942f15436a0246ec5f2775232ad7
7
+ data.tar.gz: 9a21533a799c5d9563b04d04bf99b1713bef3860d3dcaa161553cc90e36622d0a9c8be4da67e29a75e1a556d17bf95f09e292595485c0300e976a7b6dc8f0243
@@ -0,0 +1,74 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ permissions: {}
9
+
10
+ concurrency:
11
+ group: release
12
+ cancel-in-progress: false
13
+
14
+ jobs:
15
+ test:
16
+ runs-on: ubuntu-latest
17
+ permissions:
18
+ contents: read
19
+ steps:
20
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
21
+ with:
22
+ persist-credentials: false
23
+ - uses: ruby/setup-ruby@3ff19f5e2baf30647122352b96108b1fbe250c64 # v1.299.0
24
+ with:
25
+ ruby-version: "4.0"
26
+ bundler-cache: true
27
+ - run: bin/test
28
+ - run: bin/lint
29
+
30
+ release-please:
31
+ needs: test
32
+ runs-on: ubuntu-latest
33
+ permissions:
34
+ contents: write
35
+ issues: write
36
+ pull-requests: write
37
+ outputs:
38
+ release_created: ${{ steps.release.outputs.release_created }}
39
+ steps:
40
+ - id: release
41
+ uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
42
+ with:
43
+ config-file: release-please-config.json
44
+ manifest-file: .release-please-manifest.json
45
+ target-branch: main
46
+
47
+ publish:
48
+ needs: release-please
49
+ if: needs.release-please.outputs.release_created == 'true'
50
+ runs-on: ubuntu-latest
51
+ permissions:
52
+ contents: write
53
+ id-token: write
54
+ steps:
55
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
56
+ with:
57
+ persist-credentials: false
58
+ - uses: ruby/setup-ruby@3ff19f5e2baf30647122352b96108b1fbe250c64 # v1.299.0
59
+ with:
60
+ ruby-version: "4.0"
61
+ bundler-cache: true
62
+ - shell: bash
63
+ run: |
64
+ set -euo pipefail
65
+ jwt=$(curl -sS --fail-with-body -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=rubygems.org" | jq -r .value)
66
+ echo "::add-mask::$jwt"
67
+ key=$(jq -n --arg jwt "$jwt" '{jwt: $jwt, owner: "66898"}' | curl -sS --fail-with-body -H "content-type: application/json" -d @- https://rubygems.org/api/v1/oidc/trusted_publisher/exchange_token | jq -r .rubygems_api_key)
68
+ test -n "$key" -a "$key" != null
69
+ echo "::add-mask::$key"
70
+ printf 'GEM_HOST_API_KEY=%s\nBUNDLE_GEM__PUSH_KEY=%s\nRUBYGEMS_API_KEY=%s\n' "$key" "$key" "$key" >> "$GITHUB_ENV"
71
+ - uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1
72
+ with:
73
+ setup-trusted-publisher: false
74
+ await-release: false
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.1.0"
3
+ }
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,62 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 4.0
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - "pkg/**/*"
7
+ - "bin/**/*"
8
+ - "vendor/**/*"
9
+ - "fixtures/**/*"
10
+
11
+ Metrics:
12
+ Enabled: false
13
+
14
+ Naming/PredicateMethod:
15
+ AllowedMethods:
16
+ - call
17
+ - run
18
+ - summarize
19
+ - prompt
20
+
21
+ Naming/MethodParameterName:
22
+ AllowedNames:
23
+ - me
24
+ - id
25
+ - as
26
+ - io
27
+
28
+ Style/GlobalVars:
29
+ Exclude:
30
+ - "spec/**/*"
31
+
32
+ Lint/EmptyBlock:
33
+ Exclude:
34
+ - "spec/**/*"
35
+
36
+ Lint/UselessDefaultValueArgument:
37
+ Enabled: false
38
+
39
+ Lint/RedundantRequireStatement:
40
+ Enabled: false
41
+
42
+ Lint/UnusedBlockArgument:
43
+ IgnoreEmptyBlocks: true
44
+ AllowUnusedKeywordArguments: true
45
+
46
+ Style/Documentation:
47
+ Enabled: false
48
+
49
+ Style/FormatStringToken:
50
+ Enabled: false
51
+
52
+ Style/FrozenStringLiteralComment:
53
+ Enabled: true
54
+
55
+ Style/StringLiterals:
56
+ EnforcedStyle: double_quotes
57
+
58
+ Style/StringLiteralsInInterpolation:
59
+ EnforcedStyle: double_quotes
60
+
61
+ Layout/LineLength:
62
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-11-16)
4
+
5
+
6
+ ### Features
7
+
8
+ * elelem-cloudflare connects elelem to Cloudflare Workers AI through elelem-openai ([b4f4c25](https://github.com/elelem-sh/cloudflare/commit/b4f4c250d7a92bee6dceb6db2be029aedf364db0))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * require elelem-openai 0.3, which takes a base url with a trailing slash ([ada49d8](https://github.com/elelem-sh/cloudflare/commit/ada49d8977ff8e58b6053d412f1dd1ef76ae5e25))
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 mo khan
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,52 @@
1
+ # elelem-cloudflare
2
+
3
+ A [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) provider plugin for [elelem](https://elelem.sh).
4
+ It talks to Workers AI's OpenAI-compatible Chat Completions API
5
+ through [elelem-openai](https://github.com/elelem-sh/openai).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ gem install elelem-cloudflare
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```sh
16
+ export CLOUDFLARE_API_TOKEN=...
17
+ export CLOUDFLARE_ACCOUNT_ID=...
18
+ elelem -p cloudflare --model @cf/meta/llama-3.3-70b-instruct-fp8-fast
19
+ ```
20
+
21
+ * `CLOUDFLARE_API_TOKEN` (required): a Workers AI API token.
22
+ * `CLOUDFLARE_ACCOUNT_ID` (required unless `CLOUDFLARE_BASE_URL` is set): your account ID.
23
+ * `CLOUDFLARE_MODEL`: the model, when `--model` is not given
24
+ * `CLOUDFLARE_BASE_URL`: overrides `https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1`
25
+
26
+ Get both values on the Workers AI page of the dashboard, under **Use REST API**:
27
+ https://developers.cloudflare.com/workers-ai/get-started/rest-api/#1-get-api-token-and-account-id
28
+
29
+ A token you create yourself needs `Workers AI - Read` and `Workers AI - Edit`:
30
+ https://developers.cloudflare.com/fundamentals/api/get-started/create-token/
31
+
32
+ To find the account ID: https://developers.cloudflare.com/fundamentals/account/find-account-and-zone-ids/
33
+
34
+ Models: https://developers.cloudflare.com/workers-ai/models/
35
+
36
+ There is no default model, since free model lists change often. With
37
+ no model set, elelem stops and names `CLOUDFLARE_MODEL`. A variable that is
38
+ set but empty counts as unset.
39
+
40
+ Free tier limits are on Cloudflare's own page: https://developers.cloudflare.com/workers-ai/platform/limits/
41
+
42
+ ## Development
43
+
44
+ ```sh
45
+ bin/setup
46
+ bin/test
47
+ bin/lint
48
+ ```
49
+
50
+ ## License
51
+
52
+ MIT. See LICENSE.txt.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "elelem/cli"
5
+
6
+ Signal.trap("INT") { exit 1 }
7
+
8
+ Elelem::CLI.new(ARGV, provider: "cloudflare").run
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Elelem
4
+ module Cloudflare
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "elelem/openai"
4
+
5
+ require_relative "cloudflare/version"
6
+
7
+ Elelem.configure do |config|
8
+ config.provider(:cloudflare) do |model: nil, **|
9
+ # A variable that is set but empty counts as unset.
10
+ env = ->(name) { ENV[name].to_s.strip.then { |v| v.empty? ? nil : v } }
11
+ key = env.call("CLOUDFLARE_API_TOKEN")
12
+ raise KeyError, "CLOUDFLARE_API_TOKEN is not set" if key.nil?
13
+
14
+ model = env.call("CLOUDFLARE_MODEL") if model.to_s.strip.empty?
15
+ raise KeyError, "CLOUDFLARE_MODEL is not set. Pass --model or set CLOUDFLARE_MODEL" if model.nil?
16
+
17
+ base_url = env.call("CLOUDFLARE_BASE_URL") || begin
18
+ account = env.call("CLOUDFLARE_ACCOUNT_ID")
19
+ raise KeyError, "CLOUDFLARE_ACCOUNT_ID is not set. Set it or CLOUDFLARE_BASE_URL" if account.nil?
20
+
21
+ "https://api.cloudflare.com/client/v4/accounts/#{account}/ai/v1"
22
+ end
23
+
24
+ Elelem::OpenAI::Provider.new(model:, api_key: key, base_url:)
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ {
2
+ "packages": {
3
+ ".": {
4
+ "release-type": "ruby",
5
+ "package-name": "elelem-cloudflare",
6
+ "version-file": "lib/elelem/cloudflare/version.rb",
7
+ "initial-version": "0.1.0",
8
+ "bump-minor-pre-major": true,
9
+ "include-component-in-tag": false
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "the cloudflare provider" do
4
+ vars = %w[CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID CLOUDFLARE_BASE_URL CLOUDFLARE_MODEL]
5
+
6
+ around do |example|
7
+ saved = ENV.to_h.slice(*vars)
8
+ example.run
9
+ ensure
10
+ vars.each { |k| ENV.delete(k) }
11
+ ENV.update(saved)
12
+ end
13
+
14
+ before do
15
+ ENV["CLOUDFLARE_API_TOKEN"] = "test-token"
16
+ ENV["CLOUDFLARE_ACCOUNT_ID"] = "test-account"
17
+ ENV["CLOUDFLARE_MODEL"] = "env-model"
18
+ ENV.delete("CLOUDFLARE_BASE_URL")
19
+ end
20
+
21
+ def build(**) = Elelem::Config.build_provider("cloudflare", **)
22
+ def uri(**) = build(**).instance_variable_get(:@uri).to_s
23
+ def model(**) = build(**).instance_variable_get(:@model)
24
+
25
+ let(:default_uri) { "https://api.cloudflare.com/client/v4/accounts/test-account/ai/v1/chat/completions" }
26
+
27
+ it "registers provider cloudflare" do
28
+ expect(Elelem::Config.names).to include("cloudflare")
29
+ expect(build).to be_a(Elelem::OpenAI::Provider)
30
+ end
31
+
32
+ it "talks to the account's Workers AI endpoint by default" do
33
+ expect(uri).to eq(default_uri)
34
+ end
35
+
36
+ it "sends CLOUDFLARE_API_TOKEN" do
37
+ expect(build.instance_variable_get(:@api_key)).to eq("test-token")
38
+ end
39
+
40
+ it "names CLOUDFLARE_API_TOKEN when the token is missing or empty" do
41
+ ENV.delete("CLOUDFLARE_API_TOKEN")
42
+ expect { build }.to raise_error(KeyError, /CLOUDFLARE_API_TOKEN/)
43
+
44
+ ENV["CLOUDFLARE_API_TOKEN"] = " "
45
+ expect { build }.to raise_error(KeyError, /CLOUDFLARE_API_TOKEN/)
46
+ end
47
+
48
+ it "names CLOUDFLARE_ACCOUNT_ID when it is missing or empty" do
49
+ ENV.delete("CLOUDFLARE_ACCOUNT_ID")
50
+ expect { build }.to raise_error(KeyError, /CLOUDFLARE_ACCOUNT_ID/)
51
+
52
+ ENV["CLOUDFLARE_ACCOUNT_ID"] = ""
53
+ expect { build }.to raise_error(KeyError, /CLOUDFLARE_ACCOUNT_ID/)
54
+ end
55
+
56
+ it "needs no CLOUDFLARE_ACCOUNT_ID when CLOUDFLARE_BASE_URL is set" do
57
+ ENV.delete("CLOUDFLARE_ACCOUNT_ID")
58
+ ENV["CLOUDFLARE_BASE_URL"] = "http://127.0.0.1:8080/v1"
59
+ expect(uri).to eq("http://127.0.0.1:8080/v1/chat/completions")
60
+ end
61
+
62
+ it "names CLOUDFLARE_MODEL when no model is set, and treats an empty one as unset" do
63
+ ENV.delete("CLOUDFLARE_MODEL")
64
+ expect { build }.to raise_error(KeyError, /CLOUDFLARE_MODEL/)
65
+
66
+ ENV["CLOUDFLARE_MODEL"] = ""
67
+ expect { build }.to raise_error(KeyError, /CLOUDFLARE_MODEL/)
68
+ end
69
+
70
+ it "takes the model from CLOUDFLARE_MODEL" do
71
+ expect(model).to eq("env-model")
72
+ end
73
+
74
+ it "prefers --model over CLOUDFLARE_MODEL" do
75
+ expect(model(model: "flag-model")).to eq("flag-model")
76
+ end
77
+
78
+ it "uses CLOUDFLARE_BASE_URL, with or without a trailing slash, and treats an empty one as unset" do
79
+ ENV["CLOUDFLARE_BASE_URL"] = "http://127.0.0.1:8080/v1/"
80
+ expect(uri).to eq("http://127.0.0.1:8080/v1/chat/completions")
81
+
82
+ ENV["CLOUDFLARE_BASE_URL"] = "http://127.0.0.1:8080/v1"
83
+ expect(uri).to eq("http://127.0.0.1:8080/v1/chat/completions")
84
+
85
+ ENV["CLOUDFLARE_BASE_URL"] = ""
86
+ expect(uri).to eq(default_uri)
87
+ end
88
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/elelem/cloudflare"
4
+
5
+ RSpec.configure do |config|
6
+ config.disable_monkey_patching!
7
+
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elelem-cloudflare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mo khan
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: elelem-openai
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.3'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0.3'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '1'
32
+ description: A Cloudflare provider plugin for elelem.
33
+ email:
34
+ - mo@mokhan.ca
35
+ executables:
36
+ - elelem-cloudflare
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".github/workflows/release.yml"
41
+ - ".release-please-manifest.json"
42
+ - ".rspec"
43
+ - ".rubocop.yml"
44
+ - CHANGELOG.md
45
+ - LICENSE.txt
46
+ - README.md
47
+ - Rakefile
48
+ - exe/elelem-cloudflare
49
+ - lib/elelem/cloudflare.rb
50
+ - lib/elelem/cloudflare/version.rb
51
+ - release-please-config.json
52
+ - spec/elelem/cloudflare/registration_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: https://elelem.sh
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ allowed_push_host: https://rubygems.org
59
+ homepage_uri: https://elelem.sh
60
+ source_code_uri: https://github.com/elelem-sh/cloudflare
61
+ rubygems_mfa_required: 'true'
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 4.0.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 4.0.6
77
+ specification_version: 4
78
+ summary: A Cloudflare provider plugin for elelem.
79
+ test_files: []