Skip to content

Commit 07c163a

Browse files
committed
chore: perform agent turn event
1 parent cb6ab4f commit 07c163a

File tree

22 files changed

+367
-52
lines changed

22 files changed

+367
-52
lines changed

docs/src/api/class-page.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ sequence of events is `request`, `response` and `requestfinished`.
544544
Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
545545
is `request`, `response` and `requestfinished`.
546546

547+
## event: Page.agentTurn
548+
* since: v1.58
549+
- argument: <[Object]>
550+
- `role` <[string]>
551+
- `message` <[string]>
552+
- `usage` ?<[Object]>
553+
- `inputTokens` <[int]>
554+
- `outputTokens` <[int]>
555+
556+
Emitted when the agent makes a turn.
557+
547558
## event: Page.webSocket
548559
* since: v1.9
549560
- argument: <[WebSocket]>

docs/src/api/params.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Emulates consistent window screen size available inside web page via `window.scr
375375
- `provider` <[string]> LLM provider to use.
376376
- `model` <[string]> Model identifier within provider.
377377
- `cacheFile` ?<[string]> Cache file to use/generate code for performed actions into. Cache is not used if not specified (default).
378-
- `cacheMode` ?<['force'|'ignore'|'auto']> Cache control, defaults to 'auto'.
378+
- `cacheMode` ?<['force'|'ignore'|'update'|'auto']> Cache control, defaults to 'auto'.
379379
- `secrets` ?<[Object]<[string], [string]>> Secrets to hide from the LLM.
380380
- `maxTurns` ?<[int]> Maximum number of agentic turns to take per call. Defaults to 10.
381381
- `maxTokens` ?<[int]> Maximum number of tokens to consume per call. The agentic loop will stop after input + output tokens exceed this value. Defaults on unlimited.

examples/todomvc/playwright.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* eslint-disable notice/notice */
22

33
import { defineConfig, devices } from '@playwright/test';
4+
import dotenv from 'dotenv';
5+
6+
dotenv.config();
47

58
/**
69
* See https://playwright.dev/docs/test-configuration.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@eslint/compat": "^1.3.2",
5757
"@eslint/eslintrc": "^3.3.1",
5858
"@eslint/js": "^9.34.0",
59-
"@lowire/loop": "^0.0.8",
59+
"@lowire/loop": "^0.0.10",
6060
"@modelcontextprotocol/sdk": "^1.17.5",
6161
"@octokit/graphql-schema": "^15.26.0",
6262
"@stylistic/eslint-plugin": "^5.2.3",

packages/playwright-client/types/types.d.ts

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,21 @@ export interface Page {
10361036
* @param options
10371037
*/
10381038
extract<Schema extends ZodTypeAny>(query: string, schema: Schema): Promise<ZodInfer<Schema>>;
1039+
/**
1040+
* Emitted when the agent makes a turn.
1041+
*/
1042+
on(event: 'agentturn', listener: (data: {
1043+
role: string;
1044+
1045+
message: string;
1046+
1047+
usage?: {
1048+
inputTokens: number;
1049+
1050+
outputTokens: number;
1051+
};
1052+
}) => any): this;
1053+
10391054
/**
10401055
* Emitted when the page closes.
10411056
*/
@@ -1243,6 +1258,21 @@ export interface Page {
12431258
*/
12441259
on(event: 'worker', listener: (worker: Worker) => any): this;
12451260

1261+
/**
1262+
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
1263+
*/
1264+
once(event: 'agentturn', listener: (data: {
1265+
role: string;
1266+
1267+
message: string;
1268+
1269+
usage?: {
1270+
inputTokens: number;
1271+
1272+
outputTokens: number;
1273+
};
1274+
}) => any): this;
1275+
12461276
/**
12471277
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
12481278
*/
@@ -1338,6 +1368,21 @@ export interface Page {
13381368
*/
13391369
once(event: 'worker', listener: (worker: Worker) => any): this;
13401370

1371+
/**
1372+
* Emitted when the agent makes a turn.
1373+
*/
1374+
addListener(event: 'agentturn', listener: (data: {
1375+
role: string;
1376+
1377+
message: string;
1378+
1379+
usage?: {
1380+
inputTokens: number;
1381+
1382+
outputTokens: number;
1383+
};
1384+
}) => any): this;
1385+
13411386
/**
13421387
* Emitted when the page closes.
13431388
*/
@@ -1545,6 +1590,21 @@ export interface Page {
15451590
*/
15461591
addListener(event: 'worker', listener: (worker: Worker) => any): this;
15471592

1593+
/**
1594+
* Removes an event listener added by `on` or `addListener`.
1595+
*/
1596+
removeListener(event: 'agentturn', listener: (data: {
1597+
role: string;
1598+
1599+
message: string;
1600+
1601+
usage?: {
1602+
inputTokens: number;
1603+
1604+
outputTokens: number;
1605+
};
1606+
}) => any): this;
1607+
15481608
/**
15491609
* Removes an event listener added by `on` or `addListener`.
15501610
*/
@@ -1640,6 +1700,21 @@ export interface Page {
16401700
*/
16411701
removeListener(event: 'worker', listener: (worker: Worker) => any): this;
16421702

1703+
/**
1704+
* Removes an event listener added by `on` or `addListener`.
1705+
*/
1706+
off(event: 'agentturn', listener: (data: {
1707+
role: string;
1708+
1709+
message: string;
1710+
1711+
usage?: {
1712+
inputTokens: number;
1713+
1714+
outputTokens: number;
1715+
};
1716+
}) => any): this;
1717+
16431718
/**
16441719
* Removes an event listener added by `on` or `addListener`.
16451720
*/
@@ -1735,6 +1810,21 @@ export interface Page {
17351810
*/
17361811
off(event: 'worker', listener: (worker: Worker) => any): this;
17371812

1813+
/**
1814+
* Emitted when the agent makes a turn.
1815+
*/
1816+
prependListener(event: 'agentturn', listener: (data: {
1817+
role: string;
1818+
1819+
message: string;
1820+
1821+
usage?: {
1822+
inputTokens: number;
1823+
1824+
outputTokens: number;
1825+
};
1826+
}) => any): this;
1827+
17381828
/**
17391829
* Emitted when the page closes.
17401830
*/
@@ -4790,6 +4880,41 @@ export interface Page {
47904880
height: number;
47914881
};
47924882

4883+
/**
4884+
* Emitted when the agent makes a turn.
4885+
*/
4886+
waitForEvent(event: 'agentturn', optionsOrPredicate?: { predicate?: (data: {
4887+
role: string;
4888+
4889+
message: string;
4890+
4891+
usage?: {
4892+
inputTokens: number;
4893+
4894+
outputTokens: number;
4895+
};
4896+
}) => boolean | Promise<boolean>, timeout?: number } | ((data: {
4897+
role: string;
4898+
4899+
message: string;
4900+
4901+
usage?: {
4902+
inputTokens: number;
4903+
4904+
outputTokens: number;
4905+
};
4906+
}) => boolean | Promise<boolean>)): Promise<{
4907+
role: string;
4908+
4909+
message: string;
4910+
4911+
usage?: {
4912+
inputTokens: number;
4913+
4914+
outputTokens: number;
4915+
};
4916+
}>;
4917+
47934918
/**
47944919
* Emitted when the page closes.
47954920
*/
@@ -22118,7 +22243,7 @@ export interface BrowserContextOptions {
2211822243
/**
2211922244
* Cache control, defaults to 'auto'.
2212022245
*/
22121-
cacheMode?: 'force'|'ignore'|'auto';
22246+
cacheMode?: 'force'|'ignore'|'update'|'auto';
2212222247

2212322248
/**
2212422249
* Secrets to hide from the LLM.

packages/playwright-core/ThirdPartyNotices.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
44

55
This project incorporates components from the projects listed below. The original copyright notices and the licenses under which Microsoft received such components are set forth below. Microsoft reserves all rights not expressly granted herein, whether by implication, estoppel or otherwise.
66

7-
- @lowire/loop@0.0.8 (https://github.com/pavelfeldman/lowire)
7+
- @lowire/loop@0.0.10 (https://github.com/pavelfeldman/lowire)
88
- @modelcontextprotocol/sdk@1.24.2 (https://github.com/modelcontextprotocol/typescript-sdk)
99
- accepts@2.0.0 (https://github.com/jshttp/accepts)
1010
- agent-base@7.1.4 (https://github.com/TooTallNate/proxy-agents)
@@ -135,7 +135,7 @@ This project incorporates components from the projects listed below. The origina
135135
- zod-to-json-schema@3.25.0 (https://github.com/StefanTerdell/zod-to-json-schema)
136136
- zod@3.25.76 (https://github.com/colinhacks/zod)
137137

138-
%% @lowire/loop@0.0.8 NOTICES AND INFORMATION BEGIN HERE
138+
%% @lowire/loop@0.0.10 NOTICES AND INFORMATION BEGIN HERE
139139
=========================================
140140
Apache License
141141
Version 2.0, January 2004
@@ -339,7 +339,7 @@ Apache License
339339
See the License for the specific language governing permissions and
340340
limitations under the License.
341341
=========================================
342-
END OF @lowire/loop@0.0.8 AND INFORMATION
342+
END OF @lowire/loop@0.0.10 AND INFORMATION
343343

344344
%% @modelcontextprotocol/sdk@1.24.2 NOTICES AND INFORMATION BEGIN HERE
345345
=========================================

packages/playwright-core/bundles/mcp/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/playwright-core/bundles/mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.1",
44
"private": true,
55
"dependencies": {
6+
"@lowire/loop": "^0.0.10",
67
"@modelcontextprotocol/sdk": "^1.24.0",
7-
"@lowire/loop": "^0.0.8",
88
"zod": "^3.25.76",
99
"zod-to-json-schema": "^3.24.6"
1010
}

packages/playwright-core/src/client/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const Events = {
5555
},
5656

5757
Page: {
58+
AgentTurn: 'agentturn',
5859
Close: 'close',
5960
Crash: 'crash',
6061
Console: 'console',

0 commit comments

Comments
 (0)