ms-vite-plugin 1.4.9 → 1.4.11

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.
@@ -101,6 +101,111 @@ if g.getAgentFastMode():
101
101
  print("Agent 快速模式已开启")
102
102
  ```
103
103
 
104
+ #### `setCpuAutoThrottle` - 设置脚本 CPU 自动限流
105
+
106
+ 默认开启。开启后,脚本 API 在 CPU 占用接近系统杀进程阈值时会轻微让步,降低被系统终止的风险。
107
+
108
+ ```python
109
+ def setCpuAutoThrottle(enabled: bool) -> bool
110
+ ```
111
+
112
+ **参数:**
113
+
114
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
115
+ | --------- | ------ | -------- | ------ | ---------------- |
116
+ | `enabled` | `bool` | 是 | - | 是否开启自动限流 |
117
+
118
+ **返回值:**
119
+
120
+ | 类型 | 描述 |
121
+ | ------ | -------------------- |
122
+ | `bool` | 实际是否开启自动限流 |
123
+
124
+ **示例:**
125
+
126
+ ```python
127
+ from kuaijs import g
128
+
129
+ enabled = g.setCpuAutoThrottle(True)
130
+ print(f"CPU 自动限流: {enabled}")
131
+ ```
132
+
133
+ #### `getCpuAutoThrottle` - 获取脚本 CPU 自动限流
134
+
135
+ 默认开启。
136
+
137
+ ```python
138
+ def getCpuAutoThrottle() -> bool
139
+ ```
140
+
141
+ **返回值:**
142
+
143
+ | 类型 | 描述 |
144
+ | ------ | -------------------- |
145
+ | `bool` | 当前是否开启自动限流 |
146
+
147
+ **示例:**
148
+
149
+ ```python
150
+ from kuaijs import g
151
+
152
+ if g.getCpuAutoThrottle():
153
+ print("CPU 自动限流已开启")
154
+ ```
155
+
156
+ #### `setCpuThrottleDelay` - 设置 CPU 限流延迟
157
+
158
+ 设置 CPU 限流单次 sleep 延迟范围(毫秒)。默认 `min_ms=3`、`max_ms=30`。仅在 CPU 自动限流开启且触发限流时生效。
159
+
160
+ ```python
161
+ def setCpuThrottleDelay(min_ms: int, max_ms: int) -> dict
162
+ ```
163
+
164
+ **参数:**
165
+
166
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
167
+ | --------- | ----- | -------- | ------ | ---------------------------------- |
168
+ | `min_ms` | `int` | 是 | - | 最低延迟(毫秒) |
169
+ | `max_ms` | `int` | 是 | - | 最高延迟(毫秒);小于 min_ms 时自动对齐 |
170
+
171
+ **返回值:**
172
+
173
+ | 类型 | 描述 |
174
+ | ------ | ------------------ |
175
+ | `dict` | `{"minMs": int, "maxMs": int}`,实际生效的延迟范围 |
176
+
177
+ **示例:**
178
+
179
+ ```python
180
+ from kuaijs import g
181
+
182
+ delay = g.setCpuThrottleDelay(3, 30)
183
+ print(f"CPU 限流延迟: {delay['minMs']}~{delay['maxMs']}ms")
184
+ ```
185
+
186
+ #### `getCpuThrottleDelay` - 获取 CPU 限流延迟
187
+
188
+ 获取 CPU 限流延迟范围(毫秒)。
189
+
190
+ ```python
191
+ def getCpuThrottleDelay() -> dict
192
+ ```
193
+
194
+ **返回值:**
195
+
196
+ | 类型 | 描述 |
197
+ | ------ | ------------------ |
198
+ | `dict` | `{"minMs": int, "maxMs": int}`,当前最低与最高延迟 |
199
+
200
+ **示例:**
201
+
202
+ ```python
203
+ from kuaijs import g
204
+
205
+ delay = g.getCpuThrottleDelay()
206
+ print(f"CPU 限流延迟: {delay['minMs']}~{delay['maxMs']}ms")
207
+ ```
208
+
104
209
  #### `restartScript` - 重启脚本
105
210
 
106
211
  ```python
@@ -36,32 +36,6 @@ else:
36
36
  # 可能需要重新初始化或检查权限
