haloforge-plugin-api 0.2.5

Plugin API for HaloForge — traits and types for building native HaloForge plugins
Documentation
import { invoke } from "@tauri-apps/api/core";
// ─── Plugin-scoped IPC ────────────────────────────────────────────────────────
let _currentPluginId = "";
/** @internal Called once by the plugin runtime to set the current plugin context. */
export function _setPluginId(id) {
    _currentPluginId = id;
}
/** @internal Exposed for SDK helpers that cannot rely on React context. */
export function _getPluginId() {
    return _currentPluginId;
}
/**
 * Call a Tauri command registered by this plugin's Rust backend.
 * The command name is automatically prefixed: `plugin_{id}_{command}`.
 *
 * @example
 * ```ts
 * const status = await invokePlugin<GitStatus>("git_status", { path: "/repo" });
 * ```
 */
export async function invokePlugin(command, args) {
    if (!_currentPluginId) {
        throw new Error("[plugin-sdk] invokePlugin: plugin ID not set. Did you call registerPlugin()?");
    }
    const wireName = `plugin_${_currentPluginId.replace(/[.\-]/g, "_")}_${command}`;
    return invoke("plugin_invoke", {
        args: { wire_name: wireName, args: args ?? {} },
    });
}
/**
 * Call a command registered by another plugin.
 * Use this to depend on services provided by another plugin.
 */
export async function invokeOtherPlugin(targetPluginId, command, args) {
    const wireName = `plugin_${targetPluginId.replace(/[.\-]/g, "_")}_${command}`;
    return invoke("plugin_invoke", {
        args: { wire_name: wireName, args: args ?? {} },
    });
}
/**
 * Call a built-in HaloForge host Tauri command directly.
 * Only available if declared in manifest permissions.
 */
export async function invokeHost(command, args) {
    return invoke(command, args);
}
function getPluginHostBridge() {
    const bridge = window.__HALOFORGE_PLUGIN_HOST__;
    return bridge?.version === 1 ? bridge : null;
}
function requireCurrentPluginId(feature) {
    if (!_currentPluginId) {
        throw new Error(`[plugin-sdk] ${feature}: plugin ID not set. Did you call registerPlugin()?`);
    }
    return _currentPluginId;
}
function requireEnterpriseGateway() {
    const gateway = getPluginHostBridge()?.enterpriseGateway;
    if (!gateway) {
        throw new Error("[plugin-sdk] enterpriseGateway: host enterprise gateway bridge is unavailable.");
    }
    return gateway;
}
/**
 * Call the host-managed enterprise model gateway without exposing cloud tokens.
 *
 * The plugin manifest must request and be granted:
 *
 * ```json
 * { "type": "host_enterprise_gateway_access" }
 * ```
 */
export function enterpriseGateway() {
    const pluginId = requireCurrentPluginId("enterpriseGateway");
    const gateway = requireEnterpriseGateway();
    return {
        generateImages: (request) => gateway.generateImages(pluginId, request),
        editImages: (request) => gateway.editImages(pluginId, request),
        listOutputs: (limit) => gateway.listOutputs(pluginId, limit),
    };
}
//# sourceMappingURL=ipc.js.map