feat: persist sgclaw browser conversations
This commit is contained in:
@@ -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(),
|
||||
}),
|
||||
],
|
||||
}
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user