ms-vite-plugin 1.4.19 → 1.4.21
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/dist/cli.js +19 -0
- package/dist/mcp/ocr-tools.d.ts +8 -0
- package/dist/mcp/ocr-tools.js +63 -9
- package/docs/AGENTS.md +1 -0
- package/docs/SKILL.md +1 -1
- package/docs/api/config.md +70 -28
- package/docs/apicn/config.md +68 -26
- package/docs/apipython/config.md +72 -29
- package/docs/mcp-agent-description.md +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -684,6 +684,13 @@ async function ocrCommand(options) {
|
|
|
684
684
|
const texts = textItems.length > 0 ? textItems : undefined;
|
|
685
685
|
const languages = parseAppleOcrLanguages(options.languages);
|
|
686
686
|
const confidenceThreshold = parseCliNumber(options.confidenceThreshold, 0.6, "confidence-threshold", 0, 1);
|
|
687
|
+
const paddleModel = options.paddleModel === undefined
|
|
688
|
+
? undefined
|
|
689
|
+
: parseCliChoice(options.paddleModel, ocr_tools_1.PADDLE_OCR_MODELS[0], ocr_tools_1.PADDLE_OCR_MODELS, "paddle-model");
|
|
690
|
+
const maxSideLen = options.maxSideLen === undefined
|
|
691
|
+
? undefined
|
|
692
|
+
: parseCliInteger(options.maxSideLen, 0, "max-side-len", 0);
|
|
693
|
+
const useGpu = options.useGpu === true ? true : undefined;
|
|
687
694
|
const timeoutMs = parseCliInteger(options.timeoutMs, 60000, "timeout-ms", 1000, 600000);
|
|
688
695
|
const format = parseCliChoice(options.format, "summary", ["summary", "json"], "format");
|
|
689
696
|
const result = await (0, ocr_tools_1.runOcrRecognitionOnDevice)(target, {
|
|
@@ -698,6 +705,9 @@ async function ocrCommand(options) {
|
|
|
698
705
|
languages,
|
|
699
706
|
confidenceThreshold,
|
|
700
707
|
exactMatch: options.exactMatch === true,
|
|
708
|
+
paddleModel,
|
|
709
|
+
maxSideLen,
|
|
710
|
+
useGpu,
|
|
701
711
|
outputPath: format === "summary" ? options.output : undefined,
|
|
702
712
|
timeoutMs,
|
|
703
713
|
});
|
|
@@ -714,6 +724,12 @@ async function ocrCommand(options) {
|
|
|
714
724
|
`mode: ${mode}`,
|
|
715
725
|
`input: ${input}`,
|
|
716
726
|
`region: x=${x}, y=${y}, ex=${ex}, ey=${ey}`,
|
|
727
|
+
...(engine === "paddleocr" && paddleModel
|
|
728
|
+
? [`paddleModel: ${paddleModel}`]
|
|
729
|
+
: []),
|
|
730
|
+
...(engine === "paddleocr" && maxSideLen !== undefined
|
|
731
|
+
? [`maxSideLen: ${maxSideLen}`]
|
|
732
|
+
: []),
|
|
717
733
|
`status: ${result.status}`,
|
|
718
734
|
].join("\n"));
|
|
719
735
|
}
|
|
@@ -1117,6 +1133,9 @@ commander_1.program
|
|
|
1117
1133
|
.option("--languages <languages>", "Apple OCR 语言,支持 JSON 数组或逗号分隔")
|
|
1118
1134
|
.option("--exact-match", "findText 要求完整匹配文本")
|
|
1119
1135
|
.option("--confidence-threshold <confidenceThreshold>", "PaddleOCR 置信度阈值", "0.6")
|
|
1136
|
+
.option("--paddle-model <paddleModel>", "仅 paddleocr:切换模型 ppocr-v6-tiny|ppocr-v6-small|ppocr-v5")
|
|
1137
|
+
.option("--max-side-len <maxSideLen>", "仅 paddleocr:检测最大边长,0 回落默认 768")
|
|
1138
|
+
.option("--use-gpu", "仅 paddleocr:切换模型时启用 GPU")
|
|
1120
1139
|
.option("--timeout-ms <timeoutMs>", "请求超时时间(毫秒)", "60000")
|
|
1121
1140
|
.option("--format <format>", "返回格式: summary|json", "summary")
|
|
1122
1141
|
.option("--output <output>", "OCR 输出文件路径(可选)")
|
package/dist/mcp/ocr-tools.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
export type OcrEngine = "appleocr" | "paddleocr";
|
|
3
3
|
export type OcrMode = "recognize" | "numbers" | "findText";
|
|
4
|
+
export type PaddleOcrModel = "ppocr-v6-tiny" | "ppocr-v6-small" | "ppocr-v5";
|
|
5
|
+
/** PaddleOCR 内置可切换模型 ID;同一时间只保留一个 active 模型。 */
|
|
6
|
+
export declare const PADDLE_OCR_MODELS: readonly ["ppocr-v6-tiny", "ppocr-v6-small", "ppocr-v5"];
|
|
7
|
+
/** PaddleOCR 检测阶段默认最大边长,与运行时一致;传 0 或负数时回落到该值。 */
|
|
8
|
+
export declare const PADDLE_OCR_DEFAULT_MAX_SIDE_LEN = 768;
|
|
4
9
|
export type ScriptResultResponse = {
|
|
5
10
|
success?: boolean;
|
|
6
11
|
result?: unknown;
|
|
@@ -19,6 +24,9 @@ export type OcrRecognitionOptions = {
|
|
|
19
24
|
languages?: string[];
|
|
20
25
|
confidenceThreshold: number;
|
|
21
26
|
exactMatch: boolean;
|
|
27
|
+
paddleModel?: PaddleOcrModel;
|
|
28
|
+
maxSideLen?: number;
|
|
29
|
+
useGpu?: boolean;
|
|
22
30
|
outputPath?: string;
|
|
23
31
|
timeoutMs: number;
|
|
24
32
|
};
|
package/dist/mcp/ocr-tools.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.APPLE_OCR_LANGUAGES = void 0;
|
|
36
|
+
exports.APPLE_OCR_LANGUAGES = exports.PADDLE_OCR_DEFAULT_MAX_SIDE_LEN = exports.PADDLE_OCR_MODELS = void 0;
|
|
37
37
|
exports.formatOcrToolText = formatOcrToolText;
|
|
38
38
|
exports.runOcrRecognitionOnDevice = runOcrRecognitionOnDevice;
|
|
39
39
|
exports.registerOcrTools = registerOcrTools;
|
|
@@ -42,6 +42,14 @@ const os = __importStar(require("os"));
|
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const z = __importStar(require("zod/v4"));
|
|
44
44
|
const tool_utils_1 = require("./tool-utils");
|
|
45
|
+
/** PaddleOCR 内置可切换模型 ID;同一时间只保留一个 active 模型。 */
|
|
46
|
+
exports.PADDLE_OCR_MODELS = [
|
|
47
|
+
"ppocr-v6-tiny",
|
|
48
|
+
"ppocr-v6-small",
|
|
49
|
+
"ppocr-v5",
|
|
50
|
+
];
|
|
51
|
+
/** PaddleOCR 检测阶段默认最大边长,与运行时一致;传 0 或负数时回落到该值。 */
|
|
52
|
+
exports.PADDLE_OCR_DEFAULT_MAX_SIDE_LEN = 768;
|
|
45
53
|
exports.APPLE_OCR_LANGUAGES = [
|
|
46
54
|
"en-US",
|
|
47
55
|
"fr-FR",
|
|
@@ -113,21 +121,36 @@ function buildAppleOcrScript(mode, input, x, y, ex, ey, texts, languages, exactM
|
|
|
113
121
|
* @param texts 查找文本数组
|
|
114
122
|
* @param confidenceThreshold 置信度阈值
|
|
115
123
|
* @param exactMatch 是否完整匹配文本
|
|
124
|
+
* @param paddleModel 可选切换的 PaddleOCR 模型 ID
|
|
125
|
+
* @param maxSideLen 可选检测阶段最大边长
|
|
126
|
+
* @param useGpu loadModel 时是否启用 GPU
|
|
116
127
|
* @returns 返回可交给 runScript 的 JavaScript 脚本
|
|
117
128
|
* @example
|
|
118
|
-
* buildPaddleOcrScript("recognize", "screen", 0, 0, 0, 0)
|
|
129
|
+
* buildPaddleOcrScript("recognize", "screen", 0, 0, 0, 0, undefined, 0.6, false)
|
|
119
130
|
*/
|
|
120
|
-
function buildPaddleOcrScript(mode, input, x, y, ex, ey, texts, confidenceThreshold, exactMatch) {
|
|
131
|
+
function buildPaddleOcrScript(mode, input, x, y, ex, ey, texts, confidenceThreshold, exactMatch, paddleModel, maxSideLen, useGpu) {
|
|
121
132
|
if (mode === "numbers") {
|
|
122
133
|
throw new Error("PaddleOCR 文档未提供 numbers 模式,请使用 appleocr 引擎。");
|
|
123
134
|
}
|
|
135
|
+
// 先设置检测长边,再切换模型;loadModel 会沿用当前长边加载目标模型。
|
|
136
|
+
const setup = [];
|
|
137
|
+
if (maxSideLen !== undefined) {
|
|
138
|
+
setup.push(`paddleOcr.setMaxSideLen(${maxSideLen});`);
|
|
139
|
+
}
|
|
140
|
+
if (paddleModel) {
|
|
141
|
+
setup.push(`paddleOcr.loadModel(${jsonLiteral(paddleModel)}, ${useGpu ?? false});`);
|
|
142
|
+
}
|
|
143
|
+
let call;
|
|
124
144
|
if (mode === "findText") {
|
|
125
145
|
if (!texts || texts.length === 0) {
|
|
126
146
|
throw new Error("findText 模式必须传 texts。");
|
|
127
147
|
}
|
|
128
|
-
|
|
148
|
+
call = `paddleOcr.findTextAbs(${jsonLiteral(input)}, ${jsonLiteral(texts)}, ${x}, ${y}, ${ex}, ${ey}, ${confidenceThreshold}, ${exactMatch});`;
|
|
129
149
|
}
|
|
130
|
-
|
|
150
|
+
else {
|
|
151
|
+
call = `paddleOcr.recognizeAbs(${jsonLiteral(input)}, ${x}, ${y}, ${ex}, ${ey}, ${confidenceThreshold});`;
|
|
152
|
+
}
|
|
153
|
+
return [...setup, call].join("\n");
|
|
131
154
|
}
|
|
132
155
|
/**
|
|
133
156
|
* 构建 OCR 运行脚本
|
|
@@ -142,13 +165,21 @@ function buildPaddleOcrScript(mode, input, x, y, ex, ey, texts, confidenceThresh
|
|
|
142
165
|
* @param languages Apple OCR 识别语言数组
|
|
143
166
|
* @param confidenceThreshold PaddleOCR 置信度阈值
|
|
144
167
|
* @param exactMatch 是否完整匹配文本
|
|
168
|
+
* @param paddleModel 可选切换的 PaddleOCR 模型 ID
|
|
169
|
+
* @param maxSideLen 可选 PaddleOCR 检测阶段最大边长
|
|
170
|
+
* @param useGpu PaddleOCR loadModel 时是否启用 GPU
|
|
145
171
|
* @returns 返回可交给 runScript 的 JavaScript 脚本
|
|
146
172
|
* @example
|
|
147
173
|
* buildOcrScript("appleocr", "recognize", "screen", 0, 0, 0, 0)
|
|
148
174
|
*/
|
|
149
|
-
function buildOcrScript(engine, mode, input, x, y, ex, ey, texts, languages, confidenceThreshold, exactMatch) {
|
|
175
|
+
function buildOcrScript(engine, mode, input, x, y, ex, ey, texts, languages, confidenceThreshold, exactMatch, paddleModel, maxSideLen, useGpu) {
|
|
150
176
|
if (engine === "paddleocr") {
|
|
151
|
-
return buildPaddleOcrScript(mode, input, x, y, ex, ey, texts, confidenceThreshold, exactMatch);
|
|
177
|
+
return buildPaddleOcrScript(mode, input, x, y, ex, ey, texts, confidenceThreshold, exactMatch, paddleModel, maxSideLen, useGpu);
|
|
178
|
+
}
|
|
179
|
+
if (paddleModel !== undefined ||
|
|
180
|
+
maxSideLen !== undefined ||
|
|
181
|
+
useGpu !== undefined) {
|
|
182
|
+
throw new Error("paddleModel / maxSideLen / useGpu 仅适用于 paddleocr 引擎。");
|
|
152
183
|
}
|
|
153
184
|
return buildAppleOcrScript(mode, input, x, y, ex, ey, texts, languages, exactMatch);
|
|
154
185
|
}
|
|
@@ -241,7 +272,7 @@ async function formatOcrToolText(response, outputPath) {
|
|
|
241
272
|
* await runOcrRecognitionOnDevice({ ip: "192.168.1.10", port: "9800" }, options)
|
|
242
273
|
*/
|
|
243
274
|
async function runOcrRecognitionOnDevice(target, options) {
|
|
244
|
-
const script = buildOcrScript(options.engine, options.mode, options.input, options.x, options.y, options.ex, options.ey, options.texts, options.languages, options.confidenceThreshold, options.exactMatch);
|
|
275
|
+
const script = buildOcrScript(options.engine, options.mode, options.input, options.x, options.y, options.ex, options.ey, options.texts, options.languages, options.confidenceThreshold, options.exactMatch, options.paddleModel, options.maxSideLen, options.useGpu);
|
|
245
276
|
const response = await callRunScript(target.ip, target.port, script, options.timeoutMs);
|
|
246
277
|
const text = await formatOcrToolText(response.body, options.outputPath);
|
|
247
278
|
return {
|
|
@@ -314,6 +345,20 @@ function registerOcrTools(server) {
|
|
|
314
345
|
.optional()
|
|
315
346
|
.default(0.6)
|
|
316
347
|
.describe("PaddleOCR 置信度阈值,默认 0.6"),
|
|
348
|
+
paddleModel: z
|
|
349
|
+
.enum(exports.PADDLE_OCR_MODELS)
|
|
350
|
+
.optional()
|
|
351
|
+
.describe("仅 paddleocr:切换内置模型,识别前执行 loadModel;不传则使用当前 active 模型,未加载时自动加载 ppocr-v6-small"),
|
|
352
|
+
maxSideLen: z
|
|
353
|
+
.number()
|
|
354
|
+
.int()
|
|
355
|
+
.min(0)
|
|
356
|
+
.optional()
|
|
357
|
+
.describe(`仅 paddleocr:检测阶段最大边长,识别前执行 setMaxSideLen;不传保持运行时当前值,0 回落到默认 ${exports.PADDLE_OCR_DEFAULT_MAX_SIDE_LEN}`),
|
|
358
|
+
useGpu: z
|
|
359
|
+
.boolean()
|
|
360
|
+
.optional()
|
|
361
|
+
.describe("仅 paddleocr:配合 paddleModel 切换模型时是否启用 GPU,默认 false"),
|
|
317
362
|
outputPath: z
|
|
318
363
|
.string()
|
|
319
364
|
.min(1)
|
|
@@ -328,7 +373,7 @@ function registerOcrTools(server) {
|
|
|
328
373
|
.default(60000)
|
|
329
374
|
.describe("runScript 请求超时时间,默认 60000 毫秒"),
|
|
330
375
|
},
|
|
331
|
-
}, async ({ engine, mode, input, x, y, ex, ey, texts, languages, exactMatch, confidenceThreshold, outputPath, timeoutMs, }) => {
|
|
376
|
+
}, async ({ engine, mode, input, x, y, ex, ey, texts, languages, exactMatch, confidenceThreshold, paddleModel, maxSideLen, useGpu, outputPath, timeoutMs, }) => {
|
|
332
377
|
const target = await (0, tool_utils_1.resolveRuntimeHttpTarget)();
|
|
333
378
|
const response = await runOcrRecognitionOnDevice(target, {
|
|
334
379
|
engine,
|
|
@@ -342,6 +387,9 @@ function registerOcrTools(server) {
|
|
|
342
387
|
languages,
|
|
343
388
|
confidenceThreshold,
|
|
344
389
|
exactMatch,
|
|
390
|
+
paddleModel,
|
|
391
|
+
maxSideLen,
|
|
392
|
+
useGpu,
|
|
345
393
|
outputPath,
|
|
346
394
|
timeoutMs,
|
|
347
395
|
});
|
|
@@ -353,6 +401,12 @@ function registerOcrTools(server) {
|
|
|
353
401
|
`mode: ${mode}`,
|
|
354
402
|
`input: ${input}`,
|
|
355
403
|
`region: x=${x}, y=${y}, ex=${ex}, ey=${ey}`,
|
|
404
|
+
...(engine === "paddleocr" && paddleModel
|
|
405
|
+
? [`paddleModel: ${paddleModel}`]
|
|
406
|
+
: []),
|
|
407
|
+
...(engine === "paddleocr" && maxSideLen !== undefined
|
|
408
|
+
? [`maxSideLen: ${maxSideLen}`]
|
|
409
|
+
: []),
|
|
356
410
|
`status: ${response.status}`,
|
|
357
411
|
].join("\n"), response.body.success === false);
|
|
358
412
|
});
|
package/docs/AGENTS.md
CHANGED
|
@@ -165,6 +165,7 @@ OCR 识别使用 `ocr_recognize`,不要手写未确认的 OCR 调用链路。
|
|
|
165
165
|
- 默认使用 `appleocr`。
|
|
166
166
|
- 数字识别优先使用 `appleocr`。
|
|
167
167
|
- PaddleOCR 同一时间只保留一个 active 模型;识别和查找方法默认自动加载 PP-OCRv6 small,如需 PP-OCRv6 tiny 调用 `loadModel("ppocr-v6-tiny")`,如需 PP-OCRv5 调用 `loadModel("ppocr-v5")`,加载成功后会替换当前模型。
|
|
168
|
+
- 切换模型与调整检测长边时,优先使用 `ocr_recognize` 的 `paddleModel`、`maxSideLen`(CLI 为 `--paddle-model`、`--max-side-len`)参数,工具会在识别前自动执行 `setMaxSideLen` 和 `loadModel`,无需手写 runScript 链路;`maxSideLen` 默认 768,传 0 回落默认值;`useGpu`/`--use-gpu` 仅在切换模型时生效。这些参数仅适用于 `paddleocr`,与 `appleocr` 同传会报错。
|
|
168
169
|
|
|
169
170
|
## 验证要求
|
|
170
171
|
|
package/docs/SKILL.md
CHANGED
|
@@ -189,7 +189,7 @@ CLI 入口:
|
|
|
189
189
|
|
|
190
190
|
控制、HID、IME、镜像、配置、当前应用、运行脚本等普通设备 HTTP API 通过 `get_docs_paths` 和 `http_api_call` 使用;CLI 入口使用 `ms docs paths` 和 `ms http-call`。
|
|
191
191
|
|
|
192
|
-
使用 `ocr_recognize` 执行 OCR 识别。`ocr_recognize` 支持 `appleocr` 和 `paddleocr`,默认 `appleocr
|
|
192
|
+
使用 `ocr_recognize` 执行 OCR 识别。`ocr_recognize` 支持 `appleocr` 和 `paddleocr`,默认 `appleocr`,识别结果坐标可直接用于点击。使用 `paddleocr` 时可传 `paddleModel`(`ppocr-v6-tiny`/`ppocr-v6-small`/`ppocr-v5`)切换模型,传 `maxSideLen` 调整检测最大边长(默认 768),传 `useGpu` 切换 GPU;工具会在识别前自动执行 `setMaxSideLen` 和 `loadModel`,这些参数仅对 `paddleocr` 生效。
|
|
193
193
|
|
|
194
194
|
图片与识别工作流:
|
|
195
195
|
|
package/docs/api/config.md
CHANGED
|
@@ -12,57 +12,53 @@
|
|
|
12
12
|
|
|
13
13
|
## API 参考
|
|
14
14
|
|
|
15
|
-
###
|
|
16
|
-
|
|
17
|
-
#### get - 读取配置项的值。
|
|
15
|
+
### all - 获取所有配置的 JSON 格式数据。
|
|
18
16
|
|
|
19
17
|
```typescript
|
|
20
|
-
function
|
|
18
|
+
function all(): Record<string, any>;
|
|
21
19
|
```
|
|
22
20
|
|
|
23
|
-
**参数:**
|
|
24
|
-
|
|
25
|
-
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
26
|
-
| ------ | ------ | -------- | ------ | -------- |
|
|
27
|
-
| `key` | string | 是 | - | 配置键名 |
|
|
28
|
-
|
|
29
21
|
**返回值:**
|
|
30
22
|
|
|
31
|
-
| 类型
|
|
32
|
-
|
|
|
33
|
-
| `any
|
|
23
|
+
| 类型 | 描述 |
|
|
24
|
+
| --------------------- | ------------------ |
|
|
25
|
+
| `Record<string, any>` | 包含所有配置的对象 |
|
|
34
26
|
|
|
35
27
|
**示例:**
|
|
36
28
|
|
|
37
29
|
```javascript
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
logi(`最大重试次数: ${maxRetries}`);
|
|
41
|
-
}
|
|
30
|
+
const allConfigs = config.all();
|
|
31
|
+
logi(`所有配置: ${JSON.stringify(allConfigs, null, 2)}`);
|
|
42
32
|
```
|
|
43
33
|
|
|
44
|
-
###
|
|
45
|
-
|
|
46
|
-
#### all - 获取所有配置的 JSON 格式数据。
|
|
34
|
+
### setAll - 设置所有配置项。
|
|
47
35
|
|
|
48
36
|
```typescript
|
|
49
|
-
function
|
|
37
|
+
function setAll(config: Record<string, any>): boolean;
|
|
50
38
|
```
|
|
51
39
|
|
|
40
|
+
**参数:**
|
|
41
|
+
|
|
42
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
43
|
+
| -------- | --------------------- | -------- | ------ | ---------------- |
|
|
44
|
+
| `config` | `Record<string, any>` | 是 | - | 完整配置对象 |
|
|
45
|
+
|
|
52
46
|
**返回值:**
|
|
53
47
|
|
|
54
|
-
| 类型
|
|
55
|
-
|
|
|
56
|
-
| `
|
|
48
|
+
| 类型 | 描述 |
|
|
49
|
+
| --------- | ------------ |
|
|
50
|
+
| `boolean` | 设置是否成功 |
|
|
57
51
|
|
|
58
52
|
**示例:**
|
|
59
53
|
|
|
60
54
|
```javascript
|
|
61
|
-
const
|
|
62
|
-
|
|
55
|
+
const success = config.setAll({ maxRetries: 5, debugEnabled: true });
|
|
56
|
+
if (success) {
|
|
57
|
+
logi("所有配置已更新");
|
|
58
|
+
}
|
|
63
59
|
```
|
|
64
60
|
|
|
65
|
-
|
|
61
|
+
### set - 更新或设置配置项的值。
|
|
66
62
|
|
|
67
63
|
```typescript
|
|
68
64
|
function set(key: string, value: any): boolean;
|
|
@@ -94,7 +90,53 @@ if (success1 && success2 && success3) {
|
|
|
94
90
|
}
|
|
95
91
|
```
|
|
96
92
|
|
|
97
|
-
|
|
93
|
+
### get - 读取配置项的值。
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
function get(key: string): any | null;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**参数:**
|
|
100
|
+
|
|
101
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
102
|
+
| ------ | ------ | -------- | ------ | -------- |
|
|
103
|
+
| `key` | string | 是 | - | 配置键名 |
|
|
104
|
+
|
|
105
|
+
**返回值:**
|
|
106
|
+
|
|
107
|
+
| 类型 | 描述 |
|
|
108
|
+
| ------------- | ------ |
|
|
109
|
+
| `any \| null` | 配置值 |
|
|
110
|
+
|
|
111
|
+
**示例:**
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
const maxRetries = config.get("maxRetries");
|
|
115
|
+
if (maxRetries !== null) {
|
|
116
|
+
logi(`最大重试次数: ${maxRetries}`);
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### getKuiConfig - 获取 KUI 的配置。
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
function getKuiConfig(): Record<string, any>;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**返回值:**
|
|
127
|
+
|
|
128
|
+
| 类型 | 描述 |
|
|
129
|
+
| --------------------- | -------------------------------------------------------- |
|
|
130
|
+
| `Record<string, any>` | `KUI_CONFIG` 对应的对象,配置不存在或无法转换时返回空对象 |
|
|
131
|
+
|
|
132
|
+
**示例:**
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const kuiConfig = config.getKuiConfig();
|
|
136
|
+
logi(`KUI 配置: ${JSON.stringify(kuiConfig, null, 2)}`);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### remove - 删除指定的配置项。
|
|
98
140
|
|
|
99
141
|
```typescript
|
|
100
142
|
function remove(key: string): boolean;
|
package/docs/apicn/config.md
CHANGED
|
@@ -12,55 +12,53 @@
|
|
|
12
12
|
|
|
13
13
|
## API 参考
|
|
14
14
|
|
|
15
|
-
###
|
|
16
|
-
|
|
17
|
-
#### 获取
|
|
15
|
+
### 所有配置
|
|
18
16
|
|
|
19
17
|
```typescript
|
|
20
|
-
function
|
|
18
|
+
function 所有配置(): 字典<任意类型>;
|
|
21
19
|
```
|
|
22
20
|
|
|
23
|
-
**参数:**
|
|
24
|
-
|
|
25
|
-
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
26
|
-
| -------- | ------ | -------- | ------ | -------- |
|
|
27
|
-
| `配置键` | 字符串 | 是 | - | 配置键名 |
|
|
28
|
-
|
|
29
21
|
**返回值:**
|
|
30
22
|
|
|
31
|
-
| 类型
|
|
32
|
-
|
|
|
33
|
-
|
|
|
23
|
+
| 类型 | 描述 |
|
|
24
|
+
| ---------------- | ------------------ |
|
|
25
|
+
| `字典<任意类型>` | 包含所有配置的对象 |
|
|
34
26
|
|
|
35
27
|
**示例:**
|
|
36
28
|
|
|
37
29
|
```javascript
|
|
38
|
-
const
|
|
39
|
-
$打印信息日志(
|
|
30
|
+
const allConfigs = $配置.所有配置();
|
|
31
|
+
$打印信息日志(`所有配置: ${JSON.stringify(allConfigs, null, 2)}`);
|
|
40
32
|
```
|
|
41
33
|
|
|
42
|
-
###
|
|
43
|
-
|
|
44
|
-
#### 所有配置
|
|
34
|
+
### 设置所有
|
|
45
35
|
|
|
46
36
|
```typescript
|
|
47
|
-
function
|
|
37
|
+
function 设置所有(config: 字典<任意类型>): 布尔值;
|
|
48
38
|
```
|
|
49
39
|
|
|
40
|
+
**参数:**
|
|
41
|
+
|
|
42
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
43
|
+
| -------- | ---------------- | -------- | ------ | ------------ |
|
|
44
|
+
| `config` | 字典<任意类型> | 是 | - | 完整配置对象 |
|
|
45
|
+
|
|
50
46
|
**返回值:**
|
|
51
47
|
|
|
52
|
-
| 类型
|
|
53
|
-
|
|
|
54
|
-
|
|
|
48
|
+
| 类型 | 描述 |
|
|
49
|
+
| -------- | ------------ |
|
|
50
|
+
| `布尔值` | 设置是否成功 |
|
|
55
51
|
|
|
56
52
|
**示例:**
|
|
57
53
|
|
|
58
54
|
```javascript
|
|
59
|
-
const
|
|
60
|
-
|
|
55
|
+
const 是否设置成功 = $配置.设置所有({ maxRetries: 5, debugEnabled: true });
|
|
56
|
+
if (是否设置成功) {
|
|
57
|
+
$打印信息日志("所有配置已更新");
|
|
58
|
+
}
|
|
61
59
|
```
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
### 设置
|
|
64
62
|
|
|
65
63
|
```typescript
|
|
66
64
|
function 设置(配置键: 字符串, 配置值: 任意类型): 布尔值;
|
|
@@ -92,7 +90,51 @@ if (是否更新成功1 && 是否更新成功2 && 是否更新成功3) {
|
|
|
92
90
|
}
|
|
93
91
|
```
|
|
94
92
|
|
|
95
|
-
|
|
93
|
+
### 获取
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
function 获取(配置键: 字符串): 任意类型 | null;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**参数:**
|
|
100
|
+
|
|
101
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
102
|
+
| -------- | ------ | -------- | ------ | -------- |
|
|
103
|
+
| `配置键` | 字符串 | 是 | - | 配置键名 |
|
|
104
|
+
|
|
105
|
+
**返回值:**
|
|
106
|
+
|
|
107
|
+
| 类型 | 描述 |
|
|
108
|
+
| ------------------ | ------ |
|
|
109
|
+
| `任意类型 \| null` | 配置值 |
|
|
110
|
+
|
|
111
|
+
**示例:**
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
const maxRetries = $配置.获取("maxRetries");
|
|
115
|
+
$打印信息日志(`最大重试次数: ${maxRetries}`);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 获取KUI配置 - 获取 KUI 的配置。
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
function 获取KUI配置(): 字典<任意类型>;
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**返回值:**
|
|
125
|
+
|
|
126
|
+
| 类型 | 描述 |
|
|
127
|
+
| ---------------- | -------------------------------------------------------- |
|
|
128
|
+
| `字典<任意类型>` | `KUI_CONFIG` 对应的对象,配置不存在或无法转换时返回空对象 |
|
|
129
|
+
|
|
130
|
+
**示例:**
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
const kuiConfig = $配置.获取KUI配置();
|
|
134
|
+
$打印信息日志(`KUI 配置: ${JSON.stringify(kuiConfig, null, 2)}`);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 删除
|
|
96
138
|
|
|
97
139
|
```typescript
|
|
98
140
|
function 删除(配置键: 字符串): 布尔值;
|
package/docs/apipython/config.md
CHANGED
|
@@ -12,61 +12,57 @@
|
|
|
12
12
|
|
|
13
13
|
## API 参考
|
|
14
14
|
|
|
15
|
-
###
|
|
16
|
-
|
|
17
|
-
#### get - 读取配置项的值。
|
|
15
|
+
### all - 获取所有配置的 JSON 格式数据。
|
|
18
16
|
|
|
19
17
|
```python
|
|
20
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Dict
|
|
21
19
|
|
|
22
|
-
def
|
|
20
|
+
def all() -> Dict[str, Any]:
|
|
23
21
|
```
|
|
24
22
|
|
|
25
|
-
**参数:**
|
|
26
|
-
|
|
27
|
-
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
28
|
-
| ------ | ------ | -------- | ------ | -------- |
|
|
29
|
-
| `key` | string | 是 | - | 配置键名 |
|
|
30
|
-
|
|
31
23
|
**返回值:**
|
|
32
24
|
|
|
33
|
-
| 类型
|
|
34
|
-
|
|
|
35
|
-
| `Any
|
|
25
|
+
| 类型 | 描述 |
|
|
26
|
+
| ---------------- | ------------------ |
|
|
27
|
+
| `Dict[str, Any]` | 包含所有配置的对象 |
|
|
36
28
|
|
|
37
29
|
**示例:**
|
|
38
30
|
|
|
39
31
|
```python
|
|
40
32
|
from kuaijs import config
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
import json
|
|
34
|
+
allConfigs = config.all()
|
|
35
|
+
print(f"所有配置: {json.dumps(allConfigs, indent=2)}")
|
|
44
36
|
```
|
|
45
37
|
|
|
46
|
-
###
|
|
47
|
-
|
|
48
|
-
#### all - 获取所有配置的 JSON 格式数据。
|
|
38
|
+
### setAll - 设置所有配置项。
|
|
49
39
|
|
|
50
40
|
```python
|
|
51
|
-
def
|
|
41
|
+
def setAll(config: Dict[str, Any]) -> bool:
|
|
52
42
|
```
|
|
53
43
|
|
|
44
|
+
**参数:**
|
|
45
|
+
|
|
46
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
47
|
+
| -------- | ---------------- | -------- | ------ | ------------ |
|
|
48
|
+
| `config` | `Dict[str, Any]` | 是 | - | 完整配置字典 |
|
|
49
|
+
|
|
54
50
|
**返回值:**
|
|
55
51
|
|
|
56
|
-
| 类型
|
|
57
|
-
|
|
|
58
|
-
| `
|
|
52
|
+
| 类型 | 描述 |
|
|
53
|
+
| ------ | ------------ |
|
|
54
|
+
| `bool` | 设置是否成功 |
|
|
59
55
|
|
|
60
56
|
**示例:**
|
|
61
57
|
|
|
62
58
|
```python
|
|
63
59
|
from kuaijs import config
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
print(
|
|
60
|
+
success = config.setAll({"maxRetries": 5, "debugEnabled": True})
|
|
61
|
+
if success:
|
|
62
|
+
print("所有配置已更新")
|
|
67
63
|
```
|
|
68
64
|
|
|
69
|
-
|
|
65
|
+
### set - 更新或设置配置项的值。
|
|
70
66
|
|
|
71
67
|
```python
|
|
72
68
|
def set(key: str, value: Any) -> bool:
|
|
@@ -98,7 +94,54 @@ if success1 and success2 and success3:
|
|
|
98
94
|
print("配置更新成功")
|
|
99
95
|
```
|
|
100
96
|
|
|
101
|
-
|
|
97
|
+
### get - 读取配置项的值。
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
def get(key: str) -> Any | None:
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**参数:**
|
|
104
|
+
|
|
105
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
106
|
+
| ------ | ------ | -------- | ------ | -------- |
|
|
107
|
+
| `key` | string | 是 | - | 配置键名 |
|
|
108
|
+
|
|
109
|
+
**返回值:**
|
|
110
|
+
|
|
111
|
+
| 类型 | 描述 |
|
|
112
|
+
| ------------- | ------ |
|
|
113
|
+
| `Any \| None` | 配置值 |
|
|
114
|
+
|
|
115
|
+
**示例:**
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from kuaijs import config
|
|
119
|
+
maxRetries = config.get("maxRetries")
|
|
120
|
+
if maxRetries:
|
|
121
|
+
print(f"最大重试次数: {maxRetries}")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### getKuiConfig - 获取 KUI 的配置。
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
def getKuiConfig() -> Dict[str, Any]:
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**返回值:**
|
|
131
|
+
|
|
132
|
+
| 类型 | 描述 |
|
|
133
|
+
| ---------------- | -------------------------------------------------------- |
|
|
134
|
+
| `Dict[str, Any]` | `KUI_CONFIG` 对应的字典,配置不存在或无法转换时返回空字典 |
|
|
135
|
+
|
|
136
|
+
**示例:**
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from kuaijs import config
|
|
140
|
+
kui_config = config.getKuiConfig()
|
|
141
|
+
print(f"KUI 配置: {kui_config}")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### remove - 删除指定的配置项。
|
|
102
145
|
|
|
103
146
|
```python
|
|
104
147
|
def remove(key: str) -> bool:
|
|
@@ -178,6 +178,7 @@ UI 预览发起后不需要长时间等待结果,可以通过 `take_screenshot
|
|
|
178
178
|
- 从当前设备截图指定坐标取色:使用 `screen_pick_color` 或 `npx ms screen-pick-color`。
|
|
179
179
|
- 执行 OCR 识别、数字识别或查找文字:使用 `ocr_recognize` 或 `npx ms ocr`。
|
|
180
180
|
- OCR 识别支持 `appleocr` 和 `paddleocr`,默认 `appleocr`,PaddleOCR 同一时间只保留一个 active 模型,识别方法默认自动加载 PP-OCRv6 small;如需 PP-OCRv6 tiny 请调用 `loadModel("ppocr-v6-tiny")`,如需 PP-OCRv5 请调用 `loadModel("ppocr-v5")`,加载成功后会替换当前模型。
|
|
181
|
+
- 切换模型或调整检测长边时,直接给 `ocr_recognize` 传 `paddleModel`、`maxSideLen`(CLI 为 `--paddle-model`、`--max-side-len`,GPU 用 `--use-gpu`),工具会在识别前自动执行 `setMaxSideLen` 和 `loadModel`;这些参数仅适用于 `paddleocr`。
|
|
181
182
|
- 制作透明找图模板:使用 `image_make_transparent` 或 `npx ms image-transparent`,输出到 `res`。
|
|
182
183
|
- 获取节点 XML:使用 `get_node_source` 或 `npx ms source --mode 1`。
|
|
183
184
|
- 查看日志:使用 `get_logs` 或 `npx ms logs`。
|