akemon 0.2.12 → 0.2.13
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/context.js +7 -2
- package/dist/task-module.js +9 -0
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -43,10 +43,12 @@ function parseConversation(content) {
|
|
|
43
43
|
for (const line of lines) {
|
|
44
44
|
const m = line.match(/^\[(.+?)\] (User|Agent): (.*)$/);
|
|
45
45
|
if (m) {
|
|
46
|
+
// Unescape \\n → newline, \\\\ → backslash
|
|
47
|
+
const content = m[3].replace(/\\n/g, "\n").replace(/\\\\/g, "\\");
|
|
46
48
|
rounds.push({
|
|
47
49
|
ts: m[1],
|
|
48
50
|
role: m[2].toLowerCase(),
|
|
49
|
-
content
|
|
51
|
+
content,
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -77,7 +79,10 @@ export async function appendRound(workdir, agentName, convId, userMsg, agentMsg)
|
|
|
77
79
|
content = "## Summary\n\n\n## Recent\n";
|
|
78
80
|
}
|
|
79
81
|
const ts = localNow();
|
|
80
|
-
|
|
82
|
+
// Escape newlines so each round stays on a single line for reliable parsing
|
|
83
|
+
const safeUser = userMsg.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
|
|
84
|
+
const safeAgent = agentMsg.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
|
|
85
|
+
const entry = `[${ts}] User: ${safeUser}\n[${ts}] Agent: ${safeAgent}\n`;
|
|
81
86
|
content = content.trimEnd() + "\n" + entry;
|
|
82
87
|
await writeFile(p, content);
|
|
83
88
|
}
|
package/dist/task-module.js
CHANGED
|
@@ -31,6 +31,7 @@ export class TaskModule {
|
|
|
31
31
|
orderRetry = new Map();
|
|
32
32
|
userTaskRetry = new Map();
|
|
33
33
|
gaveUp = new Set();
|
|
34
|
+
executing = new Set(); // orders currently being fulfilled
|
|
34
35
|
// Push notification support
|
|
35
36
|
urgentOrderIds = new Set();
|
|
36
37
|
triggerWorkFn = null;
|
|
@@ -130,6 +131,8 @@ export class TaskModule {
|
|
|
130
131
|
for (const order of orders) {
|
|
131
132
|
if (this.gaveUp.has(order.id))
|
|
132
133
|
continue;
|
|
134
|
+
if (this.executing.has(order.id))
|
|
135
|
+
continue;
|
|
133
136
|
const retry = this.orderRetry.get(order.id);
|
|
134
137
|
if (retry && Date.now() < retry.nextAt)
|
|
135
138
|
continue;
|
|
@@ -205,6 +208,8 @@ export class TaskModule {
|
|
|
205
208
|
// Execute sequentially
|
|
206
209
|
for (const item of filtered) {
|
|
207
210
|
try {
|
|
211
|
+
if (item.type === "order")
|
|
212
|
+
this.executing.add(item.id);
|
|
208
213
|
switch (item.type) {
|
|
209
214
|
case "order":
|
|
210
215
|
await this.executeOrder(item.data);
|
|
@@ -221,6 +226,10 @@ export class TaskModule {
|
|
|
221
226
|
catch (err) {
|
|
222
227
|
console.log(`[task] Error processing ${item.type}:${item.id}: ${err.message}`);
|
|
223
228
|
}
|
|
229
|
+
finally {
|
|
230
|
+
if (item.type === "order")
|
|
231
|
+
this.executing.delete(item.id);
|
|
232
|
+
}
|
|
224
233
|
}
|
|
225
234
|
bus.emit(SIG.CYCLE_END, sig(SIG.CYCLE_END, { ts: Date.now() }));
|
|
226
235
|
}
|