andy-stack_vaultkeeper-ai/Views/MainView.ts
Andrew Beal c69351404b Add ability for users to provide suggestions during diff review through new DiffControls component. Integrate suggestion workflow into chat input, allowing users to approve/reject changes or provide feedback without interrupting the review process.
Improve component lifecycle management by converting DiffService and StatusBarService to extend Component class, ensuring proper cleanup and event handling. Add automatic service cleanup in DependencyService during deregistration.

Refine error handling in AI function responses to return error messages instead of Error objects for better serialization. Update user rejection messaging to provide clearer guidance to AI about stopping actions.
2025-11-27 12:39:08 +00:00

73 lines
No EOL
1.8 KiB
TypeScript

import { ItemView, WorkspaceLeaf } from 'obsidian';
import { mount, unmount } from 'svelte';
import ChatWindow from 'Components/ChatWindow.svelte';
import TopBar from 'Components/TopBar.svelte';
import type { StatusBarService } from 'Services/StatusBarService';
import { Resolve } from 'Services/DependencyService';
import { Services } from 'Services/Services';
export const VIEW_TYPE_MAIN = 'vaultkeeper-ai-main-view';
interface ChatWindowComponent {
focusInput: () => void;
resetChatArea: () => void;
}
export class MainView extends ItemView {
private statusBarService: StatusBarService = Resolve<StatusBarService>(Services.StatusBarService);
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
topBar: ReturnType<typeof TopBar> | undefined;
input: ChatWindowComponent | undefined;
public getViewType() {
return VIEW_TYPE_MAIN;
}
public getDisplayText() {
return "Vaultkeeper AI";
}
public getIcon(): string {
return 'sparkles';
}
protected override onOpen(): Promise<void> {
const container = this.contentEl;
container.empty();
// Mount TopBar with reference to ChatWindow's focus function
this.topBar = mount(TopBar, {
target: container,
props: {
leaf: this.leaf,
onNewConversation: () => {
this.input?.resetChatArea();
this.input?.focusInput();
}
}
});
// Mount ChatWindow first
this.input = mount(ChatWindow, {
target: container,
props: {}
}) as ChatWindowComponent;
return Promise.resolve();
}
public override async onClose(): Promise<void> {
if (this.topBar) {
await unmount(this.topBar);
}
if (this.input) {
await unmount(this.input);
}
this.statusBarService.removeStatusBarMessage();
}
}