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:
|
|
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)
|