Skip to content

Commit 86c8e7e

Browse files
committed
refactor: single input value
1 parent 2bdd0f2 commit 86c8e7e

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

packages/backend/src/graphql/__tests__/mutations/ai/generate-ai-steps.test.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ const DEFAULT_MOCKED_OUTPUT = {
7272
}
7373

7474
const DEFAULT_INPUT = {
75-
trigger: 'New FormSG submission',
76-
actions:
77-
'Send a welcome email to the new user\nSend a welcome SMS to the new user',
75+
prompt:
76+
'#### Start the workflow\nNew FormSG submission\n\n#### Actions\nSend a welcome email to the new user\nSend a welcome SMS to the new user',
7877
}
7978

8079
describe('generateAiSteps mutation', () => {
@@ -115,28 +114,12 @@ describe('generateAiSteps mutation', () => {
115114
null,
116115
{
117116
input: {
118-
trigger: 'gibberish',
119-
actions: 'gibberish',
117+
prompt: 'gibberish',
120118
},
121119
},
122120
context,
123121
),
124-
).rejects.toThrow('Description must be at least 15 characters')
125-
})
126-
127-
it('should throw an error if the input is invalid', async () => {
128-
await expect(
129-
generateAiSteps(
130-
null,
131-
{
132-
input: {
133-
trigger: 'New user submit a new form response',
134-
actions: 'gibberish',
135-
},
136-
},
137-
context,
138-
),
139-
).rejects.toThrow('Description must be at least 30 characters')
122+
).rejects.toThrow('Prompt must be at least 15 characters')
140123
})
141124

142125
it('should map step positions correctly', async () => {

packages/backend/src/graphql/mutations/ai/generate-ai-steps.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ const generateAiSteps: MutationResolvers['generateAiSteps'] = async (
3333

3434
try {
3535
const validatedInput = INPUT_SCHEMA.parse(params.input)
36-
const { trigger: triggerInput, actions: actionsInput } = validatedInput
37-
const userPrompt = `**trigger**:\n${triggerInput}\n\n**actions**:\n${actionsInput}`
36+
const { prompt: userPrompt } = validatedInput
3837

3938
if (!context.currentUser) {
4039
throw new ForbiddenError('Not authorised!')
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { z } from 'zod/v3'
22

33
export const INPUT_SCHEMA = z.object({
4-
trigger: z
4+
prompt: z
55
.string()
66
.trim()
7-
.min(15, 'Description must be at least 15 characters')
8-
.max(250, 'Description must not exceed 250 characters'),
9-
actions: z
10-
.string()
11-
.trim()
12-
.min(30, 'Description must be at least 30 characters')
13-
.max(3000, 'Description must not exceed 3000 characters'),
7+
.min(15, 'Prompt must be at least 15 characters')
8+
.max(3000, 'Prompt must not exceed 3000 characters'),
149
})

packages/backend/src/graphql/schema.graphql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ type Mutation {
127127
}
128128

129129
input GenerateAiStepsInput {
130-
trigger: String!
131-
actions: String!
130+
prompt: String!
132131
}
133132

134133
type AdminMutation {

0 commit comments

Comments
 (0)