mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
refactor(plugin-sdk): consolidate tool result helpers (#99740)
* refactor(plugin-sdk): consolidate tool result helpers * docs(plugin-sdk): tighten tool result guidance * refactor(feishu): use tool results directly
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, expectTypeOf, it, vi } from "vitest";
|
||||
|
||||
vi.mock("../agents/tools/common.js", () => {
|
||||
throw new Error("tool-results must not load the broad agent tool helpers");
|
||||
});
|
||||
|
||||
import { jsonResult, textResult, type AgentToolResult } from "./tool-results.js";
|
||||
|
||||
describe("tool result helpers", () => {
|
||||
it("preserves typed JSON details", () => {
|
||||
const payload = { ok: true, messageId: "msg-1" };
|
||||
const result = jsonResult(payload);
|
||||
|
||||
expectTypeOf(result).toEqualTypeOf<AgentToolResult<typeof payload>>();
|
||||
expect(result).toEqual({
|
||||
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
|
||||
details: payload,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps model text separate from typed details", () => {
|
||||
const details = { ok: true, messageId: "msg-1" };
|
||||
const result = textResult("Message sent.", details);
|
||||
|
||||
expectTypeOf(result).toEqualTypeOf<AgentToolResult<typeof details>>();
|
||||
expect(result).toEqual({
|
||||
content: [{ type: "text", text: "Message sent." }],
|
||||
details,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
export type { AgentToolResult } from "../agents/runtime/index.js";
|
||||
export { jsonResult, textResult } from "../agents/tools/tool-results.js";
|
||||
Reference in New Issue
Block a user