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:
Dallin Romney
2026-07-04 16:50:44 -07:00
committed by GitHub
parent c2fc7aa28a
commit bfffa950d7
24 changed files with 105 additions and 152 deletions
+31
View File
@@ -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,
});
});
});
+2
View File
@@ -0,0 +1,2 @@
export type { AgentToolResult } from "../agents/runtime/index.js";
export { jsonResult, textResult } from "../agents/tools/tool-results.js";