refactor(plugin-sdk): add managed task flow runtime · openclaw/openclaw@b60eb17
steipete
·
2026-04-28
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -725,18 +725,18 @@ canonical replacement.
|
725 | 725 | |
726 | 726 | </Accordion> |
727 | 727 | |
728 | | -<Accordion title="runtime.tasks.flow → runtime.tasks.flows"> |
| 728 | +<Accordion title="runtime.tasks.flow → runtime.tasks.managedFlows"> |
729 | 729 | **Old**: `runtime.tasks.flow` (singular) returned a live task-flow accessor. |
730 | 730 | |
731 | | -**New**: `runtime.tasks.flows` (plural) returns DTO-based TaskFlow access, |
732 | | -which is import-safe and does not require the full task runtime to be |
733 | | -loaded. |
| 731 | +**New**: `runtime.tasks.managedFlows` keeps the managed TaskFlow mutation |
| 732 | +runtime for plugins that create, update, cancel, or run child tasks from a |
| 733 | +flow. Use `runtime.tasks.flows` when the plugin only needs DTO-based reads. |
734 | 734 | |
735 | 735 | ```typescript |
736 | 736 | // Before |
737 | | -const flow = api.runtime.tasks.flow(ctx); |
| 737 | +const flow = api.runtime.tasks.flow.fromToolContext(ctx); |
738 | 738 | // After |
739 | | -const flows = api.runtime.tasks.flows(ctx); |
| 739 | +const flow = api.runtime.tasks.managedFlows.fromToolContext(ctx); |
740 | 740 | ``` |
741 | 741 | |
742 | 742 | </Accordion> |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -179,11 +179,11 @@ Internal OpenClaw runtime code has the same direction: load config once at the C
|
179 | 179 | Inside the Gateway this runtime is in-process. In plugin CLI commands it calls the configured Gateway over RPC, so commands such as `openclaw googlemeet recover-tab` can inspect paired nodes from the terminal. Node commands still go through normal Gateway node pairing, command allowlists, and node-local command handling. |
180 | 180 | |
181 | 181 | </Accordion> |
182 | | -<Accordion title="api.runtime.taskFlow"> |
| 182 | +<Accordion title="api.runtime.tasks.managedFlows"> |
183 | 183 | Bind a Task Flow runtime to an existing OpenClaw session key or trusted tool context, then create and manage Task Flows without passing an owner on every call. |
184 | 184 | |
185 | 185 | ```typescript |
186 | | -const taskFlow = api.runtime.taskFlow.fromToolContext(ctx); |
| 186 | +const taskFlow = api.runtime.tasks.managedFlows.fromToolContext(ctx); |
187 | 187 | |
188 | 188 | const created = taskFlow.createManaged({ |
189 | 189 | controllerId: "my-plugin/review-batch", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,7 @@ The plugin applies:
|
89 | 89 | - Request body size and timeout guards |
90 | 90 | - Fixed-window rate limiting |
91 | 91 | - In-flight request limiting |
92 | | -- Owner-bound TaskFlow access through `api.runtime.taskFlow.bindSession(...)` |
| 92 | +- Owner-bound TaskFlow access through `api.runtime.tasks.managedFlows.bindSession(...)` |
93 | 93 | |
94 | 94 | ## Request format |
95 | 95 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,8 +13,8 @@ export default definePluginEntry({
|
13 | 13 | return null; |
14 | 14 | } |
15 | 15 | const taskFlow = |
16 | | -api.runtime?.taskFlow && ctx.sessionKey |
17 | | - ? api.runtime.taskFlow.fromToolContext(ctx) |
| 16 | +api.runtime?.tasks.managedFlows && ctx.sessionKey |
| 17 | + ? api.runtime.tasks.managedFlows.fromToolContext(ctx) |
18 | 18 | : undefined; |
19 | 19 | return createLobsterTool(api, { taskFlow }) as AnyAgentTool; |
20 | 20 | }) as OpenClawPluginToolFactory, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ type JsonLike =
|
12 | 12 | }; |
13 | 13 | |
14 | 14 | type BoundTaskFlow = ReturnType< |
15 | | -NonNullable<OpenClawPluginApi["runtime"]>["taskFlow"]["bindSession"] |
| 15 | +NonNullable<OpenClawPluginApi["runtime"]>["tasks"]["managedFlows"]["bindSession"] |
16 | 16 | >; |
17 | 17 | |
18 | 18 | type FlowRecord = ReturnType<BoundTaskFlow["createManaged"]>; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ import {
|
13 | 13 | } from "./lobster-taskflow.js"; |
14 | 14 | |
15 | 15 | type BoundTaskFlow = ReturnType< |
16 | | -NonNullable<OpenClawPluginApi["runtime"]>["taskFlow"]["bindSession"] |
| 16 | +NonNullable<OpenClawPluginApi["runtime"]>["tasks"]["managedFlows"]["bindSession"] |
17 | 17 | >; |
18 | 18 | |
19 | 19 | type JsonLike = |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,7 @@ import { vi } from "vitest";
|
2 | 2 | import type { OpenClawPluginApi } from "../runtime-api.js"; |
3 | 3 | |
4 | 4 | export type BoundTaskFlow = ReturnType< |
5 | | -NonNullable<OpenClawPluginApi["runtime"]>["taskFlow"]["bindSession"] |
| 5 | +NonNullable<OpenClawPluginApi["runtime"]>["tasks"]["managedFlows"]["bindSession"] |
6 | 6 | >; |
7 | 7 | |
8 | 8 | export function createFakeTaskFlow(overrides?: Partial<BoundTaskFlow>): BoundTaskFlow { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -14,8 +14,10 @@ function createApi(params?: {
|
14 | 14 | source: "test", |
15 | 15 | pluginConfig: params?.pluginConfig ?? {}, |
16 | 16 | runtime: { |
17 | | -taskFlow: { |
18 | | -bindSession: vi.fn(({ sessionKey }: { sessionKey: string }) => ({ sessionKey })), |
| 17 | +tasks: { |
| 18 | +managedFlows: { |
| 19 | +bindSession: vi.fn(({ sessionKey }: { sessionKey: string }) => ({ sessionKey })), |
| 20 | +}, |
19 | 21 | }, |
20 | 22 | } as unknown as OpenClawPluginApi["runtime"], |
21 | 23 | registerHttpRoute: params?.registerHttpRoute ?? vi.fn(), |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ function registerWebhookRoutes(api: OpenClawPluginApi): void {
|
17 | 17 | }); |
18 | 18 | |
19 | 19 | for (const route of routes) { |
20 | | -const taskFlow = api.runtime.taskFlow.bindSession({ |
| 20 | +const taskFlow = api.runtime.tasks.managedFlows.bindSession({ |
21 | 21 | sessionKey: route.sessionKey, |
22 | 22 | }); |
23 | 23 | const target: TaskFlowWebhookTarget = { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ import {
|
18 | 18 | } from "../runtime-api.js"; |
19 | 19 | import type { WebhookSecretInput } from "./config.js"; |
20 | 20 | |
21 | | -type BoundTaskFlowRuntime = ReturnType<PluginRuntime["taskFlow"]["bindSession"]>; |
| 21 | +type BoundTaskFlowRuntime = ReturnType<PluginRuntime["tasks"]["managedFlows"]["bindSession"]>; |
22 | 22 | |
23 | 23 | type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue }; |
24 | 24 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。