The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { z } from 'zod';
import { type ToolInput } from '@/ai/types/ToolInput';
// Coercing would turn a missing name into the tool name "undefined".
const ExecuteToolSchema = z.object({
toolName: z.string().min(1),
arguments: z.unknown().optional(),
});
export const unwrapToolInput = ({
input,
toolName,
}: {
input: ToolInput;
toolName: string;
}): {
toolInput: ToolInput;
toolName: string;
} => {
if (toolName !== 'execute_tool') {
return { toolInput: input, toolName };
}
const parsed = ExecuteToolSchema.safeParse(input);
if (!parsed.success) {
return { toolInput: input, toolName };
}
return {
toolInput: parsed.data.arguments as ToolInput,
toolName: parsed.data.toolName,
};
};