37
37
  ```
38
38
 
39
- ### autoSwitchApiKeyboard - 自动切换到 API 键盘
40
-
41
- ```python
42
- def autoSwitchApiKeyboard() -> bool
43
- ```
44
-
45
- **返回值:**
46
-
47
- | 类型 | 描述 |
48
- | ------ | ------------------------------------------ |
49
- | `bool` | 是否成功切换并连接到 API 键盘,成功为 True |
50
-
51
- - 该方法仅在系统设置中添加了快点JS API键盘 并且已授权完全访问权限时有效。
52
-
53
- **示例:**
54
-
55
- ```python
56
- from kuaijs import ime
57
-
58
- # 自动切换到 API 键盘(如未弹出会尝试切换)
59
- if ime.autoSwitchApiKeyboard():
60
- print("已切换到 API 键盘")
61
- else:
62
- print("切换失败,请检查键盘设置和完全访问权限")
63
- ```
64
-
65
39
  ## 文本获取和清除
66
40
 
67
41
  ### getText - 获取当前输入框的文本内容
@@ -46,6 +46,7 @@ class NodeInfo:
46
46
 
47
47
  class NodeSelectorOptions(TypedDict, total=False):
48
48
  maxDepth: int # 最大层级深度,默认 50
49
+ mode: int # 抓取模式:模式 1、模式 2,默认模式 1
49
50
  ```
50
51
 
51
52
  ## 节点选择器 (NodeSelector)
@@ -67,6 +68,7 @@ def createNodeSelector(params: Optional[NodeSelectorOptions] = None) -> NodeSele
67
68
  | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
68
69
  | ---------- | ---- | -------- | ------ | --------------------- |
69
70
  | `maxDepth` | int | 否 | 50 | 最大层级深度,默认 50 |
71
+ | `mode` | int | 否 | 1 | 抓取模式。模式 1、模式 2,默认模式 1 |
70
72
 
71
73
  **返回值:** `NodeSelector`
72
74
 
@@ -77,7 +79,8 @@ from kuaijs import node
77
79
 
78
80
  # 创建选择器
79
81
  selector = node.createNodeSelector({
80
- "maxDepth": 20 # 最大20层深度
82
+ "maxDepth": 20, # 最大20层深度
83
+ "mode": 1 # 默认模式 1
81
84
  })
82
85
  ```
83
86
 
@@ -5,7 +5,7 @@
5
5
  - 导入方式:
6
6
 
7
7
  ```python
8
- from kuaijs import action, hid, image, appleocr, paddleocr, yolo, system, device, file, mysql, netcard, ime, media, hotupdate, tomatoocr, tts, ui, utils, node, pip, logger
8
+ from kuaijs import action, hid, image, appleocr, paddleocr, yolo, yolocls, system, device, file, mysql, netcard, ime, media, hotupdate, tomatoocr, tts, ui, utils, node, pip, logger
9
9
  ```
10
10
 
11
11
  ## 下载资源
@@ -43,7 +43,7 @@ class OCRResult(TypedDict):
43
43
  初始化 PP-OCRv5 模型,这是使用 OCR 功能的前提。
44
44
 
45
45
  ```python
46
- def loadV5(maxSideLen: int = 640) -> bool
46
+ def loadV5(maxSideLen: int = 640, useGpu: bool = False) -> bool
47
47
  ```
48
48
 
49
49
  **参数:**
@@ -51,12 +51,15 @@ def loadV5(maxSideLen: int = 640) -> bool
51
51
  | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
52
52
  | ------------ | ---- | -------- | ------ | -------------------------------- |
53
53
  | `maxSideLen` | int | 否 | 640 | 输入图像的最大边长,默认值为 640 |
54
+ | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
54
55
 
55
56
  **返回值:**
56
57
 
57
- | 类型 | 描述 |
58
- | ------ | ---------------- |
59
- | `bool` | 是否成功加载模型 |
58
+ | 类型 | 描述 |
59
+ | ------ | --------------------------------------------------- |
60
+ | `bool` | 加载成功或模型已加载返回 `True`,否则返回 `False` |
61
+
62
+ 重复调用 `loadV5` 时,如果模型已经加载,会直接返回 `True`,不会重新加载或应用新的参数。需要更换加载参数时,先调用 `free()` 释放模型。
60
63
 
61
64
  **示例:**
62
65
 
@@ -134,6 +137,29 @@ else:
134
137
  print(f"网络图片识别结果数量: {len(url_results)}")
135
138
  ```
