collavre_openclaw 0.1.0 → 0.2.1
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 +4 -4
- data/app/services/collavre_openclaw/openclaw_adapter.rb +46 -3
- data/db/migrate/20260202120143_remove_description_from_openclaw_accounts.rb +5 -0
- data/db/migrate/20260202120254_remove_agent_provisioned_at_from_openclaw_accounts.rb +5 -0
- data/db/migrate/20260202130000_remove_agent_id_from_openclaw_accounts.rb +5 -0
- data/db/migrate/20260202140000_rename_api_token_to_api_key_in_openclaw_accounts.rb +5 -0
- data/db/migrate/20260202150001_migrate_pending_callbacks_to_user.rb +52 -0
- data/db/migrate/20260202150002_drop_openclaw_accounts.rb +18 -0
- data/lib/collavre_openclaw/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffa08c6ff97565abd9d9f0c468b5abce5aaa03df463fd529d9fd5f3f08a7aa6d
|
|
4
|
+
data.tar.gz: 4bb98ed84ea98fb1067f97c9ae9eea9f9b49365357fecf000fb102a70dd09586
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1fe26478d449c92f136e39142c1fde6db0261c171df1e45bd3e7a2e815065d09c00199c0dbdb93b88e39763da9a13a0909e7bb7f66da5c153acd003f653c990
|
|
7
|
+
data.tar.gz: 74f7c89b22522e2a43f097d064d5e17785ff91fc042a9db39c3350b142c1a059fe5fade168dd77b62b09c458a5fcc359f68d85d28422fb46f90e69a48b91336d
|
|
@@ -24,6 +24,12 @@ module CollavreOpenclaw
|
|
|
24
24
|
return nil
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
unless @user&.llm_api_key.present?
|
|
28
|
+
Rails.logger.error("[CollavreOpenclaw] No API key configured for user #{@user&.id} (may be a decryption failure)")
|
|
29
|
+
yield "Error: OpenClaw API key not configured or decryption failed. Please re-enter the API key in AI agent settings." if block_given?
|
|
30
|
+
return nil
|
|
31
|
+
end
|
|
32
|
+
|
|
27
33
|
response_content = +""
|
|
28
34
|
|
|
29
35
|
begin
|
|
@@ -297,12 +303,24 @@ module CollavreOpenclaw
|
|
|
297
303
|
|
|
298
304
|
req.body = payload.to_json
|
|
299
305
|
|
|
300
|
-
req.options.on_data = proc do |chunk, _size,
|
|
301
|
-
|
|
302
|
-
|
|
306
|
+
req.options.on_data = proc do |chunk, _size, env|
|
|
307
|
+
# Only process streaming data for successful responses
|
|
308
|
+
if env&.status.nil? || (env.status >= 200 && env.status < 300)
|
|
309
|
+
buffer << chunk
|
|
310
|
+
process_sse_buffer(buffer, &block)
|
|
311
|
+
else
|
|
312
|
+
buffer << chunk
|
|
313
|
+
end
|
|
303
314
|
end
|
|
304
315
|
end
|
|
305
316
|
|
|
317
|
+
# Check HTTP status and raise meaningful errors
|
|
318
|
+
unless response.status >= 200 && response.status < 300
|
|
319
|
+
error_body = buffer.presence || response.body
|
|
320
|
+
error_message = parse_error_message(response.status, error_body)
|
|
321
|
+
raise error_message
|
|
322
|
+
end
|
|
323
|
+
|
|
306
324
|
# Process any remaining data in buffer
|
|
307
325
|
process_sse_buffer(buffer, final: true, &block)
|
|
308
326
|
|
|
@@ -331,6 +349,31 @@ module CollavreOpenclaw
|
|
|
331
349
|
end
|
|
332
350
|
end
|
|
333
351
|
|
|
352
|
+
def parse_error_message(status, body)
|
|
353
|
+
detail = ""
|
|
354
|
+
begin
|
|
355
|
+
json = JSON.parse(body, symbolize_names: true) if body.present?
|
|
356
|
+
detail = json[:error] || json[:message] || json.to_s if json
|
|
357
|
+
rescue JSON::ParserError
|
|
358
|
+
detail = body.to_s.truncate(200)
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
case status
|
|
362
|
+
when 401
|
|
363
|
+
"Authentication failed (HTTP 401). Check your API key. #{detail}"
|
|
364
|
+
when 403
|
|
365
|
+
"Access forbidden (HTTP 403). #{detail}"
|
|
366
|
+
when 404
|
|
367
|
+
"Gateway endpoint not found (HTTP 404). Check your Gateway URL."
|
|
368
|
+
when 429
|
|
369
|
+
"Rate limited (HTTP 429). #{detail}"
|
|
370
|
+
when 500..599
|
|
371
|
+
"Gateway server error (HTTP #{status}). #{detail}"
|
|
372
|
+
else
|
|
373
|
+
"HTTP #{status}: #{detail}"
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
|
|
334
377
|
def handle_json_response(body, &block)
|
|
335
378
|
json = JSON.parse(body, symbolize_names: true)
|
|
336
379
|
content = json.dig(:choices, 0, :message, :content)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
class MigratePendingCallbacksToUser < ActiveRecord::Migration[7.2]
|
|
2
|
+
def up
|
|
3
|
+
# Add user_id column
|
|
4
|
+
add_column :openclaw_pending_callbacks, :user_id, :integer
|
|
5
|
+
|
|
6
|
+
# Migrate existing data
|
|
7
|
+
execute <<-SQL
|
|
8
|
+
UPDATE openclaw_pending_callbacks
|
|
9
|
+
SET user_id = (
|
|
10
|
+
SELECT user_id FROM openclaw_accounts
|
|
11
|
+
WHERE openclaw_accounts.id = openclaw_pending_callbacks.openclaw_account_id
|
|
12
|
+
)
|
|
13
|
+
SQL
|
|
14
|
+
|
|
15
|
+
# Remove old foreign key and column
|
|
16
|
+
remove_foreign_key :openclaw_pending_callbacks, :openclaw_accounts
|
|
17
|
+
remove_index :openclaw_pending_callbacks, :openclaw_account_id
|
|
18
|
+
remove_column :openclaw_pending_callbacks, :openclaw_account_id
|
|
19
|
+
|
|
20
|
+
# Add new foreign key
|
|
21
|
+
add_foreign_key :openclaw_pending_callbacks, :users
|
|
22
|
+
add_index :openclaw_pending_callbacks, :user_id
|
|
23
|
+
|
|
24
|
+
# Make user_id not null (after data migration)
|
|
25
|
+
change_column_null :openclaw_pending_callbacks, :user_id, false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def down
|
|
29
|
+
# Add back openclaw_account_id
|
|
30
|
+
add_column :openclaw_pending_callbacks, :openclaw_account_id, :integer
|
|
31
|
+
|
|
32
|
+
# Migrate data back (if openclaw_accounts still exists)
|
|
33
|
+
execute <<-SQL
|
|
34
|
+
UPDATE openclaw_pending_callbacks
|
|
35
|
+
SET openclaw_account_id = (
|
|
36
|
+
SELECT id FROM openclaw_accounts
|
|
37
|
+
WHERE openclaw_accounts.user_id = openclaw_pending_callbacks.user_id
|
|
38
|
+
LIMIT 1
|
|
39
|
+
)
|
|
40
|
+
SQL
|
|
41
|
+
|
|
42
|
+
# Remove user foreign key
|
|
43
|
+
remove_foreign_key :openclaw_pending_callbacks, :users
|
|
44
|
+
remove_index :openclaw_pending_callbacks, :user_id
|
|
45
|
+
remove_column :openclaw_pending_callbacks, :user_id
|
|
46
|
+
|
|
47
|
+
# Add back original foreign key
|
|
48
|
+
add_foreign_key :openclaw_pending_callbacks, :openclaw_accounts
|
|
49
|
+
add_index :openclaw_pending_callbacks, :openclaw_account_id
|
|
50
|
+
change_column_null :openclaw_pending_callbacks, :openclaw_account_id, false
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class DropOpenclawAccounts < ActiveRecord::Migration[7.2]
|
|
2
|
+
def up
|
|
3
|
+
drop_table :openclaw_accounts
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def down
|
|
7
|
+
create_table :openclaw_accounts do |t|
|
|
8
|
+
t.integer :user_id, null: false
|
|
9
|
+
t.string :gateway_url, null: false
|
|
10
|
+
t.string :api_key
|
|
11
|
+
t.string :channel_id
|
|
12
|
+
|
|
13
|
+
t.timestamps
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
add_index :openclaw_accounts, :user_id, unique: true
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: collavre_openclaw
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Collavre
|
|
@@ -63,6 +63,12 @@ files:
|
|
|
63
63
|
- db/migrate/20260201000001_create_pending_callbacks.rb
|
|
64
64
|
- db/migrate/20260202000001_remove_webhook_secret_from_openclaw_accounts.rb
|
|
65
65
|
- db/migrate/20260202074949_add_agent_id_to_openclaw_accounts.rb
|
|
66
|
+
- db/migrate/20260202120143_remove_description_from_openclaw_accounts.rb
|
|
67
|
+
- db/migrate/20260202120254_remove_agent_provisioned_at_from_openclaw_accounts.rb
|
|
68
|
+
- db/migrate/20260202130000_remove_agent_id_from_openclaw_accounts.rb
|
|
69
|
+
- db/migrate/20260202140000_rename_api_token_to_api_key_in_openclaw_accounts.rb
|
|
70
|
+
- db/migrate/20260202150001_migrate_pending_callbacks_to_user.rb
|
|
71
|
+
- db/migrate/20260202150002_drop_openclaw_accounts.rb
|
|
66
72
|
- lib/collavre_openclaw.rb
|
|
67
73
|
- lib/collavre_openclaw/configuration.rb
|
|
68
74
|
- lib/collavre_openclaw/engine.rb
|