@maaxyz/maa-node 0.0.1-alpha.1

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.
Files changed (105) hide show
  1. package/agent/maatouch/universal/maatouch +0 -0
  2. package/agent/minicap/arm64-v8a/bin/minicap +0 -0
  3. package/agent/minicap/arm64-v8a/bin/minicap-nopie +0 -0
  4. package/agent/minicap/arm64-v8a/lib/android-21/minicap.so +0 -0
  5. package/agent/minicap/arm64-v8a/lib/android-22/minicap.so +0 -0
  6. package/agent/minicap/arm64-v8a/lib/android-23/minicap.so +0 -0
  7. package/agent/minicap/arm64-v8a/lib/android-24/minicap.so +0 -0
  8. package/agent/minicap/arm64-v8a/lib/android-25/minicap.so +0 -0
  9. package/agent/minicap/arm64-v8a/lib/android-26/minicap.so +0 -0
  10. package/agent/minicap/arm64-v8a/lib/android-27/minicap.so +0 -0
  11. package/agent/minicap/arm64-v8a/lib/android-28/minicap.so +0 -0
  12. package/agent/minicap/arm64-v8a/lib/android-29/minicap +0 -0
  13. package/agent/minicap/arm64-v8a/lib/android-29/minicap-nopie +0 -0
  14. package/agent/minicap/arm64-v8a/lib/android-29/minicap.so +0 -0
  15. package/agent/minicap/arm64-v8a/lib/android-30/minicap.so +0 -0
  16. package/agent/minicap/arm64-v8a/lib/android-31/minicap.so +0 -0
  17. package/agent/minicap/armeabi-v7a/bin/minicap +0 -0
  18. package/agent/minicap/armeabi-v7a/bin/minicap-nopie +0 -0
  19. package/agent/minicap/armeabi-v7a/lib/android-10/minicap.so +0 -0
  20. package/agent/minicap/armeabi-v7a/lib/android-14/minicap.so +0 -0
  21. package/agent/minicap/armeabi-v7a/lib/android-15/minicap.so +0 -0
  22. package/agent/minicap/armeabi-v7a/lib/android-16/minicap.so +0 -0
  23. package/agent/minicap/armeabi-v7a/lib/android-17/minicap.so +0 -0
  24. package/agent/minicap/armeabi-v7a/lib/android-18/minicap.so +0 -0
  25. package/agent/minicap/armeabi-v7a/lib/android-19/minicap.so +0 -0
  26. package/agent/minicap/armeabi-v7a/lib/android-21/minicap.so +0 -0
  27. package/agent/minicap/armeabi-v7a/lib/android-22/minicap.so +0 -0
  28. package/agent/minicap/armeabi-v7a/lib/android-23/minicap.so +0 -0
  29. package/agent/minicap/armeabi-v7a/lib/android-24/minicap.so +0 -0
  30. package/agent/minicap/armeabi-v7a/lib/android-25/minicap.so +0 -0
  31. package/agent/minicap/armeabi-v7a/lib/android-26/minicap.so +0 -0
  32. package/agent/minicap/armeabi-v7a/lib/android-27/minicap.so +0 -0
  33. package/agent/minicap/armeabi-v7a/lib/android-28/minicap.so +0 -0
  34. package/agent/minicap/armeabi-v7a/lib/android-29/minicap +0 -0
  35. package/agent/minicap/armeabi-v7a/lib/android-29/minicap-nopie +0 -0
  36. package/agent/minicap/armeabi-v7a/lib/android-29/minicap.so +0 -0
  37. package/agent/minicap/armeabi-v7a/lib/android-30/minicap.so +0 -0
  38. package/agent/minicap/armeabi-v7a/lib/android-31/minicap.so +0 -0
  39. package/agent/minicap/armeabi-v7a/lib/android-9/minicap.so +0 -0
  40. package/agent/minicap/x86/bin/minicap +0 -0
  41. package/agent/minicap/x86/bin/minicap-nopie +0 -0
  42. package/agent/minicap/x86/lib/android-14/minicap.so +0 -0
  43. package/agent/minicap/x86/lib/android-15/minicap.so +0 -0
  44. package/agent/minicap/x86/lib/android-16/minicap.so +0 -0
  45. package/agent/minicap/x86/lib/android-17/minicap.so +0 -0
  46. package/agent/minicap/x86/lib/android-18/minicap.so +0 -0
  47. package/agent/minicap/x86/lib/android-19/minicap.so +0 -0
  48. package/agent/minicap/x86/lib/android-21/minicap.so +0 -0
  49. package/agent/minicap/x86/lib/android-22/minicap.so +0 -0
  50. package/agent/minicap/x86/lib/android-23/minicap.so +0 -0
  51. package/agent/minicap/x86/lib/android-24/minicap.so +0 -0
  52. package/agent/minicap/x86/lib/android-25/minicap.so +0 -0
  53. package/agent/minicap/x86/lib/android-26/minicap.so +0 -0
  54. package/agent/minicap/x86/lib/android-27/minicap.so +0 -0
  55. package/agent/minicap/x86/lib/android-28/minicap.so +0 -0
  56. package/agent/minicap/x86/lib/android-29/minicap +0 -0
  57. package/agent/minicap/x86/lib/android-29/minicap-nopie +0 -0
  58. package/agent/minicap/x86/lib/android-29/minicap.so +0 -0
  59. package/agent/minicap/x86/lib/android-31/minicap.so +0 -0
  60. package/agent/minicap/x86_64/bin/minicap +0 -0
  61. package/agent/minicap/x86_64/bin/minicap-nopie +0 -0
  62. package/agent/minicap/x86_64/lib/android-21/minicap.so +0 -0
  63. package/agent/minicap/x86_64/lib/android-22/minicap.so +0 -0
  64. package/agent/minicap/x86_64/lib/android-23/minicap.so +0 -0
  65. package/agent/minicap/x86_64/lib/android-24/minicap.so +0 -0
  66. package/agent/minicap/x86_64/lib/android-25/minicap.so +0 -0
  67. package/agent/minicap/x86_64/lib/android-26/minicap.so +0 -0
  68. package/agent/minicap/x86_64/lib/android-27/minicap.so +0 -0
  69. package/agent/minicap/x86_64/lib/android-28/minicap.so +0 -0
  70. package/agent/minicap/x86_64/lib/android-29/minicap +0 -0
  71. package/agent/minicap/x86_64/lib/android-29/minicap-nopie +0 -0
  72. package/agent/minicap/x86_64/lib/android-29/minicap.so +0 -0
  73. package/agent/minicap/x86_64/lib/android-31/minicap.so +0 -0
  74. package/agent/minitouch/arm64-v8a/minitouch +0 -0
  75. package/agent/minitouch/armeabi/minitouch +0 -0
  76. package/agent/minitouch/armeabi-v7a/minitouch +0 -0
  77. package/agent/minitouch/x86/minitouch +0 -0
  78. package/agent/minitouch/x86_64/minitouch +0 -0
  79. package/dist/context.d.ts +52 -0
  80. package/dist/controller.d.ts +105 -0
  81. package/dist/global.d.ts +10 -0
  82. package/dist/index.d.ts +9 -0
  83. package/dist/index.js +1028 -0
  84. package/dist/job.d.ts +23 -0
  85. package/dist/maa.d.ts +376 -0
  86. package/dist/pi.d.ts +9 -0
  87. package/dist/pipeline.d.ts +249 -0
  88. package/dist/resource.d.ts +36 -0
  89. package/dist/tasker.d.ts +128 -0
  90. package/dist/types.d.ts +27 -0
  91. package/package.json +33 -0
  92. package/scripts/build.mjs +20 -0
  93. package/src/context.ts +78 -0
  94. package/src/controller.ts +366 -0
  95. package/src/global.ts +49 -0
  96. package/src/index.ts +9 -0
  97. package/src/job.ts +68 -0
  98. package/src/maa.d.ts +376 -0
  99. package/src/maa.js +27 -0
  100. package/src/pi.ts +62 -0
  101. package/src/pipeline.ts +694 -0
  102. package/src/resource.ts +173 -0
  103. package/src/tasker.ts +231 -0
  104. package/src/types.ts +31 -0
  105. package/tsconfig.json +9 -0
