mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-13 14:37:26 +00:00
fix(agentstack): require agent DIDs for registration (#85)
This commit is contained in:
parent
41ab662afa
commit
895bb9989e
2 changed files with 7 additions and 5 deletions
|
|
@ -132,6 +132,7 @@ describe("AgentStack coordinator", () => {
|
||||||
it("rejects unknown agents and invalid DIDs", () => {
|
it("rejects unknown agents and invalid DIDs", () => {
|
||||||
const stack = new AgentStack();
|
const stack = new AgentStack();
|
||||||
expect(() => stack.createTask({ ownerDid: "nope", sourceApp: "x", title: "t" })).toThrow();
|
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" });
|
const task = stack.createTask({ ownerDid: owner, sourceApp: "x", title: "t" });
|
||||||
expect(() => stack.assignTask(task.id, agentDid("ghost"))).toThrow(/Unknown agent/);
|
expect(() => stack.assignTask(task.id, agentDid("ghost"))).toThrow(/Unknown agent/);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,12 @@ export class AgentStack {
|
||||||
return `${prefix}_${this.seq}`;
|
return `${prefix}_${this.seq}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerAgent(agent: AgentProfile): AgentProfile {
|
registerAgent(agent: AgentProfile): AgentProfile {
|
||||||
if (!parseDid(agent.did)) {
|
const parsed = parseDid(agent.did);
|
||||||
throw new Error(`Invalid agent DID: ${agent.did}`);
|
if (!parsed || parsed.kind !== "agent") {
|
||||||
}
|
throw new Error(`Invalid agent DID: ${agent.did}`);
|
||||||
this.agents.set(agent.did, agent);
|
}
|
||||||
|
this.agents.set(agent.did, agent);
|
||||||
this.emit({ type: "agent.registered", agent });
|
this.emit({ type: "agent.registered", agent });
|
||||||
return agent;
|
return agent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue