dsh-multigameassistant 2.0.3 → 2.0.4

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.
@@ -0,0 +1,100 @@
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
+ import {
3
+ LOW_CONTEXT_WINDOW_MS
4
+ } from "./chunk-SA72K6M2.js";
5
+ import "./chunk-2UFLGPDY.js";
6
+
7
+ // packages/gateway/lib/low-context.js
8
+ import { readFileSync, statSync } from "node:fs";
9
+ var name = "adg-low-context";
10
+ var inject = ["compaction"];
11
+ var isReplace = (event) => typeof event.surfaceOp === "object" && event.surfaceOp !== null;
12
+ var sourceOf = (data) => data?.source ?? {};
13
+ var TYPED = /* @__PURE__ */ new Set(["user", "user-rpc"]);
14
+ var SENT = /* @__PURE__ */ new Set(["notice", "relay"]);
15
+ function isMessage(event) {
16
+ if (event.type !== "user/message" || isReplace(event))
17
+ return false;
18
+ const { kind, form } = sourceOf(event.data);
19
+ return TYPED.has(String(kind)) || SENT.has(String(form));
20
+ }
21
+ function lowContextRange(session, options) {
22
+ const nodes = session.surface.nodes;
23
+ const events = nodes.map((seq) => session.eventAt(seq));
24
+ const first = events[0]?.type === "system/message" ? 1 : 0;
25
+ const messages = [];
26
+ for (let i = first; i < events.length; i++)
27
+ if (events[i] !== void 0 && isMessage(events[i]))
28
+ messages.push(i);
29
+ if (messages.length === 0)
30
+ return null;
31
+ const cutoff = options.now - (options.windowMs ?? LOW_CONTEXT_WINDOW_MS);
32
+ const keepFrom = messages.find((i) => events[i].time >= cutoff) ?? messages[messages.length - 1];
33
+ if (keepFrom <= first)
34
+ return null;
35
+ if (events.slice(first, keepFrom).every((event) => event === void 0 || isReplace(event) || event.type === "system/message"))
36
+ return null;
37
+ return { start: nodes[first], end: nodes[keepFrom - 1] };
38
+ }
39
+ function parseLowContext(raw) {
40
+ return raw?.lowContext === true;
41
+ }
42
+ function settingsReader(file) {
43
+ let stamp = "";
44
+ let on = false;
45
+ return () => {
46
+ if (file === void 0)
47
+ return on;
48
+ try {
49
+ const stat = statSync(file);
50
+ const now = `${stat.mtimeMs}:${stat.size}`;
51
+ if (now !== stamp) {
52
+ stamp = now;
53
+ on = parseLowContext(JSON.parse(readFileSync(file, "utf8")));
54
+ }
55
+ } catch {
56
+ stamp = "";
57
+ on = false;
58
+ }
59
+ return on;
60
+ };
61
+ }
62
+ function taskOver(agent, work) {
63
+ if ((agent.inbox?.nextTurn?.length ?? 0) > 0 || (agent.inbox?.nextStep?.length ?? 0) > 0)
64
+ return false;
65
+ return work?.workPending?.(agent.session.id) !== true;
66
+ }
67
+ function apply(ctx, config = {}) {
68
+ const log = ctx.logger("adg-low-context");
69
+ const enabled = settingsReader(config.file);
70
+ const engine = ctx.compaction;
71
+ if (typeof engine?.compactRegion !== "function") {
72
+ log.warn("this dsh compaction has no compactRegion: low-context mode is off");
73
+ return;
74
+ }
75
+ ctx.on("agent/turn-stopping", (async ({ agent, signal }) => {
76
+ if (!enabled() || signal.aborted)
77
+ return;
78
+ try {
79
+ if (!taskOver(agent, ctx.get("adgGateway")))
80
+ return;
81
+ const range = lowContextRange(agent.session, { now: Date.now() });
82
+ if (range === null)
83
+ return;
84
+ const result = await engine.compactRegion(range.start, range.end, agent, signal);
85
+ log.info(`low-context: compacted ${result.shadowedSeqs.length} records (seqs ${range.start}-${range.end}) of ${agent.session.id}`);
86
+ } catch (error) {
87
+ log.warn(`low-context compaction of ${agent.session.id} failed: ${error instanceof Error ? error.message : String(error)}`);
88
+ }
89
+ }));
90
+ }
91
+ export {
92
+ apply,
93
+ inject,
94
+ isMessage,
95
+ lowContextRange,
96
+ name,
97
+ parseLowContext,
98
+ settingsReader,
99
+ taskOver
100
+ };
package/lib/monitor.js CHANGED
@@ -1,8 +1,8 @@
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
  parseDuration
4
- } from "./chunk-C6HSCWNE.js";
5
- import "./chunk-OQZ2XZVP.js";
4
+ } from "./chunk-UOVFYP7C.js";
5
+ import "./chunk-XHP3SLMO.js";
6
6
  import {
7
7
  writeFileAtomic
8
8
  } from "./chunk-CCAB6XXZ.js";
@@ -11,7 +11,7 @@ import {
11
11
  MONITOR_CAPABILITY,
12
12
  MonitorSettings,
13
13
  external_exports
14
- } from "./chunk-IH3K4QPN.js";
14
+ } from "./chunk-SA72K6M2.js";
15
15
  import "./chunk-2UFLGPDY.js";
16
16
 
17
17
  // packages/monitor/lib/index.js
