Skip to content

Commit ab3c902

Browse files
committed
Fix inconsistent credit consumption in chat
Refactor `isAgentCall` logic to check only the last message in the history rather than any message. This prevents valid user messages from being incorrectly flagged as agent calls due to previous assistant history, ensuring proper credit consumption for multi-turn conversations. Fixes #9
1 parent 4bc7470 commit ab3c902

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

index.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ export async function CopilotAuthPlugin({ client }) {
118118
? JSON.parse(init.body)
119119
: init.body;
120120
if (body?.messages) {
121-
isAgentCall = body.messages.some(
122-
(msg) => msg.role && ["tool", "assistant"].includes(msg.role),
123-
);
121+
if (body.messages.length > 0) {
122+
const lastMessage = body.messages[body.messages.length - 1];
123+
isAgentCall = lastMessage.role && ["tool", "assistant"].includes(lastMessage.role);
124+
}
124125
isVisionRequest = body.messages.some(
125126
(msg) =>
126127
Array.isArray(msg.content) &&

0 commit comments

Comments
 (0)