Skip to content

Commit 39141ee

Browse files
committed
cleaning
1 parent 916a0ca commit 39141ee

29 files changed

Lines changed: 301 additions & 78 deletions

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@
7070
"@google-ai/generativelanguage": "^1.1.0",
7171
"@huggingface/inference": "2.7.0",
7272
"@koa/cors": "^5.0.0",
73-
"@langchain/anthropic": "^1.3.26",
74-
"@langchain/community": "^1.1.27",
75-
"@langchain/core": "^1.1.39",
76-
"@langchain/google-genai": "^2.1.26",
77-
"@langchain/mistralai": "^1.0.4",
78-
"@langchain/ollama": "^1.2.2",
79-
"@langchain/openai": "^1.4.3",
80-
"@langchain/perplexity": "^0.1.0",
73+
"@langchain/anthropic": "^1.3.29",
74+
"@langchain/community": "^1.1.28",
75+
"@langchain/core": "^1.1.46",
76+
"@langchain/google-genai": "^2.1.30",
77+
"@langchain/mistralai": "^1.0.8",
78+
"@langchain/ollama": "^1.2.7",
79+
"@langchain/openai": "^1.4.5",
80+
"@langchain/perplexity": "^0.2.0",
8181
"@langchain/textsplitters": "^1.0.1",
8282
"@mozilla/readability": "^0.4.4",
8383
"@radix-ui/react-tooltip": "^1.2.8",
@@ -106,7 +106,8 @@
106106
"json5": "^2.2.3",
107107
"koa": "^2.16.3",
108108
"koa-proxies": "^0.12.4",
109-
"langchain": "^1.3.1",
109+
"@langchain/classic": "^1.0.32",
110+
"langsmith": "^0.7.1",
110111
"live-plugin-manager": "^0.18.1",
111112
"lockfile": "^1.0.4",
112113
"lodash.get": "^4.4.2",

scripts/analyze-bundle.mjs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import esbuild from "esbuild";
2+
import builtins from "builtin-modules";
3+
import path from "path";
4+
import fs from "fs";
5+
import { fileURLToPath } from "url";
6+
import obsidianAliasPlugin from "../obsidian-alias/index.js";
7+
8+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
9+
const root = path.join(__dirname, "..");
10+
11+
const wasmPlugin = (config) => ({
12+
name: "wasm",
13+
setup(build) {
14+
build.onResolve({ filter: /\.wasm$/ }, (args) => {
15+
if (args.resolveDir === "") return;
16+
return {
17+
path: path.isAbsolute(args.path)
18+
? args.path
19+
: path.join(args.resolveDir, args.path),
20+
namespace: `wasm-${config.mode}`,
21+
};
22+
});
23+
build.onLoad({ filter: /.*/, namespace: "wasm-embed" }, async (args) => ({
24+
contents: await fs.promises.readFile(args.path),
25+
loader: "binary",
26+
}));
27+
},
28+
});
29+
30+
const result = await esbuild.build({
31+
entryPoints: [path.join(root, "src/main.ts")],
32+
bundle: true,
33+
metafile: true,
34+
write: false,
35+
minify: true,
36+
plugins: [wasmPlugin({ mode: "embed" }), obsidianAliasPlugin()],
37+
inject: [path.join(root, "obsidian-alias/buffer-inject.mjs")],
38+
external: [
39+
"obsidian",
40+
"electron",
41+
...builtins.filter((m) => m !== "buffer"),
42+
"node:url",
43+
"node:fs",
44+
"node:fs/promises",
45+
"node:path",
46+
"node:module",
47+
"node:async_hooks",
48+
"node:crypto",
49+
"node:stream",
50+
"node:util",
51+
"node:events",
52+
"node:os",
53+
],
54+
format: "cjs",
55+
target: "es2023",
56+
loader: { ".css": "empty" },
57+
absWorkingDir: root,
58+
});
59+
60+
const outBytes = Object.values(result.metafile.outputs)[0]?.bytes ?? 0;
61+
62+
function pkgFromPath(filePath) {
63+
const nm = filePath.split("node_modules/");
64+
if (nm.length < 2) {
65+
if (filePath.includes("/src/")) return "(plugin src)";
66+
return "(other)";
67+
}
68+
let rest = nm[nm.length - 1];
69+
if (rest.startsWith(".pnpm/")) {
70+
const match = rest.match(/node_modules\/((?:@[^/]+\/[^/]+|[^/]+))/);
71+
return match ? match[1] : rest.split("/")[0];
72+
}
73+
if (rest.startsWith("@")) {
74+
const parts = rest.split("/");
75+
return `${parts[0]}/${parts[1]}`;
76+
}
77+
return rest.split("/")[0];
78+
}
79+
80+
const byPkg = new Map();
81+
for (const [file, meta] of Object.entries(result.metafile.inputs)) {
82+
const pkg = pkgFromPath(file);
83+
byPkg.set(pkg, (byPkg.get(pkg) ?? 0) + meta.bytes);
84+
}
85+
86+
const sorted = [...byPkg.entries()].sort((a, b) => b[1] - a[1]);
87+
88+
console.log(`\nBundled output (minified): ${(outBytes / 1024 / 1024).toFixed(2)} MB\n`);
89+
console.log("Top packages by contributed source bytes (pre-tree-shake input):\n");
90+
console.log("Rank Size Package");
91+
console.log("---- -------- -------");
92+
sorted.slice(0, 40).forEach(([pkg, bytes], i) => {
93+
const mb = bytes / 1024 / 1024;
94+
const label = mb >= 0.1 ? `${mb.toFixed(2)} MB` : `${(bytes / 1024).toFixed(0)} KB`;
95+
console.log(`${String(i + 1).padStart(4)} ${label.padEnd(9)} ${pkg}`);
96+
});
97+
98+
const langchain = sorted.filter(([p]) => p.includes("langchain") || p === "langchain");
99+
const lcTotal = langchain.reduce((s, [, b]) => s + b, 0);
100+
console.log(`\nLangChain family total (input bytes): ${(lcTotal / 1024 / 1024).toFixed(2)} MB across ${langchain.length} packages`);

