* harmonyos_list_kits + harmonyos_get_kit_docs — Kit 分类导航
*/
import { z } from 'zod';
import { listKits, getKitDocs } from '../lib/knowledge.js';
import { guardKnowledge } from './setup.js';
const ListKitsInputSchema = z.object({}).strict();
export function registerListKitsTool(server) {
server.registerTool('harmonyos_list_kits', {
title: 'List HarmonyOS Kits',
description: `列出所有 HarmonyOS Kit 及其文档数量。
返回 HarmonyOS NEXT 所有的开发 Kit 类别及每个 Kit 下的文档统计。
**使用场景:**
- 了解 HarmonyOS 有哪些开发能力
- 确定某个功能属于哪个 Kit
- 为 harmonyos_get_kit_docs 提供 Kit 名称
**返回:** Kit 列表,按文档数量降序排列,每个 Kit 包含名称、文档数量和示例路径。`,
inputSchema: ListKitsInputSchema,
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
},
}, async () => {
const guard = guardKnowledge();
if (guard)
return { content: [{ type: 'text', text: guard }] };
const kits = listKits();
if (kits.length === 0) {
return {
content: [{ type: 'text', text: '未找到 Kit 信息。请确认 KITS.md 已生成。' }],
};
}
const lines = ['# HarmonyOS Kit 列表', '', `共 ${kits.length} 个 Kit 类别:`, ''];
for (const kit of kits) {
lines.push(`## ${kit.name} (${kit.docCount} 个文档)`);
if (kit.samplePaths.length > 0) {
for (const sp of kit.samplePaths) {
lines.push(` - \`${sp}\``);
}
}
lines.push('');
}
lines.push('---');
lines.push('💡 使用 `harmonyos_get_kit_docs` 获取某个 Kit 的完整文档路径列表。');
return {
content: [{ type: 'text', text: lines.join('\n') }],
};
});
}
const GetKitDocsInputSchema = z.object({
kit: z.string()
.min(1, 'Kit 名称不能为空')
.describe('Kit 名称,如 "ArkUI"、"ArkTS"、"AbilityKit"、"MediaKit" 等。支持模糊匹配。'),
}).strict();
export function registerGetKitDocsTool(server) {
server.registerTool('harmonyos_get_kit_docs', {
title: 'Get Kit Documents',
description: `获取指定 Kit 类别下的所有文档路径列表。
根据 Kit 名称(支持模糊匹配)返回该类别下的所有文档路径。
**使用场景:**
- 浏览某个 Kit 的完整文档
- 了解 ArkUI 有哪些组件文档
- 查看 AbilityKit 的能力范围
**参数:**
- kit: Kit 名称(如 "ArkUI", "AbilityKit", "MediaKit")
**返回:** 该 Kit 下的文档路径列表,可用于 harmonyos_get_document 获取完整内容。`,
inputSchema: GetKitDocsInputSchema,
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
},
}, async (params) => {
const guard = guardKnowledge();
if (guard)
return { content: [{ type: 'text', text: guard }] };
const docs = getKitDocs(params.kit);
if (docs.length === 0) {
return {
content: [{
type: 'text',
text: `未找到与 "${params.kit}" 匹配的 Kit。\n\n使用 harmonyos_list_kits 查看所有可用的 Kit 名称。`,
}],
};
}
const lines = [
`# Kit: ${params.kit}`,
'',
`共 ${docs.length} 个文档:`,
'',
];
for (const doc of docs.slice(0, 100)) {
lines.push(`- \`${doc}\``);
}
if (docs.length > 100) {
lines.push('');
lines.push(`... 还有 ${docs.length - 100} 个文档,使用 harmonyos_search_docs 缩小范围`);
}
lines.push('');
lines.push('💡 使用 `harmonyos_get_document` 获取单个文档的完整内容。');
return {
content: [{ type: 'text', text: lines.join('\n') }],
};
});
}