|
@@ -142,12 +142,12 @@ export class ActionBuilder {
|
|
|
|
|
|
const searchGoogle = new Action(async (input: z.infer<typeof searchGoogleActionSchema.schema>) => {
|
|
const searchGoogle = new Action(async (input: z.infer<typeof searchGoogleActionSchema.schema>) => {
|
|
const context = this.context;
|
|
const context = this.context;
|
|
- const intent = input.intent || `Searching for "${input.query}" in Google`;
|
|
|
|
|
|
+ const intent = input.intent || `在百度中搜索"${input.query}"`;
|
|
context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
|
|
|
|
- await context.browserContext.navigateTo(`https://www.google.com/search?q=${input.query}`);
|
|
|
|
|
|
+ await context.browserContext.navigateTo(`https://www.baidu.com/s?wd=${input.query}`);
|
|
|
|
|
|
- const msg2 = `Searched for "${input.query}" in Google`;
|
|
|
|
|
|
+ const msg2 = `在百度中搜索"${input.query}"`;
|
|
context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg2);
|
|
context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg2);
|
|
return new ActionResult({
|
|
return new ActionResult({
|
|
extractedContent: msg2,
|
|
extractedContent: msg2,
|
|
@@ -157,11 +157,11 @@ export class ActionBuilder {
|
|
actions.push(searchGoogle);
|
|
actions.push(searchGoogle);
|
|
|
|
|
|
const goToUrl = new Action(async (input: z.infer<typeof goToUrlActionSchema.schema>) => {
|
|
const goToUrl = new Action(async (input: z.infer<typeof goToUrlActionSchema.schema>) => {
|
|
- const intent = input.intent || `Navigating to ${input.url}`;
|
|
|
|
|
|
+ const intent = input.intent || `导航至${input.url}`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
|
|
|
|
await this.context.browserContext.navigateTo(input.url);
|
|
await this.context.browserContext.navigateTo(input.url);
|
|
- const msg2 = `Navigated to ${input.url}`;
|
|
|
|
|
|
+ const msg2 = `已导航到${input.url}`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg2);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg2);
|
|
return new ActionResult({
|
|
return new ActionResult({
|
|
extractedContent: msg2,
|
|
extractedContent: msg2,
|
|
@@ -172,12 +172,12 @@ export class ActionBuilder {
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
const goBack = new Action(async (input: z.infer<typeof goBackActionSchema.schema>) => {
|
|
const goBack = new Action(async (input: z.infer<typeof goBackActionSchema.schema>) => {
|
|
- const intent = input.intent || 'Navigating back';
|
|
|
|
|
|
+ const intent = input.intent || '正在返回';
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
|
|
|
|
const page = await this.context.browserContext.getCurrentPage();
|
|
const page = await this.context.browserContext.getCurrentPage();
|
|
await page.goBack();
|
|
await page.goBack();
|
|
- const msg2 = 'Navigated back';
|
|
|
|
|
|
+ const msg2 = '已返回';
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg2);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg2);
|
|
return new ActionResult({
|
|
return new ActionResult({
|
|
extractedContent: msg2,
|
|
extractedContent: msg2,
|
|
@@ -188,10 +188,10 @@ export class ActionBuilder {
|
|
|
|
|
|
const wait = new Action(async (input: z.infer<typeof waitActionSchema.schema>) => {
|
|
const wait = new Action(async (input: z.infer<typeof waitActionSchema.schema>) => {
|
|
const seconds = input.seconds || 3;
|
|
const seconds = input.seconds || 3;
|
|
- const intent = input.intent || `Waiting for ${seconds} seconds`;
|
|
|
|
|
|
+ const intent = input.intent || `正在等待${seconds}秒`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
await new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
|
await new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
|
- const msg = `${seconds} seconds elapsed`;
|
|
|
|
|
|
+ const msg = `已等待${seconds}秒`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg);
|
|
return new ActionResult({ extractedContent: msg, includeInMemory: true });
|
|
return new ActionResult({ extractedContent: msg, includeInMemory: true });
|
|
}, waitActionSchema);
|
|
}, waitActionSchema);
|
|
@@ -200,7 +200,7 @@ export class ActionBuilder {
|
|
// Element Interaction Actions
|
|
// Element Interaction Actions
|
|
const clickElement = new Action(
|
|
const clickElement = new Action(
|
|
async (input: z.infer<typeof clickElementActionSchema.schema>) => {
|
|
async (input: z.infer<typeof clickElementActionSchema.schema>) => {
|
|
- const intent = input.intent || `Click element with index ${input.index}`;
|
|
|
|
|
|
+ const intent = input.intent || `点击索引元素 ${input.index}`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
|
|
|
|
const page = await this.context.browserContext.getCurrentPage();
|
|
const page = await this.context.browserContext.getCurrentPage();
|
|
@@ -208,12 +208,12 @@ export class ActionBuilder {
|
|
|
|
|
|
const elementNode = state?.selectorMap.get(input.index);
|
|
const elementNode = state?.selectorMap.get(input.index);
|
|
if (!elementNode) {
|
|
if (!elementNode) {
|
|
- throw new Error(`Element with index ${input.index} does not exist - retry or use alternative actions`);
|
|
|
|
|
|
+ throw new Error(`索引为${input.index}的元素不存在-请重试或使用其他操作`);
|
|
}
|
|
}
|
|
|
|
|
|
// Check if element is a file uploader
|
|
// Check if element is a file uploader
|
|
if (page.isFileUploader(elementNode)) {
|
|
if (page.isFileUploader(elementNode)) {
|
|
- const msg = `Index ${input.index} - has an element which opens file upload dialog. To upload files please use a specific function to upload files`;
|
|
|
|
|
|
+ const msg = `索引${input.index}-包含一个打开文件上传对话框的元素。要上传文件,请使用特定功能来上传文件`;
|
|
logger.info(msg);
|
|
logger.info(msg);
|
|
return new ActionResult({
|
|
return new ActionResult({
|
|
extractedContent: msg,
|
|
extractedContent: msg,
|
|
@@ -224,13 +224,13 @@ export class ActionBuilder {
|
|
try {
|
|
try {
|
|
const initialTabIds = await this.context.browserContext.getAllTabIds();
|
|
const initialTabIds = await this.context.browserContext.getAllTabIds();
|
|
await page.clickElementNode(this.context.options.useVision, elementNode);
|
|
await page.clickElementNode(this.context.options.useVision, elementNode);
|
|
- let msg = `Clicked button with index ${input.index}: ${elementNode.getAllTextTillNextClickableElement(2)}`;
|
|
|
|
|
|
+ let msg = `点击了索引为${input.index}的按钮: ${elementNode.getAllTextTillNextClickableElement(2)}`;
|
|
logger.info(msg);
|
|
logger.info(msg);
|
|
|
|
|
|
// TODO: could be optimized by chrome extension tab api
|
|
// TODO: could be optimized by chrome extension tab api
|
|
const currentTabIds = await this.context.browserContext.getAllTabIds();
|
|
const currentTabIds = await this.context.browserContext.getAllTabIds();
|
|
if (currentTabIds.size > initialTabIds.size) {
|
|
if (currentTabIds.size > initialTabIds.size) {
|
|
- const newTabMsg = 'New tab opened - switching to it';
|
|
|
|
|
|
+ const newTabMsg = '新标签页已打开 - 正在切换到该标签页';
|
|
msg += ` - ${newTabMsg}`;
|
|
msg += ` - ${newTabMsg}`;
|
|
logger.info(newTabMsg);
|
|
logger.info(newTabMsg);
|
|
// find the tab id that is not in the initial tab ids
|
|
// find the tab id that is not in the initial tab ids
|
|
@@ -242,7 +242,7 @@ export class ActionBuilder {
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg);
|
|
return new ActionResult({ extractedContent: msg, includeInMemory: true });
|
|
return new ActionResult({ extractedContent: msg, includeInMemory: true });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- const msg = `Element no longer available with index ${input.index} - most likely the page changed`;
|
|
|
|
|
|
+ const msg = `索引为${input.index}的元素不再可用 - 可能页面已经改变`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_FAIL, msg);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_FAIL, msg);
|
|
return new ActionResult({
|
|
return new ActionResult({
|
|
error: error instanceof Error ? error.message : String(error),
|
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -256,7 +256,7 @@ export class ActionBuilder {
|
|
|
|
|
|
const inputText = new Action(
|
|
const inputText = new Action(
|
|
async (input: z.infer<typeof inputTextActionSchema.schema>) => {
|
|
async (input: z.infer<typeof inputTextActionSchema.schema>) => {
|
|
- const intent = input.intent || `Input text into index ${input.index}`;
|
|
|
|
|
|
+ const intent = input.intent || `在索引为${input.index}的元素中输入文本`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_START, intent);
|
|
|
|
|
|
const page = await this.context.browserContext.getCurrentPage();
|
|
const page = await this.context.browserContext.getCurrentPage();
|
|
@@ -264,11 +264,11 @@ export class ActionBuilder {
|
|
|
|
|
|
const elementNode = state?.selectorMap.get(input.index);
|
|
const elementNode = state?.selectorMap.get(input.index);
|
|
if (!elementNode) {
|
|
if (!elementNode) {
|
|
- throw new Error(`Element with index ${input.index} does not exist - retry or use alternative actions`);
|
|
|
|
|
|
+ throw new Error(`索引为${input.index}的元素不存在 - 请重试或使用其他操作`);
|
|
}
|
|
}
|
|
|
|
|
|
await page.inputTextElementNode(this.context.options.useVision, elementNode, input.text);
|
|
await page.inputTextElementNode(this.context.options.useVision, elementNode, input.text);
|
|
- const msg = `Input ${input.text} into index ${input.index}`;
|
|
|
|
|
|
+ const msg = `在索引为${input.index}的元素中输入了 ${input.text}`;
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg);
|
|
this.context.emitEvent(Actors.NAVIGATOR, ExecutionState.ACT_OK, msg);
|
|
return new ActionResult({ extractedContent: msg, includeInMemory: true });
|
|
return new ActionResult({ extractedContent: msg, includeInMemory: true });
|
|
},
|
|
},
|