if (!trimmed) { return"Command name cannot be empty";
}
// Must start with a letter, contain only letters, numbers, hyphens, underscores // Note: trimmed is already lowercased, so no need for /i flag if (!/^[a-z][a-z0-9_-]*$/.test(trimmed)) { return"Command name must start with a letter and contain only letters, numbers, hyphens, and underscores";
}
if (reservedCommands.has(trimmed)) { return `Command name "${trimmed}" is reserved by a built-in command`;
}
returnnull;
}
/** *Validateaplugincommanddefinitionwithoutregisteringit. *Returnsanerrormessageifinvalid,ornullifvalid. *Sharedbyboththeglobalregistrationpathandsnapshot(non-activating)loads.
*/
export function validatePluginCommandDefinition(
command: OpenClawPluginCommandDefinition,
): string | null { if (typeof command.handler !== "function") { return"Command handler must be a function";
} if (typeof command.name !== "string") { return"Command name must be a string";
} if (typeof command.description !== "string") { return"Command description must be a string";
} if (!command.description.trim()) { return"Command description cannot be empty";
} const nameError = validateCommandName(command.name.trim()); if (nameError) { return nameError;
} for (const [label, alias] of Object.entries(command.nativeNames ?? {})) { if (typeof alias !== "string") { continue;
} const aliasError = validateCommandName(alias.trim()); if (aliasError) { return `Native command alias "${label}" invalid: ${aliasError}`;
}
} for (const [label, message] of Object.entries(command.nativeProgressMessages ?? {})) { if (typeof message !== "string") { return `Native progress message "${label}" must be a string`;
} if (!message.trim()) { return `Native progress message "${label}" cannot be empty`;
}
} returnnull;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.