@elizaos/plugin-browser 2.0.0-alpha.7 → 2.0.0-alpha.9
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/dist/actions/click.d.ts.map +1 -1
- package/dist/actions/click.js +68 -8
- package/dist/actions/click.js.map +1 -1
- package/dist/actions/extract.d.ts.map +1 -1
- package/dist/actions/extract.js +70 -12
- package/dist/actions/extract.js.map +1 -1
- package/dist/actions/navigate.d.ts.map +1 -1
- package/dist/actions/navigate.js +67 -9
- package/dist/actions/navigate.js.map +1 -1
- package/dist/actions/screenshot.d.ts.map +1 -1
- package/dist/actions/screenshot.js +68 -8
- package/dist/actions/screenshot.js.map +1 -1
- package/dist/actions/select.d.ts.map +1 -1
- package/dist/actions/select.js +71 -9
- package/dist/actions/select.js.map +1 -1
- package/dist/actions/type.d.ts.map +1 -1
- package/dist/actions/type.js +71 -9
- package/dist/actions/type.js.map +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/register.d.ts.map +1 -1
- package/dist/cli/register.js +5 -1
- package/dist/cli/register.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -48
- package/dist/index.js.map +1 -1
- package/dist/providerRelevance.d.ts +4 -0
- package/dist/providerRelevance.d.ts.map +1 -0
- package/dist/providerRelevance.js +33 -0
- package/dist/providerRelevance.js.map +1 -0
- package/dist/providers/browser-state.d.ts.map +1 -1
- package/dist/providers/browser-state.js +25 -0
- package/dist/providers/browser-state.js.map +1 -1
- package/dist/services/browser-service.d.ts.map +1 -1
- package/dist/services/browser-service.js +9 -4
- package/dist/services/browser-service.js.map +1 -1
- package/dist/services/process-manager.d.ts.map +1 -1
- package/dist/services/process-manager.js.map +1 -1
- package/dist/services/websocket-client.d.ts.map +1 -1
- package/dist/services/websocket-client.js +4 -2
- package/dist/services/websocket-client.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/captcha.d.ts.map +1 -1
- package/dist/utils/captcha.js.map +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +1 -1
- package/dist/utils/retry.js.map +1 -1
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +2 -1
- package/dist/utils/security.js.map +1 -1
- package/dist/utils/url.d.ts.map +1 -1
- package/dist/utils/url.js +2 -1
- package/dist/utils/url.js.map +1 -1
- package/package.json +110 -110
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;AAClF,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,iBA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yC,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;gBAC5D,MAAM,QAAQ,GAAG,KAAgD,CAAC;gBAClE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBACnC,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACvE,MAAM,IAAI,KAAK,CAAC,iCAAiC,aAAa,EAAE,CAAC,CAAC;gBACpE,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IACD,QAAQ,EAAE,CAAC,cAAc,CAAC;IAC1B,OAAO,EAAE;QACP,qBAAqB;QACrB,kBAAkB;QAClB,iBAAiB;QACjB,mBAAmB;QACnB,oBAAoB;QACpB,uBAAuB;KACxB;IACD,SAAS,EAAE,CAAC,oBAAoB,CAAC;CAClC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import type { IAgentRuntime, Memory, Plugin, Provider, ProviderResult, State } from \"@elizaos/core\";\nimport { logger, ServiceType } from \"@elizaos/core\";\nimport { z } from \"zod\";\nimport { browserClickAction } from \"./actions/click.js\";\nimport { browserExtractAction } from \"./actions/extract.js\";\nimport { browserNavigateAction } from \"./actions/navigate.js\";\nimport { browserScreenshotAction } from \"./actions/screenshot.js\";\nimport { browserSelectAction } from \"./actions/select.js\";\nimport { browserTypeAction } from \"./actions/type.js\";\nimport { BrowserService, Session } from \"./services/browser-service.js\";\nimport { BrowserProcessManager } from \"./services/process-manager.js\";\nimport { BrowserWebSocketClient } from \"./services/websocket-client.js\";\n\nexport * from \"./types.js\";\nexport * from \"./utils/index.js\";\nexport { BrowserService, Session, BrowserWebSocketClient, BrowserProcessManager };\nexport {\n browserNavigateAction,\n browserClickAction,\n browserTypeAction,\n browserSelectAction,\n browserExtractAction,\n browserScreenshotAction,\n};\nconst configSchema = z.object({\n BROWSERBASE_API_KEY: z.string().optional(),\n BROWSERBASE_PROJECT_ID: z.string().optional(),\n OPENAI_API_KEY: z.string().optional(),\n ANTHROPIC_API_KEY: z.string().optional(),\n OLLAMA_BASE_URL: z.string().optional(),\n OLLAMA_MODEL: z.string().optional(),\n BROWSER_HEADLESS: z\n .string()\n .transform((val: string) => val === \"true\")\n .optional()\n .default(true),\n CAPSOLVER_API_KEY: z.string().optional(),\n BROWSER_SERVER_PORT: z.string().optional().default(\"3456\"),\n});\n\nconst browserStateProvider: Provider = {\n name: \"BROWSER_STATE\",\n description: \"Provides current browser state information\",\n\n get: async (\n runtime: IAgentRuntime,\n _message: Memory,\n _state?: State\n ): Promise<ProviderResult> => {\n const service = runtime.getService<BrowserService>(ServiceType.BROWSER);\n const session = await service?.getCurrentSession();\n\n if (!session || !service) {\n return {\n text: \"No active browser session\",\n values: {\n hasSession: false,\n },\n data: {},\n };\n }\n\n try {\n const client = service.getClient();\n const state = await client.getState(session.id);\n\n return {\n text: `Current browser page: \"${state.title}\" at ${state.url}`,\n values: {\n hasSession: true,\n url: state.url,\n title: state.title,\n },\n data: {\n sessionId: session.id,\n createdAt: session.createdAt.toISOString(),\n },\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Error getting browser state: ${errorMessage}`);\n return {\n text: \"Error getting browser state\",\n values: {\n hasSession: true,\n error: true,\n },\n data: {},\n };\n }\n },\n};\n\n// CLI self-registration - importing this module triggers CLI command registration.\n// Wrapped in a dynamic import so the plugin still loads when @elizaos/plugin-cli\n// is unavailable (e.g. when consumed outside the monorepo).\nimport(\"./cli/index.js\").catch(() => {\n // plugin-cli not available — skip CLI registration silently\n});\n\nexport const browserPlugin: Plugin = {\n name: \"plugin-browser\",\n description: \"Browser automation plugin\",\n config: {\n BROWSERBASE_API_KEY: process.env.BROWSERBASE_API_KEY ?? null,\n BROWSERBASE_PROJECT_ID: process.env.BROWSERBASE_PROJECT_ID ?? null,\n OPENAI_API_KEY: process.env.OPENAI_API_KEY ?? null,\n ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? null,\n OLLAMA_BASE_URL: process.env.OLLAMA_BASE_URL ?? null,\n OLLAMA_MODEL: process.env.OLLAMA_MODEL ?? null,\n BROWSER_HEADLESS: process.env.BROWSER_HEADLESS ?? \"true\",\n CAPSOLVER_API_KEY: process.env.CAPSOLVER_API_KEY ?? null,\n BROWSER_SERVER_PORT: process.env.BROWSER_SERVER_PORT ?? \"3456\",\n },\n async init(config: Record<string, string | null>, _runtime: IAgentRuntime) {\n logger.info(\"Initializing browser automation plugin\");\n try {\n const validatedConfig = await configSchema.parseAsync(config);\n\n for (const [key, value] of Object.entries(validatedConfig)) {\n if (value !== undefined && value !== null) {\n process.env[key] = String(value);\n }\n }\n\n // Auto-enable browser actions when the plugin is loaded.\n // The plugin being present in the runtime means the user toggled it on.\n process.env.ENABLE_BROWSER = \"true\";\n process.env.BROWSER_ENABLED = \"true\";\n\n logger.info(\"Browser plugin initialized successfully\");\n } catch (error) {\n if (error && typeof error === \"object\" && \"issues\" in error) {\n const zodError = error as { issues?: Array<{ message: string }> };\n if (Array.isArray(zodError.issues)) {\n const errorMessages = zodError.issues.map((e) => e.message).join(\", \");\n throw new Error(`Invalid plugin configuration: ${errorMessages}`);\n }\n }\n throw error;\n }\n },\n services: [BrowserService],\n actions: [\n browserNavigateAction,\n browserClickAction,\n browserTypeAction,\n browserSelectAction,\n browserExtractAction,\n browserScreenshotAction,\n ],\n providers: [browserStateProvider],\n};\n\nexport default browserPlugin;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,CAAC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QACnB,oBAAoB;QACpB,uBAAuB;KACvB;IACD,SAAS,EAAE,CAAC,oBAAoB,CAAC;CACjC,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import type { IAgentRuntime, Plugin } from \"@elizaos/core\";\nimport { logger } from \"@elizaos/core\";\nimport { z } from \"zod\";\nimport { browserClickAction } from \"./actions/click.js\";\nimport { browserExtractAction } from \"./actions/extract.js\";\nimport { browserNavigateAction } from \"./actions/navigate.js\";\nimport { browserScreenshotAction } from \"./actions/screenshot.js\";\nimport { browserSelectAction } from \"./actions/select.js\";\nimport { browserTypeAction } from \"./actions/type.js\";\nimport { browserStateProvider } from \"./providers/browser-state.js\";\nimport { BrowserService, Session } from \"./services/browser-service.js\";\nimport { BrowserProcessManager } from \"./services/process-manager.js\";\nimport { BrowserWebSocketClient } from \"./services/websocket-client.js\";\n\nexport * from \"./types.js\";\nexport * from \"./utils/index.js\";\nexport {\n\tBrowserService,\n\tSession,\n\tBrowserWebSocketClient,\n\tBrowserProcessManager,\n};\nexport {\n\tbrowserNavigateAction,\n\tbrowserClickAction,\n\tbrowserTypeAction,\n\tbrowserSelectAction,\n\tbrowserExtractAction,\n\tbrowserScreenshotAction,\n};\nconst configSchema = z.object({\n\tBROWSERBASE_API_KEY: z.string().optional(),\n\tBROWSERBASE_PROJECT_ID: z.string().optional(),\n\tOPENAI_API_KEY: z.string().optional(),\n\tANTHROPIC_API_KEY: z.string().optional(),\n\tOLLAMA_BASE_URL: z.string().optional(),\n\tOLLAMA_MODEL: z.string().optional(),\n\tBROWSER_HEADLESS: z\n\t\t.string()\n\t\t.transform((val: string) => val === \"true\")\n\t\t.optional()\n\t\t.default(true),\n\tCAPSOLVER_API_KEY: z.string().optional(),\n\tBROWSER_SERVER_PORT: z.string().optional().default(\"3456\"),\n});\n\n// CLI self-registration - importing this module triggers CLI command registration.\n// Wrapped in a dynamic import so the plugin still loads when @elizaos/plugin-cli\n// is unavailable (e.g. when consumed outside the monorepo).\nimport(\"./cli/index.js\").catch(() => {\n\t// plugin-cli not available — skip CLI registration silently\n});\n\nexport const browserPlugin: Plugin = {\n\tname: \"plugin-browser\",\n\tdescription: \"Browser automation plugin\",\n\tconfig: {\n\t\tBROWSERBASE_API_KEY: process.env.BROWSERBASE_API_KEY ?? null,\n\t\tBROWSERBASE_PROJECT_ID: process.env.BROWSERBASE_PROJECT_ID ?? null,\n\t\tOPENAI_API_KEY: process.env.OPENAI_API_KEY ?? null,\n\t\tANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? null,\n\t\tOLLAMA_BASE_URL: process.env.OLLAMA_BASE_URL ?? null,\n\t\tOLLAMA_MODEL: process.env.OLLAMA_MODEL ?? null,\n\t\tBROWSER_HEADLESS: process.env.BROWSER_HEADLESS ?? \"true\",\n\t\tCAPSOLVER_API_KEY: process.env.CAPSOLVER_API_KEY ?? null,\n\t\tBROWSER_SERVER_PORT: process.env.BROWSER_SERVER_PORT ?? \"3456\",\n\t},\n\tasync init(config: Record<string, string | null>, _runtime: IAgentRuntime) {\n\t\tlogger.info(\"Initializing browser automation plugin\");\n\t\ttry {\n\t\t\tconst validatedConfig = await configSchema.parseAsync(config);\n\n\t\t\tfor (const [key, value] of Object.entries(validatedConfig)) {\n\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\tprocess.env[key] = String(value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Auto-enable browser actions when the plugin is loaded.\n\t\t\t// The plugin being present in the runtime means the user toggled it on.\n\t\t\tprocess.env.ENABLE_BROWSER = \"true\";\n\t\t\tprocess.env.BROWSER_ENABLED = \"true\";\n\n\t\t\tlogger.info(\"Browser plugin initialized successfully\");\n\t\t} catch (error) {\n\t\t\tif (error && typeof error === \"object\" && \"issues\" in error) {\n\t\t\t\tconst zodError = error as { issues?: Array<{ message: string }> };\n\t\t\t\tif (Array.isArray(zodError.issues)) {\n\t\t\t\t\tconst errorMessages = zodError.issues\n\t\t\t\t\t\t.map((e) => e.message)\n\t\t\t\t\t\t.join(\", \");\n\t\t\t\t\tthrow new Error(`Invalid plugin configuration: ${errorMessages}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t},\n\tservices: [BrowserService],\n\tactions: [\n\t\tbrowserNavigateAction,\n\t\tbrowserClickAction,\n\t\tbrowserTypeAction,\n\t\tbrowserSelectAction,\n\t\tbrowserExtractAction,\n\t\tbrowserScreenshotAction,\n\t],\n\tproviders: [browserStateProvider],\n};\n\nexport default browserPlugin;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Memory } from "@elizaos/core";
|
|
2
|
+
export declare function validateActionKeywords(message: Memory, recentMessages: unknown, keywords: string[]): boolean;
|
|
3
|
+
export declare function validateActionRegex(message: Memory, recentMessages: unknown, regex: RegExp): boolean;
|
|
4
|
+
//# sourceMappingURL=providerRelevance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providerRelevance.d.ts","sourceRoot":"","sources":["../src/providerRelevance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAqB5C,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,OAAO,EACvB,QAAQ,EAAE,MAAM,EAAE,GAChB,OAAO,CAIT;AAED,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,OAAO,EACvB,KAAK,EAAE,MAAM,GACX,OAAO,CAIT"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function getMessageText(message) {
|
|
2
|
+
if (!message || typeof message !== "object")
|
|
3
|
+
return "";
|
|
4
|
+
const content = message.content;
|
|
5
|
+
if (typeof content === "string")
|
|
6
|
+
return content;
|
|
7
|
+
if (!content || typeof content !== "object")
|
|
8
|
+
return "";
|
|
9
|
+
const text = content.text;
|
|
10
|
+
return typeof text === "string" ? text : "";
|
|
11
|
+
}
|
|
12
|
+
function toHaystack(message, recentMessages) {
|
|
13
|
+
const recent = Array.isArray(recentMessages) ? recentMessages : [];
|
|
14
|
+
return [
|
|
15
|
+
getMessageText(message),
|
|
16
|
+
...recent.map((entry) => getMessageText(entry)),
|
|
17
|
+
]
|
|
18
|
+
.join(" ")
|
|
19
|
+
.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
export function validateActionKeywords(message, recentMessages, keywords) {
|
|
22
|
+
const haystack = toHaystack(message, recentMessages);
|
|
23
|
+
if (!haystack.trim())
|
|
24
|
+
return true;
|
|
25
|
+
return keywords.some((keyword) => haystack.includes(keyword.toLowerCase()));
|
|
26
|
+
}
|
|
27
|
+
export function validateActionRegex(message, recentMessages, regex) {
|
|
28
|
+
const haystack = toHaystack(message, recentMessages);
|
|
29
|
+
if (!haystack.trim())
|
|
30
|
+
return true;
|
|
31
|
+
return regex.test(haystack);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=providerRelevance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providerRelevance.js","sourceRoot":"","sources":["../src/providerRelevance.ts"],"names":[],"mappings":"AAEA,SAAS,cAAc,CAAC,OAAgB;IACvC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACvD,MAAM,OAAO,GAAI,OAAiC,CAAC,OAAO,CAAC;IAC3D,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACvD,MAAM,IAAI,GAAI,OAA8B,CAAC,IAAI,CAAC;IAClD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,cAAuB;IAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO;QACN,cAAc,CAAC,OAAO,CAAC;QACvB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;KAC/C;SACC,IAAI,CAAC,GAAG,CAAC;SACT,WAAW,EAAE,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,sBAAsB,CACrC,OAAe,EACf,cAAuB,EACvB,QAAkB;IAElB,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;IAClC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,mBAAmB,CAClC,OAAe,EACf,cAAuB,EACvB,KAAa;IAEb,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;IAClC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import type { Memory } from \"@elizaos/core\";\n\nfunction getMessageText(message: unknown): string {\n\tif (!message || typeof message !== \"object\") return \"\";\n\tconst content = (message as { content?: unknown }).content;\n\tif (typeof content === \"string\") return content;\n\tif (!content || typeof content !== \"object\") return \"\";\n\tconst text = (content as { text?: unknown }).text;\n\treturn typeof text === \"string\" ? text : \"\";\n}\n\nfunction toHaystack(message: Memory, recentMessages: unknown): string {\n\tconst recent = Array.isArray(recentMessages) ? recentMessages : [];\n\treturn [\n\t\tgetMessageText(message),\n\t\t...recent.map((entry) => getMessageText(entry)),\n\t]\n\t\t.join(\" \")\n\t\t.toLowerCase();\n}\n\nexport function validateActionKeywords(\n\tmessage: Memory,\n\trecentMessages: unknown,\n\tkeywords: string[],\n): boolean {\n\tconst haystack = toHaystack(message, recentMessages);\n\tif (!haystack.trim()) return true;\n\treturn keywords.some((keyword) => haystack.includes(keyword.toLowerCase()));\n}\n\nexport function validateActionRegex(\n\tmessage: Memory,\n\trecentMessages: unknown,\n\tregex: RegExp,\n): boolean {\n\tconst haystack = toHaystack(message, recentMessages);\n\tif (!haystack.trim()) return true;\n\treturn regex.test(haystack);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-state.d.ts","sourceRoot":"","sources":["../../src/providers/browser-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"browser-state.d.ts","sourceRoot":"","sources":["../../src/providers/browser-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,QAAQ,EAGR,MAAM,eAAe,CAAC;AAQvB,eAAO,MAAM,oBAAoB,EAAE,QAgFlC,CAAC"}
|
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import { logger, ServiceType } from "@elizaos/core";
|
|
2
|
+
import { validateActionKeywords, validateActionRegex, } from "../providerRelevance.js";
|
|
2
3
|
export const browserStateProvider = {
|
|
3
4
|
name: "BROWSER_STATE",
|
|
4
5
|
description: "Provides current browser state information",
|
|
6
|
+
dynamic: true,
|
|
5
7
|
get: async (runtime, _message, _state) => {
|
|
8
|
+
const __providerKeywords = [
|
|
9
|
+
"browser",
|
|
10
|
+
"state",
|
|
11
|
+
"browserstateprovider",
|
|
12
|
+
"plugin",
|
|
13
|
+
"status",
|
|
14
|
+
"context",
|
|
15
|
+
"info",
|
|
16
|
+
"details",
|
|
17
|
+
"chat",
|
|
18
|
+
"conversation",
|
|
19
|
+
"agent",
|
|
20
|
+
"room",
|
|
21
|
+
"channel",
|
|
22
|
+
"user",
|
|
23
|
+
];
|
|
24
|
+
const __providerRegex = new RegExp(`\\b(${__providerKeywords.join("|")})\\b`, "i");
|
|
25
|
+
const __recentMessages = _state?.recentMessagesData || [];
|
|
26
|
+
const __isRelevant = validateActionKeywords(_message, __recentMessages, __providerKeywords) ||
|
|
27
|
+
validateActionRegex(_message, __recentMessages, __providerRegex);
|
|
28
|
+
if (!__isRelevant) {
|
|
29
|
+
return { text: "" };
|
|
30
|
+
}
|
|
6
31
|
const service = runtime.getService(ServiceType.BROWSER);
|
|
7
32
|
const session = await service?.getCurrentSession();
|
|
8
33
|
if (!session || !service) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-state.js","sourceRoot":"","sources":["../../src/providers/browser-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser-state.js","sourceRoot":"","sources":["../../src/providers/browser-state.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EACN,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AAGjC,MAAM,CAAC,MAAM,oBAAoB,GAAa;IAC7C,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,4CAA4C;IAEzD,OAAO,EAAE,IAAI;IACb,GAAG,EAAE,KAAK,EACT,OAAsB,EACtB,QAAgB,EAChB,MAAc,EACY,EAAE;QAC5B,MAAM,kBAAkB,GAAG;YAC1B,SAAS;YACT,OAAO;YACP,sBAAsB;YACtB,QAAQ;YACR,QAAQ;YACR,SAAS;YACT,MAAM;YACN,SAAS;YACT,MAAM;YACN,cAAc;YACd,OAAO;YACP,MAAM;YACN,SAAS;YACT,MAAM;SACN,CAAC;QACF,MAAM,eAAe,GAAG,IAAI,MAAM,CACjC,OAAO,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EACzC,GAAG,CACH,CAAC;QACF,MAAM,gBAAgB,GAAG,MAAM,EAAE,kBAAk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,MAAM,CAAC,KAAK,CAAC,CAAC;YACxD,MAAM,CAAC,KAAK,CAAC,gCAAgC,YAAY,EAAE,CAAC,CAAC;YAC7D,OAAO;gBACN,IAAI,EAAE,6BAA6B;gBACnC,MAAM,EAAE;oBACP,UAAU,EAAE,IAAI;oBAChB,KAAK,EAAE,IAAI;iBACX;gBACD,IAAI,EAAE,EAAE;aACR,CAAC;QACH,CAAC;IACF,CAAC;CACD,CAAC","sourcesContent":["import type {\n\tIAgentRuntime,\n\tMemory,\n\tProvider,\n\tProviderResult,\n\tState,\n} from \"@elizaos/core\";\nimport { logger, ServiceType } from \"@elizaos/core\";\nimport {\n\tvalidateActionKeywords,\n\tvalidateActionRegex,\n} from \"../providerRelevance.js\";\nimport type { BrowserService } from \"../services/browser-service.js\";\n\nexport const browserStateProvider: Provider = {\n\tname: \"BROWSER_STATE\",\n\tdescription: \"Provides current browser state information\",\n\n\tdynamic: true,\n\tget: async (\n\t\truntime: IAgentRuntime,\n\t\t_message: Memory,\n\t\t_state?: State,\n\t): Promise<ProviderResult> => {\n\t\tconst __providerKeywords = [\n\t\t\t\"browser\",\n\t\t\t\"state\",\n\t\t\t\"browserstateprovider\",\n\t\t\t\"plugin\",\n\t\t\t\"status\",\n\t\t\t\"context\",\n\t\t\t\"info\",\n\t\t\t\"details\",\n\t\t\t\"chat\",\n\t\t\t\"conversation\",\n\t\t\t\"agent\",\n\t\t\t\"room\",\n\t\t\t\"channel\",\n\t\t\t\"user\",\n\t\t];\n\t\tconst __providerRegex = new RegExp(\n\t\t\t`\\\\b(${__providerKeywords.join(\"|\")})\\\\b`,\n\t\t\t\"i\",\n\t\t);\n\t\tconst __recentMessages = _state?.recentMessagesData || [];\n\t\tconst __isRelevant =\n\t\t\tvalidateActionKeywords(_message, __recentMessages, __providerKeywords) ||\n\t\t\tvalidateActionRegex(_message, __recentMessages, __providerRegex);\n\t\tif (!__isRelevant) {\n\t\t\treturn { text: \"\" };\n\t\t}\n\t\tconst service = runtime.getService<BrowserService>(ServiceType.BROWSER);\n\t\tconst session = await service?.getCurrentSession();\n\n\t\tif (!session || !service) {\n\t\t\treturn {\n\t\t\t\ttext: \"No active browser session\",\n\t\t\t\tvalues: {\n\t\t\t\t\thasSession: false,\n\t\t\t\t},\n\t\t\t\tdata: {},\n\t\t\t};\n\t\t}\n\n\t\ttry {\n\t\t\tconst client = service.getClient();\n\t\t\tconst state = await client.getState(session.id);\n\n\t\t\treturn {\n\t\t\t\ttext: `Current browser page: \"${state.title}\" at ${state.url}`,\n\t\t\t\tvalues: {\n\t\t\t\t\thasSession: true,\n\t\t\t\t\turl: state.url,\n\t\t\t\t\ttitle: state.title,\n\t\t\t\t},\n\t\t\t\tdata: {\n\t\t\t\t\tsessionId: session.id,\n\t\t\t\t\tcreatedAt: session.createdAt.toISOString(),\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlogger.error(`Error getting browser state: ${errorMessage}`);\n\t\t\treturn {\n\t\t\t\ttext: \"Error getting browser state\",\n\t\t\t\tvalues: {\n\t\t\t\t\thasSession: true,\n\t\t\t\t\terror: true,\n\t\t\t\t},\n\t\t\t\tdata: {},\n\t\t\t};\n\t\t}\n\t},\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-service.d.ts","sourceRoot":"","sources":["../../src/services/browser-service.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"browser-service.d.ts","sourceRoot":"","sources":["../../src/services/browser-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,aAAa,EAElB,OAAO,EAEP,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,qBAAa,OAAQ,YAAW,cAAc;IAErC,EAAE,EAAE,MAAM;IACV,SAAS,EAAE,IAAI;gBADf,EAAE,EAAE,MAAM,EACV,SAAS,GAAE,IAAiB;CAEpC;AAED,qBAAa,cAAe,SAAQ,OAAO;IAC1C,MAAM,CAAC,WAAW,YAAuB;IACzC,qBAAqB,SAAgC;IAErD,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,aAAa,CAAS;IAE9B,gEAAgE;IAChE,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,CAAC,EAAE,aAAa;WAgCtB,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;WAyDtD,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAYrB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAsC3B,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBlD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAI3D,iBAAiB,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAOjD,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAUtC,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAatD,SAAS,IAAI,sBAAsB;YAOrB,YAAY;CA8B1B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger, Service, ServiceType } from "@elizaos/core";
|
|
1
|
+
import { logger, Service, ServiceType, } from "@elizaos/core";
|
|
2
2
|
import { BrowserProcessManager } from "./process-manager.js";
|
|
3
3
|
import { BrowserWebSocketClient } from "./websocket-client.js";
|
|
4
4
|
export class Session {
|
|
@@ -117,7 +117,9 @@ export class BrowserService extends Service {
|
|
|
117
117
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
118
118
|
}
|
|
119
119
|
catch (startError) {
|
|
120
|
-
const msg = startError instanceof Error
|
|
120
|
+
const msg = startError instanceof Error
|
|
121
|
+
? startError.message
|
|
122
|
+
: String(startError);
|
|
121
123
|
logger.error(`Failed to initialize browser service: ${msg}`);
|
|
122
124
|
// Don't throw — allow the service to exist in a degraded state
|
|
123
125
|
// so other plugins can still function.
|
|
@@ -141,7 +143,8 @@ export class BrowserService extends Service {
|
|
|
141
143
|
throw new Error("Browser service not initialized");
|
|
142
144
|
}
|
|
143
145
|
const response = await this.client.sendMessage("createSession", {});
|
|
144
|
-
const serverSessionId = response.data
|
|
146
|
+
const serverSessionId = response.data
|
|
147
|
+
?.sessionId;
|
|
145
148
|
if (!serverSessionId) {
|
|
146
149
|
throw new Error("Failed to create session on server");
|
|
147
150
|
}
|
|
@@ -170,7 +173,9 @@ export class BrowserService extends Service {
|
|
|
170
173
|
async destroySession(sessionId) {
|
|
171
174
|
const session = this.sessions.get(sessionId);
|
|
172
175
|
if (session) {
|
|
173
|
-
await this.client.sendMessage("destroySession", {
|
|
176
|
+
await this.client.sendMessage("destroySession", {
|
|
177
|
+
sessionId: session.id,
|
|
178
|
+
});
|
|
174
179
|
this.sessions.delete(sessionId);
|
|
175
180
|
if (this.currentSessionId === sessionId) {
|
|
176
181
|
this.currentSessionId = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-service.js","sourceRoot":"","sources":["../../src/services/browser-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,OAAO,OAAO;IAET;IACA;IAFT,YACS,EAAU,EACV,YAAk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AC;gBACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAC7C,IAAI,SAAS,EAAE,CAAC;oBACd,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;oBACvC,OAAO;gBACT,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5E,MAAM,CAAC,KAAK,CAAC,wBAAwB,OAAO,IAAI,WAAW,YAAY,YAAY,EAAE,CAAC,CAAC;YACzF,CAAC;YAED,IAAI,OAAO,GAAG,WAAW,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CACT,qCAAqC,OAAO,GAAG,IAAI,iBAAiB,OAAO,IAAI,WAAW,GAAG,CAC9F,CAAC;gBACF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,WAAW,CAAC,CAAC;IACvF,CAAC","sourcesContent":["import { type IAgentRuntime, logger, Service, ServiceType } from \"@elizaos/core\";\nimport type { BrowserSession } from \"../types.js\";\nimport { BrowserProcessManager } from \"./process-manager.js\";\nimport { BrowserWebSocketClient } from \"./websocket-client.js\";\n\nexport class Session implements BrowserSession {\n constructor(\n public id: string,\n public createdAt: Date = new Date()\n ) {}\n}\n\nexport class BrowserService extends Service {\n static serviceType = ServiceType.BROWSER;\n capabilityDescription = \"Browser automation service\";\n\n private sessions = new Map<string, Session>();\n private currentSessionId: string | null = null;\n private processManager: BrowserProcessManager;\n private client: BrowserWebSocketClient;\n private isInitialized = false;\n\n /** Whether this service is operating in sandbox remote mode. */\n private sandboxMode = false;\n\n constructor(runtime?: IAgentRuntime) {\n super(runtime);\n if (!runtime) {\n throw new Error(\"BrowserService requires a runtime\");\n }\n this.runtime = runtime;\n\n // Detect sandbox mode from runtime\n this.sandboxMode = Boolean(\n (runtime as Record<string, unknown>).sandboxMode,\n );\n\n const portSetting = runtime.getSetting(\"BROWSER_SERVER_PORT\");\n const port = typeof portSetting === \"string\" ? parseInt(portSetting, 10) : 3456;\n\n // In sandbox mode, connect to remote endpoint instead of local process\n if (this.sandboxMode) {\n const remoteWsUrl =\n (runtime.getSetting(\"SANDBOX_BROWSER_WS_URL\") as string | null) ??\n `ws://localhost:${port}`;\n this.processManager = new BrowserProcessManager(port);\n this.client = new BrowserWebSocketClient(remoteWsUrl);\n logger.info(`Browser service: sandbox mode, remote endpoint: ${remoteWsUrl}`);\n } else {\n this.processManager = new BrowserProcessManager(port);\n this.client = new BrowserWebSocketClient(`ws://localhost:${port}`);\n }\n }\n\n static async start(runtime: IAgentRuntime): Promise<BrowserService> {\n logger.info(\"Starting browser automation service\");\n try {\n const service = new BrowserService(runtime);\n\n // In sandbox mode, do NOT start a local browser server process\n if (service.sandboxMode) {\n logger.info(\"Browser service: sandbox mode — skipping local server spawn\");\n logger.info(\"Connecting to remote browser server...\");\n try {\n await service.initialize();\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.warn(`Remote browser not reachable: ${errorMessage}`);\n logger.warn(\"Browser plugin will be in degraded state\");\n }\n return service;\n }\n\n logger.info(\"Starting browser server process...\");\n let serverStarted = false;\n try {\n await service.processManager.start();\n serverStarted = true;\n logger.info(\"Browser server started successfully\");\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to start browser server: ${errorMessage}`);\n logger.warn(\"Browser plugin will be available but automation will not work\");\n logger.warn(\"To fix this, run: cd packages/plugin-browser && npm run build\");\n }\n\n // Only attempt WebSocket initialization if the server actually started.\n // Otherwise we'd retry processManager.start() inside initialize() and\n // throw again, which crashes service registration.\n if (serverStarted) {\n logger.info(\"Initializing WebSocket client...\");\n await service.initialize();\n }\n\n return service;\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to start browser service: ${errorMessage}`);\n throw error;\n }\n }\n\n static async stopRuntime(runtime: IAgentRuntime): Promise<void> {\n logger.info(\"Stopping browser automation service\");\n const service = runtime.getService<BrowserService>(BrowserService.serviceType);\n if (!service) {\n throw new Error(\"Browser service not found\");\n }\n await service.stop();\n }\n\n async stop(): Promise<void> {\n logger.info(\"Cleaning up browser sessions\");\n\n for (const sessionId of this.sessions.keys()) {\n await this.destroySession(sessionId);\n }\n\n this.client.disconnect();\n await this.processManager.stop();\n this.isInitialized = false;\n }\n\n async initialize(): Promise<void> {\n if (this.isInitialized) {\n return;\n }\n\n try {\n if (!this.processManager.isServerRunning()) {\n logger.warn(\"Browser server is not running, attempting to start...\");\n try {\n await this.processManager.start();\n await new Promise((resolve) => setTimeout(resolve, 2000));\n } catch (startError) {\n const msg = startError instanceof Error ? startError.message : String(startError);\n logger.error(`Failed to initialize browser service: ${msg}`);\n // Don't throw — allow the service to exist in a degraded state\n // so other plugins can still function.\n return;\n }\n }\n\n logger.info(\"Connecting to browser server...\");\n await this.client.connect();\n\n await this.waitForReady();\n\n this.isInitialized = true;\n logger.info(\"Browser service initialized successfully\");\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`Failed to initialize browser service: ${errorMessage}`);\n throw error;\n }\n }\n\n async createSession(sessionId: string): Promise<Session> {\n if (!this.isInitialized) {\n throw new Error(\"Browser service not initialized\");\n }\n\n const response = await this.client.sendMessage(\"createSession\", {});\n const serverSessionId = (response.data as { sessionId?: string })?.sessionId;\n if (!serverSessionId) {\n throw new Error(\"Failed to create session on server\");\n }\n\n const session = new Session(serverSessionId);\n this.sessions.set(sessionId, session);\n this.currentSessionId = sessionId;\n\n return session;\n }\n\n async getSession(sessionId: string): Promise<Session | undefined> {\n return this.sessions.get(sessionId);\n }\n\n async getCurrentSession(): Promise<Session | undefined> {\n if (!this.currentSessionId) {\n return undefined;\n }\n return this.sessions.get(this.currentSessionId);\n }\n\n async getOrCreateSession(): Promise<Session> {\n const currentSession = await this.getCurrentSession();\n if (currentSession) {\n return currentSession;\n }\n\n const sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n return this.createSession(sessionId);\n }\n\n async destroySession(sessionId: string): Promise<void> {\n const session = this.sessions.get(sessionId);\n if (session) {\n await this.client.sendMessage(\"destroySession\", { sessionId: session.id });\n this.sessions.delete(sessionId);\n if (this.currentSessionId === sessionId) {\n this.currentSessionId = null;\n }\n }\n }\n\n getClient(): BrowserWebSocketClient {\n if (!this.isInitialized) {\n throw new Error(\"Browser service not initialized\");\n }\n return this.client;\n }\n\n private async waitForReady(maxAttempts = 60, delayMs = 3000): Promise<void> {\n logger.info(\"Waiting for browser server to be ready...\");\n\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n try {\n const isHealthy = await this.client.health();\n if (isHealthy) {\n logger.info(\"Browser server is ready\");\n return;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.debug(`Health check attempt ${attempt}/${maxAttempts} failed: ${errorMessage}`);\n }\n\n if (attempt < maxAttempts) {\n logger.info(\n `Server not ready yet, retrying in ${delayMs / 1000}s... (attempt ${attempt}/${maxAttempts})`\n );\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n }\n\n throw new Error(`Browser server did not become ready after ${maxAttempts} attempts`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"browser-service.js","sourceRoot":"","sources":["../../src/services/browser-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,MAAM,EACN,OAAO,EACP,WAAW,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,OAAO,OAAO;IAEX;IACA;IA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AAE,CAAC;YACzD,IAAI,CAAC;gBACJ,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAC7C,IAAI,SAAS,EAAE,CAAC;oBACf,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;oBACvC,OAAO;gBACR,CAAC;YACF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,YAAY,GACjB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACxD,MAAM,CAAC,KAAK,CACX,wBAAwB,OAAO,IAAI,WAAW,YAAY,YAAY,EAAE,CACxE,CAAC;YACH,CAAC;YAED,IAAI,OAAO,GAAG,WAAW,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CACV,qCAAqC,OAAO,GAAG,IAAI,iBAAiB,OAAO,IAAI,WAAW,GAAG,CAC7F,CAAC;gBACF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;YAC9D,CAAC;QACF,CAAC;QAED,MAAM,IAAI,KAAK,CACd,6CAA6C,WAAW,WAAW,CACnE,CAAC;IACH,CAAC","sourcesContent":["import {\n\ttype IAgentRuntime,\n\tlogger,\n\tService,\n\tServiceType,\n} from \"@elizaos/core\";\nimport type { BrowserSession } from \"../types.js\";\nimport { BrowserProcessManager } from \"./process-manager.js\";\nimport { BrowserWebSocketClient } from \"./websocket-client.js\";\n\nexport class Session implements BrowserSession {\n\tconstructor(\n\t\tpublic id: string,\n\t\tpublic createdAt: Date = new Date(),\n\t) {}\n}\n\nexport class BrowserService extends Service {\n\tstatic serviceType = ServiceType.BROWSER;\n\tcapabilityDescription = \"Browser automation service\";\n\n\tprivate sessions = new Map<string, Session>();\n\tprivate currentSessionId: string | null = null;\n\tprivate processManager: BrowserProcessManager;\n\tprivate client: BrowserWebSocketClient;\n\tprivate isInitialized = false;\n\n\t/** Whether this service is operating in sandbox remote mode. */\n\tprivate sandboxMode = false;\n\n\tconstructor(runtime?: IAgentRuntime) {\n\t\tsuper(runtime);\n\t\tif (!runtime) {\n\t\t\tthrow new Error(\"BrowserService requires a runtime\");\n\t\t}\n\t\tthis.runtime = runtime;\n\n\t\t// Detect sandbox mode from runtime\n\t\tthis.sandboxMode = Boolean(\n\t\t\t(runtime as unknown as Record<string, unknown>).sandboxMode,\n\t\t);\n\n\t\tconst portSetting = runtime.getSetting(\"BROWSER_SERVER_PORT\");\n\t\tconst port =\n\t\t\ttypeof portSetting === \"string\" ? parseInt(portSetting, 10) : 3456;\n\n\t\t// In sandbox mode, connect to remote endpoint instead of local process\n\t\tif (this.sandboxMode) {\n\t\t\tconst remoteWsUrl =\n\t\t\t\t(runtime.getSetting(\"SANDBOX_BROWSER_WS_URL\") as string | null) ??\n\t\t\t\t`ws://localhost:${port}`;\n\t\t\tthis.processManager = new BrowserProcessManager(port);\n\t\t\tthis.client = new BrowserWebSocketClient(remoteWsUrl);\n\t\t\tlogger.info(\n\t\t\t\t`Browser service: sandbox mode, remote endpoint: ${remoteWsUrl}`,\n\t\t\t);\n\t\t} else {\n\t\t\tthis.processManager = new BrowserProcessManager(port);\n\t\t\tthis.client = new BrowserWebSocketClient(`ws://localhost:${port}`);\n\t\t}\n\t}\n\n\tstatic async start(runtime: IAgentRuntime): Promise<BrowserService> {\n\t\tlogger.info(\"Starting browser automation service\");\n\t\ttry {\n\t\t\tconst service = new BrowserService(runtime);\n\n\t\t\t// In sandbox mode, do NOT start a local browser server process\n\t\t\tif (service.sandboxMode) {\n\t\t\t\tlogger.info(\n\t\t\t\t\t\"Browser service: sandbox mode — skipping local server spawn\",\n\t\t\t\t);\n\t\t\t\tlogger.info(\"Connecting to remote browser server...\");\n\t\t\t\ttry {\n\t\t\t\t\tawait service.initialize();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\t\t\tlogger.warn(`Remote browser not reachable: ${errorMessage}`);\n\t\t\t\t\tlogger.warn(\"Browser plugin will be in degraded state\");\n\t\t\t\t}\n\t\t\t\treturn service;\n\t\t\t}\n\n\t\t\tlogger.info(\"Starting browser server process...\");\n\t\t\tlet serverStarted = false;\n\t\t\ttry {\n\t\t\t\tawait service.processManager.start();\n\t\t\t\tserverStarted = true;\n\t\t\t\tlogger.info(\"Browser server started successfully\");\n\t\t\t} catch (error) {\n\t\t\t\tconst errorMessage =\n\t\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\t\tlogger.error(`Failed to start browser server: ${errorMessage}`);\n\t\t\t\tlogger.warn(\n\t\t\t\t\t\"Browser plugin will be available but automation will not work\",\n\t\t\t\t);\n\t\t\t\tlogger.warn(\n\t\t\t\t\t\"To fix this, run: cd packages/plugin-browser && npm run build\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Only attempt WebSocket initialization if the server actually started.\n\t\t\t// Otherwise we'd retry processManager.start() inside initialize() and\n\t\t\t// throw again, which crashes service registration.\n\t\t\tif (serverStarted) {\n\t\t\t\tlogger.info(\"Initializing WebSocket client...\");\n\t\t\t\tawait service.initialize();\n\t\t\t}\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlogger.error(`Failed to start browser service: ${errorMessage}`);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tstatic async stopRuntime(runtime: IAgentRuntime): Promise<void> {\n\t\tlogger.info(\"Stopping browser automation service\");\n\t\tconst service = runtime.getService<BrowserService>(\n\t\t\tBrowserService.serviceType,\n\t\t);\n\t\tif (!service) {\n\t\t\tthrow new Error(\"Browser service not found\");\n\t\t}\n\t\tawait service.stop();\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tlogger.info(\"Cleaning up browser sessions\");\n\n\t\tfor (const sessionId of this.sessions.keys()) {\n\t\t\tawait this.destroySession(sessionId);\n\t\t}\n\n\t\tthis.client.disconnect();\n\t\tawait this.processManager.stop();\n\t\tthis.isInitialized = false;\n\t}\n\n\tasync initialize(): Promise<void> {\n\t\tif (this.isInitialized) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tif (!this.processManager.isServerRunning()) {\n\t\t\t\tlogger.warn(\"Browser server is not running, attempting to start...\");\n\t\t\t\ttry {\n\t\t\t\t\tawait this.processManager.start();\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 2000));\n\t\t\t\t} catch (startError) {\n\t\t\t\t\tconst msg =\n\t\t\t\t\t\tstartError instanceof Error\n\t\t\t\t\t\t\t? startError.message\n\t\t\t\t\t\t\t: String(startError);\n\t\t\t\t\tlogger.error(`Failed to initialize browser service: ${msg}`);\n\t\t\t\t\t// Don't throw — allow the service to exist in a degraded state\n\t\t\t\t\t// so other plugins can still function.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlogger.info(\"Connecting to browser server...\");\n\t\t\tawait this.client.connect();\n\n\t\t\tawait this.waitForReady();\n\n\t\t\tthis.isInitialized = true;\n\t\t\tlogger.info(\"Browser service initialized successfully\");\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlogger.error(`Failed to initialize browser service: ${errorMessage}`);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync createSession(sessionId: string): Promise<Session> {\n\t\tif (!this.isInitialized) {\n\t\t\tthrow new Error(\"Browser service not initialized\");\n\t\t}\n\n\t\tconst response = await this.client.sendMessage(\"createSession\", {});\n\t\tconst serverSessionId = (response.data as { sessionId?: string })\n\t\t\t?.sessionId;\n\t\tif (!serverSessionId) {\n\t\t\tthrow new Error(\"Failed to create session on server\");\n\t\t}\n\n\t\tconst session = new Session(serverSessionId);\n\t\tthis.sessions.set(sessionId, session);\n\t\tthis.currentSessionId = sessionId;\n\n\t\treturn session;\n\t}\n\n\tasync getSession(sessionId: string): Promise<Session | undefined> {\n\t\treturn this.sessions.get(sessionId);\n\t}\n\n\tasync getCurrentSession(): Promise<Session | undefined> {\n\t\tif (!this.currentSessionId) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.sessions.get(this.currentSessionId);\n\t}\n\n\tasync getOrCreateSession(): Promise<Session> {\n\t\tconst currentSession = await this.getCurrentSession();\n\t\tif (currentSession) {\n\t\t\treturn currentSession;\n\t\t}\n\n\t\tconst sessionId = `session-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n\t\treturn this.createSession(sessionId);\n\t}\n\n\tasync destroySession(sessionId: string): Promise<void> {\n\t\tconst session = this.sessions.get(sessionId);\n\t\tif (session) {\n\t\t\tawait this.client.sendMessage(\"destroySession\", {\n\t\t\t\tsessionId: session.id,\n\t\t\t});\n\t\t\tthis.sessions.delete(sessionId);\n\t\t\tif (this.currentSessionId === sessionId) {\n\t\t\t\tthis.currentSessionId = null;\n\t\t\t}\n\t\t}\n\t}\n\n\tgetClient(): BrowserWebSocketClient {\n\t\tif (!this.isInitialized) {\n\t\t\tthrow new Error(\"Browser service not initialized\");\n\t\t}\n\t\treturn this.client;\n\t}\n\n\tprivate async waitForReady(maxAttempts = 60, delayMs = 3000): Promise<void> {\n\t\tlogger.info(\"Waiting for browser server to be ready...\");\n\n\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\ttry {\n\t\t\t\tconst isHealthy = await this.client.health();\n\t\t\t\tif (isHealthy) {\n\t\t\t\t\tlogger.info(\"Browser server is ready\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst errorMessage =\n\t\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\t\tlogger.debug(\n\t\t\t\t\t`Health check attempt ${attempt}/${maxAttempts} failed: ${errorMessage}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (attempt < maxAttempts) {\n\t\t\t\tlogger.info(\n\t\t\t\t\t`Server not ready yet, retrying in ${delayMs / 1000}s... (attempt ${attempt}/${maxAttempts})`,\n\t\t\t\t);\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, delayMs));\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Browser server did not become ready after ${maxAttempts} attempts`,\n\t\t);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/services/process-manager.ts"],"names":[],"mappings":"AAQA,qBAAa,qBAAqB;
|
|
1
|
+
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/services/process-manager.ts"],"names":[],"mappings":"AAQA,qBAAa,qBAAqB;IAKrB,OAAO,CAAC,UAAU;IAJ9B,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAuB;gBAErB,UAAU,GAAE,MAAa;IAI7C,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,UAAU;IAyDlB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAuC3B;;;OAGG;YACW,QAAQ;IA4BhB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAuHtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB3B,eAAe,IAAI,OAAO;IAI1B,YAAY,IAAI,MAAM;CAGtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-manager.js","sourceRoot":"","sources":["../../src/services/process-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA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import { existsSync } from \"node:fs\";\nimport { platform } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { logger } from \"@elizaos/core\";\nimport WebSocket from \"ws\";\n\nexport class BrowserProcessManager {\n private process: ChildProcess | null = null;\n private isRunning = false;\n private binaryPath: string | null = null;\n\n constructor(private serverPort: number = 3456) {\n this.binaryPath = this.findBinary();\n }\n\n private getBinaryName(): { primary: string; fallback: string } {\n const platformName = platform();\n const arch = process.arch;\n const ext = platformName === \"win32\" ? \".exe\" : \"\";\n\n return {\n primary: `browser-server-${platformName}-${arch}${ext}`,\n fallback: `browser-server-${platformName}${ext}`,\n };\n }\n\n private findBinary(): string | null {\n const moduleDir = dirname(fileURLToPath(import.meta.url));\n const isDocker =\n process.env.DOCKER_CONTAINER === \"true\" || existsSync(\"/.dockerenv\");\n const binaryNames = this.getBinaryName();\n\n const possiblePaths = [\n ...(isDocker\n ? [\n \"/usr/local/bin/browser-server\",\n \"/usr/local/bin/browser-server-linux\",\n \"/app/browser-server\",\n `/app/binaries/${binaryNames.primary}`,\n `/app/binaries/${binaryNames.fallback}`,\n ]\n : []),\n\n ...(!isDocker ? [join(moduleDir, \"../server/dist/index.js\")] : []),\n join(moduleDir, \"../server/binaries\", binaryNames.primary),\n join(moduleDir, \"../server/binaries\", binaryNames.fallback),\n join(moduleDir, \"../../../browser-server\", binaryNames.primary),\n join(moduleDir, \"../../../browser-server\", binaryNames.fallback),\n join(moduleDir, \"../../.bin\", \"browser-server\"),\n join(moduleDir, \"../server/dist/index.js\"),\n\n ...(isDocker\n ? [\n \"/app/packages/plugin-browser/server/dist/index.js\",\n \"/app/browser-server/dist/index.js\",\n ]\n : []),\n ];\n\n for (const p of possiblePaths) {\n if (existsSync(p)) {\n logger.info(`Found browser server at: ${p}`);\n return p;\n }\n }\n\n const srcPath = join(moduleDir, \"../server/src/index.ts\");\n if (existsSync(srcPath)) {\n logger.warn(\n \"No compiled binary found, will try to run from source with tsx\",\n );\n return srcPath;\n }\n\n logger.error(\"Could not find browser server binary or source files\");\n logger.error(`Searched paths: ${possiblePaths.join(\", \")}`);\n return null;\n }\n\n // ---------------------------------------------------------------------------\n // Port management\n // ---------------------------------------------------------------------------\n\n /**\n * Probe the port for an existing stagehand-server.\n * Returns `true` if a WebSocket server is already listening and responds.\n */\n private probeExistingServer(): Promise<boolean> {\n return new Promise((resolve) => {\n const timeout = setTimeout(() => {\n conn.close();\n resolve(false);\n }, 2_000);\n\n const conn = new WebSocket(`ws://localhost:${this.serverPort}`);\n\n conn.on(\"message\", (data) => {\n try {\n const msg = JSON.parse(data.toString());\n // The stagehand-server sends { type: \"connected\", ... } on connect.\n if (msg.type === \"connected\") {\n clearTimeout(timeout);\n conn.close();\n resolve(true);\n return;\n }\n } catch {\n // Not valid JSON — not our server.\n }\n clearTimeout(timeout);\n conn.close();\n resolve(false);\n });\n\n conn.on(\"open\", () => {\n // Connection opened — wait for the \"connected\" message (handled above).\n // If no message arrives within the timeout, we'll resolve(false).\n });\n\n conn.on(\"error\", () => {\n clearTimeout(timeout);\n resolve(false);\n });\n });\n }\n\n /**\n * Kill whatever process is listening on `this.serverPort`.\n * Uses `lsof` on Unix / `netstat` on Windows. Best-effort.\n */\n private async freePort(): Promise<void> {\n const port = this.serverPort;\n try {\n if (process.platform === \"win32\") {\n // netstat → find PID → taskkill\n const out = execSync(\n `netstat -ano | findstr :${port} | findstr LISTENING`,\n { encoding: \"utf8\", stdio: [\"pipe\", \"pipe\", \"ignore\"] },\n );\n const pid = out.trim().split(/\\s+/).pop();\n if (pid && /^\\d+$/.test(pid)) {\n execSync(`taskkill /F /PID ${pid}`, { stdio: \"ignore\" });\n }\n } else {\n execSync(`lsof -ti :${port} | xargs kill -9`, { stdio: \"ignore\" });\n }\n // Give the OS a moment to release the port.\n await new Promise((r) => setTimeout(r, 500));\n logger.info(`Freed port ${port}`);\n } catch {\n // Nothing on the port, or kill failed — either way it's fine.\n }\n }\n\n // ---------------------------------------------------------------------------\n // Start / stop\n // ---------------------------------------------------------------------------\n\n async start(): Promise<void> {\n if (this.isRunning) {\n logger.warn(\"Browser server is already running\");\n return;\n }\n\n // ── 1. Check for an existing stagehand-server on the port ──────────────\n if (await this.probeExistingServer()) {\n logger.info(\n `Reusing existing browser server on port ${this.serverPort}`,\n );\n this.isRunning = true;\n return;\n }\n\n // ── 2. Something else is on the port — try to free it ──────────────────\n await this.freePort();\n\n // ── 3. Spawn a new server ──────────────────────────────────────────────\n if (!this.binaryPath) {\n throw new Error(\n \"Browser server binary not found - please ensure server is built\",\n );\n }\n\n const binaryPath = this.binaryPath;\n\n return new Promise((resolve, reject) => {\n let settled = false;\n const startupTimeout = setTimeout(() => {\n if (!settled) {\n settled = true;\n if (this.process) this.process.kill(\"SIGTERM\");\n reject(new Error(\"Browser server startup timed out after 30s\"));\n }\n }, 30_000);\n const ok = () => {\n if (!settled) {\n settled = true;\n clearTimeout(startupTimeout);\n resolve();\n }\n };\n const fail = (err: Error) => {\n if (!settled) {\n settled = true;\n clearTimeout(startupTimeout);\n reject(err);\n }\n };\n\n // Pass through the parent env as-is; only override port + NODE_ENV.\n const env: Record<string, string | undefined> = {\n ...process.env,\n BROWSER_SERVER_PORT: this.serverPort.toString(),\n NODE_ENV: process.env.NODE_ENV ?? \"production\",\n };\n\n const isBinary =\n !binaryPath.endsWith(\".js\") && !binaryPath.endsWith(\".ts\");\n const isTypeScript = binaryPath.endsWith(\".ts\");\n\n if (isBinary) {\n this.process = spawn(binaryPath, [], { env });\n } else if (isTypeScript) {\n try {\n const tsxPath = require.resolve(\"tsx/cli\", {\n paths: [process.cwd()],\n });\n this.process = spawn(\"node\", [tsxPath, binaryPath], { env });\n } catch {\n logger.warn(\n \"tsx not found, falling back to node --import tsx\",\n );\n this.process = spawn(\"node\", [\"--import\", \"tsx\", binaryPath], {\n env,\n });\n }\n } else {\n this.process = spawn(\"node\", [binaryPath], { env });\n }\n\n this.process.stdout?.on(\"data\", (data: Buffer) => {\n const message = data.toString().trim();\n logger.debug(`[BrowserServer] ${message}`);\n\n if (message.includes(\"listening on port\")) {\n this.isRunning = true;\n ok();\n }\n });\n\n this.process.stderr?.on(\"data\", (data: Buffer) => {\n const text = data.toString().trim();\n if (\n text.includes(\"Error\") ||\n text.includes(\"EADDRINUSE\") ||\n text.includes(\"FATAL\")\n ) {\n logger.error(`[BrowserServer] ${text}`);\n } else {\n logger.debug(`[BrowserServer stderr] ${text}`);\n }\n });\n\n this.process.on(\"error\", (error: Error) => {\n logger.error(`Failed to start browser server: ${error.message}`);\n this.isRunning = false;\n fail(error);\n });\n\n this.process.on(\"exit\", (code) => {\n this.isRunning = false;\n if (code !== 0 && code !== null) {\n logger.warn(`Browser server exited with code ${code}`);\n fail(new Error(`Browser server exited with code ${code}`));\n } else {\n logger.info(\"Browser server stopped\");\n }\n });\n });\n }\n\n async stop(): Promise<void> {\n if (!this.process || !this.isRunning) {\n return;\n }\n\n return new Promise((resolve) => {\n this.process?.on(\"exit\", () => {\n this.isRunning = false;\n resolve();\n });\n\n this.process?.kill(\"SIGTERM\");\n\n setTimeout(() => {\n if (this.isRunning && this.process) {\n this.process.kill(\"SIGKILL\");\n }\n }, 5000);\n });\n }\n\n isServerRunning(): boolean {\n return this.isRunning;\n }\n\n getServerUrl(): string {\n return `ws://localhost:${this.serverPort}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"process-manager.js","sourceRoot":"","sources":["../../src/services/process-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,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I,KAAK,IAAI,EAAE,CAAC;oBACjC,MAAM,CAAC,IAAI,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAC;oBACvD,IAAI,CAAC,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAC5D,CAAC;qBAAM,CAAC;oBACP,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;gBACvC,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,OAAO;QACR,CAAC;QAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;gBAC7B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;gBACvB,OAAO,EAAE,CAAC;YACX,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAE9B,UAAU,CAAC,GAAG,EAAE;gBACf,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACpC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC9B,CAAC;YACF,CAAC,EAAE,IAAI,CAAC,CAAC;QACV,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,eAAe;QACd,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,YAAY;QACX,OAAO,kBAAkB,IAAI,CAAC,UAAU,EAAE,CAAC;IAC5C,CAAC;CACD","sourcesContent":["import { type ChildProcess, execSync, spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { platform } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { logger } from \"@elizaos/core\";\nimport WebSocket from \"ws\";\n\nexport class BrowserProcessManager {\n\tprivate process: ChildProcess | null = null;\n\tprivate isRunning = false;\n\tprivate binaryPath: string | null = null;\n\n\tconstructor(private serverPort: number = 3456) {\n\t\tthis.binaryPath = this.findBinary();\n\t}\n\n\tprivate getBinaryName(): { primary: string; fallback: string } {\n\t\tconst platformName = platform();\n\t\tconst arch = process.arch;\n\t\tconst ext = platformName === \"win32\" ? \".exe\" : \"\";\n\n\t\treturn {\n\t\t\tprimary: `browser-server-${platformName}-${arch}${ext}`,\n\t\t\tfallback: `browser-server-${platformName}${ext}`,\n\t\t};\n\t}\n\n\tprivate findBinary(): string | null {\n\t\tconst moduleDir = dirname(fileURLToPath(import.meta.url));\n\t\tconst isDocker =\n\t\t\tprocess.env.DOCKER_CONTAINER === \"true\" || existsSync(\"/.dockerenv\");\n\t\tconst binaryNames = this.getBinaryName();\n\n\t\tconst possiblePaths = [\n\t\t\t...(isDocker\n\t\t\t\t? [\n\t\t\t\t\t\t\"/usr/local/bin/browser-server\",\n\t\t\t\t\t\t\"/usr/local/bin/browser-server-linux\",\n\t\t\t\t\t\t\"/app/browser-server\",\n\t\t\t\t\t\t`/app/binaries/${binaryNames.primary}`,\n\t\t\t\t\t\t`/app/binaries/${binaryNames.fallback}`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\n\t\t\t...(!isDocker ? [join(moduleDir, \"../server/dist/index.js\")] : []),\n\t\t\tjoin(moduleDir, \"../server/binaries\", binaryNames.primary),\n\t\t\tjoin(moduleDir, \"../server/binaries\", binaryNames.fallback),\n\t\t\tjoin(moduleDir, \"../../../browser-server\", binaryNames.primary),\n\t\t\tjoin(moduleDir, \"../../../browser-server\", binaryNames.fallback),\n\t\t\tjoin(moduleDir, \"../../.bin\", \"browser-server\"),\n\t\t\tjoin(moduleDir, \"../server/dist/index.js\"),\n\n\t\t\t...(isDocker\n\t\t\t\t? [\n\t\t\t\t\t\t\"/app/packages/plugin-browser/server/dist/index.js\",\n\t\t\t\t\t\t\"/app/browser-server/dist/index.js\",\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t];\n\n\t\tfor (const p of possiblePaths) {\n\t\t\tif (existsSync(p)) {\n\t\t\t\tlogger.info(`Found browser server at: ${p}`);\n\t\t\t\treturn p;\n\t\t\t}\n\t\t}\n\n\t\tconst srcPath = join(moduleDir, \"../server/src/index.ts\");\n\t\tif (existsSync(srcPath)) {\n\t\t\tlogger.warn(\n\t\t\t\t\"No compiled binary found, will try to run from source with tsx\",\n\t\t\t);\n\t\t\treturn srcPath;\n\t\t}\n\n\t\tlogger.error(\"Could not find browser server binary or source files\");\n\t\tlogger.error(`Searched paths: ${possiblePaths.join(\", \")}`);\n\t\treturn null;\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Port management\n\t// ---------------------------------------------------------------------------\n\n\t/**\n\t * Probe the port for an existing stagehand-server.\n\t * Returns `true` if a WebSocket server is already listening and responds.\n\t */\n\tprivate probeExistingServer(): Promise<boolean> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tconn.close();\n\t\t\t\tresolve(false);\n\t\t\t}, 2_000);\n\n\t\t\tconst conn = new WebSocket(`ws://localhost:${this.serverPort}`);\n\n\t\t\tconn.on(\"message\", (data) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst msg = JSON.parse(data.toString());\n\t\t\t\t\t// The stagehand-server sends { type: \"connected\", ... } on connect.\n\t\t\t\t\tif (msg.type === \"connected\") {\n\t\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\t\tconn.close();\n\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Not valid JSON — not our server.\n\t\t\t\t}\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tconn.close();\n\t\t\t\tresolve(false);\n\t\t\t});\n\n\t\t\tconn.on(\"open\", () => {\n\t\t\t\t// Connection opened — wait for the \"connected\" message (handled above).\n\t\t\t\t// If no message arrives within the timeout, we'll resolve(false).\n\t\t\t});\n\n\t\t\tconn.on(\"error\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve(false);\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Kill whatever process is listening on `this.serverPort`.\n\t * Uses `lsof` on Unix / `netstat` on Windows. Best-effort.\n\t */\n\tprivate async freePort(): Promise<void> {\n\t\tconst port = this.serverPort;\n\t\ttry {\n\t\t\tif (process.platform === \"win32\") {\n\t\t\t\t// netstat → find PID → taskkill\n\t\t\t\tconst out = execSync(\n\t\t\t\t\t`netstat -ano | findstr :${port} | findstr LISTENING`,\n\t\t\t\t\t{ encoding: \"utf8\", stdio: [\"pipe\", \"pipe\", \"ignore\"] },\n\t\t\t\t);\n\t\t\t\tconst pid = out.trim().split(/\\s+/).pop();\n\t\t\t\tif (pid && /^\\d+$/.test(pid)) {\n\t\t\t\t\texecSync(`taskkill /F /PID ${pid}`, { stdio: \"ignore\" });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\texecSync(`lsof -ti :${port} | xargs kill -9`, { stdio: \"ignore\" });\n\t\t\t}\n\t\t\t// Give the OS a moment to release the port.\n\t\t\tawait new Promise((r) => setTimeout(r, 500));\n\t\t\tlogger.info(`Freed port ${port}`);\n\t\t} catch {\n\t\t\t// Nothing on the port, or kill failed — either way it's fine.\n\t\t}\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Start / stop\n\t// ---------------------------------------------------------------------------\n\n\tasync start(): Promise<void> {\n\t\tif (this.isRunning) {\n\t\t\tlogger.warn(\"Browser server is already running\");\n\t\t\treturn;\n\t\t}\n\n\t\t// ── 1. Check for an existing stagehand-server on the port ──────────────\n\t\tif (await this.probeExistingServer()) {\n\t\t\tlogger.info(`Reusing existing browser server on port ${this.serverPort}`);\n\t\t\tthis.isRunning = true;\n\t\t\treturn;\n\t\t}\n\n\t\t// ── 2. Something else is on the port — try to free it ──────────────────\n\t\tawait this.freePort();\n\n\t\t// ── 3. Spawn a new server ──────────────────────────────────────────────\n\t\tif (!this.binaryPath) {\n\t\t\tthrow new Error(\n\t\t\t\t\"Browser server binary not found - please ensure server is built\",\n\t\t\t);\n\t\t}\n\n\t\tconst binaryPath = this.binaryPath;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet settled = false;\n\t\t\tconst startupTimeout = setTimeout(() => {\n\t\t\t\tif (!settled) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tif (this.process) this.process.kill(\"SIGTERM\");\n\t\t\t\t\treject(new Error(\"Browser server startup timed out after 30s\"));\n\t\t\t\t}\n\t\t\t}, 30_000);\n\t\t\tconst ok = () => {\n\t\t\t\tif (!settled) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tclearTimeout(startupTimeout);\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst fail = (err: Error) => {\n\t\t\t\tif (!settled) {\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tclearTimeout(startupTimeout);\n\t\t\t\t\treject(err);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Pass through the parent env as-is; only override port + NODE_ENV.\n\t\t\tconst env: Record<string, string | undefined> = {\n\t\t\t\t...process.env,\n\t\t\t\tBROWSER_SERVER_PORT: this.serverPort.toString(),\n\t\t\t\tNODE_ENV: process.env.NODE_ENV ?? \"production\",\n\t\t\t};\n\n\t\t\tconst isBinary =\n\t\t\t\t!binaryPath.endsWith(\".js\") && !binaryPath.endsWith(\".ts\");\n\t\t\tconst isTypeScript = binaryPath.endsWith(\".ts\");\n\n\t\t\tif (isBinary) {\n\t\t\t\tthis.process = spawn(binaryPath, [], { env });\n\t\t\t} else if (isTypeScript) {\n\t\t\t\ttry {\n\t\t\t\t\tconst tsxPath = require.resolve(\"tsx/cli\", {\n\t\t\t\t\t\tpaths: [process.cwd()],\n\t\t\t\t\t});\n\t\t\t\t\tthis.process = spawn(\"node\", [tsxPath, binaryPath], { env });\n\t\t\t\t} catch {\n\t\t\t\t\tlogger.warn(\"tsx not found, falling back to node --import tsx\");\n\t\t\t\t\tthis.process = spawn(\"node\", [\"--import\", \"tsx\", binaryPath], {\n\t\t\t\t\t\tenv,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.process = spawn(\"node\", [binaryPath], { env });\n\t\t\t}\n\n\t\t\tthis.process.stdout?.on(\"data\", (data: Buffer) => {\n\t\t\t\tconst message = data.toString().trim();\n\t\t\t\tlogger.debug(`[BrowserServer] ${message}`);\n\n\t\t\t\tif (message.includes(\"listening on port\")) {\n\t\t\t\t\tthis.isRunning = true;\n\t\t\t\t\tok();\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis.process.stderr?.on(\"data\", (data: Buffer) => {\n\t\t\t\tconst text = data.toString().trim();\n\t\t\t\tif (\n\t\t\t\t\ttext.includes(\"Error\") ||\n\t\t\t\t\ttext.includes(\"EADDRINUSE\") ||\n\t\t\t\t\ttext.includes(\"FATAL\")\n\t\t\t\t) {\n\t\t\t\t\tlogger.error(`[BrowserServer] ${text}`);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.debug(`[BrowserServer stderr] ${text}`);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis.process.on(\"error\", (error: Error) => {\n\t\t\t\tlogger.error(`Failed to start browser server: ${error.message}`);\n\t\t\t\tthis.isRunning = false;\n\t\t\t\tfail(error);\n\t\t\t});\n\n\t\t\tthis.process.on(\"exit\", (code) => {\n\t\t\t\tthis.isRunning = false;\n\t\t\t\tif (code !== 0 && code !== null) {\n\t\t\t\t\tlogger.warn(`Browser server exited with code ${code}`);\n\t\t\t\t\tfail(new Error(`Browser server exited with code ${code}`));\n\t\t\t\t} else {\n\t\t\t\t\tlogger.info(\"Browser server stopped\");\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tif (!this.process || !this.isRunning) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn new Promise((resolve) => {\n\t\t\tthis.process?.on(\"exit\", () => {\n\t\t\t\tthis.isRunning = false;\n\t\t\t\tresolve();\n\t\t\t});\n\n\t\t\tthis.process?.kill(\"SIGTERM\");\n\n\t\t\tsetTimeout(() => {\n\t\t\t\tif (this.isRunning && this.process) {\n\t\t\t\t\tthis.process.kill(\"SIGKILL\");\n\t\t\t\t}\n\t\t\t}, 5000);\n\t\t});\n\t}\n\n\tisServerRunning(): boolean {\n\t\treturn this.isRunning;\n\t}\n\n\tgetServerUrl(): string {\n\t\treturn `ws://localhost:${this.serverPort}`;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-client.d.ts","sourceRoot":"","sources":["../../src/services/websocket-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"websocket-client.d.ts","sourceRoot":"","sources":["../../src/services/websocket-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gBAAgB,EAEhB,iBAAiB,EACjB,MAAM,aAAa,CAAC;AAIrB,qBAAa,sBAAsB;IAQtB,OAAO,CAAC,SAAS;IAP7B,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,eAAe,CAAqC;IAC5D,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,cAAc,CAAQ;gBAEV,SAAS,EAAE,MAAM;IAE/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2D9B,OAAO,CAAC,eAAe;YAgBT,gBAAgB;IAmBxB,WAAW,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC,iBAAiB,CAAC;IAgC7B,UAAU,IAAI,IAAI;IAUlB,WAAW,IAAI,OAAO;IAIhB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAanE,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAC1C,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,IAAI,CAAC;KAChB,CAAC;IAWI,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUpD,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUvD,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUrD,KAAK,CACV,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC;IAOvB,IAAI,CACT,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,iBAAiB,CAAC;IAOvB,MAAM,CACX,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC;IAOvB,OAAO,CACZ,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC;IAOvB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIzD,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI3D,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;CAchC"}
|
|
@@ -25,7 +25,8 @@ export class BrowserWebSocketClient {
|
|
|
25
25
|
try {
|
|
26
26
|
const messageText = this.rawDataToString(data);
|
|
27
27
|
const message = JSON.parse(messageText);
|
|
28
|
-
if (message.requestId &&
|
|
28
|
+
if (message.requestId &&
|
|
29
|
+
this.messageHandlers.has(message.requestId)) {
|
|
29
30
|
const handler = this.messageHandlers.get(message.requestId);
|
|
30
31
|
this.messageHandlers.delete(message.requestId);
|
|
31
32
|
handler?.(message);
|
|
@@ -207,7 +208,8 @@ export class BrowserWebSocketClient {
|
|
|
207
208
|
async health() {
|
|
208
209
|
try {
|
|
209
210
|
const response = await this.sendMessage("health", {});
|
|
210
|
-
return response.type === "health" &&
|
|
211
|
+
return (response.type === "health" &&
|
|
212
|
+
response.data?.status === "ok");
|
|
211
213
|
}
|
|
212
214
|
catch (error) {
|
|
213
215
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-client.js","sourceRoot":"","sources":["../../src/services/websocket-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,SAAS,MAAM,IAAI,CAAC;AAK3B,MAAM,OAAO,sBAAsB;IAQb;IAPZ,EAAE,GAAqB,IAAI,CAAC;IAC5B,eAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;IACpD,SAAS,GAAG,KAAK,CAAC;IAClB,iBAAiB,GAAG,CAAC,CAAC;IACtB,oBAAoB,GAAG,CAAC,CAAC;IACzB,cAAc,GAAG,IAAI,CAAC;IAE9B,YAAoB,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IAEzC,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC;gBACH,IAAI,CAAC,EAAE,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAExC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;oBACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;oBACtB,IAAI,CAAC,iBAAiB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ACT,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,SAAiB,EAAE,WAAmB;QAClD,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE;YACvC,SAAS;YACT,IAAI,EAAE,EAAE,WAAW,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,SAAiB;QAChC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,SAAiB;QAClC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAK,QAAQ,CAAC,IAA2B,EAAE,MAAM,KAAK,IAAI,CAAC;QAC9F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5E,MAAM,CAAC,KAAK,CAAC,kCAAkC,YAAY,EAAE,CAAC,CAAC;YAC/D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF","sourcesContent":["import { logger } from \"@elizaos/core\";\nimport WebSocket from \"ws\";\nimport type { NavigationResult, WebSocketMessage, WebSocketResponse } from \"../types.js\";\n\ntype MessageHandler = (response: WebSocketResponse) => void;\n\nexport class BrowserWebSocketClient {\n private ws: WebSocket | null = null;\n private messageHandlers = new Map<string, MessageHandler>();\n private connected = false;\n private reconnectAttempts = 0;\n private maxReconnectAttempts = 5;\n private reconnectDelay = 1000;\n\n constructor(private serverUrl: string) {}\n\n async connect(): Promise<void> {\n return new Promise((resolve, reject) => {\n try {\n this.ws = new WebSocket(this.serverUrl);\n\n this.ws.on(\"open\", () => {\n this.connected = true;\n this.reconnectAttempts = 0;\n logger.info(`[Browser] Connected to server at ${this.serverUrl}`);\n resolve();\n });\n\n this.ws.on(\"message\", (data: WebSocket.RawData) => {\n try {\n const messageText = this.rawDataToString(data);\n const message = JSON.parse(messageText) as WebSocketResponse;\n\n if (message.requestId && this.messageHandlers.has(message.requestId)) {\n const handler = this.messageHandlers.get(message.requestId);\n this.messageHandlers.delete(message.requestId);\n handler?.(message);\n }\n\n if (message.type === \"connected\") {\n logger.info(`[Browser] Server connected: ${JSON.stringify(message)}`);\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`[Browser] Error parsing message: ${errorMessage}`);\n }\n });\n\n this.ws.on(\"error\", (error: Error) => {\n logger.error(`[Browser] WebSocket error: ${error.message}`);\n if (!this.connected) {\n reject(error);\n }\n });\n\n this.ws.on(\"close\", () => {\n this.connected = false;\n logger.info(\"[Browser] Disconnected from server\");\n\n if (this.ws && this.reconnectAttempts < this.maxReconnectAttempts) {\n this.attemptReconnect();\n }\n });\n } catch (error) {\n reject(error);\n }\n });\n }\n\n private rawDataToString(data: WebSocket.RawData): string {\n if (typeof data === \"string\") {\n return data;\n }\n if (Buffer.isBuffer(data)) {\n return data.toString(\"utf8\");\n }\n if (data instanceof ArrayBuffer) {\n return Buffer.from(data).toString(\"utf8\");\n }\n if (Array.isArray(data)) {\n return Buffer.concat(data).toString(\"utf8\");\n }\n return String(data);\n }\n\n private async attemptReconnect(): Promise<void> {\n this.reconnectAttempts++;\n logger.info(\n `[Browser] Attempting reconnection ${this.reconnectAttempts}/${this.maxReconnectAttempts}...`\n );\n\n await new Promise((resolve) =>\n setTimeout(resolve, this.reconnectDelay * this.reconnectAttempts)\n );\n\n try {\n await this.connect();\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`[Browser] Reconnection failed: ${errorMessage}`);\n }\n }\n\n async sendMessage(type: string, data: Record<string, unknown>): Promise<WebSocketResponse> {\n if (!this.ws || !this.connected) {\n throw new Error(\"Not connected to browser server\");\n }\n\n const requestId = `req-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n const message: WebSocketMessage = {\n type,\n requestId,\n ...data,\n };\n\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n this.messageHandlers.delete(requestId);\n reject(new Error(`Request timeout for ${type}`));\n }, 30000);\n\n this.messageHandlers.set(requestId, (response) => {\n clearTimeout(timeout);\n if (response.type === \"error\") {\n reject(new Error(response.error ?? \"Unknown error\"));\n } else {\n resolve(response);\n }\n });\n\n this.ws?.send(JSON.stringify(message));\n logger.debug(`[Browser] Sent message: ${type} (${requestId})`);\n });\n }\n\n disconnect(): void {\n this.reconnectAttempts = this.maxReconnectAttempts;\n if (this.ws) {\n this.ws.close();\n this.ws = null;\n }\n this.connected = false;\n logger.info(\"[Browser] Client disconnected\");\n }\n\n isConnected(): boolean {\n return this.connected;\n }\n\n async navigate(sessionId: string, url: string): Promise<NavigationResult> {\n const response = await this.sendMessage(\"navigate\", {\n sessionId,\n data: { url },\n });\n const data = response.data as Record<string, unknown> | undefined;\n return {\n success: Boolean(data?.success),\n url: String(data?.url ?? url),\n title: String(data?.title ?? \"\"),\n };\n }\n\n async getState(\n sessionId: string\n ): Promise<{ url: string; title: string; sessionId: string; createdAt: Date }> {\n const response = await this.sendMessage(\"getState\", { sessionId });\n const data = response.data as Record<string, unknown> | undefined;\n return {\n url: String(data?.url ?? \"\"),\n title: String(data?.title ?? \"\"),\n sessionId,\n createdAt: new Date(),\n };\n }\n\n async goBack(sessionId: string): Promise<NavigationResult> {\n const response = await this.sendMessage(\"goBack\", { sessionId });\n const data = response.data as Record<string, unknown> | undefined;\n return {\n success: Boolean(data?.success ?? true),\n url: String(data?.url ?? \"\"),\n title: String(data?.title ?? \"\"),\n };\n }\n\n async goForward(sessionId: string): Promise<NavigationResult> {\n const response = await this.sendMessage(\"goForward\", { sessionId });\n const data = response.data as Record<string, unknown> | undefined;\n return {\n success: Boolean(data?.success ?? true),\n url: String(data?.url ?? \"\"),\n title: String(data?.title ?? \"\"),\n };\n }\n\n async refresh(sessionId: string): Promise<NavigationResult> {\n const response = await this.sendMessage(\"refresh\", { sessionId });\n const data = response.data as Record<string, unknown> | undefined;\n return {\n success: Boolean(data?.success ?? true),\n url: String(data?.url ?? \"\"),\n title: String(data?.title ?? \"\"),\n };\n }\n\n async click(sessionId: string, description: string): Promise<WebSocketResponse> {\n return await this.sendMessage(\"click\", {\n sessionId,\n data: { description },\n });\n }\n\n async type(sessionId: string, text: string, field: string): Promise<WebSocketResponse> {\n return await this.sendMessage(\"type\", {\n sessionId,\n data: { text, field },\n });\n }\n\n async select(sessionId: string, option: string, dropdown: string): Promise<WebSocketResponse> {\n return await this.sendMessage(\"select\", {\n sessionId,\n data: { option, dropdown },\n });\n }\n\n async extract(sessionId: string, instruction: string): Promise<WebSocketResponse> {\n return await this.sendMessage(\"extract\", {\n sessionId,\n data: { instruction },\n });\n }\n\n async screenshot(sessionId: string): Promise<WebSocketResponse> {\n return await this.sendMessage(\"screenshot\", { sessionId });\n }\n\n async solveCaptcha(sessionId: string): Promise<WebSocketResponse> {\n return await this.sendMessage(\"solveCaptcha\", { sessionId });\n }\n\n async health(): Promise<boolean> {\n try {\n const response = await this.sendMessage(\"health\", {});\n return response.type === \"health\" && (response.data as { status: string })?.status === \"ok\";\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n logger.error(`[Browser] Health check failed: ${errorMessage}`);\n return false;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"websocket-client.js","sourceRoot":"","sources":["../../src/services/websocket-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAA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C;YACJ,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtD,OAAO,CACN,QAAQ,CAAC,IAAI,KAAK,QAAQ;gBACzB,QAAQ,CAAC,IAA2B,EAAE,MAAM,KAAK,IAAI,CACtD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,YAAY,GACjB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACxD,MAAM,CAAC,KAAK,CAAC,kCAAkC,YAAY,EAAE,CAAC,CAAC;YAC/D,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;CACD","sourcesContent":["import { logger } from \"@elizaos/core\";\nimport WebSocket from \"ws\";\nimport type {\n\tNavigationResult,\n\tWebSocketMessage,\n\tWebSocketResponse,\n} from \"../types.js\";\n\ntype MessageHandler = (response: WebSocketResponse) => void;\n\nexport class BrowserWebSocketClient {\n\tprivate ws: WebSocket | null = null;\n\tprivate messageHandlers = new Map<string, MessageHandler>();\n\tprivate connected = false;\n\tprivate reconnectAttempts = 0;\n\tprivate maxReconnectAttempts = 5;\n\tprivate reconnectDelay = 1000;\n\n\tconstructor(private serverUrl: string) {}\n\n\tasync connect(): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tthis.ws = new WebSocket(this.serverUrl);\n\n\t\t\t\tthis.ws.on(\"open\", () => {\n\t\t\t\t\tthis.connected = true;\n\t\t\t\t\tthis.reconnectAttempts = 0;\n\t\t\t\t\tlogger.info(`[Browser] Connected to server at ${this.serverUrl}`);\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\n\t\t\t\tthis.ws.on(\"message\", (data: WebSocket.RawData) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst messageText = this.rawDataToString(data);\n\t\t\t\t\t\tconst message = JSON.parse(messageText) as WebSocketResponse;\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tmessage.requestId &&\n\t\t\t\t\t\t\tthis.messageHandlers.has(message.requestId)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconst handler = this.messageHandlers.get(message.requestId);\n\t\t\t\t\t\t\tthis.messageHandlers.delete(message.requestId);\n\t\t\t\t\t\t\thandler?.(message);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (message.type === \"connected\") {\n\t\t\t\t\t\t\tlogger.info(\n\t\t\t\t\t\t\t\t`[Browser] Server connected: ${JSON.stringify(message)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\t\t\t\tlogger.error(`[Browser] Error parsing message: ${errorMessage}`);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tthis.ws.on(\"error\", (error: Error) => {\n\t\t\t\t\tlogger.error(`[Browser] WebSocket error: ${error.message}`);\n\t\t\t\t\tif (!this.connected) {\n\t\t\t\t\t\treject(error);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tthis.ws.on(\"close\", () => {\n\t\t\t\t\tthis.connected = false;\n\t\t\t\t\tlogger.info(\"[Browser] Disconnected from server\");\n\n\t\t\t\t\tif (this.ws && this.reconnectAttempts < this.maxReconnectAttempts) {\n\t\t\t\t\t\tthis.attemptReconnect();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate rawDataToString(data: WebSocket.RawData): string {\n\t\tif (typeof data === \"string\") {\n\t\t\treturn data;\n\t\t}\n\t\tif (Buffer.isBuffer(data)) {\n\t\t\treturn data.toString(\"utf8\");\n\t\t}\n\t\tif (data instanceof ArrayBuffer) {\n\t\t\treturn Buffer.from(data).toString(\"utf8\");\n\t\t}\n\t\tif (Array.isArray(data)) {\n\t\t\treturn Buffer.concat(data).toString(\"utf8\");\n\t\t}\n\t\treturn String(data);\n\t}\n\n\tprivate async attemptReconnect(): Promise<void> {\n\t\tthis.reconnectAttempts++;\n\t\tlogger.info(\n\t\t\t`[Browser] Attempting reconnection ${this.reconnectAttempts}/${this.maxReconnectAttempts}...`,\n\t\t);\n\n\t\tawait new Promise((resolve) =>\n\t\t\tsetTimeout(resolve, this.reconnectDelay * this.reconnectAttempts),\n\t\t);\n\n\t\ttry {\n\t\t\tawait this.connect();\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlogger.error(`[Browser] Reconnection failed: ${errorMessage}`);\n\t\t}\n\t}\n\n\tasync sendMessage(\n\t\ttype: string,\n\t\tdata: Record<string, unknown>,\n\t): Promise<WebSocketResponse> {\n\t\tif (!this.ws || !this.connected) {\n\t\t\tthrow new Error(\"Not connected to browser server\");\n\t\t}\n\n\t\tconst requestId = `req-${Date.now()}-${Math.random().toString(36).substring(7)}`;\n\t\tconst message: WebSocketMessage = {\n\t\t\ttype,\n\t\t\trequestId,\n\t\t\t...data,\n\t\t};\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.messageHandlers.delete(requestId);\n\t\t\t\treject(new Error(`Request timeout for ${type}`));\n\t\t\t}, 30000);\n\n\t\t\tthis.messageHandlers.set(requestId, (response) => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tif (response.type === \"error\") {\n\t\t\t\t\treject(new Error(response.error ?? \"Unknown error\"));\n\t\t\t\t} else {\n\t\t\t\t\tresolve(response);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis.ws?.send(JSON.stringify(message));\n\t\t\tlogger.debug(`[Browser] Sent message: ${type} (${requestId})`);\n\t\t});\n\t}\n\n\tdisconnect(): void {\n\t\tthis.reconnectAttempts = this.maxReconnectAttempts;\n\t\tif (this.ws) {\n\t\t\tthis.ws.close();\n\t\t\tthis.ws = null;\n\t\t}\n\t\tthis.connected = false;\n\t\tlogger.info(\"[Browser] Client disconnected\");\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n\n\tasync navigate(sessionId: string, url: string): Promise<NavigationResult> {\n\t\tconst response = await this.sendMessage(\"navigate\", {\n\t\t\tsessionId,\n\t\t\tdata: { url },\n\t\t});\n\t\tconst data = response.data as Record<string, unknown> | undefined;\n\t\treturn {\n\t\t\tsuccess: Boolean(data?.success),\n\t\t\turl: String(data?.url ?? url),\n\t\t\ttitle: String(data?.title ?? \"\"),\n\t\t};\n\t}\n\n\tasync getState(sessionId: string): Promise<{\n\t\turl: string;\n\t\ttitle: string;\n\t\tsessionId: string;\n\t\tcreatedAt: Date;\n\t}> {\n\t\tconst response = await this.sendMessage(\"getState\", { sessionId });\n\t\tconst data = response.data as Record<string, unknown> | undefined;\n\t\treturn {\n\t\t\turl: String(data?.url ?? \"\"),\n\t\t\ttitle: String(data?.title ?? \"\"),\n\t\t\tsessionId,\n\t\t\tcreatedAt: new Date(),\n\t\t};\n\t}\n\n\tasync goBack(sessionId: string): Promise<NavigationResult> {\n\t\tconst response = await this.sendMessage(\"goBack\", { sessionId });\n\t\tconst data = response.data as Record<string, unknown> | undefined;\n\t\treturn {\n\t\t\tsuccess: Boolean(data?.success ?? true),\n\t\t\turl: String(data?.url ?? \"\"),\n\t\t\ttitle: String(data?.title ?? \"\"),\n\t\t};\n\t}\n\n\tasync goForward(sessionId: string): Promise<NavigationResult> {\n\t\tconst response = await this.sendMessage(\"goForward\", { sessionId });\n\t\tconst data = response.data as Record<string, unknown> | undefined;\n\t\treturn {\n\t\t\tsuccess: Boolean(data?.success ?? true),\n\t\t\turl: String(data?.url ?? \"\"),\n\t\t\ttitle: String(data?.title ?? \"\"),\n\t\t};\n\t}\n\n\tasync refresh(sessionId: string): Promise<NavigationResult> {\n\t\tconst response = await this.sendMessage(\"refresh\", { sessionId });\n\t\tconst data = response.data as Record<string, unknown> | undefined;\n\t\treturn {\n\t\t\tsuccess: Boolean(data?.success ?? true),\n\t\t\turl: String(data?.url ?? \"\"),\n\t\t\ttitle: String(data?.title ?? \"\"),\n\t\t};\n\t}\n\n\tasync click(\n\t\tsessionId: string,\n\t\tdescription: string,\n\t): Promise<WebSocketResponse> {\n\t\treturn await this.sendMessage(\"click\", {\n\t\t\tsessionId,\n\t\t\tdata: { description },\n\t\t});\n\t}\n\n\tasync type(\n\t\tsessionId: string,\n\t\ttext: string,\n\t\tfield: string,\n\t): Promise<WebSocketResponse> {\n\t\treturn await this.sendMessage(\"type\", {\n\t\t\tsessionId,\n\t\t\tdata: { text, field },\n\t\t});\n\t}\n\n\tasync select(\n\t\tsessionId: string,\n\t\toption: string,\n\t\tdropdown: string,\n\t): Promise<WebSocketResponse> {\n\t\treturn await this.sendMessage(\"select\", {\n\t\t\tsessionId,\n\t\t\tdata: { option, dropdown },\n\t\t});\n\t}\n\n\tasync extract(\n\t\tsessionId: string,\n\t\tinstruction: string,\n\t): Promise<WebSocketResponse> {\n\t\treturn await this.sendMessage(\"extract\", {\n\t\t\tsessionId,\n\t\t\tdata: { instruction },\n\t\t});\n\t}\n\n\tasync screenshot(sessionId: string): Promise<WebSocketResponse> {\n\t\treturn await this.sendMessage(\"screenshot\", { sessionId });\n\t}\n\n\tasync solveCaptcha(sessionId: string): Promise<WebSocketResponse> {\n\t\treturn await this.sendMessage(\"solveCaptcha\", { sessionId });\n\t}\n\n\tasync health(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst response = await this.sendMessage(\"health\", {});\n\t\t\treturn (\n\t\t\t\tresponse.type === \"health\" &&\n\t\t\t\t(response.data as { status: string })?.status === \"ok\"\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tlogger.error(`[Browser] Health check failed: ${errorMessage}`);\n\t\t\treturn false;\n\t\t}\n\t}\n}\n"]}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,IAAI,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB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O,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CACrD;AAED,MAAM,WAAW,eAAe;IAC/B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,oBAAoB,EAAG,SAAkB,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAwHA,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAkB,CAAC","sourcesContent":["export interface BrowserSession {\n\tid: string;\n\tcreatedAt: Date;\n\turl?: string;\n\ttitle?: string;\n}\n\nexport interface NavigationResult {\n\tsuccess: boolean;\n\turl: string;\n\ttitle: string;\n\terror?: string;\n}\n\nexport interface BrowserActionResult {\n\tsuccess: boolean;\n\tdata?: Record<string, unknown>;\n\terror?: string;\n}\n\nexport interface ExtractResult {\n\tsuccess: boolean;\n\tfound: boolean;\n\tdata?: string;\n\terror?: string;\n}\n\nexport interface ScreenshotResult {\n\tsuccess: boolean;\n\tdata?: string;\n\tmimeType?: \"image/png\" | \"image/jpeg\";\n\turl?: string;\n\ttitle?: string;\n\terror?: string;\n}\n\nexport interface CaptchaResult {\n\tdetected: boolean;\n\ttype: CaptchaType;\n\tsiteKey?: string;\n\tsolved: boolean;\n\ttoken?: string;\n\terror?: string;\n}\n\nexport type CaptchaType =\n\t| \"turnstile\"\n\t| \"recaptcha-v2\"\n\t| \"recaptcha-v3\"\n\t| \"hcaptcha\"\n\t| \"none\";\n\nexport interface SecurityConfig {\n\tallowedDomains?: string[];\n\tblockedDomains?: string[];\n\tmaxUrlLength?: number;\n\tallowLocalhost?: boolean;\n\tallowFileProtocol?: boolean;\n}\n\nexport interface RetryConfig {\n\tmaxAttempts: number;\n\tinitialDelayMs: number;\n\tmaxDelayMs: number;\n\tbackoffMultiplier: number;\n}\n\nexport interface BrowserConfig {\n\theadless?: boolean;\n\tbrowserbaseApiKey?: string;\n\tbrowserbaseProjectId?: string;\n\topenaiApiKey?: string;\n\tanthropicApiKey?: string;\n\tollamaBaseUrl?: string;\n\tollamaModel?: string;\n\tcapsolverApiKey?: string;\n\tserverPort?: number;\n}\n\nexport interface WebSocketMessage {\n\ttype: string;\n\trequestId: string;\n\tsessionId?: string;\n\tdata?: Record<string, unknown>;\n}\n\nexport interface WebSocketResponse {\n\ttype: string;\n\trequestId: string;\n\tsuccess: boolean;\n\tdata?: Record<string, unknown>;\n\terror?: string;\n}\n\nexport interface CapSolverConfig {\n\tapiKey: string;\n\tapiUrl?: string;\n\tretryAttempts?: number;\n\tpollingInterval?: number;\n}\n\nexport interface CaptchaTask {\n\ttype: string;\n\twebsiteURL: string;\n\twebsiteKey: string;\n\tproxy?: string;\n\tuserAgent?: string;\n\t[key: string]: string | boolean | number | undefined;\n}\n\nexport interface RateLimitConfig {\n\tmaxActionsPerMinute: number;\n\tmaxSessionsPerHour: number;\n}\n\nexport interface RateLimitEntry {\n\tcount: number;\n\tresetTime: number;\n}\n\nexport const BROWSER_SERVICE_TYPE = \"browser\" as const;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/utils/captcha.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7E,UAAU,mBAAmB;
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/utils/captcha.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7E,UAAU,mBAAmB;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,gBAAgB;IAKhB,OAAO,CAAC,MAAM;IAJ1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAErB,MAAM,EAAE,eAAe;IAM3C;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IA8B9C,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA2C3D,cAAc,CACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC;IA4BZ,gBAAgB,CACrB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,UAAQ,EACnB,KAAK,CAAC,EAAE,MAAM,GACZ,O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