136
139
 
140
+ #### `recognizeAbs` - 执行 OCR 识别,并将结果坐标映射为原图/全屏绝对坐标
141
+
142
+ 参数与 `recognize` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
143
+
144
+ ```python
145
+ def recognizeAbs(
146
+ input: str,
147
+ x: int = 0,
148
+ y: int = 0,
149
+ ex: int = 0,
150
+ ey: int = 0,
151
+ confidenceThreshold: float = 0.6
152
+ ) -> List[OCRResult]
153
+ ```
154
+
155
+ **示例:**
156
+
157
+ ```python
158
+ abs_results = paddleocr.recognizeAbs("screen", 100, 100, 500, 300)
159
+ if abs_results:
160
+ print(f"绝对坐标中心点: ({abs_results[0].centerX}, {abs_results[0].centerY})")
161
+ ```
162
+
137
163
  #### `findText` - 在识别结果中查找目标文本并返回对应子串坐标
138
164
 
139
165
  在 OCR 识别结果中查找指定文本,返回匹配文本的坐标和置信度等信息。
@@ -190,6 +216,30 @@ else:
190
216
  print(f"区域命中数量: {len(region_hits)}")
191
217
  ```
192
218
 
219
+ #### `findTextAbs` - 查找目标文本,并将结果坐标映射为原图/全屏绝对坐标
220
+
221
+ 参数与 `findText` 相同。传入裁剪区域时,返回坐标可直接用于全屏点击。
222
+
223
+ ```python
224
+ def findTextAbs(
225
+ input: str,
226
+ targetTexts: List[str],
227
+ x: int = 0,
228
+ y: int = 0,
229
+ ex: int = 0,
230
+ ey: int = 0,
231
+ confidenceThreshold: float = 0.6
232
+ ) -> List[OCRResult]
233
+ ```
234
+
235
+ **示例:**
236
+
237
+ ```python
238
+ abs_hits = paddleocr.findTextAbs("screen", ["确定"], 100, 100, 500, 400, 0.6)
239
+ if abs_hits:
240
+ print(f"绝对坐标中心点: ({abs_hits[0].centerX}, {abs_hits[0].centerY})")
241
+ ```
242
+
193
243
  ### 资源管理
194
244
 
195
245
  #### `free` - 释放 OCR 模型占用的内存资源
@@ -10,6 +10,7 @@
10
10
  - **URL 操作**: 打开网页链接或应用 URL Scheme
11
11
  - **系统通知**: 发送系统通知消息
12
12
  - **内存管理**: 获取内存使用信息
13
+ - **CPU 管理**: 获取 CPU 使用率
13
14
  - **快点 Agent 服务**: 启动 快点 Agent 服务
14
15
 
15
16
  ## 类型定义
@@ -42,10 +43,11 @@ class InstalledAppInfo(TypedDict):
42
43
 
43
44
  ```python
44
45
  class MemoryInfo(TypedDict):
45
- used: int # 已使用内存(MB)
46
- available: int # 可用内存(MB)
47
- total: int # 总内存(MB)
48
- usagePercentage: float # 内存使用率(百分比)
46
+ used: int # 当前应用占用(MB)
47
+ available: int # 系统可用内存(MB)
48
+ total: int # 系统总内存(MB)
49
+ systemUsed: int # 系统已用内存(MB)
50
+ usagePercentage: float # 系统占用率(百分比)
49
51
  ```
50
52
 
51
53
  ## API 参考
@@ -387,25 +389,26 @@ def getMemoryInfo() -> MemoryInfo
387
389
 
388
390
  **返回值:**
389
391
  | 类型 | 描述 |
390
- | ----------------- | ---------------------- |
391
- | `used` | 已使用内存(单位:MB) |
392
- | `available` | 可用内存(单位:MB) |
393
- | `total` | 总内存(单位:MB) |
394
- | `usagePercentage` | 内存使用率(百分比) |
392
+ | ----------------- | ---------------------------- |
393
+ | `used` | 当前应用占用(单位:MB) |
394
+ | `available` | 系统可用内存(单位:MB) |
395
+ | `total` | 系统总内存(单位:MB) |
396
+ | `systemUsed` | 系统已用内存(单位:MB) |
397
+ | `usagePercentage` | 系统内存占用率(百分比) |
395
398
 
396
399
  **说明:**
397
400
 
398
- 该方法返回设备的完整内存使用信息,包括已使用内存、可用内存、总内存和使用率。
401
+ 该方法返回当前应用占用和系统内存概况。`usagePercentage` 表示系统整体占用率。
399
402
 
400
403
  **示例:**
401
404
 
402
405
  ```python
