dsh-multigameassistant 2.0.1 → 2.0.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.
@@ -32,11 +32,11 @@ import {
32
32
  globToRegExp,
33
33
  parseManifest,
34
34
  versionOfTag
35
- } from "./chunk-J46OASOG.js";
35
+ } from "./chunk-OQZ2XZVP.js";
36
36
  import {
37
37
  sessionConversations
38
- } from "./chunk-BNGDT7YT.js";
39
- import "./chunk-ZQ6KFVEO.js";
38
+ } from "./chunk-AWZ4O7BY.js";
39
+ import "./chunk-ZXD4IYZP.js";
40
40
  import {
41
41
  writeFileAtomic
42
42
  } from "./chunk-CCAB6XXZ.js";
@@ -59,7 +59,7 @@ import {
59
59
  optimizeScriptPrompt,
60
60
  parseGitHubLink,
61
61
  taskMessage
62
- } from "./chunk-HPQCV6WO.js";
62
+ } from "./chunk-IH3K4QPN.js";
63
63
  import "./chunk-2UFLGPDY.js";
64
64
 
65
65
  // packages/script-registry/lib/index.js
@@ -94,7 +94,7 @@ var SCRIPT_ROLE = {
94
94
  "\u4F60\u662F MultiGameAssistant \u7684\u300C\u811A\u672C\u300Dagent\uFF1A\u5B89\u88C5\u3001\u66F4\u65B0\u548C\u4ECB\u7ECD\u811A\u672C\uFF0C\u68C0\u67E5\u548C\u4FEE\u597D\u8FD0\u884C\u73AF\u5883\uFF0C\u68C0\u67E5\u811A\u672C\u5305\uFF0C\u5B89\u88C5\u548C\u5408\u5E76\u6280\u80FD\u3002",
95
95
  UPDATE_RULE,
96
96
  "script_update \u4ECE Mirror\u9171\uFF08\u8F6F\u4EF6\u91CC\u7684 CDK\uFF0C\u6216\u811A\u672C\u81EA\u5DF1\u8BBE\u7F6E\u91CC\u586B\u7684 CDK\uFF09\u6216 GitHub \u7684\u53D1\u5E03\u5305\u4E0B\u8F7D\uFF0C\u5E76\u63A5\u4E0A\u539F\u6765\u7684\u914D\u7F6E\u3002\u8FD0\u884C\u4EFB\u52A1\u524D\u8F6F\u4EF6\u4E5F\u4F1A\u5148\u8FD9\u6837\u66F4\u65B0\u4E00\u6B21\uFF08\u8DDF\u7740\u5206\u652F\u6E90\u7801\u7684\u811A\u672C\u4E0D\u4F1A\u81EA\u52A8\u66F4\u65B0\uFF09\uFF0C\u66F4\u65B0\u5931\u8D25\u5C31\u7167\u65E7\u7528\u73B0\u6709\u7248\u672C\u8FD0\u884C\u3002",
97
- "\u4E0D\u8BFB\u6E38\u620F\u6D3B\u52A8\u3001\u4E0D\u5199\u65E5\u62A5\u3001\u4E0D\u6539\u6D41\u6C34\u7EBF\u548C\u5B9A\u65F6\uFF1B\u9700\u8981\u8FD9\u4E9B\u65F6\u5728\u56DE\u590D\u91CC\u8BF4\u6E05\u695A\uFF0C\u7528\u6237\u4F1A\u4EA4\u7ED9\u5BF9\u5E94\u7684 agent\u3002"
97
+ "\u4E0D\u8BFB\u6E38\u620F\u6D3B\u52A8\u3001\u4E0D\u5199\u65E5\u62A5\u3001\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"
98
98
  ].join("\n")
99
99
  };
100
100
 
@@ -429,7 +429,8 @@ var DEFAULT_SETTINGS = {
429
429
  tokenRef: "GITHUB_TOKEN",
430
430
  keepVersions: 3,
431
431
  includePrereleases: false,
432
- cdkRef: "MIRRORCHYAN_CDK"
432
+ cdkRef: "MIRRORCHYAN_CDK",
433
+ autoUpdate: "ask"
433
434
  };
