opencode-fast-apply 2.1.3 → 2.1.5
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 +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,7 +98,6 @@ function validateToken(token) {
|
|
|
98
98
|
| `FAST_APPLY_API_KEY` | `optional-api-key` | API key (optional for local servers) |
|
|
99
99
|
| `FAST_APPLY_URL` | `http://localhost:1234/v1` | OpenAI-compatible API endpoint |
|
|
100
100
|
| `FAST_APPLY_MODEL` | `fastapply-1.5b` | Model name |
|
|
101
|
-
| `FAST_APPLY_TIMEOUT` | `30000` | Request timeout in ms |
|
|
102
101
|
| `FAST_APPLY_TEMPERATURE` | `0.05` | Temperature (0.0-2.0) |
|
|
103
102
|
|
|
104
103
|
## How It Works
|
|
@@ -162,12 +161,6 @@ curl -X POST http://localhost:1234/v1/chat/completions \
|
|
|
162
161
|
- Use Q4 quantization for faster inference
|
|
163
162
|
- Increase `FAST_APPLY_MAX_TOKENS` if responses are truncated
|
|
164
163
|
|
|
165
|
-
### Timeout Errors
|
|
166
|
-
```bash
|
|
167
|
-
# Increase timeout for slower hardware
|
|
168
|
-
export FAST_APPLY_TIMEOUT="60000" # 60 seconds
|
|
169
|
-
```
|
|
170
|
-
|
|
171
164
|
## Contributing
|
|
172
165
|
|
|
173
166
|
Contributions welcome! This plugin could potentially be integrated into OpenCode core.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,qBAAqB,CAAA;AA2ZvD,eAAO,MAAM,eAAe,EAAE,MA4J7B,CAAA;AAGD,eAAe,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -16,21 +16,20 @@ const sessionParamsCache = new Map();
|
|
|
16
16
|
const FAST_APPLY_API_KEY = process.env.FAST_APPLY_API_KEY || "optional-api-key";
|
|
17
17
|
const FAST_APPLY_URL = (process.env.FAST_APPLY_URL || "http://localhost:1234/v1").replace(/\/v1\/?$/, "");
|
|
18
18
|
const FAST_APPLY_MODEL = process.env.FAST_APPLY_MODEL || "fastapply-1.5b";
|
|
19
|
-
const FAST_APPLY_TIMEOUT = parseInt(process.env.FAST_APPLY_TIMEOUT || "30000", 10);
|
|
20
19
|
const FAST_APPLY_TEMPERATURE = parseFloat(process.env.FAST_APPLY_TEMPERATURE || "0.05");
|
|
21
20
|
const FAST_APPLY_SYSTEM_PROMPT = "You are a coding assistant that helps merge code updates, ensuring every modification is fully integrated.";
|
|
22
|
-
const FAST_APPLY_USER_PROMPT = `Merge all changes from the
|
|
21
|
+
const FAST_APPLY_USER_PROMPT = `Merge all changes from the <<<UPDATE>>> snippet into the <<<CODE>>> below.
|
|
23
22
|
- Preserve the code's structure, order, comments, and indentation exactly.
|
|
24
|
-
- Output only the updated code, enclosed within
|
|
23
|
+
- Output only the updated code, enclosed within <<<UPDATED_CODE>>> and <<</UPDATED_CODE>>> tags.
|
|
25
24
|
- Do not include any additional text, explanations, placeholders, ellipses, or code fences.
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
<<<CODE>>>{original_code}<<</CODE>>>
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
<<<UPDATE>>>{update_snippet}<<</UPDATE>>>
|
|
30
29
|
|
|
31
30
|
Provide the complete updated code.`;
|
|
32
|
-
const UPDATED_CODE_START = "
|
|
33
|
-
const UPDATED_CODE_END = "
|
|
31
|
+
const UPDATED_CODE_START = "<<<UPDATED_CODE>>>";
|
|
32
|
+
const UPDATED_CODE_END = "<<</UPDATED_CODE>>>";
|
|
34
33
|
const TOOL_INSTRUCTIONS = `**DEFAULT tool for editing existing files. Use INSTEAD of native 'edit' tool.**
|
|
35
34
|
|
|
36
35
|
CRITICAL: For EXISTING files ONLY. Use 'write' for new files.
|
|
@@ -98,27 +97,17 @@ function alsoKeepThis() {
|
|
|
98
97
|
|
|
99
98
|
## Fallback
|
|
100
99
|
If API fails, use native \`edit\` tool with exact string matching.`;
|
|
101
|
-
function escapeXmlTags(text) {
|
|
102
|
-
return text
|
|
103
|
-
.replace(/<updated-code>/g, "<updated-code>")
|
|
104
|
-
.replace(/<\/updated-code>/g, "</updated-code>");
|
|
105
|
-
}
|
|
106
|
-
function unescapeXmlTags(text) {
|
|
107
|
-
return text
|
|
108
|
-
.replace(/<updated-code>/g, "<updated-code>")
|
|
109
|
-
.replace(/<\/updated-code>/g, "</updated-code>");
|
|
110
|
-
}
|
|
111
100
|
function extractUpdatedCode(raw) {
|
|
112
101
|
const stripped = raw.trim();
|
|
113
102
|
const startTag = UPDATED_CODE_START;
|
|
114
103
|
const endTag = UPDATED_CODE_END;
|
|
115
104
|
let startIdx = stripped.indexOf(startTag);
|
|
116
105
|
if (startIdx === -1) {
|
|
117
|
-
startIdx = stripped.indexOf("
|
|
106
|
+
startIdx = stripped.indexOf("<<<UPDATED_CODE");
|
|
118
107
|
if (startIdx !== -1) {
|
|
119
|
-
const closeTagIdx = stripped.indexOf("
|
|
108
|
+
const closeTagIdx = stripped.indexOf(">>>", startIdx);
|
|
120
109
|
if (closeTagIdx !== -1) {
|
|
121
|
-
startIdx = closeTagIdx +
|
|
110
|
+
startIdx = closeTagIdx + 3;
|
|
122
111
|
}
|
|
123
112
|
}
|
|
124
113
|
}
|
|
@@ -129,28 +118,28 @@ function extractUpdatedCode(raw) {
|
|
|
129
118
|
if (stripped.startsWith("```") && stripped.endsWith("```")) {
|
|
130
119
|
const lines = stripped.split("\n");
|
|
131
120
|
if (lines.length >= 2) {
|
|
132
|
-
return
|
|
121
|
+
return lines.slice(1, -1).join("\n");
|
|
133
122
|
}
|
|
134
123
|
}
|
|
135
|
-
return
|
|
124
|
+
return stripped;
|
|
136
125
|
}
|
|
137
126
|
let endIdx = stripped.indexOf(endTag, startIdx);
|
|
138
127
|
if (endIdx === -1) {
|
|
139
|
-
endIdx = stripped.indexOf("
|
|
128
|
+
endIdx = stripped.indexOf("<<</UPDATED_CODE", startIdx);
|
|
140
129
|
}
|
|
141
130
|
if (endIdx === -1) {
|
|
142
131
|
const extracted = stripped.slice(startIdx).trim();
|
|
143
|
-
const lastCloseTag = extracted.lastIndexOf("
|
|
132
|
+
const lastCloseTag = extracted.lastIndexOf("<<<");
|
|
144
133
|
if (lastCloseTag !== -1 && extracted.slice(lastCloseTag).toLowerCase().includes("update")) {
|
|
145
|
-
return
|
|
134
|
+
return extracted.slice(0, lastCloseTag).trim();
|
|
146
135
|
}
|
|
147
|
-
return
|
|
136
|
+
return extracted;
|
|
148
137
|
}
|
|
149
138
|
const inner = stripped.substring(startIdx, endIdx);
|
|
150
139
|
if (!inner || inner.trim().length === 0) {
|
|
151
140
|
throw new Error("Empty updated-code block");
|
|
152
141
|
}
|
|
153
|
-
return
|
|
142
|
+
return inner;
|
|
154
143
|
}
|
|
155
144
|
function generateUnifiedDiff(filepath, original, modified) {
|
|
156
145
|
const patch = createTwoFilesPatch(`a/${filepath}`, `b/${filepath}`, original, modified, "", "", { context: 3 });
|
|
@@ -229,14 +218,10 @@ async function callFastApply(originalCode, codeEdit, instructions) {
|
|
|
229
218
|
error: "FAST_APPLY_API_KEY not set. Get one at https://openai.com/api",
|
|
230
219
|
};
|
|
231
220
|
}
|
|
232
|
-
const controller = new AbortController();
|
|
233
|
-
const timeoutId = setTimeout(() => controller.abort(), FAST_APPLY_TIMEOUT);
|
|
234
221
|
try {
|
|
235
|
-
const escapedOriginalCode = escapeXmlTags(originalCode);
|
|
236
|
-
const escapedCodeEdit = escapeXmlTags(codeEdit);
|
|
237
222
|
const userContent = FAST_APPLY_USER_PROMPT
|
|
238
|
-
.replace("{original_code}",
|
|
239
|
-
.replace("{update_snippet}",
|
|
223
|
+
.replace("{original_code}", originalCode)
|
|
224
|
+
.replace("{update_snippet}", codeEdit);
|
|
240
225
|
const response = await fetch(`${FAST_APPLY_URL}/v1/chat/completions`, {
|
|
241
226
|
method: "POST",
|
|
242
227
|
headers: {
|
|
@@ -257,9 +242,7 @@ async function callFastApply(originalCode, codeEdit, instructions) {
|
|
|
257
242
|
],
|
|
258
243
|
temperature: FAST_APPLY_TEMPERATURE,
|
|
259
244
|
}),
|
|
260
|
-
signal: controller.signal,
|
|
261
245
|
});
|
|
262
|
-
clearTimeout(timeoutId);
|
|
263
246
|
if (!response.ok) {
|
|
264
247
|
const errorText = await response.text();
|
|
265
248
|
return {
|
|
@@ -282,14 +265,7 @@ async function callFastApply(originalCode, codeEdit, instructions) {
|
|
|
282
265
|
};
|
|
283
266
|
}
|
|
284
267
|
catch (err) {
|
|
285
|
-
clearTimeout(timeoutId);
|
|
286
268
|
const error = err;
|
|
287
|
-
if (error.name === "AbortError") {
|
|
288
|
-
return {
|
|
289
|
-
success: false,
|
|
290
|
-
error: `Fast Apply API timeout after ${FAST_APPLY_TIMEOUT}ms`,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
269
|
return {
|
|
294
270
|
success: false,
|
|
295
271
|
error: `Fast Apply API request failed: ${error.message}`,
|
package/package.json
CHANGED