-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
browser automation support #668
Conversation
…nclude as external
options?: BrowseSessionOptions & TraceOptions | ||
): Promise<BrowserPage> { | ||
return this.browsers.browse(url, options) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling for the async function browse
. Consider adding a try-catch block to handle potential exceptions.
generated by pr-review-commit
missing_error_handling
private async launchBrowser(options?: {}) { | ||
await this.init() | ||
const browser = await this._playwright.chromium.launch() | ||
return browser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function launchBrowser
does not handle potential errors during the async operations. Consider adding error handling to improve robustness.
generated by pr-review-commit
missing_error_handling
} catch (e) { | ||
logError(e) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function stopAndRemove
does not handle potential errors during the async operations. Consider adding error handling to improve robustness.
generated by pr-review-commit
missing_error_handling
The changes in this pull request mostly revolve around the introduction of a new functionality: browsing the web with Playwright. A new Other notable changes include:
The changes look good, the new functionality has been well integrated with the existing codebase, and it seems to follow the project's coding standards. However, the Otherwise, LGTM 🚀.
|
} | ||
})() | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling for the defImages
function when handling Buffer files. Consider adding a try-catch block to handle potential errors.
generated by pr-review-commit
missing_error_handling
const res = new Turndown().turndown(html) | ||
return res | ||
} catch (e) { | ||
logError(e) | ||
trace?.error("HTML conversion failed", e) | ||
return undefined | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The turndown
package is used but it's not imported. Please import it at the top of the file.
generated by pr-review-commit
missing_dependency
} | ||
})() | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function passed to createImageNode
is async but it's not awaited or returned. This could lead to unhandled promise rejections.
generated by pr-review-commit
missing_async
…arkdown conversion in core package
if (this._playwright) return | ||
const p = await import("playwright") | ||
if (!p) throw new Error("playwright installation not completed") | ||
this._playwright = p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling for the init
function. Consider adding a try-catch block to handle potential exceptions.
generated by pr-review-commit
missing_error_handling
trace?.error("HTML conversion failed", e) | ||
return undefined | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no error handling for the HTMLToMarkdown
function. Consider adding a try-catch block to handle potential exceptions.
generated by pr-review-commit
missing_error_handling
@@ -103,7 +104,8 @@ export class NodeHost implements RuntimeHost { | |||
readonly path = createNodePath() | |||
readonly server = new NodeServerManager() | |||
readonly workspace = createFileSystem() | |||
readonly docker = new DockerManager() | |||
readonly containers = new DockerManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DockerManager class is not imported but it is used in this file.
generated by pr-review-commit
missing_import
const { trace } = options || {} | ||
|
||
try { | ||
const res = new Turndown().turndown(html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Turndown class is not imported but it is used in this file.
generated by pr-review-commit
missing_import
const { files } = await workspace.grep( | ||
/[a-z][a-z0-9]+/, | ||
"**/*.md") | ||
const { files } = await workspace.grep(/[a-z][a-z0-9]+/, "**/*.md") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a typo in the word "weahter". It should be "weather".
generated by pr-docs-review-commit
typo
defTool("weather", "live weahter", | ||
{ city: "Paris" }, // schema | ||
async ({ city }) => // callback | ||
defTool("weather", "live weahter", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a typo in the word "weahter". It should be "weather".
generated by pr-docs-review-commit
typo
import { Page } from "playwright" | ||
|
||
const page = await host.browse(url) as Page | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new file "browse.md" has been added in the "scripts" reference section. This file provides documentation for interacting with a headless browser using Playwright.
generated by pr-docs-review-commit
new_file
|
||
## Installation | ||
|
||
You will need to install Playright locally before using the `browse` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a typo here. The correct spelling should be "Playwright" not "Playright".
generated by pr-docs-review-commit
typo
|
||
```js | ||
import { Page } from "playwright" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a typo here. The correct word should be "cast" not "case".
generated by pr-docs-review-commit
typo
} | ||
})() | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type check for files instanceof Buffer
in the defImages
function is incorrect. The files
parameter can be a string or a WorkspaceFile
object, but it cannot be a Buffer
object. Please revise the type check.
generated by pr-review-commit
incorrect_type_check
* @param url | ||
* @param options | ||
*/ | ||
browse(url: string, options?: BrowseSessionOptions): Promise<BrowserPage> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The browse
function in the ShellHost
interface is missing a description. Please add a description to explain what this function does.
generated by pr-review-commit
missing_function_description
playwright
has been added to the package.json dependencies, indicating the introduction of browser automation functionalities.🌐browse
method has been added to theRuntimeHost
interface, which allows browsing a URL with specific options. This is reflected in the implementation changes inNodehost
. 🛠️BrowserManager
has been introduced inpackages/cli/src/playwright.ts
to handle browsing activities with methods likeinit
,launchBrowser
,stopAndRemove
, andbrowse
. This class manages and controls browser instances and tasks. 🕹️packages/cli/src/nodehost.ts
, the DockerManager has been renamed tocontainers
, and a new instance of BrowserManager namedbrowsers
has been added. Moreover, the functionremoveContainers
now includes the functionremoveBrowsers
. 🔄packages/core/src/host.ts
,packages/core/src/promptcontext.ts
, andpackages/core/src/testhost.ts
, relevant changes are made to incorporate the new browser functionality. 📝packages/core/src/types/prompt_template.d.ts
where new interfacesBrowseSessionOptions
,BrowserLocator
,BrowseResponse
, andBrowserPage
are introduced to provide better structure for browser interactions. 🖥️packages/sample/genaisrc/browse.genai.mts
demonstrating an example usage of browsing a webpage and fetching content using the newbrowse
ability. 👩💻