|
1 | 1 | import { tinyfishFetchHosting } from '@/tools/tinyfish/hosting' |
2 | | -import type { TinyFishFetchParams, TinyFishFetchResponse } from '@/tools/tinyfish/types' |
| 2 | +import type { |
| 3 | + TinyFishFetchParams, |
| 4 | + TinyFishFetchResponse, |
| 5 | + TinyFishRawFetch, |
| 6 | +} from '@/tools/tinyfish/types' |
3 | 7 | import { |
4 | 8 | MAX_FETCH_URLS, |
5 | 9 | parseList, |
@@ -81,33 +85,29 @@ export const fetchUrlsTool: ToolConfig<TinyFishFetchParams, TinyFishFetchRespons |
81 | 85 | throw new Error(await tinyfishErrorMessage(response)) |
82 | 86 | } |
83 | 87 |
|
84 | | - const data = await response.json() |
| 88 | + const data = (await response.json()) as TinyFishRawFetch |
85 | 89 |
|
86 | 90 | return { |
87 | 91 | success: true, |
88 | 92 | output: { |
89 | | - results: Array.isArray(data.results) |
90 | | - ? data.results.map((result: any) => ({ |
91 | | - url: result?.url ?? '', |
92 | | - finalUrl: result?.final_url ?? null, |
93 | | - title: result?.title ?? null, |
94 | | - description: result?.description ?? null, |
95 | | - language: result?.language ?? null, |
96 | | - format: result?.format ?? 'markdown', |
97 | | - text: result?.text ?? null, |
98 | | - author: result?.author ?? null, |
99 | | - publishedDate: result?.published_date ?? null, |
100 | | - links: result?.links ?? [], |
101 | | - imageLinks: result?.image_links ?? [], |
102 | | - latencyMs: result?.latency_ms ?? null, |
103 | | - })) |
104 | | - : [], |
105 | | - errors: Array.isArray(data.errors) |
106 | | - ? data.errors.map((issue: any) => ({ |
107 | | - url: issue?.url ?? '', |
108 | | - error: issue?.error ?? '', |
109 | | - })) |
110 | | - : [], |
| 93 | + results: (data.results ?? []).map((result) => ({ |
| 94 | + url: result?.url ?? '', |
| 95 | + finalUrl: result?.final_url ?? null, |
| 96 | + title: result?.title ?? null, |
| 97 | + description: result?.description ?? null, |
| 98 | + language: result?.language ?? null, |
| 99 | + format: result?.format ?? 'markdown', |
| 100 | + text: result?.text ?? null, |
| 101 | + author: result?.author ?? null, |
| 102 | + publishedDate: result?.published_date ?? null, |
| 103 | + links: result?.links ?? [], |
| 104 | + imageLinks: result?.image_links ?? [], |
| 105 | + latencyMs: result?.latency_ms ?? null, |
| 106 | + })), |
| 107 | + errors: (data.errors ?? []).map((issue) => ({ |
| 108 | + url: issue?.url ?? '', |
| 109 | + error: issue?.error ?? '', |
| 110 | + })), |
111 | 111 | }, |
112 | 112 | } |
113 | 113 | }, |
|
0 commit comments