@mintplex-labs/anything-llm-cli 0.0.4 → 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 +70 -202
- 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,74 +32,51 @@ 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
|
-
|
|
35
|
+
### Via package manager
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
npm install -g @mintplex-labs/anything-llm-cli
|
|
39
|
+
# or
|
|
40
|
+
yarn global add @mintplex-labs/anything-llm-cli
|
|
41
|
+
# or
|
|
42
|
+
pnpm add -g @mintplex-labs/anything-llm-cli
|
|
43
|
+
# or
|
|
44
|
+
bun install -g @mintplex-labs/anything-llm-cli
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
This installs the `any` command globally.
|
|
48
|
-
|
|
49
47
|
### Standalone binary
|
|
50
48
|
|
|
51
|
-
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`.
|
|
52
50
|
|
|
53
|
-
| Platform
|
|
54
|
-
|
|
|
55
|
-
| macOS ARM
|
|
56
|
-
| macOS Intel
|
|
57
|
-
| Linux x64
|
|
58
|
-
| Linux ARM
|
|
59
|
-
| Windows x64
|
|
51
|
+
| Platform | Binary |
|
|
52
|
+
| ----------- | --------------------- |
|
|
53
|
+
| macOS ARM | `any-darwin-arm64` |
|
|
54
|
+
| macOS Intel | `any-darwin-x64` |
|
|
55
|
+
| Linux x64 | `any-linux-x64` |
|
|
56
|
+
| Linux ARM | `any-linux-arm64` |
|
|
57
|
+
| Windows x64 | `any-windows-x64.exe` |
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
## Quickstart
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
1. **Get your API key** from your AnythingLLM instance under **Settings > Developer API**.
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
git clone https://github.com/mintplex-labs/anything-llm-cli.git
|
|
67
|
-
cd anything-llm-cli
|
|
68
|
-
bun run setup
|
|
69
|
-
```
|
|
63
|
+
2. **Set your environment variables:**
|
|
70
64
|
|
|
71
|
-
|
|
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
|
+
```
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
> **Tip:** Add these to your `.bashrc` or `.zshrc` for persistence.
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
bun run start prompt "Hello!"
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Or compile a native binary:
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
bun run build
|
|
83
|
-
./dist/any prompt "Hello!"
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Setup
|
|
73
|
+
3. **Send your first prompt:**
|
|
87
74
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
For the npm package or standalone binary, set environment variables directly:
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
export ANYTHING_LLM_API_KEY="your-api-key"
|
|
96
|
-
export ANYTHING_LLM_BASE_URL="https://my-instance.example.com" # optional, default: http://localhost:3001
|
|
97
|
-
export ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG="my-workspace" # optional, avoids needing -w
|
|
98
|
-
```
|
|
75
|
+
```bash
|
|
76
|
+
any prompt "What is AnythingLLM?"
|
|
77
|
+
```
|
|
99
78
|
|
|
100
|
-
If no workspace is specified
|
|
101
|
-
|
|
102
|
-
> **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.
|
|
103
80
|
|
|
104
81
|
## Usage
|
|
105
82
|
|
|
@@ -107,180 +84,71 @@ If no workspace is specified via `-w` or the environment variable, the CLI will
|
|
|
107
84
|
any prompt <message> [options]
|
|
108
85
|
```
|
|
109
86
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
### Commands
|
|
113
|
-
|
|
114
|
-
| Command | Alias | Description |
|
|
115
|
-
| --- | --- | --- |
|
|
116
|
-
| `prompt <message...>` | `p` | Send a prompt to the LLM |
|
|
87
|
+
### Options
|
|
117
88
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
| Flag | Description |
|
|
121
|
-
| --- | --- |
|
|
89
|
+
| Flag | Description |
|
|
90
|
+
| ------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
122
91
|
| `-w, --workspace <slug>` | Workspace slug. Falls back to `ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG` env var, or auto-creates a default workspace |
|
|
123
|
-
| `-a, --attach <path...>` | Attach image files to the prompt (png, jpg, jpeg, gif, webp)
|
|
124
|
-
| `-t, --thread [slug]`
|
|
125
|
-
| `--nt, --new-thread`
|
|
126
|
-
| `-S, --no-stream`
|
|
127
|
-
|
|
128
|
-
#### Supported attachment types
|
|
129
|
-
|
|
130
|
-
`png`, `jpg`, `jpeg`, `gif`, `webp`
|
|
92
|
+
| `-a, --attach <path...>` | Attach image files to the prompt (png, jpg, jpeg, gif, webp) |
|
|
93
|
+
| `-t, --thread [slug]` | Use a specific thread for the conversation |
|
|
94
|
+
| `--nt, --new-thread` | Start a new thread for this conversation |
|
|
95
|
+
| `-S, --no-stream` | Disable streaming (wait for full response) |
|
|
131
96
|
|
|
132
97
|
### Examples
|
|
133
98
|
|
|
134
|
-
**Simple prompt:**
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
any prompt "What is AnythingLLM?"
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**Multi-word prompts without quotes:**
|
|
141
|
-
|
|
142
99
|
```bash
|
|
100
|
+
# Simple prompt (quotes optional)
|
|
143
101
|
any prompt What is AnythingLLM
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Using the short alias:**
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
any p "What is AnythingLLM?"
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
**Pipe in context from another command:**
|
|
153
102
|
|
|
154
|
-
|
|
103
|
+
# Pipe in context
|
|
155
104
|
cat error.log | any prompt "Explain these errors"
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
105
|
git diff | any prompt "Write a commit message for these changes"
|
|
160
|
-
```
|
|
161
106
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
**Use a specific thread for ongoing conversations:**
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
any prompt "Let's continue our discussion" -t thread-slug
|
|
170
|
-
```
|
|
107
|
+
# Use a specific workspace
|
|
108
|
+
any prompt "Hello" -w my-workspace
|
|
171
109
|
|
|
172
|
-
|
|
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
|
|
173
113
|
|
|
174
|
-
|
|
175
|
-
any prompt "
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
**Disable streaming (useful for scripting):**
|
|
114
|
+
# Attach images
|
|
115
|
+
any prompt "What's in this image?" -a ./photo.png
|
|
179
116
|
|
|
180
|
-
|
|
117
|
+
# Scripting (no streaming, capture output)
|
|
181
118
|
RESULT=$(any prompt "Give me a one-word answer: yes or no?" -S)
|
|
182
|
-
echo "The LLM said: $RESULT"
|
|
183
|
-
```
|
|
184
119
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
any prompt "Write a summary of AnythingLLM" > summary.md
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
> When piped to a file, ANSI formatting is automatically stripped and agent tool call assembly is cleaned up for readable plaintext output.
|
|
192
|
-
|
|
193
|
-
**Attach images:**
|
|
194
|
-
|
|
195
|
-
```bash
|
|
196
|
-
any prompt "What's in this image?" -a ./photo.png
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
any prompt "Compare these images" -a image1.png image2.jpg
|
|
120
|
+
# Save response to a file
|
|
121
|
+
any prompt "Write a summary" > summary.md
|
|
201
122
|
```
|
|
202
123
|
|
|
203
|
-
|
|
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.
|
|
204
125
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
## TypeScript SDK
|
|
208
|
-
|
|
209
|
-
The project also includes a fully-typed TypeScript SDK (`AnythingLLM` class) that you can use programmatically:
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
import { AnythingLLM } from "./src/sdk";
|
|
213
|
-
|
|
214
|
-
const client = new AnythingLLM({
|
|
215
|
-
apiKey: "your-api-key",
|
|
216
|
-
baseUrl: "http://localhost:3001",
|
|
217
|
-
});
|
|
126
|
+
## Environment Variables
|
|
218
127
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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) |
|
|
224
133
|
|
|
225
|
-
|
|
226
|
-
console.log(result.data.textResponse);
|
|
227
|
-
}
|
|
134
|
+
## Development
|
|
228
135
|
|
|
229
|
-
|
|
230
|
-
const stream = client.workspaces.streamChat({
|
|
231
|
-
slug: "my-workspace",
|
|
232
|
-
message: "Tell me a story",
|
|
233
|
-
mode: "chat",
|
|
234
|
-
});
|
|
136
|
+
Requires [Bun](https://bun.sh).
|
|
235
137
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
|
241
144
|
```
|
|
242
145
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
| Method | Description |
|
|
246
|
-
| --- | --- |
|
|
247
|
-
| `workspaces.list()` | List all workspaces |
|
|
248
|
-
| `workspaces.get({ slug })` | Get a workspace by slug |
|
|
249
|
-
| `workspaces.create({ name, ... })` | Create a new workspace |
|
|
250
|
-
| `workspaces.chat({ slug, message })` | Send a message and get a complete response |
|
|
251
|
-
| `workspaces.streamChat({ slug, message })` | Stream a response as SSE chunks |
|
|
252
|
-
| `threads.create({ workspaceSlug, title })` | Create a new thread in a workspace |
|
|
253
|
-
| `threads.chat({ workspaceSlug, threadSlug, message })` | Chat within a thread |
|
|
254
|
-
| `threads.streamChat({ workspaceSlug, threadSlug, message })` | Stream a response within a thread |
|
|
255
|
-
| `threads.getMessages({ workspaceSlug, threadSlug? })` | Get chat history |
|
|
256
|
-
|
|
257
|
-
## Development
|
|
146
|
+
## Uninstall
|
|
258
147
|
|
|
259
148
|
```bash
|
|
260
|
-
#
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
# Run in development
|
|
264
|
-
bun run start
|
|
265
|
-
|
|
266
|
-
# Lint and format
|
|
267
|
-
bun run lint
|
|
268
|
-
|
|
269
|
-
# Build for current platform
|
|
270
|
-
bun run build
|
|
149
|
+
# If installed via install script
|
|
150
|
+
sudo rm /usr/local/bin/any
|
|
271
151
|
|
|
272
|
-
#
|
|
273
|
-
|
|
152
|
+
# If installed via package manager
|
|
153
|
+
npm uninstall -g @mintplex-labs/anything-llm-cli
|
|
274
154
|
```
|
|
275
|
-
|
|
276
|
-
## Environment Variables
|
|
277
|
-
|
|
278
|
-
| Variable | Required | Default | Description |
|
|
279
|
-
| --- | --- | --- | --- |
|
|
280
|
-
| `ANYTHING_LLM_API_KEY` | Yes | — | Your AnythingLLM API key |
|
|
281
|
-
| `ANYTHING_LLM_BASE_URL` | No | `http://localhost:3001` | Base URL of your AnythingLLM instance |
|
|
282
|
-
| `ANYTHING_LLM_DEFAULT_WORKSPACE_SLUG` | No | — | Default workspace slug (avoids needing `-w` flag) |
|
|
283
|
-
|
|
284
|
-
## License
|
|
285
|
-
|
|
286
|
-
[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}
|