@sema-agent/core
Version:
Stateless, task-oriented AI agent core
38 lines (37 loc) • 1.83 kB
JavaScript
import { canonicalJsonStringify, sha16 } from "./canonical-json.js";
import { mcpPeerTarget } from "./peer-seat.js";
export function peerRegistrationDigestOf(source, facts) {
return sha16(canonicalJsonStringify({ source, registration: facts }));
}
export function credentialReferenceFact(ref) {
if (ref === undefined)
return {};
return { credentials: ref.kind === "handle" ? { kind: "handle" } : ref };
}
export function a2aPeerRegistration(spec) {
return {
url: spec.url,
...(spec.cardUrl !== undefined ? { cardUrl: spec.cardUrl } : {}),
boundary: spec.boundary === "inside" ? "inside" : "outside",
...(spec.ownerTeam !== undefined ? { ownerTeam: spec.ownerTeam } : {}),
...(spec.fingerprint !== undefined ? { fingerprint: spec.fingerprint } : {}),
...credentialReferenceFact(spec.credentials),
...(spec.principalHeader !== undefined ? { principalHeader: spec.principalHeader } : {}),
};
}
export function mcpPeerRegistration(spec, kind) {
const target = mcpPeerTarget(spec, kind);
const t = spec.transport;
const where = target.transport === "host"
? {}
: target.transport === "stdio"
? { command: target.command, args: target.args, ...credentialReferenceFact(target.credentials) }
: { url: target.url, ...credentialReferenceFact(target.credentials), ...("principalHeader" in t && t.principalHeader !== undefined ? { principalHeader: t.principalHeader } : {}) };
return {
transport: target.transport,
...where,
...(typeof spec.fingerprint === "string" ? { fingerprint: spec.fingerprint } : {}),
...(spec.sessionMetaKey !== undefined ? { sessionMetaKey: spec.sessionMetaKey } : {}),
...(spec.callerMeta === true ? { callerMeta: true } : {}),
};
}