personal-bot 0.2.19 → 0.3.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.
- package/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -5
- package/.mcp.json +11 -0
- package/CONTEXT.md +17 -73
- package/README.md +41 -120
- package/README.zh-CN.md +41 -120
- package/docs/README.md +31 -23
- package/docs/architecture/design.md +74 -0
- package/docs/architecture/extensibility.md +78 -0
- package/docs/architecture/model-context.md +31 -0
- package/docs/architecture/model-instruction-guidelines.md +34 -0
- package/docs/architecture/principles.md +33 -0
- package/docs/guides/capabilities.md +36 -0
- package/docs/guides/cross-harness-workers.md +83 -0
- package/docs/guides/history.md +25 -0
- package/docs/guides/workspace-configuration.md +102 -0
- package/docs/hosts/antigravity.md +52 -0
- package/docs/hosts/claude-code.md +47 -0
- package/docs/hosts/dsh.md +67 -0
- package/docs/hosts/pi.md +49 -0
- package/docs/maintainers/release.md +59 -0
- package/hooks/hooks.json +0 -3
- package/lib/antigravity-plugin/hooks.json +23 -0
- package/lib/antigravity-plugin/lib/claude.d.ts +1 -0
- package/lib/antigravity-plugin/lib/claude.js +13 -0
- package/lib/antigravity-plugin/lib/common/json.d.ts +6 -0
- package/lib/antigravity-plugin/lib/common/json.js +16 -0
- package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
- package/lib/antigravity-plugin/lib/common/paths.js +2 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +3 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/common/version.d.ts +3 -0
- package/lib/antigravity-plugin/lib/common/version.js +13 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +11597 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2715 -0
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +10 -0
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +67 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +16 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +56 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +79 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +60 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/registry.d.ts +15 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/registry.js +34 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +164 -0
- package/lib/antigravity-plugin/lib/model/acp.js +12 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +48 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +24 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.js +1 -0
- package/lib/antigravity-plugin/lib/model/workspace-mcp.d.ts +51 -0
- package/lib/antigravity-plugin/lib/model/workspace-mcp.js +4 -0
- package/lib/antigravity-plugin/lib/plugin.d.ts +1 -0
- package/lib/antigravity-plugin/lib/plugin.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +8 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +93 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.js +26 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +91 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +101 -0
- package/lib/antigravity-plugin/mcp_config.json +13 -0
- package/lib/antigravity-plugin/package.json +6 -0
- package/lib/antigravity-plugin/plugin.json +7 -0
- package/lib/antigravity-plugin/resources/agents/coordinator.md +11 -0
- package/{resources/claude → lib/antigravity-plugin/resources}/agents/general-purpose.md +0 -5
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/prompts/workspace.md +31 -0
- package/lib/antigravity-plugin/resources/references/compute-finance.md +22 -0
- package/lib/antigravity-plugin/resources/references/compute.md +16 -0
- package/lib/antigravity-plugin/resources/references/task-conductor.md +25 -0
- package/lib/antigravity-plugin/resources/templates/workspace-agents.md +21 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +16 -0
- package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +42 -0
- package/lib/claude.js +4 -11
- package/lib/client.js +14 -531
- package/lib/common/markdown.js +2 -3
- package/lib/common/validation.d.ts +2 -0
- package/lib/common/validation.js +4 -0
- package/lib/extension/acp-member.d.ts +2 -0
- package/lib/extension/acp-member.js +9 -8
- package/lib/extension/acp-worker.js +11578 -121
- package/lib/extension/dsh/acp-member.js +26 -2
- package/lib/extension/dsh/command.js +19 -57
- package/lib/extension/dsh/history.js +2 -4
- package/lib/extension/dsh/management.d.ts +0 -2
- package/lib/extension/dsh/management.js +27 -126
- package/lib/extension/dsh/workspace.d.ts +5 -47
- package/lib/extension/dsh/workspace.js +76 -108
- package/lib/extension/mcp-bridge.d.ts +41 -0
- package/lib/extension/mcp-bridge.js +412 -0
- package/lib/extension/mcp-workers.d.ts +980 -0
- package/lib/extension/mcp-workers.js +882 -0
- package/lib/extension/mcp.js +2715 -0
- package/lib/extension/plugin-runtime.d.ts +10 -0
- package/lib/extension/plugin-runtime.js +67 -0
- package/lib/extension/setup-cli.js +215 -2
- package/lib/integrations/acp/agents.d.ts +10 -11
- package/lib/integrations/acp/agents.js +65 -33
- package/lib/integrations/acp/claude.d.ts +2 -2
- package/lib/integrations/acp/claude.js +5 -3
- package/lib/integrations/acp/connection.d.ts +17 -4
- package/lib/integrations/acp/connection.js +53 -27
- package/lib/integrations/acp/executable.d.ts +3 -0
- package/lib/integrations/acp/executable.js +42 -0
- package/lib/integrations/acp/harnesses/claude.d.ts +2 -0
- package/lib/integrations/acp/harnesses/claude.js +49 -0
- package/lib/integrations/acp/harnesses/dsh.d.ts +2 -0
- package/lib/integrations/acp/harnesses/dsh.js +35 -0
- package/lib/integrations/acp/harnesses/generic.d.ts +13 -0
- package/lib/integrations/acp/harnesses/generic.js +37 -0
- package/lib/integrations/acp/harnesses/pi.d.ts +2 -0
- package/lib/integrations/acp/harnesses/pi.js +34 -0
- package/lib/integrations/acp/harnesses/presets.d.ts +3 -0
- package/lib/integrations/acp/harnesses/presets.js +20 -0
- package/lib/integrations/acp/launch.d.ts +33 -4
- package/lib/integrations/acp/launch.js +60 -48
- package/lib/integrations/acp/mcp.d.ts +6 -0
- package/lib/integrations/acp/mcp.js +40 -0
- package/lib/integrations/acp/model-selection.d.ts +9 -2
- package/lib/integrations/acp/model-selection.js +73 -27
- package/lib/integrations/acp/registry.d.ts +18 -0
- package/lib/integrations/acp/registry.js +50 -0
- package/lib/integrations/agent-resources.d.ts +16 -1
- package/lib/integrations/agent-resources.js +45 -9
- package/lib/integrations/dsh/mcp.d.ts +4 -0
- package/lib/integrations/dsh/mcp.js +28 -0
- package/lib/integrations/dsh/resources.d.ts +3 -3
- package/lib/integrations/dsh/resources.js +21 -12
- package/lib/integrations/dsh/skills.d.ts +5 -1
- package/lib/integrations/dsh/skills.js +10 -6
- package/lib/integrations/hosts/antigravity.d.ts +4 -0
- package/lib/integrations/hosts/antigravity.js +79 -0
- package/lib/integrations/hosts/claude.d.ts +3 -0
- package/lib/integrations/hosts/claude.js +60 -0
- package/lib/integrations/hosts/registry.d.ts +15 -0
- package/lib/integrations/hosts/registry.js +34 -0
- package/lib/model/acp.d.ts +107 -2
- package/lib/model/acp.js +12 -1
- package/lib/model/agent.d.ts +35 -33
- package/lib/model/plugin-host.d.ts +48 -0
- package/lib/model/plugin-host.js +1 -0
- package/lib/model/workspace-config.d.ts +12 -0
- package/lib/model/workspace-mcp.d.ts +51 -0
- package/lib/model/workspace-mcp.js +4 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +17 -0
- package/lib/services/agents/acp-run.d.ts +13 -1
- package/lib/services/agents/acp-run.js +30 -2
- package/lib/services/agents/agent-service.d.ts +35 -120
- package/lib/services/agents/agent-service.js +156 -160
- package/lib/services/installation/setup-service.js +17 -1
- package/lib/services/workspace/workspace-config.d.ts +2 -1
- package/lib/services/workspace/workspace-config.js +39 -7
- package/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/services/workspace/workspace-mcp.js +200 -0
- package/lib/services/workspace/workspace-skills.d.ts +8 -0
- package/lib/services/workspace/workspace-skills.js +91 -0
- package/lib/storage/acp-files.d.ts +3 -1
- package/lib/storage/acp-files.js +32 -2
- package/lib/storage/acp-history.d.ts +3 -2
- package/lib/storage/acp-history.js +19 -7
- package/lib/storage/agent-files.d.ts +8 -8
- package/lib/storage/agent-files.js +27 -47
- package/lib/tools/history/contract.d.ts +1 -1
- package/lib/tools/history/contract.js +17 -11
- package/lib/ui/dsh/index.js +8 -3
- package/lib/ui/dsh/management.d.ts +1 -1
- package/lib/ui/dsh/management.js +24 -456
- package/lib/ui/dsh/remote.d.ts +0 -2
- package/lib/ui/dsh/remote.js +1 -1
- package/package.json +12 -7
- package/resources/agents/coordinator.md +2 -2
- package/resources/antigravity/skills/pbot/SKILL.md +16 -0
- package/resources/claude/skills/pbot/SKILL.md +1 -1
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/resources/prompts/workspace.md +9 -8
- package/resources/references/compute.md +9 -11
- package/resources/references/task-conductor.md +12 -26
- package/resources/skills/project-maintenance/SKILL.md +17 -22
- package/resources/skills/provider-connections/SKILL.md +24 -40
- package/resources/templates/workspace-agents.md +8 -0
- package/scripts/README.md +17 -34
- package/src/claude.ts +4 -8
- package/src/common/markdown.ts +2 -3
- package/src/common/validation.ts +6 -0
- package/src/extension/acp-member.ts +9 -8
- package/src/extension/acp-worker.ts +239 -97
- package/src/extension/command.ts +38 -36
- package/src/extension/dsh/acp-member.ts +21 -2
- package/src/extension/dsh/command.ts +21 -51
- package/src/extension/dsh/files.ts +1 -0
- package/src/extension/dsh/history.ts +9 -6
- package/src/extension/dsh/management.ts +27 -58
- package/src/extension/dsh/workspace.ts +88 -99
- package/src/extension/events.ts +13 -10
- package/src/extension/history.ts +2 -50
- package/src/extension/lifecycle.ts +37 -22
- package/src/extension/mcp-bridge.ts +412 -0
- package/src/extension/mcp-workers.ts +941 -0
- package/src/extension/pi-acp-member.ts +29 -5
- package/src/extension/plugin-runtime.ts +63 -0
- package/src/extension/setup-cli.ts +186 -2
- package/src/integrations/acp/agents.ts +70 -24
- package/src/integrations/acp/claude.ts +11 -4
- package/src/integrations/acp/connection.ts +63 -25
- package/src/integrations/acp/executable.ts +41 -0
- package/src/integrations/acp/harnesses/claude.ts +50 -0
- package/src/integrations/acp/harnesses/dsh.ts +40 -0
- package/src/integrations/acp/harnesses/generic.ts +52 -0
- package/src/integrations/acp/harnesses/pi.ts +35 -0
- package/src/integrations/acp/harnesses/presets.ts +22 -0
- package/src/integrations/acp/launch.ts +69 -47
- package/src/integrations/acp/mcp.ts +43 -0
- package/src/integrations/acp/model-selection.ts +68 -25
- package/src/integrations/acp/registry.ts +60 -0
- package/src/integrations/agent-resources.ts +70 -6
- package/src/integrations/dsh/mcp.ts +30 -0
- package/src/integrations/dsh/resources.ts +28 -13
- package/src/integrations/dsh/skills.ts +16 -6
- package/src/integrations/hosts/antigravity.ts +83 -0
- package/src/integrations/hosts/claude.ts +62 -0
- package/src/integrations/hosts/registry.ts +42 -0
- package/src/integrations/pi/mcp.ts +26 -0
- package/src/mcp.ts +14 -0
- package/src/model/acp.ts +113 -3
- package/src/model/agent.ts +18 -14
- package/src/model/plugin-host.ts +39 -0
- package/src/model/workspace-config.ts +14 -0
- package/src/model/workspace-mcp.ts +64 -0
- package/src/pbot.ts +69 -20
- package/src/plugin.ts +19 -0
- package/src/services/agents/acp-run.ts +35 -3
- package/src/services/agents/agent-service.ts +180 -160
- package/src/services/installation/setup-service.ts +17 -2
- package/src/services/workspace/workspace-config.ts +42 -6
- package/src/services/workspace/workspace-mcp.ts +242 -0
- package/src/services/workspace/workspace-skills.ts +78 -0
- package/src/storage/acp-files.ts +32 -3
- package/src/storage/acp-history.ts +18 -7
- package/src/storage/agent-files.ts +27 -41
- package/src/tools/history/contract.ts +17 -11
- package/src/tools/register.ts +4 -8
- package/src/ui/dsh/index.ts +8 -3
- package/src/ui/dsh/management.ts +40 -282
- package/src/ui/dsh/remote.ts +2 -2
- package/docs/adr/0001-claude-skill-discovery.md +0 -3
- package/docs/adr/0002-claude-native-collaboration.md +0 -3
- package/docs/agent-collaboration.md +0 -190
- package/docs/architecture-guidelines.md +0 -37
- package/docs/capability-design.md +0 -55
- package/docs/claude-code-design.md +0 -44
- package/docs/claude-code.md +0 -57
- package/docs/dsh.md +0 -337
- package/docs/file-storage.md +0 -97
- package/docs/history.md +0 -54
- package/docs/installation-design.md +0 -86
- package/docs/interaction-design.md +0 -21
- package/docs/model-context.md +0 -76
- package/docs/model-instruction-guidelines.md +0 -51
- package/docs/release.md +0 -108
- package/docs/technical-design.md +0 -163
- package/docs/workspace-configuration.md +0 -79
- package/lib/extension/claude-hooks.d.ts +0 -9
- package/lib/extension/claude-hooks.js +0 -78
- package/lib/extension/dsh/agent-events.d.ts +0 -24
- package/lib/extension/dsh/agent-events.js +0 -242
- package/lib/extension/dsh/agent-runtime.d.ts +0 -49
- package/lib/extension/dsh/agent-runtime.js +0 -351
- package/lib/integrations/dsh/dsh-agents.d.ts +0 -30
- package/lib/integrations/dsh/dsh-agents.js +0 -104
- package/lib/integrations/dsh/input.d.ts +0 -21
- package/lib/integrations/dsh/input.js +0 -62
- package/lib/integrations/dsh/notifications.d.ts +0 -8
- package/lib/integrations/dsh/notifications.js +0 -55
- package/lib/integrations/dsh/session.d.ts +0 -14
- package/lib/integrations/dsh/session.js +0 -60
- package/lib/integrations/team-context.d.ts +0 -18
- package/lib/integrations/team-context.js +0 -61
- package/lib/model/team.d.ts +0 -85
- package/lib/services/agents/agent-notices.d.ts +0 -13
- package/lib/services/agents/agent-notices.js +0 -25
- package/lib/services/agents/start-options.d.ts +0 -4
- package/lib/services/agents/start-options.js +0 -20
- package/lib/services/agents/team-service.d.ts +0 -168
- package/lib/services/agents/team-service.js +0 -345
- package/lib/storage/team-files.d.ts +0 -16
- package/lib/storage/team-files.js +0 -111
- package/lib/tools/agents/actions.d.ts +0 -62
- package/lib/tools/agents/actions.js +0 -62
- package/lib/tools/agents/contract.d.ts +0 -181
- package/lib/tools/agents/contract.js +0 -84
- package/lib/tools/agents/dsh-tool.d.ts +0 -5
- package/lib/tools/agents/dsh-tool.js +0 -34
- package/lib/tools/result.d.ts +0 -18
- package/lib/tools/result.js +0 -10
- package/lib/tools/teams/actions.d.ts +0 -23
- package/lib/tools/teams/actions.js +0 -40
- package/lib/tools/teams/contract.d.ts +0 -201
- package/lib/tools/teams/contract.js +0 -91
- package/lib/tools/teams/dsh-tool.d.ts +0 -8
- package/lib/tools/teams/dsh-tool.js +0 -39
- package/lib/ui/dsh/attachments.d.ts +0 -5
- package/lib/ui/dsh/attachments.js +0 -39
- package/resources/prompts/claude-coordinator.md +0 -1
- package/resources/prompts/native-coordinator.md +0 -1
- package/resources/prompts/team-member.md +0 -7
- package/src/extension/agent-events.ts +0 -210
- package/src/extension/agents-command.ts +0 -89
- package/src/extension/claude-hooks.ts +0 -74
- package/src/extension/dsh/agent-events.ts +0 -148
- package/src/extension/dsh/agent-runtime.ts +0 -252
- package/src/extension/subagent-entry.ts +0 -270
- package/src/extension/teams-command.ts +0 -67
- package/src/integrations/dsh/dsh-agents.ts +0 -97
- package/src/integrations/dsh/input.ts +0 -66
- package/src/integrations/dsh/notifications.ts +0 -46
- package/src/integrations/pi/agent-context.ts +0 -18
- package/src/integrations/pi/agent-input.ts +0 -19
- package/src/integrations/pi/pi-agents.ts +0 -84
- package/src/integrations/pi/team-context.ts +0 -26
- package/src/integrations/team-context.ts +0 -64
- package/src/model/team.ts +0 -29
- package/src/services/agents/agent-notices.ts +0 -28
- package/src/services/agents/start-options.ts +0 -19
- package/src/services/agents/team-service.ts +0 -275
- package/src/storage/team-files.ts +0 -93
- package/src/tools/agents/actions.ts +0 -57
- package/src/tools/agents/contract.ts +0 -101
- package/src/tools/agents/dsh-tool.ts +0 -37
- package/src/tools/agents/tool.ts +0 -20
- package/src/tools/teams/actions.ts +0 -34
- package/src/tools/teams/contract.ts +0 -109
- package/src/tools/teams/dsh-tool.ts +0 -45
- package/src/tools/teams/tool.ts +0 -29
- package/src/ui/agent-display.ts +0 -14
- package/src/ui/dsh/attachments.ts +0 -42
- package/src/ui/pi/menu.ts +0 -37
- package/src/ui/pi/reader.ts +0 -46
- /package/lib/{model/team.js → antigravity-plugin/lib/model/plugin-host.js} +0 -0
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
3
|
-
import { agentNotice, teamNotice } from "../../services/agents/agent-notices.js";
|
|
4
|
-
import { deliveredDshNotices, pendingDshNotices } from "../../integrations/dsh/notifications.js";
|
|
5
|
-
import { flushDshAgent } from "../../integrations/dsh/session.js";
|
|
6
|
-
/** Server-owned scheduling survives browser disconnects; native cancellation pauses dispatch. */
|
|
7
|
-
export class DshAgentEvents {
|
|
8
|
-
ctx;
|
|
9
|
-
agent;
|
|
10
|
-
agents;
|
|
11
|
-
teams;
|
|
12
|
-
owner;
|
|
13
|
-
check;
|
|
14
|
-
#dispatching = new Map();
|
|
15
|
-
#signals = new Map();
|
|
16
|
-
#timer;
|
|
17
|
-
#scan;
|
|
18
|
-
#closed = false;
|
|
19
|
-
#pausePending = false;
|
|
20
|
-
#paused = false;
|
|
21
|
-
#error;
|
|
22
|
-
#errorKey;
|
|
23
|
-
#busySince;
|
|
24
|
-
#recovery;
|
|
25
|
-
#completed = [];
|
|
26
|
-
#autoWake = false;
|
|
27
|
-
constructor(ctx, agent, agents, teams, owner, check) {
|
|
28
|
-
this.ctx = ctx;
|
|
29
|
-
this.agent = agent;
|
|
30
|
-
this.agents = agents;
|
|
31
|
-
this.teams = teams;
|
|
32
|
-
this.owner = owner;
|
|
33
|
-
this.check = check;
|
|
34
|
-
}
|
|
35
|
-
get error() { return this.#error; }
|
|
36
|
-
start() {
|
|
37
|
-
this.teams.recover(this.owner);
|
|
38
|
-
this.ctx.on("agent/pre-step", async ({ signal }, next) => {
|
|
39
|
-
if (!this.#signals.has(signal)) {
|
|
40
|
-
const cancel = () => {
|
|
41
|
-
if (!this.#closed) {
|
|
42
|
-
this.#paused = true;
|
|
43
|
-
this.#autoWake = false;
|
|
44
|
-
this.#pausePending = true;
|
|
45
|
-
try {
|
|
46
|
-
this.pauseTeams();
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
this.recordError(error);
|
|
50
|
-
}
|
|
51
|
-
void this.refresh();
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
this.#signals.set(signal, cancel);
|
|
55
|
-
signal.addEventListener("abort", cancel, { once: true });
|
|
56
|
-
if (signal.aborted)
|
|
57
|
-
cancel();
|
|
58
|
-
}
|
|
59
|
-
await this.refresh();
|
|
60
|
-
this.check();
|
|
61
|
-
const decision = await next();
|
|
62
|
-
this.check();
|
|
63
|
-
if (decision.kind !== "enter" || this.#paused)
|
|
64
|
-
return decision;
|
|
65
|
-
const note = this.notice(decision.messages);
|
|
66
|
-
return note ? { ...decision, messages: [...decision.messages, note] } : decision;
|
|
67
|
-
});
|
|
68
|
-
this.ctx.on("session/event", (session, event) => {
|
|
69
|
-
if (session !== this.agent.session || this.#closed)
|
|
70
|
-
return;
|
|
71
|
-
if (event.type === "agent/inbox/spliced" && event.data.inserted.some(message => message.source.kind === "user")) {
|
|
72
|
-
this.#paused = false;
|
|
73
|
-
this.#autoWake = true;
|
|
74
|
-
}
|
|
75
|
-
if (event.type === "user/message" && event.data.source.kind === "pbot-results")
|
|
76
|
-
this.#autoWake = true;
|
|
77
|
-
if (event.type === "turn/end") {
|
|
78
|
-
for (const [signal, cancel] of this.#signals)
|
|
79
|
-
signal.removeEventListener("abort", cancel);
|
|
80
|
-
this.#signals.clear();
|
|
81
|
-
if (event.data.reason.kind === "aborted") {
|
|
82
|
-
this.#paused = true;
|
|
83
|
-
this.#autoWake = false;
|
|
84
|
-
this.#pausePending = true;
|
|
85
|
-
try {
|
|
86
|
-
this.pauseTeams();
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
this.recordError(error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
void this.refresh();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
this.#timer = setInterval(() => { void this.refresh(); }, 1000);
|
|
96
|
-
this.#timer.unref();
|
|
97
|
-
this.ctx.effect(() => () => this.close());
|
|
98
|
-
}
|
|
99
|
-
pauseTeams() {
|
|
100
|
-
if (!this.#pausePending)
|
|
101
|
-
return;
|
|
102
|
-
try {
|
|
103
|
-
this.teams.pauseAll(this.owner, "主会话中断");
|
|
104
|
-
this.#pausePending = false;
|
|
105
|
-
this.#dispatching.clear();
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
if (error.code !== "PBOT_CONTROL_BUSY") {
|
|
109
|
-
this.teams.fail(error);
|
|
110
|
-
this.#dispatching.clear();
|
|
111
|
-
}
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
recordError(error) {
|
|
116
|
-
if (this.#closed || error.name === "AbortError")
|
|
117
|
-
return;
|
|
118
|
-
if (error.code === "PBOT_CONTROL_BUSY") {
|
|
119
|
-
this.#busySince ??= Date.now();
|
|
120
|
-
if (Date.now() - this.#busySince < 5000)
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
else
|
|
124
|
-
this.#busySince = undefined;
|
|
125
|
-
const message = String(error);
|
|
126
|
-
let recovery = error.code === "PBOT_CONTROL_BUSY" ? "retry" : "repair";
|
|
127
|
-
try {
|
|
128
|
-
this.teams.check();
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
recovery = "reload";
|
|
132
|
-
}
|
|
133
|
-
if (message !== this.#error || recovery !== this.#recovery) {
|
|
134
|
-
this.ctx.logger.warn("pbot 协作扫描失败:" + message);
|
|
135
|
-
this.#errorKey = "agent-error:" + randomUUID();
|
|
136
|
-
}
|
|
137
|
-
this.#error = message;
|
|
138
|
-
this.#recovery = recovery;
|
|
139
|
-
}
|
|
140
|
-
notice(proposed = []) {
|
|
141
|
-
const known = new Set([...deliveredDshNotices(this.agent.session.snapshotEvents()),
|
|
142
|
-
...pendingDshNotices([...this.agent.inbox.nextTurn, ...this.agent.inbox.nextStep, ...proposed])]);
|
|
143
|
-
let value;
|
|
144
|
-
if (this.#error && this.#errorKey) {
|
|
145
|
-
if (!known.has(this.#errorKey))
|
|
146
|
-
value = { keys: [this.#errorKey], content: "# 协作扫描故障\n\n" + this.#error +
|
|
147
|
-
"\n\n先查看控制记录和原生报告,再决定是否重试,避免重复执行。" +
|
|
148
|
-
(this.#recovery === "reload" ? "团队服务已停用;修复文件后还需重载服务端 personal-bot 插件。" :
|
|
149
|
-
this.#recovery === "retry" ? "控制锁持续占用,后台会继续重试;不会自动删除锁或重新提交任务。" : "报告或控制记录读取失败,修复后后台会重试扫描。") +
|
|
150
|
-
(this.#pausePending ? "\n\n团队暂停尚未确认,不能据此开始成员私人任务。" : "") };
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
value = teamNotice(this.teams.notifications(this.owner, this.agents.list(this.owner)), known) ??
|
|
154
|
-
agentNotice(this.#completed, this.teams.links(), known);
|
|
155
|
-
}
|
|
156
|
-
return value ? createUserMessage({ content: [{ type: "text", text: value.content }],
|
|
157
|
-
source: { kind: "pbot-results", form: "notice", summary: "Personal Bot 协作更新", keys: value.keys } }) : undefined;
|
|
158
|
-
}
|
|
159
|
-
refresh() {
|
|
160
|
-
if (this.#closed || this.#scan)
|
|
161
|
-
return this.#scan ?? Promise.resolve();
|
|
162
|
-
this.#scan = (async () => {
|
|
163
|
-
try {
|
|
164
|
-
await this.scan();
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
this.recordError(error);
|
|
168
|
-
}
|
|
169
|
-
if (this.#closed || this.#paused || !this.#autoWake || this.agent.status !== "idle")
|
|
170
|
-
return;
|
|
171
|
-
try {
|
|
172
|
-
this.check();
|
|
173
|
-
const note = this.notice();
|
|
174
|
-
if (note) {
|
|
175
|
-
// A failed admission cannot start an automatic retry loop. Actual receipt or new human input re-arms wakeup.
|
|
176
|
-
this.#autoWake = false;
|
|
177
|
-
this.agent.followup(note);
|
|
178
|
-
await flushDshAgent(this.agent);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
this.recordError(error);
|
|
183
|
-
}
|
|
184
|
-
})().finally(() => { this.#scan = undefined; });
|
|
185
|
-
return this.#scan;
|
|
186
|
-
}
|
|
187
|
-
async scan() {
|
|
188
|
-
this.check();
|
|
189
|
-
this.pauseTeams();
|
|
190
|
-
await this.agents.refresh(this.owner);
|
|
191
|
-
if (this.#closed)
|
|
192
|
-
return;
|
|
193
|
-
this.check();
|
|
194
|
-
const completed = await this.agents.completions(this.owner);
|
|
195
|
-
if (this.#closed)
|
|
196
|
-
return;
|
|
197
|
-
this.check();
|
|
198
|
-
this.#completed = completed;
|
|
199
|
-
try {
|
|
200
|
-
this.pauseTeams();
|
|
201
|
-
for (const input of this.teams.advance(this.owner, this.agents.list(this.owner), completed))
|
|
202
|
-
this.#dispatching.set(input.requestId, input);
|
|
203
|
-
for (const [id, input] of this.#dispatching) {
|
|
204
|
-
try {
|
|
205
|
-
this.agents.enqueueTeam(input, this.owner);
|
|
206
|
-
this.#dispatching.delete(id);
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
const code = error.code;
|
|
210
|
-
if (code === "PBOT_CONTROL_BUSY")
|
|
211
|
-
throw error;
|
|
212
|
-
if (code !== "TEAM_INPUT_STALE")
|
|
213
|
-
throw error;
|
|
214
|
-
this.teams.pauseMember(input.agentId, "安排失效;未自动重发");
|
|
215
|
-
this.#dispatching.delete(id);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
if (error.code !== "PBOT_CONTROL_BUSY") {
|
|
221
|
-
this.teams.fail(error);
|
|
222
|
-
this.#dispatching.clear();
|
|
223
|
-
}
|
|
224
|
-
throw error;
|
|
225
|
-
}
|
|
226
|
-
this.#error = undefined;
|
|
227
|
-
this.#errorKey = undefined;
|
|
228
|
-
this.#busySince = undefined;
|
|
229
|
-
this.#recovery = undefined;
|
|
230
|
-
}
|
|
231
|
-
async close() {
|
|
232
|
-
this.#closed = true;
|
|
233
|
-
if (this.#timer)
|
|
234
|
-
clearInterval(this.#timer);
|
|
235
|
-
this.#timer = undefined;
|
|
236
|
-
for (const [signal, cancel] of this.#signals)
|
|
237
|
-
signal.removeEventListener("abort", cancel);
|
|
238
|
-
this.#signals.clear();
|
|
239
|
-
await this.#scan;
|
|
240
|
-
this.#dispatching.clear();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
-
import { type FileBlock, type ImageBlock } from "@deepseek-ai/dsh-llm";
|
|
4
|
-
import { AgentRun } from "../../services/agents/agent-run.js";
|
|
5
|
-
import type { TeamService } from "../../services/agents/team-service.js";
|
|
6
|
-
import { AgentFiles } from "../../storage/agent-files.js";
|
|
7
|
-
import type { AgentDescriptor } from "../../model/agent.js";
|
|
8
|
-
/** One expert's native event adapter. AgentRun and TeamService own durable business state. */
|
|
9
|
-
export declare class DshAgentRuntime {
|
|
10
|
-
#private;
|
|
11
|
-
readonly ctx: Context;
|
|
12
|
-
readonly agent: Agent;
|
|
13
|
-
readonly d: AgentDescriptor;
|
|
14
|
-
readonly generation: string;
|
|
15
|
-
readonly files: AgentFiles;
|
|
16
|
-
readonly teams: TeamService;
|
|
17
|
-
readonly owner: {
|
|
18
|
-
check(): void;
|
|
19
|
-
release(): Promise<void>;
|
|
20
|
-
};
|
|
21
|
-
readonly execution: AgentRun;
|
|
22
|
-
constructor(ctx: Context, agent: Agent, d: AgentDescriptor, generation: string, files: AgentFiles, teams: TeamService, owner: {
|
|
23
|
-
check(): void;
|
|
24
|
-
release(): Promise<void>;
|
|
25
|
-
});
|
|
26
|
-
check: () => void;
|
|
27
|
-
actor: () => {
|
|
28
|
-
requestId?: string;
|
|
29
|
-
kind: "member";
|
|
30
|
-
agentId: string;
|
|
31
|
-
generation: string;
|
|
32
|
-
};
|
|
33
|
-
private current;
|
|
34
|
-
private pause;
|
|
35
|
-
private enqueue;
|
|
36
|
-
private fail;
|
|
37
|
-
initialize(teamTool: boolean): void;
|
|
38
|
-
/** Called only after native Agent creation has resolved, never from setup. */
|
|
39
|
-
start(): void;
|
|
40
|
-
interact(text: string, delivery?: "steer" | "followUp", files?: readonly string[], attachments?: readonly (ImageBlock | FileBlock)[], caller?: AbortSignal): Promise<{
|
|
41
|
-
status: "queued";
|
|
42
|
-
messageId: import("@deepseek-ai/dsh-llm").MessageId;
|
|
43
|
-
}>;
|
|
44
|
-
private event;
|
|
45
|
-
private humanPending;
|
|
46
|
-
private pump;
|
|
47
|
-
private deliver;
|
|
48
|
-
stop(): Promise<void>;
|
|
49
|
-
}
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { foldConsumedWork } from "@deepseek-ai/dsh-agent";
|
|
2
|
-
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
3
|
-
import { AgentRun } from "../../services/agents/agent-run.js";
|
|
4
|
-
import { AgentFiles, launch } from "../../storage/agent-files.js";
|
|
5
|
-
import { requireThat } from "../../common/validation.js";
|
|
6
|
-
import { dshInput, dshHumanInput } from "../../integrations/dsh/input.js";
|
|
7
|
-
import { requestSource, finalDshAnswer } from "../../integrations/dsh/messages.js";
|
|
8
|
-
import { flushDshAgent } from "../../integrations/dsh/session.js";
|
|
9
|
-
import { createTeamContext, teamBrief } from "../../integrations/team-context.js";
|
|
10
|
-
/** One expert's native event adapter. AgentRun and TeamService own durable business state. */
|
|
11
|
-
export class DshAgentRuntime {
|
|
12
|
-
ctx;
|
|
13
|
-
agent;
|
|
14
|
-
d;
|
|
15
|
-
generation;
|
|
16
|
-
files;
|
|
17
|
-
teams;
|
|
18
|
-
owner;
|
|
19
|
-
execution;
|
|
20
|
-
#lifetime = new AbortController();
|
|
21
|
-
#inbox = { "next-turn": [], "next-step": [] };
|
|
22
|
-
#seen = new Map();
|
|
23
|
-
#events = Promise.resolve();
|
|
24
|
-
#turnEvents = [];
|
|
25
|
-
#answer = "";
|
|
26
|
-
#hasAnswer = false;
|
|
27
|
-
#activeTeam;
|
|
28
|
-
#teamBriefed = false;
|
|
29
|
-
#pendingPause;
|
|
30
|
-
#pump;
|
|
31
|
-
#timer;
|
|
32
|
-
#stopping;
|
|
33
|
-
#closing = false;
|
|
34
|
-
#failure;
|
|
35
|
-
#ready = false;
|
|
36
|
-
#teamTool = false;
|
|
37
|
-
constructor(ctx, agent, d, generation, files, teams, owner) {
|
|
38
|
-
this.ctx = ctx;
|
|
39
|
-
this.agent = agent;
|
|
40
|
-
this.d = d;
|
|
41
|
-
this.generation = generation;
|
|
42
|
-
this.files = files;
|
|
43
|
-
this.teams = teams;
|
|
44
|
-
this.owner = owner;
|
|
45
|
-
this.execution = new AgentRun(files, d.agentId, generation);
|
|
46
|
-
}
|
|
47
|
-
check = () => {
|
|
48
|
-
this.#lifetime.signal.throwIfAborted();
|
|
49
|
-
this.owner.check();
|
|
50
|
-
this.files.check();
|
|
51
|
-
const run = this.files.read(this.d.agentId, "launch.json", launch);
|
|
52
|
-
requireThat(run.generation === this.generation && !run.stop, "专家已停止或启动代次变化。");
|
|
53
|
-
};
|
|
54
|
-
actor = () => ({ kind: "member", agentId: this.d.agentId, generation: this.generation,
|
|
55
|
-
...(this.#activeTeam && this.execution.current?.source === "parent" ? { requestId: this.#activeTeam.request.requestId } : {}) });
|
|
56
|
-
current() { return this.files.read(this.d.agentId, "launch.json", launch).generation === this.generation; }
|
|
57
|
-
pause(reason) {
|
|
58
|
-
this.#pendingPause = reason;
|
|
59
|
-
try {
|
|
60
|
-
this.teams.pauseMember(this.d.agentId, reason);
|
|
61
|
-
this.#pendingPause = undefined;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
if (error.code !== "PBOT_CONTROL_BUSY")
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
enqueue(work) {
|
|
69
|
-
this.#events = this.#events.then(work).catch(error => this.fail(error));
|
|
70
|
-
}
|
|
71
|
-
fail(error) {
|
|
72
|
-
if (this.#failure)
|
|
73
|
-
return;
|
|
74
|
-
this.#failure = error;
|
|
75
|
-
this.#lifetime.abort();
|
|
76
|
-
try {
|
|
77
|
-
if (this.current()) {
|
|
78
|
-
this.teams.files.setReady(this.d.agentId, this.generation, false);
|
|
79
|
-
this.execution.save({ state: "error", activity: "控制失败", error: String(error) });
|
|
80
|
-
this.pause("专家控制失败");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (failure) {
|
|
84
|
-
this.ctx.logger.error("pbot 专家状态保存失败", failure);
|
|
85
|
-
}
|
|
86
|
-
void this.owner.release().catch(failure => this.ctx.logger.error("pbot 专家释放失败", failure));
|
|
87
|
-
}
|
|
88
|
-
initialize(teamTool) {
|
|
89
|
-
this.check();
|
|
90
|
-
this.#teamTool = teamTool;
|
|
91
|
-
this.teams.files.setReady(this.d.agentId, this.generation, false);
|
|
92
|
-
this.pause("专家载入:旧批次不自动恢复");
|
|
93
|
-
this.execution.recover();
|
|
94
|
-
for (const event of this.agent.session.snapshotEvents())
|
|
95
|
-
if (event.type === "user/message" && event.data.source.kind === "pbot-team-context") {
|
|
96
|
-
const { teamId, seqs } = event.data.source, seen = this.#seen.get(teamId) ?? new Set();
|
|
97
|
-
for (const seq of seqs)
|
|
98
|
-
seen.add(seq);
|
|
99
|
-
this.#seen.set(teamId, seen);
|
|
100
|
-
}
|
|
101
|
-
this.ctx.on("session/event", (session, event) => {
|
|
102
|
-
if (session === this.agent.session)
|
|
103
|
-
this.enqueue(() => this.event(event));
|
|
104
|
-
});
|
|
105
|
-
this.ctx.on("agent/status", ({ agent, status }) => {
|
|
106
|
-
if (agent !== this.agent)
|
|
107
|
-
return;
|
|
108
|
-
this.enqueue(() => {
|
|
109
|
-
if (!this.current() || this.#closing || this.#failure)
|
|
110
|
-
return;
|
|
111
|
-
this.execution.save({ state: status === "idle" ? "idle" : "busy", activity: status === "idle" ? "空闲" : "执行" });
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
this.ctx.on("agent/pre-step", async (_payload, next) => {
|
|
115
|
-
await this.#events;
|
|
116
|
-
this.check();
|
|
117
|
-
if (this.#activeTeam && !this.humanPending() && this.execution.current?.source === "parent" && Date.now() >= this.#activeTeam.run.deadlineAt) {
|
|
118
|
-
this.pause("已到期限");
|
|
119
|
-
this.agent.cancel({ kind: "hook", reason: "团队请求已到期限" });
|
|
120
|
-
return { kind: "reject" };
|
|
121
|
-
}
|
|
122
|
-
const decision = await next();
|
|
123
|
-
this.check();
|
|
124
|
-
if (decision.kind !== "enter" || !this.#activeTeam || this.execution.current?.source !== "parent" || this.humanPending() ||
|
|
125
|
-
decision.messages.some(message => message.source.kind === "user"))
|
|
126
|
-
return decision;
|
|
127
|
-
const link = this.teams.links().get(this.#activeTeam.request.requestId);
|
|
128
|
-
requireThat(link, "团队关联不可读取。");
|
|
129
|
-
const seen = this.#seen.get(link.team.teamId) ?? new Set();
|
|
130
|
-
const context = createTeamContext(link, seen);
|
|
131
|
-
if (this.#teamBriefed && !context)
|
|
132
|
-
return decision;
|
|
133
|
-
const text = [...(this.#teamBriefed ? [] : [teamBrief(link)]), ...(context ? [context.content] : [])].join("\n\n");
|
|
134
|
-
return { ...decision, messages: [...decision.messages, createUserMessage({ content: [{ type: "text", text }],
|
|
135
|
-
source: { kind: "pbot-team-context", form: "relay", teamId: link.team.teamId, seqs: context?.seqs ?? [] } })] };
|
|
136
|
-
});
|
|
137
|
-
this.execution.save({ state: "idle", activity: "空闲" });
|
|
138
|
-
this.ctx.effect(() => () => this.stop());
|
|
139
|
-
}
|
|
140
|
-
/** Called only after native Agent creation has resolved, never from setup. */
|
|
141
|
-
start() {
|
|
142
|
-
this.check();
|
|
143
|
-
this.#timer = setInterval(() => { void this.pump(); }, 250);
|
|
144
|
-
this.#timer.unref();
|
|
145
|
-
void this.pump();
|
|
146
|
-
}
|
|
147
|
-
async interact(text, delivery = "steer", files = [], attachments = [], caller) {
|
|
148
|
-
this.check();
|
|
149
|
-
requireThat((text.trim().length > 0 || files.length || attachments.length) && text.length <= 24000, "请输入消息或附加文件;消息最多 24000 字符。");
|
|
150
|
-
const signal = caller ? AbortSignal.any([caller, this.#lifetime.signal]) : this.#lifetime.signal;
|
|
151
|
-
const message = await dshHumanInput(this.ctx, this.d.cwd, text, files, attachments, signal);
|
|
152
|
-
this.check();
|
|
153
|
-
signal.throwIfAborted();
|
|
154
|
-
this.teams.pauseMember(this.d.agentId, "成员由人工接管");
|
|
155
|
-
if (delivery === "followUp")
|
|
156
|
-
this.agent.followup(message);
|
|
157
|
-
else
|
|
158
|
-
this.agent.steer(message);
|
|
159
|
-
// Native inbox admission transfers ownership to the expert, independently of the UI request.
|
|
160
|
-
await flushDshAgent(this.agent);
|
|
161
|
-
return { status: "queued", messageId: message.id };
|
|
162
|
-
}
|
|
163
|
-
async event(event) {
|
|
164
|
-
if (!this.current())
|
|
165
|
-
return;
|
|
166
|
-
if (event.type === "turn/start") {
|
|
167
|
-
this.#turnEvents = [];
|
|
168
|
-
this.#answer = "";
|
|
169
|
-
this.#hasAnswer = false;
|
|
170
|
-
this.#teamBriefed = false;
|
|
171
|
-
this.execution.begin();
|
|
172
|
-
}
|
|
173
|
-
if (this.execution.current)
|
|
174
|
-
this.#turnEvents.push(event);
|
|
175
|
-
if (event.type === "agent/inbox/spliced") {
|
|
176
|
-
const change = event.data;
|
|
177
|
-
const removed = this.#inbox[change.target].splice(change.start, change.removedCount ?? 0, ...change.inserted);
|
|
178
|
-
if (change.inserted.some(message => message.source.kind === "user"))
|
|
179
|
-
this.pause("成员由人工接管");
|
|
180
|
-
for (const message of removed) {
|
|
181
|
-
if (message.source.kind === "user" && change.outcome !== "canceled")
|
|
182
|
-
this.execution.enterHuman();
|
|
183
|
-
const source = requestSource(message, this.generation);
|
|
184
|
-
if (!source)
|
|
185
|
-
continue;
|
|
186
|
-
if (change.outcome === "canceled") {
|
|
187
|
-
this.execution.cancelQueued(source.requestId);
|
|
188
|
-
if (this.#activeTeam?.request.requestId === source.requestId && !this.execution.current?.requestIds.includes(source.requestId))
|
|
189
|
-
this.#activeTeam = undefined;
|
|
190
|
-
}
|
|
191
|
-
else
|
|
192
|
-
this.execution.enter(source.requestId);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (event.type === "user/message") {
|
|
196
|
-
const source = requestSource(event.data, this.generation);
|
|
197
|
-
if (source)
|
|
198
|
-
this.execution.consume(source.requestId);
|
|
199
|
-
if (event.data.source.kind === "user")
|
|
200
|
-
this.execution.humanInput();
|
|
201
|
-
if (event.data.source.kind === "pbot-team-context") {
|
|
202
|
-
const { teamId, seqs } = event.data.source, seen = this.#seen.get(teamId) ?? new Set();
|
|
203
|
-
if (this.#activeTeam?.team.teamId === teamId)
|
|
204
|
-
this.#teamBriefed = true;
|
|
205
|
-
for (const seq of seqs)
|
|
206
|
-
seen.add(seq);
|
|
207
|
-
this.#seen.set(teamId, seen);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (event.type === "assistant/message") {
|
|
211
|
-
this.#answer = finalDshAnswer(event);
|
|
212
|
-
this.#hasAnswer = true;
|
|
213
|
-
}
|
|
214
|
-
if (event.type === "turn/end") {
|
|
215
|
-
const accounted = foldConsumedWork(this.#turnEvents).end?.seq === event.seq;
|
|
216
|
-
await flushDshAgent(this.agent);
|
|
217
|
-
const reason = event.data.reason;
|
|
218
|
-
this.execution.finish({
|
|
219
|
-
state: reason.kind === "aborted" ? "cancelled" : reason.kind === "interrupted" || reason.kind === "forked" ? "interrupted"
|
|
220
|
-
: reason.kind === "completed" && accounted ? "completed" : "failed",
|
|
221
|
-
position: this.#hasAnswer ? "dsh:" + event.seq : null,
|
|
222
|
-
answer: this.#answer,
|
|
223
|
-
...(reason.kind === "error" ? { error: reason.error.message } : !["completed", "aborted"].includes(reason.kind) ? { error: reason.kind } : {}),
|
|
224
|
-
});
|
|
225
|
-
this.#activeTeam = undefined;
|
|
226
|
-
this.#turnEvents = [];
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
humanPending() { return [...this.agent.inbox.nextTurn, ...this.agent.inbox.nextStep].some(message => message.source.kind === "user"); }
|
|
230
|
-
pump() {
|
|
231
|
-
if (this.#pump || this.#closing)
|
|
232
|
-
return this.#pump ?? Promise.resolve();
|
|
233
|
-
this.#pump = this.deliver().catch(error => {
|
|
234
|
-
if (error.code === "PBOT_CONTROL_BUSY" || (this.#closing && this.#lifetime.signal.aborted))
|
|
235
|
-
return;
|
|
236
|
-
this.fail(error);
|
|
237
|
-
}).finally(() => { this.#pump = undefined; });
|
|
238
|
-
return this.#pump;
|
|
239
|
-
}
|
|
240
|
-
async deliver() {
|
|
241
|
-
const run = this.files.read(this.d.agentId, "launch.json", launch);
|
|
242
|
-
if (run.generation !== this.generation || run.stop) {
|
|
243
|
-
void this.owner.release().catch(error => this.fail(error));
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
await this.#events;
|
|
247
|
-
this.check();
|
|
248
|
-
if (this.#pendingPause) {
|
|
249
|
-
this.pause(this.#pendingPause);
|
|
250
|
-
if (this.#pendingPause)
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const capable = this.#teamTool && !!this.ctx.tools.get("pbot_team_message", this.agent);
|
|
254
|
-
if (capable !== this.#ready) {
|
|
255
|
-
this.teams.files.setReady(this.d.agentId, this.generation, capable);
|
|
256
|
-
this.#ready = capable;
|
|
257
|
-
if (!capable)
|
|
258
|
-
this.pause("成员团队工具已停用");
|
|
259
|
-
}
|
|
260
|
-
if (this.#activeTeam) {
|
|
261
|
-
if (Date.now() >= this.#activeTeam.run.deadlineAt) {
|
|
262
|
-
this.pause("已到期限");
|
|
263
|
-
if (!this.humanPending() && !this.execution.interactive && this.execution.current?.source !== "mixed" && this.execution.current?.source !== "interactive")
|
|
264
|
-
this.agent.cancel({ kind: "hook", reason: "团队请求已到期限" });
|
|
265
|
-
}
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
const links = this.teams.links();
|
|
269
|
-
const idle = () => this.agent.status === "idle" && !this.agent.inbox.nextTurn.length && !this.agent.inbox.nextStep.length && !this.execution.current && !this.execution.pending && !this.execution.interactive;
|
|
270
|
-
for (const request of this.files.messages(this.d.agentId)) {
|
|
271
|
-
if (request.generation !== this.generation || this.execution.accepted(request.requestId))
|
|
272
|
-
continue;
|
|
273
|
-
const link = links.get(request.requestId);
|
|
274
|
-
if (link && (link.team.closed || link.run.state !== "running" || link.run.deadlineAt <= Date.now()))
|
|
275
|
-
continue;
|
|
276
|
-
if (link && !idle())
|
|
277
|
-
break;
|
|
278
|
-
const message = await dshInput(this.ctx, this.d, request, this.#lifetime.signal);
|
|
279
|
-
this.check();
|
|
280
|
-
const submit = async () => {
|
|
281
|
-
this.check();
|
|
282
|
-
const accept = () => this.execution.claim(request.requestId);
|
|
283
|
-
if (link) {
|
|
284
|
-
if (!idle())
|
|
285
|
-
return;
|
|
286
|
-
this.#activeTeam = this.teams.claim(this.d.agentId, this.generation, request.requestId, accept);
|
|
287
|
-
if (!this.#activeTeam)
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
else
|
|
291
|
-
accept();
|
|
292
|
-
if (request.delivery === "followUp")
|
|
293
|
-
this.agent.followup(message);
|
|
294
|
-
else
|
|
295
|
-
this.agent.steer(message);
|
|
296
|
-
await flushDshAgent(this.agent);
|
|
297
|
-
};
|
|
298
|
-
if (link) {
|
|
299
|
-
// Public status stays idle during native maintenance. Its idle admission is authoritative.
|
|
300
|
-
let entered = false;
|
|
301
|
-
try {
|
|
302
|
-
await this.agent.runMaintenance(async (signal) => { entered = true; signal.throwIfAborted(); await submit(); });
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
if (entered)
|
|
306
|
-
throw error;
|
|
307
|
-
this.check();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
else
|
|
311
|
-
await submit();
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
stop() {
|
|
316
|
-
if (this.#stopping)
|
|
317
|
-
return this.#stopping;
|
|
318
|
-
this.#closing = true;
|
|
319
|
-
this.#lifetime.abort();
|
|
320
|
-
if (this.#timer)
|
|
321
|
-
clearInterval(this.#timer);
|
|
322
|
-
this.#timer = undefined;
|
|
323
|
-
this.#stopping = (async () => {
|
|
324
|
-
try {
|
|
325
|
-
if (this.current()) {
|
|
326
|
-
this.files.control(() => {
|
|
327
|
-
const run = this.files.read(this.d.agentId, "launch.json", launch);
|
|
328
|
-
if (run.generation === this.generation && !run.stop) {
|
|
329
|
-
run.stop = true;
|
|
330
|
-
this.files.write(this.d.agentId, "launch.json", run, launch);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
this.teams.files.setReady(this.d.agentId, this.generation, false);
|
|
334
|
-
this.#ready = false;
|
|
335
|
-
this.pause("专家停止");
|
|
336
|
-
if (!this.#failure)
|
|
337
|
-
this.execution.save({ state: "stopping", activity: "停止" });
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
finally {
|
|
341
|
-
this.agent.cancel({ kind: "disposed" });
|
|
342
|
-
}
|
|
343
|
-
await this.agent.whenIdle();
|
|
344
|
-
await this.#pump;
|
|
345
|
-
await this.#events;
|
|
346
|
-
if (this.current() && !this.#failure)
|
|
347
|
-
this.execution.save({ state: "stopped", activity: "已停止" });
|
|
348
|
-
})();
|
|
349
|
-
return this.#stopping;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import type { Agent, AgentSetup } from "@deepseek-ai/dsh-agent";
|
|
3
|
-
import type { AgentDescriptor, AgentSessionReference } from "../../model/agent.js";
|
|
4
|
-
import type { AgentHost } from "../../services/agents/agent-service.js";
|
|
5
|
-
/** Native handles belong to the execution component, independently of browser observers. */
|
|
6
|
-
export declare class DshAgents implements AgentHost {
|
|
7
|
-
#private;
|
|
8
|
-
readonly ctx: Context;
|
|
9
|
-
readonly parent: Agent;
|
|
10
|
-
readonly composition: {
|
|
11
|
-
setup(d: AgentDescriptor, directory: string, generation: string): AgentSetup;
|
|
12
|
-
ready(agent: Agent, generation: string): void;
|
|
13
|
-
stopping(agent: Agent, generation: string): Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
readonly lifetime: AbortSignal;
|
|
16
|
-
readonly kind = "dsh";
|
|
17
|
-
constructor(ctx: Context, parent: Agent, composition: {
|
|
18
|
-
setup(d: AgentDescriptor, directory: string, generation: string): AgentSetup;
|
|
19
|
-
ready(agent: Agent, generation: string): void;
|
|
20
|
-
stopping(agent: Agent, generation: string): Promise<void>;
|
|
21
|
-
}, lifetime: AbortSignal);
|
|
22
|
-
available(): void;
|
|
23
|
-
alive(id: string): boolean;
|
|
24
|
-
private reference;
|
|
25
|
-
validateSession(d: AgentDescriptor, reference: AgentSessionReference): Promise<void>;
|
|
26
|
-
launch(d: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): Promise<void>;
|
|
27
|
-
release(id: string, generation: string): Promise<void>;
|
|
28
|
-
report(d: AgentDescriptor, reference: AgentSessionReference, position: string): Promise<string>;
|
|
29
|
-
close(): Promise<void>;
|
|
30
|
-
}
|