farming-code 2.2.30 → 2.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +7 -0
- package/backend/acp/{client-services.js → client-services.cjs} +132 -134
- package/backend/acp/packaged-claude-acp.cjs +37 -0
- package/backend/acp/packaged-codex-acp.cjs +37 -0
- package/backend/acp/patch-decisions.cjs +182 -0
- package/backend/acp/permission-security.cjs +131 -0
- package/backend/{acp-checkpoint-store.js → acp-checkpoint-store.cjs} +90 -59
- package/backend/{acp-runtime.js → acp-runtime.cjs} +1220 -1112
- package/backend/acp-session-state.cjs +622 -0
- package/backend/acp-transcript.cjs +525 -0
- package/backend/agent-env.cjs +257 -0
- package/backend/agent-extension-discovery.cjs +452 -0
- package/backend/agent-extension-inventory.cjs +116 -0
- package/backend/agent-json-stream.cjs +283 -0
- package/backend/agent-lifecycle-journal.cjs +185 -0
- package/backend/{agent-manager.js → agent-manager.cjs} +3116 -4275
- package/backend/agent-order-transaction.cjs +85 -0
- package/backend/agent-order.cjs +159 -0
- package/backend/agent-provider-session.cjs +98 -0
- package/backend/agent-runtime-binding.cjs +179 -0
- package/backend/agent-session-history.cjs +1022 -0
- package/backend/agent-session-inventory.cjs +291 -0
- package/backend/async-cache.cjs +104 -0
- package/backend/atomic-json-store.cjs +67 -0
- package/backend/auth.cjs +261 -0
- package/backend/authoritative-inventory-cache.cjs +383 -0
- package/backend/business-health.cjs +68 -0
- package/backend/chat-runtime.cjs +50 -0
- package/backend/claude-settings.cjs +132 -0
- package/backend/cli-agents.cjs +435 -0
- package/backend/codex-context-window.cjs +196 -0
- package/backend/codex-models.cjs +228 -0
- package/backend/codex-session-archive.cjs +82 -0
- package/backend/codex-session-history.cjs +590 -0
- package/backend/{codex-terminal-profile.js → codex-terminal-profile.cjs} +149 -155
- package/backend/codex-transcript-sanitizer.cjs +130 -0
- package/backend/codex-transcript.cjs +2107 -0
- package/backend/command-runner-child.cjs +105 -0
- package/backend/config-manager.cjs +1263 -0
- package/backend/control-api.cjs +439 -0
- package/backend/data/LICENSE.cua +21 -0
- package/backend/executable-discovery.cjs +204 -0
- package/backend/farming-agent-bootstrap.cjs +81 -0
- package/backend/farming-agent-bootstrap.zh_cn.md +6 -2
- package/backend/{farming-app-cli.js → farming-app-cli.cjs} +441 -493
- package/backend/farming-cli.cjs +414 -0
- package/backend/farming-net-pass.cjs +319 -0
- package/backend/farming-net-registry.cjs +123 -0
- package/backend/farming-net-server.cjs +309 -0
- package/backend/farming-session-store.cjs +651 -0
- package/backend/git-worktree-info.cjs +181 -0
- package/backend/haiku-token.cjs +828 -0
- package/backend/index-html.cjs +96 -0
- package/backend/input-parts.cjs +68 -0
- package/backend/input-routing.cjs +40 -0
- package/backend/{local-session-engine.js → local-session-engine.cjs} +276 -282
- package/backend/main-agent-skills.cjs +309 -0
- package/backend/main-page-session.cjs +132 -0
- package/backend/native-pty-controller-generation.cjs +139 -0
- package/backend/{native-pty-host-client.js → native-pty-host-client.cjs} +338 -346
- package/backend/native-pty-host-identity.cjs +125 -0
- package/backend/native-pty-host-path.cjs +68 -0
- package/backend/{native-pty-host.js → native-pty-host.cjs} +480 -569
- package/backend/native-session-engine.cjs +296 -0
- package/backend/network.cjs +57 -0
- package/backend/npm-update-helper.cjs +399 -0
- package/backend/packaged-node-pty.cjs +120 -0
- package/backend/preview-session-manager.cjs +89 -0
- package/backend/provider-adapters.cjs +492 -0
- package/backend/provider-home-configuration.cjs +211 -0
- package/backend/provider-session-id.cjs +79 -0
- package/backend/provider-session-service.cjs +333 -0
- package/backend/qr-share-tickets.cjs +119 -0
- package/backend/resource-broadcast-protocol.cjs +50 -0
- package/backend/review-diff-router.cjs +202 -0
- package/backend/review-diff-service.cjs +1267 -0
- package/backend/review-session-router.cjs +93 -0
- package/backend/review-session-service.cjs +470 -0
- package/backend/review-session-store.cjs +161 -0
- package/backend/review-state-router.cjs +132 -0
- package/backend/review-state-store.cjs +299 -0
- package/backend/run-history-store.cjs +97 -0
- package/backend/runtime-dependency-manager.cjs +893 -0
- package/backend/runtime-executable-invocation.cjs +37 -0
- package/backend/runtime-observation.cjs +96 -0
- package/backend/server-process-identity.cjs +70 -0
- package/backend/server.cjs +3356 -0
- package/backend/session-engine-bridge.cjs +144 -0
- package/backend/session-engine-router.cjs +105 -0
- package/backend/session-engine.cjs +64 -0
- package/backend/session-stream-protocol.cjs +181 -0
- package/backend/shell-busy-integration.cjs +442 -0
- package/backend/slash-command-discovery.cjs +423 -0
- package/backend/storage-layout.cjs +263 -0
- package/backend/system-monitor.cjs +96 -0
- package/backend/terminal-attach-checkpoint.cjs +73 -0
- package/backend/terminal-exit-quiescence.cjs +57 -0
- package/backend/{terminal-reducer-flow-control.js → terminal-reducer-flow-control.cjs} +45 -22
- package/backend/terminal-runtime-cleanup.cjs +99 -0
- package/backend/{terminal-screen-state.js → terminal-screen-state.cjs} +100 -108
- package/backend/{terminal-screen-worker-pool.js → terminal-screen-worker-pool.cjs} +89 -79
- package/backend/{terminal-screen-worker-thread.js → terminal-screen-worker-thread.cjs} +64 -65
- package/backend/terminal-screen-worker.cjs +352 -0
- package/backend/terminal-state-serialization.cjs +147 -0
- package/backend/{terminal-status.js → terminal-status.cjs} +137 -187
- package/backend/theme-manager.cjs +185 -0
- package/backend/{update-service.js → update-service.cjs} +258 -248
- package/backend/usage-forecast.cjs +95 -0
- package/backend/{usage-history-client.js → usage-history-client.cjs} +144 -94
- package/backend/usage-history-smoke.cjs +85 -0
- package/backend/usage-history-worker.cjs +60 -0
- package/backend/{usage-monitor.js → usage-monitor.cjs} +363 -390
- package/backend/workspace-directory.cjs +239 -0
- package/backend/workspace-discovery.cjs +271 -0
- package/backend/{workspace-file-router.js → workspace-file-router.cjs} +213 -282
- package/backend/{workspace-file-service.js → workspace-file-service.cjs} +1139 -1318
- package/backend/workspace-root-registry.cjs +192 -0
- package/bin/farming +1 -1
- package/dist/acp/codex-acp-1.1.4.mjs +18 -1
- package/dist/assets/App-BCkdpWB6.css +1 -0
- package/dist/assets/App-CRjKpaGp.js +697 -0
- package/dist/assets/CodeSelect-Ci8sKZPU.js +1 -0
- package/dist/assets/CodeSelect-T2eNzrOc.css +1 -0
- package/dist/assets/{FileEditorMarkdownPreview-Cs9cLv8a.js → FileEditorMarkdownPreview-V06QHlAg.js} +55 -55
- package/dist/assets/FileEditorPane-BX-Wjg9U.js +2 -0
- package/dist/assets/IconGlyphs-YhV7tqd4.js +1 -0
- package/dist/assets/ProjectFilesSection-BDT2_r0o.js +12 -0
- package/dist/assets/ReviewPage-BqAs5sG1.js +3 -0
- package/dist/assets/code-dark-B7eM_9G9.css +1 -0
- package/dist/assets/{cssMode-Bdg5RpcJ.js → cssMode-ADdAlxTO.js} +1 -1
- package/dist/assets/{editor.api2-D74ufkbr.js → editor.api2-BFLAr0YF.js} +162 -162
- package/dist/assets/file-icons-BpeqWkIB.js +1 -0
- package/dist/assets/{freemarker2-DfMDJfnE.js → freemarker2-C90q5jrp.js} +1 -1
- package/dist/assets/{handlebars-BEdPtzMT.js → handlebars-BwUQcEDq.js} +1 -1
- package/dist/assets/{html-B1fPb1QD.js → html-1s3uPKfh.js} +1 -1
- package/dist/assets/{htmlMode-CY2ZjHxH.js → htmlMode-xtKD99de.js} +1 -1
- package/dist/assets/{index-D-zetSol.js → index-C8MchCem.js} +3 -3
- package/dist/assets/{javascript-BV2OsWA0.js → javascript-Ph7ijyny.js} +1 -1
- package/dist/assets/{jsonMode-zd07aeuX.js → jsonMode-D-jGAnFH.js} +1 -1
- package/dist/assets/linkComputer-CbGyI_qx.js +1 -0
- package/dist/assets/{liquid-BParI24X.js → liquid-0IamE_cI.js} +1 -1
- package/dist/assets/{lspLanguageFeatures-BzredkoV.js → lspLanguageFeatures-BxnQunWF.js} +1 -1
- package/dist/assets/main-CLKXa6hf.css +1 -0
- package/dist/assets/{mdx-vGzUJN98.js → mdx-DdNmfivn.js} +1 -1
- package/dist/assets/{monaco.contribution-BmaeBQEc.js → monaco.contribution-B43jsUs1.js} +2 -2
- package/dist/assets/{python-CUwdLgsI.js → python-IAt4X5TS.js} +1 -1
- package/dist/assets/{razor-BScebUxU.js → razor-DRkFYW0S.js} +1 -1
- package/dist/assets/review-C8-oPKXk.css +1 -0
- package/dist/assets/{tsMode-DzUAibXK.js → tsMode-_d_4U2gf.js} +1 -1
- package/dist/assets/{typescript-D9EOeM7N.js → typescript-C7zcMq9l.js} +1 -1
- package/dist/assets/{workers-DAiomYZM.js → workers-D0nOyJzf.js} +1 -1
- package/dist/assets/workspace-editor-model-DND_Y-Bj.js +1 -0
- package/dist/assets/workspace-editor-monaco-BPWhgcIB.js +4 -0
- package/dist/assets/workspace-editor-monaco-N641qPjX.js +1 -0
- package/dist/assets/workspace-view-state-k1bTlJ_Z.js +13 -0
- package/dist/assets/{xml-wWl1dhkQ.js → xml-BR-HvxT8.js} +1 -1
- package/dist/assets/{yaml-Dc2WDaOZ.js → yaml-YtFQwh4q.js} +1 -1
- package/dist/index.html +1 -1
- package/extensions/browser/backend/agent-browser-runtime.cjs +1040 -0
- package/extensions/browser/backend/agent-capability.cjs +85 -0
- package/extensions/browser/backend/browser-mcp-server.cjs +655 -0
- package/extensions/browser/backend/browser-resource-manager.cjs +1486 -0
- package/extensions/browser/backend/browser-resource-store.cjs +228 -0
- package/extensions/browser/backend/browser-router.cjs +203 -0
- package/extensions/browser/backend/executable-discovery.cjs +248 -0
- package/extensions/browser/backend/farming-browser-client.cjs +116 -0
- package/extensions/browser/backend/index.cjs +32 -0
- package/extensions/browser/backend/managed-chromium-installer.cjs +833 -0
- package/extensions/browser/bin/farming-browser +16 -7
- package/extensions/computer/backend/agent-capability.cjs +72 -0
- package/extensions/computer/backend/computer-constants.cjs +59 -0
- package/extensions/computer/backend/computer-mcp-server.cjs +182 -0
- package/extensions/computer/backend/computer-resource-manager.cjs +1219 -0
- package/extensions/computer/backend/computer-resource-store.cjs +190 -0
- package/extensions/computer/backend/computer-router.cjs +257 -0
- package/extensions/computer/backend/cua-tools.json +3067 -0
- package/extensions/computer/backend/farming-computer-client.cjs +84 -0
- package/extensions/computer/backend/index.cjs +35 -0
- package/extensions/computer/backend/isolated-browser-provider.cjs +157 -0
- package/extensions/computer/bin/farming-computer +131 -0
- package/frontend/farming-net/app.js +255 -262
- package/frontend/ghostty-loader.js +24 -20
- package/frontend/reading-anchor.js +210 -193
- package/frontend/runtime-paths.js +24 -26
- package/frontend/session-bridge.js +90 -111
- package/frontend/session-modal-bridge.js +184 -302
- package/frontend/skin-bridge.js +20 -23
- package/frontend/skins/crt/app.js +7686 -7901
- package/frontend/skins/crt/effects.js +7 -6
- package/frontend/skins/crt/index.html +6 -6
- package/frontend/skins/crt/styles/markdown.css +4 -4
- package/frontend/terminal-bridge.js +174 -181
- package/frontend/terminal-replay.js +320 -345
- package/frontend/theme-loader.js +55 -71
- package/package.json +64 -37
- package/shared/backend-connection-status.js +38 -69
- package/shared/browser-protocol.js +235 -110
- package/shared/websocket-liveness.js +40 -0
- package/backend/acp/packaged-claude-acp.js +0 -13
- package/backend/acp/packaged-codex-acp.js +0 -13
- package/backend/acp/patch-decisions.js +0 -153
- package/backend/acp/permission-security.js +0 -108
- package/backend/acp-session-state.js +0 -634
- package/backend/acp-transcript.js +0 -512
- package/backend/agent-env.js +0 -250
- package/backend/agent-json-stream.js +0 -268
- package/backend/agent-lifecycle-journal.js +0 -133
- package/backend/agent-order.js +0 -166
- package/backend/agent-provider-session.js +0 -76
- package/backend/agent-runtime-binding.js +0 -174
- package/backend/agent-session-history.js +0 -986
- package/backend/async-cache.js +0 -94
- package/backend/atomic-json-store.js +0 -37
- package/backend/auth.js +0 -251
- package/backend/chat-runtime.js +0 -28
- package/backend/claude-settings.js +0 -121
- package/backend/cli-agents.js +0 -486
- package/backend/codex-context-window.js +0 -189
- package/backend/codex-models.js +0 -226
- package/backend/codex-session-archive.js +0 -65
- package/backend/codex-session-history.js +0 -647
- package/backend/codex-transcript-sanitizer.js +0 -115
- package/backend/codex-transcript.js +0 -2362
- package/backend/command-runner-child.js +0 -67
- package/backend/config-manager.js +0 -1117
- package/backend/control-api.js +0 -455
- package/backend/executable-discovery.js +0 -216
- package/backend/farming-agent-bootstrap.js +0 -49
- package/backend/farming-cli.js +0 -403
- package/backend/farming-net-pass.js +0 -285
- package/backend/farming-net-registry.js +0 -112
- package/backend/farming-net-server.js +0 -298
- package/backend/farming-session-store.js +0 -677
- package/backend/git-worktree-info.js +0 -181
- package/backend/haiku-token.js +0 -772
- package/backend/index-html.js +0 -80
- package/backend/input-parts.js +0 -54
- package/backend/input-routing.js +0 -24
- package/backend/json-cli-runtime.js +0 -275
- package/backend/main-agent-skills.js +0 -288
- package/backend/main-page-session.js +0 -122
- package/backend/native-pty-controller-generation.js +0 -106
- package/backend/native-pty-host-identity.js +0 -86
- package/backend/native-pty-host-path.js +0 -42
- package/backend/native-session-engine.js +0 -268
- package/backend/network.js +0 -23
- package/backend/npm-update-helper.js +0 -374
- package/backend/packaged-node-pty.js +0 -99
- package/backend/preview-session-manager.js +0 -68
- package/backend/provider-adapters.js +0 -399
- package/backend/provider-session-id.js +0 -47
- package/backend/provider-session-service.js +0 -345
- package/backend/qr-share-tickets.js +0 -100
- package/backend/review-diff-router.js +0 -180
- package/backend/review-diff-service.js +0 -1270
- package/backend/review-session-router.js +0 -74
- package/backend/review-session-service.js +0 -446
- package/backend/review-session-store.js +0 -151
- package/backend/review-state-router.js +0 -116
- package/backend/review-state-store.js +0 -286
- package/backend/run-history-store.js +0 -67
- package/backend/runtime-dependency-manager.js +0 -759
- package/backend/runtime-executable-invocation.js +0 -20
- package/backend/runtime-observation.js +0 -81
- package/backend/server-process-identity.js +0 -47
- package/backend/server.js +0 -3225
- package/backend/session-engine-bridge.js +0 -129
- package/backend/session-engine-router.js +0 -66
- package/backend/session-engine.js +0 -39
- package/backend/session-stream-protocol.js +0 -185
- package/backend/shell-busy-integration.js +0 -472
- package/backend/slash-command-discovery.js +0 -433
- package/backend/storage-layout.js +0 -205
- package/backend/system-monitor.js +0 -77
- package/backend/terminal-attach-checkpoint.js +0 -74
- package/backend/terminal-exit-quiescence.js +0 -39
- package/backend/terminal-runtime-cleanup.js +0 -80
- package/backend/terminal-screen-worker.js +0 -337
- package/backend/terminal-state-serialization.js +0 -127
- package/backend/theme-manager.js +0 -163
- package/backend/usage-forecast.js +0 -86
- package/backend/usage-history-scanner.ts +0 -2718
- package/backend/usage-history-smoke.js +0 -64
- package/backend/usage-history-worker.js +0 -34
- package/backend/workspace-directory.js +0 -232
- package/backend/workspace-discovery.js +0 -311
- package/backend/workspace-root-registry.js +0 -166
- package/dist/assets/App-BKNUILuL.css +0 -1
- package/dist/assets/App-Z1N7T0eM.js +0 -695
- package/dist/assets/FileEditorPane-CNtuGjQ3.js +0 -2
- package/dist/assets/IconGlyphs-BClgag6E.js +0 -1
- package/dist/assets/ProjectFilesSection-K3GHuQ4U.js +0 -12
- package/dist/assets/ReviewPage-BRuxFaH5.js +0 -3
- package/dist/assets/code-dark-kLsQLvpf.css +0 -1
- package/dist/assets/file-icons-BOlcJ0ZF.js +0 -1
- package/dist/assets/main-DUTz-Rd2.css +0 -1
- package/dist/assets/review-BcnwQtJv.css +0 -1
- package/dist/assets/workspace-editor-model-CSGCl21x.js +0 -1
- package/dist/assets/workspace-editor-monaco-CJNwbpCy.js +0 -4
- package/dist/assets/workspace-editor-monaco-CO9w8YV0.js +0 -1
- package/dist/assets/workspace-view-state-BjKPYp0E.js +0 -7
- package/extensions/browser/backend/agent-browser-runtime.js +0 -1041
- package/extensions/browser/backend/agent-capability.js +0 -55
- package/extensions/browser/backend/browser-mcp-server.js +0 -621
- package/extensions/browser/backend/browser-resource-manager.js +0 -1331
- package/extensions/browser/backend/browser-resource-store.js +0 -190
- package/extensions/browser/backend/browser-router.js +0 -141
- package/extensions/browser/backend/executable-discovery.js +0 -238
- package/extensions/browser/backend/farming-browser-client.js +0 -83
- package/extensions/browser/backend/index.js +0 -7
- package/extensions/browser/backend/managed-chromium-installer.js +0 -593
- package/extensions/browser/frontend/BrowserSidebarPortals.tsx +0 -360
- package/extensions/browser/frontend/BrowserViewer.tsx +0 -500
- package/extensions/browser/frontend/browser-resource-state.ts +0 -60
- package/extensions/browser/frontend/browser.css +0 -567
- package/extensions/browser/frontend/types.ts +0 -38
- package/extensions/browser/frontend/useBrowserResources.ts +0 -166
- package/frontend/vendor/ghostty-web/index.d.ts +0 -1842
- package/shared/backend-connection-status.d.ts +0 -37
- package/shared/browser-protocol.d.ts +0 -5
- /package/dist/assets/{api-w2x5QfxB.js → api-ByCV9MEr.js} +0 -0
- /package/dist/assets/{core-vPkV8P_m.js → core-Czwdx12k.js} +0 -0
- /package/dist/assets/{fsharp-DNZNZyEE.js → fsharp-BjPpkoJe.js} +0 -0
- /package/dist/assets/{go-_kPJjNc_.js → go-BkIDmSUP.js} +0 -0
- /package/dist/assets/{graphql-4HCNVt5g.js → graphql-CCJTpqi1.js} +0 -0
- /package/dist/assets/{hcl-C87ymY0o.js → hcl-s4z8lUFg.js} +0 -0
- /package/dist/assets/{ini-BYrrGNTc.js → ini-CyUW1I7Z.js} +0 -0
- /package/dist/assets/{java-B211rJbk.js → java-CFCcGRiM.js} +0 -0
- /package/dist/assets/{julia-DVPsRtBm.js → julia-DQyH_EYb.js} +0 -0
- /package/dist/assets/{kotlin-BYyNerjp.js → kotlin-B8hA5O51.js} +0 -0
- /package/dist/assets/{less-EC9UblGE.js → less-DaVdaas0.js} +0 -0
- /package/dist/assets/{lexon-B1yuUdqW.js → lexon-DLBhPd3y.js} +0 -0
- /package/dist/assets/{lua-Bo6GFzxT.js → lua-gB1c_cif.js} +0 -0
- /package/dist/assets/{m3-C-Y9cBVI.js → m3-C2T3z3gB.js} +0 -0
- /package/dist/assets/{markdown-BHu-wLbe.js → markdown-CKq-Euj1.js} +0 -0
- /package/dist/assets/{mips-Dkds26rX.js → mips-Bcs5qIDX.js} +0 -0
- /package/dist/assets/{msdax-PU4g-8_g.js → msdax-CBP48FHF.js} +0 -0
- /package/dist/assets/{mysql-fPpuGpS7.js → mysql-c7tiPcFj.js} +0 -0
- /package/dist/assets/{objective-c-Wy1e5JUf.js → objective-c-D4BZkeEV.js} +0 -0
- /package/dist/assets/{pascal-BIXwvrqU.js → pascal-CJDZg0MN.js} +0 -0
- /package/dist/assets/{pascaligo-DwR0AtL_.js → pascaligo-Bygi8Ynl.js} +0 -0
- /package/dist/assets/{perl-CGHAl8my.js → perl-aS8bkf7E.js} +0 -0
- /package/dist/assets/{pgsql-B91M73E2.js → pgsql-CzNAYFYl.js} +0 -0
- /package/dist/assets/{php-C70ttrCx.js → php-DOtoEFTT.js} +0 -0
- /package/dist/assets/{pla-BNrXaRh0.js → pla-DugRnao1.js} +0 -0
- /package/dist/assets/{postiats-Dv2IAZR9.js → postiats-DsXwusKh.js} +0 -0
- /package/dist/assets/{powerquery-CkY5Wq7J.js → powerquery-DL3o72oD.js} +0 -0
- /package/dist/assets/{powershell-uGIYLU3C.js → powershell-C1qHekys.js} +0 -0
- /package/dist/assets/{protobuf-CavfmJu-.js → protobuf-DHgsc-cH.js} +0 -0
- /package/dist/assets/{pug-Drqnyitx.js → pug-FZXlE_Iu.js} +0 -0
- /package/dist/assets/{qrcode-7uGsTEmi.js → qrcode-DJDTdjL7.js} +0 -0
- /package/dist/assets/{qsharp-C7yF-Dti.js → qsharp-bLyhI3DT.js} +0 -0
- /package/dist/assets/{r-HXLGP0_-.js → r-DjFGXbAa.js} +0 -0
- /package/dist/assets/{redis-C4y6mf2p.js → redis-DSoZ_V6u.js} +0 -0
- /package/dist/assets/{redshift-DdQrFPrv.js → redshift-CzkdCsrg.js} +0 -0
- /package/dist/assets/{restructuredtext-CBrf2PNj.js → restructuredtext-B_XPrGCQ.js} +0 -0
- /package/dist/assets/{ruby-CVtMoX2B.js → ruby-Cry2RneJ.js} +0 -0
- /package/dist/assets/{rust-Ckq4sbMP.js → rust-CWzdbFq1.js} +0 -0
- /package/dist/assets/{sb-er66OpE3.js → sb-DmofU59h.js} +0 -0
- /package/dist/assets/{scala-BdWZz-hH.js → scala-BUC2l-vN.js} +0 -0
- /package/dist/assets/{scheme-kTV_s2kP.js → scheme-CNIB_72f.js} +0 -0
- /package/dist/assets/{scss-Bymy2VJQ.js → scss-DcL4-NbX.js} +0 -0
- /package/dist/assets/{shell-bwEP1LQ1.js → shell-CgAGvSSA.js} +0 -0
- /package/dist/assets/{solidity-DCddeBgL.js → solidity-DSkt6O_P.js} +0 -0
- /package/dist/assets/{sophia-BMN3AQig.js → sophia--5ytcjDN.js} +0 -0
- /package/dist/assets/{sparql-CSXOLjzi.js → sparql-C1Srr7cD.js} +0 -0
- /package/dist/assets/{sql-COg8ewmK.js → sql-2k_O5fj7.js} +0 -0
- /package/dist/assets/{st-CIaZtBS_.js → st-DCCCPqfz.js} +0 -0
- /package/dist/assets/{swift-DXiOhUHu.js → swift-Dd8mAfOt.js} +0 -0
- /package/dist/assets/{systemverilog-BTDE6Dr2.js → systemverilog-B0-aZYXu.js} +0 -0
- /package/dist/assets/{tcl-B0zy9NvV.js → tcl-CZAZwPVX.js} +0 -0
- /package/dist/assets/{twig-D594l4Z1.js → twig-D-Ag0tdS.js} +0 -0
- /package/dist/assets/{typespec-XKVjaPqo.js → typespec-B7kTFp0Z.js} +0 -0
- /package/dist/assets/{useWorkspaceMenuKeyboard-Bpy_s69Z.js → useWorkspaceMenuKeyboard-uYZpDxhU.js} +0 -0
- /package/dist/assets/{vb-B2wYoKRV.js → vb-20w1JPum.js} +0 -0
- /package/dist/assets/{wgsl-D0Yf2LbK.js → wgsl-CLJfqFt0.js} +0 -0
- /package/dist/assets/{workspace-working-copy-C3FSR3N6.js → workspace-working-copy-Cfz07cOd.js} +0 -0
|
@@ -0,0 +1,1040 @@
|
|
|
1
|
+
// Generated by scripts/build-backend-runtime.ts. Do not edit.
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var agent_browser_runtime_exports = {};
|
|
31
|
+
__export(agent_browser_runtime_exports, {
|
|
32
|
+
AGENT_BROWSER_VERSION: () => AGENT_BROWSER_VERSION,
|
|
33
|
+
AgentBrowserRuntime: () => AgentBrowserRuntime,
|
|
34
|
+
DEFAULT_VIEWPORT: () => DEFAULT_VIEWPORT,
|
|
35
|
+
clampViewport: () => clampViewport,
|
|
36
|
+
defaultRunCommand: () => defaultRunCommand,
|
|
37
|
+
externalTabLabel: () => externalTabLabel,
|
|
38
|
+
namespaceForResource: () => namespaceForResource,
|
|
39
|
+
sessionForResource: () => sessionForResource,
|
|
40
|
+
waitForIdentityExit: () => waitForIdentityExit
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(agent_browser_runtime_exports);
|
|
43
|
+
var fs = __toESM(require("fs"));
|
|
44
|
+
var path = __toESM(require("path"));
|
|
45
|
+
var crypto = __toESM(require("crypto"));
|
|
46
|
+
var import_child_process = require("child_process");
|
|
47
|
+
var import_events = require("events");
|
|
48
|
+
var import_server_process_identity = require("../../../backend/server-process-identity.cjs");
|
|
49
|
+
var import_runtime_executable_invocation = require("../../../backend/runtime-executable-invocation.cjs");
|
|
50
|
+
const WebSocket = require("ws");
|
|
51
|
+
const AGENT_BROWSER_VERSION = "0.32.3";
|
|
52
|
+
const DEFAULT_VIEWPORT = Object.freeze({ width: 1280, height: 720, deviceScaleFactor: 1 });
|
|
53
|
+
const MAX_VIEWPORT_DIMENSION = 4096;
|
|
54
|
+
const MAX_VIEWPORT_PIXELS = 8e6;
|
|
55
|
+
const COMMAND_TIMEOUT_MS = 3e4;
|
|
56
|
+
const CLOSE_TIMEOUT_MS = 1e4;
|
|
57
|
+
const PROCESS_EXIT_TIMEOUT_MS = 5e3;
|
|
58
|
+
const PROCESS_EXIT_POLL_MS = 100;
|
|
59
|
+
const MAX_ACTION_TIMEOUT_MS = 12e4;
|
|
60
|
+
const MAX_SCRIPT_LENGTH = 1e5;
|
|
61
|
+
function namespaceForResource(configDir, id, generation) {
|
|
62
|
+
const digest = crypto.createHash("sha256").update(`${path.resolve(configDir)}:${String(id)}:${Number(generation)}`).digest("hex").slice(0, 16);
|
|
63
|
+
return `farming-${digest}`;
|
|
64
|
+
}
|
|
65
|
+
function sessionForResource(id, generation) {
|
|
66
|
+
const digest = crypto.createHash("sha256").update(`${String(id)}:${Number(generation)}`).digest("hex").slice(0, 16);
|
|
67
|
+
return `fb-${digest}`;
|
|
68
|
+
}
|
|
69
|
+
function externalTabLabel(id, generation) {
|
|
70
|
+
return `farming-${String(id)}-g${Number(generation)}`;
|
|
71
|
+
}
|
|
72
|
+
function clampViewport(value = {}) {
|
|
73
|
+
let width = Math.max(320, Math.min(MAX_VIEWPORT_DIMENSION, Math.round(Number(value.width) || DEFAULT_VIEWPORT.width)));
|
|
74
|
+
let height = Math.max(240, Math.min(MAX_VIEWPORT_DIMENSION, Math.round(Number(value.height) || DEFAULT_VIEWPORT.height)));
|
|
75
|
+
const requestedScale = Number(value.deviceScaleFactor);
|
|
76
|
+
let deviceScaleFactor = Number.isFinite(requestedScale) ? Math.max(1, Math.min(2, requestedScale)) : DEFAULT_VIEWPORT.deviceScaleFactor;
|
|
77
|
+
const pixels = width * height * deviceScaleFactor * deviceScaleFactor;
|
|
78
|
+
if (pixels > MAX_VIEWPORT_PIXELS) {
|
|
79
|
+
deviceScaleFactor = Math.max(1, Math.sqrt(MAX_VIEWPORT_PIXELS / (width * height)));
|
|
80
|
+
}
|
|
81
|
+
if (width * height * deviceScaleFactor * deviceScaleFactor > MAX_VIEWPORT_PIXELS) {
|
|
82
|
+
const ratio = Math.sqrt(MAX_VIEWPORT_PIXELS / (width * height));
|
|
83
|
+
width = Math.max(320, Math.floor(width * ratio));
|
|
84
|
+
height = Math.max(240, Math.floor(height * ratio));
|
|
85
|
+
deviceScaleFactor = 1;
|
|
86
|
+
}
|
|
87
|
+
return { width, height, deviceScaleFactor };
|
|
88
|
+
}
|
|
89
|
+
function parseJsonOutput(stdout) {
|
|
90
|
+
const text = String(stdout || "").trim();
|
|
91
|
+
if (!text) throw new Error("agent-browser returned no JSON output");
|
|
92
|
+
const candidates = [text, ...text.split(/\r?\n/).reverse()];
|
|
93
|
+
for (const candidate of candidates) {
|
|
94
|
+
try {
|
|
95
|
+
const parsed = JSON.parse(candidate);
|
|
96
|
+
if (isRecord(parsed)) return parsed;
|
|
97
|
+
} catch {
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`agent-browser returned invalid JSON: ${text.slice(0, 240)}`);
|
|
101
|
+
}
|
|
102
|
+
function isRecord(value) {
|
|
103
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
104
|
+
}
|
|
105
|
+
function recordValue(value) {
|
|
106
|
+
return isRecord(value) ? value : {};
|
|
107
|
+
}
|
|
108
|
+
function defaultRunCommand(executablePath, args, options = {}) {
|
|
109
|
+
const env = options.env || process.env;
|
|
110
|
+
const invocation = env.FARMING_AGENT_BROWSER_STATIC === "1" ? { command: executablePath, args } : (0, import_runtime_executable_invocation.runtimeExecutableInvocation)(executablePath, args, env);
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
(0, import_child_process.execFile)(invocation.command, invocation.args, {
|
|
113
|
+
encoding: "utf8",
|
|
114
|
+
timeout: options.timeoutMs || COMMAND_TIMEOUT_MS,
|
|
115
|
+
maxBuffer: options.maxBuffer || 4 * 1024 * 1024,
|
|
116
|
+
env
|
|
117
|
+
}, (error, stdout, stderr) => {
|
|
118
|
+
let result;
|
|
119
|
+
try {
|
|
120
|
+
result = parseJsonOutput(stdout);
|
|
121
|
+
} catch (parseError) {
|
|
122
|
+
if (!error) {
|
|
123
|
+
reject(parseError);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (error || result?.success === false) {
|
|
128
|
+
const detail = error?.killed ? `Browser command timed out after ${options.timeoutMs || COMMAND_TIMEOUT_MS} ms` : result?.error || result?.message || String(stderr || "").trim() || error?.message || "agent-browser command failed";
|
|
129
|
+
const commandError = Object.assign(new Error(String(detail), { cause: error }), {
|
|
130
|
+
code: result?.code || error?.code || "AGENT_BROWSER_COMMAND_FAILED"
|
|
131
|
+
});
|
|
132
|
+
reject(commandError);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
resolve(result || {});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function commandData(result) {
|
|
140
|
+
return recordValue(result.data);
|
|
141
|
+
}
|
|
142
|
+
function publicCommandData(result) {
|
|
143
|
+
if (!result || !Object.prototype.hasOwnProperty.call(result, "data")) return {};
|
|
144
|
+
const data = result.data;
|
|
145
|
+
return isRecord(data) ? data : { value: data };
|
|
146
|
+
}
|
|
147
|
+
function normalizeRef(input = {}) {
|
|
148
|
+
const ref = String(input.ref || "").trim();
|
|
149
|
+
if (ref) return ref.startsWith("@") ? ref : `@${ref}`;
|
|
150
|
+
const selector = String(input.selector || "").trim();
|
|
151
|
+
if (selector) return selector;
|
|
152
|
+
throw new Error("ref or selector is required");
|
|
153
|
+
}
|
|
154
|
+
function normalizeTimeoutMs(value, fallback = COMMAND_TIMEOUT_MS) {
|
|
155
|
+
const timeoutMs = Number(value);
|
|
156
|
+
if (!Number.isFinite(timeoutMs)) return fallback;
|
|
157
|
+
return Math.max(100, Math.min(MAX_ACTION_TIMEOUT_MS, Math.round(timeoutMs)));
|
|
158
|
+
}
|
|
159
|
+
function requiredText(value, name, maxLength = 1e4) {
|
|
160
|
+
const text = String(value ?? "");
|
|
161
|
+
if (!text.trim()) throw new Error(`${name} is required`);
|
|
162
|
+
if (text.length > maxLength) throw new Error(`${name} is too long`);
|
|
163
|
+
return text;
|
|
164
|
+
}
|
|
165
|
+
function errorMessage(error) {
|
|
166
|
+
return error instanceof Error ? error.message : String(error || "");
|
|
167
|
+
}
|
|
168
|
+
function oneOf(value, values, name) {
|
|
169
|
+
const normalized = String(value || "").trim();
|
|
170
|
+
if (!values.includes(normalized)) {
|
|
171
|
+
throw new Error(`${name} must be one of: ${values.join(", ")}`);
|
|
172
|
+
}
|
|
173
|
+
return normalized;
|
|
174
|
+
}
|
|
175
|
+
function normalizedTabs(data) {
|
|
176
|
+
const record = recordValue(data);
|
|
177
|
+
const tabs = Array.isArray(record.tabs) ? record.tabs : Array.isArray(data) ? data : [];
|
|
178
|
+
return tabs.map(recordValue).filter((tab) => String(tab.tabId || tab.id || "").trim()).map((tab) => ({
|
|
179
|
+
tabId: String(tab.tabId || tab.id).trim(),
|
|
180
|
+
label: String(tab.label || ""),
|
|
181
|
+
title: String(tab.title || ""),
|
|
182
|
+
type: String(tab.type || "page"),
|
|
183
|
+
url: String(tab.url || "about:blank"),
|
|
184
|
+
active: tab.active === true
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
function snapshotElements(refs) {
|
|
188
|
+
if (!isRecord(refs)) return [];
|
|
189
|
+
return Object.entries(refs).slice(0, 500).map(([ref, rawValue]) => {
|
|
190
|
+
const value = recordValue(rawValue);
|
|
191
|
+
return {
|
|
192
|
+
ref: String(ref).replace(/^@/, ""),
|
|
193
|
+
role: String(value.role || ""),
|
|
194
|
+
name: String(value.name || "").slice(0, 240),
|
|
195
|
+
value: String(value.value || "").slice(0, 240),
|
|
196
|
+
disabled: value.disabled === true
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function processIdFromSessionInfo(data) {
|
|
201
|
+
const info = recordValue(data);
|
|
202
|
+
const runtime = recordValue(info.runtime);
|
|
203
|
+
const daemon = recordValue(info.daemon);
|
|
204
|
+
const session = recordValue(info.session);
|
|
205
|
+
const candidates = [
|
|
206
|
+
info.pid,
|
|
207
|
+
runtime.backgroundPid,
|
|
208
|
+
info.daemonPid,
|
|
209
|
+
daemon.pid,
|
|
210
|
+
session.pid
|
|
211
|
+
];
|
|
212
|
+
for (const candidate of candidates) {
|
|
213
|
+
const pid = Number(candidate);
|
|
214
|
+
if (Number.isSafeInteger(pid) && pid > 0) return pid;
|
|
215
|
+
}
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
function versionFromSessionInfo(data) {
|
|
219
|
+
const info = recordValue(data);
|
|
220
|
+
const daemon = recordValue(info.daemon);
|
|
221
|
+
return String(
|
|
222
|
+
info.version || info.agentBrowserVersion || daemon.version || ""
|
|
223
|
+
).replace(/^agent-browser\s+/i, "").trim();
|
|
224
|
+
}
|
|
225
|
+
function webSocketPort(data) {
|
|
226
|
+
const info = recordValue(data);
|
|
227
|
+
const server = recordValue(info.server);
|
|
228
|
+
const port = Number(info.port || info.streamPort || server.port);
|
|
229
|
+
return Number.isSafeInteger(port) && port > 0 && port <= 65535 ? port : null;
|
|
230
|
+
}
|
|
231
|
+
function keyCodeFor(key) {
|
|
232
|
+
const named = {
|
|
233
|
+
Backspace: 8,
|
|
234
|
+
Tab: 9,
|
|
235
|
+
Enter: 13,
|
|
236
|
+
Shift: 16,
|
|
237
|
+
Control: 17,
|
|
238
|
+
Alt: 18,
|
|
239
|
+
Escape: 27,
|
|
240
|
+
" ": 32,
|
|
241
|
+
ArrowLeft: 37,
|
|
242
|
+
ArrowUp: 38,
|
|
243
|
+
ArrowRight: 39,
|
|
244
|
+
ArrowDown: 40,
|
|
245
|
+
Delete: 46,
|
|
246
|
+
Meta: 91
|
|
247
|
+
};
|
|
248
|
+
if (named[key]) return named[key];
|
|
249
|
+
return key?.length === 1 ? key.toUpperCase().charCodeAt(0) : 0;
|
|
250
|
+
}
|
|
251
|
+
async function waitForIdentityExit(expected, options = {}) {
|
|
252
|
+
if (!expected) return true;
|
|
253
|
+
const readProcessIdentity = options.readProcessIdentity || import_server_process_identity.readServerProcessIdentity;
|
|
254
|
+
const wait = options.wait || ((durationMs) => new Promise((resolve) => {
|
|
255
|
+
setTimeout(resolve, durationMs);
|
|
256
|
+
}));
|
|
257
|
+
const timeoutMs = options.timeoutMs || PROCESS_EXIT_TIMEOUT_MS;
|
|
258
|
+
const startedAt = Date.now();
|
|
259
|
+
while ((0, import_server_process_identity.matchingProcessIdentity)(
|
|
260
|
+
expected,
|
|
261
|
+
await readProcessIdentity(expected.pid)
|
|
262
|
+
)) {
|
|
263
|
+
if (Date.now() - startedAt >= timeoutMs) return false;
|
|
264
|
+
await wait(PROCESS_EXIT_POLL_MS);
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
class AgentBrowserRuntime extends import_events.EventEmitter {
|
|
269
|
+
id;
|
|
270
|
+
generation;
|
|
271
|
+
configDir;
|
|
272
|
+
agentBrowserPath;
|
|
273
|
+
requiredVersion;
|
|
274
|
+
executablePath;
|
|
275
|
+
externalCdpUrl;
|
|
276
|
+
profileDir;
|
|
277
|
+
namespace;
|
|
278
|
+
session;
|
|
279
|
+
tabLabel;
|
|
280
|
+
runCommand;
|
|
281
|
+
createWebSocket;
|
|
282
|
+
readProcessIdentity;
|
|
283
|
+
wait;
|
|
284
|
+
viewport;
|
|
285
|
+
viewportRevision;
|
|
286
|
+
latestFrame;
|
|
287
|
+
processIdentity;
|
|
288
|
+
connectedCdp;
|
|
289
|
+
stream;
|
|
290
|
+
streamReady;
|
|
291
|
+
activeTabId;
|
|
292
|
+
streamTabId;
|
|
293
|
+
knownTabIds;
|
|
294
|
+
ownedTabIds;
|
|
295
|
+
popupAdmissionUntil;
|
|
296
|
+
started;
|
|
297
|
+
closedByOwner;
|
|
298
|
+
closeComplete;
|
|
299
|
+
closePromise;
|
|
300
|
+
commandChain;
|
|
301
|
+
screenshotChain;
|
|
302
|
+
constructor(options) {
|
|
303
|
+
super();
|
|
304
|
+
this.id = options.id;
|
|
305
|
+
this.generation = options.generation;
|
|
306
|
+
this.configDir = options.configDir;
|
|
307
|
+
this.agentBrowserPath = options.agentBrowserPath;
|
|
308
|
+
this.requiredVersion = options.requiredVersion || AGENT_BROWSER_VERSION;
|
|
309
|
+
this.executablePath = options.executablePath || "";
|
|
310
|
+
this.externalCdpUrl = options.externalCdpUrl || "";
|
|
311
|
+
this.profileDir = options.profileDir;
|
|
312
|
+
this.namespace = options.namespace || namespaceForResource(
|
|
313
|
+
this.configDir,
|
|
314
|
+
this.id,
|
|
315
|
+
this.generation
|
|
316
|
+
);
|
|
317
|
+
this.session = options.session || sessionForResource(this.id, this.generation);
|
|
318
|
+
this.tabLabel = options.tabLabel || externalTabLabel(this.id, this.generation);
|
|
319
|
+
this.runCommand = options.runCommand || defaultRunCommand;
|
|
320
|
+
this.createWebSocket = options.createWebSocket || ((url) => new WebSocket(url));
|
|
321
|
+
this.readProcessIdentity = options.readProcessIdentity || import_server_process_identity.readServerProcessIdentity;
|
|
322
|
+
this.wait = options.wait || ((durationMs) => new Promise((resolve) => {
|
|
323
|
+
setTimeout(resolve, durationMs);
|
|
324
|
+
}));
|
|
325
|
+
this.viewport = { ...DEFAULT_VIEWPORT };
|
|
326
|
+
this.viewportRevision = 0;
|
|
327
|
+
this.latestFrame = null;
|
|
328
|
+
this.processIdentity = null;
|
|
329
|
+
this.connectedCdp = false;
|
|
330
|
+
this.stream = null;
|
|
331
|
+
this.streamReady = false;
|
|
332
|
+
this.activeTabId = "";
|
|
333
|
+
this.streamTabId = "";
|
|
334
|
+
this.knownTabIds = /* @__PURE__ */ new Set();
|
|
335
|
+
this.ownedTabIds = /* @__PURE__ */ new Set();
|
|
336
|
+
this.popupAdmissionUntil = 0;
|
|
337
|
+
this.started = false;
|
|
338
|
+
this.closedByOwner = false;
|
|
339
|
+
this.closeComplete = false;
|
|
340
|
+
this.closePromise = null;
|
|
341
|
+
this.commandChain = Promise.resolve();
|
|
342
|
+
this.screenshotChain = Promise.resolve();
|
|
343
|
+
}
|
|
344
|
+
baseArgs() {
|
|
345
|
+
return ["--namespace", this.namespace, "--session", this.session];
|
|
346
|
+
}
|
|
347
|
+
async command(args, options = {}) {
|
|
348
|
+
if (!this.agentBrowserPath) throw new Error("agent-browser runtime is unavailable");
|
|
349
|
+
const env = {
|
|
350
|
+
...process.env,
|
|
351
|
+
...options.env,
|
|
352
|
+
AGENT_BROWSER_NO_AUTO_DIALOG: "true",
|
|
353
|
+
...!this.externalCdpUrl ? {
|
|
354
|
+
AGENT_BROWSER_EXECUTABLE_PATH: this.executablePath,
|
|
355
|
+
AGENT_BROWSER_PROFILE: this.profileDir
|
|
356
|
+
} : {}
|
|
357
|
+
};
|
|
358
|
+
const execute = () => this.runCommand(
|
|
359
|
+
this.agentBrowserPath,
|
|
360
|
+
[...this.baseArgs(), ...args, "--json"],
|
|
361
|
+
{ ...options, env }
|
|
362
|
+
);
|
|
363
|
+
const result = this.commandChain.catch(() => {
|
|
364
|
+
}).then(execute);
|
|
365
|
+
this.commandChain = result;
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
async sessionInfo() {
|
|
369
|
+
return commandData(await this.command(["session", "info"]));
|
|
370
|
+
}
|
|
371
|
+
async start(initialUrl) {
|
|
372
|
+
const url = initialUrl || "about:blank";
|
|
373
|
+
try {
|
|
374
|
+
fs.mkdirSync(path.dirname(this.profileDir), { recursive: true, mode: 448 });
|
|
375
|
+
if (this.externalCdpUrl) {
|
|
376
|
+
await this.command(["connect", this.externalCdpUrl]);
|
|
377
|
+
this.connectedCdp = true;
|
|
378
|
+
const created = commandData(await this.command([
|
|
379
|
+
"tab",
|
|
380
|
+
"new",
|
|
381
|
+
"--label",
|
|
382
|
+
this.tabLabel,
|
|
383
|
+
"about:blank"
|
|
384
|
+
]));
|
|
385
|
+
const tabId = String(created.tabId || created.id || created.targetId || this.tabLabel);
|
|
386
|
+
await this.command(["tab", tabId]);
|
|
387
|
+
this.ownedTabIds.add(tabId);
|
|
388
|
+
if (url !== "about:blank") await this.command(["open", url]);
|
|
389
|
+
} else {
|
|
390
|
+
if (!this.executablePath) throw new Error("A compatible system browser is required");
|
|
391
|
+
await this.command(["open", url]);
|
|
392
|
+
}
|
|
393
|
+
const tabs = await this.listTabs();
|
|
394
|
+
const activeTab = tabs.find((tab) => tab.active) || tabs[0];
|
|
395
|
+
if (!activeTab) throw new Error("agent-browser did not create an initial tab");
|
|
396
|
+
this.activeTabId = activeTab.tabId;
|
|
397
|
+
this.streamTabId = activeTab.tabId;
|
|
398
|
+
this.knownTabIds = new Set(tabs.map((tab) => tab.tabId));
|
|
399
|
+
if (!this.externalCdpUrl) {
|
|
400
|
+
for (const tab of tabs) this.ownedTabIds.add(tab.tabId);
|
|
401
|
+
}
|
|
402
|
+
const info = await this.sessionInfo();
|
|
403
|
+
const version = versionFromSessionInfo(info);
|
|
404
|
+
if (version && version !== this.requiredVersion) {
|
|
405
|
+
throw new Error(`agent-browser ${this.requiredVersion} is required, but session uses ${version}`);
|
|
406
|
+
}
|
|
407
|
+
const pid = processIdFromSessionInfo(info);
|
|
408
|
+
if (!pid) throw new Error("agent-browser did not report its daemon process identity");
|
|
409
|
+
const processIdentity = await this.readProcessIdentity(pid);
|
|
410
|
+
if (!processIdentity || processIdentity.processGroupId !== pid) {
|
|
411
|
+
throw new Error("agent-browser daemon process identity could not be verified");
|
|
412
|
+
}
|
|
413
|
+
this.processIdentity = processIdentity;
|
|
414
|
+
this.emit("process-identity", processIdentity);
|
|
415
|
+
let status = commandData(await this.command(["stream", "status"]));
|
|
416
|
+
if (!webSocketPort(status)) {
|
|
417
|
+
try {
|
|
418
|
+
status = commandData(await this.command(["stream", "enable"]));
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (!/already enabled/i.test(errorMessage(error))) throw error;
|
|
421
|
+
status = commandData(await this.command(["stream", "status"]));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const port = webSocketPort(status);
|
|
425
|
+
if (!port) throw new Error("agent-browser stream did not report a loopback port");
|
|
426
|
+
await this.connectStream(`ws://127.0.0.1:${port}`);
|
|
427
|
+
this.started = true;
|
|
428
|
+
const metadata = await this.metadata();
|
|
429
|
+
this.emit("metadata", metadata);
|
|
430
|
+
return metadata;
|
|
431
|
+
} catch (error) {
|
|
432
|
+
try {
|
|
433
|
+
await this.close();
|
|
434
|
+
} catch (cleanupError) {
|
|
435
|
+
throw new Error(
|
|
436
|
+
`${errorMessage(error)}; agent-browser cleanup failed: ${errorMessage(cleanupError)}`,
|
|
437
|
+
{ cause: cleanupError }
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
throw error;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
connectStream(url) {
|
|
444
|
+
return new Promise((resolve, reject) => {
|
|
445
|
+
const socket = this.createWebSocket(url);
|
|
446
|
+
this.stream = socket;
|
|
447
|
+
let settled = false;
|
|
448
|
+
const failStart = (error) => {
|
|
449
|
+
if (settled) return;
|
|
450
|
+
settled = true;
|
|
451
|
+
reject(error instanceof Error ? error : new Error(String(error || "agent-browser stream failed")));
|
|
452
|
+
};
|
|
453
|
+
socket.once("open", () => {
|
|
454
|
+
if (settled) return;
|
|
455
|
+
settled = true;
|
|
456
|
+
this.streamReady = true;
|
|
457
|
+
resolve();
|
|
458
|
+
});
|
|
459
|
+
socket.on("message", (raw) => this.handleStreamMessage(raw));
|
|
460
|
+
socket.once("error", (error) => {
|
|
461
|
+
if (!settled) {
|
|
462
|
+
failStart(error);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (!this.closedByOwner) this.emit("error", error);
|
|
466
|
+
});
|
|
467
|
+
socket.once("close", () => {
|
|
468
|
+
this.streamReady = false;
|
|
469
|
+
if (!settled) {
|
|
470
|
+
failStart(new Error("agent-browser stream closed before it was ready"));
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (!this.closedByOwner) this.emit("exit", "agent-browser stream closed");
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
handleStreamMessage(raw) {
|
|
478
|
+
let message;
|
|
479
|
+
try {
|
|
480
|
+
message = JSON.parse(raw.toString());
|
|
481
|
+
} catch {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (message.type === "frame" && message.data) {
|
|
485
|
+
const metadata = message.metadata || {};
|
|
486
|
+
const width = Number(metadata.deviceWidth) || this.viewport.width;
|
|
487
|
+
const height = Number(metadata.deviceHeight) || this.viewport.height;
|
|
488
|
+
const frame = {
|
|
489
|
+
type: "browser-frame",
|
|
490
|
+
generation: this.generation,
|
|
491
|
+
viewportRevision: this.viewportRevision,
|
|
492
|
+
viewport: { width, height },
|
|
493
|
+
deviceScaleFactor: Number(metadata.pageScaleFactor) || this.viewport.deviceScaleFactor,
|
|
494
|
+
format: "jpeg",
|
|
495
|
+
data: String(message.data),
|
|
496
|
+
metadata
|
|
497
|
+
};
|
|
498
|
+
this.latestFrame = frame;
|
|
499
|
+
this.emit("frame", frame);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (message.type === "tabs") {
|
|
503
|
+
const tabs = normalizedTabs(message.data || message);
|
|
504
|
+
const active = tabs.find((tab) => tab.active) || tabs[0];
|
|
505
|
+
if (active) this.activeTabId = active.tabId;
|
|
506
|
+
const newTabIds = tabs.map((tab) => tab.tabId).filter((tabId) => !this.knownTabIds.has(tabId));
|
|
507
|
+
this.knownTabIds = new Set(tabs.map((tab) => tab.tabId));
|
|
508
|
+
this.emit("tabs", {
|
|
509
|
+
tabs,
|
|
510
|
+
newTabIds,
|
|
511
|
+
popupAdmitted: Date.now() <= this.popupAdmissionUntil
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
sendStream(message) {
|
|
516
|
+
if (!this.stream || !this.streamReady || this.stream.readyState !== WebSocket.OPEN) {
|
|
517
|
+
throw new Error("agent-browser stream is not connected");
|
|
518
|
+
}
|
|
519
|
+
this.stream.send(JSON.stringify(message));
|
|
520
|
+
}
|
|
521
|
+
async metadata() {
|
|
522
|
+
const [urlResult, titleResult] = await Promise.all([
|
|
523
|
+
this.command(["get", "url"]),
|
|
524
|
+
this.command(["get", "title"])
|
|
525
|
+
]);
|
|
526
|
+
return {
|
|
527
|
+
url: String(commandData(urlResult).url || "about:blank"),
|
|
528
|
+
title: String(commandData(titleResult).title || "")
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
async listTabs() {
|
|
532
|
+
return normalizedTabs(commandData(await this.command(["tab", "list"])));
|
|
533
|
+
}
|
|
534
|
+
async createTab(url = "about:blank", label = "") {
|
|
535
|
+
const args = ["tab", "new"];
|
|
536
|
+
if (label) args.push("--label", label);
|
|
537
|
+
args.push(url);
|
|
538
|
+
const created = commandData(await this.command(args));
|
|
539
|
+
const tabs = await this.listTabs();
|
|
540
|
+
const tabId = String(created.tabId || created.id || created.targetId || "").trim();
|
|
541
|
+
const tab = tabs.find((candidate) => candidate.tabId === tabId) || tabs.find((candidate) => candidate.active) || tabs.at(-1);
|
|
542
|
+
if (!tab) throw new Error("agent-browser did not report the new tab");
|
|
543
|
+
this.knownTabIds = new Set(tabs.map((candidate) => candidate.tabId));
|
|
544
|
+
this.ownedTabIds.add(tab.tabId);
|
|
545
|
+
await this.switchTab(tab.tabId);
|
|
546
|
+
return tab;
|
|
547
|
+
}
|
|
548
|
+
async switchTab(tabId) {
|
|
549
|
+
const target = String(tabId || "").trim();
|
|
550
|
+
if (!target) throw new Error("tab id is required");
|
|
551
|
+
await this.command(["tab", target]);
|
|
552
|
+
this.activeTabId = target;
|
|
553
|
+
this.streamTabId = target;
|
|
554
|
+
const tabs = await this.listTabs();
|
|
555
|
+
const tab = tabs.find((candidate) => candidate.tabId === target);
|
|
556
|
+
if (!tab) throw new Error(`Browser tab ${target} is unavailable`);
|
|
557
|
+
this.knownTabIds = new Set(tabs.map((candidate) => candidate.tabId));
|
|
558
|
+
return tab;
|
|
559
|
+
}
|
|
560
|
+
async closeTab(tabId) {
|
|
561
|
+
const target = String(tabId || "").trim();
|
|
562
|
+
if (!target) throw new Error("tab id is required");
|
|
563
|
+
await this.command(["tab", "close", target], { timeoutMs: CLOSE_TIMEOUT_MS });
|
|
564
|
+
this.knownTabIds.delete(target);
|
|
565
|
+
this.ownedTabIds.delete(target);
|
|
566
|
+
const tabs = await this.listTabs();
|
|
567
|
+
const active = tabs.find((tab) => tab.active) || tabs[0];
|
|
568
|
+
this.activeTabId = active?.tabId || "";
|
|
569
|
+
if (this.streamTabId === target) this.streamTabId = "";
|
|
570
|
+
return tabs;
|
|
571
|
+
}
|
|
572
|
+
admitPopup() {
|
|
573
|
+
this.popupAdmissionUntil = Date.now() + 2e3;
|
|
574
|
+
}
|
|
575
|
+
async navigate(url) {
|
|
576
|
+
await this.command(["open", url]);
|
|
577
|
+
const metadata = await this.metadata();
|
|
578
|
+
this.emit("metadata", metadata);
|
|
579
|
+
return metadata;
|
|
580
|
+
}
|
|
581
|
+
async navigationCommand(command) {
|
|
582
|
+
await this.command([command]);
|
|
583
|
+
const metadata = await this.metadata();
|
|
584
|
+
this.emit("metadata", metadata);
|
|
585
|
+
return metadata;
|
|
586
|
+
}
|
|
587
|
+
goBack() {
|
|
588
|
+
return this.navigationCommand("back");
|
|
589
|
+
}
|
|
590
|
+
goForward() {
|
|
591
|
+
return this.navigationCommand("forward");
|
|
592
|
+
}
|
|
593
|
+
reload() {
|
|
594
|
+
return this.navigationCommand("reload");
|
|
595
|
+
}
|
|
596
|
+
async snapshot() {
|
|
597
|
+
const data = commandData(await this.command(["snapshot"]));
|
|
598
|
+
const metadata = await this.metadata();
|
|
599
|
+
return {
|
|
600
|
+
...metadata,
|
|
601
|
+
elements: snapshotElements(data.refs),
|
|
602
|
+
accessibilityTree: String(data.snapshot || ""),
|
|
603
|
+
origin: String(data.origin || "")
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
async screenshot() {
|
|
607
|
+
const operation = async () => {
|
|
608
|
+
const output = path.join(
|
|
609
|
+
path.dirname(this.profileDir),
|
|
610
|
+
`screenshot-${this.generation}-${crypto.randomUUID()}.png`
|
|
611
|
+
);
|
|
612
|
+
const data = commandData(await this.command(["screenshot", output]));
|
|
613
|
+
const resolved = path.resolve(String(data.path || output));
|
|
614
|
+
const resourceDir = path.resolve(path.dirname(this.profileDir));
|
|
615
|
+
if (resolved !== path.resolve(output) && !resolved.startsWith(`${resourceDir}${path.sep}`)) {
|
|
616
|
+
throw new Error("agent-browser returned an unsafe screenshot path");
|
|
617
|
+
}
|
|
618
|
+
try {
|
|
619
|
+
return { mimeType: "image/png", data: fs.readFileSync(resolved).toString("base64") };
|
|
620
|
+
} finally {
|
|
621
|
+
fs.rmSync(resolved, { force: true });
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
const next = this.screenshotChain.catch(() => {
|
|
625
|
+
}).then(operation);
|
|
626
|
+
this.screenshotChain = next;
|
|
627
|
+
return next;
|
|
628
|
+
}
|
|
629
|
+
async click(input) {
|
|
630
|
+
this.admitPopup();
|
|
631
|
+
await this.command(["click", normalizeRef(input)]);
|
|
632
|
+
return { ok: true };
|
|
633
|
+
}
|
|
634
|
+
async elementAction(kind, input) {
|
|
635
|
+
const command = oneOf(
|
|
636
|
+
kind,
|
|
637
|
+
["dblclick", "hover", "focus", "check", "uncheck", "scrollintoview", "highlight"],
|
|
638
|
+
"element action"
|
|
639
|
+
);
|
|
640
|
+
const result = await this.command([command, normalizeRef(input)]);
|
|
641
|
+
return publicCommandData(result);
|
|
642
|
+
}
|
|
643
|
+
async type(input, clear) {
|
|
644
|
+
const action = clear ? "fill" : "type";
|
|
645
|
+
await this.command([action, normalizeRef(input), String(input.text ?? "")]);
|
|
646
|
+
return { ok: true };
|
|
647
|
+
}
|
|
648
|
+
async keyboard(input) {
|
|
649
|
+
const mode = oneOf(input?.mode, ["type", "inserttext"], "keyboard mode");
|
|
650
|
+
const text = String(input?.text ?? "");
|
|
651
|
+
const result = await this.command(["keyboard", mode, text]);
|
|
652
|
+
return publicCommandData(result);
|
|
653
|
+
}
|
|
654
|
+
async select(input) {
|
|
655
|
+
const values = Array.isArray(input?.values) ? input.values.map((value) => String(value)) : [String(input?.value ?? "")];
|
|
656
|
+
if (values.length === 0 || values.some((value) => !value)) {
|
|
657
|
+
throw new Error("at least one select value is required");
|
|
658
|
+
}
|
|
659
|
+
const result = await this.command(["select", normalizeRef(input), ...values]);
|
|
660
|
+
return publicCommandData(result);
|
|
661
|
+
}
|
|
662
|
+
async drag(input) {
|
|
663
|
+
const source = normalizeRef({
|
|
664
|
+
ref: input?.sourceRef,
|
|
665
|
+
selector: input?.sourceSelector
|
|
666
|
+
});
|
|
667
|
+
const target = normalizeRef({
|
|
668
|
+
ref: input?.targetRef,
|
|
669
|
+
selector: input?.targetSelector
|
|
670
|
+
});
|
|
671
|
+
const result = await this.command(["drag", source, target]);
|
|
672
|
+
return publicCommandData(result);
|
|
673
|
+
}
|
|
674
|
+
async upload(input) {
|
|
675
|
+
const files = Array.isArray(input?.files) ? input.files.map((file) => String(file)) : [];
|
|
676
|
+
if (files.length === 0) throw new Error("at least one upload file is required");
|
|
677
|
+
const result = await this.command(["upload", normalizeRef(input), ...files], {
|
|
678
|
+
timeoutMs: normalizeTimeoutMs(input?.timeoutMs)
|
|
679
|
+
});
|
|
680
|
+
return publicCommandData(result);
|
|
681
|
+
}
|
|
682
|
+
async download(input) {
|
|
683
|
+
const outputPath = requiredText(input?.outputPath, "download output path");
|
|
684
|
+
const timeoutMs = normalizeTimeoutMs(input?.timeoutMs);
|
|
685
|
+
const result = await this.command([
|
|
686
|
+
"download",
|
|
687
|
+
normalizeRef(input),
|
|
688
|
+
outputPath,
|
|
689
|
+
"--timeout",
|
|
690
|
+
String(timeoutMs)
|
|
691
|
+
], {
|
|
692
|
+
timeoutMs: timeoutMs + 5e3
|
|
693
|
+
});
|
|
694
|
+
return publicCommandData(result);
|
|
695
|
+
}
|
|
696
|
+
async waitFor(input) {
|
|
697
|
+
const mode = oneOf(
|
|
698
|
+
input?.mode || "selector",
|
|
699
|
+
["selector", "time", "url", "load", "function", "text"],
|
|
700
|
+
"wait mode"
|
|
701
|
+
);
|
|
702
|
+
const args = ["wait"];
|
|
703
|
+
if (mode === "selector") {
|
|
704
|
+
args.push(normalizeRef(input));
|
|
705
|
+
if (input?.state) {
|
|
706
|
+
args.push("--state", oneOf(
|
|
707
|
+
input.state,
|
|
708
|
+
["visible", "hidden", "attached", "detached"],
|
|
709
|
+
"wait state"
|
|
710
|
+
));
|
|
711
|
+
}
|
|
712
|
+
} else if (mode === "time") {
|
|
713
|
+
const durationMs = normalizeTimeoutMs(input?.durationMs, 1e3);
|
|
714
|
+
args.push(String(durationMs));
|
|
715
|
+
} else {
|
|
716
|
+
const option = mode === "function" ? "fn" : mode;
|
|
717
|
+
const value = mode === "load" ? oneOf(input?.value, ["load", "domcontentloaded", "networkidle"], "load state") : requiredText(input?.value, `${mode} wait value`, mode === "function" ? MAX_SCRIPT_LENGTH : 1e4);
|
|
718
|
+
args.push(`--${option}`, value);
|
|
719
|
+
}
|
|
720
|
+
const timeoutMs = normalizeTimeoutMs(input?.timeoutMs);
|
|
721
|
+
args.push("--timeout", String(timeoutMs));
|
|
722
|
+
const result = await this.command(args, {
|
|
723
|
+
timeoutMs: timeoutMs + 5e3
|
|
724
|
+
});
|
|
725
|
+
return publicCommandData(result);
|
|
726
|
+
}
|
|
727
|
+
async get(input) {
|
|
728
|
+
const what = oneOf(
|
|
729
|
+
input?.what,
|
|
730
|
+
["text", "html", "value", "attr", "title", "url", "count", "box", "styles"],
|
|
731
|
+
"get type"
|
|
732
|
+
);
|
|
733
|
+
const args = ["get", what];
|
|
734
|
+
if (!["title", "url"].includes(what)) args.push(normalizeRef(input));
|
|
735
|
+
if (what === "attr") args.push(requiredText(input?.attribute, "attribute name", 256));
|
|
736
|
+
return publicCommandData(await this.command(args));
|
|
737
|
+
}
|
|
738
|
+
async is(input) {
|
|
739
|
+
const state = oneOf(input?.state, ["visible", "enabled", "checked"], "element state");
|
|
740
|
+
return publicCommandData(await this.command(["is", state, normalizeRef(input)]));
|
|
741
|
+
}
|
|
742
|
+
async find(input) {
|
|
743
|
+
const locator = oneOf(
|
|
744
|
+
input?.locator,
|
|
745
|
+
["role", "text", "label", "placeholder", "alt", "title", "testid", "first", "last", "nth"],
|
|
746
|
+
"find locator"
|
|
747
|
+
);
|
|
748
|
+
const action = oneOf(
|
|
749
|
+
input?.action || "click",
|
|
750
|
+
["click", "fill", "type", "hover", "focus", "check", "uncheck"],
|
|
751
|
+
"find action"
|
|
752
|
+
);
|
|
753
|
+
const args = ["find", locator];
|
|
754
|
+
if (locator === "nth") {
|
|
755
|
+
const index = Number(input?.index);
|
|
756
|
+
if (!Number.isSafeInteger(index) || index < 0) throw new Error("find index must be a non-negative integer");
|
|
757
|
+
args.push(String(index), requiredText(input?.value, "find selector"));
|
|
758
|
+
} else {
|
|
759
|
+
args.push(requiredText(input?.value, "find value"));
|
|
760
|
+
}
|
|
761
|
+
args.push(action);
|
|
762
|
+
if (["fill", "type"].includes(action)) args.push(String(input?.text ?? ""));
|
|
763
|
+
if (input?.name) args.push("--name", String(input.name));
|
|
764
|
+
if (input?.exact === true) args.push("--exact");
|
|
765
|
+
const result = await this.command(args);
|
|
766
|
+
return publicCommandData(result);
|
|
767
|
+
}
|
|
768
|
+
async evaluate(input) {
|
|
769
|
+
const expression = requiredText(input?.expression, "JavaScript expression", MAX_SCRIPT_LENGTH);
|
|
770
|
+
const encoded = Buffer.from(expression).toString("base64");
|
|
771
|
+
return publicCommandData(await this.command(["eval", "--base64", encoded]));
|
|
772
|
+
}
|
|
773
|
+
async debugLog(kind, input) {
|
|
774
|
+
const command = oneOf(kind, ["console", "errors"], "debug log");
|
|
775
|
+
const args = [command];
|
|
776
|
+
if (input?.clear === true) args.push("--clear");
|
|
777
|
+
return publicCommandData(await this.command(args));
|
|
778
|
+
}
|
|
779
|
+
async network(input) {
|
|
780
|
+
const operation = oneOf(input?.operation || "requests", ["requests", "request"], "network operation");
|
|
781
|
+
if (operation === "request") {
|
|
782
|
+
return publicCommandData(await this.command([
|
|
783
|
+
"network",
|
|
784
|
+
"request",
|
|
785
|
+
requiredText(input?.requestId, "request id", 256)
|
|
786
|
+
]));
|
|
787
|
+
}
|
|
788
|
+
const args = ["network", "requests"];
|
|
789
|
+
if (input?.clear === true) args.push("--clear");
|
|
790
|
+
for (const [key, flag] of [
|
|
791
|
+
["filter", "--filter"],
|
|
792
|
+
["resourceType", "--type"],
|
|
793
|
+
["method", "--method"],
|
|
794
|
+
["status", "--status"]
|
|
795
|
+
]) {
|
|
796
|
+
if (input?.[key] !== void 0 && input[key] !== "") {
|
|
797
|
+
args.push(flag, String(input[key]));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return publicCommandData(await this.command(args));
|
|
801
|
+
}
|
|
802
|
+
async cookies(input) {
|
|
803
|
+
const operation = oneOf(input?.operation || "get", ["get", "set", "clear"], "cookie operation");
|
|
804
|
+
const args = ["cookies", operation];
|
|
805
|
+
if (operation === "set") {
|
|
806
|
+
args.push(
|
|
807
|
+
requiredText(input?.name, "cookie name", 1024),
|
|
808
|
+
String(input?.value ?? "")
|
|
809
|
+
);
|
|
810
|
+
for (const [key, flag] of [
|
|
811
|
+
["url", "--url"],
|
|
812
|
+
["domain", "--domain"],
|
|
813
|
+
["path", "--path"],
|
|
814
|
+
["sameSite", "--sameSite"],
|
|
815
|
+
["expires", "--expires"]
|
|
816
|
+
]) {
|
|
817
|
+
if (input?.[key] !== void 0 && input[key] !== "") {
|
|
818
|
+
args.push(flag, String(input[key]));
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (input?.httpOnly === true) args.push("--httpOnly");
|
|
822
|
+
if (input?.secure === true) args.push("--secure");
|
|
823
|
+
}
|
|
824
|
+
const result = await this.command(args);
|
|
825
|
+
return publicCommandData(result);
|
|
826
|
+
}
|
|
827
|
+
async storage(input) {
|
|
828
|
+
const storageType = oneOf(input?.storageType, ["local", "session"], "storage type");
|
|
829
|
+
const operation = oneOf(input?.operation || "get", ["get", "set", "clear"], "storage operation");
|
|
830
|
+
const args = ["storage", storageType, operation];
|
|
831
|
+
if (operation === "get" && input?.key) args.push(String(input.key));
|
|
832
|
+
if (operation === "set") {
|
|
833
|
+
args.push(requiredText(input?.key, "storage key", 1e4), String(input?.value ?? ""));
|
|
834
|
+
}
|
|
835
|
+
const result = await this.command(args);
|
|
836
|
+
return publicCommandData(result);
|
|
837
|
+
}
|
|
838
|
+
async frame(input) {
|
|
839
|
+
const target = input?.main === true ? "main" : normalizeRef(input);
|
|
840
|
+
return publicCommandData(await this.command(["frame", target]));
|
|
841
|
+
}
|
|
842
|
+
async dialog(input) {
|
|
843
|
+
const operation = oneOf(input?.operation || "status", ["status", "accept", "dismiss"], "dialog operation");
|
|
844
|
+
const args = ["dialog", operation];
|
|
845
|
+
if (operation === "accept" && input?.text !== void 0) args.push(String(input.text));
|
|
846
|
+
const result = await this.command(args);
|
|
847
|
+
return publicCommandData(result);
|
|
848
|
+
}
|
|
849
|
+
async press(input) {
|
|
850
|
+
if (input?.type === "key") {
|
|
851
|
+
const key2 = String(input.key || "");
|
|
852
|
+
if (!key2) throw new Error("key is required");
|
|
853
|
+
const code = String(input.code || "");
|
|
854
|
+
const windowsVirtualKeyCode = keyCodeFor(key2);
|
|
855
|
+
const common = {
|
|
856
|
+
key: key2,
|
|
857
|
+
code,
|
|
858
|
+
modifiers: Number(input.modifiers) || 0,
|
|
859
|
+
windowsVirtualKeyCode
|
|
860
|
+
};
|
|
861
|
+
this.sendStream({ type: "input_keyboard", eventType: "keyDown", ...common });
|
|
862
|
+
this.sendStream({ type: "input_keyboard", eventType: "keyUp", ...common });
|
|
863
|
+
return { ok: true };
|
|
864
|
+
}
|
|
865
|
+
const key = String(input?.key || "").trim();
|
|
866
|
+
if (!key) throw new Error("key is required");
|
|
867
|
+
await this.command(["press", key]);
|
|
868
|
+
return { ok: true };
|
|
869
|
+
}
|
|
870
|
+
async resize(value) {
|
|
871
|
+
const next = clampViewport(value);
|
|
872
|
+
if (next.width === this.viewport.width && next.height === this.viewport.height && next.deviceScaleFactor === this.viewport.deviceScaleFactor) return this.viewport;
|
|
873
|
+
await this.command([
|
|
874
|
+
"set",
|
|
875
|
+
"viewport",
|
|
876
|
+
String(next.width),
|
|
877
|
+
String(next.height),
|
|
878
|
+
String(next.deviceScaleFactor)
|
|
879
|
+
]);
|
|
880
|
+
this.viewport = next;
|
|
881
|
+
this.viewportRevision += 1;
|
|
882
|
+
return this.viewport;
|
|
883
|
+
}
|
|
884
|
+
async pointer(input) {
|
|
885
|
+
const x = Number(input.x);
|
|
886
|
+
const y = Number(input.y);
|
|
887
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return;
|
|
888
|
+
const eventTypes = {
|
|
889
|
+
move: "mouseMoved",
|
|
890
|
+
down: "mousePressed",
|
|
891
|
+
up: "mouseReleased"
|
|
892
|
+
};
|
|
893
|
+
const action = String(input.action || "");
|
|
894
|
+
const eventType = eventTypes[action];
|
|
895
|
+
if (!eventType) return;
|
|
896
|
+
if (action === "down") this.admitPopup();
|
|
897
|
+
this.sendStream({
|
|
898
|
+
type: "input_mouse",
|
|
899
|
+
eventType,
|
|
900
|
+
x,
|
|
901
|
+
y,
|
|
902
|
+
button: action === "move" ? "none" : input.button || "left",
|
|
903
|
+
clickCount: action === "move" ? 0 : 1,
|
|
904
|
+
modifiers: Number(input.modifiers) || 0
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
async wheel(input) {
|
|
908
|
+
const x = Number(input.x);
|
|
909
|
+
const y = Number(input.y);
|
|
910
|
+
this.sendStream({
|
|
911
|
+
type: "input_mouse",
|
|
912
|
+
eventType: "mouseWheel",
|
|
913
|
+
x: Number.isFinite(x) ? x : this.viewport.width / 2,
|
|
914
|
+
y: Number.isFinite(y) ? y : this.viewport.height / 2,
|
|
915
|
+
deltaX: Number(input.deltaX) || 0,
|
|
916
|
+
deltaY: Number(input.deltaY) || 0,
|
|
917
|
+
modifiers: Number(input.modifiers) || 0
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
async insertText(text) {
|
|
921
|
+
const value = String(text || "");
|
|
922
|
+
if (/[^\x20-\x7e]/.test(value)) {
|
|
923
|
+
await this.command(["keyboard", "inserttext", value]);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
for (const key of value) {
|
|
927
|
+
const common = {
|
|
928
|
+
key,
|
|
929
|
+
code: "",
|
|
930
|
+
windowsVirtualKeyCode: keyCodeFor(key),
|
|
931
|
+
modifiers: 0
|
|
932
|
+
};
|
|
933
|
+
this.sendStream({
|
|
934
|
+
type: "input_keyboard",
|
|
935
|
+
eventType: "keyDown",
|
|
936
|
+
...common,
|
|
937
|
+
text: key
|
|
938
|
+
});
|
|
939
|
+
this.sendStream({
|
|
940
|
+
type: "input_keyboard",
|
|
941
|
+
eventType: "keyUp",
|
|
942
|
+
...common
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
async closeOwnedExternalTabs() {
|
|
947
|
+
for (const tabId of [...this.ownedTabIds]) {
|
|
948
|
+
try {
|
|
949
|
+
await this.command(["tab", "close", tabId], { timeoutMs: CLOSE_TIMEOUT_MS });
|
|
950
|
+
this.ownedTabIds.delete(tabId);
|
|
951
|
+
} catch (error) {
|
|
952
|
+
const tabs = await this.listTabs();
|
|
953
|
+
if (tabs.some((tab) => tab.tabId === tabId)) throw error;
|
|
954
|
+
this.ownedTabIds.delete(tabId);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
async closeSession() {
|
|
959
|
+
const info = await this.sessionInfo();
|
|
960
|
+
if (info.active === false) return;
|
|
961
|
+
if (!this.processIdentity) {
|
|
962
|
+
const pid = processIdFromSessionInfo(info);
|
|
963
|
+
if (pid) this.processIdentity = await this.readProcessIdentity(pid);
|
|
964
|
+
}
|
|
965
|
+
if (this.connectedCdp) {
|
|
966
|
+
await this.closeOwnedExternalTabs();
|
|
967
|
+
}
|
|
968
|
+
let closeError = null;
|
|
969
|
+
try {
|
|
970
|
+
await this.command(["close"], { timeoutMs: CLOSE_TIMEOUT_MS });
|
|
971
|
+
} catch (error) {
|
|
972
|
+
if (!this.processIdentity || (0, import_server_process_identity.matchingProcessIdentity)(
|
|
973
|
+
this.processIdentity,
|
|
974
|
+
await this.readProcessIdentity(this.processIdentity.pid)
|
|
975
|
+
)) {
|
|
976
|
+
closeError ||= error;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
if (closeError) throw closeError;
|
|
980
|
+
}
|
|
981
|
+
async close() {
|
|
982
|
+
if (this.closeComplete) return;
|
|
983
|
+
if (this.closePromise) return this.closePromise;
|
|
984
|
+
this.closedByOwner = true;
|
|
985
|
+
this.closePromise = (async () => {
|
|
986
|
+
if (this.stream) {
|
|
987
|
+
this.stream.removeAllListeners();
|
|
988
|
+
this.stream.close();
|
|
989
|
+
this.stream = null;
|
|
990
|
+
this.streamReady = false;
|
|
991
|
+
}
|
|
992
|
+
const cleanupErrors = [];
|
|
993
|
+
try {
|
|
994
|
+
await this.closeSession();
|
|
995
|
+
const processIdentity = this.processIdentity;
|
|
996
|
+
if (!await waitForIdentityExit(processIdentity, {
|
|
997
|
+
readProcessIdentity: this.readProcessIdentity,
|
|
998
|
+
wait: this.wait
|
|
999
|
+
})) {
|
|
1000
|
+
throw new Error(`agent-browser daemon ${processIdentity?.pid || "unknown"} did not exit`);
|
|
1001
|
+
}
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
cleanupErrors.push(error);
|
|
1004
|
+
}
|
|
1005
|
+
if (cleanupErrors.length) {
|
|
1006
|
+
throw new Error(cleanupErrors.map(errorMessage).join("; "), {
|
|
1007
|
+
cause: cleanupErrors[0]
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
this.closeComplete = true;
|
|
1011
|
+
})().finally(() => {
|
|
1012
|
+
this.closePromise = null;
|
|
1013
|
+
});
|
|
1014
|
+
return this.closePromise;
|
|
1015
|
+
}
|
|
1016
|
+
static async recover(options) {
|
|
1017
|
+
const runtime = new AgentBrowserRuntime({
|
|
1018
|
+
...options,
|
|
1019
|
+
id: options.id,
|
|
1020
|
+
generation: options.generation,
|
|
1021
|
+
externalCdpUrl: "recovery"
|
|
1022
|
+
});
|
|
1023
|
+
runtime.processIdentity = options.processIdentity || null;
|
|
1024
|
+
runtime.connectedCdp = true;
|
|
1025
|
+
runtime.closedByOwner = true;
|
|
1026
|
+
await runtime.close();
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1030
|
+
0 && (module.exports = {
|
|
1031
|
+
AGENT_BROWSER_VERSION,
|
|
1032
|
+
AgentBrowserRuntime,
|
|
1033
|
+
DEFAULT_VIEWPORT,
|
|
1034
|
+
clampViewport,
|
|
1035
|
+
defaultRunCommand,
|
|
1036
|
+
externalTabLabel,
|
|
1037
|
+
namespaceForResource,
|
|
1038
|
+
sessionForResource,
|
|
1039
|
+
waitForIdentityExit
|
|
1040
|
+
});
|