feat: persist sgclaw browser conversations

This commit is contained in:
zyl
2026-03-27 01:57:42 +08:00
parent bae0e452a5
commit d315c13f66
11 changed files with 402 additions and 20 deletions

View File

@@ -134,6 +134,9 @@ export function normalizeSmokeInstruction(rawInstruction) {
function instructionPlan(instruction) {
const baiduQuery = extractQuery(instruction, ['打开百度搜索', '打开百度并搜索'])
if (baiduQuery) {
const url = new URL('https://www.baidu.com/s')
url.searchParams.set('wd', baiduQuery)
return {
key: 'baidu',
summary: `已在百度搜索${baiduQuery}`,
@@ -141,19 +144,7 @@ function instructionPlan(instruction) {
browserToolCall('call_baidu_1', {
action: 'navigate',
expected_domain: BAIDU_DOMAIN,
url: BAIDU_URL,
}),
browserToolCall('call_baidu_2', {
action: 'type',
expected_domain: BAIDU_DOMAIN,
selector: BAIDU_INPUT_SELECTOR,
text: baiduQuery,
clear_first: true,
}),
browserToolCall('call_baidu_3', {
action: 'click',
expected_domain: BAIDU_DOMAIN,
selector: BAIDU_BUTTON_SELECTOR,
url: url.toString(),
}),
],
}

View File

@@ -67,6 +67,29 @@ function assertCompatRuntimeTraffic(requests) {
if (!instructions.includes('打开知乎搜索天气')) {
throw new Error('fake DeepSeek server did not receive the Zhihu smoke instruction')
}
const zhihuRequest = requests.find((entry) => {
return (entry.body?.messages ?? []).some((message) =>
message?.role === 'user' &&
normalizeSmokeInstruction(message.content) === '打开知乎搜索天气')
})
if (!zhihuRequest) {
throw new Error('fake DeepSeek server did not receive the Zhihu follow-up turn')
}
const zhihuMessages = zhihuRequest.body?.messages ?? []
const hasPriorUserTurn = zhihuMessages.some((message) =>
message?.role === 'user' &&
normalizeSmokeInstruction(message.content) === '打开百度搜索天气')
const hasPriorAssistantTurn = zhihuMessages.some((message) =>
message?.role === 'assistant' &&
typeof message.content === 'string' &&
message.content.includes('已在百度搜索天气'))
if (!hasPriorUserTurn || !hasPriorAssistantTurn) {
throw new Error('DeepSeek follow-up turn is missing prior browser conversation history')
}
}
main().catch((error) => {