@aipanel/dsh-plugin 1.2.10 → 1.2.11

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 (2) hide show
  1. package/dist/index.js +86 -3
  2. package/package.json +6 -4
package/dist/index.js CHANGED
@@ -594,6 +594,8 @@ function setupEventRelay(ctx, config) {
594
594
  const lastSent = /* @__PURE__ */ new Map();
595
595
  const lastTitles = /* @__PURE__ */ new Map();
596
596
  const dirty = /* @__PURE__ */ new Set();
597
+ const childOf = /* @__PURE__ */ new Map();
598
+ const subagentRunningByParent = /* @__PURE__ */ new Map();
597
599
  let flushTimer = null;
598
600
  let lastPostErrorAt = 0;
599
601
  const scheduleFlush = () => {
@@ -611,15 +613,48 @@ function setupEventRelay(ctx, config) {
611
613
  const ensureState = (sessionId) => {
612
614
  let s = states.get(sessionId);
613
615
  if (s === void 0) {
614
- s = { running: false, thinking: false };
616
+ s = { running: false, thinking: false, pending: false, subagentRunning: 0 };
615
617
  states.set(sessionId, s);
616
618
  }
617
619
  return s;
618
620
  };
621
+ const updateSubagentCount = (parentId, childId, running) => {
622
+ let set = subagentRunningByParent.get(parentId);
623
+ if (running) {
624
+ if (set === void 0) {
625
+ set = /* @__PURE__ */ new Set();
626
+ subagentRunningByParent.set(parentId, set);
627
+ }
628
+ set.add(childId);
629
+ } else if (set !== void 0) {
630
+ set.delete(childId);
631
+ }
632
+ const count = set === void 0 || set.size === 0 ? 0 : set.size;
633
+ if (set !== void 0 && set.size === 0) subagentRunningByParent.delete(parentId);
634
+ const s = ensureState(parentId);
635
+ if (s.subagentRunning !== count) {
636
+ s.subagentRunning = count;
637
+ markDirty(parentId);
638
+ }
639
+ };
640
+ const setPending = (sessionId, pending, kind) => {
641
+ const s = ensureState(sessionId);
642
+ if (s.pending === pending && s.pendingKind === kind) return;
643
+ s.pending = pending;
644
+ s.pendingKind = pending ? kind : void 0;
645
+ markDirty(sessionId);
646
+ };
619
647
  const handleAgentStatus = ({ agent, status }) => {
620
648
  const sessionId = String(agent.session.id);
621
649
  if (!sessionId) return;
622
650
  const running = status === "running";
651
+ const header = agent.session.header;
652
+ if (header?.origin === "subagent" && header.parentSession !== void 0) {
653
+ const parentId = String(header.parentSession);
654
+ childOf.set(sessionId, parentId);
655
+ updateSubagentCount(parentId, sessionId, running);
656
+ return;
657
+ }
623
658
  const s = ensureState(sessionId);
624
659
  if (s.running === running) return;
625
660
  s.running = running;
@@ -672,8 +707,25 @@ function setupEventRelay(ctx, config) {
672
707
  if (last === void 0 || last.thinking !== s.thinking) {
673
708
  events.push({ type: "thinking", sessionId, thinking: s.thinking });
674
709
  }
710
+ if (last === void 0 || last.pending !== s.pending || last.pendingKind !== s.pendingKind) {
711
+ events.push({
712
+ type: "session.pending",
713
+ sessionId,
714
+ pending: s.pending,
715
+ ...s.pendingKind === void 0 ? {} : { kind: s.pendingKind }
716
+ });
717
+ }
718
+ if (last === void 0 || last.subagentRunning !== s.subagentRunning) {
719
+ events.push({ type: "session.subagents", sessionId, running: s.subagentRunning });
720
+ }
675
721
  if (events.length === 0) continue;
676
- lastSent.set(sessionId, { running: s.running, thinking: s.thinking });
722
+ lastSent.set(sessionId, {
723
+ running: s.running,
724
+ thinking: s.thinking,
725
+ pending: s.pending,
726
+ pendingKind: s.pendingKind,
727
+ subagentRunning: s.subagentRunning
728
+ });
677
729
  for (const event of events) post(event);
678
730
  }
679
731
  };
@@ -699,8 +751,39 @@ function setupEventRelay(ctx, config) {
699
751
  }
700
752
  });
701
753
  };
702
- ctx.on("agent/status", handleAgentStatus);
754
+ ctx.on("agent/status", handleAgentStatus, { global: true });
703
755
  ctx.on("session/event", handleSessionEvent, { global: true });
756
+ ctx.on(
757
+ "approval/request",
758
+ async (request, next) => {
759
+ const sessionId = String(request.agent?.session?.id ?? "");
760
+ if (!sessionId) return next();
761
+ setPending(sessionId, true, "approval");
762
+ try {
763
+ return await next();
764
+ } finally {
765
+ setPending(sessionId, false);
766
+ }
767
+ },
768
+ // scoped(Scoped<Agent>)事件:root ctx 需 global 才能收到所有 agent
769
+ { global: true }
770
+ );
771
+ ctx.on(
772
+ "user-questions/request",
773
+ async (request, next) => {
774
+ const sessionId = String(request.agent?.session?.id ?? "");
775
+ if (!sessionId) return next();
776
+ const isPlanReview = request.questions?.some((q) => q.intent?.kind === "plan-review");
777
+ setPending(sessionId, true, isPlanReview ? "plan-review" : "question");
778
+ try {
779
+ return await next();
780
+ } finally {
781
+ setPending(sessionId, false);
782
+ }
783
+ },
784
+ // scoped(Scoped<Agent>)事件:root ctx 需 global 才能收到所有 agent
785
+ { global: true }
786
+ );
704
787
  }
705
788
 
706
789
  // dsh-plugin/src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aipanel/dsh-plugin",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "type": "module",
5
5
  "description": "AIPanel for DeepSeek Harness (dsh):注入审查工具 run_diagnostics、编辑后自动诊断。",
6
6
  "main": "./dist/index.js",
@@ -16,14 +16,16 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@deepseek-ai/cordis": "^4.0.2",
19
- "@deepseek-ai/dsh-settings": "^0.1.2-rc.1",
20
19
  "@deepseek-ai/dsh-agent": "^0.1.2-rc.1",
21
20
  "@deepseek-ai/dsh-llm": "^0.1.2-rc.1",
21
+ "@deepseek-ai/dsh-session": "^0.1.2-rc.1",
22
+ "@deepseek-ai/dsh-settings": "^0.1.2-rc.1",
22
23
  "@deepseek-ai/dsh-tools": "^0.1.2-rc.1",
24
+ "@deepseek-ai/dsh-user-approval": "^0.1.2-rc.1",
25
+ "@deepseek-ai/dsh-user-questions": "^0.1.2-rc.1",
23
26
  "@deepseek-ai/dsh-util-values": "^0.1.2-rc.1",
24
- "@deepseek-ai/dsh-session": "^0.1.2-rc.1",
25
27
  "esbuild": "^0.25.0",
26
- "@aipanel/core": "1.2.10"
28
+ "@aipanel/core": "1.2.11"
27
29
  },
28
30
  "scripts": {
29
31
  "build": "esbuild src/index.ts --bundle --outfile=dist/index.js --platform=node --format=esm --target=node18 --external:@deepseek-ai/* --external:node:* --external:vue-tsc",