refactor: move tasks into bundled plugin

This commit is contained in:
Peter Steinberger
2026-03-31 14:48:22 +01:00
parent 584db0aff2
commit c75f4695b7
39 changed files with 2492 additions and 736 deletions

View File

@@ -215,6 +215,20 @@ describe("plugin runtime command execution", () => {
]);
},
},
{
name: "exposes runtime.operations helpers",
assert: (runtime: ReturnType<typeof createPluginRuntime>) => {
expect(runtime.operations).toBeDefined();
expectFunctionKeys(runtime.operations as Record<string, unknown>, [
"dispatch",
"getById",
"findByRunId",
"list",
"summarize",
"cancel",
]);
},
},
] as const)("$name", ({ assert }) => {
expectRuntimeShape(assert);
});

View File

@@ -6,8 +6,10 @@ import {
createLazyRuntimeMethodBinder,
createLazyRuntimeModule,
} from "../../shared/lazy-runtime.js";
import { defaultTaskOperationsRuntime } from "../../tasks/operations-runtime.js";
import { VERSION } from "../../version.js";
import { listWebSearchProviders, runWebSearch } from "../../web-search/runtime.js";
import { getRegisteredOperationsRuntime } from "../operations-state.js";
import { createRuntimeAgent } from "./runtime-agent.js";
import { defineCachedValue } from "./runtime-cache.js";
import { createRuntimeChannel } from "./runtime-channel.js";
@@ -96,6 +98,20 @@ function createRuntimeModelAuth(): PluginRuntime["modelAuth"] {
};
}
function createRuntimeOperations(): PluginRuntime["operations"] {
const resolveRuntime = () => getRegisteredOperationsRuntime() ?? defaultTaskOperationsRuntime;
return {
dispatch: (event) => resolveRuntime().dispatch(event),
getById: (operationId) => resolveRuntime().getById(operationId),
findByRunId: (runId) => resolveRuntime().findByRunId(runId),
list: (query) => resolveRuntime().list(query),
summarize: (query) => resolveRuntime().summarize(query),
audit: (query) => resolveRuntime().audit(query),
maintenance: (query) => resolveRuntime().maintenance(query),
cancel: (params) => resolveRuntime().cancel(params),
};
}
function createUnavailableSubagentRuntime(): PluginRuntime["subagent"] {
const unavailable = () => {
throw new Error("Plugin runtime subagent methods are only available during a gateway request.");
@@ -203,6 +219,7 @@ export function createPluginRuntime(_options: CreatePluginRuntimeOptions = {}):
events: createRuntimeEvents(),
logging: createRuntimeLogging(),
state: { resolveStateDir },
operations: createRuntimeOperations(),
} satisfies Omit<
PluginRuntime,
"tts" | "mediaUnderstanding" | "stt" | "modelAuth" | "imageGeneration"

View File

@@ -1,5 +1,17 @@
import type { HeartbeatRunResult } from "../../infra/heartbeat-wake.js";
import type { LogLevel } from "../../logging/levels.js";
import type {
PluginOperationAuditFinding,
PluginOperationAuditQuery,
PluginOperationDispatchEvent,
PluginOperationDispatchResult,
PluginOperationListQuery,
PluginOperationMaintenanceQuery,
PluginOperationMaintenanceSummary,
PluginOperationRecord,
PluginOperationSummary,
PluginOperationsCancelResult,
} from "../operations-state.js";
export type { HeartbeatRunResult };
@@ -115,4 +127,19 @@ export type PluginRuntimeCore = {
cfg?: import("../../config/config.js").OpenClawConfig;
}) => Promise<import("../../agents/model-auth.js").ResolvedProviderAuth>;
};
operations: {
dispatch: (event: PluginOperationDispatchEvent) => Promise<PluginOperationDispatchResult>;
getById: (operationId: string) => Promise<PluginOperationRecord | null>;
findByRunId: (runId: string) => Promise<PluginOperationRecord | null>;
list: (query?: PluginOperationListQuery) => Promise<PluginOperationRecord[]>;
summarize: (query?: PluginOperationListQuery) => Promise<PluginOperationSummary>;
audit: (query?: PluginOperationAuditQuery) => Promise<PluginOperationAuditFinding[]>;
maintenance: (
query?: PluginOperationMaintenanceQuery,
) => Promise<PluginOperationMaintenanceSummary>;
cancel: (params: {
cfg: import("../../config/config.js").OpenClawConfig;
operationId: string;
}) => Promise<PluginOperationsCancelResult>;
};
};