inloop-brain 0.0.7 → 0.0.9

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: b010ec1dfb8d235662298c1b6bfa1b5ac3449abbe57ef897f28c938a2bc40578
4
- data.tar.gz: 7bd980f2aefaac9c121de941aa934f9d521082e94bef253938f9a545a0ac2eda
3
+ metadata.gz: 61025b8763503388d32c42d1169bd9e4231da28b6d383a7e9039fe55bc5e951e
4
+ data.tar.gz: 3da29a86dca04caf0b20cb08bc1cc7a7c1597613bee59042d2cf0ef863b62499
5
5
  SHA512:
6
- metadata.gz: 396a1272894e4f37b8774f1bd6982e27cf51afc62929506ce06523b52b22be04f0415d880189ca9215fc443445e2d7a80f659b077efe197b8260c0d70dedb038
7
- data.tar.gz: 6927c57bcc86f9d089a73ebbfbcc7fab492d2eb28c2195253864f607c1f9c3ab3c3ac3e73b9df61cd7f3558657871f83921af88ab6d6b1c04da83ae8658b320b
6
+ metadata.gz: 4c484e3325531265497f6e2e1bd914e0b6f4525505840095af558330b2c28edaf8528eb9325205bdb349725db605640af96c622298b46474009d8bc186e8d23e
7
+ data.tar.gz: 7f516136819c318c81718348a61598c414b931fa3d54c385f8d11868081035e0c251963bc760906674a111f0be6269754cf35e91ef8a4adfbe7c9ef9381791e4
@@ -0,0 +1,34 @@
1
+ name: Publish RubyGem
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ release_tag:
7
+ description: "Optional git tag to publish"
8
+ required: false
9
+ default: ""
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: write
16
+ id-token: write
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0
22
+
23
+ - name: Checkout tag
24
+ if: inputs.release_tag != ''
25
+ run: git checkout "${{ inputs.release_tag }}"
26
+
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: "3.2"
31
+ bundler-cache: true
32
+
33
+ - name: Release gem via Trusted Publisher (OIDC)
34
+ uses: rubygems/release-gem@v1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Inloop Brain
2
2
 
3
- A command-line tool for interacting with the Inloop Brain Access Kit API.
3
+ A command-line tool for interacting with the Inloop Brain OpenAI-compatible API.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,26 +8,52 @@ A command-line tool for interacting with the Inloop Brain Access Kit API.
8
8
  gem install inloop-brain
9
9
  ```
10
10
 
11
+ ## Requirements
12
+
13
+ - Ruby >= 2.6.0
14
+
11
15
  ## Usage
12
16
 
13
17
  ```
14
- echo "What can you do?" | inloop-brain --key=YOUR_ACCESS_KEY
18
+ echo "What can you do?" | inloop-brain --key=YOUR_API_KEY
15
19
  ```
16
20
 
17
21
  Or
18
22
 
19
23
  ```
