fix(catalog): digest provider projections
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
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. */
|
||||
@@ -9,6 +12,14 @@ export const names = (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);
|
||||
|
||||
@@ -46,6 +46,9 @@ export interface ProductCatalog {
|
||||
}
|
||||
|
||||
export function createProductCatalog(root: string): Promise<ProductCatalog>;
|
||||
export function providerCatalogDigest(
|
||||
providers: ProductCatalog["providers"],
|
||||
): string;
|
||||
export function createCliInventory(cli: unknown): {
|
||||
readonly primary: readonly string[];
|
||||
readonly aliases: readonly {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { format } from "prettier";
|
||||
|
||||
import { assertSameNames, loadSources } from "./catalog-core.mjs";
|
||||
import { assertSameNames, digest, loadSources } from "./catalog-core.mjs";
|
||||
import {
|
||||
createCliInventory,
|
||||
cliCommandDescriptionIssues,
|
||||
@@ -15,6 +15,9 @@ export {
|
||||
cliCommandOptionNames,
|
||||
};
|
||||
|
||||
/** Return the stable digest for the source-derived provider projection. */
|
||||
export const providerCatalogDigest = (providers) => digest(providers);
|
||||
|
||||
/** Project current runtime contracts into deterministic, machine-readable facts. */
|
||||
export const createProductCatalog = async (root) => {
|
||||
const sources = await loadSources(root);
|
||||
@@ -25,6 +28,7 @@ export const createProductCatalog = async (root) => {
|
||||
sources.catalogIdentity.CLI_COMMAND_NAMES,
|
||||
);
|
||||
const tools = toolFamilyCatalog(sources);
|
||||
const providers = providerCatalog(sources);
|
||||
const metadata = sources.packageMetadata.PACKAGE_METADATA;
|
||||
return {
|
||||
catalog_schema_version: 1,
|
||||
@@ -39,7 +43,7 @@ export const createProductCatalog = async (root) => {
|
||||
skill_version: metadata.skillVersion,
|
||||
},
|
||||
tools,
|
||||
providers: providerCatalog(sources),
|
||||
providers,
|
||||
setup_clients: sources.supportedClients.SUPPORTED_CLIENT_DEFINITIONS.map(
|
||||
({ name, displayName, format }) => ({
|
||||
id: name,
|
||||
@@ -56,7 +60,10 @@ export const createProductCatalog = async (root) => {
|
||||
},
|
||||
runtime_catalog: {
|
||||
counts: sources.catalogIdentity.CATALOG_IDENTITY.counts,
|
||||
digests: sources.catalogIdentity.CATALOG_IDENTITY.digests,
|
||||
digests: {
|
||||
...sources.catalogIdentity.CATALOG_IDENTITY.digests,
|
||||
providers_sha256: providerCatalogDigest(providers),
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user