android-midscene-automation 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
1
  # 更新记录
2
+ ## v1.1.8
3
+ - [Appium]流程布局新增横向显示,默认为纵向。
4
+ - [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
5
+ - [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
6
+ - [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
7
+ - [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
8
+
9
+ ## v1.1.7
10
+ - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
11
+ - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
12
+ - [Appium]优化多分支汇合线:汇合点按左右汇入线居中,增大纵向间距,曲线在底部留白处平滑汇入,减少节点遮挡。
13
+
2
14
  ## v1.1.6
3
15
  - [Appium]优化流程画布交互:点击节点自动放大并居中,流程总览支持还原位置,AI 识别节点提示词最多展示三行。
4
16
  - [Appium]统一节点编辑界面:AI 识别、组件定位、节点信息和超时设置使用紧凑分组,优化循环、滑动、缩放等参数布局。
package/README.md CHANGED
@@ -1502,6 +1502,18 @@ Linux: ~/.local/share/android-midscene-automation
1502
1502
 
1503
1503
  # 项目更新记录
1504
1504
 
1505
+ ## v1.1.8
1506
+ - [Appium]流程布局新增横向显示,默认为纵向。
1507
+ - [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
1508
+ - [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
1509
+ - [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
1510
+ - [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
1511
+
1512
+ ## v1.1.7
1513
+ - [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
1514
+ - [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
1515
+ - [Appium]优化多分支汇合线:汇合点按左右汇入线居中,增大纵向间距,曲线在底部留白处平滑汇入,减少节点遮挡。
1516
+
1505
1517
  ## v1.1.6
1506
1518
  - [Appium]优化流程画布交互:点击节点自动放大并居中,流程总览支持还原位置,AI 识别节点提示词最多展示三行。
1507
1519
  - [Appium]统一节点编辑界面:AI 识别、组件定位、节点信息和超时设置使用紧凑分组,优化循环、滑动、缩放等参数布局。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "android-midscene-automation",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oooooooko/android-midscene-automation.git"
@@ -63,5 +63,17 @@ test('loads quietly, serializes rapid edits, validates colors and surfaces save
63
63
  await delay(400);
64
64
  assert.equal(auto.status.value, '已自动保存');
65
65
  assert.equal(submissions.at(-1)?.screenshotReport, true);
66
+ const savedCount = submissions.length;
67
+ form.appium.flowNodeColor = '#';
68
+ await delay(400);
69
+ assert.equal(submissions.length, savedCount, 'incomplete node colors must not be saved');
70
+ Object.assign(form.appium, { flowBackgroundColor: '#eaf2fb', flowNodeColor: '#f6faff', flowNodeBorderColor: '#a8c1df', flowLineColor: '#6385b0' });
71
+ await delay(400);
72
+ assert.equal(submissions.length, savedCount + 1, 'theme colors are saved together');
73
+ assert.equal(submissions.at(-1)?.flowNodeColor, '#f6faff');
74
+ assert.equal(submissions.at(-1)?.flowNodeBorderColor, '#a8c1df');
75
+ form.appium.flowNodeBorderColor = '#';
76
+ await delay(400);
77
+ assert.equal(submissions.length, savedCount + 1);
66
78
  } finally { scope.stop(); }
67
79
  });
@@ -42,10 +42,18 @@ test('Appium autosave is isolated from manual config, persists and rejects inval
42
42
  const base = `http://127.0.0.1:${address.port}`;
43
43
  const post = (path: string, body: unknown) => fetch(base + path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
44
44
  const initial = await (await fetch(base + '/api/config')).json() as AppConfig;
45
- const appium = { ...initial.appium, flowLineColor: '#AbC', model: { baseUrl: 'https://example.invalid', apiKey: 'test', name: 'new-model' } };
45
+ assert.equal(initial.appium.flowNodeColor, '#ffffff');
46
+ assert.equal(initial.appium.flowNodeBorderColor, '#dfe8f3');
47
+ assert.equal(initial.appium.flowLineStyle, 'curved');
48
+ assert.equal(initial.appium.flowLayoutDirection, 'vertical');
49
+ const appium = { ...initial.appium, flowLineStyle: 'curved', flowLayoutDirection: 'horizontal', flowLineColor: '#AbC', flowNodeColor: '#dEf', flowNodeBorderColor: '#123', model: { baseUrl: 'https://example.invalid', apiKey: 'test', name: 'new-model' } };
46
50
  assert.equal((await post('/api/config/appium', { appium, runtime: { androidSdkPath: 'invalid-draft' }, midscene: { model: { name: 'unsaved' } } })).status, 200);
47
51
  let stored = await (await fetch(base + '/api/config')).json() as AppConfig;
48
52
  assert.equal(stored.appium.flowLineColor, '#aabbcc');
53
+ assert.equal(stored.appium.flowNodeColor, '#ddeeff');
54
+ assert.equal(stored.appium.flowNodeBorderColor, '#112233');
55
+ assert.equal(stored.appium.flowLineStyle, 'curved');
56
+ assert.equal(stored.appium.flowLayoutDirection, 'horizontal');
49
57
  assert.deepEqual(stored.runtime, initial.runtime);
50
58
  assert.deepEqual(stored.midscene, initial.midscene);
51
59
  const { appium: _appium, ...manual } = structuredClone(initial);
@@ -55,9 +63,18 @@ test('Appium autosave is isolated from manual config, persists and rejects inval
55
63
  assert.deepEqual(stored.appium.model, initial.appium.model, 'automatic saves must not persist untested model drafts');
56
64
  assert.equal(stored.midscene.model.name, initial.midscene.model.name, 'runtime save must not persist an untested model');
57
65
  assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLineColor: 'invalid' } })).status, 400);
66
+ assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLineStyle: 'invalid' } })).status, 400);
67
+ assert.equal((await post('/api/config/appium', { appium: { ...appium, flowLayoutDirection: 'diagonal' } })).status, 400);
68
+ for (const key of ['flowNodeColor', 'flowNodeBorderColor']) {
69
+ assert.equal((await post('/api/config/appium', { appium: { ...appium, [key]: 'invalid' } })).status, 400);
70
+ }
58
71
  assert.equal((await post('/api/config/appium', { appium: null })).status, 400);
59
72
  const { loadModelConfigFromDb } = await import('./config-store');
60
73
  assert.equal(loadModelConfigFromDb()?.appium?.flowLineColor, '#aabbcc');
74
+ assert.equal(loadModelConfigFromDb()?.appium?.flowNodeColor, '#ddeeff');
75
+ assert.equal(loadModelConfigFromDb()?.appium?.flowNodeBorderColor, '#112233');
76
+ assert.equal(loadModelConfigFromDb()?.appium?.flowLineStyle, 'curved');
77
+ assert.equal(loadModelConfigFromDb()?.appium?.flowLayoutDirection, 'horizontal');
61
78
 
62
79
  for (const key of ['midscene', 'scriptOptimizer', 'appium'] as const) {
63
80
  const before = await (await fetch(base + '/api/config')).json() as AppConfig;
@@ -333,7 +333,7 @@ async function appiumRequest<T>(
333
333
  throw new ReplayStoppedError();
334
334
  }
335
335
  context?.appiumLog(`[Appium] 异常:${method} ${effectivePath}(${errorDetail(error)})`);
336
- if (error instanceof AppiumRequestTimeoutError) throw error;
336
+ if (error instanceof AppiumRequestTimeoutError || error instanceof ConditionTimeoutError) throw error;
337
337
  if (isTimeoutError(error)) {
338
338
  throw new AppiumServiceError(`Appium 请求超时 ${requestUrl},${errorDetail(error)}`);
339
339
  }
@@ -550,6 +550,7 @@ async function findElementWithinDeadline(sessionId: string, step: AppiumRecorded
550
550
  return await findElementBySelector(sessionId, step.selector, parentId);
551
551
  } catch (error) {
552
552
  throwIfReplayStopped(error);
553
+ if (error instanceof ConditionTimeoutError) throw error;
553
554
  lastError = error;
554
555
  // Continue with the fallback chain below.
555
556
  }
@@ -567,6 +568,7 @@ async function findElementWithinDeadline(sessionId: string, step: AppiumRecorded
567
568
  return await findElementBySelector(sessionId, selector);
568
569
  } catch (error) {
569
570
  throwIfReplayStopped(error);
571
+ if (error instanceof ConditionTimeoutError) throw error;
570
572
  lastError = error;
571
573
  }
572
574
  }
@@ -726,6 +728,7 @@ async function waitForElementGone(sessionId: string, step: AppiumRecordedStepRec
726
728
  await findElement(sessionId, step, remaining);
727
729
  } catch (error) {
728
730
  throwIfReplayStopped(error);
731
+ if (error instanceof ConditionTimeoutError) throw error;
729
732
  return;
730
733
  }
731
734
  const pauseMs = Math.min(500, timeoutMs - (Date.now() - startedAt));
@@ -1,5 +1,6 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import { test } from 'node:test';
3
+ import { setTimeout as delay } from 'node:timers/promises';
3
4
  import childProcess from 'node:child_process';
4
5
  import { syncBuiltinESMExports } from 'node:module';
5
6
  import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
@@ -186,6 +187,66 @@ test('text matching does not start another Appium query at the node deadline', a
186
187
  }
187
188
  });