20
- echo "What can you do?" | inloop-brain -k YOUR_ACCESS_KEY > output.txt
24
+ echo "What can you do?" | inloop-brain -k YOUR_API_KEY > output.txt
21
25
  ```
22
26
 
23
27
  ### Environment Variables
24
28
 
25
- You can customize the target host and protocol:
29
+ Use an API key generated from the Brain API share link in app.inloop.studio. The API uses the published `llms.txt` context when available.
30
+
31
+ - `INLOOP_BRAIN_API_KEY`: API key used for Authorization (recommended)
32
+ - `INLOOP_BRAIN_API_URL`: Full API URL (default: https://app.inloop.studio/api/v1/chat/completions)
33
+ - `INLOOP_BRAIN_MODEL`: Model name to send (default: inloop-brain)
34
+ - `INLOOP_BRAIN_HOST`: Host override (default: app.inloop.studio)
35
+ - `INLOOP_BRAIN_PROTOCOL`: Protocol override (default: https)
36
+
37
+ ### Options
38
+
39
+ - `--api-url`: Override API URL
40
+ - `--model`: Model name to send
41
+ - `--system`: System prompt to prepend
42
+
43
+ ## Development
44
+
45
+ ### Dependencies
46
+
47
+ - bundler (~> 2.0)
48
+ - rake (~> 13.0)
49
+ - rspec (~> 3.0)
26
50
 
27
- - `INLOOP_BRAIN_HOST`: Host to connect to (default: localhost:3000)
28
- - `INLOOP_BRAIN_PROTOCOL`: Protocol to use (default: http)
51
+ ## Links
29
52
 
53
+ - Homepage: https://inloop.studio
54
+ - Source Code: https://github.com/inloopstudio-team/inloop-brain
55
+ - Changelog: https://github.com/inloopstudio-team/inloop-brain/blob/main/CHANGELOG.md
30
56
 
31
57
  ## License
32
58
 
33
- The gem is available as open source under the terms of the Nonstandard license of inloop.studio
59
+ The gem is available as open source under the terms of the Nonstandard license of inloop.studio
data/bin/inloop-brain CHANGED
@@ -1,18 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # bin/inloop-brain - A command-line tool to interact with the Brain Access Kit API
3
+ # bin/inloop-brain - A command-line tool to interact with the Inloop Brain API (OpenAI-compatible)
4
4
 
5
5
  require 'optparse'
6
6
  require 'net/http'
7
7
  require 'uri'
8
+ require 'json'
8
9
 
9
10
  # Parse command line options
10
11
  options = {}
11
12
  parser = OptionParser.new do |opts|
12
- opts.banner = "This is brain access kit of inloop.studio\n\n Usage: inloop-brain [options]"
13
- opts.on('-k KEY', '--key=KEY', 'Access key for the Brain Access Kit') do |key|
13
+ opts.banner = "This is the Inloop Brain CLI\n\n Usage: inloop-brain [options]"
14
+ opts.on('-k KEY', '--key=KEY', 'API key for the Inloop Brain (OpenAI-compatible)') do |key|
14
15
  options[:key] = key
15
16
  end
17
+ opts.on('-m MODEL', '--model=MODEL', 'Model name (default: inloop-brain)') do |model|
18
+ options[:model] = model
19
+ end
20
+ opts.on('--system=TEXT', 'System prompt to prepend to the conversation') do |text|
21
+ options[:system] = text
22
+ end
23
+ opts.on('--api-url=URL', 'Override API URL (default: https://app.inloop.studio/api/v1/chat/completions)') do |url|
24
+ options[:api_url] = url
25
+ end
16
26
  opts.on('-d', '--debug', 'Enable debug mode') do
17
27
  options[:debug] = true
18
28
  end
@@ -31,8 +41,9 @@ rescue OptionParser::InvalidOption => e
31
41
  end
32
42
 
33
43
  # Validate required parameters
44
+ options[:key] ||= ENV['INLOOP_BRAIN_API_KEY']
34
45
  unless options[:key]
35
- STDERR.puts "Error: Missing required parameter 'key'"
46
+ STDERR.puts "Error: Missing required parameter 'key' (or set INLOOP_BRAIN_API_KEY)"
36
47
  STDERR.puts parser
37
48
  exit 1
38
49
  end
@@ -47,10 +58,13 @@ if input.empty?
47
58
  end
48
59
 
49
60
  # Configure the API request
50
- host = ENV['INLOOP_BRAIN_HOST'] || 'discovery.inloop.studio'
51
- protocol = ENV['INLOOP_BRAIN_PROTOCOL'] || 'https'
52
- endpoint = "/web_tools/brain_access_kit/#{options[:key]}/handle_prompt.txt"
53
- uri = URI.parse("#{protocol}://#{host}#{endpoint}")
61
+ api_url = options[:api_url] || ENV['INLOOP_BRAIN_API_URL']
62
+ if api_url.nil? || api_url.strip.empty?
63
+ host = ENV['INLOOP_BRAIN_HOST'] || 'app.inloop.studio'
64
+ protocol = ENV['INLOOP_BRAIN_PROTOCOL'] || 'https'
65
+ api_url = "#{protocol}://#{host}/api/v1/chat/completions"
66
+ end
67
+ uri = URI.parse(api_url)
54
68
 
55
69
  if options[:debug]
56
70
  puts "Making request to: #{uri}"
@@ -64,14 +78,21 @@ http.use_ssl = (uri.scheme == 'https')
64
78
  http.open_timeout = 10
65
79
  http.read_timeout = 60
66
80
 
67
- request = Net::HTTP::Post.new(uri.path)
81
+ request = Net::HTTP::Post.new(uri)
68
82
  # Set proper headers
69
- request['Content-Type'] = 'application/x-www-form-urlencoded'
70
- request['Accept'] = 'text/plain'
71
- request['User-Agent'] = 'Inloop-Brain-CLI/0.0.1'
83
+ request['Content-Type'] = 'application/json'
84
+ request['Accept'] = 'application/json'
85
+ request['Authorization'] = "Bearer #{options[:key]}"
86
+ request['User-Agent'] = 'Inloop-Brain-CLI/0.0.9'
72
87
 
73
- # Set form data
74
- request.set_form_data('prompt' => input)
88
+ messages = []
89
+ messages << { role: 'system', content: options[:system] } if options[:system].to_s.strip != ''
90
+ messages << { role: 'user', content: input }
91
+ body = {
92
+ model: options[:model] || ENV['INLOOP_BRAIN_MODEL'] || 'inloop-brain',
93
+ messages: messages
94
+ }
95
+ request.body = JSON.dump(body)
75
96
 
76
97
  # Send the request and handle the response
77
98
  begin
@@ -89,20 +110,26 @@ begin
89
110
  response.each_header { |key, value| puts " #{key}: #{value}" }
90
111
  end
91
112
 
113
+ begin
114
+ payload = JSON.parse(response.body.to_s)
115
+ rescue JSON::ParserError
116
+ payload = nil
117
+ end
118
+
92
119
  if response.code.to_i == 200
93
- puts response.body
120
+ content = payload.dig("choices", 0, "message", "content") if payload
121
+ content ||= payload.dig("choices", 0, "text") if payload
122
+ if content
123
+ puts content
124
+ else
125
+ STDERR.puts "Error: Unexpected response format"
126
+ STDERR.puts response.body
127
+ exit 1
128
+ end
94
129
  else
130
+ message = payload.dig("error", "message") if payload
95
131
  STDERR.puts "Error: API returned status code #{response.code}"
96
- STDERR.puts response.body
97
-
98
- # Additional troubleshooting for 422 errors
99
- if response.code.to_i == 422
100
- STDERR.puts "\nThe 422 error typically indicates a validation problem. Possible issues:"
101
- STDERR.puts "1. The endpoint format may have changed"
102
- STDERR.puts "2. The access key format may be incorrect"
103
- STDERR.puts "3. The prompt may be in an invalid format"
104
- STDERR.puts "\nTry running with --debug for more information."
105
- end
132
+ STDERR.puts(message || response.body)
106
133
  exit 1
107
134
  end
108
135
  rescue => e
data/inloop-brain.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "inloop-brain"
5
- spec.version = "0.0.7"
5
+ spec.version = "0.0.9"
6
6
  spec.authors = ["Abhishek Parolkar"]
7
7
  spec.email = ["abhishek@inloop.studio"]
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inloop-brain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abhishek Parolkar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-30 00:00:00.000000000 Z
11
+ date: 2026-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,8 @@ executables:
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
+ - ".github/workflows/push.yml"
65
+ - Gemfile
64
66
  - LICENSE.txt
65
67
  - README.md
66
68
  - Rakefile
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  - !ruby/object:Gem::Version
89
91
  version: '0'
90
92
  requirements: []
91
- rubygems_version: 3.5.22
93
+ rubygems_version: 3.4.19
92
94
  signing_key:
93
95
  specification_version: 4
94
96
  summary: Command-line interface for the Inloop Brain Access Kit