diff --git a/clients/ts-sdk/src/functions/crawl/crawl.test.ts b/clients/ts-sdk/src/functions/crawl/crawl.test.ts new file mode 100644 index 0000000000..1ec269fba6 --- /dev/null +++ b/clients/ts-sdk/src/functions/crawl/crawl.test.ts @@ -0,0 +1,21 @@ +import { beforeAll, describe, expectTypeOf } from "vitest"; +import { TrieveSDK } from "../../sdk"; +import { CrawlRequest } from "../../types.gen"; +import { TRIEVE } from "../../__tests__/constants"; +import { test } from "../../__tests__/utils"; + +describe("Crawl Tests", async () => { + let trieve: TrieveSDK; + beforeAll(() => { + trieve = TRIEVE; + }); + + test("getCrawlsForDataset", async () => { + const data = await trieve.getCrawlsForDataset({ + page: 1, + limit: 10, + }); + + expectTypeOf(data).toEqualTypeOf>(); + }); +}); diff --git a/clients/ts-sdk/src/functions/crawl/index.ts b/clients/ts-sdk/src/functions/crawl/index.ts index 1de070f987..5d462cb6bf 100644 --- a/clients/ts-sdk/src/functions/crawl/index.ts +++ b/clients/ts-sdk/src/functions/crawl/index.ts @@ -7,28 +7,30 @@ import { TrieveSDK } from "../../sdk"; import { $OpenApiTs, - Dataset, + CreateCrawlReqPayload, + CrawlRequest, GetCrawlRequestsForDatasetData, } from "../../types.gen"; /** - * Function that provides the ability to create a dataset. This function is used to create a new dataset in the organization. + * Function that retrieves all crawl requests for the current dataset, with optional pagination. * * Example: * ```js - * const dataset = await trieve.createDataset({ - * dataset_name: "My Dataset", + * const crawls = await trieve.getCrawlsForDataset({ + * page: 1, + * limit: 10, * }); * ``` */ export async function getCrawlsForDataset( /** @hidden */ this: TrieveSDK, - props: GetCrawlRequestsForDatasetData, + props: Omit = {}, signal?: AbortSignal, -): Promise { +): Promise> { if (!this.datasetId) { - throw new Error("Dataset ID is required to create a crawl"); + throw new Error("Dataset ID is required to get crawls"); } return this.trieve.fetch<"eject">( @@ -36,10 +38,42 @@ export async function getCrawlsForDataset( props.page ?? 1 }` as keyof $OpenApiTs, "get", + { + datasetId: this.datasetId, + }, + signal, + ) as Promise>; +} + +/** + * Function that creates a new crawl request for the current dataset. + * + * Example: + * ```js + * const crawl = await trieve.createCrawl({ + * crawl_options: { + * site_url: "https://example.com", + * }, + * }); + * ``` + */ +export async function createCrawl( + /** @hidden */ + this: TrieveSDK, + props: CreateCrawlReqPayload, + signal?: AbortSignal, +): Promise { + if (!this.datasetId) { + throw new Error("Dataset ID is required to create a crawl"); + } + + return this.trieve.fetch( + "/api/crawl", + "post", { data: props, datasetId: this.datasetId, }, signal, - ) as Promise; + ) as Promise; }