@azumag/opencode-rate-limit-fallback 1.19.2 → 1.21.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/README.md +132 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +59 -968
- package/dist/logger.d.ts +0 -1
- package/dist/logger.js +0 -1
- package/package.json +5 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ OpenCode plugin that automatically switches to fallback models when rate limited
|
|
|
15
15
|
- Toast notifications for user feedback
|
|
16
16
|
- Subagent session support with automatic fallback propagation to parent sessions
|
|
17
17
|
- Configurable maximum subagent nesting depth
|
|
18
|
+
- **Metrics collection** to track rate limits, fallbacks, and model performance
|
|
18
19
|
|
|
19
20
|
## Installation
|
|
20
21
|
|
|
@@ -62,7 +63,15 @@ Create a configuration file at one of these locations:
|
|
|
62
63
|
{ "providerID": "anthropic", "modelID": "claude-3-5-sonnet-20250514" },
|
|
63
64
|
{ "providerID": "google", "modelID": "gemini-2.5-pro" },
|
|
64
65
|
{ "providerID": "google", "modelID": "gemini-2.5-flash" }
|
|
65
|
-
]
|
|
66
|
+
],
|
|
67
|
+
"metrics": {
|
|
68
|
+
"enabled": true,
|
|
69
|
+
"output": {
|
|
70
|
+
"console": true,
|
|
71
|
+
"format": "pretty"
|
|
72
|
+
},
|
|
73
|
+
"resetInterval": "daily"
|
|
74
|
+
}
|
|
66
75
|
}
|
|
67
76
|
```
|
|
68
77
|
|
|
@@ -122,6 +131,128 @@ When OpenCode uses subagents (e.g., for complex tasks requiring specialized agen
|
|
|
122
131
|
| `maxSubagentDepth` | number | `10` | Maximum nesting depth for subagent hierarchies |
|
|
123
132
|
| `enableSubagentFallback` | boolean | `true` | Enable/disable fallback for subagent sessions |
|
|
124
133
|
|
|
134
|
+
## Metrics
|
|
135
|
+
|
|
136
|
+
The plugin includes a metrics collection feature that tracks:
|
|
137
|
+
- Rate limit events per provider/model
|
|
138
|
+
- Fallback statistics (total, successful, failed, average duration)
|
|
139
|
+
- Model performance (requests, successes, failures, response time)
|
|
140
|
+
|
|
141
|
+
### Metrics Configuration
|
|
142
|
+
|
|
143
|
+
Metrics can be configured via the `metrics` section in your config file:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"metrics": {
|
|
148
|
+
"enabled": true,
|
|
149
|
+
"output": {
|
|
150
|
+
"console": true,
|
|
151
|
+
"file": "/path/to/metrics.json",
|
|
152
|
+
"format": "pretty"
|
|
153
|
+
},
|
|
154
|
+
"resetInterval": "daily"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Metrics Options
|
|
160
|
+
|
|
161
|
+
| Option | Type | Default | Description |
|
|
162
|
+
|--------|------|---------|-------------|
|
|
163
|
+
| `enabled` | boolean | `false` | Enable/disable metrics collection |
|
|
164
|
+
| `output.console` | boolean | `true` | Print metrics to console |
|
|
165
|
+
| `output.file` | string | `undefined` | Path to save metrics file |
|
|
166
|
+
| `output.format` | string | `"pretty"` | Output format: `"pretty"`, `"json"`, or `"csv"` |
|
|
167
|
+
| `resetInterval` | string | `"daily"` | Reset interval: `"hourly"`, `"daily"`, or `"weekly"` |
|
|
168
|
+
|
|
169
|
+
### Output Formats
|
|
170
|
+
|
|
171
|
+
**Pretty** (human-readable):
|
|
172
|
+
```
|
|
173
|
+
============================================================
|
|
174
|
+
Rate Limit Fallback Metrics
|
|
175
|
+
============================================================
|
|
176
|
+
Started: 2025-02-10T02:00:00.000Z
|
|
177
|
+
Generated: 2025-02-10T02:30:00.000Z
|
|
178
|
+
|
|
179
|
+
Rate Limits:
|
|
180
|
+
----------------------------------------
|
|
181
|
+
anthropic/claude-3-5-sonnet-20250514:
|
|
182
|
+
Count: 5
|
|
183
|
+
First: 2025-02-10T02:00:00.000Z
|
|
184
|
+
Last: 2025-02-10T02:29:00.000Z
|
|
185
|
+
Avg Interval: 3.50s
|
|
186
|
+
|
|
187
|
+
Fallbacks:
|
|
188
|
+
----------------------------------------
|
|
189
|
+
Total: 3
|
|
190
|
+
Successful: 2
|
|
191
|
+
Failed: 1
|
|
192
|
+
Avg Duration: 1.25s
|
|
193
|
+
|
|
194
|
+
Model Performance:
|
|
195
|
+
----------------------------------------
|
|
196
|
+
google/gemini-2.5-pro:
|
|
197
|
+
Requests: 10
|
|
198
|
+
Successes: 9
|
|
199
|
+
Failures: 1
|
|
200
|
+
Avg Response: 0.85s
|
|
201
|
+
Success Rate: 90.0%
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**JSON** (machine-readable):
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"rateLimits": {
|
|
208
|
+
"anthropic/claude-3-5-sonnet-20250514": {
|
|
209
|
+
"count": 5,
|
|
210
|
+
"firstOccurrence": 1739148000000,
|
|
211
|
+
"lastOccurrence": 1739149740000,
|
|
212
|
+
"averageInterval": 3500
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"fallbacks": {
|
|
216
|
+
"total": 3,
|
|
217
|
+
"successful": 2,
|
|
218
|
+
"failed": 1,
|
|
219
|
+
"averageDuration": 1250,
|
|
220
|
+
"byTargetModel": {
|
|
221
|
+
"google/gemini-2.5-pro": {
|
|
222
|
+
"usedAsFallback": 2,
|
|
223
|
+
"successful": 2,
|
|
224
|
+
"failed": 0
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
"modelPerformance": {
|
|
229
|
+
"google/gemini-2.5-pro": {
|
|
230
|
+
"requests": 10,
|
|
231
|
+
"successes": 9,
|
|
232
|
+
"failures": 1,
|
|
233
|
+
"averageResponseTime": 850
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
"startedAt": 1739148000000,
|
|
237
|
+
"generatedAt": 1739149800000
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**CSV** (spreadsheet-friendly):
|
|
242
|
+
```
|
|
243
|
+
=== RATE_LIMITS ===
|
|
244
|
+
model,count,first_occurrence,last_occurrence,avg_interval_ms
|
|
245
|
+
anthropic/claude-3-5-sonnet-20250514,5,1739148000000,1739149740000,3500
|
|
246
|
+
|
|
247
|
+
=== FALLBACKS_SUMMARY ===
|
|
248
|
+
total,successful,failed,avg_duration_ms
|
|
249
|
+
3,2,1,1250
|
|
250
|
+
|
|
251
|
+
=== MODEL_PERFORMANCE ===
|
|
252
|
+
model,requests,successes,failures,avg_response_time_ms,success_rate
|
|
253
|
+
google/gemini-2.5-pro,10,9,1,850,90.0
|
|
254
|
+
```
|
|
255
|
+
|
|
125
256
|
## License
|
|
126
257
|
|
|
127
258
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limit Fallback Plugin - Main entry point
|
|
3
|
+
*
|
|
4
|
+
* This plugin automatically switches to fallback models when rate limited
|
|
5
|
+
*/
|
|
1
6
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
7
|
export declare const RateLimitFallback: Plugin;
|
|
3
8
|
export default RateLimitFallback;
|
|
4
|
-
|
|
9
|
+
export type { PluginConfig, MetricsConfig, FallbackModel, FallbackMode } from "./src/types/index.js";
|
|
10
|
+
export { MetricsManager } from "./src/metrics/MetricsManager.js";
|
|
11
|
+
export { createLogger, type LogConfig, type Logger } from "./logger.js";
|