opencode-rag-plugin 2.13.0 → 2.13.1
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 +16 -0
- package/dist/core/config.d.ts +16 -7
- package/dist/core/config.js +4 -1
- package/dist/decision/systemone.d.ts +2 -1
- package/dist/decision/systemone.js +27 -4
- package/dist/safety/shell-guard.js +4 -1
- package/package.json +1 -1
package/ReadMe.md
CHANGED
|
@@ -310,6 +310,22 @@ Requires Ollama ≥ 0.35. **Disabled by default.** Opt in via `decision.enabled`
|
|
|
310
310
|
}
|
|
311
311
|
```
|
|
312
312
|
|
|
313
|
+
`decision.baseUrl` accepts a root URL, an `/api`-suffixed URL, or an `/v1`-suffixed URL - both suffixes are stripped, so requests always go to `<root>/v1/systemone`. Any server exposing that route works, for example **llama-swap**:
|
|
314
|
+
|
|
315
|
+
```json
|
|
316
|
+
{
|
|
317
|
+
"decision": {
|
|
318
|
+
"enabled": true,
|
|
319
|
+
"provider": "ollama",
|
|
320
|
+
"baseUrl": "http://127.0.0.1:11437",
|
|
321
|
+
"model": "Clef-Flash",
|
|
322
|
+
"apiKey": "sk-llama-local"
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
`decision.apiKey` is sent as `Authorization: Bearer <key>` and is required when the server protects its routes (llama-swap's `api_key`).
|
|
328
|
+
|
|
313
329
|
**Using it well**
|
|
314
330
|
|
|
315
331
|
- Always include a `none` / "cannot be determined" option.
|
package/dist/core/config.d.ts
CHANGED
|
@@ -235,14 +235,21 @@ export interface DecisionConfig {
|
|
|
235
235
|
/** Decision provider name. Only "ollama" is supported for now. */
|
|
236
236
|
provider: string;
|
|
237
237
|
/**
|
|
238
|
-
* Base URL of the
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
238
|
+
* Base URL of the decision server. Root URLs (`http://127.0.0.1:11434`),
|
|
239
|
+
* the `/api`-suffixed convention used by the other sections, and the
|
|
240
|
+
* `/v1`-suffixed convention used by OpenAI-compatible servers (e.g.
|
|
241
|
+
* llama-swap) are accepted - the suffixes are stripped because decision
|
|
242
|
+
* models are served at `/v1/systemone`.
|
|
242
243
|
*/
|
|
243
244
|
baseUrl: string;
|
|
244
245
|
/** Decision model name (`tev1`/`tev1:4b` or `tev1:0.8b`). */
|
|
245
246
|
model: string;
|
|
247
|
+
/**
|
|
248
|
+
* Optional bearer key for the decision endpoint. Some servers (e.g.
|
|
249
|
+
* llama-swap) protect every route with an API key; when set, requests
|
|
250
|
+
* carry `Authorization: Bearer <apiKey>`.
|
|
251
|
+
*/
|
|
252
|
+
apiKey?: string;
|
|
246
253
|
/** Request timeout in milliseconds. The first call may load the model. */
|
|
247
254
|
timeoutMs: number;
|
|
248
255
|
/** Ollama keep_alive value (e.g. "30m", "-1" for keep-in-memory). */
|
|
@@ -274,13 +281,13 @@ export interface DecisionConfig {
|
|
|
274
281
|
* `destructive` or `malicious` probability reaches `threshold` is escalated to
|
|
275
282
|
* OpenCode's permission prompt; a clean command executes unchanged.
|
|
276
283
|
*
|
|
277
|
-
* The guard reuses the `decision` backend unless `provider`/`baseUrl`/`model
|
|
278
|
-
* override it here. It is applied through OpenCode V2's permission
|
|
284
|
+
* The guard reuses the `decision` backend unless `provider`/`baseUrl`/`model`/
|
|
285
|
+
* `apiKey` override it here. It is applied through OpenCode V2's permission
|
|
279
286
|
* `evaluate` hook, so it needs no rule changes in `opencode.json`.
|
|
280
287
|
*/
|
|
281
288
|
export interface ShellGuardConfig {
|
|
282
289
|
/**
|
|
283
|
-
* Master gate. Default false
|
|
290
|
+
* Master gate. Default false - the guard is opt-in because every shell
|
|
284
291
|
* command then waits for the local decision model.
|
|
285
292
|
*/
|
|
286
293
|
enabled: boolean;
|
|
@@ -290,6 +297,8 @@ export interface ShellGuardConfig {
|
|
|
290
297
|
baseUrl?: string;
|
|
291
298
|
/** Model override (defaults to `decision.model`). */
|
|
292
299
|
model?: string;
|
|
300
|
+
/** API-key override (defaults to `decision.apiKey`). */
|
|
301
|
+
apiKey?: string;
|
|
293
302
|
/**
|
|
294
303
|
* Flag a command when `p(destructive)` or `p(malicious)` reaches this
|
|
295
304
|
* probability (0-1). Default 0.5. Lower = more prompts; tune against the
|
package/dist/core/config.js
CHANGED
|
@@ -651,6 +651,9 @@ export function validateConfig(config) {
|
|
|
651
651
|
if (config.decision.maxStateChars != null && config.decision.maxStateChars <= 0) {
|
|
652
652
|
warnings.push("decision.maxStateChars must be > 0");
|
|
653
653
|
}
|
|
654
|
+
if (config.decision.apiKey != null && typeof config.decision.apiKey !== "string") {
|
|
655
|
+
warnings.push("decision.apiKey must be a string when set");
|
|
656
|
+
}
|
|
654
657
|
try {
|
|
655
658
|
new URL(config.decision.baseUrl);
|
|
656
659
|
}
|
|
@@ -675,7 +678,7 @@ export function validateConfig(config) {
|
|
|
675
678
|
if (sg.maxCacheEntries != null && (typeof sg.maxCacheEntries !== "number" || !Number.isFinite(sg.maxCacheEntries) || sg.maxCacheEntries < 0)) {
|
|
676
679
|
warnings.push("shellGuard.maxCacheEntries must be >= 0");
|
|
677
680
|
}
|
|
678
|
-
for (const key of ["provider", "baseUrl", "model"]) {
|
|
681
|
+
for (const key of ["provider", "baseUrl", "model", "apiKey"]) {
|
|
679
682
|
if (sg[key] != null && typeof sg[key] !== "string") {
|
|
680
683
|
warnings.push(`shellGuard.${key} must be a string when set`);
|
|
681
684
|
}
|
|
@@ -42,13 +42,14 @@ export declare class OllamaDecisionProvider implements DecisionProvider {
|
|
|
42
42
|
readonly name = "ollama";
|
|
43
43
|
private readonly baseUrl;
|
|
44
44
|
private readonly model;
|
|
45
|
+
private readonly apiKey?;
|
|
45
46
|
private readonly timeoutMs;
|
|
46
47
|
private readonly keepAlive?;
|
|
47
48
|
private readonly proxy?;
|
|
48
49
|
private readonly retryMax;
|
|
49
50
|
private readonly retryBaseDelayMs;
|
|
50
51
|
/**
|
|
51
|
-
* @param config - Decision-model configuration (endpoint, model, timeout, proxy, retries).
|
|
52
|
+
* @param config - Decision-model configuration (endpoint, model, api key, timeout, proxy, retries).
|
|
52
53
|
*/
|
|
53
54
|
constructor(config: DecisionConfig);
|
|
54
55
|
/**
|
|
@@ -22,7 +22,21 @@ export const SYSTEMONE_MAX_OPTIONS = 24;
|
|
|
22
22
|
*/
|
|
23
23
|
export function resolveSystemOneUrl(baseUrl) {
|
|
24
24
|
const trimmed = baseUrl.replace(/\/+$/, "");
|
|
25
|
-
|
|
25
|
+
// Accept root, the `/api` suffix used by the embedding/description
|
|
26
|
+
// sections, and the `/v1` suffix used by OpenAI-compatible servers
|
|
27
|
+
// (e.g. llama-swap). Both suffixes are stripped because the decision
|
|
28
|
+
// route is `/v1/systemone`.
|
|
29
|
+
let root = trimmed;
|
|
30
|
+
let changed = true;
|
|
31
|
+
while (changed) {
|
|
32
|
+
changed = false;
|
|
33
|
+
for (const suffix of ["/api", "/v1"]) {
|
|
34
|
+
if (root.endsWith(suffix)) {
|
|
35
|
+
root = root.slice(0, -suffix.length).replace(/\/+$/, "");
|
|
36
|
+
changed = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
26
40
|
return `${root}/v1/systemone`;
|
|
27
41
|
}
|
|
28
42
|
/** Coerce a number-or-numeric-string to a finite number, else undefined. */
|
|
@@ -117,17 +131,19 @@ export class OllamaDecisionProvider {
|
|
|
117
131
|
name = "ollama";
|
|
118
132
|
baseUrl;
|
|
119
133
|
model;
|
|
134
|
+
apiKey;
|
|
120
135
|
timeoutMs;
|
|
121
136
|
keepAlive;
|
|
122
137
|
proxy;
|
|
123
138
|
retryMax;
|
|
124
139
|
retryBaseDelayMs;
|
|
125
140
|
/**
|
|
126
|
-
* @param config - Decision-model configuration (endpoint, model, timeout, proxy, retries).
|
|
141
|
+
* @param config - Decision-model configuration (endpoint, model, api key, timeout, proxy, retries).
|
|
127
142
|
*/
|
|
128
143
|
constructor(config) {
|
|
129
144
|
this.baseUrl = config.baseUrl;
|
|
130
145
|
this.model = config.model;
|
|
146
|
+
this.apiKey = config.apiKey?.trim() || undefined;
|
|
131
147
|
this.timeoutMs = config.timeoutMs > 0 ? config.timeoutMs : 120000;
|
|
132
148
|
this.keepAlive = config.keepAlive;
|
|
133
149
|
this.proxy = config.proxy;
|
|
@@ -163,11 +179,14 @@ export class OllamaDecisionProvider {
|
|
|
163
179
|
`Shorten \`state\` or ask fewer questions.`);
|
|
164
180
|
}
|
|
165
181
|
const url = resolveSystemOneUrl(this.baseUrl);
|
|
182
|
+
const headers = this.apiKey
|
|
183
|
+
? { Authorization: `Bearer ${this.apiKey}` }
|
|
184
|
+
: {};
|
|
166
185
|
let lastError;
|
|
167
186
|
for (let attempt = 0; attempt <= this.retryMax; attempt++) {
|
|
168
187
|
let response;
|
|
169
188
|
try {
|
|
170
|
-
response = await postJson(url, body,
|
|
189
|
+
response = await postJson(url, body, headers, this.timeoutMs, this.proxy, abort);
|
|
171
190
|
}
|
|
172
191
|
catch (err) {
|
|
173
192
|
lastError = err instanceof Error ? err : new Error(String(err));
|
|
@@ -211,6 +230,10 @@ export class OllamaDecisionProvider {
|
|
|
211
230
|
*/
|
|
212
231
|
describeHttpError(status, text) {
|
|
213
232
|
const detail = truncate(text);
|
|
233
|
+
if (status === 401 || status === 403) {
|
|
234
|
+
return (`Decision endpoint unauthorized (${status}) - the server requires an API key. ` +
|
|
235
|
+
`Set \`decision.apiKey\` (e.g. llama-swap's "api_key"). ${detail}`);
|
|
236
|
+
}
|
|
214
237
|
if (status === 404) {
|
|
215
238
|
const lower = text.toLowerCase();
|
|
216
239
|
const modelLower = this.model.toLowerCase();
|
|
@@ -223,7 +246,7 @@ export class OllamaDecisionProvider {
|
|
|
223
246
|
return (`Decision request not found (404) — tev1 requires Ollama >= 0.35 and the model must be pulled ` +
|
|
224
247
|
`(\`ollama pull ${this.model}\`). ${detail}`);
|
|
225
248
|
}
|
|
226
|
-
return `
|
|
249
|
+
return `Decision request failed (${status}): ${detail}`;
|
|
227
250
|
}
|
|
228
251
|
/** Exponential backoff between retries. */
|
|
229
252
|
sleep(attempt) {
|
|
@@ -197,7 +197,9 @@ export class ShellGuard {
|
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
const { guard, decision, logging } = cfg;
|
|
200
|
-
|
|
200
|
+
// The API key participates in the signature so a key change rebuilds the
|
|
201
|
+
// provider (the key never leaves this in-memory cache/state).
|
|
202
|
+
const signature = `${decision.provider}|${decision.baseUrl}|${decision.model}|${decision.apiKey ?? ""}`;
|
|
201
203
|
const cacheKey = `${signature}\u0000${command}`;
|
|
202
204
|
const cacheTtlMs = guard.cacheTtlMs ?? 0;
|
|
203
205
|
if (cacheTtlMs > 0) {
|
|
@@ -360,6 +362,7 @@ export function resolveShellGuardRuntimeConfig(cfg, directory) {
|
|
|
360
362
|
provider: guard.provider?.trim() || base.provider,
|
|
361
363
|
baseUrl: guard.baseUrl?.trim() || base.baseUrl,
|
|
362
364
|
model: guard.model?.trim() || base.model,
|
|
365
|
+
apiKey: guard.apiKey?.trim() || base.apiKey,
|
|
363
366
|
};
|
|
364
367
|
const log = resolveLogConfig(cfg);
|
|
365
368
|
return {
|