fix(agentstack): require agent DIDs for registration (#85)

This commit is contained in:
RissRIce 2026-06-22 06:24:33 -06:00 committed by GitHub
parent 41ab662afa
commit 895bb9989e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -132,6 +132,7 @@ describe("AgentStack coordinator", () => {
it("rejects unknown agents and invalid DIDs", () => {
const stack = new AgentStack();
expect(() => stack.createTask({ ownerDid: "nope", sourceApp: "x", title: "t" })).toThrow();
expect(() => stack.registerAgent({ ...agent, did: userDid("not-an-agent") })).toThrow(/Invalid agent DID/);
const task = stack.createTask({ ownerDid: owner, sourceApp: "x", title: "t" });
expect(() => stack.assignTask(task.id, agentDid("ghost"))).toThrow(/Unknown agent/);
});

View file

@ -76,11 +76,12 @@ export class AgentStack {
return `${prefix}_${this.seq}`;
}
registerAgent(agent: AgentProfile): AgentProfile {
if (!parseDid(agent.did)) {
throw new Error(`Invalid agent DID: ${agent.did}`);
}
this.agents.set(agent.did, agent);
registerAgent(agent: AgentProfile): AgentProfile {
const parsed = parseDid(agent.did);
if (!parsed || parsed.kind !== "agent") {
throw new Error(`Invalid agent DID: ${agent.did}`);
}
this.agents.set(agent.did, agent);
this.emit({ type: "agent.registered", agent });
return agent;
}