wiki-graph 0.3.0 → 0.3.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/dist/cli.d.ts +1 -0
- package/dist/cli.js +38312 -4
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +24706 -10909
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1843 -36
- package/dist/index.d.ts +1843 -36
- package/dist/index.js +34565 -9
- package/dist/index.js.map +1 -0
- package/dist/queue-worker.d.ts +1 -0
- package/dist/{cli.cjs → queue-worker.js} +21449 -38388
- package/dist/queue-worker.js.map +1 -0
- package/package.json +6 -45
- package/README.md +0 -278
- package/dist/cli.cjs.map +0 -1
- package/docs/images/flowchart.excalidraw +0 -3293
- package/docs/images/flowchart.svg +0 -4
- package/docs/images/terminal-cn.png +0 -0
- package/docs/images/terminal-en.png +0 -0
- package/docs/wikispine-runtime.md +0 -143
- /package/{data → dist/data}/editor/clue_reviewer.jinja +0 -0
- /package/{data → dist/data}/editor/clue_reviewer_generator.jinja +0 -0
- /package/{data → dist/data}/editor/revision_feedback.jinja +0 -0
- /package/{data → dist/data}/editor/text_compressor.jinja +0 -0
- /package/{data → dist/data}/guaranteed/response_intent_classifier.jinja +0 -0
- /package/{data → dist/data}/help/commands/archive/next.jinja +0 -0
- /package/{data → dist/data}/help/commands/gc.jinja +0 -0
- /package/{data → dist/data}/help/commands/legacy/migrate.jinja +0 -0
- /package/{data → dist/data}/help/commands/legacy.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/add.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/list.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/move.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/remove.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/reset.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/set-source.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/set-summary.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/set-title.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter/tree.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/chapter.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/cover.jinja +0 -0
- /package/{data → dist/data}/help/commands/maintenance/meta.jinja +0 -0
- /package/{data → dist/data}/help/commands/predicate.jinja +0 -0
- /package/{data → dist/data}/help/commands/root.jinja +0 -0
- /package/{data → dist/data}/help/commands/transform.jinja +0 -0
- /package/{data → dist/data}/help/commands/uri.jinja +0 -0
- /package/{data → dist/data}/help/topics/config.jinja +0 -0
- /package/{data → dist/data}/help/topics/format.jinja +0 -0
- /package/{data → dist/data}/help/topics/readiness.jinja +0 -0
- /package/{data → dist/data}/help/topics/recipe.jinja +0 -0
- /package/{data → dist/data}/help/topics/runtime.jinja +0 -0
- /package/{data → dist/data}/help/topics/uri.jinja +0 -0
- /package/{data → dist/data}/output/epub/cover.xhtml.jinja +0 -0
- /package/{data → dist/data}/output/epub/nav.xhtml.jinja +0 -0
- /package/{data → dist/data}/output/epub/package.opf.xml.jinja +0 -0
- /package/{data → dist/data}/output/epub/section.xhtml.jinja +0 -0
- /package/{data → dist/data}/topologization/book_coherence_extraction.jinja +0 -0
- /package/{data → dist/data}/topologization/chunk_extraction.jinja +0 -0
- /package/{data → dist/data}/topologization/evidence_choice.jinja +0 -0
- /package/{data → dist/data}/topologization/translate_chunks.jinja +0 -0
- /package/{data → dist/data}/topologization/user_focused_extraction.jinja +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { LanguageModel, ModelMessage } from 'ai';
|
|
2
|
+
import { Environment } from 'nunjucks';
|
|
1
3
|
import * as Sqlite3Namespace from 'sqlite3';
|
|
2
|
-
import { ModelMessage, LanguageModel } from 'ai';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
declare enum Language {
|
|
@@ -56,16 +57,16 @@ declare function formatLanguageForPrompt(code: LanguageCode): Language;
|
|
|
56
57
|
declare function normalizeLanguageCode(language: Language | string | null | undefined): LanguageCode | undefined;
|
|
57
58
|
declare function getWikipageLanguageCode(language: Language | string | null | undefined): "en" | "zh" | undefined;
|
|
58
59
|
|
|
59
|
-
declare const
|
|
60
|
+
declare const WIKI_GRAPH_CONTEXT_VERSION = 1;
|
|
60
61
|
declare const TASK_STATUS_VERSION = 1;
|
|
61
|
-
type
|
|
62
|
-
interface
|
|
62
|
+
type WikiGraphTaskType = "source-to-graph" | "source-graph-to-summary";
|
|
63
|
+
interface WikiGraphTaskIdentity {
|
|
63
64
|
readonly normalizedSource: string;
|
|
64
65
|
readonly parameters: unknown;
|
|
65
|
-
readonly taskType:
|
|
66
|
+
readonly taskType: WikiGraphTaskType;
|
|
66
67
|
readonly version?: number;
|
|
67
68
|
}
|
|
68
|
-
interface
|
|
69
|
+
interface WikiGraphTaskContextOptions {
|
|
69
70
|
readonly rootDirPath: string;
|
|
70
71
|
}
|
|
71
72
|
interface TaskStatus {
|
|
@@ -74,25 +75,119 @@ interface TaskStatus {
|
|
|
74
75
|
readonly status: "running" | "succeeded";
|
|
75
76
|
readonly version: typeof TASK_STATUS_VERSION;
|
|
76
77
|
}
|
|
77
|
-
declare class
|
|
78
|
+
declare class WikiGraphTaskContext {
|
|
78
79
|
#private;
|
|
79
|
-
constructor(options:
|
|
80
|
-
createTask(identity:
|
|
81
|
-
runTask<T>(identity:
|
|
80
|
+
constructor(options: WikiGraphTaskContextOptions);
|
|
81
|
+
createTask(identity: WikiGraphTaskIdentity): WikiGraphTask;
|
|
82
|
+
runTask<T>(identity: WikiGraphTaskIdentity, operation: (task: WikiGraphTask) => Promise<T> | T): Promise<T>;
|
|
82
83
|
}
|
|
83
|
-
declare class
|
|
84
|
+
declare class WikiGraphTask {
|
|
84
85
|
#private;
|
|
85
86
|
constructor(id: string, path: string);
|
|
86
87
|
get artifactDirPath(): string;
|
|
87
88
|
get id(): string;
|
|
88
89
|
get path(): string;
|
|
89
90
|
readStatus(): Promise<TaskStatus | undefined>;
|
|
90
|
-
run<T>(operation: (task:
|
|
91
|
+
run<T>(operation: (task: WikiGraphTask) => Promise<T> | T): Promise<T>;
|
|
91
92
|
remove(): Promise<void>;
|
|
92
93
|
}
|
|
93
|
-
declare function
|
|
94
|
+
declare function createWikiGraphTaskId(identity: WikiGraphTaskIdentity): string;
|
|
95
|
+
|
|
96
|
+
interface PendingCacheEntry {
|
|
97
|
+
cacheKey: string;
|
|
98
|
+
response: string;
|
|
99
|
+
}
|
|
100
|
+
declare class LLMCache {
|
|
101
|
+
#private;
|
|
102
|
+
constructor(cacheDirPath: string);
|
|
103
|
+
createEntry(cacheKey: string, response: string): PendingCacheEntry;
|
|
104
|
+
read(cacheKey: string): Promise<string | undefined>;
|
|
105
|
+
write(entry: PendingCacheEntry): Promise<void>;
|
|
106
|
+
}
|
|
94
107
|
|
|
95
108
|
type LLMessage = ModelMessage;
|
|
109
|
+
type LLMModel = LanguageModel;
|
|
110
|
+
type TemperatureSetting = number | readonly number[];
|
|
111
|
+
interface SamplingProfile {
|
|
112
|
+
readonly temperature?: TemperatureSetting;
|
|
113
|
+
readonly topP?: TemperatureSetting;
|
|
114
|
+
}
|
|
115
|
+
type SamplingScopeConfig<S extends string> = {
|
|
116
|
+
readonly [scope in S]: SamplingProfile;
|
|
117
|
+
};
|
|
118
|
+
interface LLMRequestOptions<S extends string> {
|
|
119
|
+
readonly signal?: AbortSignal;
|
|
120
|
+
readonly temperature?: TemperatureSetting;
|
|
121
|
+
readonly topP?: TemperatureSetting;
|
|
122
|
+
readonly scope?: S;
|
|
123
|
+
readonly useCache?: boolean;
|
|
124
|
+
readonly retryIndex?: number;
|
|
125
|
+
readonly retryMax?: number;
|
|
126
|
+
}
|
|
127
|
+
type LLMRequestFunction<S extends string> = (messages: readonly LLMessage[], options?: LLMRequestOptions<S>) => Promise<string>;
|
|
128
|
+
type LLMLazyRequestOperation<S extends string, T> = (request: LLMRequestFunction<S>) => Promise<T>;
|
|
129
|
+
type LLMStreamProgressCallback = (event: {
|
|
130
|
+
readonly outputCharacters: number;
|
|
131
|
+
}) => void | Promise<void>;
|
|
132
|
+
interface LLMTokenUsage {
|
|
133
|
+
readonly cacheReadTokens?: number;
|
|
134
|
+
readonly inputTokens?: number;
|
|
135
|
+
readonly outputTokens?: number;
|
|
136
|
+
}
|
|
137
|
+
type LLMTokenUsageCallback = (usage: LLMTokenUsage) => void | Promise<void>;
|
|
138
|
+
interface LLMOptions<S extends string> {
|
|
139
|
+
readonly model: LLMModel;
|
|
140
|
+
readonly dataDirPath: string;
|
|
141
|
+
readonly logDirPath?: string;
|
|
142
|
+
readonly cacheDirPath?: string;
|
|
143
|
+
readonly concurrent?: number;
|
|
144
|
+
readonly stream?: boolean;
|
|
145
|
+
readonly timeout?: number;
|
|
146
|
+
readonly temperature?: TemperatureSetting;
|
|
147
|
+
readonly topP?: TemperatureSetting;
|
|
148
|
+
readonly sampling?: SamplingScopeConfig<S>;
|
|
149
|
+
readonly retryTimes?: number;
|
|
150
|
+
readonly retryIntervalSeconds?: number;
|
|
151
|
+
readonly onStreamProgress?: LLMStreamProgressCallback;
|
|
152
|
+
readonly onTokenUsage?: LLMTokenUsageCallback;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface LLMContextRequestInput<S extends string> {
|
|
156
|
+
messages: readonly LLMessage[];
|
|
157
|
+
options: LLMRequestOptions<S>;
|
|
158
|
+
pendingCacheEntries?: Map<string, PendingCacheEntry>;
|
|
159
|
+
logFiles?: string[];
|
|
160
|
+
}
|
|
161
|
+
type LLMContextRequest<S extends string> = (input: LLMContextRequestInput<S>) => Promise<string>;
|
|
162
|
+
declare class LLMContext<S extends string> {
|
|
163
|
+
#private;
|
|
164
|
+
readonly sessionId: number;
|
|
165
|
+
constructor(sessionId: number, requestFn: LLMContextRequest<S>, cache?: LLMCache);
|
|
166
|
+
request(messages: readonly LLMessage[], options?: LLMRequestOptions<S>): Promise<string>;
|
|
167
|
+
commit(): Promise<void>;
|
|
168
|
+
rollback(): Promise<void>;
|
|
169
|
+
run<T>(operation: (context: LLMContext<S>) => Promise<T>): Promise<T>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
declare class LLM<S extends string> {
|
|
173
|
+
#private;
|
|
174
|
+
readonly config: Readonly<{
|
|
175
|
+
concurrent: number;
|
|
176
|
+
provider?: string;
|
|
177
|
+
modelId: string;
|
|
178
|
+
sampling?: SamplingScopeConfig<S>;
|
|
179
|
+
stream: boolean;
|
|
180
|
+
timeout: number;
|
|
181
|
+
temperature: TemperatureSetting;
|
|
182
|
+
topP: TemperatureSetting;
|
|
183
|
+
}>;
|
|
184
|
+
constructor(options: LLMOptions<S>);
|
|
185
|
+
context(): LLMContext<S>;
|
|
186
|
+
withContext<T>(operation: (context: LLMContext<S>) => Promise<T>): Promise<T>;
|
|
187
|
+
request(messages: readonly LLMessage[], options?: LLMRequestOptions<S>): Promise<string>;
|
|
188
|
+
request<T>(operation: LLMLazyRequestOperation<S, T>): Promise<T>;
|
|
189
|
+
loadSystemPrompt(templateName: string, templateContext?: Record<string, unknown>): string;
|
|
190
|
+
}
|
|
96
191
|
|
|
97
192
|
declare class LLMPaymentRequiredError extends Error {
|
|
98
193
|
readonly isRetryable = false;
|
|
@@ -100,6 +195,47 @@ declare class LLMPaymentRequiredError extends Error {
|
|
|
100
195
|
constructor(message?: string, options?: ErrorOptions);
|
|
101
196
|
}
|
|
102
197
|
|
|
198
|
+
declare enum WikiGraphScope {
|
|
199
|
+
EditorCompress = "serial-generation/editor-compress",
|
|
200
|
+
EditorReview = "serial-generation/editor-review",
|
|
201
|
+
EditorReviewGuide = "serial-generation/editor-review-guide",
|
|
202
|
+
ReaderChoice = "serial-generation/reader-choice",
|
|
203
|
+
ReaderExtraction = "serial-generation/reader-extraction"
|
|
204
|
+
}
|
|
205
|
+
declare const WIKI_GRAPH_SCOPES: readonly [WikiGraphScope.EditorCompress, WikiGraphScope.EditorReview, WikiGraphScope.EditorReviewGuide, WikiGraphScope.ReaderChoice, WikiGraphScope.ReaderExtraction];
|
|
206
|
+
declare const WIKI_GRAPH_EDITOR_SCOPES: Readonly<{
|
|
207
|
+
compress: WikiGraphScope.EditorCompress;
|
|
208
|
+
review: WikiGraphScope.EditorReview;
|
|
209
|
+
reviewGuide: WikiGraphScope.EditorReviewGuide;
|
|
210
|
+
}>;
|
|
211
|
+
declare const WIKI_GRAPH_READER_SCOPES: Readonly<{
|
|
212
|
+
choice: WikiGraphScope.ReaderChoice;
|
|
213
|
+
extraction: WikiGraphScope.ReaderExtraction;
|
|
214
|
+
}>;
|
|
215
|
+
|
|
216
|
+
declare function withLoggingContext<T>(input: {
|
|
217
|
+
readonly operation: string;
|
|
218
|
+
readonly logDirPath?: string;
|
|
219
|
+
readonly verbose?: boolean;
|
|
220
|
+
}, operation: () => Promise<T>): Promise<T>;
|
|
221
|
+
|
|
222
|
+
declare const CLI_PRIMARY_COMMAND = "wg";
|
|
223
|
+
declare const CLI_FULL_COMMAND = "wikigraph";
|
|
224
|
+
|
|
225
|
+
declare function resolveDataDirPath(): string;
|
|
226
|
+
|
|
227
|
+
declare function createEnv(dirPath: string, options?: {
|
|
228
|
+
readonly autoescape?: boolean;
|
|
229
|
+
readonly trimBlocks?: boolean;
|
|
230
|
+
}): Environment;
|
|
231
|
+
|
|
232
|
+
declare function resolveWikiGraphHomeDirectoryPath(): string;
|
|
233
|
+
declare function resolveWikiGraphCoreDatabasePath(): string;
|
|
234
|
+
|
|
235
|
+
type WikiGraphTempCategory = "archive-open" | "archive-write" | "cli-output" | "sdpub-upgrade" | "stdin-create" | "url-create";
|
|
236
|
+
declare function resolveWikiGraphStateRootPath(): string;
|
|
237
|
+
declare function createWikiGraphTempDirectory(category: WikiGraphTempCategory): Promise<string>;
|
|
238
|
+
|
|
103
239
|
type SqliteDatabase = Sqlite3Namespace.Database;
|
|
104
240
|
type SqlBindValue = Buffer | Uint8Array | number | string | null;
|
|
105
241
|
type SqlBindParams = readonly SqlBindValue[];
|
|
@@ -124,17 +260,26 @@ declare class Database {
|
|
|
124
260
|
getLastInsertRowId(): Promise<number>;
|
|
125
261
|
}
|
|
126
262
|
|
|
263
|
+
declare function openSharedStateDatabase(databasePath: string, schemaSql: string, options?: {
|
|
264
|
+
readonly readonly?: boolean;
|
|
265
|
+
}): Promise<Database>;
|
|
266
|
+
declare function ensureSharedStateDatabaseInitialized(databasePath: string, schemaSql: string): Promise<void>;
|
|
267
|
+
|
|
127
268
|
declare enum ChunkRetention {
|
|
128
269
|
Verbatim = "verbatim",
|
|
129
270
|
Detailed = "detailed",
|
|
130
271
|
Focused = "focused",
|
|
131
272
|
Relevant = "relevant"
|
|
132
273
|
}
|
|
274
|
+
declare const isChunkRetention: (value: string) => value is ChunkRetention;
|
|
275
|
+
declare const expectChunkRetention: (value: string) => ChunkRetention;
|
|
133
276
|
declare enum ChunkImportance {
|
|
134
277
|
Critical = "critical",
|
|
135
278
|
Important = "important",
|
|
136
279
|
Helpful = "helpful"
|
|
137
280
|
}
|
|
281
|
+
declare const isChunkImportance: (value: string) => value is ChunkImportance;
|
|
282
|
+
declare const expectChunkImportance: (value: string) => ChunkImportance;
|
|
138
283
|
type SentenceId = readonly [chapterId: number, sentenceIndex: number];
|
|
139
284
|
interface SentenceRecord {
|
|
140
285
|
readonly text: string;
|
|
@@ -173,6 +318,7 @@ interface ChunkRecord {
|
|
|
173
318
|
readonly wordsCount: number;
|
|
174
319
|
readonly weight: number;
|
|
175
320
|
}
|
|
321
|
+
type CreateChunkRecord = Omit<ChunkRecord, "id">;
|
|
176
322
|
interface ReadingEdgeRecord {
|
|
177
323
|
readonly fromId: number;
|
|
178
324
|
readonly toId: number;
|
|
@@ -211,6 +357,16 @@ interface SnakeRecord {
|
|
|
211
357
|
readonly wordsCount: number;
|
|
212
358
|
readonly weight: number;
|
|
213
359
|
}
|
|
360
|
+
interface CreateSnakeRecord {
|
|
361
|
+
readonly serialId: number;
|
|
362
|
+
readonly groupId: number;
|
|
363
|
+
readonly localSnakeId: number;
|
|
364
|
+
readonly size: number;
|
|
365
|
+
readonly firstLabel: string;
|
|
366
|
+
readonly lastLabel: string;
|
|
367
|
+
readonly wordsCount?: number;
|
|
368
|
+
readonly weight?: number;
|
|
369
|
+
}
|
|
214
370
|
interface SnakeChunkRecord {
|
|
215
371
|
readonly snakeId: number;
|
|
216
372
|
readonly chunkId: number;
|
|
@@ -228,7 +384,54 @@ interface SentenceGroupRecord {
|
|
|
228
384
|
readonly endSentenceIndex: number;
|
|
229
385
|
readonly fragmentId?: number;
|
|
230
386
|
}
|
|
387
|
+
declare const enum ObjectMetadataKind {
|
|
388
|
+
Archive = 1,
|
|
389
|
+
Chapter = 2,
|
|
390
|
+
Chunk = 3,
|
|
391
|
+
Entity = 4,
|
|
392
|
+
Triple = 5,
|
|
393
|
+
Object = 6
|
|
394
|
+
}
|
|
395
|
+
interface ObjectMetadataTarget {
|
|
396
|
+
readonly kind: ObjectMetadataKind;
|
|
397
|
+
readonly objectPath: string;
|
|
398
|
+
readonly chapterId?: number;
|
|
399
|
+
readonly chunkId?: number;
|
|
400
|
+
readonly entityQid?: string;
|
|
401
|
+
readonly tripleSubjectQid?: string;
|
|
402
|
+
readonly triplePredicate?: string;
|
|
403
|
+
readonly tripleObjectQid?: string;
|
|
404
|
+
}
|
|
231
405
|
|
|
406
|
+
declare const TEXT_STREAM_KIND: {
|
|
407
|
+
readonly source: 1;
|
|
408
|
+
readonly summary: 2;
|
|
409
|
+
};
|
|
410
|
+
type TextStreamName = keyof typeof TEXT_STREAM_KIND;
|
|
411
|
+
interface TextStreamFileAccess {
|
|
412
|
+
deleteTree(path: string): Promise<void>;
|
|
413
|
+
ensureDirectory(path: string): Promise<void>;
|
|
414
|
+
listFiles(path: string): Promise<readonly string[]>;
|
|
415
|
+
readFile(path: string): Promise<Uint8Array | undefined>;
|
|
416
|
+
writeFile(path: string, content: string | Uint8Array, options: {
|
|
417
|
+
readonly overwrite?: boolean;
|
|
418
|
+
}): Promise<void>;
|
|
419
|
+
}
|
|
420
|
+
interface TextStreamSentenceSegmenter {
|
|
421
|
+
pipe(stream: Iterable<string>): AsyncIterable<{
|
|
422
|
+
readonly offset: number;
|
|
423
|
+
readonly text: string;
|
|
424
|
+
readonly wordsCount: number;
|
|
425
|
+
}>;
|
|
426
|
+
}
|
|
427
|
+
interface WriteTextStreamOptions {
|
|
428
|
+
readonly segmenter?: TextStreamSentenceSegmenter;
|
|
429
|
+
}
|
|
430
|
+
interface ReadonlyTextStreams {
|
|
431
|
+
getSentence(sentenceId: SentenceId): Promise<string>;
|
|
432
|
+
getSerial(serialId: number): ReadonlySerialTextStream;
|
|
433
|
+
getSummarySerial(serialId: number): ReadonlySerialTextStream;
|
|
434
|
+
}
|
|
232
435
|
interface ReadonlySerialTextStream {
|
|
233
436
|
getFragment(fragmentId: number): Promise<FragmentRecord>;
|
|
234
437
|
getSentence?(sentenceIndex: number): Promise<SentenceRecord>;
|
|
@@ -240,6 +443,106 @@ interface ReadonlySerialTextStream {
|
|
|
240
443
|
readonly path: string;
|
|
241
444
|
readonly serialId: number;
|
|
242
445
|
}
|
|
446
|
+
declare class TextStreams implements ReadonlyTextStreams {
|
|
447
|
+
#private;
|
|
448
|
+
constructor(documentPath: string, database: Database, fileAccess?: TextStreamFileAccess);
|
|
449
|
+
ensureCreated(): Promise<void>;
|
|
450
|
+
getSentence(sentenceId: SentenceId): Promise<string>;
|
|
451
|
+
getSerial(serialId: number): SerialTextStream;
|
|
452
|
+
getSummarySerial(serialId: number): SerialTextStream;
|
|
453
|
+
}
|
|
454
|
+
declare class SerialTextStream implements ReadonlySerialTextStream {
|
|
455
|
+
#private;
|
|
456
|
+
constructor(documentPath: string, database: Database, fileAccess: TextStreamFileAccess, stream: TextStreamName, serialId: number);
|
|
457
|
+
createDraft(): Promise<TextStreamDraft>;
|
|
458
|
+
getFragment(fragmentId: number): Promise<FragmentRecord>;
|
|
459
|
+
getSentence(sentenceIndex: number): Promise<SentenceRecord>;
|
|
460
|
+
listFragmentIds(): Promise<readonly number[]>;
|
|
461
|
+
listSentences(): Promise<readonly SentenceRecord[]>;
|
|
462
|
+
listSentencesInRange(startSentenceIndex: number, endSentenceIndex: number): Promise<readonly SentenceRecord[]>;
|
|
463
|
+
readTextInRange(startSentenceIndex: number, endSentenceIndex: number): Promise<string | undefined>;
|
|
464
|
+
readText(): Promise<string | undefined>;
|
|
465
|
+
writeTextStream(text: string, options?: WriteTextStreamOptions): Promise<void>;
|
|
466
|
+
delete(): Promise<void>;
|
|
467
|
+
get path(): string;
|
|
468
|
+
get serialId(): number;
|
|
469
|
+
}
|
|
470
|
+
declare class TextStreamDraft {
|
|
471
|
+
#private;
|
|
472
|
+
constructor(serialId: number, startSentenceIndex: number, callbacks: {
|
|
473
|
+
readonly discard: () => void;
|
|
474
|
+
readonly finalize: (startSentenceIndex: number, summary: string, sentences: readonly SentenceRecord[]) => Promise<FragmentRecord | undefined>;
|
|
475
|
+
});
|
|
476
|
+
addSentence(text: string, wordsCount: number, location?: {
|
|
477
|
+
readonly byteOffset: number;
|
|
478
|
+
readonly byteLength: number;
|
|
479
|
+
}): SentenceId;
|
|
480
|
+
commit(): Promise<FragmentRecord | undefined>;
|
|
481
|
+
commitWithText(text: string): Promise<FragmentRecord | undefined>;
|
|
482
|
+
discard(): void;
|
|
483
|
+
setSummary(summary: string): void;
|
|
484
|
+
get fragmentId(): number;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
interface FragmentWriter {
|
|
488
|
+
write(path: string, content: string): Promise<void>;
|
|
489
|
+
}
|
|
490
|
+
interface FragmentFileAccess {
|
|
491
|
+
ensureDirectory(path: string): Promise<void>;
|
|
492
|
+
listFileContents?(path: string): Promise<ReadonlyMap<string, Uint8Array>>;
|
|
493
|
+
listFiles(path: string): Promise<readonly string[]>;
|
|
494
|
+
readFile(path: string): Promise<Uint8Array | undefined>;
|
|
495
|
+
}
|
|
496
|
+
interface ReadonlyFragments {
|
|
497
|
+
getSerial(serialId: number): ReadonlySerialFragments;
|
|
498
|
+
getSummarySerial(serialId: number): ReadonlySerialFragments;
|
|
499
|
+
getSentence(sentenceId: SentenceId): Promise<string>;
|
|
500
|
+
getSummary(serialId: number, fragmentId: number): Promise<string>;
|
|
501
|
+
getWordsCount(serialId: number, fragmentId: number): Promise<number>;
|
|
502
|
+
readonly path: string;
|
|
503
|
+
}
|
|
504
|
+
interface TextStreamWriteOptions {
|
|
505
|
+
readonly maxWordsCount?: number;
|
|
506
|
+
}
|
|
507
|
+
interface ReadonlySerialFragments {
|
|
508
|
+
getFragment(fragmentId: number): Promise<FragmentRecord>;
|
|
509
|
+
listFragmentIds(): Promise<readonly number[]>;
|
|
510
|
+
readonly serialId: number;
|
|
511
|
+
readonly path: string;
|
|
512
|
+
}
|
|
513
|
+
declare class Fragments implements ReadonlyFragments {
|
|
514
|
+
#private;
|
|
515
|
+
constructor(documentPath: string, writer?: FragmentWriter, fileAccess?: FragmentFileAccess);
|
|
516
|
+
ensureCreated(): Promise<void>;
|
|
517
|
+
getSerial(serialId: number): SerialFragments;
|
|
518
|
+
getSummarySerial(serialId: number): SerialFragments;
|
|
519
|
+
getSentence(sentenceId: SentenceId): Promise<string>;
|
|
520
|
+
getSummary(serialId: number, fragmentId: number): Promise<string>;
|
|
521
|
+
getWordsCount(serialId: number, fragmentId: number): Promise<number>;
|
|
522
|
+
get path(): string;
|
|
523
|
+
}
|
|
524
|
+
declare class SerialFragments implements ReadonlySerialFragments {
|
|
525
|
+
#private;
|
|
526
|
+
constructor(documentPath: string, serialId: number, rootDirectoryName?: string, writer?: FragmentWriter, fileAccess?: FragmentFileAccess);
|
|
527
|
+
createDraft(): Promise<FragmentDraft>;
|
|
528
|
+
getFragment(fragmentId: number): Promise<FragmentRecord>;
|
|
529
|
+
listFragmentIds(): Promise<readonly number[]>;
|
|
530
|
+
writeTextStream(text: string, options?: TextStreamWriteOptions): Promise<void>;
|
|
531
|
+
get serialId(): number;
|
|
532
|
+
get path(): string;
|
|
533
|
+
}
|
|
534
|
+
declare class FragmentDraft {
|
|
535
|
+
#private;
|
|
536
|
+
constructor(serialId: number, fragmentId: number, startSentenceIndex: number, callbacks: {
|
|
537
|
+
readonly discard: () => void;
|
|
538
|
+
readonly finalize: (fragmentId: number, startSentenceIndex: number, summary: string, sentences: readonly SentenceRecord[]) => Promise<FragmentRecord | undefined>;
|
|
539
|
+
});
|
|
540
|
+
addSentence(text: string, wordsCount: number): SentenceId;
|
|
541
|
+
commit(): Promise<FragmentRecord | undefined>;
|
|
542
|
+
discard(): void;
|
|
543
|
+
setSummary(summary: string): void;
|
|
544
|
+
get fragmentId(): number;
|
|
545
|
+
}
|
|
243
546
|
|
|
244
547
|
declare const bookMetaSchema: z.ZodObject<{
|
|
245
548
|
version: z.ZodLiteral<1>;
|
|
@@ -259,6 +562,7 @@ declare const bookMetaSchema: z.ZodObject<{
|
|
|
259
562
|
}, z.core.$strip>;
|
|
260
563
|
type BookMeta = z.infer<typeof bookMetaSchema>;
|
|
261
564
|
|
|
565
|
+
declare const TOC_FILE_VERSION = 1;
|
|
262
566
|
interface TocItem {
|
|
263
567
|
readonly title?: string | null | undefined;
|
|
264
568
|
readonly serialId?: number | undefined;
|
|
@@ -345,7 +649,153 @@ interface ReadonlyFragmentGroupStore {
|
|
|
345
649
|
interface ReadonlyObjectMetadataStore {
|
|
346
650
|
getMap(objectPath: string): Promise<Readonly<Record<string, unknown>>>;
|
|
347
651
|
}
|
|
652
|
+
declare class ObjectMetadataStore implements ReadonlyObjectMetadataStore {
|
|
653
|
+
#private;
|
|
654
|
+
constructor(database: Database);
|
|
655
|
+
getMap(objectPath: string): Promise<Readonly<Record<string, unknown>>>;
|
|
656
|
+
replaceMap(target: ObjectMetadataTarget, map: Readonly<Record<string, unknown>>): Promise<void>;
|
|
657
|
+
put(target: ObjectMetadataTarget, key: string, value: unknown): Promise<void>;
|
|
658
|
+
deleteKey(objectPath: string, key: string): Promise<void>;
|
|
659
|
+
clear(objectPath: string): Promise<void>;
|
|
660
|
+
deleteChapterSubtree(chapterId: number): Promise<void>;
|
|
661
|
+
deleteDeletedChunks(): Promise<void>;
|
|
662
|
+
deleteDeletedEntitiesAndTriples(): Promise<void>;
|
|
663
|
+
}
|
|
664
|
+
declare class SerialStore implements ReadonlySerialStore {
|
|
665
|
+
#private;
|
|
666
|
+
constructor(database: Database);
|
|
667
|
+
create(): Promise<number>;
|
|
668
|
+
createWithId(serialId: number): Promise<void>;
|
|
669
|
+
ensure(serialId: number): Promise<void>;
|
|
670
|
+
getById(serialId: number): Promise<SerialRecord | undefined>;
|
|
671
|
+
getRevision(serialId: number): Promise<number>;
|
|
672
|
+
getRevisions(serialIds: readonly number[]): Promise<ReadonlyMap<number, number>>;
|
|
673
|
+
bumpRevision(serialId: number): Promise<void>;
|
|
674
|
+
bumpChaptersRevision(): Promise<void>;
|
|
675
|
+
getChaptersRevision(): Promise<number>;
|
|
676
|
+
getMaxId(): Promise<number>;
|
|
677
|
+
setTopologyReady(serialId: number, ready?: boolean, parameterHash?: string): Promise<void>;
|
|
678
|
+
setKnowledgeGraphReady(serialId: number, ready?: boolean, parameterHash?: string): Promise<void>;
|
|
679
|
+
listIds(): Promise<number[]>;
|
|
680
|
+
listDocumentOrders(): Promise<ReadonlyMap<number, number>>;
|
|
681
|
+
setDocumentOrders(entries: readonly {
|
|
682
|
+
readonly documentOrder: number;
|
|
683
|
+
readonly serialId: number;
|
|
684
|
+
}[]): Promise<void>;
|
|
685
|
+
}
|
|
686
|
+
declare class GraphBuildParameterStore implements ReadonlyGraphBuildParameterStore {
|
|
687
|
+
#private;
|
|
688
|
+
constructor(database: Database);
|
|
689
|
+
save(input: {
|
|
690
|
+
readonly language?: string;
|
|
691
|
+
readonly prompt: string;
|
|
692
|
+
}): Promise<GraphBuildParameterRecord>;
|
|
693
|
+
getByHash(hash: string): Promise<GraphBuildParameterRecord | undefined>;
|
|
694
|
+
deleteUnreferenced(): Promise<void>;
|
|
695
|
+
}
|
|
696
|
+
declare class ChunkStore implements ReadonlyChunkStore {
|
|
697
|
+
#private;
|
|
698
|
+
constructor(database: Database);
|
|
699
|
+
countAll(): Promise<number>;
|
|
700
|
+
create(record: CreateChunkRecord): Promise<ChunkRecord>;
|
|
701
|
+
save(record: ChunkRecord): Promise<void>;
|
|
702
|
+
getById(chunkId: number): Promise<ChunkRecord | undefined>;
|
|
703
|
+
listAll(): Promise<ChunkRecord[]>;
|
|
704
|
+
listBySentenceStartIndexes(serialId: number, sentenceStartIndexes: readonly number[]): Promise<ChunkRecord[]>;
|
|
705
|
+
listBySentenceRange(serialId: number, startSentenceIndex: number, endSentenceIndex: number): Promise<ChunkRecord[]>;
|
|
706
|
+
listBySerial(serialId: number): Promise<ChunkRecord[]>;
|
|
707
|
+
getMaxId(): Promise<number>;
|
|
708
|
+
listFragmentPairs(): Promise<ReadonlyArray<readonly [number, number]>>;
|
|
709
|
+
}
|
|
710
|
+
declare class ReadingEdgeStore implements ReadonlyReadingEdgeStore {
|
|
711
|
+
#private;
|
|
712
|
+
constructor(database: Database);
|
|
713
|
+
countAll(): Promise<number>;
|
|
714
|
+
save(record: ReadingEdgeRecord): Promise<void>;
|
|
715
|
+
listAll(): Promise<ReadingEdgeRecord[]>;
|
|
716
|
+
listBySerial(serialId: number): Promise<ReadingEdgeRecord[]>;
|
|
717
|
+
listIncoming(chunkId: number): Promise<ReadingEdgeRecord[]>;
|
|
718
|
+
listOutgoing(chunkId: number): Promise<ReadingEdgeRecord[]>;
|
|
719
|
+
}
|
|
720
|
+
declare class SnakeStore implements ReadonlySnakeStore {
|
|
721
|
+
#private;
|
|
722
|
+
constructor(database: Database);
|
|
723
|
+
create(record: CreateSnakeRecord): Promise<number>;
|
|
724
|
+
getById(snakeId: number): Promise<SnakeRecord | undefined>;
|
|
725
|
+
listIdsByGroup(serialId: number, groupId: number): Promise<number[]>;
|
|
726
|
+
listBySerial(serialId: number): Promise<SnakeRecord[]>;
|
|
727
|
+
}
|
|
728
|
+
declare class MentionStore implements ReadonlyMentionStore {
|
|
729
|
+
#private;
|
|
730
|
+
constructor(database: Database);
|
|
731
|
+
save(record: MentionRecord): Promise<void>;
|
|
732
|
+
saveMany(records: readonly MentionRecord[]): Promise<void>;
|
|
733
|
+
getById(mentionId: string): Promise<MentionRecord | undefined>;
|
|
734
|
+
listAll(): Promise<MentionRecord[]>;
|
|
735
|
+
listByQid(qid: string): Promise<MentionRecord[]>;
|
|
736
|
+
listBySurfaces(surfaces: readonly string[]): Promise<MentionRecord[]>;
|
|
737
|
+
listBySurfaceTerms(terms: readonly string[]): Promise<MentionRecord[]>;
|
|
738
|
+
listByChapter(chapterId: number): Promise<MentionRecord[]>;
|
|
739
|
+
deleteByChapter(chapterId: number): Promise<void>;
|
|
740
|
+
}
|
|
741
|
+
declare class MentionLinkStore implements ReadonlyMentionLinkStore {
|
|
742
|
+
#private;
|
|
743
|
+
constructor(database: Database);
|
|
744
|
+
save(record: MentionLinkRecord): Promise<void>;
|
|
745
|
+
saveMany(records: readonly MentionLinkRecord[]): Promise<void>;
|
|
746
|
+
getById(linkId: string): Promise<MentionLinkRecord | undefined>;
|
|
747
|
+
listByTriple(input: {
|
|
748
|
+
readonly objectQid: string;
|
|
749
|
+
readonly predicate: string;
|
|
750
|
+
readonly subjectQid: string;
|
|
751
|
+
}): Promise<MentionLinkRecord[]>;
|
|
752
|
+
listByChapter(chapterId: number): Promise<MentionLinkRecord[]>;
|
|
753
|
+
deleteByChapter(chapterId: number): Promise<void>;
|
|
754
|
+
}
|
|
755
|
+
declare class SnakeChunkStore implements ReadonlySnakeChunkStore {
|
|
756
|
+
#private;
|
|
757
|
+
constructor(database: Database);
|
|
758
|
+
save(record: SnakeChunkRecord): Promise<void>;
|
|
759
|
+
listChunkIds(snakeId: number): Promise<number[]>;
|
|
760
|
+
listBySnake(snakeId: number): Promise<SnakeChunkRecord[]>;
|
|
761
|
+
}
|
|
762
|
+
declare class SnakeEdgeStore implements ReadonlySnakeEdgeStore {
|
|
763
|
+
#private;
|
|
764
|
+
constructor(database: Database);
|
|
765
|
+
save(record: SnakeEdgeRecord): Promise<void>;
|
|
766
|
+
listIncoming(snakeId: number): Promise<SnakeEdgeRecord[]>;
|
|
767
|
+
listOutgoing(snakeId: number): Promise<SnakeEdgeRecord[]>;
|
|
768
|
+
listWithin(snakeIds: readonly number[]): Promise<SnakeEdgeRecord[]>;
|
|
769
|
+
listBySerial(serialId: number): Promise<SnakeEdgeRecord[]>;
|
|
770
|
+
}
|
|
771
|
+
declare class FragmentGroupStore implements ReadonlyFragmentGroupStore {
|
|
772
|
+
#private;
|
|
773
|
+
constructor(database: Database);
|
|
774
|
+
save(record: SentenceGroupRecord): Promise<void>;
|
|
775
|
+
saveMany(records: readonly SentenceGroupRecord[]): Promise<void>;
|
|
776
|
+
listBySerial(serialId: number): Promise<SentenceGroupRecord[]>;
|
|
777
|
+
listSerialIds(): Promise<number[]>;
|
|
778
|
+
listGroupIdsForSerial(serialId: number): Promise<number[]>;
|
|
779
|
+
}
|
|
348
780
|
|
|
781
|
+
interface DocumentFileStore {
|
|
782
|
+
close(): Promise<void>;
|
|
783
|
+
deleteFile(path: string): Promise<void>;
|
|
784
|
+
deleteTree(path: string): Promise<void>;
|
|
785
|
+
ensureDirectory(path: string): Promise<void>;
|
|
786
|
+
initializeDatabaseSchema(): boolean;
|
|
787
|
+
markDatabaseDirty?(): void;
|
|
788
|
+
markSearchIndexDatabaseDirty?(): void;
|
|
789
|
+
openDatabaseReadonly(): boolean;
|
|
790
|
+
listFileContents?(path: string): Promise<ReadonlyMap<string, Uint8Array>>;
|
|
791
|
+
listFiles(path: string): Promise<readonly string[]>;
|
|
792
|
+
readFile(path: string): Promise<Uint8Array | undefined>;
|
|
793
|
+
resolveDatabasePath(documentPath: string): Promise<string>;
|
|
794
|
+
resolveSearchIndexDatabasePath?(documentPath: string): Promise<string>;
|
|
795
|
+
writeFile(path: string, content: string | Uint8Array, options: {
|
|
796
|
+
readonly overwrite?: boolean;
|
|
797
|
+
}): Promise<void>;
|
|
798
|
+
}
|
|
349
799
|
interface ReadonlyDocument {
|
|
350
800
|
readonly chunks: ReadonlyChunkStore;
|
|
351
801
|
readonly fragmentGroups: ReadonlyFragmentGroupStore;
|
|
@@ -370,6 +820,107 @@ interface ReadonlyDocument {
|
|
|
370
820
|
readToc(): Promise<TocFile | undefined>;
|
|
371
821
|
release(): Promise<void>;
|
|
372
822
|
}
|
|
823
|
+
interface DocumentContext {
|
|
824
|
+
complete(): void;
|
|
825
|
+
dispose(): Promise<void>;
|
|
826
|
+
ownSerial(serialId: number): void;
|
|
827
|
+
run<T>(operation: () => Promise<T> | T): Promise<T>;
|
|
828
|
+
}
|
|
829
|
+
interface Document extends ReadonlyDocument {
|
|
830
|
+
readonly chunks: ChunkStore;
|
|
831
|
+
readonly fragmentGroups: FragmentGroupStore;
|
|
832
|
+
readonly graphBuildParameters: GraphBuildParameterStore;
|
|
833
|
+
readonly readingEdges: ReadingEdgeStore;
|
|
834
|
+
readonly mentionLinks: MentionLinkStore;
|
|
835
|
+
readonly mentions: MentionStore;
|
|
836
|
+
readonly metadata: ObjectMetadataStore;
|
|
837
|
+
readonly serials: SerialStore;
|
|
838
|
+
readonly snakeChunks: SnakeChunkStore;
|
|
839
|
+
readonly snakeEdges: SnakeEdgeStore;
|
|
840
|
+
readonly snakes: SnakeStore;
|
|
841
|
+
createContext(): DocumentContext;
|
|
842
|
+
getSerialFragments(serialId: number): SerialTextStream;
|
|
843
|
+
getSummaryFragments(serialId: number): SerialTextStream;
|
|
844
|
+
createSerial(): Promise<number>;
|
|
845
|
+
clearSerialGraph(serialId: number): Promise<void>;
|
|
846
|
+
clearSerialSource(serialId: number): Promise<void>;
|
|
847
|
+
deleteSerial(serialId: number): Promise<void>;
|
|
848
|
+
deleteSearchIndexDatabase(): Promise<void>;
|
|
849
|
+
deleteSummary(serialId: number): Promise<void>;
|
|
850
|
+
flush(): Promise<void>;
|
|
851
|
+
openSession<T>(operation: (document: Document) => Promise<T> | T): Promise<T>;
|
|
852
|
+
peekNextSerialId(): Promise<number>;
|
|
853
|
+
replaceBookMeta(meta: BookMeta): Promise<void>;
|
|
854
|
+
replaceToc(toc: TocFile): Promise<void>;
|
|
855
|
+
writeBookMeta(meta: BookMeta): Promise<void>;
|
|
856
|
+
writeCover(cover: SourceAsset): Promise<void>;
|
|
857
|
+
writeSummary(serialId: number, summary: string): Promise<void>;
|
|
858
|
+
writeToc(toc: TocFile): Promise<void>;
|
|
859
|
+
writeSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
|
|
860
|
+
}
|
|
861
|
+
declare class DirectoryDocument implements Document {
|
|
862
|
+
#private;
|
|
863
|
+
readonly chunks: ChunkStore;
|
|
864
|
+
readonly fragmentGroups: FragmentGroupStore;
|
|
865
|
+
readonly graphBuildParameters: GraphBuildParameterStore;
|
|
866
|
+
readonly readingEdges: ReadingEdgeStore;
|
|
867
|
+
readonly mentionLinks: MentionLinkStore;
|
|
868
|
+
readonly mentions: MentionStore;
|
|
869
|
+
readonly metadata: ObjectMetadataStore;
|
|
870
|
+
readonly path: string;
|
|
871
|
+
readonly serials: SerialStore;
|
|
872
|
+
readonly snakeChunks: SnakeChunkStore;
|
|
873
|
+
readonly snakeEdges: SnakeEdgeStore;
|
|
874
|
+
readonly snakes: SnakeStore;
|
|
875
|
+
constructor(database: Database, textStreams: TextStreams, path: string, fileStore?: DocumentFileStore);
|
|
876
|
+
static open(documentPath: string, options?: {
|
|
877
|
+
readonly fileStore?: DocumentFileStore;
|
|
878
|
+
}): Promise<DirectoryDocument>;
|
|
879
|
+
static openSession<T>(documentPath: string, operation: (document: DirectoryDocument) => Promise<T> | T): Promise<T>;
|
|
880
|
+
getSerialFragments(serialId: number): SerialTextStream;
|
|
881
|
+
getSummaryFragments(serialId: number): SerialTextStream;
|
|
882
|
+
createContext(): DocumentContext;
|
|
883
|
+
createSerial(): Promise<number>;
|
|
884
|
+
clearSerialGraph(serialId: number): Promise<void>;
|
|
885
|
+
clearSerialSource(serialId: number): Promise<void>;
|
|
886
|
+
deleteSerial(serialId: number): Promise<void>;
|
|
887
|
+
deleteSummary(serialId: number): Promise<void>;
|
|
888
|
+
getSentence(sentenceId: SentenceId): Promise<string>;
|
|
889
|
+
openSession<T>(operation: (document: Document) => Promise<T> | T): Promise<T>;
|
|
890
|
+
readDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
|
|
891
|
+
readSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
|
|
892
|
+
writeSearchIndexDatabase<T>(operation: (database: Database) => Promise<T> | T): Promise<T>;
|
|
893
|
+
deleteSearchIndexDatabase(): Promise<void>;
|
|
894
|
+
peekNextSerialId(): Promise<number>;
|
|
895
|
+
readBookMeta(): Promise<BookMeta | undefined>;
|
|
896
|
+
readCover(): Promise<SourceAsset | undefined>;
|
|
897
|
+
readSummary(serialId: number): Promise<string | undefined>;
|
|
898
|
+
readToc(): Promise<TocFile | undefined>;
|
|
899
|
+
writeBookMeta(meta: BookMeta): Promise<void>;
|
|
900
|
+
replaceBookMeta(meta: BookMeta): Promise<void>;
|
|
901
|
+
writeCover(cover: SourceAsset): Promise<void>;
|
|
902
|
+
writeSummary(serialId: number, summary: string): Promise<void>;
|
|
903
|
+
writeToc(toc: TocFile): Promise<void>;
|
|
904
|
+
replaceToc(toc: TocFile): Promise<void>;
|
|
905
|
+
flush(): Promise<void>;
|
|
906
|
+
release(): Promise<void>;
|
|
907
|
+
close(): Promise<void>;
|
|
908
|
+
runWithContext<T>(context: DirectoryDocumentContext, operation: () => Promise<T> | T): Promise<T>;
|
|
909
|
+
rollbackContext(context: DirectoryDocumentContext): Promise<void>;
|
|
910
|
+
}
|
|
911
|
+
declare class DirectoryDocumentContext implements DocumentContext {
|
|
912
|
+
#private;
|
|
913
|
+
constructor(document: DirectoryDocument);
|
|
914
|
+
complete(): void;
|
|
915
|
+
dispose(): Promise<void>;
|
|
916
|
+
ownSerial(serialId: number): void;
|
|
917
|
+
run<T>(operation: () => Promise<T> | T): Promise<T>;
|
|
918
|
+
listCreatedFilePaths(): readonly string[];
|
|
919
|
+
listOwnedSerialIds(): readonly number[];
|
|
920
|
+
registerCreatedFile(path: string): void;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
declare const SCHEMA_SQL = "\n CREATE TABLE IF NOT EXISTS serials (\n id INTEGER PRIMARY KEY,\n document_order INTEGER NOT NULL DEFAULT 0\n );\n\n CREATE TABLE IF NOT EXISTS serial_states (\n serial_id INTEGER PRIMARY KEY,\n revision INTEGER NOT NULL DEFAULT 0,\n topology_ready INTEGER NOT NULL DEFAULT 0,\n topology_parameter_hash TEXT,\n knowledge_graph_ready INTEGER NOT NULL DEFAULT 0,\n knowledge_graph_parameter_hash TEXT,\n FOREIGN KEY (serial_id) REFERENCES serials(id)\n );\n\n CREATE TABLE IF NOT EXISTS archive_revisions (\n key TEXT PRIMARY KEY,\n value INTEGER NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS archive_index_settings (\n id INTEGER PRIMARY KEY CHECK (id = 1),\n fts_embedded INTEGER NOT NULL DEFAULT 0\n );\n\n CREATE TABLE IF NOT EXISTS graph_build_parameters (\n hash TEXT PRIMARY KEY,\n prompt TEXT NOT NULL,\n language TEXT,\n created_at TEXT NOT NULL\n );\n\n CREATE TABLE IF NOT EXISTS chunks (\n id INTEGER PRIMARY KEY,\n generation INTEGER NOT NULL,\n serial_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n label TEXT NOT NULL,\n content TEXT NOT NULL,\n retention TEXT,\n importance TEXT,\n wordsCount INTEGER NOT NULL DEFAULT 0,\n weight REAL NOT NULL DEFAULT 0.0\n );\n\n CREATE INDEX IF NOT EXISTS idx_chunks_sentence\n ON chunks(serial_id, sentence_index);\n\n CREATE INDEX IF NOT EXISTS idx_chunks_serial_id\n ON chunks(serial_id, id);\n\n CREATE TABLE IF NOT EXISTS chunk_sentences (\n chunk_id INTEGER NOT NULL,\n serial_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n FOREIGN KEY (chunk_id) REFERENCES chunks(id),\n PRIMARY KEY (chunk_id, serial_id, sentence_index)\n );\n\n CREATE TABLE IF NOT EXISTS reading_edges (\n from_id INTEGER NOT NULL,\n to_id INTEGER NOT NULL,\n strength TEXT,\n weight REAL NOT NULL DEFAULT 0.1,\n PRIMARY KEY (from_id, to_id),\n FOREIGN KEY (from_id) REFERENCES chunks(id),\n FOREIGN KEY (to_id) REFERENCES chunks(id)\n );\n\n CREATE TABLE IF NOT EXISTS snakes (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n serial_id INTEGER NOT NULL,\n group_id INTEGER NOT NULL,\n local_snake_id INTEGER NOT NULL,\n size INTEGER NOT NULL,\n first_label TEXT NOT NULL,\n last_label TEXT NOT NULL,\n wordsCount INTEGER NOT NULL DEFAULT 0,\n weight REAL NOT NULL DEFAULT 0.0,\n UNIQUE(serial_id, group_id, local_snake_id)\n );\n\n CREATE TABLE IF NOT EXISTS snake_chunks (\n snake_id INTEGER NOT NULL,\n chunk_id INTEGER NOT NULL,\n position INTEGER NOT NULL,\n FOREIGN KEY (snake_id) REFERENCES snakes(id),\n FOREIGN KEY (chunk_id) REFERENCES chunks(id),\n PRIMARY KEY (snake_id, chunk_id)\n );\n\n CREATE TABLE IF NOT EXISTS snake_edges (\n from_snake_id INTEGER NOT NULL,\n to_snake_id INTEGER NOT NULL,\n weight REAL NOT NULL DEFAULT 0.1,\n PRIMARY KEY (from_snake_id, to_snake_id),\n FOREIGN KEY (from_snake_id) REFERENCES snakes(id),\n FOREIGN KEY (to_snake_id) REFERENCES snakes(id)\n );\n\n CREATE TABLE IF NOT EXISTS sentence_groups (\n serial_id INTEGER NOT NULL,\n group_id INTEGER NOT NULL,\n start_sentence_index INTEGER NOT NULL,\n end_sentence_index INTEGER NOT NULL,\n PRIMARY KEY (serial_id, group_id, start_sentence_index, end_sentence_index)\n );\n\n CREATE TABLE IF NOT EXISTS mentions (\n id TEXT PRIMARY KEY,\n chapter_id INTEGER NOT NULL,\n sentence_index INTEGER,\n range_start INTEGER NOT NULL,\n range_end INTEGER NOT NULL,\n surface TEXT NOT NULL,\n qid TEXT NOT NULL,\n confidence REAL,\n note TEXT,\n FOREIGN KEY (chapter_id) REFERENCES serials(id)\n );\n\n CREATE INDEX IF NOT EXISTS idx_mentions_chapter\n ON mentions(chapter_id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_chapter_position\n ON mentions(chapter_id, sentence_index, range_start, range_end, id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_chapter_qid\n ON mentions(chapter_id, qid);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_qid\n ON mentions(qid);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_qid_position\n ON mentions(qid, chapter_id, sentence_index, range_start, range_end, id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_surface\n ON mentions(surface);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_surface_position\n ON mentions(surface, chapter_id, sentence_index, range_start, range_end, id);\n\n CREATE INDEX IF NOT EXISTS idx_mentions_sentence\n ON mentions(chapter_id, sentence_index);\n\n CREATE TABLE IF NOT EXISTS mention_links (\n id TEXT PRIMARY KEY,\n source_mention_id TEXT NOT NULL,\n target_mention_id TEXT NOT NULL,\n predicate TEXT NOT NULL,\n confidence REAL,\n note TEXT,\n FOREIGN KEY (source_mention_id) REFERENCES mentions(id),\n FOREIGN KEY (target_mention_id) REFERENCES mentions(id)\n );\n\n CREATE TABLE IF NOT EXISTS mention_link_evidence_sentences (\n link_id TEXT NOT NULL,\n chapter_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n FOREIGN KEY (link_id) REFERENCES mention_links(id),\n PRIMARY KEY (link_id, chapter_id, sentence_index)\n );\n\n CREATE INDEX IF NOT EXISTS idx_mention_link_evidence_sentences_sentence\n ON mention_link_evidence_sentences(chapter_id, sentence_index);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_source\n ON mention_links(source_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_target\n ON mention_links(target_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_predicate\n ON mention_links(predicate);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_predicate_source_target\n ON mention_links(predicate, source_mention_id, target_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_predicate_target_source\n ON mention_links(predicate, target_mention_id, source_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_source_predicate_target\n ON mention_links(source_mention_id, predicate, target_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_target_predicate_source\n ON mention_links(target_mention_id, predicate, source_mention_id);\n\n CREATE INDEX IF NOT EXISTS idx_mention_links_source_target_predicate\n ON mention_links(source_mention_id, target_mention_id, predicate);\n\n CREATE INDEX IF NOT EXISTS idx_reading_edges_target\n ON reading_edges(to_id, from_id);\n\n CREATE INDEX IF NOT EXISTS idx_snake_edges_target\n ON snake_edges(to_snake_id, from_snake_id);\n\n CREATE VIEW IF NOT EXISTS chapter_entities AS\n SELECT\n chapter_id,\n qid,\n COUNT(*) AS mention_count\n FROM mentions\n GROUP BY chapter_id, qid;\n\n CREATE VIEW IF NOT EXISTS book_entities AS\n SELECT\n qid,\n SUM(mention_count) AS mention_count\n FROM chapter_entities\n GROUP BY qid;\n\n CREATE VIEW IF NOT EXISTS chapter_entity_relations AS\n SELECT\n source_mentions.chapter_id AS chapter_id,\n source_mentions.qid AS subject_qid,\n mention_links.predicate AS predicate,\n target_mentions.qid AS object_qid,\n COUNT(*) AS evidence_count\n FROM mention_links\n JOIN mentions AS source_mentions\n ON source_mentions.id = mention_links.source_mention_id\n JOIN mentions AS target_mentions\n ON target_mentions.id = mention_links.target_mention_id\n WHERE source_mentions.chapter_id = target_mentions.chapter_id\n GROUP BY\n source_mentions.chapter_id,\n source_mentions.qid,\n mention_links.predicate,\n target_mentions.qid;\n\n CREATE VIEW IF NOT EXISTS book_entity_relations AS\n SELECT\n subject_qid,\n predicate,\n object_qid,\n SUM(evidence_count) AS evidence_count\n FROM chapter_entity_relations\n GROUP BY subject_qid, predicate, object_qid;\n\n CREATE TABLE IF NOT EXISTS text_sentence_records (\n id INTEGER PRIMARY KEY,\n kind INTEGER NOT NULL,\n chapter_id INTEGER NOT NULL,\n sentence_index INTEGER NOT NULL,\n words_count INTEGER NOT NULL DEFAULT 0,\n byte_offset INTEGER NOT NULL DEFAULT 0,\n byte_length INTEGER NOT NULL DEFAULT 0,\n UNIQUE(kind, chapter_id, sentence_index)\n );\n\n CREATE INDEX IF NOT EXISTS idx_text_sentence_records_chapter\n ON text_sentence_records(kind, chapter_id, sentence_index);\n\n CREATE TABLE IF NOT EXISTS object_metadata (\n id INTEGER PRIMARY KEY,\n object_kind INTEGER NOT NULL,\n object_path TEXT NOT NULL,\n key TEXT NOT NULL,\n value_json TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n chapter_id INTEGER,\n chunk_id INTEGER,\n entity_qid TEXT,\n triple_subject_qid TEXT,\n triple_predicate TEXT,\n triple_object_qid TEXT,\n UNIQUE(object_path, key)\n );\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_object\n ON object_metadata(object_path);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_chapter\n ON object_metadata(chapter_id);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_chunk\n ON object_metadata(chunk_id);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_entity\n ON object_metadata(entity_qid);\n\n CREATE INDEX IF NOT EXISTS idx_object_metadata_triple\n ON object_metadata(\n triple_subject_qid,\n triple_predicate,\n triple_object_qid\n );\n";
|
|
373
924
|
|
|
374
925
|
declare const EVIDENCE_SELECTION_PROMPT_FRAGMENT: string;
|
|
375
926
|
declare const EVIDENCE_SELECTION_JSON_SHAPE: readonly [{
|
|
@@ -458,11 +1009,24 @@ declare function resolveEvidenceSelectionList(input: {
|
|
|
458
1009
|
];
|
|
459
1010
|
declare function rankEvidenceQuote(quote: string, sentences: readonly EvidenceSelectionSentence[]): EvidenceSelectionCandidate[];
|
|
460
1011
|
|
|
1012
|
+
interface GcContext {
|
|
1013
|
+
readonly force: boolean;
|
|
1014
|
+
readonly now: number;
|
|
1015
|
+
readonly stateDirectoryPath: string;
|
|
1016
|
+
readonly dryRun: boolean;
|
|
1017
|
+
}
|
|
1018
|
+
interface GcJobResult {
|
|
1019
|
+
readonly scanned: number;
|
|
1020
|
+
readonly removed: number;
|
|
1021
|
+
readonly freedBytes: number;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
461
1024
|
interface WikipageResolverOptions {
|
|
462
1025
|
readonly cacheDatabasePath?: string;
|
|
463
1026
|
readonly concurrency?: number;
|
|
464
1027
|
readonly fetch?: typeof fetch;
|
|
465
1028
|
readonly language?: string;
|
|
1029
|
+
readonly logDirPath?: string;
|
|
466
1030
|
readonly maxBatchSize?: number;
|
|
467
1031
|
readonly minRequestIntervalMs?: number;
|
|
468
1032
|
readonly normalizer?: DisambiguationProfileNormalizer;
|
|
@@ -564,6 +1128,10 @@ declare class WikipageCache {
|
|
|
564
1128
|
}
|
|
565
1129
|
|
|
566
1130
|
type GuaranteedRequest = (messages: readonly LLMessage[], index: number, maxRetries: number) => Promise<string | undefined>;
|
|
1131
|
+
type GuaranteedLazyRequest = <T>(operation: (request: GuaranteedRequest) => Promise<T>) => Promise<T>;
|
|
1132
|
+
type GuaranteedRequestController = GuaranteedRequest & {
|
|
1133
|
+
lazy?: GuaranteedLazyRequest;
|
|
1134
|
+
};
|
|
567
1135
|
|
|
568
1136
|
interface CreateDisambiguationProfileNormalizerOptions {
|
|
569
1137
|
readonly maxMeanings?: number;
|
|
@@ -584,12 +1152,28 @@ declare class RateLimiter {
|
|
|
584
1152
|
}
|
|
585
1153
|
declare function parseRetryAfterMs(value: string | null): number | undefined;
|
|
586
1154
|
|
|
1155
|
+
interface WikipageFetchLog {
|
|
1156
|
+
readonly filePath: string | undefined;
|
|
1157
|
+
append(entry: WikipageFetchLogEntry): Promise<void>;
|
|
1158
|
+
warnFailed(): void;
|
|
1159
|
+
}
|
|
1160
|
+
interface WikipageFetchLogEntry {
|
|
1161
|
+
readonly attempt: number;
|
|
1162
|
+
readonly durationMs: number;
|
|
1163
|
+
readonly error?: unknown;
|
|
1164
|
+
readonly response?: Response;
|
|
1165
|
+
readonly responseText?: string;
|
|
1166
|
+
readonly startedAt: number;
|
|
1167
|
+
readonly url: URL;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
587
1170
|
type SupportedWiki = "enwiki" | "zhwiki";
|
|
588
1171
|
interface WikimediaClientOptions {
|
|
589
1172
|
readonly concurrency: number;
|
|
590
1173
|
readonly fetch?: typeof fetch;
|
|
591
1174
|
readonly language: string;
|
|
592
1175
|
readonly minRequestIntervalMs: number;
|
|
1176
|
+
readonly requestLog: WikipageFetchLog;
|
|
593
1177
|
readonly retryBaseDelayMs: number;
|
|
594
1178
|
readonly retryTimes: number;
|
|
595
1179
|
readonly userAgent?: string;
|
|
@@ -651,6 +1235,11 @@ interface WikimatchCandidate {
|
|
|
651
1235
|
readonly range: WikimatchTextRange;
|
|
652
1236
|
readonly surface: string;
|
|
653
1237
|
}
|
|
1238
|
+
interface WikimatchSentence {
|
|
1239
|
+
readonly id?: string;
|
|
1240
|
+
readonly range: WikimatchTextRange;
|
|
1241
|
+
readonly text: string;
|
|
1242
|
+
}
|
|
654
1243
|
interface WikimatchQidOption {
|
|
655
1244
|
readonly description?: string;
|
|
656
1245
|
readonly disambiguation?: DisambiguationExpansion;
|
|
@@ -668,6 +1257,11 @@ interface WikimatchWindow {
|
|
|
668
1257
|
readonly groups: readonly WikimatchConflictGroup[];
|
|
669
1258
|
readonly text: string;
|
|
670
1259
|
}
|
|
1260
|
+
interface WikimatchSurface {
|
|
1261
|
+
readonly id: string;
|
|
1262
|
+
readonly count: number;
|
|
1263
|
+
readonly text: string;
|
|
1264
|
+
}
|
|
671
1265
|
interface WikimatchConflictGroup {
|
|
672
1266
|
readonly candidateIds: readonly string[];
|
|
673
1267
|
readonly id: string;
|
|
@@ -679,6 +1273,60 @@ interface BuildWikimatchWindowsOptions {
|
|
|
679
1273
|
readonly optionBudget: number;
|
|
680
1274
|
readonly text: string;
|
|
681
1275
|
}
|
|
1276
|
+
interface NarrowWikimatchCandidateOptionsInput {
|
|
1277
|
+
readonly candidate: WikimatchCandidate;
|
|
1278
|
+
readonly policyPrompt: string;
|
|
1279
|
+
readonly text: string;
|
|
1280
|
+
}
|
|
1281
|
+
interface WikimatchCandidateOptionNarrowingResult {
|
|
1282
|
+
readonly candidate: WikimatchCandidate;
|
|
1283
|
+
readonly fallback?: WikimatchCandidateOptionNarrowingFallback;
|
|
1284
|
+
}
|
|
1285
|
+
interface WikimatchCandidateOptionNarrowingFallback {
|
|
1286
|
+
readonly issues: readonly string[];
|
|
1287
|
+
readonly reason: "guaranteed_json_failed";
|
|
1288
|
+
}
|
|
1289
|
+
interface WikimatchCandidateOptionNarrowingResponse {
|
|
1290
|
+
readonly qids: readonly WikimatchCandidateOptionNarrowingItemOutput[];
|
|
1291
|
+
}
|
|
1292
|
+
interface WikimatchCandidateOptionNarrowingItemOutput {
|
|
1293
|
+
readonly decision: "keep" | "reject";
|
|
1294
|
+
readonly qid: string;
|
|
1295
|
+
}
|
|
1296
|
+
interface BuildWikimatchSurfaceProtectionInputOptions {
|
|
1297
|
+
readonly candidates: readonly WikimatchCandidate[];
|
|
1298
|
+
readonly percentile: number;
|
|
1299
|
+
readonly text: string;
|
|
1300
|
+
}
|
|
1301
|
+
interface WikimatchSurfaceProtectionInput {
|
|
1302
|
+
readonly policyPrompt: string;
|
|
1303
|
+
readonly suspiciousSurfaces: readonly WikimatchSurface[];
|
|
1304
|
+
}
|
|
1305
|
+
interface WikimatchSurfaceProtectionBuildResult {
|
|
1306
|
+
readonly candidates: readonly WikimatchCandidate[];
|
|
1307
|
+
readonly suppressedCandidates: readonly WikimatchCandidate[];
|
|
1308
|
+
readonly suspiciousSurfaces: readonly WikimatchSurface[];
|
|
1309
|
+
}
|
|
1310
|
+
interface WikimatchSurfaceProtectionResult {
|
|
1311
|
+
readonly fallback?: WikimatchSurfaceProtectionFallback;
|
|
1312
|
+
readonly protectedSurfaces: readonly WikimatchProtectedSurface[];
|
|
1313
|
+
}
|
|
1314
|
+
interface WikimatchProtectedSurface {
|
|
1315
|
+
readonly note?: string;
|
|
1316
|
+
readonly surfaceId: string;
|
|
1317
|
+
readonly text: string;
|
|
1318
|
+
}
|
|
1319
|
+
interface WikimatchSurfaceProtectionFallback {
|
|
1320
|
+
readonly issues: readonly string[];
|
|
1321
|
+
readonly reason: "guaranteed_json_failed";
|
|
1322
|
+
}
|
|
1323
|
+
interface WikimatchProtectedSurfaceOutput {
|
|
1324
|
+
readonly note?: string;
|
|
1325
|
+
readonly surfaceId: string;
|
|
1326
|
+
}
|
|
1327
|
+
interface WikimatchSurfaceProtectionResponse {
|
|
1328
|
+
readonly protectedSurfaces: readonly WikimatchProtectedSurfaceOutput[];
|
|
1329
|
+
}
|
|
682
1330
|
type WikimatchPolicyDecision = "continue" | "never_recall" | "recall" | "skip_this_time";
|
|
683
1331
|
interface WikimatchPolicyJudgeInput {
|
|
684
1332
|
readonly candidates: readonly WikimatchCandidate[];
|
|
@@ -735,10 +1383,114 @@ interface JudgeWikimatchPolicyOptions extends WikimatchPolicyJudgeInput {
|
|
|
735
1383
|
declare function judgeWikimatchPolicy(options: JudgeWikimatchPolicyOptions): Promise<WikimatchPolicyJudgeResult>;
|
|
736
1384
|
declare function parsePolicyResponse(candidates: readonly WikimatchCandidate[], response: WikimatchPolicyResponse, groups?: readonly WikimatchConflictGroup[]): WikimatchPolicyJudgeResult;
|
|
737
1385
|
declare function validatePolicyResponse(candidates: readonly WikimatchCandidate[], response: WikimatchPolicyResponse, groups?: readonly WikimatchConflictGroup[]): readonly string[];
|
|
1386
|
+
declare function formatCandidateForPrompt(candidate: WikimatchCandidate, _group?: WikimatchConflictGroup): object;
|
|
1387
|
+
|
|
1388
|
+
interface NarrowWikimatchCandidateOptionsOptions extends NarrowWikimatchCandidateOptionsInput {
|
|
1389
|
+
readonly maxRetries?: number;
|
|
1390
|
+
readonly optionBudget: number;
|
|
1391
|
+
readonly request: GuaranteedRequest;
|
|
1392
|
+
}
|
|
1393
|
+
declare function narrowWikimatchCandidateOptions(options: NarrowWikimatchCandidateOptionsOptions): Promise<WikimatchCandidateOptionNarrowingResult>;
|
|
1394
|
+
declare function parseNarrowingResponse(candidate: WikimatchCandidate, response: WikimatchCandidateOptionNarrowingResponse): WikimatchCandidateOptionNarrowingResult;
|
|
1395
|
+
declare function validateNarrowingResponse(candidate: WikimatchCandidate, response: WikimatchCandidateOptionNarrowingResponse): readonly string[];
|
|
1396
|
+
|
|
1397
|
+
declare function countWikimatchCandidateOptions(candidate: WikimatchCandidate): number;
|
|
1398
|
+
declare function countWikimatchQidOption(option: WikimatchQidOption): number;
|
|
1399
|
+
declare function listCandidateSelectableQids(candidate: WikimatchCandidate): readonly string[];
|
|
1400
|
+
declare function filterCandidateQidOptions(candidate: WikimatchCandidate, allowedQids: ReadonlySet<string>): WikimatchCandidate;
|
|
1401
|
+
declare function splitCandidateByOptionBudget(candidate: WikimatchCandidate, optionBudget: number): readonly WikimatchCandidate[];
|
|
1402
|
+
declare function sliceCandidateByOptionBudget(candidate: WikimatchCandidate, optionBudget: number, offset: number): {
|
|
1403
|
+
readonly candidate: WikimatchCandidate;
|
|
1404
|
+
readonly nextOffset?: number;
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
declare function enrichWikimatchCandidates(candidates: readonly WikimatchCandidate[], options?: {
|
|
1408
|
+
readonly progress?: WikipageResolveProgressReporter;
|
|
1409
|
+
readonly resolverOptions?: Omit<WikipageResolverOptions, "progress">;
|
|
1410
|
+
}): Promise<readonly WikimatchCandidate[]>;
|
|
1411
|
+
declare function applyQidResolutions(candidates: readonly WikimatchCandidate[], resolutions: readonly QidResolution[]): readonly WikimatchCandidate[];
|
|
1412
|
+
|
|
1413
|
+
interface JudgeWikimatchSurfaceProtectionOptions extends WikimatchSurfaceProtectionInput {
|
|
1414
|
+
readonly maxRetries?: number;
|
|
1415
|
+
readonly request: GuaranteedRequest;
|
|
1416
|
+
}
|
|
1417
|
+
declare function judgeWikimatchSurfaceProtection(options: JudgeWikimatchSurfaceProtectionOptions): Promise<WikimatchSurfaceProtectionResult>;
|
|
1418
|
+
declare function parseSurfaceProtectionResponse(surfaces: readonly WikimatchSurface[], response: WikimatchSurfaceProtectionResponse): WikimatchSurfaceProtectionResult;
|
|
1419
|
+
declare function validateSurfaceProtectionResponse(surfaces: readonly WikimatchSurface[], response: WikimatchSurfaceProtectionResponse): readonly string[];
|
|
1420
|
+
|
|
1421
|
+
declare function buildWikimatchSurfaceProtectionInput(options: BuildWikimatchSurfaceProtectionInputOptions): WikimatchSurfaceProtectionBuildResult;
|
|
1422
|
+
|
|
1423
|
+
interface SuppressContainedRangeInput {
|
|
1424
|
+
readonly range: {
|
|
1425
|
+
readonly end: number;
|
|
1426
|
+
readonly start: number;
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
declare function suppressContainedRanges<T extends SuppressContainedRangeInput>(items: readonly T[]): readonly T[];
|
|
1430
|
+
|
|
1431
|
+
interface MatchWikispineSentenceCandidatesOptions {
|
|
1432
|
+
readonly command?: string;
|
|
1433
|
+
readonly dataDir?: string;
|
|
1434
|
+
readonly endpoint?: string;
|
|
1435
|
+
readonly fetch?: typeof fetch;
|
|
1436
|
+
readonly includeDisambiguation?: boolean;
|
|
1437
|
+
readonly maxCandidatesPerSurface?: number;
|
|
1438
|
+
readonly onProgress?: (progress: WikispineMatchProgress) => Promise<void> | void;
|
|
1439
|
+
readonly provider?: WikispineProvider;
|
|
1440
|
+
readonly sentences: readonly WikimatchSentence[];
|
|
1441
|
+
}
|
|
1442
|
+
type WikispineProvider = "cli" | "fetch";
|
|
1443
|
+
interface WikispineMatchProgress {
|
|
1444
|
+
readonly coveredRangeEnd: number;
|
|
1445
|
+
}
|
|
1446
|
+
interface TestWikispineRuntimeOptions {
|
|
1447
|
+
readonly command?: string;
|
|
1448
|
+
readonly dataDir?: string;
|
|
1449
|
+
readonly endpoint?: string;
|
|
1450
|
+
readonly fetch?: typeof fetch;
|
|
1451
|
+
readonly provider?: WikispineProvider;
|
|
1452
|
+
}
|
|
1453
|
+
interface WikispineRuntimeTestResult {
|
|
1454
|
+
readonly durationMs: number;
|
|
1455
|
+
readonly metadata?: WikispineMetadata;
|
|
1456
|
+
readonly ok: true;
|
|
1457
|
+
readonly provider: WikispineProvider;
|
|
1458
|
+
}
|
|
1459
|
+
interface WikispineMetadata {
|
|
1460
|
+
readonly automaton_shard_count: number;
|
|
1461
|
+
readonly format: string;
|
|
1462
|
+
readonly qid_count: number;
|
|
1463
|
+
readonly surface_count: number;
|
|
1464
|
+
readonly surface_normalization: string;
|
|
1465
|
+
}
|
|
1466
|
+
declare const DEFAULT_WIKISPINE_FETCH_ENDPOINT = "https://wikispi-service-cxbfjlteab.cn-hangzhou.fcapp.run";
|
|
1467
|
+
declare function matchWikispineSentenceCandidates(options: MatchWikispineSentenceCandidatesOptions): Promise<readonly WikimatchCandidate[]>;
|
|
1468
|
+
declare function testWikispineRuntime(options: TestWikispineRuntimeOptions): Promise<WikispineRuntimeTestResult>;
|
|
738
1469
|
|
|
739
1470
|
declare function buildWikimatchWindows(options: BuildWikimatchWindowsOptions): readonly WikimatchWindow[];
|
|
740
1471
|
|
|
741
|
-
|
|
1472
|
+
interface WordBoundary {
|
|
1473
|
+
readonly end: number;
|
|
1474
|
+
readonly start: number;
|
|
1475
|
+
}
|
|
1476
|
+
declare function listWordBoundaries(text: string): readonly WordBoundary[];
|
|
1477
|
+
declare function expandRangeByWords(input: {
|
|
1478
|
+
readonly rangeEnd: number;
|
|
1479
|
+
readonly rangeStart: number;
|
|
1480
|
+
readonly text: string;
|
|
1481
|
+
readonly words: number;
|
|
1482
|
+
}): {
|
|
1483
|
+
readonly end: number;
|
|
1484
|
+
readonly start: number;
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
type WikiGraphSamplingConfig = SamplingScopeConfig<WikiGraphScope>;
|
|
1488
|
+
declare function createDefaultWikiGraphSampling(input?: {
|
|
1489
|
+
readonly temperature?: TemperatureSetting;
|
|
1490
|
+
readonly topP?: TemperatureSetting;
|
|
1491
|
+
}): WikiGraphSamplingConfig;
|
|
1492
|
+
|
|
1493
|
+
type WikiGraphOperation = "digest-epub" | "digest-markdown" | "digest-text-stream" | "digest-txt";
|
|
742
1494
|
interface SerialDiscoveryItem {
|
|
743
1495
|
readonly id: number;
|
|
744
1496
|
readonly fragments?: number | undefined;
|
|
@@ -761,21 +1513,175 @@ interface DigestProgressEvent {
|
|
|
761
1513
|
readonly completedWords: number;
|
|
762
1514
|
readonly totalWords: number;
|
|
763
1515
|
}
|
|
764
|
-
type
|
|
765
|
-
type
|
|
766
|
-
type
|
|
1516
|
+
type WikiGraphProgressEventType = WikiGraphProgressEvent["type"];
|
|
1517
|
+
type WikiGraphProgressEvent = SerialsDiscoveredEvent | SerialProgressEvent | DigestProgressEvent;
|
|
1518
|
+
type WikiGraphProgressCallback = (event: WikiGraphProgressEvent) => void | Promise<void>;
|
|
1519
|
+
|
|
1520
|
+
type TextStream = AsyncIterable<string> | Iterable<string>;
|
|
1521
|
+
|
|
1522
|
+
type ReaderTextStream = TextStream;
|
|
1523
|
+
|
|
1524
|
+
interface SerialProgressSink {
|
|
1525
|
+
begin?(input?: {
|
|
1526
|
+
readonly fragments: number;
|
|
1527
|
+
readonly words: number;
|
|
1528
|
+
}): Promise<void>;
|
|
1529
|
+
advance(wordsCount: number): Promise<void>;
|
|
1530
|
+
complete(finalWordsCount?: number): Promise<void>;
|
|
1531
|
+
}
|
|
767
1532
|
|
|
768
1533
|
declare const CHAPTER_STAGES: readonly ["planned", "sourced", "graphed", "summarized"];
|
|
769
1534
|
type ChapterStage = (typeof CHAPTER_STAGES)[number];
|
|
1535
|
+
interface ChapterEntry {
|
|
1536
|
+
readonly chapterId: number;
|
|
1537
|
+
readonly childCount: number;
|
|
1538
|
+
readonly depth: number;
|
|
1539
|
+
readonly documentOrder: number;
|
|
1540
|
+
readonly fragmentCount: number;
|
|
1541
|
+
readonly stage: ChapterStage;
|
|
1542
|
+
readonly title: string | null;
|
|
1543
|
+
readonly tocPath: readonly string[];
|
|
1544
|
+
readonly words: number;
|
|
1545
|
+
}
|
|
1546
|
+
interface ChapterDetails extends ChapterEntry {
|
|
1547
|
+
readonly graphReady: boolean;
|
|
1548
|
+
readonly hasSummary: boolean;
|
|
1549
|
+
readonly words: number;
|
|
1550
|
+
}
|
|
1551
|
+
interface ChapterTree {
|
|
1552
|
+
readonly chapters: readonly ChapterTreeNode[];
|
|
1553
|
+
}
|
|
1554
|
+
interface ChapterTreeNode {
|
|
1555
|
+
readonly children: readonly ChapterTreeNode[];
|
|
1556
|
+
readonly id: number;
|
|
1557
|
+
readonly title: string | null;
|
|
1558
|
+
}
|
|
1559
|
+
interface ChapterTreeInput {
|
|
1560
|
+
readonly chapters: readonly ChapterTreeInputNode[];
|
|
1561
|
+
}
|
|
1562
|
+
interface ChapterTreeInputNode {
|
|
1563
|
+
readonly children: readonly ChapterTreeInputNode[];
|
|
1564
|
+
readonly id: number;
|
|
1565
|
+
readonly title?: string | null | undefined;
|
|
1566
|
+
}
|
|
1567
|
+
interface ChapterTreeApplyResult {
|
|
1568
|
+
readonly changed: boolean;
|
|
1569
|
+
readonly moved: readonly ChapterTreeMoveChange[];
|
|
1570
|
+
readonly renamed: readonly ChapterTreeTitleChange[];
|
|
1571
|
+
readonly unchanged: number;
|
|
1572
|
+
}
|
|
1573
|
+
interface ChapterTreeMoveChange {
|
|
1574
|
+
readonly chapterId: number;
|
|
1575
|
+
readonly newIndex: number;
|
|
1576
|
+
readonly newParentChapterId: number | null;
|
|
1577
|
+
readonly newPath: readonly string[];
|
|
1578
|
+
readonly oldIndex: number;
|
|
1579
|
+
readonly oldParentChapterId: number | null;
|
|
1580
|
+
readonly oldPath: readonly string[];
|
|
1581
|
+
}
|
|
1582
|
+
interface ChapterTreeTitleChange {
|
|
1583
|
+
readonly chapterId: number;
|
|
1584
|
+
readonly newTitle: string | null;
|
|
1585
|
+
readonly oldTitle: string | null;
|
|
1586
|
+
}
|
|
1587
|
+
interface MoveChapterOptions {
|
|
1588
|
+
readonly afterChapterId?: number;
|
|
1589
|
+
readonly beforeChapterId?: number;
|
|
1590
|
+
readonly first?: boolean;
|
|
1591
|
+
readonly last?: boolean;
|
|
1592
|
+
readonly parentChapterId?: number;
|
|
1593
|
+
readonly root?: boolean;
|
|
1594
|
+
}
|
|
1595
|
+
interface AdvanceChapterStagesOptions {
|
|
1596
|
+
readonly chapterId?: number;
|
|
1597
|
+
readonly extractionPrompt: string;
|
|
1598
|
+
readonly llm: LLM<WikiGraphScope>;
|
|
1599
|
+
readonly logDirPath?: string;
|
|
1600
|
+
readonly onProgress?: AdvanceChapterStagesProgressCallback;
|
|
1601
|
+
readonly targetStage: ChapterStage;
|
|
1602
|
+
readonly userLanguage?: Language;
|
|
1603
|
+
}
|
|
1604
|
+
interface AdvanceChapterStagesProgressState {
|
|
1605
|
+
readonly graphWords: number;
|
|
1606
|
+
readonly summaryWords: number;
|
|
1607
|
+
readonly totalGraphWords: number;
|
|
1608
|
+
readonly totalSummaryWords: number;
|
|
1609
|
+
}
|
|
1610
|
+
type AdvanceChapterStagesProgressCallback = (event: AdvanceChapterStagesProgressEvent) => void | Promise<void>;
|
|
1611
|
+
type AdvanceChapterStagesProgressEvent = {
|
|
1612
|
+
readonly type: "selected";
|
|
1613
|
+
readonly state: AdvanceChapterStagesProgressState;
|
|
1614
|
+
readonly targetStage: ChapterStage;
|
|
1615
|
+
readonly totalChapters: number;
|
|
1616
|
+
} | {
|
|
1617
|
+
readonly type: "skipped";
|
|
1618
|
+
readonly chapter: ChapterEntry;
|
|
1619
|
+
readonly reason: "planned";
|
|
1620
|
+
readonly targetStage: ChapterStage;
|
|
1621
|
+
} | {
|
|
1622
|
+
readonly type: "progress";
|
|
1623
|
+
readonly state: AdvanceChapterStagesProgressState;
|
|
1624
|
+
readonly targetStage: ChapterStage;
|
|
1625
|
+
} | {
|
|
1626
|
+
readonly type: "started";
|
|
1627
|
+
readonly chapter: ChapterEntry;
|
|
1628
|
+
readonly step: "graph" | "summary";
|
|
1629
|
+
readonly targetStage: ChapterStage;
|
|
1630
|
+
} | {
|
|
1631
|
+
readonly type: "completed";
|
|
1632
|
+
readonly chapter: ChapterEntry;
|
|
1633
|
+
readonly step: "graph" | "summary";
|
|
1634
|
+
readonly targetStage: ChapterStage;
|
|
1635
|
+
};
|
|
1636
|
+
interface AdvanceChapterStagesResult {
|
|
1637
|
+
readonly advanced: readonly ChapterEntry[];
|
|
1638
|
+
readonly pending: readonly ChapterEntry[];
|
|
1639
|
+
readonly skipped: readonly ChapterEntry[];
|
|
1640
|
+
}
|
|
1641
|
+
interface AddChapterOptions {
|
|
1642
|
+
readonly parentChapterId?: number;
|
|
1643
|
+
readonly title?: string | null | undefined;
|
|
1644
|
+
}
|
|
1645
|
+
declare function parseChapterTreeInput(input: unknown): ChapterTreeInput;
|
|
1646
|
+
interface GenerateChapterGraphOptions {
|
|
1647
|
+
readonly extractionPrompt: string;
|
|
1648
|
+
readonly llm: LLM<WikiGraphScope>;
|
|
1649
|
+
readonly logDirPath?: string;
|
|
1650
|
+
readonly progressTracker?: SerialProgressSink;
|
|
1651
|
+
readonly userLanguage?: Language;
|
|
1652
|
+
}
|
|
1653
|
+
interface GenerateChapterSummaryOptions {
|
|
1654
|
+
readonly llm: LLM<WikiGraphScope>;
|
|
1655
|
+
readonly logDirPath?: string;
|
|
1656
|
+
readonly userLanguage?: Language;
|
|
1657
|
+
}
|
|
1658
|
+
declare function advanceChapterStages(document: Document, options: AdvanceChapterStagesOptions): Promise<AdvanceChapterStagesResult>;
|
|
1659
|
+
declare function addChapter(document: Document, options: AddChapterOptions): Promise<ChapterDetails>;
|
|
1660
|
+
declare function generateChapterGraph(document: Document, chapterId: number, options: GenerateChapterGraphOptions): Promise<ChapterDetails>;
|
|
1661
|
+
declare function generateChapterSummary(document: Document, chapterId: number, options: GenerateChapterSummaryOptions): Promise<ChapterDetails>;
|
|
1662
|
+
declare function getChapterDetails(document: ReadonlyDocument, chapterId: number): Promise<ChapterDetails>;
|
|
1663
|
+
declare function listChapters(document: ReadonlyDocument): Promise<readonly ChapterEntry[]>;
|
|
1664
|
+
declare function getChapterTree(document: ReadonlyDocument): Promise<ChapterTree>;
|
|
1665
|
+
declare function applyChapterTree(document: Document, tree: ChapterTreeInput, options?: {
|
|
1666
|
+
readonly dryRun?: boolean;
|
|
1667
|
+
}): Promise<ChapterTreeApplyResult>;
|
|
1668
|
+
declare function moveChapter(document: Document, chapterId: number, options: MoveChapterOptions): Promise<ChapterDetails>;
|
|
1669
|
+
declare function removeChapter(document: Document, chapterId: number, options?: {
|
|
1670
|
+
readonly recursive?: boolean;
|
|
1671
|
+
}): Promise<void>;
|
|
1672
|
+
declare function resetChapter(document: Document, chapterId: number, stage: Exclude<ChapterStage, "summarized">): Promise<ChapterDetails>;
|
|
1673
|
+
declare function setChapterSource(document: Document, chapterId: number, stream: ReaderTextStream): Promise<ChapterDetails>;
|
|
1674
|
+
declare function setChapterSummary(document: Document, chapterId: number, summary: string): Promise<ChapterDetails>;
|
|
1675
|
+
declare function setChapterTitle(document: Document, chapterId: number, title: string | null | undefined): Promise<ChapterDetails>;
|
|
770
1676
|
|
|
771
|
-
interface
|
|
1677
|
+
interface WikiGraphSerialEntry {
|
|
772
1678
|
readonly fragmentCount: number;
|
|
773
1679
|
readonly serialId: number;
|
|
774
1680
|
readonly title: string | null;
|
|
775
1681
|
readonly tocPath: readonly string[];
|
|
776
1682
|
}
|
|
777
1683
|
|
|
778
|
-
declare class
|
|
1684
|
+
declare class WikiGraphArchive {
|
|
779
1685
|
#private;
|
|
780
1686
|
constructor(document: ReadonlyDocument, documentDirectoryPath: string);
|
|
781
1687
|
exportEpub(path: string): Promise<void>;
|
|
@@ -785,7 +1691,7 @@ declare class SpineDigest {
|
|
|
785
1691
|
readToc(): Promise<TocFile | undefined>;
|
|
786
1692
|
readArchiveFormatVersion(): Promise<number>;
|
|
787
1693
|
readChapterStage(serialId: number): Promise<ChapterStage>;
|
|
788
|
-
listSerials(): Promise<readonly
|
|
1694
|
+
listSerials(): Promise<readonly WikiGraphSerialEntry[]>;
|
|
789
1695
|
readSerialSummary(serialId: number): Promise<string>;
|
|
790
1696
|
saveAs(path: string): Promise<void>;
|
|
791
1697
|
}
|
|
@@ -794,7 +1700,7 @@ interface DigestDocumentSessionOptions {
|
|
|
794
1700
|
readonly documentDirPath?: string;
|
|
795
1701
|
}
|
|
796
1702
|
|
|
797
|
-
interface
|
|
1703
|
+
interface WikiGraphLLMOptions {
|
|
798
1704
|
readonly cacheDirPath?: string;
|
|
799
1705
|
readonly concurrent?: number;
|
|
800
1706
|
readonly logDirPath?: string;
|
|
@@ -806,37 +1712,938 @@ interface SpineDigestLLMOptions {
|
|
|
806
1712
|
readonly timeout?: number;
|
|
807
1713
|
readonly topP?: number | readonly number[];
|
|
808
1714
|
}
|
|
809
|
-
interface
|
|
1715
|
+
interface WikiGraphOptions {
|
|
810
1716
|
readonly debugLogDirPath?: string;
|
|
811
|
-
readonly llm?: LanguageModel |
|
|
1717
|
+
readonly llm?: LanguageModel | WikiGraphLLMOptions;
|
|
812
1718
|
readonly verbose?: boolean;
|
|
813
1719
|
}
|
|
814
|
-
type
|
|
815
|
-
interface
|
|
1720
|
+
type WikiGraphOpenSessionOptions = DigestDocumentSessionOptions;
|
|
1721
|
+
interface WikiGraphSourceSessionOptions extends DigestDocumentSessionOptions {
|
|
816
1722
|
readonly extractionPrompt?: string;
|
|
817
|
-
readonly onProgress?:
|
|
1723
|
+
readonly onProgress?: WikiGraphProgressCallback;
|
|
818
1724
|
readonly path: string;
|
|
819
1725
|
readonly targetStage?: ChapterStage;
|
|
820
1726
|
readonly userLanguage?: Language;
|
|
821
1727
|
}
|
|
822
|
-
interface
|
|
1728
|
+
interface WikiGraphTextStreamSessionOptions extends DigestDocumentSessionOptions {
|
|
823
1729
|
readonly bookLanguage?: string | null;
|
|
824
1730
|
readonly extractionPrompt?: string;
|
|
825
|
-
readonly onProgress?:
|
|
1731
|
+
readonly onProgress?: WikiGraphProgressCallback;
|
|
826
1732
|
readonly sourceFormat?: "markdown" | "txt";
|
|
827
1733
|
readonly stream: AsyncIterable<string> | Iterable<string>;
|
|
828
1734
|
readonly targetStage?: ChapterStage;
|
|
829
1735
|
readonly title?: string | null;
|
|
830
1736
|
readonly userLanguage?: Language;
|
|
831
1737
|
}
|
|
832
|
-
declare class
|
|
1738
|
+
declare class WikiGraph {
|
|
1739
|
+
#private;
|
|
1740
|
+
constructor(options: WikiGraphOptions);
|
|
1741
|
+
digestEpubSession<T>(options: WikiGraphSourceSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
|
|
1742
|
+
digestMarkdownSession<T>(options: WikiGraphSourceSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
|
|
1743
|
+
digestTextStreamSession<T>(options: WikiGraphTextStreamSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
|
|
1744
|
+
digestTxtSession<T>(options: WikiGraphSourceSessionOptions, operation: (digest: WikiGraphArchive) => Promise<T> | T): Promise<T>;
|
|
1745
|
+
openSession<T>(path: string, operation: (digest: WikiGraphArchive) => Promise<T> | T, options?: WikiGraphOpenSessionOptions): Promise<T>;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
interface GraphNode {
|
|
1749
|
+
readonly content: string;
|
|
1750
|
+
readonly id: number;
|
|
1751
|
+
readonly importance?: ChunkImportance;
|
|
1752
|
+
readonly label: string;
|
|
1753
|
+
readonly retention?: ChunkRetention;
|
|
1754
|
+
readonly sentenceIds: readonly SentenceId[];
|
|
1755
|
+
readonly weight: number;
|
|
1756
|
+
readonly wordsCount: number;
|
|
1757
|
+
}
|
|
1758
|
+
interface GraphEdge {
|
|
1759
|
+
readonly fromId: number;
|
|
1760
|
+
readonly strength?: string;
|
|
1761
|
+
readonly toId: number;
|
|
1762
|
+
readonly weight: number;
|
|
1763
|
+
}
|
|
1764
|
+
interface GraphEvidenceLine {
|
|
1765
|
+
readonly sentenceId: SentenceId;
|
|
1766
|
+
readonly text: string;
|
|
1767
|
+
}
|
|
1768
|
+
interface GraphStatus {
|
|
1769
|
+
readonly chapterId: number;
|
|
1770
|
+
readonly edgeCount: number;
|
|
1771
|
+
readonly graphReady: boolean;
|
|
1772
|
+
readonly nodeCount: number;
|
|
1773
|
+
}
|
|
1774
|
+
interface GraphSearchHit {
|
|
1775
|
+
readonly node: GraphNode;
|
|
1776
|
+
readonly matchedFields: readonly GraphSearchField[];
|
|
1777
|
+
}
|
|
1778
|
+
type GraphSearchField = "content" | "evidence" | "label";
|
|
1779
|
+
interface GraphNeighbor {
|
|
1780
|
+
readonly direction: "incoming" | "outgoing";
|
|
1781
|
+
readonly edge: GraphEdge;
|
|
1782
|
+
readonly node: GraphNode;
|
|
1783
|
+
}
|
|
1784
|
+
interface GraphPathStep {
|
|
1785
|
+
readonly edge?: GraphEdge;
|
|
1786
|
+
readonly node: GraphNode;
|
|
1787
|
+
}
|
|
1788
|
+
declare function getGraphStatus(document: ReadonlyDocument, chapterId: number): Promise<GraphStatus>;
|
|
1789
|
+
declare function listGraphNodes(document: ReadonlyDocument, chapterId: number): Promise<readonly GraphNode[]>;
|
|
1790
|
+
declare function getGraphNode(document: ReadonlyDocument, chapterId: number, nodeId: number): Promise<GraphNode>;
|
|
1791
|
+
declare function searchGraphNodes(document: ReadonlyDocument, chapterId: number, pattern: string): Promise<readonly GraphSearchHit[]>;
|
|
1792
|
+
declare function listGraphNeighbors(document: ReadonlyDocument, chapterId: number, nodeId: number): Promise<readonly GraphNeighbor[]>;
|
|
1793
|
+
declare function getGraphEvidence(document: ReadonlyDocument, chapterId: number, nodeId: number): Promise<readonly GraphEvidenceLine[]>;
|
|
1794
|
+
declare function findGraphPath(document: ReadonlyDocument, chapterId: number, fromNodeId: number, toNodeId: number): Promise<readonly GraphPathStep[]>;
|
|
1795
|
+
|
|
1796
|
+
declare const TEXT_SENTENCE_KIND: {
|
|
1797
|
+
readonly source: 1;
|
|
1798
|
+
readonly summary: 2;
|
|
1799
|
+
};
|
|
1800
|
+
type TextSentenceKind = (typeof TEXT_SENTENCE_KIND)[keyof typeof TEXT_SENTENCE_KIND];
|
|
1801
|
+
declare const SEARCH_OBJECT_PROPERTY_OWNER_KIND: {
|
|
1802
|
+
readonly chapter: 1;
|
|
1803
|
+
readonly chunk: 2;
|
|
1804
|
+
readonly entity: 3;
|
|
1805
|
+
};
|
|
1806
|
+
type SearchObjectPropertyOwnerKind = (typeof SEARCH_OBJECT_PROPERTY_OWNER_KIND)[keyof typeof SEARCH_OBJECT_PROPERTY_OWNER_KIND];
|
|
1807
|
+
declare const SEARCH_OBJECT_PROPERTY_KIND: {
|
|
1808
|
+
readonly title: 1;
|
|
1809
|
+
readonly label: 1;
|
|
1810
|
+
readonly content: 2;
|
|
1811
|
+
readonly surface: 1;
|
|
1812
|
+
};
|
|
1813
|
+
type SearchObjectPropertyKind = (typeof SEARCH_OBJECT_PROPERTY_KIND)[keyof typeof SEARCH_OBJECT_PROPERTY_KIND];
|
|
1814
|
+
interface TextSentenceRecordInput {
|
|
1815
|
+
readonly chapterId: number;
|
|
1816
|
+
readonly kind: TextSentenceKind;
|
|
1817
|
+
readonly sentenceIndex: number;
|
|
1818
|
+
readonly text: string;
|
|
1819
|
+
readonly wordsCount: number;
|
|
1820
|
+
}
|
|
1821
|
+
interface SearchObjectPropertyRecordInput {
|
|
1822
|
+
readonly chapterId?: number;
|
|
1823
|
+
readonly ownerId: string;
|
|
1824
|
+
readonly ownerKind: SearchObjectPropertyOwnerKind;
|
|
1825
|
+
readonly propertyKind: SearchObjectPropertyKind;
|
|
1826
|
+
readonly text: string;
|
|
1827
|
+
}
|
|
1828
|
+
interface SearchIndexInput {
|
|
1829
|
+
readonly objectProperties: readonly SearchObjectPropertyRecordInput[];
|
|
1830
|
+
readonly textSentences: readonly TextSentenceRecordInput[];
|
|
1831
|
+
}
|
|
1832
|
+
type SearchIndexProgressPhase = "checking" | "clearing" | "collecting" | "finalizing" | "indexing-objects" | "indexing-text";
|
|
1833
|
+
interface SearchIndexProgressEvent {
|
|
1834
|
+
readonly done?: number;
|
|
1835
|
+
readonly phase: SearchIndexProgressPhase;
|
|
1836
|
+
readonly total?: number;
|
|
1837
|
+
readonly unit?: "chapter" | "object" | "sentence";
|
|
1838
|
+
}
|
|
1839
|
+
type SearchIndexProgressReporter = (event: SearchIndexProgressEvent) => void | Promise<void>;
|
|
1840
|
+
type SearchIndexStatus = "current" | "dirty" | "missing";
|
|
1841
|
+
interface SearchIndexTextHit {
|
|
1842
|
+
readonly chapterId: number;
|
|
1843
|
+
readonly kind: TextSentenceKind;
|
|
1844
|
+
readonly rank: number;
|
|
1845
|
+
readonly score: number;
|
|
1846
|
+
readonly sentenceIndex: number;
|
|
1847
|
+
readonly wordsCount: number;
|
|
1848
|
+
}
|
|
1849
|
+
interface SearchIndexObjectHit {
|
|
1850
|
+
readonly chapterId?: number;
|
|
1851
|
+
readonly ownerId: string;
|
|
1852
|
+
readonly ownerKind: SearchObjectPropertyOwnerKind;
|
|
1853
|
+
readonly propertyKind: SearchObjectPropertyKind;
|
|
1854
|
+
readonly score: number;
|
|
1855
|
+
}
|
|
1856
|
+
interface SearchIndexQueryResult {
|
|
1857
|
+
readonly objectHits: readonly SearchIndexObjectHit[];
|
|
1858
|
+
readonly terms: readonly string[];
|
|
1859
|
+
readonly textHits: readonly SearchIndexTextHit[];
|
|
1860
|
+
}
|
|
1861
|
+
declare const SEARCH_INDEX_FTS_HIT_LIMIT = 32000;
|
|
1862
|
+
interface ArchiveIndexSettings {
|
|
1863
|
+
readonly ftsEmbedded: boolean;
|
|
1864
|
+
}
|
|
1865
|
+
declare function readArchiveIndexSettings(document: ReadonlyDocument): Promise<ArchiveIndexSettings>;
|
|
1866
|
+
declare function setFtsIndexEmbedded(document: Document, embedded: boolean): Promise<void>;
|
|
1867
|
+
declare function isSearchIndexCurrent(document: ReadonlyDocument, input?: SearchIndexInput): Promise<boolean>;
|
|
1868
|
+
declare function readSearchIndexStatus(document: ReadonlyDocument, input?: SearchIndexInput): Promise<SearchIndexStatus>;
|
|
1869
|
+
declare function ensureSearchIndex(document: Document, input: SearchIndexInput, progress?: SearchIndexProgressReporter): Promise<void>;
|
|
1870
|
+
declare function querySearchIndex(document: ReadonlyDocument, query: string, options?: {
|
|
1871
|
+
readonly chapters?: readonly number[];
|
|
1872
|
+
readonly match?: ArchiveFindMatch;
|
|
1873
|
+
readonly objectHitLimit?: number;
|
|
1874
|
+
readonly textAfter?: {
|
|
1875
|
+
readonly chapterId: number;
|
|
1876
|
+
readonly kind: TextSentenceKind;
|
|
1877
|
+
readonly rank: number;
|
|
1878
|
+
readonly sentenceIndex: number;
|
|
1879
|
+
};
|
|
1880
|
+
readonly textHitLimit?: number;
|
|
1881
|
+
readonly types?: readonly ArchiveFindObjectType[] | null;
|
|
1882
|
+
}): Promise<SearchIndexQueryResult | undefined>;
|
|
1883
|
+
declare function createSearchIndexFingerprint(input: SearchIndexInput): string;
|
|
1884
|
+
declare function readSearchIndexFingerprintFromDatabase(database: Database): Promise<string | undefined>;
|
|
1885
|
+
|
|
1886
|
+
type ArchiveObjectType = "chapter" | "chapter-title" | "chapter-tree" | "edge" | "entity" | "fragment" | "meta" | "node" | "source" | "state" | "summary" | "triple";
|
|
1887
|
+
type ChapterStateTarget = "knowledge-graph" | "reading-graph" | "reading-summary" | "source";
|
|
1888
|
+
type ChapterStateValue = "missing" | "ready";
|
|
1889
|
+
type ChapterState = Record<ChapterStateTarget, ChapterStateValue>;
|
|
1890
|
+
type ArchiveCollectionType = "chapter" | "chapter-title" | "entity" | "fragment" | "meta" | "node" | "source" | "summary" | "triple";
|
|
1891
|
+
type ArchiveFindObjectType = "chapter" | "chapter-title" | "chapter-tree" | "entity" | "fragment" | "meta" | "node" | "source" | "summary" | "triple";
|
|
1892
|
+
type ArchiveFindFilterType = "chapter" | "chapter-title" | "entity" | "fragment" | "meta" | "node" | "source" | "summary" | "triple";
|
|
1893
|
+
interface ArchiveIndex {
|
|
1894
|
+
readonly chapters: readonly ChapterEntry[];
|
|
1895
|
+
readonly edgeCount: number;
|
|
1896
|
+
readonly meta: BookMeta | undefined;
|
|
1897
|
+
readonly nodeCount: number;
|
|
1898
|
+
readonly summaryCount: number;
|
|
1899
|
+
}
|
|
1900
|
+
interface ArchiveFindHit {
|
|
1901
|
+
readonly backlinks?: ArchiveBacklinks;
|
|
1902
|
+
readonly chapter?: number;
|
|
1903
|
+
readonly evidence?: ArchiveFindEvidencePreview;
|
|
1904
|
+
readonly evidenceLinks?: readonly MentionLinkRecord[];
|
|
1905
|
+
readonly evidenceMentions?: readonly EntityEvidenceMention[];
|
|
1906
|
+
readonly field: ArchiveFindField;
|
|
1907
|
+
readonly id: string;
|
|
1908
|
+
readonly matchCount?: number;
|
|
1909
|
+
readonly matchedTerms?: readonly string[];
|
|
1910
|
+
readonly missingTerms?: readonly string[];
|
|
1911
|
+
readonly position?: ArchiveFindPosition;
|
|
1912
|
+
readonly score?: number;
|
|
1913
|
+
readonly snippet: string;
|
|
1914
|
+
readonly state?: ChapterState;
|
|
1915
|
+
readonly title: string;
|
|
1916
|
+
readonly triple?: {
|
|
1917
|
+
readonly objectLabel: string;
|
|
1918
|
+
readonly predicate: string;
|
|
1919
|
+
readonly subjectLabel: string;
|
|
1920
|
+
};
|
|
1921
|
+
readonly type: ArchiveFindObjectType;
|
|
1922
|
+
}
|
|
1923
|
+
interface EntityEvidenceMention {
|
|
1924
|
+
readonly match: Pick<ArchiveFindHit, "matchCount" | "matchedTerms" | "missingTerms" | "score">;
|
|
1925
|
+
readonly mention: MentionRecord;
|
|
1926
|
+
}
|
|
1927
|
+
interface ArchiveFindEvidencePreview {
|
|
1928
|
+
readonly nextCursor: string | null;
|
|
1929
|
+
readonly shown: number;
|
|
1930
|
+
readonly sources: readonly ArchiveEvidenceItem[];
|
|
1931
|
+
readonly total: number;
|
|
1932
|
+
}
|
|
1933
|
+
type ArchiveFindField = "content" | "metadata" | "source" | "summary" | "title";
|
|
1934
|
+
interface ArchiveFindOptions {
|
|
1935
|
+
readonly archiveKey?: string;
|
|
1936
|
+
readonly backlinks?: boolean;
|
|
1937
|
+
readonly chapters?: readonly number[];
|
|
1938
|
+
readonly cursor?: string;
|
|
1939
|
+
readonly evidenceLimit?: number;
|
|
1940
|
+
readonly ids?: readonly string[];
|
|
1941
|
+
readonly limit?: number;
|
|
1942
|
+
readonly match?: ArchiveFindMatch;
|
|
1943
|
+
readonly order?: ArchiveFindOrder;
|
|
1944
|
+
readonly sourceContext?: number;
|
|
1945
|
+
readonly triplePattern?: ArchiveTriplePattern;
|
|
1946
|
+
readonly types?: readonly ArchiveFindFilterType[];
|
|
1947
|
+
}
|
|
1948
|
+
type ArchiveFindOrder = "doc-asc" | "doc-desc";
|
|
1949
|
+
type ArchiveFindMatch = "all" | "any";
|
|
1950
|
+
interface ArchiveFindPosition {
|
|
1951
|
+
readonly chapter: number;
|
|
1952
|
+
readonly documentOrder?: number;
|
|
1953
|
+
readonly fragment?: number;
|
|
1954
|
+
readonly sentence?: number;
|
|
1955
|
+
}
|
|
1956
|
+
interface ArchiveFindResult {
|
|
1957
|
+
readonly chapters: readonly number[] | null;
|
|
1958
|
+
readonly items: readonly ArchiveFindHit[];
|
|
1959
|
+
readonly lens: ArchiveFindLens;
|
|
1960
|
+
readonly lensHint: ArchiveFindLensHint | null;
|
|
1961
|
+
readonly limit: number;
|
|
1962
|
+
readonly match: ArchiveFindMatch;
|
|
1963
|
+
readonly nextCursor: string | null;
|
|
1964
|
+
readonly order: ArchiveFindOrder;
|
|
1965
|
+
readonly query: string;
|
|
1966
|
+
readonly terms: readonly string[];
|
|
1967
|
+
readonly types: readonly ArchiveFindFilterType[] | null;
|
|
1968
|
+
}
|
|
1969
|
+
type ArchiveFindLens = "broad" | "exact" | "typed";
|
|
1970
|
+
interface ArchiveFindLensHint {
|
|
1971
|
+
readonly lenses: {
|
|
1972
|
+
readonly chapter: string;
|
|
1973
|
+
readonly chunk: string;
|
|
1974
|
+
readonly entity: string;
|
|
1975
|
+
readonly node: string;
|
|
1976
|
+
readonly triple: string;
|
|
1977
|
+
};
|
|
1978
|
+
readonly message: string;
|
|
1979
|
+
}
|
|
1980
|
+
interface ArchiveCollectionOptions {
|
|
1981
|
+
readonly backlinks?: boolean;
|
|
1982
|
+
readonly chapters?: readonly number[];
|
|
1983
|
+
readonly cursor?: string;
|
|
1984
|
+
readonly evidenceLimit?: number;
|
|
1985
|
+
readonly ids?: readonly string[];
|
|
1986
|
+
readonly limit?: number;
|
|
1987
|
+
readonly order?: ArchiveFindOrder;
|
|
1988
|
+
readonly sourceContext?: number;
|
|
1989
|
+
readonly triplePattern?: ArchiveTriplePattern;
|
|
1990
|
+
readonly types?: readonly ArchiveCollectionType[];
|
|
1991
|
+
}
|
|
1992
|
+
interface ArchiveTriplePattern {
|
|
1993
|
+
readonly objectQid?: string;
|
|
1994
|
+
readonly predicate?: string;
|
|
1995
|
+
readonly subjectQid?: string;
|
|
1996
|
+
}
|
|
1997
|
+
interface ArchiveCollectionResult {
|
|
1998
|
+
readonly chapters: readonly number[] | null;
|
|
1999
|
+
readonly ids: readonly string[] | null;
|
|
2000
|
+
readonly items: readonly ArchiveFindHit[];
|
|
2001
|
+
readonly limit: number;
|
|
2002
|
+
readonly nextCursor: string | null;
|
|
2003
|
+
readonly order: ArchiveFindOrder;
|
|
2004
|
+
readonly types: readonly ArchiveCollectionType[] | null;
|
|
2005
|
+
}
|
|
2006
|
+
interface ArchiveBacklinks {
|
|
2007
|
+
readonly chunks: ArchiveBacklinkBucket;
|
|
2008
|
+
readonly entities: ArchiveBacklinkBucket;
|
|
2009
|
+
readonly triples: ArchiveBacklinkBucket;
|
|
2010
|
+
}
|
|
2011
|
+
interface ArchiveBacklinkBucket {
|
|
2012
|
+
readonly items: readonly ArchiveFindHit[];
|
|
2013
|
+
readonly limit: number;
|
|
2014
|
+
readonly nextCursor: string | null;
|
|
2015
|
+
}
|
|
2016
|
+
type ArchiveListKind = "chapters" | "edges" | "fragments" | "meta" | "nodes" | "summaries";
|
|
2017
|
+
type ArchiveListItem = {
|
|
2018
|
+
readonly evidence?: ArchiveFindEvidencePreview;
|
|
2019
|
+
readonly id: string;
|
|
2020
|
+
readonly label: string;
|
|
2021
|
+
readonly score?: number;
|
|
2022
|
+
readonly state?: ChapterState;
|
|
2023
|
+
readonly summary: string;
|
|
2024
|
+
readonly type: Exclude<ArchiveObjectType, "triple">;
|
|
2025
|
+
} | {
|
|
2026
|
+
readonly evidence?: ArchiveFindEvidencePreview;
|
|
2027
|
+
readonly id: string;
|
|
2028
|
+
readonly label: string;
|
|
2029
|
+
readonly evidenceLinks?: readonly MentionLinkRecord[];
|
|
2030
|
+
readonly objectLabel: string;
|
|
2031
|
+
readonly objectQid: string;
|
|
2032
|
+
readonly predicate: string;
|
|
2033
|
+
readonly score?: number;
|
|
2034
|
+
readonly subjectLabel: string;
|
|
2035
|
+
readonly subjectQid: string;
|
|
2036
|
+
readonly summary: string;
|
|
2037
|
+
readonly type: "triple";
|
|
2038
|
+
};
|
|
2039
|
+
type ArchivePage = {
|
|
2040
|
+
readonly id: string;
|
|
2041
|
+
readonly state: ChapterState;
|
|
2042
|
+
readonly title: string;
|
|
2043
|
+
readonly type: "chapter";
|
|
2044
|
+
} | {
|
|
2045
|
+
readonly id: string;
|
|
2046
|
+
readonly title: string;
|
|
2047
|
+
readonly type: "chapter-title";
|
|
2048
|
+
} | {
|
|
2049
|
+
readonly id: string;
|
|
2050
|
+
readonly title: string;
|
|
2051
|
+
readonly tree: ChapterTree;
|
|
2052
|
+
readonly type: "chapter-tree";
|
|
2053
|
+
} | {
|
|
2054
|
+
readonly generatedNodeSummary: string;
|
|
2055
|
+
readonly id: string;
|
|
2056
|
+
readonly incoming: readonly GraphNeighbor[];
|
|
2057
|
+
readonly neighbors: readonly GraphNeighbor[];
|
|
2058
|
+
readonly outgoing: readonly GraphNeighbor[];
|
|
2059
|
+
readonly position: ArchiveFindPosition | undefined;
|
|
2060
|
+
readonly sourceFragments: readonly ArchiveNodeSourceFragment[];
|
|
2061
|
+
readonly title: string;
|
|
2062
|
+
readonly type: "node";
|
|
2063
|
+
} | {
|
|
2064
|
+
readonly backlinks?: ArchiveBacklinks;
|
|
2065
|
+
readonly fragment: ArchiveSourceFragment;
|
|
2066
|
+
readonly id: string;
|
|
2067
|
+
readonly nextFragmentId: string | undefined;
|
|
2068
|
+
readonly nodes: readonly ArchiveNodeLabel[];
|
|
2069
|
+
readonly previousFragmentId: string | undefined;
|
|
2070
|
+
readonly title: string;
|
|
2071
|
+
readonly type: "fragment";
|
|
2072
|
+
} | {
|
|
2073
|
+
readonly content: string;
|
|
2074
|
+
readonly id: string;
|
|
2075
|
+
readonly title: string;
|
|
2076
|
+
readonly type: "summary";
|
|
2077
|
+
} | {
|
|
2078
|
+
readonly evidence: ArchiveFindEvidencePreview;
|
|
2079
|
+
readonly id: string;
|
|
2080
|
+
readonly label: string;
|
|
2081
|
+
readonly labels: readonly string[];
|
|
2082
|
+
readonly mentionCount: number;
|
|
2083
|
+
readonly qid: string;
|
|
2084
|
+
readonly type: "entity";
|
|
2085
|
+
} | {
|
|
2086
|
+
readonly en: ArchiveEntityWikipageLocale | null;
|
|
2087
|
+
readonly id: string;
|
|
2088
|
+
readonly type: "entity-wikipage";
|
|
2089
|
+
readonly zh: ArchiveEntityWikipageLocale | null;
|
|
2090
|
+
} | {
|
|
2091
|
+
readonly evidence: ArchiveFindEvidencePreview;
|
|
2092
|
+
readonly id: string;
|
|
2093
|
+
readonly label: string;
|
|
2094
|
+
readonly objectQid: string;
|
|
2095
|
+
readonly predicate: string;
|
|
2096
|
+
readonly subjectQid: string;
|
|
2097
|
+
readonly type: "triple";
|
|
2098
|
+
} | {
|
|
2099
|
+
readonly authors?: readonly string[];
|
|
2100
|
+
readonly description?: string;
|
|
2101
|
+
readonly id: string;
|
|
2102
|
+
readonly publisher?: string;
|
|
2103
|
+
readonly title: string;
|
|
2104
|
+
readonly type: "meta";
|
|
2105
|
+
} | {
|
|
2106
|
+
readonly id: string;
|
|
2107
|
+
readonly state: ChapterState;
|
|
2108
|
+
readonly type: "state";
|
|
2109
|
+
} | {
|
|
2110
|
+
readonly id: string;
|
|
2111
|
+
readonly target: ChapterStateTarget;
|
|
2112
|
+
readonly type: "state";
|
|
2113
|
+
readonly value: ChapterStateValue;
|
|
2114
|
+
};
|
|
2115
|
+
interface ArchiveEntityWikipageLocale {
|
|
2116
|
+
readonly description?: string;
|
|
2117
|
+
readonly title: string;
|
|
2118
|
+
readonly url: string;
|
|
2119
|
+
}
|
|
2120
|
+
interface ArchivePack {
|
|
2121
|
+
readonly anchor: ArchivePage;
|
|
2122
|
+
readonly budget: number;
|
|
2123
|
+
readonly related: readonly ArchiveListItem[];
|
|
2124
|
+
}
|
|
2125
|
+
type ArchiveRelatedRole = "any" | "object" | "self" | "subject";
|
|
2126
|
+
interface ArchiveRelatedOptions {
|
|
2127
|
+
readonly cursor?: string;
|
|
2128
|
+
readonly evidenceLimit?: number;
|
|
2129
|
+
readonly limit?: number;
|
|
2130
|
+
readonly order?: ArchiveFindOrder;
|
|
2131
|
+
readonly query?: string;
|
|
2132
|
+
readonly role?: ArchiveRelatedRole;
|
|
2133
|
+
readonly sourceContext?: number;
|
|
2134
|
+
}
|
|
2135
|
+
interface ArchiveRelatedResult {
|
|
2136
|
+
readonly items: readonly ArchiveListItem[];
|
|
2137
|
+
readonly limit: number;
|
|
2138
|
+
readonly nextCursor: string | null;
|
|
2139
|
+
}
|
|
2140
|
+
interface ArchiveEvidence {
|
|
2141
|
+
readonly items: readonly ArchiveEvidenceItem[];
|
|
2142
|
+
readonly limit: number;
|
|
2143
|
+
readonly nextCursor: string | null;
|
|
2144
|
+
}
|
|
2145
|
+
interface ArchiveEvidenceItem {
|
|
2146
|
+
readonly chapterId: number;
|
|
2147
|
+
readonly endSentenceIndex: number;
|
|
2148
|
+
readonly fragmentId?: number;
|
|
2149
|
+
readonly id: string;
|
|
2150
|
+
readonly score?: number;
|
|
2151
|
+
readonly source: string;
|
|
2152
|
+
readonly startSentenceIndex: number;
|
|
2153
|
+
readonly title: string;
|
|
2154
|
+
readonly type: "source";
|
|
2155
|
+
}
|
|
2156
|
+
interface ArchiveNodeLabel {
|
|
2157
|
+
readonly id: string;
|
|
2158
|
+
readonly title: string;
|
|
2159
|
+
}
|
|
2160
|
+
interface ArchiveSourceFragment {
|
|
2161
|
+
readonly fragmentId?: number;
|
|
2162
|
+
readonly id: string;
|
|
2163
|
+
readonly preview: string;
|
|
2164
|
+
readonly sentenceCount: number;
|
|
2165
|
+
readonly text: string;
|
|
2166
|
+
readonly wordsCount: number;
|
|
2167
|
+
}
|
|
2168
|
+
interface ArchiveNodeSourceFragment {
|
|
2169
|
+
readonly id: string;
|
|
2170
|
+
readonly text: string;
|
|
2171
|
+
readonly truncated: boolean;
|
|
2172
|
+
}
|
|
2173
|
+
interface ArchiveEvidenceOptions {
|
|
2174
|
+
readonly cursor?: string;
|
|
2175
|
+
readonly limit?: number;
|
|
2176
|
+
readonly order?: ArchiveFindOrder;
|
|
2177
|
+
readonly query?: string;
|
|
2178
|
+
readonly sourceContext?: number;
|
|
2179
|
+
}
|
|
2180
|
+
interface ArchivePageOptions {
|
|
2181
|
+
readonly backlinks?: boolean;
|
|
2182
|
+
readonly evidenceLimit?: number;
|
|
2183
|
+
readonly order?: ArchiveFindOrder;
|
|
2184
|
+
readonly sourceContext?: number;
|
|
2185
|
+
readonly wikipageResolverOptions?: WikipageResolverOptions;
|
|
2186
|
+
}
|
|
2187
|
+
declare function getArchiveIndex(document: ReadonlyDocument): Promise<ArchiveIndex>;
|
|
2188
|
+
declare function listArchiveObjects(document: ReadonlyDocument, kind: ArchiveListKind): Promise<readonly ArchiveListItem[]>;
|
|
2189
|
+
declare function listArchiveCollection(document: ReadonlyDocument, options?: ArchiveCollectionOptions): Promise<ArchiveCollectionResult>;
|
|
2190
|
+
declare function findArchiveObjects(document: ReadonlyDocument, query: string, options?: ArchiveFindOptions): Promise<ArchiveFindResult>;
|
|
2191
|
+
declare function rebuildArchiveSearchIndex(document: Document, progress?: SearchIndexProgressReporter): Promise<void>;
|
|
2192
|
+
declare function isArchiveSearchIndexCurrent(document: ReadonlyDocument): Promise<boolean>;
|
|
2193
|
+
declare function readArchiveSearchIndexStatus(document: ReadonlyDocument): Promise<"current" | "dirty" | "missing">;
|
|
2194
|
+
declare function clearDirtyArchiveSearchIndex(document: Document): Promise<void>;
|
|
2195
|
+
declare function createArchiveSearchIndexFingerprint(document: ReadonlyDocument): Promise<string>;
|
|
2196
|
+
declare function grepArchiveObjects(document: ReadonlyDocument, query: string, options?: ArchiveFindOptions): Promise<ArchiveFindResult>;
|
|
2197
|
+
declare function readArchiveText(document: ReadonlyDocument, id: string): Promise<string>;
|
|
2198
|
+
declare function readArchivePage(document: ReadonlyDocument, id: string, options?: ArchivePageOptions): Promise<ArchivePage>;
|
|
2199
|
+
declare function listArchiveLinks(document: ReadonlyDocument, id: string, direction: "backlinks" | "links"): Promise<readonly GraphNeighbor[]>;
|
|
2200
|
+
declare function listAllArchiveLinks(document: ReadonlyDocument, id: string): Promise<readonly GraphNeighbor[]>;
|
|
2201
|
+
declare function listRelatedArchiveObjects(document: ReadonlyDocument, id: string, options?: ArchiveRelatedOptions): Promise<ArchiveRelatedResult>;
|
|
2202
|
+
declare function listArchiveEvidence(document: ReadonlyDocument, uri: string, options?: ArchiveEvidenceOptions): Promise<ArchiveEvidence>;
|
|
2203
|
+
declare function packArchiveContext(document: ReadonlyDocument, id: string, budget: number): Promise<ArchivePack>;
|
|
2204
|
+
declare function formatChapterId(chapterId: number): string;
|
|
2205
|
+
declare function formatEdgeId(edge: ReadingEdgeRecord): string;
|
|
2206
|
+
declare function formatNodeId(nodeId: number): string;
|
|
2207
|
+
declare function formatSummaryId(chapterId: number): string;
|
|
2208
|
+
|
|
2209
|
+
type ContinuationCursor = {
|
|
2210
|
+
readonly archiveKey: string;
|
|
2211
|
+
readonly archivePath: string;
|
|
2212
|
+
readonly backlinks?: boolean;
|
|
2213
|
+
readonly chapters: readonly number[] | null;
|
|
2214
|
+
readonly cursor: string;
|
|
2215
|
+
readonly evidenceLimit?: number;
|
|
2216
|
+
readonly format: "json" | "jsonl" | "text";
|
|
2217
|
+
readonly ids: readonly string[] | null;
|
|
2218
|
+
readonly kind: "collection";
|
|
2219
|
+
readonly order: "doc-asc" | "doc-desc";
|
|
2220
|
+
readonly sourceContext?: number;
|
|
2221
|
+
readonly triplePattern?: {
|
|
2222
|
+
readonly objectQid?: string;
|
|
2223
|
+
readonly predicate?: string;
|
|
2224
|
+
readonly subjectQid?: string;
|
|
2225
|
+
};
|
|
2226
|
+
readonly types: readonly string[] | null;
|
|
2227
|
+
} | {
|
|
2228
|
+
readonly archiveKey: string;
|
|
2229
|
+
readonly archivePath: string;
|
|
2230
|
+
readonly backlinks?: boolean;
|
|
2231
|
+
readonly cursor: string;
|
|
2232
|
+
readonly evidenceLimit?: number;
|
|
2233
|
+
readonly format: "json" | "jsonl" | "text";
|
|
2234
|
+
readonly kind: "search";
|
|
2235
|
+
readonly query?: string;
|
|
2236
|
+
readonly sourceContext?: number;
|
|
2237
|
+
readonly triplePattern?: {
|
|
2238
|
+
readonly objectQid?: string;
|
|
2239
|
+
readonly predicate?: string;
|
|
2240
|
+
readonly subjectQid?: string;
|
|
2241
|
+
};
|
|
2242
|
+
readonly types: readonly string[] | null;
|
|
2243
|
+
} | {
|
|
2244
|
+
readonly archiveKey: string;
|
|
2245
|
+
readonly archivePath: string;
|
|
2246
|
+
readonly cursor: string;
|
|
2247
|
+
readonly format: "json" | "jsonl" | "text";
|
|
2248
|
+
readonly kind: "evidence";
|
|
2249
|
+
readonly order: "doc-asc" | "doc-desc";
|
|
2250
|
+
readonly query?: string;
|
|
2251
|
+
readonly sourceContext?: number;
|
|
2252
|
+
readonly targetUri: string;
|
|
2253
|
+
} | {
|
|
2254
|
+
readonly archiveKey: string;
|
|
2255
|
+
readonly archivePath: string;
|
|
2256
|
+
readonly cursor: string;
|
|
2257
|
+
readonly evidenceLimit?: number;
|
|
2258
|
+
readonly format: "json" | "jsonl" | "text";
|
|
2259
|
+
readonly kind: "related";
|
|
2260
|
+
readonly order: "doc-asc" | "doc-desc";
|
|
2261
|
+
readonly query?: string;
|
|
2262
|
+
readonly role?: "any" | "object" | "self" | "subject";
|
|
2263
|
+
readonly sourceContext?: number;
|
|
2264
|
+
readonly targetUri: string;
|
|
2265
|
+
};
|
|
2266
|
+
declare function createContinuationCursor(input: ContinuationCursor): Promise<string>;
|
|
2267
|
+
declare function readContinuationCursor(cursorId: string): Promise<ContinuationCursor>;
|
|
2268
|
+
|
|
2269
|
+
interface SearchSessionInput {
|
|
2270
|
+
readonly archiveKey: string;
|
|
2271
|
+
readonly chapters: readonly number[] | null;
|
|
2272
|
+
readonly chunkHits?: readonly SearchChunkHitInput[];
|
|
2273
|
+
readonly entityHits?: readonly SearchEntityHitInput[];
|
|
2274
|
+
readonly evidenceEvents?: readonly SearchEvidenceHitEventInput[];
|
|
2275
|
+
readonly items?: readonly ArchiveFindHit[];
|
|
2276
|
+
readonly lens: string;
|
|
2277
|
+
readonly match: string;
|
|
2278
|
+
readonly order: string;
|
|
2279
|
+
readonly query: string;
|
|
2280
|
+
readonly revisionScope: string;
|
|
2281
|
+
readonly terms: readonly string[];
|
|
2282
|
+
readonly tripleHits?: readonly SearchTripleHitInput[];
|
|
2283
|
+
readonly types: readonly string[] | null;
|
|
2284
|
+
}
|
|
2285
|
+
declare const SEARCH_EVIDENCE_KIND: {
|
|
2286
|
+
readonly mention: 1;
|
|
2287
|
+
readonly mentionLink: 2;
|
|
2288
|
+
readonly chunk: 3;
|
|
2289
|
+
};
|
|
2290
|
+
type SearchEvidenceKind = (typeof SEARCH_EVIDENCE_KIND)[keyof typeof SEARCH_EVIDENCE_KIND];
|
|
2291
|
+
interface SearchEvidenceHitEventInput {
|
|
2292
|
+
readonly chapterId: number;
|
|
2293
|
+
readonly evidenceId: string;
|
|
2294
|
+
readonly evidenceKind: SearchEvidenceKind;
|
|
2295
|
+
readonly score: number;
|
|
2296
|
+
readonly sentenceIndex: number;
|
|
2297
|
+
}
|
|
2298
|
+
interface SearchEntityHitInput {
|
|
2299
|
+
readonly evidenceTopScores?: readonly number[];
|
|
2300
|
+
readonly propertyTopScores?: readonly number[];
|
|
2301
|
+
readonly qid: string;
|
|
2302
|
+
}
|
|
2303
|
+
interface SearchTripleHitInput {
|
|
2304
|
+
readonly evidenceTopScores: readonly number[];
|
|
2305
|
+
readonly objectQid: string;
|
|
2306
|
+
readonly predicate: string;
|
|
2307
|
+
readonly subjectQid: string;
|
|
2308
|
+
}
|
|
2309
|
+
interface SearchChunkHitInput {
|
|
2310
|
+
readonly chunkId: number;
|
|
2311
|
+
readonly evidenceTopScores?: readonly number[];
|
|
2312
|
+
readonly propertyTopScores?: readonly number[];
|
|
2313
|
+
}
|
|
2314
|
+
interface SearchSessionPage {
|
|
2315
|
+
readonly chapters: readonly number[] | null;
|
|
2316
|
+
readonly items: readonly ArchiveFindHit[];
|
|
2317
|
+
readonly lens: string;
|
|
2318
|
+
readonly match: string;
|
|
2319
|
+
readonly nextCursor: string | null;
|
|
2320
|
+
readonly query: string;
|
|
2321
|
+
readonly sessionId: string;
|
|
2322
|
+
readonly terms: readonly string[];
|
|
2323
|
+
readonly types: readonly string[] | null;
|
|
2324
|
+
}
|
|
2325
|
+
interface SearchSessionDescriptor {
|
|
2326
|
+
readonly chapters: readonly number[] | null;
|
|
2327
|
+
readonly createdAt: number;
|
|
2328
|
+
readonly lens: string;
|
|
2329
|
+
readonly match: string;
|
|
2330
|
+
readonly objectCachesPopulated: boolean;
|
|
2331
|
+
readonly query: string;
|
|
2332
|
+
readonly sessionId: string;
|
|
2333
|
+
readonly terms: readonly string[];
|
|
2334
|
+
readonly types: readonly string[] | null;
|
|
2335
|
+
}
|
|
2336
|
+
type SearchSessionCacheInput = Omit<SearchSessionInput, "items">;
|
|
2337
|
+
declare function readCachedSearchSessionPage(input: SearchSessionCacheInput, offset: number, limit: number): Promise<SearchSessionPage | undefined>;
|
|
2338
|
+
declare function createSearchSession(input: SearchSessionInput): Promise<string>;
|
|
2339
|
+
declare function deleteArchiveSearchSessions(archiveKey: string): Promise<void>;
|
|
2340
|
+
declare function runSearchCacheGc(context: GcContext): Promise<GcJobResult>;
|
|
2341
|
+
|
|
2342
|
+
declare const BUILD_JOB_STATES: readonly ["queued", "running", "canceling", "paused", "succeeded", "failed", "canceled"];
|
|
2343
|
+
type BuildJobState = (typeof BUILD_JOB_STATES)[number];
|
|
2344
|
+
type BuildJobTarget = "knowledge-graph" | "reading-graph" | "reading-summary";
|
|
2345
|
+
type BuildJobProgressPhase = "committing" | "enrichment" | "grounding" | "matching" | "narrowing" | "relation-discovery" | "screening";
|
|
2346
|
+
type BuildJobProgressUnit = "candidate" | "char" | "item" | "page" | "qid" | "sentence" | "window" | "record";
|
|
2347
|
+
interface BuildJobProgressCounter {
|
|
2348
|
+
readonly done: number;
|
|
2349
|
+
readonly name: string;
|
|
2350
|
+
readonly total: number;
|
|
2351
|
+
readonly unit: BuildJobProgressUnit | "word";
|
|
2352
|
+
}
|
|
2353
|
+
interface BuildJobTokenUsage {
|
|
2354
|
+
readonly cacheReadTokens?: number;
|
|
2355
|
+
readonly inputTokens?: number;
|
|
2356
|
+
readonly outputTokens?: number;
|
|
2357
|
+
}
|
|
2358
|
+
interface BuildJob {
|
|
2359
|
+
readonly archiveKey: string;
|
|
2360
|
+
readonly archivePath: string;
|
|
2361
|
+
readonly cachePath: string;
|
|
2362
|
+
readonly chapterId: number;
|
|
2363
|
+
readonly createdAt: number;
|
|
2364
|
+
readonly currentStep?: BuildJobTarget;
|
|
2365
|
+
readonly errorJSON?: string;
|
|
2366
|
+
readonly eventsPath: string;
|
|
2367
|
+
readonly finishedAt?: number;
|
|
2368
|
+
readonly jobId: string;
|
|
2369
|
+
readonly inputRevision?: number;
|
|
2370
|
+
readonly logPath: string;
|
|
2371
|
+
readonly llmJSON?: string;
|
|
2372
|
+
readonly ownerId?: string;
|
|
2373
|
+
readonly ownerPid?: number;
|
|
2374
|
+
readonly prompt?: string;
|
|
2375
|
+
readonly queueRank: number;
|
|
2376
|
+
readonly state: BuildJobState;
|
|
2377
|
+
readonly readingSummaryStartedAt?: number;
|
|
2378
|
+
readonly target: BuildJobTarget;
|
|
2379
|
+
readonly updatedAt: number;
|
|
2380
|
+
readonly workspacePath: string;
|
|
2381
|
+
}
|
|
2382
|
+
type BuildJobEvent = {
|
|
2383
|
+
readonly at: number;
|
|
2384
|
+
readonly jobId: string;
|
|
2385
|
+
readonly seq: number;
|
|
2386
|
+
readonly state: BuildJobState;
|
|
2387
|
+
readonly type: "created" | "paused" | "resumed" | "boosted" | "canceling";
|
|
2388
|
+
} | {
|
|
2389
|
+
readonly at: number;
|
|
2390
|
+
readonly jobId: string;
|
|
2391
|
+
readonly seq: number;
|
|
2392
|
+
readonly from: BuildJobTarget;
|
|
2393
|
+
readonly to: BuildJobTarget;
|
|
2394
|
+
readonly type: "target_changed";
|
|
2395
|
+
} | {
|
|
2396
|
+
readonly at: number;
|
|
2397
|
+
readonly jobId: string;
|
|
2398
|
+
readonly seq: number;
|
|
2399
|
+
readonly state: "running";
|
|
2400
|
+
readonly type: "started";
|
|
2401
|
+
} | {
|
|
2402
|
+
readonly at: number;
|
|
2403
|
+
readonly jobId: string;
|
|
2404
|
+
readonly seq: number;
|
|
2405
|
+
readonly state: "queued";
|
|
2406
|
+
readonly type: "requeued";
|
|
2407
|
+
} | {
|
|
2408
|
+
readonly at: number;
|
|
2409
|
+
readonly jobId: string;
|
|
2410
|
+
readonly seq: number;
|
|
2411
|
+
readonly step: BuildJobTarget;
|
|
2412
|
+
readonly type: "step_started" | "step_completed";
|
|
2413
|
+
} | {
|
|
2414
|
+
readonly at: number;
|
|
2415
|
+
readonly counters: readonly BuildJobProgressCounter[];
|
|
2416
|
+
readonly jobId: string;
|
|
2417
|
+
readonly phase?: BuildJobProgressPhase;
|
|
2418
|
+
readonly seq: number;
|
|
2419
|
+
readonly step?: BuildJobTarget;
|
|
2420
|
+
readonly tokens?: BuildJobTokenUsage;
|
|
2421
|
+
readonly type: "status_snapshot";
|
|
2422
|
+
} | {
|
|
2423
|
+
readonly at: number;
|
|
2424
|
+
readonly error?: unknown;
|
|
2425
|
+
readonly jobId: string;
|
|
2426
|
+
readonly seq: number;
|
|
2427
|
+
readonly state: "failed" | "canceled" | "succeeded";
|
|
2428
|
+
readonly type: "failed" | "canceled" | "succeeded";
|
|
2429
|
+
};
|
|
2430
|
+
interface AddBuildJobOptions {
|
|
2431
|
+
readonly archivePath: string;
|
|
2432
|
+
readonly boost?: boolean;
|
|
2433
|
+
readonly chapterId: number;
|
|
2434
|
+
readonly jobId?: string;
|
|
2435
|
+
readonly llmJSON?: string;
|
|
2436
|
+
readonly prompt?: string;
|
|
2437
|
+
readonly target: BuildJobTarget;
|
|
2438
|
+
}
|
|
2439
|
+
interface BuildJobListOptions {
|
|
2440
|
+
readonly activeOnly?: boolean;
|
|
2441
|
+
readonly all?: boolean;
|
|
2442
|
+
readonly archivePath?: string;
|
|
2443
|
+
}
|
|
2444
|
+
interface BuildJobWorkerOptions {
|
|
2445
|
+
readonly concurrency: number;
|
|
2446
|
+
readonly executeJob: (job: BuildJob, reporter: BuildJobProgressReporter, context: BuildJobExecutionContext) => Promise<void>;
|
|
2447
|
+
readonly idleTimeoutMs?: number;
|
|
2448
|
+
}
|
|
2449
|
+
interface BuildJobExecutionContext {
|
|
2450
|
+
readonly signal: AbortSignal;
|
|
2451
|
+
}
|
|
2452
|
+
interface BuildJobProgressReporter {
|
|
2453
|
+
addOutputCharacters(characters: number): Promise<void>;
|
|
2454
|
+
addTokenUsage(usage: BuildJobTokenUsage): Promise<void>;
|
|
2455
|
+
setTotals(input: {
|
|
2456
|
+
readonly totalGraphWords?: number;
|
|
2457
|
+
readonly totalReadingSummaryWords?: number;
|
|
2458
|
+
}): Promise<void>;
|
|
2459
|
+
stepCompleted(step: BuildJobTarget): Promise<void>;
|
|
2460
|
+
stepStarted(step: BuildJobTarget): Promise<void>;
|
|
2461
|
+
updateWords(input: {
|
|
2462
|
+
readonly graphWords?: number;
|
|
2463
|
+
readonly readingSummaryWords?: number;
|
|
2464
|
+
}): Promise<void>;
|
|
2465
|
+
updatePhase(input: {
|
|
2466
|
+
readonly done: number;
|
|
2467
|
+
readonly force?: boolean;
|
|
2468
|
+
readonly phase: BuildJobProgressPhase;
|
|
2469
|
+
readonly phaseDetail?: string;
|
|
2470
|
+
readonly total: number;
|
|
2471
|
+
readonly unit: BuildJobProgressUnit;
|
|
2472
|
+
}): Promise<void>;
|
|
2473
|
+
throwIfStopped(): Promise<void>;
|
|
2474
|
+
}
|
|
2475
|
+
type BuildJobConflictScope = {
|
|
2476
|
+
readonly kind: "archive";
|
|
2477
|
+
} | {
|
|
2478
|
+
readonly chapterIds: readonly number[];
|
|
2479
|
+
readonly kind: "chapter";
|
|
2480
|
+
};
|
|
2481
|
+
declare function addBuildJob(options: AddBuildJobOptions): Promise<BuildJob>;
|
|
2482
|
+
declare function recordBuildJobInputRevision(input: {
|
|
2483
|
+
readonly currentRevision: number;
|
|
2484
|
+
readonly jobId: string;
|
|
2485
|
+
readonly ownerId: string;
|
|
2486
|
+
}): Promise<BuildJob>;
|
|
2487
|
+
declare function assertBuildJobInputRevision(input: {
|
|
2488
|
+
readonly currentRevision: number;
|
|
2489
|
+
readonly jobId: string;
|
|
2490
|
+
readonly ownerId: string;
|
|
2491
|
+
}): Promise<void>;
|
|
2492
|
+
declare function listBuildJobs(options?: BuildJobListOptions): Promise<BuildJob[]>;
|
|
2493
|
+
declare function getBuildJob(jobId: string): Promise<BuildJob>;
|
|
2494
|
+
declare function resolveBuildJobId(jobIdPrefix: string): Promise<string>;
|
|
2495
|
+
declare function pauseBuildJob(jobId: string): Promise<BuildJob>;
|
|
2496
|
+
declare function resumeBuildJob(jobId: string): Promise<BuildJob>;
|
|
2497
|
+
declare function cancelBuildJob(jobId: string): Promise<BuildJob>;
|
|
2498
|
+
declare function boostBuildJob(jobId: string): Promise<BuildJob>;
|
|
2499
|
+
declare function updateBuildJobTarget(jobId: string, target: BuildJobTarget): Promise<BuildJob>;
|
|
2500
|
+
declare function assertNoActiveBuildJobs(input: {
|
|
2501
|
+
readonly archivePath: string;
|
|
2502
|
+
readonly chapterIds: readonly number[];
|
|
2503
|
+
readonly operation: string;
|
|
2504
|
+
readonly requiresTarget?: BuildJobTarget;
|
|
2505
|
+
}): Promise<void>;
|
|
2506
|
+
declare function assertNoActiveBuildJobConflicts(input: {
|
|
2507
|
+
readonly archivePath: string;
|
|
2508
|
+
readonly operation: string;
|
|
2509
|
+
readonly requiresTarget?: BuildJobTarget;
|
|
2510
|
+
readonly scope: BuildJobConflictScope;
|
|
2511
|
+
}): Promise<void>;
|
|
2512
|
+
declare function runBuildJobWorker(options: BuildJobWorkerOptions): Promise<void>;
|
|
2513
|
+
declare function readBuildJobEvents(job: Pick<BuildJob, "eventsPath">): Promise<BuildJobEvent[]>;
|
|
2514
|
+
declare function cleanBuildJobs(options?: {
|
|
2515
|
+
readonly olderThanMs?: number;
|
|
2516
|
+
readonly states?: readonly BuildJobState[];
|
|
2517
|
+
}): Promise<number>;
|
|
2518
|
+
declare function runBuildQueueGc(context: GcContext): Promise<GcJobResult>;
|
|
2519
|
+
|
|
2520
|
+
interface ChapterGraphBuildArtifact {
|
|
2521
|
+
readonly documentPath: string;
|
|
2522
|
+
readonly chapterId: number;
|
|
2523
|
+
readonly parameter: GraphBuildParameterInput$1;
|
|
2524
|
+
}
|
|
2525
|
+
interface GraphBuildParameterInput$1 {
|
|
2526
|
+
readonly language?: string;
|
|
2527
|
+
readonly prompt: string;
|
|
2528
|
+
}
|
|
2529
|
+
interface ChapterSummaryInputSnapshot {
|
|
2530
|
+
readonly filePath: string;
|
|
2531
|
+
}
|
|
2532
|
+
interface BuildChapterGraphArtifactOptions extends GenerateChapterGraphOptions {
|
|
2533
|
+
readonly sourceText: readonly string[];
|
|
2534
|
+
readonly workspacePath: string;
|
|
2535
|
+
}
|
|
2536
|
+
interface BuildChapterSummaryArtifactOptions extends GenerateChapterSummaryOptions {
|
|
2537
|
+
readonly snapshotPath?: string;
|
|
2538
|
+
readonly sourceDocumentPath?: string;
|
|
2539
|
+
readonly workspacePath: string;
|
|
2540
|
+
}
|
|
2541
|
+
declare function readChapterBuildInput(document: ReadonlyDocument, chapterId: number): Promise<{
|
|
2542
|
+
readonly details: ChapterDetails;
|
|
2543
|
+
readonly revision: number;
|
|
2544
|
+
readonly sourceText: readonly string[];
|
|
2545
|
+
}>;
|
|
2546
|
+
declare function buildChapterGraphArtifact(chapterId: number, options: BuildChapterGraphArtifactOptions): Promise<ChapterGraphBuildArtifact>;
|
|
2547
|
+
declare function commitChapterGraphArtifact(document: Document, artifact: ChapterGraphBuildArtifact): Promise<ChapterDetails>;
|
|
2548
|
+
declare function buildChapterSummaryArtifact(document: ReadonlyDocument, chapterId: number, options: BuildChapterSummaryArtifactOptions): Promise<string>;
|
|
2549
|
+
declare function buildChapterSummaryArtifactFromSnapshot(chapterId: number, options: BuildChapterSummaryArtifactOptions & {
|
|
2550
|
+
readonly snapshotPath: string;
|
|
2551
|
+
}): Promise<string>;
|
|
2552
|
+
declare function commitChapterSummaryArtifact(document: Document, chapterId: number, summary: string): Promise<ChapterDetails>;
|
|
2553
|
+
declare function snapshotChapterSummaryInput(document: ReadonlyDocument, chapterId: number, workspacePath: string): Promise<ChapterSummaryInputSnapshot>;
|
|
2554
|
+
|
|
2555
|
+
interface ChapterKnowledgeGraphBuildArtifact {
|
|
2556
|
+
readonly chapterId: number;
|
|
2557
|
+
readonly mentionLinksPath: string;
|
|
2558
|
+
readonly mentionsPath: string;
|
|
2559
|
+
readonly parameter: GraphBuildParameterInput;
|
|
2560
|
+
readonly workspacePath: string;
|
|
2561
|
+
}
|
|
2562
|
+
interface ChapterKnowledgeGraphInputSnapshot {
|
|
2563
|
+
readonly details: ChapterDetails;
|
|
2564
|
+
readonly fragments: readonly FragmentRecord[];
|
|
2565
|
+
}
|
|
2566
|
+
interface GraphBuildParameterInput {
|
|
2567
|
+
readonly language?: string;
|
|
2568
|
+
readonly prompt: string;
|
|
2569
|
+
}
|
|
2570
|
+
interface BuildChapterKnowledgeGraphArtifactOptions {
|
|
2571
|
+
readonly mentionLinks: AsyncIterable<MentionLinkRecord> | Iterable<MentionLinkRecord>;
|
|
2572
|
+
readonly mentions: AsyncIterable<MentionRecord> | Iterable<MentionRecord>;
|
|
2573
|
+
readonly parameter?: GraphBuildParameterInput;
|
|
2574
|
+
readonly workspacePath: string;
|
|
2575
|
+
}
|
|
2576
|
+
interface GenerateChapterKnowledgeGraphArtifactOptions {
|
|
2577
|
+
readonly policyPrompt: string;
|
|
2578
|
+
readonly progressTracker?: Pick<BuildJobProgressReporter, "throwIfStopped" | "updatePhase">;
|
|
2579
|
+
readonly request: GuaranteedRequestController;
|
|
2580
|
+
readonly resolverOptions?: Omit<WikipageResolverOptions, "progress">;
|
|
2581
|
+
readonly wikispine?: Pick<MatchWikispineSentenceCandidatesOptions, "command" | "dataDir" | "endpoint" | "provider">;
|
|
2582
|
+
readonly workspacePath: string;
|
|
2583
|
+
}
|
|
2584
|
+
declare function generateChapterKnowledgeGraphArtifact(document: ReadonlyDocument, chapterId: number, options: GenerateChapterKnowledgeGraphArtifactOptions): Promise<ChapterKnowledgeGraphBuildArtifact>;
|
|
2585
|
+
declare function snapshotChapterKnowledgeGraphInput(document: ReadonlyDocument, chapterId: number): Promise<ChapterKnowledgeGraphInputSnapshot>;
|
|
2586
|
+
declare function generateChapterKnowledgeGraphArtifactFromSnapshot(chapterId: number, snapshot: ChapterKnowledgeGraphInputSnapshot, options: GenerateChapterKnowledgeGraphArtifactOptions): Promise<ChapterKnowledgeGraphBuildArtifact>;
|
|
2587
|
+
declare function buildChapterKnowledgeGraphArtifact(chapterId: number, options: BuildChapterKnowledgeGraphArtifactOptions): Promise<ChapterKnowledgeGraphBuildArtifact>;
|
|
2588
|
+
declare function groundWikimatchCandidates(input: {
|
|
2589
|
+
readonly candidates: readonly WikimatchCandidate[];
|
|
2590
|
+
readonly policyPrompt: string;
|
|
2591
|
+
readonly progressTracker?: Pick<BuildJobProgressReporter, "throwIfStopped" | "updatePhase">;
|
|
2592
|
+
readonly request: GuaranteedRequestController;
|
|
2593
|
+
readonly text: string;
|
|
2594
|
+
}): Promise<readonly WikimatchAcceptedMention[]>;
|
|
2595
|
+
declare function createEnrichmentProgressReporter(progressTracker: Pick<BuildJobProgressReporter, "throwIfStopped" | "updatePhase">): (event: WikipageResolveProgress) => Promise<void>;
|
|
2596
|
+
declare function commitChapterKnowledgeGraphArtifact(document: Document, artifact: ChapterKnowledgeGraphBuildArtifact): Promise<void>;
|
|
2597
|
+
declare function clearChapterKnowledgeGraph(document: Document, chapterId: number): Promise<void>;
|
|
2598
|
+
|
|
2599
|
+
declare function writeWikgArchive(documentDirectoryPath: string, outputPath: string): Promise<void>;
|
|
2600
|
+
declare function readWikgArchiveFormatVersion(documentDirectoryPath: string): Promise<number>;
|
|
2601
|
+
|
|
2602
|
+
declare const WIKI_GRAPH_URI_PREFIX = "wikg://";
|
|
2603
|
+
declare const WIKI_GRAPH_JOB_URI_PREFIX = "wikg://local/job";
|
|
2604
|
+
interface LocatedWikiGraphUri {
|
|
2605
|
+
readonly archivePath?: string;
|
|
2606
|
+
readonly objectUri?: string;
|
|
2607
|
+
}
|
|
2608
|
+
declare function isWikiGraphUri(value: string | undefined): value is string;
|
|
2609
|
+
declare function isWikiGraphJobUri(value: string | undefined): value is string;
|
|
2610
|
+
declare function parseLocatedWikiGraphUri(uri: string): LocatedWikiGraphUri;
|
|
2611
|
+
declare function formatLocatedWikiGraphUri(archivePath: string, objectUri?: string): string;
|
|
2612
|
+
declare function formatWikiGraphCommandUri(archivePath: string, objectUri?: string, cwd?: string): string;
|
|
2613
|
+
declare function formatLocatedChapterUri(archivePath: string, chapterId: number): string;
|
|
2614
|
+
declare function formatLocatedChapterResourceUri(archivePath: string, chapterId: number, resource: "source" | "summary" | "title"): string;
|
|
2615
|
+
declare function formatLocatedChapterSourceCollectionUri(archivePath: string, chapterId: number): string;
|
|
2616
|
+
declare function requireArchiveUri(uri: string): string;
|
|
2617
|
+
declare function requireLocatedObjectUri(uri: string): {
|
|
2618
|
+
readonly archivePath: string;
|
|
2619
|
+
readonly objectUri: string;
|
|
2620
|
+
};
|
|
2621
|
+
declare function requireLocatedObjectOrArchiveUri(uri: string): {
|
|
2622
|
+
readonly archivePath: string;
|
|
2623
|
+
readonly objectUri?: string;
|
|
2624
|
+
};
|
|
2625
|
+
|
|
2626
|
+
declare class WikiGraphArchiveFile {
|
|
833
2627
|
#private;
|
|
834
|
-
constructor(
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
2628
|
+
constructor(path: string);
|
|
2629
|
+
read<T>(operation: (digest: WikiGraphArchive) => Promise<T> | T, options?: {
|
|
2630
|
+
readonly documentDirPath?: string;
|
|
2631
|
+
}): Promise<T>;
|
|
2632
|
+
readDocument<T>(operation: (document: DirectoryDocument, directoryPath: string) => Promise<T> | T, options?: {
|
|
2633
|
+
readonly documentDirPath?: string;
|
|
2634
|
+
readonly searchIndexWritebackPolicy?: "archive" | "cache";
|
|
2635
|
+
}): Promise<T>;
|
|
2636
|
+
write<T>(operation: (document: DirectoryDocument) => Promise<T> | T, options?: {
|
|
2637
|
+
readonly searchIndexWritebackPolicy?: "archive" | "cache";
|
|
2638
|
+
}): Promise<T>;
|
|
840
2639
|
}
|
|
841
2640
|
|
|
842
|
-
|
|
2641
|
+
interface LegacySdpubMigrationResult {
|
|
2642
|
+
readonly inputPath: string;
|
|
2643
|
+
readonly outputPath: string;
|
|
2644
|
+
}
|
|
2645
|
+
declare function migrateLegacySdpubToWikg(inputPath: string, outputPath?: string): Promise<LegacySdpubMigrationResult>;
|
|
2646
|
+
|
|
2647
|
+
declare function formatError(error: unknown): string;
|
|
2648
|
+
|
|
2649
|
+
export { type AddBuildJobOptions, type AddChapterOptions, type AdvanceChapterStagesOptions, type AdvanceChapterStagesProgressCallback, type AdvanceChapterStagesProgressEvent, type AdvanceChapterStagesResult, type ArchiveBacklinkBucket, type ArchiveBacklinks, type ArchiveCollectionOptions, type ArchiveCollectionResult, type ArchiveCollectionType, type ArchiveEvidence, type ArchiveEvidenceItem, type ArchiveFindEvidencePreview, type ArchiveFindField, type ArchiveFindFilterType, type ArchiveFindHit, type ArchiveFindObjectType, type ArchiveFindOptions, type ArchiveFindOrder, type ArchiveFindPosition, type ArchiveFindResult, type ArchiveIndex, type ArchiveIndexSettings, type ArchiveListItem, type ArchiveListKind, type ArchiveNodeLabel, type ArchiveNodeSourceFragment, type ArchiveObjectType, type ArchivePack, type ArchivePage, type ArchiveRelatedResult, type ArchiveTriplePattern, type BookMeta, type BuildChapterGraphArtifactOptions, type BuildChapterKnowledgeGraphArtifactOptions, type BuildChapterSummaryArtifactOptions, type BuildJob, type BuildJobConflictScope, type BuildJobEvent, type BuildJobExecutionContext, type BuildJobListOptions, type BuildJobProgressCounter, type BuildJobProgressReporter, type BuildJobState, type BuildJobTarget, type BuildJobWorkerOptions, type BuildWikimatchSurfaceProtectionInputOptions, type BuildWikimatchWindowsOptions, CHAPTER_STAGES, CLI_FULL_COMMAND, CLI_PRIMARY_COMMAND, type CachedDisambiguationRecord, type CachedPageRecord, type CachedQidRecord, type ChapterDetails, type ChapterEntry, type ChapterGraphBuildArtifact, type ChapterKnowledgeGraphBuildArtifact, type ChapterKnowledgeGraphInputSnapshot, type ChapterStage, type ChapterTree, type ChapterTreeApplyResult, type ChapterTreeInput, type ChapterTreeInputNode, type ChapterTreeMoveChange, type ChapterTreeNode, type ChapterTreeTitleChange, ChunkImportance, type ChunkRecord, ChunkRetention, ChunkStore, type ContinuationCursor, type CreateSnakeRecord, DEFAULT_WIKISPINE_FETCH_ENDPOINT, Database, type DigestProgressEvent, DirectoryDocument, type DisambiguationExpansion, type DisambiguationLinkedQid, type DisambiguationMeaningPriority, type DisambiguationPageText, type DisambiguationProfile, type DisambiguationProfileMeaning, type DisambiguationProfileNormalizer, type DisambiguationProfileNormalizerInput, type Document, type DocumentContext, EVIDENCE_SELECTION_JSON_SHAPE, EVIDENCE_SELECTION_PROMPT_FRAGMENT, type EvidenceQuoteMatchStrategy, type EvidenceQuoteScore, type EvidenceSelection, type EvidenceSelectionCandidate, type EvidenceSelectionFailure, type EvidenceSelectionList, type EvidenceSelectionResolution, type EvidenceSelectionSentence, type EvidenceSentenceId, FragmentDraft, FragmentGroupStore, type FragmentRecord, Fragments, type GenerateChapterGraphOptions, type GenerateChapterSummaryOptions, type GraphBuildParameterRecord, GraphBuildParameterStore, type GraphEdge, type GraphEvidenceLine, type GraphNeighbor, type GraphNode, type GraphPathStep, type GraphSearchField, type GraphSearchHit, type GraphStatus, type GuaranteedRequest, type GuaranteedRequestController, type JudgeWikimatchPolicyOptions, type JudgeWikimatchSurfaceProtectionOptions, LLM, type LLMOptions, LLMPaymentRequiredError, type LLMRequestOptions, type LLMStreamProgressCallback, type LLMTokenUsage, type LLMTokenUsageCallback, type LLMessage, Language, LanguageCode, type LocatedWikiGraphUri, type MatchWikispineSentenceCandidatesOptions, type MentionLinkRecord, MentionLinkStore, type MentionRecord, MentionStore, type MoveChapterOptions, type NarrowWikimatchCandidateOptionsInput, type NarrowWikimatchCandidateOptionsOptions, ObjectMetadataKind, ObjectMetadataStore, type ObjectMetadataTarget, type QidResolution, RateLimiter, type ReadingEdgeRecord, ReadingEdgeStore, type ReadonlyChunkStore, type ReadonlyDocument, type ReadonlyFragmentGroupStore, type ReadonlyTextStreams as ReadonlyFragments, type ReadonlyGraphBuildParameterStore, type ReadonlyMentionLinkStore, type ReadonlyMentionStore, type ReadonlyObjectMetadataStore, type ReadonlyReadingEdgeStore, type ReadonlySerialTextStream as ReadonlySerialFragments, type ReadonlySerialStore, type ReadonlySerialTextStream, type ReadonlySnakeChunkStore, type ReadonlySnakeEdgeStore, type ReadonlySnakeStore, type ReadonlyTextStreams, SCHEMA_SQL, SEARCH_INDEX_FTS_HIT_LIMIT, SEARCH_OBJECT_PROPERTY_KIND, SEARCH_OBJECT_PROPERTY_OWNER_KIND, type SearchIndexInput, type SearchIndexObjectHit, type SearchIndexProgressEvent, type SearchIndexProgressPhase, type SearchIndexProgressReporter, type SearchIndexQueryResult, type SearchIndexStatus, type SearchIndexTextHit, type SearchObjectPropertyKind, type SearchObjectPropertyOwnerKind, type SearchSessionDescriptor, type SearchSessionInput, type SearchSessionPage, type SentenceGroupRecord, type SentenceId, type SentenceRecord, type SerialDiscoveryItem, SerialFragments, type SerialProgressEvent, type SerialRecord, SerialStore, SerialTextStream, type SerialsDiscoveredEvent, type SnakeChunkRecord, SnakeChunkStore, type SnakeEdgeRecord, SnakeEdgeStore, type SnakeRecord, SnakeStore, TEXT_SENTENCE_KIND, TOC_FILE_VERSION, type TestWikispineRuntimeOptions, type TextSentenceKind, TextStreams, WIKI_GRAPH_CONTEXT_VERSION, WIKI_GRAPH_EDITOR_SCOPES, WIKI_GRAPH_JOB_URI_PREFIX, WIKI_GRAPH_READER_SCOPES, WIKI_GRAPH_SCOPES, WIKI_GRAPH_URI_PREFIX, WikiGraph, WikiGraphArchive, WikiGraphArchiveFile, type WikiGraphLLMOptions, type WikiGraphOpenSessionOptions, type WikiGraphOperation, type WikiGraphOptions, type WikiGraphProgressCallback, type WikiGraphProgressEvent, type WikiGraphProgressEventType, WikiGraphScope, type WikiGraphSerialEntry, type WikiGraphSourceSessionOptions, WikiGraphTask, WikiGraphTaskContext, type WikiGraphTaskContextOptions, type WikiGraphTaskIdentity, type WikiGraphTaskType, type WikiGraphTextStreamSessionOptions, type WikimatchAcceptedMention, type WikimatchCandidate, type WikimatchCandidateOptionNarrowingFallback, type WikimatchCandidateOptionNarrowingItemOutput, type WikimatchCandidateOptionNarrowingResponse, type WikimatchCandidateOptionNarrowingResult, type WikimatchConflictGroup, type WikimatchPolicyContinuation, type WikimatchPolicyDecision, type WikimatchPolicyDecisionOutput, type WikimatchPolicyFallback, type WikimatchPolicyJudgeInput, type WikimatchPolicyJudgeResult, type WikimatchPolicyResponse, type WikimatchPolicyUpdate, type WikimatchProtectedSurface, type WikimatchQidOption, type WikimatchSentence, type WikimatchSurface, type WikimatchSurfaceProtectionBuildResult, type WikimatchSurfaceProtectionFallback, type WikimatchSurfaceProtectionInput, type WikimatchSurfaceProtectionResponse, type WikimatchSurfaceProtectionResult, type WikimatchTextRange, type WikimatchWindow, WikimediaClient, WikipageCache, WikipageResolver, type WikipageResolverOptions, type WikipageSitelink, type WikispineProvider, type WikispineRuntimeTestResult, addBuildJob, addChapter, advanceChapterStages, applyChapterTree, applyQidResolutions, assertBuildJobInputRevision, assertNoActiveBuildJobConflicts, assertNoActiveBuildJobs, boostBuildJob, buildChapterGraphArtifact, buildChapterKnowledgeGraphArtifact, buildChapterSummaryArtifact, buildChapterSummaryArtifactFromSnapshot, buildWikimatchSurfaceProtectionInput, buildWikimatchWindows, cancelBuildJob, cleanBuildJobs, clearChapterKnowledgeGraph, clearDirtyArchiveSearchIndex, commitChapterGraphArtifact, commitChapterKnowledgeGraphArtifact, commitChapterSummaryArtifact, countWikimatchCandidateOptions, countWikimatchQidOption, createArchiveSearchIndexFingerprint, createContinuationCursor, createDefaultWikiGraphSampling, createDisambiguationProfileNormalizer, createEnrichmentProgressReporter, createEnv, createSearchIndexFingerprint, createSearchSession, createWikiGraphTaskId, createWikiGraphTempDirectory, deleteArchiveSearchSessions, enrichWikimatchCandidates, ensureSearchIndex, ensureSharedStateDatabaseInitialized, expandRangeByWords, expectChunkImportance, expectChunkRetention, filterCandidateQidOptions, findArchiveObjects, findGraphPath, formatCandidateForPrompt, formatChapterId, formatEdgeId, formatError, formatEvidenceSelectionChoicePrompt, formatLanguageForPrompt, formatLocatedChapterResourceUri, formatLocatedChapterSourceCollectionUri, formatLocatedChapterUri, formatLocatedWikiGraphUri, formatNodeId, formatSummaryId, formatWikiGraphCommandUri, generateChapterGraph, generateChapterKnowledgeGraphArtifact, generateChapterKnowledgeGraphArtifactFromSnapshot, generateChapterSummary, getArchiveIndex, getBuildJob, getChapterDetails, getChapterTree, getGraphEvidence, getGraphNode, getGraphStatus, getLanguageCode, getWikipageLanguageCode, grepArchiveObjects, groundWikimatchCandidates, isArchiveSearchIndexCurrent, isChunkImportance, isChunkRetention, isSearchIndexCurrent, isWikiGraphJobUri, isWikiGraphUri, judgeWikimatchPolicy, judgeWikimatchSurfaceProtection, listAllArchiveLinks, listArchiveCollection, listArchiveEvidence, listArchiveLinks, listArchiveObjects, listBuildJobs, listCandidateSelectableQids, listChapters, listGraphNeighbors, listGraphNodes, listRelatedArchiveObjects, listWordBoundaries, matchWikispineSentenceCandidates, migrateLegacySdpubToWikg, moveChapter, narrowWikimatchCandidateOptions, normalizeEvidenceDisplayText, normalizeEvidenceText, normalizeLanguageCode, openSharedStateDatabase, packArchiveContext, parseChapterTreeInput, parseLocatedWikiGraphUri, parseNarrowingResponse, parsePolicyResponse, parseRetryAfterMs, parseSurfaceProtectionResponse, pauseBuildJob, querySearchIndex, rankEvidenceQuote, readArchiveIndexSettings, readArchivePage, readArchiveSearchIndexStatus, readArchiveText, readBuildJobEvents, readCachedSearchSessionPage, readChapterBuildInput, readContinuationCursor, readSearchIndexFingerprintFromDatabase, readSearchIndexStatus, readWikgArchiveFormatVersion, rebuildArchiveSearchIndex, recordBuildJobInputRevision, removeChapter, requireArchiveUri, requireLocatedObjectOrArchiveUri, requireLocatedObjectUri, resetChapter, resolveBuildJobId, resolveDataDirPath, resolveEvidenceSelection, resolveEvidenceSelectionList, resolveWikiGraphCoreDatabasePath, resolveWikiGraphHomeDirectoryPath, resolveWikiGraphStateRootPath, resumeBuildJob, runBuildJobWorker, runBuildQueueGc, runSearchCacheGc, scoreEvidenceQuote, searchGraphNodes, setChapterSource, setChapterSummary, setChapterTitle, setFtsIndexEmbedded, sliceCandidateByOptionBudget, snapshotChapterKnowledgeGraphInput, snapshotChapterSummaryInput, splitCandidateByOptionBudget, suppressContainedRanges, testWikispineRuntime, updateBuildJobTarget, validateNarrowingResponse, validatePolicyResponse, validateSurfaceProtectionResponse, withLoggingContext, writeWikgArchive };
|