Phase 4 successfully integrated TypeScript workflow support into the skills package, enabling AI agents and CLI tools to work with both JSON and TypeScript workflow formats.
File: packages/skills/package.json
Added transformer dependency:
"dependencies": {
"@n8n-as-code/sync": "0.12.0",
"@n8n-as-code/transformer": "0.1.0",
"chalk": "^4.1.2",
"commander": "^11.1.0",
"flexsearch": "^0.8.212"
}File: packages/skills/src/services/workflow-validator.ts
Modified to validate both JSON and TypeScript workflows:
Before:
validateWorkflow(workflow: any): ValidationResultAfter:
async validateWorkflow(
workflowInput: any | string,
isTypeScript: boolean = false
): Promise<ValidationResult>Key Changes:
- Accepts either JSON object or TypeScript code string
- Compiles TypeScript to JSON before validation
- Reports compilation errors as validation errors
- Internal method
validateWorkflowJson()performs actual validation - Removed
WorkflowSanitizerimport, now usesTypeScriptParserandWorkflowBuilder
File: packages/skills/src/cli.ts
Updated to support both file formats:
Before:
.command('validate')
.description('Validate a workflow JSON file')
.argument('<file>', 'Path to workflow JSON file')After:
.command('validate')
.description('Validate a workflow file (JSON or TypeScript)')
.argument('<file>', 'Path to workflow file (.json or .workflow.ts)')Implementation:
- Auto-detects file type by extension (
.tsor.workflow.ts) - Async action handler for TypeScript compilation
- Passes appropriate format to validator
Usage Examples:
# Validate JSON workflow
n8nac skills validate my-workflow.json
# Validate TypeScript workflow
n8nac skills validate my-workflow.workflow.ts
# Strict mode treats warnings as errors
n8nac skills validate workflow.ts --strictFile: packages/skills/src/commands/workflows.ts
Added TypeScript conversion option:
New Options:
--typescript- Convert downloaded JSON to TypeScript format--json- Keep as JSON (default for backward compatibility)
Before:
.command('install <id>')
.description('Download a workflow JSON file')After:
.command('install <id>')
.description('Download a workflow file')
.option('--typescript', 'Convert to TypeScript format (.workflow.ts)')
.option('--json', 'Keep as JSON format (default unless --typescript)')Implementation:
- Downloads workflow JSON from registry
- Optionally converts to TypeScript using transformer pipeline
- Automatically sets file extension (
.jsonor.workflow.ts) - Shows conversion status message
Usage Examples:
# Download as JSON (default)
n8nac skills examples download 123
# Download and convert to TypeScript
n8nac skills examples download 123 --typescript
# Download to specific path
n8nac skills examples download 123 -o my-workflow.workflow.ts --typescript
# Force overwrite existing file
n8nac skills examples download 123 --typescript --forceFor JSON workflows:
JSON object → validateWorkflowJson() → ValidationResult
For TypeScript workflows:
TypeScript code → parseCode() → AST → build() → JSON → validateWorkflowJson() → ValidationResult
TypeScript compilation errors are captured and reported as validation errors:
{
valid: false,
errors: [{
type: 'error',
message: 'Failed to compile TypeScript workflow: Unexpected token @'
}],
warnings: []
}Fetch JSON → Parse → JsonToAstParser → AST → AstToTypeScriptGenerator → .workflow.ts
- ✅ All existing JSON workflows still work
- ✅ Default behavior unchanged (downloads as JSON)
- ✅ TypeScript support is opt-in via
--typescriptflag
- ✅ Validate TypeScript workflows before commit
- ✅ Download community workflows as TypeScript
- ✅ AI agents can now work with TypeScript format
- ✅ Better code review for complex workflows
npm run build -w @n8n-as-code/skills ✅- No TypeScript compilation errors
- Async methods properly typed
- Proper error handling for compilation failures
| Command | Description | New Features |
|---|---|---|
validate <file> |
Validate workflow | Supports .workflow.ts files |
examples download <id> |
Download workflow | --typescript flag for conversion |
# 1. Search for a workflow
n8nac skills examples search "email automation"
# 2. Get workflow details
n8nac skills examples info 42
# 3. Download as TypeScript
n8nac skills examples download 42 --typescript
# 4. Validate the downloaded workflow
n8nac skills validate email-automation.workflow.ts
# 5. Use in your n8n-as-code project
# (Sync package will now recognize .workflow.ts files)Phase 5: Adapt CLI commands:
n8nac sync- Already works via Phase 3 changes- Add
n8nac convert- Bidirectional JSON ↔ TypeScript conversion
Phase 6: Documentation and integration testing:
- Update README with TypeScript examples
- Create migration guide
- E2E tests for validator and workflows commands
- Example TypeScript workflows
The skills package now serves as a bridge between the n8n community (JSON workflows) and the n8n-as-code TypeScript ecosystem. Users can:
- Download community workflows in TypeScript format
- Validate TypeScript workflows before deployment
- Use AI agents to search and analyze workflows regardless of format
- Maintain consistency between local development (TypeScript) and n8n API (JSON)
This completes the skills package adaptation, making it fully compatible with the TypeScript workflow transformation introduced in Phases 1-3.