package/src/global.ts ADDED
@@ -0,0 +1,49 @@
1
+ import * as maa from './maa'
2
+
3
+ export const Global = {
4
+ get version() {
5
+ return maa.version()
6
+ },
7
+
8
+ set log_dir(value: string) {
9
+ if (!maa.set_global_option_log_dir(value)) {
10
+ throw 'Global set log_dir failed'
11
+ }
12
+ },
13
+
14
+ set save_draw(value: boolean) {
15
+ if (!maa.set_global_option_save_draw(value)) {
16
+ throw 'Global set save_draw failed'
17
+ }
18
+ },
19
+
20
+ set recording(value: boolean) {
21
+ if (!maa.set_global_option_recording(value)) {
22
+ throw 'Global set recording failed'
23
+ }
24
+ },
25
+
26
+ set stdout_level(value: keyof typeof maa.LoggingLevel) {
27
+ if (!maa.set_global_option_stdout_level(maa.LoggingLevel[value])) {
28
+ throw 'Global set stdout_level failed'
29
+ }
30
+ },
31
+
32
+ set show_hit_draw(value: boolean) {
33
+ if (!maa.set_global_option_show_hit_draw(value)) {
34
+ throw 'Global set show_hit_draw failed'
35
+ }
36
+ },
37
+
38
+ set debug_mode(value: boolean) {
39
+ if (!maa.set_global_option_debug_mode(value)) {
40
+ throw 'Global set debug_mode failed'
41
+ }
42
+ },
43
+
44
+ config_init_option(user_path: string, default_json = '{}') {
45
+ if (!maa.config_init_option(user_path, default_json)) {
46
+ throw 'Global config_init_option failed'
47
+ }
48
+ }
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * as api from './maa'
2
+ export * from './controller'
3
+ export * from './resource'
4
+ export * from './tasker'
5
+ export * from './context'
6
+ export * from './global'
7
+ export * from './pi'
8
+ export * from './types'
9
+ export * from './pipeline'
package/src/job.ts ADDED
@@ -0,0 +1,68 @@
1
+ import * as maa from './maa'
2
+
3
+ export interface JobSource<Id> {
4
+ status(id: Id): maa.Status
5
+ wait(id: Id): Promise<maa.Status>
6
+ }
7
+
8
+ export class Job<Id, Source extends JobSource<Id>> {
9
+ source: Source
10
+ id: Id
11
+ #status: maa.Status | null
12
+
13
+ constructor(source: Source, id: Id) {
14
+ this.source = source
15
+ this.id = id
16
+ this.#status = null
17
+ }
18
+
19
+ get status(): maa.Status {
20
+ return this.#status ?? this.source.status(this.id)
21
+ }
22
+
23
+ wait() {
24
+ const realWait = async () => {
25
+ this.#status = await this.source.wait(this.id)
26
+ return this
27
+ }
28
+
29
+ const pro = realWait() as Promise<this> & {
30
+ status: Promise<maa.Status>
31
+ done: Promise<boolean>
32
+ succeeded: Promise<boolean>
33
+ failed: Promise<boolean>
34
+ }
35
+ for (const key of ['status', 'done', 'succeeded', 'failed']) {
36
+ Object.defineProperty(pro, key, {
37
+ get: () => {
38
+ return new Promise(resolve => {
39
+ pro.then(self => {
40
+ resolve((self as any)[key])
41
+ })
42
+ })
43
+ }
44
+ })
45
+ }
46
+ return pro
47
+ }
48
+
49
+ get done() {
50
+ return [maa.Status.Succeeded, maa.Status.Failed].includes(this.status)
51
+ }
52
+
53
+ get succeeded() {
54
+ return this.status == maa.Status.Succeeded
55
+ }
56
+
57
+ get failed() {
58
+ return this.status == maa.Status.Failed
59
+ }
60
+
61
+ get running() {
62
+ return this.status == maa.Status.Running
63
+ }
64
+
65
+ get pending() {
66
+ return this.status == maa.Status.Pending
67
+ }
68
+ }
package/src/maa.d.ts ADDED
@@ -0,0 +1,376 @@
1
+ export type ResourceHandle = { __brand: 'ResourceHandle' }
2
+ export type ControllerHandle = { __brand: 'ControllerHandle' }
3
+ export type TaskerHandle = { __brand: 'TaskerHandle' }
4
+ export type ContextHandle = { __brand: 'ContextHandle' }
5
+ export type DesktopHandle = string & { __brand: 'DesktopHandle' }
6
+
7
+ type Uint64 = number | string
8
+ type Id = Uint64
9
+ type ScreencapOrInputMethods = Uint64
10
+
11
+ export type ResId = Id & { __brand: 'ResId' }
12
+ export type CtrlId = Id & { __brand: 'CtrlId' }
13
+ export type TaskId = Id & { __brand: 'TaskId' }
14
+ export type RecoId = Id & { __brand: 'RecoId' }
15
+ export type NodeId = Id & { __brand: 'NodeId' }
16
+
17
+ export type Status = number & { __brand: 'Status' }
18
+ export type LoggingLevel = number & { __brand: 'LoggingLevel' }
19
+ export type InferenceDevice = number & { __brand: 'InferenceDevice' }
20
+ export type InferenceExecutionProvider = number & { __brand: 'InferenceExecutionProvider' }
21
+
22
+ export type ImageData = ArrayBuffer
23
+
24
+ export type Rect = {
25
+ x: number
26
+ y: number
27
+ width: number
28
+ height: number
29
+ }
30
+
31
+ export type FlatRect = [x: number, y: number, width: number, height: number]
32
+
33
+ type MaybePromise<T> = T | Promise<T>
34
+
35
+ export type NotificationCallback = (message: string, details_json: string) => MaybePromise<void>
36
+ export type CustomRecognitionCallback = (
37
+ context: ContextHandle,
38
+ task_id: TaskId,
39
+ current_task_name: string,
40
+ custom_recognition_name: string,
41
+ custom_recognition_param: string,
42
+ image: ImageData,
43
+ roi: Rect
44
+ ) => MaybePromise<[out_box: Rect, out_detail: string] | null>
45
+ export type CustomActionCallback = (
46
+ context: ContextHandle,
47
+ task_id: TaskId,
48
+ current_task_name: string,
49
+ custom_action_name: string,
50
+ custom_action_param: string,
51
+ reco_id: RecoId,
52
+ box: Rect
53
+ ) => MaybePromise<boolean>
54
+
55
+ export type CustomControllerParamResultMap = {
56
+ connect: [[], boolean]
57
+ request_uuid: [[], string | null]
58
+ start_app: [[intent: string], boolean]
59
+ stop_app: [[intent: string], boolean]
60
+ screencap: [[], ImageData | null]
61
+ click: [[x: number, y: number], boolean]
62
+ swipe: [[x1: number, y1: number, x2: number, y2: number, duration: number], boolean]
63
+ touch_down: [[contact: number, x: number, y: number, pressure: number], boolean]
64
+ touch_move: [[contact: number, x: number, y: number, pressure: number], boolean]
65
+ touch_up: [[contact: number], boolean]
66
+ press_key: [[keycode: number], boolean]
67
+ input_text: [[text: string], boolean]
68
+ }
69
+ export type CustomControllerCallback = (
70
+ action: keyof CustomControllerParamResultMap,
71
+ ...param: any[]
72
+ ) => MaybePromise<any>
73
+
74
+ // context.cpp
75
+
76
+ export declare function context_run_pipeline(
77
+ context: ContextHandle,
78
+ entry: string,
79
+ pipeline_override: string
80
+ ): Promise<TaskId>
81
+ export declare function context_run_recognition(
82
+ context: ContextHandle,
83
+ entry: string,
84
+ pipeline_override: string,
85
+ image: ImageData
86
+ ): Promise<RecoId>
87
+ export declare function context_run_action(
88
+ context: ContextHandle,
89
+ entry: string,
90
+ pipeline_override: string,
91
+ box: Rect,
92
+ reco_detail: string
93
+ ): Promise<NodeId>
94
+ export declare function context_override_pipeline(
95
+ context: ContextHandle,
96
+ pipeline_override: string
97
+ ): boolean
98
+ export declare function context_override_next(
99
+ context: ContextHandle,
100
+ name: string,
101
+ next: string[]
102
+ ): boolean
103
+ export declare function context_get_task_id(context: ContextHandle): TaskId
104
+ export declare function context_get_tasker(context: ContextHandle): TaskerHandle
105
+ export declare function context_clone(context: ContextHandle): ContextHandle
106
+
107
+ // controller.cpp
108
+
109
+ export declare function adb_controller_create(
110
+ adb_path: string,
111
+ address: string,
112
+ screencap_methods: ScreencapOrInputMethods,
113
+ input_methods: ScreencapOrInputMethods,
114
+ config: string,
115
+ agent_path: string,
116
+ callback: NotificationCallback | null
117
+ ): ControllerHandle | null
118
+ export declare function win32_controller_create(
119
+ handle: DesktopHandle,
120
+ screencap_methods: ScreencapOrInputMethods,
121
+ input_methods: ScreencapOrInputMethods,
122
+ callback: NotificationCallback | null
123
+ ): ControllerHandle | null
124
+ export declare function custom_controller_create(
125
+ custom_callback: CustomControllerCallback,
126
+ callback: NotificationCallback | null
127
+ ): ControllerHandle | null
128
+ export declare function dbg_controller_create(
129
+ read_path: string,
130
+ write_path: string,
131
+ type: Uint64,
132
+ config: string,
133
+ callback: NotificationCallback | null
134
+ ): ControllerHandle | null
135
+ export declare function controller_destroy(handle: ControllerHandle): void
136
+ export declare function controller_set_option_screenshot_target_long_side(
137
+ handle: ControllerHandle,
138
+ value: number
139
+ ): boolean
140
+ export declare function controller_set_option_screenshot_target_short_side(
141
+ handle: ControllerHandle,
142
+ value: number
143
+ ): boolean
144
+ export declare function controller_set_option_screenshot_use_raw_size(
145
+ handle: ControllerHandle,
146
+ value: boolean
147
+ ): boolean
148
+ export declare function controller_set_option_recording(
149
+ handle: ControllerHandle,
150
+ value: boolean
151
+ ): boolean
152
+ export declare function controller_post_connection(handle: ControllerHandle): CtrlId
153
+ export declare function controller_post_click(
154
+ handle: ControllerHandle,
155
+ x: number,
156
+ y: number
157
+ ): CtrlId
158
+ export declare function controller_post_swipe(
159
+ handle: ControllerHandle,
160
+ x1: number,
161
+ y1: number,
162
+ x2: number,
163
+ y2: number,
164
+ duration: number
165
+ ): CtrlId
166
+ export declare function controller_post_press_key(handle: ControllerHandle, keycode: number): CtrlId
167
+ export declare function controller_post_input_text(handle: ControllerHandle, text: string): CtrlId
168
+ export declare function controller_post_start_app(handle: ControllerHandle, intent: string): CtrlId
169
+ export declare function controller_post_stop_app(handle: ControllerHandle, intent: string): CtrlId
170
+ export declare function controller_post_touch_down(
171
+ handle: ControllerHandle,
172
+ contact: number,
173
+ x: number,
174
+ y: number,
175
+ pressure: number
176
+ ): CtrlId
177
+ export declare function controller_post_touch_move(
178
+ handle: ControllerHandle,
179
+ contact: number,
180
+ x: number,
181
+ y: number,
182
+ pressure: number
183
+ ): CtrlId
184
+ export declare function controller_post_touch_up(handle: ControllerHandle, contact: number): CtrlId
185
+ export declare function controller_post_screencap(handle: ControllerHandle): CtrlId
186
+ export declare function controller_status(handle: ControllerHandle, ctrl_id: CtrlId): Status
187
+ export declare function controller_wait(handle: ControllerHandle, ctrl_id: CtrlId): Promise<Status>
188
+ export declare function controller_connected(handle: ControllerHandle): boolean
189
+ export declare function controller_cached_image(handle: ControllerHandle): ImageData | null
190
+ export declare function controller_get_uuid(handle: ControllerHandle): string | null
191
+
192
+ // resource.cpp
193
+
194
+ export declare function resource_create(
195
+ callback: NotificationCallback | null
196
+ ): ResourceHandle | null
197
+ export declare function resource_destroy(handle: ResourceHandle): void
198
+ export declare function resource_set_option_inference_device(
199
+ handle: ResourceHandle,
200
+ id: InferenceDevice | number
201
+ ): boolean
202
+ export declare function resource_set_option_inference_execution_provider(
203
+ handle: ResourceHandle,
204
+ provider: InferenceExecutionProvider
205
+ ): boolean
206
+ export declare function resource_register_custom_recognition(
207
+ handle: ResourceHandle,
208
+ name: string,
209
+ recognizer: CustomRecognitionCallback
210
+ ): boolean
211
+ export declare function resource_unregister_custom_recognition(
212
+ handle: ResourceHandle,
213
+ name: string
214
+ ): boolean
215
+ export declare function resource_clear_custom_recognition(handle: ResourceHandle): boolean
216
+ export declare function resource_register_custom_action(
217
+ handle: ResourceHandle,
218
+ name: string,
219
+ action: CustomActionCallback
220
+ ): boolean
221
+ export declare function resource_unregister_custom_action(
222
+ handle: ResourceHandle,
223
+ name: string
224
+ ): boolean
225
+ export declare function resource_clear_custom_action(handle: ResourceHandle): boolean
226
+ export declare function resource_post_path(handle: ResourceHandle, path: string): ResId
227
+ export declare function resource_clear(handle: ResourceHandle): boolean
228
+ export declare function resource_status(handle: ResourceHandle, res_id: ResId): Status
229
+ export declare function resource_wait(handle: ResourceHandle, res_id: ResId): Promise<Status>
230
+ export declare function resource_loaded(handle: ResourceHandle): boolean
231
+ export declare function resource_get_hash(handle: ResourceHandle): string | null
232
+ export declare function resource_get_task_list(handle: ResourceHandle): string[] | null
233
+
234
+ // tasker.cpp
235
+
236
+ export declare function tasker_create(callback: NotificationCallback | null): TaskerHandle | null
237
+ export declare function tasker_destroy(handle: TaskerHandle): void
238
+ export declare function tasker_bind_resource(
239
+ handle: TaskerHandle,
240
+ resource: ResourceHandle | null
241
+ ): boolean
242
+ export declare function tasker_bind_controller(
243
+ handle: TaskerHandle,
244
+ controller: ControllerHandle | null
245
+ ): boolean
246
+ export declare function tasker_inited(handle: TaskerHandle): boolean
247
+ export declare function tasker_post_pipeline(
248
+ handle: TaskerHandle,
249
+ entry: string,
250
+ pipeline_override: string
251
+ ): TaskId
252
+ export declare function tasker_status(handle: TaskerHandle, task_id: TaskId): Status
253
+ export declare function tasker_wait(handle: TaskerHandle, task_id: TaskId): Promise<Status>
254
+ export declare function tasker_running(handle: TaskerHandle): boolean
255
+ export declare function tasker_post_stop(handle: TaskerHandle): TaskId
256
+ export declare function tasker_get_resource(handle: TaskerHandle): ResourceHandle | null
257
+ export declare function tasker_get_controller(handle: TaskerHandle): ControllerHandle | null
258
+ export declare function tasker_clear_cache(handle: TaskerHandle): boolean
259
+ export declare function tasker_get_recognition_detail(
260
+ handle: TaskerHandle,
261
+ reco_id: RecoId
262
+ ):
263
+ | [
264
+ name: string,
265
+ algorithm: string,
266
+ hit: boolean,
267
+ box: Rect,
268
+ detail: string,
269
+ raw: ImageData,
270
+ draws: ImageData[]
271
+ ]
272
+ | null
273
+ export declare function tasker_get_node_detail(
274
+ handle: TaskerHandle,
275
+ node_id: NodeId
276
+ ): [name: string, reco_id: RecoId, completed: boolean] | null
277
+ export declare function tasker_get_task_detail(
278
+ handle: TaskerHandle,
279
+ task_id: TaskId
280
+ ): [entry: string, node_ids: NodeId[], status: Status] | null
281
+ export declare function tasker_get_latest_node(
282
+ handle: TaskerHandle,
283
+ task_name: string
284
+ ): NodeId | null
285
+
286
+ // config.cpp
287
+
288
+ export declare function config_init_option(user_path: string, default_json: string): boolean
289
+
290
+ // find.cpp
291
+
292
+ export declare function find_adb(
293
+ adb_path: string | null
294
+ ): Promise<
295
+ | [
296
+ name: string,
297
+ adb_path: string,
298
+ address: string,
299
+ screencap_methods: ScreencapOrInputMethods,
300
+ input_methods: ScreencapOrInputMethods,
301
+ config: string
302
+ ][]
303
+ | null
304
+ >
305
+ export declare function find_desktop(): Promise<
306
+ [handle: DesktopHandle, class_name: string, window_name: string][] | null
307
+ >
308
+
309
+ // utility.cpp
310
+
311
+ export declare function version(): string
312
+ export declare function set_global_option_log_dir(value: string): boolean
313
+ export declare function set_global_option_save_draw(value: boolean): boolean
314
+ export declare function set_global_option_recording(value: boolean): boolean
315
+ export declare function set_global_option_stdout_level(value: LoggingLevel): boolean
316
+ export declare function set_global_option_show_hit_draw(value: boolean): boolean
317
+ export declare function set_global_option_debug_mode(value: boolean): boolean
318
+
319
+ // pi.cpp
320
+
321
+ export declare function pi_register_custom_recognizer(
322
+ id: Id,
323
+ name: string,
324
+ recognizer: CustomRecognitionCallback
325
+ ): void
326
+ export declare function pi_register_custom_action(
327
+ id: Id,
328
+ name: string,
329
+ action: CustomActionCallback
330
+ ): void
331
+ export declare function pi_run_cli(
332
+ id: Id,
333
+ resource_path: string,
334
+ user_path: string,
335
+ directly: boolean,
336
+ callback: NotificationCallback | null
337
+ ): Promise<boolean>
338
+
339
+ // export declare function unwrap_window_hwnd(hwnd: Win32Hwnd): string
340
+ // export declare function wrap_window_hwnd(hwnd: string): Win32Hwnd | null
341
+
342
+ export declare const Status: Record<
343
+ 'Invalid' | 'Pending' | 'Running' | 'Succeeded' | 'Failed',
344
+ Status
345
+ >
346
+ export declare const LoggingLevel: Record<
347
+ 'Off' | 'Fatal' | 'Error' | 'Warn' | 'Info' | 'Debug' | 'Trace' | 'All',
348
+ LoggingLevel
349
+ >
350
+ export declare const AdbScreencapMethod: Record<
351
+ | 'EncodeToFileAndPull'
352
+ | 'Encode'
353
+ | 'RawWithGzip'
354
+ | 'RawByNetcat'
355
+ | 'MinicapDirect'
356
+ | 'MinicapStream'
357
+ | 'EmulatorExtras'
358
+ | 'All'
359
+ | 'Default',
360
+ ScreencapOrInputMethods
361
+ >
362
+ export declare const AdbInputMethod: Record<
363
+ 'AdbShell' | 'MinitouchAndAdbKey' | 'Maatouch' | 'EmulatorExtras' | 'All' | 'Default',
364
+ ScreencapOrInputMethods
365
+ >
366
+ export declare const Win32ScreencapMethod: Record<
367
+ 'GDI' | 'FramePool' | 'DXGI_DesktopDup',
368
+ ScreencapOrInputMethods
369
+ >
370
+ export declare const Win32InputMethod: Record<'Seize' | 'SendMessage', ScreencapOrInputMethods>
371
+ export declare const DbgControllerType: Record<'CarouselImage' | 'ReplayRecording', Uint64>
372
+ export declare const InferenceDevice: Record<'CPU' | 'Auto', InferenceDevice>
373
+ export declare const InferenceExecutionProvider: Record<
374
+ 'Auto' | 'CPU' | 'DirectML' | 'CoreML' | 'CUDA',
375
+ InferenceExecutionProvider
376
+ >
package/src/maa.js ADDED
@@ -0,0 +1,27 @@
1
+ if (!globalThis.MaaAPI) {
2
+ switch (`${process.platform}-${process.arch}`) {
3
+ case 'win32-x64':
4
+ globalThis.MaaAPI = require('@maaxyz/maa-node-win32-x64')
5
+ break
6
+ case 'win32-arm64':
7
+ globalThis.MaaAPI = require('@maaxyz/maa-node-win32-arm64')
8
+ break
9
+ case 'linux-x64':
10
+ globalThis.MaaAPI = require('@maaxyz/maa-node-linux-x64')
11
+ break
12
+ case 'linux-arm64':
13
+ globalThis.MaaAPI = require('@maaxyz/maa-node-linux-arm64')
14
+ break
15
+ case 'darwin-x64':
16
+ globalThis.MaaAPI = require('@maaxyz/maa-node-darwin-x64')
17
+ break
18
+ case 'darwin-arm64':
19
+ globalThis.MaaAPI = require('@maaxyz/maa-node-darwin-arm64')
20
+ break
21
+ default:
22
+ globalThis.MaaAPI = {}
23
+ break
24
+ }
25
+ }
26
+
27
+ module.exports = globalThis.MaaAPI
package/src/pi.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { Context } from './context'
2
+ import * as maa from './maa'
3
+ import {
4
+ CustomActionCallback,
5
+ CustomActionSelf,
6
+ CustomRecognizerCallback,
7
+ CustomRecognizerSelf
8
+ } from './types'
9
+
10
+ export const Pi = {
11
+ __running: false,
12
+
13
+ notify(message: string, details_json: string): maa.MaybePromise<void> {},
14
+
15
+ register_custom_recognizer(id: maa.Id, name: string, func: CustomRecognizerCallback) {
16
+ maa.pi_register_custom_recognizer(id, name, (context, id, task, name, param, image, roi) => {
17
+ const self: CustomRecognizerSelf = {
18
+ context: new Context(context),
19
+ id,
20
+ task,
21
+ name,
22
+ param: JSON.parse(param),
23
+ image,
24
+ roi
25
+ }
26
+ return func.apply(self, [self])
27
+ })
28
+ },
29
+
30
+ register_custom_action(id: maa.Id, name: string, func: CustomActionCallback) {
31
+ maa.pi_register_custom_action(id, name, (context, id, task, name, param, recoId, box) => {
32
+ const self: CustomActionSelf = {
33
+ context: new Context(context),
34
+ id,
35
+ task,
36
+ name,
37
+ param: JSON.parse(param),
38
+ recoId,
39
+ box
40
+ }
41
+ return func.apply(self, [self])
42
+ })
43
+ },
44
+
45
+ async run_cli(id: maa.Id, resource_path: string, user_path: string, directly: boolean) {
46
+ if (Pi.__running) {
47
+ return false
48
+ }
49
+ Pi.__running = true
50
+ const res = await maa.pi_run_cli(
51
+ id,
52
+ resource_path,
53
+ user_path,
54
+ directly,
55
+ (message, details) => {
56
+ return Pi.notify(message, details)
57
+ }
58
+ )
59
+ Pi.__running = false
60
+ return res
61
+ }
62
+ }