@opengeni/documents 0.2.31 → 0.2.36
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/index.d.ts +120 -6
- package/dist/index.js +416 -17
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +660 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Settings } from '@opengeni/config';
|
|
2
|
-
import { FileAsset,
|
|
2
|
+
import { FileAsset, KnowledgeSourceKind, DocumentSearchMode, AddDocumentRequest, DocumentCurationStatus, Document, CreateDocumentBaseRequest, DocumentBase, DocumentSearchResult } from '@opengeni/contracts';
|
|
3
3
|
import { Database } from '@opengeni/db';
|
|
4
4
|
import { ObjectStorage } from '@opengeni/storage';
|
|
5
5
|
|
|
@@ -8,6 +8,11 @@ declare const DEFAULT_DOCUMENT_EMBEDDING_MODEL = "text-embedding-3-large";
|
|
|
8
8
|
declare const DEFAULT_DOCUMENT_EMBEDDING_DIMENSIONS = 3072;
|
|
9
9
|
declare const DEFAULT_DOCUMENT_CHUNK_SIZE = 1200;
|
|
10
10
|
declare const DEFAULT_DOCUMENT_CHUNK_OVERLAP = 160;
|
|
11
|
+
declare const DEFAULT_DOCUMENT_CURATION_MODEL = "gpt-4o-mini";
|
|
12
|
+
declare const DOCUMENT_CURATION_MAX_INPUT_CHARS = 24000;
|
|
13
|
+
declare const DOCUMENT_CURATION_AUTO_FILE_CONFIDENCE = 0.75;
|
|
14
|
+
declare const DEFAULT_BASE_NAME = "Default";
|
|
15
|
+
declare const DEFAULT_BASE_DESCRIPTION = "Default base for dropped files and notes.";
|
|
11
16
|
type ParsedDocument = {
|
|
12
17
|
text: string;
|
|
13
18
|
metadata?: Record<string, unknown>;
|
|
@@ -29,10 +34,54 @@ type DocumentEmbedder = {
|
|
|
29
34
|
embedMany: (texts: string[]) => Promise<number[][]>;
|
|
30
35
|
embedQuery: (text: string) => Promise<number[]>;
|
|
31
36
|
};
|
|
37
|
+
type DocumentCurationCandidateBase = {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
description: string | null;
|
|
41
|
+
};
|
|
42
|
+
type DocumentCurationInput = {
|
|
43
|
+
/** Parsed document text, clipped to DOCUMENT_CURATION_MAX_INPUT_CHARS. */
|
|
44
|
+
text: string;
|
|
45
|
+
filename: string;
|
|
46
|
+
/** Current (usually filename-derived) title. */
|
|
47
|
+
title: string;
|
|
48
|
+
/** Candidate bases the document could be filed into (never its current base). */
|
|
49
|
+
bases: DocumentCurationCandidateBase[];
|
|
50
|
+
};
|
|
51
|
+
type DocumentCurationOutcome = {
|
|
52
|
+
title: string | null;
|
|
53
|
+
summary: string | null;
|
|
54
|
+
sourceKind: KnowledgeSourceKind | null;
|
|
55
|
+
topics: string[];
|
|
56
|
+
targetBaseId: string | null;
|
|
57
|
+
confidence: number;
|
|
58
|
+
reason: string | null;
|
|
59
|
+
};
|
|
60
|
+
type DocumentCurator = {
|
|
61
|
+
model: string;
|
|
62
|
+
curate: (input: DocumentCurationInput) => Promise<DocumentCurationOutcome>;
|
|
63
|
+
};
|
|
32
64
|
type DocumentServices = {
|
|
33
65
|
parser: DocumentParser;
|
|
34
66
|
chunker: DocumentChunker;
|
|
35
67
|
embedder: DocumentEmbedder;
|
|
68
|
+
/** Optional: names/summarizes/categorizes dropped documents during indexing. */
|
|
69
|
+
curator?: DocumentCurator | undefined;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Read-scoping for document queries. Fail-closed: when a caller supplies no
|
|
73
|
+
* filter, private documents are invisible (only their creator may see them,
|
|
74
|
+
* and only by passing their subject id).
|
|
75
|
+
*/
|
|
76
|
+
type DocumentAccessFilter = {
|
|
77
|
+
/** Grant subject id of the human viewer; null/undefined hides private docs. */
|
|
78
|
+
viewerSubjectId?: string | null | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Agent retrieval surface: only agent-enabled documents. Workspace-visible
|
|
81
|
+
* documents are available to every agent; private documents are available
|
|
82
|
+
* only when the agent carries the creating subject as its viewer subject.
|
|
83
|
+
*/
|
|
84
|
+
agentOnly?: boolean | undefined;
|
|
36
85
|
};
|
|
37
86
|
type DocumentSearchInput = {
|
|
38
87
|
workspaceId: string;
|
|
@@ -42,6 +91,7 @@ type DocumentSearchInput = {
|
|
|
42
91
|
mode?: DocumentSearchMode | undefined;
|
|
43
92
|
sourceKinds?: KnowledgeSourceKind[] | undefined;
|
|
44
93
|
aclTags?: string[] | undefined;
|
|
94
|
+
access?: DocumentAccessFilter | undefined;
|
|
45
95
|
};
|
|
46
96
|
type DocumentIndexHooks = {
|
|
47
97
|
beforeEmbed?: (input: {
|
|
@@ -91,6 +141,37 @@ declare class DeterministicEmbeddingProvider implements DocumentEmbedder {
|
|
|
91
141
|
embedMany(texts: string[]): Promise<number[][]>;
|
|
92
142
|
embedQuery(text: string): Promise<number[]>;
|
|
93
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Deterministic no-network curation: first meaningful line becomes the title,
|
|
146
|
+
* the opening text becomes the summary, and the kind is guessed from the
|
|
147
|
+
* filename/content type. Never proposes a base move (confidence 0). Used as
|
|
148
|
+
* the `heuristic` provider and as the in-pipeline fallback when the LLM
|
|
149
|
+
* curator fails — a drop must always end up named and summarized.
|
|
150
|
+
*/
|
|
151
|
+
declare function heuristicCuration(input: DocumentCurationInput, contentType?: string): DocumentCurationOutcome;
|
|
152
|
+
declare class HeuristicCurationProvider implements DocumentCurator {
|
|
153
|
+
readonly model = "heuristic";
|
|
154
|
+
curate(input: DocumentCurationInput): Promise<DocumentCurationOutcome>;
|
|
155
|
+
}
|
|
156
|
+
declare class OpenAICurationProvider implements DocumentCurator {
|
|
157
|
+
private client;
|
|
158
|
+
private readonly apiKey;
|
|
159
|
+
private readonly baseURL;
|
|
160
|
+
private readonly defaultHeaders;
|
|
161
|
+
private readonly defaultQuery;
|
|
162
|
+
readonly model: string;
|
|
163
|
+
constructor(args: {
|
|
164
|
+
apiKey?: string | undefined;
|
|
165
|
+
baseURL?: string | undefined;
|
|
166
|
+
defaultHeaders?: Record<string, string> | undefined;
|
|
167
|
+
defaultQuery?: Record<string, string> | undefined;
|
|
168
|
+
model?: string | undefined;
|
|
169
|
+
});
|
|
170
|
+
curate(input: DocumentCurationInput): Promise<DocumentCurationOutcome>;
|
|
171
|
+
private openai;
|
|
172
|
+
}
|
|
173
|
+
/** Parse + clamp model output; a targetBaseId outside the candidate list is dropped. */
|
|
174
|
+
declare function parseCurationOutcome(raw: string, bases: DocumentCurationCandidateBase[]): DocumentCurationOutcome;
|
|
94
175
|
declare function createDocumentServices(settings?: Settings, overrides?: Partial<DocumentServices>): DocumentServices;
|
|
95
176
|
declare function documentOpenAIEmbeddingConfig(settings?: Settings): {
|
|
96
177
|
apiKey?: string | undefined;
|
|
@@ -104,25 +185,58 @@ declare function createDocumentBase(db: Database, input: CreateDocumentBaseReque
|
|
|
104
185
|
}): Promise<DocumentBase>;
|
|
105
186
|
declare function listDocumentBases(db: Database, workspaceId: string): Promise<DocumentBase[]>;
|
|
106
187
|
declare function getDocumentBase(db: Database, workspaceId: string, baseId: string): Promise<DocumentBase | null>;
|
|
188
|
+
/**
|
|
189
|
+
* Find-or-create the workspace's Default base — where knowledge drops land
|
|
190
|
+
* before configured curation files them elsewhere. Matched by name
|
|
191
|
+
* (case-insensitive) so a user-created "Default" is adopted rather than
|
|
192
|
+
* duplicated.
|
|
193
|
+
*/
|
|
194
|
+
declare function ensureDefaultBase(db: Database, input: {
|
|
195
|
+
accountId: string;
|
|
196
|
+
workspaceId: string;
|
|
197
|
+
}): Promise<DocumentBase>;
|
|
107
198
|
declare function addDocumentToBase(db: Database, input: AddDocumentRequest & {
|
|
108
199
|
accountId: string;
|
|
109
200
|
workspaceId: string;
|
|
110
201
|
baseId: string;
|
|
202
|
+
createdBy?: string | null | undefined;
|
|
203
|
+
curationStatus?: DocumentCurationStatus | undefined;
|
|
204
|
+
access?: DocumentAccessFilter | undefined;
|
|
205
|
+
}): Promise<Document>;
|
|
206
|
+
/**
|
|
207
|
+
* Move a document and its indexed chunks to another base. With no explicit
|
|
208
|
+
* target, applies the stored curation suggestion. A 'suggested' or 'pending'
|
|
209
|
+
* document that gets moved counts as filed.
|
|
210
|
+
*/
|
|
211
|
+
declare function moveDocumentToBase(db: Database, input: {
|
|
212
|
+
accountId: string;
|
|
213
|
+
workspaceId: string;
|
|
214
|
+
documentId: string;
|
|
215
|
+
targetBaseId?: string | null | undefined;
|
|
216
|
+
access?: DocumentAccessFilter | undefined;
|
|
111
217
|
}): Promise<Document>;
|
|
112
218
|
declare function deleteDocumentFromBase(db: Database, input: {
|
|
113
219
|
accountId: string;
|
|
114
220
|
workspaceId: string;
|
|
115
221
|
baseId: string;
|
|
116
222
|
documentId: string;
|
|
223
|
+
access?: DocumentAccessFilter | undefined;
|
|
117
224
|
}): Promise<void>;
|
|
118
|
-
declare function listDocuments(db: Database, workspaceId: string, baseId: string): Promise<Document[]>;
|
|
119
|
-
declare function getDocument(db: Database, workspaceId: string, documentId: string): Promise<Document | null>;
|
|
120
|
-
declare function queueDocumentForReindex(db: Database, workspaceId: string, documentId: string): Promise<Document>;
|
|
225
|
+
declare function listDocuments(db: Database, workspaceId: string, baseId: string, access?: DocumentAccessFilter): Promise<Document[]>;
|
|
226
|
+
declare function getDocument(db: Database, workspaceId: string, documentId: string, access?: DocumentAccessFilter): Promise<Document | null>;
|
|
227
|
+
declare function queueDocumentForReindex(db: Database, workspaceId: string, documentId: string, access?: DocumentAccessFilter): Promise<Document>;
|
|
121
228
|
declare function indexDocumentNow(db: Database, objectStorage: ObjectStorage, workspaceId: string, documentId: string, services?: DocumentServices, hooks?: DocumentIndexHooks): Promise<Document>;
|
|
122
229
|
declare function searchDocuments(db: Database, input: DocumentSearchInput, services?: Pick<DocumentServices, "embedder">): Promise<DocumentSearchResult[]>;
|
|
123
|
-
declare function getDocumentChunk(db: Database, workspaceId: string, chunkId: string): Promise<DocumentSearchResult | null>;
|
|
230
|
+
declare function getDocumentChunk(db: Database, workspaceId: string, chunkId: string, access?: DocumentAccessFilter): Promise<DocumentSearchResult | null>;
|
|
231
|
+
/** Whether a single already-fetched document is readable by this human viewer. */
|
|
232
|
+
declare function canViewDocument(document: Pick<DocumentAccessRecord, "visibility" | "createdBy">, viewerSubjectId: string | null | undefined): boolean;
|
|
233
|
+
type DocumentAccessRecord = {
|
|
234
|
+
visibility: string;
|
|
235
|
+
createdBy: string | null;
|
|
236
|
+
agentAccess: boolean;
|
|
237
|
+
};
|
|
124
238
|
declare function parseDocumentBytes(bytes: Uint8Array, file: FileAsset, parser?: DocumentParser): Promise<ParsedDocument>;
|
|
125
239
|
declare function chunkText(text: string, maxChars?: number, overlapChars?: number): string[];
|
|
126
240
|
declare function deterministicEmbedding(text: string, dimensions?: number): number[];
|
|
127
241
|
|
|
128
|
-
export { DEFAULT_DOCUMENT_CHUNK_OVERLAP, DEFAULT_DOCUMENT_CHUNK_SIZE, DEFAULT_DOCUMENT_EMBEDDING_DIMENSIONS, DEFAULT_DOCUMENT_EMBEDDING_MODEL, DEFAULT_DOCUMENT_PARSER, DeterministicEmbeddingProvider, type DocumentChunk, type DocumentChunker, type DocumentEmbedder, type DocumentIndexHooks, type DocumentParser, type DocumentSearchInput, type DocumentServices, LiteParseDocumentParser, OpenAIEmbeddingProvider, type ParsedDocument, RecursiveTextChunker, addDocumentToBase, chunkText, createDocumentBase, createDocumentServices, deleteDocumentFromBase, deterministicEmbedding, documentOpenAIEmbeddingConfig, getDocument, getDocumentBase, getDocumentChunk, indexDocumentNow, listDocumentBases, listDocuments, parseDocumentBytes, queueDocumentForReindex, searchDocuments };
|
|
242
|
+
export { DEFAULT_BASE_DESCRIPTION, DEFAULT_BASE_NAME, DEFAULT_DOCUMENT_CHUNK_OVERLAP, DEFAULT_DOCUMENT_CHUNK_SIZE, DEFAULT_DOCUMENT_CURATION_MODEL, DEFAULT_DOCUMENT_EMBEDDING_DIMENSIONS, DEFAULT_DOCUMENT_EMBEDDING_MODEL, DEFAULT_DOCUMENT_PARSER, DOCUMENT_CURATION_AUTO_FILE_CONFIDENCE, DOCUMENT_CURATION_MAX_INPUT_CHARS, DeterministicEmbeddingProvider, type DocumentAccessFilter, type DocumentChunk, type DocumentChunker, type DocumentCurationCandidateBase, type DocumentCurationInput, type DocumentCurationOutcome, type DocumentCurator, type DocumentEmbedder, type DocumentIndexHooks, type DocumentParser, type DocumentSearchInput, type DocumentServices, HeuristicCurationProvider, LiteParseDocumentParser, OpenAICurationProvider, OpenAIEmbeddingProvider, type ParsedDocument, RecursiveTextChunker, addDocumentToBase, canViewDocument, chunkText, createDocumentBase, createDocumentServices, deleteDocumentFromBase, deterministicEmbedding, documentOpenAIEmbeddingConfig, ensureDefaultBase, getDocument, getDocumentBase, getDocumentChunk, heuristicCuration, indexDocumentNow, listDocumentBases, listDocuments, moveDocumentToBase, parseCurationOutcome, parseDocumentBytes, queueDocumentForReindex, searchDocuments };
|