188
189
 
190
+ test('missing element completes its last query and follows the timeout branch without reporting a service failure', async () => {
191
+ const root = await mkdtemp(join(tmpdir(), 'text-deadline-'));
192
+ const env = { ...process.env };
193
+ const original = { execFile: childProcess.execFile, fetch: globalThis.fetch };
194
+ let elementQueries = 0;
195
+ try {
196
+ const sdk = join(root, 'sdk');
197
+ await mkdir(join(sdk, 'platform-tools'), { recursive: true });
198
+ await writeFile(join(sdk, 'platform-tools', 'adb'), '');
199
+ Object.assign(process.env, {
200
+ ANDROID_MIDSCENE_DATA_ROOT: root,
201
+ ANDROID_HOME: sdk,
202
+ ANDROID_SDK_ROOT: sdk,
203
+ APPIUM_SERVER_URL: 'http://external.invalid',
204
+ });
205
+ childProcess.execFile = ((_command, _args: string[], _options, callback) => {
206
+ queueMicrotask(() => callback(null, '', ''));
207
+ return {};
208
+ }) as typeof childProcess.execFile;
209
+ syncBuiltinESMExports();
210
+ globalThis.fetch = async (input, init) => {
211
+ const path = new URL(String(input)).pathname;
212
+ if (path === '/session' && init?.method === 'POST') {
213
+ return Response.json({ value: { sessionId: 'deadline-session' } });
214
+ }
215
+ if (path === '/session/deadline-session/element') {
216
+ elementQueries += 1;
217
+ await delay(150, undefined, { signal: init?.signal ?? undefined });
218
+ return Response.json({ value: { error: 'no such element', message: 'not found' } }, { status: 404 });
219
+ }
220
+ return Response.json({ value: null });
221
+ };
222
+ const { replayAppiumScript } = await import('./appium-runner');
223
+ const script: AppiumRecordedScriptRecord = {
224
+ id: 'deadline', name: 'deadline', deviceId: 'fake-device', appPackage: '', appActivity: '', createdAt: '', updatedAt: '',
225
+ steps: [{
226
+ id: 'text', type: 'assertExists', label: '判断低功耗主页', timeoutMs: 100,
227
+ selector: { strategy: 'id', value: 'example:id/batterItem', unique: true },
228
+ timeoutBranch: 'no', flow: { nodeKind: 'condition', noTargetId: 'done' },
229
+ }, { id: 'done', type: 'noop', label: '继续执行' }],
230
+ };
231
+ const result = await replayAppiumScript(script, 'fake-device', undefined, undefined, {
232
+ screenshotReport: false,
233
+ reportSummaryEnabled: false,
234
+ });
235
+ assert.equal(result.success, true, result.output);
236
+ assert.doesNotMatch(result.output, /服务无响应/);
237
+ assert.equal(elementQueries, 1, 'no retry after the node deadline');
238
+ assert.match(result.output, /判断超时,按配置进入右侧分支/);
239
+ } finally {
240
+ childProcess.execFile = original.execFile;
241
+ globalThis.fetch = original.fetch;
242
+ syncBuiltinESMExports();
243
+ for (const key of ['ANDROID_MIDSCENE_DATA_ROOT', 'ANDROID_HOME', 'ANDROID_SDK_ROOT', 'APPIUM_SERVER_URL']) {
244
+ if (env[key] === undefined) delete process.env[key]; else process.env[key] = env[key];
245
+ }
246
+ await rm(root, { recursive: true, force: true });
247
+ }
248
+ });
249
+
189
250
  test('optional tap recovers a blocked UiAutomator2 session and uses the ADB hierarchy', async () => {
190
251
  const root = await mkdtemp(join(tmpdir(), 'optional-recovery-'));
191
252
  const env = { ...process.env };
@@ -0,0 +1,52 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { buildFlowGraph } from '../../src/appium-recorder/flow-graph';
4
+ import { labelFlowStep } from '../../src/appium-recorder/flow-labels';
5
+ import type { AppiumRecordedStep } from '../../src/appium-recorder/types';
6
+
7
+ const steps: AppiumRecordedStep[] = [
8
+ { id: 'outer', type: 'assertExists', label: '外层判断', flow: { nodeKind: 'condition' } },
9
+ { id: 'inner', type: 'assertExists', label: '内层判断', flow: { nodeKind: 'condition', parentConditionId: 'outer', parentBranch: 'yes' } },
10
+ { id: 'left', type: 'delay', label: '等待', flow: { parentConditionId: 'inner', parentBranch: 'yes' } },
11
+ { id: 'right', type: 'delay', label: '等待', flow: { parentConditionId: 'inner', parentBranch: 'no' } },
12
+ { id: 'outer-no', type: 'delay', label: '等待', flow: { parentConditionId: 'outer', parentBranch: 'no' } },
13
+ { id: 'finish', type: 'log', label: '公共节点' },
14
+ ];
15
+ const options = { expandedStepIndex: null, selectedCopyIndexes: [], copyMode: false, canOpenInsertMenu: true,
16
+ isStartActionDisabled: () => false, isInsertActionDisabled: () => false, isAppExecutionDisabled: () => false,
17
+ startActionGroups: [], mainActionGroups: [], labelStep: labelFlowStep, isCopySelected: () => false };
18
+
19
+ test('both layout directions preserve flow links, center merges and avoid expanded cards', () => {
20
+ const original = structuredClone(steps);
21
+ const baseline = buildFlowGraph(steps, options);
22
+ for (const layoutDirection of ['vertical', 'horizontal'] as const) {
23
+ const horizontal = layoutDirection === 'horizontal';
24
+ const graph = buildFlowGraph(steps, { ...options, layoutDirection, expandedStepIndex: 2, measuredNodeHeights: { 'step:left': 920 } });
25
+ assert.deepEqual(graph.edges, baseline.edges, 'display direction must not change the flow');
26
+ const byId = new Map(graph.nodes.map(node => [node.id, node]));
27
+ const crossCenter = (id: string) => {
28
+ const node = byId.get(id)!;
29
+ return horizontal ? node.position.y + Number(node.height) / 2 : node.position.x + Number(node.width) / 2;
30
+ };
31
+ for (const [index, a] of graph.nodes.entries()) {
32
+ assert.equal(a.sourcePosition, horizontal ? 'right' : 'bottom');
33
+ if (a.data.kind === 'step') assert.equal(a.width, 340);
34
+ for (const b of graph.nodes.slice(index + 1)) {
35
+ const overlapX = Math.min(a.position.x + Number(a.width), b.position.x + Number(b.width)) - Math.max(a.position.x, b.position.x);
36
+ const overlapY = Math.min(a.position.y + Number(a.height), b.position.y + Number(b.height)) - Math.max(a.position.y, b.position.y);
37
+ assert.ok(overlapX <= 1 || overlapY <= 1, `${layoutDirection}: ${a.id} overlaps ${b.id}`);
38
+ }
39
+ }
40
+ for (const edge of graph.edges) {
41
+ const source = byId.get(edge.source)!;
42
+ const target = byId.get(edge.target)!;
43
+ assert.ok(horizontal ? target.position.x >= source.position.x + Number(source.width) + 23
44
+ : target.position.y >= source.position.y + Number(source.height) + 23);
45
+ if ((edge.data as { merge?: boolean })?.merge) {
46
+ const incoming = graph.edges.filter(item => item.target === edge.target).map(item => crossCenter(item.source));
47
+ assert.ok(Math.abs(crossCenter(edge.target) - (Math.min(...incoming) + Math.max(...incoming)) / 2) <= 1);
48
+ }
49
+ }
50
+ }
51
+ assert.deepEqual(steps, original);
52
+ });
@@ -0,0 +1,34 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { createServer } from 'node:http';
4
+ import { setTimeout as delay } from 'node:timers/promises';
5
+ import { ConditionTimeoutError } from './condition-timeout';
6
+ import { AppiumRequestTimeoutError, timedAppiumFetch, withElementDeadline } from './request-timeout';
7
+
8
+ test('element deadline does not shorten an in-flight request or its response body', async () => {
9
+ const server = createServer(async (_req, res) => {
10
+ res.writeHead(404, { 'Content-Type': 'application/json' });
11
+ res.flushHeaders();
12
+ await delay(150);
13
+ res.end('{"value":{"error":"no such element"}}');
14
+ });
15
+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
16
+ const url = `http://127.0.0.1:${(server.address() as { port: number }).port}/element`;
17
+ try {
18
+ const result = await withElementDeadline(50, () => timedAppiumFetch(url, {}, 2000));
19
+ assert.equal(result.response.status, 404);
20
+ assert.equal(JSON.parse(result.text).value.error, 'no such element');
21
+ await assert.rejects(withElementDeadline(1, async () => {
22
+ await delay(10);
23
+ return timedAppiumFetch(url, {}, 2000);
24
+ }), ConditionTimeoutError);
25
+ await assert.rejects(withElementDeadline(10, () => timedAppiumFetch(url, {}, 50)), AppiumRequestTimeoutError);
26
+ const controller = new AbortController();
27
+ const request = timedAppiumFetch(url, { signal: controller.signal }, 2000);
28
+ controller.abort(new Error('user stopped'));
29
+ await assert.rejects(request, /user stopped/);
30
+ } finally {
31
+ server.closeAllConnections();
32
+ await new Promise<void>(resolve => server.close(() => resolve()));
33
+ }
34
+ });
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { ConditionTimeoutError } from './condition-timeout';
2
3
 
3
4
  const deadline = new AsyncLocalStorage<number>();
4
5
  export class AppiumRequestTimeoutError extends Error {}
@@ -14,8 +15,11 @@ export function remainingElementDeadlineMs() {
14
15
 
15
16
  // 响应体也受同一个期限约束,避免收到 HTTP 头后继续无限等待。
16
17
  export async function timedAppiumFetch(url: string, init: RequestInit, timeoutMs: number) {
17
- const remaining = Math.max(1, Math.min(timeoutMs, (deadline.getStore() ?? Infinity) - Date.now()));
18
- const timeout = AbortSignal.timeout(Math.ceil(remaining));
18
+ const elementRemaining = remainingElementDeadlineMs();
19
+ if (elementRemaining <= 0) throw new ConditionTimeoutError('元素定位等待期限已到');
20
+ // 节点期限限制是否继续查找;已发出的请求使用独立通信超时,
21
+ // 避免把最后一次正常查询因剩余预算过短误报为服务无响应。
22
+ const timeout = AbortSignal.timeout(Math.ceil(timeoutMs));
19
23
  const signal = init.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
20
24
  try {
21
25
  const response = await fetch(url, { ...init, signal });
@@ -23,7 +27,7 @@ export async function timedAppiumFetch(url: string, init: RequestInit, timeoutMs
23
27
  return { response, text };
24
28
  } catch (error) {
25
29
  if (timeout.aborted && !init.signal?.aborted) {
26
- throw new AppiumRequestTimeoutError(`设备自动化服务无响应:Appium 请求超过 ${Math.ceil(remaining)}ms,已停止等待(${url})`);
30
+ throw new AppiumRequestTimeoutError(`设备自动化服务无响应:Appium 请求超过 ${Math.ceil(timeoutMs)}ms,已停止等待(${url})`);
27
31
  }
28
32
  throw error;
29
33
  }
package/server/config.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { resolveReportSummary, type ReportSummaryConfig } from '../src/appium-recorder/report-summary';
2
2
  import type { AiPromptPreset } from '../src/appium-recorder/ai-prompt-presets';
3
3
  import fs from 'node:fs';
4
- import { isHexColor, normalizeFlowBackground, normalizeFlowLineColor } from '../src/appium-recorder/flow-appearance';
4
+ import { isHexColor, normalizeFlowBackground, normalizeFlowLineColor, normalizeFlowLineStyle, normalizeFlowLayoutDirection, normalizeFlowNodeColor, normalizeFlowNodeBorderColor } from '../src/appium-recorder/flow-appearance';
5
5
  import os from 'node:os';
6
6
  import path from 'node:path';
7
7
  import YAML from 'yaml';
@@ -13,7 +13,7 @@ import { resolveAiDeduplication, type AiDeduplicationConfig } from '../src/appiu
13
13
  import type { MidsceneModelProvider } from '../src/config/midscene-model-presets';
14
14
 
15
15
  export type AppConfig = {
16
- appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowLineColor?: string; screenshotReport?: boolean };
16
+ appium: { reportSummary?: ReportSummaryConfig; model: AiRecognitionModel; promptOptimizer?: { model: AiRecognitionModel }; aiPromptPresets?: AiPromptPreset[]; aiDeduplication?: AiDeduplicationConfig; flowBackgroundColor?: string; flowNodeColor?: string; flowNodeBorderColor?: string; flowLineColor?: string; flowLineStyle?: 'straight' | 'curved'; flowLayoutDirection?: 'vertical' | 'horizontal'; screenshotReport?: boolean };
17
17
  runtime: {
18
18
  androidSdkPath: string;
19
19
  reportOutputPath: string;
@@ -99,7 +99,11 @@ function normalizeConfig(config: Partial<AppConfig> | null | undefined): AppConf
99
99
  aiDeduplication: resolveAiDeduplication(config?.appium?.aiDeduplication),
100
100
  screenshotReport: config?.appium?.screenshotReport === true,
101
101
  flowBackgroundColor: normalizeFlowBackground(config?.appium?.flowBackgroundColor),
102
+ flowNodeColor: normalizeFlowNodeColor(config?.appium?.flowNodeColor),
103
+ flowNodeBorderColor: normalizeFlowNodeBorderColor(config?.appium?.flowNodeBorderColor),
102
104
  flowLineColor: normalizeFlowLineColor(config?.appium?.flowLineColor),
105
+ flowLineStyle: normalizeFlowLineStyle(config?.appium?.flowLineStyle),
106
+ flowLayoutDirection: normalizeFlowLayoutDirection(config?.appium?.flowLayoutDirection),
103
107
  model: Object.fromEntries(['baseUrl', 'apiKey', 'name'].map((key) => {
104
108
  const value = config?.appium?.model?.[key as keyof AiRecognitionModel];
105
109
  return [key, typeof value === 'string' ? value.trim() : ''];
@@ -234,11 +238,22 @@ export function saveConfig(config: AppConfig) {
234
238
  try { resolveAiDeduplication(config.appium?.aiDeduplication); }
235
239
  catch (error) { throw new ConfigValidationError(error instanceof Error ? error.message : '截图去重配置无效'); }
236
240
  if (config.appium?.flowBackgroundColor !== undefined && !isHexColor(config.appium.flowBackgroundColor)) {
237
- throw new ConfigValidationError('流程背景色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
241
+ throw new ConfigValidationError('画布背景色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
238
242
  }
239
243
  if (config.appium?.flowLineColor !== undefined && !isHexColor(config.appium.flowLineColor)) {
240
244
  throw new ConfigValidationError('连接线条颜色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
241
245
  }
246
+ if (config.appium?.flowLineStyle !== undefined && !['straight', 'curved'].includes(config.appium.flowLineStyle)) {
247
+ throw new ConfigValidationError('连接线条样式必须是直线或曲线');
248
+ }
249
+ if (config.appium?.flowLayoutDirection !== undefined && !['vertical', 'horizontal'].includes(config.appium.flowLayoutDirection)) {
250
+ throw new ConfigValidationError('流程布局方向必须是纵向或横向');
251
+ }
252
+ for (const key of ['flowNodeColor', 'flowNodeBorderColor'] as const) {
253
+ if (config.appium?.[key] !== undefined && !isHexColor(config.appium[key])) {
254
+ throw new ConfigValidationError('节点颜色必须是有效的十六进制颜色(#RGB 或 #RRGGBB)');
255
+ }
256
+ }
242
257
  const normalized = normalizeConfig(config);
243
258
  validateRuntimeConfig(normalized);
244
259
  cachedConfig = normalized;
package/src/App.vue CHANGED
@@ -993,7 +993,11 @@ onUnmounted(() => {
993
993
  :ai-prompt-presets="configForm.appium.aiPromptPresets"
994
994
  :report-summary="configForm.appium.reportSummary"
995
995
  :flow-background-color="configForm.appium.flowBackgroundColor"
996
+ :flow-node-color="configForm.appium.flowNodeColor"
997
+ :flow-node-border-color="configForm.appium.flowNodeBorderColor"
996
998
  :flow-line-color="configForm.appium.flowLineColor"
999
+ :flow-line-style="configForm.appium.flowLineStyle"
1000
+ :flow-layout-direction="configForm.appium.flowLayoutDirection"
997
1001
  :device-actions="deviceActions"
998
1002
  :playground-available="playgroundAvailable"
999
1003
  :playground-device-id="playgroundDeviceId"
@@ -1,12 +1,12 @@
1
1
  <script setup lang="ts">
2
- import { computed, h, onMounted, onUnmounted, provide, reactive, shallowRef, watch } from 'vue';
3
- import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor } from './flow-appearance';
2
+ import { computed, h, nextTick, onMounted, onUnmounted, provide, reactive, shallowRef, useTemplateRef, watch } from 'vue';
3
+ import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor, flowLineStyleKey, normalizeFlowLineStyle, type FlowLineStyle, flowLayoutDirectionKey, normalizeFlowLayoutDirection, type FlowLayoutDirection, flowNodeColorKey, normalizeFlowNodeColor, flowNodeBorderColorKey, normalizeFlowNodeBorderColor } from './flow-appearance';
4
4
  import { useCoordinatePicker } from './coordinate-preview';
5
5
  import { DEFAULT_NODE_TIMEOUT_MS } from './node-timeout';
6
6
  import { aiPromptPresetsKey, DEFAULT_AI_PROMPT_PRESETS, type AiPromptPreset } from './ai-prompt-presets';
7
7
  import AiRecognitionPromptInput from './components/AiRecognitionPromptInput.vue';
8
8
  import { ElForm, ElFormItem, ElInputNumber, ElMessage, ElMessageBox, ElOption, ElSelect } from 'element-plus';
9
- import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
9
+ import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, FolderOpened, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
10
10
  import RunHistoryDialog from './RunHistoryDialog.vue';
11
11
  import type { AndroidDevice, AppPreset, DeviceAction } from '../types';
12
12
  import DevicePreviewPanel from '../components/device/DevicePreviewPanel.vue';
@@ -111,7 +111,11 @@ const props = defineProps<{
111
111
  aiPromptPresets?: AiPromptPreset[];
112
112
  reportSummary?: ReportSummaryConfig;
113
113
  flowBackgroundColor?: string;
114
+ flowNodeColor?: string;
115
+ flowNodeBorderColor?: string;
114
116
  flowLineColor?: string;
117
+ flowLineStyle?: FlowLineStyle;
118
+ flowLayoutDirection?: FlowLayoutDirection;
115
119
  active: boolean;
116
120
  appPresets: AppPreset[];
117
121
  deviceActions: readonly DeviceAction[];
@@ -137,7 +141,11 @@ const props = defineProps<{
137
141
 
138
142
  // provide/inject 随组件关系传递,放大弹窗 teleport 后也能使用同一颜色。
139
143
  provide(flowBackgroundKey, computed(() => normalizeFlowBackground(props.flowBackgroundColor)));
144
+ provide(flowNodeColorKey, computed(() => normalizeFlowNodeColor(props.flowNodeColor)));
145
+ provide(flowNodeBorderColorKey, computed(() => normalizeFlowNodeBorderColor(props.flowNodeBorderColor)));
140
146
  provide(flowLineColorKey, computed(() => normalizeFlowLineColor(props.flowLineColor)));
147
+ provide(flowLineStyleKey, computed(() => normalizeFlowLineStyle(props.flowLineStyle)));
148
+ provide(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(props.flowLayoutDirection)));
141
149
  const availableAiPromptPresets = computed(() => props.aiPromptPresets ?? DEFAULT_AI_PROMPT_PRESETS);
142
150
  const availableReportTemplates = computed(() => [
143
151
  ...REPORT_SUMMARY_PROMPT_PRESETS,
@@ -150,6 +158,7 @@ const tree = shallowRef<AppiumNode | null>(null);
150
158
  const selectedNode = shallowRef<AppiumNode | null>(null);
151
159
  const scripts = shallowRef<AppiumRecordedScript[]>([]);
152
160
  const selectedScriptId = shallowRef('');
161
+ const recordedStepsRef = useTemplateRef('recordedStepsRef');
153
162
  const newScriptDialogVisible = shallowRef(false);
154
163
  const newScriptRevision = shallowRef(0);
155
164
  const storedWorkbenchTab = window.localStorage.getItem(WORKBENCH_TAB_STORAGE_KEY);
@@ -1866,6 +1875,7 @@ function loadScript(script: AppiumRecordedScript) {
1866
1875
  }
1867
1876
  steps.value = normalizeLegacyNestedConditionBranches((script.steps || []).map(normalizeLegacyFlowScope));
1868
1877
  markDraftSaved();
1878
+ void nextTick(() => recordedStepsRef.value?.resetMainFlowPosition());
1869
1879
  }
1870
1880
 
1871
1881
  function loadSelectedScript() {
@@ -2390,6 +2400,7 @@ watch(
2390
2400
 
2391
2401
  <section class="appium-workbench__section appium-workbench__flow">
2392
2402
  <RecordedSteps
2403
+ ref="recordedStepsRef"
2393
2404
  :key="newScriptRevision"
2394
2405
  :ai-recognition-model-configured="aiRecognitionModelConfigured"
2395
2406
  :steps="steps"
@@ -2448,7 +2459,7 @@ watch(
2448
2459
  <el-button size="small" :icon="Clock" aria-label="历史结果对比" @click.stop="historyScript = { id: script.id, name: script.name }" />
2449
2460
  </span></el-tooltip>
2450
2461
  <el-tooltip content="加载" placement="top" :show-after="200"><span class="appium-script-icon">
2451
- <el-button size="small" :icon="Document" aria-label="加载" @click.stop="loadScript(script)" />
2462
+ <el-button size="small" :icon="FolderOpened" aria-label="加载" @click.stop="loadScript(script)" />
2452
2463
  </span></el-tooltip>
2453
2464
  <el-tooltip content="修改脚本名称" placement="top" :show-after="200"><span class="appium-script-icon">
2454
2465
  <el-button
@@ -232,7 +232,7 @@ async function save(enabled: boolean, observation?: AiObservationConfig) {
232
232
  .ai-recognition-settings__toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0 12px; }
233
233
  .ai-recognition-settings__toggle-row :deep(.el-checkbox) { margin-right: 0; }
234
234
  .ai-recognition-settings__toggles :deep(.el-form-item__content) { align-items: center; }
235
- .ai-recognition-settings__groups { overflow: hidden; border: 1px solid var(--el-border-color-lighter); border-radius: 10px; background: #fff; }
235
+ .ai-recognition-settings__groups { overflow: hidden; border: 1px solid var(--el-border-color-lighter); border-radius: 10px; background: var(--ui-surface); }
236
236
  .ai-recognition-settings__groups :deep(.el-collapse-item__header) { height: 42px; padding: 0 10px; border-bottom-color: var(--el-border-color-lighter); font-size: 12px; }
237
237
  .ai-recognition-settings__groups :deep(.el-collapse-item__wrap) { border-bottom-color: var(--el-border-color-lighter); }
238
238
  .ai-recognition-settings__groups :deep(.el-collapse-item:last-child .el-collapse-item__header),