astro-actions
Expert 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.
What this skill does
# Astro Actions Expert
Type-safe server functions with automatic validation, standardized errors, and progressive enhancement.
## Agent Workflow (MANDATORY)
Before ANY implementation, use `TeamCreate` to spawn 3 agents:
1. **fuse-ai-pilot:explore-codebase** - Check existing actions in `src/actions/`
2. **fuse-ai-pilot:research-expert** - Verify latest Actions docs via Context7/Exa
3. **mcp__context7__query-docs** - Get defineAction and ActionError examples
After implementation, run **fuse-ai-pilot:sniper** for validation.
---
## Overview
### When to Use
- Handling form submissions with server-side validation
- Creating type-safe backend mutations without API boilerplate
- Building progressive enhancement (works without JS)
- Replacing API endpoints for client-server communication
### Why Astro Actions
| Feature | Benefit |
|---------|---------|
| `defineAction()` | Type-safe server function definition |
| Zod validation | Automatic JSON and FormData parsing |
| `ActionError` | Standardized error codes and messages |
| `accept: 'form'` | Direct HTML form submission support |
| Progressive enhancement | Works without JavaScript enabled |
| `astro:actions` | Client import for type-safe calls |
---
## Core Concepts
### Action Structure
All actions live in `src/actions/index.ts` and export a `server` object:
```typescript
// src/actions/index.ts
import { defineAction } from 'astro:actions';
import { z } from 'astro/zod';
export const server = {
myAction: defineAction({ /* ... */ })
}
```
### Accept Modes
| Mode | Description |
|------|-------------|
| `accept: 'json'` (default) | Parses JSON request body |
| `accept: 'form'` | Parses HTML FormData directly |
### Error Codes
Standard HTTP-aligned codes: `UNAUTHORIZED`, `FORBIDDEN`, `NOT_FOUND`, `BAD_REQUEST`, `INTERNAL_SERVER_ERROR`, `CONFLICT`, `TOO_MANY_REQUESTS`.
---
## Reference Guide
| Need | Reference |
|------|-----------|
| Concepts & architecture | [overview.md](references/overview.md) |
| defineAction patterns | [defining-actions.md](references/defining-actions.md) |
| ActionError handling | [error-handling.md](references/error-handling.md) |
| HTML form integration | [forms.md](references/forms.md) |
| Progressive enhancement | [progressive-enhancement.md](references/progressive-enhancement.md) |
| Contact form template | [templates/contact-form.md](references/templates/contact-form.md) |
| JSON action template | [templates/json-action.md](references/templates/json-action.md) |
---
## Best Practices
1. **Always define `input` schema** — Never skip Zod validation
2. **Use `ActionError` for known errors** — Standardized codes for client handling
3. **`accept: 'form'` for HTML forms** — Native form submission support
4. **Progressive enhancement** — Form works without JS, enhanced with it
5. **Check `ctx.cookies` for auth** — Throw `UNAUTHORIZED` when not logged in
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.