@mtayfur/opencode-prompt-enhancer 1.0.1 → 1.0.2
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 +6 -5
- package/dist/plugins/prompt-enhancer.js +16 -11
- package/package.json +1 -1
- package/plugins/prompt-enhancer.tsx +15 -13
package/README.md
CHANGED
|
@@ -49,23 +49,24 @@ OpenCode `>=1.18.12 <2` is required.
|
|
|
49
49
|
|
|
50
50
|
Restart OpenCode after changing the plugin configuration.
|
|
51
51
|
|
|
52
|
-
## Model
|
|
52
|
+
## Model
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
The enhancer uses OpenCode's `small_model` when `model` is not set.
|
|
55
55
|
|
|
56
56
|
```jsonc
|
|
57
57
|
{
|
|
58
58
|
"plugin": [
|
|
59
59
|
[
|
|
60
60
|
"@mtayfur/opencode-prompt-enhancer@latest",
|
|
61
|
-
{
|
|
61
|
+
{
|
|
62
|
+
"model": "anthropic/claude-sonnet-4-6",
|
|
63
|
+
"variant": "high"
|
|
64
|
+
}
|
|
62
65
|
]
|
|
63
66
|
]
|
|
64
67
|
}
|
|
65
68
|
```
|
|
66
69
|
|
|
67
|
-
The same options object can be added to a local plugin entry. Restart OpenCode after changing the model.
|
|
68
|
-
|
|
69
70
|
## Use
|
|
70
71
|
|
|
71
72
|
1. Open OpenCode in a workspace.
|
|
@@ -79,16 +79,18 @@ function indentContextContinuation(text, indentation) {
|
|
|
79
79
|
}
|
|
80
80
|
function resolveEnhancerModel(api, options) {
|
|
81
81
|
const modelOverride = typeof options?.model === "string" ? options.model : undefined;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
api.ui.toast({
|
|
86
|
-
variant: "warning",
|
|
87
|
-
title: TOAST_TITLE,
|
|
88
|
-
message: `Invalid model override ${JSON.stringify(modelOverride)}; expected "provider/model". Using default model.`
|
|
89
|
-
});
|
|
82
|
+
const model = modelOverride ? parseModelString(modelOverride) : parseModelString(api.state.config.small_model);
|
|
83
|
+
if (modelOverride && !model) {
|
|
84
|
+
throw new Error(`Invalid model override ${JSON.stringify(modelOverride)}; expected "provider/model".`);
|
|
90
85
|
}
|
|
91
|
-
|
|
86
|
+
if (!model) throw new Error("OpenCode small_model is not configured.");
|
|
87
|
+
const variant = typeof options?.variant === "string" && options.variant.trim() ? options.variant.trim() : undefined;
|
|
88
|
+
return {
|
|
89
|
+
model,
|
|
90
|
+
...(variant ? {
|
|
91
|
+
variant
|
|
92
|
+
} : {})
|
|
93
|
+
};
|
|
92
94
|
}
|
|
93
95
|
function clonePromptInfo(prompt) {
|
|
94
96
|
return {
|
|
@@ -290,7 +292,7 @@ function gatherContext(api) {
|
|
|
290
292
|
}
|
|
291
293
|
async function enhanceWithModel(api, options, input, signal) {
|
|
292
294
|
const directory = api.state.path.directory;
|
|
293
|
-
const
|
|
295
|
+
const selection = resolveEnhancerModel(api, options);
|
|
294
296
|
const context = gatherContext(api);
|
|
295
297
|
const userMessage = [`<CONTEXT>\n${context}\n</CONTEXT>`, `<DRAFT>\n${input}\n</DRAFT>`].join("\n\n");
|
|
296
298
|
const created = await api.client.session.create({
|
|
@@ -311,7 +313,10 @@ async function enhanceWithModel(api, options, input, signal) {
|
|
|
311
313
|
const response = await withRequestTimeout(signal, ENHANCEMENT_TIMEOUT_MS, requestSignal => api.client.session.prompt({
|
|
312
314
|
sessionID: tempSessionID,
|
|
313
315
|
directory,
|
|
314
|
-
model,
|
|
316
|
+
model: selection.model,
|
|
317
|
+
...(selection.variant ? {
|
|
318
|
+
variant: selection.variant
|
|
319
|
+
} : {}),
|
|
315
320
|
system: ENHANCER_SYSTEM_PROMPT,
|
|
316
321
|
parts: [{
|
|
317
322
|
type: "text",
|
package/package.json
CHANGED
|
@@ -160,20 +160,21 @@ function indentContextContinuation(text: string, indentation: string): string {
|
|
|
160
160
|
return text.replaceAll("\n", `\n${indentation}`)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
function resolveEnhancerModel(
|
|
163
|
+
function resolveEnhancerModel(
|
|
164
|
+
api: Api,
|
|
165
|
+
options: PluginOptions | undefined,
|
|
166
|
+
): { model: ModelRef, variant?: string } {
|
|
164
167
|
const modelOverride = typeof options?.model === "string" ? options.model : undefined
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
api.ui.toast({
|
|
170
|
-
variant: "warning",
|
|
171
|
-
title: TOAST_TITLE,
|
|
172
|
-
message: `Invalid model override ${JSON.stringify(modelOverride)}; expected "provider/model". Using default model.`,
|
|
173
|
-
})
|
|
168
|
+
const model = modelOverride ? parseModelString(modelOverride) : parseModelString(api.state.config.small_model)
|
|
169
|
+
if (modelOverride && !model) {
|
|
170
|
+
throw new Error(`Invalid model override ${JSON.stringify(modelOverride)}; expected "provider/model".`)
|
|
174
171
|
}
|
|
172
|
+
if (!model) throw new Error("OpenCode small_model is not configured.")
|
|
175
173
|
|
|
176
|
-
|
|
174
|
+
const variant = typeof options?.variant === "string" && options.variant.trim()
|
|
175
|
+
? options.variant.trim()
|
|
176
|
+
: undefined
|
|
177
|
+
return { model, ...(variant ? { variant } : {}) }
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
function clonePromptInfo(prompt: TuiPromptInfo): TuiPromptInfo {
|
|
@@ -448,7 +449,7 @@ async function enhanceWithModel(
|
|
|
448
449
|
signal: AbortSignal,
|
|
449
450
|
): Promise<string> {
|
|
450
451
|
const directory = api.state.path.directory
|
|
451
|
-
const
|
|
452
|
+
const selection = resolveEnhancerModel(api, options)
|
|
452
453
|
const context = gatherContext(api)
|
|
453
454
|
const userMessage = [
|
|
454
455
|
`<CONTEXT>\n${context}\n</CONTEXT>`,
|
|
@@ -475,7 +476,8 @@ async function enhanceWithModel(
|
|
|
475
476
|
{
|
|
476
477
|
sessionID: tempSessionID,
|
|
477
478
|
directory,
|
|
478
|
-
model,
|
|
479
|
+
model: selection.model,
|
|
480
|
+
...(selection.variant ? { variant: selection.variant } : {}),
|
|
479
481
|
system: ENHANCER_SYSTEM_PROMPT,
|
|
480
482
|
parts: [
|
|
481
483
|
{
|