@cerebriline/core 4.100.240 → 4.100.241
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/assets/skills/README.md +14 -0
- package/assets/skills/build-project/SKILL.md +103 -0
- package/assets/skills/docker-compose-deploy/SKILL.md +239 -0
- package/assets/skills/librarian/SKILL.md +177 -0
- package/assets/skills/mandatory-qa-prompt-and-issue-resolution/SKILL.md +58 -0
- package/assets/skills/run-project/SKILL.md +103 -0
- package/assets/skills/sdd-discuss/SKILL.md +129 -0
- package/assets/skills/sdd-execute/SKILL.md +146 -0
- package/assets/skills/sdd-plan/SKILL.md +140 -0
- package/assets/skills/sdd-quick/SKILL.md +40 -0
- package/assets/skills/sdd-status/SKILL.md +75 -0
- package/assets/skills/sdd-verify/SKILL.md +122 -0
- package/assets/skills/sdd-wizard/SKILL.md +105 -0
- package/assets/skills/tdd-coverage/SKILL.md +88 -0
- package/assets/skills/tdd-gen/SKILL.md +82 -0
- package/assets/skills/tdd-test/SKILL.md +61 -0
- package/assets/skills/tdd-wizard/SKILL.md +162 -0
- package/dist/extensions/config/bundled-skills.d.ts +24 -0
- package/dist/extensions/config/index.d.ts +2 -1
- package/dist/extensions/config/unified-config-file-watcher.d.ts +15 -0
- package/dist/extensions/config/user-instruction-config-loader.d.ts +15 -0
- package/dist/extensions/tools/executors/document/ebook.d.ts +10 -0
- package/dist/extensions/tools/executors/document/formats.d.ts +25 -0
- package/dist/extensions/tools/executors/document/ocr.d.ts +3 -0
- package/dist/extensions/tools/executors/document/recognition.d.ts +16 -0
- package/dist/extensions/tools/executors/document-extract.d.ts +91 -0
- package/dist/extensions/tools/librarian-tools.d.ts +35 -0
- package/dist/extensions/tools/library-import-run.d.ts +79 -0
- package/dist/extensions/tools/library-tools.d.ts +88 -0
- package/dist/extensions/tools/memory-tools.d.ts +41 -0
- package/dist/extensions/tools/sdd-tool.d.ts +215 -0
- package/dist/extensions/tools/team/create-agent-tool.d.ts +5 -4
- package/dist/hub/daemon/entry.js +547 -545
- package/dist/hub/index.js +531 -529
- package/dist/index.d.ts +17 -1
- package/dist/index.js +1070 -689
- package/dist/services/global-settings.d.ts +9 -0
- package/dist/services/llms/provider-settings.d.ts +15 -15
- package/dist/services/retrieval/catalogue.d.ts +370 -0
- package/dist/services/retrieval/chunker.d.ts +44 -0
- package/dist/services/retrieval/embedding-client.d.ts +78 -0
- package/dist/services/retrieval/fingerprint.d.ts +21 -0
- package/dist/services/retrieval/firecrawl.d.ts +77 -0
- package/dist/services/retrieval/lancedb-runtime.d.ts +84 -0
- package/dist/services/retrieval/lancedb-runtime.manifest.d.ts +17 -0
- package/dist/services/retrieval/library-store.d.ts +148 -0
- package/dist/services/retrieval/library.d.ts +139 -0
- package/dist/services/retrieval/memory-recall.d.ts +97 -0
- package/dist/services/retrieval/memory.d.ts +184 -0
- package/dist/services/retrieval/retrieve.d.ts +85 -0
- package/dist/services/retrieval/tar-extract.d.ts +14 -0
- package/dist/services/retrieval/tar-write.d.ts +20 -0
- package/dist/services/retrieval/vector-index.d.ts +82 -0
- package/dist/services/sdd/sdd-engine.d.ts +248 -0
- package/dist/services/telemetry/index.js +1 -1
- package/dist/types/config.d.ts +7 -0
- package/dist/types/session.d.ts +2 -0
- package/package.json +4 -4
- package/dist/extensions/tools/code-intel.d.ts +0 -131
|
@@ -34,6 +34,9 @@ export declare const GlobalSettingsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
34
34
|
}, z.core.$strip>>>;
|
|
35
35
|
disabledPlugins: z.ZodOptional<z.ZodPipe<z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodString>>>, z.ZodTransform<string[] | undefined, string[] | undefined>>>;
|
|
36
36
|
disabledAgentPlugins: z.ZodOptional<z.ZodPipe<z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodString>>>, z.ZodTransform<string[] | undefined, string[] | undefined>>>;
|
|
37
|
+
bundledSkills: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
38
|
+
enabled: z.ZodBoolean;
|
|
39
|
+
}, z.core.$strip>>>>;
|
|
37
40
|
}, z.core.$strip>, z.ZodTransform<{
|
|
38
41
|
telemetryOptOut: boolean;
|
|
39
42
|
autoUpdateEnabled: boolean;
|
|
@@ -46,6 +49,9 @@ export declare const GlobalSettingsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
46
49
|
tools?: ModelToolSettings;
|
|
47
50
|
disabledPlugins?: string[];
|
|
48
51
|
disabledAgentPlugins?: string[];
|
|
52
|
+
bundledSkills?: Record<string, {
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
}>;
|
|
49
55
|
}, {
|
|
50
56
|
telemetryOptOut: boolean;
|
|
51
57
|
autoUpdateEnabled: boolean;
|
|
@@ -60,6 +66,9 @@ export declare const GlobalSettingsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
60
66
|
}>> | undefined;
|
|
61
67
|
disabledPlugins?: string[] | undefined;
|
|
62
68
|
disabledAgentPlugins?: string[] | undefined;
|
|
69
|
+
bundledSkills?: Record<string, {
|
|
70
|
+
enabled: boolean;
|
|
71
|
+
}> | undefined;
|
|
63
72
|
}>>;
|
|
64
73
|
export type GlobalSettings = z.infer<typeof GlobalSettingsSchema>;
|
|
65
74
|
export interface WriteGlobalSettingsOptions {
|
|
@@ -15,25 +15,25 @@ export declare const normalizeProviderId: typeof Llms.normalizeProviderId;
|
|
|
15
15
|
export type ProviderDefaultsConfig = ProviderDefaults;
|
|
16
16
|
export declare const ProviderIdSchema: z.ZodString;
|
|
17
17
|
export declare const ProviderProtocolSchema: z.ZodEnum<{
|
|
18
|
-
"openai-responses": "openai-responses";
|
|
19
18
|
anthropic: "anthropic";
|
|
20
19
|
gemini: "gemini";
|
|
20
|
+
"openai-chat": "openai-chat";
|
|
21
|
+
"openai-responses": "openai-responses";
|
|
21
22
|
"openai-r1": "openai-r1";
|
|
22
23
|
"ai-sdk": "ai-sdk";
|
|
23
|
-
"openai-chat": "openai-chat";
|
|
24
24
|
}>;
|
|
25
25
|
export declare const ProviderClientSchema: z.ZodEnum<{
|
|
26
26
|
custom: "custom";
|
|
27
27
|
fetch: "fetch";
|
|
28
28
|
anthropic: "anthropic";
|
|
29
|
-
"openai-compatible": "openai-compatible";
|
|
30
29
|
gemini: "gemini";
|
|
31
|
-
vertex: "vertex";
|
|
32
|
-
bedrock: "bedrock";
|
|
33
|
-
openai: "openai";
|
|
34
30
|
"openai-r1": "openai-r1";
|
|
35
31
|
"ai-sdk": "ai-sdk";
|
|
36
32
|
"ai-sdk-community": "ai-sdk-community";
|
|
33
|
+
openai: "openai";
|
|
34
|
+
"openai-compatible": "openai-compatible";
|
|
35
|
+
bedrock: "bedrock";
|
|
36
|
+
vertex: "vertex";
|
|
37
37
|
}>;
|
|
38
38
|
export declare const AuthSettingsSchema: z.ZodObject<{
|
|
39
39
|
apiKey: z.ZodOptional<z.ZodString>;
|
|
@@ -162,9 +162,9 @@ export declare const AwsSettingsSchema: z.ZodObject<{
|
|
|
162
162
|
region: z.ZodOptional<z.ZodString>;
|
|
163
163
|
profile: z.ZodOptional<z.ZodString>;
|
|
164
164
|
authentication: z.ZodOptional<z.ZodEnum<{
|
|
165
|
-
"api-key": "api-key";
|
|
166
165
|
profile: "profile";
|
|
167
166
|
iam: "iam";
|
|
167
|
+
"api-key": "api-key";
|
|
168
168
|
apikey: "apikey";
|
|
169
169
|
}>>;
|
|
170
170
|
usePromptCache: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -231,25 +231,25 @@ export declare const ProviderSettingsSchema: z.ZodObject<{
|
|
|
231
231
|
}, z.core.$strip>>;
|
|
232
232
|
model: z.ZodOptional<z.ZodString>;
|
|
233
233
|
protocol: z.ZodOptional<z.ZodEnum<{
|
|
234
|
-
"openai-responses": "openai-responses";
|
|
235
234
|
anthropic: "anthropic";
|
|
236
235
|
gemini: "gemini";
|
|
236
|
+
"openai-chat": "openai-chat";
|
|
237
|
+
"openai-responses": "openai-responses";
|
|
237
238
|
"openai-r1": "openai-r1";
|
|
238
239
|
"ai-sdk": "ai-sdk";
|
|
239
|
-
"openai-chat": "openai-chat";
|
|
240
240
|
}>>;
|
|
241
241
|
client: z.ZodOptional<z.ZodEnum<{
|
|
242
242
|
custom: "custom";
|
|
243
243
|
fetch: "fetch";
|
|
244
244
|
anthropic: "anthropic";
|
|
245
|
-
"openai-compatible": "openai-compatible";
|
|
246
245
|
gemini: "gemini";
|
|
247
|
-
vertex: "vertex";
|
|
248
|
-
bedrock: "bedrock";
|
|
249
|
-
openai: "openai";
|
|
250
246
|
"openai-r1": "openai-r1";
|
|
251
247
|
"ai-sdk": "ai-sdk";
|
|
252
248
|
"ai-sdk-community": "ai-sdk-community";
|
|
249
|
+
openai: "openai";
|
|
250
|
+
"openai-compatible": "openai-compatible";
|
|
251
|
+
bedrock: "bedrock";
|
|
252
|
+
vertex: "vertex";
|
|
253
253
|
}>>;
|
|
254
254
|
routingProviderId: z.ZodOptional<z.ZodString>;
|
|
255
255
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -341,9 +341,9 @@ export declare const ProviderSettingsSchema: z.ZodObject<{
|
|
|
341
341
|
region: z.ZodOptional<z.ZodString>;
|
|
342
342
|
profile: z.ZodOptional<z.ZodString>;
|
|
343
343
|
authentication: z.ZodOptional<z.ZodEnum<{
|
|
344
|
-
"api-key": "api-key";
|
|
345
344
|
profile: "profile";
|
|
346
345
|
iam: "iam";
|
|
346
|
+
"api-key": "api-key";
|
|
347
347
|
apikey: "apikey";
|
|
348
348
|
}>>;
|
|
349
349
|
usePromptCache: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -389,8 +389,8 @@ export declare const ProviderSettingsSchema: z.ZodObject<{
|
|
|
389
389
|
vision: "vision";
|
|
390
390
|
reasoning: "reasoning";
|
|
391
391
|
tools: "tools";
|
|
392
|
-
streaming: "streaming";
|
|
393
392
|
"prompt-cache": "prompt-cache";
|
|
393
|
+
streaming: "streaming";
|
|
394
394
|
"computer-use": "computer-use";
|
|
395
395
|
oauth: "oauth";
|
|
396
396
|
popular: "popular";
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Library's catalogue: sections, the shelves in them, and the books on
|
|
3
|
+
* the shelves.
|
|
4
|
+
*
|
|
5
|
+
* A book is a folder (`books/<uid>/`) and a collection in the text store. The
|
|
6
|
+
* folder is the book itself: the files it was made from, named by their
|
|
7
|
+
* sha256, the text read out of each, its pictures, and `book.json` saying
|
|
8
|
+
* what all of it is. The database is the index of those folders, so a folder
|
|
9
|
+
* can be carried to another Library and read back in, which is what export
|
|
10
|
+
* and import do.
|
|
11
|
+
*
|
|
12
|
+
* Nothing the model does here is final. A deleted book, or a source taken
|
|
13
|
+
* out of one, goes to the trash and stays there for thirty days.
|
|
14
|
+
*/
|
|
15
|
+
import { type LibrarySettings } from "@cerebriline/shared";
|
|
16
|
+
import type { Library } from "./library";
|
|
17
|
+
export declare const BOOK_FORMAT = "cerebriline-book";
|
|
18
|
+
export declare const LIBRARY_EXPORT_FORMAT = "cerebriline-library";
|
|
19
|
+
/** How long the trash keeps what was deleted. */
|
|
20
|
+
export declare const TRASH_DAYS = 30;
|
|
21
|
+
/** Where the collections of a Library from before it had shelves are put. */
|
|
22
|
+
export declare const LEGACY_SECTION = "General";
|
|
23
|
+
export interface LibraryShelf {
|
|
24
|
+
id: number;
|
|
25
|
+
sectionId: number;
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
books: number;
|
|
29
|
+
passages: number;
|
|
30
|
+
}
|
|
31
|
+
export interface LibrarySection {
|
|
32
|
+
id: number;
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
shelves: LibraryShelf[];
|
|
36
|
+
}
|
|
37
|
+
/** Where a scraped book came from, kept so it can be brought up to date. */
|
|
38
|
+
export interface BookWebOrigin {
|
|
39
|
+
/** What was asked for, when the links were found by searching. */
|
|
40
|
+
query?: string;
|
|
41
|
+
/** The links given or found: where a later check starts again. */
|
|
42
|
+
links: string[];
|
|
43
|
+
crawl?: {
|
|
44
|
+
limit?: number;
|
|
45
|
+
depth?: number;
|
|
46
|
+
};
|
|
47
|
+
checkedAt?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface BookMetadata {
|
|
50
|
+
authors?: string[];
|
|
51
|
+
edition?: string;
|
|
52
|
+
year?: number;
|
|
53
|
+
language?: string;
|
|
54
|
+
isbn?: string;
|
|
55
|
+
publisher?: string;
|
|
56
|
+
tags?: string[];
|
|
57
|
+
web?: BookWebOrigin;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
export interface LibraryBook {
|
|
61
|
+
id: number;
|
|
62
|
+
uid: string;
|
|
63
|
+
/** Undefined for a book in the trash. */
|
|
64
|
+
shelfId?: number;
|
|
65
|
+
collectionId: number;
|
|
66
|
+
title: string;
|
|
67
|
+
description: string;
|
|
68
|
+
metadata: BookMetadata;
|
|
69
|
+
createdAt: string;
|
|
70
|
+
updatedAt: string;
|
|
71
|
+
trashedAt?: string;
|
|
72
|
+
/** Where a trashed book stood. */
|
|
73
|
+
trashedFrom?: {
|
|
74
|
+
section: string;
|
|
75
|
+
shelf: string;
|
|
76
|
+
};
|
|
77
|
+
sources: number;
|
|
78
|
+
passages: number;
|
|
79
|
+
}
|
|
80
|
+
export type BookSourceKind = "file" | "web" | "text";
|
|
81
|
+
export interface BookSource {
|
|
82
|
+
id: number;
|
|
83
|
+
bookId: number;
|
|
84
|
+
kind: BookSourceKind;
|
|
85
|
+
sha256: string;
|
|
86
|
+
name: string;
|
|
87
|
+
/** The source itself, relative to the book's folder. */
|
|
88
|
+
stored?: string;
|
|
89
|
+
/** Its text, relative to the book's folder. */
|
|
90
|
+
textFile?: string;
|
|
91
|
+
url?: string;
|
|
92
|
+
bytes: number;
|
|
93
|
+
addedAt: string;
|
|
94
|
+
documentId?: number;
|
|
95
|
+
fingerprint?: number[];
|
|
96
|
+
metadata: Record<string, unknown>;
|
|
97
|
+
removedAt?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface BookImage {
|
|
100
|
+
id: number;
|
|
101
|
+
bookId: number;
|
|
102
|
+
sourceId: number;
|
|
103
|
+
sha256: string;
|
|
104
|
+
/** Relative to the book's folder. */
|
|
105
|
+
file: string;
|
|
106
|
+
mediaType: string;
|
|
107
|
+
bytes: number;
|
|
108
|
+
width?: number;
|
|
109
|
+
height?: number;
|
|
110
|
+
/** Where in the source it was: `page 7`, `chapter 2`. */
|
|
111
|
+
origin?: string;
|
|
112
|
+
/** What a vision model said it shows, or failing that its caption in the book. */
|
|
113
|
+
description?: string;
|
|
114
|
+
/** A vision model has described it: `description` is not just its caption. */
|
|
115
|
+
described: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface SourceImageInput {
|
|
118
|
+
/** The name the source's text links it by: `images/<file>`. */
|
|
119
|
+
file: string;
|
|
120
|
+
data: Uint8Array;
|
|
121
|
+
mediaType: string;
|
|
122
|
+
width?: number;
|
|
123
|
+
height?: number;
|
|
124
|
+
origin?: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
/** `description` is a vision model's, not the caption the book gave it. */
|
|
127
|
+
described?: boolean;
|
|
128
|
+
}
|
|
129
|
+
export interface AddSourceInput {
|
|
130
|
+
kind: BookSourceKind;
|
|
131
|
+
/** A file name, or a page's title. */
|
|
132
|
+
name: string;
|
|
133
|
+
/** For a file: where it is now. It is copied into the book. */
|
|
134
|
+
path?: string;
|
|
135
|
+
url?: string;
|
|
136
|
+
/** The source as text or markdown: what is searched. */
|
|
137
|
+
text: string;
|
|
138
|
+
title?: string;
|
|
139
|
+
metadata?: Record<string, unknown>;
|
|
140
|
+
images?: readonly SourceImageInput[];
|
|
141
|
+
/** A source of this book it takes the place of. */
|
|
142
|
+
replaces?: number;
|
|
143
|
+
}
|
|
144
|
+
export interface AddSourceResult {
|
|
145
|
+
source: BookSource;
|
|
146
|
+
outcome: "added" | "replaced" | "unchanged";
|
|
147
|
+
passages: number;
|
|
148
|
+
images: number;
|
|
149
|
+
}
|
|
150
|
+
export interface BookMatch {
|
|
151
|
+
book: LibraryBook;
|
|
152
|
+
source?: BookSource;
|
|
153
|
+
reason: "same file" | "same link" | "same isbn" | "same title and author" | "same title" | "similar text";
|
|
154
|
+
/** For "similar text": the share of the text the two have in common, 0 to 1. */
|
|
155
|
+
similarity?: number;
|
|
156
|
+
}
|
|
157
|
+
export interface FindSimilarInput {
|
|
158
|
+
sha256?: string;
|
|
159
|
+
url?: string;
|
|
160
|
+
title?: string;
|
|
161
|
+
authors?: readonly string[];
|
|
162
|
+
isbn?: string;
|
|
163
|
+
fingerprint?: readonly number[];
|
|
164
|
+
/** Text similarity below this is not reported. @default 0.3 */
|
|
165
|
+
minSimilarity?: number;
|
|
166
|
+
}
|
|
167
|
+
export type ExportScope = {
|
|
168
|
+
library: true;
|
|
169
|
+
} | {
|
|
170
|
+
sectionId: number;
|
|
171
|
+
} | {
|
|
172
|
+
shelfId: number;
|
|
173
|
+
} | {
|
|
174
|
+
bookId: number;
|
|
175
|
+
};
|
|
176
|
+
export interface ExportResult {
|
|
177
|
+
file: string;
|
|
178
|
+
books: number;
|
|
179
|
+
files: number;
|
|
180
|
+
bytes: number;
|
|
181
|
+
}
|
|
182
|
+
export interface ImportOptions {
|
|
183
|
+
settings?: LibrarySettings;
|
|
184
|
+
/** Put every book on this shelf, whatever shelf the archive says. */
|
|
185
|
+
shelfId?: number;
|
|
186
|
+
/**
|
|
187
|
+
* A book already here (the same book, by its id): leave it, replace it,
|
|
188
|
+
* or bring the archive's in beside it as a copy. @default "skip"
|
|
189
|
+
*/
|
|
190
|
+
existing?: "skip" | "replace" | "copy";
|
|
191
|
+
}
|
|
192
|
+
export interface ImportResult {
|
|
193
|
+
imported: {
|
|
194
|
+
title: string;
|
|
195
|
+
section: string;
|
|
196
|
+
shelf: string;
|
|
197
|
+
}[];
|
|
198
|
+
skipped: {
|
|
199
|
+
title: string;
|
|
200
|
+
reason: string;
|
|
201
|
+
}[];
|
|
202
|
+
}
|
|
203
|
+
export interface CatalogueProblem {
|
|
204
|
+
book?: string;
|
|
205
|
+
problem: string;
|
|
206
|
+
}
|
|
207
|
+
/** A title as it is compared: lower case, letters and digits only. */
|
|
208
|
+
export declare function normalizeTitle(title: string): string;
|
|
209
|
+
export declare function normalizeIsbn(isbn: string): string;
|
|
210
|
+
export declare class Catalogue {
|
|
211
|
+
private readonly library;
|
|
212
|
+
private readonly db;
|
|
213
|
+
private readonly booksDirectory;
|
|
214
|
+
constructor(library: Library);
|
|
215
|
+
private one;
|
|
216
|
+
private all;
|
|
217
|
+
bookDirectory(book: Pick<LibraryBook, "uid">): string;
|
|
218
|
+
/**
|
|
219
|
+
* A Library from before it had shelves: each of its collections becomes a
|
|
220
|
+
* shelf in "General" holding one book of that name. The documents stay
|
|
221
|
+
* indexed as they are; their files were never copied in, so the book
|
|
222
|
+
* records where they were.
|
|
223
|
+
*/
|
|
224
|
+
private adoptLegacyCollections;
|
|
225
|
+
sections(): LibrarySection[];
|
|
226
|
+
findSection(name: string): LibrarySection | undefined;
|
|
227
|
+
/** A shelf by name; in one section when that is given, and otherwise wherever it is the only one of that name. */
|
|
228
|
+
findShelf(name: string, section?: string): LibraryShelf | undefined;
|
|
229
|
+
shelf(shelfId: number): (LibraryShelf & {
|
|
230
|
+
section: string;
|
|
231
|
+
}) | undefined;
|
|
232
|
+
ensureSection(name: string, description?: string): LibrarySection;
|
|
233
|
+
updateSection(sectionId: number, change: {
|
|
234
|
+
name?: string;
|
|
235
|
+
description?: string;
|
|
236
|
+
}): void;
|
|
237
|
+
/** Remove a section and its shelves. Their books go to the trash. */
|
|
238
|
+
deleteSection(sectionId: number): number;
|
|
239
|
+
ensureShelf(sectionId: number, name: string, description?: string): LibraryShelf;
|
|
240
|
+
updateShelf(shelfId: number, change: {
|
|
241
|
+
name?: string;
|
|
242
|
+
description?: string;
|
|
243
|
+
sectionId?: number;
|
|
244
|
+
}): void;
|
|
245
|
+
/** Remove a shelf. Its books go to the trash; resolves with how many. */
|
|
246
|
+
deleteShelf(shelfId: number): number;
|
|
247
|
+
private toBook;
|
|
248
|
+
private static readonly BOOK_COLUMNS;
|
|
249
|
+
/** The books on a shelf, or all of them; the trash only when asked for. */
|
|
250
|
+
books(filter?: {
|
|
251
|
+
shelfId?: number;
|
|
252
|
+
trashed?: boolean;
|
|
253
|
+
}): LibraryBook[];
|
|
254
|
+
book(bookId: number): LibraryBook | undefined;
|
|
255
|
+
bookByUid(uid: string): LibraryBook | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* A book by what the model can name it with: its number (`#12`), its id,
|
|
258
|
+
* or its title. Several books of one title come back together, for the
|
|
259
|
+
* caller to say which.
|
|
260
|
+
*/
|
|
261
|
+
findBooks(reference: string, options?: {
|
|
262
|
+
trashed?: boolean;
|
|
263
|
+
}): LibraryBook[];
|
|
264
|
+
/** The collections search may read: every book not in the trash, or those of the shelves named. */
|
|
265
|
+
searchableCollections(shelfIds?: readonly number[]): number[];
|
|
266
|
+
/** Where a collection's passages are from: "Section / Shelf / Title". */
|
|
267
|
+
collectionLabels(): Map<number, string>;
|
|
268
|
+
createBook(input: {
|
|
269
|
+
shelfId: number;
|
|
270
|
+
title: string;
|
|
271
|
+
description?: string;
|
|
272
|
+
metadata?: BookMetadata;
|
|
273
|
+
uid?: string;
|
|
274
|
+
createdAt?: string;
|
|
275
|
+
}): LibraryBook;
|
|
276
|
+
/** Change what a book says of itself. `metadata` is merged; a key set to null is removed. */
|
|
277
|
+
updateBook(bookId: number, change: {
|
|
278
|
+
title?: string;
|
|
279
|
+
description?: string;
|
|
280
|
+
metadata?: Record<string, unknown>;
|
|
281
|
+
shelfId?: number;
|
|
282
|
+
}): LibraryBook;
|
|
283
|
+
/** To the trash: out of every search, and gone for good after thirty days. */
|
|
284
|
+
trashBook(bookId: number): void;
|
|
285
|
+
/** Out of the trash, onto the shelf it was on (made again if it is gone) or the one given. */
|
|
286
|
+
restoreBook(bookId: number, shelfId?: number): LibraryBook;
|
|
287
|
+
/** Delete a book for good: its passages, its vectors and its folder. */
|
|
288
|
+
purgeBook(bookId: number): Promise<void>;
|
|
289
|
+
/** Empty the trash of what has been in it past its days. `days: 0` empties it. */
|
|
290
|
+
purgeTrash(days?: number, at?: Date): Promise<{
|
|
291
|
+
books: number;
|
|
292
|
+
sources: number;
|
|
293
|
+
}>;
|
|
294
|
+
private toSource;
|
|
295
|
+
sources(bookId: number, options?: {
|
|
296
|
+
removed?: boolean;
|
|
297
|
+
}): BookSource[];
|
|
298
|
+
source(sourceId: number): BookSource | undefined;
|
|
299
|
+
images(bookId: number): BookImage[];
|
|
300
|
+
/** The name a source is indexed under: its own, made unique within the book. */
|
|
301
|
+
private documentName;
|
|
302
|
+
/**
|
|
303
|
+
* Add a source to a book: the file is copied in under its sha256, its
|
|
304
|
+
* text and pictures are written beside it, and the text is indexed. The
|
|
305
|
+
* same content already in the book is left alone; a page of the same
|
|
306
|
+
* link with other content takes the old one's place.
|
|
307
|
+
*/
|
|
308
|
+
addSource(bookId: number, input: AddSourceInput, settings?: LibrarySettings): Promise<AddSourceResult>;
|
|
309
|
+
/**
|
|
310
|
+
* Take a source out of its book. It is no longer searched, and its files
|
|
311
|
+
* stay in the book's folder for thirty days, where `restoreSource` finds
|
|
312
|
+
* them.
|
|
313
|
+
*/
|
|
314
|
+
removeSource(sourceId: number): Promise<void>;
|
|
315
|
+
restoreSource(sourceId: number, settings?: LibrarySettings): Promise<BookSource>;
|
|
316
|
+
/** Index a source's text from its file in the book's folder. */
|
|
317
|
+
private indexSource;
|
|
318
|
+
/** Remove a source for good: its passages, its vectors, its rows and its files. */
|
|
319
|
+
private dropSource;
|
|
320
|
+
/** Give a picture its description, or another one. */
|
|
321
|
+
describeImage(imageId: number, description: string): void;
|
|
322
|
+
/**
|
|
323
|
+
* Give pictures of one source their descriptions after the fact: each is
|
|
324
|
+
* kept with its picture, written into the source's text where the picture
|
|
325
|
+
* is linked, and the source is indexed again so the words can be found.
|
|
326
|
+
*
|
|
327
|
+
* This is what adding a book does when a vision model is set; it lets a
|
|
328
|
+
* book added without one be completed without reading the book again.
|
|
329
|
+
*/
|
|
330
|
+
describeSourceImages(sourceId: number, described: readonly {
|
|
331
|
+
imageId: number;
|
|
332
|
+
description: string;
|
|
333
|
+
alt: string;
|
|
334
|
+
}[], settings?: LibrarySettings): Promise<{
|
|
335
|
+
described: number;
|
|
336
|
+
passages: number;
|
|
337
|
+
}>;
|
|
338
|
+
/**
|
|
339
|
+
* Move every source of one book into another, and trash the emptied one.
|
|
340
|
+
* A source the other already holds is left where it is.
|
|
341
|
+
*/
|
|
342
|
+
mergeBooks(fromId: number, intoId: number, settings?: LibrarySettings): Promise<{
|
|
343
|
+
moved: number;
|
|
344
|
+
alreadyThere: number;
|
|
345
|
+
}>;
|
|
346
|
+
/**
|
|
347
|
+
* The books that may be this one: the same file, the same link, the same
|
|
348
|
+
* ISBN, the same title, or text that is largely the same. Books in the
|
|
349
|
+
* trash are included, and say so.
|
|
350
|
+
*/
|
|
351
|
+
findSimilar(input: FindSimilarInput): BookMatch[];
|
|
352
|
+
private bookFile;
|
|
353
|
+
/** Write `book.json`: what the folder is, for a person and for import. */
|
|
354
|
+
writeBookFile(bookId: number): void;
|
|
355
|
+
private rewriteBookFiles;
|
|
356
|
+
/**
|
|
357
|
+
* Write the Library, a section, a shelf or one book to a file: the books'
|
|
358
|
+
* folders as they are, and where each stood. Vectors are left out; they
|
|
359
|
+
* are made again where the file is read in, with the model set there.
|
|
360
|
+
*/
|
|
361
|
+
export(scope: ExportScope, file: string): Promise<ExportResult>;
|
|
362
|
+
/**
|
|
363
|
+
* Read an exported file in. Sections and shelves are made where they are
|
|
364
|
+
* missing; a book already here is left alone unless told otherwise.
|
|
365
|
+
*/
|
|
366
|
+
import(file: string, options?: ImportOptions): Promise<ImportResult>;
|
|
367
|
+
private importBook;
|
|
368
|
+
/** What is wrong with the Library as it stands: missing files, books with nothing in them. */
|
|
369
|
+
problems(): CatalogueProblem[];
|
|
370
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a document's text into the chunks that are indexed.
|
|
3
|
+
*
|
|
4
|
+
* Every chunk is a contiguous slice of the source, so it carries the offsets
|
|
5
|
+
* it came from and can be shown in place. The steps, in order:
|
|
6
|
+
*
|
|
7
|
+
* 1. With `markdownHeaders`, the text is first cut into sections at its
|
|
8
|
+
* markdown headers, and each chunk remembers the headers above it.
|
|
9
|
+
* 2. A section larger than `size` is cut at the most natural boundary that
|
|
10
|
+
* is small enough: paragraphs, then lines, then sentences, then words,
|
|
11
|
+
* and only then mid-word.
|
|
12
|
+
* 3. Neighbouring pieces are packed into chunks of at most `size`, each
|
|
13
|
+
* starting up to `overlap` before the end of the one before.
|
|
14
|
+
* 4. With `minSize`, a chunk smaller than that is merged into its neighbour
|
|
15
|
+
* when the result still fits, forward first and then backward.
|
|
16
|
+
*
|
|
17
|
+
* Sizes are counted in characters, or in estimated tokens (four characters
|
|
18
|
+
* each) unless a real counter is passed as `measure`.
|
|
19
|
+
*/
|
|
20
|
+
export interface ChunkOptions {
|
|
21
|
+
/** Largest chunk. Default 1500. */
|
|
22
|
+
size?: number;
|
|
23
|
+
/** Shared between neighbouring chunks of one section. Default 100. */
|
|
24
|
+
overlap?: number;
|
|
25
|
+
/** Chunks smaller than this are merged when possible. 0 turns it off. Default 0. */
|
|
26
|
+
minSize?: number;
|
|
27
|
+
/** What `size`, `overlap` and `minSize` count. Default "characters". */
|
|
28
|
+
unit?: "characters" | "tokens";
|
|
29
|
+
/** Cut at markdown headers first, and record them. Default true. */
|
|
30
|
+
markdownHeaders?: boolean;
|
|
31
|
+
/** A real counter, replacing the estimate for `unit`. */
|
|
32
|
+
measure?: (text: string) => number;
|
|
33
|
+
}
|
|
34
|
+
export interface TextChunk {
|
|
35
|
+
/** Position among the document's chunks, from 0. */
|
|
36
|
+
index: number;
|
|
37
|
+
text: string;
|
|
38
|
+
/** Offsets of `text` in the source: `source.slice(start, end) === text`. */
|
|
39
|
+
start: number;
|
|
40
|
+
end: number;
|
|
41
|
+
/** The markdown headers above the chunk's start, outermost first. */
|
|
42
|
+
headings: string[];
|
|
43
|
+
}
|
|
44
|
+
export declare function chunkText(source: string, options?: ChunkOptions): TextChunk[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding and reranking over HTTP, for the Library and the memory store.
|
|
3
|
+
*
|
|
4
|
+
* One wire format each, the ones every server in use speaks:
|
|
5
|
+
*
|
|
6
|
+
* - embeddings: OpenAI's `POST <base>/embeddings` with `{model, input: []}`,
|
|
7
|
+
* answered by `{data: [{index, embedding}]}`. Ollama, llama.cpp, opencoti,
|
|
8
|
+
* LM Studio, vLLM, TEI and OpenAI itself all serve it.
|
|
9
|
+
* - reranking: `POST <base>/rerank` with `{model, query, documents, top_n}`,
|
|
10
|
+
* answered by `{results: [{index, relevance_score}]}` (Jina's and Cohere's
|
|
11
|
+
* shape; llama.cpp with `--reranking`, vLLM and Infinity serve it). TEI's
|
|
12
|
+
* bare array of `{index, score}` is read too.
|
|
13
|
+
*
|
|
14
|
+
* A server that is busy is not a failure: 429 and 5xx are retried with a
|
|
15
|
+
* growing wait before the error is passed on.
|
|
16
|
+
*/
|
|
17
|
+
export interface RetrievalEndpoint {
|
|
18
|
+
/** With or without a trailing `/v1`; `/v1` is added when the path has none. */
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
model: string;
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
export interface EmbedOptions {
|
|
25
|
+
/** Texts per request. Default 64. */
|
|
26
|
+
batchSize?: number;
|
|
27
|
+
/** Requests in flight at once. 0 means no limit of ours. Default 4. */
|
|
28
|
+
concurrency?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Text put in front of every input. Instruction-tuned embedders want one
|
|
31
|
+
* for queries and usually none for documents.
|
|
32
|
+
*/
|
|
33
|
+
prefix?: string;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
/** Attempts per request before a busy or failing server is reported. Default 4. */
|
|
37
|
+
maxAttempts?: number;
|
|
38
|
+
/** First wait between attempts, doubled each time. Default 500. */
|
|
39
|
+
retryDelayMs?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface EmbedResult {
|
|
42
|
+
vectors: Float32Array[];
|
|
43
|
+
dimension: number;
|
|
44
|
+
/** The model as the server named it, when it did. */
|
|
45
|
+
model?: string;
|
|
46
|
+
promptTokens?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface RerankOptions {
|
|
49
|
+
/** Documents per request. Default 32. */
|
|
50
|
+
batchSize?: number;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
fetch?: typeof fetch;
|
|
53
|
+
maxAttempts?: number;
|
|
54
|
+
retryDelayMs?: number;
|
|
55
|
+
}
|
|
56
|
+
export declare class RetrievalEndpointError extends Error {
|
|
57
|
+
readonly status?: number | undefined;
|
|
58
|
+
readonly body?: string | undefined;
|
|
59
|
+
constructor(message: string, status?: number | undefined, body?: string | undefined);
|
|
60
|
+
}
|
|
61
|
+
/** `http://host:1234` and `http://host:1234/v1/` both become `http://host:1234/v1`. */
|
|
62
|
+
export declare function resolveRetrievalBaseUrl(baseUrl: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the server refused an input for its size. llama.cpp reports that
|
|
65
|
+
* as a 500, which would otherwise read as a server worth asking again.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isInputTooLarge(error: unknown): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Embed texts, in the order given. Every vector has the same length, and
|
|
70
|
+
* there is exactly one per text, or this throws: a short or ragged answer
|
|
71
|
+
* written to an index is worse than no answer.
|
|
72
|
+
*/
|
|
73
|
+
export declare function embedTexts(endpoint: RetrievalEndpoint, texts: readonly string[], options?: EmbedOptions): Promise<EmbedResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Score each document against the query. One score per document, in the
|
|
76
|
+
* order the documents were given; higher is more relevant.
|
|
77
|
+
*/
|
|
78
|
+
export declare function rerankDocuments(endpoint: RetrievalEndpoint, query: string, documents: readonly string[], options?: RerankOptions): Promise<number[]>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A text's fingerprint: a few numbers that say how much of two texts is the
|
|
3
|
+
* same, without keeping either.
|
|
4
|
+
*
|
|
5
|
+
* This is how the Library tells that a file is a book it already has under
|
|
6
|
+
* another name or in another format, and how it tells a new edition (much
|
|
7
|
+
* the same, not all) from a copy (all but the same). It needs no model.
|
|
8
|
+
*
|
|
9
|
+
* MinHash over five-word shingles: the share of positions where two
|
|
10
|
+
* fingerprints agree estimates the share of five-word runs the texts have in
|
|
11
|
+
* common.
|
|
12
|
+
*/
|
|
13
|
+
export declare const FINGERPRINT_SIZE = 64;
|
|
14
|
+
/**
|
|
15
|
+
* The fingerprint of a text. Markup, case, punctuation and line breaks are
|
|
16
|
+
* not part of it, so the same book read out of a PDF and out of an EPUB come
|
|
17
|
+
* out close. Empty for a text of fewer than five words.
|
|
18
|
+
*/
|
|
19
|
+
export declare function textFingerprint(text: string): number[];
|
|
20
|
+
/** How much of two texts is the same, 0 to 1, from their fingerprints. */
|
|
21
|
+
export declare function fingerprintSimilarity(a: readonly number[], b: readonly number[]): number;
|