@zhongqian97-code/ecode 0.0.4 → 0.0.6
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 +24 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const _ew=process.emitWarning.bind(process);process.emitWarning=function(w,...a){if((w?.message??w)?.includes?.('punycode'))return;_ew(w,...a);};
|
|
2
3
|
|
|
3
4
|
// src/index.ts
|
|
4
5
|
import { createRequire } from "module";
|
|
@@ -99,12 +100,16 @@ function createLLMClient(config2) {
|
|
|
99
100
|
}
|
|
100
101
|
const response = await openai.chat.completions.create(requestParams);
|
|
101
102
|
const tcAccumulator = /* @__PURE__ */ new Map();
|
|
103
|
+
let reasoningAccumulator = "";
|
|
102
104
|
for await (const chunk of response) {
|
|
103
105
|
const choice = chunk.choices[0];
|
|
104
106
|
if (!choice) continue;
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
|
|
107
|
+
const delta = choice.delta;
|
|
108
|
+
if (delta.reasoning_content) {
|
|
109
|
+
reasoningAccumulator += delta.reasoning_content;
|
|
110
|
+
}
|
|
111
|
+
if (delta.tool_calls) {
|
|
112
|
+
for (const tc of delta.tool_calls) {
|
|
108
113
|
if (!tcAccumulator.has(tc.index)) {
|
|
109
114
|
tcAccumulator.set(tc.index, {
|
|
110
115
|
id: tc.id ?? "",
|
|
@@ -121,14 +126,16 @@ function createLLMClient(config2) {
|
|
|
121
126
|
const isLast = choice.finish_reason !== null;
|
|
122
127
|
if (isLast) {
|
|
123
128
|
yield {
|
|
124
|
-
text:
|
|
129
|
+
text: delta.content ?? "",
|
|
125
130
|
done: true,
|
|
126
131
|
finishReason: choice.finish_reason,
|
|
127
|
-
toolCalls: tcAccumulator.size > 0 ? Array.from(tcAccumulator.values()) : void 0
|
|
132
|
+
toolCalls: tcAccumulator.size > 0 ? Array.from(tcAccumulator.values()) : void 0,
|
|
133
|
+
reasoning: reasoningAccumulator || void 0
|
|
128
134
|
};
|
|
129
135
|
} else {
|
|
130
136
|
yield {
|
|
131
|
-
text:
|
|
137
|
+
text: delta.content ?? "",
|
|
138
|
+
reasoning: delta.reasoning_content,
|
|
132
139
|
done: false
|
|
133
140
|
};
|
|
134
141
|
}
|
|
@@ -220,14 +227,16 @@ async function startRepl(config2) {
|
|
|
220
227
|
continueLoop = false;
|
|
221
228
|
process.stdout.write("assistant: ");
|
|
222
229
|
let assistantText = "";
|
|
230
|
+
let assistantReasoning;
|
|
223
231
|
const toolCalls = [];
|
|
224
232
|
for await (const chunk of llm.stream(messages, [BASH_TOOL])) {
|
|
225
233
|
if (chunk.text) {
|
|
226
234
|
process.stdout.write(chunk.text);
|
|
227
235
|
assistantText += chunk.text;
|
|
228
236
|
}
|
|
229
|
-
if (chunk.done
|
|
230
|
-
toolCalls.push(...chunk.toolCalls);
|
|
237
|
+
if (chunk.done) {
|
|
238
|
+
if (chunk.toolCalls) toolCalls.push(...chunk.toolCalls);
|
|
239
|
+
if (chunk.reasoning) assistantReasoning = chunk.reasoning;
|
|
231
240
|
}
|
|
232
241
|
}
|
|
233
242
|
if (toolCalls.length > 0) {
|
|
@@ -238,7 +247,8 @@ async function startRepl(config2) {
|
|
|
238
247
|
id: tc.id,
|
|
239
248
|
type: "function",
|
|
240
249
|
function: { name: tc.name, arguments: tc.arguments }
|
|
241
|
-
}))
|
|
250
|
+
})),
|
|
251
|
+
...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
|
|
242
252
|
});
|
|
243
253
|
for (const tc of toolCalls) {
|
|
244
254
|
if (tc.name === "bash") {
|
|
@@ -264,7 +274,11 @@ async function startRepl(config2) {
|
|
|
264
274
|
} else {
|
|
265
275
|
process.stdout.write("\n");
|
|
266
276
|
if (assistantText) {
|
|
267
|
-
messages.push({
|
|
277
|
+
messages.push({
|
|
278
|
+
role: "assistant",
|
|
279
|
+
content: assistantText,
|
|
280
|
+
...assistantReasoning ? { reasoning_content: assistantReasoning } : {}
|
|
281
|
+
});
|
|
268
282
|
}
|
|
269
283
|
}
|
|
270
284
|
}
|