diff --git a/crates/pidgin-napi/schema/api.json b/crates/pidgin-napi/schema/api.json index eef6b28..f534d1a 100644 --- a/crates/pidgin-napi/schema/api.json +++ b/crates/pidgin-napi/schema/api.json @@ -938,6 +938,27 @@ "name": "fuzzyFilter" } } + }, + { + "name": "detectSupportedImageMimeType", + "doc": "`detectSupportedImageMimeType` (utils/mime.ts): sniff a supported image MIME\ntype from magic bytes, or `null`.", + "shape": "unary", + "infallible": true, + "readonly": true, + "params": [ + { + "name": "buffer", + "type": "bytes" + } + ], + "returns": { + "nullable": "string" + }, + "bindings": { + "node": { + "name": "detectSupportedImageMimeType" + } + } } ] }, diff --git a/crates/pidgin-napi/src/core_impl.rs b/crates/pidgin-napi/src/core_impl.rs index b64d698..5cdb389 100644 --- a/crates/pidgin-napi/src/core_impl.rs +++ b/crates/pidgin-napi/src/core_impl.rs @@ -39,6 +39,11 @@ /// (JS `number`); `fuzzyFilter` returns the surviving indices as `uint32` (JS /// `number`), widened from the engine's `usize` at the seam — the JS-visible /// scores and indices are identical to the pre-swap wrappers. +/// - the coding-agent mime op (`detectSupportedImageMimeType`) routes into +/// `pidgin_coding::utils::mime`, backing the native `utils/mime.ts` shim. The +/// image byte prefix crosses as the `bytes` scalar — spelled `Uint8Array` on +/// the JS side (a read-only view) — and the sniffed MIME type crosses back as +/// `string | null`, identical to the pre-swap hand-written wrapper. pub struct PidginImpl; impl crate::generated::PidginCore for PidginImpl { @@ -284,6 +289,12 @@ impl crate::generated::PidginCore for PidginImpl { .map(|i| i as u32) .collect() } + + fn detect_supported_image_mime_type( + buffer: napi::bindgen_prelude::Uint8Array, + ) -> Option { + pidgin_coding::utils::mime::detect_supported_image_mime_type(&buffer).map(|s| s.to_string()) + } } // --- coding-agent session-cwd seam (core/session-cwd.ts) -------------------- diff --git a/crates/pidgin-napi/src/generated.rs b/crates/pidgin-napi/src/generated.rs index c1da374..0f4aa7f 100644 --- a/crates/pidgin-napi/src/generated.rs +++ b/crates/pidgin-napi/src/generated.rs @@ -12,6 +12,9 @@ fn err(e: impl std::fmt::Display) -> napi::Error { napi::Error::from_reason(e.to_string()) } +/// Bulk bytes cross into JS as a Buffer (Arrow IPC payloads and friends). +pub type Bytes = napi::bindgen_prelude::Buffer; + /// Result of [`slice_with_width`]; serialized to `{ text, width }`. #[napi(object)] #[derive(Clone)] @@ -110,6 +113,9 @@ pub trait PidginCore: Sized + Send + Sync + 'static { fn has_trust_requiring_project_resources(cwd: String, home_dir: String) -> bool; fn fuzzy_match(query: String, text: String) -> FuzzyMatchResult; fn fuzzy_filter(texts: Vec, query: String) -> Vec; + fn detect_supported_image_mime_type( + buffer: napi::bindgen_prelude::Uint8Array, + ) -> Option; } /// The `KeybindingsManagerCore` contract — implement over the engine in `crate::core_impl`. @@ -450,6 +456,15 @@ pub fn fuzzy_filter(texts: Vec, query: String) -> Vec { ::fuzzy_filter(texts, query) } +/// `detectSupportedImageMimeType` (utils/mime.ts): sniff a supported image MIME +/// type from magic bytes, or `null`. +#[napi(js_name = "detectSupportedImageMimeType")] +pub fn detect_supported_image_mime_type( + buffer: napi::bindgen_prelude::Uint8Array, +) -> Option { + ::detect_supported_image_mime_type(buffer) +} + /// The Rust-backed keybindings core, exposed to JavaScript as /// `KeybindingsManagerCore`. #[napi] diff --git a/crates/pidgin-napi/src/lib.rs b/crates/pidgin-napi/src/lib.rs index 9d976aa..a4c3c2b 100644 --- a/crates/pidgin-napi/src/lib.rs +++ b/crates/pidgin-napi/src/lib.rs @@ -185,19 +185,12 @@ pub fn anthropic_parse_sse_stream( // --- coding-agent utils layer ----------------------------------------------- // -// Thin wrappers over `pidgin_coding::utils::*`, backing the hand-written native -// shims under conformance/shims/packages/coding-agent/src/utils/. Each mirrors -// the pi export it replaces; the shims re-export the un-ported surface from the -// preserved pi original and override only these symbols. - -/// `detectSupportedImageMimeType` (utils/mime.ts): sniff a supported image MIME -/// type from magic bytes, or `null`. -#[napi(js_name = "detectSupportedImageMimeType")] -pub fn detect_supported_image_mime_type( - buffer: napi::bindgen_prelude::Uint8Array, -) -> Option { - pidgin_coding::utils::mime::detect_supported_image_mime_type(&buffer).map(|s| s.to_string()) -} +// The `detectSupportedImageMimeType` byte-sniffer (utils/mime.ts) now generates +// from the fluessig api schema through `crate::generated` + `crate::core_impl`, +// routing into `pidgin_coding::utils::mime`. Its image buffer arg is authored as +// the fluessig `bytes` scalar (spelled `Uint8Array` in the node `.d.ts`). The +// hand-written `#[napi]` export that lived here was deleted; edit `schema/api.json` +// and rerun `regen.sh` instead of re-adding it. // --- coding-agent http-dispatcher layer ------------------------------------- //