操作栏「打开网页」按钮不显示 + AI 界面按钮长得不一样 (v2.0.39)

用户连着反馈三条,逐个查清楚:

  ① "操作栏里应该有『打开网页』按钮,但没显示"
  ② "是 ai 自己写的界面 不是链接"
  ③ "还是没有 / 没有一个按键能用"

## ① extractUrls 漏认 7/11 种写法(按钮不显示的根因)

`extractUrls` 是**手写扫描器,只认 `](` 紧挨着的 markdown 链接**。
实测(`scripts/verify-extract-urls.py`,16 个用例)漏掉这些:

  · **裸 URL** —— `见 https://example.com`(**模型最常这么写**)
  · `[文字] (地址)` —— 中英混排中间常有空格
  · `<https://example.com>` 尖括号包裹
  · 中文标点紧跟 —— `见(https://…)。`
  · 换行里的裸 URL

后果不是"少显示一个链接",而是 **extractUrls 返回空 → 整个按钮不显示**。

重写成**正则扫全文**,markdown 链接 + 裸 URL 两类都收,顺带:
  · 剪掉 URL 尾巴上的中文标点(`)。`、`,`)—— 不剪的话点开必 404
  · 带上**链接文字**(`data class FoundUrl`)—— 以前列表里只显示 host,
    于是同域名的两条链接(`https://example.com` 和 `…/index-zh`)
    看起来**一模一样**,用户根本分不出该点哪个

### 自己踩的两个正则坑(都记进注释了)

**坑一**:裸 URL 正则允许右括号 → `[x](https://a.com)` 被**再匹配一次**,
同一条链接算出两个不同地址(一个还带多余的右括号)。

**坑二**:改成完全禁止括号 → 维基那种地址 `…/wiki/A_(b)` 被截断成 `…/wiki/A_`,
而且外层的 `\)` 匹配的是**地址里那个括号**,最终得到 `…/wiki/A_(b`(缺括号、404)。

最终用**平衡括号**写法:`(?:[^\s()]|\([^\s()]*\))+` ——
右括号只能以完整 `(…)` 的形式出现在地址里。

★ 写这个验证脚本时它自己也错过一次:它**重写了一遍逻辑**来测,
所以改了 Kotlin 之后它还在报旧结果,等于没测。现在直接从 Kotlin 源码里
把正则抠出来跑(`kotlin_regex()`),测的是真代码。

## ② 按钮永久显示 + 可以自己输网址

以前是"这条回复里有链接才显示按钮",两个问题:
  · extractUrls 一漏认,按钮整个不见(就是 ① )
  · 用户根本无从知道"这条能不能开网页"

现在按钮**无条件显示**,而且点开之后:
  · 有链接 → 列出来(带链接文字,能分清)
  · 没链接 → 也能**自己输网址**(没写协议自动补 https)
它就是个浏览器入口,任何时候按都有意义。

顺带改了:**只有一个链接时也走这个界面**,不再直接跳转 ——
用户该有机会先看一眼自己要打开哪个地址。

## ③ AI 写的界面里,按钮长得不一样(用户说"没有一个按键能用")

实测功能是好的(点了值确实回到模型手里),问题在**视觉**:

  · `data-doubao-result` 的按钮被 App 改写成 `<a class="db-btn">`
    → 拿到亮蓝整行的样式,看得出来能点
  · 而 `onclick="Doubao.sendToAi(...)"` 的按钮**保持原样**,
    落进"普通按钮"那条规则 → **小灰块**,在深色主题里跟正文几乎一样

同一屏里一半亮蓝一半灰暗,用户当然会以为"只有蓝的能点"甚至"都不能点"。
(用户截图里 ①③⑤⑥ 是灰的、②④ 是蓝的,就是这个原因。)

现在**所有 button / .db-btn 一律同样显眼的实心蓝**,普通按钮那条规则删了。
想要不抢眼的加 `class="db-plain"`。

