gologin-agent-browser-cli 0.1.0

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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +220 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +352 -0
  5. package/dist/commands/check.d.ts +2 -0
  6. package/dist/commands/check.js +17 -0
  7. package/dist/commands/click.d.ts +2 -0
  8. package/dist/commands/click.js +17 -0
  9. package/dist/commands/close.d.ts +2 -0
  10. package/dist/commands/close.js +12 -0
  11. package/dist/commands/current.d.ts +2 -0
  12. package/dist/commands/current.js +9 -0
  13. package/dist/commands/dblclick.d.ts +2 -0
  14. package/dist/commands/dblclick.js +17 -0
  15. package/dist/commands/fill.d.ts +2 -0
  16. package/dist/commands/fill.js +18 -0
  17. package/dist/commands/find.d.ts +2 -0
  18. package/dist/commands/find.js +86 -0
  19. package/dist/commands/focus.d.ts +2 -0
  20. package/dist/commands/focus.js +17 -0
  21. package/dist/commands/get.d.ts +2 -0
  22. package/dist/commands/get.js +19 -0
  23. package/dist/commands/hover.d.ts +2 -0
  24. package/dist/commands/hover.js +17 -0
  25. package/dist/commands/open.d.ts +2 -0
  26. package/dist/commands/open.js +67 -0
  27. package/dist/commands/pdf.d.ts +2 -0
  28. package/dist/commands/pdf.js +18 -0
  29. package/dist/commands/press.d.ts +2 -0
  30. package/dist/commands/press.js +19 -0
  31. package/dist/commands/screenshot.d.ts +2 -0
  32. package/dist/commands/screenshot.js +20 -0
  33. package/dist/commands/scroll.d.ts +2 -0
  34. package/dist/commands/scroll.js +25 -0
  35. package/dist/commands/scrollIntoView.d.ts +2 -0
  36. package/dist/commands/scrollIntoView.js +17 -0
  37. package/dist/commands/select.d.ts +2 -0
  38. package/dist/commands/select.js +18 -0
  39. package/dist/commands/sessions.d.ts +2 -0
  40. package/dist/commands/sessions.js +15 -0
  41. package/dist/commands/shared.d.ts +3 -0
  42. package/dist/commands/shared.js +13 -0
  43. package/dist/commands/snapshot.d.ts +2 -0
  44. package/dist/commands/snapshot.js +16 -0
  45. package/dist/commands/type.d.ts +2 -0
  46. package/dist/commands/type.js +18 -0
  47. package/dist/commands/uncheck.d.ts +2 -0
  48. package/dist/commands/uncheck.js +17 -0
  49. package/dist/commands/upload.d.ts +2 -0
  50. package/dist/commands/upload.js +18 -0
  51. package/dist/commands/wait.d.ts +2 -0
  52. package/dist/commands/wait.js +41 -0
  53. package/dist/daemon/browser.d.ts +37 -0
  54. package/dist/daemon/browser.js +557 -0
  55. package/dist/daemon/refStore.d.ts +9 -0
  56. package/dist/daemon/refStore.js +26 -0
  57. package/dist/daemon/server.d.ts +1 -0
  58. package/dist/daemon/server.js +235 -0
  59. package/dist/daemon/sessionManager.d.ts +50 -0
  60. package/dist/daemon/sessionManager.js +512 -0
  61. package/dist/daemon/snapshot.d.ts +8 -0
  62. package/dist/daemon/snapshot.js +285 -0
  63. package/dist/lib/config.d.ts +3 -0
  64. package/dist/lib/config.js +58 -0
  65. package/dist/lib/errors.d.ts +12 -0
  66. package/dist/lib/errors.js +63 -0
  67. package/dist/lib/types.d.ts +301 -0
  68. package/dist/lib/types.js +2 -0
  69. package/dist/lib/utils.d.ts +27 -0
  70. package/dist/lib/utils.js +165 -0
  71. package/examples/agent-flow.sh +19 -0
  72. package/package.json +59 -0
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runDoubleClickCommand = runDoubleClickCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runDoubleClickCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ if (!target) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser dblclick <target> [--session <sessionId>]", 400);
13
+ }
14
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
15
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/dblclick`, { target });
16
+ (0, shared_1.writeActionResult)(context, "double-clicked", target, response);
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runFillCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runFillCommand = runFillCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runFillCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const text = parsed.positional.slice(1).join(" ");
11
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
12
+ if (!target || !text) {
13
+ throw new errors_1.AppError("BAD_REQUEST", 'Usage: gologin-agent-browser fill <target> <text> [--session <sessionId>]', 400);
14
+ }
15
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
16
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/fill`, { target, text });
17
+ (0, shared_1.writeActionResult)(context, "filled", target, response);
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runFindCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runFindCommand = runFindCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ const ACTIONS = new Set(["click", "fill", "type", "hover", "text"]);
8
+ function parseFindLocator(positional) {
9
+ const mode = positional[0];
10
+ if (mode === "role") {
11
+ const role = positional[1];
12
+ const action = positional[2];
13
+ const value = positional.slice(3).join(" ") || undefined;
14
+ if (!role || !action || !ACTIONS.has(action)) {
15
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser find role <role> <action> [value] [--name <name>]", 400);
16
+ }
17
+ return { locator: { strategy: "role", role }, action, value };
18
+ }
19
+ if (mode === "text") {
20
+ const text = positional[1];
21
+ const action = positional[2];
22
+ const value = positional.slice(3).join(" ") || undefined;
23
+ if (!text || !action || !ACTIONS.has(action)) {
24
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser find text <text> <action> [value]", 400);
25
+ }
26
+ return { locator: { strategy: "text", text }, action, value };
27
+ }
28
+ if (mode === "label") {
29
+ const label = positional[1];
30
+ const action = positional[2];
31
+ const value = positional.slice(3).join(" ") || undefined;
32
+ if (!label || !action || !ACTIONS.has(action)) {
33
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser find label <label> <action> [value]", 400);
34
+ }
35
+ return { locator: { strategy: "label", label }, action, value };
36
+ }
37
+ if (mode === "placeholder") {
38
+ const placeholder = positional[1];
39
+ const action = positional[2];
40
+ const value = positional.slice(3).join(" ") || undefined;
41
+ if (!placeholder || !action || !ACTIONS.has(action)) {
42
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser find placeholder <placeholder> <action> [value]", 400);
43
+ }
44
+ return { locator: { strategy: "placeholder", placeholder }, action, value };
45
+ }
46
+ if (mode === "first" || mode === "last") {
47
+ const selector = positional[1];
48
+ const action = positional[2];
49
+ const value = positional.slice(3).join(" ") || undefined;
50
+ if (!selector || !action || !ACTIONS.has(action)) {
51
+ throw new errors_1.AppError("BAD_REQUEST", `Usage: gologin-agent-browser find ${mode} <selector> <action> [value]`, 400);
52
+ }
53
+ return { locator: { strategy: mode, selector }, action, value };
54
+ }
55
+ if (mode === "nth") {
56
+ const nth = positional[1];
57
+ const selector = positional[2];
58
+ const action = positional[3];
59
+ const value = positional.slice(4).join(" ") || undefined;
60
+ if (!nth || !selector || !action || !ACTIONS.has(action) || Number.isNaN(Number(nth))) {
61
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser find nth <n> <selector> <action> [value]", 400);
62
+ }
63
+ return { locator: { strategy: "nth", selector, nth: Number(nth) }, action, value };
64
+ }
65
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser find <role|text|label|placeholder|first|last|nth> ...", 400);
66
+ }
67
+ async function runFindCommand(context, argv) {
68
+ const parsed = (0, utils_1.parseArgs)(argv);
69
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
70
+ const name = (0, utils_1.getFlagString)(parsed, "name");
71
+ const exact = (0, utils_1.getFlagBoolean)(parsed, "exact");
72
+ const { locator, action, value } = parseFindLocator(parsed.positional);
73
+ if (locator.strategy === "role" && name) {
74
+ locator.name = name;
75
+ }
76
+ if (exact) {
77
+ locator.exact = true;
78
+ }
79
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
80
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/find`, { locator, action, value });
81
+ if (action === "text") {
82
+ context.stdout.write(`${response.value ?? ""}\n`);
83
+ return;
84
+ }
85
+ context.stdout.write(`find ${action} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
86
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runFocusCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runFocusCommand = runFocusCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runFocusCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ if (!target) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser focus <target> [--session <sessionId>]", 400);
13
+ }
14
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
15
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/focus`, { target });
16
+ (0, shared_1.writeActionResult)(context, "focused", target, response);
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runGetCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runGetCommand = runGetCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ const GET_KINDS = new Set(["text", "value", "html", "title", "url"]);
8
+ async function runGetCommand(context, argv) {
9
+ const parsed = (0, utils_1.parseArgs)(argv);
10
+ const kind = parsed.positional[0];
11
+ const target = parsed.positional[1];
12
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
13
+ if (!kind || !GET_KINDS.has(kind)) {
14
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser get <text|value|html|title|url> [target] [--session <sessionId>]", 400);
15
+ }
16
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
17
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/get`, { kind, target });
18
+ context.stdout.write(`${response.value}\n`);
19
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runHoverCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runHoverCommand = runHoverCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runHoverCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ if (!target) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser hover <target> [--session <sessionId>]", 400);
13
+ }
14
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
15
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/hover`, { target });
16
+ (0, shared_1.writeActionResult)(context, "hovered", target, response);
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runOpenCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runOpenCommand = runOpenCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ function parseIdleTimeout(value) {
7
+ if (!value) {
8
+ return undefined;
9
+ }
10
+ const timeout = Number(value);
11
+ if (!Number.isInteger(timeout) || timeout <= 0) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "--idle-timeout-ms must be a positive integer", 400);
13
+ }
14
+ return timeout;
15
+ }
16
+ function parseProxy(parsed) {
17
+ const country = (0, utils_1.getFlagString)(parsed, "proxy-country");
18
+ const mode = (0, utils_1.getFlagString)(parsed, "proxy-mode");
19
+ const host = (0, utils_1.getFlagString)(parsed, "proxy-host");
20
+ const portRaw = (0, utils_1.getFlagString)(parsed, "proxy-port");
21
+ const username = (0, utils_1.getFlagString)(parsed, "proxy-user");
22
+ const password = (0, utils_1.getFlagString)(parsed, "proxy-pass");
23
+ if (country) {
24
+ throw new errors_1.AppError("BAD_REQUEST", "--proxy-country is not available for temporary cloud profiles yet; use a preconfigured --profile or a custom proxy host/port", 400);
25
+ }
26
+ if (host || portRaw || username || password || mode) {
27
+ const port = Number(portRaw);
28
+ if (!host || !portRaw || !Number.isInteger(port) || port <= 0) {
29
+ throw new errors_1.AppError("BAD_REQUEST", "Custom proxy requires --proxy-host and a valid --proxy-port", 400);
30
+ }
31
+ const resolvedMode = mode ?? "http";
32
+ if (!["http", "socks4", "socks5"].includes(resolvedMode)) {
33
+ throw new errors_1.AppError("BAD_REQUEST", "--proxy-mode must be one of http, socks4, or socks5", 400);
34
+ }
35
+ return {
36
+ mode: resolvedMode,
37
+ host,
38
+ port,
39
+ username,
40
+ password
41
+ };
42
+ }
43
+ return undefined;
44
+ }
45
+ async function runOpenCommand(context, argv) {
46
+ const parsed = (0, utils_1.parseArgs)(argv);
47
+ const url = parsed.positional[0];
48
+ const profileId = (0, utils_1.getFlagString)(parsed, "profile");
49
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
50
+ const proxy = parseProxy(parsed);
51
+ const idleTimeoutMs = parseIdleTimeout((0, utils_1.getFlagString)(parsed, "idle-timeout-ms"));
52
+ if (!url) {
53
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser open <url> [--profile <profileId>] [--session <sessionId>] [--idle-timeout-ms <ms>] [--proxy-host <host> --proxy-port <port>]", 400);
54
+ }
55
+ const response = await context.client.request("POST", "/sessions/open", {
56
+ url,
57
+ profileId,
58
+ sessionId,
59
+ proxy,
60
+ idleTimeoutMs
61
+ });
62
+ const proxyLabel = (0, utils_1.formatProxyLabel)(response.proxy);
63
+ const proxyToken = proxyLabel ? ` proxy=${proxyLabel}` : "";
64
+ const liveView = response.liveViewUrl ? ` liveview=${response.liveViewUrl}` : "";
65
+ const idleTimeout = response.idleTimeoutMs !== undefined ? ` idleTimeoutMs=${response.idleTimeoutMs}` : "";
66
+ context.stdout.write(`session=${response.sessionId} url=${response.url}${proxyToken}${idleTimeout}${liveView}\n`);
67
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runPdfCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPdfCommand = runPdfCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runPdfCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const inputPath = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ if (!inputPath) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser pdf <path> [--session <sessionId>]", 400);
13
+ }
14
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
15
+ const path = (0, utils_1.ensureAbsolutePath)(context.cwd, inputPath);
16
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/pdf`, { path });
17
+ context.stdout.write(`pdf=${response.path} session=${response.sessionId}\n`);
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runPressCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPressCommand = runPressCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runPressCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const key = parsed.positional[0];
10
+ const target = parsed.positional[1];
11
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
12
+ if (!key) {
13
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser press <key> [target] [--session <sessionId>]", 400);
14
+ }
15
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
16
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/press`, { key, target });
17
+ const targetSuffix = target ? ` target=${target}` : "";
18
+ context.stdout.write(`pressed key=${key}${targetSuffix} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
19
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runScreenshotCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runScreenshotCommand = runScreenshotCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runScreenshotCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const inputPath = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ const annotate = (0, utils_1.getFlagBoolean)(parsed, "annotate");
12
+ if (!inputPath) {
13
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser screenshot <path> [--session <sessionId>]", 400);
14
+ }
15
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
16
+ const targetPath = (0, utils_1.ensureAbsolutePath)(context.cwd, inputPath);
17
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/screenshot`, { path: targetPath, annotate });
18
+ const annotated = response.annotated ? " annotated=yes" : "";
19
+ context.stdout.write(`screenshot=${response.path} session=${response.sessionId}${annotated}\n`);
20
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runScrollCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runScrollCommand = runScrollCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ const SCROLL_DIRECTIONS = new Set(["up", "down", "left", "right"]);
8
+ async function runScrollCommand(context, argv) {
9
+ const parsed = (0, utils_1.parseArgs)(argv);
10
+ const direction = parsed.positional[0];
11
+ const maybePixels = parsed.positional[1];
12
+ const target = (0, utils_1.getFlagString)(parsed, "target");
13
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
14
+ if (!direction || !SCROLL_DIRECTIONS.has(direction)) {
15
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser scroll <up|down|left|right> [pixels] [--target <target>] [--session <sessionId>]", 400);
16
+ }
17
+ if (maybePixels && !(0, utils_1.isNumericToken)(maybePixels)) {
18
+ throw new errors_1.AppError("BAD_REQUEST", "scroll pixels must be a number", 400);
19
+ }
20
+ const pixels = maybePixels ? Number(maybePixels) : undefined;
21
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
22
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/scroll`, { direction, pixels, target });
23
+ const targetSuffix = response.target ? ` target=${response.target}` : "";
24
+ context.stdout.write(`scrolled direction=${response.direction} pixels=${response.pixels}${targetSuffix} session=${response.sessionId} url=${response.url}\n`);
25
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runScrollIntoViewCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runScrollIntoViewCommand = runScrollIntoViewCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runScrollIntoViewCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ if (!target) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser scrollintoview <target> [--session <sessionId>]", 400);
13
+ }
14
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
15
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/scrollintoview`, { target });
16
+ (0, shared_1.writeActionResult)(context, "scrolled-into-view", target, response);
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runSelectCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSelectCommand = runSelectCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runSelectCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const value = parsed.positional.slice(1).join(" ");
11
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
12
+ if (!target || !value) {
13
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser select <target> <value> [--session <sessionId>]", 400);
14
+ }
15
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
16
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/select`, { target, value });
17
+ (0, shared_1.writeActionResult)(context, "selected", target, response);
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runSessionsCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSessionsCommand = runSessionsCommand;
4
+ const utils_1 = require("../lib/utils");
5
+ async function runSessionsCommand(context, argv) {
6
+ (0, utils_1.parseArgs)(argv);
7
+ const response = await context.client.request("GET", "/sessions");
8
+ if (response.sessions.length === 0) {
9
+ context.stdout.write("no sessions\n");
10
+ return;
11
+ }
12
+ for (const session of response.sessions) {
13
+ context.stdout.write(`${(0, utils_1.formatSessionLine)(session)}\n`);
14
+ }
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { ActionResponse, CommandContext } from "../lib/types";
2
+ export declare function resolveSessionId(context: CommandContext, explicitSessionId?: string): Promise<string>;
3
+ export declare function writeActionResult(context: CommandContext, verb: string, target: string, response: ActionResponse): void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSessionId = resolveSessionId;
4
+ exports.writeActionResult = writeActionResult;
5
+ async function resolveSessionId(context, explicitSessionId) {
6
+ if (explicitSessionId) {
7
+ return explicitSessionId;
8
+ }
9
+ return (await context.client.request("GET", "/sessions/current")).sessionId;
10
+ }
11
+ function writeActionResult(context, verb, target, response) {
12
+ context.stdout.write(`${verb} target=${target} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
13
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runSnapshotCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSnapshotCommand = runSnapshotCommand;
4
+ const utils_1 = require("../lib/utils");
5
+ async function runSnapshotCommand(context, argv) {
6
+ const parsed = (0, utils_1.parseArgs)(argv);
7
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
8
+ const interactive = (0, utils_1.getFlagBoolean)(parsed, "interactive");
9
+ const resolvedSessionId = sessionId ??
10
+ (await context.client.request("GET", "/sessions/current")).sessionId;
11
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/snapshot`, interactive ? { interactive: true } : {});
12
+ context.stdout.write(`session=${response.sessionId} url=${response.url}\n`);
13
+ for (const item of response.items) {
14
+ context.stdout.write(`${(0, utils_1.formatSnapshotItem)(item)}\n`);
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runTypeCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runTypeCommand = runTypeCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runTypeCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const text = parsed.positional.slice(1).join(" ");
11
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
12
+ if (!target || !text) {
13
+ throw new errors_1.AppError("BAD_REQUEST", 'Usage: gologin-agent-browser type <target> <text> [--session <sessionId>]', 400);
14
+ }
15
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
16
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/type`, { target, text });
17
+ (0, shared_1.writeActionResult)(context, "typed", target, response);
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runUncheckCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runUncheckCommand = runUncheckCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runUncheckCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ if (!target) {
12
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser uncheck <target> [--session <sessionId>]", 400);
13
+ }
14
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
15
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/uncheck`, { target });
16
+ (0, shared_1.writeActionResult)(context, "unchecked", target, response);
17
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runUploadCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runUploadCommand = runUploadCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runUploadCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const target = parsed.positional[0];
10
+ const files = parsed.positional.slice(1).map((file) => (0, utils_1.ensureAbsolutePath)(context.cwd, file));
11
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
12
+ if (!target || files.length === 0) {
13
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser upload <target> <file...> [--session <sessionId>]", 400);
14
+ }
15
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
16
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/upload`, { target, files });
17
+ context.stdout.write(`uploaded files=${response.files.length} target=${target} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
18
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommandContext } from "../lib/types";
2
+ export declare function runWaitCommand(context: CommandContext, argv: string[]): Promise<void>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWaitCommand = runWaitCommand;
4
+ const errors_1 = require("../lib/errors");
5
+ const utils_1 = require("../lib/utils");
6
+ const shared_1 = require("./shared");
7
+ async function runWaitCommand(context, argv) {
8
+ const parsed = (0, utils_1.parseArgs)(argv);
9
+ const first = parsed.positional[0];
10
+ const sessionId = (0, utils_1.getFlagString)(parsed, "session");
11
+ const text = (0, utils_1.getFlagString)(parsed, "text");
12
+ const urlPattern = (0, utils_1.getFlagString)(parsed, "url");
13
+ const loadState = (0, utils_1.getFlagString)(parsed, "load");
14
+ const body = {};
15
+ if (first) {
16
+ if ((0, utils_1.isNumericToken)(first)) {
17
+ body.timeoutMs = Number(first);
18
+ }
19
+ else {
20
+ body.target = first;
21
+ }
22
+ }
23
+ if (text) {
24
+ body.text = text;
25
+ }
26
+ if (urlPattern) {
27
+ body.urlPattern = urlPattern;
28
+ }
29
+ if (loadState === "load" || loadState === "domcontentloaded" || loadState === "networkidle") {
30
+ body.loadState = loadState;
31
+ }
32
+ else if (loadState) {
33
+ throw new errors_1.AppError("BAD_REQUEST", "wait --load must be load, domcontentloaded, or networkidle", 400);
34
+ }
35
+ if (!body.target && !body.text && !body.urlPattern && !body.loadState && body.timeoutMs === undefined) {
36
+ throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser wait <target|ms> [--text <text>] [--url <pattern>] [--load <state>] [--session <sessionId>]", 400);
37
+ }
38
+ const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
39
+ const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/wait`, body);
40
+ context.stdout.write(`waited session=${response.sessionId} url=${response.url} for=${response.waitedFor}\n`);
41
+ }