dify-cli
v1.2.0
Published
CLI tool to manage Dify workflows via DSL files
Readme
Dify CLI
CLI tool to manage Dify workflows via DSL files.
Features
- Update existing workflows with local DSL files
- Publish workflows to make them available via API
- Create new workflows from DSL templates
- List available workflow files
Installation
npm (Recommended)
Add to your project:
pnpm add dify-cli dotenv-cliCreate package.json scripts:
{
"scripts": {
"dify": "dotenv -e .env -- dify-cli",
"list": "dotenv -e .env -- dify-cli list",
"update": "dotenv -e .env -- dify-cli update",
"publish": "dotenv -e .env -- dify-cli publish",
"new": "dotenv -e .env -- dify-cli new"
}
}Configure .env:
DIFY_URL="https://dify.example.com"
DIFY_USER_EMAIL="[email protected]"
DIFY_USER_PASSWORD="your-password"
WORKFLOWS_DIR="./workflows"Run commands:
pnpm run list
pnpm run update <workflow-id>
pnpm run publish <workflow-id>
pnpm run new <name>Global Installation
npm install -g dify-cliDocker
# Clone the repository
git clone https://github.com/jimx7/dify-cli.git
cd dify-cli
# Configure credentials
cp .env.example .env
# Edit .env with your Dify credentials
# Build Docker image
docker compose build
# Run commands
docker compose run --rm dify-cli list
docker compose run --rm dify-cli update <workflow-id>
docker compose run --rm dify-cli publish <workflow-id>
docker compose run --rm dify-cli new <name>Configuration
Create .env file with your Dify credentials:
DIFY_URL="https://dify.example.com"
DIFY_USER_EMAIL="[email protected]"
DIFY_USER_PASSWORD="your-password"
WORKFLOWS_DIR="./workflows"Usage
Commands
| Command | Description |
|---------|-------------|
| list | List available workflow files |
| update <id> | Update existing workflow with DSL file |
| publish <id> | Publish workflow (make available via API) |
| new <name> | Create new workflow, rename file with returned ID |
Workflows Directory
DSL files are stored in workflows/ directory:
- Deployed workflows:
<name>_<workflow-id>.yml(with ID in filename) - New workflows:
<name>.yml(without ID, will be renamed after creation)
Example:
workflows/
├── document-assistant_00f0761f-43fc-4532-b160-407401f4e5f7.yml # deployed
└── new-workflow.yml # ready to createExamples
# List all workflows
pnpm run list
# Update an existing workflow
pnpm run update 00f0761f-43fc-4532-b160-407401f4e5f7
# Publish a workflow
pnpm run publish 00f0761f-43fc-4532-b160-407401f4e5f7
# Create a new workflow from template
# (First create workflows/my-chatbot.yml)
pnpm run new my-chatbotEnvironment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| DIFY_URL | Dify instance URL | - |
| DIFY_USER_EMAIL | Login email | - |
| DIFY_USER_PASSWORD | Login password | - |
| WORKFLOWS_DIR | Workflows directory path | ./workflows |
| NODE_TLS_REJECT_UNAUTHORIZED | SSL verification | 0 |
DSL File Format
Dify DSL files are YAML files that define workflow structure. Example:
app:
description: My Chatbot
icon: "\U0001F916"
icon_background: '#2563EB'
mode: advanced-chat
name: My Chatbot
kind: app
version: 0.5.0
workflow:
graph:
nodes:
- data:
type: start
title: User Input
id: start_node
- data:
type: llm
title: LLM
model:
name: gpt-4
provider: openai
prompt_template:
- role: system
text: You are a helpful assistant.
id: llm_node
- data:
type: answer
answer: '{{#llm_node.text#}}'
id: answer_node
edges:
- source: start_node
target: llm_node
- source: llm_node
target: answer_nodeLicense
MIT
