anveesa 0.1.0 → 0.2.0

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/Cargo.lock CHANGED
@@ -54,7 +54,7 @@ dependencies = [
54
54
 
55
55
  [[package]]
56
56
  name = "anveesa"
57
- version = "0.1.0"
57
+ version = "0.2.0"
58
58
  dependencies = [
59
59
  "anyhow",
60
60
  "base64",
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "anveesa"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  edition = "2024"
5
5
  default-run = "anveesa"
6
6
 
package/README.md CHANGED
@@ -3,6 +3,25 @@
3
3
  Anveesa is a Rust terminal wrapper for AI providers. It gives you one command,
4
4
  `anveesa`, while each provider is configured as either:
5
5
 
6
+ ## 📦 Publishing to npm
7
+
8
+ Anveesa can be published as an npm package via a Node.js wrapper that invokes the Rust binary.
9
+
10
+ ### Install from npm
11
+
12
+ ```bash
13
+ npm install -g anveesa-cli
14
+ ```
15
+
16
+ ### Build and publish
17
+
18
+ ```bash
19
+ npm run build
20
+ npm publish
21
+ ```
22
+
23
+ See `package.json` in the root directory for build scripts and npm configuration.
24
+
6
25
  - `openai-compatible`: HTTP chat completions providers such as OpenRouter and other compatible gateways.
7
26
  - `command`: local CLIs such as Codex, Copilot, and Claude Code, where Anveesa spawns a command and passes the prompt.
8
27
 
@@ -148,6 +167,28 @@ OpenAI-compatible API providers:
148
167
 
149
168
  - `openai`
150
169
  - `sumopod`
170
+
171
+ ### How to change the model
172
+
173
+ You can change the model using these commands:
174
+
175
+ **Via config file:**
176
+ ```bash
177
+ anveesa config set-model "your-model"
178
+ ```
179
+
180
+ **Via command line:**
181
+ ```bash
182
+ anveesa --model "your-model" "your prompt"
183
+ ```
184
+
185
+ **Interactive mode:**
186
+ ```bash
187
+ anveesa
188
+ # Then select/change model in the prompt
189
+ ```
190
+
191
+ The model can be set per provider (e.g., `sumopod`, `openai`, `openrouter`, etc.) and can be overridden per command with `--model`.
151
192
  - `openrouter`
152
193
  - `glm`
153
194
  - `glm-coding`
package/bin/anveesa.js CHANGED
@@ -48,17 +48,20 @@ if (!binaryPath) {
48
48
  process.exit(1);
49
49
  }
50
50
 
51
- // Spawn the Rust binary
51
+ // Spawn the Rust binary with proper TTY support
52
+ const { spawn } = require('child_process');
52
53
  const args = process.argv.slice(2);
53
- const options = {
54
+ const child = spawn(binaryPath, args, {
54
55
  cwd: process.cwd(),
55
- stdio: ['inherit', 'inherit', 'inherit'],
56
+ stdio: 'inherit',
56
57
  env: { ...process.env },
57
- };
58
+ });
58
59
 
59
- try {
60
- execFile(binaryPath, args, options);
61
- } catch (error) {
60
+ child.on('error', (error) => {
62
61
  console.error('Error running anveesa:', error.message);
63
62
  process.exit(1);
64
- }
63
+ });
64
+
65
+ child.on('exit', (code) => {
66
+ process.exit(code ?? 1);
67
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "anveesa",
3
- "version": "0.1.0",
4
- "description": "Anveesa terminal wrapper for AI providers",
3
+ "version": "0.2.0",
4
+ "description": "A terminal CLI that wraps AI providers (OpenAI-compatible APIs and local CLIs) into a single unified command",
5
5
  "main": "bin/anveesa.js",
6
6
  "bin": {
7
7
  "anveesa": "bin/anveesa.js"
@@ -20,7 +20,7 @@
20
20
  "src/",
21
21
  "README.md"
22
22
  ],
23
- "keywords": ["ai", "cli", "terminal", "rust"],
23
+ "keywords": ["ai", "cli", "terminal", "rust", "openai", "agent", "copilot"],
24
24
  "license": "MIT",
25
25
  "engines": {
26
26
  "node": ">=16"
@@ -28,5 +28,10 @@
28
28
  "repository": {
29
29
  "type": "git",
30
30
  "url": "https://github.com/pandhuwibowo/anveesa-cli.git"
31
- }
31
+ },
32
+ "homepage": "https://github.com/pandhuwibowo/anveesa-cli",
33
+ "bugs": {
34
+ "url": "https://github.com/pandhuwibowo/anveesa-cli/issues"
35
+ },
36
+ "author": "Anveesa"
32
37
  }
@@ -35,11 +35,28 @@ function checkAndInstall() {
35
35
  console.log('✓ Installation complete!');
36
36
  return true;
37
37
  } else {
38
- console.error('✗ Anveesa binary not found.');
39
- console.error('');
40
- console.error('Build the Rust binary first:');
41
- console.error(' npm run install:bin');
38
+ // Try to build automatically
39
+ try {
40
+ console.log(' Building anveesa binary from source...');
41
+ execSync('cargo build --release', {
42
+ cwd: path.join(__dirname, '..'),
43
+ stdio: 'inherit'
44
+ });
45
+ const rebuilt = getBinaryPath();
46
+ if (rebuilt) {
47
+ console.log('✓ Binary built successfully at:', rebuilt);
48
+ console.log('✓ Installation complete!');
49
+ return true;
50
+ }
51
+ } catch (e) {
52
+ // cargo not available or build failed
53
+ }
54
+
55
+ console.error('✗ Anveesa binary not found and could not be built.');
42
56
  console.error('');
57
+ console.error('Make sure Rust is installed: https://rustup.rs/');
58
+ console.error('Then run:');
59
+ console.error(' cargo build --release');
43
60
  return false;
44
61
  }
45
62
  }
@@ -46,6 +46,7 @@ pub async fn ask(
46
46
 
47
47
  let client = reqwest::Client::builder()
48
48
  .connect_timeout(CONNECT_TIMEOUT)
49
+ .read_timeout(Duration::from_secs(300)) // 5-minute read timeout for long streams
49
50
  .build()
50
51
  .context("failed to build HTTP client")?;
51
52
  let url = format!("{}/chat/completions", config.base_url.trim_end_matches('/'));
@@ -662,22 +663,42 @@ async fn stream_response(
662
663
  events: &UnboundedSender<StreamEvent>,
663
664
  ) -> Result<()> {
664
665
  let mut buffer = String::new();
666
+ let mut consecutive_errors: usize = 0;
667
+ const MAX_CONSECUTIVE_ERRORS: usize = 3;
665
668
 
666
- while let Some(chunk) = response
667
- .chunk()
668
- .await
669
- .context("failed to read streamed response chunk")?
670
- {
671
- buffer.push_str(&String::from_utf8_lossy(&chunk));
672
-
673
- while let Some(newline) = buffer.find('\n') {
674
- let line: String = buffer.drain(..=newline).collect();
675
- if let Some(token) = state.ingest_line(line.trim_end_matches(['\r', '\n'])) {
676
- let _ = events.send(StreamEvent::Token(token));
669
+ loop {
670
+ let chunk_result = response.chunk().await;
671
+
672
+ match chunk_result {
673
+ Ok(Some(chunk)) => {
674
+ consecutive_errors = 0; // Reset error counter on successful read
675
+ buffer.push_str(&String::from_utf8_lossy(&chunk));
676
+
677
+ while let Some(newline) = buffer.find('\n') {
678
+ let line: String = buffer.drain(..=newline).collect();
679
+ if let Some(token) = state.ingest_line(line.trim_end_matches(['\r', '\n'])) {
680
+ let _ = events.send(StreamEvent::Token(token));
681
+ }
682
+ }
683
+ }
684
+ Ok(None) => {
685
+ // Stream ended normally
686
+ break;
687
+ }
688
+ Err(_e) => {
689
+ consecutive_errors += 1;
690
+ if consecutive_errors >= MAX_CONSECUTIVE_ERRORS {
691
+ // Log the error but don't fail the whole request
692
+ eprintln!("\n[warning: stream interrupted after {} consecutive errors]", consecutive_errors);
693
+ break;
694
+ }
695
+ // Try to continue reading - transient network hiccups happen
696
+ continue;
677
697
  }
678
698
  }
679
699
  }
680
700
 
701
+ // Process any remaining data in the buffer
681
702
  if !buffer.is_empty()
682
703
  && let Some(token) = state.ingest_line(buffer.trim())
683
704
  {
@@ -716,7 +737,10 @@ impl StreamState {
716
737
  self.done = true;
717
738
  return None;
718
739
  }
719
- let chunk: Value = serde_json::from_str(data).ok()?;
740
+ let chunk: Value = match serde_json::from_str(data) {
741
+ Ok(v) => v,
742
+ Err(_) => return None, // Skip malformed lines instead of bailing
743
+ };
720
744
  self.apply_chunk(&chunk)
721
745
  }
722
746
 
@@ -725,7 +749,15 @@ impl StreamState {
725
749
  self.usage = parse_usage(usage);
726
750
  }
727
751
 
728
- let delta = chunk.get("choices")?.get(0)?.get("delta")?;
752
+ let Some(choices) = chunk.get("choices") else {
753
+ return None;
754
+ };
755
+ let Some(first_choice) = choices.get(0) else {
756
+ return None;
757
+ };
758
+ let Some(delta) = first_choice.get("delta") else {
759
+ return None;
760
+ };
729
761
 
730
762
  if let Some(tool_calls) = delta.get("tool_calls").and_then(Value::as_array) {
731
763
  for call in tool_calls {
@@ -733,7 +765,8 @@ impl StreamState {
733
765
  }
734
766
  }
735
767
 
736
- let text = delta.get("content").and_then(Value::as_str)?;
768
+ // Content may be absent (e.g., tool-call-only chunks) — don't bail.
769
+ let text = delta.get("content").and_then(Value::as_str).unwrap_or("");
737
770
  if text.is_empty() {
738
771
  return None;
739
772
  }