@maaxyz/maa-node 4.5.6 → 5.0.0-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.
@@ -84,7 +84,6 @@ __export(index_server_exports, {
84
84
  DbgController: () => DbgController,
85
85
  Global: () => Global,
86
86
  Job: () => Job,
87
- Pi: () => Pi,
88
87
  Resource: () => Resource,
89
88
  ResourceBase: () => ResourceBase,
90
89
  TaskJob: () => TaskJob,
@@ -150,42 +149,6 @@ var Job = class {
150
149
  // src/controller.ts
151
150
  var import_path = __toESM(require("path"));
152
151
  var import_maa = __toESM(require_maa());
153
-
154
- // src/utils.ts
155
- function chain_notify_impl(cb, order = "after") {
156
- const old = this.notify;
157
- switch (order) {
158
- case "before":
159
- this.notify = async (msg, details) => {
160
- await cb(msg, details);
161
- await old.call(this, msg, details);
162
- };
163
- break;
164
- case "after":
165
- this.notify = async (msg, details) => {
166
- await old.call(this, msg, details);
167
- await cb(msg, details);
168
- };
169
- break;
170
- case "before-no-wait":
171
- this.notify = async (msg, details) => {
172
- cb(msg, details);
173
- await old.call(this, msg, details);
174
- };
175
- break;
176
- case "after-no-wait":
177
- this.notify = async (msg, details) => {
178
- await old.call(this, msg, details);
179
- cb(msg, details);
180
- };
181
- break;
182
- case "replace":
183
- this.notify = cb;
184
- break;
185
- }
186
- }
187
-
188
- // src/controller.ts
189
152
  var ImageJob = class extends Job {
190
153
  #ctrl;
191
154
  constructor(ctrl, source, id) {
@@ -212,19 +175,16 @@ var ImageJob = class extends Job {
212
175
  return pro;
213
176
  }
214
177
  };
215
- var ControllerBase = class {
178
+ var ControllerBase = class _ControllerBase {
216
179
  handle;
217
180
  #source;
218
- notify(message, details_json) {
219
- }
220
- chain_notify = chain_notify_impl;
221
- chain_parsed_notify(cb, order = "after") {
222
- this.chain_notify((msg, details) => {
223
- return cb({
181
+ static wrapSink(cb) {
182
+ return (ctrl, msg, details) => {
183
+ return cb(ctrl, {
224
184
  msg: msg.replace(/^Controller\./, ""),
225
185
  ...JSON.parse(details)
226
186
  });
227
- }, order);
187
+ };
228
188
  }
229
189
  constructor(handle) {
230
190
  this.handle = handle;
@@ -236,6 +196,24 @@ var ControllerBase = class {
236
196
  destroy() {
237
197
  import_maa.default.controller_destroy(this.handle);
238
198
  }
199
+ add_sink(cb) {
200
+ const ws = new WeakRef(this);
201
+ return import_maa.default.controller_add_sink(this.handle, (msg, details) => {
202
+ const ctrl = ws.deref();
203
+ if (ctrl) {
204
+ cb(ctrl, msg, details);
205
+ }
206
+ });
207
+ }
208
+ add_wrapped_sink(cb) {
209
+ return this.add_sink(_ControllerBase.wrapSink(cb));
210
+ }
211
+ remove_sink(sink_id) {
212
+ import_maa.default.controller_remove_sink(this.handle, sink_id);
213
+ }
214
+ clear_sinks() {
215
+ import_maa.default.controller_clear_sinks(this.handle);
216
+ }
239
217
  set screenshot_target_long_side(value) {
240
218
  if (!import_maa.default.controller_set_option_screenshot_target_long_side(this.handle, value)) {
241
219
  throw "Controller set screenshot_target_long_side failed";
@@ -311,23 +289,18 @@ var ControllerBase = class {
311
289
  };
312
290
  var AdbController = class _AdbController extends ControllerBase {
313
291
  constructor(adb_path, address, screencap_methods, input_methods, config, agent) {
314
- let ws;
315
292
  const h = import_maa.default.adb_controller_create(
316
293
  adb_path,
317
294
  address,
318
295
  screencap_methods,
319
296
  input_methods,
320
297
  config,
321
- agent ?? _AdbController.agent_path(),
322
- (message, details_json) => {
323
- return ws.deref()?.notify(message, details_json);
324
- }
298
+ agent ?? _AdbController.agent_path()
325
299
  );
326
300
  if (!h) {
327
301
  throw "AdbController create failed";
328
302
  }
329
303
  super(h);
330
- ws = new WeakRef(this);
331
304
  }
332
305
  static agent_path() {
333
306
  return import_path.default.join(__dirname, "..", "agent");
@@ -338,20 +311,15 @@ var AdbController = class _AdbController extends ControllerBase {
338
311
  };
339
312
  var Win32Controller = class extends ControllerBase {
340
313
  constructor(hwnd, screencap_methods, input_methods) {
341
- let ws;
342
314
  const h = import_maa.default.win32_controller_create(
343
315
  hwnd ?? "0",
344
316
  screencap_methods,
345
- input_methods,
346
- (message, details_json) => {
347
- return ws.deref()?.notify(message, details_json);
348
- }
317
+ input_methods
349
318
  );
350
319
  if (!h) {
351
320
  throw "Win32Controller create failed";
352
321
  }
353
322
  super(h);
354
- ws = new WeakRef(this);
355
323
  }
356
324
  static find() {
357
325
  return import_maa.default.find_desktop();
@@ -359,21 +327,11 @@ var Win32Controller = class extends ControllerBase {
359
327
  };
360
328
  var DbgController = class extends ControllerBase {
361
329
  constructor(read_path, write_path, type, config) {
362
- let ws;
363
- const h = import_maa.default.dbg_controller_create(
364
- read_path,
365
- write_path,
366
- type,
367
- config,
368
- (message, details_json) => {
369
- return ws.deref()?.notify(message, details_json);
370
- }
371
- );
330
+ const h = import_maa.default.dbg_controller_create(read_path, write_path, type, config);
372
331
  if (!h) {
373
332
  throw "DbgController create failed";
374
333
  }
375
334
  super(h);
376
- ws = new WeakRef(this);
377
335
  }
378
336
  };
379
337
  var CustomControllerActor = class {
@@ -424,20 +382,13 @@ var CustomControllerActorDefaultImpl = class extends CustomControllerActor {
424
382
  };
425
383
  var CustomController = class extends ControllerBase {
426
384
  constructor(actor) {
427
- let ws;
428
- const h = import_maa.default.custom_controller_create(
429
- (action, ...param) => {
430
- return actor[action](...param);
431
- },
432
- (message, details_json) => {
433
- return ws.deref()?.notify(message, details_json);
434
- }
435
- );
385
+ const h = import_maa.default.custom_controller_create((action, ...param) => {
386
+ return actor[action](...param);
387
+ });
436
388
  if (!h) {
437
389
  throw "CustomController create failed";
438
390
  }
439
391
  super(h);
440
- ws = new WeakRef(this);
441
392
  }
442
393
  };
443
394
 
@@ -472,19 +423,24 @@ var TaskJob = class extends Job {
472
423
  return pro;
473
424
  }
474
425
  };
475
- var TaskerBase = class {
426
+ var TaskerBase = class _TaskerBase {
476
427
  handle;
477
428
  #source;
478
- notify(message, details_json) {
429
+ static wrapSink(cb) {
430
+ return (tasker, msg, details) => {
431
+ return cb(tasker, {
432
+ msg: msg.replace(/^Tasker\./, ""),
433
+ ...JSON.parse(details)
434
+ });
435
+ };
479
436
  }
480
- chain_notify = chain_notify_impl;
481
- chain_parsed_notify(cb, order = "after") {
482
- this.chain_notify((msg, details) => {
483
- return cb({
484
- msg: msg.replace(/^(?:Tasker|Node)?\./, ""),
437
+ static wrapContextSink(cb) {
438
+ return (ctx, msg, details) => {
439
+ return cb(ctx, {
440
+ msg: msg.replace(/^Node\./, ""),
485
441
  ...JSON.parse(details)
486
442
  });
487
- }, order);
443
+ };
488
444
  }
489
445
  constructor(handle) {
490
446
  this.handle = handle;
@@ -496,6 +452,38 @@ var TaskerBase = class {
496
452
  destroy() {
497
453
  import_maa2.default.tasker_destroy(this.handle);
498
454
  }
455
+ add_sink(cb) {
456
+ const ws = new WeakRef(this);
457
+ return import_maa2.default.tasker_add_sink(this.handle, (msg, details) => {
458
+ const tasker = ws.deref();
459
+ if (tasker) {
460
+ cb(tasker, msg, details);
461
+ }
462
+ });
463
+ }
464
+ add_wrapped_sink(cb) {
465
+ return this.add_sink(_TaskerBase.wrapSink(cb));
466
+ }
467
+ remove_sink(sink_id) {
468
+ import_maa2.default.tasker_remove_sink(this.handle, sink_id);
469
+ }
470
+ clear_sinks() {
471
+ import_maa2.default.tasker_clear_sinks(this.handle);
472
+ }
473
+ add_context_sink(cb) {
474
+ return import_maa2.default.tasker_add_context_sink(this.handle, (ctx, msg, details) => {
475
+ cb(new Context(ctx), msg, details);
476
+ });
477
+ }
478
+ add_wrapped_context_sink(cb) {
479
+ return this.add_context_sink(_TaskerBase.wrapContextSink(cb));
480
+ }
481
+ remove_context_sink(sink_id) {
482
+ import_maa2.default.tasker_remove_context_sink(this.handle, sink_id);
483
+ }
484
+ clear_context_sinks() {
485
+ import_maa2.default.tasker_clear_context_sinks(this.handle);
486
+ }
499
487
  bind(slave) {
500
488
  let ret;
501
489
  if (slave instanceof ControllerBase) {
@@ -596,15 +584,11 @@ var TaskerBase = class {
596
584
  };
597
585
  var Tasker = class extends TaskerBase {
598
586
  constructor() {
599
- let ws;
600
- const h = import_maa2.default.tasker_create((message, details_json) => {
601
- return ws.deref()?.notify(message, details_json);
602
- });
587
+ const h = import_maa2.default.tasker_create();
603
588
  if (!h) {
604
589
  throw "Tasker create failed";
605
590
  }
606
591
  super(h);
607
- ws = new WeakRef(this);
608
592
  }
609
593
  };
610
594
 
@@ -676,19 +660,16 @@ var Context = class _Context {
676
660
 
677
661
  // src/resource.ts
678
662
  var import_maa3 = __toESM(require_maa());
679
- var ResourceBase = class {
663
+ var ResourceBase = class _ResourceBase {
680
664
  handle;
681
665
  #source;
682
- notify(message, details_json) {
683
- }
684
- chain_notify = chain_notify_impl;
685
- chain_parsed_notify(cb, order = "after") {
686
- this.chain_notify((msg, details) => {
687
- return cb({
666
+ static wrapSink(cb) {
667
+ return (res, msg, details) => {
668
+ return cb(res, {
688
669
  msg: msg.replace(/^Resource\./, ""),
689
670
  ...JSON.parse(details)
690
671
  });
691
- }, order);
672
+ };
692
673
  }
693
674
  constructor(handle) {
694
675
  this.handle = handle;
@@ -700,6 +681,24 @@ var ResourceBase = class {
700
681
  destroy() {
701
682
  import_maa3.default.resource_destroy(this.handle);
702
683
  }
684
+ add_sink(cb) {
685
+ const ws = new WeakRef(this);
686
+ return import_maa3.default.resource_add_sink(this.handle, (msg, details) => {
687
+ const res = ws.deref();
688
+ if (res) {
689
+ cb(res, msg, details);
690
+ }
691
+ });
692
+ }
693
+ add_wrapped_sink(cb) {
694
+ return this.add_sink(_ResourceBase.wrapSink(cb));
695
+ }
696
+ remove_sink(sink_id) {
697
+ import_maa3.default.resource_remove_sink(this.handle, sink_id);
698
+ }
699
+ clear_sinks() {
700
+ import_maa3.default.resource_clear_sinks(this.handle);
701
+ }
703
702
  set inference_device(id) {
704
703
  if (typeof id === "string") {
705
704
  id = import_maa3.default.InferenceDevice[id];
@@ -817,15 +816,11 @@ var ResourceBase = class {
817
816
  };
818
817
  var Resource = class extends ResourceBase {
819
818
  constructor() {
820
- let ws;
821
- const h = import_maa3.default.resource_create((message, details_json) => {
822
- return ws.deref()?.notify(message, details_json);
823
- });
819
+ const h = import_maa3.default.resource_create();
824
820
  if (!h) {
825
821
  throw "Resource create failed";
826
822
  }
827
823
  super(h);
828
- ws = new WeakRef(this);
829
824
  }
830
825
  };
831
826
 
@@ -862,68 +857,11 @@ var Global = {
862
857
  }
863
858
  };
864
859
 
865
- // src/pi.ts
866
- var maa7 = __toESM(require_maa());
867
- var Pi = {
868
- __running: false,
869
- notify(message, details_json) {
870
- },
871
- register_custom_recognizer(id, name, func) {
872
- maa7.pi_register_custom_recognizer(
873
- id,
874
- name,
875
- (context, id2, task, name2, param, image, roi) => {
876
- const self = {
877
- context: new Context(context),
878
- id: id2,
879
- task,
880
- name: name2,
881
- param: JSON.parse(param),
882
- image,
883
- roi
884
- };
885
- return func.apply(self, [self]);
886
- }
887
- );
888
- },
889
- register_custom_action(id, name, func) {
890
- maa7.pi_register_custom_action(id, name, (context, id2, task, name2, param, recoId, box) => {
891
- const self = {
892
- context: new Context(context),
893
- id: id2,
894
- task,
895
- name: name2,
896
- param: JSON.parse(param),
897
- recoId,
898
- box
899
- };
900
- return func.apply(self, [self]);
901
- });
902
- },
903
- async run_cli(id, resource_path, user_path, directly) {
904
- if (Pi.__running) {
905
- return false;
906
- }
907
- Pi.__running = true;
908
- const res = await maa7.pi_run_cli(
909
- id,
910
- resource_path,
911
- user_path,
912
- directly,
913
- (message, details) => {
914
- return Pi.notify(message, details);
915
- }
916
- );
917
- Pi.__running = false;
918
- return res;
919
- }
920
- };
921
-
922
860
  // src/server.ts
923
- var maa8 = __toESM(require_maa());
861
+ var maa7 = __toESM(require_maa());
924
862
  var AgentServer = {
925
863
  register_custom_recognizer(name, func) {
926
- maa8.agent_server_register_custom_recognition(
864
+ maa7.agent_server_register_custom_recognition(
927
865
  name,
928
866
  (context, id, task, name2, param, image, roi) => {
929
867
  const self = {
@@ -940,7 +878,7 @@ var AgentServer = {
940
878
  );
941
879
  },
942
880
  register_custom_action(name, func) {
943
- maa8.agent_server_register_custom_action(
881
+ maa7.agent_server_register_custom_action(
944
882
  name,
945
883
  (context, id, task, name2, param, recoId, box) => {
946
884
  const self = {
@@ -957,18 +895,18 @@ var AgentServer = {
957
895
  );
958
896
  },
959
897
  start_up(identifier) {
960
- if (!maa8.agent_server_start_up(identifier)) {
898
+ if (!maa7.agent_server_start_up(identifier)) {
961
899
  throw "AgentServer start up failed";
962
900
  }
963
901
  },
964
902
  shut_down() {
965
- maa8.agent_server_shut_down();
903
+ maa7.agent_server_shut_down();
966
904
  },
967
905
  async join() {
968
- await maa8.agent_server_join();
906
+ await maa7.agent_server_join();
969
907
  },
970
908
  detach() {
971
- maa8.agent_server_detach();
909
+ maa7.agent_server_detach();
972
910
  }
973
911
  };
974
912
  // Annotate the CommonJS export names for ESM import in node:
@@ -983,7 +921,6 @@ var AgentServer = {
983
921
  DbgController,
984
922
  Global,
985
923
  Job,
986
- Pi,
987
924
  Resource,
988
925
  ResourceBase,
989
926
  TaskJob,
package/dist/maa.d.ts CHANGED
@@ -14,6 +14,7 @@ export type CtrlId = Id & { __brand: 'CtrlId' }
14
14
  export type TaskId = Id & { __brand: 'TaskId' }
15
15
  export type RecoId = Id & { __brand: 'RecoId' }
16
16
  export type NodeId = Id & { __brand: 'NodeId' }
17
+ export type SinkId = Id & { __brand: 'SinkId' }
17
18
 
18
19
  export type Status = number & { __brand: 'Status' }
19
20
  export type LoggingLevel = number & { __brand: 'LoggingLevel' }
@@ -33,7 +34,12 @@ export type FlatRect = [x: number, y: number, width: number, height: number]
33
34
 
34
35
  type MaybePromise<T> = T | Promise<T>
35
36
 
36
- export type NotificationCallback = (message: string, details_json: string) => MaybePromise<void>
37
+ export type EventCallback = (message: string, details_json: string) => MaybePromise<void>
38
+ export type EventCallbackWithHandle<T> = (
39
+ handle: T,
40
+ message: string,
41
+ details_json: string
42
+ ) => MaybePromise<void>
37
43
  export type CustomRecognitionCallback = (
38
44
  context: ContextHandle,
39
45
  task_id: TaskId,
@@ -119,27 +125,29 @@ export declare function adb_controller_create(
119
125
  screencap_methods: ScreencapOrInputMethods,
120
126
  input_methods: ScreencapOrInputMethods,
121
127
  config: string,
122
- agent_path: string,
123
- callback: NotificationCallback | null
128
+ agent_path: string
124
129
  ): ControllerHandle | null
125
130
  export declare function win32_controller_create(
126
131
  handle: DesktopHandle,
127
132
  screencap_methods: ScreencapOrInputMethods,
128
- input_methods: ScreencapOrInputMethods,
129
- callback: NotificationCallback | null
133
+ input_methods: ScreencapOrInputMethods
130
134
  ): ControllerHandle | null
131
135
  export declare function custom_controller_create(
132
- custom_callback: CustomControllerCallback,
133
- callback: NotificationCallback | null
136
+ custom_callback: CustomControllerCallback
134
137
  ): ControllerHandle | null
135
138
  export declare function dbg_controller_create(
136
139
  read_path: string,
137
140
  write_path: string,
138
141
  type: Uint64,
139
- config: string,
140
- callback: NotificationCallback | null
142
+ config: string
141
143
  ): ControllerHandle | null
142
144
  export declare function controller_destroy(handle: ControllerHandle): void
145
+ export declare function controller_add_sink(
146
+ handle: ControllerHandle,
147
+ callback: EventCallback
148
+ ): SinkId
149
+ export declare function controller_remove_sink(handle: ControllerHandle, sink_id: SinkId): void
150
+ export declare function controller_clear_sinks(handle: ControllerHandle): void
143
151
  export declare function controller_set_option_screenshot_target_long_side(
144
152
  handle: ControllerHandle,
145
153
  value: number
@@ -196,10 +204,11 @@ export declare function controller_get_uuid(handle: ControllerHandle): string |
196
204
 
197
205
  // resource.cpp
198
206
 
199
- export declare function resource_create(
200
- callback: NotificationCallback | null
201
- ): ResourceHandle | null
207
+ export declare function resource_create(): ResourceHandle | null
202
208
  export declare function resource_destroy(handle: ResourceHandle): void
209
+ export declare function resource_add_sink(handle: ResourceHandle, callback: EventCallback): SinkId
210
+ export declare function resource_remove_sink(handle: ResourceHandle, sink_id: SinkId): void
211
+ export declare function resource_clear_sinks(handle: ResourceHandle): void
203
212
  export declare function resource_set_option_inference_device(
204
213
  handle: ResourceHandle,
205
214
  id: InferenceDevice | number
@@ -251,7 +260,16 @@ export declare function resource_get_node_list(handle: ResourceHandle): string[]
251
260
 
252
261
  // tasker.cpp
253
262
 
254
- export declare function tasker_create(callback: NotificationCallback | null): TaskerHandle | null
263
+ export declare function tasker_create(): TaskerHandle | null
264
+ export declare function tasker_add_sink(handle: TaskerHandle, callback: EventCallback): SinkId
265
+ export declare function tasker_remove_sink(handle: TaskerHandle, sink_id: SinkId): void
266
+ export declare function tasker_clear_sinks(handle: TaskerHandle): void
267
+ export declare function tasker_add_context_sink(
268
+ handle: TaskerHandle,
269
+ callback: EventCallbackWithHandle<ContextHandle>
270
+ ): SinkId
271
+ export declare function tasker_remove_context_sink(handle: TaskerHandle, sink_id: SinkId): void
272
+ export declare function tasker_clear_context_sinks(handle: TaskerHandle): void
255
273
  export declare function tasker_destroy(handle: TaskerHandle): void
256
274
  export declare function tasker_bind_resource(
257
275
  handle: TaskerHandle,
@@ -333,26 +351,6 @@ export declare function set_global_option_save_draw(value: boolean): boolean
333
351
  export declare function set_global_option_stdout_level(value: LoggingLevel): boolean
334
352
  export declare function set_global_option_debug_mode(value: boolean): boolean
335
353
 
336
- // pi.cpp
337
-
338
- export declare function pi_register_custom_recognizer(
339
- id: Id,
340
- name: string,
341
- recognizer: CustomRecognitionCallback
342
- ): void
343
- export declare function pi_register_custom_action(
344
- id: Id,
345
- name: string,
346
- action: CustomActionCallback
347
- ): void
348
- export declare function pi_run_cli(
349
- id: Id,
350
- resource_path: string,
351
- user_path: string,
352
- directly: boolean,
353
- callback: NotificationCallback | null
354
- ): Promise<boolean>
355
-
356
354
  export declare const Status: Record<
357
355
  'Invalid' | 'Pending' | 'Running' | 'Succeeded' | 'Failed',
358
356
  Status
@@ -400,6 +398,12 @@ export declare function agent_client_bind_resource(
400
398
  handle: AgentClientHandle,
401
399
  resource: ResourceHandle
402
400
  ): boolean
401
+ export declare function agent_client_register_sink(
402
+ handle: AgentClientHandle,
403
+ tasker: TaskerHandle | null,
404
+ resource: ResourceHandle | null,
405
+ controller: ControllerHandle | null
406
+ ): boolean
403
407
  export declare function agent_client_connect(handle: AgentClientHandle): Promise<boolean>
404
408
  export declare function agent_client_disconnect(handle: AgentClientHandle): boolean
405
409
  export declare function agent_client_connected(handle: AgentClientHandle): boolean
@@ -1,8 +1,7 @@
1
1
  import { Job, JobSource } from './job';
2
2
  import maa from './maa';
3
3
  import { DumpTask } from './pipeline';
4
- import { ChainNotifyType, CustomActionCallback, CustomRecognizerCallback } from './types';
5
- import { chain_notify_impl } from './utils';
4
+ import { CustomActionCallback, CustomRecognizerCallback } from './types';
6
5
  export type ResourceNotify = {
7
6
  msg: 'Loading.Starting' | 'Loading.Succeeded' | 'Loading.Failed';
8
7
  res_id: maa.ResId;
@@ -12,11 +11,13 @@ export type ResourceNotify = {
12
11
  export declare class ResourceBase {
13
12
  #private;
14
13
  handle: maa.ResourceHandle;
15
- notify(message: string, details_json: string): maa.MaybePromise<void>;
16
- chain_notify: typeof chain_notify_impl;
17
- chain_parsed_notify(cb: (msg: ResourceNotify) => maa.MaybePromise<void>, order?: ChainNotifyType): void;
14
+ static wrapSink(cb: (res: ResourceBase, msg: ResourceNotify) => maa.MaybePromise<void>): (res: ResourceBase, msg: string, details: string) => maa.MaybePromise<void>;
18
15
  constructor(handle: maa.ResourceHandle);
19
16
  destroy(): void;
17
+ add_sink(cb: maa.EventCallbackWithHandle<ResourceBase>): maa.SinkId;
18
+ add_wrapped_sink(cb: (ctrl: ResourceBase, msg: ResourceNotify) => maa.MaybePromise<void>): maa.SinkId;
19
+ remove_sink(sink_id: maa.SinkId): void;
20
+ clear_sinks(): void;
20
21
  set inference_device(id: keyof typeof maa.InferenceDevice | number);
21
22
  set inference_execution_provider(provider: keyof typeof maa.InferenceExecutionProvider);
22
23
  register_custom_recognizer(name: string, func: CustomRecognizerCallback): void;
package/dist/tasker.d.ts CHANGED
@@ -1,9 +1,8 @@
1
+ import { Context } from './context';
1
2
  import { ControllerBase } from './controller';
2
3
  import { Job, JobSource } from './job';
3
4
  import maa from './maa';
4
5
  import { ResourceBase } from './resource';
5
- import { ChainNotifyType } from './types';
6
- import { chain_notify_impl } from './utils';
7
6
  type TaskDetail = ReturnType<TaskerBase['task_detail']>;
8
7
  type RecoDetailEntry = {
9
8
  box: maa.FlatRect;
@@ -54,7 +53,8 @@ export type TaskerNotify = {
54
53
  entry: string;
55
54
  uuid: string;
56
55
  hash: string;
57
- } | {
56
+ };
57
+ export type TaskerContextNotify = {
58
58
  msg: 'NextList.Starting' | 'NextList.Succeeded' | 'NextList.Failed';
59
59
  task_id: maa.TaskId;
60
60
  name: string;
@@ -76,11 +76,18 @@ export type TaskerNotify = {
76
76
  export declare class TaskerBase {
77
77
  #private;
78
78
  handle: maa.TaskerHandle;
79
- notify(message: string, details_json: string): maa.MaybePromise<void>;
80
- chain_notify: typeof chain_notify_impl;
81
- chain_parsed_notify(cb: (msg: TaskerNotify) => maa.MaybePromise<void>, order?: ChainNotifyType): void;
79
+ static wrapSink(cb: (tasker: TaskerBase, msg: TaskerNotify) => maa.MaybePromise<void>): (tasker: TaskerBase, msg: string, details: string) => maa.MaybePromise<void>;
80
+ static wrapContextSink(cb: (ctx: Context, msg: TaskerContextNotify) => maa.MaybePromise<void>): (ctx: Context, msg: string, details: string) => maa.MaybePromise<void>;
82
81
  constructor(handle: maa.TaskerHandle);
83
82
  destroy(): void;
83
+ add_sink(cb: maa.EventCallbackWithHandle<TaskerBase>): maa.SinkId;
84
+ add_wrapped_sink(cb: (tasker: TaskerBase, msg: TaskerNotify) => maa.MaybePromise<void>): maa.SinkId;
85
+ remove_sink(sink_id: maa.SinkId): void;
86
+ clear_sinks(): void;
87
+ add_context_sink(cb: maa.EventCallbackWithHandle<Context>): maa.SinkId;
88
+ add_wrapped_context_sink(cb: (ctx: Context, msg: TaskerContextNotify) => maa.MaybePromise<void>): maa.SinkId;
89
+ remove_context_sink(sink_id: maa.SinkId): void;
90
+ clear_context_sinks(): void;
84
91
  bind(slave: ControllerBase | ResourceBase): void;
85
92
  post_task(entry: string, param?: Record<string, unknown> | Record<string, unknown>[]): TaskJob;
86
93
  get inited(): boolean;
package/dist/types.d.ts CHANGED
@@ -24,5 +24,4 @@ export type CustomRecognizerCallback = CustomCallback<CustomRecognizerSelf, [
24
24
  out_detail: string
25
25
  ] | null>;
26
26
  export type CustomActionCallback = CustomCallback<CustomActionSelf, boolean>;
27
- export type ChainNotifyType = 'before' | 'after' | 'before-no-wait' | 'after-no-wait' | 'replace';
28
27
  export {};
package/package.json CHANGED
@@ -25,13 +25,13 @@
25
25
  "prettier": "^3.5.2",
26
26
  "typescript": "^5.8.2"
27
27
  },
28
- "version": "4.5.6",
28
+ "version": "5.0.0-alpha.1",
29
29
  "optionalDependencies": {
30
- "@maaxyz/maa-node-darwin-arm64": "4.5.6",
31
- "@maaxyz/maa-node-darwin-x64": "4.5.6",
32
- "@maaxyz/maa-node-linux-arm64": "4.5.6",
33
- "@maaxyz/maa-node-linux-x64": "4.5.6",
34
- "@maaxyz/maa-node-win32-arm64": "4.5.6",
35
- "@maaxyz/maa-node-win32-x64": "4.5.6"
30
+ "@maaxyz/maa-node-darwin-arm64": "5.0.0-alpha.1",
31
+ "@maaxyz/maa-node-darwin-x64": "5.0.0-alpha.1",
32
+ "@maaxyz/maa-node-linux-arm64": "5.0.0-alpha.1",
33
+ "@maaxyz/maa-node-linux-x64": "5.0.0-alpha.1",
34
+ "@maaxyz/maa-node-win32-arm64": "5.0.0-alpha.1",
35
+ "@maaxyz/maa-node-win32-x64": "5.0.0-alpha.1"
36
36
  }
37
37
  }