src/LLMProviders/custom/anthropic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getHBValues } from "#/utils/barhandles";
55
import SettingItem from "#/ui/settings/components/item";
66
import Input from "#/ui/settings/components/input";
77
import CustomProvider, { default_values as baseDefaultValues } from "./base";
8-
import { IconExternalLink } from "@tabler/icons-react";
8+
import { IconExternalLink } from "#/ui/icons";
99

1010
const globalVars: Record<string, boolean> = {
1111
n: true,

src/LLMProviders/langchain/azureOpenAIChat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
} from "@langchain/openai";
77
import { BaseChatModelParams } from "@langchain/core/language_models/chat_models";
88

9-
import { IconExternalLink } from "@tabler/icons-react";
9+
import { IconExternalLink } from "#/ui/icons";
1010
import LLMProviderInterface, { LLMConfig } from "../interface";
1111
import debug from "debug";
1212

src/LLMProviders/langchain/azureOpenAIInstruct.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import LangchainBase from "./base";
33
import type { AzureOpenAIInput, OpenAIInput } from "@langchain/openai";
4-
import { IconExternalLink } from "@tabler/icons-react";
4+
import { IconExternalLink } from "#/ui/icons";
55

66
import LLMProviderInterface, { LLMConfig } from "../interface";
77
import debug from "debug";

src/LLMProviders/langchain/chatanthropic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import debug from "debug";
33
import LangchainBase from "./base";
44

55
import LLMProviderInterface, { LLMConfig } from "../interface";
6-
import { IconExternalLink } from "@tabler/icons-react";
6+
import { IconExternalLink } from "#/ui/icons";
77
import { BaseLanguageModelParams } from "@langchain/core/language_models/base";
88

99
import { Dropdown, fetchWithoutCORS, Input, Message, SettingItem, useGlobal } from "../refs";

src/LLMProviders/langchain/googleGenerativeAI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import LangchainBase from "./base";
33
import { GoogleGenerativeAIChatInput } from "@langchain/google-genai";
44
import React from "react";
55
import LLMProviderInterface, { LLMConfig } from "../interface";
6-
import { IconExternalLink } from "@tabler/icons-react";
6+
import { IconExternalLink } from "#/ui/icons";
77
import debug from "debug";
88
import { HeaderEditor, ModelsHandler } from "../utils";
99

src/LLMProviders/langchain/hf.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import debug from "debug";
33
import LangchainBase from "./base";
44
import LLMProviderInterface, { LLMConfig } from "../interface";
5-
import { IconExternalLink } from "@tabler/icons-react";
5+
import { IconExternalLink } from "#/ui/icons";
66
import { BaseLLMParams } from "@langchain/core/language_models/llms";
77
import type { HFInput } from "@langchain/community/llms/hf";
88

src/LLMProviders/langchain/mistralaiChat.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import LangchainBase from "./base";
22
import React from "react";
33
import LLMProviderInterface, { LLMConfig } from "../interface";
4-
import { IconExternalLink } from "@tabler/icons-react";
4+
import { IconExternalLink } from "#/ui/icons";
55

66
import debug from "debug";
77
import { ModelsHandler } from "../utils";
8-
import { OpenAIChatInput } from "@langchain/openai";
98

109
const logger = debug("textgenerator:llmProvider:mistralChat");
1110

1211
import { Input, SettingItem, useGlobal } from "../refs";
13-
import { MistralAIInput } from "@langchain/mistralai";
12+
import type { MistralAIInput } from "@langchain/mistralai";
1413

1514
const default_values = {
1615
basePath: "https://api.mistral.ai/v1",
@@ -51,7 +50,6 @@ export default class LangchainMistralAIChatProvider
5150
getConfig(options: LLMConfig): Partial<MistralAIInput> {
5251
return this.cleanConfig({
5352
apiKey: options.api_key,
54-
5553
// ------------Necessary stuff--------------
5654
modelKwargs: {
5755
...options.modelKwargs,
@@ -71,7 +69,7 @@ export default class LangchainMistralAIChatProvider
7169

7270
maxRetries: 3,
7371
headers: options.headers || undefined,
74-
} as Partial<OpenAIChatInput>);
72+
} as Partial<MistralAIInput>);
7573
}
7674
async load() {
7775
const { MistralAI } = await import("@langchain/mistralai");

src/LLMProviders/langchain/ollama.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import debug from "debug";
33
import LangchainBase from "./base";
44
import LLMProviderInterface, { LLMConfig } from "../interface";
5-
import { IconExternalLink } from "@tabler/icons-react";
5+
import { IconExternalLink } from "#/ui/icons";
66
import { BaseLLMParams } from "@langchain/core/language_models/llms";
77

88
import { OllamaInput } from "@langchain/community/llms/ollama";

0 commit comments

Comments
 (0)