opencode-morphllm 0.0.9 → 0.0.10
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 +149 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,62 +4,189 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/opencode-morphllm)
|
|
5
5
|
[](https://www.npmjs.com/package/opencode-morphllm)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
An [OpenCode](https://opencode.ai/) plugin that integrates [MorphLLM](https://morphllm.com/)'s intelligent model routing and powerful MCP tools into your AI coding workflow.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- **GitHub**: https://github.com/VitoLin/opencode-morphllm
|
|
10
|
+
- **NPM**: https://www.npmjs.com/package/opencode-morphllm
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
### Intelligent Model Router
|
|
15
|
+
|
|
16
|
+
Automatically classifies your prompts by complexity (easy/medium/hard) and routes them to the most cost-effective and appropriate model. Save money on simple tasks while using powerful models only when needed.
|
|
17
|
+
|
|
18
|
+
### MCP Tools
|
|
19
|
+
|
|
20
|
+
Adds MorphLLM's specialized MCP tools to OpenCode:
|
|
21
|
+
|
|
22
|
+
- **`edit_file`** - Fast, precise file editing tool optimized for code modifications
|
|
23
|
+
- **`warpgrep_codebase_search`** - Advanced codebase search with contextual understanding
|
|
24
|
+
|
|
25
|
+
### Prompt Caching Optimization
|
|
26
|
+
|
|
27
|
+
Optional mode that maintains model consistency within a session, reducing costs through prompt caching.
|
|
12
28
|
|
|
13
29
|
## Installation
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
### 1. Install the Plugin
|
|
16
32
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
Add the plugin to your OpenCode configuration at `~/.config/opencode/opencode.json`:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"plugins": ["opencode-morphllm"]
|
|
38
|
+
}
|
|
21
39
|
```
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
### 2. Configure MorphLLM
|
|
24
42
|
|
|
25
|
-
|
|
43
|
+
Create a configuration file at `~/.config/opencode/morph.json`:
|
|
26
44
|
|
|
27
45
|
```json
|
|
28
46
|
{
|
|
29
|
-
"MORPH_API_KEY": "
|
|
47
|
+
"MORPH_API_KEY": "your_morph_api_key_here",
|
|
30
48
|
"MORPH_ROUTER_CONFIGS": {
|
|
31
49
|
"MORPH_MODEL_EASY": "github-copilot/gpt-5-mini",
|
|
32
50
|
"MORPH_MODEL_MEDIUM": "opencode/minimax-m2.1-free",
|
|
33
51
|
"MORPH_MODEL_HARD": "github-copilot/gemini-2.5-pro",
|
|
34
52
|
"MORPH_ROUTER_ENABLED": true,
|
|
35
|
-
"MORPH_ROUTER_PROMPT_CACHING_AWARE":
|
|
53
|
+
"MORPH_ROUTER_PROMPT_CACHING_AWARE": false
|
|
36
54
|
}
|
|
37
55
|
}
|
|
38
56
|
```
|
|
39
57
|
|
|
40
|
-
|
|
58
|
+
Find available models at [models.dev](https://models.dev).
|
|
59
|
+
|
|
60
|
+
## Configuration Reference
|
|
61
|
+
|
|
62
|
+
### Core Settings
|
|
63
|
+
|
|
64
|
+
| Option | Description | Required |
|
|
65
|
+
| --------------- | --------------------- | -------- |
|
|
66
|
+
| `MORPH_API_KEY` | Your MorphLLM API key | Yes |
|
|
67
|
+
|
|
68
|
+
### Router Settings (inside `MORPH_ROUTER_CONFIGS`)
|
|
69
|
+
|
|
70
|
+
| Option | Description | Default |
|
|
71
|
+
| ----------------------------------- | --------------------------------------------------------- | -------------------- |
|
|
72
|
+
| `MORPH_ROUTER_ENABLED` | Enable/disable the intelligent router | `true` |
|
|
73
|
+
| `MORPH_MODEL_EASY` | Model for easy prompts (simple questions, formatting) | - |
|
|
74
|
+
| `MORPH_MODEL_MEDIUM` | Model for medium prompts (standard coding tasks) | - |
|
|
75
|
+
| `MORPH_MODEL_HARD` | Model for hard prompts (complex architecture, debugging) | - |
|
|
76
|
+
| `MORPH_MODEL_DEFAULT` | Fallback model when classification fails | `MORPH_MODEL_MEDIUM` |
|
|
77
|
+
| `MORPH_ROUTER_PROMPT_CACHING_AWARE` | Stick to first model per session for caching optimization | `false` |
|
|
78
|
+
|
|
79
|
+
### Model Format
|
|
80
|
+
|
|
81
|
+
Models are specified as `provider/model-id`. Examples:
|
|
82
|
+
|
|
83
|
+
- `github-copilot/gpt-5-mini`
|
|
84
|
+
- `github-copilot/gemini-2.5-pro`
|
|
85
|
+
- `opencode/minimax-m2.1-free`
|
|
86
|
+
|
|
87
|
+
### Legacy Format
|
|
88
|
+
|
|
89
|
+
For backward compatibility, you can also use flat configuration:
|
|
41
90
|
|
|
42
91
|
```json
|
|
43
92
|
{
|
|
44
|
-
"MORPH_API_KEY": "
|
|
93
|
+
"MORPH_API_KEY": "your_key",
|
|
45
94
|
"MORPH_MODEL_EASY": "github-copilot/gpt-5-mini",
|
|
46
95
|
"MORPH_MODEL_MEDIUM": "opencode/minimax-m2.1-free",
|
|
47
96
|
"MORPH_MODEL_HARD": "github-copilot/gemini-2.5-pro",
|
|
48
|
-
"MORPH_ROUTER_ENABLED": true
|
|
49
|
-
"MORPH_ROUTER_PROMPT_CACHING_AWARE": true
|
|
97
|
+
"MORPH_ROUTER_ENABLED": true
|
|
50
98
|
}
|
|
51
99
|
```
|
|
52
100
|
|
|
101
|
+
### Project-Level Configuration
|
|
102
|
+
|
|
103
|
+
You can also configure per-project settings by creating `.opencode/morph.json` in your project root. Project settings override user settings.
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
my-project/
|
|
107
|
+
├── .opencode/
|
|
108
|
+
│ └── morph.json # Project-specific Morph config
|
|
109
|
+
└── src/
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Both `.json` and `.jsonc` (with comments) formats are supported.
|
|
113
|
+
|
|
114
|
+
## How It Works
|
|
115
|
+
|
|
116
|
+
### Intelligent Routing
|
|
117
|
+
|
|
118
|
+
When you send a prompt, the plugin:
|
|
119
|
+
|
|
120
|
+
1. **Classifies** the prompt complexity using MorphLLM's classification engine
|
|
121
|
+
2. **Selects** the appropriate model based on your configuration
|
|
122
|
+
3. **Routes** the request to the chosen model
|
|
123
|
+
|
|
124
|
+
Example routing:
|
|
125
|
+
|
|
126
|
+
- "Format this JSON" → Easy → `MORPH_MODEL_EASY` (cheaper, faster)
|
|
127
|
+
- "Add a React component" → Medium → `MORPH_MODEL_MEDIUM`
|
|
128
|
+
- "Debug this race condition" → Hard → `MORPH_MODEL_HARD` (powerful)
|
|
129
|
+
|
|
130
|
+
### Prompt Caching Mode
|
|
131
|
+
|
|
132
|
+
When `MORPH_ROUTER_PROMPT_CACHING_AWARE` is enabled:
|
|
133
|
+
|
|
134
|
+
- The first prompt in a session determines the model for all subsequent prompts
|
|
135
|
+
- Reduces costs through prompt caching with compatible providers
|
|
136
|
+
- Best for long conversations on similar topics
|
|
137
|
+
|
|
53
138
|
## Development
|
|
54
139
|
|
|
55
|
-
|
|
140
|
+
To work on the plugin locally:
|
|
56
141
|
|
|
57
|
-
|
|
142
|
+
1. Clone the repository
|
|
143
|
+
2. Point OpenCode to your local copy in `~/.config/opencode/opencode.json`:
|
|
58
144
|
|
|
59
145
|
```json
|
|
60
|
-
|
|
61
|
-
"/path/to/morph-opencode-plugin/"
|
|
62
|
-
|
|
146
|
+
{
|
|
147
|
+
"plugins": ["/path/to/morph-opencode-plugin/"]
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
3. Changes are immediately reflected when you run OpenCode
|
|
152
|
+
|
|
153
|
+
### Scripts
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Build
|
|
157
|
+
bun run build
|
|
158
|
+
|
|
159
|
+
# Test
|
|
160
|
+
bun test
|
|
161
|
+
|
|
162
|
+
# Format
|
|
163
|
+
bun run format
|
|
63
164
|
```
|
|
64
165
|
|
|
65
|
-
|
|
166
|
+
## Troubleshooting
|
|
167
|
+
|
|
168
|
+
### Plugin not loading
|
|
169
|
+
|
|
170
|
+
Ensure the plugin is properly listed in your OpenCode config:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"plugins": ["opencode-morphllm"]
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Router not working
|
|
179
|
+
|
|
180
|
+
Check that:
|
|
181
|
+
|
|
182
|
+
1. `MORPH_API_KEY` is set correctly
|
|
183
|
+
2. `MORPH_ROUTER_ENABLED` is not set to `false`
|
|
184
|
+
3. At least one model is configured
|
|
185
|
+
|
|
186
|
+
### Where to find models
|
|
187
|
+
|
|
188
|
+
Visit [models.dev](https://models.dev) to browse available models and their IDs.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
[MIT](LICENSE)
|