@open330/kiwimu 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +230 -0
- package/assets/logos/logo_2_minimalist_icon.png +0 -0
- package/assets/logos/logo_2_minimalist_icon_transparent.png +0 -0
- package/package.json +62 -0
- package/src/build/renderer.ts +128 -0
- package/src/build/static/graph.js +114 -0
- package/src/build/static/search.js +66 -0
- package/src/build/static/style.css +853 -0
- package/src/build/templates.ts +616 -0
- package/src/config.ts +54 -0
- package/src/deploy.ts +32 -0
- package/src/expand/llm.ts +63 -0
- package/src/index.ts +615 -0
- package/src/ingest/docx.ts +15 -0
- package/src/ingest/legacy.ts +66 -0
- package/src/ingest/pdf.ts +14 -0
- package/src/ingest/pptx.ts +39 -0
- package/src/ingest/web.ts +77 -0
- package/src/llm-client.ts +177 -0
- package/src/pipeline/chunker.ts +63 -0
- package/src/pipeline/graph.ts +35 -0
- package/src/pipeline/linker.ts +49 -0
- package/src/pipeline/llm-chunker.ts +368 -0
- package/src/pipeline/llm-linker.ts +84 -0
- package/src/store.ts +209 -0
package/src/deploy.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
|
|
4
|
+
export async function deployGhPages(siteDir: string, message = "deploy: update wiki"): Promise<void> {
|
|
5
|
+
if (!existsSync(siteDir)) {
|
|
6
|
+
throw new Error(`Build directory not found: ${siteDir}. Run 'kiwimu build' first.`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ghPages = await import("gh-pages");
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
ghPages.publish(
|
|
12
|
+
siteDir,
|
|
13
|
+
{
|
|
14
|
+
message,
|
|
15
|
+
dotfiles: false,
|
|
16
|
+
},
|
|
17
|
+
(err) => {
|
|
18
|
+
if (err) reject(err);
|
|
19
|
+
else resolve();
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function deployVercel(siteDir: string): Promise<void> {
|
|
26
|
+
const proc = Bun.spawn(["vercel", "--prod", siteDir], {
|
|
27
|
+
stdout: "inherit",
|
|
28
|
+
stderr: "inherit",
|
|
29
|
+
});
|
|
30
|
+
const exitCode = await proc.exited;
|
|
31
|
+
if (exitCode !== 0) throw new Error("Vercel deploy failed");
|
|
32
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Page } from "../store";
|
|
2
|
+
|
|
3
|
+
const EXPAND_PROMPT = `You are a wiki editor for a learning platform. Given a wiki page about a topic,
|
|
4
|
+
expand it with more detail, examples, and related concepts. Keep the markdown format.
|
|
5
|
+
Add subsections where appropriate. Be accurate and educational.
|
|
6
|
+
|
|
7
|
+
Current page title: {title}
|
|
8
|
+
Current content:
|
|
9
|
+
{content}
|
|
10
|
+
|
|
11
|
+
Related pages for context:
|
|
12
|
+
{context}
|
|
13
|
+
|
|
14
|
+
Write an expanded version of this page in markdown:`;
|
|
15
|
+
|
|
16
|
+
function buildPrompt(page: Page, context: Page[]): string {
|
|
17
|
+
return EXPAND_PROMPT.replace("{title}", page.title)
|
|
18
|
+
.replace("{content}", page.content)
|
|
19
|
+
.replace("{context}", context.slice(0, 10).map((p) => `- ${p.title}`).join("\n"));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function expandWithApi(page: Page, context: Page[], provider: string, model?: string): Promise<string> {
|
|
23
|
+
const prompt = buildPrompt(page, context);
|
|
24
|
+
|
|
25
|
+
if (provider === "anthropic") {
|
|
26
|
+
const { default: Anthropic } = await import("@anthropic-ai/sdk");
|
|
27
|
+
const client = new Anthropic();
|
|
28
|
+
const resp = await client.messages.create({
|
|
29
|
+
model: model || "claude-sonnet-4-20250514",
|
|
30
|
+
max_tokens: 4096,
|
|
31
|
+
messages: [{ role: "user", content: prompt }],
|
|
32
|
+
});
|
|
33
|
+
return (resp.content[0] as any).text;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (provider === "openai") {
|
|
37
|
+
const { default: OpenAI } = await import("openai");
|
|
38
|
+
const client = new OpenAI();
|
|
39
|
+
const resp = await client.chat.completions.create({
|
|
40
|
+
model: model || "gpt-4o",
|
|
41
|
+
messages: [{ role: "user", content: prompt }],
|
|
42
|
+
});
|
|
43
|
+
return resp.choices[0].message.content || "";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function expandWithCli(page: Page, context: Page[], tool: string): Promise<string> {
|
|
50
|
+
const prompt = buildPrompt(page, context);
|
|
51
|
+
const cmd = tool === "claude" ? ["claude", "-p", prompt] : ["codex", "--quiet", "--prompt", prompt];
|
|
52
|
+
|
|
53
|
+
const proc = Bun.spawn(cmd, { stdout: "pipe", stderr: "pipe" });
|
|
54
|
+
const output = await new Response(proc.stdout).text();
|
|
55
|
+
const exitCode = await proc.exited;
|
|
56
|
+
|
|
57
|
+
if (exitCode !== 0) {
|
|
58
|
+
const stderr = await new Response(proc.stderr).text();
|
|
59
|
+
throw new Error(`${tool} failed: ${stderr}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return output;
|
|
63
|
+
}
|