
















@@ -235,6 +235,17 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
235235registry.diagnostics.push(diag);
236236};
237237238+const throwRegistrationError = (message: string): never => {
239+throw new Error(message);
240+};
241+242+const requireRegistrationValue = (value: string | undefined, message: string): string => {
243+if (!value) {
244+throw new Error(message);
245+}
246+return value;
247+};
248+238249const registerCodexAppServerExtensionFactory = (
239250record: PluginRecord,
240251factory: Parameters<OpenClawPluginApi["registerCodexAppServerExtensionFactory"]>[0],
@@ -414,23 +425,17 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
414425const eventList = Array.isArray(events) ? events : [events];
415426const normalizedEvents = eventList.map((event) => event.trim()).filter(Boolean);
416427const entry = opts?.entry ?? null;
417-const name = entry?.hook.name ?? opts?.name?.trim();
418-if (!name) {
419-pushDiagnostic({
420-level: "warn",
421-pluginId: record.id,
422-source: record.source,
423-message: "hook registration missing name",
424-});
425-return;
426-}
427-const existingHook = registry.hooks.find((entry) => entry.entry.hook.name === name);
428+const hookName = requireRegistrationValue(
429+entry?.hook.name ?? opts?.name?.trim(),
430+"hook registration missing name",
431+);
432+const existingHook = registry.hooks.find((entry) => entry.entry.hook.name === hookName);
428433if (existingHook) {
429434pushDiagnostic({
430435level: "error",
431436pluginId: record.id,
432437source: record.source,
433-message: `hook already registered: ${name} (${existingHook.pluginId})`,
438+message: `hook already registered: ${hookName} (${existingHook.pluginId})`,
434439});
435440return;
436441}
@@ -441,7 +446,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
441446 ...entry,
442447hook: {
443448 ...entry.hook,
444- name,
449+name: hookName,
445450 description,
446451source: "openclaw-plugin",
447452pluginId: record.id,
@@ -453,7 +458,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
453458}
454459 : {
455460hook: {
456- name,
461+name: hookName,
457462 description,
458463source: "openclaw-plugin",
459464pluginId: record.id,
@@ -466,7 +471,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
466471invocation: { enabled: true },
467472};
468473469-record.hookNames.push(name);
474+record.hookNames.push(hookName);
470475registry.hooks.push({
471476pluginId: record.id,
472477entry: hookEntry,
@@ -483,7 +488,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
483488return;
484489}
485490486-const previousRegistrations = activePluginHookRegistrations.get(name) ?? [];
491+const previousRegistrations = activePluginHookRegistrations.get(hookName) ?? [];
487492for (const registration of previousRegistrations) {
488493unregisterInternalHook(registration.event, registration.handler);
489494}
@@ -496,10 +501,10 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
496501registerInternalHook(event, handler);
497502nextRegistrations.push({ event, handler });
498503}
499-activePluginHookRegistrations.set(name, nextRegistrations);
504+activePluginHookRegistrations.set(hookName, nextRegistrations);
500505const rollbackEntries = pluginHookRollback.get(record.id) ?? [];
501506rollbackEntries.push({
502- name,
507+name: hookName,
503508previousRegistrations: [...previousRegistrations],
504509});
505510pluginHookRollback.set(record.id, rollbackEntries);
@@ -1562,13 +1567,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
15621567},
15631568registerMemoryCapability: (capability) => {
15641569if (!hasKind(record.kind, "memory")) {
1565-pushDiagnostic({
1566-level: "error",
1567-pluginId: record.id,
1568-source: record.source,
1569-message: "only memory plugins can register a memory capability",
1570-});
1571-return;
1570+throwRegistrationError("only memory plugins can register a memory capability");
15721571}
15731572if (
15741573Array.isArray(record.kind) &&
@@ -1588,13 +1587,9 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
15881587},
15891588registerMemoryPromptSection: (builder) => {
15901589if (!hasKind(record.kind, "memory")) {
1591-pushDiagnostic({
1592-level: "error",
1593-pluginId: record.id,
1594-source: record.source,
1595-message: "only memory plugins can register a memory prompt section",
1596-});
1597-return;
1590+throwRegistrationError(
1591+"only memory plugins can register a memory prompt section",
1592+);
15981593}
15991594if (
16001595Array.isArray(record.kind) &&
@@ -1620,13 +1615,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
16201615},
16211616registerMemoryFlushPlan: (resolver) => {
16221617if (!hasKind(record.kind, "memory")) {
1623-pushDiagnostic({
1624-level: "error",
1625-pluginId: record.id,
1626-source: record.source,
1627-message: "only memory plugins can register a memory flush plan",
1628-});
1629-return;
1618+throwRegistrationError("only memory plugins can register a memory flush plan");
16301619}
16311620if (
16321621Array.isArray(record.kind) &&
@@ -1646,13 +1635,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
16461635},
16471636registerMemoryRuntime: (runtime) => {
16481637if (!hasKind(record.kind, "memory")) {
1649-pushDiagnostic({
1650-level: "error",
1651-pluginId: record.id,
1652-source: record.source,
1653-message: "only memory plugins can register a memory runtime",
1654-});
1655-return;
1638+throwRegistrationError("only memory plugins can register a memory runtime");
16561639}
16571640if (
16581641Array.isArray(record.kind) &&
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。