Skip to content

Commit 635a4b5

Browse files
committed
Update browser extension
1 parent 455f66f commit 635a4b5

3 files changed

Lines changed: 1010 additions & 71 deletions

File tree

llms/extensions/browser/__init__.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,24 @@ def get_state_file(req):
4444
def _add_debug_log(cmd_str, result, duration):
4545
global DEBUG_LOG_COUNTER
4646
DEBUG_LOG_COUNTER += 1
47+
stdout = result.get("stdout", "")
48+
stderr = result.get("stderr", result.get("error", ""))
49+
rc = result.get("returncode", -1)
4750
DEBUG_LOG.append(
4851
{
4952
"id": DEBUG_LOG_COUNTER,
5053
"ts": time.time(),
5154
"cmd": cmd_str,
52-
"rc": result.get("returncode", -1),
53-
"stdout": result.get("stdout", ""),
54-
"stderr": result.get("stderr", result.get("error", "")),
55+
"rc": rc,
56+
"stdout": stdout,
57+
"stderr": stderr,
5558
"ok": result.get("success", False),
5659
"ms": round(duration * 1000),
5760
}
5861
)
62+
ctx.dbg(f"{cmd_str}\n{stdout}")
63+
if stderr.strip() if stderr else False:
64+
ctx.dbg(f"{rc}: {stderr}")
5965

6066
async def run_browser_cmd_async(*args, timeout=30, env=None, record=True):
6167
"""Run agent-browser command asynchronously."""
@@ -442,18 +448,32 @@ async def run_script(req):
442448
name += ".sh"
443449
path = os.path.join(get_script_dir(req), os.path.basename(name))
444450

445-
if not os.path.exists(path):
451+
# Check for inline content (e.g. selected text)
452+
body = await req.json() if req.content_length else {}
453+
inline_content = body.get("content") if body else None
454+
455+
if not inline_content and not os.path.exists(path):
446456
return web.json_response({"error": "Script not found"}, status=404)
447457

448458
t0 = time.monotonic()
449459
try:
450-
proc = await asyncio.create_subprocess_exec(
451-
"bash",
452-
path,
453-
stdout=asyncio.subprocess.PIPE,
454-
stderr=asyncio.subprocess.PIPE,
455-
env={**os.environ, "AGENT_BROWSER_SESSION": "default"},
456-
)
460+
if inline_content:
461+
proc = await asyncio.create_subprocess_exec(
462+
"bash",
463+
"-c",
464+
inline_content,
465+
stdout=asyncio.subprocess.PIPE,
466+
stderr=asyncio.subprocess.PIPE,
467+
env={**os.environ, "AGENT_BROWSER_SESSION": "default"},
468+
)
469+
else:
470+
proc = await asyncio.create_subprocess_exec(
471+
"bash",
472+
path,
473+
stdout=asyncio.subprocess.PIPE,
474+
stderr=asyncio.subprocess.PIPE,
475+
env={**os.environ, "AGENT_BROWSER_SESSION": "default"},
476+
)
457477
stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=120)
458478

459479
result = {

0 commit comments

Comments
 (0)