Store the full clean text so an omitted middle is recoverable via read_file. Best-effort.
(url: string, text: string)
| 150 | |
| 151 | /** Store the full clean text so an omitted middle is recoverable via read_file. Best-effort. */ |
| 152 | async function storeFullText(url: string, text: string): Promise<string | null> { |
| 153 | try { |
| 154 | const { QODEX_HOME } = await import('../../config/defaults.js'); |
| 155 | const { promises: fs } = await import('fs'); |
| 156 | const dir = path.join(QODEX_HOME, 'cache', 'web'); |
| 157 | await fs.mkdir(dir, { recursive: true }); |
| 158 | const slug = (() => { |
| 159 | try { return new URL(url).hostname.replace(/[^a-z0-9.]+/gi, '-').slice(0, 40); } catch { return 'page'; } |
| 160 | })(); |
| 161 | const hash = createHash('sha1').update(url).digest('hex').slice(0, 10); |
| 162 | const file = path.join(dir, `${slug}-${hash}.md`); |
| 163 | await fs.writeFile(file, text); |
| 164 | return file; |
| 165 | } catch { return null; } |
| 166 | } |
| 167 | |
| 168 | export class WebFetchTool extends Tool<z.infer<typeof WebFetchArgs>> { |
| 169 | name = 'web_fetch'; |