@operad-io/memory 0.0.0-stage → 0.2.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 +16 -2
- package/memory.schema.json +17 -0
- package/package.json +23 -4
- package/skills/memory/SKILL.md +84 -0
- package/src/commit.ts +279 -0
- package/src/index.ts +138 -0
- package/src/link-report.ts +224 -0
- package/src/links.ts +378 -0
- package/src/memory.ts +215 -0
- package/src/search/backend.ts +489 -0
- package/src/search/chunks.ts +86 -0
- package/src/search/command.ts +216 -0
- package/src/search/frontmatter.ts +114 -0
- package/src/search/service.ts +580 -0
- package/src/search/sources.ts +212 -0
- package/src/search/types.ts +245 -0
- package/src/tidy.ts +342 -0
- package/src/wiki.ts +619 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the index reads from: every bot's memory directory, the shared wiki,
|
|
3
|
+
* and a chat's messages as a document with numbered lines. A chat's fact types
|
|
4
|
+
* are written here rather than imported from the chat plugin, so the memory
|
|
5
|
+
* plugin does not depend on the plugin whose records it indexes.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
11
|
+
import { configPath, isRecord, type ObjectStore } from "@operad-io/engine";
|
|
12
|
+
|
|
13
|
+
/** The directory a bot's memory lives in, under its working directory. */
|
|
14
|
+
export function botMemoryDirectory(cwd: string): string {
|
|
15
|
+
return join(cwd, "memory");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The `bot` section of a home's `config.json`, with the default bot present. */
|
|
19
|
+
function botSettings(home: string): Readonly<Record<string, Record<string, unknown>>> {
|
|
20
|
+
const file = configPath(home);
|
|
21
|
+
if (!existsSync(file)) return { default: {} };
|
|
22
|
+
let parsed: unknown;
|
|
23
|
+
try {
|
|
24
|
+
parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
25
|
+
} catch {
|
|
26
|
+
return { default: {} };
|
|
27
|
+
}
|
|
28
|
+
const plugins = isRecord(parsed) ? parsed.plugins : undefined;
|
|
29
|
+
const entry = isRecord(plugins) ? plugins["bot"] : undefined;
|
|
30
|
+
const settings = isRecord(entry) && isRecord(entry.settings) ? entry.settings : {};
|
|
31
|
+
const bots = isRecord(settings["bots"]) ? settings["bots"] : {};
|
|
32
|
+
const found: Record<string, Record<string, unknown>> = {};
|
|
33
|
+
for (const [name, value] of Object.entries(bots)) {
|
|
34
|
+
if (isRecord(value)) found[name] = value;
|
|
35
|
+
}
|
|
36
|
+
if (found["default"] === undefined) found["default"] = {};
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function expandUnder(path: string, base: string): string {
|
|
41
|
+
if (path === "~") return homedir();
|
|
42
|
+
if (path.startsWith("~/")) return join(homedir(), path.slice(2));
|
|
43
|
+
return isAbsolute(path) ? resolve(path) : resolve(base, path);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function directoryExists(path: string): boolean {
|
|
47
|
+
try {
|
|
48
|
+
return statSync(path).isDirectory();
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Every existing bot memory directory. The bot plugin's default layout is
|
|
56
|
+
* `~/.operad/bot/<name>/memory`; a bot whose settings name another working
|
|
57
|
+
* directory is read from that directory's `memory/`. A directory that is not
|
|
58
|
+
* there is not indexed, and a bot is never given another bot's path.
|
|
59
|
+
*/
|
|
60
|
+
export function botMemoryDirectories(home: string): readonly string[] {
|
|
61
|
+
const found = new Set<string>();
|
|
62
|
+
const root = join(home, "bot");
|
|
63
|
+
if (directoryExists(root)) {
|
|
64
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
65
|
+
if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
|
|
66
|
+
const memory = join(root, entry.name, "memory");
|
|
67
|
+
if (directoryExists(memory)) found.add(resolve(memory));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// An older default bot kept its memory directly under the bot home.
|
|
71
|
+
const oldDefault = join(root, "memory");
|
|
72
|
+
if (directoryExists(oldDefault)) found.add(resolve(oldDefault));
|
|
73
|
+
for (const settings of Object.values(botSettings(home))) {
|
|
74
|
+
const written = settings["cwd"];
|
|
75
|
+
if (typeof written !== "string" || written.length === 0) continue;
|
|
76
|
+
let cwd: string;
|
|
77
|
+
try {
|
|
78
|
+
cwd = expandUnder(written, root);
|
|
79
|
+
} catch {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const memory = botMemoryDirectory(cwd);
|
|
83
|
+
if (directoryExists(memory)) found.add(resolve(memory));
|
|
84
|
+
}
|
|
85
|
+
return [...found].sort();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Every Markdown file under a directory, hidden directories left out. */
|
|
89
|
+
export function markdownFiles(directory: string): readonly string[] {
|
|
90
|
+
if (!directoryExists(directory)) return [];
|
|
91
|
+
const found: string[] = [];
|
|
92
|
+
const visit = (current: string): void => {
|
|
93
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
94
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
95
|
+
const path = join(current, entry.name);
|
|
96
|
+
if (entry.isDirectory()) {
|
|
97
|
+
visit(path);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (entry.isFile() && /\.(?:md|markdown)$/iu.test(entry.name)) found.push(path);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
visit(directory);
|
|
104
|
+
return found.sort();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A chat message as the index reads it. */
|
|
108
|
+
export interface IndexedChatMessage {
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly role: "user" | "assistant";
|
|
111
|
+
readonly text: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const MESSAGE_FACT = "chat.message";
|
|
115
|
+
const MESSAGE_CHANGE_FACT = "chat.message_change";
|
|
116
|
+
|
|
117
|
+
function messageOfFact(fact: { readonly data: Record<string, unknown> }): IndexedChatMessage | undefined {
|
|
118
|
+
const data = fact.data;
|
|
119
|
+
if (typeof data["id"] !== "string" || typeof data["text"] !== "string") return undefined;
|
|
120
|
+
if (data["role"] !== "user" && data["role"] !== "assistant") return undefined;
|
|
121
|
+
return { id: data["id"], role: data["role"], text: data["text"] };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A chat's messages with the latest text and the withdrawn ones left out. The
|
|
126
|
+
* fact types are the chat plugin's record (ADR 0027); only the two fields the
|
|
127
|
+
* index needs are read.
|
|
128
|
+
*/
|
|
129
|
+
export function chatMessages(store: ObjectStore, chat: string): readonly IndexedChatMessage[] {
|
|
130
|
+
const order: string[] = [];
|
|
131
|
+
const messages = new Map<string, IndexedChatMessage>();
|
|
132
|
+
const changes = new Map<string, { readonly text?: string; readonly withdrawn?: true }>();
|
|
133
|
+
let cursor: string | undefined;
|
|
134
|
+
do {
|
|
135
|
+
const page = store.facts(
|
|
136
|
+
{ type: "chat", id: chat },
|
|
137
|
+
{ ...(cursor === undefined ? {} : { cursor }), limit: 500 },
|
|
138
|
+
);
|
|
139
|
+
for (const fact of page.facts) {
|
|
140
|
+
if (fact.type === MESSAGE_FACT) {
|
|
141
|
+
const message = messageOfFact(fact);
|
|
142
|
+
if (message === undefined) continue;
|
|
143
|
+
if (!messages.has(message.id)) order.push(message.id);
|
|
144
|
+
messages.set(message.id, message);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (fact.type !== MESSAGE_CHANGE_FACT) continue;
|
|
148
|
+
const data = fact.data;
|
|
149
|
+
if (typeof data["id"] !== "string") continue;
|
|
150
|
+
const before = changes.get(data["id"]) ?? {};
|
|
151
|
+
if (data["kind"] === "withdraw") changes.set(data["id"], { ...before, withdrawn: true });
|
|
152
|
+
else if (data["kind"] === "text" && typeof data["text"] === "string") {
|
|
153
|
+
changes.set(data["id"], { ...before, text: data["text"] });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
cursor = page.next;
|
|
157
|
+
} while (cursor !== undefined);
|
|
158
|
+
|
|
159
|
+
const found: IndexedChatMessage[] = [];
|
|
160
|
+
for (const id of order) {
|
|
161
|
+
const message = messages.get(id);
|
|
162
|
+
if (message === undefined) continue;
|
|
163
|
+
const change = changes.get(id);
|
|
164
|
+
if (change?.withdrawn === true) continue;
|
|
165
|
+
found.push(change?.text === undefined ? message : { ...message, text: change.text });
|
|
166
|
+
}
|
|
167
|
+
return found;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A chat as lines a reader can cite: one heading, then one block per message.
|
|
172
|
+
* The line numbers stay stable as messages are appended, so a hit's range keeps
|
|
173
|
+
* meaning the same message.
|
|
174
|
+
*/
|
|
175
|
+
export function chatDocument(chat: string, title: string, messages: readonly IndexedChatMessage[]): string {
|
|
176
|
+
const lines = [`# ${title.length > 0 ? title : chat}`, `chat ${chat}`, ""];
|
|
177
|
+
for (const message of messages) {
|
|
178
|
+
lines.push(`${message.role === "user" ? "person" : "assistant"}:`);
|
|
179
|
+
for (const line of message.text.split(/\r?\n/u)) lines.push(line);
|
|
180
|
+
lines.push("");
|
|
181
|
+
}
|
|
182
|
+
return lines.join("\n");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** A chat's title, as its stored object states it. */
|
|
186
|
+
export function chatTitle(id: string, data: Readonly<Record<string, unknown>>): string {
|
|
187
|
+
const title = data["title"];
|
|
188
|
+
return typeof title === "string" && title.length > 0 ? title : id;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A chat's working directory, path-resolved to the owner a bot search compares. */
|
|
192
|
+
export function chatOwner(data: Readonly<Record<string, unknown>>): string | undefined {
|
|
193
|
+
const cwd = data["cwd"];
|
|
194
|
+
return typeof cwd === "string" && cwd.length > 0 ? resolve(cwd) : undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The path a file document is shown under: relative to its root. */
|
|
198
|
+
export function documentPath(file: string, root: string): string {
|
|
199
|
+
return relative(root, file).split("\\").join("/");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** A file's directory inside its root, empty at the root. */
|
|
203
|
+
export function documentDirectory(file: string, root: string): string {
|
|
204
|
+
const rel = documentPath(file, root);
|
|
205
|
+
const directory = dirname(rel);
|
|
206
|
+
return directory === "." ? "" : directory.split("\\").join("/");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** A file's name, as an about lookup and a title use it. */
|
|
210
|
+
export function fileName(file: string): string {
|
|
211
|
+
return basename(file);
|
|
212
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/** The shapes the full-text index and the search tool share. */
|
|
2
|
+
|
|
3
|
+
/** What a search may cover. */
|
|
4
|
+
export const SEARCH_SCOPES = ["wiki", "memory", "chats"] as const;
|
|
5
|
+
|
|
6
|
+
/** One place a search reaches. */
|
|
7
|
+
export type SearchScope = (typeof SEARCH_SCOPES)[number];
|
|
8
|
+
|
|
9
|
+
/** The FTS5 tokenizer the index is built with. */
|
|
10
|
+
export type TokenizerName = "trigram" | "unicode61";
|
|
11
|
+
|
|
12
|
+
/** Frontmatter values, as text: a filter compares text to text. */
|
|
13
|
+
export type FrontmatterValue = string;
|
|
14
|
+
|
|
15
|
+
/** One document's frontmatter, each key with all of its values. */
|
|
16
|
+
export type DocumentFields = Readonly<Record<string, readonly FrontmatterValue[]>>;
|
|
17
|
+
|
|
18
|
+
/** How a note writes a link: `[[target]]` or `[text](target)`. */
|
|
19
|
+
export type NoteLinkKind = "wikilink" | "markdown";
|
|
20
|
+
|
|
21
|
+
/** One link a note writes, before it is resolved to a file. */
|
|
22
|
+
export interface NoteLink {
|
|
23
|
+
/** The target as written and percent-decoded, without its `#heading`. */
|
|
24
|
+
readonly target: string;
|
|
25
|
+
/** The `#heading` the link points into, without the `#`. */
|
|
26
|
+
readonly heading?: string | undefined;
|
|
27
|
+
readonly kind: NoteLinkKind;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One link a note writes, with the line and excerpt a backlink shows. */
|
|
31
|
+
export interface IndexedNoteLink extends NoteLink {
|
|
32
|
+
/** The 1-based line of the link in the source note. */
|
|
33
|
+
readonly line?: number | undefined;
|
|
34
|
+
/** The line around the link, shortened for reading. */
|
|
35
|
+
readonly excerpt?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One stored link, with the document it points at when the index resolved it. */
|
|
39
|
+
export interface StoredNoteLink extends IndexedNoteLink {
|
|
40
|
+
/** The note that writes the link. */
|
|
41
|
+
readonly docId: string;
|
|
42
|
+
/** The link's place in the source note, counting from zero. */
|
|
43
|
+
readonly ordinal: number;
|
|
44
|
+
/** The document the link resolves to; absent while nothing matches it. */
|
|
45
|
+
readonly targetId?: string | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The new resolved target of one stored link. */
|
|
49
|
+
export interface NoteLinkTarget {
|
|
50
|
+
readonly docId: string;
|
|
51
|
+
readonly ordinal: number;
|
|
52
|
+
readonly targetId?: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One note that links to the note being read, with the place the link is written. */
|
|
56
|
+
export interface Backlink {
|
|
57
|
+
/** The id of the note that writes the link. */
|
|
58
|
+
readonly id: string;
|
|
59
|
+
/** The path of the note that writes the link, inside its scope. */
|
|
60
|
+
readonly path: string;
|
|
61
|
+
readonly title: string;
|
|
62
|
+
readonly target: string;
|
|
63
|
+
readonly heading?: string | undefined;
|
|
64
|
+
readonly kind: NoteLinkKind;
|
|
65
|
+
/** The 1-based line of the link in the source note. */
|
|
66
|
+
readonly line: number;
|
|
67
|
+
/** The line around the link, shortened for reading. */
|
|
68
|
+
readonly excerpt: string;
|
|
69
|
+
/** Whether the linking note's frontmatter says `untrusted: true`. */
|
|
70
|
+
readonly untrusted: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One link as a query returns it, with both ends when the link resolved. */
|
|
74
|
+
export interface NoteLinkInfo {
|
|
75
|
+
/** The id of the note that writes the link. */
|
|
76
|
+
readonly from: string;
|
|
77
|
+
readonly fromPath?: string | undefined;
|
|
78
|
+
/** The id of the note the link points at, when it resolved. */
|
|
79
|
+
readonly to?: string | undefined;
|
|
80
|
+
readonly toPath?: string | undefined;
|
|
81
|
+
readonly target: string;
|
|
82
|
+
readonly heading?: string | undefined;
|
|
83
|
+
readonly kind: NoteLinkKind;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A target no note resolves to, with how many links name it. */
|
|
87
|
+
export interface UnresolvedTarget {
|
|
88
|
+
readonly target: string;
|
|
89
|
+
readonly count: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The part of the index a link query covers; absent fields mean all of it. */
|
|
93
|
+
export interface LinkQuery {
|
|
94
|
+
readonly scope?: SearchScope | undefined;
|
|
95
|
+
readonly owner?: string | undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** One document as the backend stores it. */
|
|
99
|
+
export interface IndexedDocument {
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly scope: SearchScope;
|
|
102
|
+
/** The bot whose memory or chat this is; empty for the wiki. */
|
|
103
|
+
readonly owner: string;
|
|
104
|
+
/** The file the document was read from, for a file document. */
|
|
105
|
+
readonly file?: string | undefined;
|
|
106
|
+
/** The path shown to a reader: relative to the wiki or the bot's memory. */
|
|
107
|
+
readonly path?: string | undefined;
|
|
108
|
+
/** The document's directory inside its root, empty at the root. */
|
|
109
|
+
readonly directory: string;
|
|
110
|
+
/** The file name inside its directory, empty for a chat. */
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly title: string;
|
|
113
|
+
/** The searchable text without its frontmatter. */
|
|
114
|
+
readonly text: string;
|
|
115
|
+
readonly fields: DocumentFields;
|
|
116
|
+
readonly lineCount: number;
|
|
117
|
+
readonly digest: string;
|
|
118
|
+
readonly mtimeMs?: number | undefined;
|
|
119
|
+
/** The modification time with nanosecond precision, as text. */
|
|
120
|
+
readonly mtimeNs?: string | undefined;
|
|
121
|
+
readonly size?: number | undefined;
|
|
122
|
+
/** The links its text writes, parsed but not yet resolved. */
|
|
123
|
+
readonly links?: readonly IndexedNoteLink[] | undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** What a backend needs to know about a document without reading it. */
|
|
127
|
+
export interface DocumentKey {
|
|
128
|
+
readonly id: string;
|
|
129
|
+
readonly scope: SearchScope;
|
|
130
|
+
readonly owner: string;
|
|
131
|
+
readonly file?: string | undefined;
|
|
132
|
+
readonly path?: string | undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** One chunk a backend matched, before the service adds the document around it. */
|
|
136
|
+
export interface BackendHit {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly lineStart: number;
|
|
139
|
+
readonly lineEnd: number;
|
|
140
|
+
readonly text: string;
|
|
141
|
+
readonly score: number;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** What one backend query holds. The caller has already restricted the scopes. */
|
|
145
|
+
export interface BackendQuery {
|
|
146
|
+
readonly text: string;
|
|
147
|
+
readonly scopes: readonly SearchScope[];
|
|
148
|
+
/** The bot asking: only its memory and its chats are reachable. */
|
|
149
|
+
readonly owner: string;
|
|
150
|
+
readonly fields?: Readonly<Record<string, string | readonly string[]>> | undefined;
|
|
151
|
+
readonly limit: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The small interface another engine implements to replace SQLite FTS5. The
|
|
156
|
+
* service owns indexing, scopes and the shape of a result; a backend owns
|
|
157
|
+
* storage and matching.
|
|
158
|
+
*/
|
|
159
|
+
export interface SearchBackend {
|
|
160
|
+
readonly tokenizer: TokenizerName;
|
|
161
|
+
/** Writes one document whole, replacing an older version with the same id. */
|
|
162
|
+
put(document: IndexedDocument): void;
|
|
163
|
+
remove(id: string): void;
|
|
164
|
+
get(id: string): IndexedDocument | undefined;
|
|
165
|
+
/** Every document's key, so the indexer can remove what is gone. */
|
|
166
|
+
keys(): readonly DocumentKey[];
|
|
167
|
+
search(query: BackendQuery): readonly BackendHit[];
|
|
168
|
+
/** The `_about.md` of one directory inside one scope, when there is one. */
|
|
169
|
+
about(scope: SearchScope, owner: string, directory: string): IndexedDocument | undefined;
|
|
170
|
+
/** Every link the index holds, resolved or not, in document and ordinal order. */
|
|
171
|
+
allLinks(): readonly StoredNoteLink[];
|
|
172
|
+
/** The links that point at one document, in document and ordinal order. */
|
|
173
|
+
linksTo(targetId: string): readonly StoredNoteLink[];
|
|
174
|
+
/** Sets the resolved target of the links named; no target leaves a link unresolved. */
|
|
175
|
+
setLinkTargets(updates: readonly NoteLinkTarget[]): void;
|
|
176
|
+
close(): void;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** What a person or a bot asks the service. */
|
|
180
|
+
export interface SearchRequest {
|
|
181
|
+
readonly text: string;
|
|
182
|
+
/** The working directory of the bot asking; its memory and chats are its own. */
|
|
183
|
+
readonly cwd: string;
|
|
184
|
+
readonly scopes?: readonly SearchScope[] | undefined;
|
|
185
|
+
readonly fields?: Readonly<Record<string, string | readonly string[]>> | undefined;
|
|
186
|
+
readonly limit?: number | undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** One search result. */
|
|
190
|
+
export interface SearchHit {
|
|
191
|
+
readonly id: string;
|
|
192
|
+
readonly scope: SearchScope;
|
|
193
|
+
readonly title: string;
|
|
194
|
+
readonly path?: string | undefined;
|
|
195
|
+
readonly lineStart: number;
|
|
196
|
+
readonly lineEnd: number;
|
|
197
|
+
readonly snippet: string;
|
|
198
|
+
readonly score: number;
|
|
199
|
+
readonly fields: DocumentFields;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** A directory's description, returned next to the hits found inside it. */
|
|
203
|
+
export interface AboutDocument {
|
|
204
|
+
readonly id: string;
|
|
205
|
+
readonly title: string;
|
|
206
|
+
readonly text: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The answer to one search. */
|
|
210
|
+
export interface SearchResult {
|
|
211
|
+
readonly query: string;
|
|
212
|
+
readonly scopes: readonly SearchScope[];
|
|
213
|
+
readonly hits: readonly SearchHit[];
|
|
214
|
+
readonly about: readonly AboutDocument[];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** What `read` asks for. Line numbers start at 1. */
|
|
218
|
+
export interface ReadRequest {
|
|
219
|
+
readonly id: string;
|
|
220
|
+
readonly from?: number | undefined;
|
|
221
|
+
readonly to?: number | undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** One document, or the requested part of it. */
|
|
225
|
+
export interface ReadResult {
|
|
226
|
+
readonly id: string;
|
|
227
|
+
readonly scope: SearchScope;
|
|
228
|
+
readonly title: string;
|
|
229
|
+
readonly path?: string | undefined;
|
|
230
|
+
readonly lineStart: number;
|
|
231
|
+
readonly lineEnd: number;
|
|
232
|
+
readonly totalLines: number;
|
|
233
|
+
readonly text: string;
|
|
234
|
+
readonly fields: DocumentFields;
|
|
235
|
+
/** The notes that link to this one; empty when nothing does. */
|
|
236
|
+
readonly backlinks: readonly Backlink[];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** A search or read that cannot be answered. */
|
|
240
|
+
export class SearchError extends Error {
|
|
241
|
+
constructor(message: string) {
|
|
242
|
+
super(message);
|
|
243
|
+
this.name = "SearchError";
|
|
244
|
+
}
|
|
245
|
+
}
|