package/lib/notify.js CHANGED
@@ -16,10 +16,10 @@ import {
16
16
  replyPlain,
17
17
  sessionConversations,
18
18
  textReply
19
- } from "./chunk-AWZ4O7BY.js";
20
- import "./chunk-ZXD4IYZP.js";
19
+ } from "./chunk-4PNYIZVU.js";
20
+ import "./chunk-IZENRXQ6.js";
21
21
  import "./chunk-CCAB6XXZ.js";
22
- import "./chunk-IH3K4QPN.js";
22
+ import "./chunk-SA72K6M2.js";
23
23
  import "./chunk-2UFLGPDY.js";
24
24
  export {
25
25
  AdgNotify,
@@ -4,17 +4,17 @@ import {
4
4
  PARAMS_SCHEMA,
5
5
  parseDuration,
6
6
  taskParams
7
- } from "./chunk-C6HSCWNE.js";
7
+ } from "./chunk-UOVFYP7C.js";
8
8
  import {
9
9
  TaskInputError,
10
10
  renderTask
11
- } from "./chunk-OQZ2XZVP.js";
11
+ } from "./chunk-XHP3SLMO.js";
12
12
  import {
13
13
  MAIN,
14
14
  finalText,
15
15
  sessionConversations
16
- } from "./chunk-AWZ4O7BY.js";
17
- import "./chunk-ZXD4IYZP.js";
16
+ } from "./chunk-4PNYIZVU.js";
17
+ import "./chunk-IZENRXQ6.js";
18
18
  import {
19
19
  writeFileAtomic
20
20
  } from "./chunk-CCAB6XXZ.js";
@@ -33,7 +33,7 @@ import {
33
33
  isMarker,
34
34
  taskMessage,
35
35
  withStartEnd
36
- } from "./chunk-IH3K4QPN.js";
36
+ } from "./chunk-SA72K6M2.js";
37
37
  import "./chunk-2UFLGPDY.js";
38
38
 
39
39
  // packages/orchestrator/lib/index.js
package/lib/qqbot.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  questionText,
5
5
  replyMarkdown,
6
6
  replyPlain
7
- } from "./chunk-AWZ4O7BY.js";
8
- import "./chunk-ZXD4IYZP.js";
7
+ } from "./chunk-4PNYIZVU.js";
8
+ import "./chunk-IZENRXQ6.js";
9
9
  import {
10
10
  writeFileAtomic
11
11
  } from "./chunk-CCAB6XXZ.js";
@@ -15,7 +15,7 @@ import {
15
15
  QQPending,
16
16
  QQSettings,
17
17
  external_exports
18
- } from "./chunk-IH3K4QPN.js";
18
+ } from "./chunk-SA72K6M2.js";
19
19
  import "./chunk-2UFLGPDY.js";
20
20
 
21
21
  // packages/qqbot/lib/index.js
package/lib/runner.js CHANGED
@@ -19,9 +19,9 @@ import {
19
19
  runnerTools,
20
20
  setIn,
21
21
  taskParams
22
- } from "./chunk-C6HSCWNE.js";
23
- import "./chunk-OQZ2XZVP.js";
24
- import "./chunk-IH3K4QPN.js";
22
+ } from "./chunk-UOVFYP7C.js";
23
+ import "./chunk-XHP3SLMO.js";
24
+ import "./chunk-SA72K6M2.js";
25
25
  import "./chunk-2UFLGPDY.js";
26
26
  export {
27
27
  AdgRunner,
package/lib/scheduler.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  SCHEDULE_CAPABILITY,
4
4
  external_exports
5
- } from "./chunk-IH3K4QPN.js";
5
+ } from "./chunk-SA72K6M2.js";
6
6
  import "./chunk-2UFLGPDY.js";
7
7
 
8
8
  // packages/scheduler/lib/index.js
@@ -32,11 +32,11 @@ import {
32
32
  globToRegExp,
33
33
  parseManifest,
34
34
  versionOfTag
35
- } from "./chunk-OQZ2XZVP.js";
35
+ } from "./chunk-XHP3SLMO.js";
36
36
  import {
37
37
  sessionConversations
38
- } from "./chunk-AWZ4O7BY.js";
39
- import "./chunk-ZXD4IYZP.js";
38
+ } from "./chunk-4PNYIZVU.js";
39
+ import "./chunk-IZENRXQ6.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-IH3K4QPN.js";
62
+ } from "./chunk-SA72K6M2.js";
63
63
  import "./chunk-2UFLGPDY.js";
64
64
 
65
65
  // packages/script-registry/lib/index.js
@@ -91,7 +91,7 @@ var SCRIPT_ROLE = {
91
91
  ],
92
92
  duty: [
93
93
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u811A\u672C",
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",
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\u7528\u6237\u6216\u540C\u4E8B\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u3001\u800C\u67D0\u4E2A\u811A\u672C\u6709\u8FD9\u4E2A\u4EFB\u52A1\u65F6\uFF0C\u4E5F\u7531\u4F60\u7528 script_run \u8FD0\u884C\u90A3\u4E2A\u4EFB\u52A1\u53BB\u505A\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
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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-multigameassistant",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "多游戏助手 MultiGameAssistant 的 dsh 插件版:让 agent 管好各个游戏的日常脚本(安装、编排定时流水线、看护运行、查活动),界面在自己的网页里。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -40,6 +40,7 @@
40
40
  "./scheduler": "./lib/scheduler.js",
41
41
  "./game-intel": "./lib/game-intel.js",
42
42
  "./agent": "./lib/agent.js",
43
+ "./low-context": "./lib/low-context.js",
43
44
  "./client": "./lib/client.js",
44
45
  "./package.json": "./package.json"
45
46
  },