Files
openclaw/src/tasks/detached-task-runtime-state.ts
Mariano bd3ad3436e tasks: add detached runtime plugin registration contract (#68915)
* tasks: register detached runtime plugins

* tasks: harden detached runtime ownership

* tasks: extract detached runtime contract types

* changelog: note detached runtime contract

* changelog: attribute detached runtime contract
2026-04-19 13:13:11 +02:00

55 lines
1.6 KiB
TypeScript

import type {
DetachedTaskLifecycleRuntime,
DetachedTaskLifecycleRuntimeRegistration,
} from "./detached-task-runtime-contract.js";
export type { DetachedTaskLifecycleRuntime, DetachedTaskLifecycleRuntimeRegistration };
let detachedTaskLifecycleRuntimeRegistration: DetachedTaskLifecycleRuntimeRegistration | undefined;
export function registerDetachedTaskLifecycleRuntime(
pluginId: string,
runtime: DetachedTaskLifecycleRuntime,
): void {
detachedTaskLifecycleRuntimeRegistration = {
pluginId,
runtime,
};
}
export function getDetachedTaskLifecycleRuntimeRegistration():
| DetachedTaskLifecycleRuntimeRegistration
| undefined {
if (!detachedTaskLifecycleRuntimeRegistration) {
return undefined;
}
return {
pluginId: detachedTaskLifecycleRuntimeRegistration.pluginId,
runtime: detachedTaskLifecycleRuntimeRegistration.runtime,
};
}
export function getRegisteredDetachedTaskLifecycleRuntime():
| DetachedTaskLifecycleRuntime
| undefined {
return detachedTaskLifecycleRuntimeRegistration?.runtime;
}
export function restoreDetachedTaskLifecycleRuntimeRegistration(
registration: DetachedTaskLifecycleRuntimeRegistration | undefined,
): void {
detachedTaskLifecycleRuntimeRegistration = registration
? {
pluginId: registration.pluginId,
runtime: registration.runtime,
}
: undefined;
}
export function clearDetachedTaskLifecycleRuntimeRegistration(): void {
detachedTaskLifecycleRuntimeRegistration = undefined;
}
export const _resetDetachedTaskLifecycleRuntimeRegistration =
clearDetachedTaskLifecycleRuntimeRegistration;