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
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 3
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-fedf39540580ba6568142c9d98c783c00dd6c0aa46222e69c319cdff832fc9aa.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-d975cb3c41e7b2790db4938b1de2b89c4005825a6347ae29ca4998f2c5b1a1be.yml
77 changes: 28 additions & 49 deletions src/resources/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export class Documents extends APIResource {
* This endpoint allows you to paginate through all documents in the index. You can
* filter the documents by title, date, metadata, etc.
*/
list(body: DocumentListParams, options?: Core.RequestOptions): Core.APIPromise<DocumentListResponse> {
return this._client.post('/documents/list', { body, ...options });
list(params: DocumentListParams, options?: Core.RequestOptions): Core.APIPromise<DocumentListResponse> {
const { collection, cursor, size } = params;
return this._client.post('/documents/list', { query: { collection, cursor, size }, ...options });
}
}

Expand All @@ -38,6 +39,8 @@ export interface Document {

sections?: Array<Document.Section>;

sections_count?: number | null;

source?:
| 'generic'
| 'generic_chat'
Expand Down Expand Up @@ -78,56 +81,28 @@ export namespace Document {
}

export interface DocumentListResponse {
count: number;

documents: Array<Document>;
items: Array<DocumentListResponse.Item>;

has_more: boolean;

page: number;
next_cursor: string | null;
}

export interface DocumentListParams {
/**
* The collections to filter documents by.
*/
collections: Array<number>;
export namespace DocumentListResponse {
export interface Item {
id: number | null;

/**
* Filter the query results.
*/
filter?: DocumentListParams.Filter;
created_at: string | null;

/**
* Number of documents to return per page.
*/
limit?: number;
ingested_at: string | null;

/**
* Page number to return.
*/
page?: number;
}
metadata: unknown;

export namespace DocumentListParams {
/**
* Filter the query results.
*/
export interface Filter {
/**
* Only query chunks of these types.
*/
chunk_type?: Array<'text' | 'markdown' | 'table' | 'image' | 'messages' | 'message'>;
resource_id: string;

/**
* Only query documents before this date.
*/
end_date?: string | null;
sections_count: number | null;

/**
* Only query documents of these types.
*/
source?: Array<
title: string | null;

source?:
| 'generic'
| 'generic_chat'
| 'generic_email'
Expand All @@ -138,16 +113,20 @@ export namespace DocumentListParams {
| 's3'
| 'gmail'
| 'notion'
| 'google_docs'
>;
| 'google_docs';

/**
* Only query documents on or after this date.
*/
start_date?: string | null;
status?: 'pending' | 'processing' | 'completed' | 'failed';
}
}

export interface DocumentListParams {
collection: string;

cursor?: string | null;

size?: number;
}

export declare namespace Documents {
export {
type Document as Document,
Expand Down
14 changes: 2 additions & 12 deletions tests/api-resources/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('resource documents', () => {
});

test('list: only required params', async () => {
const responsePromise = client.documents.list({ collections: [0] });
const responsePromise = client.documents.list({ collection: 'collection' });
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -39,16 +39,6 @@ describe('resource documents', () => {
});

test('list: required and optional params', async () => {
const response = await client.documents.list({
collections: [0],
filter: {
chunk_type: ['text'],
end_date: '2019-12-27T18:11:19.117Z',
source: ['generic'],
start_date: '2019-12-27T18:11:19.117Z',
},
limit: 0,
page: 2,
});
const response = await client.documents.list({ collection: 'collection', cursor: 'cursor', size: 0 });
});
});