andy-stack_vaultkeeper-ai/Helpers/Helpers.ts
Andrew Beal 28c8ccb44b feat: add quick actions system with provider-aware model settings
Introduce QuickActionsService and QuickAgent for lightweight, single-shot AI
operations. Add a dedicated quickActionModel setting alongside a new top-level
provider setting, with validation ensuring all models match the selected provider
and provider-specific defaults. Refactor FileSystemService to offer both TFile
and path-based overloads (readFile/readFilePath, writeToFile/writeToFilePath,
patchFile/patchFileAtPath). Replace window/document globals with activeWindow/
activeDocument throughout InputService and VaultkeeperAISettingTab for Obsidian
mobile compatibility.
Update linting packages to latest.
2026-04-20 20:20:22 +01:00

60 lines
No EOL
1.8 KiB
TypeScript

import type VaultkeeperAIPlugin from "main";
import path from "path-browserify";
export function openPluginSettings(plugin: VaultkeeperAIPlugin) {
if (!("setting" in plugin.app) || typeof plugin.app.setting !== "object" || plugin.app.setting === null) {
return;
}
if ("open" in plugin.app.setting) {
// @ts-expect-error - accessing internal API
plugin.app.setting.open();
}
if ("openTabById" in plugin.app.setting) {
// @ts-expect-error - accessing internal API
plugin.app.setting.openTabById(plugin.manifest.id);
}
}
export function closePluginSettings(plugin: VaultkeeperAIPlugin) {
if (!("setting" in plugin.app) || typeof plugin.app.setting !== "object" || plugin.app.setting === null) {
return;
}
if ("close" in plugin.app.setting) {
// @ts-expect-error - accessing internal API
plugin.app.setting.close();
}
}
export function randomSample<T>(array: T[], n: number): T[] {
const result: T[] = [];
const taken = new Set<number>();
while (result.length < n && result.length < array.length) {
const index = Math.floor(Math.random() * array.length);
if (!taken.has(index)) {
taken.add(index);
result.push(array[index]);
}
}
return result;
}
export function shuffleArray<T>(array: T[]): T[] {
const shuffled = [...array];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
export function pathExtname(filePath: string) {
return path.extname(filePath).substring(1).toLocaleLowerCase();
}
export async function sleep(ms: number): Promise<void> {
return new Promise(resolve => activeWindow.setTimeout(resolve, ms));
}