fix: play on YouTube in one step, Korea as the default location, searches in the user's language
- botBrowser `play`: searches YouTube for the words as said, opens the first video (not an ad, without the playlist) and starts it, in one call (an address given opens that page); `type` also takes `query`. Live 0.1.19: the model stopped on YouTube's home page or the results, a retry was refused as a third call, and the answer still said the video played. - `brain.location` (기본 위치, default 대한민국) goes to the brain as `location_name`: the time line says it without GeoIP (no database on the game PC), and getWeather without a place uses it. - Planner and webSearch keep search words in the user's language (never translated into English), so recommendations fit where the user is. Evals (qwen3:8b, 3 runs): play ending on a playing video found with the words as said 0/6 -> 5/6; Korean searches for Korean requests 6/9 -> 8/9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -238,6 +238,8 @@ class Settings:
|
||||
location_ip_address: str | None
|
||||
location_auto_detect: bool
|
||||
location_cgnat_resolve_public_ip: bool
|
||||
# A place the user set (e.g. "대한민국"): used instead of detection when set (location.spec.md).
|
||||
location_name: str | None
|
||||
|
||||
# Web Search
|
||||
web_search_enabled: bool
|
||||
@@ -551,6 +553,7 @@ def get_default_config() -> Dict[str, Any]:
|
||||
# When behind CGNAT (100.64.0.0/10), attempt a privacy-light external DNS query to discover true public IP.
|
||||
# Uses a single OpenDNS resolver lookup of myip.opendns.com over DNS (no HTTP services). Disable to avoid any external request.
|
||||
"location_cgnat_resolve_public_ip": True,
|
||||
"location_name": None,
|
||||
|
||||
# Web Search
|
||||
"web_search_enabled": True,
|
||||
@@ -762,6 +765,7 @@ def load_settings() -> Settings:
|
||||
location_ip_address = None if location_ip_address_val in (None, "", "null") else str(location_ip_address_val)
|
||||
location_auto_detect = bool(merged.get("location_auto_detect", True))
|
||||
location_cgnat_resolve_public_ip = bool(merged.get("location_cgnat_resolve_public_ip", True))
|
||||
location_name = str(merged.get("location_name") or "").strip() or None
|
||||
web_search_enabled = bool(merged.get("web_search_enabled", True))
|
||||
brave_search_api_key = str(merged.get("brave_search_api_key", "") or "").strip()
|
||||
wikipedia_fallback_enabled = bool(merged.get("wikipedia_fallback_enabled", True))
|
||||
@@ -902,6 +906,7 @@ def load_settings() -> Settings:
|
||||
location_ip_address=location_ip_address,
|
||||
location_auto_detect=location_auto_detect,
|
||||
location_cgnat_resolve_public_ip=location_cgnat_resolve_public_ip,
|
||||
location_name=location_name,
|
||||
|
||||
# Web Search
|
||||
web_search_enabled=web_search_enabled,
|
||||
|
||||
@@ -761,6 +761,9 @@ def _live_time_location_string(cfg) -> str:
|
||||
tz_name: Optional[str] = None
|
||||
if not getattr(cfg, 'location_enabled', True):
|
||||
location_context = "Location: Disabled"
|
||||
elif isinstance(getattr(cfg, 'location_name', None), str) and cfg.location_name.strip():
|
||||
# The place the user set wins over detection (location.spec.md); local time is the PC's.
|
||||
location_context = f"Location: {cfg.location_name.strip()} (where the user is)"
|
||||
else:
|
||||
location_context, tz_name = get_location_context_with_timezone(
|
||||
config_ip=getattr(cfg, 'location_ip_address', None),
|
||||
|
||||
@@ -232,7 +232,10 @@ _PROMPT_TEMPLATE = (
|
||||
"10. Maximum {max_steps} steps. Do not number them — one step per line.\n"
|
||||
"11. Output ONLY the steps, no preamble, no trailing commentary, no "
|
||||
"JSON fences, no explanations.\n"
|
||||
"12. Write the steps in the same language the user wrote the query in.\n"
|
||||
"12. Write the steps in the same language the user wrote the query in. "
|
||||
"The words of every search or play argument stay in the user's "
|
||||
"language too, never translated into English, because a search in the "
|
||||
"user's language finds what people where they are get.\n"
|
||||
)
|
||||
|
||||
|
||||
@@ -279,7 +282,8 @@ def _build_user_message(
|
||||
else:
|
||||
parts.append("DIALOGUE CONTEXT: (empty)")
|
||||
parts.append(f"USER QUERY: {query.strip()}")
|
||||
parts.append("\nEmit the plan now, one step per line, no numbering.")
|
||||
parts.append("\nEmit the plan now, one step per line, no numbering, written in the language of "
|
||||
"the USER QUERY (the words of searches too).")
|
||||
return "\n\n".join(parts)
|
||||
|
||||
|
||||
|
||||
@@ -108,7 +108,14 @@ The planner prompt instructs the model to emit:
|
||||
`webSearch query='his most famous songs'`.
|
||||
- A final synthesis/reply step when any `searchMemory` or tool step
|
||||
was planned.
|
||||
- Steps in the same language the user wrote the query in.
|
||||
- Steps in the same language the user wrote the query in, the words of
|
||||
search and play arguments too (never translated into English: a search
|
||||
in the user's language finds what people where they are get); the
|
||||
closing line of the user message repeats it, which a small model follows
|
||||
better than the rule alone. Eval `evals/test_search_in_users_language.py`
|
||||
(qwen3:8b, 3 runs of 3 Korean requests): Korean searches 6/9 before
|
||||
("요즘 볼 만한 넷플릭스 드라마" searched "best netflix dramas 2026" 3/3), 8/9
|
||||
after (that one 2/3).
|
||||
|
||||
### Parsing and hygiene
|
||||
|
||||
|
||||
@@ -18,8 +18,12 @@ from ...debug import debug_log
|
||||
|
||||
FENCE_START = "<<<BEGIN UNTRUSTED WEB PAGE>>>"
|
||||
FENCE_END = "<<<END UNTRUSTED WEB PAGE>>>"
|
||||
_ACTIONS = ("open", "read", "click", "type", "back")
|
||||
_ACTIONS = ("open", "read", "click", "type", "back", "play")
|
||||
PAGE_WAIT_S = 15.0
|
||||
# play: two pages (the results and the video) and the wait for the video to start.
|
||||
PLAY_WAIT_S = 25.0
|
||||
# Where play searches: YouTube's results for the words (encoded by the tool).
|
||||
PLAY_SEARCH = "https://www.youtube.com/results?search_query="
|
||||
TEXT_CHARS = 6000
|
||||
MAX_ITEMS = 40
|
||||
CDP_ENV = "JARVIS_BROWSER_CDP"
|
||||
@@ -58,6 +62,12 @@ _PLAY = r"""
|
||||
(() => { const v = [...document.querySelectorAll('video')].filter(m => (m.currentSrc || m.src) && m.paused
|
||||
&& !m.ended && !m.error && m.currentTime === 0 && m.getBoundingClientRect().width >= innerWidth * 0.5);
|
||||
if (!v.length) return false; v[0].play().catch(() => {}); return true; })()"""
|
||||
# The first video in a list of results (a visible `/watch?v=` link, not an ad), as its plain address.
|
||||
_FIRST_VIDEO = "(() => {" + _HELPERS + r"""
|
||||
const a = [...document.querySelectorAll('a[href*="/watch?v="]')].find(e => vis(e)
|
||||
&& !e.closest('ytd-ad-slot-renderer,ytd-promoted-video-renderer,ytd-in-feed-ad-layout-renderer,[is-ad]'));
|
||||
if (!a) return null; const u = new URL(a.getAttribute('href'), location.href);
|
||||
return u.origin + u.pathname + '?v=' + encodeURIComponent(u.searchParams.get('v')); })()"""
|
||||
_CLICK = "(() => {" + _HELPERS + r"""
|
||||
return ((t) => { const m = /^\s*\[(\d+)\]\s*$/.exec(t); let el = null;
|
||||
if (m) el = (window.__jvItems || [])[Number(m[1]) - 1];
|
||||
@@ -239,6 +249,18 @@ class BrowserSession:
|
||||
self._press_play()
|
||||
return self.read()
|
||||
|
||||
def play(self, results_url: str) -> Dict[str, Any]:
|
||||
"""Open a list of results, wait for its first video and open that (its player is started
|
||||
as on any video page reached)."""
|
||||
self.open(results_url)
|
||||
while True:
|
||||
video = self._eval(_FIRST_VIDEO)
|
||||
if video:
|
||||
return self.open(video)
|
||||
if self.deadline - time.monotonic() < 0.3:
|
||||
raise BrowserError("no video came up for those words")
|
||||
time.sleep(0.25)
|
||||
|
||||
def _press_play(self) -> None:
|
||||
"""On a page just reached whose main player did not start: look again and press play."""
|
||||
try:
|
||||
@@ -273,7 +295,7 @@ MAX_TABS = 5
|
||||
_lock = threading.Lock()
|
||||
# Navigations that are safe to send again on a fresh connection; a click, typing or back may have
|
||||
# taken effect before the connection broke, so they are never repeated.
|
||||
_REPEATABLE = ("open", "read")
|
||||
_REPEATABLE = ("open", "read", "play")
|
||||
|
||||
|
||||
def _action(raw: Any) -> str:
|
||||
@@ -359,7 +381,10 @@ class BotBrowserTool(Tool):
|
||||
"Open and use a website in Jarvis's own web browser: search on a site, click, type into "
|
||||
"a box, read the page. "
|
||||
"Actions: open an address, read the current page, click a link or button by its label, "
|
||||
"type into a search box or field (optionally pressing Enter), or go back. To search on a "
|
||||
"type into a search box or field (optionally pressing Enter), go back, or play. To play a "
|
||||
"song or video, call play once with the words as query, exactly as the user said them and "
|
||||
"in their language (never translated): it searches YouTube, opens the first video and "
|
||||
"starts it, and the page that comes back says whether it truly plays. To search on a "
|
||||
"site, call open with the site's address and the words as query, in plain text exactly as "
|
||||
"the user said them (never put the words into an address yourself); only the page that "
|
||||
"comes back shows whether the search ran. Use it when "
|
||||
@@ -375,11 +400,12 @@ class BotBrowserTool(Tool):
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {"type": "string", "enum": list(_ACTIONS),
|
||||
"description": "open, read, click, type or back"},
|
||||
"description": "open, read, click, type, back or play"},
|
||||
"url": {"type": "string", "description": "for open: the web address"},
|
||||
"query": {"type": "string", "description": "for open: words to search for on that site, as "
|
||||
"plain text (never percent-encoded); they go into the address's empty search "
|
||||
"parameter (e.g. ...?search_query=) or into the site's search box"},
|
||||
"parameter (e.g. ...?search_query=) or into the site's search box. For play: "
|
||||
"the song or video to play, as the user said it"},
|
||||
"target": {"type": "string", "description": "for click: the link or button label, or [n] from the list"},
|
||||
"text": {"type": "string", "description": "for type: what to type"},
|
||||
"field": {"type": "string", "description": "for type: the field's label or placeholder (optional)"},
|
||||
@@ -410,13 +436,25 @@ class BotBrowserTool(Tool):
|
||||
call = lambda s: (s.open(url), s.type(words, None, True))[1]
|
||||
else:
|
||||
call = lambda s: s.open(url)
|
||||
elif action == "play":
|
||||
words = str(args.get("query") or args.get("text") or "").strip()
|
||||
page = str(args.get("url") or "").strip() if not words else ""
|
||||
# An address to play (given as url, or as the words): that page opens and its player starts.
|
||||
address = _web_url(words or page) if re.match(r"^(https?://|www\.)", words or page, re.I) else None
|
||||
if address:
|
||||
call = lambda s: s.open(address)
|
||||
elif not words:
|
||||
return _fail("play needs the words of the song or video to play (query)")
|
||||
else:
|
||||
results = PLAY_SEARCH + urllib.parse.quote_plus(words)
|
||||
call = lambda s: s.play(results)
|
||||
elif action == "click":
|
||||
target = str(args.get("target") or "").strip()
|
||||
if not target:
|
||||
return _fail("click needs the label of a link or button")
|
||||
call = lambda s: s.click(target)
|
||||
elif action == "type":
|
||||
text = str(args.get("text") or "")
|
||||
text = str(args.get("text") or args.get("query") or "") # models also write query
|
||||
if not text:
|
||||
return _fail("type needs the text to type")
|
||||
call = lambda s: s.type(text, args.get("field") or None, bool(args.get("submit")))
|
||||
@@ -425,7 +463,7 @@ class BotBrowserTool(Tool):
|
||||
else:
|
||||
call = lambda s: s.read()
|
||||
who = str(getattr(context, "user_id", "") or "")
|
||||
deadline = time.monotonic() + PAGE_WAIT_S # one deadline for connecting, the action and its page
|
||||
deadline = time.monotonic() + (PLAY_WAIT_S if action == "play" else PAGE_WAIT_S) # one deadline for connecting, the action and its page
|
||||
t0 = time.perf_counter()
|
||||
with _lock:
|
||||
for attempt in (1, 2):
|
||||
|
||||
@@ -17,7 +17,7 @@ read it, click a link or button, type into a field, go back. Product rules: `doc
|
||||
`https://`); `file:`, `chrome:`, `data:`, `javascript:` and the rest are refused. The browser's
|
||||
own network rules (public addresses only) are the app's proxy's job.
|
||||
- **Raw data, no LLM call.** The tool returns plain text for the reply model.
|
||||
- **Bounded.** One deadline of 15 s covers an action: connecting, the action and waiting for the
|
||||
- **Bounded.** One deadline of 15 s (25 s for `play`) covers an action: connecting, the action and waiting for the
|
||||
page; events arriving in between do not extend it. Text is cut at 6,000 characters and the list
|
||||
of links and buttons at 40.
|
||||
- **A window per person.** Each asker (`ToolContext.user_id`) has a page and connection of their
|
||||
@@ -29,8 +29,8 @@ read it, click a link or button, type into a field, go back. Product rules: `doc
|
||||
- **One tab, also for "new tab" links.** Before a click or typing, links, forms and `<base>` lose
|
||||
their `target` and `window.open` loads the address in the same tab, so what opens is what the
|
||||
tool reads next.
|
||||
- **Never twice.** When the connection breaks during an action, `open` and `read` are tried once
|
||||
more on a fresh connection (a fresh tab); `click`, `type` and `back` are not, because they may
|
||||
- **Never twice.** When the connection breaks during an action, `open`, `read` and `play` (which
|
||||
only opens pages) are tried once more on a fresh connection (a fresh tab); `click`, `type` and `back` are not, because they may
|
||||
already have taken effect: the tool says it may or may not have happened.
|
||||
- **The fence holds.** `<<<` and `>>>` in anything read from a page become `‹‹‹` and `›››`, so page
|
||||
text cannot close or reopen the fence.
|
||||
@@ -45,8 +45,9 @@ One tool, `action` picks the operation (read as its first known word, so `open_p
|
||||
| `open` | `url` (`query`) | opens the address in the bot browser's tab; with `query` (words to search for, plain text) they go, encoded by the tool (`urlencode`), into the address's last empty search parameter (`...?search_query=`), else the address opens and they are typed into its search box and sent (as `type` with `submit`) |
|
||||
| `read` | | reads the current page again (with a `url`, opens it) |
|
||||
| `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` (`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 |
|
||||
| `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 |
|
||||
| `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
|
||||
(`Media: playing 1:15 of 3:45; paused 0:00`, each `<video>` and `<audio>` with a source, `(muted)`
|
||||
@@ -55,7 +56,13 @@ When the page has a main player (a video at least half the window wide) and noth
|
||||
note follows the fence: the video is not playing, do not say it plays; if it should, click its play
|
||||
button and look again, and if it still does not play, tell the user it did not start. The
|
||||
description tells the model to search a site with `open` and `query` in plain text, never putting the
|
||||
words into an address itself (live 2026-11-16: 아이유 hand-encoded into 아이우). Eval
|
||||
words into an address itself (live 2026-11-16: 아이유 hand-encoded into 아이우), and to play a song or
|
||||
video with one `play` whose `query` is the words as the user said them, in their language (live
|
||||
2026-11-16, 0.1.19: "아이유 신곡 틀어 줘" opened YouTube's home page, then a `type` with `query` instead of
|
||||
`text` failed and its retry was refused as a third call of the tool in one answer; "뉴진스 하입보이"
|
||||
searched "NewJeans Hypothesis" in English and stopped on the results; both answers said the video
|
||||
played). Eval `evals/test_bot_browser_tool.py` (qwen3:8b, 3 runs of the two requests): ending on a
|
||||
playing video found with the words as said 0/6 before, 5/6 after (6/6 played; once "IU new song"). Eval
|
||||
`evals/test_bot_browser_tool.py` (qwen3:8b, 3 runs each): reaching YouTube with the right words 1/3
|
||||
before, 3/3 after; a video page that stays paused reported as playing 1/3 before, never after (3/3
|
||||
said it did not play).
|
||||
|
||||
@@ -289,6 +289,13 @@ class WeatherTool(Tool):
|
||||
# debug log, doesn't change behaviour downstream.
|
||||
place_from_fallback = False
|
||||
|
||||
set_place = getattr(getattr(context, "cfg", None), "location_name", None)
|
||||
set_place = set_place.strip() if isinstance(set_place, str) else ""
|
||||
if not location_str and set_place:
|
||||
# No place asked for: the place the user set in the settings (location.spec.md).
|
||||
location_str = set_place
|
||||
debug_log(" 📍 using the location set in the settings", "tools")
|
||||
|
||||
if not location_str:
|
||||
# No location provided - try auto-detected coordinates first.
|
||||
user_loc = self._get_user_location(context)
|
||||
|
||||
@@ -570,7 +570,7 @@ class WebSearchTool(Tool):
|
||||
return {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"search_query": {"type": "string", "description": "A self-contained search query with entity names resolved from conversation history (not a literal echo of the user's utterance). Prefer a compact keyword phrase over a conversational sentence — e.g. 'Harry Styles most famous songs', not 'what are his most famous songs'."}
|
||||
"search_query": {"type": "string", "description": "A self-contained search query with entity names resolved from conversation history (not a literal echo of the user's utterance), in the language the user spoke (never translated into English: results then fit where the user is). Prefer a compact keyword phrase over a conversational sentence — e.g. 'Harry Styles most famous songs', not 'what are his most famous songs'."}
|
||||
},
|
||||
"required": ["search_query"]
|
||||
}
|
||||
|
||||
@@ -7,7 +7,10 @@ memory.
|
||||
|
||||
The query comes in `search_query`; `query` is read when `search_query` is missing or empty (the
|
||||
planner writes steps as `webSearch query='...'` and models copy it; live 2026-11-16 both searches of
|
||||
an answer failed on it).
|
||||
an answer failed on it). Its description asks for the query in the language the user spoke, never
|
||||
translated into English, so the results fit where the user is (live 2026-11-16: a Korean request for
|
||||
Netflix dramas searched in English and recommended American shows; eval
|
||||
`evals/test_search_in_users_language.py`, with the planner rule in `planner.spec.md`).
|
||||
|
||||
### Real-time info routing (`STREAM_BROWSER`)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ This specification documents the location detection module (`src/jarvis/utils/lo
|
||||
| `location_ip_address` | str \| null | `null` | Manually configured public IP. Takes precedence over auto-detection when set. |
|
||||
| `location_cgnat_resolve_public_ip` | bool | `true` | When a CGNAT address (100.64.0.0/10) is detected, attempt a single DNS query to OpenDNS to resolve the true public IP. Disable to prevent any external DNS query. |
|
||||
| `location_cache_minutes` | int | `60` | TTL for cached location lookups persisted to disk. |
|
||||
| `location_name` | str \| null | `null` | A place the user set (v2: the app's `brain.location`, default `대한민국`). When set (and `location_enabled`), the reply engine's time line says `Location: <name> (where the user is)` without any detection, and `getWeather` without a place asked for uses it (a place the person names still wins). The local time is then the computer's. Live 2026-11-16: the game PC has no GeoLite2 database, so detection always failed ("Location: Unknown", weather asked for the city) and searches fitted no country. |
|
||||
|
||||
### IP Resolution Chain
|
||||
|
||||
|
||||
Reference in New Issue
Block a user