dsh-multigameassistant 2.3.1 → 2.3.3

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/lib/qqbot.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { createRequire as __adgCreateRequire } from 'node:module'; import { dirname as __adgDirname } from 'node:path'; import { fileURLToPath as __adgFileURLToPath } from 'node:url'; const require = __adgCreateRequire(import.meta.url); const __filename = __adgFileURLToPath(import.meta.url); const __dirname = __adgDirname(__filename);
2
2
  import {
3
3
  approvalText,
4
+ finalKey,
4
5
  questionText,
5
6
  replyMarkdown,
6
- replyPlain
7
- } from "./chunk-4QXRDWGS.js";
8
- import "./chunk-QSETYM2Y.js";
9
- import "./chunk-M7GNYL5B.js";
7
+ replyPlain,
8
+ replyRest
9
+ } from "./chunk-RREVLKRY.js";
10
+ import "./chunk-OCJFAT7J.js";
11
+ import "./chunk-4NR36PKL.js";
10
12
  import {
11
13
  writeFileAtomic
12
14
  } from "./chunk-RESS7WVY.js";
@@ -15,7 +17,7 @@ import {
15
17
  QQBOT_SECRET_REF,
16
18
  QQPending,
17
19
  QQSettings
18
- } from "./chunk-34VNH3YS.js";
20
+ } from "./chunk-BB2T4JHF.js";
19
21
  import {
20
22
  external_exports
21
23
  } from "./chunk-6DSSLS7I.js";
@@ -47,7 +49,9 @@ var HINTS = {
47
49
  11265: "\u673A\u5668\u4EBA\u5DF2\u88AB\u5C01\u7981",
48
50
  40034005: "\u8981\u56DE\u590D\u7684\u6D88\u606F\u5DF2\u7ECF\u8FC7\u671F",
49
51
  22009: "\u6D88\u606F\u53D1\u9001\u592A\u9891\u7E41\uFF0C\u88AB\u9650\u5236\u4E86",
50
- 40054005: "\u5BF9\u65B9\u5173\u95ED\u4E86\u673A\u5668\u4EBA\u7684\u4E3B\u52A8\u6D88\u606F"
52
+ 40054005: "\u5BF9\u65B9\u5173\u95ED\u4E86\u673A\u5668\u4EBA\u7684\u4E3B\u52A8\u6D88\u606F",
53
+ 40007: "\u6D41\u5F0F\u6D88\u606F\u5DF2\u7ECF\u663E\u793A\u7684\u5F00\u5934\u4E0D\u80FD\u6539",
54
+ 50002: "\u6D41\u5F0F\u6D88\u606F\u53D1\u5F97\u592A\u9891\u7E41\uFF0C\u88AB\u9650\u5236\u4E86"
51
55
  };
