mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 05:12:15 +00:00
refactor(tasks): update plugin and acp task-flow consumers
This commit is contained in:
@@ -39,7 +39,7 @@ let AcpRuntimeError: typeof import("../runtime/errors.js").AcpRuntimeError;
|
||||
let resetAcpSessionManagerForTests: typeof import("./manager.js").__testing.resetAcpSessionManagerForTests;
|
||||
let findTaskByRunId: typeof import("../../tasks/task-registry.js").findTaskByRunId;
|
||||
let resetTaskRegistryForTests: typeof import("../../tasks/task-registry.js").resetTaskRegistryForTests;
|
||||
let resetFlowRegistryForTests: typeof import("../../tasks/flow-registry.js").resetFlowRegistryForTests;
|
||||
let resetTaskFlowRegistryForTests: typeof import("../../tasks/task-flow-registry.js").resetTaskFlowRegistryForTests;
|
||||
let installInMemoryTaskRegistryRuntime: typeof import("../../test-utils/task-registry-runtime.js").installInMemoryTaskRegistryRuntime;
|
||||
|
||||
const baseCfg = {
|
||||
@@ -55,13 +55,13 @@ async function withAcpManagerTaskStateDir(run: (root: string) => Promise<void>):
|
||||
await withTempDir({ prefix: "openclaw-acp-manager-task-" }, async (root) => {
|
||||
process.env.OPENCLAW_STATE_DIR = root;
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetFlowRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
installInMemoryTaskRegistryRuntime();
|
||||
try {
|
||||
await run(root);
|
||||
} finally {
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetFlowRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -184,7 +184,7 @@ describe("AcpSessionManager", () => {
|
||||
} = await import("./manager.js"));
|
||||
({ AcpRuntimeError } = await import("../runtime/errors.js"));
|
||||
({ findTaskByRunId, resetTaskRegistryForTests } = await import("../../tasks/task-registry.js"));
|
||||
({ resetFlowRegistryForTests } = await import("../../tasks/flow-registry.js"));
|
||||
({ resetTaskFlowRegistryForTests } = await import("../../tasks/task-flow-registry.js"));
|
||||
({ installInMemoryTaskRegistryRuntime } =
|
||||
await import("../../test-utils/task-registry-runtime.js"));
|
||||
});
|
||||
@@ -205,7 +205,7 @@ describe("AcpSessionManager", () => {
|
||||
process.env.OPENCLAW_STATE_DIR = ORIGINAL_STATE_DIR;
|
||||
}
|
||||
resetTaskRegistryForTests({ persist: false });
|
||||
resetFlowRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
});
|
||||
|
||||
it("marks ACP-shaped sessions without metadata as stale", () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { getFlowById, resetFlowRegistryForTests } from "../../tasks/flow-registry.js";
|
||||
import { getTaskFlowById, resetTaskFlowRegistryForTests } from "../../tasks/task-flow-registry.js";
|
||||
import { getTaskById, resetTaskRegistryForTests } from "../../tasks/task-registry.js";
|
||||
import { createRuntimeTaskFlow } from "./runtime-taskflow.js";
|
||||
|
||||
@@ -30,7 +30,7 @@ vi.mock("../../agents/subagent-control.js", () => ({
|
||||
|
||||
afterEach(() => {
|
||||
resetTaskRegistryForTests();
|
||||
resetFlowRegistryForTests({ persist: false });
|
||||
resetTaskFlowRegistryForTests({ persist: false });
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
@@ -146,7 +146,7 @@ describe("runtime TaskFlow", () => {
|
||||
parentFlowId: created.flowId,
|
||||
ownerKey: "agent:main:main",
|
||||
});
|
||||
expect(getFlowById(created.flowId)).toMatchObject({
|
||||
expect(getTaskFlowById(created.flowId)).toMatchObject({
|
||||
flowId: created.flowId,
|
||||
});
|
||||
expect(ownerTaskFlow.getTaskSummary(created.flowId)).toMatchObject({
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import {
|
||||
findLatestFlowForOwner,
|
||||
getFlowByIdForOwner,
|
||||
listFlowsForOwner,
|
||||
resolveFlowForLookupTokenForOwner,
|
||||
} from "../../tasks/flow-owner-access.js";
|
||||
import type { FlowRecord, JsonValue } from "../../tasks/flow-registry.types.js";
|
||||
import {
|
||||
createManagedFlow,
|
||||
failFlow,
|
||||
finishFlow,
|
||||
type FlowUpdateResult,
|
||||
requestFlowCancel,
|
||||
resumeFlow,
|
||||
setFlowWaiting,
|
||||
} from "../../tasks/flow-runtime-internal.js";
|
||||
import {
|
||||
cancelFlowByIdForOwner,
|
||||
getFlowTaskSummary,
|
||||
runTaskInFlowForOwner,
|
||||
} from "../../tasks/task-executor.js";
|
||||
import {
|
||||
findLatestTaskFlowForOwner,
|
||||
getTaskFlowByIdForOwner,
|
||||
listTaskFlowsForOwner,
|
||||
resolveTaskFlowForLookupTokenForOwner,
|
||||
} from "../../tasks/task-flow-owner-access.js";
|
||||
import type { TaskFlowRecord, JsonValue } from "../../tasks/task-flow-registry.types.js";
|
||||
import {
|
||||
createManagedTaskFlow,
|
||||
failFlow,
|
||||
finishFlow,
|
||||
type TaskFlowUpdateResult,
|
||||
requestFlowCancel,
|
||||
resumeFlow,
|
||||
setFlowWaiting,
|
||||
} from "../../tasks/task-flow-runtime-internal.js";
|
||||
import type {
|
||||
TaskDeliveryStatus,
|
||||
TaskDeliveryState,
|
||||
@@ -31,7 +31,7 @@ import type {
|
||||
import { normalizeDeliveryContext } from "../../utils/delivery-context.js";
|
||||
import type { OpenClawPluginToolContext } from "../types.js";
|
||||
|
||||
export type ManagedTaskFlowRecord = FlowRecord & {
|
||||
export type ManagedTaskFlowRecord = TaskFlowRecord & {
|
||||
syncMode: "managed";
|
||||
controllerId: string;
|
||||
};
|
||||
@@ -46,7 +46,7 @@ export type ManagedTaskFlowMutationResult =
|
||||
| {
|
||||
applied: false;
|
||||
code: ManagedTaskFlowMutationErrorCode;
|
||||
current?: FlowRecord;
|
||||
current?: TaskFlowRecord;
|
||||
};
|
||||
|
||||
export type BoundTaskFlowTaskRunResult =
|
||||
@@ -59,7 +59,7 @@ export type BoundTaskFlowTaskRunResult =
|
||||
created: false;
|
||||
reason: string;
|
||||
found: boolean;
|
||||
flow?: FlowRecord;
|
||||
flow?: TaskFlowRecord;
|
||||
};
|
||||
|
||||
export type BoundTaskFlowCancelResult = Awaited<ReturnType<typeof cancelFlowByIdForOwner>>;
|
||||
@@ -80,10 +80,10 @@ export type BoundTaskFlowRuntime = {
|
||||
updatedAt?: number;
|
||||
endedAt?: number | null;
|
||||
}) => ManagedTaskFlowRecord;
|
||||
get: (flowId: string) => FlowRecord | undefined;
|
||||
list: () => FlowRecord[];
|
||||
findLatest: () => FlowRecord | undefined;
|
||||
resolve: (token: string) => FlowRecord | undefined;
|
||||
get: (flowId: string) => TaskFlowRecord | undefined;
|
||||
list: () => TaskFlowRecord[];
|
||||
findLatest: () => TaskFlowRecord | undefined;
|
||||
resolve: (token: string) => TaskFlowRecord | undefined;
|
||||
getTaskSummary: (flowId: string) => TaskRegistrySummary | undefined;
|
||||
setWaiting: (params: {
|
||||
flowId: string;
|
||||
@@ -163,7 +163,9 @@ function assertSessionKey(sessionKey: string | undefined, errorMessage: string):
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function asManagedTaskFlowRecord(flow: FlowRecord | undefined): ManagedTaskFlowRecord | undefined {
|
||||
function asManagedTaskFlowRecord(
|
||||
flow: TaskFlowRecord | undefined,
|
||||
): ManagedTaskFlowRecord | undefined {
|
||||
if (!flow || flow.syncMode !== "managed" || !flow.controllerId) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -175,8 +177,8 @@ function resolveManagedFlowForOwner(params: {
|
||||
ownerKey: string;
|
||||
}):
|
||||
| { ok: true; flow: ManagedTaskFlowRecord }
|
||||
| { ok: false; code: "not_found" | "not_managed"; current?: FlowRecord } {
|
||||
const flow = getFlowByIdForOwner({
|
||||
| { ok: false; code: "not_found" | "not_managed"; current?: TaskFlowRecord } {
|
||||
const flow = getTaskFlowByIdForOwner({
|
||||
flowId: params.flowId,
|
||||
callerOwnerKey: params.ownerKey,
|
||||
});
|
||||
@@ -190,7 +192,7 @@ function resolveManagedFlowForOwner(params: {
|
||||
return { ok: true, flow: managed };
|
||||
}
|
||||
|
||||
function mapFlowUpdateResult(result: FlowUpdateResult): ManagedTaskFlowMutationResult {
|
||||
function mapFlowUpdateResult(result: TaskFlowUpdateResult): ManagedTaskFlowMutationResult {
|
||||
if (result.applied) {
|
||||
const managed = asManagedTaskFlowRecord(result.flow);
|
||||
if (!managed) {
|
||||
@@ -228,7 +230,7 @@ function createBoundTaskFlowRuntime(params: {
|
||||
sessionKey: ownerKey,
|
||||
...(requesterOrigin ? { requesterOrigin } : {}),
|
||||
createManaged: (input) =>
|
||||
createManagedFlow({
|
||||
createManagedTaskFlow({
|
||||
ownerKey,
|
||||
controllerId: input.controllerId,
|
||||
requesterOrigin,
|
||||
@@ -244,25 +246,25 @@ function createBoundTaskFlowRuntime(params: {
|
||||
endedAt: input.endedAt,
|
||||
}) as ManagedTaskFlowRecord,
|
||||
get: (flowId) =>
|
||||
getFlowByIdForOwner({
|
||||
getTaskFlowByIdForOwner({
|
||||
flowId,
|
||||
callerOwnerKey: ownerKey,
|
||||
}),
|
||||
list: () =>
|
||||
listFlowsForOwner({
|
||||
listTaskFlowsForOwner({
|
||||
callerOwnerKey: ownerKey,
|
||||
}),
|
||||
findLatest: () =>
|
||||
findLatestFlowForOwner({
|
||||
findLatestTaskFlowForOwner({
|
||||
callerOwnerKey: ownerKey,
|
||||
}),
|
||||
resolve: (token) =>
|
||||
resolveFlowForLookupTokenForOwner({
|
||||
resolveTaskFlowForLookupTokenForOwner({
|
||||
token,
|
||||
callerOwnerKey: ownerKey,
|
||||
}),
|
||||
getTaskSummary: (flowId) => {
|
||||
const flow = getFlowByIdForOwner({
|
||||
const flow = getTaskFlowByIdForOwner({
|
||||
flowId,
|
||||
callerOwnerKey: ownerKey,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user