fix(vscode): wire native notifications from runtime events
This commit is contained in:
@@ -79,6 +79,16 @@ type ApiProxyResponsePayload = {
|
||||
bodyBase64: string;
|
||||
};
|
||||
|
||||
type NotificationBridgePayload = {
|
||||
title?: string;
|
||||
body?: string;
|
||||
tag?: string;
|
||||
};
|
||||
|
||||
type NotificationsNotifyRequestPayload = {
|
||||
payload?: NotificationBridgePayload;
|
||||
};
|
||||
|
||||
interface FileEntry {
|
||||
name: string;
|
||||
path: string;
|
||||
@@ -2792,6 +2802,28 @@ export async function handleBridgeMessage(message: BridgeRequest, ctx?: BridgeCo
|
||||
}
|
||||
}
|
||||
|
||||
case 'notifications:can-notify': {
|
||||
return { id, type, success: true, data: true };
|
||||
}
|
||||
|
||||
case 'notifications:notify': {
|
||||
const request = (payload || {}) as NotificationsNotifyRequestPayload;
|
||||
const notification = request.payload || {};
|
||||
const title = typeof notification.title === 'string' ? notification.title.trim() : '';
|
||||
const body = typeof notification.body === 'string' ? notification.body.trim() : '';
|
||||
|
||||
const message = title && body
|
||||
? `${title}: ${body}`
|
||||
: title || body;
|
||||
|
||||
if (!message) {
|
||||
return { id, type, success: true, data: { shown: false } };
|
||||
}
|
||||
|
||||
void vscode.window.showInformationMessage(message);
|
||||
return { id, type, success: true, data: { shown: true } };
|
||||
}
|
||||
|
||||
// ============== Git Operations ==============
|
||||
|
||||
case 'api:git/check': {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { RuntimeAPIs, TerminalAPI, NotificationsAPI } from '@openchamber/ui/lib/api/types';
|
||||
import type { RuntimeAPIs, TerminalAPI } from '@openchamber/ui/lib/api/types';
|
||||
import { createVSCodeFilesAPI } from './files';
|
||||
import { createVSCodeSettingsAPI } from './settings';
|
||||
import { createVSCodePermissionsAPI } from './permissions';
|
||||
@@ -7,6 +7,7 @@ import { createVSCodeEditorAPI } from './editor';
|
||||
import { createVSCodeGitAPI } from './git';
|
||||
import { createVSCodeActionsAPI } from './vscode';
|
||||
import { createVSCodeGitHubAPI } from './github';
|
||||
import { createVSCodeNotificationsAPI } from './notifications';
|
||||
|
||||
// Stub APIs return sensible defaults instead of throwing
|
||||
const createStubTerminalAPI = (): TerminalAPI => ({
|
||||
@@ -17,11 +18,6 @@ const createStubTerminalAPI = (): TerminalAPI => ({
|
||||
close: async () => {},
|
||||
});
|
||||
|
||||
const createStubNotificationsAPI = (): NotificationsAPI => ({
|
||||
notifyAgentCompletion: async () => true,
|
||||
canNotify: () => true,
|
||||
});
|
||||
|
||||
export const createVSCodeAPIs = (): RuntimeAPIs => ({
|
||||
runtime: { platform: 'vscode', isDesktop: false, isVSCode: true, label: 'VS Code Extension' },
|
||||
terminal: createStubTerminalAPI(),
|
||||
@@ -29,7 +25,7 @@ export const createVSCodeAPIs = (): RuntimeAPIs => ({
|
||||
files: createVSCodeFilesAPI(),
|
||||
settings: createVSCodeSettingsAPI(),
|
||||
permissions: createVSCodePermissionsAPI(),
|
||||
notifications: createStubNotificationsAPI(),
|
||||
notifications: createVSCodeNotificationsAPI(),
|
||||
github: createVSCodeGitHubAPI(),
|
||||
tools: createVSCodeToolsAPI(),
|
||||
editor: createVSCodeEditorAPI(),
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { NotificationPayload, NotificationsAPI } from '@openchamber/ui/lib/api/types';
|
||||
import { sendBridgeMessage } from './bridge';
|
||||
|
||||
type NotifyResponse = { shown?: boolean };
|
||||
|
||||
export const createVSCodeNotificationsAPI = (): NotificationsAPI => ({
|
||||
async notifyAgentCompletion(payload?: NotificationPayload): Promise<boolean> {
|
||||
try {
|
||||
const response = await sendBridgeMessage<NotifyResponse>('notifications:notify', { payload });
|
||||
return Boolean(response?.shown);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
async canNotify(): Promise<boolean> {
|
||||
try {
|
||||
return await sendBridgeMessage<boolean>('notifications:can-notify');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user