refactor(schemas): select native and GPU variants by name

This commit is contained in:
morluto committed 2026-10-27 14:04:53 +08:00
1 parent d14f199736
commit c602fe8828
3 files changed
+39 -32

No files matched your search

@@ -4,7 +4,7 @@ import { z } from "zod";
import {
gpuCodeObjectsSchema,
gpuCodeObjectsObjectSchema,
gpuCodeObjectsSelectionSchema,
gpuCodeObjectsSelectionSchemas,
gpuObjectSchema,
gpuKernelSchema,
gpuTargetSchema,
@@ -31,16 +31,16 @@ import { AnalysisResourceConstraintError } from "../analysisErrorCore.js";
export const gpuCodeObjectsViewRequestSchema = z.discriminatedUnion(
"collection",
[
gpuCodeObjectsSelectionSchema.options[0].extend({
gpuCodeObjectsSelectionSchemas.objects.extend({
kind: z.literal("gpu-code-objects"),
}),
gpuCodeObjectsSelectionSchema.options[1].extend({
gpuCodeObjectsSelectionSchemas.kernels.extend({
kind: z.literal("gpu-code-objects"),
}),
gpuCodeObjectsSelectionSchema.options[2].extend({
gpuCodeObjectsSelectionSchemas.ptx.extend({
kind: z.literal("gpu-code-objects"),
}),
gpuCodeObjectsSelectionSchema.options[3].extend({
gpuCodeObjectsSelectionSchemas.targets.extend({
kind: z.literal("gpu-code-objects"),
}),
],
+29 -23
View File
@@ -377,32 +377,38 @@ const selection = {
offset: count.default(0),
limit: z.number().int().positive().default(32),
};
export const gpuCodeObjectsSelectionSchemas = {
objects: z.strictObject({
...selection,
collection: z.literal("objects"),
fields: z.array(gpuObjectSchema.keyof()).optional(),
}),
kernels: z.strictObject({
...selection,
collection: z.literal("kernels"),
object_ids: z.array(z.string()).optional(),
names: z.array(z.string()).optional(),
fields: z.array(gpuKernelSchema.keyof()).optional(),
}),
ptx: z.strictObject({
collection: z.literal("ptx"),
object_id: z.string(),
offset: count.default(0),
limit: z.number().int().positive().default(4096),
}),
targets: z.strictObject({
...selection,
collection: z.literal("targets"),
fields: z.array(gpuTargetSchema.keyof()).optional(),
}),
};
export const gpuCodeObjectsSelectionSchema = z.discriminatedUnion(
"collection",
[
z.strictObject({
...selection,
collection: z.literal("objects"),
fields: z.array(gpuObjectSchema.keyof()).optional(),
}),
z.strictObject({
...selection,
collection: z.literal("kernels"),
object_ids: z.array(z.string()).optional(),
names: z.array(z.string()).optional(),
fields: z.array(gpuKernelSchema.keyof()).optional(),
}),
z.strictObject({
collection: z.literal("ptx"),
object_id: z.string(),
offset: count.default(0),
limit: z.number().int().positive().default(4096),
}),
z.strictObject({
...selection,
collection: z.literal("targets"),
fields: z.array(gpuTargetSchema.keyof()).optional(),
}),
gpuCodeObjectsSelectionSchemas.objects,
gpuCodeObjectsSelectionSchemas.kernels,
gpuCodeObjectsSelectionSchemas.ptx,
gpuCodeObjectsSelectionSchemas.targets,
],
);
export const inspectGpuCodeObjectsInputSchema = z
+5 -4
View File
@@ -6,9 +6,11 @@ import { readEvidencePayload } from "../evidenceValidation.js";
import { digestCanonicalValue } from "../canonicalDigest.js";
import { functionDossierSchema } from "../native/functionDossier.js";
import {
availableFunctionBodySchema,
functionBodySchema,
functionBodyEntryAgrees,
} from "../native/functionBody.js";
import { unavailableNativeFactSchema } from "./nativeFactAvailability.js";
import { nativeSymbolOrigin } from "./nativeSymbol.js";
import {
addressedValueSchema,
@@ -26,11 +28,10 @@ import {
const matchingRowsSchema = nativeInventoryRowsSchemas.names.element
.extend({ address: nativeAddressInputSchema })
.array();
const availableBodySchema = functionBodySchema.options[1];
const matchingBodySchema = z.discriminatedUnion("available", [
functionBodySchema.options[0],
availableBodySchema.safeExtend({
ranges: availableBodySchema.shape.ranges.element
unavailableNativeFactSchema,
availableFunctionBodySchema.safeExtend({
ranges: availableFunctionBodySchema.shape.ranges.element
.extend({
start: nativeAddressInputSchema,
end: nativeAddressInputSchema,