mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-09 00:34:04 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
|
|
import type { OpenClawPluginCommandDefinition } from "./types.js";
|
|
|
|
export type RegisteredPluginCommand = OpenClawPluginCommandDefinition & {
|
|
pluginId: string;
|
|
pluginName?: string;
|
|
pluginRoot?: string;
|
|
};
|
|
|
|
type PluginCommandState = {
|
|
pluginCommands: Map<string, RegisteredPluginCommand>;
|
|
registryLocked: boolean;
|
|
};
|
|
|
|
const PLUGIN_COMMAND_STATE_KEY = Symbol.for("openclaw.pluginCommandsState");
|
|
|
|
const getState = () =>
|
|
resolveGlobalSingleton<PluginCommandState>(PLUGIN_COMMAND_STATE_KEY, () => ({
|
|
pluginCommands: new Map<string, RegisteredPluginCommand>(),
|
|
registryLocked: false,
|
|
}));
|
|
|
|
const getPluginCommandMap = () => getState().pluginCommands;
|
|
|
|
export const pluginCommands = new Proxy(new Map<string, RegisteredPluginCommand>(), {
|
|
get(_target, property) {
|
|
const value = Reflect.get(getPluginCommandMap(), property, getPluginCommandMap());
|
|
return typeof value === "function" ? value.bind(getPluginCommandMap()) : value;
|
|
},
|
|
});
|
|
|
|
export function isPluginCommandRegistryLocked(): boolean {
|
|
return getState().registryLocked;
|
|
}
|
|
|
|
export function setPluginCommandRegistryLocked(locked: boolean): void {
|
|
getState().registryLocked = locked;
|
|
}
|
|
|
|
export function clearPluginCommands(): void {
|
|
pluginCommands.clear();
|
|
}
|
|
|
|
export function clearPluginCommandsForPlugin(pluginId: string): void {
|
|
for (const [key, cmd] of pluginCommands.entries()) {
|
|
if (cmd.pluginId === pluginId) {
|
|
pluginCommands.delete(key);
|
|
}
|
|
}
|
|
}
|
|
|
|
function resolvePluginNativeName(
|
|
command: OpenClawPluginCommandDefinition,
|
|
provider?: string,
|
|
): string {
|
|
const providerName = provider?.trim().toLowerCase();
|
|
const providerOverride = providerName ? command.nativeNames?.[providerName] : undefined;
|
|
if (typeof providerOverride === "string" && providerOverride.trim()) {
|
|
return providerOverride.trim();
|
|
}
|
|
const defaultOverride = command.nativeNames?.default;
|
|
if (typeof defaultOverride === "string" && defaultOverride.trim()) {
|
|
return defaultOverride.trim();
|
|
}
|
|
return command.name;
|
|
}
|
|
|
|
export function getPluginCommandSpecs(provider?: string): Array<{
|
|
name: string;
|
|
description: string;
|
|
acceptsArgs: boolean;
|
|
}> {
|
|
const providerName = provider?.trim().toLowerCase();
|
|
if (providerName && providerName !== "telegram" && providerName !== "discord") {
|
|
return [];
|
|
}
|
|
return Array.from(pluginCommands.values()).map((cmd) => ({
|
|
name: resolvePluginNativeName(cmd, provider),
|
|
description: cmd.description,
|
|
acceptsArgs: cmd.acceptsArgs ?? false,
|
|
}));
|
|
}
|