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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 55f1fde91ceaf7db785f461e7463ae966ad015006ecba5bf8be22ac57f79d834
|
|
4
|
+
data.tar.gz: 736ef6e4237b38fcc055d73a0d188d404389ed66b6ce9ed0a45e3ab0edf66b50
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
356
|
+
text = "[#{sender_name}]: #{text}"
|
|
316
357
|
end
|
|
317
358
|
|
|
318
|
-
|
|
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
|
|