## 真机实测

 · 按用户截图的形态造界面(心跳线 canvas + 六个按钮):
   修复前 ①③⑤⑥ 灰、②④ 蓝 → 修复后**六个一模一样全蓝**
 · 点 JS 按钮 ① → `{"value":"查岗"}` 回到 Python ✓
 · 点 JS 按钮 ③ → `{"value":"来点黄的"}` ✓
 · 造一条含 5 种写法的回复 → 操作栏 🌐 按钮出现(蓝色,提示 5 个链接)✓
 · 点开 → 5 个链接全在,前两个带模型写的文字(能分清同域名)✓
 · 顶部"输入网址"入口在 ✓

## 验证

 · `scripts/verify-extract-urls.py`(16 项,直接从 Kotlin 源码抠正则)
 · `scripts/probe-heartbeat-ui.py`(复刻用户截图的形态)
 · `scripts/probe-seed-bare-urls.py`(含 5 种 URL 写法的回复)
This commit is contained in:
doubao
2026-10-15 12:04:32 +08:00
parent 885a1f0123
commit 103c939051
10 changed files with 537 additions and 101 deletions

View File

@@ -0,0 +1,86 @@
"""按用户截图里的样子造一个界面:心跳线 + 六个按钮。
★ 用户报"没有一个按键能用",而我之前测的都是朴素 HTML。
所以这里**按他截图里的形态**造:canvas 画心跳线 + 六个中文按钮 +
一段很长的角色扮演文案(把按钮挤到屏幕外),看按钮到底能不能点。
三种按钮形态都放上:
① onclick="Doubao.sendToAi(...)" —— JS 桥
② data-doubao-result="..." —— App 侧字符串替换(不依赖 JS)
③ 纯 <button> 什么都没标 —— 对照,本来就不该有回传能力
"""
import json
import sys
import urllib.request
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
URL = "http://127.0.0.1:15199"
CONV = "c_main"
def call(path, payload=None, method="POST", timeout=180):
data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None
req = urllib.request.Request(
URL + path, data=data, method=method,
headers={"Content-Type": "application/json; charset=utf-8"},
)
with urllib.request.urlopen(req, timeout=timeout) as r:
return json.loads(r.read().decode("utf-8"))
HTML = """
<h1 style="font-size:20px">今天,你归我了</h1>
<canvas id="beat" width="320" height="90"
style="width:100%;background:#14161b;border-radius:10px"></canvas>
<p style="margin:14px 0 6px;color:#8c939d;font-size:13px">下面六个按钮,点哪个我就干哪个:</p>
<button onclick="Doubao.sendToAi('查岗')">① 抽查我位置</button>
<button data-doubao-result="来点黄的">② 来点黄的</button>
<button onclick="Doubao.sendToAi('讲个故事')">③ 讲个故事</button>
<button data-doubao-result="夸我">④ 夸我</button>
<button onclick="Doubao.sendToAi('唱歌')">⑤ 唱首歌</button>
<button onclick="Doubao.close()">⑥ 关掉界面</button>
<div id="st" style="margin-top:12px;font-size:12px;color:#8c939d">(点一下试试,这里会显示结果)</div>
<script>
// 心跳线 —— 复刻用户截图里那个效果
var c = document.getElementById('beat'), g = c.getContext('2d');
c.width = 320; c.height = 90;
var t = 0;
function draw() {
g.clearRect(0, 0, 320, 90);
g.strokeStyle = '#4c8dff';
g.lineWidth = 2;
g.beginPath();
for (var x = 0; x < 320; x++) {
var y = 45 + Math.sin((x + t) / 9) * Math.exp(-((x % 90) / 40)) * 26
+ Math.sin((x + t) / 2.2) * 1.4;
if (x === 0) g.moveTo(x, y); else g.lineTo(x, y);
}
g.stroke();
t += 3;
requestAnimationFrame(draw);
}
draw();
// JS 桥可用性自检 —— 直接显示在页面上,一眼就能看出桥在不在
document.getElementById('st').textContent =
'typeof Doubao = ' + (typeof Doubao) +
' | sendToAi: ' + (typeof Doubao !== 'undefined' && typeof Doubao.sendToAi === 'function');
</script>
"""
print("=== 按用户截图的形态弹一个界面 ===")
res = call("/api/tools/run", {
"name": "show_ui",
"args": {"title": "心检", "html": HTML, "wait": True, "timeout": 90},
"conversationId": CONV,
}, timeout=180)
print(json.dumps(res, ensure_ascii=False)[:400])

