1+ import puppeteer from "@cloudflare/puppeteer" ;
12import { LoadAPIKeyError , generateObject , generateText } from "ai" ;
23import { Hono } from "hono" ;
34import { HTTPException } from "hono/http-exception" ;
@@ -19,7 +20,6 @@ import {
1920} from "./templates/layout" ;
2021import type { ResearchType , ResearchTypeDB } from "./types" ;
2122import { formatDuration , getModel } from "./utils" ;
22- import puppeteer from "@cloudflare/puppeteer" ;
2323
2424export { ResearchWorkflow } from "./workflows" ;
2525
@@ -115,7 +115,7 @@ app.get("/", async (c) => {
115115} ) ;
116116
117117app . get ( "/create" , async ( c ) => {
118- const userRags = await c . env . AI . autorag ( ) . list ( )
118+ const userRags = await c . env . AI . autorag ( ) . list ( ) ;
119119
120120 return c . html (
121121 < Layout >
@@ -202,7 +202,11 @@ app.post("/create", async (c) => {
202202
203203 const initialLearnings = form . get ( "initial-learnings" ) as string | undefined ;
204204 const browseInternetFormValue = form . get ( "browse_internet" ) ;
205- const browse_internet = browseInternetFormValue === "on" || browseInternetFormValue === "" || browseInternetFormValue === null ? true : false ; // default to true if present (even as empty string from checked) or not present at all.
205+ const browse_internet = ! ! (
206+ browseInternetFormValue === "on" ||
207+ browseInternetFormValue === "" ||
208+ browseInternetFormValue === null
209+ ) ; // default to true if present (even as empty string from checked) or not present at all.
206210 const autorag_id_form = form . get ( "autorag_id" ) as string | null ;
207211 const autorag_id = autorag_id_form === "" ? null : autorag_id_form ;
208212
@@ -320,17 +324,54 @@ app.get("/details/:id", async (c) => {
320324 </ button >
321325 < div className = "relative inline-block text-left" >
322326 < div >
323- < button type = "button" className = "inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" id = "options-menu" aria-haspopup = "true" aria-expanded = "true" onClick = { `toggleDropdown('${ id } ')` } >
327+ < button
328+ type = "button"
329+ className = "inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
330+ id = "options-menu"
331+ aria-haspopup = "true"
332+ aria-expanded = "true"
333+ onClick = { `toggleDropdown('${ id } ')` }
334+ >
324335 Download Report
325- < svg className = "-mr-1 ml-2 h-5 w-5" xmlns = "http://www.w3.org/2000/svg" viewBox = "0 0 20 20" fill = "currentColor" aria-hidden = "true" >
326- < path fillRule = "evenodd" d = "M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clipRule = "evenodd" />
336+ < svg
337+ className = "-mr-1 ml-2 h-5 w-5"
338+ xmlns = "http://www.w3.org/2000/svg"
339+ viewBox = "0 0 20 20"
340+ fill = "currentColor"
341+ aria-hidden = "true"
342+ >
343+ < path
344+ fillRule = "evenodd"
345+ d = "M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
346+ clipRule = "evenodd"
347+ />
327348 </ svg >
328349 </ button >
329350 </ div >
330- < div id = { `download-dropdown-${ id } ` } className = "origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 hidden z-10" role = "menu" aria-orientation = "vertical" aria-labelledby = "options-menu" >
331- < div className = "py-1" role = "none" >
332- < a href = { `/details/${ id } /download/pdf` } download = "report.pdf" className = "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role = "menuitem" > Download as PDF</ a >
333- < a href = { `/details/${ id } /download/markdown` } download = "report.md" className = "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role = "menuitem" > Download as Markdown</ a >
351+ < div
352+ id = { `download-dropdown-${ id } ` }
353+ className = "origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 hidden z-10"
354+ role = "menu"
355+ aria-orientation = "vertical"
356+ aria-labelledby = "options-menu"
357+ >
358+ < div className = "py-1" >
359+ < a
360+ href = { `/details/${ id } /download/pdf` }
361+ download = "report.pdf"
362+ className = "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900"
363+ role = "menuitem"
364+ >
365+ Download as PDF
366+ </ a >
367+ < a
368+ href = { `/details/${ id } /download/markdown` }
369+ download = "report.md"
370+ className = "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900"
371+ role = "menuitem"
372+ >
373+ Download as Markdown
374+ </ a >
334375 </ div >
335376 </ div >
336377 </ div >
@@ -361,17 +402,17 @@ app.get("/details/:id/download/pdf", async (c) => {
361402 const content = resp . results . result ?? "" ;
362403 const htmlContent = renderMarkdownReportContent ( content ) ;
363404
364- const browser = await puppeteer . launch ( c . env . BROWSER ) ;
365- const page = await browser . newPage ( ) ;
405+ const browser = await puppeteer . launch ( c . env . BROWSER ) ;
406+ const page = await browser . newPage ( ) ;
366407
367- // // Step 2: Send HTML and CSS to our browser
368- await page . setContent ( htmlContent ) ;
408+ // // Step 2: Send HTML and CSS to our browser
409+ await page . setContent ( htmlContent ) ;
369410
370- // // Step 3: Generate and return PDF
371- const pdf = await page . pdf ( { printBackground : true } ) ;
411+ // // Step 3: Generate and return PDF
412+ const pdf = await page . pdf ( { printBackground : true } ) ;
372413
373- // Close browser since we no longer need it
374- await browser . close ( ) ;
414+ // Close browser since we no longer need it
415+ await browser . close ( ) ;
375416
376417 c . header ( "Content-Type" , "application/pdf" ) ;
377418 c . header ( "Content-Disposition" , 'attachment; filename="report.pdf"' ) ;
0 commit comments