feat: Workflow integration — hooks, actions, and WDK adapter#1526
Draft
mrprkr wants to merge 1 commit intoThinkmill:mainfrom
Draft
feat: Workflow integration — hooks, actions, and WDK adapter#1526mrprkr wants to merge 1 commit intoThinkmill:mainfrom
mrprkr wants to merge 1 commit intoThinkmill:mainfrom
Conversation
|
72dce87 to
722fc2f
Compare
…dapter Add a hook/event system, manual action triggers, and a GitHub Actions workflow adapter to Keystatic, enabling developers to trigger automated workflows from the Keystatic dashboard when content is created, saved, or deleted. Core hook system (@keystatic/core): - Content lifecycle hooks: beforeCreate, afterCreate, beforeSave, afterSave, beforeDelete, afterDelete - Runtime registry: registerActions(), registerHooks(), registerGlobalHooks() for wiring workflows to collections/singletons - Hook executor: sequential before* (with cancel/modify), parallel after* (with error isolation) - Action buttons: dropdown menu (zap icon) in item/singleton toolbar - Toast notifications for hook execution and action results - Write-back support via update() on hook/action context GitHub Actions adapter (@keystatic/workflows): - useWorkflow(file, options): dispatch workflow_dispatch event, await result, show formatted toast - awaitWorkflow(file, options): dispatch and poll for completion, supports .then() chaining for before* hook cancellation - Communicates via API endpoint that calls GitHub REST API - String-based workflow refs (workflow YAML filenames) Example GitHub Actions workflows: - translate-post.yml: duplicate and translate a post - content-audit.yml: SEO, quality, and publishing readiness checks - generate-og-image.yml: render social preview images with @vercel/og - ai-content-assistant.yml: AI summary, title suggestions, tag generation using OpenAI Documentation: - docs/hooks.mdoc: lifecycle events, registration, cancellation, data modification, execution order - docs/actions.mdoc: registration, context, results, conditional visibility, UI placement - docs/workflows.mdoc: GitHub Actions integration, writing workflows, API endpoint setup, useWorkflow/awaitWorkflow adapters Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
722fc2f to
3b7ddf4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a hook/event system, manual action triggers, and a Workflow DevKit (WDK) adapter to Keystatic, enabling developers to wire durable workflows to content lifecycle events and dashboard UI buttons.
beforeCreate,afterCreate,beforeSave,afterSave,beforeDelete,afterDelete— registered viaregisterHooks()at runtimeregisterActions()@keystatic/workflows: Adapter package withuseWorkflow()andawaitWorkflow()that bridge Keystatic hooks/actions to WDK workflows via an API endpointregisterActions/registerHooks/registerGlobalHooksto avoid webpack stripping function properties from config objectsKey design decisions
before*hooks run sequentially and can cancel/modify operationsafter*hooks run in parallel (fire-and-forget) with error isolationNew packages/files
packages/keystatic/src/hooks/packages/keystatic/src/app/action-buttons.tsxpackages/keystatic/src/app/useActions.tspackages/keystatic/src/app/useHookExecutor.tspackages/keystatic-workflows/@keystatic/workflowsWDK adapter packagedocs/src/content/pages/hooks.mdocdocs/src/content/pages/actions.mdocdocs/src/content/pages/workflows.mdocModified files
packages/keystatic/src/config.tsx—hooksandactionson Collection, Singleton, Config typespackages/keystatic/src/app/updating.tsx— before/after hook integration in useUpsertItem/useDeleteItempackages/keystatic/src/app/ItemPage.tsx— action buttons in toolbarpackages/keystatic/src/app/SingletonPage.tsx— action buttons in toolbardocs/src/content/navigation.yaml— new nav entriesUsage example
Test plan
@keystatic/workflowsadapters