mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
- Stop chat service before loading conversations and resetting - Add proper diff cancellation with resolve callback - Add runtime type guards for plugin settings API access - Improve diff view layout with padding adjustments - Remove overly permissive TypeScript ESLint overrides
40 lines
No EOL
1.2 KiB
TypeScript
40 lines
No EOL
1.2 KiB
TypeScript
import type VaultkeeperAIPlugin from "main";
|
|
|
|
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 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;
|
|
} |