opencode-codebuddy-external-auth 1.0.8 → 1.0.10
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 +32 -13
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -53,14 +53,31 @@ function convertMessagesToPrompt(messages) {
|
|
|
53
53
|
*/
|
|
54
54
|
function createOpenAIStreamResponse(text, model) {
|
|
55
55
|
const encoder = new TextEncoder();
|
|
56
|
+
const id = `chatcmpl-${Date.now()}`;
|
|
57
|
+
const created = Math.floor(Date.now() / 1000);
|
|
56
58
|
return new ReadableStream({
|
|
57
59
|
start(controller) {
|
|
58
|
-
//
|
|
59
|
-
const
|
|
60
|
-
id
|
|
60
|
+
// First chunk with role
|
|
61
|
+
const roleChunk = {
|
|
62
|
+
id,
|
|
61
63
|
object: "chat.completion.chunk",
|
|
62
|
-
created
|
|
63
|
-
model
|
|
64
|
+
created,
|
|
65
|
+
model,
|
|
66
|
+
choices: [
|
|
67
|
+
{
|
|
68
|
+
index: 0,
|
|
69
|
+
delta: { role: "assistant" },
|
|
70
|
+
finish_reason: null,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify(roleChunk)}\n\n`));
|
|
75
|
+
// Content chunk
|
|
76
|
+
const contentChunk = {
|
|
77
|
+
id,
|
|
78
|
+
object: "chat.completion.chunk",
|
|
79
|
+
created,
|
|
80
|
+
model,
|
|
64
81
|
choices: [
|
|
65
82
|
{
|
|
66
83
|
index: 0,
|
|
@@ -69,13 +86,13 @@ function createOpenAIStreamResponse(text, model) {
|
|
|
69
86
|
},
|
|
70
87
|
],
|
|
71
88
|
};
|
|
72
|
-
controller.enqueue(encoder.encode(`data: ${JSON.stringify(
|
|
73
|
-
//
|
|
89
|
+
controller.enqueue(encoder.encode(`data: ${JSON.stringify(contentChunk)}\n\n`));
|
|
90
|
+
// Done chunk
|
|
74
91
|
const doneChunk = {
|
|
75
|
-
id
|
|
92
|
+
id,
|
|
76
93
|
object: "chat.completion.chunk",
|
|
77
|
-
created
|
|
78
|
-
model
|
|
94
|
+
created,
|
|
95
|
+
model,
|
|
79
96
|
choices: [
|
|
80
97
|
{
|
|
81
98
|
index: 0,
|
|
@@ -130,7 +147,8 @@ async function executeCodeBuddyCLI(prompt, model, systemPrompt) {
|
|
|
130
147
|
args.push("--system-prompt", systemPrompt);
|
|
131
148
|
}
|
|
132
149
|
args.push(prompt);
|
|
133
|
-
|
|
150
|
+
// Debug log (可注释掉)
|
|
151
|
+
// console.log(`[codebuddy-external] Executing: codebuddy ${args.join(" ").substring(0, 100)}...`);
|
|
134
152
|
const child = spawn("codebuddy", args, {
|
|
135
153
|
env: { ...process.env },
|
|
136
154
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -182,8 +200,9 @@ function createProxyFetch() {
|
|
|
182
200
|
const openaiRequest = JSON.parse(typeof body === "string" ? body : await new Response(body).text());
|
|
183
201
|
// Convert to CodeBuddy format
|
|
184
202
|
const { prompt, systemPrompt } = convertMessagesToPrompt(openaiRequest.messages);
|
|
185
|
-
|
|
186
|
-
console.log(`[codebuddy-external]
|
|
203
|
+
// Debug logs (可注释掉)
|
|
204
|
+
// console.log(`[codebuddy-external] Invoking CodeBuddy CLI`);
|
|
205
|
+
// console.log(`[codebuddy-external] Model: ${openaiRequest.model}, Prompt length: ${prompt.length}`);
|
|
187
206
|
// Execute codebuddy CLI
|
|
188
207
|
const resultText = await executeCodeBuddyCLI(prompt, openaiRequest.model, systemPrompt);
|
|
189
208
|
// Convert response to OpenAI format
|