MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / validateInput

Function validateInput

packages/kernel/core/src/validation.ts:50–86  ·  view source on GitHub ↗
(input: {
  schema: unknown;
  value: unknown;
  path: string;
})

Source from the content-addressed store, hash-verified

48
49/** Validate a value against a Standard Schema */
50export const validateInput = (input: {
51 schema: unknown;
52 value: unknown;
53 path: string;
54}): Effect.Effect<unknown, Error> => {
55 const validate = getSchemaValidator(input.schema);
56 if (!validate) {
57 return Effect.fail(
58 new KernelCoreEffectError({
59 module: "validation",
60 message: `Tool ${input.path} has no Standard Schema validator on inputSchema`,
61 }),
62 );
63 }
64
65 return Effect.tryPromise({
66 try: () => Promise.resolve(validate(input.value)),
67 catch: (cause) =>
68 new KernelCoreEffectError({
69 module: "validation",
70 message: `Validation error for ${input.path}`,
71 cause,
72 }),
73 }).pipe(
74 Effect.flatMap((result) => {
75 if ("issues" in result && result.issues) {
76 return Effect.fail(
77 new KernelCoreEffectError({
78 module: "validation",
79 message: `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`,
80 }),
81 );
82 }
83 return Effect.succeed(result.value);
84 }),
85 );
86};

Callers

nothing calls this directly

Calls 4

getSchemaValidatorFunction · 0.85
validateFunction · 0.85
formatIssuesFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected