Skip to content

Commit 5141143

Browse files
committed
Merge branch 'main' into screenshots
2 parents 1461114 + 794d5b8 commit 5141143

File tree

81 files changed

+14278
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+14278
-422
lines changed

.husky/commit-msg

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
npx --no -- commitlint --edit "$1"
1+
#!/bin/sh
2+
3+
# Ensure node is in PATH (for fnm users)
4+
export PATH="$HOME/Library/Application Support/fnm/aliases/default/bin:$PATH"
5+
6+
npx --no -- commitlint --edit "$1"

apps/chrome-extension/static/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Midscene.js",
33
"description": "Open-source SDK for automating web pages using natural language through AI.",
4-
"version": "0.130",
4+
"version": "0.132",
55
"manifest_version": 3,
66
"permissions": [
77
"activeTab",

apps/playground/src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ export default function App() {
127127
<div className="playground-panel-header">
128128
<div className="header-row">
129129
<Logo />
130-
<NavActions showEnvConfig={false} />
130+
<NavActions
131+
showTooltipWhenEmpty={false}
132+
showModelName={false}
133+
/>
131134
</div>
132135
</div>
133136

apps/report/src/components/detail-side/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ const DetailSide = (): JSX.Element => {
212212
},
213213
]
214214
: []),
215+
...(task?.searchAreaUsage
216+
? [
217+
{
218+
key: 'searchAreaUsage',
219+
content: (
220+
<pre>{JSON.stringify(task.searchAreaUsage, undefined, 2)}</pre>
221+
),
222+
},
223+
]
224+
: []),
215225
...(task?.usage
216226
? [
217227
{

apps/report/src/components/sidebar/index.less

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
.task-meta-tokens {
7575
display: grid;
76-
grid-template-columns: 1fr auto 112px 26px;
76+
grid-template-columns: 1fr auto minmax(100px, 1fr) 55px 65px;
7777
gap: 8px;
7878
align-items: center;
7979
font-size: 12px;
@@ -91,11 +91,11 @@
9191
justify-content: center;
9292

9393
&:nth-child(2) {
94-
grid-column: 3;
94+
grid-column: 4;
9595
}
9696

9797
&:nth-child(3) {
98-
grid-column: 4;
98+
grid-column: 5;
9999
}
100100

101101
.token-value {
@@ -168,7 +168,7 @@
168168

169169

170170
&.pro-mode {
171-
grid-template-columns: 1fr auto 100px 55px 65px;
171+
grid-template-columns: 1fr auto minmax(100px, 1fr) 55px 65px;
172172
}
173173

174174
.status-icon {
@@ -230,7 +230,7 @@
230230
flex-shrink: 0;
231231

232232
&.pro-mode {
233-
grid-template-columns: 1fr auto 100px 55px 65px;
233+
grid-template-columns: 1fr auto minmax(100px, 1fr) 55px 65px;
234234
}
235235

236236
.header-name {

apps/report/src/components/sidebar/index.tsx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import './index.less';
22
import { useAllCurrentTasks, useExecutionDump } from '@/components/store';
3-
import type { ExecutionTask, ExecutionTaskInsightLocate } from '@midscene/core';
3+
import type {
4+
AIUsageInfo,
5+
ExecutionTask,
6+
ExecutionTaskInsightLocate,
7+
} from '@midscene/core';
48
import { typeStr } from '@midscene/core/agent';
9+
10+
// Extended task type with searchAreaUsage
11+
type ExecutionTaskWithSearchAreaUsage = ExecutionTask & {
12+
searchAreaUsage?: AIUsageInfo;
13+
};
514
import {
615
type AnimationScript,
716
iconForStatus,
@@ -16,7 +25,7 @@ import type { PlaywrightTasks } from '../../types';
1625
import ReportOverview from '../report-overview';
1726

1827
const SideItem = (props: {
19-
task: ExecutionTask;
28+
task: ExecutionTaskWithSearchAreaUsage;
2029
selected?: boolean;
2130
onClick?: () => void;
2231
onItemHover?: (task: ExecutionTask | null, x?: number, y?: number) => any;
@@ -138,19 +147,31 @@ const SideItem = (props: {
138147
{/* Display usage info in table style if available and Pro mode is enabled */}
139148
{props.proModeEnabled && (
140149
<>
141-
<Tooltip title="The name of the model used this time">
150+
<Tooltip title={task.usage?.model_name || ''}>
142151
<div className="usage-column model-name">
143152
{task.usage?.model_name || '-'}
144153
</div>
145154
</Tooltip>
146155
<Tooltip title="Input tokens sent to the AI model">
147156
<div className="usage-column prompt-tokens">
148-
{task.usage?.prompt_tokens || '-'}
157+
{(() => {
158+
const mainUsage = task.usage?.prompt_tokens || 0;
159+
const searchAreaUsage =
160+
task.searchAreaUsage?.prompt_tokens || 0;
161+
const total = mainUsage + searchAreaUsage;
162+
return total > 0 ? total : '-';
163+
})()}
149164
</div>
150165
</Tooltip>
151166
<Tooltip title="Output tokens generated by the AI model">
152167
<div className="usage-column completion-tokens">
153-
{task.usage?.completion_tokens || '-'}
168+
{(() => {
169+
const mainUsage = task.usage?.completion_tokens || 0;
170+
const searchAreaUsage =
171+
task.searchAreaUsage?.completion_tokens || 0;
172+
const total = mainUsage + searchAreaUsage;
173+
return total > 0 ? total : '-';
174+
})()}
154175
</div>
155176
</Tooltip>
156177
</>
@@ -235,13 +256,24 @@ const Sidebar = (props: SidebarProps = {}): JSX.Element => {
235256
const totalPromptTokens =
236257
groupedDump?.executions
237258
.flatMap((e) => e.tasks)
238-
.reduce((acc, task) => acc + (task.usage?.prompt_tokens || 0), 0) || 0;
259+
.reduce((acc, task) => {
260+
const mainUsage = task.usage?.prompt_tokens || 0;
261+
const searchAreaUsage =
262+
(task as ExecutionTaskWithSearchAreaUsage).searchAreaUsage
263+
?.prompt_tokens || 0;
264+
return acc + mainUsage + searchAreaUsage;
265+
}, 0) || 0;
239266

240267
const totalCompletionTokens =
241268
groupedDump?.executions
242269
.flatMap((e) => e.tasks)
243-
.reduce((acc, task) => acc + (task.usage?.completion_tokens || 0), 0) ||
244-
0;
270+
.reduce((acc, task) => {
271+
const mainUsage = task.usage?.completion_tokens || 0;
272+
const searchAreaUsage =
273+
(task as ExecutionTaskWithSearchAreaUsage).searchAreaUsage
274+
?.completion_tokens || 0;
275+
return acc + mainUsage + searchAreaUsage;
276+
}, 0) || 0;
245277

246278
const executionContent = groupedDump ? (
247279
<div className="execution-info-section">

apps/report/test-data/ai-model.json

Lines changed: 2857 additions & 0 deletions
Large diffs are not rendered by default.

apps/site/docs/en/automate-with-scripts-in-yaml.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,50 @@ web:
174174

175175
# Whether to ignore HTTPS certificate errors, optional, defaults to false.
176176
acceptInsecureCerts: <boolean>
177+
```
178+
179+
### Global agent configuration
180+
181+
If you need to use the `aiActionContext` parameter, you can set it through the global `agent` configuration:
177182

183+
```yaml
184+
# Global AI agent configuration
185+
agent:
178186
# Background knowledge to send to the AI model when calling aiAction, optional.
179187
aiActionContext: <string>
180188
```
181189

190+
:::tip aiActionContext configuration
191+
192+
- **Applicable environments**: Web, iOS, and Android environments can all use the global `agent` configuration to set `aiActionContext`
193+
- **Purpose**: Provides background knowledge to the AI model, like how to handle popups, business introduction, etc.
194+
195+
:::
196+
197+
#### Usage example
198+
199+
```yaml
200+
# Global agent configuration, applies to all environments
201+
agent:
202+
aiActionContext: "If any popup appears, click agree. If login page appears, skip it."
203+
204+
# iOS environment configuration
205+
ios:
206+
launch: https://www.bing.com
207+
wdaPort: 8100
208+
209+
# Or Android environment configuration
210+
android:
211+
deviceId: s4ey59
212+
launch: https://www.bing.com
213+
214+
tasks:
215+
- name: Search for weather
216+
flow:
217+
- ai: Search for "today's weather"
218+
- aiAssert: The results show weather information
219+
```
220+
182221
### The `android` part
183222

184223
```yaml

apps/site/docs/en/bridge-mode-by-chrome-extension.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The bridge mode in the Midscene Chrome extension is a tool that allows you to us
88

99
Using the desktop version of Chrome allows you to reuse all cookies, plugins, page status, and everything else you want. You can work with automation scripts to complete your tasks. This mode is commonly referred to as 'man-in-the-loop' in the context of automation.
1010

11-
![bridge mode](/midscene-bridge-mode.jpg)
11+
![bridge mode](/midscene-bridge-mode.png)
1212

1313
:::info Demo Project
1414
check the demo project of bridge mode: [https://github.com/web-infra-dev/midscene-example/blob/main/bridge-mode-demo](https://github.com/web-infra-dev/midscene-example/blob/main/bridge-mode-demo)
@@ -57,7 +57,7 @@ Promise.resolve(
5757
Start the chrome extension and switch to 'Bridge Mode' tab. Click "Allow connection".
5858

5959
<p align="center">
60-
<img src="/bridge_in_extension.jpg" alt="bridge in extension" width="400"/>
60+
<img src="/bridge_in_extension.png" alt="bridge in extension" width="400"/>
6161
</p>
6262

6363
## Step 5. Run the script

0 commit comments

Comments
 (0)