collavre_openclaw 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7022c888e2fbe72f646eba7d022d489ff1458da405058638c0b15bc426076ec
4
- data.tar.gz: 4b822a95fba2cba72b9ceda1d8a92f24919b8982221d8ef4ce1ed6cddea4ade0
3
+ metadata.gz: 55f1fde91ceaf7db785f461e7463ae966ad015006ecba5bf8be22ac57f79d834
4
+ data.tar.gz: 736ef6e4237b38fcc055d73a0d188d404389ed66b6ce9ed0a45e3ab0edf66b50
5
5
  SHA512:
6
- metadata.gz: 26df63f943760253bba51dd0667e06a6fdac8821a5982e49163d9d6114f94eed5ff110f47d4af58531e22a966f7efa669f3cacafb608c3446b9d025530b9806f
7
- data.tar.gz: 33b8d566a78989521fe384add9bdedbdce668422c9658176c4c9cd2aa5620e31fa3fe247f7aefb82fd045ba33573bcfce391f2d3f88c8788c32a6d4737ce3cdb
6
+ metadata.gz: 5b249de9cc87980cf465d513af74900fead2c8ddb0c05262d578e821afec6830391e6bf8b30c7f57da0aa277945684c654a7435dfd081ef6da059f93bb7cacf7
7
+ data.tar.gz: cd4f77c3f1536726ecd3d1078922c8ab3a335307fae35a34aa52352cca58376c95e6d9f8bc23a5ec8609c4935606ca803579f23e17d22ad62c5f3bc78e5405e2
@@ -198,6 +198,47 @@ module CollavreOpenclaw
198
198
  end
199
199
  end
200
200
 
201
+ def extract_image_sources(message)
202
+ parts = message[:parts] || message["parts"]
203
+ return [] if parts.nil?
204
+
205
+ Array(parts).filter_map { |part| part[:image] || part["image"] }
206
+ end
207
+
208
+ def encode_image_source(source)
209
+ if defined?(ActiveStorage) && source.is_a?(ActiveStorage::Blob)
210
+ data = Base64.strict_encode64(source.download)
211
+ {
212
+ type: "image_url",
213
+ image_url: { url: "data:#{source.content_type};base64,#{data}" }
214
+ }
215
+ elsif source.respond_to?(:download)
216
+ # ActiveStorage::Attached::One
217
+ blob = source.respond_to?(:blob) ? source.blob : source
218
+ return nil unless blob
219
+
220
+ data = Base64.strict_encode64(blob.download)
221
+ {
222
+ type: "image_url",
223
+ image_url: { url: "data:#{blob.content_type};base64,#{data}" }
224
+ }
225
+ elsif source.is_a?(String) && source.match?(%r{^https?://})
226
+ { type: "image_url", image_url: { url: source } }
227
+ elsif source.is_a?(String)
228
+ # File path
229
+ return nil unless File.exist?(source)
230
+
231
+ mime = Marcel::MimeType.for(Pathname.new(source))
232
+ data = Base64.strict_encode64(File.binread(source))
233
+ { type: "image_url", image_url: { url: "data:#{mime};base64,#{data}" } }
234
+ else
235
+ nil
236
+ end
237
+ rescue StandardError => e
238
+ Rails.logger.warn("[CollavreOpenclaw] Failed to encode image: #{e.message}")
239
+ nil
240
+ end
241
+
201
242
  # ─────────────────────────────────────────────
202
243
  # HTTP transport (fallback)
203
244
  # ─────────────────────────────────────────────
@@ -308,14 +349,25 @@ module CollavreOpenclaw
308
349
  def format_messages(messages)
309
350
  Array(messages).map do |msg|
310
351
  role = msg[:role] || msg["role"]
311
- content = extract_message_text(msg)
352
+ text = extract_message_text(msg)
312
353
 
313
354
  sender_name = msg[:sender_name] || msg["sender_name"]
314
355
  if sender_name.present? && normalize_role(role) == "user"
315
- content = "[#{sender_name}]: #{content}"
356
+ text = "[#{sender_name}]: #{text}"
316
357
  end
317
358
 
318
- { role: normalize_role(role), content: content.to_s }
359
+ image_sources = extract_image_sources(msg)
360
+
361
+ if image_sources.any?
362
+ content_parts = [ { type: "text", text: text.to_s } ]
363
+ image_sources.each do |source|
364
+ image_data = encode_image_source(source)
365
+ content_parts << image_data if image_data
366
+ end
367
+ { role: normalize_role(role), content: content_parts }
368
+ else
369
+ { role: normalize_role(role), content: text.to_s }
370
+ end
319
371
  end
320
372
  end
321
373
 
@@ -1,3 +1,3 @@
1
1
  module CollavreOpenclaw
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collavre