Skip to content

Commit 38962d1

Browse files
fix(models): validate manifest compatibility bounds
1 parent 15f50e9 commit 38962d1

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎apps/server/src/provider/ClaudeModelManifest.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TrimmedNonEmptyString } from "@t3tools/contracts";
2+
import { compareSemverVersions, parseSemver } from "@t3tools/shared/semver";
23
import * as Option from "effect/Option";
34
import * as Schema from "effect/Schema";
45

@@ -20,13 +21,31 @@ export const ClaudeProfileAdapterSchema = Schema.Struct({
2021
claudeCode: Schema.optional(ClaudeCodeProfileSchema),
2122
});
2223

23-
export const ClaudeModelAdapterSchema = Schema.Struct({
24-
claudeCode: Schema.optional(
25-
Schema.Struct({
26-
minVersion: Schema.optional(TrimmedNonEmptyString),
27-
maxVersionExclusive: Schema.optional(TrimmedNonEmptyString),
24+
const ClaudeVersionSchema = TrimmedNonEmptyString.pipe(
25+
Schema.check(
26+
Schema.makeFilter((version) => parseSemver(version) !== null, {
27+
expected: "a supported semantic version",
2828
}),
2929
),
30+
);
31+
32+
const ClaudeCodeCompatibilitySchema = Schema.Struct({
33+
minVersion: Schema.optional(ClaudeVersionSchema),
34+
maxVersionExclusive: Schema.optional(ClaudeVersionSchema),
35+
}).pipe(
36+
Schema.check(
37+
Schema.makeFilter(
38+
({ minVersion, maxVersionExclusive }) =>
39+
minVersion === undefined ||
40+
maxVersionExclusive === undefined ||
41+
compareSemverVersions(minVersion, maxVersionExclusive) < 0,
42+
{ expected: "a minimum version below the exclusive maximum version" },
43+
),
44+
),
45+
);
46+
47+
export const ClaudeModelAdapterSchema = Schema.Struct({
48+
claudeCode: Schema.optional(ClaudeCodeCompatibilitySchema),
3049
});
3150

3251
export type ClaudeCodeProfile = typeof ClaudeCodeProfileSchema.Type;

‎apps/server/src/provider/ModelManifest.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ const REMOTE_CLAUDE_MANIFEST: ModelManifestData = {
185185
},
186186
};
187187

188+
const remoteClaudeManifestWithCompatibility = (compatibility: unknown): ModelManifestData => ({
189+
...REMOTE_CLAUDE_MANIFEST,
190+
providers: {
191+
claudeAgent: {
192+
profiles: REMOTE_CLAUDE_MANIFEST.providers!.claudeAgent!.profiles,
193+
models: REMOTE_CLAUDE_MANIFEST.providers!.claudeAgent!.models.map((model) => ({
194+
...model,
195+
adapter: { claudeCode: compatibility },
196+
})),
197+
},
198+
},
199+
});
200+
188201
const INVALID_REMOTE_MANIFESTS: ReadonlyArray<ModelManifestData> = [
189202
{
190203
...REMOTE_CLAUDE_MANIFEST,
@@ -235,6 +248,12 @@ const INVALID_REMOTE_MANIFESTS: ReadonlyArray<ModelManifestData> = [
235248
},
236249
},
237250
},
251+
remoteClaudeManifestWithCompatibility({ minVersion: "2.x" }),
252+
remoteClaudeManifestWithCompatibility({ maxVersionExclusive: "2.x" }),
253+
remoteClaudeManifestWithCompatibility({
254+
minVersion: "2.2",
255+
maxVersionExclusive: "2.1",
256+
}),
238257
];
239258

240259
const httpClientLayer = (handler: () => Response) =>

0 commit comments

Comments
 (0)