@zemerik/gemini-assist 1.1.1-beta
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/.env.example +8 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +50 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +35 -0
- package/.github/ISSUE_TEMPLATE/question.md +29 -0
- package/.github/dependabot.yml +49 -0
- package/.github/labels.yml +129 -0
- package/.github/pull_request_template.md +46 -0
- package/.github/stale.yml +25 -0
- package/.github/workflows/ci.yml +192 -0
- package/.github/workflows/release.yml +71 -0
- package/.rustignore +5 -0
- package/Cargo.toml +19 -0
- package/LICENSE +0 -0
- package/README.md +220 -0
- package/README_RUST.md +134 -0
- package/RELEASE_NOTES.md +124 -0
- package/bin/gemini-assist.js +136 -0
- package/build.rs +3 -0
- package/gitignore +1 -0
- package/index.d.ts +13 -0
- package/index.js +317 -0
- package/napi.config.json +33 -0
- package/package.json +63 -0
- package/scripts/postinstall.js +11 -0
- package/src/gemini.js +127 -0
- package/src/gemini_client.rs +159 -0
- package/src/lib.rs +58 -0
- package/src/rust/gemini_client.rs +157 -0
- package/src/rust/lib.rs +57 -0
- package/src/utils.js +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Gemini Assist v1.1.1-Beta
|
|
2
|
+
|
|
3
|
+
AI Assistant CLI tool powered by Google Gemini API. Interact with Google's Gemini AI model directly from your terminal.
|
|
4
|
+
|
|
5
|
+
**🚀 Hybrid Architecture: 50% JavaScript, 50% Rust**
|
|
6
|
+
This project uses Rust for core API operations and JavaScript for the CLI interface, providing the best of both worlds: Rust's performance and JavaScript's flexibility.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🤖 **Interactive Chat Mode** - Have conversations with Gemini AI
|
|
11
|
+
- 💬 **Single Query Mode** - Quick one-off questions
|
|
12
|
+
- 🎨 **Beautiful CLI Interface** - Colorful, user-friendly terminal experience
|
|
13
|
+
- ⚙️ **Configurable** - Customize model, temperature, and more
|
|
14
|
+
- 📦 **Easy Installation** - Simple npm package installation
|
|
15
|
+
- 🔑 **Secure API Key Management** - Support for environment variables
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
- Node.js >= 14.0.0
|
|
22
|
+
- For Rust build: Rust toolchain (optional, JS fallback available)
|
|
23
|
+
|
|
24
|
+
### Global Installation (Recommended)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g gemini-assist
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Building Rust Components
|
|
31
|
+
|
|
32
|
+
The package includes Rust bindings for better performance. To build them:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g @napi-rs/cli
|
|
36
|
+
npm run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If Rust bindings aren't available, the CLI automatically falls back to a JavaScript implementation. See [README_RUST.md](README_RUST.md) for details.
|
|
40
|
+
|
|
41
|
+
### Local Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install gemini-assist
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Getting Started
|
|
48
|
+
|
|
49
|
+
### 1. Get Your Gemini API Key
|
|
50
|
+
|
|
51
|
+
1. Visit [Google AI Studio](https://makersuite.google.com/app/apikey)
|
|
52
|
+
2. Sign in with your Google account
|
|
53
|
+
3. Create a new API key
|
|
54
|
+
4. Copy your API key
|
|
55
|
+
|
|
56
|
+
### 2. Set Your API Key
|
|
57
|
+
|
|
58
|
+
**Option A: Environment Variable (Recommended)**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
export GEMINI_API_KEY=your_api_key_here
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Option B: Command Line Flag**
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
gemini-assist --api-key your_api_key_here "Your question here"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Option C: .env File (Recommended for Local Development)**
|
|
71
|
+
|
|
72
|
+
Create a `.env` file in your project directory:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Copy the example file
|
|
76
|
+
cp .env.example .env
|
|
77
|
+
|
|
78
|
+
# Then edit .env and add your API key
|
|
79
|
+
# GEMINI_API_KEY=your_api_key_here
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The `.env` file is automatically loaded by the CLI using the `dotenv` package.
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
### Interactive Mode
|
|
87
|
+
|
|
88
|
+
Start an interactive chat session:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
gemini-assist --interactive
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Or simply:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
gemini-assist
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
In interactive mode:
|
|
101
|
+
- Type your questions and press Enter
|
|
102
|
+
- Type `exit`, `quit`, `bye`, or `q` to end the session
|
|
103
|
+
- Type `clear` to clear the screen
|
|
104
|
+
|
|
105
|
+
### Single Query Mode
|
|
106
|
+
|
|
107
|
+
Ask a quick question:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
gemini-assist "What is the capital of France?"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Command Line Options
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
gemini-assist [options] [query]
|
|
117
|
+
|
|
118
|
+
Options:
|
|
119
|
+
-V, --version Show version number
|
|
120
|
+
-k, --api-key <key> Gemini API key (or set GEMINI_API_KEY env variable)
|
|
121
|
+
-m, --model <model> Gemini model to use (default: gemini-1.5-flash)
|
|
122
|
+
-i, --interactive Start interactive chat mode
|
|
123
|
+
-t, --temperature <value> Temperature for response 0-1 (default: 0.7)
|
|
124
|
+
-h, --help Display help for command
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Examples
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Interactive mode with custom model
|
|
131
|
+
gemini-assist --interactive --model gemini-1.5-pro
|
|
132
|
+
|
|
133
|
+
# Single query with custom temperature
|
|
134
|
+
gemini-assist -t 0.9 "Write a creative story"
|
|
135
|
+
|
|
136
|
+
# Using alias
|
|
137
|
+
gassist "Explain quantum computing"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Programmatic Usage
|
|
141
|
+
|
|
142
|
+
You can also use Gemini Assist as a Node.js module:
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const { GeminiClient } = require('gemini-assist');
|
|
146
|
+
|
|
147
|
+
const client = new GeminiClient('your-api-key', {
|
|
148
|
+
model: 'gemini-1.5-flash',
|
|
149
|
+
temperature: 0.7
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
async function chat() {
|
|
153
|
+
const response = await client.chat('Hello, how are you?');
|
|
154
|
+
console.log(response);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
chat();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Available Models
|
|
161
|
+
|
|
162
|
+
- `gemini-2.5-flash` (default) - Latest fast and efficient model
|
|
163
|
+
- `gemini-1.5-flash` - Fast and efficient, previous version
|
|
164
|
+
- `gemini-1.5-pro` - More capable model for complex tasks
|
|
165
|
+
- `gemini-pro` - Legacy model (may be deprecated)
|
|
166
|
+
|
|
167
|
+
**Note:** Model availability depends on your API key's access level. If a model doesn't work, try another one.
|
|
168
|
+
|
|
169
|
+
## Configuration
|
|
170
|
+
|
|
171
|
+
### Environment Variables
|
|
172
|
+
|
|
173
|
+
- `GEMINI_API_KEY` - Your Gemini API key (required)
|
|
174
|
+
- `DEBUG` - Set to `true` for detailed error messages
|
|
175
|
+
|
|
176
|
+
## Troubleshooting
|
|
177
|
+
|
|
178
|
+
### API Key Issues
|
|
179
|
+
|
|
180
|
+
If you get an "Invalid API key" error:
|
|
181
|
+
1. Verify your API key at [Google AI Studio](https://makersuite.google.com/app/apikey)
|
|
182
|
+
2. Make sure there are no extra spaces when copying the key
|
|
183
|
+
3. Check that the `GEMINI_API_KEY` environment variable is set correctly
|
|
184
|
+
|
|
185
|
+
### Rate Limits
|
|
186
|
+
|
|
187
|
+
If you encounter rate limit errors:
|
|
188
|
+
- Wait a few moments before trying again
|
|
189
|
+
- Check your API quota at Google AI Studio
|
|
190
|
+
- Consider upgrading your API plan if needed
|
|
191
|
+
|
|
192
|
+
### Safety Filters
|
|
193
|
+
|
|
194
|
+
If content is blocked by safety filters:
|
|
195
|
+
- Rephrase your query
|
|
196
|
+
- Avoid potentially harmful or inappropriate content
|
|
197
|
+
- Check Google's content policy
|
|
198
|
+
|
|
199
|
+
## Requirements
|
|
200
|
+
|
|
201
|
+
- Node.js >= 14.0.0
|
|
202
|
+
- npm or yarn
|
|
203
|
+
- Valid Gemini API key
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT
|
|
208
|
+
|
|
209
|
+
## Contributing
|
|
210
|
+
|
|
211
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
212
|
+
|
|
213
|
+
## Support
|
|
214
|
+
|
|
215
|
+
For issues, questions, or feature requests, please open an issue on the project repository.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
**Version:** 1.1.1-Beta
|
|
220
|
+
**Powered by:** Google Gemini API
|
package/README_RUST.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Rust Integration Guide
|
|
2
|
+
|
|
3
|
+
This project is a **50% JavaScript, 50% Rust** hybrid implementation.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
- **Rust (50%)**: Core Gemini API client logic, HTTP requests, and performance-critical operations
|
|
8
|
+
- **JavaScript (50%)**: CLI interface, user interaction, command parsing, and UI/UX
|
|
9
|
+
|
|
10
|
+
## Building the Rust Component
|
|
11
|
+
|
|
12
|
+
### Prerequisites
|
|
13
|
+
|
|
14
|
+
1. Install Rust: https://rustup.rs/
|
|
15
|
+
2. Install Node.js (v14+)
|
|
16
|
+
3. Install napi-rs CLI:
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @napi-rs/cli
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Build Commands
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Build Rust bindings for all platforms (release mode)
|
|
25
|
+
npm run build
|
|
26
|
+
|
|
27
|
+
# Build for development (debug mode)
|
|
28
|
+
npm run build:debug
|
|
29
|
+
|
|
30
|
+
# Build for current platform only
|
|
31
|
+
cargo build --release
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Project Structure
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
Gemini Assist/
|
|
38
|
+
├── Cargo.toml # Rust package configuration
|
|
39
|
+
├── build.rs # NAPI build script
|
|
40
|
+
├── src/
|
|
41
|
+
│ ├── lib.rs # NAPI bindings entry point
|
|
42
|
+
│ └── gemini_client.rs # Rust Gemini API client
|
|
43
|
+
├── bin/
|
|
44
|
+
│ └── gemini-assist.js # JavaScript CLI entry point
|
|
45
|
+
└── src/
|
|
46
|
+
├── gemini.js # JS wrapper (uses Rust when available)
|
|
47
|
+
└── utils.js # JS utilities
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## How It Works
|
|
51
|
+
|
|
52
|
+
1. **Rust Client** (`src/gemini_client.rs`):
|
|
53
|
+
- Handles all HTTP communication with Gemini API
|
|
54
|
+
- Manages chat history in memory
|
|
55
|
+
- Processes API responses and error handling
|
|
56
|
+
- Uses `reqwest` for async HTTP requests
|
|
57
|
+
|
|
58
|
+
2. **NAPI Bindings** (`src/lib.rs`):
|
|
59
|
+
- Exposes Rust functions to Node.js
|
|
60
|
+
- Handles async operations with Tokio
|
|
61
|
+
- Provides type-safe JavaScript interop
|
|
62
|
+
|
|
63
|
+
3. **JavaScript Wrapper** (`src/gemini.js`):
|
|
64
|
+
- Attempts to load Rust native bindings
|
|
65
|
+
- Falls back to JavaScript implementation if Rust not available
|
|
66
|
+
- Provides seamless API compatibility
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
### Testing Rust Code
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Run Rust tests
|
|
74
|
+
cargo test
|
|
75
|
+
|
|
76
|
+
# Check Rust code
|
|
77
|
+
cargo clippy
|
|
78
|
+
|
|
79
|
+
# Format Rust code
|
|
80
|
+
cargo fmt
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Development Workflow
|
|
84
|
+
|
|
85
|
+
1. Make changes to Rust code in `src/gemini_client.rs` or `src/lib.rs`
|
|
86
|
+
2. Rebuild: `npm run build:debug`
|
|
87
|
+
3. Test: `npm start --interactive`
|
|
88
|
+
|
|
89
|
+
### Fallback Behavior
|
|
90
|
+
|
|
91
|
+
If Rust bindings aren't available:
|
|
92
|
+
- The CLI automatically falls back to the JavaScript implementation
|
|
93
|
+
- Uses `@google/generative-ai` SDK instead
|
|
94
|
+
- All functionality remains available
|
|
95
|
+
|
|
96
|
+
## Performance Benefits
|
|
97
|
+
|
|
98
|
+
The Rust implementation provides:
|
|
99
|
+
- **Faster HTTP requests** (Rust's async runtime)
|
|
100
|
+
- **Lower memory usage** (no V8 overhead for API calls)
|
|
101
|
+
- **Better error handling** (Rust's type system)
|
|
102
|
+
- **Thread safety** (Tokio async runtime)
|
|
103
|
+
|
|
104
|
+
## Troubleshooting
|
|
105
|
+
|
|
106
|
+
### Rust Not Building
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Ensure Rust is installed
|
|
110
|
+
rustc --version
|
|
111
|
+
|
|
112
|
+
# Update Rust toolchain
|
|
113
|
+
rustup update
|
|
114
|
+
|
|
115
|
+
# Clean and rebuild
|
|
116
|
+
cargo clean
|
|
117
|
+
npm run build
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Module Not Found
|
|
121
|
+
|
|
122
|
+
If you see "Cannot find module '../index.node'":
|
|
123
|
+
- Run `npm run build` to compile Rust bindings
|
|
124
|
+
- Ensure you're on a supported platform
|
|
125
|
+
- Check `package.json` napi configuration
|
|
126
|
+
|
|
127
|
+
### Platform Support
|
|
128
|
+
|
|
129
|
+
Rust bindings are built for:
|
|
130
|
+
- macOS (x86_64, ARM64)
|
|
131
|
+
- Linux (x86_64, ARM64, musl)
|
|
132
|
+
- Windows (x86_64, ARM64)
|
|
133
|
+
|
|
134
|
+
For other platforms, JavaScript fallback will be used.
|
package/RELEASE_NOTES.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Release Notes - Gemini Assist v1.1.1-Beta
|
|
2
|
+
|
|
3
|
+
## 🎉 Gemini Assist v1.1.1-Beta
|
|
4
|
+
|
|
5
|
+
**Release Date:** December 2024
|
|
6
|
+
**Version:** 1.1.1-Beta
|
|
7
|
+
**Status:** Beta Release
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Gemini Assist v1.1.1-Beta is the first beta release of our AI Assistant CLI tool, bringing the power of Google's Gemini AI directly to your terminal. This release focuses on core functionality, ease of use, and a polished command-line experience.
|
|
14
|
+
|
|
15
|
+
## ✨ New Features
|
|
16
|
+
|
|
17
|
+
### Core Functionality
|
|
18
|
+
- **Interactive Chat Mode** - Engage in natural conversations with Gemini AI through an intuitive terminal interface
|
|
19
|
+
- **Single Query Mode** - Quick one-off questions for fast answers without starting a full chat session
|
|
20
|
+
- **Dual Command Support** - Use either `gemini-assist` or the shorter `gassist` alias
|
|
21
|
+
|
|
22
|
+
### API Integration
|
|
23
|
+
- **Full Gemini API Support** - Seamless integration with Google's Generative AI SDK
|
|
24
|
+
- **Multiple Model Support** - Choose between different Gemini models (gemini-pro, gemini-pro-vision)
|
|
25
|
+
- **Configurable Parameters** - Customize temperature and other generation parameters
|
|
26
|
+
|
|
27
|
+
### User Experience
|
|
28
|
+
- **Beautiful CLI Interface** - Colorful, user-friendly terminal output with chalk styling
|
|
29
|
+
- **Welcome Screen** - Professional welcome message on startup
|
|
30
|
+
- **Error Handling** - Comprehensive error messages with helpful troubleshooting tips
|
|
31
|
+
- **Command History** - Maintains conversation context during interactive sessions
|
|
32
|
+
|
|
33
|
+
### Developer Experience
|
|
34
|
+
- **Programmatic API** - Use as an npm package in your Node.js projects
|
|
35
|
+
- **Environment Variable Support** - Secure API key management via .env files
|
|
36
|
+
- **Flexible Configuration** - Multiple ways to configure API keys and options
|
|
37
|
+
|
|
38
|
+
## 🔧 Technical Details
|
|
39
|
+
|
|
40
|
+
### Dependencies
|
|
41
|
+
- `@google/generative-ai` (^0.21.0) - Official Google Generative AI SDK
|
|
42
|
+
- `commander` (^11.1.0) - Command-line interface framework
|
|
43
|
+
- `chalk` (^4.1.2) - Terminal string styling
|
|
44
|
+
- `dotenv` (^16.4.5) - Environment variable management
|
|
45
|
+
|
|
46
|
+
### Architecture
|
|
47
|
+
- Modular design with separate concerns:
|
|
48
|
+
- `bin/gemini-assist.js` - CLI entry point and command handling
|
|
49
|
+
- `src/gemini.js` - Gemini API client and chat logic
|
|
50
|
+
- `src/utils.js` - Utility functions and helpers
|
|
51
|
+
- `index.js` - Programmatic API export
|
|
52
|
+
|
|
53
|
+
### Supported Platforms
|
|
54
|
+
- macOS
|
|
55
|
+
- Linux
|
|
56
|
+
- Windows (with Node.js)
|
|
57
|
+
|
|
58
|
+
## 📋 Usage Examples
|
|
59
|
+
|
|
60
|
+
### Basic Interactive Mode
|
|
61
|
+
```bash
|
|
62
|
+
gemini-assist --interactive
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Single Query
|
|
66
|
+
```bash
|
|
67
|
+
gemini-assist "Explain quantum computing in simple terms"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Custom Configuration
|
|
71
|
+
```bash
|
|
72
|
+
gemini-assist --model gemini-pro --temperature 0.9 --interactive
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 🐛 Known Issues
|
|
76
|
+
|
|
77
|
+
- Chat history is not persisted between sessions
|
|
78
|
+
- No support for file uploads or multimodal inputs in this release
|
|
79
|
+
- Rate limiting errors may occur with free-tier API keys
|
|
80
|
+
|
|
81
|
+
## 🔮 Upcoming Features (Planned)
|
|
82
|
+
|
|
83
|
+
- Chat history persistence
|
|
84
|
+
- Multi-modal support (images, files)
|
|
85
|
+
- Streaming responses for real-time output
|
|
86
|
+
- Custom prompt templates
|
|
87
|
+
- Conversation export/import
|
|
88
|
+
- Plugin system for extensibility
|
|
89
|
+
|
|
90
|
+
## 📝 Installation
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install -g gemini-assist
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 🔑 Getting Started
|
|
97
|
+
|
|
98
|
+
1. Get your API key from [Google AI Studio](https://makersuite.google.com/app/apikey)
|
|
99
|
+
2. Set environment variable: `export GEMINI_API_KEY=your_key`
|
|
100
|
+
3. Run: `gemini-assist --interactive`
|
|
101
|
+
|
|
102
|
+
## ⚠️ Beta Notice
|
|
103
|
+
|
|
104
|
+
This is a beta release. While we've tested the core functionality, you may encounter:
|
|
105
|
+
- Occasional API errors
|
|
106
|
+
- Performance variations
|
|
107
|
+
- Missing features compared to future stable releases
|
|
108
|
+
|
|
109
|
+
We welcome feedback and bug reports to help improve the tool!
|
|
110
|
+
|
|
111
|
+
## 🙏 Acknowledgments
|
|
112
|
+
|
|
113
|
+
- Google Gemini API team for the powerful AI capabilities
|
|
114
|
+
- Open source community for the excellent npm packages used
|
|
115
|
+
|
|
116
|
+
## 📄 License
|
|
117
|
+
|
|
118
|
+
MIT License - See LICENSE file for details
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
**Download:** `npm install -g gemini-assist`
|
|
123
|
+
**Documentation:** See README.md
|
|
124
|
+
**Issues:** Please report via GitHub Issues
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
require('dotenv').config();
|
|
8
|
+
|
|
9
|
+
const { GeminiClient } = require('../src/gemini');
|
|
10
|
+
const { validateApiKey, printWelcome, printError } = require('../src/utils');
|
|
11
|
+
|
|
12
|
+
const packageJson = require('../package.json');
|
|
13
|
+
|
|
14
|
+
// CLI Configuration
|
|
15
|
+
program
|
|
16
|
+
.name('gemini-assist')
|
|
17
|
+
.description('AI Assistant CLI powered by Google Gemini API')
|
|
18
|
+
.version(packageJson.version)
|
|
19
|
+
.option('-k, --api-key <key>', 'Gemini API key (or set GEMINI_API_KEY env variable)')
|
|
20
|
+
.option('-m, --model <model>', 'Gemini model to use (default: gemini-2.5-flash)')
|
|
21
|
+
.option('-i, --interactive', 'Start interactive chat mode', false)
|
|
22
|
+
.option('-t, --temperature <value>', 'Temperature for response (0-1)', '0.7')
|
|
23
|
+
.parse(process.argv);
|
|
24
|
+
|
|
25
|
+
const options = program.opts();
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
try {
|
|
29
|
+
// Get API key
|
|
30
|
+
const apiKey = options.apiKey || process.env.GEMINI_API_KEY;
|
|
31
|
+
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
printError('API key is required. Set GEMINI_API_KEY environment variable or use --api-key flag.');
|
|
34
|
+
console.log(chalk.yellow('\nTo get your API key:'));
|
|
35
|
+
console.log(chalk.cyan(' 1. Visit https://makersuite.google.com/app/apikey'));
|
|
36
|
+
console.log(chalk.cyan(' 2. Create a new API key'));
|
|
37
|
+
console.log(chalk.cyan(' 3. Create a .env file in the project root:'));
|
|
38
|
+
console.log(chalk.gray(' cp .env.example .env'));
|
|
39
|
+
console.log(chalk.cyan(' 4. Add your API key to .env file:'));
|
|
40
|
+
console.log(chalk.gray(' GEMINI_API_KEY=your_key_here'));
|
|
41
|
+
console.log(chalk.cyan(' OR set it as environment variable:'));
|
|
42
|
+
console.log(chalk.gray(' export GEMINI_API_KEY=your_key_here\n'));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!validateApiKey(apiKey)) {
|
|
47
|
+
printError('Invalid API key format. Please check your API key.');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Initialize Gemini client
|
|
52
|
+
const client = new GeminiClient(apiKey, {
|
|
53
|
+
model: options.model,
|
|
54
|
+
temperature: parseFloat(options.temperature)
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Interactive mode
|
|
58
|
+
if (options.interactive || process.argv.length === 2) {
|
|
59
|
+
await startInteractiveMode(client);
|
|
60
|
+
} else {
|
|
61
|
+
// Single query mode
|
|
62
|
+
const query = program.args.join(' ');
|
|
63
|
+
if (!query) {
|
|
64
|
+
printError('Please provide a query or use --interactive mode.');
|
|
65
|
+
program.help();
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const response = await client.chat(query);
|
|
70
|
+
console.log(chalk.green('\n' + response + '\n'));
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
printError(`Error: ${error.message}`);
|
|
74
|
+
if (process.env.DEBUG) {
|
|
75
|
+
console.error(error);
|
|
76
|
+
}
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function startInteractiveMode(client) {
|
|
82
|
+
printWelcome();
|
|
83
|
+
|
|
84
|
+
const rl = readline.createInterface({
|
|
85
|
+
input: process.stdin,
|
|
86
|
+
output: process.stdout,
|
|
87
|
+
prompt: chalk.cyan('You> ')
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
console.log(chalk.gray('Type your message and press Enter. Type "exit", "quit", or "bye" to end the conversation.\n'));
|
|
91
|
+
|
|
92
|
+
rl.prompt();
|
|
93
|
+
|
|
94
|
+
rl.on('line', async (input) => {
|
|
95
|
+
const query = input.trim();
|
|
96
|
+
|
|
97
|
+
if (!query) {
|
|
98
|
+
rl.prompt();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Exit commands
|
|
103
|
+
if (['exit', 'quit', 'bye', 'q'].includes(query.toLowerCase())) {
|
|
104
|
+
console.log(chalk.yellow('\nGoodbye! 👋\n'));
|
|
105
|
+
rl.close();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Clear command
|
|
110
|
+
if (query.toLowerCase() === 'clear') {
|
|
111
|
+
console.clear();
|
|
112
|
+
printWelcome();
|
|
113
|
+
rl.prompt();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Show thinking indicator
|
|
118
|
+
process.stdout.write(chalk.gray('Gemini> '));
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const response = await client.chat(query);
|
|
122
|
+
console.log(chalk.green(response) + '\n');
|
|
123
|
+
} catch (error) {
|
|
124
|
+
printError(`Error: ${error.message}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
rl.prompt();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
rl.on('close', () => {
|
|
131
|
+
process.exit(0);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Run the CLI
|
|
136
|
+
main();
|
package/build.rs
ADDED
package/gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test-*.js
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
export declare function validateApiKeyRust(apiKey: string): boolean
|
|
7
|
+
export declare function rustVersion(): string
|
|
8
|
+
export declare class RustGeminiClient {
|
|
9
|
+
constructor(apiKey: string, modelName?: string | undefined | null, temperature?: number | undefined | null)
|
|
10
|
+
chat(prompt: string): Promise<string>
|
|
11
|
+
clearHistory(): Promise<void>
|
|
12
|
+
getHistoryCount(): Promise<number>
|
|
13
|
+
}
|