Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions services/notifications/src/lib/agent-session-notification-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
type SendAgentSessionNotificationResult,
} from '@kilocode/notifications';

import { sanitizeTitle, type UserNotificationPreferences } from './cloud-agent-session-push';
import {
DEFAULT_USER_NOTIFICATION_PREFERENCES,
sanitizeTitle,
type UserNotificationPreferences,
} from './cloud-agent-session-push';

export type { SendAgentSessionNotificationParams } from '@kilocode/notifications';

Expand Down Expand Up @@ -47,16 +51,6 @@ export function buildAgentSessionNotificationContent(
};
}

const DEFAULT_PREFERENCES: UserNotificationPreferences = {
agentPushEnabled: true,
chatMessagesEnabled: true,
agentAttentionEnabled: true,
sessionStatusEnabled: true,
kiloclawActivityEnabled: true,
balanceAlertsEnabled: true,
securityFindingsEnabled: true,
};

export type DispatchAgentSessionNotificationPushDeps = {
getSession: (userId: string, cliSessionId: string) => Promise<AgentNotificationSession | null>;
hasOrganizationAccess: (userId: string, organizationId: string) => Promise<boolean>;
Expand Down Expand Up @@ -145,7 +139,7 @@ export async function dispatchAgentSessionNotificationPush(
let prefs: UserNotificationPreferences;
try {
const row = await deps.readPreferences(parsed.userId);
prefs = row ?? DEFAULT_PREFERENCES;
prefs = row ?? DEFAULT_USER_NOTIFICATION_PREFERENCES;
} catch {
return { dispatched: false, reason: 'failed' };
}
Expand Down
21 changes: 12 additions & 9 deletions services/notifications/src/lib/cloud-agent-session-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export type UserNotificationPreferences = {
securityFindingsEnabled: boolean;
};

/** Default-on value used when a preference read returns no row. */
export const DEFAULT_USER_NOTIFICATION_PREFERENCES: UserNotificationPreferences = {
agentPushEnabled: true,
chatMessagesEnabled: true,
agentAttentionEnabled: true,
sessionStatusEnabled: true,
kiloclawActivityEnabled: true,
balanceAlertsEnabled: true,
securityFindingsEnabled: true,
};

const TITLE_MAX_LENGTH = 80;

export function sanitizeTitle(title: string | null | undefined): string | null {
Expand Down Expand Up @@ -90,15 +101,7 @@ async function dispatchSessionPush(
let prefs: UserNotificationPreferences;
try {
const row = await deps.readPreferences(userId);
prefs = row ?? {
agentPushEnabled: true,
chatMessagesEnabled: true,
agentAttentionEnabled: true,
sessionStatusEnabled: true,
kiloclawActivityEnabled: true,
balanceAlertsEnabled: true,
securityFindingsEnabled: true,
};
prefs = row ?? DEFAULT_USER_NOTIFICATION_PREFERENCES;
} catch {
return { dispatched: false, reason: 'dispatch_failed' };
}
Expand Down
17 changes: 5 additions & 12 deletions services/notifications/src/lib/internal-dispatch-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {
PerRecipientResult,
} from '@kilocode/notifications';

import type { UserNotificationPreferences } from './cloud-agent-session-push';
import {
DEFAULT_USER_NOTIFICATION_PREFERENCES,
type UserNotificationPreferences,
} from './cloud-agent-session-push';

type RecipientDOStub = {
dispatchPush: (input: DispatchPushInput) => Promise<DispatchPushOutcome>;
Expand All @@ -27,16 +30,6 @@ export type InternalDispatchDeps = {
readPreferences: (userId: string) => Promise<UserNotificationPreferences | null>;
};

const DEFAULT_PREFERENCES: UserNotificationPreferences = {
agentPushEnabled: true,
chatMessagesEnabled: true,
agentAttentionEnabled: true,
sessionStatusEnabled: true,
kiloclawActivityEnabled: true,
balanceAlertsEnabled: true,
securityFindingsEnabled: true,
};

function securityFindingTitle(
notificationKind: 'new_finding' | 'sla_warning' | 'sla_breach',
severity: string
Expand Down Expand Up @@ -195,7 +188,7 @@ export async function dispatchInternalPushCore(
let prefs: UserNotificationPreferences;
try {
const row = await deps.readPreferences(userId);
prefs = row ?? DEFAULT_PREFERENCES;
prefs = row ?? DEFAULT_USER_NOTIFICATION_PREFERENCES;
} catch {
return 'failed' as const;
}
Expand Down