feat(vscode): add context menu commands (#83)
* Fix bun lock * Add Context Menu * Make it always visible * Add Improve and Explain Command
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createVSCodeAPIs } from './api';
|
||||
import { onThemeChange, proxyApiRequest, sendBridgeMessage, startSseProxy, stopSseProxy } from './api/bridge';
|
||||
import { onCommand, onThemeChange, proxyApiRequest, sendBridgeMessage, startSseProxy, stopSseProxy } from './api/bridge';
|
||||
import type { RuntimeAPIs } from '../../ui/src/lib/api/types';
|
||||
import {
|
||||
buildVSCodeThemeFromPalette,
|
||||
@@ -566,6 +566,57 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
return originalFetch(input as RequestInfo, init);
|
||||
};
|
||||
|
||||
// Listen for addToContext command from extension
|
||||
onCommand('addToContext', (payload) => {
|
||||
const { text } = payload as { text: string };
|
||||
|
||||
// Import the store dynamically to avoid circular dependencies
|
||||
import('../../ui/src/stores/useSessionStore').then(({ useSessionStore }) => {
|
||||
const store = useSessionStore.getState();
|
||||
const currentText = store.pendingInputText || '';
|
||||
// Append to existing text with double newline separator
|
||||
const newText = currentText ? `${currentText}\n\n${text}` : text;
|
||||
store.setPendingInputText(newText);
|
||||
});
|
||||
});
|
||||
|
||||
// Listen for createSessionWithPrompt command from extension (Explain, Improve Code)
|
||||
onCommand('createSessionWithPrompt', (payload) => {
|
||||
const { prompt } = payload as { prompt: string };
|
||||
|
||||
Promise.all([
|
||||
import('../../ui/src/stores/useSessionStore'),
|
||||
import('../../ui/src/stores/useConfigStore'),
|
||||
]).then(([{ useSessionStore }, { useConfigStore }]) => {
|
||||
const sessionStore = useSessionStore.getState();
|
||||
const configStore = useConfigStore.getState();
|
||||
|
||||
// Open a new session draft first
|
||||
sessionStore.openNewSessionDraft();
|
||||
|
||||
// Get current provider/model/agent configuration
|
||||
const { currentProviderId, currentModelId, currentAgentName } = configStore;
|
||||
|
||||
if (currentProviderId && currentModelId) {
|
||||
// Send the message - this will create the session from the draft and send
|
||||
sessionStore.sendMessage(
|
||||
prompt,
|
||||
currentProviderId,
|
||||
currentModelId,
|
||||
currentAgentName ?? undefined,
|
||||
undefined, // attachments
|
||||
undefined, // agentMentionName
|
||||
undefined // additionalParts
|
||||
).catch((error: unknown) => {
|
||||
console.error('[OpenChamber] Failed to send prompt:', error);
|
||||
});
|
||||
} else {
|
||||
// If no provider/model configured, just set the text and let user send manually
|
||||
sessionStore.setPendingInputText(prompt);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
import('../../ui/src/main')
|
||||
.then(async () => {
|
||||
await waitForUiMount();
|
||||
|
||||
Reference in New Issue
Block a user