2025-01-07 11:10:28 +08:00
|
|
|
|
import {
|
|
|
|
|
AgentOverChromeBridge,
|
|
|
|
|
getBridgePageInCliSide,
|
|
|
|
|
} from '@/bridge-mode/agent-cli-side';
|
2025-01-15 19:54:03 +08:00
|
|
|
|
import { describe, expect, it, vi } from 'vitest';
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
vi.setConfig({
|
|
|
|
|
testTimeout: 60 * 1000,
|
|
|
|
|
});
|
2025-01-07 11:10:28 +08:00
|
|
|
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
2025-02-14 21:54:47 +08:00
|
|
|
|
const describeIf = process.env.BRIDGE_MODE ? describe : describe.skip;
|
2025-01-24 15:02:50 +08:00
|
|
|
|
|
2025-02-14 21:54:47 +08:00
|
|
|
|
describeIf(
|
2025-01-07 11:10:28 +08:00
|
|
|
|
'fully functional agent in server(cli) side',
|
2025-02-14 21:54:47 +08:00
|
|
|
|
{
|
|
|
|
|
timeout: 3 * 60 * 10,
|
|
|
|
|
},
|
2025-01-07 11:10:28 +08:00
|
|
|
|
() => {
|
|
|
|
|
it('basic', async () => {
|
|
|
|
|
const page = getBridgePageInCliSide();
|
|
|
|
|
expect(page).toBeDefined();
|
|
|
|
|
|
|
|
|
|
// server should be destroyed as well
|
|
|
|
|
await page.destroy();
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
it('page in cli side', async () => {
|
|
|
|
|
const page = getBridgePageInCliSide();
|
|
|
|
|
|
|
|
|
|
// make sure the extension bridge is launched before timeout
|
|
|
|
|
await page.connectNewTabWithUrl('https://www.baidu.com');
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
// sleep 3s
|
|
|
|
|
await sleep(3000);
|
|
|
|
|
|
|
|
|
|
await page.destroy();
|
|
|
|
|
});
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
it('agent in cli side, new tab', async () => {
|
|
|
|
|
const agent = new AgentOverChromeBridge();
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
await agent.connectNewTabWithUrl('https://www.bing.com');
|
|
|
|
|
await sleep(3000);
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-26 20:34:56 +08:00
|
|
|
|
await agent.ai('type "AI 101" and hit Enter and scroll down');
|
2025-01-15 19:54:03 +08:00
|
|
|
|
await sleep(3000);
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
await agent.aiAssert('there are some search results');
|
|
|
|
|
await agent.destroy();
|
|
|
|
|
});
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
it('agent in cli side, current tab', async () => {
|
|
|
|
|
const agent = new AgentOverChromeBridge();
|
|
|
|
|
await agent.connectCurrentTab();
|
|
|
|
|
await sleep(3000);
|
|
|
|
|
const answer = await agent.aiQuery(
|
|
|
|
|
'name of the current page? return {name: string}',
|
|
|
|
|
);
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
console.log(answer);
|
|
|
|
|
expect(answer.name).toBeTruthy();
|
|
|
|
|
await agent.destroy();
|
|
|
|
|
});
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-02-14 21:54:47 +08:00
|
|
|
|
it('agent in cli side, current tab, limit popup to current page', async () => {
|
2025-01-15 19:54:03 +08:00
|
|
|
|
const agent = new AgentOverChromeBridge();
|
2025-02-14 21:54:47 +08:00
|
|
|
|
await agent.connectCurrentTab({ forceSameTabNavigation: true });
|
2025-01-07 11:10:28 +08:00
|
|
|
|
|
2025-01-15 19:54:03 +08:00
|
|
|
|
await agent.ai('click "文库",sleep 1500ms,type "AI 101" and hit Enter');
|
|
|
|
|
await sleep(3000);
|
|
|
|
|
await agent.destroy();
|
|
|
|
|
});
|
2025-01-07 11:10:28 +08:00
|
|
|
|
},
|
|
|
|
|
);
|