akemon 0.2.11 → 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 +8 -5
- 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,12 +131,8 @@ export class TaskModule {
|
|
|
130
131
|
for (const order of orders) {
|
|
131
132
|
if (this.gaveUp.has(order.id))
|
|
132
133
|
continue;
|
|
133
|
-
|
|
134
|
-
const orderAge = Date.now() - new Date(order.created_at || 0).getTime();
|
|
135
|
-
if (orderAge > 3_600_000) {
|
|
136
|
-
this.gaveUp.add(order.id);
|
|
134
|
+
if (this.executing.has(order.id))
|
|
137
135
|
continue;
|
|
138
|
-
}
|
|
139
136
|
const retry = this.orderRetry.get(order.id);
|
|
140
137
|
if (retry && Date.now() < retry.nextAt)
|
|
141
138
|
continue;
|
|
@@ -211,6 +208,8 @@ export class TaskModule {
|
|
|
211
208
|
// Execute sequentially
|
|
212
209
|
for (const item of filtered) {
|
|
213
210
|
try {
|
|
211
|
+
if (item.type === "order")
|
|
212
|
+
this.executing.add(item.id);
|
|
214
213
|
switch (item.type) {
|
|
215
214
|
case "order":
|
|
216
215
|
await this.executeOrder(item.data);
|
|
@@ -227,6 +226,10 @@ export class TaskModule {
|
|
|
227
226
|
catch (err) {
|
|
228
227
|
console.log(`[task] Error processing ${item.type}:${item.id}: ${err.message}`);
|
|
229
228
|
}
|
|
229
|
+
finally {
|
|
230
|
+
if (item.type === "order")
|
|
231
|
+
this.executing.delete(item.id);
|
|
232
|
+
}
|
|
230
233
|
}
|
|
231
234
|
bus.emit(SIG.CYCLE_END, sig(SIG.CYCLE_END, { ts: Date.now() }));
|
|
232
235
|
}
|