From 98fc900d5ace8574db9bddec84ab2644596baa24 Mon Sep 17 00:00:00 2001 From: Joan Xie Date: Sat, 1 Nov 2025 15:07:43 -0700 Subject: [PATCH] WIP --- src/schemas/any.ts | 27 ++++++++++++++++++++------- src/schemas/index.ts | 4 ++-- src/types.ts | 10 ++++++++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/schemas/any.ts b/src/schemas/any.ts index bd7cec8..000eba4 100644 --- a/src/schemas/any.ts +++ b/src/schemas/any.ts @@ -5,11 +5,24 @@ import * as v0_2 from "./0.2.js"; import * as v0_3 from "./0.3.js"; /** - * Union schema that accepts any supported manifest version (0.1, 0.2, 0.3). - * Use this when you need to validate manifests of any version. + * Union schema that accepts any supported manifest version. + * Uses preprocessing to normalize dxt_version to manifest_version, + * then efficiently discriminates based on the now-required manifest_version field. */ -export const McpbManifestSchema = z.union([ - v0_1.McpbManifestSchema, - v0_2.McpbManifestSchema, - v0_3.McpbManifestSchema, -]); +export const McpbManifestSchema = z.preprocess( + (val) => { + // Normalize: if it has dxt_version, ensure manifest_version is also set + if (val && typeof val === "object" && "dxt_version" in val) { + const obj = val as Record; + if (!obj.manifest_version && obj.dxt_version) { + return { ...obj, manifest_version: obj.dxt_version }; + } + } + return val; + }, + z.union([ + v0_1.McpbManifestSchema, + v0_2.McpbManifestSchema, + v0_3.McpbManifestSchema, + ]), +); diff --git a/src/schemas/index.ts b/src/schemas/index.ts index 3729f0e..df8ff1e 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -1,8 +1,8 @@ export * as v0_1 from "./0.1.js"; export * as v0_2 from "./0.2.js"; export * as v0_3 from "./0.3.js"; -export * as any from "./any.js"; -export * as latest from "./latest.js"; +export * as vAny from "./any.js"; +export * as vLatest from "./latest.js"; export { MANIFEST_VERSION as LATEST_MANIFEST_VERSION, McpbManifestSchema, diff --git a/src/types.ts b/src/types.ts index 9fb510f..e6ba766 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ import type * as z from "zod"; -import type { McpbManifestSchema as McpbManifestSchemaAny } from "./schemas/any.js"; +import type { McpbManifestSchema as McpbManifestSchema_vAny } from "./schemas/any.js"; import type { McpbManifestAuthorSchema, McpbManifestCompatibilitySchema, @@ -51,7 +51,7 @@ export type McpbUserConfigValues = z.infer; * McpbManifest type that accepts any supported manifest version * This is the default manifest type that should be used for maximum compatibility. */ -export type McpbManifest = z.infer; +export type McpbManifestAny = z.infer; /** * McpbManifest type for the latest manifest version only @@ -59,6 +59,12 @@ export type McpbManifest = z.infer; */ export type McpbManifestLatest = z.infer; +/** + * @deprecated Use McpbManifestAny instead + * Default manifest type that accepts any supported version + */ +export type McpbManifest = McpbManifestAny; + /** * Information about a MCPB package signature */