kodevu 0.1.59 → 0.1.61
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/package.json +1 -1
- package/src/reviewers.js +68 -17
package/package.json
CHANGED
package/src/reviewers.js
CHANGED
|
@@ -172,6 +172,8 @@ export const REVIEWERS = {
|
|
|
172
172
|
async run(config, workingDir, promptText, diffText) {
|
|
173
173
|
const requestBody = {
|
|
174
174
|
model: config.openaiModel,
|
|
175
|
+
stream: true,
|
|
176
|
+
stream_options: { include_usage: true },
|
|
175
177
|
messages: [
|
|
176
178
|
{
|
|
177
179
|
role: "user",
|
|
@@ -188,17 +190,16 @@ export const REVIEWERS = {
|
|
|
188
190
|
signal: AbortSignal.timeout(config.commandTimeoutMs)
|
|
189
191
|
});
|
|
190
192
|
|
|
191
|
-
const responseText = await response.text();
|
|
192
|
-
let payload;
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
payload = responseText ? JSON.parse(responseText) : {};
|
|
196
|
-
} catch {
|
|
197
|
-
payload = null;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
193
|
if (!response.ok) {
|
|
201
|
-
|
|
194
|
+
let errorMessage = `HTTP ${response.status}`;
|
|
195
|
+
let responseText = "";
|
|
196
|
+
try {
|
|
197
|
+
responseText = await response.text();
|
|
198
|
+
const payload = JSON.parse(responseText);
|
|
199
|
+
errorMessage = payload?.error?.message || responseText;
|
|
200
|
+
} catch {
|
|
201
|
+
if (responseText) errorMessage = responseText;
|
|
202
|
+
}
|
|
202
203
|
return {
|
|
203
204
|
code: response.status,
|
|
204
205
|
timedOut: false,
|
|
@@ -208,30 +209,80 @@ export const REVIEWERS = {
|
|
|
208
209
|
};
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
let message = "";
|
|
213
|
+
let usage = null;
|
|
214
|
+
let stdoutText = "";
|
|
215
|
+
const contentType = response.headers.get("content-type") || "";
|
|
216
|
+
|
|
217
|
+
if (contentType.includes("text/event-stream")) {
|
|
218
|
+
const decoder = new TextDecoder("utf8");
|
|
219
|
+
let buffer = "";
|
|
220
|
+
|
|
221
|
+
for await (const chunk of response.body) {
|
|
222
|
+
const textChunk = decoder.decode(chunk, { stream: true });
|
|
223
|
+
stdoutText += textChunk;
|
|
224
|
+
buffer += textChunk;
|
|
225
|
+
const parts = buffer.split("\n");
|
|
226
|
+
buffer = parts.pop() || "";
|
|
227
|
+
for (const line of parts) {
|
|
228
|
+
const trimmed = line.trim();
|
|
229
|
+
if (trimmed.startsWith("data: ")) {
|
|
230
|
+
if (trimmed === "data: [DONE]") continue;
|
|
231
|
+
try {
|
|
232
|
+
const data = JSON.parse(trimmed.slice(6));
|
|
233
|
+
if (data.choices?.[0]?.delta?.content) {
|
|
234
|
+
message += data.choices[0].delta.content;
|
|
235
|
+
}
|
|
236
|
+
if (data.usage) {
|
|
237
|
+
usage = {
|
|
238
|
+
inputTokens: Number(data.usage.prompt_tokens || 0),
|
|
239
|
+
outputTokens: Number(data.usage.completion_tokens || 0),
|
|
240
|
+
totalTokens: Number(data.usage.total_tokens || 0)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
} catch (e) {
|
|
244
|
+
// Ignore JSON parse errors for individual chunks
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
stdoutText = await response.text();
|
|
251
|
+
let payload;
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
payload = stdoutText ? JSON.parse(stdoutText) : {};
|
|
255
|
+
} catch {
|
|
256
|
+
payload = null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
message = extractOpenAiMessageContent(payload?.choices?.[0]?.message?.content);
|
|
260
|
+
if (payload?.usage) {
|
|
261
|
+
usage = {
|
|
214
262
|
inputTokens: Number(payload.usage.prompt_tokens || 0),
|
|
215
263
|
outputTokens: Number(payload.usage.completion_tokens || 0),
|
|
216
264
|
totalTokens: Number(payload.usage.total_tokens || 0)
|
|
217
|
-
}
|
|
218
|
-
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
219
268
|
|
|
220
269
|
return {
|
|
221
270
|
code: 0,
|
|
222
271
|
timedOut: false,
|
|
223
|
-
stdout:
|
|
272
|
+
stdout: stdoutText,
|
|
224
273
|
stderr: "",
|
|
225
274
|
message,
|
|
226
275
|
usage
|
|
227
276
|
};
|
|
228
277
|
} catch (error) {
|
|
229
278
|
const timedOut = error?.name === "TimeoutError" || error?.name === "AbortError";
|
|
279
|
+
const baseMessage = error?.message || String(error);
|
|
280
|
+
const causeMessage = error?.cause ? ` (Cause: ${error.cause.message || String(error.cause)})` : "";
|
|
230
281
|
return {
|
|
231
282
|
code: 1,
|
|
232
283
|
timedOut,
|
|
233
284
|
stdout: "",
|
|
234
|
-
stderr:
|
|
285
|
+
stderr: `${baseMessage}${causeMessage}`,
|
|
235
286
|
message: ""
|
|
236
287
|
};
|
|
237
288
|
}
|