@mintplex-labs/anything-llm-cli 0.0.5 → 0.0.6
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 +49 -187
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AnythingLLM CLI
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A command-line interface for chatting with your [AnythingLLM](https://anythingllm.com) instance from the terminal.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
╔════════════════════════════════════════════════════════════════╗
|
|
@@ -32,12 +32,6 @@ curl -fsSL https://raw.githubusercontent.com/Mintplex-Labs/anything-llm-cli/main
|
|
|
32
32
|
|
|
33
33
|
This detects your platform, downloads the latest binary, and installs it to `/usr/local/bin`. Run it again to update.
|
|
34
34
|
|
|
35
|
-
To uninstall:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
sudo rm /usr/local/bin/any
|
|
39
|
-
```
|
|
40
|
-
|
|
41
35
|
### Via package manager
|
|
42
36
|
|
|
43
37
|
```bash
|
|
@@ -50,11 +44,9 @@ pnpm add -g @mintplex-labs/anything-llm-cli
|
|
|
50
44
|
bun install -g @mintplex-labs/anything-llm-cli
|
|
51
45
|
```
|
|
52
46
|
|
|
53
|
-
This installs the `any` command globally.
|
|
54
|
-
|
|
55
47
|
### Standalone binary
|
|
56
48
|
|
|
57
|
-
Download a prebuilt binary
|
|
49
|
+
Download a prebuilt binary from the [Releases](https://github.com/mintplex-labs/anything-llm-cli/releases) page and place it somewhere on your `PATH`.
|
|
58
50
|
|
|
59
51
|
| Platform | Binary |
|
|
60
52
|
| ----------- | --------------------- |
|
|
@@ -64,48 +56,27 @@ Download a prebuilt binary for your platform from the [Releases](https://github.
|
|
|
64
56
|
| Linux ARM | `any-linux-arm64` |
|
|
65
57
|
| Windows x64 | `any-windows-x64.exe` |
|
|
66
58
|
|
|
67
|
-
|
|
59
|
+
## Quickstart
|
|
68
60
|
|
|
69
|
-
|
|
61
|
+
1. **Get your API key** from your AnythingLLM instance under **Settings > Developer API**.
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
git clone https://github.com/mintplex-labs/anything-llm-cli.git
|
|
73
|
-
cd anything-llm-cli
|
|
74
|
-
bun run setup
|
|
75
|
-
```
|
|
63
|
+
2. **Set your environment variables:**
|
|
76
64
|
|
|
77
|
-
|
|
65
|
+
```bash
|
|
66
|
+
export ANYTHING_LLM_API_KEY="your-api-key"
|
|
67
|
+
# Optional — defaults to http://localhost:3001
|
|
68
|
+
export ANYTHING_LLM_BASE_URL="https://my-instance.example.com"
|
|
69
|
+
```
|
|
78
70
|
|
|
79
|
-
|
|
71
|
+
> **Tip:** Add these to your `.bashrc` or `.zshrc` for persistence.
|
|
80
72
|
|
|
81
|
-
|
|
82
|
-
bun run start prompt "Hello!"
|
|
83
|
-
```
|
|
73
|
+
3. **Send your first prompt:**
|
|
84
74
|
|
|
85
|
-
|
|
75
|
+
```bash
|
|
76
|
+
any prompt "What is AnythingLLM?"
|
|
77
|
+
```
|
|
86
78
|
|
|
87
|
-
|
|
88
|
-
bun run build
|
|
89
|
-
./dist/any prompt "Hello!"
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Setup
|
|
93
|
-
|
|
94
|
-
The only required setup is your API key. You can generate one from your AnythingLLM instance under **Settings > Developer API**.
|
|
95
|
-
|
|
96
|
-
If running from source, fill in your `.env.local` file — Bun loads it automatically.
|
|
97
|
-
|
|
98
|
-
For the npm package or standalone binary, set environment variables directly:
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
export ANYTHING_LLM_API_KEY="your-api-key"
|
|
102
|
-
export ANYTHING_LLM_BASE_URL="https://my-instance.example.com" # optional, default: http://localhost:3001
|
|
103
|
-
export ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG="my-workspace" # optional, avoids needing -w
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
If no workspace is specified via `-w` or the environment variable, the CLI will automatically create and use a default workspace.
|
|
107
|
-
|
|
108
|
-
> **Tip:** Add these to your `.bashrc`, `.zshrc`, or `.env` file for persistence.
|
|
79
|
+
That's it! If no workspace is specified, the CLI will automatically create and use a default one.
|
|
109
80
|
|
|
110
81
|
## Usage
|
|
111
82
|
|
|
@@ -113,15 +84,7 @@ If no workspace is specified via `-w` or the environment variable, the CLI will
|
|
|
113
84
|
any prompt <message> [options]
|
|
114
85
|
```
|
|
115
86
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
### Commands
|
|
119
|
-
|
|
120
|
-
| Command | Alias | Description |
|
|
121
|
-
| --------------------- | ----- | ------------------------ |
|
|
122
|
-
| `prompt <message...>` | `p` | Send a prompt to the LLM |
|
|
123
|
-
|
|
124
|
-
### Options (for `prompt`)
|
|
87
|
+
### Options
|
|
125
88
|
|
|
126
89
|
| Flag | Description |
|
|
127
90
|
| ------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
@@ -131,162 +94,61 @@ Running `any` with no arguments displays the help screen.
|
|
|
131
94
|
| `--nt, --new-thread` | Start a new thread for this conversation |
|
|
132
95
|
| `-S, --no-stream` | Disable streaming (wait for full response) |
|
|
133
96
|
|
|
134
|
-
#### Supported attachment types
|
|
135
|
-
|
|
136
|
-
`png`, `jpg`, `jpeg`, `gif`, `webp`
|
|
137
|
-
|
|
138
97
|
### Examples
|
|
139
98
|
|
|
140
|
-
**Simple prompt:**
|
|
141
|
-
|
|
142
|
-
```bash
|
|
143
|
-
any prompt "What is AnythingLLM?"
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Multi-word prompts without quotes:**
|
|
147
|
-
|
|
148
99
|
```bash
|
|
100
|
+
# Simple prompt (quotes optional)
|
|
149
101
|
any prompt What is AnythingLLM
|
|
150
|
-
```
|
|
151
102
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
any p "What is AnythingLLM?"
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
**Pipe in context from another command:**
|
|
159
|
-
|
|
160
|
-
```bash
|
|
103
|
+
# Pipe in context
|
|
161
104
|
cat error.log | any prompt "Explain these errors"
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
```bash
|
|
165
105
|
git diff | any prompt "Write a commit message for these changes"
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
curl -s https://api.example.com/data | any prompt "Summarize this JSON"
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
**Use a specific thread for ongoing conversations:**
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
any prompt "Let's continue our discussion" -t thread-slug
|
|
176
|
-
```
|
|
177
106
|
|
|
178
|
-
|
|
107
|
+
# Use a specific workspace
|
|
108
|
+
any prompt "Hello" -w my-workspace
|
|
179
109
|
|
|
180
|
-
|
|
181
|
-
any prompt "
|
|
182
|
-
|
|
110
|
+
# Threads for ongoing conversations
|
|
111
|
+
any prompt "Let's talk about testing" --new-thread
|
|
112
|
+
any prompt "Continue where we left off" -t thread-slug
|
|
183
113
|
|
|
184
|
-
|
|
114
|
+
# Attach images
|
|
115
|
+
any prompt "What's in this image?" -a ./photo.png
|
|
185
116
|
|
|
186
|
-
|
|
117
|
+
# Scripting (no streaming, capture output)
|
|
187
118
|
RESULT=$(any prompt "Give me a one-word answer: yes or no?" -S)
|
|
188
|
-
echo "The LLM said: $RESULT"
|
|
189
|
-
```
|
|
190
119
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
any prompt "Write a summary of AnythingLLM" > summary.md
|
|
120
|
+
# Save response to a file
|
|
121
|
+
any prompt "Write a summary" > summary.md
|
|
195
122
|
```
|
|
196
123
|
|
|
197
|
-
> When piped
|
|
198
|
-
|
|
199
|
-
**Attach images:**
|
|
124
|
+
> When piped or redirected, ANSI formatting is automatically stripped for clean plaintext output. Agent workspaces with tools (web browsing, scraping, etc.) are fully supported.
|
|
200
125
|
|
|
201
|
-
|
|
202
|
-
any prompt "What's in this image?" -a ./photo.png
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
any prompt "Compare these images" -a image1.png image2.jpg
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
**Agent workspaces:**
|
|
210
|
-
|
|
211
|
-
Agent workspaces that use tools (web browsing, scraping, etc.) are fully supported. In the terminal, tool call assembly updates in place and agent thoughts are dimmed for readability. When piped to a file, output is clean plaintext.
|
|
212
|
-
|
|
213
|
-
## TypeScript SDK
|
|
214
|
-
|
|
215
|
-
The project also includes a fully-typed TypeScript SDK (`AnythingLLM` class) that you can use programmatically:
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
import { AnythingLLM } from "./src/sdk";
|
|
219
|
-
|
|
220
|
-
const client = new AnythingLLM({
|
|
221
|
-
apiKey: "your-api-key",
|
|
222
|
-
baseUrl: "http://localhost:3001",
|
|
223
|
-
});
|
|
126
|
+
## Environment Variables
|
|
224
127
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
128
|
+
| Variable | Required | Default | Description |
|
|
129
|
+
| ------------------------------------- | -------- | ----------------------- | ------------------------------------------------- |
|
|
130
|
+
| `ANYTHING_LLM_API_KEY` | Yes | — | Your AnythingLLM API key |
|
|
131
|
+
| `ANYTHING_LLM_BASE_URL` | No | `http://localhost:3001` | Base URL of your AnythingLLM instance |
|
|
132
|
+
| `ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG` | No | — | Default workspace slug (avoids needing `-w` flag) |
|
|
230
133
|
|
|
231
|
-
|
|
232
|
-
console.log(result.data.textResponse);
|
|
233
|
-
}
|
|
134
|
+
## Development
|
|
234
135
|
|
|
235
|
-
|
|
236
|
-
const stream = client.workspaces.streamChat({
|
|
237
|
-
slug: "my-workspace",
|
|
238
|
-
message: "Tell me a story",
|
|
239
|
-
mode: "chat",
|
|
240
|
-
});
|
|
136
|
+
Requires [Bun](https://bun.sh).
|
|
241
137
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
138
|
+
```bash
|
|
139
|
+
git clone https://github.com/mintplex-labs/anything-llm-cli.git
|
|
140
|
+
cd anything-llm-cli
|
|
141
|
+
bun run setup # Install deps + create .env.local
|
|
142
|
+
bun run start prompt "Hello!" # Run in development
|
|
143
|
+
bun run build # Compile native binary → dist/any
|
|
247
144
|
```
|
|
248
145
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
| Method | Description |
|
|
252
|
-
| ------------------------------------------------------------ | ------------------------------------------ |
|
|
253
|
-
| `workspaces.list()` | List all workspaces |
|
|
254
|
-
| `workspaces.get({ slug })` | Get a workspace by slug |
|
|
255
|
-
| `workspaces.create({ name, ... })` | Create a new workspace |
|
|
256
|
-
| `workspaces.chat({ slug, message })` | Send a message and get a complete response |
|
|
257
|
-
| `workspaces.streamChat({ slug, message })` | Stream a response as SSE chunks |
|
|
258
|
-
| `threads.create({ workspaceSlug, title })` | Create a new thread in a workspace |
|
|
259
|
-
| `threads.chat({ workspaceSlug, threadSlug, message })` | Chat within a thread |
|
|
260
|
-
| `threads.streamChat({ workspaceSlug, threadSlug, message })` | Stream a response within a thread |
|
|
261
|
-
| `threads.getMessages({ workspaceSlug, threadSlug? })` | Get chat history |
|
|
262
|
-
|
|
263
|
-
## Development
|
|
146
|
+
## Uninstall
|
|
264
147
|
|
|
265
148
|
```bash
|
|
266
|
-
#
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
# Run in development
|
|
270
|
-
bun run start
|
|
271
|
-
|
|
272
|
-
# Lint and format
|
|
273
|
-
bun run lint
|
|
274
|
-
|
|
275
|
-
# Build for current platform
|
|
276
|
-
bun run build
|
|
149
|
+
# If installed via install script
|
|
150
|
+
sudo rm /usr/local/bin/any
|
|
277
151
|
|
|
278
|
-
#
|
|
279
|
-
|
|
152
|
+
# If installed via package manager
|
|
153
|
+
npm uninstall -g @mintplex-labs/anything-llm-cli
|
|
280
154
|
```
|
|
281
|
-
|
|
282
|
-
## Environment Variables
|
|
283
|
-
|
|
284
|
-
| Variable | Required | Default | Description |
|
|
285
|
-
| ------------------------------------- | -------- | ----------------------- | ------------------------------------------------- |
|
|
286
|
-
| `ANYTHING_LLM_API_KEY` | Yes | — | Your AnythingLLM API key |
|
|
287
|
-
| `ANYTHING_LLM_BASE_URL` | No | `http://localhost:3001` | Base URL of your AnythingLLM instance |
|
|
288
|
-
| `ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG` | No | — | Default workspace slug (avoids needing `-w` flag) |
|
|
289
|
-
|
|
290
|
-
## License
|
|
291
|
-
|
|
292
|
-
[MIT](LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ Expecting one of '${J.join("', '")}'`);if(this._lifeCycleHooks[q])this._lifeCycl
|
|
|
24
24
|
`),this.outputHelp({error:!0});let J=z||{},Q=J.exitCode||1,X=J.code||"commander.error";this._exit(Q,X,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in T.env){let z=q.attributeName();if(this.getOptionValue(z)===void 0||["default","config","env"].includes(this.getOptionValueSource(z)))if(q.required||q.optional)this.emit(`optionEnv:${q.name()}`,T.env[q.envVar]);else this.emit(`optionEnv:${q.name()}`)}})}_parseOptionsImplied(){let q=new s4(this.options),z=(J)=>{return this.getOptionValue(J)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(J))};this.options.filter((J)=>J.implied!==void 0&&z(J.attributeName())&&q.valueFromOption(this.getOptionValue(J.attributeName()),J)).forEach((J)=>{Object.keys(J.implied).filter((Q)=>!z(Q)).forEach((Q)=>{this.setOptionValueWithSource(Q,J.implied[Q],"implied")})})}missingArgument(q){let z=`error: missing required argument '${q}'`;this.error(z,{code:"commander.missingArgument"})}optionMissingArgument(q){let z=`error: option '${q.flags}' argument missing`;this.error(z,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(q){let z=`error: required option '${q.flags}' not specified`;this.error(z,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(q,z){let J=(Z)=>{let $=Z.attributeName(),_=this.getOptionValue($),G=this.options.find((B)=>B.negate&&$===B.attributeName()),Y=this.options.find((B)=>!B.negate&&$===B.attributeName());if(G&&(G.presetArg===void 0&&_===!1||G.presetArg!==void 0&&_===G.presetArg))return G;return Y||Z},Q=(Z)=>{let $=J(Z),_=$.attributeName();if(this.getOptionValueSource(_)==="env")return`environment variable '${$.envVar}'`;return`option '${$.flags}'`},X=`error: ${Q(q)} cannot be used with ${Q(z)}`;this.error(X,{code:"commander.conflictingOption"})}unknownOption(q){if(this._allowUnknownOption)return;let z="";if(q.startsWith("--")&&this._showSuggestionAfterError){let Q=[],X=this;do{let Z=X.createHelp().visibleOptions(X).filter(($)=>$.long).map(($)=>$.long);Q=Q.concat(Z),X=X.parent}while(X&&!X._enablePositionalOptions);z=J4(q,Q)}let J=`error: unknown option '${q}'${z}`;this.error(J,{code:"commander.unknownOption"})}_excessArguments(q){if(this._allowExcessArguments)return;let z=this.registeredArguments.length,J=z===1?"":"s",X=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${z} argument${J} but got ${q.length}.`;this.error(X,{code:"commander.excessArguments"})}unknownCommand(){let q=this.args[0],z="";if(this._showSuggestionAfterError){let Q=[];this.createHelp().visibleCommands(this).forEach((X)=>{if(Q.push(X.name()),X.alias())Q.push(X.alias())}),z=J4(q,Q)}let J=`error: unknown command '${q}'${z}`;this.error(J,{code:"commander.unknownCommand"})}version(q,z,J){if(q===void 0)return this._version;this._version=q,z=z||"-V, --version",J=J||"output the version number";let Q=this.createOption(z,J);return this._versionOptionName=Q.attributeName(),this._registerOption(Q),this.on("option:"+Q.name(),()=>{this._outputConfiguration.writeOut(`${q}
|
|
25
25
|
`),this._exit(0,"commander.version",q)}),this}description(q,z){if(q===void 0&&z===void 0)return this._description;if(this._description=q,z)this._argsDescription=z;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let z=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)z=this.commands[this.commands.length-1];if(q===z._name)throw Error("Command alias can't be the same as its name");let J=this.parent?._findCommand(q);if(J){let Q=[J.name()].concat(J.aliases()).join("|");throw Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${Q}'`)}return z._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach((z)=>this.alias(z)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let z=this.registeredArguments.map((J)=>{return m4(J)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?z:[]).join(" ")}return this._usage=q,this}name(q){if(q===void 0)return this._name;return this._name=q,this}helpGroup(q){if(q===void 0)return this._helpGroupHeading??"";return this._helpGroupHeading=q,this}commandsGroup(q){if(q===void 0)return this._defaultCommandGroup??"";return this._defaultCommandGroup=q,this}optionsGroup(q){if(q===void 0)return this._defaultOptionGroup??"";return this._defaultOptionGroup=q,this}_initOptionGroup(q){if(this._defaultOptionGroup&&!q.helpGroupHeading)q.helpGroup(this._defaultOptionGroup)}_initCommandGroup(q){if(this._defaultCommandGroup&&!q.helpGroup())q.helpGroup(this._defaultCommandGroup)}nameFromFilename(q){return this._name=P.basename(q,P.extname(q)),this}executableDir(q){if(q===void 0)return this._executableDir;return this._executableDir=q,this}helpInformation(q){let z=this.createHelp(),J=this._getOutputContext(q);z.prepareContext({error:J.error,helpWidth:J.helpWidth,outputHasColors:J.hasColors});let Q=z.formatHelp(this,z);if(J.hasColors)return Q;return this._outputConfiguration.stripColor(Q)}_getOutputContext(q){q=q||{};let z=!!q.error,J,Q,X;if(z)J=($)=>this._outputConfiguration.writeErr($),Q=this._outputConfiguration.getErrHasColors(),X=this._outputConfiguration.getErrHelpWidth();else J=($)=>this._outputConfiguration.writeOut($),Q=this._outputConfiguration.getOutHasColors(),X=this._outputConfiguration.getOutHelpWidth();return{error:z,write:($)=>{if(!Q)$=this._outputConfiguration.stripColor($);return J($)},hasColors:Q,helpWidth:X}}outputHelp(q){let z;if(typeof q==="function")z=q,q=void 0;let J=this._getOutputContext(q),Q={error:J.error,write:J.write,command:this};this._getCommandAndAncestors().reverse().forEach((Z)=>Z.emit("beforeAllHelp",Q)),this.emit("beforeHelp",Q);let X=this.helpInformation({error:J.error});if(z){if(X=z(X),typeof X!=="string"&&!Buffer.isBuffer(X))throw Error("outputHelp callback must return a string or a Buffer")}if(J.write(X),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",Q),this._getCommandAndAncestors().forEach((Z)=>Z.emit("afterAllHelp",Q))}helpOption(q,z){if(typeof q==="boolean"){if(q){if(this._helpOption===null)this._helpOption=void 0;if(this._defaultOptionGroup)this._initOptionGroup(this._getHelpOption())}else this._helpOption=null;return this}if(this._helpOption=this.createOption(q??"-h, --help",z??"display help for command"),q||z)this._initOptionGroup(this._helpOption);return this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(q){return this._helpOption=q,this._initOptionGroup(q),this}help(q){this.outputHelp(q);let z=Number(T.exitCode??0);if(z===0&&q&&typeof q!=="function"&&q.error)z=1;this._exit(z,"commander.help","(outputHelp)")}addHelpText(q,z){let J=["beforeAll","before","after","afterAll"];if(!J.includes(q))throw Error(`Unexpected value for position to addHelpText.
|
|
26
26
|
Expecting one of '${J.join("', '")}'`);let Q=`${q}Help`;return this.on(Q,(X)=>{let Z;if(typeof z==="function")Z=z({error:X.error,command:X.command});else Z=z;if(Z)X.write(`${Z}
|
|
27
|
-
`)}),this}_outputHelpIfRequested(q){let z=this._getHelpOption();if(z&&q.find((Q)=>z.is(Q)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function Q4(q){return q.map((z)=>{if(!z.startsWith("--inspect"))return z;let J,Q="127.0.0.1",X="9229",Z;if((Z=z.match(/^(--inspect(-brk)?)$/))!==null)J=Z[1];else if((Z=z.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(J=Z[1],/^\d+$/.test(Z[3]))X=Z[3];else Q=Z[3];else if((Z=z.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)J=Z[1],Q=Z[3],X=Z[4];if(J&&X!=="0")return`${J}=${Q}:${parseInt(X)+1}`;return z})}function c(){if(T.env.NO_COLOR||T.env.FORCE_COLOR==="0"||T.env.FORCE_COLOR==="false")return!1;if(T.env.FORCE_COLOR||T.env.CLICOLOR_FORCE!==void 0)return!0;return}n4.Command=d;n4.useColor=c});var Y4=D((e4)=>{var{Argument:Z4}=k(),{Command:l}=X4(),{CommanderError:a4,InvalidArgumentError:$4}=A(),{Help:o4}=v(),{Option:_4}=h();e4.program=new l;e4.createCommand=(q)=>new l(q);e4.createOption=(q,z)=>new _4(q,z);e4.createArgument=(q,z)=>new Z4(q,z);e4.Command=l;e4.Option=_4;e4.Argument=Z4;e4.Help=o4;e4.CommanderError=a4;e4.InvalidArgumentError=$4;e4.InvalidOptionArgumentError=$4});var B4=I4(Y4(),1),{program:w,createCommand:F6,createArgument:y6,createOption:A6,CommanderError:w6,InvalidArgumentError:C6,InvalidOptionArgumentError:k6,Command:x6,Argument:O6,Option:b6,Help:f6}=B4.default;var O={name:"@mintplex-labs/anything-llm-cli",version:"0.0.
|
|
27
|
+
`)}),this}_outputHelpIfRequested(q){let z=this._getHelpOption();if(z&&q.find((Q)=>z.is(Q)))this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)")}}function Q4(q){return q.map((z)=>{if(!z.startsWith("--inspect"))return z;let J,Q="127.0.0.1",X="9229",Z;if((Z=z.match(/^(--inspect(-brk)?)$/))!==null)J=Z[1];else if((Z=z.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null)if(J=Z[1],/^\d+$/.test(Z[3]))X=Z[3];else Q=Z[3];else if((Z=z.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null)J=Z[1],Q=Z[3],X=Z[4];if(J&&X!=="0")return`${J}=${Q}:${parseInt(X)+1}`;return z})}function c(){if(T.env.NO_COLOR||T.env.FORCE_COLOR==="0"||T.env.FORCE_COLOR==="false")return!1;if(T.env.FORCE_COLOR||T.env.CLICOLOR_FORCE!==void 0)return!0;return}n4.Command=d;n4.useColor=c});var Y4=D((e4)=>{var{Argument:Z4}=k(),{Command:l}=X4(),{CommanderError:a4,InvalidArgumentError:$4}=A(),{Help:o4}=v(),{Option:_4}=h();e4.program=new l;e4.createCommand=(q)=>new l(q);e4.createOption=(q,z)=>new _4(q,z);e4.createArgument=(q,z)=>new Z4(q,z);e4.Command=l;e4.Option=_4;e4.Argument=Z4;e4.Help=o4;e4.CommanderError=a4;e4.InvalidArgumentError=$4;e4.InvalidOptionArgumentError=$4});var B4=I4(Y4(),1),{program:w,createCommand:F6,createArgument:y6,createOption:A6,CommanderError:w6,InvalidArgumentError:C6,InvalidOptionArgumentError:k6,Command:x6,Argument:O6,Option:b6,Help:f6}=B4.default;var O={name:"@mintplex-labs/anything-llm-cli",version:"0.0.6",description:"A CLI tool to interact with AnythingLLM from the terminal",type:"module",bin:{any:"dist/index.js"},files:["dist/index.js","README.md"],keywords:["anythingllm","llm","cli","ai"],repository:{type:"git",url:"https://github.com/Mintplex-Labs/anything-llm-cli"},license:"MIT",scripts:{setup:"cp .env.example .env.local && bun install",start:"bun run src/index.ts",build:"bun build --compile --minify --outfile=dist/any src/index.ts","build:npm":"bun build --minify --target=node --banner '#!/usr/bin/env node' --outfile=dist/index.js src/index.ts",prepublishOnly:"bun run build:npm",lint:"bunx biome check --write .","build:linux-x64":"bun build --compile --minify --target=bun-linux-x64 --outfile=dist/any-linux-x64 src/index.ts","build:linux-arm64":"bun build --compile --minify --target=bun-linux-arm64 --outfile=dist/any-linux-arm64 src/index.ts","build:windows-x64":"bun build --compile --minify --target=bun-windows-x64 --outfile=dist/any-windows-x64.exe src/index.ts","build:darwin-x64":"bun build --compile --minify --target=bun-darwin-x64 --outfile=dist/any-darwin-x64 src/index.ts","build:darwin-arm64":"bun build --compile --minify --target=bun-darwin-arm64 --outfile=dist/any-darwin-arm64 src/index.ts","build:all":"bun run build:linux-x64 && bun run build:linux-arm64 && bun run build:windows-x64 && bun run build:darwin-x64 && bun run build:darwin-arm64"},devDependencies:{"@biomejs/biome":"2.3.15","@types/bun":"latest",lefthook:"^2.1.1"},peerDependencies:{typescript:"^5"},dependencies:{commander:"^14.0.3"}};import{readFileSync as M6}from"node:fs";import{basename as T6,extname as U6,resolve as R6}from"node:path";class b{apiKey=process.env.ANYTHINGLLM_API_KEY||"";baseUrl=new URL("http://localhost:3001");static fileToAttachment(q){let z={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp"},J=R6(q),Q=U6(J).toLowerCase(),X=z[Q];if(!X)console.error(`Unsupported file type: ${Q}
|
|
28
28
|
Supported: ${Object.keys(z).join(", ")}`),process.exit(1);let $=M6(J).toString("base64");return{name:T6(J),mime:X,contentString:`data:${X};base64,${$}`}}streamResponse(q,z){let J=this;return{[Symbol.asyncIterator](){return async function*(){let Q=new URL(q,J.baseUrl),X=await fetch(Q.href,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${J.apiKey}`},body:JSON.stringify(z)});if(!X.ok||!X.body)throw Error(`Stream request failed with status ${X.status}`);let Z=new TextDecoder,$="";for await(let _ of X.body){$+=Z.decode(_,{stream:!0});let G=$.split(`
|
|
29
29
|
|
|
30
30
|
`);$=G.pop()||"";for(let Y of G){let B=Y.trim();if(!B.startsWith("data:"))continue;yield JSON.parse(B.slice(5).trim())}}}()}}}async callApi(q,z={}){try{let J=new URL(q,this.baseUrl),Q=await fetch(J.href,{method:z.method||"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:z.body?JSON.stringify(z.body):void 0});if(!Q.ok){let Z=await Q.text();throw Error(`API request failed with status ${Q.status}: ${Z}`)}return{ok:!0,data:await Q.json()}}catch(J){return{ok:!1,error:J instanceof Error?J.message:String(J)}}}admin={};documents={};systemSettings={};embeds={};workspaces={create:async(q)=>{return this.callApi("api/v1/workspace/new",{method:"POST",body:{...q,openAiTemp:q.temperature,openAiHistory:q.historyMessageCount,openAiPrompt:q.systemPrompt,chatMode:q.mode}})},list:async()=>{return this.callApi("api/v1/workspaces")},get:async(q)=>{return this.callApi(`api/v1/workspace/${q.slug}`)},chat:async(q)=>{return this.callApi(`api/v1/workspace/${q.slug}/chat`,{method:"POST",body:{message:q.message,mode:q.mode??"chat",attachments:q.attachments}})},streamChat:(q)=>{return this.streamResponse(`api/v1/workspace/${q.slug}/stream-chat`,{message:q.message,mode:q.mode??"chat",attachments:q.attachments})}};threads={create:async(q)=>{return this.callApi(`api/v1/workspace/${q.workspaceSlug}/thread/new`,{method:"POST",body:{...q,name:q.title}})},chat:async(q)=>{return this.callApi(`api/v1/workspace/${q.workspaceSlug}/thread/${q.threadSlug}/chat`,{method:"POST",body:{message:q.message,mode:q.mode??"chat",attachments:q.attachments}})},streamChat:(q)=>{return this.streamResponse(`api/v1/workspace/${q.workspaceSlug}/thread/${q.threadSlug}/stream-chat`,{message:q.message,mode:q.mode??"chat",attachments:q.attachments})},getMessages:async(q)=>{let z=q.threadSlug?`api/v1/workspace/${q.workspaceSlug}/thread/${q.threadSlug}/chats`:`api/v1/workspace/${q.workspaceSlug}/chats`;return this.callApi(z)}};constructor({apiKey:q,baseUrl:z}){this.apiKey=q||this.apiKey,this.baseUrl=z?new URL(z):this.baseUrl}}function G4(){return new Promise((q)=>{let z="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",(J)=>{z+=J}),process.stdin.on("end",()=>q(z))})}var H4="anythingllm-cli-default-workspace";async function M4(q,z){let J=q.join(" "),Q=process.env.ANYTHING_LLM_API_KEY;if(!Q)console.error("ANYTHING_LLM_API_KEY environment variable is not set"),process.exit(1);let X="";if(process.stdin.isTTY===!1)X=await G4();let Z=X?`${X} ${J}`:J,$=z.attach?z.attach.map(b.fileToAttachment):void 0,_=new b({apiKey:Q,baseUrl:process.env.ANYTHING_LLM_BASE_URL}),G=z.workspace||H4;if(G===H4){let U=await _.workspaces.get({slug:G});if(!U.ok)console.error(`Failed to get workspace "${G}": ${U.error}`),process.exit(1);if(U.data.workspace.length===0){let W=await _.workspaces.create({name:"AnythingLLM CLI Default Workspace",systemPrompt:"You are a helpful assistant responding to prompts from the AnythingLLM CLI tool. You will sometimes receive context passed in from the stdinput."});if(!W.ok)console.error(`Failed to create workspace: ${W.error}`),process.exit(1)}}let Y=z.thread;if(z.newThread){let U=await _.threads.create({workspaceSlug:G,title:`AnythingLLM CLI Thread - ${new Date().toLocaleString()}`});if(!U.ok)console.error(`Failed to create thread: ${U.error}`),process.exit(1);Y=U.data.thread.slug}if(!z.stream){let U=Y?await _.threads.chat({threadSlug:Y,message:Z,workspaceSlug:G,attachments:$}):await _.workspaces.chat({slug:G,message:Z,attachments:$});if(!U.ok)console.error(`LLM request failed: ${U.error}`),process.exit(1);process.stdout.write(`${U.data.textResponse}
|