403
406
  from kuaijs import system
404
407
  mem = system.getMemoryInfo()
405
- print(mem.used, mem.available, mem.total, mem.usagePercentage)
408
+ print(f"应用: {mem.used}MB, 系统: {mem.systemUsed}/{mem.total}MB, 占用: {mem.usagePercentage}%")
406
409
 
407
410
  if mem.usagePercentage > 80:
408
- print("内存使用率过高,建议清理内存")
411
+ print("系统内存占用较高")
409
412
  ```
410
413
 
411
414
  #### getUsedMemory - 获取已使用内存。
@@ -465,6 +468,58 @@ usage = (used / total) * 100 if total else 0
465
468
  print(f"使用率: {usage:.1f}%")
466
469
  ```
467
470
 
471
+ #### getSystemUsedMemory - 获取系统已用内存。
472
+
473
+ ```python
474
+ def getSystemUsedMemory() -> int
475
+ ```
476
+
477
+ **返回值:**
478
+ | 类型 | 描述 |
479
+ | ---- | ------------ |
480
+ | `int`| 系统已用内存(MB) |
481
+
482
+ **说明:**
483
+
484
+ 该方法返回系统物理内存的已使用量,计算方式为系统总内存减去可用内存,与 `getMemoryInfo()` 返回的 `systemUsed` 一致。
485
+
486
+ **示例:**
487
+
488
+ ```python
489
+ from kuaijs import system
490
+
491
+ system_used = system.getSystemUsedMemory()
492
+ print(f"系统已用内存: {system_used}MB")
493
+
494
+ mem = system.getMemoryInfo()
495
+ print(f"getMemoryInfo systemUsed: {mem['systemUsed']}MB")
496
+ ```
497
+
498
+ ### CPU 管理
499
+
500
+ #### getCpuUsage - 获取 CPU 使用率。
501
+
502
+ ```python
503
+ def getCpuUsage() -> float
504
+ ```
505
+
506
+ **返回值:**
507
+ | 类型 | 描述 |
508
+ | ---- | ---- |
509
+ | `float` | 当前应用 CPU 使用率(百分比) |
510
+
511
+ **示例:**
512
+
513
+ ```python
514
+ from kuaijs import system
515
+
516
+ cpu_usage = system.getCpuUsage()
517
+ print(f"CPU 使用率: {cpu_usage}%")
518
+
519
+ if cpu_usage > 80:
520
+ print("CPU 使用率较高,建议降低脚本负载")
521
+ ```
522
+
468
523
  ### 快点 Agent 服务
469
524
 
470
525
  #### startAgent - 启动 快点 Agent 服务。
@@ -65,7 +65,7 @@ class YoloResult(TypedDict):
65
65
  加载模型是使用目标检测功能的前提。
66
66
 
67
67
  ```python
68
- def load(paramPath: str, binPath: str, nc: int, version: int = 11) -> Optional[str]
68
+ def load(paramPath: str, binPath: str, nc: int = 0, version: int = 11, useGpu: bool = False) -> Optional[str]
69
69
  ```
70
70
 
71
71
  **参数:**
