dsh-multigameassistant 2.0.0 → 2.0.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/README.md +7 -3
- package/cordis.patch.yml +3 -1
- package/lib/analyzer.js +3 -3
- package/lib/{chunk-FLQD3DKB.js → chunk-I5AFAEXG.js} +471 -75
- package/lib/{chunk-7XMNAHZ2.js → chunk-NWM5ZN7E.js} +1 -1
- package/lib/{chunk-2DZ75ANX.js → chunk-OPV336S5.js} +380 -58
- package/lib/{chunk-BL6OSR2I.js → chunk-QAP7IYBS.js} +248 -29
- package/lib/{chunk-KIAOFNCB.js → chunk-YG4B5G7F.js} +38 -5
- package/lib/{chunk-5WTH2CYW.js → chunk-ZR74PFWR.js} +2 -2
- package/lib/emulator.js +2 -2
- package/lib/feishu.js +3 -3
- package/lib/game-intel.js +583 -37
- package/lib/gateway.js +2 -2
- package/lib/guard.js +1 -1
- package/lib/intervene.js +8 -6
- package/lib/monitor.js +3 -3
- package/lib/notify.js +3 -3
- package/lib/orchestrator.js +5 -5
- package/lib/qqbot.js +3 -3
- package/lib/runner.js +3 -3
- package/lib/scheduler.js +1 -1
- package/lib/script-registry.js +42 -9
- package/package.json +4 -3
- package/skills/game-intel.md +10 -0
- package/web/assets/index-9SCfW_a1.js +241 -0
- package/web/assets/index-9SCfW_a1.js.map +1 -0
- package/web/assets/index-BodAAefM.css +1 -0
- package/web/index.html +2 -2
- package/web/assets/index-B8Gy9VoQ.css +0 -1
- package/web/assets/index-DAKeB3Cw.js +0 -235
- package/web/assets/index-DAKeB3Cw.js.map +0 -1
package/lib/game-intel.js
CHANGED
|
@@ -7,26 +7,30 @@ import {
|
|
|
7
7
|
GAME_MANIFEST_FILE,
|
|
8
8
|
GameManifest,
|
|
9
9
|
parseGameManifest
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NWM5ZN7E.js";
|
|
11
11
|
import {
|
|
12
12
|
sessionConversations
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-I5AFAEXG.js";
|
|
14
|
+
import "./chunk-OPV336S5.js";
|
|
15
15
|
import {
|
|
16
16
|
writeFileAtomic
|
|
17
17
|
} from "./chunk-CCAB6XXZ.js";
|
|
18
18
|
import {
|
|
19
19
|
GAMES_CAPABILITY,
|
|
20
20
|
GamesSettings,
|
|
21
|
+
OWN_IMAGE,
|
|
22
|
+
OWN_SOURCE,
|
|
23
|
+
SCREEN_SOURCE,
|
|
24
|
+
SHOT_IMAGE,
|
|
21
25
|
external_exports,
|
|
22
26
|
taskMessage
|
|
23
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-QAP7IYBS.js";
|
|
24
28
|
import "./chunk-2UFLGPDY.js";
|
|
25
29
|
|
|
26
30
|
// packages/game-intel/lib/index.js
|
|
27
31
|
import { createHash } from "node:crypto";
|
|
28
|
-
import { mkdir as mkdir2, readdir, readFile as readFile2, writeFile } from "node:fs/promises";
|
|
29
|
-
import { join as join2 } from "node:path";
|
|
32
|
+
import { mkdir as mkdir2, readdir, readFile as readFile2, rm, writeFile } from "node:fs/promises";
|
|
33
|
+
import { isAbsolute, join as join2, resolve } from "node:path";
|
|
30
34
|
import { Service } from "@deepseek-ai/cordis";
|
|
31
35
|
|
|
32
36
|
// packages/game-intel/lib/calendar.js
|
|
@@ -162,6 +166,15 @@ var KEEP_UNDATED_MS = 14 * MS.DAY;
|
|
|
162
166
|
var MISMATCH_MS = 30 * MS.HOUR;
|
|
163
167
|
var DEFAULT_SETTINGS = { report: { enabled: true, at: "09:00", games: [], soonDays: 3, ai: true }, followed: [] };
|
|
164
168
|
var AGENT_PAGE = { id: "agent", name: "agent \u67E5\u5230\u7684\u7F51\u9875" };
|
|
169
|
+
var OWN_FIELDS = ["name", "startsAt", "endsAt", "kind", "description", "url", "cover"];
|
|
170
|
+
var CHOSEN_FIELDS = ["cover", "startsAt", "endsAt", "shopEndsAt"];
|
|
171
|
+
function saidBy(item, source) {
|
|
172
|
+
if (source === OWN_SOURCE)
|
|
173
|
+
return item.mine;
|
|
174
|
+
if (source === SCREEN_SOURCE)
|
|
175
|
+
return item.screen === void 0 ? void 0 : { endsAt: item.screen.endsAt, cover: item.screen.image };
|
|
176
|
+
return item.facts[source];
|
|
177
|
+
}
|
|
165
178
|
var StoredSchema = external_exports.object({
|
|
166
179
|
activities: external_exports.array(external_exports.looseObject({ id: external_exports.string(), game: external_exports.string(), name: external_exports.string() })).default([]),
|
|
167
180
|
refreshed: external_exports.record(external_exports.string(), external_exports.object({ at: external_exports.number(), ok: external_exports.boolean(), count: external_exports.number(), detail: external_exports.string().optional() })).default({}),
|
|
@@ -225,9 +238,11 @@ var Calendar = class {
|
|
|
225
238
|
/** Every picture address a data site gave: the only ones the host will fetch. */
|
|
226
239
|
pictures() {
|
|
227
240
|
const out = /* @__PURE__ */ new Set();
|
|
228
|
-
for (const a of this.#items)
|
|
229
|
-
|
|
230
|
-
|
|
241
|
+
for (const a of this.#items) {
|
|
242
|
+
for (const cover of [a.cover, a.mine?.cover, ...Object.values(a.facts).map((f) => f.cover)])
|
|
243
|
+
if (cover !== void 0)
|
|
244
|
+
out.add(cover);
|
|
245
|
+
}
|
|
231
246
|
for (const v of Object.values(this.#saved.versions))
|
|
232
247
|
if (v.cover !== void 0)
|
|
233
248
|
out.add(v.cover);
|
|
@@ -345,7 +360,7 @@ var Calendar = class {
|
|
|
345
360
|
delete item.facts[source.id];
|
|
346
361
|
this.#derive(item, timeZone);
|
|
347
362
|
}
|
|
348
|
-
this.#items = this.#items.filter((a) => a.game !== game ||
|
|
363
|
+
this.#items = this.#items.filter((a) => a.game !== game || this.#sourced(a) || a.mine !== void 0);
|
|
349
364
|
this.#prune(now);
|
|
350
365
|
this.#saved.refreshed[game] = { at: now, ok: true, count: events.length };
|
|
351
366
|
await this.save();
|
|
@@ -369,7 +384,8 @@ var Calendar = class {
|
|
|
369
384
|
* time, checked against the site's end); from a web page (`site`) it is
|
|
370
385
|
* that page's word on the event (the user's page it came from, else
|
|
371
386
|
* "agent 查到的网页"), kept beside the data sites' and used where they say
|
|
372
|
-
* nothing.
|
|
387
|
+
* nothing. `shot`: the screenshot read from the screen, already kept
|
|
388
|
+
* (`shot:<file>`): the evidence, and the picture where no source has one.
|
|
373
389
|
* @returns the events written, with how each was matched.
|
|
374
390
|
*/
|
|
375
391
|
async applyRead(game, from, events, context) {
|
|
@@ -397,11 +413,13 @@ var Calendar = class {
|
|
|
397
413
|
...event.cover !== void 0 && /^https:\/\/\S+$/.test(event.cover) ? { cover: event.cover } : {}
|
|
398
414
|
};
|
|
399
415
|
} else {
|
|
416
|
+
const image = context.shot ?? item.screen?.image;
|
|
400
417
|
item.screen = {
|
|
401
418
|
at: now,
|
|
402
419
|
...event.remaining === void 0 ? {} : { remaining: event.remaining },
|
|
403
420
|
...end === void 0 ? {} : { endsAt: end },
|
|
404
|
-
evidence:
|
|
421
|
+
evidence: context.shot !== void 0,
|
|
422
|
+
...image === void 0 ? {} : { image },
|
|
405
423
|
...context.sessionId === void 0 ? {} : { sessionId: context.sessionId }
|
|
406
424
|
};
|
|
407
425
|
if (event.todo !== void 0)
|
|
@@ -414,14 +432,170 @@ var Calendar = class {
|
|
|
414
432
|
delete item.progress;
|
|
415
433
|
}
|
|
416
434
|
this.#derive(item, timeZone);
|
|
417
|
-
if (from === "screen" && context.evidence !== void 0)
|
|
418
|
-
item.screen.evidence = await context.evidence(this.#public(item)).catch(() => false);
|
|
419
435
|
written.push({ activity: this.#public(item), matched: existing !== void 0 });
|
|
420
436
|
}
|
|
421
437
|
this.#prune(now);
|
|
422
438
|
await this.save();
|
|
423
439
|
return written;
|
|
424
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* The user's own word on an event (`target.id`), or an event of their own
|
|
443
|
+
* (a `name` and no id; one of that name already in the calendar is that
|
|
444
|
+
* one). Fields equal to what the sources say are not kept, so a later
|
|
445
|
+
* refresh still moves them; on an event only the user has, every field is.
|
|
446
|
+
* @returns the event; undefined when there is no event with that id in that game.
|
|
447
|
+
* @throws Error when a new one has no name.
|
|
448
|
+
*/
|
|
449
|
+
async saveOwn(target, patch, now, timeZone) {
|
|
450
|
+
let item;
|
|
451
|
+
if (target.id !== void 0) {
|
|
452
|
+
item = this.#items.find((a) => a.id === target.id && a.game === target.game);
|
|
453
|
+
if (item === void 0)
|
|
454
|
+
return void 0;
|
|
455
|
+
} else {
|
|
456
|
+
const name = typeof patch.name === "string" ? patch.name.trim() : "";
|
|
457
|
+
if (name === "")
|
|
458
|
+
throw new Error("\u65B0\u6D3B\u52A8\u8981\u6709\u540D\u5B57");
|
|
459
|
+
item = this.#items.find((a) => a.game === target.game && a.names.some((n) => idKey(n) === idKey(name))) ?? this.#create(target.game, name);
|
|
460
|
+
}
|
|
461
|
+
const mine = { ...item.mine };
|
|
462
|
+
delete mine.at;
|
|
463
|
+
for (const key of OWN_FIELDS) {
|
|
464
|
+
const value = patch[key];
|
|
465
|
+
if (value === void 0)
|
|
466
|
+
continue;
|
|
467
|
+
if (value === null || typeof value === "string" && value.trim() === "")
|
|
468
|
+
delete mine[key];
|
|
469
|
+
else
|
|
470
|
+
mine[key] = typeof value === "string" ? value.trim() : value;
|
|
471
|
+
}
|
|
472
|
+
if (mine.startsAt !== void 0 && mine.endsAt !== void 0 && mine.endsAt <= mine.startsAt)
|
|
473
|
+
throw new Error("\u7ED3\u675F\u65F6\u95F4\u8981\u665A\u4E8E\u5F00\u59CB\u65F6\u95F4");
|
|
474
|
+
if (this.#sourced(item)) {
|
|
475
|
+
const base = structuredClone(item);
|
|
476
|
+
delete base.mine;
|
|
477
|
+
this.#derive(base, timeZone);
|
|
478
|
+
for (const key of OWN_FIELDS)
|
|
479
|
+
if (mine[key] !== void 0 && mine[key] === base[key])
|
|
480
|
+
delete mine[key];
|
|
481
|
+
}
|
|
482
|
+
if (Object.keys(mine).length === 0)
|
|
483
|
+
delete item.mine;
|
|
484
|
+
else
|
|
485
|
+
item.mine = { ...mine, at: now };
|
|
486
|
+
if (item.chosen !== void 0) {
|
|
487
|
+
const written = OWN_FIELDS.filter((key) => patch[key] !== void 0 && mine[key] !== void 0);
|
|
488
|
+
const taken = OWN_FIELDS.filter((key) => patch[key] === null);
|
|
489
|
+
item.chosen.over = unique([...item.chosen.over, ...written]).filter((key) => !taken.includes(key));
|
|
490
|
+
if (item.chosen.source === OWN_SOURCE && item.mine === void 0)
|
|
491
|
+
delete item.chosen;
|
|
492
|
+
}
|
|
493
|
+
if (mine.name !== void 0)
|
|
494
|
+
item.names = unique([...item.names, mine.name]);
|
|
495
|
+
if (patch.todo !== void 0)
|
|
496
|
+
item.todo = unique(patch.todo.map((t) => t.trim()).filter((t) => t !== "" && !item.done.includes(t)));
|
|
497
|
+
if (!this.#sourced(item) && item.mine === void 0) {
|
|
498
|
+
this.#items = this.#items.filter((a) => a !== item);
|
|
499
|
+
await this.save();
|
|
500
|
+
return void 0;
|
|
501
|
+
}
|
|
502
|
+
this.#derive(item, timeZone);
|
|
503
|
+
await this.save();
|
|
504
|
+
return this.#public(item);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Take back what the user wrote on an event: the sources' word shows again;
|
|
508
|
+
* an event only the user had goes.
|
|
509
|
+
* @returns the event as it is now; undefined when it went (or was not there).
|
|
510
|
+
*/
|
|
511
|
+
async resetOwn(id, timeZone) {
|
|
512
|
+
const item = this.#items.find((a) => a.id === id);
|
|
513
|
+
if (item === void 0)
|
|
514
|
+
return void 0;
|
|
515
|
+
delete item.mine;
|
|
516
|
+
if (item.chosen?.source === OWN_SOURCE)
|
|
517
|
+
delete item.chosen;
|
|
518
|
+
else if (item.chosen !== void 0)
|
|
519
|
+
item.chosen.over = [];
|
|
520
|
+
if (!this.#sourced(item)) {
|
|
521
|
+
this.#items = this.#items.filter((a) => a !== item);
|
|
522
|
+
await this.save();
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
525
|
+
this.#derive(item, timeZone);
|
|
526
|
+
await this.save();
|
|
527
|
+
return this.#public(item);
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* The source an event's picture and dates come from (`null`: the default order).
|
|
531
|
+
* @returns the event; undefined when there is none with that id.
|
|
532
|
+
* @throws Error when that source says nothing about the event.
|
|
533
|
+
*/
|
|
534
|
+
async chooseSource(id, source, timeZone) {
|
|
535
|
+
const item = this.#items.find((a) => a.id === id);
|
|
536
|
+
if (item === void 0)
|
|
537
|
+
return void 0;
|
|
538
|
+
if (source === null)
|
|
539
|
+
delete item.chosen;
|
|
540
|
+
else if (saidBy(item, source) === void 0)
|
|
541
|
+
throw new Error("\u8FD9\u4E2A\u6D3B\u52A8\u6CA1\u6709\u8FD9\u4E2A\u6765\u6E90");
|
|
542
|
+
else
|
|
543
|
+
item.chosen = { source, over: [] };
|
|
544
|
+
this.#derive(item, timeZone);
|
|
545
|
+
await this.save();
|
|
546
|
+
return this.#public(item);
|
|
547
|
+
}
|
|
548
|
+
/** The screenshot the agent took of an event, as its own picture (the lowest rank). */
|
|
549
|
+
async setShot(id, shot, context) {
|
|
550
|
+
const item = this.#items.find((a) => a.id === id);
|
|
551
|
+
if (item === void 0)
|
|
552
|
+
return void 0;
|
|
553
|
+
item.screen = { ...item.screen, at: context.now, evidence: true, image: shot, ...context.sessionId === void 0 ? {} : { sessionId: context.sessionId } };
|
|
554
|
+
this.#derive(item, context.timeZone);
|
|
555
|
+
await this.save();
|
|
556
|
+
return this.#public(item);
|
|
557
|
+
}
|
|
558
|
+
/** Work every event out again: a calendar saved by an older version shows what this one would. */
|
|
559
|
+
async rederive(timeZone) {
|
|
560
|
+
if (this.#items.length === 0)
|
|
561
|
+
return;
|
|
562
|
+
for (const item of this.#items)
|
|
563
|
+
if (this.#sourced(item) || item.mine !== void 0)
|
|
564
|
+
this.#derive(item, timeZone(item.game));
|
|
565
|
+
await this.save();
|
|
566
|
+
}
|
|
567
|
+
/** The pictures the user added that an event still shows (`own:<file>`). */
|
|
568
|
+
ownImages() {
|
|
569
|
+
const out = /* @__PURE__ */ new Set();
|
|
570
|
+
for (const a of this.#items)
|
|
571
|
+
if (a.mine?.cover?.startsWith("own:") === true)
|
|
572
|
+
out.add(a.mine.cover);
|
|
573
|
+
return out;
|
|
574
|
+
}
|
|
575
|
+
/** The screenshots an event was read from that are still kept (`shot:<file>`). */
|
|
576
|
+
shotImages() {
|
|
577
|
+
const out = /* @__PURE__ */ new Set();
|
|
578
|
+
for (const a of this.#items)
|
|
579
|
+
if (a.screen?.image !== void 0)
|
|
580
|
+
out.add(a.screen.image);
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Screenshots kept before they were pictures (one file per event): now
|
|
585
|
+
* kept as `shot:<file>`, by event id.
|
|
586
|
+
*/
|
|
587
|
+
async adoptShots(shots, timeZone) {
|
|
588
|
+
if (shots.size === 0)
|
|
589
|
+
return;
|
|
590
|
+
for (const item of this.#items) {
|
|
591
|
+
const shot = shots.get(item.id);
|
|
592
|
+
if (shot === void 0 || item.screen === void 0)
|
|
593
|
+
continue;
|
|
594
|
+
item.screen.image = shot;
|
|
595
|
+
this.#derive(item, timeZone(item.game));
|
|
596
|
+
}
|
|
597
|
+
await this.save();
|
|
598
|
+
}
|
|
425
599
|
async remove(id) {
|
|
426
600
|
const before = this.#items.length;
|
|
427
601
|
this.#items = this.#items.filter((a) => a.id !== id);
|
|
@@ -447,6 +621,10 @@ var Calendar = class {
|
|
|
447
621
|
const running = loose.find((a) => (a.startsAt ?? 0) <= now && now <= (a.endsAt ?? Infinity));
|
|
448
622
|
return running ?? loose[0];
|
|
449
623
|
}
|
|
624
|
+
/** Some source (a data site, a web page, the game screen) knows it. */
|
|
625
|
+
#sourced(item) {
|
|
626
|
+
return Object.keys(item.facts).length > 0 || item.screen !== void 0;
|
|
627
|
+
}
|
|
450
628
|
#create(game, name) {
|
|
451
629
|
let id = `${game}/${idKey(name)}`;
|
|
452
630
|
for (let n = 2; this.#items.some((a) => a.id === id); n++)
|
|
@@ -459,32 +637,80 @@ var Calendar = class {
|
|
|
459
637
|
* The event as shown, from what its sources said: each detail from the
|
|
460
638
|
* data sites first (the one that wrote last), then the web pages (the
|
|
461
639
|
* newest reading); the end from the game screen when no source gives one.
|
|
640
|
+
* The picture goes by rank: what the user set, then what a source gives,
|
|
641
|
+
* then the agent's screenshot. A source the user chose comes before all of
|
|
642
|
+
* that for the picture and the dates, where it says anything.
|
|
462
643
|
* Disagreements on the end are said: a web page against a data site, the
|
|
463
|
-
* screen against a data site (the data site counts).
|
|
644
|
+
* screen against a data site (the data site counts), unless the user chose.
|
|
464
645
|
*/
|
|
465
646
|
#derive(item, timeZone) {
|
|
466
647
|
const ordered = Object.entries(item.facts).map(([id, fact], index) => ({ id, fact, index })).sort((a, b) => Number(a.fact.web) - Number(b.fact.web) || b.fact.at - a.fact.at || b.index - a.index);
|
|
467
648
|
const first = (key) => ordered.find((o) => o.fact[key] !== void 0)?.fact[key];
|
|
649
|
+
const firstFrom = (key) => ordered.find((o) => o.fact[key] !== void 0)?.id;
|
|
468
650
|
const set = (key, value) => {
|
|
469
651
|
if (value === void 0)
|
|
470
652
|
delete item[key];
|
|
471
653
|
else
|
|
472
654
|
item[key] = value;
|
|
473
655
|
};
|
|
656
|
+
const origin = {};
|
|
657
|
+
const put = (key, value, from) => {
|
|
658
|
+
set(key, value);
|
|
659
|
+
if (value === void 0 || from === void 0)
|
|
660
|
+
delete origin[key];
|
|
661
|
+
else
|
|
662
|
+
origin[key] = from;
|
|
663
|
+
};
|
|
474
664
|
const site = ordered.find((o) => !o.fact.web);
|
|
475
665
|
const primary = ordered[0];
|
|
476
|
-
|
|
477
|
-
|
|
666
|
+
put("startsAt", site !== void 0 ? site.fact.startsAt : first("startsAt"), site !== void 0 ? site.id : firstFrom("startsAt"));
|
|
667
|
+
if (first("endsAt") !== void 0)
|
|
668
|
+
put("endsAt", first("endsAt"), firstFrom("endsAt"));
|
|
669
|
+
else
|
|
670
|
+
put("endsAt", item.screen?.endsAt, SCREEN_SOURCE);
|
|
478
671
|
set("shopEndsAt", site !== void 0 ? site.fact.shopEndsAt : first("shopEndsAt"));
|
|
479
672
|
set("url", first("url"));
|
|
480
|
-
|
|
673
|
+
put("cover", first("cover"), firstFrom("cover"));
|
|
481
674
|
set("description", first("description"));
|
|
482
675
|
set("kind", first("kind"));
|
|
483
676
|
if (primary === void 0)
|
|
484
677
|
delete item.site;
|
|
485
678
|
else
|
|
486
679
|
item.site = { source: primary.id, name: primary.fact.name, at: primary.fact.at };
|
|
680
|
+
const mine = item.mine;
|
|
681
|
+
if (mine?.name !== void 0) {
|
|
682
|
+
if (item.name !== mine.name)
|
|
683
|
+
item.baseName = item.name;
|
|
684
|
+
item.name = mine.name;
|
|
685
|
+
} else if (item.baseName !== void 0) {
|
|
686
|
+
item.name = item.baseName;
|
|
687
|
+
delete item.baseName;
|
|
688
|
+
}
|
|
689
|
+
for (const key of ["kind", "description", "url"])
|
|
690
|
+
if (mine?.[key] !== void 0)
|
|
691
|
+
set(key, mine[key]);
|
|
692
|
+
for (const key of ["startsAt", "endsAt", "cover"])
|
|
693
|
+
if (mine?.[key] !== void 0)
|
|
694
|
+
put(key, mine[key], OWN_SOURCE);
|
|
695
|
+
if (item.cover === void 0)
|
|
696
|
+
put("cover", item.screen?.image, SCREEN_SOURCE);
|
|
697
|
+
const chosen = item.chosen;
|
|
698
|
+
const said = chosen === void 0 ? void 0 : saidBy(item, chosen.source);
|
|
699
|
+
if (chosen !== void 0 && said !== void 0) {
|
|
700
|
+
for (const key of CHOSEN_FIELDS) {
|
|
701
|
+
const value = said[key];
|
|
702
|
+
if (value === void 0 || key !== "shopEndsAt" && chosen.over.includes(key) && mine?.[key] !== void 0)
|
|
703
|
+
continue;
|
|
704
|
+
if (key === "shopEndsAt")
|
|
705
|
+
set(key, value);
|
|
706
|
+
else
|
|
707
|
+
put(key, value, chosen.source);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
item.shown = origin;
|
|
487
711
|
delete item.mismatch;
|
|
712
|
+
if (mine?.endsAt !== void 0 || said !== void 0)
|
|
713
|
+
return;
|
|
488
714
|
const siteEnd = site?.fact.endsAt;
|
|
489
715
|
if (site === void 0 || siteEnd === void 0)
|
|
490
716
|
return;
|
|
@@ -502,6 +728,8 @@ var Calendar = class {
|
|
|
502
728
|
#prune(now) {
|
|
503
729
|
this.#items = this.#items.filter((a) => {
|
|
504
730
|
if (a.endsAt === void 0) {
|
|
731
|
+
if (a.mine !== void 0)
|
|
732
|
+
return true;
|
|
505
733
|
const seen = [a.screen?.at, ...Object.values(a.facts).map((f) => f.at)].filter((t) => t !== void 0);
|
|
506
734
|
return (seen.length === 0 ? now : Math.max(...seen)) + KEEP_UNDATED_MS > now;
|
|
507
735
|
}
|
|
@@ -509,9 +737,30 @@ var Calendar = class {
|
|
|
509
737
|
});
|
|
510
738
|
}
|
|
511
739
|
#public(item) {
|
|
512
|
-
const { names: _names, facts, ...activity } = item;
|
|
513
|
-
const sources = Object.entries(facts).map(([id, f]) => ({
|
|
514
|
-
|
|
740
|
+
const { names: _names, facts, mine, baseName: _baseName, chosen, ...activity } = item;
|
|
741
|
+
const sources = Object.entries(facts).map(([id, f]) => ({
|
|
742
|
+
id,
|
|
743
|
+
name: f.name,
|
|
744
|
+
at: f.at,
|
|
745
|
+
web: f.web,
|
|
746
|
+
...f.startsAt === void 0 ? {} : { startsAt: f.startsAt },
|
|
747
|
+
...f.endsAt === void 0 ? {} : { endsAt: f.endsAt },
|
|
748
|
+
...f.shopEndsAt === void 0 ? {} : { shopEndsAt: f.shopEndsAt },
|
|
749
|
+
...f.cover === void 0 ? {} : { cover: f.cover }
|
|
750
|
+
}));
|
|
751
|
+
const own = mine === void 0 ? void 0 : {
|
|
752
|
+
at: mine.at,
|
|
753
|
+
fields: OWN_FIELDS.filter((k) => mine[k] !== void 0),
|
|
754
|
+
...mine.startsAt === void 0 ? {} : { startsAt: mine.startsAt },
|
|
755
|
+
...mine.endsAt === void 0 ? {} : { endsAt: mine.endsAt },
|
|
756
|
+
...mine.cover === void 0 ? {} : { cover: mine.cover }
|
|
757
|
+
};
|
|
758
|
+
return structuredClone({
|
|
759
|
+
...activity,
|
|
760
|
+
...sources.length === 0 ? {} : { sources },
|
|
761
|
+
...own === void 0 ? {} : { own },
|
|
762
|
+
...chosen === void 0 || saidBy(item, chosen.source) === void 0 ? {} : { chosen: chosen.source }
|
|
763
|
+
});
|
|
515
764
|
}
|
|
516
765
|
};
|
|
517
766
|
function migrate(item) {
|
|
@@ -988,6 +1237,14 @@ function followedManifest(game) {
|
|
|
988
1237
|
}
|
|
989
1238
|
|
|
990
1239
|
// packages/game-intel/lib/tools.js
|
|
1240
|
+
var OWN_KEYS = { name: "name", starts_at: "startsAt", ends_at: "endsAt", kind: "kind", description: "description", url: "url", image: "cover" };
|
|
1241
|
+
function sourceName(a, source) {
|
|
1242
|
+
if (source === OWN_SOURCE)
|
|
1243
|
+
return "\u7528\u6237\u81EA\u5DF1\u586B\u7684";
|
|
1244
|
+
if (source === SCREEN_SOURCE)
|
|
1245
|
+
return "\u6E38\u620F\u753B\u9762";
|
|
1246
|
+
return a.sources?.find((s) => s.id === source)?.name ?? a.site?.name ?? (a.screen !== void 0 ? "\u6E38\u620F\u753B\u9762" : "\u672A\u77E5");
|
|
1247
|
+
}
|
|
991
1248
|
function parse(schema, args) {
|
|
992
1249
|
const parsed = schema.safeParse(args);
|
|
993
1250
|
if (!parsed.success)
|
|
@@ -1022,7 +1279,12 @@ function gameTools(deps) {
|
|
|
1022
1279
|
...a.startsAt !== void 0 && a.startsAt > now ? { starts: shortDate(a.startsAt, timeZone) } : {},
|
|
1023
1280
|
ends: a.endsAt === void 0 ? "\u672A\u77E5" : `${shortDate(a.endsAt, timeZone)}\uFF08${leftText(a.endsAt, now)}\uFF09`,
|
|
1024
1281
|
...a.shopEndsAt === void 0 ? {} : { shop_ends: shortDate(a.shopEndsAt, timeZone) },
|
|
1025
|
-
dates_from: a.
|
|
1282
|
+
dates_from: sourceName(a, a.shown?.endsAt ?? a.shown?.startsAt),
|
|
1283
|
+
...a.sources === void 0 ? {} : { sources: a.sources.map((s) => ({ id: s.id, name: s.name, ...s.endsAt === void 0 ? {} : { ends: shortDate(s.endsAt, timeZone) } })) },
|
|
1284
|
+
...a.chosen === void 0 ? {} : { chosen_by_user: sourceName(a, a.chosen) },
|
|
1285
|
+
...a.own === void 0 ? {} : { set_by_user: a.own.fields.map((f) => Object.entries(OWN_KEYS).find(([, v]) => v === f)[0]), ...a.sources === void 0 && a.screen === void 0 ? { added_by_user: true } : {} },
|
|
1286
|
+
...a.kind === void 0 ? {} : { kind: a.kind },
|
|
1287
|
+
...a.cover === void 0 ? {} : { image: a.cover.startsWith("own:") ? "\u7528\u6237\u7684\u56FE\u7247" : a.cover.startsWith("shot:") ? "\u6E38\u620F\u622A\u56FE\uFF08\u4F18\u5148\u7EA7\u6700\u4F4E\uFF0C\u6CA1\u6709\u522B\u7684\u56FE\u65F6\u7528\u5B83\uFF09" : a.cover },
|
|
1026
1288
|
...a.screen === void 0 ? {} : { read_in_game: shortDate(a.screen.at, timeZone), ...a.progress === void 0 ? {} : { progress: a.progress } },
|
|
1027
1289
|
// The checklist (from the game screen or kept by the user on the board), and the user's own "done".
|
|
1028
1290
|
...a.todo.length + a.done.length === 0 ? {} : { todo: a.todo, done: a.done },
|
|
@@ -1207,6 +1469,97 @@ function gameTools(deps) {
|
|
|
1207
1469
|
};
|
|
1208
1470
|
}
|
|
1209
1471
|
}),
|
|
1472
|
+
tool({
|
|
1473
|
+
name: "game_activity_save",
|
|
1474
|
+
description: [
|
|
1475
|
+
"\u66FF\u7528\u6237\u624B\u52A8\u6DFB\u52A0\u4E00\u4E2A\u6D3B\u52A8\uFF0C\u6216\u6539\u4E00\u4E2A\u5DF2\u6709\u6D3B\u52A8\uFF08id \u4ECE game_activities \u67E5\uFF09\u3002\u7528\u6237\u8BF4\u300C\u5E2E\u6211\u52A0\u4E00\u4E2A XX \u6D3B\u52A8\u300D\u300C\u628A XX \u7684\u7ED3\u675F\u65F6\u95F4\u6539\u6210\u2026\u300D\u300C\u7ED9\u8FD9\u4E2A\u6D3B\u52A8\u6362\u5F20\u56FE\u300D\u65F6\u7528\u3002",
|
|
1476
|
+
"\u5199\u8FDB\u53BB\u7684\u5B57\u6BB5\u662F\u7528\u6237\u81EA\u5DF1\u7684\u8BF4\u6CD5\uFF1A\u6BD4\u6570\u636E\u7AD9\u548C\u7F51\u9875\u4F18\u5148\uFF0C\u5237\u65B0\u4E0D\u4F1A\u6539\u6389\u4E5F\u4E0D\u4F1A\u5220\u6389\uFF1B\u548C\u6765\u6E90\u4E00\u6837\u7684\u503C\u4E0D\u5355\u72EC\u4FDD\u5B58\u3002\u8BFB\u5230\u7684\u7F51\u9875\u6216\u6E38\u620F\u753B\u9762\u7528 game_record\uFF0C\u4E0D\u8981\u7528\u8FD9\u4E2A\u3002",
|
|
1477
|
+
"\u6D3B\u52A8\u56FE\u7247\u5206\u4E09\u7EA7\uFF1A\u7528\u6237\u8BBE\u7684 > \u6570\u636E\u7AD9\u548C\u7F51\u9875\u7ED9\u7684 > agent \u7684\u622A\u56FE\u3002image \u5199\u56FE\u7247\u7F51\u5740\uFF08https\uFF0C\u4F1A\u4E0B\u8F7D\u4FDD\u5B58\uFF09\u6216\u672C\u673A\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84\uFF08\u76F8\u5BF9\u8DEF\u5F84\u6309\u5DE5\u4F5C\u533A\uFF09\u7B97\u7528\u6237\u8BBE\u7684\uFF1B\u5199 screenshot\uFF08\u8FD9\u4E2A\u5BF9\u8BDD\u6700\u8FD1\u4E00\u5F20\u622A\u56FE\uFF09\u7B97 agent \u7684\u622A\u56FE\uFF0C\u53EA\u5728\u6CA1\u6709\u522B\u7684\u56FE\u65F6\u663E\u793A\u3002clear \u91CC\u7684\u5B57\u6BB5\u6536\u56DE\u7528\u6237\u7684\u503C\uFF0C\u6062\u590D\u6210\u6765\u6E90\u7684\u3002",
|
|
1478
|
+
"use_source \u9009\u8FD9\u4E2A\u6D3B\u52A8\u7684\u56FE\u7247\u548C\u65F6\u95F4\u7528\u54EA\u4E2A\u6765\u6E90\uFF08game_activities \u7684 sources \u91CC\u7684 id\uFF0C\u6216 own=\u7528\u6237\u81EA\u5DF1\u586B\u7684\u3001screen=\u6E38\u620F\u753B\u9762\u3001default=\u6062\u590D\u9ED8\u8BA4\u987A\u5E8F\uFF09\uFF1B\u7528\u6237\u8BF4\u300C\u7528 PRTS \u7684\u65F6\u95F4\u300D\u65F6\u7528\u3002"
|
|
1479
|
+
].join(""),
|
|
1480
|
+
properties: {
|
|
1481
|
+
game: GAME,
|
|
1482
|
+
id: { type: "string", description: "\u8981\u6539\u7684\u6D3B\u52A8 id\uFF08\u4E0D\u586B\u5C31\u662F\u65B0\u52A0\uFF1B\u540C\u540D\u7684\u5DF2\u6709\u6D3B\u52A8\u4F1A\u5F53\u6210\u540C\u4E00\u4E2A\uFF09\u3002" },
|
|
1483
|
+
name: { type: "string", description: "\u6D3B\u52A8\u540D\uFF1B\u65B0\u52A0\u65F6\u5FC5\u586B\u3002" },
|
|
1484
|
+
starts_at: { type: "string", description: "\u5F00\u59CB\u65F6\u95F4\uFF0C\u5199\u6210 2026/10/25 04:00 \u6216 10/25 04:00\uFF08\u6E38\u620F\u670D\u52A1\u5668\u65F6\u95F4\uFF09\u3002" },
|
|
1485
|
+
ends_at: { type: "string", description: "\u7ED3\u675F\u65F6\u95F4\uFF0C\u5199\u6CD5\u540C\u4E0A\u3002" },
|
|
1486
|
+
kind: { type: "string", description: "\u7C7B\u578B\uFF08\u53EF\u9009\uFF09\uFF0C\u4F8B\u5982\u300CSideStory\u300D\u300C\u7B7E\u5230\u300D\u300C\u9650\u65F6\u5546\u5E97\u300D\u3002" },
|
|
1487
|
+
description: { type: "string", description: "\u8BF4\u660E\uFF08\u53EF\u9009\uFF09\uFF0C500 \u5B57\u4EE5\u5185\u3002" },
|
|
1488
|
+
url: { type: "string", description: "\u6D3B\u52A8\u9875\u9762\u5730\u5740\uFF08\u53EF\u9009\uFF09\u3002" },
|
|
1489
|
+
image: { type: "string", description: "\u6D3B\u52A8\u5361\u7247\u7684\u56FE\u7247\uFF1Ahttps \u56FE\u7247\u7F51\u5740\u3001\u672C\u673A\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84\uFF0C\u6216 screenshot\uFF08\u4F18\u5148\u7EA7\u6700\u4F4E\uFF09\u3002" },
|
|
1490
|
+
use_source: { type: "string", description: "\u56FE\u7247\u548C\u65F6\u95F4\u7528\u54EA\u4E2A\u6765\u6E90\uFF1A\u6765\u6E90 id\u3001own\u3001screen\uFF0C\u6216 default\uFF08\u6062\u590D\u9ED8\u8BA4\u987A\u5E8F\uFF09\u3002\u8981\u6709 id\u3002" },
|
|
1491
|
+
todo: { type: "array", items: { type: "string" }, description: "\u8981\u505A\u7684\u4E8B\uFF08\u53EF\u9009\uFF0C\u66FF\u6362\u539F\u6765\u6CA1\u505A\u5B8C\u7684\u6E05\u5355\uFF09\uFF0C\u4F8B\u5982\u300C\u6D3B\u52A8\u5546\u5E97\u6362\u5B8C\u300D\u3002" },
|
|
1492
|
+
clear: { type: "array", items: { type: "string", enum: Object.keys(OWN_KEYS) }, description: "\u6536\u56DE\u7528\u6237\u586B\u8FC7\u7684\u8FD9\u4E9B\u5B57\u6BB5\uFF08\u6062\u590D\u6210\u6765\u6E90\u7684\u503C\uFF09\u3002" }
|
|
1493
|
+
},
|
|
1494
|
+
required: ["game"],
|
|
1495
|
+
kind: "other",
|
|
1496
|
+
title: (a) => `${typeof a["id"] === "string" ? "\u4FEE\u6539" : "\u6DFB\u52A0"}\u6D3B\u52A8\uFF1A${String(a["name"] ?? a["id"] ?? "")}`,
|
|
1497
|
+
execute: async (args, exec) => {
|
|
1498
|
+
const a = parse(external_exports.object({
|
|
1499
|
+
game: external_exports.string(),
|
|
1500
|
+
id: external_exports.string().nullish(),
|
|
1501
|
+
name: external_exports.string().max(60).nullish(),
|
|
1502
|
+
starts_at: external_exports.string().nullish(),
|
|
1503
|
+
ends_at: external_exports.string().nullish(),
|
|
1504
|
+
kind: external_exports.string().max(20).nullish(),
|
|
1505
|
+
description: external_exports.string().max(500).nullish(),
|
|
1506
|
+
url: external_exports.string().regex(/^https?:\/\/\S+$/, "\u53EA\u80FD\u662F http \u6216 https \u7F51\u5740").nullish(),
|
|
1507
|
+
image: external_exports.string().nullish(),
|
|
1508
|
+
todo: external_exports.array(external_exports.string().min(1).max(80)).max(30).nullish(),
|
|
1509
|
+
use_source: external_exports.string().nullish(),
|
|
1510
|
+
clear: external_exports.array(external_exports.enum(Object.keys(OWN_KEYS))).nullish()
|
|
1511
|
+
}), args);
|
|
1512
|
+
const game = known(a.game);
|
|
1513
|
+
if (a.id == null && (a.name == null || a.name.trim() === ""))
|
|
1514
|
+
throw new Error("\u65B0\u52A0\u6D3B\u52A8\u8981\u5199 name\uFF1B\u6539\u5DF2\u6709\u7684\u6D3B\u52A8\u8981\u5199 id\uFF08game_activities \u53EF\u67E5\uFF09");
|
|
1515
|
+
if (a.id == null && a.use_source != null)
|
|
1516
|
+
throw new Error("use_source \u8981\u548C id \u4E00\u8D77\u7528\uFF1A\u5148\u7528 game_activities \u67E5\u5230\u8FD9\u4E2A\u6D3B\u52A8");
|
|
1517
|
+
const when = (text, what) => {
|
|
1518
|
+
if (text == null)
|
|
1519
|
+
return void 0;
|
|
1520
|
+
const at = parseDateText(text, game.timezone, deps.now());
|
|
1521
|
+
if (at == null)
|
|
1522
|
+
throw new Error(`${what}\u300C${text}\u300D\u770B\u4E0D\u61C2\uFF1A\u5199\u6210 2026/10/25 04:00 \u6216 10/25 04:00`);
|
|
1523
|
+
return at;
|
|
1524
|
+
};
|
|
1525
|
+
const patch = {
|
|
1526
|
+
...a.name == null ? {} : { name: a.name },
|
|
1527
|
+
...a.starts_at == null ? {} : { startsAt: when(a.starts_at, "\u5F00\u59CB\u65F6\u95F4") },
|
|
1528
|
+
...a.ends_at == null ? {} : { endsAt: when(a.ends_at, "\u7ED3\u675F\u65F6\u95F4") },
|
|
1529
|
+
...a.kind == null ? {} : { kind: a.kind },
|
|
1530
|
+
...a.description == null ? {} : { description: a.description },
|
|
1531
|
+
...a.url == null ? {} : { url: a.url },
|
|
1532
|
+
...a.todo == null ? {} : { todo: a.todo }
|
|
1533
|
+
};
|
|
1534
|
+
for (const key of a.clear ?? [])
|
|
1535
|
+
patch[OWN_KEYS[key]] = null;
|
|
1536
|
+
const sessionId = exec.agent?.session.id;
|
|
1537
|
+
const edited = Object.keys(patch).length > 0 || a.image != null;
|
|
1538
|
+
let activity = edited || a.id == null ? await deps.saveActivity(game.id, a.id ?? void 0, patch, a.image ?? void 0, sessionId) : void 0;
|
|
1539
|
+
if (a.use_source != null)
|
|
1540
|
+
activity = await deps.chooseSource(a.id, a.use_source === "default" ? null : a.use_source === "own" ? OWN_SOURCE : a.use_source === "screen" ? SCREEN_SOURCE : a.use_source);
|
|
1541
|
+
if (activity === void 0)
|
|
1542
|
+
throw new Error("\u6CA1\u6709\u8981\u6539\u7684\u5185\u5BB9\uFF1A\u5199\u4E0A\u8981\u6539\u7684\u5B57\u6BB5\u3001image \u6216 use_source");
|
|
1543
|
+
return { saved: brief(activity, game.timezone), note: a.id == null ? "\u5DF2\u52A0\u5230\u6D3B\u52A8\u65E5\u5386\uFF1B\u6E38\u620F\u9875\u548C\u65E5\u62A5\u91CC\u90FD\u80FD\u770B\u5230" : "\u5DF2\u6539\u597D" };
|
|
1544
|
+
}
|
|
1545
|
+
}),
|
|
1546
|
+
tool({
|
|
1547
|
+
name: "game_activity_remove",
|
|
1548
|
+
description: "\u53BB\u6389\u6D3B\u52A8\uFF1Awhat=mine \u53EA\u6536\u56DE\u7528\u6237\u81EA\u5DF1\u586B\u7684\u5185\u5BB9\uFF08\u540D\u5B57\u3001\u65F6\u95F4\u3001\u56FE\u7247\u7B49\u6062\u590D\u6210\u6765\u6E90\u7684\uFF1B\u53EA\u6709\u7528\u6237\u586B\u7684\u6D3B\u52A8\u4F1A\u6574\u4E2A\u53BB\u6389\uFF09\uFF1Bwhat=all \u628A\u6D3B\u52A8\u4ECE\u65E5\u5386\u53BB\u6389\uFF08\u6570\u636E\u7AD9\u8FD8\u5217\u7740\u7684\u8BDD\uFF0C\u4E0B\u6B21\u5237\u65B0\u4F1A\u518D\u51FA\u73B0\uFF09\u3002\u53EA\u5728\u7528\u6237\u8981\u6C42\u65F6\u7528\u3002",
|
|
1549
|
+
properties: {
|
|
1550
|
+
id: { type: "string", description: "\u6D3B\u52A8 id\uFF08game_activities \u53EF\u67E5\uFF09\u3002" },
|
|
1551
|
+
what: { type: "string", enum: ["mine", "all"], description: "mine\uFF1A\u53EA\u6536\u56DE\u7528\u6237\u586B\u7684\uFF1Ball\uFF1A\u6574\u4E2A\u53BB\u6389\uFF08\u9ED8\u8BA4\uFF09\u3002" }
|
|
1552
|
+
},
|
|
1553
|
+
required: ["id"],
|
|
1554
|
+
kind: "other",
|
|
1555
|
+
title: (a) => `${a["what"] === "mine" ? "\u6062\u590D" : "\u53BB\u6389"}\u6D3B\u52A8\uFF1A${String(a["id"] ?? "")}`,
|
|
1556
|
+
execute: async (args) => {
|
|
1557
|
+
const a = parse(external_exports.object({ id: external_exports.string(), what: external_exports.enum(["mine", "all"]).nullish() }), args);
|
|
1558
|
+
const activity = await deps.removeActivity(a.id, a.what ?? "all");
|
|
1559
|
+
const game = activity === void 0 ? void 0 : deps.games().find((g) => g.id === activity.game);
|
|
1560
|
+
return activity === void 0 || game === void 0 ? { removed: a.id } : { restored: brief(activity, game.timezone) };
|
|
1561
|
+
}
|
|
1562
|
+
}),
|
|
1210
1563
|
tool({
|
|
1211
1564
|
name: "game_launch",
|
|
1212
1565
|
description: "\u6E38\u620F\u6CA1\u5F00\u65F6\u542F\u52A8\u5B83\uFF1A\u7528\u73A9\u5B83\u7684\u811A\u672C\u5728\u300C\u542F\u52A8\u6E38\u620F\u300D\u91CC\u7684\u8BBE\u7F6E\uFF08\u6A21\u62DF\u5668\u91CC\u7684\u6E38\u620F\u4F1A\u5148\u542F\u52A8\u6A21\u62DF\u5668\uFF1BPC \u7248\u6253\u5F00\u8BBE\u7F6E\u597D\u7684\u7A0B\u5E8F\u6216\u542F\u52A8\u5668\uFF09\uFF0C\u5DF2\u7ECF\u5F00\u7740\u5C31\u4EC0\u4E48\u90FD\u4E0D\u505A\u3002\u6709\u811A\u672C\u6B63\u5728\u7528\u8FD9\u53F0\u6A21\u62DF\u5668\u6216\u9F20\u6807\u952E\u76D8\u65F6\u4F1A\u62D2\u7EDD\u3002\u542F\u52A8\u540E\u622A\u56FE\u786E\u8BA4\uFF1A\u5173\u6389\u516C\u544A\u548C\u66F4\u65B0\u63D0\u793A\uFF0C\u542F\u52A8\u5668\u9700\u8981\u70B9\u300C\u5F00\u59CB\u6E38\u620F\u300D\u5C31\u70B9\uFF1B\u8981\u8F93\u5165\u8D26\u53F7\u5BC6\u7801\u6216\u9A8C\u8BC1\u7801\u65F6\u505C\u4E0B\u4EA4\u7ED9\u7528\u6237\u3002",
|
|
@@ -1273,7 +1626,7 @@ var GAME_ROLE = {
|
|
|
1273
1626
|
duty: [
|
|
1274
1627
|
"# \u4F60\u7684\u89D2\u8272\uFF1A\u6E38\u620F",
|
|
1275
1628
|
"\u4F60\u662F MultiGameAssistant \u7684\u300C\u6E38\u620F\u300Dagent\uFF1A\u8BFB\u6E38\u620F\u7684\u6D3B\u52A8\u3001\u8D44\u8BAF\u548C\u8FDB\u5EA6\u5E76\u8BB0\u4E0B\u6765\uFF08game_record\uFF09\uFF0C\u5199\u65E5\u62A5\uFF0C\u6DFB\u52A0\u6E38\u620F\u3002",
|
|
1276
|
-
"\u4E0D\u5B89\u88C5\u3001\u8FD0\u884C\u6216\u4FEE\u811A\u672C\uFF0C\u4E0D\u6539\u6D41\u6C34\u7EBF\u548C\u5B9A\u65F6\uFF1B\u9700\u8981\u8FD9\u4E9B\u65F6\
|
|
1629
|
+
"\u4E0D\u5B89\u88C5\u3001\u8FD0\u884C\u6216\u4FEE\u811A\u672C\uFF0C\u4E0D\u6539\u6D41\u6C34\u7EBF\u548C\u5B9A\u65F6\uFF1B\u9700\u8981\u8FD9\u4E9B\u65F6\u4EA4\u7ED9\u5BF9\u5E94\u7684\u540C\u4E8B\uFF08agent_delegate\uFF09\uFF0C\u6216\u8005\u5728\u56DE\u590D\u91CC\u8BF4\u6E05\u695A\u3002"
|
|
1277
1630
|
].join("\n")
|
|
1278
1631
|
};
|
|
1279
1632
|
var SKILL = new URL("../skills/game-intel.md", import.meta.url);
|
|
@@ -1318,6 +1671,8 @@ var AdgGameIntel = class extends Service {
|
|
|
1318
1671
|
this.ready = (async () => {
|
|
1319
1672
|
await calendar.load();
|
|
1320
1673
|
await this.loadGames(log);
|
|
1674
|
+
await this.adoptEvidence().catch((error) => log.warn(`old screenshots not converted: ${String(error)}`));
|
|
1675
|
+
await calendar.rederive((game) => this.timezone(game)).catch((error) => log.warn(`calendar not worked out again: ${String(error)}`));
|
|
1321
1676
|
daily.start();
|
|
1322
1677
|
})();
|
|
1323
1678
|
ctx.effect(() => () => this.daily.stop(), "adg-game-intel daily report");
|
|
@@ -1379,6 +1734,26 @@ var AdgGameIntel = class extends Service {
|
|
|
1379
1734
|
add: async (manifest, guide) => {
|
|
1380
1735
|
await this.ready;
|
|
1381
1736
|
return this.addGame(manifest, guide);
|
|
1737
|
+
},
|
|
1738
|
+
saveActivity: async (game, id, patch, image, sessionId) => {
|
|
1739
|
+
await this.ready;
|
|
1740
|
+
if (image?.trim() === "screenshot") {
|
|
1741
|
+
const shot = await this.imageFrom(image, sessionId);
|
|
1742
|
+
return this.saveAgentShot(await this.saveActivity(game, id, patch), shot, sessionId);
|
|
1743
|
+
}
|
|
1744
|
+
return this.saveActivity(game, id, patch, image === void 0 ? void 0 : await this.imageFrom(image, sessionId));
|
|
1745
|
+
},
|
|
1746
|
+
chooseSource: async (id, source) => {
|
|
1747
|
+
await this.ready;
|
|
1748
|
+
return this.chooseSource(id, source);
|
|
1749
|
+
},
|
|
1750
|
+
removeActivity: async (id, what) => {
|
|
1751
|
+
await this.ready;
|
|
1752
|
+
if (what === "mine")
|
|
1753
|
+
return this.resetActivity(id);
|
|
1754
|
+
if (!await this.removeActivity(id))
|
|
1755
|
+
throw new Error("\u6CA1\u6709\u8FD9\u4E2A\u6D3B\u52A8\uFF08\u53EF\u80FD\u5DF2\u7ECF\u7ED3\u675F\u88AB\u6E05\u6389\u4E86\uFF09");
|
|
1756
|
+
return void 0;
|
|
1382
1757
|
}
|
|
1383
1758
|
}))
|
|
1384
1759
|
registered.push(agent.tools.register({ ...tool2, execute: async (args, exec) => {
|
|
@@ -1430,9 +1805,13 @@ var AdgGameIntel = class extends Service {
|
|
|
1430
1805
|
return settings;
|
|
1431
1806
|
},
|
|
1432
1807
|
"games/evidence": async (params) => {
|
|
1808
|
+
await this.ready;
|
|
1433
1809
|
const id = params.activityId;
|
|
1434
|
-
|
|
1810
|
+
const screen = calendar.get(id)?.screen;
|
|
1811
|
+
if (screen?.evidence !== true)
|
|
1435
1812
|
throw new Error("\u8FD9\u4E2A\u6D3B\u52A8\u6CA1\u6709\u4FDD\u5B58\u622A\u56FE");
|
|
1813
|
+
if (screen.image !== void 0)
|
|
1814
|
+
return this.picture(screen.image);
|
|
1436
1815
|
return { mediaType: "image/png", data: (await readFile2(this.evidenceFile(id))).toString("base64") };
|
|
1437
1816
|
},
|
|
1438
1817
|
"games/image": async (params) => {
|
|
@@ -1491,9 +1870,23 @@ var AdgGameIntel = class extends Service {
|
|
|
1491
1870
|
},
|
|
1492
1871
|
"games/activity/remove": async (params) => {
|
|
1493
1872
|
await this.ready;
|
|
1494
|
-
await
|
|
1495
|
-
changed();
|
|
1873
|
+
await this.removeActivity(params.activityId);
|
|
1496
1874
|
return {};
|
|
1875
|
+
},
|
|
1876
|
+
"games/activity/save": async (params) => {
|
|
1877
|
+
await this.ready;
|
|
1878
|
+
const { game, activityId, image, todo, ...fields } = params;
|
|
1879
|
+
return this.saveActivity(game, activityId, { ...fields, ...todo === void 0 ? {} : { todo } }, image === void 0 ? void 0 : Buffer.from(image.data, "base64"));
|
|
1880
|
+
},
|
|
1881
|
+
"games/activity/source": async (params) => {
|
|
1882
|
+
await this.ready;
|
|
1883
|
+
const { activityId, source } = params;
|
|
1884
|
+
return this.chooseSource(activityId, source);
|
|
1885
|
+
},
|
|
1886
|
+
"games/activity/reset": async (params) => {
|
|
1887
|
+
await this.ready;
|
|
1888
|
+
const activity = await this.resetActivity(params.activityId);
|
|
1889
|
+
return activity === void 0 ? {} : { activity };
|
|
1497
1890
|
}
|
|
1498
1891
|
}
|
|
1499
1892
|
});
|
|
@@ -1508,6 +1901,14 @@ var AdgGameIntel = class extends Service {
|
|
|
1508
1901
|
* gave are fetched: this is not a general-purpose proxy.
|
|
1509
1902
|
*/
|
|
1510
1903
|
async picture(url) {
|
|
1904
|
+
if (OWN_IMAGE.test(url) || SHOT_IMAGE.test(url)) {
|
|
1905
|
+
const [kind, file] = url.split(":");
|
|
1906
|
+
const mediaType2 = IMAGE_TYPES.find(([ext2]) => file.endsWith(`.${ext2}`))[1];
|
|
1907
|
+
const bytes2 = await readFile2(join2(this.imageDir(kind), file)).catch(() => {
|
|
1908
|
+
throw new Error("\u8FD9\u5F20\u56FE\u7247\u5DF2\u7ECF\u4E0D\u5728\u4E86");
|
|
1909
|
+
});
|
|
1910
|
+
return { mediaType: mediaType2, data: bytes2.toString("base64") };
|
|
1911
|
+
}
|
|
1511
1912
|
if (!this.calendar.pictures().has(url) && !this.games.some((g) => g.manifest.art === url))
|
|
1512
1913
|
throw new Error("\u8FD9\u5F20\u56FE\u7247\u4E0D\u662F\u6570\u636E\u7AD9\u6216\u6E38\u620F\u5305\u7ED9\u7684\u5730\u5740");
|
|
1513
1914
|
const name = createHash("sha256").update(url).digest("hex").slice(0, 32);
|
|
@@ -1584,6 +1985,117 @@ var AdgGameIntel = class extends Service {
|
|
|
1584
1985
|
await this.loadGames(this.log);
|
|
1585
1986
|
this.changed(gameId);
|
|
1586
1987
|
}
|
|
1988
|
+
// ── the user's own events ──
|
|
1989
|
+
/**
|
|
1990
|
+
* Add an event of the user's own, or write their word on one (see
|
|
1991
|
+
* `Calendar.saveOwn`); `image`: a new picture, kept under
|
|
1992
|
+
* `<data>/games/images/own/`. @throws Error with what is wrong.
|
|
1993
|
+
*/
|
|
1994
|
+
async saveActivity(gameId, activityId, patch, image) {
|
|
1995
|
+
const { manifest } = this.game(gameId);
|
|
1996
|
+
if (activityId !== void 0 && this.calendar.get(activityId)?.game !== manifest.id)
|
|
1997
|
+
throw new Error(`${manifest.name}\u6CA1\u6709\u6D3B\u52A8\u300C${activityId}\u300D\uFF08\u53EF\u80FD\u5DF2\u7ECF\u7ED3\u675F\u88AB\u6E05\u6389\u4E86\uFF1Bgame_activities \u53EF\u67E5\uFF09`);
|
|
1998
|
+
const cover = image === void 0 ? patch.cover : await this.keepImage(image);
|
|
1999
|
+
const activity = await this.calendar.saveOwn({ game: manifest.id, id: activityId }, { ...patch, ...cover === void 0 ? {} : { cover } }, this.clock.now(), manifest.timezone);
|
|
2000
|
+
await this.sweepImages();
|
|
2001
|
+
this.changed(manifest.id);
|
|
2002
|
+
if (activity === void 0)
|
|
2003
|
+
throw new Error("\u4EC0\u4E48\u90FD\u6CA1\u7559\u4E0B\uFF1A\u8FD9\u4E2A\u6D3B\u52A8\u53EA\u6709\u4F60\u586B\u7684\u5185\u5BB9\uFF0C\u6E05\u7A7A\u540E\u5C31\u4ECE\u65E5\u5386\u53BB\u6389\u4E86");
|
|
2004
|
+
return activity;
|
|
2005
|
+
}
|
|
2006
|
+
timezone(game) {
|
|
2007
|
+
return this.games.find((g) => g.manifest.id === game)?.manifest.timezone ?? "Asia/Shanghai";
|
|
2008
|
+
}
|
|
2009
|
+
/** Keep the agent's screenshot of an event as what it read from the screen: the lowest rank of picture. */
|
|
2010
|
+
async saveAgentShot(saved, bytes, sessionId) {
|
|
2011
|
+
const shot = await this.keepImage(bytes, "shot");
|
|
2012
|
+
const activity = await this.calendar.setShot(saved.id, shot, { now: this.clock.now(), timeZone: this.timezone(saved.game), sessionId });
|
|
2013
|
+
await this.sweepImages();
|
|
2014
|
+
this.changed(saved.game);
|
|
2015
|
+
return activity ?? saved;
|
|
2016
|
+
}
|
|
2017
|
+
/** Which source an event's picture and dates come from; `null`: the default order. */
|
|
2018
|
+
async chooseSource(activityId, source) {
|
|
2019
|
+
const before = this.calendar.get(activityId);
|
|
2020
|
+
if (before === void 0)
|
|
2021
|
+
throw new Error("\u6CA1\u6709\u8FD9\u4E2A\u6D3B\u52A8\uFF08\u53EF\u80FD\u5DF2\u7ECF\u7ED3\u675F\u88AB\u6E05\u6389\u4E86\uFF09");
|
|
2022
|
+
const activity = await this.calendar.chooseSource(activityId, source, this.timezone(before.game));
|
|
2023
|
+
if (activity === void 0)
|
|
2024
|
+
throw new Error("\u6CA1\u6709\u8FD9\u4E2A\u6D3B\u52A8\uFF08\u53EF\u80FD\u5DF2\u7ECF\u7ED3\u675F\u88AB\u6E05\u6389\u4E86\uFF09");
|
|
2025
|
+
this.changed(before.game);
|
|
2026
|
+
return activity;
|
|
2027
|
+
}
|
|
2028
|
+
/** Take back what the user wrote on an event. @returns it as it is now; undefined when it went. */
|
|
2029
|
+
async resetActivity(activityId) {
|
|
2030
|
+
const before = this.calendar.get(activityId);
|
|
2031
|
+
if (before === void 0)
|
|
2032
|
+
throw new Error("\u6CA1\u6709\u8FD9\u4E2A\u6D3B\u52A8\uFF08\u53EF\u80FD\u5DF2\u7ECF\u7ED3\u675F\u88AB\u6E05\u6389\u4E86\uFF09");
|
|
2033
|
+
const activity = await this.calendar.resetOwn(activityId, this.timezone(before.game));
|
|
2034
|
+
await this.sweepImages();
|
|
2035
|
+
this.changed(before.game);
|
|
2036
|
+
return activity;
|
|
2037
|
+
}
|
|
2038
|
+
async removeActivity(activityId) {
|
|
2039
|
+
const removed = await this.calendar.remove(activityId);
|
|
2040
|
+
await this.sweepImages();
|
|
2041
|
+
this.changed();
|
|
2042
|
+
return removed;
|
|
2043
|
+
}
|
|
2044
|
+
/**
|
|
2045
|
+
* A picture for an event, as the agent names it: an http(s) address (fetched
|
|
2046
|
+
* now and kept, so it stays when the page goes), a file on this computer
|
|
2047
|
+
* (a path relative to the workspace is fine), or `screenshot`, the last
|
|
2048
|
+
* screenshot of this conversation.
|
|
2049
|
+
*/
|
|
2050
|
+
async imageFrom(source, sessionId) {
|
|
2051
|
+
const from = source.trim();
|
|
2052
|
+
if (from === "screenshot") {
|
|
2053
|
+
const shot = sessionId === void 0 ? void 0 : this.ctx.get("adgIntervene")?.lastShot(sessionId);
|
|
2054
|
+
if (shot === void 0)
|
|
2055
|
+
throw new Error("\u8FD9\u4E2A\u5BF9\u8BDD\u8FD8\u6CA1\u6709\u622A\u56FE\uFF1A\u5148\u7528 screen_capture \u622A\u4E00\u5F20");
|
|
2056
|
+
return shot;
|
|
2057
|
+
}
|
|
2058
|
+
if (/^https?:\/\//i.test(from)) {
|
|
2059
|
+
const response = await fetch(from, { signal: AbortSignal.timeout(2e4), headers: { accept: "image/*", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) MultiGameAssistant" } });
|
|
2060
|
+
if (!response.ok)
|
|
2061
|
+
throw new Error(`\u56FE\u7247\u8BFB\u4E0D\u5230\uFF1AHTTP ${response.status}`);
|
|
2062
|
+
return Buffer.from(await response.arrayBuffer());
|
|
2063
|
+
}
|
|
2064
|
+
const path = from.replace(/^file:\/\/\/?/i, "");
|
|
2065
|
+
const workspace = this.ctx.get("adgGateway")?.workspaceDir();
|
|
2066
|
+
const full = isAbsolute(path) || workspace === void 0 ? path : resolve(workspace, path);
|
|
2067
|
+
return readFile2(full).catch(() => {
|
|
2068
|
+
throw new Error(`\u8BFB\u4E0D\u5230\u56FE\u7247\u6587\u4EF6\uFF1A${full}`);
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Keep a picture the user added (`own`) or a screenshot an event was read
|
|
2073
|
+
* from (`shot`), named by its content. @returns its address (`own:<hash>.<ext>`).
|
|
2074
|
+
*/
|
|
2075
|
+
async keepImage(bytes, kind = "own") {
|
|
2076
|
+
if (kind === "own" && bytes.length > MAX_IMAGE_BYTES)
|
|
2077
|
+
throw new Error("\u56FE\u7247\u592A\u5927\uFF08\u6700\u591A 8 MB\uFF09");
|
|
2078
|
+
const ext = imageType(bytes);
|
|
2079
|
+
if (ext === void 0)
|
|
2080
|
+
throw new Error("\u4E0D\u662F\u652F\u6301\u7684\u56FE\u7247\uFF08png\u3001jpg\u3001gif\u3001webp\u3001avif\uFF09");
|
|
2081
|
+
const file = `${createHash("sha256").update(bytes).digest("hex").slice(0, 32)}.${ext}`;
|
|
2082
|
+
const dir = this.imageDir(kind);
|
|
2083
|
+
await mkdir2(dir, { recursive: true });
|
|
2084
|
+
await writeFile(join2(dir, file), bytes);
|
|
2085
|
+
return `${kind}:${file}`;
|
|
2086
|
+
}
|
|
2087
|
+
imageDir(kind) {
|
|
2088
|
+
return join2(this.dir, "images", kind === "own" ? "own" : "shots");
|
|
2089
|
+
}
|
|
2090
|
+
/** Pictures the user added, and screenshots, that no event has any more. */
|
|
2091
|
+
async sweepImages() {
|
|
2092
|
+
for (const [kind, used] of [["own", this.calendar.ownImages()], ["shot", this.calendar.shotImages()]]) {
|
|
2093
|
+
const dir = this.imageDir(kind);
|
|
2094
|
+
const files = await readdir(dir).catch(() => []);
|
|
2095
|
+
await Promise.all(files.filter((f) => !used.has(`${kind}:${f}`)).map((f) => rm(join2(dir, f), { force: true }).catch(() => {
|
|
2096
|
+
})));
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
1587
2099
|
/**
|
|
1588
2100
|
* The scripts that play each game: the ones its pack lists, and installed
|
|
1589
2101
|
* scripts whose id, name, repository or pack names it (script-match.ts),
|
|
@@ -1715,6 +2227,7 @@ var AdgGameIntel = class extends Service {
|
|
|
1715
2227
|
results.push({ game: manifest.id, ok: failures.length === 0 || count > 0, count, ...failures.length === 0 ? {} : { detail: failures.join("\uFF1B") } });
|
|
1716
2228
|
this.changed(manifest.id);
|
|
1717
2229
|
}
|
|
2230
|
+
await this.sweepImages();
|
|
1718
2231
|
return results;
|
|
1719
2232
|
}
|
|
1720
2233
|
// ── what the agent read ──
|
|
@@ -1731,21 +2244,38 @@ var AdgGameIntel = class extends Service {
|
|
|
1731
2244
|
return { ...event, source: { id: link.id, name: link.name } };
|
|
1732
2245
|
return host === void 0 ? event : { ...event, source: { id: "agent", name: `${host}\uFF08agent \u67E5\u5230\uFF09` } };
|
|
1733
2246
|
});
|
|
1734
|
-
const
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
sessionId,
|
|
1738
|
-
...shot === void 0 ? {} : {
|
|
1739
|
-
evidence: async (activity) => {
|
|
1740
|
-
await mkdir2(join2(this.dir, "evidence"), { recursive: true });
|
|
1741
|
-
await writeFile(this.evidenceFile(activity.id), shot);
|
|
1742
|
-
return true;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
2247
|
+
const kept = shot === void 0 ? void 0 : await this.keepImage(shot, "shot").catch((error) => {
|
|
2248
|
+
this.log.warn(`screenshot not kept: ${error instanceof Error ? error.message : String(error)}`);
|
|
2249
|
+
return void 0;
|
|
1745
2250
|
});
|
|
2251
|
+
const written = await this.calendar.applyRead(gameId, from, credited, { now: this.clock.now(), timeZone: manifest.timezone, sessionId, shot: kept });
|
|
2252
|
+
await this.sweepImages();
|
|
1746
2253
|
this.changed(gameId);
|
|
1747
2254
|
return written;
|
|
1748
2255
|
}
|
|
2256
|
+
/**
|
|
2257
|
+
* Screenshots kept before they were pictures: one file per event under
|
|
2258
|
+
* `evidence/`. Each becomes a `shot:` picture (and its event's background).
|
|
2259
|
+
*/
|
|
2260
|
+
async adoptEvidence() {
|
|
2261
|
+
const shots = /* @__PURE__ */ new Map();
|
|
2262
|
+
for (const a of this.calendar.list()) {
|
|
2263
|
+
if (a.screen?.evidence !== true || a.screen.image !== void 0)
|
|
2264
|
+
continue;
|
|
2265
|
+
const file = this.evidenceFile(a.id);
|
|
2266
|
+
const bytes = await readFile2(file).catch(() => void 0);
|
|
2267
|
+
if (bytes === void 0)
|
|
2268
|
+
continue;
|
|
2269
|
+
const kept = await this.keepImage(bytes, "shot").catch(() => void 0);
|
|
2270
|
+
if (kept === void 0)
|
|
2271
|
+
continue;
|
|
2272
|
+
shots.set(a.id, kept);
|
|
2273
|
+
await rm(file, { force: true }).catch(() => {
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
await this.calendar.adoptShots(shots, (game) => this.games.find((g) => g.manifest.id === game)?.manifest.timezone ?? "Asia/Shanghai");
|
|
2277
|
+
}
|
|
2278
|
+
/** Where a screenshot was kept before `shot:` pictures. */
|
|
1749
2279
|
evidenceFile(activityId) {
|
|
1750
2280
|
return join2(this.dir, "evidence", `${activityId.replace(/[^\p{L}\p{N}-]+/gu, "_")}.png`);
|
|
1751
2281
|
}
|
|
@@ -1945,6 +2475,20 @@ ${guide.trim()}
|
|
|
1945
2475
|
return { channels, text };
|
|
1946
2476
|
}
|
|
1947
2477
|
};
|
|
2478
|
+
function imageType(bytes) {
|
|
2479
|
+
const ascii = (from, to) => String.fromCharCode(...bytes.subarray(from, to));
|
|
2480
|
+
if (bytes[0] === 137 && ascii(1, 4) === "PNG")
|
|
2481
|
+
return "png";
|
|
2482
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255)
|
|
2483
|
+
return "jpg";
|
|
2484
|
+
if (ascii(0, 4) === "GIF8")
|
|
2485
|
+
return "gif";
|
|
2486
|
+
if (ascii(0, 4) === "RIFF" && ascii(8, 12) === "WEBP")
|
|
2487
|
+
return "webp";
|
|
2488
|
+
if (ascii(4, 8) === "ftyp" && /^avi[fs]$/.test(ascii(8, 12)))
|
|
2489
|
+
return "avif";
|
|
2490
|
+
return void 0;
|
|
2491
|
+
}
|
|
1948
2492
|
function hostName(url) {
|
|
1949
2493
|
try {
|
|
1950
2494
|
return new URL(url).hostname.replace(/^www\./, "");
|
|
@@ -1968,11 +2512,13 @@ export {
|
|
|
1968
2512
|
DEFAULT_SETTINGS,
|
|
1969
2513
|
DailyReport,
|
|
1970
2514
|
GAME_ROLE,
|
|
2515
|
+
OWN_FIELDS,
|
|
1971
2516
|
buildReport,
|
|
1972
2517
|
daysLeft,
|
|
1973
2518
|
lib_default as default,
|
|
1974
2519
|
gameTools,
|
|
1975
2520
|
idKey,
|
|
2521
|
+
imageType,
|
|
1976
2522
|
leftText,
|
|
1977
2523
|
localDay,
|
|
1978
2524
|
nameKey,
|