Skip to content
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

Merged
merged 8 commits into from
Aug 28, 2024
134 changes: 134 additions & 0 deletions docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"mammoth": "^1.8.0",
"mathjs": "^13.1.1",
"pdfjs-dist": "4.5.136",
"playwright": "^1.46.1",
"tree-sitter-wasms": "^0.1.11",
"tsx": "^4.19.0",
"typescript": "5.5.4",
Expand Down Expand Up @@ -75,8 +76,8 @@
"zx": "^8.1.4"
},
"scripts": {
"compile": "esbuild src/main.ts --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer&& node ../../scripts/patch-cli.mjs",
"compile-debug": "esbuild src/main.ts --sourcemap --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer",
"compile": "esbuild src/main.ts --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer --external:playwright && node ../../scripts/patch-cli.mjs",
"compile-debug": "esbuild src/main.ts --sourcemap --metafile=./esbuild.meta.json --bundle --platform=node --target=node20 --outfile=built/genaiscript.cjs --external:tsx --external:esbuild --external:get-tsconfig --external:resolve-pkg-maps --external:dockerode --external:pdfjs-dist --external:web-tree-sitter --external:tree-sitter-wasms --external:promptfoo --external:typescript --external:@lvce-editor/ripgrep --external:gpt-3-encoder --external:mammoth --external:xlsx --external:mathjs --external:@azure/identity --external:gpt-tokenizer --external:playwright",
"postcompile": "node built/genaiscript.cjs info help > ../../docs/src/content/docs/reference/cli/commands.md",
"vis:treemap": "npx --yes esbuild-visualizer --metadata esbuild.meta.json --filename esbuild.treemap.html",
"vis:network": "npx --yes esbuild-visualizer --metadata esbuild.meta.json --filename esbuild.network.html --template network",
Expand All @@ -85,4 +86,4 @@
"typecheck": "tsc -p src",
"lint": "npx --yes publint"
}
}
}
1 change: 0 additions & 1 deletion packages/cli/src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import MemoryStream from "memorystream"
import { finished } from "stream/promises"
import { ensureDir, remove } from "fs-extra"
import { copyFile, readFile, writeFile } from "fs/promises"
import { DOCKERODE_VERSION } from "./version"
import {
DOCKER_DEFAULT_IMAGE,
DOCKER_VOLUMES_DIR,
Expand Down
21 changes: 17 additions & 4 deletions packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
} from "./azuretoken"
import { LanguageModel } from "../../core/src/chat"
import { errorMessage } from "../../core/src/error"
import { BrowserManager } from "./playwright"

class NodeServerManager implements ServerManager {
async start(): Promise<void> {
Expand Down Expand Up @@ -103,7 +104,8 @@
readonly path = createNodePath()
readonly server = new NodeServerManager()
readonly workspace = createFileSystem()
readonly docker = new DockerManager()
readonly containers = new DockerManager()

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

readonly browsers = new BrowserManager()
readonly defaultModelOptions = {
model: DEFAULT_MODEL,
temperature: DEFAULT_TEMPERATURE,
Expand Down Expand Up @@ -258,14 +260,21 @@
await remove(name)
}

async browse(
url: string,
options?: BrowseSessionOptions & TraceOptions
): Promise<BrowserPage> {
return this.browsers.browse(url, options)
}

Check failure on line 268 in packages/cli/src/nodehost.ts

View workflow job for this annotation

GitHub Actions / build

There is no error handling for the async function `browse`. Consider adding a try-catch block to handle potential exceptions.

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


async exec(
containerId: string,
command: string,
args: string[],
options: ShellOptions & TraceOptions
) {
if (containerId) {
const container = await this.docker.container(containerId)
const container = await this.containers.container(containerId)
return await container.exec(command, args, options)
}

Expand Down Expand Up @@ -331,10 +340,14 @@
async container(
options: ContainerOptions & TraceOptions
): Promise<ContainerHost> {
return await this.docker.startContainer(options)
return await this.containers.startContainer(options)
}

async removeContainers(): Promise<void> {
await this.docker.stopAndRemove()
await this.containers.stopAndRemove()
}

async removeBrowsers(): Promise<void> {
await this.browsers.stopAndRemove()
}
}
Loading