fix: adapt tidb tool to moltbot tools

This commit is contained in:
Cheese 2026-01-28 11:34:52 +08:00
parent 693123ac3f
commit 98fb58e318
No known key found for this signature in database
2 changed files with 13 additions and 13 deletions

View File

@ -1,11 +1,11 @@
import { describe, expect, it } from "vitest";
import type { ClawdbotConfig } from "../config/config.js";
import { createClawdbotTools } from "./clawdbot-tools.js";
import type { MoltbotConfig } from "../config/config.js";
import { createMoltbotTools } from "./moltbot-tools.js";
describe("createClawdbotTools (tidb)", () => {
describe("createMoltbotTools (tidb)", () => {
it("omits tidb tool when disabled", () => {
const cfg: ClawdbotConfig = {
const cfg: MoltbotConfig = {
tools: {
tidb: {
enabled: false,
@ -13,12 +13,12 @@ describe("createClawdbotTools (tidb)", () => {
},
},
};
const tools = createClawdbotTools({ config: cfg });
const tools = createMoltbotTools({ config: cfg });
expect(tools.some((tool) => tool.name === "tidb")).toBe(false);
});
it("adds tidb tool when enabled + configured", () => {
const cfg: ClawdbotConfig = {
const cfg: MoltbotConfig = {
tools: {
tidb: {
enabled: true,
@ -26,19 +26,19 @@ describe("createClawdbotTools (tidb)", () => {
},
},
};
const tools = createClawdbotTools({ config: cfg });
const tools = createMoltbotTools({ config: cfg });
expect(tools.some((tool) => tool.name === "tidb")).toBe(true);
});
it("adds tidb tool when enabled (even if url is missing)", () => {
const cfg: ClawdbotConfig = {
const cfg: MoltbotConfig = {
tools: {
tidb: {
enabled: true,
},
},
};
const tools = createClawdbotTools({ config: cfg });
const tools = createMoltbotTools({ config: cfg });
expect(tools.some((tool) => tool.name === "tidb")).toBe(true);
});
});

View File

@ -2,7 +2,7 @@ import { spawn } from "node:child_process";
import { Type } from "@sinclair/typebox";
import type { ClawdbotConfig } from "../../config/config.js";
import type { MoltbotConfig } from "../../config/config.js";
import { sanitizeBinaryOutput } from "../shell-utils.js";
import { optionalStringEnum } from "../schema/typebox.js";
import type { AnyAgentTool } from "./common.js";
@ -197,9 +197,9 @@ function parseTsvToRows(stdout: string): {
return { columns, rows };
}
type TiDbToolConfig = NonNullable<ClawdbotConfig["tools"]>["tidb"];
type TiDbToolConfig = NonNullable<MoltbotConfig["tools"]>["tidb"];
function resolveTiDbToolConfig(cfg?: ClawdbotConfig): TiDbToolConfig | undefined {
function resolveTiDbToolConfig(cfg?: MoltbotConfig): TiDbToolConfig | undefined {
const tidb = cfg?.tools?.tidb;
if (!tidb || typeof tidb !== "object") return undefined;
return tidb as TiDbToolConfig;
@ -255,7 +255,7 @@ function resolveMaxOutputChars(cfg?: TiDbToolConfig): number {
return 60_000;
}
export function createTiDbTool(options: { config?: ClawdbotConfig }): AnyAgentTool | null {
export function createTiDbTool(options: { config?: MoltbotConfig }): AnyAgentTool | null {
const cfg = options.config;
if (!cfg) return null;