Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,9 @@ import { assert, describe, expect, it } from 'vitest'
import { schema } from '@/apps/pair/actions/send-prompt/schema'

describe('call-pair schema', () => {
describe('promptType validation', () => {
it('should accept valid prompt types', () => {
const validTypes = [
'analyse',
'categorise',
'summarise',
'write',
'custom',
]

validTypes.forEach((promptType) => {
const result = schema.safeParse({
promptType,
prompt: 'test prompt',
responseFields: [
{
fieldName: 'summary',
fieldType: 'text',
},
],
})
assert(result.success === true)
assert(result.data.promptType === promptType)
})
})

it('should reject invalid prompt types', () => {
const result = schema.safeParse({
promptType: 'invalid',
prompt: 'test prompt',
})
assert(result.success === false)
})

it('should require promptType', () => {
const result = schema.safeParse({
prompt: 'test prompt',
})
assert(result.success === false)
})
})

describe('prompt validation', () => {
it('should accept valid non-empty prompts', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'Analyze this document',
responseFields: [
{
Expand All @@ -63,16 +20,13 @@ describe('call-pair schema', () => {

it('should reject empty prompts', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: '',
})
assert(result.success === false)
})

it('should require prompt field', () => {
const result = schema.safeParse({
promptType: 'analyse',
})
const result = schema.safeParse({})
assert(result.success === false)
})
})
Expand All @@ -90,7 +44,6 @@ describe('call-pair schema', () => {
'should accept valid field names with letters, numbers, and spaces: %s',
(fieldName) => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand Down Expand Up @@ -118,7 +71,6 @@ describe('call-pair schema', () => {
'should reject field names with invalid characters: %s',
(fieldName) => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [{ fieldName, fieldType: 'text' }],
})
Expand All @@ -128,7 +80,6 @@ describe('call-pair schema', () => {

it('should reject empty field names', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -143,7 +94,6 @@ describe('call-pair schema', () => {
it('should reject field names longer than 64 characters', () => {
const longName = 'a'.repeat(65)
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -158,7 +108,6 @@ describe('call-pair schema', () => {
it('should accept field names exactly 64 characters long', () => {
const maxName = 'a'.repeat(64)
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -172,7 +121,6 @@ describe('call-pair schema', () => {

it('should not accept duplicate field names (case-insensitive)', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand Down Expand Up @@ -201,7 +149,6 @@ describe('call-pair schema', () => {
describe('fieldType validation', () => {
it('should accept text field type', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -216,7 +163,6 @@ describe('call-pair schema', () => {

it('should accept number field type', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -231,7 +177,6 @@ describe('call-pair schema', () => {

it('should accept category field type with valid categories', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -247,7 +192,6 @@ describe('call-pair schema', () => {

it('should reject invalid field types', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -261,7 +205,6 @@ describe('call-pair schema', () => {

it('should reject empty response fields', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [],
})
Expand All @@ -280,7 +223,6 @@ describe('call-pair schema', () => {
describe('fieldCategories validation', () => {
it('should require fieldCategories when fieldType is category', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -299,7 +241,6 @@ describe('call-pair schema', () => {

it('should accept valid comma-separated categories', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -314,7 +255,6 @@ describe('call-pair schema', () => {

it('should accept categories without spaces', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -329,7 +269,6 @@ describe('call-pair schema', () => {

it('should reject empty categories when fieldType is category', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -353,7 +292,6 @@ describe('call-pair schema', () => {
'should reject categories with empty items after trimming: %s',
(fieldCategories) => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -378,7 +316,6 @@ describe('call-pair schema', () => {
'should reject categories with duplicates (case-insensitive): %s',
(fieldCategories) => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -399,7 +336,6 @@ describe('call-pair schema', () => {

it('should allow fieldCategories to be optional when fieldType is not category', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand All @@ -416,7 +352,6 @@ describe('call-pair schema', () => {
describe('multiple fields validation', () => {
it('should accept multiple valid response fields', () => {
const result = schema.safeParse({
promptType: 'analyse',
prompt: 'test prompt',
responseFields: [
{
Expand Down Expand Up @@ -462,7 +397,6 @@ describe('call-pair schema', () => {
],
})
assert(result.success === true)
assert(result.data.promptType === 'analyse')
assert(result.data.responseFields.length === 3)
})
})
Expand Down
44 changes: 17 additions & 27 deletions packages/backend/src/apps/pair/actions/send-prompt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import StepError, { GenericSolution } from '@/errors/step'
import {
DEFAULT_PROMPT_VALUES,
DEFAULT_RESPONSE_FIELDS_VALUES,
PROMPT_PRESETS,
} from '../../common/constants'
import generateObject from '../../common/generate-object'
import { generateSchemaFromFields } from '../../common/generate-schema'
Expand All @@ -23,24 +24,6 @@ const action: IRawAction = {
description:
'Enter a custom prompt to summarise, categorise or analyse data with Pair',
arguments: [
{
label: 'What would you like to do?',
key: 'promptType',
type: 'dropdown' as const,
required: true,
options: [
{ label: 'Analyse', value: 'analyse' },
{ label: 'Categorise', value: 'categorise' },
{ label: 'Summarise', value: 'summarise' },
{ label: 'Write', value: 'write' },
{
label: 'Custom prompt',
value: 'custom',
description: 'Do it yourself',
},
],
showOptionValue: false,
},
{
label: 'Describe what you want Pair to do',
key: 'prompt',
Expand All @@ -56,10 +39,21 @@ const action: IRawAction = {
* this feature simple.
*/
customRteMenuOptions: [],
defaultValue: {
fieldKey: 'promptType',
options: DEFAULT_PROMPT_VALUES,
},
presets: PROMPT_PRESETS.map((preset) => ({
key: preset.key,
label: preset.label,
description: preset.description,
assignments: [
{
fieldKey: 'prompt',
value: DEFAULT_PROMPT_VALUES[preset.key],
},
{
fieldKey: 'responseFields',
value: DEFAULT_RESPONSE_FIELDS_VALUES[preset.key],
},
],
})),
},
{
label: 'Define how you want Pair to structure what it extracts',
Expand All @@ -68,7 +62,7 @@ const action: IRawAction = {
type: 'multirow-multicol' as const,
required: true,
hiddenIf: {
fieldKey: 'promptType',
fieldKey: 'prompt',
op: 'is_empty',
},
addRowButtonText: 'Add output',
Expand Down Expand Up @@ -107,10 +101,6 @@ const action: IRawAction = {
customStyle: { flex: 3 },
},
],
defaultValue: {
fieldKey: 'promptType',
options: DEFAULT_RESPONSE_FIELDS_VALUES,
},
},
],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '../../common/schema'

export const schema = z.object({
promptType: z.enum(['analyse', 'categorise', 'summarise', 'write', 'custom']),
prompt: z.string().min(1),
responseFields: z
.array(
Expand Down
Loading
Loading