mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-03 00:51:33 +00:00
58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
// Node-host plugin command contracts, including the opt-in duplex transport.
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
|
|
export type OpenClawPluginNodeHostCommandAvailabilityContext = {
|
|
/** Node-local configuration used to build this host's Gateway declaration. */
|
|
config: OpenClawConfig;
|
|
/** Node-host process environment. */
|
|
env: NodeJS.ProcessEnv;
|
|
};
|
|
|
|
export type OpenClawPluginNodeHostCommandIo = {
|
|
emitChunk(chunk: string): Promise<void>;
|
|
onInput(callback: (payloadJSON: string) => void): void;
|
|
signal: AbortSignal;
|
|
};
|
|
|
|
export type OpenClawPluginNodeHostCommandContext = {
|
|
/** Emit one node-owned event through the active Gateway connection. */
|
|
sendNodeEvent(event: string, payload: unknown): Promise<unknown>;
|
|
/** Agent session that owns this invocation, when the caller supplied one. */
|
|
sessionKey?: string;
|
|
/** Aborts when the Gateway cancels this specific node-host invocation. */
|
|
signal?: AbortSignal;
|
|
};
|
|
|
|
type OpenClawPluginNodeHostCommandBase = {
|
|
command: string;
|
|
cap?: string;
|
|
dangerous?: boolean;
|
|
/** Return false to omit this command and capability from the node declaration. */
|
|
isAvailable?: (context: OpenClawPluginNodeHostCommandAvailabilityContext) => boolean;
|
|
/** Watch node-local availability and request a fresh Gateway declaration. */
|
|
watchAvailability?: (
|
|
context: OpenClawPluginNodeHostCommandAvailabilityContext,
|
|
onChange: () => void,
|
|
) => (() => void) | void;
|
|
agentTool?: {
|
|
name: string;
|
|
description: string;
|
|
parameters?: Record<string, unknown>;
|
|
/** Platforms where this tool is allowlisted by default; omit for explicit config only. */
|
|
defaultPlatforms?: Array<"ios" | "android" | "macos" | "windows" | "linux" | "unknown">;
|
|
mcp?: { server: string; tool: string };
|
|
};
|
|
};
|
|
|
|
export type OpenClawPluginNodeHostCommand = OpenClawPluginNodeHostCommandBase & {
|
|
// Not a discriminated handle signature: a union of different arities makes
|
|
// plain `command.handle(params)` uncallable for consumers holding the union.
|
|
// The node host enforces io presence for duplex commands at runtime.
|
|
duplex?: boolean;
|
|
handle: (
|
|
paramsJSON?: string | null,
|
|
io?: OpenClawPluginNodeHostCommandIo,
|
|
context?: OpenClawPluginNodeHostCommandContext,
|
|
) => Promise<string>;
|
|
};
|