@lgrammel/kiwix-tool 1.0.0 → 2.0.1
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/README.md +89 -13
- package/dist/index.d.ts +51 -50
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +190 -73
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,32 +1,108 @@
|
|
|
1
1
|
# @lgrammel/kiwix-tool
|
|
2
2
|
|
|
3
|
-
AI SDK 7
|
|
3
|
+
AI SDK 7 tool package for searching and reading local [Kiwix](https://kiwix.org/) `.zim` archives from Node.js.
|
|
4
|
+
|
|
5
|
+
Use it when a local agent should answer from an offline knowledge base such as Wikipedia, Stack Exchange, project docs, or another ZIM archive.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @lgrammel/kiwix-tool
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This package uses `@openzim/libzim` under the hood and must run in a Node.js-compatible environment.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
4
16
|
|
|
5
17
|
```ts
|
|
6
|
-
import {
|
|
18
|
+
import { kiwixReadPage, kiwixSearch } from "@lgrammel/kiwix-tool";
|
|
19
|
+
import { openai } from "@ai-sdk/openai";
|
|
7
20
|
import { ToolLoopAgent } from "ai";
|
|
8
21
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
22
|
+
const prompt =
|
|
23
|
+
process.argv.slice(2).join(" ") || "Explain what Kiwix is in three concise bullet points.";
|
|
24
|
+
|
|
25
|
+
const kiwixArchiveContext = {
|
|
26
|
+
zimPath: process.env.WIKIPEDIA_ZIM_PATH ?? "~/opt/zim/wikipedia.zim"
|
|
27
|
+
};
|
|
12
28
|
|
|
13
29
|
const agent = new ToolLoopAgent({
|
|
14
|
-
model,
|
|
15
|
-
instructions:
|
|
30
|
+
model: openai("gpt-5.5"),
|
|
31
|
+
instructions:
|
|
32
|
+
"Answer using the local Wikipedia archive. Search before reading pages, and cite the page titles you used.",
|
|
16
33
|
tools: {
|
|
17
|
-
wikipediaSearch:
|
|
18
|
-
wikipediaRead:
|
|
34
|
+
wikipediaSearch: kiwixSearch,
|
|
35
|
+
wikipediaRead: kiwixReadPage
|
|
36
|
+
},
|
|
37
|
+
toolsContext: {
|
|
38
|
+
wikipediaSearch: {
|
|
39
|
+
...kiwixArchiveContext,
|
|
40
|
+
searchResultLimit: 5,
|
|
41
|
+
searchCandidateLimit: 100
|
|
42
|
+
},
|
|
43
|
+
wikipediaRead: {
|
|
44
|
+
...kiwixArchiveContext,
|
|
45
|
+
readMaxBytes: 80 * 1024
|
|
46
|
+
}
|
|
19
47
|
}
|
|
20
48
|
});
|
|
21
49
|
|
|
22
50
|
const result = await agent.generate({
|
|
23
|
-
prompt
|
|
51
|
+
prompt
|
|
24
52
|
});
|
|
53
|
+
|
|
54
|
+
console.log(result.text);
|
|
25
55
|
```
|
|
26
56
|
|
|
27
57
|
## Tools
|
|
28
58
|
|
|
29
|
-
- `
|
|
30
|
-
- `
|
|
59
|
+
- `kiwixSearch`: full-text search over the archive. It fetches a configurable number of raw libzim results, reranks them to prefer exact and prefix title/path matches, then returns the configured number of results. Input is `{ query }`. Output is `results` with `title`, `path`, and optional `snippet`.
|
|
60
|
+
- `kiwixReadPage`: read a page by exact path returned from search. Input is `{ path }`. Output is `title`, `path`, `content`, and `truncated`.
|
|
61
|
+
|
|
62
|
+
The model cannot choose result, candidate, or read limits. Search result count, internal search candidate count, and page byte limits are configured only on the tool that uses them through each tool's `toolsContext` entry, validated by that tool's `contextSchema`, so tool outputs stay predictable for agents. HTML pages are converted to UTF-8 text before returning them to the model.
|
|
63
|
+
|
|
64
|
+
## API
|
|
65
|
+
|
|
66
|
+
Use the exported tools directly and pass tool-specific configuration through `toolsContext`:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { kiwixReadPage, kiwixSearch } from "@lgrammel/kiwix-tool";
|
|
70
|
+
|
|
71
|
+
const kiwixArchiveContext = {
|
|
72
|
+
zimPath: "~/opt/zim/wikipedia.zim"
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const tools = {
|
|
76
|
+
wikipediaSearch: kiwixSearch,
|
|
77
|
+
wikipediaRead: kiwixReadPage
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const toolsContext = {
|
|
81
|
+
wikipediaSearch: {
|
|
82
|
+
...kiwixArchiveContext,
|
|
83
|
+
searchResultLimit: 5,
|
|
84
|
+
searchCandidateLimit: 100
|
|
85
|
+
},
|
|
86
|
+
wikipediaRead: {
|
|
87
|
+
...kiwixArchiveContext,
|
|
88
|
+
readMaxBytes: 80 * 1024
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Each tool keeps its archive connection private and refreshes it if the archive context changes.
|
|
94
|
+
|
|
95
|
+
## Shared Archive Context
|
|
96
|
+
|
|
97
|
+
- `zimPath`: path to the `.zim` file. `~/` is expanded to the current user's home directory.
|
|
98
|
+
- `preloadXapianDb`: preload the full-text index when opening the archive. Defaults to `true`.
|
|
99
|
+
- `preloadDirentRanges`: number of directory entry ranges to preload when opening the archive.
|
|
100
|
+
|
|
101
|
+
## Search Context
|
|
102
|
+
|
|
103
|
+
- `searchResultLimit`: fixed number of search results returned to the agent. Defaults to `5` and is capped at `10`.
|
|
104
|
+
- `searchCandidateLimit`: number of raw libzim results fetched before title-aware reranking. Defaults to `100` and is capped at `500`. The effective candidate limit is never lower than `searchResultLimit`.
|
|
105
|
+
|
|
106
|
+
## Read Context
|
|
31
107
|
|
|
32
|
-
|
|
108
|
+
- `readMaxBytes`: maximum page bytes read before conversion to text. Defaults to `81920` and is capped at `524288`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,71 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ToolExecutionOptions } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
3
|
+
declare const kiwixSearchInputSchema: z.ZodObject<{
|
|
4
4
|
query: z.ZodString;
|
|
5
5
|
}, z.core.$strip>;
|
|
6
|
-
|
|
6
|
+
declare const kiwixReadInputSchema: z.ZodObject<{
|
|
7
7
|
path: z.ZodString;
|
|
8
8
|
}, z.core.$strip>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
zimPath:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Preload the full-text index when opening the archive.
|
|
28
|
-
*/
|
|
29
|
-
preloadXapianDb?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Number of directory entry ranges to preload when opening the archive.
|
|
32
|
-
*/
|
|
33
|
-
preloadDirentRanges?: number;
|
|
34
|
-
}
|
|
35
|
-
export interface KiwixSearchResult {
|
|
9
|
+
declare const kiwixSearchContextSchema: z.ZodObject<{
|
|
10
|
+
zimPath: z.ZodString;
|
|
11
|
+
preloadXapianDb: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
preloadDirentRanges: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
searchResultLimit: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
searchCandidateLimit: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
declare const kiwixReadPageContextSchema: z.ZodObject<{
|
|
17
|
+
zimPath: z.ZodString;
|
|
18
|
+
preloadXapianDb: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
preloadDirentRanges: z.ZodOptional<z.ZodNumber>;
|
|
20
|
+
readMaxBytes: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
type ParsedKiwixSearchInput = z.output<typeof kiwixSearchInputSchema>;
|
|
23
|
+
type ParsedKiwixReadInput = z.output<typeof kiwixReadInputSchema>;
|
|
24
|
+
type KiwixSearchContext = z.output<typeof kiwixSearchContextSchema>;
|
|
25
|
+
type KiwixReadPageContext = z.output<typeof kiwixReadPageContextSchema>;
|
|
26
|
+
interface KiwixSearchResult {
|
|
36
27
|
title: string;
|
|
37
28
|
path: string;
|
|
38
29
|
snippet?: string;
|
|
39
30
|
}
|
|
40
|
-
|
|
31
|
+
interface KiwixSearchOutput {
|
|
41
32
|
results: KiwixSearchResult[];
|
|
42
33
|
}
|
|
43
|
-
|
|
34
|
+
interface KiwixReadOutput {
|
|
44
35
|
title: string;
|
|
45
36
|
path: string;
|
|
46
37
|
content: string;
|
|
47
38
|
truncated: boolean;
|
|
48
39
|
}
|
|
49
|
-
|
|
50
|
-
export type KiwixReadTool = Tool<ParsedKiwixReadInput, KiwixReadOutput>;
|
|
51
|
-
export declare class KiwixReader {
|
|
40
|
+
declare class KiwixSearchTool {
|
|
52
41
|
#private;
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
42
|
+
readonly description = "Search the local Kiwix archive. Returns page paths, titles, and short snippets. Use the read tool with a returned path to read a page.";
|
|
43
|
+
readonly inputSchema: z.ZodObject<{
|
|
44
|
+
query: z.ZodString;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
readonly contextSchema: z.ZodObject<{
|
|
47
|
+
zimPath: z.ZodString;
|
|
48
|
+
preloadXapianDb: z.ZodOptional<z.ZodBoolean>;
|
|
49
|
+
preloadDirentRanges: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
searchResultLimit: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
searchCandidateLimit: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
execute: ({ query }: ParsedKiwixSearchInput, { context }: ToolExecutionOptions<KiwixSearchContext>) => Promise<KiwixSearchOutput>;
|
|
59
54
|
}
|
|
60
|
-
|
|
55
|
+
declare class KiwixReadPageTool {
|
|
61
56
|
#private;
|
|
62
|
-
readonly
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
readonly description = "Read one page from the local Kiwix archive by exact path from the search tool.";
|
|
58
|
+
readonly inputSchema: z.ZodObject<{
|
|
59
|
+
path: z.ZodString;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
readonly contextSchema: z.ZodObject<{
|
|
62
|
+
zimPath: z.ZodString;
|
|
63
|
+
preloadXapianDb: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
preloadDirentRanges: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
readMaxBytes: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
execute: ({ path }: ParsedKiwixReadInput, { context }: ToolExecutionOptions<KiwixReadPageContext>) => Promise<KiwixReadOutput>;
|
|
66
68
|
}
|
|
67
|
-
export declare
|
|
68
|
-
export declare
|
|
69
|
-
export
|
|
70
|
-
export declare function kiwixReadTool(reader: KiwixReader): KiwixReadTool;
|
|
69
|
+
export declare const kiwixSearch: KiwixSearchTool;
|
|
70
|
+
export declare const kiwixReadPage: KiwixReadPageTool;
|
|
71
|
+
export {};
|
|
71
72
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,oBAAoB,EAAE,MAAM,IAAI,CAAC;AAKrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,QAAA,MAAM,sBAAsB;;iBAE1B,CAAC;AAEH,QAAA,MAAM,oBAAoB;;iBAExB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gBH;AAED,eAAO,MAAM,WAAW,iBAIvB,CAAC;AAEF,eAAO,MAAM,aAAa,mBAIzB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,112 +1,170 @@
|
|
|
1
|
-
import { tool } from "ai";
|
|
2
1
|
import { convert as htmlToText } from "html-to-text";
|
|
3
2
|
import { homedir } from "node:os";
|
|
4
3
|
import { isAbsolute, join } from "node:path";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
const DEFAULT_SEARCH_RESULT_LIMIT = 5;
|
|
7
6
|
const MAX_SEARCH_RESULT_LIMIT = 10;
|
|
7
|
+
const DEFAULT_SEARCH_CANDIDATE_LIMIT = 100;
|
|
8
|
+
const MAX_SEARCH_CANDIDATE_LIMIT = 500;
|
|
8
9
|
const DEFAULT_READ_MAX_BYTES = 80 * 1024;
|
|
9
10
|
const HARD_READ_MAX_BYTES = 512 * 1024;
|
|
10
11
|
const MAX_SNIPPET_LENGTH = 600;
|
|
11
|
-
|
|
12
|
+
const kiwixSearchInputSchema = z.object({
|
|
12
13
|
query: z.string().min(1).describe("Full-text search query for the Kiwix archive."),
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
+
const kiwixReadInputSchema = z.object({
|
|
15
16
|
path: z.string().min(1).describe("Exact ZIM page path returned by the search tool."),
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
+
const kiwixArchiveContextSchema = z.object({
|
|
19
|
+
zimPath: z
|
|
20
|
+
.string()
|
|
21
|
+
.min(1)
|
|
22
|
+
.describe("Path to the `.zim` file. A leading `~/` is expanded to the current user's home directory."),
|
|
23
|
+
preloadXapianDb: z
|
|
24
|
+
.boolean()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Preload the full-text index when opening the archive. Defaults to true."),
|
|
27
|
+
preloadDirentRanges: z
|
|
28
|
+
.number()
|
|
29
|
+
.int()
|
|
30
|
+
.nonnegative()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("Number of directory entry ranges to preload when opening the archive."),
|
|
33
|
+
});
|
|
34
|
+
const kiwixSearchContextSchema = kiwixArchiveContextSchema.extend({
|
|
35
|
+
searchResultLimit: z
|
|
36
|
+
.number()
|
|
37
|
+
.int()
|
|
38
|
+
.positive()
|
|
39
|
+
.max(MAX_SEARCH_RESULT_LIMIT)
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Fixed number of search results returned to the agent. Defaults to 5 and is capped at 10."),
|
|
42
|
+
searchCandidateLimit: z
|
|
43
|
+
.number()
|
|
44
|
+
.int()
|
|
45
|
+
.positive()
|
|
46
|
+
.max(MAX_SEARCH_CANDIDATE_LIMIT)
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("Number of raw libzim results fetched before title-aware reranking. Defaults to 100 and is capped at 500."),
|
|
49
|
+
});
|
|
50
|
+
const kiwixReadPageContextSchema = kiwixArchiveContextSchema.extend({
|
|
51
|
+
readMaxBytes: z
|
|
52
|
+
.number()
|
|
53
|
+
.int()
|
|
54
|
+
.positive()
|
|
55
|
+
.max(HARD_READ_MAX_BYTES)
|
|
56
|
+
.optional()
|
|
57
|
+
.describe("Fixed maximum page bytes read before HTML-to-text conversion. Defaults to 81920."),
|
|
58
|
+
});
|
|
59
|
+
class KiwixArchive {
|
|
18
60
|
zimPath;
|
|
19
|
-
searchResultLimit;
|
|
20
|
-
readMaxBytes;
|
|
21
61
|
#archive;
|
|
22
62
|
#libzim;
|
|
63
|
+
#context;
|
|
64
|
+
constructor(context) {
|
|
65
|
+
this.zimPath = resolveHomePath(context.zimPath);
|
|
66
|
+
this.#context = context;
|
|
67
|
+
}
|
|
68
|
+
get() {
|
|
69
|
+
this.#archive ??= this.#openArchive();
|
|
70
|
+
return this.#archive;
|
|
71
|
+
}
|
|
72
|
+
loadLibzim() {
|
|
73
|
+
this.#libzim ??= import("@openzim/libzim");
|
|
74
|
+
return this.#libzim;
|
|
75
|
+
}
|
|
76
|
+
async #openArchive() {
|
|
77
|
+
const { Archive, OpenConfig } = await this.loadLibzim();
|
|
78
|
+
const config = new OpenConfig();
|
|
79
|
+
config.preloadXapianDb(this.#context.preloadXapianDb ?? true);
|
|
80
|
+
if (this.#context.preloadDirentRanges !== undefined) {
|
|
81
|
+
config.preloadDirentRanges(this.#context.preloadDirentRanges);
|
|
82
|
+
}
|
|
83
|
+
return new Archive(this.zimPath, config);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class KiwixSearchTool {
|
|
87
|
+
description = "Search the local Kiwix archive. Returns page paths, titles, and short snippets. Use the read tool with a returned path to read a page.";
|
|
88
|
+
inputSchema = kiwixSearchInputSchema;
|
|
89
|
+
contextSchema = kiwixSearchContextSchema;
|
|
23
90
|
#searcher;
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.#
|
|
30
|
-
}
|
|
31
|
-
async search(query) {
|
|
32
|
-
const { Searcher } = await this.#loadLibzim();
|
|
33
|
-
this.#searcher ??= new Searcher(await this.#getArchive());
|
|
91
|
+
#archive;
|
|
92
|
+
#archiveCacheKey;
|
|
93
|
+
execute = async ({ query }, { context }) => {
|
|
94
|
+
const archive = this.#getArchive(context);
|
|
95
|
+
const { Searcher } = await archive.loadLibzim();
|
|
96
|
+
this.#searcher ??= new Searcher(await archive.get());
|
|
34
97
|
const search = this.#searcher.search(query);
|
|
35
|
-
const
|
|
98
|
+
const searchResultLimit = clampSearchResultLimit(context.searchResultLimit ?? DEFAULT_SEARCH_RESULT_LIMIT);
|
|
99
|
+
const searchCandidateLimit = clampSearchCandidateLimit(Math.max(context.searchCandidateLimit ?? DEFAULT_SEARCH_CANDIDATE_LIMIT, searchResultLimit));
|
|
100
|
+
const results = Array.from(search.getResults(0, searchCandidateLimit))
|
|
101
|
+
.map((result, index) => ({
|
|
36
102
|
title: result.title,
|
|
37
103
|
path: result.path,
|
|
38
104
|
snippet: cleanSnippet(result.snippet),
|
|
105
|
+
score: scoreSearchResult(query, result.title, result.path),
|
|
106
|
+
index,
|
|
107
|
+
}))
|
|
108
|
+
.sort((a, b) => b.score - a.score || a.index - b.index)
|
|
109
|
+
.slice(0, searchResultLimit)
|
|
110
|
+
.map(({ title, path, snippet }) => ({
|
|
111
|
+
title,
|
|
112
|
+
path,
|
|
113
|
+
snippet,
|
|
39
114
|
}));
|
|
40
115
|
return { results };
|
|
116
|
+
};
|
|
117
|
+
#getArchive(context) {
|
|
118
|
+
const archiveCacheKey = getArchiveCacheKey(context);
|
|
119
|
+
if (archiveCacheKey !== this.#archiveCacheKey) {
|
|
120
|
+
this.#archive = new KiwixArchive(context);
|
|
121
|
+
this.#archiveCacheKey = archiveCacheKey;
|
|
122
|
+
this.#searcher = undefined;
|
|
123
|
+
}
|
|
124
|
+
if (!this.#archive) {
|
|
125
|
+
throw new Error("Kiwix archive was not initialized.");
|
|
126
|
+
}
|
|
127
|
+
return this.#archive;
|
|
41
128
|
}
|
|
42
|
-
|
|
43
|
-
|
|
129
|
+
}
|
|
130
|
+
class KiwixReadPageTool {
|
|
131
|
+
description = "Read one page from the local Kiwix archive by exact path from the search tool.";
|
|
132
|
+
inputSchema = kiwixReadInputSchema;
|
|
133
|
+
contextSchema = kiwixReadPageContextSchema;
|
|
134
|
+
#archive;
|
|
135
|
+
#archiveCacheKey;
|
|
136
|
+
execute = async ({ path }, { context }) => {
|
|
137
|
+
const entry = (await this.#getArchive(context).get()).getEntryByPath(path);
|
|
44
138
|
const item = entry.getItem(true);
|
|
45
139
|
const size = toSafeNumber(item.size);
|
|
46
|
-
const
|
|
140
|
+
const readMaxBytes = clampReadMaxBytes(context.readMaxBytes ?? DEFAULT_READ_MAX_BYTES);
|
|
141
|
+
const data = item.getData(0, Math.min(readMaxBytes, size)).data;
|
|
47
142
|
return {
|
|
48
143
|
title: entry.title,
|
|
49
144
|
path: entry.path,
|
|
50
145
|
content: formatPageContent(item, data),
|
|
51
146
|
truncated: data.byteLength < size,
|
|
52
147
|
};
|
|
53
|
-
}
|
|
54
|
-
#getArchive() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const { Archive, OpenConfig } = await this.#loadLibzim();
|
|
60
|
-
const config = new OpenConfig();
|
|
61
|
-
if (this.#options.preloadXapianDb !== undefined) {
|
|
62
|
-
config.preloadXapianDb(this.#options.preloadXapianDb);
|
|
148
|
+
};
|
|
149
|
+
#getArchive(context) {
|
|
150
|
+
const archiveCacheKey = getArchiveCacheKey(context);
|
|
151
|
+
if (archiveCacheKey !== this.#archiveCacheKey) {
|
|
152
|
+
this.#archive = new KiwixArchive(context);
|
|
153
|
+
this.#archiveCacheKey = archiveCacheKey;
|
|
63
154
|
}
|
|
64
|
-
if (this.#
|
|
65
|
-
|
|
155
|
+
if (!this.#archive) {
|
|
156
|
+
throw new Error("Kiwix archive was not initialized.");
|
|
66
157
|
}
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
#loadLibzim() {
|
|
70
|
-
this.#libzim ??= import("@openzim/libzim");
|
|
71
|
-
return this.#libzim;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export class KiwixTools {
|
|
75
|
-
reader;
|
|
76
|
-
#searchTool;
|
|
77
|
-
#readTool;
|
|
78
|
-
constructor(options) {
|
|
79
|
-
this.reader = new KiwixReader(options);
|
|
80
|
-
}
|
|
81
|
-
get searchTool() {
|
|
82
|
-
this.#searchTool ??= kiwixSearchTool(this.reader);
|
|
83
|
-
return this.#searchTool;
|
|
84
|
-
}
|
|
85
|
-
get readTool() {
|
|
86
|
-
this.#readTool ??= kiwixReadTool(this.reader);
|
|
87
|
-
return this.#readTool;
|
|
158
|
+
return this.#archive;
|
|
88
159
|
}
|
|
89
160
|
}
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
export function kiwixSearchTool(reader) {
|
|
99
|
-
return tool({
|
|
100
|
-
description: "Search the local Kiwix archive. Returns page paths, titles, and short snippets. Use the read tool with a returned path to read a page.",
|
|
101
|
-
inputSchema: kiwixSearchInputSchema,
|
|
102
|
-
execute: async ({ query }) => reader.search(query),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
export function kiwixReadTool(reader) {
|
|
106
|
-
return tool({
|
|
107
|
-
description: "Read one page from the local Kiwix archive by exact path from the search tool.",
|
|
108
|
-
inputSchema: kiwixReadInputSchema,
|
|
109
|
-
execute: async ({ path }) => reader.readPath(path),
|
|
161
|
+
export const kiwixSearch = new KiwixSearchTool();
|
|
162
|
+
export const kiwixReadPage = new KiwixReadPageTool();
|
|
163
|
+
function getArchiveCacheKey(context) {
|
|
164
|
+
return JSON.stringify({
|
|
165
|
+
zimPath: resolveHomePath(context.zimPath),
|
|
166
|
+
preloadXapianDb: context.preloadXapianDb,
|
|
167
|
+
preloadDirentRanges: context.preloadDirentRanges,
|
|
110
168
|
});
|
|
111
169
|
}
|
|
112
170
|
function formatPageContent(item, data) {
|
|
@@ -134,6 +192,62 @@ function cleanSnippet(snippet) {
|
|
|
134
192
|
}
|
|
135
193
|
return text.length > MAX_SNIPPET_LENGTH ? `${text.slice(0, MAX_SNIPPET_LENGTH).trim()}...` : text;
|
|
136
194
|
}
|
|
195
|
+
function scoreSearchResult(query, title, path) {
|
|
196
|
+
const normalizedQuery = normalizeSearchText(query);
|
|
197
|
+
if (!normalizedQuery) {
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
const normalizedTitle = normalizeSearchText(title);
|
|
201
|
+
const normalizedPathTitle = normalizePathTitle(path);
|
|
202
|
+
const queryTerms = normalizedQuery.split(" ");
|
|
203
|
+
let score = 0;
|
|
204
|
+
if (normalizedTitle === normalizedQuery) {
|
|
205
|
+
score += 1000;
|
|
206
|
+
}
|
|
207
|
+
if (normalizedPathTitle === normalizedQuery) {
|
|
208
|
+
score += 900;
|
|
209
|
+
}
|
|
210
|
+
if (normalizedTitle.startsWith(`${normalizedQuery} `)) {
|
|
211
|
+
score += 700;
|
|
212
|
+
}
|
|
213
|
+
if (normalizedPathTitle.startsWith(`${normalizedQuery} `)) {
|
|
214
|
+
score += 600;
|
|
215
|
+
}
|
|
216
|
+
if (normalizedTitle.includes(normalizedQuery)) {
|
|
217
|
+
score += 300;
|
|
218
|
+
}
|
|
219
|
+
if (normalizedPathTitle.includes(normalizedQuery)) {
|
|
220
|
+
score += 200;
|
|
221
|
+
}
|
|
222
|
+
for (const term of queryTerms) {
|
|
223
|
+
if (normalizedTitle.includes(term)) {
|
|
224
|
+
score += 20;
|
|
225
|
+
}
|
|
226
|
+
if (normalizedPathTitle.includes(term)) {
|
|
227
|
+
score += 10;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return score;
|
|
231
|
+
}
|
|
232
|
+
function normalizePathTitle(path) {
|
|
233
|
+
const pathTitle = path.split("/").pop() ?? path;
|
|
234
|
+
try {
|
|
235
|
+
return normalizeSearchText(decodeURIComponent(pathTitle.replace(/\.[^.]+$/, "")));
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return normalizeSearchText(pathTitle.replace(/\.[^.]+$/, ""));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function normalizeSearchText(text) {
|
|
242
|
+
return text
|
|
243
|
+
.normalize("NFKD")
|
|
244
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
245
|
+
.replace(/[_-]+/g, " ")
|
|
246
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
|
247
|
+
.toLowerCase()
|
|
248
|
+
.replace(/\s+/g, " ")
|
|
249
|
+
.trim();
|
|
250
|
+
}
|
|
137
251
|
function isTextMimeType(mimeType) {
|
|
138
252
|
return (mimeType.startsWith("text/") ||
|
|
139
253
|
isHtmlMimeType(mimeType) ||
|
|
@@ -158,6 +272,9 @@ function resolveHomePath(path) {
|
|
|
158
272
|
function clampSearchResultLimit(limit) {
|
|
159
273
|
return Math.min(Math.max(Math.trunc(limit), 1), MAX_SEARCH_RESULT_LIMIT);
|
|
160
274
|
}
|
|
275
|
+
function clampSearchCandidateLimit(limit) {
|
|
276
|
+
return Math.min(Math.max(Math.trunc(limit), 1), MAX_SEARCH_CANDIDATE_LIMIT);
|
|
277
|
+
}
|
|
161
278
|
function clampReadMaxBytes(maxBytes) {
|
|
162
279
|
return Math.min(Math.max(Math.trunc(maxBytes), 1), HARD_READ_MAX_BYTES);
|
|
163
280
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAC3C,MAAM,0BAA0B,GAAG,GAAG,CAAC;AACvC,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AACzC,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,CAAC;AACvC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAI/B,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,+CAA+C,CAAC;CACnF,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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AI,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAa;IAC3C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAa;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,0BAA0B,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAgB;IACzC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,YAAY,CAAC,KAAsB;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lgrammel/kiwix-tool",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "AI SDK 7 tool for reading Kiwix/ZIM archives with Node.js libzim bindings.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/html-to-text": "^9.0.4",
|
|
34
|
-
"ai": "7.0.0-canary.
|
|
34
|
+
"ai": "^7.0.0-canary.133"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"ai": "7.0.0-canary.
|
|
37
|
+
"ai": "^7.0.0-canary.133"
|
|
38
38
|
}
|
|
39
39
|
}
|