View File

@@ -0,0 +1,48 @@
"""塞一条带**裸 URL** 的助手回复(旧版 extractUrls 认不出来的那种)。
★ 用户报"操作栏里应该有『打开网页』按钮,但没显示"。
旧实现只认 `](` 紧挨着的 markdown 链接,裸 URL 一律漏 →
extractUrls 返回空 → 按钮整个不显示。
这条回复就是用来验证修好没有的。
"""
import json
import sys
import urllib.request
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
URL = "http://127.0.0.1:15199"
def call(path, payload=None, method="POST", timeout=60):
data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None
req = urllib.request.Request(
URL + path, data=data, method=method,
headers={"Content-Type": "application/json; charset=utf-8"},
)
with urllib.request.urlopen(req, timeout=timeout) as r:
return json.loads(r.read().decode("utf-8"))
content = (
"给你几个链接,写法故意各不相同(旧版只有第一种能被认出来):\n\n"
"1. 标准的:[Example 官网](https://example.com)\n"
"2. 中间有空格的:[Example 中文] (https://example.com/index-zh)\n"
"3. **裸 URL**:直接去 https://www.iana.org/help/example-domains 看\n"
"4. 尖括号包裹:<https://example.org>\n"
"5. 中文标点紧跟:也可以看 https://www.rfc-editor.org/rfc/rfc2606,里面有说明\n"
)
convs = call("/api/conversations", None, "GET").get("conversations") or []
cid = convs[0]["id"] if convs else "c_main"
print("往", cid, "写消息…")
res = call(f"/api/conversations/{cid}", {"messages": [
{"role": "user", "content": "给我几个链接"},
{"role": "assistant", "content": content},
]}, "PATCH")
full = res.get("conversation") or {}
print("现在", len(full.get("messages") or []), "条消息")

View File

