fix(v2): botBrowser refuses a negative volume level
level=-10 was read as 10 (the sign was dropped) and unmuted the page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -479,8 +479,8 @@ class BotBrowserTool(Tool):
|
||||
elif action == "back":
|
||||
call = lambda s: s.back()
|
||||
elif action == "volume":
|
||||
m = re.search(r"\d+(?:\.\d+)?", str(args.get("level") if args.get("level") is not None else ""))
|
||||
if not m:
|
||||
m = re.search(r"-?\d+(?:\.\d+)?", str(args.get("level") if args.get("level") is not None else ""))
|
||||
if not m or float(m.group()) < 0:
|
||||
return _fail("volume needs a level from 0 to 100")
|
||||
level = min(100, round(float(m.group())))
|
||||
call = lambda s: s.volume(level)
|
||||
|
||||
@@ -51,7 +51,7 @@ One tool, `action` picks the operation (read as its first known word, so `open_p
|
||||
| `click` | `target` | clicks the link or button whose label is `target` (an exact label first, else the one containing it; `[n]` from the last list also works) |
|
||||
| `type` | `text` or `query` (`field`, `submit`) | types into the field whose label, placeholder or name contains `field` (else the focused field, else the first search or text box); `submit` presses Enter |
|
||||
| `back` | | goes back one page |
|
||||
| `volume` | `level` | sets the sound of the page to `level` (0 to 100, the first number in it, above 100 is 100): every `<video>` and `<audio>` with a source gets that volume and is unmuted above 0, muted at 0, and a player that keeps a volume of its own (YouTube's `#movie_player`, which sets it again on its next video) is told the same; a page without sound or video is an error. For "half" the model gives half of the volume the page shows |
|
||||
| `volume` | `level` | sets the sound of the page to `level` (0 to 100, the first number in it, above 100 is 100; a negative level or none is an error): every `<video>` and `<audio>` with a source gets that volume and is unmuted above 0, muted at 0, and a player that keeps a volume of its own (YouTube's `#movie_player`, which sets it again on its next video) is told the same; a page without sound or video is an error. For "half" the model gives half of the volume the page shows |
|
||||
| `play` | `query` (or `url`) | plays a song or video: searches YouTube for the words (`.../results?search_query=`, encoded by the tool), waits for the first video in the results (a visible `/watch?v=` link, not one inside an ad), opens it by its plain address (`/watch?v=<id>`, without the playlist the link may carry), and its player starts as on any video page opened (below); an address given (as `url`, or as words that start with `http(s)://` or `www.`) opens that page instead. No video in the results before the deadline is an error. Its deadline is 25 s (two pages and the start) |
|
||||
|
||||
Every action answers with the page after it: title, address, the state of its sound and video
|
||||
|
||||
@@ -203,8 +203,10 @@ def test_volume_sets_the_sound_of_the_page_to_the_level_asked(fake):
|
||||
BotBrowserTool().run({"action": "volume", "level": "30%"}, ctx())
|
||||
BotBrowserTool().run({"action": "volume", "level": 250}, ctx())
|
||||
assert fake.calls[1:] == [("volume", 30), ("volume", 100)]
|
||||
bad = BotBrowserTool().run({"action": "volume"}, ctx())
|
||||
assert not bad.success and len(fake.calls) == 3
|
||||
for missing in ({"action": "volume"}, {"action": "volume", "level": -10}, {"action": "volume", "level": "-5%"}):
|
||||
bad = BotBrowserTool().run(missing, ctx())
|
||||
assert not bad.success, missing
|
||||
assert len(fake.calls) == 3
|
||||
|
||||
|
||||
def test_the_volume_of_sound_that_plays_is_reported(fake):
|
||||
|
||||
Reference in New Issue
Block a user