andy-stack_vaultkeeper-ai/Views/MainView.ts
Andrew Beal 37db1a8908 refactor: improve type safety and add Zod validation for function arguments
- Change function arguments type from `Record<string, object>` to `Record<string, unknown>`
- Add Zod schemas for all AI function arguments validation
- Improve TypeScript types across modals and services
- Add ESLint disable comments for intentional exceptions
- Fix async/await handling in modal and view lifecycle methods
- Update dependencies (@typescript-eslint 8.46.4, rollup 4.53.2, zod 4.1.12)
2025-11-10 19:41:17 +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;
getViewType() {
return VIEW_TYPE_MAIN;
}
getDisplayText() {
return "Vaultkeeper AI";
}
getIcon(): string {
return 'sparkles';
}
// ItemView requires onOpen to return Promise<void>, but mount operations are synchronous
// eslint-disable-next-line @typescript-eslint/require-await
async onOpen() {
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;
}
async onClose() {
if (this.topBar) {
await unmount(this.topBar);
}
if (this.input) {
await unmount(this.input);
}
this.statusBarService.removeStatusBarMessage();
}
}