Files
openclaw/src/plugins/plugin-command-account-start-scope.ts
T
Peter Steinberger d6f70a96cb fix(plugins): native commands execute the selected plugin (#121544)
* fix(plugins): preserve selected command identity

* test(telegram): use scoped command registries

* test(telegram): isolate command runtime fixtures

* test(telegram): warm native command runtime

* refactor(plugins): keep command metadata private

* fix(plugins): accept synchronous command handlers

* fix(plugins): scope command drain bypass to live execution

* test(telegram): use scoped command registry fixtures

* test(telegram): isolate native menu runtime fixtures

* test(telegram): isolate login session store

* test(telegram): surface login flow failures

* test(telegram): preload native login module

* test(telegram): scope native command registries

* fix(plugins): complete command dispatch contracts

* fix(plugins): break command dispatch import cycles

* fix(plugins): stabilize command dispatch contracts

* fix(channels): keep plugin dispatch options internal

* fix(plugins): keep command dispatch carrier opaque

* test(channels): align delivery adapter fixtures

* test(delivery): align custody ownership coverage

* test(delivery): align latest queue reconciliation

* test(channels): drop obsolete delivery wrappers

* fix(plugins): rebind channel reload starts

* fix(plugins): scope command catalog reloads

* fix(ci): align current runtime contracts

* chore(plugin-sdk): refresh API baseline
2026-08-10 19:30:47 -07:00

35 lines
1.1 KiB
TypeScript

import { AsyncLocalStorage } from "node:async_hooks";
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
type PluginCommandAccountStartScope = Readonly<{
channelId: string;
retainCatalog: () => void;
}>;
const PLUGIN_COMMAND_ACCOUNT_START_SCOPE_KEY: unique symbol = Symbol.for(
"openclaw.pluginCommandAccountStartScope",
);
const pluginCommandAccountStartScope = resolveGlobalSingleton<
AsyncLocalStorage<PluginCommandAccountStartScope>
>(
PLUGIN_COMMAND_ACCOUNT_START_SCOPE_KEY,
() => new AsyncLocalStorage<PluginCommandAccountStartScope>(),
);
/** Runs one channel account startup lifetime with its catalog-retention owner. */
export function withPluginCommandAccountStartScope<T>(
scope: PluginCommandAccountStartScope,
run: () => T,
): T {
return pluginCommandAccountStartScope.run(scope, run);
}
/** Marks the current account only when its startup channel matches the catalog provider. */
export function retainPluginCommandCatalogForCurrentAccount(channelId: string): void {
const scope = pluginCommandAccountStartScope.getStore();
if (scope?.channelId === channelId) {
scope.retainCatalog();
}
}