-
Notifications
You must be signed in to change notification settings - Fork 384
feat: improve scrollable element detection, enhance abort error handl… #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,7 +61,12 @@ const llmsTxtCache = new Map<string, string | null>() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Fetch /llms.txt for a URL's origin. Cached per origin, `null` = tried and not found. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function fetchLlmsTxt(url: string): Promise<string | null> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const origin = new URL(url).origin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let origin: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| origin = new URL(url).origin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null // Invalid URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (llmsTxtCache.has(origin)) return llmsTxtCache.get(origin)! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const endpoint = `${origin}/llms.txt` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -101,3 +106,30 @@ export function assert(condition: unknown, message?: string, silent?: boolean): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error(errorMessage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Check if an error is an AbortError (from AbortController) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Handles various forms: Error with name 'AbortError', or rawError property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function isAbortError(error: unknown): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (error instanceof Error && error.name === 'AbortError') return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof error === 'object' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error !== null && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'rawError' in error && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (error as { rawError?: Error }).rawError?.name === 'AbortError' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+112
to
+122
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Handles various forms: Error with name 'AbortError', or rawError property | |
| */ | |
| export function isAbortError(error: unknown): boolean { | |
| if (error instanceof Error && error.name === 'AbortError') return true | |
| if ( | |
| typeof error === 'object' && | |
| error !== null && | |
| 'rawError' in error && | |
| (error as { rawError?: Error }).rawError?.name === 'AbortError' | |
| ) | |
| return true | |
| * Handles various forms: | |
| * - Error with name 'AbortError' | |
| * - Error with message 'AbortError' | |
| * - Plain objects with name/message 'AbortError' | |
| * - Wrapped errors via a `rawError` property | |
| */ | |
| export function isAbortError(error: unknown): boolean { | |
| // Direct Error instance: check both name and message | |
| if (error instanceof Error) { | |
| if (error.name === 'AbortError' || error.message === 'AbortError') { | |
| return true | |
| } | |
| } | |
| // Error-like objects or wrappers (including { rawError: ... }) | |
| if (typeof error === 'object' && error !== null) { | |
| const maybeError = error as { name?: unknown; message?: unknown; rawError?: unknown } | |
| // Plain object with AbortError-like fields | |
| if (maybeError.name === 'AbortError' || maybeError.message === 'AbortError') { | |
| return true | |
| } | |
| // Wrapped error under `rawError` | |
| if ('rawError' in maybeError && maybeError.rawError != null) { | |
| const raw = maybeError.rawError as unknown | |
| if (raw instanceof Error) { | |
| if (raw.name === 'AbortError' || raw.message === 'AbortError') { | |
| return true | |
| } | |
| } else if (typeof raw === 'object') { | |
| const rawObj = raw as { name?: unknown; message?: unknown } | |
| if (rawObj.name === 'AbortError' || rawObj.message === 'AbortError') { | |
| return true | |
| } | |
| } | |
| } | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,15 +56,15 @@ | |||||||||
| signal: abortSignal, | ||||||||||
| }) | ||||||||||
| } catch (error: unknown) { | ||||||||||
| const isAbortError = (error as any)?.name === 'AbortError' | ||||||||||
| const isAborted = error instanceof Error && error.name === 'AbortError' | ||||||||||
| const errorMessage = isAbortError ? 'Network request aborted' : 'Network request failed' | ||||||||||
| if (!isAbortError) console.error(error) | ||||||||||
|
Comment on lines
60
to
61
|
||||||||||
| const errorMessage = isAbortError ? 'Network request aborted' : 'Network request failed' | |
| if (!isAbortError) console.error(error) | |
| const errorMessage = isAborted ? 'Network request aborted' : 'Network request failed' | |
| if (!isAborted) console.error(error) |
Check failure on line 138 in packages/llms/src/OpenAIClient.ts
GitHub Actions / test (24)
Array type using 'Array<T>' is forbidden. Use 'T[]' instead
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -93,15 +93,21 @@ async function withRetry<T>( | |||||||||||||||||||||||||
| return await fn() | ||||||||||||||||||||||||||
| } catch (error: unknown) { | ||||||||||||||||||||||||||
| // do not retry if aborted by user | ||||||||||||||||||||||||||
| if ((error as any)?.rawError?.name === 'AbortError') throw error | ||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||
| error instanceof InvokeError && | ||||||||||||||||||||||||||
| error.rawError instanceof Error && | ||||||||||||||||||||||||||
| error.rawError.name === 'AbortError' | ||||||||||||||||||||||||||
|
Comment on lines
+97
to
+99
|
||||||||||||||||||||||||||
| error instanceof InvokeError && | |
| error.rawError instanceof Error && | |
| error.rawError.name === 'AbortError' | |
| ( | |
| error instanceof InvokeError && | |
| error.rawError instanceof Error && | |
| (error.rawError.name === 'AbortError' || error.rawError.message === 'AbortError') | |
| ) || | |
| ( | |
| error instanceof Error && | |
| (error.name === 'AbortError' || error.message === 'AbortError') | |
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,7 @@ | |
|
|
||
| display: none; | ||
| } | ||
|
|
||
| .wrapper.visible { | ||
| display: block; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rawResponseis only present onInvokeError, but the current guard useserror instanceof Errorand then casts toInvokeError. For plainErrorinstances this will always produceundefinedand hides the intent. Prefer checkingerror instanceof InvokeErrorbefore reading.rawResponse.