(input: {
schema: unknown;
value: unknown;
path: string;
})
| 48 | |
| 49 | /** Validate a value against a Standard Schema */ |
| 50 | export 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 | }; |
nothing calls this directly
no test coverage detected