mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 21:32:39 +02:00
19 lines
521 B
TypeScript
19 lines
521 B
TypeScript
import { z } from "zod";
|
|
import { parseWithSchema, safeParseWithSchema } from "./parse";
|
|
|
|
export interface ToolUiContract<T> {
|
|
schema: z.ZodType<T>;
|
|
parse: (input: unknown) => T;
|
|
safeParse: (input: unknown) => T | null;
|
|
}
|
|
|
|
export function defineToolUiContract<T>(
|
|
componentName: string,
|
|
schema: z.ZodType<T>,
|
|
): ToolUiContract<T> {
|
|
return {
|
|
schema,
|
|
parse: (input: unknown) => parseWithSchema(schema, input, componentName),
|
|
safeParse: (input: unknown) => safeParseWithSchema(schema, input),
|
|
};
|
|
}
|