aboutsummaryrefslogtreecommitdiff
path: root/src/util/mutex.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-04 22:44:55 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-04 22:44:55 +0530
commit71da8e0719c50d9b11c918b032b9ed4d77aabf5b (patch)
tree16794f5884f95abe9fff79d7eec7e08f24286aed /src/util/mutex.ts
parent2a98be01d28044beabe6a1363f01a5a3acde9fd5 (diff)
feat: parallel tool execution with automatic mutation serialization
- Add lightweight async mutex (src/util/mutex.ts) for FIFO serialization - Add serialized?: boolean to BrowserToolDefinition - Wire mutex acquisition into registerBrowserTool execute wrapper - Expose mutationMutex() on BrowserClient - Mark all mutation tools (click, type, scroll, navigate, switch_tab, etc.) as serialized - Leave observation tools (screenshot, page_info, execute_js, http_get, etc.) unguarded - Update prompt and skill docs to reflect parallel-safe behavior - Fix scroll tool: add Page.bringToFront, explicit button:none/buttons:0/pointerType:mouse - Update .gitignore to ignore scripts/ and data/ folders
Diffstat (limited to 'src/util/mutex.ts')
-rw-r--r--src/util/mutex.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/mutex.ts b/src/util/mutex.ts
new file mode 100644
index 0000000..08efe76
--- /dev/null
+++ b/src/util/mutex.ts
@@ -0,0 +1,25 @@
+/**
+ * Lightweight async mutex (~10 lines). Acquire returns a release function.
+ * When the mutex is free, acquire() resolves immediately. When held,
+ * callers are queued and execute serially in FIFO order.
+ */
+export type Mutex = {
+ acquire(): Promise<() => void>;
+};
+
+export const createMutex = (): Mutex => {
+ let queue = Promise.resolve<unknown>(undefined);
+
+ return {
+ async acquire(): Promise<() => void> {
+ let release = () => {};
+ const next = new Promise<void>((resolve) => {
+ release = resolve;
+ });
+ const prev = queue;
+ queue = prev.then(() => next);
+ await prev;
+ return release;
+ },
+ };
+};