refactor(catalog): consolidate digest presentation (#17447)

This commit is contained in:
Vincent Koc
2026-12-06 16:00:19 +08:00
committed by GitHub
parent 46b9617629
commit 74712cde2b
+11 -31
View File
@@ -128,14 +128,19 @@ export const digestCatalogProjection = (value: unknown): string =>
sha256Hex(canonicalJson(value));
/** Digests of the presented tool and prompt catalog. */
const digestPresentedCatalogs = (
catalog: ReturnType<typeof presentToolCatalog>,
const digestCatalogs = (
catalog: ReturnType<typeof createToolCatalog>,
prompts: ReturnType<typeof createPromptCatalog>,
outputSchemaProfile: McpOutputSchemaProfile,
compactPresentation?: CompactInputSchemaPresentation,
) => {
const presentation = advertisedToolPresentation(
outputSchemaProfile,
compactPresentation,
);
const tools = canonicalJson({
output_schema_profile: outputSchemaProfile,
catalog,
catalog: presentToolCatalog(catalog, presentation),
});
const promptCatalog = canonicalJson(prompts);
// RFC 8785 writes an object as its members in key order, each value in its
@@ -149,21 +154,6 @@ const digestPresentedCatalogs = (
} as const;
};
const digestCatalogs = (
catalog: ReturnType<typeof createToolCatalog>,
prompts: ReturnType<typeof createPromptCatalog>,
compactPresentation: CompactInputSchemaPresentation,
outputSchemaProfile: McpOutputSchemaProfile,
) =>
digestPresentedCatalogs(
presentToolCatalog(
catalog,
advertisedToolPresentation(outputSchemaProfile, compactPresentation),
),
prompts,
outputSchemaProfile,
);
/**
* Catalog digests over the given tool contracts. Exported so tests can prove
* which contract fields the identity covers; production uses
@@ -180,8 +170,8 @@ export const createCatalogDigests = (
digestCatalogs(
createToolCatalog(sortByName(contracts)),
createPromptCatalog(promptContracts),
compactPresentation,
outputSchemaProfile,
compactPresentation,
);
/** Build-time identities share schema conversion across both output profiles. */
@@ -192,18 +182,8 @@ export const createCatalogDigestProfiles = (
const catalog = createToolCatalog(sortByName(contracts));
const prompts = createPromptCatalog(promptContracts);
return {
off: digestCatalogs(
catalog,
prompts,
COMPACT_INPUT_SCHEMA_PRESENTATION,
"off",
),
compact: digestCatalogs(
catalog,
prompts,
COMPACT_INPUT_SCHEMA_PRESENTATION,
"compact",
),
off: digestCatalogs(catalog, prompts, "off"),
compact: digestCatalogs(catalog, prompts, "compact"),
};
};