@@ -74,8 +74,9 @@ def load(paramPath: str, binPath: str, nc: int, version: int = 11) -> Optional[s
74
74
  | ----------- | ---- | -------- | ------ | ------------------------------------------- |
75
75
  | `paramPath` | str | 是 | - | NCNN 模型的 param 文件绝对路径 |
76
76
  | `binPath` | str | 是 | - | NCNN 模型的 bin 文件绝对路径 |
77
- | `nc` | int | | - | 模型的标签数量(在标签集 data.yaml 中查看) |
77
+ | `nc` | int | | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空列表 |
78
78
  | `version` | int | 否 | 11 | YOLO 模型版本号(仅支持 8/11/26) |
79
+ | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
79
80
 
80
81
  **返回值:**
81
82
 
@@ -92,8 +93,9 @@ from kuaijs import yolo
92
93
  model_id = yolo.load(
93
94
  "yolov8n_ncnn_model/model.ncnn.param",
94
95
  "yolov8n_ncnn_model/model.ncnn.bin",
95
- 80,
96
+ 0,
96
97
  8,
98
+ False,
97
99
  )
98
100
  ```
99
101
 
@@ -102,7 +104,7 @@ model_id = yolo.load(
102
104
  加载模型是使用目标检测功能的前提。
103
105
 
104
106
  ```python
105
- def loadV11(paramPath: str, binPath: str, nc: int) -> Optional[str]
107
+ def loadV11(paramPath: str, binPath: str, nc: int = 0, useGpu: bool = False) -> Optional[str]
106
108
  ```
107
109
 
108
110
  **参数:**
@@ -111,7 +113,8 @@ def loadV11(paramPath: str, binPath: str, nc: int) -> Optional[str]
111
113
  | ----------- | ---- | -------- | ------ | ------------------------------------------- |
112
114
  | `paramPath` | str | 是 | - | NCNN 模型的 param 文件绝对路径 |
113
115
  | `binPath` | str | 是 | - | NCNN 模型的 bin 文件绝对路径 |
114
- | `nc` | int | | - | 模型的标签数量(在标签集 data.yaml 中查看) |
116
+ | `nc` | int | | 0 | 模型的标签数量;传 `0` 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空列表 |
117
+ | `useGpu` | bool | 否 | False | 是否启用 GPU 加速 |
115
118
 
116
119
  **返回值:**
117
120
 
@@ -129,7 +132,8 @@ from kuaijs import yolo
129
132
  model_id = yolo.loadV11(
130
133
  "yolo11n_ncnn_model/model.ncnn.param",
131
134
  "yolo11n_ncnn_model/model.ncnn.bin",
132
- 80 # COCO 数据集有 80 个类别
135
+ 0, # 自动根据模型输出推断类别数量
136
+ False,
133
137
  )
134
138
 
135
139
  if model_id:
@@ -176,7 +180,7 @@ def detect(
176
180
  from kuaijs import yolo
177
181
 
178
182
  # 首先加载模型
179
- mid = yolo.loadV11("yolo11n_ncnn_model/model.ncnn.param", "yolo11n_ncnn_model/model.ncnn.bin", 80)
183
+ mid = yolo.loadV11("yolo11n_ncnn_model/model.ncnn.param", "yolo11n_ncnn_model/model.ncnn.bin", 0)
180
184
 
181
185
  if not mid:
182
186
  print("模型加载失败")
@@ -227,6 +231,32 @@ else:
227
231
  print(f"网络图片检测结果: {len(url_results)} 个物体")
228
232
  ```
229
233
 
234
+ #### detectAbs - 对指定区域执行目标检测,并将结果坐标映射为原图/全屏绝对坐标
235
+
236
+ ```python
237
+ def detectAbs(
238
+ modelId: str,
239
+ img: str,
240
+ x: int = 0,
241
+ y: int = 0,
242
+ ex: int = 0,
243
+ ey: int = 0,
244
+ targetSize: int = 640,
245
+ threshold: float = 0.4,
246
+ nmsThreshold: float = 0.5
247
+ ) -> List[YoloResult]
248
+ ```
249
+
250
+ **示例:**
251
+
252
+ ```python
253
+ from kuaijs import yolo, action
254
+
255
+ abs_results = yolo.detectAbs(mid, "screen", 100, 100, 500, 400, 640, 0.4, 0.5)
256
+ if abs_results:
257
+ action.click(abs_results[0]["centerX"], abs_results[0]["centerY"])
258
+ ```
259
+
230
260
  ### 资源管理
231
261
 
232
262
  #### free - 释放指定模型