Skip to content

Commit 43a2156

Browse files
committed
fix(plugin-sdk): split runtime task contracts
1 parent 52bf19c commit 43a2156

4 files changed

Lines changed: 84 additions & 57 deletions

File tree

src/plugin-sdk/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type {
6767
PluginRuntimeTaskFlows,
6868
PluginRuntimeTaskRuns,
6969
PluginRuntimeTasks,
70-
} from "../plugins/runtime/runtime-tasks.js";
70+
} from "../plugins/runtime/runtime-tasks.types.js";
7171
export type {
7272
TaskFlowDetail,
7373
TaskFlowView,

src/plugins/runtime/runtime-tasks.ts

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { OpenClawConfig } from "../../config/types.openclaw.js";
21
import { cancelTaskById, listTasksForFlowId } from "../../tasks/runtime-internal.js";
32
import {
43
mapTaskFlowDetail,
@@ -21,16 +20,23 @@ import {
2120
resolveTaskForLookupTokenForOwner,
2221
} from "../../tasks/task-owner-access.js";
2322
import { normalizeDeliveryContext } from "../../utils/delivery-context.shared.js";
24-
import type { OpenClawPluginToolContext } from "../tool-types.js";
2523
import type { PluginRuntimeTaskFlow } from "./runtime-taskflow.types.js";
2624
import type {
25+
BoundTaskFlowsRuntime,
26+
BoundTaskRunsRuntime,
27+
PluginRuntimeTaskFlows,
28+
PluginRuntimeTaskRuns,
29+
PluginRuntimeTasks,
2730
TaskFlowDetail,
28-
TaskFlowView,
29-
TaskRunAggregateSummary,
3031
TaskRunCancelResult,
31-
TaskRunDetail,
32-
TaskRunView,
33-
} from "./task-domain-types.js";
32+
} from "./runtime-tasks.types.js";
33+
export type {
34+
BoundTaskFlowsRuntime,
35+
BoundTaskRunsRuntime,
36+
PluginRuntimeTaskFlows,
37+
PluginRuntimeTaskRuns,
38+
PluginRuntimeTasks,
39+
} from "./runtime-tasks.types.js";
3440

3541
function assertSessionKey(sessionKey: string | undefined, errorMessage: string): string {
3642
const normalized = sessionKey?.trim();
@@ -51,53 +57,6 @@ function mapCancelledTaskResult(
5157
};
5258
}
5359

54-
export type BoundTaskRunsRuntime = {
55-
readonly sessionKey: string;
56-
readonly requesterOrigin?: ReturnType<typeof normalizeDeliveryContext>;
57-
get: (taskId: string) => TaskRunDetail | undefined;
58-
list: () => TaskRunView[];
59-
findLatest: () => TaskRunDetail | undefined;
60-
resolve: (token: string) => TaskRunDetail | undefined;
61-
cancel: (params: { taskId: string; cfg: OpenClawConfig }) => Promise<TaskRunCancelResult>;
62-
};
63-
64-
export type PluginRuntimeTaskRuns = {
65-
bindSession: (params: {
66-
sessionKey: string;
67-
requesterOrigin?: import("../../tasks/task-registry.types.js").TaskDeliveryState["requesterOrigin"];
68-
}) => BoundTaskRunsRuntime;
69-
fromToolContext: (
70-
ctx: Pick<OpenClawPluginToolContext, "sessionKey" | "deliveryContext">,
71-
) => BoundTaskRunsRuntime;
72-
};
73-
74-
export type BoundTaskFlowsRuntime = {
75-
readonly sessionKey: string;
76-
readonly requesterOrigin?: ReturnType<typeof normalizeDeliveryContext>;
77-
get: (flowId: string) => TaskFlowDetail | undefined;
78-
list: () => TaskFlowView[];
79-
findLatest: () => TaskFlowDetail | undefined;
80-
resolve: (token: string) => TaskFlowDetail | undefined;
81-
getTaskSummary: (flowId: string) => TaskRunAggregateSummary | undefined;
82-
};
83-
84-
export type PluginRuntimeTaskFlows = {
85-
bindSession: (params: {
86-
sessionKey: string;
87-
requesterOrigin?: import("../../tasks/task-registry.types.js").TaskDeliveryState["requesterOrigin"];
88-
}) => BoundTaskFlowsRuntime;
89-
fromToolContext: (
90-
ctx: Pick<OpenClawPluginToolContext, "sessionKey" | "deliveryContext">,
91-
) => BoundTaskFlowsRuntime;
92-
};
93-
94-
export type PluginRuntimeTasks = {
95-
runs: PluginRuntimeTaskRuns;
96-
flows: PluginRuntimeTaskFlows;
97-
/** @deprecated Use runtime.tasks.flows for DTO-based TaskFlow access. */
98-
flow: PluginRuntimeTaskFlow;
99-
};
100-
10160
function createBoundTaskRunsRuntime(params: {
10261
sessionKey: string;
10362
requesterOrigin?: import("../../tasks/task-registry.types.js").TaskDeliveryState["requesterOrigin"];
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import type { OpenClawConfig } from "../../config/types.openclaw.js";
2+
import type { TaskDeliveryState } from "../../tasks/task-registry.types.js";
3+
import type { OpenClawPluginToolContext } from "../tool-types.js";
4+
import type { PluginRuntimeTaskFlow } from "./runtime-taskflow.types.js";
5+
import type {
6+
TaskFlowDetail,
7+
TaskFlowView,
8+
TaskRunAggregateSummary,
9+
TaskRunCancelResult,
10+
TaskRunDetail,
11+
TaskRunView,
12+
} from "./task-domain-types.js";
13+
export type {
14+
TaskFlowDetail,
15+
TaskFlowView,
16+
TaskRunAggregateSummary,
17+
TaskRunCancelResult,
18+
TaskRunDetail,
19+
TaskRunView,
20+
} from "./task-domain-types.js";
21+
22+
export type BoundTaskRunsRuntime = {
23+
readonly sessionKey: string;
24+
readonly requesterOrigin?: TaskDeliveryState["requesterOrigin"];
25+
get: (taskId: string) => TaskRunDetail | undefined;
26+
list: () => TaskRunView[];
27+
findLatest: () => TaskRunDetail | undefined;
28+
resolve: (token: string) => TaskRunDetail | undefined;
29+
cancel: (params: { taskId: string; cfg: OpenClawConfig }) => Promise<TaskRunCancelResult>;
30+
};
31+
32+
export type PluginRuntimeTaskRuns = {
33+
bindSession: (params: {
34+
sessionKey: string;
35+
requesterOrigin?: TaskDeliveryState["requesterOrigin"];
36+
}) => BoundTaskRunsRuntime;
37+
fromToolContext: (
38+
ctx: Pick<OpenClawPluginToolContext, "sessionKey" | "deliveryContext">,
39+
) => BoundTaskRunsRuntime;
40+
};
41+
42+
export type BoundTaskFlowsRuntime = {
43+
readonly sessionKey: string;
44+
readonly requesterOrigin?: TaskDeliveryState["requesterOrigin"];
45+
get: (flowId: string) => TaskFlowDetail | undefined;
46+
list: () => TaskFlowView[];
47+
findLatest: () => TaskFlowDetail | undefined;
48+
resolve: (token: string) => TaskFlowDetail | undefined;
49+
getTaskSummary: (flowId: string) => TaskRunAggregateSummary | undefined;
50+
};
51+
52+
export type PluginRuntimeTaskFlows = {
53+
bindSession: (params: {
54+
sessionKey: string;
55+
requesterOrigin?: TaskDeliveryState["requesterOrigin"];
56+
}) => BoundTaskFlowsRuntime;
57+
fromToolContext: (
58+
ctx: Pick<OpenClawPluginToolContext, "sessionKey" | "deliveryContext">,
59+
) => BoundTaskFlowsRuntime;
60+
};
61+
62+
export type PluginRuntimeTasks = {
63+
runs: PluginRuntimeTaskRuns;
64+
flows: PluginRuntimeTaskFlows;
65+
/** @deprecated Use runtime.tasks.flows for DTO-based TaskFlow access. */
66+
flow: PluginRuntimeTaskFlow;
67+
};

src/plugins/runtime/types-core.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
TextToSpeech,
1111
TextToSpeechTelephony,
1212
} from "../../plugin-sdk/tts-runtime.types.js";
13+
import type { PluginRuntimeTaskFlows, PluginRuntimeTaskRuns } from "./runtime-tasks.types.js";
1314

1415
export type { HeartbeatRunResult };
1516

@@ -153,8 +154,8 @@ export type PluginRuntimeCore = {
153154
resolveStateDir: typeof import("../../config/paths.js").resolveStateDir;
154155
};
155156
tasks: {
156-
runs: import("./runtime-tasks.js").PluginRuntimeTaskRuns;
157-
flows: import("./runtime-tasks.js").PluginRuntimeTaskFlows;
157+
runs: PluginRuntimeTaskRuns;
158+
flows: PluginRuntimeTaskFlows;
158159
/** @deprecated Use runtime.tasks.flows for DTO-based TaskFlow access. */
159160
flow: import("./runtime-taskflow.types.js").PluginRuntimeTaskFlow;
160161
};

0 commit comments

Comments
 (0)