dsh-multigameassistant 2.1.0 → 2.2.0

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.
Files changed (46) hide show
  1. package/cordis.patch.yml +16 -1
  2. package/lib/analyzer.js +38 -82
  3. package/lib/browser.js +1 -1
  4. package/lib/{chunk-77ZYHRN7.js → chunk-26JIEF6M.js} +153 -5
  5. package/lib/{chunk-SHTX4AGU.js → chunk-6DSSLS7I.js} +26 -0
  6. package/lib/{chunk-YG4B5G7F.js → chunk-B4UT4NYH.js} +1 -0
  7. package/lib/{chunk-EOWM56PA.js → chunk-EKTA4OYC.js} +3 -3
  8. package/lib/{chunk-TWUATN5X.js → chunk-I4NHWXKH.js} +3 -3
  9. package/lib/{chunk-FH64SAZU.js → chunk-ICJLH3DP.js} +1 -1
  10. package/lib/chunk-J4QJC6UZ.js +22944 -0
  11. package/lib/chunk-J4QJC6UZ.js.LEGAL.txt +8 -0
  12. package/lib/{chunk-MEKSHT6V.js → chunk-KTOQFJ7R.js} +387 -38
  13. package/lib/{chunk-V2X4PLF5.js → chunk-NEUZQ7TI.js} +264 -20
  14. package/lib/emulator.js +3 -3
  15. package/lib/feishu.js +5 -5
  16. package/lib/game-intel.js +454 -57
  17. package/lib/gateway.js +16 -6
  18. package/lib/guard.js +2 -2
  19. package/lib/intervene.js +8 -6
  20. package/lib/low-context.js +3 -3
  21. package/lib/monitor.js +4 -4
  22. package/lib/notify.js +5 -5
  23. package/lib/orchestrator.js +8 -8
  24. package/lib/qqbot.js +5 -5
  25. package/lib/runner.js +4 -4
  26. package/lib/scheduler.js +2 -2
  27. package/lib/script-registry.js +33 -3558
  28. package/lib/webapi-GDSF5EWP.js +2481 -0
  29. package/package.json +1 -1
  30. package/skills/game-intel.md +9 -1
  31. package/skills/script-analysis.md +30 -3
  32. package/skills/web-reading.md +7 -2
  33. package/web/assets/index-C5cMI4PK.css +1 -0
  34. package/web/assets/index-ClYIoZUR.js +244 -0
  35. package/web/assets/index-ClYIoZUR.js.map +1 -0
  36. package/web/index.html +2 -2
  37. package/lib/chunk-RFCFA5P5.js +0 -11
  38. package/lib/games/arknights/game.yaml +0 -36
  39. package/lib/games/endfield/game.yaml +0 -25
  40. package/lib/games/starrail/game.yaml +0 -33
  41. package/lib/packs/maa/adg.script.yaml +0 -220
  42. package/lib/packs/maaend/adg.script.yaml +0 -160
  43. package/lib/packs/march7th/adg.script.yaml +0 -216
  44. package/web/assets/index-C-csjWiw.js +0 -244
  45. package/web/assets/index-C-csjWiw.js.map +0 -1
  46. package/web/assets/index-CjtVfcDS.css +0 -1
@@ -0,0 +1,8 @@
1
+ Bundled license information:
2
+
3
+ @modelcontextprotocol/client/dist/src-xKF0PJN-.mjs:
4
+ /*!
5
+ * content-type
6
+ * Copyright(c) 2015 Douglas Christopher Wilson
7
+ * MIT Licensed
8
+ */
@@ -2,7 +2,7 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  SUMMARIES_FILE,
4
4
  summariesReader
5
- } from "./chunk-FH64SAZU.js";
5
+ } from "./chunk-ICJLH3DP.js";
6
6
  import {
7
7
  writeFileAtomic
8
8
  } from "./chunk-RESS7WVY.js";
