mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
- Deleted highlight-default.min.css, katex.min.css, and markdown.css as they are no longer needed. - Implemented StreamingMarkdownService for improved markdown processing with support for math and syntax highlighting. - Added StreamingService for handling streaming requests to the Gemini API with error handling and chunk parsing. - Introduced styles_old.css for enhanced code block styling and better readability.
80 lines
No EOL
2 KiB
TypeScript
80 lines
No EOL
2 KiB
TypeScript
import { type Vault } from "obsidian";
|
|
|
|
export function isValidJson(str: string): boolean {
|
|
try {
|
|
JSON.parse(str);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
export async function createDirectories(vault: Vault, filePath: string) {
|
|
const dirPath: string = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
|
|
const dirs: string[] = dirPath.split('/');
|
|
|
|
let currentPath = "";
|
|
for (const dir of dirs) {
|
|
if (dir) {
|
|
currentPath = currentPath ? `${currentPath}/${dir}` : dir;
|
|
if (vault.getAbstractFileByPath(currentPath) == null) {
|
|
await vault.createFolder(currentPath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export function loadExternalCSS(href: string): Promise<void> {
|
|
return new Promise((resolve, reject) => {
|
|
const link = document.createElement('link');
|
|
link.rel = 'stylesheet';
|
|
link.type = 'text/css';
|
|
link.href = href;
|
|
link.onload = () => resolve();
|
|
link.onerror = reject;
|
|
document.head.appendChild(link);
|
|
});
|
|
}
|
|
|
|
export class Semaphore {
|
|
private max: number;
|
|
private count: number;
|
|
private readonly waitAsync: boolean;
|
|
private readonly queue: ((value: boolean) => void)[];
|
|
|
|
constructor(max: number, waitAsync: boolean) {
|
|
this.max = max;
|
|
this.count = max;
|
|
this.waitAsync = waitAsync;
|
|
this.queue = [];
|
|
}
|
|
|
|
async wait(): Promise<boolean> {
|
|
if (this.count > 0) {
|
|
this.count--;
|
|
return true;
|
|
}
|
|
|
|
if (!this.waitAsync) {
|
|
return false;
|
|
}
|
|
|
|
return new Promise<boolean>((resolve) => {
|
|
this.queue.push(resolve);
|
|
});
|
|
}
|
|
|
|
release(): void {
|
|
if (this.queue.length > 0) {
|
|
const resolve = this.queue.shift();
|
|
if (resolve) {
|
|
resolve(true);
|
|
}
|
|
} else {
|
|
if (this.count < this.max) {
|
|
this.count++;
|
|
}
|
|
}
|
|
}
|
|
} |