fix(tasks): narrow control runtime override type

This commit is contained in:
Vincent Koc
2026-04-11 11:55:59 +01:00
parent a866c51b9d
commit 68fcd85bff

View File

@@ -63,24 +63,26 @@ type TaskRegistryDeliveryRuntime = Pick<
typeof import("./task-registry-delivery-runtime.js"),
"sendMessage"
>;
type TaskRegistryControlRuntime = Pick<
typeof import("./task-registry-control.runtime.js"),
"getAcpSessionManager" | "killSubagentRunAdmin"
>;
type TaskRegistryControlRuntime = {
getAcpSessionManager: () => Pick<
ReturnType<(typeof import("./task-registry-control.runtime.js"))["getAcpSessionManager"]>,
"cancelSession"
>;
killSubagentRunAdmin: (typeof import("./task-registry-control.runtime.js"))["killSubagentRunAdmin"];
};
const TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY = Symbol.for(
"openclaw.taskRegistry.deliveryRuntimeOverride",
);
const TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY = Symbol.for(
"openclaw.taskRegistry.controlRuntimeOverride",
);
type TaskRegistryGlobalWithDeliveryOverride = typeof globalThis & {
type TaskRegistryGlobalWithRuntimeOverrides = typeof globalThis & {
[TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY]?: TaskRegistryDeliveryRuntime | null;
[TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY]?: TaskRegistryControlRuntime | null;
};
let deliveryRuntimePromise: Promise<typeof import("./task-registry-delivery-runtime.js")> | null =
null;
let controlRuntimePromise: Promise<typeof import("./task-registry-control.runtime.js")> | null =
null;
let controlRuntimePromise: Promise<TaskRegistryControlRuntime> | null = null;
type TaskDeliveryOwner = {
sessionKey?: string;
@@ -376,7 +378,7 @@ function appendTaskEvent(event: {
}
function loadTaskRegistryDeliveryRuntime() {
const deliveryRuntimeOverride = (globalThis as TaskRegistryGlobalWithDeliveryOverride)[
const deliveryRuntimeOverride = (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[
TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY
];
if (deliveryRuntimeOverride) {
@@ -387,7 +389,7 @@ function loadTaskRegistryDeliveryRuntime() {
}
function loadTaskRegistryControlRuntime() {
const controlRuntimeOverride = (globalThis as TaskRegistryGlobalWithDeliveryOverride)[
const controlRuntimeOverride = (globalThis as TaskRegistryGlobalWithRuntimeOverrides)[
TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY
];
if (controlRuntimeOverride) {
@@ -1978,28 +1980,28 @@ export function resetTaskRegistryForTests(opts?: { persist?: boolean }) {
}
export function resetTaskRegistryDeliveryRuntimeForTests() {
(globalThis as TaskRegistryGlobalWithDeliveryOverride)[
(globalThis as TaskRegistryGlobalWithRuntimeOverrides)[
TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY
] = null;
deliveryRuntimePromise = null;
}
export function setTaskRegistryDeliveryRuntimeForTests(runtime: TaskRegistryDeliveryRuntime): void {
(globalThis as TaskRegistryGlobalWithDeliveryOverride)[
(globalThis as TaskRegistryGlobalWithRuntimeOverrides)[
TASK_REGISTRY_DELIVERY_RUNTIME_OVERRIDE_KEY
] = runtime;
deliveryRuntimePromise = null;
}
export function resetTaskRegistryControlRuntimeForTests() {
(globalThis as TaskRegistryGlobalWithDeliveryOverride)[
(globalThis as TaskRegistryGlobalWithRuntimeOverrides)[
TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY
] = null;
controlRuntimePromise = null;
}
export function setTaskRegistryControlRuntimeForTests(runtime: TaskRegistryControlRuntime): void {
(globalThis as TaskRegistryGlobalWithDeliveryOverride)[
(globalThis as TaskRegistryGlobalWithRuntimeOverrides)[
TASK_REGISTRY_CONTROL_RUNTIME_OVERRIDE_KEY
] = runtime;
controlRuntimePromise = null;