#proton/core

    moonbit-community/proton/core owns the bridge between native MoonBit code and page JavaScript.

    It provides:

    • op registration and dispatch
    • command host dispatch over the IPC protocol
    • window.__MoonBit__ bridge wiring
    • extension events

    Application lifecycle and app composition belong in the root proton facade, which owns the source-built native runtime and its async host loop.

    CommandPermissionError

    pub(all) suberror CommandPermissionError {
    Missing(extension_id~ : String)
    Foreign(expected~ : String, actual~ : String)
    } derive(Eq,
    Debug
    )

    A command attempted to use a capability outside its request grant.

    CommandPermissionError::equal

    CommandPermissionError::message

    fn CommandPermissionError::message(self : CommandPermissionError) -> String

    CommandPermissionError::not_equal

    OpDispatchError

    pub(all) suberror OpDispatchError {
    InvalidPayload(name~ : String, detail~ : String)
    UnknownOp(name~ : String)
    HandlerFailed(name~ : String, detail~ : String)
    HostClosed
    AsyncHandlerRequiresAsync(name~ : String)
    RequestContextRequired(name~ : String)
    } derive(Eq,
    Debug
    )

    Failures while decoding and invoking one registered operation.

    OpDispatchError::equal

    OpDispatchError::message

    fn OpDispatchError::message(self : OpDispatchError) -> String

    OpDispatchError::not_equal

    fn OpDispatchError::not_equal(x : OpDispatchError, y : OpDispatchError) -> Bool

    OpDispatchError::output

    fn OpDispatchError::output(self : OpDispatchError, logger : &Logger) -> Unit

    OpDispatchError::to_string

    fn OpDispatchError::to_string(self : OpDispatchError) -> String

    OpRegistrationError

    pub(all) suberror OpRegistrationError {
    EmptyName
    DuplicateName(name~ : String)
    HostClosed
    RegistrationSealed
    } derive(Eq,
    Debug
    )

    Failures while adding command handlers to an operation registry.

    OpRegistrationError::equal

    OpRegistrationError::message

    fn OpRegistrationError::message(self : OpRegistrationError) -> String

    OpRegistrationError::not_equal

    OpRegistrationError::output

    fn OpRegistrationError::output(self : OpRegistrationError, logger : &Logger) -> Unit

    OpRegistrationError::to_string

    fn OpRegistrationError::to_string(self : OpRegistrationError) -> String

    AppCommandHost

    type AppCommandHost

    Command host for user app code.

    The framework decides how this host is connected to the window runtime. App authors register commands and run the host without depending on the underlying IPC implementation.

    AppCommandHost::AppCommandHost

    fn AppCommandHost::AppCommandHost(expose_error_details? : Bool, diagnostic_reporter? : (String) -> Unit) -> AppCommandHost

    Creates an empty app command host.

    Set diagnostic_reporter to retain backend-only handler diagnostics. Set expose_error_details only for a trusted development frontend.

    AppCommandHost::close

    fn AppCommandHost::close(self : AppCommandHost) -> Unit

    Closes this command host and rejects future dispatches.

    AppCommandHost::dispatch_ipc

    Dispatches one IPC request on the current async loop.

    AppCommandHost::dispatch_ipc_with_context

    Dispatches one IPC request with request-scoped context.

    AppCommandHost::op

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op(self : AppCommandHost, name : String, callback : (Payload) -> Reply raise?) -> Unit raise OpRegistrationError

    Registers a synchronous app command.

    AppCommandHost::op_async

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op_async(self : AppCommandHost, name : String, callback : async (Payload) -> Reply) -> Unit raise OpRegistrationError

    Registers an async app command.

    AppCommandHost::op_async_with_context

    fn[Payload :
    FromJson
    , Reply : ToJson] AppCommandHost::op_async_with_context(self : AppCommandHost, name : String, callback : async (AppCommandRequestContext, Payload) -> Reply) -> Unit raise OpRegistrationError

    Registers an async app command that receives request-scoped context.

    AppCommandHost::registered_ops

    fn AppCommandHost::registered_ops(self : AppCommandHost) -> Array[String]

    Returns registered command names in registration order.

    AppCommandHost::seal_registrations

    fn AppCommandHost::seal_registrations(self : AppCommandHost) -> Unit

    Prevents later command registration while keeping existing commands usable.

    AppCommandRequestContext

    pub struct AppCommandRequestContext {
    window : CommandWindow?
    window_id : String
    source_origin : String
    page_instance : String?
    permission_extension : String?
    permission_scope_value : Json?
    tasks :
    TaskGroup
    [Unit]
    wake_signal : RuntimeWakeSignal
    emit_event : async (
    ContractRoute
    , String, Json) -> Unit noraise
    locale_preferences :
    LocalePreferences

    }

    Request-scoped context for one bridged app command dispatch.

    AppCommandRequestContext::AppCommandRequestContext

    fn AppCommandRequestContext::AppCommandRequestContext(tasks :
    TaskGroup
    [Unit], locale_preferences :
    LocalePreferences
    , window? : CommandWindow, window_id? : String, source_origin? : String, page_instance? : String?, permission_extension? : String, permission_scope? : Json, wake_signal? : RuntimeWakeSignal, emit_event? : async (
    ContractRoute
    , String, Json) -> Unit noraise) -> AppCommandRequestContext

    AppCommandRequestContext::emit

    async fn[Payload : ToJson] AppCommandRequestContext::emit(self : AppCommandRequestContext, event :
    Event
    [Payload], payload : Payload) -> Unit

    Emits a typed event to the renderer page that issued this command.

    AppCommandRequestContext::locale

    Returns the immutable application locale selected at startup.

    AppCommandRequestContext::page_instance

    fn AppCommandRequestContext::page_instance(self : AppCommandRequestContext) -> String?

    Returns the renderer page instance that issued this request, when the context came from the native bridge.

    AppCommandRequestContext::permission_scope

    fn AppCommandRequestContext::permission_scope(self : AppCommandRequestContext, extension_id : String) -> Json raise CommandPermissionError

    Returns this request's extension-specific permission scope.

    AppCommandRequestContext::preferred_languages

    Returns the application's ordered language preferences.

    AppCommandRequestContext::source_origin

    fn AppCommandRequestContext::source_origin(self : AppCommandRequestContext) -> String

    AppCommandRequestContext::task_group

    Returns the task group owned by this command lifecycle.

    Child tasks are cancelled and joined when the issuing window closes.

    AppCommandRequestContext::wait_for_wake

    async fn AppCommandRequestContext::wait_for_wake(self : AppCommandRequestContext, revision : Int64) -> Unit

    AppCommandRequestContext::wake_revision

    fn AppCommandRequestContext::wake_revision(self : AppCommandRequestContext) -> Int64

    AppCommandRequestContext::wake_signal

    AppCommandRequestContext::window

    AppCommandRequestContext::window_id

    fn AppCommandRequestContext::window_id(self : AppCommandRequestContext) -> String

    CommandWindow

    pub struct CommandWindow {
    show_message_dialog : async (String?, String, String) -> Unit
    show_confirm_dialog : async (String?, String, String) -> Bool
    open_file_dialog : async (String?, String?) -> String?
    save_file_dialog : async (String?, String?) -> String?
    choose_directory_dialog : async (String?, String?) -> String?
    }

    Window-scoped application capabilities available to one command request. The native window identity and implementation remain owned by the Proton runtime; extensions can only invoke these semantic operations.

    CommandWindow::CommandWindow

    fn CommandWindow::CommandWindow(show_message_dialog : async (String?, String, String) -> Unit, show_confirm_dialog : async (String?, String, String) -> Bool, open_file_dialog : async (String?, String?) -> String?, save_file_dialog : async (String?, String?) -> String?, choose_directory_dialog : async (String?, String?) -> String?) -> CommandWindow

    CommandWindow::choose_directory

    async fn CommandWindow::choose_directory(self : CommandWindow, title : String?, path : String?) -> String?

    CommandWindow::confirm

    async fn CommandWindow::confirm(self : CommandWindow, title : String?, message : String, level : String) -> Bool

    CommandWindow::open_file

    async fn CommandWindow::open_file(self : CommandWindow, title : String?, path : String?) -> String?

    CommandWindow::save_file

    async fn CommandWindow::save_file(self : CommandWindow, title : String?, path : String?) -> String?

    CommandWindow::show_message

    async fn CommandWindow::show_message(self : CommandWindow, title : String?, message : String, level : String) -> Unit

    MbtProcessHost

    type MbtProcessHost

    Command host intended to run in the MBT process.

    The host is independent from the browser window, so application code can use normal MoonBit syntax, state, and async handlers without living in the GUI process.

    MbtProcessHost::MbtProcessHost

    fn MbtProcessHost::MbtProcessHost(expose_error_details? : Bool, diagnostic_reporter? : (String) -> Unit) -> MbtProcessHost

    Creates an empty MBT-side command host.

    Set diagnostic_reporter to retain backend-only handler diagnostics. Set expose_error_details only for a trusted development frontend.

    MbtProcessHost::close

    fn MbtProcessHost::close(self : MbtProcessHost) -> Unit

    Closes this host and rejects future dispatches.

    MbtProcessHost::dispatch_async

    Dispatches one decoded IPC request on the current async loop.

    User command hosts use this path so async ops run inside the user process event loop instead of creating a nested event loop elsewhere.

    MbtProcessHost::dispatch_async_with_context

    Dispatches one decoded IPC request with request-scoped context.

    MbtProcessHost::op

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op(self : MbtProcessHost, name : String, callback : (Payload) -> Reply raise?) -> Unit raise OpRegistrationError

    Registers a synchronous MBT-side op.

    MbtProcessHost::op_async

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op_async(self : MbtProcessHost, name : String, callback : async (Payload) -> Reply) -> Unit raise OpRegistrationError

    Registers an async MBT-side op.

    MbtProcessHost::op_async_with_context

    fn[Payload :
    FromJson
    , Reply : ToJson] MbtProcessHost::op_async_with_context(self : MbtProcessHost, name : String, callback : async (AppCommandRequestContext, Payload) -> Reply) -> Unit raise OpRegistrationError

    Registers an async MBT-side op that receives request-scoped context.

    MbtProcessHost::registered_ops

    fn MbtProcessHost::registered_ops(self : MbtProcessHost) -> Array[String]

    Returns registered op names in registration order.

    RuntimeWakeSignal

    pub struct RuntimeWakeSignal {
    revision : Int64
    condition :
    Cond

    }

    Scheduler-local notification shared by the runtime pump and command tasks. The revision makes waiting race-free when a notification arrives between a native poll and suspension on the condition variable.

    RuntimeWakeSignal::RuntimeWakeSignal

    fn RuntimeWakeSignal::RuntimeWakeSignal() -> RuntimeWakeSignal

    RuntimeWakeSignal::notify

    fn RuntimeWakeSignal::notify(self : RuntimeWakeSignal) -> Unit

    RuntimeWakeSignal::revision

    fn RuntimeWakeSignal::revision(self : RuntimeWakeSignal) -> Int64

    RuntimeWakeSignal::wait_for_change

    async fn RuntimeWakeSignal::wait_for_change(self : RuntimeWakeSignal, revision : Int64) -> Unit

    TemplateReplacement

    type TemplateReplacement

    moonbit_global_name

    fn moonbit_global_name() -> String

    Returns the root JavaScript namespace used by Proton runtime helpers. JavaScript bridges and generated helper scripts should agree on this value when exposing Proton functionality on window.

    moonbit_op_binding_name

    fn moonbit_op_binding_name() -> String

    Returns the native binding name used by the op bridge. Native dispatch glue and injected runtime scripts both use this name to route op calls through the same binding.

    render_js_template

    fn render_js_template(template : String, replacements : Array[TemplateReplacement]) -> String

    Applies a sequence of token replacements to a JavaScript template string. Replacements are processed in order, which allows later entries to build on earlier substitutions when generating runtime helper scripts.

    replacement

    fn replacement(token : String, value : String) -> TemplateReplacement

    Creates a single token replacement entry for render_js_template. This keeps call sites readable when several template tokens need to be substituted together.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io