All files / ollama-view/src/commands framingCommands.ts

37.09% Statements 46/124
100% Branches 1/1
100% Functions 1/1
37.09% Lines 46/124

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 1251x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x 1x                   1x 1x 1x 1x 1x 1x                                                                       1x 1x 1x 1x 1x 1x             1x 1x 1x 1x 1x 1x                                                 1x 1x 1x  
import * as vscode from 'vscode';
 
import { FramingSource } from '../models/modelFraming';
import { FramingEditorPanel } from '../panels/framingEditorPanel';
import { FramingItem } from '../providers/framingProvider';
import { FramingService } from '../services/framingService';
 
interface FramingAction extends vscode.QuickPickItem {
    id: string;
    command: string;
}
 
/**
 * Registers all framing-related commands.
 */
export function registerFramingCommands(context: vscode.ExtensionContext, framingService: FramingService) {
    // Open editor for a framing
    context.subscriptions.push(
        vscode.commands.registerCommand('ollamaView.editFraming', (item: FramingItem) => {
            if (!item || !item.framing) {
                return;
            }
            FramingEditorPanel.createOrShow(context.extensionUri, item.framing, framingService);
        }),
    );
 
    // Duplicate an existing framing
    context.subscriptions.push(
        vscode.commands.registerCommand('ollamaView.duplicateFraming', async (item: FramingItem) => {
            if (!item || !item.framing) {
                return;
            }
            const copy = await framingService.duplicateFraming(item.framing.id);
            if (copy) {
                vscode.window.showInformationMessage(`Model Framing duplicated as '${copy.name}'.`);
                vscode.commands.executeCommand('ollamaView.refresh');
                FramingEditorPanel.createOrShow(context.extensionUri, copy, framingService);
            }
        }),
    );
 
    // Show more actions for a framing
    context.subscriptions.push(
        vscode.commands.registerCommand('ollamaView.showMoreFramingActions', async (item: FramingItem) => {
            if (!item || !item.framing) {
                return;
            }

            const actions: FramingAction[] = [
                {
                    label: '$(edit) Edit',
                    id: 'edit',
                    command: 'ollamaView.editFraming',
                    description: 'Open framing editor',
                },
                {
                    label: '$(copy) Duplicate',
                    id: 'duplicate',
                    command: 'ollamaView.duplicateFraming',
                    description: 'Create a copy of this framing',
                },
            ];

            if (item.framing.source === FramingSource.User) {
                actions.push({
                    label: '$(trash) Delete',
                    id: 'delete',
                    command: 'ollamaView.deleteFraming',
                    description: 'Permanently remove framing',
                });
            }

            const result = await vscode.window.showQuickPick(actions, {
                placeHolder: `Actions for ${item.framing.name}`,
            });

            if (result) {
                vscode.commands.executeCommand(result.command, item);
            }
        }),
    );
 
    // Create a new blank framing
    context.subscriptions.push(
        vscode.commands.registerCommand('ollamaView.createFraming', async () => {
            const framing = await framingService.createFraming({
                name: 'New Model Framing',
                systemMessage: 'You are a helpful assistant.',
            });
            vscode.commands.executeCommand('ollamaView.refresh');
            FramingEditorPanel.createOrShow(context.extensionUri, framing, framingService);
        }),
    );
 
    // Delete a framing
    context.subscriptions.push(
        vscode.commands.registerCommand('ollamaView.deleteFraming', async (item: FramingItem) => {
            if (!item || !item.framing) {
                return;
            }

            const framing = item.framing;
            const confirm = await vscode.window.showWarningMessage(
                `Are you sure you want to delete model framing "${framing.name}"? This action cannot be undone.`,
                { modal: true },
                'Delete',
            );

            if (confirm === 'Delete') {
                const success = await framingService.deleteFraming(framing.id);
                if (success) {
                    vscode.window.showInformationMessage(`Model Framing "${framing.name}" deleted.`);
                    vscode.commands.executeCommand('ollamaView.refresh');

                    // Close panel if open
                    const panel = FramingEditorPanel.panels.get(framing.id);
                    if (panel) {
                        panel.dispose();
                    }
                }
            }
        }),
    );
}