opencode-codebuddy-external-auth 1.0.12 → 1.0.14
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/dist/plugin.js +19 -13
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -204,6 +204,9 @@ function createProxyFetch() {
|
|
|
204
204
|
const openaiRequest = JSON.parse(typeof body === "string" ? body : await new Response(body).text());
|
|
205
205
|
// Convert to CodeBuddy format
|
|
206
206
|
const { prompt, systemPrompt } = convertMessagesToPrompt(openaiRequest.messages);
|
|
207
|
+
// 调试日志
|
|
208
|
+
console.log(`[codebuddy-external] Messages count: ${openaiRequest.messages.length}`);
|
|
209
|
+
console.log(`[codebuddy-external] Prompt: ${prompt.substring(0, 100)}...`);
|
|
207
210
|
// 根据配置选择 HTTP API 模式或 CLI 模式
|
|
208
211
|
if (CONFIG.useHttpApi) {
|
|
209
212
|
return await executeViaHttpApi(openaiRequest, prompt, systemPrompt);
|
|
@@ -230,11 +233,13 @@ function createProxyFetch() {
|
|
|
230
233
|
*/
|
|
231
234
|
async function executeViaHttpApi(openaiRequest, prompt, systemPrompt) {
|
|
232
235
|
// 构建 CodeBuddy /agent 请求
|
|
236
|
+
// 暂时禁用流式模式,先确保基础功能正常
|
|
237
|
+
const useStream = false; // openaiRequest.stream
|
|
233
238
|
const agentRequest = {
|
|
234
239
|
prompt,
|
|
235
240
|
model: openaiRequest.model,
|
|
236
241
|
print: true, // 关键:非交互模式,返回结果
|
|
237
|
-
outputFormat:
|
|
242
|
+
outputFormat: useStream ? "stream-json" : "text",
|
|
238
243
|
};
|
|
239
244
|
if (systemPrompt) {
|
|
240
245
|
agentRequest.systemPrompt = systemPrompt;
|
|
@@ -252,7 +257,7 @@ async function executeViaHttpApi(openaiRequest, prompt, systemPrompt) {
|
|
|
252
257
|
throw new Error(`HTTP API error: ${response.status} - ${errorText}`);
|
|
253
258
|
}
|
|
254
259
|
// 处理流式响应
|
|
255
|
-
if (
|
|
260
|
+
if (useStream && response.body) {
|
|
256
261
|
return new Response(transformCodeBuddyStreamToOpenAI(response.body, openaiRequest.model), {
|
|
257
262
|
headers: {
|
|
258
263
|
"Content-Type": "text/event-stream",
|
|
@@ -261,18 +266,19 @@ async function executeViaHttpApi(openaiRequest, prompt, systemPrompt) {
|
|
|
261
266
|
},
|
|
262
267
|
});
|
|
263
268
|
}
|
|
264
|
-
// 非流式响应
|
|
269
|
+
// 非流式响应 - 等待完整结果
|
|
265
270
|
const responseText = await response.text();
|
|
266
|
-
let resultText = responseText;
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
let resultText = responseText.trim();
|
|
272
|
+
// 返回 OpenAI 格式响应
|
|
273
|
+
// 如果客户端请求流式,返回伪流式响应
|
|
274
|
+
if (openaiRequest.stream) {
|
|
275
|
+
return new Response(createOpenAIStreamResponse(resultText, openaiRequest.model), {
|
|
276
|
+
headers: {
|
|
277
|
+
"Content-Type": "text/event-stream",
|
|
278
|
+
"Cache-Control": "no-cache",
|
|
279
|
+
"Connection": "keep-alive",
|
|
280
|
+
},
|
|
281
|
+
});
|
|
276
282
|
}
|
|
277
283
|
return new Response(createOpenAIResponse(resultText, openaiRequest.model), {
|
|
278
284
|
headers: { "Content-Type": "application/json" },
|