pull/659/head
Travis Fischer 2024-06-19 02:42:50 -07:00
rodzic f8cd52221d
commit 3ccd56a392
1 zmienionych plików z 4 dodań i 4 usunięć

Wyświetl plik

@ -13,7 +13,7 @@ export namespace scraper {
strict: true strict: true
}) })
export type ScrapeResult = { export type ScrapeResult = Partial<{
author: string author: string
byline: string byline: string
description: string description: string
@ -36,7 +36,7 @@ export namespace scraper {
/** The text for the main content of the page. */ /** The text for the main content of the page. */
textContent: string textContent: string
} }>
} }
/** /**
@ -97,7 +97,7 @@ export class ScraperClient extends AIFunctionsProvider {
format?: 'html' | 'markdown' | 'plaintext' | 'all' format?: 'html' | 'markdown' | 'plaintext' | 'all'
timeoutMs?: number timeoutMs?: number
} }
): Promise<Partial<scraper.ScrapeResult>> { ): Promise<scraper.ScrapeResult> {
const { const {
timeoutMs = 60_000, timeoutMs = 60_000,
format = 'markdown', format = 'markdown',
@ -111,7 +111,7 @@ export class ScraperClient extends AIFunctionsProvider {
}) })
.json<scraper.ScrapeResult>() .json<scraper.ScrapeResult>()
if (res.length <= 40) { if (res.length && res.length <= 40) {
try { try {
const message = (JSON.parse(res.textContent as string) as any).message const message = (JSON.parse(res.textContent as string) as any).message
throw new Error(`Failed to scrape URL "${opts.url}": ${message}`) throw new Error(`Failed to scrape URL "${opts.url}": ${message}`)