n8n-workflow-sdk
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "n8n-workflow-sdk":https://skillpi.com/zh/skills/deepskill-78c9ce1dfb17559e09feaa80316b109347307803e36110202053760870ab1e78。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用官方 TypeScript SDK 以编程方式构建 n8n 工作流。适用于通过代码创建 n8n 工作流、生成工作流 JSON、在 n8n JSON 与 TypeScript 之间转换,或将工作流创建集成到应用中的场景。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: n8n-workflow-sdk
description: >-
Build n8n workflows programmatically with the official TypeScript SDK.
Use when a user asks to create n8n workflows from code, generate workflow
JSON, build automation pipelines programmatically, convert between n8n
JSON and TypeScript, or integrate n8n workflow creation into applications.
license: Sustainable Use License
compatibility: 'Node.js 18+, TypeScript'
metadata:
author: terminal-skills
version: 1.0.0
category: automation
tags:
- n8n
- workflow
- automation
- sdk
- typescript
- ai
- langchainn8n Workflow SDK
Overview
@n8n/workflow-sdk is the official TypeScript SDK from n8n (v0.2.0, released February 2026) for programmatically creating, validating, and converting workflows. Instead of dragging nodes in the UI, define workflows as code — type-safe, version-controlled, and composable. Supports all n8n node types including AI/LangChain nodes. Includes bidirectional conversion between JSON and TypeScript.
Instructions
Step 1: Install and Create a Basic Workflow
npm install @n8n/workflow-sdk
// workflows/data-sync.ts — Programmatic workflow creation
import { WorkflowBuilder, manual, httpRequest, code } from '@n8n/workflow-sdk'
// Build a simple data sync workflow
const workflow = new WorkflowBuilder()
.withName('Daily Data Sync')
.addTrigger(manual())
.then(httpRequest({
url: 'https://api.example.com/users',
method: 'GET',
headers: {
Authorization: '={{ $env.API_KEY }}', // n8n expression for env variable
},
}))
.then(code({
language: 'typescript',
code: `
// Transform API response to internal format
return items.map(item => ({
json: {
id: item.json.id,
email: item.json.email,
name: \`\${item.json.firstName} \${item.json.lastName}\`,
active: item.json.status === 'active',
syncedAt: new Date().toISOString(),
}
}))
`,
}))
.build()
// workflow is now a valid n8n JSON object ready to import
console.log(JSON.stringify(workflow, null, 2))
Step 2: Control Flow — Branching and Merging
// workflows/lead-routing.ts — Conditional workflow with branches
import {
WorkflowBuilder, webhook, ifElse, merge,
httpRequest, node, sticky,
} from '@n8n/workflow-sdk'
const workflow = new WorkflowBuilder()
.withName('Lead Routing')
// Trigger on incoming webhook
.addTrigger(webhook({
path: 'new-lead',
method: 'POST',
responseMode: 'onReceived',
}))
// Branch based on lead score
.then(ifElse({
conditions: {
combinator: 'and',
conditions: [
{ leftValue: '={{ $json.score }}', operator: 'gte', rightValue: 80 },
],
},
}))
// True branch — high-value lead → Salesforce + Slack notification
.onTrue(
httpRequest({
url: 'https://mycompany.salesforce.com/api/leads',
method: 'POST',
body: '={{ JSON.stringify($json) }}',
})
)
// False branch — low-score lead → add to nurture campaign
.onFalse(
httpRequest({
url: 'https://api.mailchimp.com/3.0/lists/abc123/members',
method: 'POST',
body: '={{ JSON.stringify({ email_address: $json.email, status: "subscribed" }) }}',
})
)
// Add documentation
.addSticky(sticky({
content: '## Lead Routing\nHigh-score leads (≥80) go to Salesforce.\nOthers enter nurture campaign.',
width: 300,
height: 150,
}))
.build()
Step 3: AI/LangChain Workflows
// workflows/ai-support-agent.ts — AI agent with tools and memory
import {
WorkflowBuilder, webhook,
languageModel, memory, tool, outputParser,
node,
} from '@n8n/workflow-sdk'
const workflow = new WorkflowBuilder()
.withName('AI Support Agent')
.addTrigger(webhook({ path: 'support', method: 'POST' }))
// AI Agent node with LangChain components
.then(node('n8n-nodes-langchain.agent', {
text: '={{ $json.message }}',
systemMessage: `You are a helpful customer support agent for a SaaS product.
Use the available tools to look up account information and
knowledge base articles. Be concise and helpful.`,
}))
// Attach LLM
.withSub(languageModel('openAi', {
model: 'gpt-4o',
temperature: 0.3,
}))
// Attach conversation memory
.withSub(memory('windowBuffer', {
sessionKey: '={{ $json.userId }}',
windowSize: 20, // remember last 20 messages
}))
// Attach tools the agent can use
.withSub(tool('httpRequest', {
name: 'lookup_account',
description: 'Look up customer account by email or ID',
url: 'https://api.myapp.com/accounts/{{ $fromAi("query") }}',
method: 'GET',
}))
.withSub(tool('httpRequest', {
name: 'search_knowledge_base',
description: 'Search the knowledge base for help articles',
url: 'https://api.myapp.com/kb/search?q={{ $fromAi("query") }}',
method: 'GET',
}))
// Parse structured output
.then(outputParser('structured', {
schema: {
answer: { type: 'string', description: 'The response to the customer' },
category: { type: 'string', description: 'Issue category: billing, technical, general' },
escalate: { type: 'boolean', description: 'Whether to escalate to human agent' },
},
}))
.build()
Step 4: Batch Processing with Split and Merge
// workflows/bulk-enrichment.ts — Process records in batches
import {
WorkflowBuilder, schedule, httpRequest,
splitInBatches, merge, code, node,
} from '@n8n/workflow-sdk'
const workflow = new WorkflowBuilder()
.withName('Contact Enrichment Pipeline')
// Run every night at 2 AM
.addTrigger(schedule({ rule: { interval: [{ field: 'hours', triggerAtHour: 2 }] } }))
// Fetch contacts that need enrichment
.then(httpRequest({
url: 'https://api.myapp.com/contacts?needs_enrichment=true&limit=500',
method: 'GET',
}))
// Process in batches of 50 to respect API rate limits
.then(splitInBatches({ batchSize: 50 }))
// Enrich each contact via Clearbit
.then(httpRequest({
url: 'https://person.clearbit.com/v2/people/find',
method: 'GET',
queryParameters: { email: '={{ $json.email }}' },
headers: { Authorization: '={{ $env.CLEARBIT_KEY }}' },
options: { batching: { batch: { batchSize: 10, batchInterval: 1000 } } },
}))
// Transform and save
.then(code({
language: 'typescript',
code: `
return items.map(item => ({
json: {
contactId: item.json.contactId,
company: item.json.company?.name,
title: item.json.title,
linkedIn: item.json.linkedin?.handle,
enrichedAt: new Date().toISOString(),
}
}))
`,
}))
.then(httpRequest({
url: 'https://api.myapp.com/contacts/bulk-update',
method: 'PATCH',
body: '={{ JSON.stringify($json) }}',
}))
.build()
Step 5: Convert Between JSON and TypeScript
// tools/convert.ts — Bidirectional workflow conversion
import {
generateWorkflowCode,
parseWorkflowCode,
validateWorkflow,
} from '@n8n/workflow-sdk'
// JSON → TypeScript (import existing workflows as code)
const existingWorkflowJson = require('./exported-workflow.json')
const tsCode = generateWorkflowCode(existingWorkflowJson)
console.log(tsCode)
// Outputs clean TypeScript using WorkflowBuilder API
// TypeScript → JSON (deploy code-defined workflows)
const workflowJson = parseWorkflowCode(tsCode)
console.log(JSON.stringify(workflowJson, null, 2))
// Outputs valid n8n JSON ready for import
// Validate before deploying
const errors = validateWorkflow(workflowJson)
if (errors.length > 0) {
console.error('Validation errors:', errors)
process.exit(1)
}
console.log('Workflow is valid ✓')
Step 6: Deploy Workflows via n8n API
// deploy.ts — Push SDK-built workflows to n8n instance
import { WorkflowBuilder } from '@n8n/workflow-sdk'
async function deployWorkflow(workflow: ReturnType<WorkflowBuilder['build']>) {
const response = await fetch(`${process.env.N8N_URL}/api/v1/workflows`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-N8N-API-KEY': process.env.N8N_API_KEY!,
},
body: JSON.stringify(workflow),
})
const result = await response.json()
console.log(`Deployed: ${result.name} (ID: ${result.id})`)
// Activate the workflow
await fetch(`${process.env.N8N_URL}/api/v1/workflows/${result.id}/activate`, {
method: 'PATCH',
headers: { 'X-N8N-API-KEY': process.env.N8N_API_KEY! },
})
console.log(`Activated: ${result.name}`)
return result.id
}
// Deploy all workflows from code
const workflows = [
require('./workflows/data-sync'),
require('./workflows/lead-routing'),
require('./workflows/ai-support-agent'),
]
for (const wf of workflows) {
await deployWorkflow(wf)
}
Guidelines
@n8n/workflow-sdkv0.2.0 is an early release (Feb 2026) — API may evolve. Pin the version.- Use
generateWorkflowCode()to migrate existing JSON workflows to code — great for version control. validateWorkflow()catches node configuration errors before deployment — use in CI.- n8n expressions (
={{ }}) work in all string parameters — reference previous node data with$json,$env,$fromAi(). - AI/LangChain nodes use
.withSub()to attach language models, memory, and tools to agent nodes. - The SDK outputs standard n8n JSON — deploy via the n8n REST API or import through the UI.
- License is Sustainable Use (n8n proprietary), not open source — check terms for your use case.
- For workflow-as-code patterns: keep workflows in a
workflows/directory, validate in CI, deploy with a script.
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的 n8n TypeScript SDK 编程式创建工作流方案
- 覆盖多种实际场景:数据同步、条件分支、AI代理、批量处理等
- 解决用户通过代码生成自动化工作流的明确需求
亮点
- 触发词精准完整,description 明确覆盖多种变体场景
- 边界清晰,准确描述适用场景
亮点
- Phase/步骤清晰,有完整示例
- frontmatter完整,结构良好
- 单文件内容组织合理
亮点
- 工具来源明确,参数正确
- 覆盖主要异常,有验证机制
- 包含部署和错误处理示例
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 35 行 -
账号、密钥或授权
使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。
主文档提及 · 第 50, 291, 302 行
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- api.example.com
- api.mailchimp.com
- api.myapp.com
- mycompany.salesforce.com
- person.clearbit.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。