$npx -y skills add fusengine/agents --skill astro-actionsExpert Astro Server Actions — defineAction, astro:actions, Zod validation, ActionError, HTML form actions, accept form, progressive enhancement, redirect patterns. Use when handling form submissions, mutations, or any server-side logic with type safety.
| 1 | # Astro Actions Expert |
| 2 | |
| 3 | Type-safe server functions with automatic validation, standardized errors, and progressive enhancement. |
| 4 | |
| 5 | ## Agent Workflow (MANDATORY) |
| 6 | |
| 7 | Before ANY implementation, use `TeamCreate` to spawn 3 agents: |
| 8 | |
| 9 | 1. **fuse-ai-pilot:explore-codebase** - Check existing actions in `src/actions/` |
| 10 | 2. **fuse-ai-pilot:research-expert** - Verify latest Actions docs via Context7/Exa |
| 11 | 3. **mcp__context7__query-docs** - Get defineAction and ActionError examples |
| 12 | |
| 13 | After implementation, run **fuse-ai-pilot:sniper** for validation. |
| 14 | |
| 15 | --- |
| 16 | |
| 17 | ## Overview |
| 18 | |
| 19 | ### When to Use |
| 20 | |
| 21 | - Handling form submissions with server-side validation |
| 22 | - Creating type-safe backend mutations without API boilerplate |
| 23 | - Building progressive enhancement (works without JS) |
| 24 | - Replacing API endpoints for client-server communication |
| 25 | |
| 26 | ### Why Astro Actions |
| 27 | |
| 28 | | Feature | Benefit | |
| 29 | |---------|---------| |
| 30 | | `defineAction()` | Type-safe server function definition | |
| 31 | | Zod validation | Automatic JSON and FormData parsing | |
| 32 | | `ActionError` | Standardized error codes and messages | |
| 33 | | `accept: 'form'` | Direct HTML form submission support | |
| 34 | | Progressive enhancement | Works without JavaScript enabled | |
| 35 | | `astro:actions` | Client import for type-safe calls | |
| 36 | |
| 37 | --- |
| 38 | |
| 39 | ## Core Concepts |
| 40 | |
| 41 | ### Action Structure |
| 42 | |
| 43 | All actions live in `src/actions/index.ts` and export a `server` object: |
| 44 | |
| 45 | ```typescript |
| 46 | // src/actions/index.ts |
| 47 | import { defineAction } from 'astro:actions'; |
| 48 | import { z } from 'astro/zod'; |
| 49 | |
| 50 | export const server = { |
| 51 | myAction: defineAction({ /* ... */ }) |
| 52 | } |
| 53 | ``` |
| 54 | |
| 55 | ### Accept Modes |
| 56 | |
| 57 | | Mode | Description | |
| 58 | |------|-------------| |
| 59 | | `accept: 'json'` (default) | Parses JSON request body | |
| 60 | | `accept: 'form'` | Parses HTML FormData directly | |
| 61 | |
| 62 | ### Error Codes |
| 63 | |
| 64 | Standard HTTP-aligned codes: `UNAUTHORIZED`, `FORBIDDEN`, `NOT_FOUND`, `BAD_REQUEST`, `INTERNAL_SERVER_ERROR`, `CONFLICT`, `TOO_MANY_REQUESTS`. |
| 65 | |
| 66 | --- |
| 67 | |
| 68 | ## Reference Guide |
| 69 | |
| 70 | | Need | Reference | |
| 71 | |------|-----------| |
| 72 | | Concepts & architecture | [overview.md](references/overview.md) | |
| 73 | | defineAction patterns | [defining-actions.md](references/defining-actions.md) | |
| 74 | | ActionError handling | [error-handling.md](references/error-handling.md) | |
| 75 | | HTML form integration | [forms.md](references/forms.md) | |
| 76 | | Progressive enhancement | [progressive-enhancement.md](references/progressive-enhancement.md) | |
| 77 | | Contact form template | [templates/contact-form.md](references/templates/contact-form.md) | |
| 78 | | JSON action template | [templates/json-action.md](references/templates/json-action.md) | |
| 79 | |
| 80 | --- |
| 81 | |
| 82 | ## Best Practices |
| 83 | |
| 84 | 1. **Always define `input` schema** — Never skip Zod validation |
| 85 | 2. **Use `ActionError` for known errors** — Standardized codes for client handling |
| 86 | 3. **`accept: 'form'` for HTML forms** — Native form submission support |
| 87 | 4. **Progressive enhancement** — Form works without JS, enhanced with it |
| 88 | 5. **Check `ctx.cookies` for auth** — Throw `UNAUTHORIZED` when not logged in |