@zhongqian97-code/ecode 0.0.3 → 0.0.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/dist/index.js +33 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
|
|
3
6
|
// src/config.ts
|
|
4
7
|
import { existsSync, readFileSync } from "fs";
|
|
5
8
|
import { homedir } from "os";
|
|
@@ -96,12 +99,16 @@ function createLLMClient(config2) {
|
|
|
96
99
|
}
|
|
97
100
|
const response = await openai.chat.completions.create(requestParams);
|
|
98
101
|
const tcAccumulator = /* @__PURE__ */ new Map();
|
|
102
|
+
let reasoningAccumulator = "";
|
|
99
103
|
for await (const chunk of response) {
|
|
100
104
|
const choice = chunk.choices[0];
|
|
101
105
|
if (!choice) continue;
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
|
|
106
|
+
const delta = choice.delta;
|
|
107
|
+
if (delta.reasoning_content) {
|
|
108
|
+
reasoningAccumulator += delta.reasoning_content;
|
|
109
|
+
}
|
|
110
|
+
if (delta.tool_calls) {
|
|
111
|
+
for (const tc of delta.tool_calls) {
|
|
105
112
|
if (!tcAccumulator.has(tc.index)) {
|
|
106
113
|
tcAccumulator.set(tc.index, {
|
|
107
114
|
id: tc.id ?? "",
|
|
@@ -118,14 +125,16 @@ function createLLMClient(config2) {
|
|
|
118
125
|
const isLast = choice.finish_reason !== null;
|
|
119
126
|
if (isLast) {
|
|
120
127
|
yield {
|
|
121
|
-
text:
|
|
128
|
+
text: delta.content ?? "",
|
|
122
129
|
done: true,
|
|
123
130
|
finishReason: choice.finish_reason,
|
|
124
|
-
toolCalls: tcAccumulator.size > 0 ? Array.from(tcAccumulator.values()) : void 0
|
|
131
|
+
toolCalls: tcAccumulator.size > 0 ? Array.from(tcAccumulator.values()) : void 0,
|
|
132
|
+
reasoning: reasoningAccumulator || void 0
|
|
125
133
|
};
|
|
126
134
|
} else {
|
|
127
135
|
yield {
|
|
128
|
-
text:
|
|
136
|
+
text: delta.content ?? "",
|
|
137
|
+
reasoning: delta.reasoning_content,
|
|
129
138
|
done: false
|
|
130
139
|
};
|
|
131
140
|
}
|
|
@@ -217,14 +226,16 @@ async function startRepl(config2) {
|
|
|
217
226
|
continueLoop = false;
|
|
218
227
|
process.stdout.write("assistant: ");
|
|
219
228
|
let assistantText = "";
|
|
229
|
+
let assistantReasoning;
|
|
220
230
|
const toolCalls = [];
|
|
221
231
|
for await (const chunk of llm.stream(messages, [BASH_TOOL])) {
|
|
222
232
|
if (chunk.text) {
|
|
223
233
|
process.stdout.write(chunk.text);
|
|
224
234
|
assistantText += chunk.text;
|
|
225
235
|
}
|
|
226
|
-
if (chunk.done
|
|
227
|
-
toolCalls.push(...chunk.toolCalls);
|
|
236
|
+
if (chunk.done) {
|
|
237
|
+
if (chunk.toolCalls) toolCalls.push(...chunk.toolCalls);
|
|
238
|
+
if (chunk.reasoning) assistantReasoning = chunk.reasoning;
|
|
228
239
|
}
|
|
229
240
|
}
|
|
230
241
|
if (toolCalls.length > 0) {
|
|
@@ -235,7 +246,8 @@ async function startRepl(config2) {
|
|
|
235
246
|
id: tc.id,
|
|
236
247
|
type: "function",
|
|
237
248
|
function: { name: tc.name, arguments: tc.arguments }
|
|
238
|
-
}))
|
|
249
|
+
})),
|
|
250
|
+
...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
|
|
239
251
|
});
|
|
240
252
|
for (const tc of toolCalls) {
|
|
241
253
|
if (tc.name === "bash") {
|
|
@@ -261,7 +273,11 @@ async function startRepl(config2) {
|
|
|
261
273
|
} else {
|
|
262
274
|
process.stdout.write("\n");
|
|
263
275
|
if (assistantText) {
|
|
264
|
-
messages.push({
|
|
276
|
+
messages.push({
|
|
277
|
+
role: "assistant",
|
|
278
|
+
content: assistantText,
|
|
279
|
+
...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
|
|
280
|
+
});
|
|
265
281
|
}
|
|
266
282
|
}
|
|
267
283
|
}
|
|
@@ -271,6 +287,13 @@ async function startRepl(config2) {
|
|
|
271
287
|
}
|
|
272
288
|
|
|
273
289
|
// src/index.ts
|
|
290
|
+
var require2 = createRequire(import.meta.url);
|
|
291
|
+
var { version } = require2("../package.json");
|
|
292
|
+
var arg = process.argv[2];
|
|
293
|
+
if (arg === "-v" || arg === "--version") {
|
|
294
|
+
console.log(version);
|
|
295
|
+
process.exit(0);
|
|
296
|
+
}
|
|
274
297
|
var config = loadConfig();
|
|
275
298
|
if (!config.apiKey) {
|
|
276
299
|
console.error(
|