434
435
  var StateFile = external_exports.object({
435
436
  version: external_exports.literal(1),
@@ -911,18 +912,24 @@ var ScriptLibrary = class {
911
912
  return { upToDate: false, ...this.#jobs.start("update", id, (ctl) => this.#installJob(id, source, { byAgent: options.byAgent }, channels, this.#packOf(script), ctl)) };
912
913
  }
913
914
  /**
914
- * Before a task runs: update when a newer version is out. Never throws —
915
- * the run goes on with what it has. Left alone: a script without an update
915
+ * Before a task runs: update when a newer version is out and the settings
916
+ * say `auto`; otherwise only check, and leave the update to the user. Never
917
+ * throws — the run goes on with what it has. Left alone: a script without an update
916
918
  * channel, one following a branch's source (official releases only), or one another job is installing. A release that is a setup
917
919
  * program is left waiting for the agent and counts as not updated.
918
920
  */
919
921
  async updateBeforeRun(id, signal) {
920
- const script = this.#script(id);
921
- const channels = this.#channels(script);
922
- if (channels.github === void 0 && channels.mirror === void 0 || this.#jobs.active(id) !== void 0)
923
- return { state: "skipped" };
924
- if (script.sourceBranch !== void 0)
922
+ if (!this.#checkable(id))
925
923
  return { state: "skipped" };
924
+ const policy = this.#state.settings.autoUpdate;
925
+ if (policy !== "auto") {
926
+ try {
927
+ const check = await this.checkUpdate(id, AbortSignal.any([signal, AbortSignal.timeout(PRE_RUN_CHECK_MS)]));
928
+ return check.available ? { state: "available", version: check.latest, policy } : { state: "current" };
929
+ } catch {
930
+ return { state: "skipped" };
931
+ }
932
+ }
926
933
  try {
927
934
  const started = await this.update(id, AbortSignal.any([signal, AbortSignal.timeout(PRE_RUN_CHECK_MS)]), { byAgent: true });
928
935
  if (started.upToDate)
@@ -941,6 +948,31 @@ var ScriptLibrary = class {
941
948
  return { state: "failed", error: signal.aborted ? "\u5DF2\u505C\u6B62" : errorText(error) };
942
949
  }
943
950
  }
951
+ /**
952
+ * Check every script that can update on its own (see {@link updateBeforeRun}) for a newer version,
953
+ * one after another; what it finds is on each script (`update`). Never throws.
954
+ */
955
+ async checkUpdates(signal) {
956
+ for (const { id } of [...this.#state.scripts]) {
957
+ if (signal?.aborted === true)
958
+ return;
959
+ if (!this.#checkable(id))
960
+ continue;
961
+ try {
962
+ await this.checkUpdate(id, signal);
963
+ } catch (error) {
964
+ this.#options.log.info(`update check for ${id} failed: ${errorText(error)}`);
965
+ }
966
+ }
967
+ }
968
+ /** It has an update channel, follows releases (not a branch's source), and nothing is installing it. */
969
+ #checkable(id) {
970
+ const script = this.#script(id);
971
+ const channels = this.#channels(script);
972
+ if (channels.github === void 0 && channels.mirror === void 0)
973
+ return false;
974
+ return script.sourceBranch === void 0 && this.#jobs.active(id) === void 0;
975
+ }
944
976
  /**
945
977
  * Set a script's update channels: a value sets it, `null` turns it off,
946
978
  * `reset` goes back to the automatic one. How it was installed stays its
@@ -989,9 +1021,10 @@ var ScriptLibrary = class {
989
1021
  const { version, archive } = fetched;
990
1022
  if (archive === void 0 && script !== void 0) {
991
1023
  script.current = version;
1024
+ delete script.update;
992
1025
  await this.#save();
993
1026
  this.#options.onChanged(scriptId);
994
- ctl.phase("done", { message: `${version} \u5DF2\u5B89\u88C5\uFF0C\u5DF2\u5207\u6362\u4E3A\u5F53\u524D\u7248\u672C` });
1027
+ ctl.phase("done", { message: `${version} \u5DF2\u5B89\u88C5\uFF0C\u5DF2\u5207\u6362\u4E3A\u5F53\u524D\u7248\u672C`, version });
995
1028
  return version;
996
1029
  }
997
1030
  const versionDir = join2(this.toolsDir, scriptId, dirName(version));
@@ -3119,6 +3152,11 @@ var describeJob = (job) => job.phase === "done" ? { ok: true, script: job.script
3119
3152
  function scriptTools(library, approve) {
3120
3153
  const repo = { type: "string", description: "GitHub \u4ED3\u5E93\uFF0C\u683C\u5F0F owner/repo\uFF0C\u4F8B\u5982 MaaAssistantArknights/MaaAssistantArknights\u3002" };
3121
3154
  const id = { type: "string", description: "\u811A\u672C\u5E93\u91CC\u7684\u811A\u672C id\uFF08script_list \u53EF\u67E5\uFF09\u3002" };
3155
+ const AUTO_UPDATE_NOTE = {
3156
+ auto: "\u7528\u6237\u8BBE\u7F6E\u4E3A\u81EA\u52A8\u66F4\u65B0\uFF1A\u6709\u65B0\u7248\u672C\u65F6\u8FD0\u884C\u524D\u4F1A\u81EA\u52A8\u66F4\u65B0\uFF0C\u4F60\u4E5F\u53EF\u4EE5\u81EA\u5DF1\u51B3\u5B9A\u66F4\u65B0",
3157
+ ask: "\u7528\u6237\u8BBE\u7F6E\u4E3A\u5148\u95EE\u518D\u66F4\u65B0\uFF1A\u6709\u65B0\u7248\u672C\u65F6\u8F6F\u4EF6\u4F1A\u5F39\u51FA\u63D0\u793A\u8BA9\u7528\u6237\u51B3\u5B9A\uFF1B\u53EA\u5728\u7528\u6237\u8981\u6C42\u65F6\u66F4\u65B0",
3158
+ off: "\u7528\u6237\u8BBE\u7F6E\u4E3A\u4E0D\u81EA\u52A8\u66F4\u65B0\uFF1A\u53EA\u5728\u7528\u6237\u8981\u6C42\u65F6\u66F4\u65B0"
3159
+ };
3122
3160
  return [
3123
3161
  tool({
3124
3162
  name: TOOL_NAMES.list,
@@ -3129,8 +3167,10 @@ function scriptTools(library, approve) {
3129
3167
  title: () => "\u67E5\u770B\u811A\u672C\u5E93",
3130
3168
  execute: async () => {
3131
3169
  const { scripts, packs, toolsDir } = library.list();
3170
+ const { autoUpdate } = await library.settings();
3132
3171
  return {
3133
3172
  toolsDir,
3173
+ autoUpdate: AUTO_UPDATE_NOTE[autoUpdate],
3134
3174
  scripts: scripts.map((s) => ({ id: s.id, name: s.name, source: s.source, version: s.source.kind === "local" ? s.localVersion?.version ?? "\uFF08\u8BA4\u4E0D\u51FA\uFF09" : s.current, channels: s.channels, dir: s.dir, family: s.family, versions: s.versions.map((v) => v.version), env: s.env === void 0 ? void 0 : { ok: s.env.ok, problems: s.env.items.filter((i) => i.status !== "ok" && i.status !== "unsupported").map((i) => `${i.label}: ${i.status}`) }, update: s.update })),
3135
3175
  availablePacks: packs.filter((p) => !p.installed && p.error === void 0).map((p) => ({ id: p.id, name: p.name, repo: p.repo, description: p.description }))
3136
3176
  };
@@ -3229,7 +3269,7 @@ function scriptTools(library, approve) {
3229
3269
  }),
3230
3270
  tool({
3231
3271
  name: TOOL_NAMES.update,
3232
- description: "\u68C0\u67E5\u5E76\u66F4\u65B0\u811A\u672C\u5230\u6700\u65B0\u53D1\u5E03\u7248\u672C\uFF08\u586B\u4E86 Mirror\u9171 CDK \u4E14\u811A\u672C\u5728 Mirror\u9171 \u53D1\u5E03\u65F6\u4ECE\u90A3\u91CC\u4E0B\u8F7D\uFF0C\u5426\u5219\u4ECE GitHub\uFF09\u3002\u5B89\u88C5\u7684\u811A\u672C\uFF1A\u65B0\u7248\u672C\u88C5\u5728\u65E7\u7248\u672C\u65C1\u8FB9\uFF0C\u914D\u7F6E\u6587\u4EF6\u5E26\u8FC7\u53BB\uFF0C\u65E7\u7248\u672C\u4FDD\u7559\u7528\u4E8E\u56DE\u6EDA\u3002\u672C\u5730\u5BFC\u5165\u7684\u811A\u672C\uFF1A\u5728\u5B83\u81EA\u5DF1\u7684\u76EE\u5F55\u91CC\u66F4\u65B0\uFF08\u4F1A\u5148\u8BF7\u7528\u6237\u786E\u8BA4\uFF09\uFF0C\u88AB\u66FF\u6362\u7684\u6587\u4EF6\u5148\u5907\u4EFD\uFF0C\u5DF2\u6709\u7684\u914D\u7F6E\u6587\u4EF6\u4E0D\u52A8\uFF0C\u53EF\u7528 script_rollback \u64A4\u9500\uFF1B\u6CA1\u6709\u66F4\u65B0\u6765\u6E90\u65F6\u7528 repo \u6307\u5B9A\u5B83\u7684 GitHub \u4ED3\u5E93\u3002\u53EA\u66F4\u65B0\u5B98\u65B9\u53D1\u5E03\uFF0C\u4E0D\u4FEE\u6539\u811A\u672C\u4EE3\u7801\u3002",
3272
+ description: "\u68C0\u67E5\u5E76\u66F4\u65B0\u811A\u672C\u5230\u6700\u65B0\u53D1\u5E03\u7248\u672C\uFF08\u586B\u4E86 Mirror\u9171 CDK \u4E14\u811A\u672C\u5728 Mirror\u9171 \u53D1\u5E03\u65F6\u4ECE\u90A3\u91CC\u4E0B\u8F7D\uFF0C\u5426\u5219\u4ECE GitHub\uFF09\u3002\u5B89\u88C5\u7684\u811A\u672C\uFF1A\u65B0\u7248\u672C\u88C5\u5728\u65E7\u7248\u672C\u65C1\u8FB9\uFF0C\u914D\u7F6E\u6587\u4EF6\u5E26\u8FC7\u53BB\uFF0C\u65E7\u7248\u672C\u4FDD\u7559\u7528\u4E8E\u56DE\u6EDA\u3002\u672C\u5730\u5BFC\u5165\u7684\u811A\u672C\uFF1A\u5728\u5B83\u81EA\u5DF1\u7684\u76EE\u5F55\u91CC\u66F4\u65B0\uFF08\u4F1A\u5148\u8BF7\u7528\u6237\u786E\u8BA4\uFF09\uFF0C\u88AB\u66FF\u6362\u7684\u6587\u4EF6\u5148\u5907\u4EFD\uFF0C\u5DF2\u6709\u7684\u914D\u7F6E\u6587\u4EF6\u4E0D\u52A8\uFF0C\u53EF\u7528 script_rollback \u64A4\u9500\uFF1B\u6CA1\u6709\u66F4\u65B0\u6765\u6E90\u65F6\u7528 repo \u6307\u5B9A\u5B83\u7684 GitHub \u4ED3\u5E93\u3002\u53EA\u66F4\u65B0\u5B98\u65B9\u53D1\u5E03\uFF0C\u4E0D\u4FEE\u6539\u811A\u672C\u4EE3\u7801\u3002\u7528\u6237\u5728\u300C\u8BBE\u7F6E \u2192 \u6743\u9650\u300D\u628A\u300C\u811A\u672C\u6709\u65B0\u7248\u672C\u65F6\u300D\u8BBE\u4E3A\u300C\u81EA\u52A8\u66F4\u65B0\u300D\u65F6\u53EF\u4EE5\u81EA\u5DF1\u51B3\u5B9A\u66F4\u65B0\uFF1B\u8BBE\u4E3A\u300C\u5148\u95EE\u6211\u300D\u6216\u300C\u4E0D\u81EA\u52A8\u66F4\u65B0\u300D\u65F6\uFF0C\u53EA\u5728\u7528\u6237\u8981\u6C42\u65F6\u66F4\u65B0\u3002",
3233
3273
  properties: {
3234
3274
  id,
3235
3275
  repo: { ...repo, description: "\u8BBE\u7F6E\u5B83\u7684 GitHub \u66F4\u65B0\u6E20\u9053\uFF08owner/repo\uFF09\uFF1B\u7701\u7565\u5219\u7528\u5DF2\u6709\u7684\u3002\u4ECE GitHub \u5B89\u88C5\u7684\u811A\u672C\u4E0D\u80FD\u6539\u3002" },
@@ -3407,6 +3447,8 @@ function setupHandOff(ctx, library, log) {
3407
3447
  }
3408
3448
 
3409
3449
  // packages/script-registry/lib/index.js
3450
+ var UPDATE_CHECK_FIRST_MS = 2 * 6e4;
3451
+ var UPDATE_CHECK_EVERY_MS = 6 * 60 * 6e4;
3410
3452
  var ConfigSchema = external_exports.object({
3411
3453
  /** Where installed scripts live: `<toolsDir>/<id>/<version>/`. */
3412
3454
  toolsDir: external_exports.string().min(1),
@@ -3455,6 +3497,22 @@ var AdgScripts = class extends Service {
3455
3497
  this.ready = library.start();
3456
3498
  this.ready.then(() => log.info(`script library ready: ${library.list().scripts.length} script(s), tools in ${library.toolsDir}`), (error) => log.error(`script library failed to load: ${error instanceof Error ? error.message : String(error)}`));
3457
3499
  ctx.effect(() => () => library.dispose(), "adg-scripts jobs");
3500
+ ctx.effect(() => {
3501
+ const stop = new AbortController();
3502
+ const check = () => {
3503
+ void this.ready.then(() => library.checkUpdates(stop.signal), () => {
3504
+ });
3505
+ };
3506
+ const first = setTimeout(check, UPDATE_CHECK_FIRST_MS);
3507
+ const every = setInterval(check, UPDATE_CHECK_EVERY_MS);
3508
+ first.unref();
3509
+ every.unref();
3510
+ return () => {
3511
+ stop.abort();
3512
+ clearTimeout(first);
3513
+ clearInterval(every);
3514
+ };
3515
+ }, "adg-scripts update checks");
3458
3516
  const approve = async (exec, reason) => {
3459
3517
  const approval = ctx.get("approval");
3460
3518
  if (approval === void 0 || exec.agent === void 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-multigameassistant",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "多游戏助手 MultiGameAssistant 的 dsh 插件版:让 agent 管好各个游戏的日常脚本(安装、编排定时流水线、看护运行、查活动),界面在自己的网页里。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -33,6 +33,8 @@ description: 游戏活动信息:查有什么活动、还剩几天、商店换
33
33
 
34
34
  - 新加:写 `game`、`name`,有时间就写 `starts_at` / `ends_at`(游戏服务器时间)。改已有的:先 `game_activities` 找到 `id`,只写要改的字段。
35
35
  - 图片 `image`:用户给的图片网址、本机图片文件路径,或 `screenshot`(这个对话最近一张截图,比如刚用 `screen_capture` 截的活动页)。
36
+ - 活动图片分三级:用户设的 > 数据站和网页给的 > agent 的截图。`screenshot` 算 agent 的截图,有别的图时不显示;用户想让截图显示,用 `use_source`=screen。
37
+ - 一个活动有多个来源时(`game_activities` 的 `sources`),用户说「用 PRTS 的时间」就写 `use_source`(来源 id、own、screen,或 default 恢复默认顺序):图片和时间都跟着换。
36
38
  - 用户填的内容比数据站优先,刷新不会改掉。要恢复成来源的:`clear` 列出字段,或 `game_activity_remove`(what=mine)。用户要删掉才用 `game_activity_remove`(what=all)。
37
39
 
38
40
  ## 日报