@@ -23,39 +23,37 @@ const KB_INFO_FLAGS = {
2323 ...WORKSPACE_FLAG ,
2424} satisfies FlagsDef ;
2525
26- function indexListUrl ( workspaceId : string , pageNumber : number ) : string {
26+ function indexDetailUrl ( workspaceId : string , indexId : string ) : string {
2727 const url = new URL ( ragEndpoint ( workspaceId , RAG_PATHS . indexList ) ) ;
28- url . searchParams . set ( "page_number" , String ( pageNumber ) ) ;
29- url . searchParams . set ( "page_size" , "100" ) ;
28+ url . searchParams . set ( "pipeline_id" , indexId ) ;
29+ url . searchParams . set ( "page_number" , "1" ) ;
30+ url . searchParams . set ( "page_size" , "1" ) ;
3031 return url . toString ( ) ;
3132}
3233
3334/**
34- * There is no dedicated detail API on the server , so fall back to paging
35- * through index/list. If a detail API ships, only this function changes.
36- * Also reused by kb delete for its confirmation summary.
35+ * The index/list API now supports pipeline_id filtering , so a single
36+ * request suffices instead of paginating. Reused by kb delete for its
37+ * confirmation summary.
3738 */
3839export async function fetchIndexDetail (
3940 client : Client ,
4041 workspaceId : string ,
4142 indexId : string ,
4243) : Promise < RagIndexRow > {
43- const maxPages = 10 ;
44- for ( let pageNumber = 1 ; pageNumber <= maxPages ; pageNumber ++ ) {
45- const response = await client . requestJson < RagIndexListResponse > ( {
46- path : indexListUrl ( workspaceId , pageNumber ) ,
47- method : "GET" ,
48- } ) ;
49- const rows = response . data ?. rows ?? [ ] ;
50- const match = rows . find ( ( row ) => row . id === indexId ) ;
51- if ( match ) return match ;
52- if ( rows . length < 100 ) break ; // reached the last page
44+ const response = await client . requestJson < RagIndexListResponse > ( {
45+ path : indexDetailUrl ( workspaceId , indexId ) ,
46+ method : "GET" ,
47+ } ) ;
48+ const row = response . data ?. rows ?. [ 0 ] ;
49+ if ( ! row ) {
50+ throw new BailianError (
51+ `Knowledge base not found: ${ indexId } ` ,
52+ ExitCode . GENERAL ,
53+ "Check the id — list knowledge bases in this workspace to verify it." ,
54+ ) ;
5355 }
54- throw new BailianError (
55- `Knowledge base not found: ${ indexId } ` ,
56- ExitCode . GENERAL ,
57- "Check the id — list knowledge bases in this workspace to verify it." ,
58- ) ;
56+ return row ;
5957}
6058
6159function formatField ( label : string , value : string | number | boolean | null | undefined ) : string {
@@ -68,7 +66,7 @@ export default defineCommand({
6866 usageArgs : "--index-id <id> [flags]" ,
6967 flags : KB_INFO_FLAGS ,
7068 notes : [
71- "No dedicated detail API on the server yet — falls back to paginating the index list (up to 10 pages of 100) ." ,
69+ "Uses the index/list API with pipeline_id filtering to fetch a single knowledge base ." ,
7270 "Indexing settings are immutable; changing them requires recreating the knowledge base." ,
7371 ] ,
7472 exampleArgs : [ "--index-id idx-xxx --workspace-id ws-xxx" ] ,
@@ -80,10 +78,8 @@ export default defineCommand({
8078 if ( settings . dryRun ) {
8179 emitResult (
8280 {
83- endpoint : indexListUrl ( workspaceId , 1 ) ,
81+ endpoint : indexDetailUrl ( workspaceId , flags . indexId ) ,
8482 request : null ,
85- strategy :
86- "paginate index/list (page_size=100, up to 10 pages) to find --index-id; no dedicated detail API" ,
8783 } ,
8884 format ,
8985 ) ;
0 commit comments