From 72dd6b92215e16aab0e232596bc2cee6af2eae8d Mon Sep 17 00:00:00 2001 From: sushaan-k Date: Sun, 17 May 2026 23:09:57 -0400 Subject: [PATCH] fix: correct crawl SDK bugs and add createCrawl wrapper The crawl module had several copy-paste bugs from the datasets module: - JSDoc on getCrawlsForDataset said "create a dataset" - Return type was Promise instead of Promise> - Error message referenced "create a crawl" on a GET operation Also adds a wrapper for POST /api/crawl (createCrawl), which is missing from the SDK even though it exists in the OpenAPI spec. The PUT and DELETE crawl endpoints are intentionally not wrapped here. The backend behavior of update_crawl_request and delete_crawl_request appears to be broken in ways that would mislead SDK callers; see the PR description for details. Changes: - Fix JSDoc, return type, and error message on getCrawlsForDataset - Make the props argument optional (limit/page are both optional) - Add createCrawl wrapper - Add a basic crawl.test.ts that exercises getCrawlsForDataset --- .../ts-sdk/src/functions/crawl/crawl.test.ts | 21 ++++++++ clients/ts-sdk/src/functions/crawl/index.ts | 50 ++++++++++++++++--- 2 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 clients/ts-sdk/src/functions/crawl/crawl.test.ts 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; }