@orangemust/dify-cli 0.1.0 → 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
@@ -1,66 +1,115 @@
1
- # dify-cli
1
+ # @orangemust/dify-cli
2
2
 
3
3
  A command-line interface for interacting with Dify applications.
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@orangemust/dify-cli.svg)](https://www.npmjs.com/package/@orangemust/dify-cli)
6
+
7
+ ---
8
+
5
9
  ## Installation
6
10
 
7
- ```bash
8
- npm install -g 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
9
18
  ```
10
19
 
11
- 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:
12
25
 
13
26
  ```bash
14
- cd dify-cli
15
- npm link
27
+ curl -s https://raw.githubusercontent.com/mack-peng/dify-cli/main/docs/guide/installation.md
16
28
  ```
17
29
 
30
+ ---
31
+
18
32
  ## Quick Start
19
33
 
20
- 1. Initialize configuration with your Dify API key:
34
+ ### Install
21
35
 
22
36
  ```bash
23
- 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"
24
41
  ```
25
42
 
26
- 2. Send a message to a Chat app:
43
+ ### 1. Configure API Key
44
+
45
+ Dify 有两种 API Key,**互不通用**。配置哪个 key,后续命令就操作哪个资源。
27
46
 
28
47
  ```bash
29
- 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
30
56
  ```
31
57
 
32
- 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
33
63
 
34
64
  ```bash
65
+ # 如果配了 app key
66
+ dify-cli info
67
+
68
+ # 如果配了 dataset key
35
69
  dify-cli knowledge list
36
70
  ```
37
71
 
38
- ## Configuration
72
+ ---
39
73
 
40
- 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
41
86
 
42
87
  ```bash
43
- # Initialize with all options
88
+ # Initialize
44
89
  dify-cli config init --api-key <key> --base-url <url> --default-user <user>
45
90
 
46
91
  # Set individual values
47
92
  dify-cli config set apiKey <key>
48
93
  dify-cli config set baseUrl https://api.dify.ai/v1
49
94
 
50
- # Get config values
95
+ # Get config
51
96
  dify-cli config get
52
97
  dify-cli config get apiKey
53
98
  ```
54
99
 
55
100
  Priority: CLI flags > Environment variables > Config file
56
101
 
57
- Environment variables:
58
- - `DIFY_API_KEY` - API key
59
- - `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
+ ---
60
109
 
61
110
  ## Commands
62
111
 
63
- ### App Information
112
+ ### App Info
64
113
 
65
114
  ```bash
66
115
  dify-cli info # Get app info
@@ -72,18 +121,18 @@ dify-cli site # Get WebApp settings
72
121
  ### Chat App
73
122
 
74
123
  ```bash
75
- dify-cli chat send "message" # Send message (blocking)
76
- 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
77
126
  dify-cli chat send "message" -c <conversation_id> # Continue conversation
78
127
  dify-cli chat stop <task_id> # Stop generation
79
- dify-cli chat feedback <message_id> -r like # Submit feedback
80
- 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
81
130
  ```
82
131
 
83
132
  ### Completion App
84
133
 
85
134
  ```bash
86
- dify-cli completion send "prompt" # Send prompt
135
+ dify-cli completion send "prompt"
87
136
  dify-cli completion send "prompt" --mode streaming
88
137
  dify-cli completion stop <task_id>
89
138
  ```
@@ -91,7 +140,7 @@ dify-cli completion stop <task_id>
91
140
  ### Chatflow App
92
141
 
93
142
  ```bash
94
- dify-cli chatflow send "message" # Send message
143
+ dify-cli chatflow send "message"
95
144
  dify-cli chatflow stop <task_id>
96
145
  dify-cli chatflow feedback <message_id> -r like
97
146
  ```
@@ -99,23 +148,23 @@ dify-cli chatflow feedback <message_id> -r like
99
148
  ### Workflow App
100
149
 
101
150
  ```bash
102
- dify-cli workflow run # Run workflow
151
+ dify-cli workflow run
103
152
  dify-cli workflow run --inputs '{"key":"value"}'
104
153
  dify-cli workflow stop <task_id>
105
- dify-cli workflow logs # List workflow logs
106
- dify-cli workflow detail <run_id> # Get run details
154
+ dify-cli workflow logs
155
+ dify-cli workflow detail <run_id>
107
156
  ```
108
157
 
109
158
  ### Knowledge Base
110
159
 
111
160
  ```bash
112
- dify-cli knowledge list # List knowledge bases
113
- dify-cli knowledge create "My Knowledge" # Create knowledge base
114
- 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>
115
164
  dify-cli knowledge update <dataset_id> --name "New Name"
116
165
  dify-cli knowledge delete <dataset_id>
117
166
 
118
- # Document operations
167
+ # Documents
119
168
  dify-cli knowledge document list <dataset_id>
120
169
  dify-cli knowledge document create-text <dataset_id> --name "Doc" --text "content"
121
170
  dify-cli knowledge document create-file <dataset_id> --file ./doc.pdf
@@ -123,35 +172,35 @@ dify-cli knowledge document get <dataset_id> <document_id>
123
172
  dify-cli knowledge document delete <dataset_id> <document_id>
124
173
  dify-cli knowledge document status <dataset_id> <batch>
125
174
 
126
- # Segment operations
175
+ # Segments
127
176
  dify-cli knowledge segment list <dataset_id> <document_id>
128
177
  dify-cli knowledge segment create <dataset_id> <document_id> --content "text"
129
178
  dify-cli knowledge segment update <dataset_id> <document_id> <segment_id> --content "text"
130
179
  dify-cli knowledge segment delete <dataset_id> <document_id> <segment_id>
131
180
  ```
132
181
 
133
- ### Conversation Management
182
+ ### Conversation
134
183
 
135
184
  ```bash
136
- dify-cli conversation list # List conversations
137
- dify-cli conversation get <conversation_id> # Get messages
185
+ dify-cli conversation list
186
+ dify-cli conversation get <conversation_id>
138
187
  dify-cli conversation rename <conversation_id> -n "New Name"
139
188
  dify-cli conversation delete <conversation_id>
140
189
  dify-cli conversation variables <conversation_id>
141
190
  ```
142
191
 
143
- ### File Operations
192
+ ### File
144
193
 
145
194
  ```bash
146
- dify-cli file upload <file_path> # Upload file
147
- dify-cli file preview <file_id> # Download file
195
+ dify-cli file upload <file_path>
196
+ dify-cli file preview <file_id>
148
197
  ```
149
198
 
150
- ### Audio Operations
199
+ ### Audio
151
200
 
152
201
  ```bash
153
- dify-cli audio to-text <audio_file> # Speech to text
154
- 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"
155
204
  ```
156
205
 
157
206
  ### Feedback
@@ -167,32 +216,27 @@ dify-cli annotation create -q "question" -a "answer"
167
216
  dify-cli annotation list
168
217
  dify-cli annotation update <id> -q "new question" -a "new answer"
169
218
  dify-cli annotation delete <id>
170
- dify-cli annotation reply-config # Get reply config
219
+ dify-cli annotation reply-config
171
220
  ```
172
221
 
173
- ## Global Options
222
+ ---
174
223
 
175
- All commands support these global options:
224
+ ## Global Options
176
225
 
177
226
  ```
178
- --api-key <key> Dify API key (overrides config and env)
179
- --base-url <url> Dify API base URL
180
- --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)
181
230
  ```
182
231
 
232
+ ---
233
+
183
234
  ## Development
184
235
 
185
236
  ```bash
186
- # Install dependencies
187
237
  npm install
188
-
189
- # Build
190
238
  npm run build
191
-
192
- # Watch mode
193
239
  npm run watch
194
-
195
- # Type check
196
240
  npx tsc --noEmit
197
241
  ```
198
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,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CAAC,OAAO,EAAE,2CAA2C,CAAC;SAC9D,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.0",
3
+ "version": "0.1.3",
4
4
  "description": "CLI for interacting with Dify applications",
5
5
  "author": "mack-peng",
6
6
  "license": "MIT",