feat(core): support error message for ai assert in yaml (#774)

This commit is contained in:
Leyang 2025-05-27 19:15:25 +08:00 committed by GitHub
parent 5451c27db4
commit 8f4e722239
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 13 additions and 4 deletions

View File

@ -248,6 +248,7 @@ tasks:
# perform an assertion
- aiAssert: <prompt>
errorMessage: <error-message> # optional, the error message to print when the assertion fails
# sleep for a number of milliseconds
- sleep: <ms>

View File

@ -84,7 +84,10 @@ while (user.length > 0) {
// Check if we've gone through all users in the current list
if (currentUserIndex >= user.length) {
// Scroll down to load more users
await agent.aiScroll('scroll down one screen')
await agent.aiScroll({
direction: 'down',
scrollType: 'once',
})
// Get the updated user list
user = await agent.aiQuery('string[], the unfollowed user names in the list')

View File

@ -249,6 +249,7 @@ tasks:
# 执行一个断言
- aiAssert: <prompt>
errorMessage: <error-message> # 可选,当断言失败时打印的错误信息。
# 等待一定时间
- sleep: <ms>

View File

@ -83,7 +83,10 @@ while (user.length > 0) {
// 检查是否已经遍历了当前列表中的所有用户
if (currentUserIndex >= user.length) {
// 向下滚动一屏
await agent.aiScroll('向下滚动一屏')
await agent.aiScroll({
direction: 'down',
scrollType: 'once',
})
// 获取更新后的用户列表
user = await agent.aiQuery('string[], 列表中所有未关注用户')

View File

@ -14,7 +14,6 @@ import { elementDescriberInstruction } from '@/ai-model/prompt/describe';
import type {
AIDescribeElementResponse,
AIElementResponse,
AISingleElementResponse,
AIUsageInfo,
BaseElement,
DetailedLocateParam,

View File

@ -85,6 +85,7 @@ export interface MidsceneYamlFlowItemAIAction {
export interface MidsceneYamlFlowItemAIAssert {
aiAssert: string;
errorMessage?: string;
}
export interface MidsceneYamlFlowItemAIQuery {

View File

@ -146,12 +146,13 @@ export class ScriptPlayer<T extends MidsceneYamlScriptEnv> {
} else if ('aiAssert' in (flowItem as MidsceneYamlFlowItemAIAssert)) {
const assertTask = flowItem as MidsceneYamlFlowItemAIAssert;
const prompt = assertTask.aiAssert;
const msg = assertTask.errorMessage;
assert(prompt, 'missing prompt for aiAssert');
assert(
typeof prompt === 'string',
'prompt for aiAssert must be a string',
);
await agent.aiAssert(prompt);
await agent.aiAssert(prompt, msg);
} else if ('aiQuery' in (flowItem as MidsceneYamlFlowItemAIQuery)) {
const queryTask = flowItem as MidsceneYamlFlowItemAIQuery;
const prompt = queryTask.aiQuery;