summaryrefslogtreecommitdiffhomepage
path: root/packages/tool-web-search/src/format.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tool-web-search/src/format.ts')
-rw-r--r--packages/tool-web-search/src/format.ts116
1 files changed, 58 insertions, 58 deletions
diff --git a/packages/tool-web-search/src/format.ts b/packages/tool-web-search/src/format.ts
index cfc9aa0..172fd85 100644
--- a/packages/tool-web-search/src/format.ts
+++ b/packages/tool-web-search/src/format.ts
@@ -8,28 +8,28 @@
/** A single search hit from Firecrawl's `/search` endpoint. */
export interface SearchHit {
- readonly title?: string;
- readonly url?: string;
- readonly description?: string;
- readonly markdown?: string;
+ readonly title?: string;
+ readonly url?: string;
+ readonly description?: string;
+ readonly markdown?: string;
}
/** One page from a completed crawl (`/crawl` status `data`). */
export interface CrawlPage {
- readonly markdown?: string;
- readonly metadata?: {
- readonly title?: string;
- readonly sourceURL?: string;
- readonly url?: string;
- };
+ readonly markdown?: string;
+ readonly metadata?: {
+ readonly title?: string;
+ readonly sourceURL?: string;
+ readonly url?: string;
+ };
}
/** The scrape response payload (`/scrape` `data`). */
export interface ScrapeResult {
- readonly data?: {
- readonly markdown?: string;
- readonly metadata?: { readonly title?: string };
- };
+ readonly data?: {
+ readonly markdown?: string;
+ readonly metadata?: { readonly title?: string };
+ };
}
/**
@@ -37,11 +37,11 @@ export interface ScrapeResult {
* spirit to tool-shell. Duplication across features is the intended trade.
*/
export function truncateOutput(output: string, cap: number): string {
- if (output.length <= cap) {
- return output;
- }
- const truncated = output.slice(0, cap);
- return `${truncated}\n\n[Output truncated: exceeded ${cap} characters]`;
+ if (output.length <= cap) {
+ return output;
+ }
+ const truncated = output.slice(0, cap);
+ return `${truncated}\n\n[Output truncated: exceeded ${cap} characters]`;
}
/**
@@ -49,21 +49,21 @@ export function truncateOutput(output: string, cap: number): string {
* joined by `---` separators. Empty → `"No results found."`.
*/
export function formatSearchResults(data: readonly SearchHit[] | null | undefined): string {
- if (!data || data.length === 0) {
- return "No results found.";
- }
- const parts: string[] = [];
- for (const r of data) {
- const title = r.title ?? "(no title)";
- const url = r.url ?? "";
- const description = r.description ?? "";
- let section = `### ${title}\n${url}\n\n${description}`;
- if (r.markdown) {
- section += `\n\n${r.markdown}`;
- }
- parts.push(section);
- }
- return parts.join("\n\n---\n\n");
+ if (!data || data.length === 0) {
+ return "No results found.";
+ }
+ const parts: string[] = [];
+ for (const r of data) {
+ const title = r.title ?? "(no title)";
+ const url = r.url ?? "";
+ const description = r.description ?? "";
+ let section = `### ${title}\n${url}\n\n${description}`;
+ if (r.markdown) {
+ section += `\n\n${r.markdown}`;
+ }
+ parts.push(section);
+ }
+ return parts.join("\n\n---\n\n");
}
/**
@@ -71,12 +71,12 @@ export function formatSearchResults(data: readonly SearchHit[] | null | undefine
* the title is absent.
*/
export function formatScrapeResult(json: ScrapeResult): string {
- const md = json.data?.markdown ?? "";
- const title = json.data?.metadata?.title;
- if (title) {
- return `# ${title}\n\n${md}`;
- }
- return md;
+ const md = json.data?.markdown ?? "";
+ const title = json.data?.metadata?.title;
+ if (title) {
+ return `# ${title}\n\n${md}`;
+ }
+ return md;
}
/**
@@ -84,28 +84,28 @@ export function formatScrapeResult(json: ScrapeResult): string {
* Empty → `"No pages crawled."`.
*/
export function formatCrawlResults(data: readonly CrawlPage[] | null | undefined): string {
- if (!data || data.length === 0) {
- return "No pages crawled.";
- }
- const parts: string[] = [];
- for (const page of data) {
- const title = page.metadata?.title ?? "(no title)";
- const url = page.metadata?.sourceURL ?? page.metadata?.url ?? "";
- let section = `## ${title}\n${url}`;
- if (page.markdown) {
- section += `\n\n${page.markdown}`;
- }
- parts.push(section);
- }
- return parts.join("\n\n---\n\n");
+ if (!data || data.length === 0) {
+ return "No pages crawled.";
+ }
+ const parts: string[] = [];
+ for (const page of data) {
+ const title = page.metadata?.title ?? "(no title)";
+ const url = page.metadata?.sourceURL ?? page.metadata?.url ?? "";
+ let section = `## ${title}\n${url}`;
+ if (page.markdown) {
+ section += `\n\n${page.markdown}`;
+ }
+ parts.push(section);
+ }
+ return parts.join("\n\n---\n\n");
}
/**
* Format discovered links as a bullet list. Empty → `"No links found."`.
*/
export function formatMapResults(links: readonly string[] | null | undefined): string {
- if (!links || links.length === 0) {
- return "No links found.";
- }
- return links.map((l) => `- ${l}`).join("\n");
+ if (!links || links.length === 0) {
+ return "No links found.";
+ }
+ return links.map((l) => `- ${l}`).join("\n");
}