| 1 |
import { activeCanvasStep, useCanvasStore } from '@agent/state/canvas'; |
| 2 |
import { steps } from '@agent/workflows/canvas/components/DemoForm'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
|
| 5 |
// Only the step on screen is live, so the fields it offers change per turn. |
| 6 |
export const updateDemoForm = { |
| 7 |
name: 'demo-form/update-fields', |
| 8 |
label: __('Filling in the form', 'extendify-local'), |
| 9 |
description: |
| 10 |
'Fill in the fields of the form step the user is on. Its fields are this tool’s inputs.', |
| 11 |
get inputSchema() { |
| 12 |
return activeCanvasStep().inputSchema ?? { type: 'object', properties: {} }; |
| 13 |
}, |
| 14 |
annotations: { readonly: false }, |
| 15 |
execute: (input = {}) => { |
| 16 |
useCanvasStore.getState().writeValues(input); |
| 17 |
return { values: useCanvasStore.getState().values }; |
| 18 |
}, |
| 19 |
}; |
| 20 |
|
| 21 |
export const nextDemoFormStep = { |
| 22 |
name: 'demo-form/next-step', |
| 23 |
label: __('Moving to the next step', 'extendify-local'), |
| 24 |
description: |
| 25 |
'Move the form on to its next step. Run this only when the user has asked to move on in so many words, never because the step looks finished.', |
| 26 |
inputSchema: { type: 'object', properties: {} }, |
| 27 |
annotations: { readonly: false }, |
| 28 |
execute: () => { |
| 29 |
const { activeStep, goToStep } = useCanvasStore.getState(); |
| 30 |
if (activeStep >= steps.length - 1) { |
| 31 |
return { |
| 32 |
moved: false, |
| 33 |
reason: 'This is the last step, so the user submits from here.', |
| 34 |
}; |
| 35 |
} |
| 36 |
goToStep(activeStep + 1); |
| 37 |
return { moved: true, step: steps[activeStep + 1].title }; |
| 38 |
}, |
| 39 |
}; |
| 40 |
|