Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions __tests__/result-document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe("renderQueryDocument (llm-zh)", () => {
const text = textOf(renderQueryDocument(doc(), { audience: "llm-zh" }));

expect(text).toContain("## 数据库查询结果");
expect(text).toContain("**数据库**:shop");
expect(text).toContain("**SQL**:SELECT * FROM users");
expect(text).toContain("**行数**:2(0.010s)");
expect(text).toContain("数据库:shop");
expect(text).toContain("SQL:SELECT * FROM users");
expect(text).toContain("行数:2(0.010s)");
expect(text).toContain("| id | name |");
expect(text).toContain("alice");
});
Expand All @@ -57,8 +57,8 @@ describe("renderQueryDocument (llm-zh)", () => {
const lines = renderQueryDocument(doc({ connectionId: "main" }), { audience: "llm-zh" });
const text = textOf(lines);

expect(text).toContain("**连接**:main");
expect(text.indexOf("**连接**")).toBeLessThan(text.indexOf("**数据库**"));
expect(text).toContain("连接:main");
expect(text.indexOf("连接:main")).toBeLessThan(text.indexOf("数据库"));
});

it("空结果输出(空结果)占位", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schema-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("formatSchemaMarkdown", () => {
expect(out).toContain("| 列 | 类型 | Null | Key | 默认 | Extra | 注释 |");
expect(out).toContain("| id | bigint(20) | | PK | | auto_increment | |");
expect(out).toContain("| user_id | bigint(20) | YES | FK | | | 下单用户 |");
expect(out).toContain("**索引(2)**");
expect(out).toContain("索引(2)");
expect(out).toContain("- `PRIMARY` [UNIQUE]: id");
expect(out).toContain("- `idx_user`: user_id");
});
Expand Down
10 changes: 6 additions & 4 deletions formatting/result-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ function relatedSummary(related: RelatedResult[]): string {
// ====== LLM 上下文(中文 markdown,/db query 消息与 db_query 工具共用)======

function renderLlm(doc: QueryResultDoc): DocLine[] {
// 元数据标签不加粗:`**` 在工具结果展开态(tool-result-render 的
// TruncatedMultiline 原文渲染)会以字面量显示在终端,且对 LLM 无信息量。
const lines: DocLine[] = [{ text: "## 数据库查询结果" }, { text: "" }];
if (doc.connectionId) lines.push({ text: `**连接**:${doc.connectionId}` });
if (doc.connectionId) lines.push({ text: `连接:${doc.connectionId}` });
lines.push(
{ text: `**数据库**:${doc.database}` },
{ text: `**SQL**:${doc.sql}` },
{ text: `**行数**:${doc.rowCount}(${doc.elapsed})` },
{ text: `数据库:${doc.database}` },
{ text: `SQL:${doc.sql}` },
{ text: `行数:${doc.rowCount}(${doc.elapsed})` },
{ text: "" },
);

Expand Down
3 changes: 2 additions & 1 deletion formatting/schema-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export function formatSchemaMarkdown(
);
}

lines.push("", `**索引(${indexes.length})**`, "");
// 索引标题不加粗:`**` 在 db_tables 工具结果展开态会以字面量显示在终端。
lines.push("", `索引(${indexes.length})`, "");
for (const idx of indexes) {
lines.push(`- \`${idx.name}\`${idx.unique ? " [UNIQUE]" : ""}: ${idx.columns.join(", ")}`);
}
Expand Down
Loading