feat(agent): create/resume factory seam

Add the agent-creation factory seam on ctx.agents (AgentRegistry):
setFactory/create/resume plus the AgentFactory interface and
CreateAgentOptions/ResumeAgentOptions. AgentLoop implements AgentFactory
and registers itself via ctx.agents.setFactory(this), so plugins
create/resume agents through the interface without depending on the
concrete loop package.

- create({ agentId, sessionId, meta?, agentOptions? }) — programmatic
  create on a caller-supplied session id (e.g. an ACP-generated id).
- resume({ agentId, resumeSessionId, agentOptions? }) — load a persisted
  session via ctx.sessionPersistence (RFC 009) and resume an agent on it;
  the live session id is the resumed id, turn numbering and derived
  history continue from the loaded log. sessionPersistence is NOT
  hard-injected (non-persistent demos still work); resume rejects with a
  typed error when it is absent. assertAgentIdFree runs before any
  session is created (and again after the load await) so a duplicate id
  never leaves an orphaned live session.

Adds the runtime dsh-session-persistence dependency to agent-loop.
This commit is contained in:
Tianyi Cui
2026-06-15 21:12:14 +08:00
parent df4b7d3d9a
commit 9a4006cb2b
13 changed files with 516 additions and 25 deletions

View File

@@ -561,6 +561,7 @@ __metadata:
"@deepseek-ai/dsh-invariants": "npm:^0.0.1"
"@deepseek-ai/dsh-llm": "npm:^0.0.1"
"@deepseek-ai/dsh-session": "npm:^0.0.1"
"@deepseek-ai/dsh-session-persistence": "npm:^0.0.1"
"@deepseek-ai/dsh-session-persistence-jsonl": "npm:^0.0.1"
"@deepseek-ai/dsh-system-prompt": "npm:^0.0.1"
"@deepseek-ai/dsh-tools": "npm:^0.0.1"
@@ -570,6 +571,7 @@ __metadata:
"@deepseek-ai/dsh-agent": ^0.0.1
"@deepseek-ai/dsh-llm": ^0.0.1
"@deepseek-ai/dsh-session": ^0.0.1
"@deepseek-ai/dsh-session-persistence": ^0.0.1
"@deepseek-ai/dsh-system-prompt": ^0.0.1
"@deepseek-ai/dsh-tools": ^0.0.1
cordis: ^4.0.0-rc.6