52
56
  var FATAL_CLOSE = {
53
57
  4004: "\u9274\u6743\u5931\u8D25\uFF1AAppID \u6216 AppSecret \u4E0D\u5BF9",
@@ -193,6 +197,20 @@ function httpApi(options) {
193
197
  token,
194
198
  sendText: (openId, text, reply) => sendMessage(openId, { text }, reply),
195
199
  sendMessage,
200
+ async streamMessage(openId, piece) {
201
+ const sent = await request("\u53D1\u9001\u6D41\u5F0F\u6D88\u606F", "POST", `/v2/users/${encodeURIComponent(openId)}/stream_messages`, {
202
+ input_mode: "replace",
203
+ input_state: piece.done ? 10 : 1,
204
+ index: piece.index,
205
+ content_type: "markdown",
206
+ content_raw: piece.text,
207
+ msg_id: piece.reply.msgId,
208
+ msg_seq: piece.reply.seq,
209
+ ...piece.streamId === void 0 ? {} : { stream_msg_id: piece.streamId },
210
+ ...piece.wakeup === true ? { is_wakeup: true } : {}
211
+ });
212
+ return sent.id ?? piece.streamId ?? "";
213
+ },
196
214
  async connect(handlers, onState) {
197
215
  closed = false;
198
216
  await open(handlers, onState);
@@ -236,6 +254,10 @@ var DEFAULT_QQ = { enabled: false, allowedUsers: [] };
236
254
  var KEEP_PENDING = 20;
237
255
  var RETRY_DELAYS_MS = [5e3, 15e3, 3e4, 6e4, 3e5];
238
256
  var PASSIVE_MS = 55 * 6e4;
257
+ var MAX_REPLIES = 5;
258
+ var STREAM_EVERY_MS = 400;
259
+ var STREAM_TOO_FAST = 50002;
260
+ var KEEP_GOT = 200;
239
261
  var QQBot = class {
240
262
  id = "qq";
241
263
  name = "QQ";
@@ -246,7 +268,14 @@ var QQBot = class {
246
268
  #error;
247
269
  #checks = [];
248
270
  #secretConfigured = false;
249
- #queues = /* @__PURE__ */ new Map();
271
+ /** Each person's messages out, one after another: what 助手 says arrives in the order it said it. */
272
+ #outbox = /* @__PURE__ */ new Map();
273
+ /** Each person's latest message: what goes to them is a reply to it while QQ takes one. */
274
+ #replyTo = /* @__PURE__ */ new Map();
275
+ /** What of 助手's words each person got (reply.ts keys): answers to two messages following one turn, and the mirror, say each thing once. */
276
+ #got = /* @__PURE__ */ new Map();
277
+ /** Messages being typed, by `openId:attempt`. */
278
+ #streams = /* @__PURE__ */ new Map();
250
279
  /** Approvals and questions asked of a person here: id → their user_openid. */
251
280
  #asked = /* @__PURE__ */ new Map();
252
281
  /** What QQ took or refused since connecting (undefined: not tried yet). */
@@ -333,6 +362,9 @@ var QQBot = class {
333
362
  this.#api?.close();
334
363
  this.#api = void 0;
335
364
  this.#connection = "idle";
365
+ for (const stream of this.#streams.values())
366
+ clearTimeout(stream.timer);
367
+ this.#streams.clear();
336
368
  }
337
369
  // ── settings ──────────────────────────────────────────────────────────
338
370
  async configure(patch) {
@@ -360,7 +392,7 @@ var QQBot = class {
360
392
  await this.#options.save(this.#state);
361
393
  this.#setCheck("users", true);
362
394
  this.#options.changed();
363
- await this.#api?.sendText(openId, "\u4F60\u5DF2\u88AB\u5141\u8BB8\u4F7F\u7528 MultiGameAssistant \u673A\u5668\u4EBA\uFF1A\u548C\u52A9\u624B\u7684\u5BF9\u8BDD\u4F1A\u540C\u6B65\u5230\u8FD9\u91CC\uFF0C\u811A\u672C\u51FA\u95EE\u9898\u65F6\u4E5F\u4F1A\u901A\u77E5\u4F60\u3002\u76F4\u63A5\u53D1\u6D88\u606F\u5C31\u80FD\u8BA9\u5B83\u5E72\u6D3B\uFF0C\u4F8B\u5982\u300C\u73B0\u5728\u4EC0\u4E48\u72B6\u6001\u300D\u3002").catch(() => {
395
+ await this.#api?.sendText(openId, "\u4F60\u5DF2\u88AB\u5141\u8BB8\u4F7F\u7528 MultiGameAssistant \u673A\u5668\u4EBA\uFF1A\u548C MultiGameAssistant \u7684\u5BF9\u8BDD\u4F1A\u540C\u6B65\u5230\u8FD9\u91CC\uFF0C\u811A\u672C\u51FA\u95EE\u9898\u65F6\u4E5F\u4F1A\u901A\u77E5\u4F60\u3002\u76F4\u63A5\u53D1\u6D88\u606F\u5C31\u80FD\u8BA9\u5B83\u5E72\u6D3B\uFF0C\u4F8B\u5982\u300C\u73B0\u5728\u4EC0\u4E48\u72B6\u6001\u300D\u3002").catch(() => {
364
396
  });
365
397
  }
366
398
  /** Take someone off the list, or dismiss them from the pending ones. */
@@ -414,7 +446,7 @@ var QQBot = class {
414
446
  }
415
447
  // ── out ───────────────────────────────────────────────────────────────
416
448
  async send(notice) {
417
- const api = this.#ready();
449
+ this.#ready();
418
450
  const people = this.#state.settings.allowedUsers;
419
451
  if (people.length === 0)
420
452
  throw new Error("\u8FD8\u6CA1\u6709\u5141\u8BB8\u4EFB\u4F55 QQ \u7528\u6237");
@@ -422,7 +454,7 @@ var QQBot = class {
422
454
  let delivered = 0;
423
455
  for (const { openId } of people) {
424
456
  try {
425
- await this.#deliver(api, openId, noticeMessage(notice));
457
+ await this.#post(openId, noticeMessage(notice));
426
458
  delivered++;
427
459
  } catch (error) {
428
460
  errors.push(message(error));
@@ -434,22 +466,27 @@ var QQBot = class {
434
466
  async sendTo(openId, notice) {
435
467
  if (!this.#allowed(openId))
436
468
  throw new Error("\u8FD9\u4E2A QQ \u7528\u6237\u6CA1\u6709\u88AB\u5141\u8BB8");
437
- await this.#ready().sendText(openId, noticeText(notice));
469
+ this.#ready();
470
+ await this.#post(openId, noticeText(notice));
438
471
  }
439
- /** 助手's conversation, to each allowed person but `except`. */
472
+ /** 助手's conversation, to each allowed person but `except`, and but whoever got these words already. */
440
473
  async mirror(post, except) {
441
- const api = this.#ready();
474
+ this.#ready();
475
+ const message2 = post.markdown === true ? { markdown: post.text, plain: plainText(post.text) } : { markdown: post.text, plain: post.text };
476
+ const sends = [];
442
477
  for (const { openId } of this.#state.settings.allowedUsers) {
443
- if (openId === except)
478
+ if (openId === except || !this.#first(openId, post.key))
444
479
  continue;
445
- await this.#deliver(api, openId, post.markdown === true ? { markdown: post.text, plain: plainText(post.text) } : { markdown: post.text, plain: post.text });
480
+ sends.push(this.#post(openId, message2));
446
481
  }
482
+ await Promise.all(sends);
447
483
  }
448
484
  /** A conversation's approvals, to its person only, as text; other sessions' stay in the app. */
449
485
  approvals = {
450
486
  active: (owner) => owner !== void 0 && this.#connection === "connected" && this.#allowed(owner),
451
487
  ask: async (request, owner) => {
452
- await this.#deliver(this.#ready(), owner, approvalMessage(request));
488
+ this.#ready();
489
+ await this.#post(owner, approvalMessage(request));
453
490
  this.#asked.set(request.approvalId, owner);
454
491
  },
455
492
  resolved: async (approvalId, outcome) => this.#settled(approvalId, outcome === "cancelled" ? "agent \u5DF2\u53D6\u6D88\u8FD9\u4E2A\u64CD\u4F5C" : outcome === "unavailable" ? "\u8FD9\u4E2A\u786E\u8BA4\u5DF2\u5931\u6548" : void 0)
@@ -458,7 +495,8 @@ var QQBot = class {
458
495
  questions = {
459
496
  active: (owner) => this.approvals.active(owner),
460
497
  ask: async (request, owner) => {
461
- await this.#deliver(this.#ready(), owner, questionMessage(request));
498
+ this.#ready();
499
+ await this.#post(owner, questionMessage(request));
462
500
  this.#asked.set(request.questionId, owner);
463
501
  },
464
502
  resolved: async (questionId, outcome) => this.#settled(questionId, outcome === "cancelled" ? "agent \u4E0D\u518D\u7B49\u8FD9\u4E2A\u56DE\u7B54\u4E86" : outcome === "unavailable" ? "\u8FD9\u4E2A\u95EE\u9898\u5DF2\u5931\u6548" : void 0)
@@ -469,8 +507,191 @@ var QQBot = class {
469
507
  this.#asked.delete(id);
470
508
  if (owner === void 0 || note === void 0 || this.#api === void 0)
471
509
  return;
472
- await this.#api.sendText(owner, `\uFF08${note}\uFF09`).catch(() => {
510
+ await this.#post(owner, `\uFF08${note}\uFF09`).catch(() => {
511
+ });
512
+ }
513
+ /**
514
+ * To one person, after what is already on its way to them: as a reply to their latest message while QQ
515
+ * takes one, else (or when QQ refuses the reply) as an active message.
516
+ */
517
+ #post(openId, message2) {
518
+ return this.#enqueue(openId, () => this.#sendNow(openId, message2));
519
+ }
520
+ /** Run `job` for this person after what is already on its way to them. */
521
+ #enqueue(openId, job) {
522
+ const next = (this.#outbox.get(openId) ?? Promise.resolve()).catch(() => {
523
+ }).then(job);
524
+ this.#outbox.set(openId, next);
525
+ void next.catch(() => {
526
+ }).then(() => {
527
+ if (this.#outbox.get(openId) === next)
528
+ this.#outbox.delete(openId);
473
529
  });
530
+ return next;
531
+ }
532
+ async #sendNow(openId, message2) {
533
+ const api = this.#ready();
534
+ const send = async (reply2) => {
535
+ if (typeof message2 === "string")
536
+ await api.sendText(openId, message2, reply2);
537
+ else
538
+ await this.#deliver(api, openId, message2, reply2);
539
+ };
540
+ const reply = this.#nextReply(openId);
541
+ if (reply === void 0)
542
+ return send();
543
+ try {
544
+ await send(reply);
545
+ } catch {
546
+ this.#replyTo.delete(openId);
547
+ await send();
548
+ }
549
+ }
550
+ // ── typing: QQ's streamed messages ────────────────────────────────────
551
+ /** 助手's words while it types them: one QQ message that fills in, kept up to date about once a second. */
552
+ #typing(openId, typing) {
553
+ const at = `${openId}:${typing.id}`;
554
+ const stream = this.#streams.get(at);
555
+ if (typing.kind !== "typing") {
556
+ this.#streams.delete(at);
557
+ if (stream === void 0)
558
+ return;
559
+ if (typing.kind === "committed" && this.#first(openId, typing.key)) {
560
+ const words = typing.key.slice(typing.key.indexOf(":") + 1);
561
+ void this.#finish(stream, words, { markdown: words, plain: plainText(words) }).catch(() => {
562
+ });
563
+ return;
564
+ }
565
+ void this.#finish(stream, typing.kind === "dropped" && stream.want !== "" ? `${stream.want}\u2026` : stream.want, void 0).catch(() => {
566
+ });
567
+ return;
568
+ }
569
+ if (stream === void 0) {
570
+ if (this.#formats.stream === false || this.#formats.markdown === false)
571
+ return;
572
+ const reply = this.#streamReply(openId);
573
+ if (reply === void 0)
574
+ return;
575
+ const started = { openId, ...reply, id: void 0, index: 0, shown: "", want: typing.text, last: 0, timer: void 0, closing: void 0, broken: false };
576
+ this.#streams.set(at, started);
577
+ this.#schedule(started);
578
+ return;
579
+ }
580
+ if (stream.closing !== void 0 || stream.broken)
581
+ return;
582
+ stream.want = typing.text;
583
+ this.#schedule(stream);
584
+ }
585
+ /**
586
+ * The message still being typed whose words `text` turned out to be (they, or the summary that starts
587
+ * with them): the words were said before the stream's end came. Taken, to be closed with `text`.
588
+ */
589
+ #typed(openId, key, text) {
590
+ if (key === void 0)
591
+ return void 0;
592
+ for (const [at, stream] of this.#streams) {
593
+ if (stream.openId !== openId || stream.closing !== void 0 || stream.want === "" || !text.startsWith(stream.want))
594
+ continue;
595
+ this.#streams.delete(at);
596
+ return stream;
597
+ }
598
+ return void 0;
599
+ }
600
+ /** A stream is a reply to the person's latest message: while QQ takes replies to it, else as a wake-up (is_wakeup). */
601
+ #streamReply(openId) {
602
+ const passive = this.#nextReply(openId);
603
+ if (passive !== void 0)
604
+ return { reply: passive, wakeup: false };
605
+ const latest = this.#replyTo.get(openId);
606
+ return latest === void 0 ? void 0 : { reply: { msgId: latest.msgId, seq: ++latest.seq }, wakeup: true };
607
+ }
608
+ #schedule(stream) {
609
+ if (stream.timer !== void 0)
610
+ return;
611
+ const wait = Math.max(0, stream.last + (this.#options.streamEveryMs ?? STREAM_EVERY_MS) - Date.now());
612
+ stream.timer = setTimeout(() => {
613
+ stream.timer = void 0;
614
+ void this.#enqueue(stream.openId, () => this.#piece(stream)).catch(() => {
615
+ });
616
+ }, wait);
617
+ stream.timer.unref?.();
618
+ }
619
+ /**
620
+ * Close a typed message with `text` (what its words became). When QQ cannot show them there (the text
621
+ * no longer starts with what it shows, or QQ refuses), `instead` goes as a message of its own.
622
+ */
623
+ #finish(stream, text, instead) {
624
+ clearTimeout(stream.timer);
625
+ stream.timer = void 0;
626
+ stream.want = text;
627
+ stream.closing = instead ?? { markdown: "", plain: "" };
628
+ return this.#enqueue(stream.openId, () => this.#piece(stream));
629
+ }
630
+ /** Bring a typed message up to date, or close it; runs in the person's outbox. */
631
+ async #piece(stream) {
632
+ const closing = stream.closing;
633
+ if (closing === void 0 && (stream.broken || stream.want === stream.shown || !stream.want.startsWith(stream.shown)))
634
+ return;
635
+ if (closing !== void 0 && stream.index < 0)
636
+ return;
637
+ const instead = closing !== void 0 && closing.markdown !== "" ? closing : void 0;
638
+ if (closing !== void 0 && (stream.broken || stream.id === void 0 && (instead === void 0 || stream.want === ""))) {
639
+ stream.index = -1;
640
+ if (instead !== void 0)
641
+ await this.#sendNow(stream.openId, instead);
642
+ return;
643
+ }
644
+ const fits = stream.want.startsWith(stream.shown);
645
+ const text = fits ? stream.want : stream.shown;
646
+ const done = closing !== void 0;
647
+ try {
648
+ const id = await this.#ready().streamMessage(stream.openId, { text, index: stream.index, done, streamId: stream.id, reply: stream.reply, wakeup: stream.wakeup });
649
+ stream.id ??= id;
650
+ stream.index = done ? -1 : stream.index + 1;
651
+ stream.shown = text;
652
+ stream.last = Date.now();
653
+ this.#formats.stream = true;
654
+ if (done && !fits && instead !== void 0)
655
+ await this.#sendNow(stream.openId, instead);
656
+ } catch (error) {
657
+ if (!done && error instanceof QQError && error.code === STREAM_TOO_FAST) {
658
+ stream.last = Date.now();
659
+ this.#schedule(stream);
660
+ return;
661
+ }
662
+ const first = stream.id === void 0;
663
+ stream.broken = true;
664
+ if (first && !stream.wakeup && error instanceof QQError && this.#formats.stream !== true) {
665
+ this.#formats.stream = false;
666
+ this.#options.log.info(`qq: streamed messages not accepted (${errorText(error)}), sending each part when it is said`);
667
+ }
668
+ if (done) {
669
+ stream.index = -1;
670
+ if (instead !== void 0)
671
+ await this.#sendNow(stream.openId, instead);
672
+ }
673
+ }
674
+ }
675
+ /** The next reply to this person's latest message, while QQ takes one. */
676
+ #nextReply(openId) {
677
+ const latest = this.#replyTo.get(openId);
678
+ if (latest === void 0 || Date.now() - latest.at >= PASSIVE_MS || latest.seq >= MAX_REPLIES)
679
+ return void 0;
680
+ return { msgId: latest.msgId, seq: ++latest.seq };
681
+ }
682
+ /** @returns whether these words (a reply.ts key) are new to this person, noting that they now have them; no key: always new. */
683
+ #first(openId, key) {
684
+ if (key === void 0)
685
+ return true;
686
+ let got = this.#got.get(openId);
687
+ if (got === void 0)
688
+ this.#got.set(openId, got = /* @__PURE__ */ new Set());
689
+ if (got.has(key))
690
+ return false;
691
+ got.add(key);
692
+ if (got.size > KEEP_GOT)
693
+ got.delete(got.values().next().value);
694
+ return true;
474
695
  }
475
696
  /**
476
697
  * Send as markdown with its buttons; what QQ refuses is dropped — the buttons, then markdown — and not
@@ -520,49 +741,62 @@ ${replyHint(message2.buttons)}` : message2.plain, reply);
520
741
  });
521
742
  return;
522
743
  }
744
+ this.#replyTo.set(event.openId, { msgId: event.id, at: Date.now(), seq: 0 });
523
745
  if (event.text === "") {
524
- void api.sendText(event.openId, "\u76EE\u524D\u53EA\u770B\u5F97\u61C2\u6587\u5B57\u6D88\u606F\u3002", { msgId: event.id, seq: 1 }).catch(() => {
746
+ void this.#post(event.openId, "\u76EE\u524D\u53EA\u770B\u5F97\u61C2\u6587\u5B57\u6D88\u606F\u3002").catch(() => {
525
747
  });
526
748
  return;
527
749
  }
528
- if (this.#options.notify()?.waiting?.(this.#actor(event)) === true) {
529
- void this.#answer(api, event).catch((error) => this.#options.log.warn(`qq reply failed: ${message(error)}`));
530
- return;
531
- }
532
- const previous = this.#queues.get(event.openId) ?? Promise.resolve();
533
- const next = previous.then(() => this.#answer(api, event)).catch((error) => this.#options.log.warn(`qq reply failed: ${message(error)}`));
534
- this.#queues.set(event.openId, next);
535
- void next.then(() => {
536
- if (this.#queues.get(event.openId) === next)
537
- this.#queues.delete(event.openId);
538
- });
750
+ void this.#answer(event).catch((error) => this.#options.log.warn(`qq reply failed: ${message(error)}`));
539
751
  }
540
- async #answer(api, event) {
752
+ async #answer(event) {
753
+ const { openId } = event;
541
754
  const notify = this.#options.notify();
542
- const started = Date.now();
543
- let seq = 0;
544
- const passive = () => Date.now() - started < PASSIVE_MS ? { msgId: event.id, seq: ++seq } : void 0;
545
- const reply = (text) => api.sendText(event.openId, text, passive());
546
755
  if (notify === void 0) {
547
- await reply("\u6D88\u606F\u670D\u52A1\u6CA1\u6709\u52A0\u8F7D\u3002");
756
+ await this.#post(openId, "\u6D88\u606F\u670D\u52A1\u6CA1\u6709\u52A0\u8F7D\u3002");
548
757
  return;
549
758
  }
550
- let answered = false;
759
+ let heard = false;
551
760
  const ack = setTimeout(() => {
552
- if (!answered)
553
- void reply("\u6536\u5230\uFF0C\u6B63\u5728\u5904\u7406\u2026").catch(() => {
761
+ if (!heard)
762
+ void this.#post(openId, "\u6536\u5230\uFF0C\u6B63\u5728\u5904\u7406\u2026").catch(() => {
554
763
  });
555
764
  }, this.#options.ackAfterMs ?? 4e3);
765
+ const failed = (error) => this.#options.log.warn(`qq message failed: ${message(error)}`);
766
+ const onTyping = (typing) => {
767
+ heard = true;
768
+ this.#typing(openId, typing);
769
+ };
770
+ const onSay = (said) => {
771
+ heard = true;
772
+ if (!this.#first(openId, said.key))
773
+ return;
774
+ const out = { markdown: said.text, plain: plainText(said.text) };
775
+ const typed = this.#typed(openId, said.key, said.text);
776
+ void (typed === void 0 ? this.#post(openId, out) : this.#finish(typed, said.text, out)).catch(failed);
777
+ };
556
778
  try {
557
779
  const actor = this.#actor(event);
558
- const answer = await notify.inbound({ actor, text: event.text });
559
- answered = true;
780
+ const answer = await notify.inbound({ actor, text: event.text, onSay, onTyping });
781
+ heard = true;
782
+ const key = finalKey(answer);
783
+ if (!this.#first(openId, key)) {
784
+ const rest = replyRest(answer);
785
+ if (rest !== "" && this.#first(openId, `${key}|rest`))
786
+ await this.#post(openId, rest);
787
+ return;
788
+ }
560
789
  const next = notify.nextQuestion?.(actor);
561
790
  const out = { markdown: replyMarkdown(answer), plain: plainText(replyPlain(answer)), ...next === void 0 ? {} : { buttons: choiceButtons(next) } };
562
- await this.#deliver(api, event.openId, out, passive()).catch(() => this.#deliver(api, event.openId, out));
791
+ const typed = this.#typed(openId, key, out.markdown);
792
+ if (typed === void 0)
793
+ return await this.#post(openId, out);
794
+ await this.#finish(typed, out.markdown, { ...out, buttons: [] });
795
+ if (out.buttons !== void 0)
796
+ await this.#post(openId, { markdown: replyHint(out.buttons), plain: replyHint(out.buttons), buttons: out.buttons });
563
797
  } catch (error) {
564
- answered = true;
565
- await reply(`\u51FA\u9519\u4E86\uFF1A${message(error)}`).catch(() => {
798
+ heard = true;
799
+ await this.#post(openId, `\u51FA\u9519\u4E86\uFF1A${message(error)}`).catch(() => {
566
800
  });
567
801
  } finally {
568
802
  clearTimeout(ack);
@@ -600,7 +834,7 @@ function questionMessage(request) {
600
834
  const first = request.questions[0];
601
835
  const text = questionText(request);
602
836
  return {
603
- markdown: text.replace(/^【助手问你】/, "**\u52A9\u624B\u95EE\u4F60**"),
837
+ markdown: text.replace(/^【(MultiGameAssistant |助手)问你】/, "**$1\u95EE\u4F60**"),
604
838
  plain: text,
605
839
  ...first === void 0 || (first.options ?? []).length === 0 ? {} : { buttons: choiceButtons(first) }
606
840
  };
@@ -679,7 +913,7 @@ var AdgQQBot = class extends Service {
679
913
  await writeFileAtomic(file, `${JSON.stringify(state, null, 2)}
680
914
  `);
681
915
  },
682
- notify: () => ({ inbound: (m) => notify.inbound(m), waiting: (actor) => notify.notify.waiting(actor), nextQuestion: (actor) => notify.notify.nextQuestion(actor) }),
916
+ notify: () => ({ inbound: (m) => notify.inbound(m), nextQuestion: (actor) => notify.notify.nextQuestion(actor) }),
683
917
  changed: () => notify.changed(),
684
918
  log: logPort
685
919
  });
package/lib/runner.js CHANGED
@@ -25,9 +25,9 @@ import {
25
25
  setIn,
26
26
  taskParams,
27
27
  tidyRuns
28
- } from "./chunk-76UHR2GO.js";
29
- import "./chunk-C7X2KJ5C.js";
30
- import "./chunk-34VNH3YS.js";
28
+ } from "./chunk-DBOGZLXA.js";
29
+ import "./chunk-7UJ3LK3G.js";
30
+ import "./chunk-BB2T4JHF.js";
31
31
  import "./chunk-6DSSLS7I.js";
32
32
  import "./chunk-2UFLGPDY.js";
33
33
  export {
package/lib/scheduler.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __adgCreateRequire } from 'node:module'; import { dirname as __adgDirname } from 'node:path'; import { fileURLToPath as __adgFileURLToPath } from 'node:url'; const require = __adgCreateRequire(import.meta.url); const __filename = __adgFileURLToPath(import.meta.url); const __dirname = __adgDirname(__filename);
2
2
  import {
3
3
  SCHEDULE_CAPABILITY
4
- } from "./chunk-34VNH3YS.js";
4
+ } from "./chunk-BB2T4JHF.js";
5
5
  import {
6
6
  external_exports
7
7
  } from "./chunk-6DSSLS7I.js";
@@ -17,14 +17,14 @@ import {
17
17
  packForRepo,
18
18
  parseMcpConfig,
19
19
  readSkills
20
- } from "./chunk-KW36B7DT.js";
20
+ } from "./chunk-AXOXWMQT.js";
21
21
  import "./chunk-B4UT4NYH.js";
22
- import "./chunk-C7X2KJ5C.js";
23
- import "./chunk-4QXRDWGS.js";
24
- import "./chunk-QSETYM2Y.js";
25
- import "./chunk-M7GNYL5B.js";
22
+ import "./chunk-7UJ3LK3G.js";
23
+ import "./chunk-RREVLKRY.js";
24
+ import "./chunk-OCJFAT7J.js";
25
+ import "./chunk-4NR36PKL.js";
26
26
  import "./chunk-RESS7WVY.js";
27
- import "./chunk-34VNH3YS.js";
27
+ import "./chunk-BB2T4JHF.js";
28
28
  import "./chunk-6DSSLS7I.js";
29
29
  import "./chunk-2UFLGPDY.js";
30
30
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-multigameassistant",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "多游戏助手 MultiGameAssistant 的 dsh 插件版:让 agent 管好各个游戏的日常脚本(安装、编排定时流水线、看护运行、查活动),界面在自己的网页里。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -20,8 +20,8 @@ description: 游戏活动信息:查有什么活动、还剩几天、商店换
20
20
  - 游戏页的「日常 · 周常」由游戏包和脚本包的 routines 列出,脚本日志或任务成功时自动勾上,到游戏的每日 / 每周重置时间清空;用户也可以自己勾、自己加。混沌回忆、卫戍协议这类周期玩法列在「活动日程」的「周期玩法」里,做完一期就是那个活动 `finished`。
21
21
  - 看日常周常用 `game_routine`(action=list):每一项这一期做没做完、谁勾的(脚本日志 / 脚本任务成功 / agent 记的 / 用户自己勾的)、靠哪条日志或哪个任务自动勾、什么时候重置。list 之前插件已经把这一期早些时候的运行记录读过一遍,脚本包后来才加的 routines 也会补上,**不用**为此重跑脚本,也不用自己去勾。
22
22
  - 用户问「日常周常为什么没显示完成」:先 `game_routine` list,对没勾上的一项看它的 auto:
23
- - 「没有:只能手动勾」→ 脚本包没写这一项的 routines:交给「脚本」(agent_delegate)在脚本包里补,log 用运行日志里的原文;
24
- - 有日志规则却没勾 → `script_run_log` 在这一期的运行里搜那段原文:搜不到说明日志里的写法不一样(交给「脚本」改 log)或者这一项确实没做(例如剿灭被跳过、实训失败);
23
+ - 「没有:只能手动勾」→ 脚本包没写这一项的 routines:交给「脚本助手」(agent_delegate)在脚本包里补,log 用运行日志里的原文;
24
+ - 有日志规则却没勾 → `script_run_log` 在这一期的运行里搜那段原文:搜不到说明日志里的写法不一样(交给「脚本助手」改 log)或者这一项确实没做(例如剿灭被跳过、实训失败);
25
25
  - 结论用一两句话告诉用户:哪几项已经自动勾上、哪几项缺规则正在补、哪几项今天确实没做。
26
26
  - 只有亲眼看到完成证据(运行日志原文、游戏画面上的完成文字)才用 `game_routine` action=set 勾,evidence 写原文和出处;页面会显示成「agent 记的」。**不要**用浏览器点游戏页的勾选框,也不要自己调接口——那样会被记成用户勾的。跳过、失败、只开始了的不算完成。
27
27
  - 日报里每个游戏先写日常周常还差哪几项、什么时候重置,插件发日报前也会先读一遍运行记录。
@@ -7,7 +7,7 @@ description: 把几个游戏脚本编成一条流水线(每天自动跑、一
7
7
 
8
8
  目标:做出一条用户看得懂、电脑带得动、一个游戏出错不拖累其他游戏的流水线。
9
9
 
10
- 谁来保存:「编排」用 `pipeline_save`(它的子 agent 要任务里写了「允许直接做的改动:改流水线和定时」才直接保存,否则保存会记成待定改动交回给「编排」决定),直接保存生效,新建和修改已有的(用户保存过的也可以)都行,不用用户审批;软件里的其他 agent 没有这个工具,把整件事用 `agent_delegate` 交给「编排」;只有没有「编排」的对话(比如共享 dsh 里的别的对话)才用 `pipeline_draft` 存成草稿,等用户在「编排」页确认。下面写「保存」的地方,按你有的那个工具来。
10
+ 谁来保存:「编排助手」用 `pipeline_save`(它的子 agent 要任务里写了「允许直接做的改动:改流水线和定时」才直接保存,否则保存会记成待定改动交回给「编排助手」决定),直接保存生效,新建和修改已有的(用户保存过的也可以)都行,不用用户审批;软件里的其他 agent 没有这个工具,把整件事用 `agent_delegate` 交给「编排助手」;只有没有「编排助手」的对话(比如共享 dsh 里的别的对话)才用 `pipeline_draft` 存成草稿,等用户在「编排」页确认。下面写「保存」的地方,按你有的那个工具来。
11
11
 
12
12
  ## 规则
13
13
 
@@ -30,7 +30,7 @@ description: 把几个游戏脚本编成一条流水线(每天自动跑、一
30
30
  - 先跑耗时短、容易失败的(例如需要登录的),把长任务放后面;用户有偏好就按用户的。
31
31
  4. 连线:串行时每一步到下一步用 **`when: always`(上一步结束后,不管成败)**,这样一个游戏失败不会让后面的游戏都不跑;只有用户明确要求「失败就停」时才用 `success` 或 `then: stop`。最后一个任务连到一个 `notify` 节点发汇总。不需要自己加「开始」「结束」节点,系统会加。
32
32
  5. 失败处理:默认不重试(游戏脚本自己多数会重试);用户在意成功率可以 `retries: 1`。
33
- 6. `pipeline_save`(没有「编排」的对话用 `pipeline_draft`)提交(id 用小写短横线,如 `daily-games`);看返回的 `check`:有 error 就改正重交;有「会自动排队」的 info 说明画了不必要的并行,可以改成串行。
33
+ 6. `pipeline_save`(没有「编排助手」的对话用 `pipeline_draft`)提交(id 用小写短横线,如 `daily-games`);看返回的 `check`:有 error 就改正重交;有「会自动排队」的 info 说明画了不必要的并行,可以改成串行。
34
34
  7. 回复用户:顺序(A → B → C → D)、为什么这样排、预计时长(`check.estimateMinutes`)、没确认的事项;问要不要现在运行一次(`pipeline_run`)或设定每天的时间(`schedule_set`;草稿要先保存)。
35
35
 
36
36
  ## 例子
@@ -19,7 +19,7 @@ description: 分析脚本库里的一个游戏自动化脚本(包括没见过
19
19
  - **不猜**:每一条启动方式、任务、配置键、日志规则都要有依据(文档、`--help` 输出、interface.json、配置文件内容、日志样本、源码)。没有依据的写进 SKILL.md 的「待确认」,不要写进 manifest。文档和代码对不上时以代码(实际行为)为准,并在「待确认」里写明。
20
20
  - 成败判定取自脚本自己的输出(退出码、日志),不要自造信号。
21
21
  - 先 `skill_focus`(scripts 写这个脚本的 id):它已有的技能才看得到,也不会混进别的脚本的技能。
22
- - **你的工具里没有 `pack_propose` 时**(「脚本」自己的那个对话,具体的活由子 agent 做):把整件事——分析、写使用说明和 SKILL.md、用 `pack_propose` 保存——交给**一个**子 agent(subagent),任务里写清脚本 id、用户的要求、按 script-analysis 技能做;它做完你再把结论告诉用户。不要先在自己的对话里读文档、看代码(会把你的对话撑大),也不用开子 agent 试探工具在不在:你的子 agent 有 `pack_propose`。
22
+ - **你的工具里没有 `pack_propose` 时**(「脚本助手」自己的那个对话,具体的活由子 agent 做):把整件事——分析、写使用说明和 SKILL.md、用 `pack_propose` 保存——交给**一个**子 agent(subagent),任务里写清脚本 id、用户的要求、按 script-analysis 技能做;它做完你再把结论告诉用户。不要先在自己的对话里读文档、看代码(会把你的对话撑大),也不用开子 agent 试探工具在不在:你的子 agent 有 `pack_propose`。
23
23
 
24
24
  ## 步骤
25
25
 
@@ -116,8 +116,11 @@ game: # 脚本玩的游戏:脚本自己不启动游
116
116
  name: 明日方舟
117
117
  android: { package: com.example.game } # 模拟器任务:运行前在模拟器里启动;写官服的包名,拿不准用 emulator_apps 在模拟器里查
118
118
  pc: { process: Game.exe } # PC 任务:进程名(程序位置由用户在界面里设置)
119
- selfLaunch: never # 脚本自己会启动游戏时写 always,或写配置条件:
120
- # [{ file: config/gui.json, path: [Start, StartGame], equals: 'True' }]
119
+ selfLaunch: never # 脚本自己会启动游戏时写 always,或写配置条件(任一成立即算):
120
+ # - { file: config/gui.json, path: [Start, StartGame], equals: 'True', note: 设置里打开了「启动游戏」 }
121
+ # - 列表里有一项各字段都符合(值或 { match: 正则 }),路径可按任务参数找项:
122
+ # { file: config/mxu-X.json, path: [instances, { where: { field: name, equals: '{instance}' } }, tasks],
123
+ # some: { enabled: true, taskName: { match: '^OpenGame$' } }, note: 实例里勾选了「启动游戏」 }
121
124
  startupSeconds: 30
122
125
  ```
123
126
 
@@ -130,7 +133,7 @@ game: # 脚本玩的游戏:脚本自己不启动游
130
133
  `create` 表示可以复制一个现有项新建(结构和脚本自己写的一样)。
131
134
  - 临时修改的路径里可以按字段找列表项:`path: [instances, { where: { field: name, equals: '{instance}' } }, address]`。
132
135
  - 脚本自己也会启动模拟器时(例如它有「启动后打开模拟器」),平台已经启动了模拟器,就用 `when: emulator-managed` 的临时修改把它关掉;用户填的是手动 ADB 地址时这条不生效,脚本照常自己启动模拟器。
133
- - 脚本会自己启动游戏,就在 `game.selfLaunch` 里写明,平台不再重复启动;平台也会先看游戏是否已经在运行。
136
+ - 脚本会自己启动游戏,就在 `game.selfLaunch` 里写明,平台不再重复启动;平台也会先看游戏是否已经在运行。脚本有「启动游戏」这类可勾选的任务或选项时,写成配置条件而不是 `never`:用户勾上了,平台就不再启动。
134
137
 
135
138
  日志规则只写在源码、文档或真实日志里确实出现过的原文;拿不准的错误先写成 `warning`。`recovery` 只给确定安全的情况写(重启任务会从头再跑一遍);脚本自己会重试的警告上不要写 stop / restart。
136
139