tpmjs/packages/tools/official/fetch-text
Ajax Davis 5926373be6 chore: update ai package to 6.0.49 across all packages
- Updated all packages from ai@6.0.23 to ai@6.0.49
- Added pnpm override to ensure consistent version
- Created changeset for publishing affected packages
2026-01-25 11:33:03 +10:00
..
src feat: add 55 new business tools and improve existing implementations 2026-01-01 19:23:32 +10:00
CHANGELOG.md chore: version packages 2025-12-31 23:54:47 +10:00
package.json chore: update ai package to 6.0.49 across all packages 2026-01-25 11:33:03 +10:00
README.md feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsconfig.json feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00
tsup.config.ts feat: add 100+ official TPMJS tools 2025-12-31 22:55:56 +10:00

@tpmjs/tools-fetch-text

Fetch a URL and return plain text content with metadata.

Installation

npm install @tpmjs/tools-fetch-text

Usage

import { fetchTextTool } from '@tpmjs/tools-fetch-text';

// Use with AI SDK
const result = await fetchTextTool.execute({
  url: 'https://example.com',
});

console.log(result.text); // Plain text content
console.log(result.contentType); // 'text/html; charset=utf-8'
console.log(result.contentLength); // 12345
console.log(result.metadata); // { fetchedAt, statusCode, redirected, finalUrl }

Features

  • Fetches any URL and returns plain text
  • Automatically strips HTML tags from HTML content
  • Decodes common HTML entities
  • 30 second timeout for requests
  • Returns metadata including content type, length, status code
  • Tracks redirects and provides final URL
  • Comprehensive error handling

Input

  • url (string, required): The URL to fetch (must be http or https)

Output

Returns a FetchTextResult object:

{
  text: string;           // Plain text content (HTML stripped if applicable)
  url: string;            // Original URL
  contentLength: number;  // Length of raw content in bytes
  contentType: string;    // Content-Type header value
  metadata: {
    fetchedAt: string;    // ISO timestamp of when content was fetched
    statusCode: number;   // HTTP status code
    redirected: boolean;  // Whether the request was redirected
    finalUrl: string;     // Final URL after redirects
  };
}

Requirements

  • Node.js 18+ (uses native fetch API)

License

MIT