Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 111 additions & 101 deletions bun.lock

Large diffs are not rendered by default.

70 changes: 37 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
"main": "main.js",
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@codemirror/state": "^6.7.4",
"@codemirror/view": "^6.43.11",
"@codemirror/state": "^6.7.6",
"@codemirror/view": "^6.44.2",
"@sveltejs/vite-plugin-svelte": "^5.1.1",
"@tsconfig/svelte": "^5.0.8",
"@tsconfig/svelte": "^5.0.9",
"@types/d3-force": "^3.0.10",
"@types/node": "^22",
"@types/node": "^22.20.7",
"@types/stopword": "^2.0.3",
"@vitest/coverage-v8": "^4.1.11",
"autoprefixer": "^10.5.5",
"@vitest/coverage-v8": "^4.1.12",
"autoprefixer": "^10.7.0",
"events": "^3.3.0",
"fake-indexeddb": "^6.2.5",
"fake-indexeddb": "^6.2.8",
"jsdom": "^27.4.0",
"obsidian": "^1.13.1",
"plotly.js-gl3d-dist-min": "^4.1.1",
"postcss": "^8.5.28",
"svelte": "^5.57.0",
"svelte-check": "^4.7.6",
"obsidian": "^1.14.4",
"plotly.js-gl3d-dist-min": "^4.3.0",
"postcss": "^8.5.33",
"svelte": "^5.59.2",
"svelte-check": "^4.7.8",
"tailwindcss": "^3.4.19",
"typescript": "^5.9.3",
"vite": "^7.3.6",
"vitest": "^4.1.11"
"vite": "^7.3.8",
"vitest": "^4.1.12"
},
"private": true,
"scripts": {
Expand All @@ -50,48 +50,52 @@
},
"type": "module",
"dependencies": {
"@langchain/anthropic": "^1.6.5",
"@langchain/core": "^1.4.1",
"@langchain/anthropic": "^1.6.6",
"@langchain/core": "^1.5.1",
"@langchain/google-genai": "2.3.6",
"@langchain/langgraph": "^1.7.5",
"@langchain/langgraph-checkpoint": "^1.2.3",
"@langchain/langgraph-sdk": "~1.17.0",
"@langchain/mcp-adapters": "^1.1.4",
"@langchain/ollama": "^1.3.0",
"@langchain/openai": "^1.8.4",
"@langchain/ollama": "^1.3.1",
"@langchain/openai": "^1.8.5",
"@msgpack/msgpack": "^3.1.3",
"@tanstack/svelte-query": "^6.1.48",
"bits-ui": "^2.19.0",
"d3-force": "^3.0.0",
"deepagents": "^1.17.0",
"@tanstack/svelte-query": "^6.4.7",
"bits-ui": "^2.22.0",
"d3-force": "^3.0.1",
"deepagents": "^1.17.1",
"diff": "^8.0.4",
"hnsw": "^1.1.1",
"langchain": "^1.6.6",
"langchain": "^1.6.8",
"langsmith": "^0.12.0",
"leiden-ts": "^0.1.0",
"minisearch": "^7.2.0",
"pdf-lib": "^1.17.1",
"pixi-viewport": "^6.0.3",
"pixi.js": "^8.20.1",
"pixi.js": "^8.23.0",
"runed": "^0.37.1",
"stopword": "^3.1.5",
"uuid": "^11.1.1",
"zod": "^4.6.6"
"zod": "^4.6.7"
},
"overrides": {
"hono": "^4.13.7",
"@hono/node-server": "^1.19.10",
"fast-uri": "^3.1.7",
"qs": "^6.16.0",
"hono": "^4.13.11",
"@hono/node-server": "^2.1.3",
"fast-uri": "^3.1.8",
"qs": "^6.17.1",
"path-to-regexp": "^8.4.0",
"body-parser": "^2.3.0",
"body-parser": "^2.4.0",
"ajv": "^8.18.0",
"ip-address": "^10.7.0",
"ip-address": "^10.7.6",
"nanoid": "^3.3.18",
"postcss": "^8.5.28",
"postcss-selector-parser": "^6.1.3",
"postcss-selector-parser": "^6.1.5",
"rollup": "^4.63.1",
"ws": "^8.21.3",
"esbuild": "^0.28.2"
"esbuild": "^0.28.2",
"proxy-addr": "^2.0.8",
"zod": "^4.6.6",
"@modelcontextprotocol/sdk": "^1.31.0",
"source-map-js": "^1.2.2"
}
}
2 changes: 1 addition & 1 deletion src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ export class Agent {
checkpointId,
step: (tuple.metadata?.step as number) ?? 0,
parentCheckpointId,
ts: tuple.checkpoint?.ts as string | undefined,
ts: tuple.checkpoint?.ts,
...(interrupts.length > 0 ? { interrupts } : {}),
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent/contextOverflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function createContextOverflowRecoveryMiddleware(options: {
} catch (error) {
if (!isContextOverflowError(error)) throw error;

const sentTokens = await options.tokenCounter(request.state.messages as BaseMessage[]);
const sentTokens = await options.tokenCounter(request.state.messages);
const keepTokens = Math.max(Math.floor(sentTokens * OVERFLOW_KEEP_RATIO), 1);
Logger.warn(
`[Agent] Context window exceeded at ~${sentTokens} history tokens; summarizing all but the last ~${keepTokens} and retrying once.`,
Expand Down
2 changes: 1 addition & 1 deletion src/agent/generationMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function stampGenerationMetadata(message: AIMessage, generation: Generati

function currentRunMetadata(): Record<string, unknown> | undefined {
try {
return getConfig()?.metadata as Record<string, unknown> | undefined;
return getConfig()?.metadata;
} catch {
return undefined; // outside a graph run (tests calling the model directly)
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent/threadReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function applyMessageWrites(
if (writes.length === 0) return base;
const channel = deltaPrototype.fromCheckpoint(base);
channel.replayWrites(writes.map(([taskId, ch, value]) => [taskId, ch, reviveMessagesValue(value, revive)]));
return channel.isAvailable() ? (channel.get() as BaseMessage[]) : base;
return channel.isAvailable() ? channel.get() : base;
}

function seedMessages(seed: unknown, revive: MessageReviver): BaseMessage[] {
Expand Down
2 changes: 1 addition & 1 deletion src/agent/vaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function redactVaultSettings(data: VaultSettingsData, privacy: VaultSetti

/** Today's file name formatter from Obsidian's global Moment, when present. */
export function windowMomentFormatter(): ((format: string) => string) | undefined {
const moment = (globalThis as { moment?: () => { format(format: string): string } }).moment;
const moment = (self as { moment?: () => { format(format: string): string } }).moment;
return typeof moment === "function" ? (format) => moment().format(format) : undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/SearchModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ export class SearchModal extends SuggestModal<SearchSuggestion> {

private stopGlowAnimation(): void {
if (this.glowAnimationId !== null) {
cancelAnimationFrame(this.glowAnimationId);
window.cancelAnimationFrame(this.glowAnimationId);
this.glowAnimationId = null;
}
if (this.borderEl) {
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useSelection.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ export class SelectionTracker {
try {
// Each window has its own highlight registry and `Highlight` class: a
// range in a popout only paints when registered on that popout's.
const win = (captured.domRanges[0].startContainer.ownerDocument?.defaultView ?? window) as Window &
typeof globalThis;
const win = captured.domRanges[0].startContainer.ownerDocument?.defaultView ?? window;
if (win.CSS?.highlights) {
win.CSS.highlights.set("s2b-selection", new win.Highlight(...captured.domRanges));
}
Expand Down Expand Up @@ -552,7 +551,7 @@ export class SelectionTracker {
// Remove CSS Highlight API highlights
try {
for (const doc of new Set([document, ...this.#listenedDocs])) {
(doc.defaultView as (Window & typeof globalThis) | null)?.CSS?.highlights?.delete("s2b-selection");
doc.defaultView?.CSS?.highlights?.delete("s2b-selection");
}
} catch {
/* safety */
Expand All @@ -579,7 +578,7 @@ export class SelectionTracker {
this.#vaultRefs = [];
for (const doc of [...this.#listenedDocs]) this.#unlisten(doc);
if (this.#refreshFrame !== undefined) {
cancelAnimationFrame(this.#refreshFrame);
window.cancelAnimationFrame(this.#refreshFrame);
this.#refreshFrame = undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function interpolate(message: string, vars: Vars | undefined): string {
function select(message: string | PluralMessage, vars: Vars | undefined, rules: Intl.PluralRules): string {
if (typeof message === "string") return message;
const count = typeof vars?.count === "number" ? vars.count : Number(vars?.count ?? Number.NaN);
const category = Number.isFinite(count) ? (rules.select(count) as PluralCategory) : "other";
const category = Number.isFinite(count) ? rules.select(count) : "other";
if (count === 0 && message.zero !== undefined) return message.zero;
return message[category] ?? message.other;
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/aiTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,9 @@ function isTransportFailure(error: unknown): boolean {
* one, and cancellation is honoured on this side instead — see
* `fetchWithLocalAbort`.
*/
function abortErrorFor(signal: AbortSignal): unknown {
return signal.reason ?? new DOMException("The operation was aborted.", "AbortError");
function abortErrorFor(signal: AbortSignal): Error {
// Every abort in this plugin passes a DOMException reason (or none).
return (signal.reason as Error | undefined) ?? new DOMException("The operation was aborted.", "AbortError");
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/lib/asyncLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export class SyncAsyncLocalStorage<T> implements AsyncLocalStorageLike<T> {

/** The two `async_hooks` primitives the hooks-based implementation needs. */
interface AsyncHooksPrimitives {
createHook(callbacks: {
createHook: (callbacks: {
init(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
}): { enable(): void; disable(): void };
executionAsyncResource(): object;
}) => { enable(): void; disable(): void };
executionAsyncResource: () => object;
}

/** Async resources carry one slot per storage instance, keyed by its symbol. */
Expand All @@ -84,7 +84,7 @@ function asAsyncHooks(candidate: unknown): AsyncHooksPrimitives | null {
function tryRequireAsyncHooks(): AsyncHooksPrimitives | null {
// Electron renderer (Obsidian desktop) exposes CommonJS `require`.
try {
const req = (globalThis as { require?: (id: string) => unknown }).require;
const req = (self as { require?: (id: string) => unknown }).require;
if (typeof req === "function") {
const mod = asAsyncHooks(req("async_hooks"));
if (mod) return mod;
Expand All @@ -95,7 +95,7 @@ function tryRequireAsyncHooks(): AsyncHooksPrimitives | null {
// Plain Node (e.g. Vitest) has no global `require` under ESM, but exposes the
// synchronous builtin accessor `process.getBuiltinModule` (Node 20.16+).
try {
const proc = (globalThis as { process?: { getBuiltinModule?: (id: string) => unknown } }).process;
const proc = (self as { process?: { getBuiltinModule?: (id: string) => unknown } }).process;
if (typeof proc?.getBuiltinModule === "function") {
const mod = asAsyncHooks(proc.getBuiltinModule("async_hooks"));
if (mod) return mod;
Expand Down Expand Up @@ -131,7 +131,7 @@ class HooksAsyncLocalStorage<T> implements AsyncLocalStorageLike<T> {
private enable(): void {
if (this.enabled) return;
this.enabled = true;
enabledStorages.push(this as HooksAsyncLocalStorage<unknown>);
enabledStorages.push(this);
if (!propagationHook) {
const { executionAsyncResource } = this.hooks;
propagationHook = this.hooks.createHook({
Expand Down
5 changes: 3 additions & 2 deletions src/providers/chatProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,10 @@ const defaultFailedAttempt = new (class extends AsyncCaller {
*/
export function embedFailedAttempt(error: unknown): void {
if (typeof error !== "object" || error === null) return;
if (isConnectionRefusedError(error) || isRequestTimeoutError(error)) throw error;
// p-retry hands this hook the thrown Error; rethrowing it aborts the retries.
if (isConnectionRefusedError(error) || isRequestTimeoutError(error)) throw error as Error;
const { status_code: statusCode } = error as { status_code?: unknown };
if (typeof statusCode === "number" && statusCode >= 400 && statusCode < 500) throw error;
if (typeof statusCode === "number" && statusCode >= 400 && statusCode < 500) throw error as Error;
defaultFailedAttempt(error);
}

Expand Down
6 changes: 3 additions & 3 deletions src/providers/openai-compatible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ async function fetchLiteLLMModelInfo(auth: AuthObject, defaultBaseUrl: string):
const data = (response.json as { data?: unknown } | null)?.data;
return Array.isArray(data) ? (data as LiteLLMModelInfoEntry[]) : [];
})().catch((): LiteLLMModelInfoEntry[] => []);
let timer: ReturnType<typeof setTimeout> | undefined;
let timer: number | undefined;
const timeout = new Promise<LiteLLMModelInfoEntry[]>((resolve) => {
timer = setTimeout(() => resolve([]), MODEL_INFO_TIMEOUT_MS);
timer = window.setTimeout(() => resolve([]), MODEL_INFO_TIMEOUT_MS);
});
try {
return await Promise.race([lookup, timeout]);
} finally {
clearTimeout(timer);
window.clearTimeout(timer);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stores/dataStore.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export class PluginDataStore {
const next = await normalizeLoadedData(this._plugin, rawData, this.#data.vaultSlug);
if (generation !== this.#saveGeneration) continue;

const previous = $state.snapshot(this.#data) as PluginData;
const previous: PluginData = $state.snapshot(this.#data);
this.#data = next;
this.#lastDiskContent = content;
return this.applyExternalChange(previous, next);
Expand Down Expand Up @@ -2292,7 +2292,7 @@ export class PluginDataStore {
await this.saveSettingsOrThrow();
// The config is saved either way; a listener that fails logs and leaves
// the index to rebuild, which is what happened before on every rename.
await Promise.all([...this.#providerRenameListeners].map((listener) => listener(oldId, newId)));
await Promise.all([...this.#providerRenameListeners].map(async (listener) => listener(oldId, newId)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/pdfExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export async function renderPdfThumbnail(data: Uint8Array, width: number): Promi
const page = await pdf.getPage(1);
const natural = page.getViewport({ scale: 1 });
const viewport = page.getViewport({ scale: width / natural.width });
const canvas = document.createElement("canvas");
const canvas = createEl("canvas");
canvas.width = Math.ceil(viewport.width);
// The tile shows only the top of the page, so a very tall page (a long
// receipt, a scrolling export) renders into a canvas cut at a square
Expand Down
8 changes: 4 additions & 4 deletions src/utils/tagSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function openTagSearch(app: App, tag: string): Promise<boolean> {

// Try to find existing search view first
let searchLeaf = workspace.getLeavesOfType("search").first();
let searchView = searchLeaf?.view as SearchView | undefined;
let searchView: SearchView | undefined = searchLeaf?.view;

// Check if view exists but isn't fully initialized
// A deferred/lazy view will have no children and no setQuery method
Expand All @@ -60,7 +60,7 @@ export async function openTagSearch(app: App, tag: string): Promise<boolean> {
await commands.executeCommandById("global-search:open");
await new Promise((resolve) => window.setTimeout(resolve, 50));
searchLeaf = workspace.getLeavesOfType("search").first();
searchView = searchLeaf?.view as SearchView | undefined;
searchView = searchLeaf?.view;
}

// Fallback: try to create the view manually
Expand All @@ -72,7 +72,7 @@ export async function openTagSearch(app: App, tag: string): Promise<boolean> {
active: true,
});
searchLeaf = leftLeaf;
searchView = searchLeaf?.view as SearchView | undefined;
searchView = searchLeaf?.view;
}
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function openTagSearch(app: App, tag: string): Promise<boolean> {
}

// Reveal and focus the search pane
workspace.revealLeaf(searchLeaf);
await workspace.revealLeaf(searchLeaf);
workspace.setActiveLeaf(searchLeaf, { focus: true });

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/vectorstore/HNSWVectorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ export class HNSWVectorStore implements VectorStore {
*/
private trackGraph(index: HNSW): void {
const tracked = index as unknown as {
insertNeighbor(node: HnswNode, neighborId: number, level: number): number[];
removeReciprocalLinks(node: HnswNode, removedIds: number[], level: number): void;
insertNeighbor: (node: HnswNode, neighborId: number, level: number) => number[];
removeReciprocalLinks: (node: HnswNode, removedIds: number[], level: number) => void;
};
const insertNeighbor = tracked.insertNeighbor;
const removeReciprocalLinks = tracked.removeReciprocalLinks;
Expand Down
4 changes: 2 additions & 2 deletions src/widget/widgetLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface WidgetLib {
/** Shown in notices. */
displayName: string;
/** The global the inlined build defines, for the skill's documentation. */
global: string;
globalName: string;
/** The build's source text, injected verbatim (after inline-script escaping). */
source: string;
}
Expand All @@ -33,7 +33,7 @@ export const WIDGET_LIBS: Readonly<Record<string, WidgetLib>> = {
plotly: {
id: "plotly",
displayName: "Plotly",
global: "Plotly",
globalName: "Plotly",
source: plotlySource,
},
};
Expand Down
2 changes: 1 addition & 1 deletion test/widget/widgetLibs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PLOTLY_PATH = "node_modules/plotly.js-gl3d-dist-min/plotly-gl3d.min.js";
describe("widget libraries", () => {
it("ships Plotly as a self-contained build that defines its global", () => {
const plotly = WIDGET_LIBS.plotly;
expect(plotly.global).toBe("Plotly");
expect(plotly.globalName).toBe("Plotly");
expect(plotly.source.length).toBeGreaterThan(500_000);
expect(plotly.source).toContain("Plotly");
});
Expand Down
Loading