This commit is contained in:
Timothy Jaeryang Baek
2026-07-16 01:27:52 -04:00
parent 200d447f62
commit cf235738f5
7 changed files with 186 additions and 126 deletions
+13 -4
View File
@@ -3,17 +3,24 @@ import { WEBUI_API_BASE_URL } from '$lib/constants';
export type NotificationTarget = {
id: string;
type: 'webhook';
name: string;
is_default?: boolean;
enabled: boolean;
events: string[];
delivery: 'away' | 'always';
config: {
url?: string;
url_masked?: string;
};
created_at?: number;
updated_at?: number;
};
export type NotificationEvent = {
event: string;
label: string;
description?: string;
};
const jsonRequest = async (url: string, token: string, method = 'GET', body?: object) => {
let error = null;
@@ -43,12 +50,14 @@ const jsonRequest = async (url: string, token: string, method = 'GET', body?: ob
return res;
};
export const getNotificationEvents = async (token: string) =>
jsonRequest(`${WEBUI_API_BASE_URL}/notifications/events`, token);
export const getNotificationEvents = async (token: string): Promise<NotificationEvent[]> => {
const data = await jsonRequest(`${WEBUI_API_BASE_URL}/notifications/events`, token);
return data?.events ?? data ?? [];
};
export const getNotificationTargets = async (
token: string
): Promise<{ targets: NotificationTarget[]; default_target_id: string | null }> =>
): Promise<{ targets: NotificationTarget[] }> =>
jsonRequest(`${WEBUI_API_BASE_URL}/notifications/targets`, token);
export const createNotificationTarget = async (
@@ -25,7 +25,6 @@
let notificationEnabled = false;
let notificationSound = true;
let targets: NotificationTarget[] = [];
let defaultTargetId: string | null = null;
let events: { event: string; label: string; description?: string }[] = [
{
event: 'chat.finished',
@@ -93,7 +92,6 @@
}
if (targetResult.status === 'fulfilled') {
targets = targetResult.value.targets ?? [];
defaultTargetId = targetResult.value.default_target_id ?? null;
} else {
toast.error(`${targetResult.reason}`);
}
@@ -139,7 +137,7 @@
try {
const id = form.id.trim();
const payload: Partial<NotificationTarget> = {
...(id ? { id, name: id } : {}),
...(id ? { id } : {}),
type: 'webhook',
enabled: form.enabled,
events: form.events,
@@ -259,7 +257,7 @@
<span class="shrink-0 text-[0.625rem] text-gray-400 dark:text-gray-600">
{$i18n.t('Webhook')}
</span>
{#if target.id === defaultTargetId}
{#if target.is_default}
<span class="shrink-0 text-[0.625rem] text-gray-400 dark:text-gray-600">
{$i18n.t('Default')}
</span>
@@ -268,7 +266,7 @@
<div
class="truncate text-[0.625rem] leading-tight text-gray-400 dark:text-gray-600"
>
{target.config?.url}
{target.config?.url_masked}
</div>
<div
class="truncate text-[0.625rem] leading-tight text-gray-400 dark:text-gray-600"
@@ -290,7 +288,7 @@
>
{$i18n.t('Send Test')}
</button>
{#if target.id !== defaultTargetId}
{#if !target.is_default}
<button
class="text-[0.625rem] text-gray-400 transition-colors duration-100 hover:text-gray-600 dark:hover:text-gray-300"
type="button"
@@ -343,15 +341,6 @@
{editingId ? $i18n.t('Edit') : $i18n.t('Add Notification Target')}
</h2>
<div class="mb-2 flex gap-1">
<button
class="h-7 rounded-md bg-gray-200/60 px-2 text-xs text-gray-900 transition-colors dark:bg-white/10 dark:text-white"
type="button"
>
{$i18n.t('Webhook')}
</button>
</div>
<div class="text-[0.625rem] text-gray-400 dark:text-gray-600">
{$i18n.t('Target ID for notify')}
</div>