mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 19:01:47 +03:00
chore: Lint extensions folder.
This commit is contained in:
@@ -36,7 +36,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: JSON.stringify({ foo: "bar" }) }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
const res = await tool.execute("id", { prompt: "return foo" });
|
||||
expect((res as any).details.json).toEqual({ foo: "bar" });
|
||||
});
|
||||
@@ -46,7 +46,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: '```json\n{"ok":true}\n```' }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
const res = await tool.execute("id", { prompt: "return ok" });
|
||||
expect((res as any).details.json).toEqual({ ok: true });
|
||||
});
|
||||
@@ -56,7 +56,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: JSON.stringify({ foo: "bar" }) }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
const schema = {
|
||||
type: "object",
|
||||
properties: { foo: { type: "string" } },
|
||||
@@ -72,7 +72,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: "not-json" }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
await expect(tool.execute("id", { prompt: "x" })).rejects.toThrow(/invalid json/i);
|
||||
});
|
||||
|
||||
@@ -81,7 +81,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: JSON.stringify({ foo: 1 }) }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
const schema = { type: "object", properties: { foo: { type: "string" } }, required: ["foo"] };
|
||||
await expect(tool.execute("id", { prompt: "x", schema })).rejects.toThrow(/match schema/i);
|
||||
});
|
||||
@@ -91,7 +91,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: JSON.stringify({ ok: true }) }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
await tool.execute("id", { prompt: "x", provider: "anthropic", model: "claude-4-sonnet" });
|
||||
const call = (runEmbeddedPiAgent as any).mock.calls[0]?.[0];
|
||||
expect(call.provider).toBe("anthropic");
|
||||
@@ -104,7 +104,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
payloads: [{ text: JSON.stringify({ ok: true }) }],
|
||||
});
|
||||
const tool = createLlmTaskTool(
|
||||
fakeApi({ pluginConfig: { allowedModels: ["openai-codex/gpt-5.2"] } }) as any,
|
||||
fakeApi({ pluginConfig: { allowedModels: ["openai-codex/gpt-5.2"] } }),
|
||||
);
|
||||
await expect(
|
||||
tool.execute("id", { prompt: "x", provider: "anthropic", model: "claude-4-sonnet" }),
|
||||
@@ -116,7 +116,7 @@ describe("llm-task tool (json-only)", () => {
|
||||
meta: {},
|
||||
payloads: [{ text: JSON.stringify({ ok: true }) }],
|
||||
});
|
||||
const tool = createLlmTaskTool(fakeApi() as any);
|
||||
const tool = createLlmTaskTool(fakeApi());
|
||||
await tool.execute("id", { prompt: "x" });
|
||||
const call = (runEmbeddedPiAgent as any).mock.calls[0]?.[0];
|
||||
expect(call.disableTools).toBe(true);
|
||||
|
||||
@@ -18,24 +18,27 @@ async function loadRunEmbeddedPiAgent(): Promise<RunEmbeddedPiAgentFn> {
|
||||
// Source checkout (tests/dev)
|
||||
try {
|
||||
const mod = await import("../../../src/agents/pi-embedded-runner.js");
|
||||
if (typeof (mod as any).runEmbeddedPiAgent === "function")
|
||||
if (typeof (mod as any).runEmbeddedPiAgent === "function") {
|
||||
return (mod as any).runEmbeddedPiAgent;
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Bundled install (built)
|
||||
const mod = await import("../../../agents/pi-embedded-runner.js");
|
||||
if (typeof (mod as any).runEmbeddedPiAgent !== "function") {
|
||||
if (typeof mod.runEmbeddedPiAgent !== "function") {
|
||||
throw new Error("Internal error: runEmbeddedPiAgent not available");
|
||||
}
|
||||
return (mod as any).runEmbeddedPiAgent;
|
||||
return mod.runEmbeddedPiAgent;
|
||||
}
|
||||
|
||||
function stripCodeFences(s: string): string {
|
||||
const trimmed = s.trim();
|
||||
const m = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
|
||||
if (m) return (m[1] ?? "").trim();
|
||||
if (m) {
|
||||
return (m[1] ?? "").trim();
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
@@ -49,7 +52,9 @@ function collectText(payloads: Array<{ text?: string; isError?: boolean }> | und
|
||||
function toModelKey(provider?: string, model?: string): string | undefined {
|
||||
const p = provider?.trim();
|
||||
const m = model?.trim();
|
||||
if (!p || !m) return undefined;
|
||||
if (!p || !m) {
|
||||
return undefined;
|
||||
}
|
||||
return `${p}/${m}`;
|
||||
}
|
||||
|
||||
@@ -84,8 +89,10 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
|
||||
}),
|
||||
|
||||
async execute(_id: string, params: Record<string, unknown>) {
|
||||
const prompt = String(params.prompt ?? "");
|
||||
if (!prompt.trim()) throw new Error("prompt required");
|
||||
const prompt = typeof params.prompt === "string" ? params.prompt : "";
|
||||
if (!prompt.trim()) {
|
||||
throw new Error("prompt required");
|
||||
}
|
||||
|
||||
const pluginCfg = (api.pluginConfig ?? {}) as PluginCfg;
|
||||
|
||||
@@ -189,7 +196,9 @@ export function createLlmTaskTool(api: OpenClawPluginApi) {
|
||||
});
|
||||
|
||||
const text = collectText((result as any).payloads);
|
||||
if (!text) throw new Error("LLM returned empty output");
|
||||
if (!text) {
|
||||
throw new Error("LLM returned empty output");
|
||||
}
|
||||
|
||||
const raw = stripCodeFences(text);
|
||||
let parsed: unknown;
|
||||
|
||||
Reference in New Issue
Block a user