Files
openclaw/extensions/linux-node/src/command-utils.ts
Peter Steinberger 92cca9343e feat(linux): headless node device capabilities (camera, location, notifications) (#107193)
* feat(linux): add node device capabilities

* fix(linux-node): actionable pending-approval error + node-host advertise integration test

* fix(linux-node): map geoclue access-denied to LOCATION_DISABLED; floor camera maxWidth to avoid zero-height scale

* fix(linux-node): clamp small camera maxWidth to 2 instead of default

* docs(linux-node): clarify where-am-i -t is a process timeout, not update throttle

* refactor(gateway): extract legacy-node filter + rejection hint to fit LOC ratchet; docs-map + deadcode baseline

* fix(gateway): drop now-unused DEFAULT_DANGEROUS_NODE_COMMANDS import after hint extraction

* test(node-host): drop imports orphaned by removed error-code test
2026-07-14 02:30:36 -07:00

54 lines
1.8 KiB
TypeScript

import type { OpenClawPluginNodeHostCommandAvailabilityContext } from "openclaw/plugin-sdk/plugin-entry";
import type { CommandOptions, SpawnResult } from "openclaw/plugin-sdk/process-runtime";
import {
resolveLinuxNodePluginConfigFromHost,
type ResolvedLinuxNodePluginConfig,
} from "./config.js";
export type RunCommand = (argv: string[], options: CommandOptions) => Promise<SpawnResult>;
export function parseParams(paramsJSON: string | null | undefined): Record<string, unknown> {
if (!paramsJSON) {
return {};
}
try {
const parsed = JSON.parse(paramsJSON) as unknown;
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
? (parsed as Record<string, unknown>)
: {};
} catch {
return {};
}
}
export function readFiniteNumber(value: unknown): number | undefined {
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
}
export function clamp(value: number, minimum: number, maximum: number): number {
return Math.min(maximum, Math.max(minimum, value));
}
export function formatToolError(result: SpawnResult): string {
const detail = result.stderr.trim() || result.stdout.trim();
return detail
? detail.replaceAll(/\s+/gu, " ").slice(0, 300)
: `exit ${result.code ?? "unknown"}`;
}
export function assertToolResult(result: SpawnResult, code: string): void {
if (result.termination === "timeout" || result.termination === "no-output-timeout") {
throw new Error(`${code}: command timed out`);
}
if (result.code !== 0) {
throw new Error(`${code}: ${formatToolError(result)}`);
}
}
export function isCapabilityEnabledForHost(
context: OpenClawPluginNodeHostCommandAvailabilityContext,
capability: keyof ResolvedLinuxNodePluginConfig,
): boolean {
return resolveLinuxNodePluginConfigFromHost(context.config)?.[capability].enabled === true;
}