Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
import { ParseResult, Predicate, Schema } from 'effect';
const errorMessage = (error: unknown): string =>
Predicate.isError(error) ? error.message : String(error);
export function JSONTransformSchema<To extends Schema.Schema.Any>(to: To) {
return Schema.transformOrFail(Schema.String, to, {
strict: true,
encode: (obj, _options, ast) =>
ParseResult.try({
try: () => JSON.stringify(obj),
catch: error => new ParseResult.Type(ast, obj, errorMessage(error)),
}),
decode: (str, _options, ast) =>
ParseResult.try({
try: () => JSON.parse(str),
catch: error => new ParseResult.Type(ast, str, errorMessage(error)),
}),
});
}