ФУНКЦИИ - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: лимиты Voice Tasker до OpenAI pipeline
This commit is contained in:
@@ -114,6 +114,41 @@ function formatPlaybackTime(value: number) {
|
||||
return formatDuration(value);
|
||||
}
|
||||
|
||||
function formatRetryAfter(value: unknown) {
|
||||
const seconds = typeof value === "number" ? value : Number(value);
|
||||
if (!Number.isFinite(seconds) || seconds <= 0) return "позже";
|
||||
if (seconds < 60) return `через ${Math.ceil(seconds)} сек.`;
|
||||
|
||||
const minutes = Math.ceil(seconds / 60);
|
||||
if (minutes < 60) return `через ${minutes} мин.`;
|
||||
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const remainingMinutes = minutes % 60;
|
||||
return remainingMinutes > 0 ? `через ${hours} ч ${remainingMinutes} мин.` : `через ${hours} ч`;
|
||||
}
|
||||
|
||||
function getVoiceTaskErrorMessage(error: unknown, fallback: string) {
|
||||
if (typeof error === "object" && error !== null && "code" in error) {
|
||||
const code = String(error.code);
|
||||
const retryAfter = "retry_after" in error ? formatRetryAfter(error.retry_after) : "позже";
|
||||
const used = "used" in error && typeof error.used === "number" ? error.used : null;
|
||||
const limit = "limit" in error && typeof error.limit === "number" ? error.limit : null;
|
||||
const usageText = used !== null && limit !== null ? ` Использовано ${used} из ${limit} за последний час.` : "";
|
||||
|
||||
if (code === "voice_task_user_hourly_limit_exceeded") {
|
||||
return `Лимит Voice Tasker для пользователя исчерпан. Повторите ${retryAfter}.${usageText}`;
|
||||
}
|
||||
|
||||
if (code === "voice_task_workspace_hourly_limit_exceeded") {
|
||||
return `Лимит Voice Tasker для workspace исчерпан. Повторите ${retryAfter}.${usageText}`;
|
||||
}
|
||||
|
||||
if ("error" in error && error.error) return String(error.error);
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function getCurrentProjectId() {
|
||||
if (typeof window === "undefined") return null;
|
||||
const match = window.location.pathname.match(/\/projects\/([^/]+)/);
|
||||
@@ -1042,8 +1077,7 @@ export function VoiceTaskerGlobalControl({ workspaceSlug }: Props) {
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
const message =
|
||||
typeof err === "object" && err && "error" in err ? String(err.error) : "Не удалось отправить аудио.";
|
||||
const message = getVoiceTaskErrorMessage(err, "Не удалось отправить аудио.");
|
||||
setError(message);
|
||||
setStatus("error");
|
||||
setToast({
|
||||
@@ -1127,8 +1161,7 @@ export function VoiceTaskerGlobalControl({ workspaceSlug }: Props) {
|
||||
if (closeOnSuccess) handleClose();
|
||||
return result;
|
||||
} catch (err) {
|
||||
const message =
|
||||
typeof err === "object" && err && "error" in err ? String(err.error) : "Не удалось применить Voice Task.";
|
||||
const message = getVoiceTaskErrorMessage(err, "Не удалось применить Voice Task.");
|
||||
setError(message);
|
||||
setStatus("success");
|
||||
if (notify) {
|
||||
|
||||
Reference in New Issue
Block a user