The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { z } from 'zod';
import { AI_EVALUATION_QUESTION_TYPES } from '@/ai/constants/ai-evaluation-question-type.const';
import { baseWorkflowActionSettingsSchema } from './base-workflow-action-settings-schema';
// A dot, brace or space would be read as variable-path structure, so the answer would never resolve.
export const CLASSIFY_ANSWER_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
// Option names are path segments too; escapePathSegment handles spaces and brackets but not dots.
export const CLASSIFY_OPTION_NAME_FORBIDDEN_CHARACTER = '.';
export const workflowClassifyCriterionSchema = z.object({
id: z.uuid().describe('Stable identifier for this criterion row.'),
name: z
.string()
.describe(
'Option name for a choice question, or the label of one score level.',
),
description: z
.string()
.optional()
.describe('What the model should understand this option to mean.'),
});
export const workflowClassifyQuestionSchema = z.object({
id: z.uuid().describe('Stable identifier for this question row.'),
name: z
.string()
.regex(
CLASSIFY_ANSWER_NAME_PATTERN,
'Answer name must be empty or contain 1 to 64 characters using only letters, digits, underscores and dashes',
)
.or(z.literal(''))
.describe(
'Answer key for this question, made of letters, digits, underscores and dashes. Downstream steps read {{stepId.answers.<name>}}.',
),
type: z
.enum(AI_EVALUATION_QUESTION_TYPES)
.describe(
'choice picks one option, score grades an ordered rubric, boolean estimates the probability that a statement holds.',
),
instructions: z
.string()
.describe('What the model should decide about the shared state.'),
criteria: z
.array(workflowClassifyCriterionSchema)
.describe(
'Options for a choice question, or ordered levels (lowest first) for a score question. Empty for boolean.',
),
});
export const workflowClassifyActionSettingsSchema =
baseWorkflowActionSettingsSchema.extend({
input: z.object({
state: z
.string()
.describe(
'The shared state every question is asked about. Supports variables.',
),
questions: z.array(workflowClassifyQuestionSchema),
}),
});