fix(cli): ensure /clear resets context and exclude system messages from approximateTokenUsed count (#443)
https://github.com/user-attachments/assets/58b8f261-a359-4cd8-8c84-90d8d91a5592
This commit is contained in:
committed by
GitHub
parent
6d6ca454cd
commit
425430debb
@@ -345,15 +345,27 @@ export default function TerminalChatInput({
|
||||
|
||||
// Emit a system message to confirm the clear action. We *append*
|
||||
// it so Ink's <Static> treats it as new output and actually renders it.
|
||||
setItems((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: `clear-${Date.now()}`,
|
||||
type: "message",
|
||||
role: "system",
|
||||
content: [{ type: "input_text", text: "Context cleared" }],
|
||||
},
|
||||
]);
|
||||
setItems((prev) => {
|
||||
const filteredOldItems = prev.filter((item) => {
|
||||
if (
|
||||
item.type === "message" &&
|
||||
(item.role === "user" || item.role === "assistant")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return [
|
||||
...filteredOldItems,
|
||||
{
|
||||
id: `clear-${Date.now()}`,
|
||||
type: "message",
|
||||
role: "system",
|
||||
content: [{ type: "input_text", text: "Terminal cleared" }],
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
return;
|
||||
} else if (inputValue === "/clearhistory") {
|
||||
|
||||
@@ -19,6 +19,10 @@ export function approximateTokensUsed(items: Array<ResponseItem>): number {
|
||||
for (const item of items) {
|
||||
switch (item.type) {
|
||||
case "message": {
|
||||
if (item.role !== "user" && item.role !== "assistant") {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const c of item.content) {
|
||||
if (c.type === "input_text" || c.type === "output_text") {
|
||||
charCount += c.text.length;
|
||||
|
||||
Reference in New Issue
Block a user