mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* refactor(contracts): move the CLI command name owner into src/contracts * refactor(contracts): own catalog identity in contracts and server identity in process (#11435) * refactor(contracts): move catalog identity into contracts and server identity into process * refactor(contracts): own the advertised MCP schema presentation in contracts * test(mcp): import the advertised presentation from contracts in toolSchemaValidity * test(release): expect the catalog identity at its contracts path in the canary * test(mcp): import the catalog identity from contracts in syntheticContractSurfaces * refactor(contracts): import CLI command names from contracts in the capability conformance test
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
import { createHash } from "node:crypto";
|
|
import { join } from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
import canonicalize from "canonicalize";
|
|
|
|
const load = (root, path) => import(pathToFileURL(join(root, path)).href);
|
|
|
|
/** Sort tool/provider names alphabetically. */
|
|
export const names = (contracts) =>
|
|
contracts
|
|
.map(({ name }) => name)
|
|
.sort((left, right) => left.localeCompare(right));
|
|
|
|
/** Return the stable digest for a generated catalog projection. */
|
|
export const digest = (value) => {
|
|
const encoded = canonicalize(value);
|
|
if (encoded === undefined)
|
|
throw new TypeError("Catalog projection is not canonical JSON");
|
|
return createHash("sha256").update(encoded).digest("hex");
|
|
};
|
|
|
|
/** Throw when two name lists diverge. */
|
|
export const assertSameNames = (label, actual, expected) => {
|
|
const actualSet = new Set(actual);
|
|
const expectedSet = new Set(expected);
|
|
const missing = [...expectedSet].filter((name) => !actualSet.has(name));
|
|
const extra = [...actualSet].filter((name) => !expectedSet.has(name));
|
|
if (missing.length === 0 && extra.length === 0) return;
|
|
throw new Error(
|
|
`${label} drifted (missing: ${missing.join(", ") || "none"}; extra: ${extra.join(", ") || "none"})`,
|
|
);
|
|
};
|
|
|
|
const SOURCE_PATHS = {
|
|
packageMetadata: "dist/generatedPackageMetadata.js",
|
|
catalogIdentity: "dist/contracts/catalog/catalogIdentity.js",
|
|
cli: "dist/cli.js",
|
|
toolContracts: "dist/contracts/toolContracts.js",
|
|
toolFamilies: "dist/contracts/toolFamilies.js",
|
|
capabilityDeclarations: "dist/composition/capabilityDeclarations.js",
|
|
supportedClients: "dist/application/SupportedClients.js",
|
|
};
|
|
|
|
/** Load every compiled source module referenced by the catalog. */
|
|
export const loadSources = async (root) =>
|
|
Object.fromEntries(
|
|
await Promise.all(
|
|
Object.entries(SOURCE_PATHS).map(async ([key, path]) => [
|
|
key,
|
|
await load(root, path),
|
|
]),
|
|
),
|
|
);
|