import { command, getRequestEvent } from '$app/server'; import { recordDecisionApiAdventuresAdventureIdDecisionsPost } from '@client'; import * as v from 'valibot'; const selectNextStepSchema = v.object({ adventureId: v.string(), possibleChoiceId: v.string() }); export const selectNextStep = command( selectNextStepSchema, async ({ adventureId, possibleChoiceId }) => { const { locals } = getRequestEvent(); const { error, response, data } = await recordDecisionApiAdventuresAdventureIdDecisionsPost({ headers: { Authorization: `Bearer ${locals.authToken}` }, path: { adventure_id: adventureId }, body: { choice_id: possibleChoiceId } }); if (error) { console.error('Error recording decision:', error); throw new Error('Failed to record decision'); } return data; } );