Weave documentation
Rust referenceweave-browser-engine

weave-browser-engine · perceive

Source declarations, signatures and documentation for perceive.

Reviewed implementation boundary: The serve path warns but still binds when WEAVE_API_KEY is absent; the authentication check then allows requests. Configure and verify authorization before exposing a server. See /libraries/weave-browser-engine/research-server.

Source: sigil/weave/libs/weave-browser-engine/src/perceive.rs. SHA-256: 4046886514eef116a2968c69643f68b9be8a99f1db54160f554de866f78b58ed.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

perceive::PerceptionBackend

Backend for advanced file perception (image description, video transcription, OCR, etc.).

Implement this trait to connect to Foundry, local ML models, or any other analysis service.

#[async_trait]
pub trait PerceptionBackend: Send + Sync {
    /// The name of this backend (e.g. `"foundry"`, `"local-onnx"`).
    fn name(&self) -> &str;

    /// Analyze a file and return structured metadata.
    ///
    /// The `file_type` is the classification from [`detect_type`].
    async fn analyze(&self, path: &Path, file_type: &str) -> BrowserResult<Value>;
}

Source line: 22.

perceive::LocalPerceptionBackend

Local-only perception backend.

Extracts basic metadata (size, extension, line/word/char counts for text files) without requiring an external service. Returns advisory messages for file types that need a richer backend (images, video, audio).

pub struct LocalPerceptionBackend;

Source line: 40.

perceive::detect_type

Classify a file extension into a broad content type.

pub fn detect_type(ext: &str) -> &'static str;

Source line: 105.

perceive::mime_for_ext

Return a MIME type string for common image extensions.

pub fn mime_for_ext(ext: &str) -> &'static str;

Source line: 123.

perceive::perceive

Analyze a file and return structured metadata as JSON.

Uses LocalPerceptionBackend by default. Pass a custom backend for richer analysis (e.g. Foundry gateway).

pub async fn perceive(input: &str) -> BrowserResult<Value>;

Source line: 140.

perceive::perceive_with_backend

Analyze a file using a specific [PerceptionBackend].

pub async fn perceive_with_backend(
    input: &str,
    backend: &dyn PerceptionBackend,
) -> BrowserResult<Value>;

Source line: 145.

On this page