@@ -13,6 +13,9 @@ type RequestConfig = {
1313 params : Record < string , string | number | boolean > ;
1414} ;
1515
16+ type MaybePaginatedDocumentListResponse = Omit < DocumentListResponse , 'pagination' > &
17+ Partial < Pick < DocumentListResponse , 'pagination' > > ;
18+
1619/**
1720 * Resource for canonical document lifecycle operations.
1821 */
@@ -21,10 +24,11 @@ export class Documents extends BaseResource {
2124 * List canonical documents in a namespace.
2225 */
2326 async list ( params ?: DocumentListParams ) : Promise < DocumentListResponse > {
24- return this . httpClient . get < DocumentListResponse > (
27+ const response = await this . httpClient . get < DocumentListResponse > (
2528 '/v1/documents' ,
2629 this . createDocumentListRequestConfig ( params ) ,
2730 ) ;
31+ return this . normalizeDocumentListResponse ( response ) ;
2832 }
2933
3034 /**
@@ -87,6 +91,24 @@ export class Documents extends BaseResource {
8791 return Object . keys ( queryParams ) . length > 0 ? { params : queryParams } : undefined ;
8892 }
8993
94+ private normalizeDocumentListResponse ( response : DocumentListResponse ) : DocumentListResponse {
95+ const maybePaginatedResponse = response as MaybePaginatedDocumentListResponse ;
96+ if ( maybePaginatedResponse . pagination ) {
97+ return response ;
98+ }
99+
100+ const total = response . documents . length ;
101+ return {
102+ ...response ,
103+ pagination : {
104+ page : 1 ,
105+ pageSize : total ,
106+ total,
107+ totalPages : total > 0 ? 1 : 0 ,
108+ } ,
109+ } ;
110+ }
111+
90112 private createChunkListRequestConfig (
91113 params ?: DocumentChunkListParams ,
92114 ) : RequestConfig | undefined {
0 commit comments