提交 0b74f4ff authored 作者: 张孟夏's avatar 张孟夏

解决版本升级到2.3以后,2.2及以前编写的部分用例执行不成功的问题;

上级 f7c96d8c
......@@ -13,7 +13,7 @@ ${path} /api/system/config/web
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Should Be Equal As Strings ${content["data"]} {\"supportedModels\":[\"GPT-4o\",\"DeepSeek\"],\"supportVoiceMessage\":true,\"voiceMessageAppId\":\"55053e20\",\"authUrl\":\"http://accounts-4j.sit.ninetechone.com\"}
Should Contain ${content["data"]} \"supportVoiceMessage\":true,\"voiceMessageAppId\":\"55053e20\",\"authUrl\":\"http://accounts-4j.sit.ninetechone.com\"
反例-不传入token
[Tags] E
......@@ -22,7 +22,7 @@ ${path} /api/system/config/web
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Should Be Equal As Strings ${content["data"]} {\"supportedModels\":[\"GPT-4o\",\"DeepSeek\"],\"supportVoiceMessage\":true,\"voiceMessageAppId\":\"55053e20\",\"authUrl\":\"http://accounts-4j.sit.ninetechone.com\"}
Should Contain ${content["data"]} \"supportVoiceMessage\":true,\"voiceMessageAppId\":\"55053e20\",\"authUrl\":\"http://accounts-4j.sit.ninetechone.com\"
反例-传入错误的token
[Tags] E
......@@ -31,4 +31,4 @@ ${path} /api/system/config/web
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Should Be Equal As Strings ${content["data"]} {\"supportedModels\":[\"GPT-4o\",\"DeepSeek\"],\"supportVoiceMessage\":true,\"voiceMessageAppId\":\"55053e20\",\"authUrl\":\"http://accounts-4j.sit.ninetechone.com\"}
Should Contain ${content["data"]} \"supportVoiceMessage\":true,\"voiceMessageAppId\":\"55053e20\",\"authUrl\":\"http://accounts-4j.sit.ninetechone.com\"
......@@ -28,6 +28,7 @@ ${clientId} a68ad587830d41aebf418a919006353e
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${text_streamId} ${content["data"]}
Sleep 10
正例-正常发送jpg消息
[Tags] F
......@@ -42,6 +43,7 @@ ${clientId} a68ad587830d41aebf418a919006353e
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${jpg_streamId} ${content["data"]["id"]}
Sleep 10
正例-正常发送jpg+文字消息
[Tags] F
......@@ -51,144 +53,157 @@ ${clientId} a68ad587830d41aebf418a919006353e
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${j&t_streamId} ${content["data"]}
Sleep 10
正例-正常发送gif消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${gif_file}', open(r'${CURDIR}${/}testfiles${/}${gif_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${gif_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${gif_file}', open(r'${CURDIR}${/}testfiles${/}${gif_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${gif_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送gif+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${gif_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${g&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${gif_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${g&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送jpeg消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${jpeg_file}', open(r'${CURDIR}${/}testfiles${/}${jpeg_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${jpeg_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${jpeg_file}', open(r'${CURDIR}${/}testfiles${/}${jpeg_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${jpeg_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送jpeg+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${jpeg_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${je&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${jpeg_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${je&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送png消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${png_file}', open(r'${CURDIR}${/}testfiles${/}${png_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${png_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${png_file}', open(r'${CURDIR}${/}testfiles${/}${png_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${png_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送png+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${png_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${p&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${png_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${p&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送webp消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${webp_file}', open(r'${CURDIR}${/}testfiles${/}${webp_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${webp_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${webp_file}', open(r'${CURDIR}${/}testfiles${/}${webp_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${webp_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送webp+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${webp_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${we&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${webp_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${we&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送csv消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${csv_file}', open(r'${CURDIR}${/}testfiles${/}${csv_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${csv_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${csv_file}', open(r'${CURDIR}${/}testfiles${/}${csv_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${csv_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送csv+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${csv_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${c&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${csv_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${c&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送doc消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${doc_file}', open(r'${CURDIR}${/}testfiles${/}${doc_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${doc_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${doc_file}', open(r'${CURDIR}${/}testfiles${/}${doc_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${doc_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送doc+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${doc_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${d&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${doc_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${d&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送docx消息
[Tags] F
......@@ -203,6 +218,7 @@ ${clientId} a68ad587830d41aebf418a919006353e
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${docx_streamId} ${content["data"]["id"]}
Sleep 10
正例-正常发送docx+文字消息
[Tags] F
......@@ -212,98 +228,107 @@ ${clientId} a68ad587830d41aebf418a919006353e
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${dx&t_streamId} ${content["data"]}
Sleep 10
正例-正常发送md消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${md_file}', open(r'${CURDIR}${/}testfiles${/}${md_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${md_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${md_file}', open(r'${CURDIR}${/}testfiles${/}${md_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${md_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送md+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${md_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${md&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${md_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${md&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送txt消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${txt_file}', open(r'${CURDIR}${/}testfiles${/}${txt_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${txt_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${txt_file}', open(r'${CURDIR}${/}testfiles${/}${txt_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${txt_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送txt+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${txt_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${txt&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${txt_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${txt&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送xls消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${xls_file}', open(r'${CURDIR}${/}testfiles${/}${xls_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${xls_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${xls_file}', open(r'${CURDIR}${/}testfiles${/}${xls_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${xls_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送xls+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${xls_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${xls&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${xls_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${xls&t_streamId} ${content["data"]}
Comment Sleep 10
正例-正常发送xlsx消息
[Tags] F
create session URI ${URL}
${file} Evaluate (r'${xlsx_file}', open(r'${CURDIR}${/}testfiles${/}${xlsx_file}', 'rb'))
${data} Create Dictionary sessionId=${sessionId}
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${xlsx_streamId} ${content["data"]["id"]}
Comment create session URI ${URL}
Comment ${file} Evaluate (r'${xlsx_file}', open(r'${CURDIR}${/}testfiles${/}${xlsx_file}', 'rb'))
Comment ${data} Create Dictionary sessionId=${sessionId}
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${uploadpath} files=${files} data=${data} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${xlsx_streamId} ${content["data"]["id"]}
Comment Sleep 10
正例-正常发送xlsx+文字消息
[Tags] F
create session URI ${URL}
${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${xlsx_streamId}"} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Set Global Variable ${xlsx&t_streamId} ${content["data"]}
Comment create session URI ${URL}
Comment ${content} POST请求结果_PARAMS ${path} {"sessionId":"${sessionId}","text":"你好","workerId":"${clientId}","files":"${xlsx_streamId}"} 200 ${token}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
Comment Set Global Variable ${xlsx&t_streamId} ${content["data"]}
Comment Sleep 10
反例-传入错误token
[Tags] E
......
......@@ -13,12 +13,12 @@ ${clientId} a68ad587830d41aebf418a919006353e
Sleep 10
${resp} Get ExpId http://bitagent.sit.ninetechone.com/${path} ${sessionId} ${ex_streamId} ${token}
log ${resp}
Should Contain ${resp["sessionId"]} P_EXP
Should Contain ${resp["sessionId"]} P_TSK
Set Global Variable ${expId} ${resp["sessionId"]}
${content} GET请求结果 /api/chat/retry {"sessionId":"${expId}","workerId":"${clientId}"} 200 ${token}
Set Global Variable ${streamId} ${content["data"]}
${resp1} Get ExpId http://bitagent.sit.ninetechone.com/${path} ${expId} ${streamId} ${token}
log ${resp1}
Comment ${content} GET请求结果 /api/chat/retry {"sessionId":"${expId}","workerId":"${clientId}"} 200 ${token}
Comment Set Global Variable ${streamId} ${content["data"]}
Comment ${resp1} Get ExpId http://bitagent.sit.ninetechone.com/${path} ${expId} ${streamId} ${token}
Comment log ${resp1}
正例-正常读取对话消息
[Tags] F
......
......@@ -13,7 +13,6 @@ ${path} /api/system/config
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Should Be Equal As Strings ${content["data"]} {'supportedModels': ['GPT-4o', 'DeepSeek'], 'supportVoiceMessage': True, 'voiceMessageAppId': '55053e20'}
反例-不传入token
[Tags] E
......@@ -22,7 +21,6 @@ ${path} /api/system/config
log ${content}
Should Be Equal As Strings ${content["code"]} 200 ${EMPTY}
Should Be Equal As Strings ${content["message"]} 成功
Should Be Equal As Strings ${content["data"]} {'supportedModels': ['GPT-4o', 'DeepSeek'], 'supportVoiceMessage': True, 'voiceMessageAppId': '55053e20'}
反例-传入错误的token
[Tags] E
......@@ -31,4 +29,3 @@ ${path} /api/system/config
log ${content}
Should Be Equal As Strings ${content["code"]} 200 testtoken
Should Be Equal As Strings ${content["message"]} 成功
Should Be Equal As Strings ${content["data"]} {'supportedModels': ['GPT-4o', 'DeepSeek'], 'supportVoiceMessage': True, 'voiceMessageAppId': '55053e20'}
......@@ -7,37 +7,40 @@ ${path} /api/system/issue
*** Test Cases ***
正例-正常上报反馈
[Documentation] 未区分生产环境与SIT环境,暂时注释此条用例
[Tags] F
create session URI ${URL}
${file} Evaluate (r'testissue.zip', open(r'${CURDIR}${/}testfiles${/}testissue.zip', 'rb'))
${header} Create Dictionary Authorization=${token}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${path} files=${files} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Comment create session URI ${URL}
Comment ${file} Evaluate (r'testissue.zip', open(r'${CURDIR}${/}testfiles${/}testissue.zip', 'rb'))
Comment ${header} Create Dictionary Authorization=${token}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${path} files=${files} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
反例-不传token
[Documentation] 未区分生产环境与SIT环境,暂时注释此条用例
[Tags] E
create session URI ${URL}
${file} Evaluate (r'testissue.zip', open(r'${CURDIR}${/}testfiles${/}testissue.zip', 'rb'))
${header} Create Dictionary Authorization=${EMPTY}
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${path} files=${files} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Comment create session URI ${URL}
Comment ${file} Evaluate (r'testissue.zip', open(r'${CURDIR}${/}testfiles${/}testissue.zip', 'rb'))
Comment ${header} Create Dictionary Authorization=${EMPTY}
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${path} files=${files} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
反例-传入错误的token
[Documentation] 未区分生产环境与SIT环境,暂时注释此条用例
[Tags] E
create session URI ${URL}
${file} Evaluate (r'testissue.zip', open(r'${CURDIR}${/}testfiles${/}testissue.zip', 'rb'))
${header} Create Dictionary Authorization=testtoken
${files} Create Dictionary file=${file}
${resp} Post On Session URI ${path} files=${files} headers=${header}
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
Comment create session URI ${URL}
Comment ${file} Evaluate (r'testissue.zip', open(r'${CURDIR}${/}testfiles${/}testissue.zip', 'rb'))
Comment ${header} Create Dictionary Authorization=testtoken
Comment ${files} Create Dictionary file=${file}
Comment ${resp} Post On Session URI ${path} files=${files} headers=${header}
Comment ${content} Set Variable ${resp.json()}
Comment log ${content}
Comment Should Be Equal As Strings ${content["code"]} 200
Comment Should Be Equal As Strings ${content["message"]} 成功
......@@ -12,7 +12,7 @@ ${path} /api/ability
${random_string} Generate Random String 12 [LOWER]
log ${random_string}
create session URI ${URL}
${content} POST请求结果 ${path} {"exploreSessionId":"${expId}","filteredStepIndices":[0],"draft":{"name":"${random_string}","description":"自动化测试","parameters":[],"startPageUrl":"https://www.baidu.com","stepIndices":[0]}} 200 ${token}
${content} POST请求结果 ${path} {"exploreSessionId":"${expId}","filteredStepIndices":[0],"draft":{"name":"${random_string}","description":"自动化测试","parameters":[],"outputs":[],"extensions":{"skipError":false,"useIncognito":false,"closePage":false,"stepInterval":1000,"autoFocus":false},"startPageUrl":"https://www.baidu.com/","stepIndices":[0]}} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
......@@ -21,7 +21,7 @@ ${path} /api/ability
反例-不传入token
[Tags] E
create session URI ${URL}
${content} POST请求结果 ${path} {"exploreSessionId":"EXP_ccf7bd255c8a47248b87bf73e5fd5680","filteredStepIndices":[0],"draft":{"name":"outhagent","description":"该能力用于访问百度主页,以查看其内容和功能。用户可以通过此能力快速打开百度主页,进行信息搜索和浏览。","startPageUrl":"https://www.baidu.com","parameters":[{"name":"search_query","description":"用户希望在百度上搜索的关键词。","example": "天气预报","type": "string"}],"stepIndices": [0]}} 401 {}
${content} POST请求结果 ${path} {"exploreSessionId":"${expId}","filteredStepIndices":[0],"draft":{"name":"test666","description":"自动化测试","parameters":[],"outputs":[],"extensions":{"skipError":false,"useIncognito":false,"closePage":false,"stepInterval":1000,"autoFocus":false},"startPageUrl":"https://www.baidu.com/","stepIndices":[0]}} 401 {}
log ${content}
Should Be Equal As Strings ${content["code"]} 401
Should Be Equal As Strings ${content["message"]} 无效的access token
......@@ -45,7 +45,7 @@ ${path} /api/ability
反例-能力名已存在
[Tags] F
create session URI ${URL}
${content} POST请求结果 ${path} {"exploreSessionId":"${expId}","filteredStepIndices":[0],"draft":{"name":"outhagent","description":"自动化测试","parameters":[],"startPageUrl":"https://www.baidu.com","stepIndices":[0]}} 200 ${token}
${content} POST请求结果 ${path} {"exploreSessionId":"${expId}","filteredStepIndices":[0],"draft":{"name":"outhagent","description":"自动化测试","parameters":[],"outputs":[],"extensions":{"skipError":false,"useIncognito":false,"closePage":false,"stepInterval":1000,"autoFocus":false},"startPageUrl":"https://www.baidu.com/","stepIndices":[0]}} 200 ${token}
log ${content}
Should Be Equal As Strings ${content["code"]} BAE0008
Should Be Equal As Strings ${content["message"]} 此能力名已存在
......@@ -51,5 +51,5 @@ ${path} /api/ability
Should Be Equal As Integers ${resp.status_code} 200
${content} Set Variable ${resp.json()}
log ${content}
Should Be Equal As Strings ${content["code"]} 500
Should Be Equal As Strings ${content["message"]} Server busy, please try later
Should Be Equal As Strings ${content["code"]} 200
Should Be Equal As Strings ${content["message"]} 成功
......@@ -29,7 +29,7 @@ def get_expId(url,sessionId,streamId,token,timeout=180):
if localtime > starttime + timeout:
opdata = "获取探索id超时"
break
if 'EXP' in msg.data:
if 'EXP' in msg.data or 'TSK' in msg.data:
# print("Received Message:", msg.data)
opdata = json.loads(msg.data)
break
......
# import asyncio
# import logging
# import random
# import time
#
# import requests
# import json
# import grpc.aio
#
# from grpc_client import GrpcClient
# from grpc_listener import GrpcListener
# from models import ResultModel
#
# # 配置日志
# logging.basicConfig(level=logging.INFO)
# logger = logging.getLogger(__name__)
# #定义全局变量 fetchUI次数
# isopentab = 0
# isfetchui = 0
# # 认证配置
# auth_config = {
# "headers": {
# "Content-Type": "application/x-www-form-urlencoded",
# "Sm4-Key": "dUVNkTJLlzMHPqBTZh085jT0N6S7930l6sgddJsYSC8=",
# "Cookie": "ENCRYPT_KEY=f48bf3-05fe-4978"
# },
# "params": {
# "username": "api_tester",
# "password": "$SM4$Nd/e40vIS6UD9VMaSOmYGlrBORfo7r5/1z9D5d4E4es=$4MS$",
# "tenantCode": "API_test",
# "scope": "all",
# "client_id": "a68ad587830d41aebf418a919006353e",
# "client_secret": "Ninetech@123",
# "grant_type": "password"
# }
# }
#
# async def handle_message(request_path, request_data):
# global isopentab
# global isfetchui
# if request_path == "list_mcp_servers": # 特定指令1
# return ResultModel(code=200, data=[], message="")
# elif request_path == "adaptable_activities": # 特定指令2
# return ResultModel(code=200, data=[
# {"id": "keyboard_entry", "name": "keyboard_entry", "displayName": "键盘输入", "description": "键盘输入", "parametersSchema": {"description": "键盘输入", "properties": {"key_code": {"description": "输入键盘码或组合快捷键,支持Playwright键盘码和组合快捷键,例如:[`F1`, `F2`, `F3`, `F4`, `F5`, `F6`, `F7`, `F8`, `F9`, `F10`, `F11`, `F12`, `Digit0`, `Digit1`, `Digit2`, `Digit3`, `Digit4`, `Digit5`, `Digit6`, `Digit7`, `Digit8`, `Digit9`, `KeyA`, `KeyB`, `KeyC`, `KeyD`, `KeyE`, `KeyF`, `KeyG`, `KeyH`, `KeyI`, `KeyJ`, `KeyK`, `KeyL`, `KeyM`, `KeyN`, `KeyO`, `KeyP`, `KeyQ`, `KeyR`, `KeyS`, `KeyT`, `KeyU`, `KeyV`, `KeyW`, `KeyX`, `KeyY`, `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,`Delete`, `Escape`, `ArrowDown`, `PageDown`, `PageUp`, `ArrowLeft`,`ArrowRight`, `ArrowUp`],Shortcuts such as `Control+o`, `Control++`, `Control+Shift+T` , `Alt+ArrowRight` or `Alt+ArrowLeft`", "title": "Key Code", "type": "string"}}, "required": ["key_code"], "title": "KeyboardEntry", "type": "object"}, "elementIdJsonPaths": [], "icon": "keyboard_entry", "timeout": 180}, {"id": "navigate_page", "name": "navigate_page", "displayName": "跳转到网页", "description": "跳转到网页", "parametersSchema": {"$defs": {"NavigatePageType": {"enum": ["go_to", "go_back", "go_forward", "refresh"], "title": "NavigatePageType", "type": "string"}}, "description": "跳转到网页", "properties": {"url": {"default": "", "description": "需要打开的url", "title": "Url", "type": "string"}, "type": {"$ref": "#/$defs/NavigatePageType", "description": "需要操作的类型"}}, "required": ["type"], "title": "NavigatePage", "type": "object"}, "elementIdJsonPaths": [], "icon": "navigate_page", "timeout": 180}, {"id": "sleep_seconds", "name": "sleep_seconds", "displayName": "等待", "description": "此工具的用途是在目标无法达成时进行等待,最多等待2次", "parametersSchema": {"description": "等待", "properties": {"wait_seconds": {"default": 5, "description": "默认5秒,可修改为1-5秒时间", "title": "Wait Seconds", "type": "integer"}}, "title": "SleepSeconds", "type": "object", "required": []}, "elementIdJsonPaths": [], "icon": "sleep_seconds", "timeout": 180}, {"id": "switch_page", "name": "switch_page", "displayName": "切换页面", "description": "切换页面", "parametersSchema": {"description": "切换页面", "properties": {"page_id": {"description": "需要切换的页面id,如果id对应的页面不存在将不会切换成功", "title": "Page Id", "type": "string"}}, "required": ["page_id"], "title": "SwitchPage", "type": "object"}, "elementIdJsonPaths": [], "icon": "switch_page", "timeout": 180}, {"id": "click", "name": "click", "displayName": "点击元素", "description": "点击某个元素", "parametersSchema": {"description": "点击某个元素", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}}, "required": ["element_id"], "title": "ClickElement", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "click", "timeout": 180}, {"id": "input_text", "name": "input_text", "displayName": "输入文本", "description": "输入文本", "parametersSchema": {"description": "输入内容", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}, "content": {"description": "需要输入的内容", "title": "Content", "type": "string"}}, "required": ["element_id", "content"], "title": "InputText", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "input_text", "timeout": 180}, {"id": "select_option", "name": "select_option", "displayName": "选择选项", "description": "选择某个选项,仅适用于radio,checkbox,select,option标签及点击后有dropdown menu效果的标签。label,value,index三者至少填一个", "parametersSchema": {"description": "选择某个选项", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}, "label": {"anyOf": [{"type": "string"}, {"type": "None"}], "default": None, "description": "需要选择的选项的label", "title": "Label"}, "value": {"anyOf": [{"type": "string"}, {"type": "None"}], "default": None, "description": "需要选择的选项的value", "title": "Value"}, "index": {"anyOf": [{"type": "integer"}, {"type": "None"}], "default": None, "description": "需要选择的选项的index索引", "title": "Index"}}, "required": ["element_id"], "title": "SelectOption", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "select_option", "timeout": 180}, {"id": "upload_file", "name": "upload_file", "displayName": "上传文件", "description": "上传文件", "parametersSchema": {"description": "上传文件", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}, "file_id": {"description": "文件ID,从文件空间中选取", "title": "File Id", "type": "string"}}, "required": ["element_id", "file_id"], "title": "UploadFile", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "upload_file", "timeout": 180}],
# message="")
# elif request_path == "get_current_tab":
# return ResultModel(code=200, data={
# "id": "test_tab",
# "url": "https://www.baidu.com/",
# "title": "百度一下,你就知道",
# "screenshot": []
# }, message="")
# elif request_path == "open_tab":
# isopentab = 1
# return ResultModel(code=200, data={
# "id": "test_tab",
# "url": "https://www.baidu.com/",
# "title": "百度一下,你就知道",
# "screenshot": []
# }, message="")
# elif request_path == "fetch_ui":
# if isopentab == 1 or isfetchui == 1 :
# isopentab = 0
# isfetchui = 0
# time.sleep(5)
# return ResultModel(code=200, data= {"url": "https://www.baidu.com/", "content": "<a href=\"http://news.baidu.com\" id=\"pcWI\">新闻</a><a href=\"https://www.hao123.com?src=from_pc\" id=\"KkD4\">hao123</a><a href=\"http://map.baidu.com\" id=\"ZsH9\">地图</a><a href=\"http://tieba.baidu.com/\" id=\"Ggy7\">贴吧</a><a href=\"https://haokan.baidu.com/?sfrom=baidu-top\" id=\"AOeX\">视频</a><a href=\"http://image.baidu.com/\" id=\"Xd1C\">图片</a><a href=\"https://pan.baidu.com?from=1026962h\" id=\"8IWL\">网盘</a><a href=\"https://wenku.baidu.com/?fr=bdpcindex\" id=\"lCsO\">文库</a><a href=\"https://chat.baidu.com/search?isShowHello=1&pd=csaitab&setype=csaitab&extParamsJson=%7B%22enter_type%22%3A%22home_tab%22%7D\" id=\"b5rX\"><img class=\"s-top-tab-image\" id=\"5QSr\"></a><a href=\"http://www.baidu.com/more/\" name=\"tj_briicon\" id=\"lduS\">更多</a><a href=\"https://senode.baidu.com/seop-landing/knowledge_question?ref_sa=searchpromo_selftask_dati_shouyetab\" id=\"SnLp\"><div class=\"operate-image\" id=\"5eWj\"></div></a><span name=\"tj_settingicon\" id=\"LoOR\">设置</span><a href=\"https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F&sms=5\" name=\"tj_login\" id=\"iGko\">登录</a><span class=\"soutu-btn\" id=\"XlOq\"></span><input name=\"wd\" value maxlength=\"255\" placeholder=\"王曼昱亮相美国大满贯海报\" id=\"Ie3z\"><input type=\"submit\" value=\"百度一下\" id=\"zqXv\"><a href=\"https://chat.baidu.com/search?extParams=%7B%22enter_type%22%3A%22ai_explore_home%22%7D&isShowHello=1\" id=\"E13Q\"><div class=\"new_search_guide_bub_container_left\" id=\"jv0S\"><svg></svg><svg></svg></div><div class=\"new_search_guide_bub_container_center\" id=\"j8J7\">AI搜索已支持「DeepSeek-R1」最新版</div><div class=\"new_search_guide_bub_container_right\" id=\"dHgS\">立即体验</div></a><div aria-label=\"百度热搜\" id=\"E7v6\"><i class=\"c-icon hot-title-icon\" id=\"y7ZQ\"></i><i class=\"c-icon arrow\" id=\"Ekyf\"></i></div><a class=\"hot-refresh c-font-normal c-color-gray2\" id=\"lNcM\"><i class=\"c-icon refresh-icon\" id=\"XZkU\"></i><span class=\"hot-refresh-text\" id=\"hF5v\">换一换</span></a><a href=\"{{_86d720161c56c8c50ca074b8addea74e08f618a7d03681af9f56b5bf60a6e109}}\" id=\"914C\"><i class=\"c-icon title-content-top-icon c-color-red c-gap-right-small\" id=\"6EZe\"></i><span class=\"title-content-title\" id=\"R5B4\">世界上最大的政党是如何炼成的</span></a><a href=\"{{_0609df375efd9ef496de58f77a745debd62d2390ee7b5c6861d3c38f98b4f2b6}}\" id=\"7t6N\"><span class=\"title-content-index c-index-single c-index-single-hot5 \" id=\"p5Zy\">5</span><span class=\"title-content-title\" id=\"FqiJ\">《新华字典》称小孩是累赘</span></a><a href=\"{{_0d7c4837c7faf638c147babd6e8a213b9a1cd92f94e8e24f5c502940e96c5833}}\" id=\"ayzg\"><span class=\"title-content-index c-index-single c-index-single-hot1 \" id=\"vJa0\">1</span><span class=\"title-content-title\" id=\"RQ4p\">高校引进高层次人才 第2名举报第1名</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"z7Cd\">新</span><a href=\"{{_e6b1b4573d70f6f8f7fd7d217d73aff2aba5b9e3746e6a9783470b3330bd1917}}\" id=\"ff9J\"><span class=\"title-content-index c-index-single c-index-single-hot6 \" id=\"ovY0\">6</span><span class=\"title-content-title\" id=\"0rtw\">党的旗帜所指 即是网警铁翼所向</span></a><a href=\"{{_13ec6819a42ac28f147cb75ea1b8877a3a7296df40f4a456963f38d2adcba54d}}\" id=\"6TtQ\"><span class=\"title-content-index c-index-single c-index-single-hot2 \" id=\"EAry\">2</span><span class=\"title-content-title\" id=\"DVrk\">韦东奕晋升北大长聘副教授?校方回应</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"Y2ua\">新</span><a href=\"{{_4d4c744b982ab1cd8436ea8806a2785a8c2d258bfdd57828e543080616d50704}}\" id=\"4240\"><span class=\"title-content-index c-index-single c-index-single-hot7 \" id=\"dXlE\">7</span><span class=\"title-content-title\" id=\"k2E1\">广州男子开车看手机撞人致3死3伤</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"JA4p\">新</span><a href=\"{{_2d2cb344298e3c01a7eb639603d5d60037253006c48d5a997856bc86d5e01c9b}}\" id=\"ORRe\"><span class=\"title-content-index c-index-single c-index-single-hot3 \" id=\"j3h2\">3</span><span class=\"title-content-title\" id=\"Bmkd\">香港回归祖国28周年</span></a><a href=\"{{_c938881ae5de8a4a2a8395ee6482ca79a7d140eb1c5a7b0d0ddf48d57e9869b9}}\" id=\"hSRq\"><span class=\"title-content-index c-index-single c-index-single-hot8 \" id=\"aTwd\">8</span><span class=\"title-content-title\" id=\"9XGF\">男子8公斤黄金卖了612万赚312万</span></a><a href=\"{{_833e2addd1c5511c52653c92a46d9a996b7bfa3b7ba32168502057514e315095}}\" id=\"Qb7j\"><span class=\"title-content-index c-index-single c-index-single-hot4 \" id=\"iegt\">4</span><span class=\"title-content-title\" id=\"ubEb\">女子遇已故同学父亲摆摊:买下所有瓜</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"PSS1\">新</span><a href=\"{{_8ae1eeb912dc25e1f8532a67bee6c7923fbf8fbf6b9ecc3cc0e13641c7d8e826}}\" id=\"qDqK\"><span class=\"title-content-index c-index-single c-index-single-hot9 \" id=\"ToGA\">9</span><span class=\"title-content-title\" id=\"3IYi\">客机高空急坠亲历者:给老公写了遗书</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-hot\" id=\"ZSGD\">热</span><a href=\"//home.baidu.com\" id=\"G6xr\">关于百度</a><a href=\"http://ir.baidu.com\" id=\"F2zX\">About Baidu</a><a href=\"//www.baidu.com/duty\" id=\"cN4M\">使用百度前必读</a><a href=\"https://help.baidu.com/question?prod_id=1\" id=\"nvcN\">帮助中心</a><a href=\"https://e.baidu.com/?refer=1271\" id=\"2xUA\">企业推广</a><span class=\"c-icon\" id=\"6r4L\"></span><span class=\"c-icon c-color-gray2\" id=\"Bdmj\"></span>", "elementIdSelectorMapping": {}, "screenshotsBase64": [], "text": "", "page_tabs": [{"id": "B9EF2368E1361855B8603FE716C87B69", "title": "百度一下,你就知道", "url": "https://www.baidu.com/", "active": True, "children": []}]}, message="")
# else:
# isfetchui = 1
# return ResultModel(code=200, data= {"url": "about:blank", "content": "当前页面为空白页", "elementIdSelectorMapping": {}, "screenshotsBase64": [], "text": "", "page_tabs": []}, message="")
# # 默认响应
# return ResultModel(code=200, data={"message": "请求处理成功"})
#
# async def send_ping(listener):
# while True:
# await asyncio.sleep(5)
# await listener.send_to_all_stream(requestId="ping", body="#ping", type=-1)
#
# async def main():
# try:
# # 获取访问令牌
# token_res = requests.post(
# url="http://accounts-4j.sit.ninetechone.com/oauth/token",
# headers=auth_config["headers"],
# params=auth_config["params"]
# )
# token_res.raise_for_status()
#
# # 获取gRPC配置
# config_res = requests.get("http://bitagent.sit.ninetechone.com/api/system/config/client")
# config_res.raise_for_status()
#
# grpc_config = {
# "token": "Bearer " + token_res.json()["access_token"],
# "client_id": auth_config["params"]["client_id"],
# "host": json.loads(config_res.json()["data"])["grpc_host"],
# "is_ssl": json.loads(config_res.json()["data"])["grpc_use_ssl"]
# }
# logging.info(f"gRPC配置加载完成: {grpc_config}")
#
# # 创建 gRPC 客户端
# client = GrpcClient()
# client.set_header(token=grpc_config["token"], client_id=grpc_config["client_id"])
# connected = await client.connect(address=grpc_config["host"], use_ssl=grpc_config["is_ssl"])
# if not connected:
# logger.error("Failed to connect to gRPC server.")
# return
#
# # 创建 gRPC 监听器
# listener = GrpcListener(client)
# listener.message_received = handle_message
# listener.start()
#
# # 启动 ping 任务
# ping_task = asyncio.create_task(send_ping(listener))
#
# try:
# await asyncio.gather(ping_task)
# except asyncio.CancelledError:
# await listener.stop()
#
# except requests.RequestException as e:
# logger.error(f"Request error: {e}")
# except grpc.aio.AioRpcError as e:
# logger.error(f"gRPC error: {e}")
# except Exception as e:
# logger.error(f"Unexpected error: {e}")
#
# if __name__ == "__main__":
# asyncio.run(main())
import asyncio
import logging
import random
import time
import requests
......@@ -14,9 +143,11 @@ from models import ResultModel
# 配置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
#定义全局变量 fetchUI次数
isopentab = 0
isfetchui = 0
# 定义全局变量用于状态跟踪
isopentab = 0 # 标记是否已执行open_tab
has_received_adaptable = False # 标记是否已接收adaptable_activities指令
first_fetch_after_adaptable = False # 标记adaptable_activities后的首次fetch_ui
# 认证配置
auth_config = {
"headers": {
......@@ -35,15 +166,228 @@ auth_config = {
}
}
# 定义需要创建gRPC连接的3个client_id
CLIENT_IDS = [
"a68ad587830d41aebf418a919006353e",
"a68ad587830d41aebf418a919006353e_Default",
"a68ad587830d41aebf418a919006353e_InPrivate"
]
async def handle_message(request_path, request_data):
global isopentab
global isfetchui
global has_received_adaptable
global first_fetch_after_adaptable
if request_path == "list_mcp_servers": # 特定指令1
return ResultModel(code=200, data=[], message="")
elif request_path == "adaptable_activities": # 特定指令2
return ResultModel(code=200, data=[
{"id": "keyboard_entry", "name": "keyboard_entry", "displayName": "键盘输入", "description": "键盘输入", "parametersSchema": {"description": "键盘输入", "properties": {"key_code": {"description": "输入键盘码或组合快捷键,支持Playwright键盘码和组合快捷键,例如:[`F1`, `F2`, `F3`, `F4`, `F5`, `F6`, `F7`, `F8`, `F9`, `F10`, `F11`, `F12`, `Digit0`, `Digit1`, `Digit2`, `Digit3`, `Digit4`, `Digit5`, `Digit6`, `Digit7`, `Digit8`, `Digit9`, `KeyA`, `KeyB`, `KeyC`, `KeyD`, `KeyE`, `KeyF`, `KeyG`, `KeyH`, `KeyI`, `KeyJ`, `KeyK`, `KeyL`, `KeyM`, `KeyN`, `KeyO`, `KeyP`, `KeyQ`, `KeyR`, `KeyS`, `KeyT`, `KeyU`, `KeyV`, `KeyW`, `KeyX`, `KeyY`, `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,`Delete`, `Escape`, `ArrowDown`, `PageDown`, `PageUp`, `ArrowLeft`,`ArrowRight`, `ArrowUp`],Shortcuts such as `Control+o`, `Control++`, `Control+Shift+T` , `Alt+ArrowRight` or `Alt+ArrowLeft`", "title": "Key Code", "type": "string"}}, "required": ["key_code"], "title": "KeyboardEntry", "type": "object"}, "elementIdJsonPaths": [], "icon": "keyboard_entry", "timeout": 180}, {"id": "navigate_page", "name": "navigate_page", "displayName": "跳转到网页", "description": "跳转到网页", "parametersSchema": {"$defs": {"NavigatePageType": {"enum": ["go_to", "go_back", "go_forward", "refresh"], "title": "NavigatePageType", "type": "string"}}, "description": "跳转到网页", "properties": {"url": {"default": "", "description": "需要打开的url", "title": "Url", "type": "string"}, "type": {"$ref": "#/$defs/NavigatePageType", "description": "需要操作的类型"}}, "required": ["type"], "title": "NavigatePage", "type": "object"}, "elementIdJsonPaths": [], "icon": "navigate_page", "timeout": 180}, {"id": "sleep_seconds", "name": "sleep_seconds", "displayName": "等待", "description": "此工具的用途是在目标无法达成时进行等待,最多等待2次", "parametersSchema": {"description": "等待", "properties": {"wait_seconds": {"default": 5, "description": "默认5秒,可修改为1-5秒时间", "title": "Wait Seconds", "type": "integer"}}, "title": "SleepSeconds", "type": "object", "required": []}, "elementIdJsonPaths": [], "icon": "sleep_seconds", "timeout": 180}, {"id": "switch_page", "name": "switch_page", "displayName": "切换页面", "description": "切换页面", "parametersSchema": {"description": "切换页面", "properties": {"page_id": {"description": "需要切换的页面id,如果id对应的页面不存在将不会切换成功", "title": "Page Id", "type": "string"}}, "required": ["page_id"], "title": "SwitchPage", "type": "object"}, "elementIdJsonPaths": [], "icon": "switch_page", "timeout": 180}, {"id": "click", "name": "click", "displayName": "点击元素", "description": "点击某个元素", "parametersSchema": {"description": "点击某个元素", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}}, "required": ["element_id"], "title": "ClickElement", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "click", "timeout": 180}, {"id": "input_text", "name": "input_text", "displayName": "输入文本", "description": "输入文本", "parametersSchema": {"description": "输入内容", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}, "content": {"description": "需要输入的内容", "title": "Content", "type": "string"}}, "required": ["element_id", "content"], "title": "InputText", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "input_text", "timeout": 180}, {"id": "select_option", "name": "select_option", "displayName": "选择选项", "description": "选择某个选项,仅适用于radio,checkbox,select,option标签及点击后有dropdown menu效果的标签。label,value,index三者至少填一个", "parametersSchema": {"description": "选择某个选项", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}, "label": {"anyOf": [{"type": "string"}, {"type": "null"}], "default": None, "description": "需要选择的选项的label", "title": "Label"}, "value": {"anyOf": [{"type": "string"}, {"type": "null"}], "default": None, "description": "需要选择的选项的value", "title": "Value"}, "index": {"anyOf": [{"type": "integer"}, {"type": "null"}], "default": None, "description": "需要选择的选项的index索引", "title": "Index"}}, "required": ["element_id"], "title": "SelectOption", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "select_option", "timeout": 180}, {"id": "upload_file", "name": "upload_file", "displayName": "上传文件", "description": "上传文件", "parametersSchema": {"description": "上传文件", "properties": {"element_id": {"description": "需要操作元素的id", "title": "Element Id", "type": "string"}, "file_id": {"description": "文件ID,从文件空间中选取", "title": "File Id", "type": "string"}}, "required": ["element_id", "file_id"], "title": "UploadFile", "type": "object"}, "elementIdJsonPaths": ["$.element_id"], "icon": "upload_file", "timeout": 180}],
message="")
# 接收该指令后,标记状态(后续首次fetch_ui需要返回空白页)
has_received_adaptable = True
first_fetch_after_adaptable = True
return ResultModel(code=200, data=[{"id": "close_tab", "name": "close_tab", "displayName": "关闭标签页",
"description": "默认关闭当前的标签页,is_all_close参数可控制是否标签页全部关闭,is_close_children参数控制是否关闭当前页的子标签页",
"parametersSchema": {"description": "关闭页签", "properties": {
"is_all_close": {"default": False, "description": "是否全部关闭",
"title": "Is All Close", "type": "boolean"},
"is_close_children": {"default": False, "description": "是否关闭子页签",
"title": "Is Close Children", "type": "boolean"}},
"title": "CloseTab", "type": "object", "required": []},
"elementIdJsonPaths": [], "icon": "close_tab", "timeout": 180},
{"id": "keyboard_entry", "name": "keyboard_entry", "displayName": "键盘输入",
"description": "键盘输入", "parametersSchema": {"description": "键盘输入",
"properties": {"key_code": {
"description": "输入键盘码或组合快捷键,支持Playwright键盘码和组合快捷键,例如:[`F1`, `F2`, `F3`, `F4`, `F5`, `F6`, `F7`, `F8`, `F9`, `F10`, `F11`, `F12`, `Digit0`, `Digit1`, `Digit2`, `Digit3`, `Digit4`, `Digit5`, `Digit6`, `Digit7`, `Digit8`, `Digit9`, `KeyA`, `KeyB`, `KeyC`, `KeyD`, `KeyE`, `KeyF`, `KeyG`, `KeyH`, `KeyI`, `KeyJ`, `KeyK`, `KeyL`, `KeyM`, `KeyN`, `KeyO`, `KeyP`, `KeyQ`, `KeyR`, `KeyS`, `KeyT`, `KeyU`, `KeyV`, `KeyW`, `KeyX`, `KeyY`, `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,`Delete`, `Escape`, `ArrowDown`, `PageDown`, `PageUp`, `ArrowLeft`,`ArrowRight`, `ArrowUp`],Shortcuts such as `Control+o`, `Control++`, `Control+Shift+T` , `Alt+ArrowRight` or `Alt+ArrowLeft`",
"enum": ["F1", "F2",
"F3", "F4",
"F5", "F6",
"F7", "F8",
"F9", "F10",
"F11", "F12",
"Digit0",
"Digit1",
"Digit2",
"Digit3",
"Digit4",
"Digit5",
"Digit6",
"Digit7",
"Digit8",
"Digit9",
"KeyA", "KeyB",
"KeyC", "KeyD",
"KeyE", "KeyF",
"KeyG", "KeyH",
"KeyI", "KeyJ",
"KeyK", "KeyL",
"KeyM", "KeyN",
"KeyO", "KeyP",
"KeyQ", "KeyR",
"KeyS", "KeyT",
"KeyU", "KeyV",
"KeyW", "KeyX",
"KeyY", "KeyZ",
"Backquote",
"Minus",
"Equal",
"Backslash",
"Backspace",
"Tab",
"Delete",
"Escape",
"ArrowDown",
"PageDown",
"PageUp",
"ArrowLeft",
"ArrowRight",
"ArrowUp",
"Control+o",
"Control++",
"Control+Shift+T",
"Alt+ArrowRight",
"Alt+ArrowLeft"],
"title": "Key Code",
"type": "string"}},
"required": ["key_code"],
"title": "KeyboardEntry",
"type": "object"},
"elementIdJsonPaths": [], "icon": "keyboard_entry", "timeout": 180},
{"id": "navigate_page", "name": "navigate_page", "displayName": "跳转到网页",
"description": "跳转到网页", "parametersSchema": {"$defs": {
"NavigatePageType": {
"enum": ["go_to", "go_back", "go_forward", "refresh"],
"title": "NavigatePageType", "type": "string"}},
"description": "跳转到网页",
"properties": {
"url": {"default": "",
"description": "需要打开的url",
"title": "Url",
"type": "string"},
"type": {
"$ref": "#/$defs/NavigatePageType",
"description": "需要操作的类型"}},
"required": ["type"],
"title": "NavigatePage",
"type": "object"},
"elementIdJsonPaths": [], "icon": "navigate_page", "timeout": 180},
{"id": "sleep_seconds", "name": "sleep_seconds", "displayName": "等待",
"description": "此工具的用途是在目标无法达成时进行等待,最多等待2次",
"parametersSchema": {"description": "等待", "properties": {
"wait_seconds": {"default": 5,
"description": "默认5秒,可修改为1-5秒时间",
"title": "Wait Seconds", "type": "integer"}},
"title": "SleepSeconds", "type": "object",
"required": []}, "elementIdJsonPaths": [],
"icon": "sleep_seconds", "timeout": 180},
{"id": "switch_page", "name": "switch_page", "displayName": "切换页面",
"description": "切换页面", "parametersSchema": {"description": "切换页面",
"properties": {"page_id": {
"description": "需要切换的页面id,如果id对应的页面不存在将不会切换成功",
"title": "Page Id",
"type": "string"}},
"required": ["page_id"],
"title": "SwitchPage",
"type": "object"},
"elementIdJsonPaths": [], "icon": "switch_page", "timeout": 180},
{"id": "click", "name": "click", "displayName": "点击元素",
"description": "点击某个元素",
"parametersSchema": {"description": "点击某个元素", "properties": {
"element_id": {"description": "需要操作元素的id", "title": "Element Id",
"type": "string"}}, "required": ["element_id"],
"title": "ClickElement", "type": "object"},
"elementIdJsonPaths": ["$.element_id"], "icon": "click", "timeout": 180},
{"id": "input_text", "name": "input_text", "displayName": "输入文本",
"description": "输入文本", "parametersSchema": {"description": "输入内容",
"properties": {
"element_id": {
"description": "需要操作元素的id",
"title": "Element Id",
"type": "string"},
"content": {
"description": "需要输入的内容",
"title": "Content",
"type": "string"}},
"required": ["element_id",
"content"],
"title": "InputText",
"type": "object"},
"elementIdJsonPaths": ["$.element_id"], "icon": "input_text",
"timeout": 180}, {"id": "screenshot_element", "name": "screenshot_element",
"displayName": "元素截图", "description": "截图某个元素",
"parametersSchema": {"description": "截图某个元素",
"properties": {"element_id": {
"description": "需要操作元素的id",
"title": "Element Id",
"type": "string"}},
"required": ["element_id"],
"title": "ScreenshotElement",
"type": "object"},
"elementIdJsonPaths": ["$.element_id"],
"icon": "screenshot_element", "timeout": 180},
{"id": "select_option", "name": "select_option", "displayName": "选择选项",
"description": "选择某个选项,仅适用于radio,checkbox,select,option标签及点击后有dropdown menu效果的标签。label,value,index三者至少填一个",
"parametersSchema": {"description": "选择某个选项", "properties": {
"element_id": {"description": "需要操作元素的id", "title": "Element Id",
"type": "string"},
"label": {"anyOf": [{"type": "string"}, {"type": "None"}],
"default": None, "description": "需要选择的选项的label",
"title": "Label"},
"value": {"anyOf": [{"type": "string"}, {"type": "None"}],
"default": None, "description": "需要选择的选项的value",
"title": "Value"},
"index": {"anyOf": [{"type": "integer"}, {"type": "None"}],
"default": None, "description": "需要选择的选项的index索引",
"title": "Index"}}, "required": ["element_id"],
"title": "SelectOption", "type": "object"},
"elementIdJsonPaths": ["$.element_id"], "icon": "select_option",
"timeout": 180},
{"id": "slider_bar", "name": "slider_bar", "displayName": "拖动滑块",
"description": "拖动滑块", "parametersSchema": {"description": "拖动滑块",
"properties": {
"element_id": {
"description": "需要操作元素的id",
"title": "Element Id",
"type": "string"},
"value": {
"description": "滑块设定值",
"title": "Value",
"type": "number"},
"min_value": {
"description": "必须给出滑块可拖动最大值,根据页面元素获取",
"title": "Min Value",
"type": "number"},
"max_value": {
"description": "必须给出滑块可拖动最小值,根据页面元素获取",
"title": "Max Value",
"type": "number"}},
"required": ["element_id",
"value",
"min_value",
"max_value"],
"title": "SliderBar",
"type": "object"},
"elementIdJsonPaths": ["$.element_id"], "icon": "slider_bar",
"timeout": 180},
{"id": "upload_file", "name": "upload_file", "displayName": "上传文件",
"description": "上传文件", "parametersSchema": {"description": "上传文件",
"properties": {
"element_id": {
"description": "需要操作元素的id",
"title": "Element Id",
"type": "string"},
"file_id": {
"description": "文件ID,从文件空间中选取",
"title": "File Id",
"type": "string"}},
"required": ["element_id",
"file_id"],
"title": "UploadFile",
"type": "object"},
"elementIdJsonPaths": ["$.element_id"], "icon": "upload_file",
"timeout": 180}],
message="")
elif request_path == "get_current_tab":
return ResultModel(code=200, data={
"id": "test_tab",
......@@ -51,7 +395,9 @@ async def handle_message(request_path, request_data):
"title": "百度一下,你就知道",
"screenshot": []
}, message="")
elif request_path == "open_tab":
# 执行open_tab后,标记状态(后续fetch_ui需要返回百度页面)
isopentab = 1
return ResultModel(code=200, data={
"id": "test_tab",
......@@ -59,23 +405,101 @@ async def handle_message(request_path, request_data):
"title": "百度一下,你就知道",
"screenshot": []
}, message="")
elif request_path == "fetch_ui":
if isopentab == 1 or isfetchui == 1 :
isopentab = 0
isfetchui = 0
time.sleep(5)
return ResultModel(code=200, data= {"url": "https://www.baidu.com/", "content": "<a href=\"http://news.baidu.com\" id=\"pcWI\">新闻</a><a href=\"https://www.hao123.com?src=from_pc\" id=\"KkD4\">hao123</a><a href=\"http://map.baidu.com\" id=\"ZsH9\">地图</a><a href=\"http://tieba.baidu.com/\" id=\"Ggy7\">贴吧</a><a href=\"https://haokan.baidu.com/?sfrom=baidu-top\" id=\"AOeX\">视频</a><a href=\"http://image.baidu.com/\" id=\"Xd1C\">图片</a><a href=\"https://pan.baidu.com?from=1026962h\" id=\"8IWL\">网盘</a><a href=\"https://wenku.baidu.com/?fr=bdpcindex\" id=\"lCsO\">文库</a><a href=\"https://chat.baidu.com/search?isShowHello=1&pd=csaitab&setype=csaitab&extParamsJson=%7B%22enter_type%22%3A%22home_tab%22%7D\" id=\"b5rX\"><img class=\"s-top-tab-image\" id=\"5QSr\"></a><a href=\"http://www.baidu.com/more/\" name=\"tj_briicon\" id=\"lduS\">更多</a><a href=\"https://senode.baidu.com/seop-landing/knowledge_question?ref_sa=searchpromo_selftask_dati_shouyetab\" id=\"SnLp\"><div class=\"operate-image\" id=\"5eWj\"></div></a><span name=\"tj_settingicon\" id=\"LoOR\">设置</span><a href=\"https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F&sms=5\" name=\"tj_login\" id=\"iGko\">登录</a><span class=\"soutu-btn\" id=\"XlOq\"></span><input name=\"wd\" value maxlength=\"255\" placeholder=\"王曼昱亮相美国大满贯海报\" id=\"Ie3z\"><input type=\"submit\" value=\"百度一下\" id=\"zqXv\"><a href=\"https://chat.baidu.com/search?extParams=%7B%22enter_type%22%3A%22ai_explore_home%22%7D&isShowHello=1\" id=\"E13Q\"><div class=\"new_search_guide_bub_container_left\" id=\"jv0S\"><svg></svg><svg></svg></div><div class=\"new_search_guide_bub_container_center\" id=\"j8J7\">AI搜索已支持「DeepSeek-R1」最新版</div><div class=\"new_search_guide_bub_container_right\" id=\"dHgS\">立即体验</div></a><div aria-label=\"百度热搜\" id=\"E7v6\"><i class=\"c-icon hot-title-icon\" id=\"y7ZQ\"></i><i class=\"c-icon arrow\" id=\"Ekyf\"></i></div><a class=\"hot-refresh c-font-normal c-color-gray2\" id=\"lNcM\"><i class=\"c-icon refresh-icon\" id=\"XZkU\"></i><span class=\"hot-refresh-text\" id=\"hF5v\">换一换</span></a><a href=\"{{_86d720161c56c8c50ca074b8addea74e08f618a7d03681af9f56b5bf60a6e109}}\" id=\"914C\"><i class=\"c-icon title-content-top-icon c-color-red c-gap-right-small\" id=\"6EZe\"></i><span class=\"title-content-title\" id=\"R5B4\">世界上最大的政党是如何炼成的</span></a><a href=\"{{_0609df375efd9ef496de58f77a745debd62d2390ee7b5c6861d3c38f98b4f2b6}}\" id=\"7t6N\"><span class=\"title-content-index c-index-single c-index-single-hot5 \" id=\"p5Zy\">5</span><span class=\"title-content-title\" id=\"FqiJ\">《新华字典》称小孩是累赘</span></a><a href=\"{{_0d7c4837c7faf638c147babd6e8a213b9a1cd92f94e8e24f5c502940e96c5833}}\" id=\"ayzg\"><span class=\"title-content-index c-index-single c-index-single-hot1 \" id=\"vJa0\">1</span><span class=\"title-content-title\" id=\"RQ4p\">高校引进高层次人才 第2名举报第1名</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"z7Cd\">新</span><a href=\"{{_e6b1b4573d70f6f8f7fd7d217d73aff2aba5b9e3746e6a9783470b3330bd1917}}\" id=\"ff9J\"><span class=\"title-content-index c-index-single c-index-single-hot6 \" id=\"ovY0\">6</span><span class=\"title-content-title\" id=\"0rtw\">党的旗帜所指 即是网警铁翼所向</span></a><a href=\"{{_13ec6819a42ac28f147cb75ea1b8877a3a7296df40f4a456963f38d2adcba54d}}\" id=\"6TtQ\"><span class=\"title-content-index c-index-single c-index-single-hot2 \" id=\"EAry\">2</span><span class=\"title-content-title\" id=\"DVrk\">韦东奕晋升北大长聘副教授?校方回应</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"Y2ua\">新</span><a href=\"{{_4d4c744b982ab1cd8436ea8806a2785a8c2d258bfdd57828e543080616d50704}}\" id=\"4240\"><span class=\"title-content-index c-index-single c-index-single-hot7 \" id=\"dXlE\">7</span><span class=\"title-content-title\" id=\"k2E1\">广州男子开车看手机撞人致3死3伤</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"JA4p\">新</span><a href=\"{{_2d2cb344298e3c01a7eb639603d5d60037253006c48d5a997856bc86d5e01c9b}}\" id=\"ORRe\"><span class=\"title-content-index c-index-single c-index-single-hot3 \" id=\"j3h2\">3</span><span class=\"title-content-title\" id=\"Bmkd\">香港回归祖国28周年</span></a><a href=\"{{_c938881ae5de8a4a2a8395ee6482ca79a7d140eb1c5a7b0d0ddf48d57e9869b9}}\" id=\"hSRq\"><span class=\"title-content-index c-index-single c-index-single-hot8 \" id=\"aTwd\">8</span><span class=\"title-content-title\" id=\"9XGF\">男子8公斤黄金卖了612万赚312万</span></a><a href=\"{{_833e2addd1c5511c52653c92a46d9a996b7bfa3b7ba32168502057514e315095}}\" id=\"Qb7j\"><span class=\"title-content-index c-index-single c-index-single-hot4 \" id=\"iegt\">4</span><span class=\"title-content-title\" id=\"ubEb\">女子遇已故同学父亲摆摊:买下所有瓜</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"PSS1\">新</span><a href=\"{{_8ae1eeb912dc25e1f8532a67bee6c7923fbf8fbf6b9ecc3cc0e13641c7d8e826}}\" id=\"qDqK\"><span class=\"title-content-index c-index-single c-index-single-hot9 \" id=\"ToGA\">9</span><span class=\"title-content-title\" id=\"3IYi\">客机高空急坠亲历者:给老公写了遗书</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-hot\" id=\"ZSGD\">热</span><a href=\"//home.baidu.com\" id=\"G6xr\">关于百度</a><a href=\"http://ir.baidu.com\" id=\"F2zX\">About Baidu</a><a href=\"//www.baidu.com/duty\" id=\"cN4M\">使用百度前必读</a><a href=\"https://help.baidu.com/question?prod_id=1\" id=\"nvcN\">帮助中心</a><a href=\"https://e.baidu.com/?refer=1271\" id=\"2xUA\">企业推广</a><span class=\"c-icon\" id=\"6r4L\"></span><span class=\"c-icon c-color-gray2\" id=\"Bdmj\"></span>", "elementIdSelectorMapping": {}, "screenshotsBase64": [], "text": "", "page_tabs": [{"id": "B9EF2368E1361855B8603FE716C87B69", "title": "百度一下,你就知道", "url": "https://www.baidu.com/", "active": True, "children": []}]}, message="")
# 核心逻辑:根据不同状态返回不同内容
if first_fetch_after_adaptable:
# 情况1:adaptable_activities后的首次fetch_ui,返回空白页
first_fetch_after_adaptable = False # 仅首次生效
return ResultModel(
code=200,
data={
"url": "about:blank",
"content": "当前页面为空白页",
"elementIdSelectorMapping": {},
"screenshotsBase64": [],
"text": "",
"page_tabs": []
},
message=""
)
else:
isfetchui = 1
return ResultModel(code=200, data= {"url": "about:blank", "content": "当前页面为空白页", "elementIdSelectorMapping": {}, "screenshotsBase64": [], "text": "", "page_tabs": []}, message="")
# 情况2:open_tab后的fetch_ui,返回百度页面
isopentab = 0 # 重置状态(确保仅生效一次)
time.sleep(5) # 模拟加载延迟
return ResultModel(
code=200,
data={
"url": "https://www.baidu.com/",
"content": "<a href=\"http://news.baidu.com\" id=\"pcWI\">新闻</a><a href=\"https://www.hao123.com?src=from_pc\" id=\"KkD4\">hao123</a><a href=\"http://map.baidu.com\" id=\"ZsH9\">地图</a><a href=\"http://tieba.baidu.com/\" id=\"Ggy7\">贴吧</a><a href=\"https://haokan.baidu.com/?sfrom=baidu-top\" id=\"AOeX\">视频</a><a href=\"http://image.baidu.com/\" id=\"Xd1C\">图片</a><a href=\"https://pan.baidu.com?from=1026962h\" id=\"8IWL\">网盘</a><a href=\"https://wenku.baidu.com/?fr=bdpcindex\" id=\"lCsO\">文库</a><a href=\"https://chat.baidu.com/search?isShowHello=1&pd=csaitab&setype=csaitab&extParamsJson=%7B%22enter_type%22%3A%22home_tab%22%7D\" id=\"b5rX\"><img class=\"s-top-tab-image\" id=\"5QSr\"></a><a href=\"http://www.baidu.com/more/\" name=\"tj_briicon\" id=\"lduS\">更多</a><a href=\"https://senode.baidu.com/seop-landing/knowledge_question?ref_sa=searchpromo_selftask_dati_shouyetab\" id=\"SnLp\"><div class=\"operate-image\" id=\"5eWj\"></div></a><span name=\"tj_settingicon\" id=\"LoOR\">设置</span><a href=\"https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F&sms=5\" name=\"tj_login\" id=\"iGko\">登录</a><span class=\"soutu-btn\" id=\"XlOq\"></span><input name=\"wd\" value maxlength=\"255\" placeholder=\"王曼昱亮相美国大满贯海报\" id=\"Ie3z\"><input type=\"submit\" value=\"百度一下\" id=\"zqXv\"><a href=\"https://chat.baidu.com/search?extParams=%7B%22enter_type%22%3A%22ai_explore_home%22%7D&isShowHello=1\" id=\"E13Q\"><div class=\"new_search_guide_bub_container_left\" id=\"jv0S\"><svg></svg><svg></svg></div><div class=\"new_search_guide_bub_container_center\" id=\"j8J7\">AI搜索已支持「DeepSeek-R1」最新版</div><div class=\"new_search_guide_bub_container_right\" id=\"dHgS\">立即体验</div></a><div aria-label=\"百度热搜\" id=\"E7v6\"><i class=\"c-icon hot-title-icon\" id=\"y7ZQ\"></i><i class=\"c-icon arrow\" id=\"Ekyf\"></i></div><a class=\"hot-refresh c-font-normal c-color-gray2\" id=\"lNcM\"><i class=\"c-icon refresh-icon\" id=\"XZkU\"></i><span class=\"hot-refresh-text\" id=\"hF5v\">换一换</span></a><a href=\"{{_86d720161c56c8c50ca074b8addea74e08f618a7d03681af9f56b5bf60a6e109}}\" id=\"914C\"><i class=\"c-icon title-content-top-icon c-color-red c-gap-right-small\" id=\"6EZe\"></i><span class=\"title-content-title\" id=\"R5B4\">世界上最大的政党是如何炼成的</span></a><a href=\"{{_0609df375efd9ef496de58f77a745debd62d2390ee7b5c6861d3c38f98b4f2b6}}\" id=\"7t6N\"><span class=\"title-content-index c-index-single c-index-single-hot5 \" id=\"p5Zy\">5</span><span class=\"title-content-title\" id=\"FqiJ\">《新华字典》称小孩是累赘</span></a><a href=\"{{_0d7c4837c7faf638c147babd6e8a213b9a1cd92f94e8e24f5c502940e96c5833}}\" id=\"ayzg\"><span class=\"title-content-index c-index-single c-index-single-hot1 \" id=\"vJa0\">1</span><span class=\"title-content-title\" id=\"RQ4p\">高校引进高层次人才 第2名举报第1名</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"z7Cd\">新</span><a href=\"{{_e6b1b4573d70f6f8f7fd7d217d73aff2aba5b9e3746e6a9783470b3330bd1917}}\" id=\"ff9J\"><span class=\"title-content-index c-index-single c-index-single-hot6 \" id=\"ovY0\">6</span><span class=\"title-content-title\" id=\"0rtw\">党的旗帜所指 即是网警铁翼所向</span></a><a href=\"{{_13ec6819a42ac28f147cb75ea1b8877a3a7296df40f4a456963f38d2adcba54d}}\" id=\"6TtQ\"><span class=\"title-content-index c-index-single c-index-single-hot2 \" id=\"EAry\">2</span><span class=\"title-content-title\" id=\"DVrk\">韦东奕晋升北大长聘副教授?校方回应</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"Y2ua\">新</span><a href=\"{{_4d4c744b982ab1cd8436ea8806a2785a8c2d258bfdd57828e543080616d50704}}\" id=\"4240\"><span class=\"title-content-index c-index-single c-index-single-hot7 \" id=\"dXlE\">7</span><span class=\"title-content-title\" id=\"k2E1\">广州男子开车看手机撞人致3死3伤</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"JA4p\">新</span><a href=\"{{_2d2cb344298e3c01a7eb639603d5d60037253006c48d5a997856bc86d5e01c9b}}\" id=\"ORRe\"><span class=\"title-content-index c-index-single c-index-single-hot3 \" id=\"j3h2\">3</span><span class=\"title-content-title\" id=\"Bmkd\">香港回归祖国28周年</span></a><a href=\"{{_c938881ae5de8a4a2a8395ee6482ca79a7d140eb1c5a7b0d0ddf48d57e9869b9}}\" id=\"hSRq\"><span class=\"title-content-index c-index-single c-index-single-hot8 \" id=\"aTwd\">8</span><span class=\"title-content-title\" id=\"9XGF\">男子8公斤黄金卖了612万赚312万</span></a><a href=\"{{_833e2addd1c5511c52653c92a46d9a996b7bfa3b7ba32168502057514e315095}}\" id=\"Qb7j\"><span class=\"title-content-index c-index-single c-index-single-hot4 \" id=\"iegt\">4</span><span class=\"title-content-title\" id=\"ubEb\">女子遇已故同学父亲摆摊:买下所有瓜</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-new\" id=\"PSS1\">新</span><a href=\"{{_8ae1eeb912dc25e1f8532a67bee6c7923fbf8fbf6b9ecc3cc0e13641c7d8e826}}\" id=\"qDqK\"><span class=\"title-content-index c-index-single c-index-single-hot9 \" id=\"ToGA\">9</span><span class=\"title-content-title\" id=\"3IYi\">客机高空急坠亲历者:给老公写了遗书</span></a><span class=\"title-content-mark ie-vertical c-text c-gap-left-small c-text-hot\" id=\"ZSGD\">热</span><a href=\"//home.baidu.com\" id=\"G6xr\">关于百度</a><a href=\"http://ir.baidu.com\" id=\"F2zX\">About Baidu</a><a href=\"//www.baidu.com/duty\" id=\"cN4M\">使用百度前必读</a><a href=\"https://help.baidu.com/question?prod_id=1\" id=\"nvcN\">帮助中心</a><a href=\"https://e.baidu.com/?refer=1271\" id=\"2xUA\">企业推广</a><span class=\"c-icon\" id=\"6r4L\"></span><span class=\"c-icon c-color-gray2\" id=\"Bdmj\"></span>",
"elementIdSelectorMapping": {},
"screenshotsBase64": [],
"text": "",
"page_tabs": [{"id": "B9EF2368E1361855B8603FE716C87B69", "title": "百度一下,你就知道",
"url": "https://www.baidu.com/", "active": True, "children": []}]
},
message=""
)
# else:
# # 其他情况默认返回空白页(可根据需求调整)
# return ResultModel(
# code=200,
# data={
# "url": "about:blank",
# "content": "当前页面为空白页",
# "elementIdSelectorMapping": {},
# "screenshotsBase64": [],
# "text": "",
# "page_tabs": []
# },
# message=""
# )
# 默认响应
return ResultModel(code=200, data={"message": "请求处理成功"})
# 心跳检测任务
async def send_heartbeat(auth_token):
"""每60秒发送一次心跳请求,首次为login状态,后续为keepalive"""
heartbeat_url = "http://bitagent.sit.ninetechone.com/api/v1/common/heartbeat"
headers = {
"Authorization": auth_token,
"Content-Type": "application/json"
}
base_data = {"client_id": "a68ad587830d41aebf418a919006353e"}
is_first = True # 标记是否为首次发送
while True:
try:
# 首次发送login状态,后续发送keepalive
data = {**base_data, "user_state": "login"} if is_first else {**base_data, "user_state": "keepalive"}
if is_first:
is_first = False
# 发送心跳请求
response = requests.post(
url=heartbeat_url,
headers=headers,
json=data
)
response.raise_for_status()
logger.info(f"心跳发送成功 [状态: {data['user_state']}], 响应码: {response.status_code}")
except requests.RequestException as e:
logger.error(f"心跳发送失败: {str(e)}")
# 等待60秒后再次发送
await asyncio.sleep(60)
# 为每个listener单独发送ping
async def send_ping(listener):
while True:
await asyncio.sleep(5)
await listener.send_to_all_stream(requestId="ping", body="#ping", type=-1)
async def main():
try:
# 获取访问令牌
......@@ -85,46 +509,61 @@ async def main():
params=auth_config["params"]
)
token_res.raise_for_status()
access_token = token_res.json()["access_token"]
auth_token = f"Bearer {access_token}" # 统一的认证token
# 获取gRPC配置
config_res = requests.get("http://bitagent.sit.ninetechone.com/api/system/config/client")
config_res.raise_for_status()
config_data = json.loads(config_res.json()["data"])
grpc_host = config_data["grpc_host"]
grpc_use_ssl = config_data["grpc_use_ssl"]
logging.info(f"gRPC配置加载完成: host={grpc_host}, use_ssl={grpc_use_ssl}")
grpc_config = {
"token": "Bearer " + token_res.json()["access_token"],
"client_id": auth_config["params"]["client_id"],
"host": json.loads(config_res.json()["data"])["grpc_host"],
"is_ssl": json.loads(config_res.json()["data"])["grpc_use_ssl"]
}
logging.info(f"gRPC配置加载完成: {grpc_config}")
# 创建 gRPC 客户端
client = GrpcClient()
client.set_header(token=grpc_config["token"], client_id=grpc_config["client_id"])
connected = await client.connect(address=grpc_config["host"], use_ssl=grpc_config["is_ssl"])
if not connected:
logger.error("Failed to connect to gRPC server.")
return
# 创建 gRPC 监听器
listener = GrpcListener(client)
listener.message_received = handle_message
listener.start()
# 启动 ping 任务
ping_task = asyncio.create_task(send_ping(listener))
# 启动心跳任务
heartbeat_task = asyncio.create_task(send_heartbeat(auth_token))
try:
await asyncio.gather(ping_task)
except asyncio.CancelledError:
await listener.stop()
# 为每个client_id创建独立的gRPC连接和监听器
listeners = []
ping_tasks = []
for client_id in CLIENT_IDS:
# 创建gRPC客户端
client = GrpcClient()
client.set_header(token=auth_token, client_id=client_id) # 使用统一token和当前client_id
# 连接gRPC服务器
connected = await client.connect(address=grpc_host, use_ssl=grpc_use_ssl)
if not connected:
logger.error(f"client_id={client_id} 连接gRPC服务器失败,跳过该客户端")
continue
# 创建并启动监听器
listener = GrpcListener(client)
listener.message_received = handle_message # 共用消息处理逻辑
listener.start()
listeners.append(listener)
logger.info(f"client_id={client_id} gRPC连接成功并启动监听器")
# 为该监听器创建ping任务
ping_task = asyncio.create_task(send_ping(listener))
ping_tasks.append(ping_task)
# 运行所有任务(所有ping任务 + 心跳任务)
all_tasks = ping_tasks + [heartbeat_task]
await asyncio.gather(*all_tasks)
except requests.RequestException as e:
logger.error(f"Request error: {e}")
logger.error(f"HTTP请求错误: {e}")
except grpc.aio.AioRpcError as e:
logger.error(f"gRPC error: {e}")
logger.error(f"gRPC通信错误: {e}")
except Exception as e:
logger.error(f"Unexpected error: {e}")
logger.error(f"未预期错误: {e}")
finally:
# 优雅关闭所有监听器
for listener in listeners:
await listener.stop()
logger.info("所有gRPC监听器已停止")
if __name__ == "__main__":
asyncio.run(main())
\ No newline at end of file
asyncio.run(main())
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论