Skip to content

Commit 540ece0

Browse files
fix(agentstack): require agent DIDs for registration
1 parent 41ab662 commit 540ece0

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

packages/agentstack/src/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ describe("AgentStack coordinator", () => {
132132
it("rejects unknown agents and invalid DIDs", () => {
133133
const stack = new AgentStack();
134134
expect(() => stack.createTask({ ownerDid: "nope", sourceApp: "x", title: "t" })).toThrow();
135+
expect(() => stack.registerAgent({ ...agent, did: userDid("not-an-agent") })).toThrow(/Invalid agent DID/);
135136
const task = stack.createTask({ ownerDid: owner, sourceApp: "x", title: "t" });
136137
expect(() => stack.assignTask(task.id, agentDid("ghost"))).toThrow(/Unknown agent/);
137138
});

packages/agentstack/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ export class AgentStack {
7676
return `${prefix}_${this.seq}`;
7777
}
7878

79-
registerAgent(agent: AgentProfile): AgentProfile {
80-
if (!parseDid(agent.did)) {
81-
throw new Error(`Invalid agent DID: ${agent.did}`);
82-
}
83-
this.agents.set(agent.did, agent);
79+
registerAgent(agent: AgentProfile): AgentProfile {
80+
const parsed = parseDid(agent.did);
81+
if (!parsed || parsed.kind !== "agent") {
82+
throw new Error(`Invalid agent DID: ${agent.did}`);
83+
}
84+
this.agents.set(agent.did, agent);
8485
this.emit({ type: "agent.registered", agent });
8586
return agent;
8687
}

0 commit comments

Comments
 (0)