collavre_openclaw 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ea44c34555f598c15ad28c01b082dc75b6b1e7d2fcd80b116fe51d7aed133a0
4
- data.tar.gz: 478d170da5c544ef32d3d709fa0011fd2af3d73f5b709440909b8b1895e343ba
3
+ metadata.gz: ffa08c6ff97565abd9d9f0c468b5abce5aaa03df463fd529d9fd5f3f08a7aa6d
4
+ data.tar.gz: 4bb98ed84ea98fb1067f97c9ae9eea9f9b49365357fecf000fb102a70dd09586
5
5
  SHA512:
6
- metadata.gz: 74a3c5f8a063bebfe3fd10481db62cbd564f3d07af5f355e95a1c84fccebd0220094ae00e12adb9080ae67a6877824765c03d47de2ae4953f4baba8c534bd3dc
7
- data.tar.gz: 11af895cbdba2f0376802d6de9bae9771498724568c2aac5363ed32ea6b6afd5df01d31c8ff301a29c4f6e9c7cc8436f225836545e46c0e94f3a1b8a2e16c232
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, _env|
301
- buffer << chunk
302
- process_sse_buffer(buffer, &block)
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)
@@ -1,3 +1,3 @@
1
1
  module CollavreOpenclaw
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collavre