@openclaw/lobster 2026.5.2 → 2026.5.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +654 -0
- package/dist/runtime-api.js +3 -0
- package/package.json +20 -3
- package/index.ts +0 -24
- package/runtime-api.ts +0 -12
- package/src/lobster-ajv-cache.ts +0 -142
- package/src/lobster-core.d.ts +0 -60
- package/src/lobster-runner.test.ts +0 -572
- package/src/lobster-runner.ts +0 -395
- package/src/lobster-taskflow.test.ts +0 -227
- package/src/lobster-taskflow.ts +0 -279
- package/src/lobster-tool.test.ts +0 -353
- package/src/lobster-tool.ts +0 -320
- package/src/taskflow-test-helpers.ts +0 -48
- package/tsconfig.json +0 -16
package/src/lobster-taskflow.ts
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import type { OpenClawPluginApi } from "../runtime-api.js";
|
|
2
|
-
import type { LobsterEnvelope, LobsterRunner, LobsterRunnerParams } from "./lobster-runner.js";
|
|
3
|
-
|
|
4
|
-
type JsonLike =
|
|
5
|
-
| null
|
|
6
|
-
| boolean
|
|
7
|
-
| number
|
|
8
|
-
| string
|
|
9
|
-
| JsonLike[]
|
|
10
|
-
| {
|
|
11
|
-
[key: string]: JsonLike;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type BoundTaskFlow = ReturnType<
|
|
15
|
-
NonNullable<OpenClawPluginApi["runtime"]>["tasks"]["managedFlows"]["bindSession"]
|
|
16
|
-
>;
|
|
17
|
-
|
|
18
|
-
type FlowRecord = ReturnType<BoundTaskFlow["createManaged"]>;
|
|
19
|
-
type MutationResult = ReturnType<BoundTaskFlow["setWaiting"]>;
|
|
20
|
-
|
|
21
|
-
type LobsterApprovalWaitState = {
|
|
22
|
-
kind: "lobster_approval";
|
|
23
|
-
prompt: string;
|
|
24
|
-
items: JsonLike[];
|
|
25
|
-
resumeToken?: string;
|
|
26
|
-
approvalId?: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type RunManagedLobsterFlowParams = {
|
|
30
|
-
taskFlow: BoundTaskFlow;
|
|
31
|
-
runner: LobsterRunner;
|
|
32
|
-
runnerParams: LobsterRunnerParams;
|
|
33
|
-
controllerId: string;
|
|
34
|
-
goal: string;
|
|
35
|
-
stateJson?: JsonLike;
|
|
36
|
-
currentStep?: string;
|
|
37
|
-
waitingStep?: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
type ResumeManagedLobsterFlowParams = {
|
|
41
|
-
taskFlow: BoundTaskFlow;
|
|
42
|
-
runner: LobsterRunner;
|
|
43
|
-
runnerParams: LobsterRunnerParams & {
|
|
44
|
-
action: "resume";
|
|
45
|
-
approve: boolean;
|
|
46
|
-
} & ({ token: string } | { approvalId: string });
|
|
47
|
-
flowId: string;
|
|
48
|
-
expectedRevision: number;
|
|
49
|
-
currentStep?: string;
|
|
50
|
-
waitingStep?: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type ManagedLobsterFlowResult =
|
|
54
|
-
| {
|
|
55
|
-
ok: true;
|
|
56
|
-
envelope: LobsterEnvelope;
|
|
57
|
-
flow: FlowRecord;
|
|
58
|
-
mutation: MutationResult;
|
|
59
|
-
}
|
|
60
|
-
| {
|
|
61
|
-
ok: false;
|
|
62
|
-
flow?: FlowRecord;
|
|
63
|
-
mutation?: MutationResult;
|
|
64
|
-
error: Error;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
function toJsonLike(value: unknown, seen = new WeakSet<object>()): JsonLike {
|
|
68
|
-
if (value === null) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
switch (typeof value) {
|
|
72
|
-
case "boolean":
|
|
73
|
-
case "string":
|
|
74
|
-
return value;
|
|
75
|
-
case "number":
|
|
76
|
-
return Number.isFinite(value) ? value : String(value);
|
|
77
|
-
case "bigint":
|
|
78
|
-
return value.toString();
|
|
79
|
-
case "undefined":
|
|
80
|
-
case "function":
|
|
81
|
-
case "symbol":
|
|
82
|
-
return null;
|
|
83
|
-
case "object": {
|
|
84
|
-
if (value instanceof Date) {
|
|
85
|
-
return value.toISOString();
|
|
86
|
-
}
|
|
87
|
-
if (Array.isArray(value)) {
|
|
88
|
-
return value.map((item) => toJsonLike(item, seen));
|
|
89
|
-
}
|
|
90
|
-
if (seen.has(value)) {
|
|
91
|
-
return "[Circular]";
|
|
92
|
-
}
|
|
93
|
-
seen.add(value);
|
|
94
|
-
const jsonObject: Record<string, JsonLike> = {};
|
|
95
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
96
|
-
if (entry === undefined || typeof entry === "function" || typeof entry === "symbol") {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
jsonObject[key] = toJsonLike(entry, seen);
|
|
100
|
-
}
|
|
101
|
-
seen.delete(value);
|
|
102
|
-
return jsonObject;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function buildApprovalWaitState(envelope: Extract<LobsterEnvelope, { ok: true }>): JsonLike {
|
|
109
|
-
if (!envelope.requiresApproval) {
|
|
110
|
-
return {
|
|
111
|
-
kind: "lobster_approval",
|
|
112
|
-
prompt: "",
|
|
113
|
-
items: [],
|
|
114
|
-
} satisfies LobsterApprovalWaitState;
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
kind: "lobster_approval",
|
|
118
|
-
prompt: envelope.requiresApproval.prompt,
|
|
119
|
-
items: envelope.requiresApproval.items.map((item) => toJsonLike(item)),
|
|
120
|
-
...(envelope.requiresApproval.resumeToken
|
|
121
|
-
? { resumeToken: envelope.requiresApproval.resumeToken }
|
|
122
|
-
: {}),
|
|
123
|
-
...(envelope.requiresApproval.approvalId
|
|
124
|
-
? { approvalId: envelope.requiresApproval.approvalId }
|
|
125
|
-
: {}),
|
|
126
|
-
} satisfies LobsterApprovalWaitState;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function applyEnvelopeToFlow(params: {
|
|
130
|
-
taskFlow: BoundTaskFlow;
|
|
131
|
-
flow: FlowRecord;
|
|
132
|
-
envelope: LobsterEnvelope;
|
|
133
|
-
waitingStep: string;
|
|
134
|
-
}): MutationResult {
|
|
135
|
-
const { taskFlow, flow, envelope, waitingStep } = params;
|
|
136
|
-
|
|
137
|
-
if (!envelope.ok) {
|
|
138
|
-
return taskFlow.fail({
|
|
139
|
-
flowId: flow.flowId,
|
|
140
|
-
expectedRevision: flow.revision,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (envelope.status === "needs_approval") {
|
|
145
|
-
return taskFlow.setWaiting({
|
|
146
|
-
flowId: flow.flowId,
|
|
147
|
-
expectedRevision: flow.revision,
|
|
148
|
-
currentStep: waitingStep,
|
|
149
|
-
waitJson: buildApprovalWaitState(envelope),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return taskFlow.finish({
|
|
154
|
-
flowId: flow.flowId,
|
|
155
|
-
expectedRevision: flow.revision,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function buildEnvelopeError(envelope: Extract<LobsterEnvelope, { ok: false }>) {
|
|
160
|
-
return new Error(envelope.error.message);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export async function runManagedLobsterFlow(
|
|
164
|
-
params: RunManagedLobsterFlowParams,
|
|
165
|
-
): Promise<ManagedLobsterFlowResult> {
|
|
166
|
-
const flow = params.taskFlow.createManaged({
|
|
167
|
-
controllerId: params.controllerId,
|
|
168
|
-
goal: params.goal,
|
|
169
|
-
currentStep: params.currentStep ?? "run_lobster",
|
|
170
|
-
...(params.stateJson !== undefined ? { stateJson: params.stateJson } : {}),
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
const envelope = await params.runner.run(params.runnerParams);
|
|
175
|
-
const mutation = applyEnvelopeToFlow({
|
|
176
|
-
taskFlow: params.taskFlow,
|
|
177
|
-
flow,
|
|
178
|
-
envelope,
|
|
179
|
-
waitingStep: params.waitingStep ?? "await_lobster_approval",
|
|
180
|
-
});
|
|
181
|
-
if (!envelope.ok) {
|
|
182
|
-
return {
|
|
183
|
-
ok: false,
|
|
184
|
-
flow,
|
|
185
|
-
mutation,
|
|
186
|
-
error: buildEnvelopeError(envelope),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
ok: true,
|
|
191
|
-
envelope,
|
|
192
|
-
flow,
|
|
193
|
-
mutation,
|
|
194
|
-
};
|
|
195
|
-
} catch (error) {
|
|
196
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
197
|
-
try {
|
|
198
|
-
const mutation = params.taskFlow.fail({
|
|
199
|
-
flowId: flow.flowId,
|
|
200
|
-
expectedRevision: flow.revision,
|
|
201
|
-
});
|
|
202
|
-
return {
|
|
203
|
-
ok: false,
|
|
204
|
-
flow,
|
|
205
|
-
mutation,
|
|
206
|
-
error: err,
|
|
207
|
-
};
|
|
208
|
-
} catch {
|
|
209
|
-
return {
|
|
210
|
-
ok: false,
|
|
211
|
-
flow,
|
|
212
|
-
error: err,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export async function resumeManagedLobsterFlow(
|
|
219
|
-
params: ResumeManagedLobsterFlowParams,
|
|
220
|
-
): Promise<ManagedLobsterFlowResult> {
|
|
221
|
-
const resumed = params.taskFlow.resume({
|
|
222
|
-
flowId: params.flowId,
|
|
223
|
-
expectedRevision: params.expectedRevision,
|
|
224
|
-
status: "running",
|
|
225
|
-
currentStep: params.currentStep ?? "resume_lobster",
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
if (!resumed.applied) {
|
|
229
|
-
return {
|
|
230
|
-
ok: false,
|
|
231
|
-
mutation: resumed,
|
|
232
|
-
error: new Error(`TaskFlow resume failed: ${resumed.code}`),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
try {
|
|
237
|
-
const envelope = await params.runner.run(params.runnerParams);
|
|
238
|
-
const mutation = applyEnvelopeToFlow({
|
|
239
|
-
taskFlow: params.taskFlow,
|
|
240
|
-
flow: resumed.flow,
|
|
241
|
-
envelope,
|
|
242
|
-
waitingStep: params.waitingStep ?? "await_lobster_approval",
|
|
243
|
-
});
|
|
244
|
-
if (!envelope.ok) {
|
|
245
|
-
return {
|
|
246
|
-
ok: false,
|
|
247
|
-
flow: resumed.flow,
|
|
248
|
-
mutation,
|
|
249
|
-
error: buildEnvelopeError(envelope),
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
ok: true,
|
|
254
|
-
envelope,
|
|
255
|
-
flow: resumed.flow,
|
|
256
|
-
mutation,
|
|
257
|
-
};
|
|
258
|
-
} catch (error) {
|
|
259
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
260
|
-
try {
|
|
261
|
-
const mutation = params.taskFlow.fail({
|
|
262
|
-
flowId: params.flowId,
|
|
263
|
-
expectedRevision: resumed.flow.revision,
|
|
264
|
-
});
|
|
265
|
-
return {
|
|
266
|
-
ok: false,
|
|
267
|
-
flow: resumed.flow,
|
|
268
|
-
mutation,
|
|
269
|
-
error: err,
|
|
270
|
-
};
|
|
271
|
-
} catch {
|
|
272
|
-
return {
|
|
273
|
-
ok: false,
|
|
274
|
-
flow: resumed.flow,
|
|
275
|
-
error: err,
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
package/src/lobster-tool.test.ts
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
|
2
|
-
import { describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { OpenClawPluginApi, OpenClawPluginToolContext } from "../runtime-api.js";
|
|
4
|
-
import { createLobsterTool } from "./lobster-tool.js";
|
|
5
|
-
import { createFakeTaskFlow } from "./taskflow-test-helpers.js";
|
|
6
|
-
|
|
7
|
-
function fakeApi(overrides: Partial<OpenClawPluginApi> = {}): OpenClawPluginApi {
|
|
8
|
-
return createTestPluginApi({
|
|
9
|
-
id: "lobster",
|
|
10
|
-
name: "lobster",
|
|
11
|
-
source: "test",
|
|
12
|
-
runtime: { version: "test" } as any,
|
|
13
|
-
resolvePath: (p) => p,
|
|
14
|
-
...overrides,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function fakeCtx(overrides: Partial<OpenClawPluginToolContext> = {}): OpenClawPluginToolContext {
|
|
19
|
-
return {
|
|
20
|
-
config: {},
|
|
21
|
-
workspaceDir: "/tmp",
|
|
22
|
-
agentDir: "/tmp",
|
|
23
|
-
agentId: "main",
|
|
24
|
-
sessionKey: "main",
|
|
25
|
-
messageChannel: undefined,
|
|
26
|
-
agentAccountId: undefined,
|
|
27
|
-
sandboxed: false,
|
|
28
|
-
...overrides,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe("lobster plugin tool", () => {
|
|
33
|
-
it("returns the Lobster envelope in details", async () => {
|
|
34
|
-
const runner = {
|
|
35
|
-
run: vi.fn().mockResolvedValue({
|
|
36
|
-
ok: true,
|
|
37
|
-
status: "ok",
|
|
38
|
-
output: [{ hello: "world" }],
|
|
39
|
-
requiresApproval: null,
|
|
40
|
-
}),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const tool = createLobsterTool(fakeApi(), { runner });
|
|
44
|
-
const res = await tool.execute("call1", {
|
|
45
|
-
action: "run",
|
|
46
|
-
pipeline: "noop",
|
|
47
|
-
timeoutMs: 1000,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
expect(runner.run).toHaveBeenCalledWith({
|
|
51
|
-
action: "run",
|
|
52
|
-
pipeline: "noop",
|
|
53
|
-
cwd: process.cwd(),
|
|
54
|
-
timeoutMs: 1000,
|
|
55
|
-
maxStdoutBytes: 512_000,
|
|
56
|
-
});
|
|
57
|
-
expect(res.details).toMatchObject({
|
|
58
|
-
ok: true,
|
|
59
|
-
status: "ok",
|
|
60
|
-
output: [{ hello: "world" }],
|
|
61
|
-
requiresApproval: null,
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("supports approval envelopes without changing the tool contract", async () => {
|
|
66
|
-
const runner = {
|
|
67
|
-
run: vi.fn().mockResolvedValue({
|
|
68
|
-
ok: true,
|
|
69
|
-
status: "needs_approval",
|
|
70
|
-
output: [],
|
|
71
|
-
requiresApproval: {
|
|
72
|
-
type: "approval_request",
|
|
73
|
-
prompt: "Send these alerts?",
|
|
74
|
-
items: [{ id: "alert-1" }],
|
|
75
|
-
resumeToken: "resume-token-1",
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const tool = createLobsterTool(fakeApi(), { runner });
|
|
81
|
-
const res = await tool.execute("call-injected-runner", {
|
|
82
|
-
action: "run",
|
|
83
|
-
pipeline: "noop",
|
|
84
|
-
argsJson: '{"since_hours":1}',
|
|
85
|
-
timeoutMs: 1500,
|
|
86
|
-
maxStdoutBytes: 4096,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(runner.run).toHaveBeenCalledWith({
|
|
90
|
-
action: "run",
|
|
91
|
-
pipeline: "noop",
|
|
92
|
-
argsJson: '{"since_hours":1}',
|
|
93
|
-
cwd: process.cwd(),
|
|
94
|
-
timeoutMs: 1500,
|
|
95
|
-
maxStdoutBytes: 4096,
|
|
96
|
-
});
|
|
97
|
-
expect(res.details).toMatchObject({
|
|
98
|
-
ok: true,
|
|
99
|
-
status: "needs_approval",
|
|
100
|
-
requiresApproval: {
|
|
101
|
-
type: "approval_request",
|
|
102
|
-
prompt: "Send these alerts?",
|
|
103
|
-
resumeToken: "resume-token-1",
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("throws when the runner returns an error envelope", async () => {
|
|
109
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
110
|
-
runner: {
|
|
111
|
-
run: vi.fn().mockResolvedValue({
|
|
112
|
-
ok: false,
|
|
113
|
-
error: {
|
|
114
|
-
type: "runtime_error",
|
|
115
|
-
message: "boom",
|
|
116
|
-
},
|
|
117
|
-
}),
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await expect(
|
|
122
|
-
tool.execute("call-runner-error", {
|
|
123
|
-
action: "run",
|
|
124
|
-
pipeline: "noop",
|
|
125
|
-
}),
|
|
126
|
-
).rejects.toThrow("boom");
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("can run through managed TaskFlow mode", async () => {
|
|
130
|
-
const runner = {
|
|
131
|
-
run: vi.fn().mockResolvedValue({
|
|
132
|
-
ok: true,
|
|
133
|
-
status: "needs_approval",
|
|
134
|
-
output: [],
|
|
135
|
-
requiresApproval: {
|
|
136
|
-
type: "approval_request",
|
|
137
|
-
prompt: "Approve this?",
|
|
138
|
-
items: [{ id: "item-1" }],
|
|
139
|
-
resumeToken: "resume-1",
|
|
140
|
-
approvalId: "approval-1",
|
|
141
|
-
},
|
|
142
|
-
}),
|
|
143
|
-
};
|
|
144
|
-
const taskFlow = createFakeTaskFlow();
|
|
145
|
-
|
|
146
|
-
const tool = createLobsterTool(fakeApi(), { runner, taskFlow });
|
|
147
|
-
const res = await tool.execute("call-managed-run", {
|
|
148
|
-
action: "run",
|
|
149
|
-
pipeline: "noop",
|
|
150
|
-
flowControllerId: "tests/lobster",
|
|
151
|
-
flowGoal: "Run Lobster workflow",
|
|
152
|
-
flowStateJson: '{"lane":"email"}',
|
|
153
|
-
flowCurrentStep: "run_lobster",
|
|
154
|
-
flowWaitingStep: "await_review",
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
expect(taskFlow.createManaged).toHaveBeenCalledWith({
|
|
158
|
-
controllerId: "tests/lobster",
|
|
159
|
-
goal: "Run Lobster workflow",
|
|
160
|
-
currentStep: "run_lobster",
|
|
161
|
-
stateJson: { lane: "email" },
|
|
162
|
-
});
|
|
163
|
-
expect(taskFlow.setWaiting).toHaveBeenCalledWith({
|
|
164
|
-
flowId: "flow-1",
|
|
165
|
-
expectedRevision: 1,
|
|
166
|
-
currentStep: "await_review",
|
|
167
|
-
waitJson: {
|
|
168
|
-
kind: "lobster_approval",
|
|
169
|
-
prompt: "Approve this?",
|
|
170
|
-
items: [{ id: "item-1" }],
|
|
171
|
-
resumeToken: "resume-1",
|
|
172
|
-
approvalId: "approval-1",
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
expect(res.details).toMatchObject({
|
|
176
|
-
ok: true,
|
|
177
|
-
status: "needs_approval",
|
|
178
|
-
flow: {
|
|
179
|
-
flowId: "flow-1",
|
|
180
|
-
},
|
|
181
|
-
mutation: {
|
|
182
|
-
applied: true,
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("rejects managed TaskFlow params when no bound taskFlow runtime is available", async () => {
|
|
188
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
189
|
-
runner: { run: vi.fn() },
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
await expect(
|
|
193
|
-
tool.execute("call-missing-taskflow", {
|
|
194
|
-
action: "run",
|
|
195
|
-
pipeline: "noop",
|
|
196
|
-
flowControllerId: "tests/lobster",
|
|
197
|
-
flowGoal: "Run Lobster workflow",
|
|
198
|
-
}),
|
|
199
|
-
).rejects.toThrow(/Managed TaskFlow run mode requires a bound taskFlow runtime/);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("rejects invalid flowStateJson in managed TaskFlow mode", async () => {
|
|
203
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
204
|
-
runner: { run: vi.fn() },
|
|
205
|
-
taskFlow: createFakeTaskFlow(),
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
await expect(
|
|
209
|
-
tool.execute("call-invalid-flow-json", {
|
|
210
|
-
action: "run",
|
|
211
|
-
pipeline: "noop",
|
|
212
|
-
flowControllerId: "tests/lobster",
|
|
213
|
-
flowGoal: "Run Lobster workflow",
|
|
214
|
-
flowStateJson: "{bad",
|
|
215
|
-
}),
|
|
216
|
-
).rejects.toThrow(/flowStateJson must be valid JSON/);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("can resume managed TaskFlow mode with only approvalId", async () => {
|
|
220
|
-
const runner = {
|
|
221
|
-
run: vi.fn().mockResolvedValue({
|
|
222
|
-
ok: true,
|
|
223
|
-
status: "ok",
|
|
224
|
-
output: [],
|
|
225
|
-
requiresApproval: null,
|
|
226
|
-
}),
|
|
227
|
-
};
|
|
228
|
-
const taskFlow = createFakeTaskFlow();
|
|
229
|
-
const tool = createLobsterTool(fakeApi(), { runner, taskFlow });
|
|
230
|
-
|
|
231
|
-
const res = await tool.execute("call-managed-resume-approval-id", {
|
|
232
|
-
action: "resume",
|
|
233
|
-
approvalId: "approval-1",
|
|
234
|
-
approve: true,
|
|
235
|
-
flowId: "flow-1",
|
|
236
|
-
flowExpectedRevision: 1,
|
|
237
|
-
flowCurrentStep: "resume_lobster",
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
expect(taskFlow.resume).toHaveBeenCalledWith({
|
|
241
|
-
flowId: "flow-1",
|
|
242
|
-
expectedRevision: 1,
|
|
243
|
-
status: "running",
|
|
244
|
-
currentStep: "resume_lobster",
|
|
245
|
-
});
|
|
246
|
-
expect(runner.run).toHaveBeenCalledWith({
|
|
247
|
-
action: "resume",
|
|
248
|
-
approvalId: "approval-1",
|
|
249
|
-
approve: true,
|
|
250
|
-
cwd: process.cwd(),
|
|
251
|
-
timeoutMs: 20_000,
|
|
252
|
-
maxStdoutBytes: 512_000,
|
|
253
|
-
});
|
|
254
|
-
expect(res.details).toMatchObject({
|
|
255
|
-
ok: true,
|
|
256
|
-
status: "ok",
|
|
257
|
-
mutation: {
|
|
258
|
-
applied: true,
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("rejects managed TaskFlow resume mode without a token or approvalId", async () => {
|
|
264
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
265
|
-
runner: { run: vi.fn() },
|
|
266
|
-
taskFlow: createFakeTaskFlow(),
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
await expect(
|
|
270
|
-
tool.execute("call-missing-resume-token", {
|
|
271
|
-
action: "resume",
|
|
272
|
-
flowId: "flow-1",
|
|
273
|
-
flowExpectedRevision: 1,
|
|
274
|
-
approve: true,
|
|
275
|
-
}),
|
|
276
|
-
).rejects.toThrow(/token or approvalId required when using managed TaskFlow resume mode/);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("rejects managed TaskFlow resume mode without approve", async () => {
|
|
280
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
281
|
-
runner: { run: vi.fn() },
|
|
282
|
-
taskFlow: createFakeTaskFlow(),
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
await expect(
|
|
286
|
-
tool.execute("call-missing-resume-approve", {
|
|
287
|
-
action: "resume",
|
|
288
|
-
token: "resume-token",
|
|
289
|
-
flowId: "flow-1",
|
|
290
|
-
flowExpectedRevision: 1,
|
|
291
|
-
}),
|
|
292
|
-
).rejects.toThrow(/approve required when using managed TaskFlow resume mode/);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it("requires action", async () => {
|
|
296
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
297
|
-
runner: { run: vi.fn() },
|
|
298
|
-
});
|
|
299
|
-
await expect(tool.execute("call-action-missing", {})).rejects.toThrow(/action required/);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("rejects unknown action", async () => {
|
|
303
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
304
|
-
runner: { run: vi.fn() },
|
|
305
|
-
});
|
|
306
|
-
await expect(
|
|
307
|
-
tool.execute("call-action-unknown", {
|
|
308
|
-
action: "explode",
|
|
309
|
-
}),
|
|
310
|
-
).rejects.toThrow(/Unknown action/);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it("rejects absolute cwd", async () => {
|
|
314
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
315
|
-
runner: { run: vi.fn() },
|
|
316
|
-
});
|
|
317
|
-
await expect(
|
|
318
|
-
tool.execute("call-absolute-cwd", {
|
|
319
|
-
action: "run",
|
|
320
|
-
pipeline: "noop",
|
|
321
|
-
cwd: "/tmp",
|
|
322
|
-
}),
|
|
323
|
-
).rejects.toThrow(/cwd must be a relative path/);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it("rejects cwd that escapes the gateway working directory", async () => {
|
|
327
|
-
const tool = createLobsterTool(fakeApi(), {
|
|
328
|
-
runner: { run: vi.fn() },
|
|
329
|
-
});
|
|
330
|
-
await expect(
|
|
331
|
-
tool.execute("call-escape-cwd", {
|
|
332
|
-
action: "run",
|
|
333
|
-
pipeline: "noop",
|
|
334
|
-
cwd: "../../etc",
|
|
335
|
-
}),
|
|
336
|
-
).rejects.toThrow(/must stay within/);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
it("can be gated off in sandboxed contexts", async () => {
|
|
340
|
-
const api = fakeApi();
|
|
341
|
-
const factoryTool = (ctx: OpenClawPluginToolContext) => {
|
|
342
|
-
if (ctx.sandboxed) {
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
return createLobsterTool(api, {
|
|
346
|
-
runner: { run: vi.fn() },
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
expect(factoryTool(fakeCtx({ sandboxed: true }))).toBeNull();
|
|
351
|
-
expect(factoryTool(fakeCtx({ sandboxed: false }))?.name).toBe("lobster");
|
|
352
|
-
});
|
|
353
|
-
});
|