mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add push notifications with VAPID (#110)
* Add OAuth authentication support for MCP servers * Improve mobile text sizing with responsive text classes * refactor: improve virtualized text viewer with React Query infinite scroll and simplified buffering * Add push notifications with VAPID and PWA support * feat: add VAPID environment variables for push notifications * Replace SquareFill with MicOff icon for stop recording buttons * Send push notifications when app is not focused * Fix stop generation button icons to use X instead of MicOff * feat: enhance push notification logging and debugging - Add structured logging throughout push notification flow - Improve error handling with detailed diagnostics - Add /api/notifications/debug endpoint for troubleshooting - Enhanced test notification response with per-subscription results - Add service worker logging and better install/activate handling * Improve VAPID push notification configuration with validation and better defaults - Add validation warnings for VAPID_SUBJECT format (requires mailto: prefix for iOS/Safari) - Expose VAPID details via notifications API endpoint - Update default VAPID_SUBJECT from mailto:admin@opencode.local to empty string - Enhance VAPID logging with key lengths and subject info - Improve documentation in .env.example with setup instructions * Fix notification URL to use repo ID instead of filesystem path * Clean up push notification logging and debug endpoints * Add push notifications documentation
This commit is contained in:
1 parent
3d9e9b8322
commit
ae644e851d
47 files changed
+4506
-67
No files matched your search
@@ -87,6 +87,12 @@ export const ENV = {
|
||||
LOG_LEVEL: getEnvString('LOG_LEVEL', DEFAULTS.LOGGING.LOG_LEVEL),
|
||||
},
|
||||
|
||||
VAPID: {
|
||||
PUBLIC_KEY: process.env.VAPID_PUBLIC_KEY ?? '',
|
||||
PRIVATE_KEY: process.env.VAPID_PRIVATE_KEY ?? '',
|
||||
SUBJECT: process.env.VAPID_SUBJECT ?? '',
|
||||
},
|
||||
|
||||
AUTH: {
|
||||
SECRET: getEnvString('AUTH_SECRET', process.env.NODE_ENV === 'production' ? '' : generateDefaultSecret()),
|
||||
TRUSTED_ORIGINS: getEnvString('AUTH_TRUSTED_ORIGINS', 'http://localhost:5173,http://localhost:5003'),
|
||||
|
||||
@@ -4,3 +4,4 @@ export * from './files'
|
||||
export * from './opencode'
|
||||
export * from './auth'
|
||||
export * from './sse'
|
||||
export * from './notifications'
|
||||
@@ -0,0 +1,69 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const NotificationEventType = {
|
||||
PERMISSION_ASKED: "permission.asked",
|
||||
QUESTION_ASKED: "question.asked",
|
||||
SESSION_ERROR: "session.error",
|
||||
SESSION_IDLE: "session.idle",
|
||||
} as const;
|
||||
|
||||
export type NotificationEventType =
|
||||
(typeof NotificationEventType)[keyof typeof NotificationEventType];
|
||||
|
||||
export const NotificationPreferencesSchema = z.object({
|
||||
enabled: z.boolean(),
|
||||
events: z.object({
|
||||
permissionAsked: z.boolean(),
|
||||
questionAsked: z.boolean(),
|
||||
sessionError: z.boolean(),
|
||||
sessionIdle: z.boolean(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const DEFAULT_NOTIFICATION_PREFERENCES = {
|
||||
enabled: false,
|
||||
events: {
|
||||
permissionAsked: true,
|
||||
questionAsked: true,
|
||||
sessionError: true,
|
||||
sessionIdle: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const PushSubscriptionKeysSchema = z.object({
|
||||
p256dh: z.string(),
|
||||
auth: z.string(),
|
||||
});
|
||||
|
||||
export const PushSubscriptionRequestSchema = z.object({
|
||||
endpoint: z.string().url(),
|
||||
keys: PushSubscriptionKeysSchema,
|
||||
deviceName: z.string().optional(),
|
||||
});
|
||||
|
||||
export const PushSubscriptionRecordSchema = z.object({
|
||||
id: z.number(),
|
||||
userId: z.string(),
|
||||
endpoint: z.string(),
|
||||
p256dh: z.string(),
|
||||
auth: z.string(),
|
||||
deviceName: z.string().nullable(),
|
||||
createdAt: z.number(),
|
||||
lastUsedAt: z.number().nullable(),
|
||||
});
|
||||
|
||||
export const PushNotificationPayloadSchema = z.object({
|
||||
title: z.string(),
|
||||
body: z.string(),
|
||||
icon: z.string().optional(),
|
||||
badge: z.string().optional(),
|
||||
tag: z.string().optional(),
|
||||
data: z
|
||||
.object({
|
||||
url: z.string().optional(),
|
||||
eventType: z.string(),
|
||||
sessionId: z.string().optional(),
|
||||
directory: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from "zod";
|
||||
import { NotificationPreferencesSchema, DEFAULT_NOTIFICATION_PREFERENCES } from "./notifications";
|
||||
|
||||
export const CustomCommandSchema = z.object({
|
||||
name: z.string(),
|
||||
@@ -124,6 +125,7 @@ export const UserPreferencesSchema = z.object({
|
||||
gitIdentity: GitIdentitySchema.optional(),
|
||||
tts: TTSConfigSchema.optional(),
|
||||
stt: STTConfigSchema.optional(),
|
||||
notifications: NotificationPreferencesSchema.optional(),
|
||||
lastKnownGoodConfig: z.string().optional(),
|
||||
repoOrder: z.array(z.number()).optional(),
|
||||
});
|
||||
@@ -169,6 +171,7 @@ export const DEFAULT_USER_PREFERENCES = {
|
||||
gitIdentity: DEFAULT_GIT_IDENTITY,
|
||||
tts: DEFAULT_TTS_CONFIG,
|
||||
stt: DEFAULT_STT_CONFIG,
|
||||
notifications: DEFAULT_NOTIFICATION_PREFERENCES,
|
||||
};
|
||||
|
||||
export const SettingsResponseSchema = z.object({
|
||||
|
||||
@@ -5,4 +5,10 @@ export const SSESubscribeSchema = z.object({
|
||||
directories: z.array(z.string()),
|
||||
});
|
||||
|
||||
export const SSEVisibilitySchema = z.object({
|
||||
clientId: z.string().min(1),
|
||||
visible: z.boolean(),
|
||||
});
|
||||
|
||||
export type SSESubscribeRequest = z.infer<typeof SSESubscribeSchema>;
|
||||
export type SSEVisibilityRequest = z.infer<typeof SSEVisibilitySchema>;
|
||||
@@ -30,6 +30,12 @@ import {
|
||||
SessionSchema,
|
||||
MessageSchema,
|
||||
} from '../schemas/opencode'
|
||||
import {
|
||||
NotificationPreferencesSchema,
|
||||
PushSubscriptionRequestSchema,
|
||||
PushSubscriptionRecordSchema,
|
||||
PushNotificationPayloadSchema,
|
||||
} from '../schemas/notifications'
|
||||
|
||||
export type UserPreferences = z.infer<typeof UserPreferencesSchema>
|
||||
export type SettingsResponse = z.infer<typeof SettingsResponseSchema>
|
||||
@@ -58,6 +64,11 @@ export type FilePatchRequest = z.infer<typeof FilePatchRequestSchema>
|
||||
export type Session = z.infer<typeof SessionSchema>
|
||||
export type Message = z.infer<typeof MessageSchema>
|
||||
|
||||
export type NotificationPreferences = z.infer<typeof NotificationPreferencesSchema>
|
||||
export type PushSubscriptionRequest = z.infer<typeof PushSubscriptionRequestSchema>
|
||||
export type PushSubscriptionRecord = z.infer<typeof PushSubscriptionRecordSchema>
|
||||
export type PushNotificationPayload = z.infer<typeof PushNotificationPayloadSchema>
|
||||
|
||||
export interface ErrorResponse {
|
||||
error: string
|
||||
details?: unknown
|
||||
|
||||
Reference in new issue
Block a user