Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions crates/pidgin-napi/schema/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
]
},
Expand Down
11 changes: 11 additions & 0 deletions crates/pidgin-napi/src/core_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> {
pidgin_coding::utils::mime::detect_supported_image_mime_type(&buffer).map(|s| s.to_string())
}
}

// --- coding-agent session-cwd seam (core/session-cwd.ts) --------------------
Expand Down
15 changes: 15 additions & 0 deletions crates/pidgin-napi/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<String>, query: String) -> Vec<u32>;
fn detect_supported_image_mime_type(
buffer: napi::bindgen_prelude::Uint8Array,
) -> Option<String>;
}

/// The `KeybindingsManagerCore` contract — implement over the engine in `crate::core_impl`.
Expand Down Expand Up @@ -450,6 +456,15 @@ pub fn fuzzy_filter(texts: Vec<String>, query: String) -> Vec<u32> {
<crate::core_impl::PidginImpl as PidginCore>::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<String> {
<crate::core_impl::PidginImpl as PidginCore>::detect_supported_image_mime_type(buffer)
}

/// The Rust-backed keybindings core, exposed to JavaScript as
/// `KeybindingsManagerCore`.
#[napi]
Expand Down
19 changes: 6 additions & 13 deletions crates/pidgin-napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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 -------------------------------------
//
Expand Down