@maaxyz/maa-node 4.5.6 → 5.0.0-alpha.2
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/client.d.ts +18 -13
- package/dist/constant.d.ts +28 -0
- package/dist/context.d.ts +33 -53
- package/dist/controller.d.ts +225 -157
- package/dist/global.d.ts +17 -9
- package/dist/index-client.d.ts +12 -12
- package/dist/index-client.js +23 -982
- package/dist/index-server.d.ts +12 -12
- package/dist/index-server.js +23 -990
- package/dist/job.d.ts +30 -22
- package/dist/pipeline.d.ts +355 -211
- package/dist/plugin.d.ts +16 -0
- package/dist/resource.d.ts +47 -39
- package/dist/server.d.ts +24 -9
- package/dist/tasker.d.ts +97 -136
- package/dist/types.d.ts +61 -27
- package/package.json +9 -12
- package/src/index-client.js +27 -0
- package/src/index-server.js +27 -0
- package/dist/maa.d.ts +0 -422
- package/dist/pi.d.ts +0 -9
- package/dist/utils.d.ts +0 -5
- package/scripts/build.mjs +0 -20
- package/src/client.ts +0 -54
- package/src/context.ts +0 -91
- package/src/controller.ts +0 -430
- package/src/global.ts +0 -37
- package/src/index-client.ts +0 -14
- package/src/index-server.ts +0 -14
- package/src/job.ts +0 -68
- package/src/maa-client.js +0 -27
- package/src/maa-server.js +0 -27
- package/src/maa.d.ts +0 -422
- package/src/maa.js +0 -1
- package/src/pi.ts +0 -66
- package/src/pipeline.ts +0 -352
- package/src/resource.ts +0 -203
- package/src/server.ts +0 -64
- package/src/tasker.ts +0 -244
- package/src/types.ts +0 -33
- package/src/utils.ts +0 -40
- package/tsconfig.json +0 -9
package/src/tasker.ts
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import { ControllerBase } from './controller'
|
|
2
|
-
import { Job, JobSource } from './job'
|
|
3
|
-
import maa from './maa'
|
|
4
|
-
import { ResourceBase } from './resource'
|
|
5
|
-
import { ChainNotifyType } from './types'
|
|
6
|
-
import { chain_notify_impl } from './utils'
|
|
7
|
-
|
|
8
|
-
type TaskDetail = ReturnType<TaskerBase['task_detail']>
|
|
9
|
-
|
|
10
|
-
type RecoDetailEntry = {
|
|
11
|
-
box: maa.FlatRect
|
|
12
|
-
score?: number // TemplateMatch
|
|
13
|
-
count?: number // FeatureMatch | ColorMatch
|
|
14
|
-
text?: string // OCR
|
|
15
|
-
cls_index?: number // NeuralNetworkClassify | NeuralNetworkDetect
|
|
16
|
-
label?: string // NeuralNetworkClassify | NeuralNetworkDetect
|
|
17
|
-
detail?: string | Record<string, unknown> // Custom
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type RecoDetail = {
|
|
21
|
-
all: RecoDetailEntry[]
|
|
22
|
-
filtered: RecoDetailEntry[]
|
|
23
|
-
best: RecoDetailEntry | null
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class TaskJob extends Job<maa.TaskId, JobSource<maa.TaskId>> {
|
|
27
|
-
#tasker: TaskerBase
|
|
28
|
-
|
|
29
|
-
constructor(tasker: TaskerBase, source: JobSource<maa.TaskId>, id: maa.TaskId) {
|
|
30
|
-
super(source, id)
|
|
31
|
-
|
|
32
|
-
this.#tasker = tasker
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get() {
|
|
36
|
-
if (this.done) {
|
|
37
|
-
return this.#tasker.task_detail(this.id)
|
|
38
|
-
} else {
|
|
39
|
-
return null
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
wait() {
|
|
44
|
-
const superPro = super.wait()
|
|
45
|
-
const pro = superPro as typeof superPro & {
|
|
46
|
-
get: () => Promise<TaskDetail>
|
|
47
|
-
}
|
|
48
|
-
pro.get = () => {
|
|
49
|
-
return new Promise(resolve => {
|
|
50
|
-
pro.then(self => {
|
|
51
|
-
resolve(self.get())
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
return pro
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type TaskerNotify =
|
|
60
|
-
| {
|
|
61
|
-
msg: 'Task.Started' | 'Task.Completed' | 'Task.Failed'
|
|
62
|
-
task_id: maa.TaskId
|
|
63
|
-
entry: string
|
|
64
|
-
uuid: string
|
|
65
|
-
hash: string
|
|
66
|
-
}
|
|
67
|
-
| {
|
|
68
|
-
msg: 'NextList.Starting' | 'NextList.Succeeded' | 'NextList.Failed'
|
|
69
|
-
task_id: maa.TaskId
|
|
70
|
-
name: string
|
|
71
|
-
list: string[]
|
|
72
|
-
focus: unknown
|
|
73
|
-
}
|
|
74
|
-
| {
|
|
75
|
-
msg: 'Recognition.Starting' | 'Recognition.Succeeded' | 'Recognition.Failed'
|
|
76
|
-
task_id: maa.TaskId
|
|
77
|
-
reco_id: maa.RecoId
|
|
78
|
-
name: string
|
|
79
|
-
focus: unknown
|
|
80
|
-
}
|
|
81
|
-
| {
|
|
82
|
-
msg: 'Action.Starting' | 'Action.Succeeded' | 'Action.Failed'
|
|
83
|
-
task_id: maa.TaskId
|
|
84
|
-
node_id: maa.NodeId
|
|
85
|
-
name: string
|
|
86
|
-
focus: unknown
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export class TaskerBase {
|
|
90
|
-
handle: maa.TaskerHandle
|
|
91
|
-
#source: JobSource<maa.TaskId>
|
|
92
|
-
|
|
93
|
-
notify(message: string, details_json: string): maa.MaybePromise<void> {}
|
|
94
|
-
|
|
95
|
-
chain_notify = chain_notify_impl
|
|
96
|
-
|
|
97
|
-
chain_parsed_notify(
|
|
98
|
-
cb: (msg: TaskerNotify) => maa.MaybePromise<void>,
|
|
99
|
-
order: ChainNotifyType = 'after'
|
|
100
|
-
) {
|
|
101
|
-
this.chain_notify((msg: string, details: string) => {
|
|
102
|
-
return cb({
|
|
103
|
-
msg: msg.replace(/^(?:Tasker|Node)?\./, '') as any,
|
|
104
|
-
...JSON.parse(details)
|
|
105
|
-
})
|
|
106
|
-
}, order)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
constructor(handle: maa.TaskerHandle) {
|
|
110
|
-
this.handle = handle
|
|
111
|
-
this.#source = {
|
|
112
|
-
status: id => maa.tasker_status(this.handle, id),
|
|
113
|
-
wait: id => maa.tasker_wait(this.handle, id)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
destroy() {
|
|
118
|
-
maa.tasker_destroy(this.handle)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
bind(slave: ControllerBase | ResourceBase) {
|
|
122
|
-
let ret: boolean
|
|
123
|
-
if (slave instanceof ControllerBase) {
|
|
124
|
-
ret = maa.tasker_bind_controller(this.handle, slave.handle)
|
|
125
|
-
} else {
|
|
126
|
-
ret = maa.tasker_bind_resource(this.handle, slave.handle)
|
|
127
|
-
}
|
|
128
|
-
if (!ret) {
|
|
129
|
-
throw 'Tasker bind failed'
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
post_task(entry: string, param: Record<string, unknown> | Record<string, unknown>[] = {}) {
|
|
134
|
-
return new TaskJob(
|
|
135
|
-
this,
|
|
136
|
-
this.#source,
|
|
137
|
-
maa.tasker_post_task(this.handle, entry, JSON.stringify(param))
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
get inited() {
|
|
142
|
-
return maa.tasker_inited(this.handle)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
get running() {
|
|
146
|
-
return maa.tasker_running(this.handle)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
post_stop() {
|
|
150
|
-
return new TaskJob(this, this.#source, maa.tasker_post_stop(this.handle))
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
get stopping() {
|
|
154
|
-
return maa.tasker_stopping(this.handle)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
get resource() {
|
|
158
|
-
const res = maa.tasker_get_resource(this.handle)
|
|
159
|
-
if (res) {
|
|
160
|
-
return new ResourceBase(res)
|
|
161
|
-
} else {
|
|
162
|
-
return null
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
get controller() {
|
|
167
|
-
const ctrl = maa.tasker_get_controller(this.handle)
|
|
168
|
-
if (ctrl) {
|
|
169
|
-
return new ControllerBase(ctrl)
|
|
170
|
-
} else {
|
|
171
|
-
return null
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
clear_cache() {
|
|
176
|
-
if (!maa.tasker_clear_cache(this.handle)) {
|
|
177
|
-
throw 'Tasker clear_cache failed'
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
recognition_detail(id: maa.RecoId) {
|
|
182
|
-
const dt = maa.tasker_get_recognition_detail(this.handle, id)
|
|
183
|
-
if (dt) {
|
|
184
|
-
const [name, algorithm, hit, box, detail, raw, draws] = dt
|
|
185
|
-
return {
|
|
186
|
-
name,
|
|
187
|
-
algorithm,
|
|
188
|
-
hit,
|
|
189
|
-
box,
|
|
190
|
-
detail: JSON.parse(detail) as RecoDetail,
|
|
191
|
-
raw,
|
|
192
|
-
draws
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
return null
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
node_detail(id: maa.NodeId) {
|
|
200
|
-
const dt = maa.tasker_get_node_detail(this.handle, id)
|
|
201
|
-
if (dt) {
|
|
202
|
-
const [name, reco_id, completed] = dt
|
|
203
|
-
return {
|
|
204
|
-
name,
|
|
205
|
-
reco: this.recognition_detail(reco_id),
|
|
206
|
-
completed
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
return null
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
task_detail(id: maa.TaskId) {
|
|
214
|
-
const dt = maa.tasker_get_task_detail(this.handle, id)
|
|
215
|
-
if (dt) {
|
|
216
|
-
const [entry, node_ids, status] = dt
|
|
217
|
-
return {
|
|
218
|
-
entry,
|
|
219
|
-
nodes: node_ids.map(i => this.node_detail(i)),
|
|
220
|
-
status
|
|
221
|
-
}
|
|
222
|
-
} else {
|
|
223
|
-
return null
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
latest_node(node: string) {
|
|
228
|
-
return maa.tasker_get_latest_node(this.handle, node)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export class Tasker extends TaskerBase {
|
|
233
|
-
constructor() {
|
|
234
|
-
let ws: WeakRef<this>
|
|
235
|
-
const h = maa.tasker_create((message, details_json) => {
|
|
236
|
-
return ws.deref()?.notify(message, details_json)
|
|
237
|
-
})
|
|
238
|
-
if (!h) {
|
|
239
|
-
throw 'Tasker create failed'
|
|
240
|
-
}
|
|
241
|
-
super(h)
|
|
242
|
-
ws = new WeakRef(this)
|
|
243
|
-
}
|
|
244
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Context } from './context'
|
|
2
|
-
import maa from './maa'
|
|
3
|
-
|
|
4
|
-
export interface CustomRecognizerSelf {
|
|
5
|
-
context: Context
|
|
6
|
-
id: maa.TaskId
|
|
7
|
-
task: string
|
|
8
|
-
name: string
|
|
9
|
-
param: unknown
|
|
10
|
-
image: maa.ImageData
|
|
11
|
-
roi: maa.Rect
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CustomActionSelf {
|
|
15
|
-
context: Context
|
|
16
|
-
id: maa.TaskId
|
|
17
|
-
task: string
|
|
18
|
-
name: string
|
|
19
|
-
param: unknown
|
|
20
|
-
recoId: maa.RecoId
|
|
21
|
-
box: maa.Rect
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type CustomCallback<Self, Ret> = (this: Self, self: Self) => maa.MaybePromise<Ret>
|
|
25
|
-
|
|
26
|
-
export type CustomRecognizerCallback = CustomCallback<
|
|
27
|
-
CustomRecognizerSelf,
|
|
28
|
-
[out_box: maa.Rect, out_detail: string] | null
|
|
29
|
-
>
|
|
30
|
-
|
|
31
|
-
export type CustomActionCallback = CustomCallback<CustomActionSelf, boolean>
|
|
32
|
-
|
|
33
|
-
export type ChainNotifyType = 'before' | 'after' | 'before-no-wait' | 'after-no-wait' | 'replace'
|
package/src/utils.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import maa from './maa'
|
|
2
|
-
import { ChainNotifyType } from './types'
|
|
3
|
-
|
|
4
|
-
export function chain_notify_impl(
|
|
5
|
-
this: { notify: maa.NotificationCallback },
|
|
6
|
-
cb: maa.NotificationCallback,
|
|
7
|
-
order: ChainNotifyType = 'after'
|
|
8
|
-
) {
|
|
9
|
-
const old = this.notify
|
|
10
|
-
|
|
11
|
-
switch (order) {
|
|
12
|
-
case 'before':
|
|
13
|
-
this.notify = async (msg, details) => {
|
|
14
|
-
await cb(msg, details)
|
|
15
|
-
await old.call(this, msg, details)
|
|
16
|
-
}
|
|
17
|
-
break
|
|
18
|
-
case 'after':
|
|
19
|
-
this.notify = async (msg, details) => {
|
|
20
|
-
await old.call(this, msg, details)
|
|
21
|
-
await cb(msg, details)
|
|
22
|
-
}
|
|
23
|
-
break
|
|
24
|
-
case 'before-no-wait':
|
|
25
|
-
this.notify = async (msg, details) => {
|
|
26
|
-
cb(msg, details)
|
|
27
|
-
await old.call(this, msg, details)
|
|
28
|
-
}
|
|
29
|
-
break
|
|
30
|
-
case 'after-no-wait':
|
|
31
|
-
this.notify = async (msg, details) => {
|
|
32
|
-
await old.call(this, msg, details)
|
|
33
|
-
cb(msg, details)
|
|
34
|
-
}
|
|
35
|
-
break
|
|
36
|
-
case 'replace':
|
|
37
|
-
this.notify = cb
|
|
38
|
-
break
|
|
39
|
-
}
|
|
40
|
-
}
|