ms-types 0.10.8 → 0.10.9
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/package.json +1 -1
- package/types/lua/action.lua +119 -89
- package/types/lua/ai.lua +34 -16
- package/types/lua/appleocr.lua +35 -22
- package/types/lua/cloud.lua +25 -12
- package/types/lua/config.lua +18 -11
- package/types/lua/cryptoUtils.lua +35 -27
- package/types/lua/cv.lua +173 -25
- package/types/lua/device.lua +38 -20
- package/types/lua/dotocr.lua +8 -2
- package/types/lua/file.lua +61 -40
- package/types/lua/global.lua +56 -20
- package/types/lua/hid.lua +147 -101
- package/types/lua/hotupdate.lua +25 -3
- package/types/lua/http.lua +71 -41
- package/types/lua/image.lua +222 -98
- package/types/lua/ime.lua +37 -13
- package/types/lua/logger.lua +22 -12
- package/types/lua/media.lua +54 -14
- package/types/lua/mysql.lua +61 -12
- package/types/lua/netcard.lua +25 -11
- package/types/lua/node.lua +4 -2
- package/types/lua/paddleocr.lua +35 -21
- package/types/lua/pip.lua +30 -18
- package/types/lua/system.lua +112 -31
- package/types/lua/tomatoocr.lua +73 -26
- package/types/lua/tts.lua +26 -10
- package/types/lua/ui.lua +35 -14
- package/types/lua/utils.lua +27 -17
- package/types/lua/yolo.lua +25 -17
- package/types/lua/yolocls.lua +27 -18
package/package.json
CHANGED
package/types/lua/action.lua
CHANGED
|
@@ -1,128 +1,147 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- 动作模块
|
|
2
3
|
---@class Action
|
|
3
4
|
local _Action = {}
|
|
4
5
|
|
|
5
6
|
--- 设置动作抖动值
|
|
6
|
-
|
|
7
|
+
---@param value integer 抖动值
|
|
8
|
+
---@example action.setJitterValue(5)
|
|
7
9
|
function _Action.setJitterValue(value) end
|
|
8
10
|
|
|
9
11
|
--- 点击
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
---@param x integer 坐标x
|
|
13
|
+
---@param y integer 坐标y
|
|
14
|
+
---@param duration integer|nil 持续时间 默认20ms
|
|
15
|
+
---@param jitter boolean|nil 抖动 开启抖动,会在像素范围随机偏移 点击 默认false
|
|
16
|
+
---@return boolean 点击是否成功
|
|
17
|
+
---@example action.click(100, 100, 20, true)
|
|
15
18
|
function _Action.click(x, y, duration, jitter) return true end
|
|
16
19
|
|
|
17
20
|
--- 随机点击
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
---@param x1 integer 区域左上角x坐标
|
|
22
|
+
---@param y1 integer 区域左上角y坐标
|
|
23
|
+
---@param x2 integer 区域右下角x坐标
|
|
24
|
+
---@param y2 integer 区域右下角y坐标
|
|
25
|
+
---@param duration integer|nil 持续时间 默认20ms
|
|
26
|
+
---@return boolean 随机点击是否成功
|
|
27
|
+
---@example action.clickRandom(100, 100, 200, 200, 20)
|
|
24
28
|
function _Action.clickRandom(x1, y1, x2, y2, duration) return true end
|
|
25
29
|
|
|
26
30
|
--- 双击
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
---@param x integer 坐标x
|
|
32
|
+
---@param y integer 坐标y
|
|
33
|
+
---@param duration integer|nil 持续时间 默认20ms
|
|
34
|
+
---@param interval integer|nil 双击间隔时间 默认20ms
|
|
35
|
+
---@param jitter boolean|nil 抖动 开启抖动,会在像素范围随机偏移 点击 默认false
|
|
36
|
+
---@return boolean 双击是否成功
|
|
37
|
+
---@example action.doubleClick(100, 100, 20, 20, true)
|
|
33
38
|
function _Action.doubleClick(x, y, duration, interval, jitter) return true end
|
|
34
39
|
|
|
35
40
|
--- 随机双击
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
---@param x1 integer 区域左上角x坐标
|
|
42
|
+
---@param y1 integer 区域左上角y坐标
|
|
43
|
+
---@param x2 integer 区域右下角x坐标
|
|
44
|
+
---@param y2 integer 区域右下角y坐标
|
|
45
|
+
---@param duration integer|nil 持续时间 默认20ms
|
|
46
|
+
---@param interval integer|nil 双击间隔时间 默认20ms
|
|
47
|
+
---@return boolean 随机双击是否成功
|
|
48
|
+
---@example action.doubleClickRandom(100, 100, 200, 200, 20, 20)
|
|
43
49
|
function _Action.doubleClickRandom(x1, y1, x2, y2, duration, interval)
|
|
44
50
|
return true
|
|
45
51
|
end
|
|
46
52
|
|
|
47
53
|
--- 直线滑动
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
---@param startX integer 起始坐标x
|
|
55
|
+
---@param startY integer 起始坐标y
|
|
56
|
+
---@param endX integer 结束坐标x
|
|
57
|
+
---@param endY integer 结束坐标y
|
|
58
|
+
---@param duration integer|nil 持续时间 默认 100ms
|
|
59
|
+
---@param jitter boolean|nil 抖动 开启抖动,会在像素范围随机偏移 滑动 默认false
|
|
60
|
+
---@param steps integer|nil 步数 生成抖动点数量 默认6
|
|
61
|
+
---@return boolean 滑动是否成功
|
|
62
|
+
---@example action.swipe(100, 100, 200, 200, 500, true, 10)
|
|
56
63
|
function _Action.swipe(startX, startY, endX, endY, duration, jitter, steps)
|
|
57
64
|
return true
|
|
58
65
|
end
|
|
59
66
|
|
|
60
67
|
--- 长按并滑动
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
---@param startX integer 起始坐标x
|
|
69
|
+
---@param startY integer 起始坐标y
|
|
70
|
+
---@param endX integer 结束坐标x
|
|
71
|
+
---@param endY integer 结束坐标y
|
|
72
|
+
---@param touchDown integer|nil 按下持续时间 默认500ms
|
|
73
|
+
---@param touchMove integer|nil 移动持续时间 默认1000ms
|
|
74
|
+
---@param touchUp integer|nil 松开持续时间 默认500ms
|
|
75
|
+
---@param jitter boolean|nil 抖动 开启抖动,会在像素范围随机偏移 长按滑动 默认false
|
|
76
|
+
---@param steps integer|nil 步数 生成抖动点数量 默认6
|
|
77
|
+
---@return boolean 长按滑动是否成功
|
|
78
|
+
---@example action.pressAndSwipe(100, 100, 200, 200, 500, 500, 500, true, 10)
|
|
71
79
|
function _Action.pressAndSwipe(startX, startY, endX, endY, touchDown, touchMove,
|
|
72
80
|
touchUp, jitter, steps) return true end
|
|
73
81
|
|
|
74
82
|
--- 曲线滑动
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
---@param startX integer 起始x坐标
|
|
84
|
+
---@param startY integer 起始y坐标
|
|
85
|
+
---@param midX integer 中间点x坐标(控制曲线弯曲程度)
|
|
86
|
+
---@param midY integer 中间点y坐标(控制曲线弯曲程度)
|
|
87
|
+
---@param endX integer 目标x坐标
|
|
88
|
+
---@param endY integer 目标y坐标
|
|
89
|
+
---@param duration integer 总持续时间(毫秒),默认1000ms,实际执行时间会有随机变化
|
|
90
|
+
---@return boolean 曲线滑动是否成功
|
|
91
|
+
---@example action.swipeCurve(100, 100, 200, 150, 300, 200, 1000)
|
|
83
92
|
function _Action.swipeCurve(startX, startY, midX, midY, endX, endY, duration)
|
|
84
93
|
return true
|
|
85
94
|
end
|
|
86
95
|
|
|
87
96
|
--- 输入文本
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
---@param text string 文本内容
|
|
98
|
+
---@return boolean 输入文本是否成功
|
|
99
|
+
---@example action.input("123456")
|
|
90
100
|
function _Action.input(text) return true end
|
|
91
101
|
|
|
92
102
|
--- 基础文本输入(不支持中文,走键盘按键)
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
---@param text string 文本内容
|
|
104
|
+
---@return boolean 输入是否成功
|
|
105
|
+
---@example action.inputSimple("hello_123")
|
|
95
106
|
function _Action.inputSimple(text) return true end
|
|
96
107
|
|
|
97
108
|
--- 删除文本
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
---@param count integer|nil 删除数量 默认为1
|
|
110
|
+
---@return boolean 删除文本是否成功
|
|
111
|
+
---@example action.backspace(1)
|
|
100
112
|
function _Action.backspace(count) return true end
|
|
101
113
|
|
|
102
114
|
--- 回车
|
|
103
|
-
|
|
115
|
+
---@return boolean 调用回车是否成功
|
|
116
|
+
---@example action.enter()
|
|
104
117
|
function _Action.enter() return true end
|
|
105
118
|
|
|
106
119
|
--- 回到主页
|
|
107
|
-
|
|
120
|
+
---@return boolean 返回首页是否成功
|
|
121
|
+
---@example action.homeScreen()
|
|
108
122
|
function _Action.homeScreen() return true end
|
|
109
123
|
|
|
110
124
|
--- 按键
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
---@param name string 按钮 home 按下home键 volumeup 按下音量上键 volumedown 按下音量下键 brightnessup 调高屏幕亮度 brightnessdown 调低屏幕亮度
|
|
126
|
+
---@return boolean 按下按钮是否成功
|
|
127
|
+
---@example action.pressButton("home")
|
|
113
128
|
function _Action.pressButton(name) return true end
|
|
114
129
|
|
|
115
130
|
--- 发送键盘组合键(标准 USB HID usage)
|
|
116
|
-
|
|
117
|
-
|
|
131
|
+
---@param keys (string|integer)[] 要发送的按键数组
|
|
132
|
+
---@return boolean 发送是否成功
|
|
133
|
+
---@example action.sendKey({"COMMAND", "c"})
|
|
134
|
+
---@example action.sendKey({0xe3, 0x06})
|
|
135
|
+
---@example action.sendKey({HidKey.COMMAND, "v"})
|
|
118
136
|
function _Action.sendKey(keys) return true end
|
|
119
137
|
|
|
120
138
|
---@class W3CActionsJson
|
|
121
139
|
---@field actions table<string, any>[] W3C action 序列
|
|
122
140
|
|
|
123
141
|
--- 执行 W3C Actions JSON
|
|
124
|
-
|
|
125
|
-
|
|
142
|
+
---@param json W3CActionsJson W3C Actions 请求体,例如 { actions: [...] }
|
|
143
|
+
---@return boolean 执行是否成功
|
|
144
|
+
---@example action.w3cActions({ actions = { { type = "pointer", id = "finger1" } } })
|
|
126
145
|
function _Action.w3cActions(json) return true end
|
|
127
146
|
|
|
128
147
|
---@class TapPoint
|
|
@@ -133,8 +152,9 @@ function _Action.w3cActions(json) return true end
|
|
|
133
152
|
local _ActionBuilder = {}
|
|
134
153
|
|
|
135
154
|
--- 添加手指
|
|
136
|
-
|
|
137
|
-
|
|
155
|
+
---@param id integer 指针编号
|
|
156
|
+
---@return Pointer 返回指针对象
|
|
157
|
+
---@example builder:addPointer(id)
|
|
138
158
|
function _ActionBuilder:addPointer(id)
|
|
139
159
|
---@type Pointer
|
|
140
160
|
local ret
|
|
@@ -142,10 +162,11 @@ function _ActionBuilder:addPointer(id)
|
|
|
142
162
|
end
|
|
143
163
|
|
|
144
164
|
--- 单指点击
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
165
|
+
---@param x integer
|
|
166
|
+
---@param y integer
|
|
167
|
+
---@param duration integer|nil 按下持续时间,默认20ms
|
|
168
|
+
---@return ActionBuilder self
|
|
169
|
+
---@example builder:singleTap(x, y, duration)
|
|
149
170
|
function _ActionBuilder:singleTap(x, y, duration)
|
|
150
171
|
---@type ActionBuilder
|
|
151
172
|
local ret
|
|
@@ -153,9 +174,10 @@ function _ActionBuilder:singleTap(x, y, duration)
|
|
|
153
174
|
end
|
|
154
175
|
|
|
155
176
|
--- 多指同时点击
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
177
|
+
---@param points TapPoint[] 坐标数组
|
|
178
|
+
---@param duration integer|nil 按下持续时间,默认20ms
|
|
179
|
+
---@return ActionBuilder self
|
|
180
|
+
---@example builder:multiTap(points, duration)
|
|
159
181
|
function _ActionBuilder:multiTap(points, duration)
|
|
160
182
|
---@type ActionBuilder
|
|
161
183
|
local ret
|
|
@@ -163,17 +185,19 @@ function _ActionBuilder:multiTap(points, duration)
|
|
|
163
185
|
end
|
|
164
186
|
|
|
165
187
|
--- 执行动作
|
|
166
|
-
|
|
188
|
+
---@return boolean 成功与否
|
|
189
|
+
---@example builder:execute()
|
|
167
190
|
function _ActionBuilder:execute() return true end
|
|
168
191
|
|
|
169
192
|
---@class Pointer
|
|
170
193
|
local _Pointer = {}
|
|
171
194
|
|
|
172
195
|
--- 移动到
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
---@param x integer
|
|
197
|
+
---@param y integer
|
|
198
|
+
---@param duration integer|nil 持续时间
|
|
199
|
+
---@return Pointer self
|
|
200
|
+
---@example pointer:moveTo(x, y, duration)
|
|
177
201
|
function _Pointer:moveTo(x, y, duration)
|
|
178
202
|
---@type Pointer
|
|
179
203
|
local ret
|
|
@@ -181,7 +205,8 @@ function _Pointer:moveTo(x, y, duration)
|
|
|
181
205
|
end
|
|
182
206
|
|
|
183
207
|
--- 按下
|
|
184
|
-
|
|
208
|
+
---@return Pointer self
|
|
209
|
+
---@example pointer:down()
|
|
185
210
|
function _Pointer:down()
|
|
186
211
|
---@type Pointer
|
|
187
212
|
local ret
|
|
@@ -189,7 +214,8 @@ function _Pointer:down()
|
|
|
189
214
|
end
|
|
190
215
|
|
|
191
216
|
--- 抬起
|
|
192
|
-
|
|
217
|
+
---@return Pointer self
|
|
218
|
+
---@example pointer:up()
|
|
193
219
|
function _Pointer:up()
|
|
194
220
|
---@type Pointer
|
|
195
221
|
local ret
|
|
@@ -197,8 +223,9 @@ function _Pointer:up()
|
|
|
197
223
|
end
|
|
198
224
|
|
|
199
225
|
--- 停留
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
---@param duration integer 停留时间,默认20ms
|
|
227
|
+
---@return Pointer self
|
|
228
|
+
---@example pointer:stay(duration)
|
|
202
229
|
function _Pointer:stay(duration)
|
|
203
230
|
---@type Pointer
|
|
204
231
|
local ret
|
|
@@ -206,10 +233,11 @@ function _Pointer:stay(duration)
|
|
|
206
233
|
end
|
|
207
234
|
|
|
208
235
|
--- 点击
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
236
|
+
---@param x integer
|
|
237
|
+
---@param y integer
|
|
238
|
+
---@param duration integer|nil 按下持续时间,默认20ms
|
|
239
|
+
---@return Pointer self
|
|
240
|
+
---@example pointer:tap(x, y, duration)
|
|
213
241
|
function _Pointer:tap(x, y, duration)
|
|
214
242
|
---@type Pointer
|
|
215
243
|
local ret
|
|
@@ -217,7 +245,8 @@ function _Pointer:tap(x, y, duration)
|
|
|
217
245
|
end
|
|
218
246
|
|
|
219
247
|
--- 完成,返回构建器
|
|
220
|
-
|
|
248
|
+
---@return ActionBuilder builder
|
|
249
|
+
---@example pointer:done()
|
|
221
250
|
function _Pointer:done()
|
|
222
251
|
---@type ActionBuilder
|
|
223
252
|
local ret
|
|
@@ -225,7 +254,8 @@ function _Pointer:done()
|
|
|
225
254
|
end
|
|
226
255
|
|
|
227
256
|
--- 创建构建器
|
|
228
|
-
|
|
257
|
+
---@return ActionBuilder ActionBuilder 实例
|
|
258
|
+
---@example local builder = action.createBuilder()
|
|
229
259
|
function _Action.createBuilder()
|
|
230
260
|
---@type ActionBuilder
|
|
231
261
|
local ret
|
package/types/lua/ai.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- AI模块
|
|
2
3
|
---@class Ai
|
|
3
4
|
local _Ai = {}
|
|
4
5
|
|
|
@@ -44,59 +45,76 @@ local _Ai = {}
|
|
|
44
45
|
|
|
45
46
|
--- 登记或更新模型供应商(脚本开头调用一次;只存内存,脚本停止即清空)
|
|
46
47
|
--- 至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新,没传的字段沿用旧值
|
|
47
|
-
---@param config table
|
|
48
|
-
---@return AiProvider|nil
|
|
48
|
+
---@param config table 新建至少要有 baseUrl、model(protocol 缺省 openai);同 id 再次调用为更新,没传的字段沿用旧值
|
|
49
|
+
---@return AiProvider|nil 保存后的完整配置;protocol 不合法或缺 baseUrl / model 时返回 null
|
|
50
|
+
---@example ai.setProvider({ name = "DeepSeek", protocol = "openai", baseUrl = "https://api.deepseek.com", apiKey = "sk-...", model = "deepseek-v4-flash" })
|
|
49
51
|
function _Ai.setProvider(config) return nil end
|
|
50
52
|
|
|
51
53
|
--- 列出已登记的供应商,默认项排在最前
|
|
52
54
|
---@return AiProvider[]
|
|
55
|
+
---@example for _, p in ipairs(ai.getProviders()) do
|
|
56
|
+
--- logi(p.name)
|
|
57
|
+
--- end
|
|
53
58
|
function _Ai.getProviders() return {} end
|
|
54
59
|
|
|
55
60
|
--- 获取默认供应商;一个都没登记时返回 nil
|
|
56
|
-
---@return AiProvider|nil
|
|
61
|
+
---@return AiProvider|nil 一个都没登记时返回 null
|
|
62
|
+
---@example local p = ai.getDefaultProvider()
|
|
57
63
|
function _Ai.getDefaultProvider() return nil end
|
|
58
64
|
|
|
59
65
|
--- 切换默认供应商
|
|
60
66
|
---@param id string 供应商 id 或 name
|
|
61
67
|
---@return boolean id 或 name 存在返回 true
|
|
68
|
+
---@example ai.setDefaultProvider("cheap")
|
|
62
69
|
function _Ai.setDefaultProvider(id) return true end
|
|
63
70
|
|
|
64
71
|
--- 删除供应商;删掉的是默认项时默认转给剩下的第一个
|
|
65
72
|
---@param id string 供应商 id 或 name
|
|
66
73
|
---@return boolean 存在并删除返回 true
|
|
74
|
+
---@example ai.removeProvider("cheap")
|
|
67
75
|
function _Ai.removeProvider(id) return true end
|
|
68
76
|
|
|
69
77
|
--- 单轮提问,可附带图片;图片参数与 image 模块一致(image + x/y/ex/ey,或 images)
|
|
70
|
-
---@param prompt string
|
|
71
|
-
---@param options AiOptions|nil
|
|
72
|
-
---@return string|nil 回复文本;失败返回
|
|
78
|
+
---@param prompt string 问题
|
|
79
|
+
---@param options AiOptions|nil 可选参数,图片参数与 image 模块一致:image 为 imageId,x/y/ex/ey 同 image.clip 裁剪
|
|
80
|
+
---@return string|nil 回复文本;失败返回 null
|
|
81
|
+
---@example ai.ask("屏幕上有几个按钮?", { image = "screen" })
|
|
82
|
+
--- ai.ask("这个区域的价格是多少?", { image = "screen", x = 0, y = 300, ex = 750, ey = 500 })
|
|
73
83
|
function _Ai.ask(prompt, options) return nil end
|
|
74
84
|
|
|
75
85
|
--- 是非判断:让模型只回答 yes / no
|
|
76
|
-
---@param question string
|
|
77
|
-
---@param options AiOptions|nil
|
|
86
|
+
---@param question string 要判断的问题
|
|
87
|
+
---@param options AiOptions|nil 同 ask
|
|
78
88
|
---@return boolean 肯定为 true;否定或请求失败为 false(失败时 lastError() 有内容)
|
|
89
|
+
---@example if ai.judge("是否出现了「领取成功」?", { image = "screen" }) then
|
|
90
|
+
--- ...
|
|
91
|
+
--- end
|
|
79
92
|
function _Ai.judge(question, options) return false end
|
|
80
93
|
|
|
81
94
|
--- 结构化提取:要求模型输出 JSON 并解析成表
|
|
82
|
-
---@param prompt string
|
|
83
|
-
---@param options AiOptions|nil
|
|
84
|
-
---@return table|nil
|
|
95
|
+
---@param prompt string 提取要求
|
|
96
|
+
---@param options AiOptions|nil 同 ask,另支持 schema
|
|
97
|
+
---@return table|nil 解析后的对象或数组;没有合法 JSON 或请求失败返回 null
|
|
98
|
+
---@example local d = ai.extract("提取验证码", { image = "screen", x = 100, y = 800, ex = 600, ey = 900, schema = { code = "string" } })
|
|
99
|
+
--- if d then logi(d.code) end
|
|
85
100
|
function _Ai.extract(prompt, options) return nil end
|
|
86
101
|
|
|
87
102
|
--- 多轮对话:自己维护完整消息数组,每次整表传入。失败返回 nil,不要把空回复推进历史。
|
|
88
|
-
---@param messages (AiMessage|string)[]
|
|
103
|
+
---@param messages (AiMessage|string)[] 消息数组;直接写字符串等于 user 消息;图片写在该条消息上
|
|
89
104
|
---@param options AiOptions|nil provider / model / temperature / maxTokens / json / timeout(不用 system / image)
|
|
90
|
-
---@return string|nil 回复文本;失败返回
|
|
105
|
+
---@return string|nil 回复文本;失败返回 null
|
|
106
|
+
---@example ai.chat({ { role = "system", content = "你是助手" }, { role = "user", content = "看下这是哪个页面", image = "screen" } })
|
|
91
107
|
function _Ai.chat(messages, options) return nil end
|
|
92
108
|
|
|
93
109
|
--- 从模型文本里解析 JSON,自动剥掉 Markdown 代码块和前后解释
|
|
94
|
-
---@param text string
|
|
95
|
-
---@return table|nil
|
|
110
|
+
---@param text string 模型输出
|
|
111
|
+
---@return table|nil 解析结果;失败返回 null
|
|
112
|
+
---@example ai.parseJson("```json\n{\"a\":1}\n```")
|
|
96
113
|
function _Ai.parseJson(text) return nil end
|
|
97
114
|
|
|
98
115
|
--- 最近一次调用失败的原因;上一次调用成功时返回 nil
|
|
99
|
-
---@return string|nil
|
|
116
|
+
---@return string|nil 错误文案;上一次调用成功时返回 null
|
|
117
|
+
---@example if ai.ask("你好") == nil then loge(ai.lastError()) end
|
|
100
118
|
function _Ai.lastError() return nil end
|
|
101
119
|
|
|
102
120
|
---@type Ai
|
package/types/lua/appleocr.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- AppleOCR模块
|
|
2
3
|
---@class AppleOCR
|
|
3
4
|
local _AppleOCR = {}
|
|
4
5
|
|
|
@@ -15,13 +16,17 @@ local _AppleOCR = {}
|
|
|
15
16
|
---@field centerY integer 文本区域中心点 y 坐标
|
|
16
17
|
|
|
17
18
|
--- 识别文本,坐标映射为原图/全屏绝对坐标
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
---@param input string 输入源(imageId、URL字符串、文件路径或"screen","screen"表示使用当前屏幕)
|
|
20
|
+
---@param x integer|nil 边界框左上角x坐标 默认 0
|
|
21
|
+
---@param y integer|nil 边界框左上角y坐标 默认 0
|
|
22
|
+
---@param ex integer|nil 边界框右下角x坐标 默认 0
|
|
23
|
+
---@param ey integer|nil 边界框右下角y坐标 默认 0
|
|
24
|
+
---@param langs string[]|nil 识别语言数组,默认为["zh-Hans", "en-US"]
|
|
25
|
+
---@return AppleOCRResult[] 识别结果数组,坐标为原图/全屏绝对坐标
|
|
26
|
+
---@example local results = appleocr.recognizeAbs("screen", 100, 100, 500, 300)
|
|
27
|
+
--- if #results > 0 then
|
|
28
|
+
--- action.click(results[0].centerX, results[0].centerY)
|
|
29
|
+
--- end
|
|
25
30
|
function _AppleOCR.recognizeAbs(input, x, y, ex, ey, langs)
|
|
26
31
|
---@type AppleOCRResult[]
|
|
27
32
|
local ret = {}
|
|
@@ -29,12 +34,16 @@ function _AppleOCR.recognizeAbs(input, x, y, ex, ey, langs)
|
|
|
29
34
|
end
|
|
30
35
|
|
|
31
36
|
--- 识别数字,坐标映射为原图/全屏绝对坐标
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
---@param input string 输入源(imageId、URL字符串、文件路径或"screen","screen"表示使用当前屏幕)
|
|
38
|
+
---@param x integer|nil 边界框左上角x坐标
|
|
39
|
+
---@param y integer|nil 边界框左上角y坐标
|
|
40
|
+
---@param ex integer|nil 边界框右下角x坐标
|
|
41
|
+
---@param ey integer|nil 边界框右下角y坐标
|
|
42
|
+
---@return AppleOCRResult[] 识别结果数组,坐标为原图/全屏绝对坐标
|
|
43
|
+
---@example local results = appleocr.recognizeNumbersAbs("screen", 100, 100, 500, 300)
|
|
44
|
+
--- if #results > 0 then
|
|
45
|
+
--- action.click(results[0].centerX, results[0].centerY)
|
|
46
|
+
--- end
|
|
38
47
|
function _AppleOCR.recognizeNumbersAbs(input, x, y, ex, ey)
|
|
39
48
|
---@type AppleOCRResult[]
|
|
40
49
|
local ret = {}
|
|
@@ -42,15 +51,19 @@ function _AppleOCR.recognizeNumbersAbs(input, x, y, ex, ey)
|
|
|
42
51
|
end
|
|
43
52
|
|
|
44
53
|
--- 查找文本,坐标映射为原图/全屏绝对坐标
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
---@param input string 输入源(imageId、URL字符串、文件路径或"screen","screen"表示使用当前屏幕)
|
|
55
|
+
---@param targets string[]|string 要查找的目标文本数组,可匹配识别结果中的子串
|
|
56
|
+
---@param x integer|nil 边界框左上角x坐标
|
|
57
|
+
---@param y integer|nil 边界框左上角y坐标
|
|
58
|
+
---@param ex integer|nil 边界框右下角x坐标
|
|
59
|
+
---@param ey integer|nil 边界框右下角y坐标
|
|
60
|
+
---@param langs string[]|nil 识别语言数组,默认为["zh-Hans", "en-US"]
|
|
61
|
+
---@param exactMatch boolean|nil 是否完整匹配,默认 false 表示包含匹配;传 true 时要求整条 OCR 识别结果文本等于目标文本
|
|
62
|
+
---@return AppleOCRResult[] 命中子串的识别结果数组,坐标为原图/全屏绝对坐标
|
|
63
|
+
---@example local results = appleocr.findTextAbs("screen", {"开始"}, 100, 100, 500, 400)
|
|
64
|
+
--- if #results > 0 then
|
|
65
|
+
--- action.click(results[0].centerX, results[0].centerY)
|
|
66
|
+
--- end
|
|
54
67
|
function _AppleOCR.findTextAbs(input, targets, x, y, ex, ey, langs, exactMatch)
|
|
55
68
|
---@type AppleOCRResult[]
|
|
56
69
|
local ret = {}
|
package/types/lua/cloud.lua
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- 云控模块
|
|
2
3
|
---@class Cloud
|
|
3
4
|
local _Cloud = {}
|
|
4
5
|
|
|
5
6
|
--- 云控 WebSocket;仅主脚本注册 onEvent
|
|
6
7
|
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
---@param
|
|
10
|
-
---@
|
|
8
|
+
--- 连接云控服务器。
|
|
9
|
+
--- 只能在主脚本上下文调用;只影响当前运行期云控连接,不会写入设置页的持久化云控配置。
|
|
10
|
+
---@param url string 完整 ws:// 或 wss:// 云控地址。
|
|
11
|
+
---@param deviceNo string|nil 可选设备编号,不传时沿用当前保存的设备编号。
|
|
12
|
+
---@return boolean URL 校验通过且连接请求已提交时返回 true。
|
|
13
|
+
---@example local accepted = cloud.connect("wss://example.com/control", "device-001")
|
|
11
14
|
function _Cloud.connect(url, deviceNo) return false end
|
|
12
15
|
|
|
13
|
-
---
|
|
14
|
-
---@return boolean
|
|
16
|
+
--- 判断云控是否已经连接成功。
|
|
17
|
+
---@return boolean 已连接时返回 true。
|
|
18
|
+
---@example if cloud.isConnected() then
|
|
19
|
+
--- cloud.report("status", { value = "ready" })
|
|
20
|
+
--- end
|
|
15
21
|
function _Cloud.isConnected() return false end
|
|
16
22
|
|
|
17
23
|
--- disconnect
|
|
18
24
|
|
|
25
|
+
--- 断开云控连接并停止自动重连。
|
|
26
|
+
---@example cloud.disconnect()
|
|
19
27
|
function _Cloud.disconnect() end
|
|
20
28
|
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
---@param
|
|
24
|
-
---@
|
|
29
|
+
--- 上报普通 Object 到云控服务器。
|
|
30
|
+
--- 设备总览状态固定使用 cloud.report("cloud:status", data) 上报;data 的 key 必须是云控端已配置的自定义字段名,多余字段不会在设备总览显示。
|
|
31
|
+
---@param event string 自定义事件名称。
|
|
32
|
+
---@param data table<string, any> 可 JSON 序列化的普通 Object。
|
|
33
|
+
---@return boolean 已连接且数据可写出时返回 true。
|
|
34
|
+
---@example cloud.report("done", { value = 1 })
|
|
25
35
|
function _Cloud.report(event, data) return false end
|
|
26
36
|
|
|
27
|
-
---
|
|
28
|
-
---@param callback fun(event: string, data: table<string, any>)|nil
|
|
37
|
+
--- 监听服务端下发的 scriptEvent 事件(仅主线程调用,不能在线程脚本中调用)。
|
|
38
|
+
---@param callback fun(event: string, data: table<string, any>)|nil 主脚本回调函数;传入 null 可取消监听。
|
|
39
|
+
---@example cloud.onEvent(function(event, data)
|
|
40
|
+
--- logi("server event:", event, data)
|
|
41
|
+
--- end)
|
|
29
42
|
function _Cloud.onEvent(callback) end
|
|
30
43
|
|
|
31
44
|
---@type Cloud
|
package/types/lua/config.lua
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- 配置模块
|
|
2
3
|
---@class Config
|
|
3
4
|
local _Config = {}
|
|
4
5
|
|
|
5
6
|
--- 获取所有配置
|
|
6
|
-
---@return table<string, any>
|
|
7
|
+
---@return table<string, any> 所有配置
|
|
8
|
+
---@example config.all()
|
|
7
9
|
function _Config.all() return {} end
|
|
8
10
|
|
|
9
11
|
--- 用完整表覆盖配置
|
|
10
|
-
---@param config table<string, any>
|
|
11
|
-
---@return boolean
|
|
12
|
+
---@param config table<string, any> 包含所有配置项的字典
|
|
13
|
+
---@return boolean 如果设置成功返回true,否则返回false
|
|
14
|
+
---@example config.setAll({ key = 100 })
|
|
12
15
|
function _Config.setAll(config) return true end
|
|
13
16
|
|
|
14
17
|
--- 设置单个配置
|
|
15
|
-
---@param key string
|
|
16
|
-
---@param value any
|
|
17
|
-
---@return boolean
|
|
18
|
+
---@param key string 配置key
|
|
19
|
+
---@param value any 配置值
|
|
20
|
+
---@return boolean 设置是否成功
|
|
21
|
+
---@example config.set("key", 100)
|
|
18
22
|
function _Config.set(key, value) return true end
|
|
19
23
|
|
|
20
24
|
--- 读取配置
|
|
21
|
-
---@param key string
|
|
22
|
-
---@return any|nil
|
|
25
|
+
---@param key string 配置key
|
|
26
|
+
---@return any|nil 配置值
|
|
27
|
+
---@example config.get("key")
|
|
23
28
|
function _Config.get(key) return nil end
|
|
24
29
|
|
|
25
30
|
--- 获取 KUI_CONFIG 表;不存在时返回空表
|
|
26
|
-
---@return table<string, any>
|
|
31
|
+
---@return table<string, any> KUI_CONFIG 对应的字典,配置不存在或无法转换时返回空对象
|
|
32
|
+
---@example config.getKuiConfig()
|
|
27
33
|
function _Config.getKuiConfig() return {} end
|
|
28
34
|
|
|
29
35
|
--- 删除配置
|
|
30
|
-
---@param key string
|
|
31
|
-
---@return boolean
|
|
36
|
+
---@param key string 配置key
|
|
37
|
+
---@return boolean 删除是否成功
|
|
38
|
+
---@example config.remove("key")
|
|
32
39
|
function _Config.remove(key) return true end
|
|
33
40
|
|
|
34
41
|
---@type Config
|