mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
Browse: get page title too
This commit is contained in:
@@ -125,9 +125,9 @@ export async function attachmentLoadInputAsync(source: Readonly<AttachmentDraftS
|
||||
try {
|
||||
const page = await callBrowseFetchPage(source.url);
|
||||
edit(
|
||||
page.content.markdown ? { input: { mimeType: 'text/markdown', data: page.content.markdown, dataSize: page.content.markdown.length } }
|
||||
: page.content.text ? { input: { mimeType: 'text/plain', data: page.content.text, dataSize: page.content.text.length } }
|
||||
: page.content.html ? { input: { mimeType: 'text/html', data: page.content.html, dataSize: page.content.html.length } }
|
||||
page.content.markdown ? { input: { mimeType: 'text/markdown', data: page.content.markdown, dataSize: page.content.markdown.length, altData: page.title } }
|
||||
: page.content.text ? { input: { mimeType: 'text/plain', data: page.content.text, dataSize: page.content.text.length, altData: page.title } }
|
||||
: page.content.html ? { input: { mimeType: 'text/html', data: page.content.html, dataSize: page.content.html.length, altData: page.title } }
|
||||
: { inputError: 'No content found at this link' },
|
||||
);
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -42,6 +42,7 @@ const fetchPageInputSchema = z.object({
|
||||
|
||||
const fetchPageWorkerOutputSchema = z.object({
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
content: z.record(pageTransformSchema, z.string()),
|
||||
error: z.string().optional(),
|
||||
stopReason: z.enum(['end', 'timeout', 'error']),
|
||||
@@ -77,6 +78,7 @@ export const browseRouter = createTRPCRouter({
|
||||
? result.value
|
||||
: {
|
||||
url: requests[index].url,
|
||||
title: '',
|
||||
content: {},
|
||||
error: result.reason?.message || 'Unknown fetch error',
|
||||
stopReason: 'error',
|
||||
@@ -106,6 +108,7 @@ async function workerPuppeteer(
|
||||
|
||||
const result: FetchPageWorkerOutputSchema = {
|
||||
url: targetUrl,
|
||||
title: '',
|
||||
content: {},
|
||||
error: undefined,
|
||||
stopReason: 'error',
|
||||
@@ -142,6 +145,15 @@ async function workerPuppeteer(
|
||||
}
|
||||
}
|
||||
|
||||
// Get the page title after successful navigation
|
||||
if (result.stopReason !== 'error') {
|
||||
try {
|
||||
result.title = await page.title();
|
||||
} catch (error: any) {
|
||||
// result.error = '[Puppeteer] ' + (error?.message || error?.toString() || 'Unknown title error');
|
||||
}
|
||||
}
|
||||
|
||||
// transform the content of the page as text
|
||||
try {
|
||||
if (result.stopReason !== 'error') {
|
||||
|
||||
Reference in New Issue
Block a user