agent-browser-loop 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.
package/src/id.ts ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Friendly ID generator using common words (similar to GitHub's style)
3
+ * Generates IDs like "swift-fox", "calm-river", "bold-star"
4
+ * When all combinations are used, appends numbers: "swift-fox-1", "swift-fox-2"
5
+ */
6
+
7
+ const ADJECTIVES = [
8
+ "swift",
9
+ "calm",
10
+ "bold",
11
+ "warm",
12
+ "cool",
13
+ "dark",
14
+ "pale",
15
+ "keen",
16
+ "soft",
17
+ "wild",
18
+ "pure",
19
+ "deep",
20
+ "fair",
21
+ "glad",
22
+ "kind",
23
+ "safe",
24
+ "wise",
25
+ "fast",
26
+ "free",
27
+ "true",
28
+ "blue",
29
+ "gold",
30
+ "gray",
31
+ "pink",
32
+ "teal",
33
+ ];
34
+
35
+ const NOUNS = [
36
+ "fox",
37
+ "owl",
38
+ "bee",
39
+ "elm",
40
+ "oak",
41
+ "sun",
42
+ "sky",
43
+ "bay",
44
+ "gem",
45
+ "arc",
46
+ "orb",
47
+ "fin",
48
+ "ray",
49
+ "dew",
50
+ "ash",
51
+ "ivy",
52
+ "jet",
53
+ "ink",
54
+ "fog",
55
+ "ice",
56
+ "fir",
57
+ "cod",
58
+ "eel",
59
+ "ant",
60
+ "bat",
61
+ ];
62
+
63
+ export type IdGenerator = {
64
+ next: () => string;
65
+ release: (id: string) => void;
66
+ };
67
+
68
+ /**
69
+ * Creates a friendly ID generator that tracks used IDs
70
+ * and ensures uniqueness within the given set
71
+ */
72
+ export function createIdGenerator(existingIds?: Set<string>): IdGenerator {
73
+ const used = new Set<string>(existingIds);
74
+
75
+ function next(): string {
76
+ // Try random combinations first (up to reasonable attempts)
77
+ const maxAttempts = ADJECTIVES.length * NOUNS.length * 2;
78
+ for (let i = 0; i < maxAttempts; i++) {
79
+ const adj = ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)];
80
+ const noun = NOUNS[Math.floor(Math.random() * NOUNS.length)];
81
+ const id = `${adj}-${noun}`;
82
+ if (!used.has(id)) {
83
+ used.add(id);
84
+ return id;
85
+ }
86
+ }
87
+
88
+ // Most combinations used, try systematically with numbers
89
+ let counter = 1;
90
+ while (true) {
91
+ for (let i = 0; i < maxAttempts; i++) {
92
+ const adj = ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)];
93
+ const noun = NOUNS[Math.floor(Math.random() * NOUNS.length)];
94
+ const id = `${adj}-${noun}-${counter}`;
95
+ if (!used.has(id)) {
96
+ used.add(id);
97
+ return id;
98
+ }
99
+ }
100
+ counter++;
101
+ }
102
+ }
103
+
104
+ function release(id: string): void {
105
+ used.delete(id);
106
+ }
107
+
108
+ return { next, release };
109
+ }
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ export * as actions from "./actions";
2
+ export type { AgentBrowserOptions } from "./browser";
3
+ export { AgentBrowser, createBrowser } from "./browser";
4
+ // Re-export utilities
5
+ export { findChromeExecutable } from "./chrome";
6
+ // Commands (shared execution logic)
7
+ export {
8
+ type ActionResult,
9
+ type Command,
10
+ commandSchema,
11
+ executeActions,
12
+ executeCommand,
13
+ executeWait,
14
+ formatStepText,
15
+ formatWaitText,
16
+ getStateWithFormat,
17
+ type StepAction,
18
+ stepActionSchema,
19
+ type WaitCondition,
20
+ waitConditionSchema,
21
+ } from "./commands";
22
+ export {
23
+ browserCliConfigSchema,
24
+ defineBrowserConfig,
25
+ parseBrowserConfig,
26
+ } from "./config";
27
+ // Daemon
28
+ export {
29
+ cleanupDaemonFiles,
30
+ DaemonClient,
31
+ type DaemonOptions,
32
+ ensureDaemon,
33
+ getPidPath,
34
+ getSocketPath,
35
+ isDaemonRunning,
36
+ startDaemon,
37
+ } from "./daemon";
38
+ // Server
39
+ export type { BrowserServerConfig } from "./server";
40
+ export { startBrowserServer } from "./server";
41
+ export { formatStateText, getState } from "./state";
42
+ export type {
43
+ BrowserCliConfig,
44
+ BrowserConfig,
45
+ BrowserState,
46
+ ClickOptions,
47
+ DumpNetworkOptions,
48
+ DumpStateOptions,
49
+ DumpStateTextOptions,
50
+ GetStateOptions,
51
+ InteractiveElement,
52
+ NavigateOptions,
53
+ NetworkEvent,
54
+ ScrollPosition,
55
+ StorageState,
56
+ TabInfo,
57
+ TypeOptions,
58
+ } from "./types";
package/src/log.ts ADDED
@@ -0,0 +1,42 @@
1
+ import {
2
+ neon,
3
+ SimplePrettyTerminalTransport,
4
+ } from "@loglayer/transport-simple-pretty-terminal";
5
+ import { ConsoleTransport, type ILogLayer, LogLayer } from "loglayer";
6
+ import { serializeError } from "serialize-error";
7
+ import { createContext } from "./context";
8
+
9
+ const isDevelopment = process.env.NODE_ENV !== "production";
10
+
11
+ const baseLoggerInstance = new LogLayer({
12
+ errorSerializer: serializeError,
13
+ transport: isDevelopment
14
+ ? [
15
+ new SimplePrettyTerminalTransport({
16
+ runtime: "node",
17
+ theme: neon,
18
+ }),
19
+ ]
20
+ : [
21
+ new ConsoleTransport({
22
+ logger: console,
23
+ }),
24
+ ],
25
+ });
26
+
27
+ const baseLogger = baseLoggerInstance;
28
+
29
+ const LogContext = createContext<ILogLayer>("log");
30
+
31
+ export function withLog<R>(metadata: Record<string, unknown>, fn: () => R) {
32
+ const currentLogger = LogContext.useSafe() ?? baseLogger;
33
+ const child = currentLogger.child().withContext(metadata);
34
+ return LogContext.with(child, fn);
35
+ }
36
+
37
+ export const log = new Proxy(baseLogger, {
38
+ get(target, prop) {
39
+ const loggerToUse = LogContext.useSafe() ?? target;
40
+ return loggerToUse[prop as keyof ILogLayer];
41
+ },
42
+ });