nextclaw-core 0.4.2 → 0.4.3
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.d.ts +1 -1
- package/dist/index.js +38 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -148,7 +148,7 @@ declare class SessionManager {
|
|
|
148
148
|
getOrCreate(key: string): Session;
|
|
149
149
|
getIfExists(key: string): Session | null;
|
|
150
150
|
addMessage(session: Session, role: string, content: string, extra?: Record<string, unknown>): void;
|
|
151
|
-
getHistory(session: Session, maxMessages?: number): Array<Record<string,
|
|
151
|
+
getHistory(session: Session, maxMessages?: number): Array<Record<string, unknown>>;
|
|
152
152
|
clear(session: Session): void;
|
|
153
153
|
private load;
|
|
154
154
|
save(session: Session): void;
|
package/dist/index.js
CHANGED
|
@@ -2296,7 +2296,25 @@ var SessionManager = class {
|
|
|
2296
2296
|
}
|
|
2297
2297
|
getHistory(session, maxMessages = 50) {
|
|
2298
2298
|
const recent = session.messages.length > maxMessages ? session.messages.slice(-maxMessages) : session.messages;
|
|
2299
|
-
return recent.map((msg) =>
|
|
2299
|
+
return recent.map((msg) => {
|
|
2300
|
+
const entry = {
|
|
2301
|
+
role: msg.role,
|
|
2302
|
+
content: msg.content
|
|
2303
|
+
};
|
|
2304
|
+
if (typeof msg.name === "string") {
|
|
2305
|
+
entry.name = msg.name;
|
|
2306
|
+
}
|
|
2307
|
+
if (typeof msg.tool_call_id === "string") {
|
|
2308
|
+
entry.tool_call_id = msg.tool_call_id;
|
|
2309
|
+
}
|
|
2310
|
+
if (Array.isArray(msg.tool_calls)) {
|
|
2311
|
+
entry.tool_calls = msg.tool_calls;
|
|
2312
|
+
}
|
|
2313
|
+
if (typeof msg.reasoning_content === "string" && msg.reasoning_content) {
|
|
2314
|
+
entry.reasoning_content = msg.reasoning_content;
|
|
2315
|
+
}
|
|
2316
|
+
return entry;
|
|
2317
|
+
});
|
|
2300
2318
|
}
|
|
2301
2319
|
clear(session) {
|
|
2302
2320
|
session.messages = [];
|
|
@@ -2536,6 +2554,7 @@ var AgentLoop = class {
|
|
|
2536
2554
|
chatId: msg.chatId,
|
|
2537
2555
|
sessionKey
|
|
2538
2556
|
});
|
|
2557
|
+
this.sessions.addMessage(session, "user", msg.content);
|
|
2539
2558
|
let iteration = 0;
|
|
2540
2559
|
let finalContent = null;
|
|
2541
2560
|
const maxIterations = this.options.maxIterations ?? 20;
|
|
@@ -2556,9 +2575,17 @@ var AgentLoop = class {
|
|
|
2556
2575
|
}
|
|
2557
2576
|
}));
|
|
2558
2577
|
this.context.addAssistantMessage(messages, response.content, toolCallDicts, response.reasoningContent ?? null);
|
|
2578
|
+
this.sessions.addMessage(session, "assistant", response.content ?? "", {
|
|
2579
|
+
tool_calls: toolCallDicts,
|
|
2580
|
+
reasoning_content: response.reasoningContent ?? null
|
|
2581
|
+
});
|
|
2559
2582
|
for (const call of response.toolCalls) {
|
|
2560
2583
|
const result = await this.tools.execute(call.name, call.arguments);
|
|
2561
2584
|
this.context.addToolResult(messages, call.id, call.name, result);
|
|
2585
|
+
this.sessions.addMessage(session, "tool", result, {
|
|
2586
|
+
tool_call_id: call.id,
|
|
2587
|
+
name: call.name
|
|
2588
|
+
});
|
|
2562
2589
|
}
|
|
2563
2590
|
} else {
|
|
2564
2591
|
finalContent = response.content;
|
|
@@ -2571,11 +2598,9 @@ var AgentLoop = class {
|
|
|
2571
2598
|
const { content: cleanedContent, replyTo } = parseReplyTags(finalContent, messageId);
|
|
2572
2599
|
finalContent = cleanedContent;
|
|
2573
2600
|
if (isSilentReplyText(finalContent, SILENT_REPLY_TOKEN)) {
|
|
2574
|
-
this.sessions.addMessage(session, "user", msg.content);
|
|
2575
2601
|
this.sessions.save(session);
|
|
2576
2602
|
return null;
|
|
2577
2603
|
}
|
|
2578
|
-
this.sessions.addMessage(session, "user", msg.content);
|
|
2579
2604
|
this.sessions.addMessage(session, "assistant", finalContent);
|
|
2580
2605
|
this.sessions.save(session);
|
|
2581
2606
|
return {
|
|
@@ -2610,6 +2635,7 @@ var AgentLoop = class {
|
|
|
2610
2635
|
chatId: originChatId,
|
|
2611
2636
|
sessionKey
|
|
2612
2637
|
});
|
|
2638
|
+
this.sessions.addMessage(session, "user", `[System: ${msg.senderId}] ${msg.content}`);
|
|
2613
2639
|
let iteration = 0;
|
|
2614
2640
|
let finalContent = null;
|
|
2615
2641
|
const maxIterations = this.options.maxIterations ?? 20;
|
|
@@ -2630,9 +2656,17 @@ var AgentLoop = class {
|
|
|
2630
2656
|
}
|
|
2631
2657
|
}));
|
|
2632
2658
|
this.context.addAssistantMessage(messages, response.content, toolCallDicts, response.reasoningContent ?? null);
|
|
2659
|
+
this.sessions.addMessage(session, "assistant", response.content ?? "", {
|
|
2660
|
+
tool_calls: toolCallDicts,
|
|
2661
|
+
reasoning_content: response.reasoningContent ?? null
|
|
2662
|
+
});
|
|
2633
2663
|
for (const call of response.toolCalls) {
|
|
2634
2664
|
const result = await this.tools.execute(call.name, call.arguments);
|
|
2635
2665
|
this.context.addToolResult(messages, call.id, call.name, result);
|
|
2666
|
+
this.sessions.addMessage(session, "tool", result, {
|
|
2667
|
+
tool_call_id: call.id,
|
|
2668
|
+
name: call.name
|
|
2669
|
+
});
|
|
2636
2670
|
}
|
|
2637
2671
|
} else {
|
|
2638
2672
|
finalContent = response.content;
|
|
@@ -2645,9 +2679,9 @@ var AgentLoop = class {
|
|
|
2645
2679
|
const { content: cleanedContent, replyTo } = parseReplyTags(finalContent, void 0);
|
|
2646
2680
|
finalContent = cleanedContent;
|
|
2647
2681
|
if (isSilentReplyText(finalContent, SILENT_REPLY_TOKEN)) {
|
|
2682
|
+
this.sessions.save(session);
|
|
2648
2683
|
return null;
|
|
2649
2684
|
}
|
|
2650
|
-
this.sessions.addMessage(session, "user", `[System: ${msg.senderId}] ${msg.content}`);
|
|
2651
2685
|
this.sessions.addMessage(session, "assistant", finalContent);
|
|
2652
2686
|
this.sessions.save(session);
|
|
2653
2687
|
return {
|