MCPcopy
hub / github.com/lobehub/lobehub / registerKbCommand

Function registerKbCommand

apps/cli/src/commands/kb.ts:30–343  ·  view source on GitHub ↗
(program: Command)

Source from the content-addressed store, hash-verified

28}
29
30export function registerKbCommand(program: Command) {
31 const kb = program
32 .command('kb')
33 .description('Manage knowledge bases, folders, documents, and files');
34
35 // ── list ──────────────────────────────────────────────
36
37 kb.command('list')
38 .description('List knowledge bases')
39 .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
40 .action(async (options: { json?: string | boolean }) => {
41 const client = await getTrpcClient();
42 const result = await client.knowledgeBase.getKnowledgeBases.query();
43 const items = Array.isArray(result) ? result : [];
44
45 if (options.json !== undefined) {
46 const fields = typeof options.json === 'string' ? options.json : undefined;
47 outputJson(items, fields);
48 return;
49 }
50
51 if (items.length === 0) {
52 console.log('No knowledge bases found.');
53 return;
54 }
55
56 const rows = items.map((kb: any) => [
57 kb.id,
58 truncate(kb.name || 'Untitled', 40),
59 truncate(kb.description || '', 50),
60 kb.updatedAt ? timeAgo(kb.updatedAt) : '',
61 ]);
62
63 printTable(rows, ['ID', 'NAME', 'DESCRIPTION', 'UPDATED']);
64 });
65
66 // ── view ──────────────────────────────────────────────
67
68 kb.command('view <id>')
69 .description('View a knowledge base')
70 .option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
71 .action(async (id: string, options: { json?: string | boolean }) => {
72 const client = await getTrpcClient();
73 const result = await client.knowledgeBase.getKnowledgeBaseById.query({ id });
74
75 if (!result) {
76 log.error(`Knowledge base not found: ${id}`);
77 process.exit(1);
78 return;
79 }
80
81 // Recursively fetch all items in the knowledge base (with pagination)
82 const allItems: any[] = [];
83 async function fetchItems(parentId: string | null, depth = 0) {
84 const PAGE_SIZE = 100;
85 let offset = 0;
86 let hasMore = true;
87

Callers 2

createProgramFunction · 0.90
createProgramFunction · 0.90

Calls 12

getTrpcClientFunction · 0.90
outputJsonFunction · 0.90
truncateFunction · 0.90
timeAgoFunction · 0.90
printTableFunction · 0.90
confirmFunction · 0.90
uploadLocalFileFunction · 0.90
fetchItemsFunction · 0.85
formatFileTypeFunction · 0.85
logMethod · 0.80
queryMethod · 0.45
pushMethod · 0.45

Tested by 1

createProgramFunction · 0.72