@orangemust/dify-cli 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,65 +4,112 @@ A command-line interface for interacting with Dify applications.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@orangemust/dify-cli.svg)](https://www.npmjs.com/package/@orangemust/dify-cli)
6
6
 
7
+ ---
8
+
7
9
  ## Installation
8
10
 
9
- ```bash
10
- npm install -g @orangemust/dify-cli
11
+ ### For Humans
12
+
13
+ Copy and paste this prompt to your LLM agent (Claude Code, Cursor, Codex, etc.):
14
+
15
+ ```text
16
+ Install and configure dify-cli by following the instructions here:
17
+ https://raw.githubusercontent.com/mack-peng/dify-cli/main/docs/guide/installation.md
11
18
  ```
12
19
 
13
- Or link locally for development:
20
+ Or read the [Installation Guide](docs/guide/installation.md), but seriously, let an agent do it. Humans fat-finger configs.
21
+
22
+ ### For LLM Agents
23
+
24
+ Fetch the installation guide and follow it:
14
25
 
15
26
  ```bash
16
- cd dify-cli
17
- npm link
27
+ curl -s https://raw.githubusercontent.com/mack-peng/dify-cli/main/docs/guide/installation.md
18
28
  ```
19
29
 
30
+ ---
31
+
20
32
  ## Quick Start
21
33
 
22
- 1. Initialize configuration with your Dify API key:
34
+ ### Install
23
35
 
24
36
  ```bash
25
- dify-cli config init --api-key <your-api-key>
37
+ npm install -g @orangemust/dify-cli
38
+
39
+ # Or run without installing:
40
+ # npx @orangemust/dify-cli chat send "hello"
26
41
  ```
27
42
 
28
- 2. Send a message to a Chat app:
43
+ ### 1. Configure API Key
44
+
45
+ Dify 有两种 API Key,**互不通用**。配置哪个 key,后续命令就操作哪个资源。
29
46
 
30
47
  ```bash
31
- dify-cli chat send "Hello, how are you?"
48
+ # 操作应用(chat/completion/workflow)用 app- 开头的 key
49
+ dify-cli config init --api-key app-xxxx
50
+
51
+ # 操作知识库用 dataset- 开头的 key
52
+ dify-cli config init --api-key dataset-xxxx
53
+
54
+ # 自部署需指定 base-url
55
+ dify-cli config init --api-key app-xxxx --base-url https://dify.example.com/v1
32
56
  ```
33
57
 
34
- 3. List knowledge bases:
58
+ > 切换操作对象时重新 `config init`,或用 `--api-key` 临时覆盖:
59
+ > `dify-cli chat send "hello" --api-key app-xxxx`
60
+ > `dify-cli knowledge list --api-key dataset-xxxx`
61
+
62
+ ### 2. Try It
35
63
 
36
64
  ```bash
65
+ # 如果配了 app key
66
+ dify-cli info
67
+
68
+ # 如果配了 dataset key
37
69
  dify-cli knowledge list
38
70
  ```
39
71
 
40
- ## Configuration
72
+ ---
41
73
 
42
- Configuration is stored in `~/.dify/config.json`. You can manage it via:
74
+ ## API Keys
75
+
76
+ | Type | Prefix | Commands |
77
+ |------|--------|----------|
78
+ | App Key | `app-` | `info`, `chat`, `completion`, `chatflow`, `workflow`, `conversation`, `file`, `audio`, `feedback`, `annotation` |
79
+ | Dataset Key | `dataset-` | `knowledge` (datasets, documents, segments) |
80
+
81
+ Config file (`~/.dify/config.json`) holds one key at a time. Switch by re-running `config init` or override per-command with `--api-key`.
82
+
83
+ ---
84
+
85
+ ## Configuration
43
86
 
44
87
  ```bash
45
- # Initialize with all options
88
+ # Initialize
46
89
  dify-cli config init --api-key <key> --base-url <url> --default-user <user>
47
90
 
48
91
  # Set individual values
49
92
  dify-cli config set apiKey <key>
50
93
  dify-cli config set baseUrl https://api.dify.ai/v1
51
94
 
52
- # Get config values
95
+ # Get config
53
96
  dify-cli config get
54
97
  dify-cli config get apiKey
55
98
  ```
56
99
 
57
100
  Priority: CLI flags > Environment variables > Config file
58
101
 
59
- Environment variables:
60
- - `DIFY_API_KEY` - API key
61
- - `DIFY_BASE_URL` - API base URL (default: `https://api.dify.ai/v1`)
102
+ ```
103
+ DIFY_API_KEY API key
104
+ DIFY_BASE_URL API base URL (default: https://api.dify.ai/v1)
105
+ DIFY_DEFAULT_USER User identifier (default: cli-user)
106
+ ```
107
+
108
+ ---
62
109
 
63
110
  ## Commands
64
111
 
65
- ### App Information
112
+ ### App Info
66
113
 
67
114
  ```bash
68
115
  dify-cli info # Get app info
@@ -74,18 +121,18 @@ dify-cli site # Get WebApp settings
74
121
  ### Chat App
75
122
 
76
123
  ```bash
77
- dify-cli chat send "message" # Send message (blocking)
78
- dify-cli chat send "message" --mode streaming # Send message (streaming)
124
+ dify-cli chat send "message" # Blocking
125
+ dify-cli chat send "message" --mode streaming # Streaming
79
126
  dify-cli chat send "message" -c <conversation_id> # Continue conversation
80
127
  dify-cli chat stop <task_id> # Stop generation
81
- dify-cli chat feedback <message_id> -r like # Submit feedback
82
- dify-cli chat suggested <message_id> # Get suggested questions
128
+ dify-cli chat feedback <message_id> -r like # Feedback
129
+ dify-cli chat suggested <message_id> # Suggested questions
83
130
  ```
84
131
 
85
132
  ### Completion App
86
133
 
87
134
  ```bash
88
- dify-cli completion send "prompt" # Send prompt
135
+ dify-cli completion send "prompt"
89
136
  dify-cli completion send "prompt" --mode streaming
90
137
  dify-cli completion stop <task_id>
91
138
  ```
@@ -93,7 +140,7 @@ dify-cli completion stop <task_id>
93
140
  ### Chatflow App
94
141
 
95
142
  ```bash
96
- dify-cli chatflow send "message" # Send message
143
+ dify-cli chatflow send "message"
97
144
  dify-cli chatflow stop <task_id>
98
145
  dify-cli chatflow feedback <message_id> -r like
99
146
  ```
@@ -101,23 +148,23 @@ dify-cli chatflow feedback <message_id> -r like
101
148
  ### Workflow App
102
149
 
103
150
  ```bash
104
- dify-cli workflow run # Run workflow
151
+ dify-cli workflow run
105
152
  dify-cli workflow run --inputs '{"key":"value"}'
106
153
  dify-cli workflow stop <task_id>
107
- dify-cli workflow logs # List workflow logs
108
- dify-cli workflow detail <run_id> # Get run details
154
+ dify-cli workflow logs
155
+ dify-cli workflow detail <run_id>
109
156
  ```
110
157
 
111
158
  ### Knowledge Base
112
159
 
113
160
  ```bash
114
- dify-cli knowledge list # List knowledge bases
115
- dify-cli knowledge create "My Knowledge" # Create knowledge base
116
- dify-cli knowledge get <dataset_id> # Get details
161
+ dify-cli knowledge list
162
+ dify-cli knowledge create "My Knowledge"
163
+ dify-cli knowledge get <dataset_id>
117
164
  dify-cli knowledge update <dataset_id> --name "New Name"
118
165
  dify-cli knowledge delete <dataset_id>
119
166
 
120
- # Document operations
167
+ # Documents
121
168
  dify-cli knowledge document list <dataset_id>
122
169
  dify-cli knowledge document create-text <dataset_id> --name "Doc" --text "content"
123
170
  dify-cli knowledge document create-file <dataset_id> --file ./doc.pdf
@@ -125,35 +172,35 @@ dify-cli knowledge document get <dataset_id> <document_id>
125
172
  dify-cli knowledge document delete <dataset_id> <document_id>
126
173
  dify-cli knowledge document status <dataset_id> <batch>
127
174
 
128
- # Segment operations
175
+ # Segments
129
176
  dify-cli knowledge segment list <dataset_id> <document_id>
130
177
  dify-cli knowledge segment create <dataset_id> <document_id> --content "text"
131
178
  dify-cli knowledge segment update <dataset_id> <document_id> <segment_id> --content "text"
132
179
  dify-cli knowledge segment delete <dataset_id> <document_id> <segment_id>
133
180
  ```
134
181
 
135
- ### Conversation Management
182
+ ### Conversation
136
183
 
137
184
  ```bash
138
- dify-cli conversation list # List conversations
139
- dify-cli conversation get <conversation_id> # Get messages
185
+ dify-cli conversation list
186
+ dify-cli conversation get <conversation_id>
140
187
  dify-cli conversation rename <conversation_id> -n "New Name"
141
188
  dify-cli conversation delete <conversation_id>
142
189
  dify-cli conversation variables <conversation_id>
143
190
  ```
144
191
 
145
- ### File Operations
192
+ ### File
146
193
 
147
194
  ```bash
148
- dify-cli file upload <file_path> # Upload file
149
- dify-cli file preview <file_id> # Download file
195
+ dify-cli file upload <file_path>
196
+ dify-cli file preview <file_id>
150
197
  ```
151
198
 
152
- ### Audio Operations
199
+ ### Audio
153
200
 
154
201
  ```bash
155
- dify-cli audio to-text <audio_file> # Speech to text
156
- dify-cli audio to-audio "text to speak" # Text to speech
202
+ dify-cli audio to-text <audio_file>
203
+ dify-cli audio to-audio "text to speak"
157
204
  ```
158
205
 
159
206
  ### Feedback
@@ -169,32 +216,27 @@ dify-cli annotation create -q "question" -a "answer"
169
216
  dify-cli annotation list
170
217
  dify-cli annotation update <id> -q "new question" -a "new answer"
171
218
  dify-cli annotation delete <id>
172
- dify-cli annotation reply-config # Get reply config
219
+ dify-cli annotation reply-config
173
220
  ```
174
221
 
175
- ## Global Options
222
+ ---
176
223
 
177
- All commands support these global options:
224
+ ## Global Options
178
225
 
179
226
  ```
180
- --api-key <key> Dify API key (overrides config and env)
181
- --base-url <url> Dify API base URL
182
- --user <id> User identifier
227
+ --api-key <key> Override API key
228
+ --base-url <url> Override base URL
229
+ --user <id> User identifier (default: cli-user)
183
230
  ```
184
231
 
232
+ ---
233
+
185
234
  ## Development
186
235
 
187
236
  ```bash
188
- # Install dependencies
189
237
  npm install
190
-
191
- # Build
192
238
  npm run build
193
-
194
- # Watch mode
195
239
  npm run watch
196
-
197
- # Type check
198
240
  npx tsc --noEmit
199
241
  ```
200
242
 
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqD7D"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsD7D"}
@@ -11,13 +11,14 @@ function registerConfigCommands(program) {
11
11
  .option('--api-key <key>', 'Dify API key')
12
12
  .option('--base-url <url>', 'Dify API base URL (default: https://api.dify.ai/v1)')
13
13
  .option('--default-user <user>', 'Default user identifier')
14
- .action((options) => {
14
+ .action(function () {
15
+ const opts = this.optsWithGlobals();
15
16
  const cm = new config_1.ConfigManager();
16
17
  const existing = cm.getAll();
17
18
  cm.save({
18
- apiKey: options.apiKey || existing.apiKey,
19
- baseUrl: options.baseUrl || existing.baseUrl || 'https://api.dify.ai/v1',
20
- defaultUser: options.defaultUser || existing.defaultUser || 'cli-user',
19
+ apiKey: opts.apiKey || existing.apiKey,
20
+ baseUrl: opts.baseUrl || existing.baseUrl || 'https://api.dify.ai/v1',
21
+ defaultUser: opts.defaultUser || existing.defaultUser || 'cli-user',
21
22
  });
22
23
  console.log((0, output_1.formatOutput)({ message: 'Configuration saved', path: process.env.HOME + '/.dify/config.json' }));
23
24
  });
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":";;AAIA,wDAqDC;AAxDD,4CAAgD;AAChD,4CAA+C;AAE/C,SAAgB,sBAAsB,CAAC,OAAgB;IACrD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,+BAA+B,CAAC,CAAC;IAEtF,MAAM;SACH,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,iBAAiB,EAAE,cAAc,CAAC;SACzC,MAAM,CAAC,kBAAkB,EAAE,qDAAqD,CAAC;SACjF,MAAM,CAAC,uBAAuB,EAAE,yBAAyB,CAAC;SAC1D,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,EAAE,GAAG,IAAI,sBAAa,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;QAC7B,EAAE,CAAC,IAAI,CAAC;YACN,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM;YACzC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,IAAI,wBAAwB;YACxE,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,QAAQ,CAAC,WAAW,IAAI,UAAU;SACvE,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,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C9D,MAAM,CAAC,CAAC,GAAY,EAAE,EAAE;QACvB,MAAM,EAAE,GAAG,IAAI,sBAAa,EAAE,CAAC;QAC/B,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAU,CAAC,CAAC;YAC/B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,eAAe,GAAG,aAAa,CAAC,CAAC;gBAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,IAAA,qBAAY,EAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,IAAA,qBAAY,EAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orangemust/dify-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "CLI for interacting with Dify applications",
5
5
  "author": "mack-peng",
6
6
  "license": "MIT",