@@ -0,0 +1,131 @@
"""测 extractUrls 认不认各种 URL 写法。
★ 为什么值得单独一个脚本:
用户报「操作栏里应该有『打开网页』按钮,但没显示」。
根因是 extractUrls 只认 `](` 紧挨着的 markdown 链接,
**裸 URL(`见 https://x.com`)这种模型最常写的形式反而漏掉** ——
返回空 → 按钮整个不显示。
★ 手法:**直接从 Kotlin 源码里把正则抠出来**,用 Python 的 re 跑
(两边正则语法基本一致)。这样测的是真代码,不是"我凭记忆重写一遍"——
第一版这个探针就是重写的,改了 Kotlin 之后它还在报旧结果,等于没测。
"""
import os
import re
import sys
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
WS = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SRC = os.path.join(WS, "android", "app", "src", "main", "java",
"com", "doubao", "lynxclone", "ui", "MarkdownText.kt")
src = open(SRC, encoding="utf-8").read()
def kotlin_regex(name: str) -> str:
# ★ `\s*` 是必须的:源码里 `RE_MD_LINK =` 后面换行过(行太长),
# 不加的话提取不到 —— 而报的是"找不到 RE_MD_LINK",
# 看起来像"改了名字",其实是格式问题。
m = re.search(rf'private val {name}\s*=\s*\n?\s*Regex\("""(.*?)"""\)', src, re.DOTALL)
if not m:
print(f"!! 源码里找不到 {name}")
sys.exit(1)
return m.group(1).strip()
RE_MD = kotlin_regex("RE_MD_LINK")
RE_BARE = kotlin_regex("RE_BARE_URL")
print("RE_MD_LINK =", RE_MD)
print("RE_BARE_URL =", RE_BARE)
print()
# Kotlin 的 `[^\]\n]` 在 Python 里要写成 `[^\]\n]`(一样)
CLEAN_TAIL = "。,、;:!?)】》」』….,;:!?"
def clean(raw: str) -> str:
"""
和 Kotlin 的 cleanUrl 等价。
★ 注意这里**没有**处理"成对括号保留"那条(Kotlin 里有)。
`https://en.wikipedia.org/wiki/A_(b)` 正则已经整个吃掉、不需要补;
Kotlin 那段是给"正则提前截断"的情况兜底的。
测这一条时两边结果会一致,所以不影响。
"""
s = raw.strip().strip("<>\"'`")
s = s.rstrip(CLEAN_TAIL)
while s.endswith(")") and s.count(")") > s.count("("):
s = s[:-1]
while s.endswith("]") and s.count("]") > s.count("["):
s = s[:-1]
if not (s.startswith("http://") or s.startswith("https://")):
return ""
return s
def extract(markdown: str):
if "http://" not in markdown and "https://" not in markdown:
return []
out, labels = [], {}
for m in re.finditer(RE_MD, markdown):
label = m.group(1).strip().strip("[]")
url = clean(m.group(2))
if url:
labels.setdefault(url, label)
if url not in out:
out.append(url)
for m in re.finditer(RE_BARE, markdown):
url = clean(m.group(0))
if url and url not in out:
out.append(url)
return [(u, labels.get(u, "")) for u in out]
CASES = [
("标准 markdown", "[文档](https://example.com/a)", 1),
("文字和括号之间有空格", "[文档] (https://example.com/a)", 1),
("括号里有空格", "[文档]( https://example.com/a )", 1),
("标题里有方括号", "[A[1]](https://example.com/a)", 1),
("★ 裸 URL", "直接访问 https://example.com/a 就行", 1),
("★ 中文标点紧跟", "见(https://example.com/a)。", 1),
("★ 尖括号包裹", "<https://example.com/a>", 1),
("★ 行尾的裸 URL", "链接是 https://example.com/a", 1),
("★ 换行里的裸 URL", "第一行\nhttps://example.com/a\n第三行", 1),
("多个链接", "[A](https://a.com) 和 [B](https://b.com)", 2),
("markdown + 裸混排", "[A](https://a.com) 还有 https://b.com", 2),
("同链接出现两次只算一个", "[A](https://a.com) 又说 https://a.com", 1),
("中文标点不被吞进地址", "看 https://example.com/a,谢谢", 1),
("带括号的地址", "[x](https://en.wikipedia.org/wiki/A_(b))", 1),
("没有链接", "这段话里一个网址都没有", 0),
("相对路径不算", "[文档](docs/x.md)", 0),
]
print("=== 认得多少 ===")
miss = 0
for label, text, want in CASES:
got = extract(text)
okc = len(got) == want
if not okc:
miss += 1
detail = ", ".join(f"{u}" + (f"[{l}]" if l else "") for u, l in got) or "(空)"
print(f" {'✓' if okc else '✗'} {label:22s} 期望{want} 得到{len(got)}: {detail}")
# 链接文字要留住(列表里靠它区分同域名的多个链接)
got = extract("[Example 官网](https://example.com) 和 [Example 中文](https://example.com/index-zh)")
print()
if len(got) == 2 and all(l for _, l in got):
print(" ✓ 两条同域链接都拿到了各自的文字(列表里能分得清)")
else:
print(" ✗ 链接文字丢了:", got)
miss += 1
print()
if miss:
print(f"❌ {miss} 项不合格")
sys.exit(1)
print("✅ 全部通过")