@@ -34,15 +34,17 @@ import {
34
34
  SHARED_MEMORY,
35
35
  SKILLS_CAPABILITY,
36
36
  SKILL_NAME,
37
+ SUMMARY_MAX_TOKENS,
37
38
  areaOf,
38
39
  classify,
39
40
  personaOf,
40
41
  personaPrompt,
41
- threadsBetween
42
- } from "./chunk-V2X4PLF5.js";
42
+ threadsBetween,
43
+ timetableText
44
+ } from "./chunk-NEUZQ7TI.js";
43
45
  import {
44
46
  external_exports
45
- } from "./chunk-SHTX4AGU.js";
47
+ } from "./chunk-6DSSLS7I.js";
46
48
  import {
47
49
  __commonJS,
48
50
  __require,
@@ -3767,6 +3769,14 @@ function routesOf(value) {
3767
3769
  const providers = value?.providers;
3768
3770
  return typeof providers === "object" && providers !== null ? providers : {};
3769
3771
  }
3772
+ function declaredMaxTokens(settings, namespace, provider, model) {
3773
+ const descriptor = settings.describe({ redactSecrets: true }).find((d) => d.ns === namespace);
3774
+ if (descriptor === void 0)
3775
+ return void 0;
3776
+ const profile = routesOf(descriptor.value)[provider] ?? routesOf(descriptor.user)[provider];
3777
+ const models = Array.isArray(profile?.models) ? profile.models : [];
3778
+ return models.map(toProviderModel).find((m) => m?.id === model)?.maxTokens;
3779
+ }
3770
3780
  function toProviderModel(entry) {
3771
3781
  if (typeof entry !== "object" || entry === null)
3772
3782
  return void 0;
@@ -4348,6 +4358,93 @@ ${content.trim()}
4348
4358
  await deps.saved?.(name);
4349
4359
  return { saved: file, replaced: existing !== void 0 };
4350
4360
  }
4361
+ var IMPORTED = ".imported.json";
4362
+ var SKIPPED = /^(node_modules|__pycache__|\.git)$/;
4363
+ async function importedSkills(dir) {
4364
+ const saved = await readFile2(join(dir, IMPORTED), "utf8").then((text) => JSON.parse(text), () => []);
4365
+ if (!Array.isArray(saved))
4366
+ return [];
4367
+ const out = [];
4368
+ for (const item of saved) {
4369
+ if (typeof item?.name !== "string" || !SKILL_NAME.test(item.name) || typeof item.origin?.kind !== "string")
4370
+ continue;
4371
+ if (await readFile2(join(dir, item.name, "SKILL.md"), "utf8").then(() => true, () => false))
4372
+ out.push(item);
4373
+ }
4374
+ return out;
4375
+ }
4376
+ async function importSkill(deps, input) {
4377
+ const { cp, mkdir: mkdirp, rm: remove } = await import("node:fs/promises");
4378
+ const imported = await importedSkills(deps.dir);
4379
+ const sameOrigin = (item) => JSON.stringify([item.origin.kind, item.origin["script"], item.origin["path"]]) === JSON.stringify([input.origin.kind, input.origin["script"], input.origin["path"]]);
4380
+ const taken = await deps.taken();
4381
+ const usable = async (name2) => {
4382
+ if (!SKILL_NAME.test(name2) || name2.length > MAX_SKILL_NAME || taken.includes(name2))
4383
+ return false;
4384
+ const exists = await readFile2(join(deps.dir, name2, "SKILL.md"), "utf8").then(() => true, () => false);
4385
+ return !exists || imported.some((item) => item.name === name2 && sameOrigin(item));
4386
+ };
4387
+ const previous = imported.find(sameOrigin);
4388
+ const candidates = [...previous === void 0 ? [] : [previous.name], input.name, ...input.fallbackName === void 0 ? [] : [input.fallbackName]];
4389
+ let name;
4390
+ for (const candidate2 of candidates)
4391
+ if (await usable(candidate2)) {
4392
+ name = candidate2;
4393
+ break;
4394
+ }
4395
+ if (name === void 0)
4396
+ throw new Error(`\u6280\u80FD\u540D\u300C${input.name}\u300D\u5DF2\u7ECF\u88AB\u522B\u7684\u6280\u80FD\u7528\u4E86`);
4397
+ const folder = join(deps.dir, name);
4398
+ const replaced = await readFile2(join(folder, "SKILL.md"), "utf8").then(() => true, () => false);
4399
+ const text = await readFile2(input.single === true ? input.from : join(input.from, "SKILL.md"), "utf8");
4400
+ const body = /^?---\r?\n[\s\S]*?\r?\n---\r?\n?([\s\S]*)$/.exec(text)?.[1] ?? text;
4401
+ await remove(folder, { recursive: true, force: true });
4402
+ await mkdirp(folder, { recursive: true });
4403
+ if (input.single !== true)
4404
+ await cp(input.from, folder, { recursive: true, filter: (source) => !SKIPPED.test(source.split(/[\\/]/).pop() ?? "") });
4405
+ const owner = [
4406
+ ...input.scripts === void 0 || input.scripts.length === 0 ? [] : [`scripts: ${JSON.stringify(input.scripts)}
4407
+ `],
4408
+ ...input.games === void 0 || input.games.length === 0 ? [] : [`games: ${JSON.stringify(input.games)}
4409
+ `]
4410
+ ].join("");
4411
+ await writeFile(join(folder, "SKILL.md"), `---
4412
+ name: ${name}
4413
+ description: ${JSON.stringify(input.description.replace(/\s+/g, " ").trim())}
4414
+ ${owner}---
4415
+
4416
+ ${body.trim()}
4417
+ `);
4418
+ const record = { name, origin: input.origin, copyHash: await copyHash(folder), at: Date.now() };
4419
+ const rest = imported.filter((item) => item.name !== name && !sameOrigin(item));
4420
+ await writeFile(join(deps.dir, IMPORTED), `${JSON.stringify([...rest, record], null, 1)}
4421
+ `);
4422
+ await deps.saved?.(name);
4423
+ return { name, saved: join(folder, "SKILL.md"), replaced };
4424
+ }
4425
+ async function importUnchanged(dir, item) {
4426
+ return await copyHash(join(dir, item.name)).catch(() => "") === item.copyHash;
4427
+ }
4428
+ async function copyHash(folder) {
4429
+ const { createHash } = await import("node:crypto");
4430
+ const { readdir: readdir2 } = await import("node:fs/promises");
4431
+ const files = [];
4432
+ const walk = async (sub) => {
4433
+ for (const entry of await readdir2(join(folder, sub), { withFileTypes: true })) {
4434
+ const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
4435
+ if (entry.isDirectory()) {
4436
+ if (!SKIPPED.test(entry.name))
4437
+ await walk(rel);
4438
+ } else if (entry.isFile())
4439
+ files.push(rel);
4440
+ }
4441
+ };
4442
+ await walk("");
4443
+ const digest = createHash("sha256");
4444
+ for (const rel of files.sort())
4445
+ digest.update(rel).update("\0").update(await readFile2(join(folder, ...rel.split("/")))).update("\0");
4446
+ return digest.digest("hex").slice(0, 16);
4447
+ }
4351
4448
  async function removeSkill(dir, name) {
4352
4449
  if (!SKILL_NAME.test(name))
4353
4450
  return false;
@@ -4365,6 +4462,7 @@ function skillSaveTool(deps) {
4365
4462
  "content \u5199\u6D53\u7F29\u540E\u7684\u505A\u6CD5\uFF1A\u4EC0\u4E48\u65F6\u5019\u7528\uFF1B\u4E00\u6B65\u4E00\u6B65\u7684\u64CD\u4F5C\uFF08\u7528\u5230\u7684\u5DE5\u5177\u3001\u547D\u4EE4\u3001\u8DEF\u5F84\u3001\u53C2\u6570\u7167\u5B9E\u5199\uFF09\uFF1B\u5224\u65AD\u6210\u529F\u7684\u65B9\u6CD5\uFF1B\u8E29\u8FC7\u7684\u5751\u548C\u6CE8\u610F\u4E8B\u9879\u3002\u4E0D\u5199\u8FD9\u6B21\u5BF9\u8BDD\u7684\u95F2\u804A\u548C\u5931\u8D25\u7684\u5C1D\u8BD5\u8FC7\u7A0B\uFF0C\u53EA\u5199\u6700\u540E\u8D70\u901A\u7684\u8DEF\u3002",
4366
4463
  "description \u4E00\u4E24\u53E5\u8BDD\u5199\u6E05\u695A\u300C\u505A\u4EC0\u4E48\u3001\u7528\u6237\u8BF4\u4EC0\u4E48\u65F6\u7528\u300D\uFF0Cagent \u9760\u5B83\u51B3\u5B9A\u4EC0\u4E48\u65F6\u5019\u8C03\u7528\u3002\u5DF2\u6709\u540C\u540D\u6280\u80FD\u65F6\u5148\u7528 replace=true \u624D\u4F1A\u8986\u76D6\u3002",
4367
4464
  "\u6280\u80FD\u53EA\u5199\u300C\u600E\u4E48\u505A\u300D\uFF1A\u7528\u6237\u7684\u504F\u597D\u3001\u79F0\u547C\u3001\u7EA6\u5B9A\uFF0C\u548C\u8FD9\u6B21\u505A\u4E86\u4EC0\u4E48\u3001\u5B9A\u4E86\u4EC0\u4E48\uFF0C\u4E0D\u5199\u6210\u6280\u80FD\uFF0C\u7528 memory_save \u8BB0\u8FDB\u957F\u671F\u8BB0\u5FC6\u3002",
4465
+ "\u6280\u80FD\u53EA\u7528\u8FD9\u4E2A\u5DE5\u5177\u4FDD\u5B58\uFF08\u5B58\u5728\u672C\u8F6F\u4EF6\u81EA\u5DF1\u7684\u6570\u636E\u76EE\u5F55\u91CC\uFF0C\u53EA\u7ED9\u672C\u8F6F\u4EF6\u7684 agent \u7528\uFF09\uFF1B\u4E0D\u8981\u81EA\u5DF1\u5F80 ~/.agents/skills\u3001~/.dsh/skills \u6216\u5DE5\u4F5C\u76EE\u5F55\u7684 .agents/skills \u5199 SKILL.md\uFF0C\u90A3\u4E9B\u662F\u522B\u7684 agent \u4E5F\u8BFB\u7684\u6587\u4EF6\u5939\uFF0C\u672C\u8F6F\u4EF6\u7684 agent \u4E0D\u8BFB\u3002",
4368
4466
  "\u4E00\u5B9A\u8981\u5206\u5230\u5BF9\u5E94\u7684\u6E38\u620F\u548C\u811A\u672C\uFF1A\u53EA\u6709\u7528\u67D0\u4E2A\u811A\u672C\u65F6\u624D\u7528\u5F97\u4E0A\u7684\uFF08\u5B83\u7684\u914D\u7F6E\u3001\u62A5\u9519\u3001\u65E5\u5FD7\uFF09\u586B scripts\uFF08\u811A\u672C id\uFF09\uFF1B\u548C\u6E38\u620F\u672C\u8EAB\u6709\u5173\u3001\u6362\u4E2A\u811A\u672C\u4E5F\u7528\u5F97\u4E0A\u7684\uFF08\u6E38\u620F\u91CC\u7684\u64CD\u4F5C\u3001\u754C\u9762\u3001\u6D3B\u52A8\u3001\u673A\u5236\uFF09\u586B games\uFF08\u6E38\u620F id\uFF0Cgame_list \u53EF\u67E5\uFF09\uFF0C\u4E0D\u586B scripts\u3002\u8FD9\u6837\u5B83\u53EA\u5728\u5904\u7406\u8FD9\u4E2A\u811A\u672C\u6216\u6E38\u620F\u65F6\u51FA\u73B0\uFF0C\u4E0D\u4F1A\u88AB\u62FF\u53BB\u7528\u5728\u522B\u7684\u811A\u672C\u3001\u522B\u7684\u6E38\u620F\u4E0A\uFF0C\u300C\u6280\u80FD\u300D\u9875\u4E5F\u6309\u6E38\u620F\u5F52\u597D\u7C7B\u3002\u548C\u54EA\u4E2A\u6E38\u620F\u90FD\u65E0\u5173\u7684\u901A\u7528\u505A\u6CD5\u4E24\u4E2A\u90FD\u4E0D\u586B\u3002"
4369
4467
  ].join(""),
4370
4468
  parameters: {
@@ -4514,6 +4612,13 @@ var SkillScope = class {
4514
4612
  ownerOf(name) {
4515
4613
  return this.#skills.get(name)?.owner;
4516
4614
  }
4615
+ kindOf(name) {
4616
+ return this.#skills.get(name)?.kind;
4617
+ }
4618
+ packOf(name) {
4619
+ const skill = this.#skills.get(name);
4620
+ return { ...skill?.pack === void 0 ? {} : { pack: skill.pack }, ...skill?.ownPack === true ? { ownPack: true } : {} };
4621
+ }
4517
4622
  /** A session's focus; undefined: no session (everything shows). A session never focused shows the general skills only. */
4518
4623
  focusOf(sessionId) {
4519
4624
  if (sessionId === void 0)
@@ -4538,8 +4643,18 @@ var SkillScope = class {
4538
4643
  this.#focus.delete(this.#focus.keys().next().value);
4539
4644
  this.#invalidate();
4540
4645
  this.#save();
4646
+ for (const listener of this.#focusListeners)
4647
+ listener(sessionId, merged);
4541
4648
  return merged;
4542
4649
  }
4650
+ #focusListeners = /* @__PURE__ */ new Set();
4651
+ /** Run `listener` after a session's focus is set (the page offers its games' packs). @returns the disposer. */
4652
+ onFocus(listener) {
4653
+ this.#focusListeners.add(listener);
4654
+ return () => {
4655
+ this.#focusListeners.delete(listener);
4656
+ };
4657
+ }
4543
4658
  /** The skills a focus shows (general ones included). */
4544
4659
  skillsFor(focus) {
4545
4660
  return [...this.#skills.values()].filter((skill) => this.visible(skill.owner, focus));
@@ -4899,7 +5014,7 @@ import { readFileSync as readFileSync2 } from "node:fs";
4899
5014
  import { mkdir as mkdir3, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
4900
5015
  import { join as join4 } from "node:path";
4901
5016
  var COMPACTION_FILE = "compaction.json";
4902
- var DEFAULT_COMPACTION = { auto: true, threshold: DEFAULT_COMPACTION_THRESHOLD, lowContext: false, archiveDays: null, ptcSubagents: true };
5017
+ var DEFAULT_COMPACTION = { auto: true, threshold: DEFAULT_COMPACTION_THRESHOLD, lowContext: false, archiveDays: null, ptcSubagents: true, summarizer: null };
4903
5018
  var CompactionStore = class {
4904
5019
  #file;
4905
5020
  /** As read at start: what dsh runs with. */
@@ -4913,8 +5028,13 @@ var CompactionStore = class {
4913
5028
  state() {
4914
5029
  return { settings: this.#current, applied: { ...this.applied, lowContext: this.#current.lowContext, archiveDays: this.#current.archiveDays } };
4915
5030
  }
4916
- async set(settings) {
4917
- const clean4 = CompactionSettings.parse(settings);
5031
+ /**
5032
+ * @param outputLimit - the chosen summarizer's own output limit, if its route declares one: a summary is asked
5033
+ * to fit in that (when below dsh's default), not in more than the model can write.
5034
+ */
5035
+ async set(settings, outputLimit) {
5036
+ const parsed = CompactionSettings.parse(settings);
5037
+ const clean4 = { ...parsed, summarizer: withLimit(parsed.summarizer, outputLimit) };
4918
5038
  await mkdir3(join4(this.#file, ".."), { recursive: true });
4919
5039
  await writeFile3(`${this.#file}.tmp`, `${JSON.stringify(clean4, null, 2)}
4920
5040
  `);
@@ -4923,6 +5043,12 @@ var CompactionStore = class {
4923
5043
  return this.state();
4924
5044
  }
4925
5045
  };
5046
+ function withLimit(summarizer, outputLimit) {
5047
+ if (summarizer === null)
5048
+ return null;
5049
+ const limit = outputLimit?.(summarizer.provider, summarizer.model);
5050
+ return { provider: summarizer.provider, model: summarizer.model, ...limit === void 0 || limit >= SUMMARY_MAX_TOKENS ? {} : { maxTokens: limit } };
5051
+ }
4926
5052
  function readSettings(file) {
4927
5053
  try {
4928
5054
  const raw = JSON.parse(readFileSync2(file, "utf8"));
@@ -6876,6 +7002,118 @@ function safely2(fn, fallback) {
6876
7002
  }
6877
7003
  }
6878
7004
 
7005
+ // packages/gateway/lib/queue.js
7006
+ var HUMAN = /* @__PURE__ */ new Set(["user", "user-rpc"]);
7007
+ function isHuman(message) {
7008
+ return typeof message.id === "string" && typeof message.source?.kind === "string" && HUMAN.has(message.source.kind);
7009
+ }
7010
+ function queuedPrompt(message, placement) {
7011
+ if (!isHuman(message))
7012
+ return void 0;
7013
+ const content = Array.isArray(message.content) ? message.content : [];
7014
+ const text = content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
7015
+ const images = content.filter((c) => c.type === "image").length;
7016
+ return {
7017
+ id: message.id,
7018
+ ...typeof message.source?.rpcId === "string" ? { requestId: message.source.rpcId } : {},
7019
+ text,
7020
+ ...images === 0 ? {} : { images },
7021
+ placement
7022
+ };
7023
+ }
7024
+ function toQueue(inbox, taken = []) {
7025
+ const items = [];
7026
+ for (const placement of ["next-step", "next-turn"]) {
7027
+ const list = inbox?.[placement];
7028
+ if (!Array.isArray(list))
7029
+ continue;
7030
+ for (const message of list) {
7031
+ const item = queuedPrompt(message, placement);
7032
+ if (item !== void 0)
7033
+ items.push(item);
7034
+ }
7035
+ }
7036
+ const waiting = new Set(items.map((item) => item.id));
7037
+ return [...taken.filter((item) => !waiting.has(item.id)), ...items];
7038
+ }
7039
+ var TakenInput = class {
7040
+ #taken = /* @__PURE__ */ new Map();
7041
+ /** Messages already handed back once (`lost`): a step that keeps failing before it logs them does not loop. */
7042
+ #handedBack = /* @__PURE__ */ new Set();
7043
+ #changed;
7044
+ /** @param changed - called when a session's taken messages change (to send its queue again). */
7045
+ constructor(changed) {
7046
+ this.#changed = changed;
7047
+ }
7048
+ /** dsh took `message` from the inbox for a step. */
7049
+ take(sessionId, message) {
7050
+ const item = queuedPrompt(message, "taken");
7051
+ if (item === void 0)
7052
+ return;
7053
+ let taken = this.#taken.get(sessionId);
7054
+ if (taken === void 0)
7055
+ this.#taken.set(sessionId, taken = /* @__PURE__ */ new Map());
7056
+ taken.set(item.id, { message, item });
7057
+ this.#changed(sessionId);
7058
+ }
7059
+ /** A message was written to the log: it is in the conversation now. */
7060
+ logged(sessionId, messageId) {
7061
+ this.#handedBack.delete(messageId);
7062
+ const taken = this.#taken.get(sessionId);
7063
+ if (taken === void 0 || !taken.delete(messageId))
7064
+ return;
7065
+ if (taken.size === 0)
7066
+ this.#taken.delete(sessionId);
7067
+ this.#changed(sessionId);
7068
+ }
7069
+ /**
7070
+ * The agent stopped with taken messages it never logged (its step failed
7071
+ * before it got that far): they are no longer taken.
7072
+ * @returns the ones to hand back to the agent, each at most once.
7073
+ */
7074
+ lost(sessionId) {
7075
+ const taken = this.#taken.get(sessionId);
7076
+ if (taken === void 0)
7077
+ return [];
7078
+ this.#taken.delete(sessionId);
7079
+ this.#changed(sessionId);
7080
+ const back = [];
7081
+ for (const [id, { message }] of taken) {
7082
+ if (this.#handedBack.has(id)) {
7083
+ this.#handedBack.delete(id);
7084
+ continue;
7085
+ }
7086
+ this.#handedBack.add(id);
7087
+ back.push(message);
7088
+ }
7089
+ return back;
7090
+ }
7091
+ /** The agent stopped: nothing it took is still on its way to the log. */
7092
+ clear(sessionId) {
7093
+ if (this.#taken.delete(sessionId))
7094
+ this.#changed(sessionId);
7095
+ }
7096
+ /** A session's taken messages as queue items, in the order taken. */
7097
+ items(sessionId) {
7098
+ return [...this.#taken.get(sessionId)?.values() ?? []].map(({ item }) => item);
7099
+ }
7100
+ };
7101
+ function resumeAfterError(agent, taken) {
7102
+ if (agent.status !== "idle" || agent.lifetimeSignal?.aborted === true)
7103
+ return 0;
7104
+ const lost = taken.lost(agent.session.id);
7105
+ for (const message of lost)
7106
+ agent.followup(message);
7107
+ const stuck = agent.inbox.nextStep.filter(isHuman);
7108
+ if (lost.length > 0)
7109
+ return lost.length + stuck.length;
7110
+ const last = stuck.at(-1);
7111
+ if (last === void 0 || !agent.inbox.remove(last.id))
7112
+ return 0;
7113
+ agent.steer(last);
7114
+ return stuck.length;
7115
+ }
7116
+
6879
7117
  // packages/gateway/lib/builtin.js
6880
7118
  function handlers(map) {
6881
7119
  return map;
@@ -6897,29 +7135,6 @@ function toContext(pressure, breakdown) {
6897
7135
  ...system === void 0 || tools === void 0 || messages === void 0 ? {} : { breakdown: { systemTokens: system, toolsTokens: tools, messageTokens: messages } }
6898
7136
  };
6899
7137
  }
6900
- function toQueue(inbox) {
6901
- const items = [];
6902
- for (const placement of ["next-step", "next-turn"]) {
6903
- const list = inbox?.[placement];
6904
- if (!Array.isArray(list))
6905
- continue;
6906
- for (const message of list) {
6907
- if (typeof message.id !== "string" || message.source?.kind !== "user")
6908
- continue;
6909
- const content = Array.isArray(message.content) ? message.content : [];
6910
- const text = content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
6911
- const images = content.filter((c) => c.type === "image").length;
6912
- items.push({
6913
- id: message.id,
6914
- ...typeof message.source.rpcId === "string" ? { requestId: message.source.rpcId } : {},
6915
- text,
6916
- ...images === 0 ? {} : { images },
6917
- placement
6918
- });
6919
- }
6920
- }
6921
- return items;
6922
- }
6923
7138
  function titleOf(values) {
6924
7139
  const title = values?.title;
6925
7140
  return typeof title === "string" ? title : null;
@@ -7053,7 +7268,7 @@ function builtinCapabilities(deps) {
7053
7268
  hasMore: snapshot.hasMore,
7054
7269
  title: titleOf(snapshot.projections.values),
7055
7270
  live: convertLiveBaseline(snapshot.assistantStream),
7056
- queue: toQueue(snapshot.projections.values.inbox),
7271
+ queue: toQueue(snapshot.projections.values.inbox, deps.takenOf?.(params.sessionId)),
7057
7272
  ...contextOf(snapshot.projections.values)
7058
7273
  };
7059
7274
  },
@@ -8629,6 +8844,7 @@ var MAIN_AGENT = {
8629
8844
  "script_help",
8630
8845
  "script_search",
8631
8846
  "script_tasks",
8847
+ "script_mcp_list",
8632
8848
  "game_list",
8633
8849
  "game_activities",
8634
8850
  "game_report",
@@ -8655,7 +8871,7 @@ function mainDuty(roles) {
8655
8871
  return [
8656
8872
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u52A9\u624B",
8657
8873
  "\u4F60\u662F\u7528\u6237\u7684\u52A9\u624B\uFF1A\u548C\u7528\u6237\u5BF9\u8BDD\uFF0C\u5F04\u6E05\u8981\u505A\u4EC0\u4E48\uFF0C\u5B89\u6392\u8C01\u6765\u505A\u3002\u622A\u56FE\u70B9\u51FB\u3001\u8FD0\u884C\u548C\u5B89\u88C5\u811A\u672C\u3001\u5206\u6790\u811A\u672C\u548C\u5199\u811A\u672C\u5305\u3001\u8BFB\u6E38\u620F\u8FD9\u4E9B\u5177\u4F53\u7684\u4E8B\u4EA4\u7ED9\u5BF9\u5E94\u7684 agent\uFF08agent_delegate\uFF09\uFF0C\u4F60\u81EA\u5DF1\u4E0D\u505A\u3002\u5206\u6790\u811A\u672C\u3001\u5199\u6216\u6539\u811A\u672C\u5305\u4EA4\u7ED9\u300C\u811A\u672C\u300D\uFF1A\u4FDD\u5B58\u811A\u672C\u5305\u7684 pack_propose \u53EA\u6709\u5B83\u6709\uFF0C\u4F60\u7684\u5B50 agent \u6CA1\u6709\u3002",
8658
- "\u7528\u6237\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u65F6\uFF0C\u4EA4\u51FA\u53BB\u4E4B\u524D\u5148\u7528 script_list\u3001script_tasks \u770B\u8FD9\u4E2A\u6E38\u620F\u4E0B\u7684\u811A\u672C\u6709\u6CA1\u6709\u8FD9\u4E2A\u529F\u80FD\uFF1A\u6709\uFF0C\u5C31\u4EA4\u7ED9\u300C\u811A\u672C\u300Dagent\uFF0C\u5199\u660E\u7528\u54EA\u4E2A\u811A\u672C\u7684\u54EA\u4E2A\u4EFB\u52A1\u53BB\u505A\uFF1B\u786E\u8BA4\u811A\u672C\u90FD\u505A\u4E0D\u4E86\uFF0C\u624D\u4EA4\u7ED9\u80FD\u622A\u56FE\u70B9\u51FB\u7684 agent \u81EA\u5DF1\u52A8\u624B\uFF0C\u5E76\u5728\u4EFB\u52A1\u91CC\u5199\u4E0A\u811A\u672C\u4E3A\u4EC0\u4E48\u505A\u4E0D\u4E86\u3002",
8874
+ "\u7528\u6237\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u65F6\uFF0C\u4EA4\u51FA\u53BB\u4E4B\u524D\u5148\u7528 script_list\u3001script_tasks \u770B\u8FD9\u4E2A\u6E38\u620F\u4E0B\u7684\u811A\u672C\u6709\u6CA1\u6709\u8FD9\u4E2A\u529F\u80FD\uFF1A\u6709\uFF0C\u5C31\u4EA4\u7ED9\u300C\u811A\u672C\u300Dagent\uFF0C\u5199\u660E\u7528\u54EA\u4E2A\u811A\u672C\u7684\u54EA\u4E2A\u4EFB\u52A1\u53BB\u505A\uFF1B\u811A\u672C\u81EA\u5E26 MCP \u670D\u52A1\u65F6\uFF08script_mcp_list\uFF09\uFF0C\u300C\u811A\u672C\u300Dagent \u8FD8\u80FD\u76F4\u63A5\u8C03\u7528\u5B83\u7684\u5DE5\u5177\uFF0C\u505A\u5230\u6574\u4E2A\u4EFB\u52A1\u4E4B\u5916\u7684\u7EC6\u7C92\u5EA6\u64CD\u4F5C\uFF08\u67E5\u72B6\u6001\u3001\u53EA\u8DD1\u67D0\u4E00\u9879\u3001\u6539\u8BBE\u7F6E\uFF09\uFF0C\u4E5F\u4EA4\u7ED9\u5B83\uFF1B\u786E\u8BA4\u811A\u672C\u90FD\u505A\u4E0D\u4E86\uFF0C\u624D\u4EA4\u7ED9\u80FD\u622A\u56FE\u70B9\u51FB\u7684 agent \u81EA\u5DF1\u52A8\u624B\uFF0C\u5E76\u5728\u4EFB\u52A1\u91CC\u5199\u4E0A\u811A\u672C\u4E3A\u4EC0\u4E48\u505A\u4E0D\u4E86\u3002",
8659
8875
  roles.length === 0 ? "\u73B0\u5728\u6CA1\u6709\u53EF\u4EE5\u4EA4\u7ED9\u7684 agent\uFF0C\u80FD\u505A\u7684\u4F60\u81EA\u5DF1\u505A\u3002" : `\u53EF\u4EE5\u4EA4\u7ED9\u7684 agent\uFF1A
8660
8876
  ${roles.map((r) => `- ${r.name}\uFF1A${r.description}`).join("\n")}`,
8661
8877
  "\u8FD0\u884C\u547D\u4EE4\u3001\u6539\u6587\u4EF6\u8FD9\u4E9B\u5DE5\u5177\u4E0D\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\uFF1A\u7528\u6237\u8981\u7684\u8FD9\u7C7B\u4E8B\uFF08\u6574\u7406\u6587\u4EF6\u3001\u5BFC\u51FA\u8BB0\u5F55\u3001\u67E5\u7CFB\u7EDF\uFF09\uFF0C\u8FD8\u6709\u67E5\u8D44\u6599\u3001\u8BFB\u65E5\u5FD7\u3001\u6BD4\u8F83\u51E0\u4E2A\u65B9\u6848\uFF0C\u90FD\u5F00\u81EA\u5DF1\u7684\u5B50 agent\uFF08subagent\uFF09\u53BB\u505A\uFF0C\u5B83\u628A\u7ED3\u679C\u4EA4\u56DE\u6765\uFF0C\u4F60\u544A\u8BC9\u7528\u6237\u3002\u622A\u56FE\u70B9\u51FB\u3001\u8FD0\u884C\u548C\u5B89\u88C5\u811A\u672C\u3001\u5206\u6790\u811A\u672C\u548C\u5199\u811A\u672C\u5305\u8FD9\u4E9B\u4EA4\u7ED9\u5BF9\u5E94\u7684\u4E3B agent\u3002",
@@ -8672,6 +8888,10 @@ var AdgGateway = class extends Service {
8672
8888
  archived = /* @__PURE__ */ new Set();
8673
8889
  /** The latest context projections per session (a control frame carries only the keys its event changed). */
8674
8890
  contexts = /* @__PURE__ */ new Map();
8891
+ /** The latest non-empty inbox projection per session, so the queue can be sent again when only the taken messages change. */
8892
+ inboxes = /* @__PURE__ */ new Map();
8893
+ /** The person's messages the agent took for a step and has not logged yet (queue.ts). */
8894
+ taken = new TakenInput((sessionId) => this.broadcast("session/queue", { sessionId, items: toQueue(this.inboxes.get(sessionId), this.taken.items(sessionId)) }));
8675
8895
  peers = /* @__PURE__ */ new Set();
8676
8896
  approvals;
8677
8897
  questions;
@@ -8723,6 +8943,8 @@ var AdgGateway = class extends Service {
8723
8943
  */
8724
8944
  memoryViews;
8725
8945
  compaction;
8946
+ /** A model's declared output limit, from the routes in 设置 → 模型服务 (while that service is there). */
8947
+ outputLimit;
8726
8948
  log;
8727
8949
  /** The skills kept in this app's skills folder (`skillsDir`): written by skill_save and the 技能 page. */
8728
8950
  savedSkills;
@@ -8799,6 +9021,7 @@ var AdgGateway = class extends Service {
8799
9021
  },
8800
9022
  selectModel: (sessionId, selection) => this.selectSessionModel(sessionId, selection),
8801
9023
  lastReplies: new LastReplies(ctx.sessionController),
9024
+ takenOf: (sessionId) => this.taken.items(sessionId),
8802
9025
  approvals: this.approvals,
8803
9026
  serverInfo: { name: "adg-gateway", version: "0.1.0" },
8804
9027
  compact: (sessionId, signal) => compactSession(ctx, sessionId, signal),
@@ -8913,6 +9136,11 @@ var AdgGateway = class extends Service {
8913
9136
  }
8914
9137
  return next();
8915
9138
  }));
9139
+ ctx.on("tools/result", ((exec, result) => {
9140
+ if (result.isError || exec.name !== "schedule_task_save" && exec.name !== "schedule_create")
9141
+ return;
9142
+ void this.announceSchedule(exec, result.value).catch((error) => log.warn(`could not announce a timed task: ${String(error)}`));
9143
+ }));
8916
9144
  ctx.on("agent/disposed", ((payload) => {
8917
9145
  if (this.agents.get(payload.agent.session.id) === payload.agent)
8918
9146
  this.agents.delete(payload.agent.session.id);
@@ -8965,6 +9193,13 @@ var AdgGateway = class extends Service {
8965
9193
  if (n > 0)
8966
9194
  ctx.logger("adg-gateway").info(`updated ${n} model route(s) with the retry policy or the system role`);
8967
9195
  }).catch((error) => ctx.logger("adg-gateway").warn(`updating model routes failed: ${String(error)}`));
9196
+ const namespace = config.providersNamespace ?? "llm-pi-ai";
9197
+ scoped.effect(() => {
9198
+ this.outputLimit = (provider, model) => declaredMaxTokens(scoped.settings, namespace, provider, model);
9199
+ return () => {
9200
+ this.outputLimit = void 0;
9201
+ };
9202
+ }, "adg-gateway output limits");
8968
9203
  scoped.effect(() => this.registry.register(providersCapability({
8969
9204
  settings: scoped.settings,
8970
9205
  llm: scoped.llm,
@@ -9040,9 +9275,12 @@ var AdgGateway = class extends Service {
9040
9275
  version: 1,
9041
9276
  methods: {
9042
9277
  "agents/home": async (params) => {
9043
- const { agentId } = params;
9278
+ const { agentId, focus } = params;
9044
9279
  try {
9045
- return { sessionId: await this.home(agentId) };
9280
+ const sessionId = await this.home(agentId);
9281
+ if (focus !== void 0)
9282
+ await this.skillScope.setFocus(sessionId, { scripts: focus.scripts ?? [], games: focus.games ?? [] }, "add");
9283
+ return { sessionId };
9046
9284
  } catch (error) {
9047
9285
  throw new RpcError(ErrorCode.InvalidParams, error instanceof Error ? error.message : String(error));
9048
9286
  }
@@ -9163,7 +9401,9 @@ var AdgGateway = class extends Service {
9163
9401
  modelInvocable: s.invocation.modelInvocable,
9164
9402
  userInvocable: s.invocation.userInvocable,
9165
9403
  ...ownerInfo(this.skillScope.ownerOf(s.name)),
9166
- ...this.savedSkills?.registered.has(s.name) === true ? { removable: true } : {}
9404
+ ...this.savedSkills?.registered.has(s.name) === true ? { removable: true } : {},
9405
+ ...this.skillScope.kindOf(s.name) === void 0 ? {} : { kind: this.skillScope.kindOf(s.name) },
9406
+ ...this.skillScope.packOf(s.name)
9167
9407
  });
9168
9408
  const saved = () => {
9169
9409
  if (this.savedSkills === void 0)
@@ -9171,6 +9411,10 @@ var AdgGateway = class extends Service {
9171
9411
  return this.savedSkills;
9172
9412
  };
9173
9413
  const options = (signal) => ({ ...this.workspace === void 0 ? {} : { cwd: this.workspace }, signal });
9414
+ scoped.effect(() => this.skillScope.onFocus((sessionId, focus) => {
9415
+ if (this.isOwn(sessionId))
9416
+ this.broadcast("skills/focused", { sessionId, scripts: [...focus.scripts], games: [...focus.games] });
9417
+ }), "adg-gateway skill focus");
9174
9418
  scoped.effect(() => this.registry.register({
9175
9419
  id: SKILLS_CAPABILITY,
9176
9420
  version: 1,
@@ -9183,6 +9427,10 @@ var AdgGateway = class extends Service {
9183
9427
  throw new RpcError(ErrorCode.NotFound, `no skill ${name}`);
9184
9428
  return { ...info(skill), content: skill.content };
9185
9429
  },
9430
+ "skills/focus": async (params) => {
9431
+ const focus = this.skillScope.focusOf(params.sessionId);
9432
+ return { scripts: [...focus?.scripts ?? []], games: [...focus?.games ?? []] };
9433
+ },
9186
9434
  "skills/save": async (params) => {
9187
9435
  const p = params;
9188
9436
  try {
@@ -9231,6 +9479,43 @@ var AdgGateway = class extends Service {
9231
9479
  return decision;
9232
9480
  }
9233
9481
  }), true));
9482
+ this.agentPart("adg-gateway taken input", (scope) => {
9483
+ const failed = /* @__PURE__ */ new WeakSet();
9484
+ const offs = [
9485
+ scope.on("agent/inbox/claimed", (({ agent, message }) => {
9486
+ this.taken.take(agent.session.id, message);
9487
+ })),
9488
+ scope.on("session/event", ((session, event) => {
9489
+ if (event.type === "user/message" && typeof event.data?.id === "string")
9490
+ this.taken.logged(session.id, event.data.id);
9491
+ })),
9492
+ scope.on("agent/error", (({ agent }) => {
9493
+ failed.add(agent);
9494
+ })),
9495
+ scope.on("agent/status", (({ agent, status }) => {
9496
+ if (status !== "idle")
9497
+ return;
9498
+ setTimeout(() => {
9499
+ if (!failed.delete(agent)) {
9500
+ if (agent.status === "idle")
9501
+ this.taken.clear(agent.session.id);
9502
+ return;
9503
+ }
9504
+ try {
9505
+ const handed = resumeAfterError(agent, this.taken);
9506
+ if (handed > 0)
9507
+ log.info(`gave ${handed} waiting message(s) of ${agent.session.id} to a new turn after its turn failed`);
9508
+ } catch (error) {
9509
+ log.warn(`could not hand the waiting messages of ${agent.session.id} to a new turn: ${error instanceof Error ? error.message : String(error)}`);
9510
+ }
9511
+ }, 0);
9512
+ }))
9513
+ ];
9514
+ return () => {
9515
+ for (const off of offs)
9516
+ off();
9517
+ };
9518
+ });
9234
9519
  if (config.dataDir !== void 0) {
9235
9520
  const persona = new PersonaStore(config.dataDir);
9236
9521
  const loaded = persona.load();
@@ -9380,7 +9665,7 @@ var AdgGateway = class extends Service {
9380
9665
  version: 1,
9381
9666
  methods: {
9382
9667
  "compaction/get": () => compaction.state(),
9383
- "compaction/set": (params) => compaction.set(params.settings)
9668
+ "compaction/set": (params) => compaction.set(params.settings, this.outputLimit)
9384
9669
  }
9385
9670
  }), "adg-gateway capability compaction");
9386
9671
  }
@@ -9733,6 +10018,38 @@ Content-Length: 0
9733
10018
  const spec = this.specOf(sessionId);
9734
10019
  return spec === void 0 || spec.subAgentOf !== void 0 ? void 0 : { id: spec.id, name: spec.name };
9735
10020
  }
10021
+ /**
10022
+ * Tell the UI that an agent set a timed task (schedule_task_save, whose
10023
+ * value carries the task) or a reminder for itself (schedule_create, found
10024
+ * again among the reminders by its words). Only the app's own agents: a
10025
+ * shared dsh's other chats are nothing of ours.
10026
+ */
10027
+ async announceSchedule(exec, value) {
10028
+ if (exec.agent === void 0)
10029
+ return;
10030
+ const spec = this.specOf(exec.agent.session.id);
10031
+ if (spec === void 0)
10032
+ return;
10033
+ const by = spec.subAgentOf === void 0 ? spec.id : spec.id.replace(/:sub$/, "");
10034
+ if (exec.name === "schedule_task_save") {
10035
+ const task = value?.task;
10036
+ if (task === void 0)
10037
+ return;
10038
+ this.broadcast("schedule/agentSet", { kind: "task", id: task.id, by, agent: task.agent, title: task.title, when: timetableText(task.schedule), changed: typeof exec.arguments["id"] === "string" });
10039
+ return;
10040
+ }
10041
+ const prompt = typeof exec.arguments["prompt"] === "string" ? exec.arguments["prompt"] : "";
10042
+ const reminder = (await this.reminders().catch(() => [])).find((r) => r.prompt === prompt);
10043
+ this.broadcast("schedule/agentSet", {
10044
+ kind: "reminder",
10045
+ ...reminder === void 0 ? {} : { id: reminder.id },
10046
+ by,
10047
+ agent: reminder?.agent ?? by,
10048
+ title: reminder?.title ?? (prompt.split("\n")[0] ?? "").slice(0, 40),
10049
+ when: reminder === void 0 ? "" : reminder.rule === "\u4E00\u6B21" ? `\u4E00\u6B21 \xB7 ${new Date(reminder.next).toLocaleString("zh-CN", { hour12: false, month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit" })}` : reminder.rule,
10050
+ changed: false
10051
+ });
10052
+ }
9736
10053
  /**
9737
10054
  * What an agent in this session is: its role, 助手 for the app's other
9738
10055
  * sessions, and for a sub-agent, its parent's made into a sub-agent's.
@@ -9958,6 +10275,27 @@ Content-Length: 0
9958
10275
  this.log.info(`${role?.name ?? MAIN_AGENT.name}'s conversation: ${sessionId}${kept === void 0 ? "" : ` (the one before, ${kept}, is gone)`}`);
9959
10276
  return sessionId;
9960
10277
  }
10278
+ /**
10279
+ * Put a skill from elsewhere (a script's own skills) among this app's
10280
+ * skills (the skills folder, the 技能 page), for its agents at once.
10281
+ * @returns the name it was saved under; throws without a skills folder.
10282
+ */
10283
+ async importSkill(input) {
10284
+ const saved = this.savedSkills;
10285
+ if (saved === void 0)
10286
+ throw new Error("\u8FD9\u91CC\u6CA1\u6709\u53EF\u4EE5\u5199\u7684\u6280\u80FD\u6587\u4EF6\u5939");
10287
+ const { name, replaced } = await importSkill(saved.deps, input);
10288
+ this.log.info(`skill ${replaced ? "imported again" : "imported"}: ${name} (${input.origin.kind}${typeof input.origin["script"] === "string" ? ` ${input.origin["script"]}` : ""})`);
10289
+ return { name, replaced };
10290
+ }
10291
+ /** The skills imported into this app's skills folder (`importSkill`), each with whether it was changed here since. */
10292
+ async importedSkills() {
10293
+ const saved = this.savedSkills;
10294
+ if (saved === void 0)
10295
+ return [];
10296
+ const dir = saved.deps.dir;
10297
+ return Promise.all((await importedSkills(dir)).map(async (item) => ({ ...item, changed: !await importUnchanged(dir, item) })));
10298
+ }
9961
10299
  /** Count a session the app just created as its own (session/created came before it was). */
9962
10300
  async adopt(sessionId) {
9963
10301
  if (!this.shared)
@@ -10116,8 +10454,14 @@ Content-Length: 0
10116
10454
  }
10117
10455
  if (changed.has("modelSelection"))
10118
10456
  this.broadcast("session/model", { sessionId: frame.sessionId, ...toSessionModel(changed.get("modelSelection")) });
10119
- if (changed.has("inbox"))
10120
- this.broadcast("session/queue", { sessionId: frame.sessionId, items: toQueue(changed.get("inbox")) });
10457
+ if (changed.has("inbox")) {
10458
+ const inbox = changed.get("inbox");
10459
+ if (toQueue(inbox).length === 0)
10460
+ this.inboxes.delete(frame.sessionId);
10461
+ else
10462
+ this.inboxes.set(frame.sessionId, inbox);
10463
+ this.broadcast("session/queue", { sessionId: frame.sessionId, items: toQueue(inbox, this.taken.items(frame.sessionId)) });
10464
+ }
10121
10465
  if (changed.has("contextPressure") || changed.has("contextBreakdown")) {
10122
10466
  const known = this.contexts.get(frame.sessionId) ?? {};
10123
10467
  const next = {
@@ -10141,6 +10485,11 @@ Content-Length: 0
10141
10485
  var lib_default = AdgGateway;
10142
10486
 
10143
10487
  export {
10488
+ pluginVersion,
10489
+ importedSkills,
10490
+ importSkill,
10491
+ importUnchanged,
10492
+ userSkills,
10144
10493
  SkillScope,
10145
10494
  streamFacts,
10146
10495
  convertEvent,