Skip to content

Commit ebcdd2e

Browse files
committed
refactoring(middleware): simplified chat response middleware
1 parent fc475d4 commit ebcdd2e

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

refact-agent/gui/src/app/middleware.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ startListening({
9999
// saving to store agent_usage counter from the backend, only one chunk has this field.
100100
const { payload } = action;
101101

102-
if ("refact_agent_request_available" in payload) {
103-
const agentUsageCounter = getAgentUsageCounter(payload);
104-
105-
dispatch(updateAgentUsage(agentUsageCounter ?? null));
106-
}
107-
108-
if ("refact_agent_max_request_num" in payload) {
109-
const maxFreeAgentUsage = getMaxFreeAgentUsage(payload);
110-
dispatch(updateMaxAgentUsageAmount(maxFreeAgentUsage));
111-
}
112-
113102
if (isChatResponseChoice(payload)) {
114-
const { usage } = payload;
103+
const {
104+
usage,
105+
refact_agent_max_request_num,
106+
refact_agent_request_available,
107+
} = payload;
108+
const actions = [
109+
updateAgentUsage(refact_agent_request_available),
110+
updateMaxAgentUsageAmount(refact_agent_max_request_num),
111+
];
112+
113+
actions.forEach((action) => dispatch(action));
114+
115115
if (usage) {
116116
dispatch(setThreadUsage({ chatId: payload.id, usage }));
117117
}

refact-agent/gui/src/features/Chat/Thread/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,6 @@ function replaceLastUserMessage(
129129
return result.concat([userMessage]);
130130
}
131131

132-
export function getAgentUsageCounter(response: ChatResponse): number | null {
133-
if (isChatResponseChoice(response)) {
134-
return response.refact_agent_request_available;
135-
}
136-
return null;
137-
}
138-
139-
export function getMaxFreeAgentUsage(response: ChatResponse): number {
140-
if (isChatResponseChoice(response)) {
141-
return response.refact_agent_max_request_num;
142-
}
143-
return 0;
144-
}
145-
146132
export function formatChatResponse(
147133
messages: ChatMessages,
148134
response: ChatResponse,

0 commit comments

Comments
 (0)