MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / unsupported_parts

Function unsupported_parts

crates/opencode-provider/src/transform.rs:481–554  ·  view source on GitHub ↗
(messages: &mut [Message], supported_modalities: &[Modality])

Source from the content-addressed store, hash-verified

479// ---------------------------------------------------------------------------
480
481pub fn unsupported_parts(messages: &mut [Message], supported_modalities: &[Modality]) {
482 for msg in messages.iter_mut() {
483 if !matches!(msg.role, crate::Role::User) {
484 continue;
485 }
486
487 if let Content::Parts(parts) = &mut msg.content {
488 for part in parts.iter_mut() {
489 if part.content_type != "image" && part.content_type != "file" {
490 continue;
491 }
492
493 // Check for empty base64 image data
494 if part.content_type == "image" {
495 if let Some(ref image_url) = part.image_url {
496 let url_str = &image_url.url;
497 if url_str.starts_with("data:") {
498 // Match data:<mime>;base64,<data>
499 if let Some(comma_pos) = url_str.find(',') {
500 let data_part = &url_str[comma_pos + 1..];
501 if data_part.is_empty() {
502 *part = ContentPart {
503 content_type: "text".to_string(),
504 text: Some("ERROR: Image file is empty or corrupted. Please provide a valid image.".to_string()),
505 ..Default::default()
506 };
507 continue;
508 }
509 }
510 }
511 }
512 }
513
514 let mime = if part.content_type == "image" {
515 part.image_url
516 .as_ref()
517 .and_then(|url| {
518 let url_str = url.url.as_str();
519 if url_str.starts_with("data:") {
520 url_str.split(';').next()
521 } else {
522 None
523 }
524 })
525 .map(|s| s.trim_start_matches("data:").to_string())
526 .unwrap_or_default()
527 } else {
528 // For file parts, use media_type field
529 part.media_type.clone().unwrap_or_default()
530 };
531
532 if let Some(modality) = mime_to_modality(&mime) {
533 if !supported_modalities.contains(&modality) {
534 // Extract filename for error message
535 let name = if let Some(ref filename) = part.filename {
536 format!("\"{}\"", filename)
537 } else {
538 modality.to_string()

Callers 1

transform_messagesFunction · 0.85

Calls 6

mime_to_modalityFunction · 0.85
findMethod · 0.80
is_emptyMethod · 0.80
containsMethod · 0.80
as_strMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected