mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 21:32:39 +02:00
feat(chat): enhance error handling for premium quota exhaustion in chat messages
This commit is contained in:
parent
d66fa1559b
commit
fa6a09197e
1 changed files with 19 additions and 2 deletions
|
|
@ -201,6 +201,9 @@ const BASE_TOOLS_WITH_UI = new Set([
|
||||||
// "write_todos", // Disabled for now
|
// "write_todos", // Disabled for now
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const PREMIUM_QUOTA_ASSISTANT_MESSAGE =
|
||||||
|
"I can’t continue with the current premium model because your premium tokens are exhausted. Switch to a free model or buy more tokens to continue.";
|
||||||
|
|
||||||
function getPinnedPremiumQuotaErrorMessage(error: unknown): string | null {
|
function getPinnedPremiumQuotaErrorMessage(error: unknown): string | null {
|
||||||
if (!(error instanceof Error)) return null;
|
if (!(error instanceof Error)) return null;
|
||||||
const normalized = error.message.toLowerCase();
|
const normalized = error.message.toLowerCase();
|
||||||
|
|
@ -992,7 +995,9 @@ export default function NewChatPage() {
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
text:
|
text:
|
||||||
premiumQuotaAlertMessage ??
|
(premiumQuotaAlertMessage
|
||||||
|
? PREMIUM_QUOTA_ASSISTANT_MESSAGE
|
||||||
|
: undefined) ??
|
||||||
"Sorry, there was an error. Please try again.",
|
"Sorry, there was an error. Please try again.",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -1288,6 +1293,16 @@ export default function NewChatPage() {
|
||||||
threadId: resumeThreadId,
|
threadId: resumeThreadId,
|
||||||
message: premiumQuotaAlertMessage,
|
message: premiumQuotaAlertMessage,
|
||||||
});
|
});
|
||||||
|
setMessages((prev) =>
|
||||||
|
prev.map((m) =>
|
||||||
|
m.id === assistantMsgId
|
||||||
|
? {
|
||||||
|
...m,
|
||||||
|
content: [{ type: "text", text: PREMIUM_QUOTA_ASSISTANT_MESSAGE }],
|
||||||
|
}
|
||||||
|
: m
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
toast.error("Failed to resume. Please try again.");
|
toast.error("Failed to resume. Please try again.");
|
||||||
}
|
}
|
||||||
|
|
@ -1647,7 +1662,9 @@ export default function NewChatPage() {
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
text:
|
text:
|
||||||
premiumQuotaAlertMessage ??
|
(premiumQuotaAlertMessage
|
||||||
|
? PREMIUM_QUOTA_ASSISTANT_MESSAGE
|
||||||
|
: undefined) ??
|
||||||
"Sorry, there was an error. Please try again.",
|
"Sorry, there was an error. Please try again.",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue