@opengeni/documents 0.5.39 → 0.6.9-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +177 -5
- package/dist/index.js +881 -137
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +1227 -150
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Settings } from "@opengeni/config";
|
|
2
|
-
import type
|
|
2
|
+
import { type AddDocumentRequest, CreateDocumentBaseRequest, Document, DocumentAuthorityKind, DocumentBase, DocumentCurationStatus, DocumentSearchMode, DocumentSearchResult, DocumentStatus, DocumentVisibility, FileAsset, KnowledgeBrowseResponse, KnowledgeRecord, KnowledgeSearchResponse, KnowledgeSourceKind, ListIndexedDocumentsResponse, type ReclassifyDocumentAuthorityRequest, type RunDocumentDefaultCollectionBackfillRequest } from "@opengeni/contracts";
|
|
3
3
|
import { type Database } from "@opengeni/db";
|
|
4
|
-
import type
|
|
4
|
+
import { type ObjectStorage } from "@opengeni/storage";
|
|
5
5
|
export { projectKnowledgeRecord } from "./knowledge-projection.js";
|
|
6
6
|
export declare const DEFAULT_DOCUMENT_PARSER = "liteparse";
|
|
7
7
|
export declare const DEFAULT_DOCUMENT_EMBEDDING_MODEL = "text-embedding-3-large";
|
|
@@ -84,12 +84,43 @@ export type DocumentAccessFilter = {
|
|
|
84
84
|
* only when the agent carries the creating subject as its viewer subject.
|
|
85
85
|
*/
|
|
86
86
|
agentOnly?: boolean | undefined;
|
|
87
|
+
/** Exact attempt whose grant snapshot must be revalidated in the content query. */
|
|
88
|
+
authorizedPersonalAttempt?: {
|
|
89
|
+
accountId: string;
|
|
90
|
+
workspaceId: string;
|
|
91
|
+
sessionId: string;
|
|
92
|
+
attemptId: string;
|
|
93
|
+
} | undefined;
|
|
87
94
|
};
|
|
88
95
|
export type DocumentAuthority = {
|
|
89
96
|
kind: DocumentAuthorityKind;
|
|
90
97
|
workspaceId: string | null;
|
|
91
98
|
subjectId: string | null;
|
|
92
99
|
};
|
|
100
|
+
/** JSON-safe projection of the opaque capability minted by the API access layer. */
|
|
101
|
+
export type DocumentAccountAdminAuthorization = Readonly<{
|
|
102
|
+
authorizationId: string;
|
|
103
|
+
accountId: string;
|
|
104
|
+
actorSubjectId: string;
|
|
105
|
+
permission: "account:admin";
|
|
106
|
+
}>;
|
|
107
|
+
export type ReclassifyDocumentAuthorityInput = ReclassifyDocumentAuthorityRequest & {
|
|
108
|
+
accountId: string;
|
|
109
|
+
workspaceId: string;
|
|
110
|
+
documentId: string;
|
|
111
|
+
actorSubjectId: string;
|
|
112
|
+
accountAdminAuthorization: DocumentAccountAdminAuthorization | null;
|
|
113
|
+
};
|
|
114
|
+
export type RunDocumentDefaultCollectionBackfillInput = RunDocumentDefaultCollectionBackfillRequest & {
|
|
115
|
+
accountId: string;
|
|
116
|
+
workspaceId: string;
|
|
117
|
+
actorSubjectId: string;
|
|
118
|
+
accountAdminAuthorization: DocumentAccountAdminAuthorization;
|
|
119
|
+
};
|
|
120
|
+
export type AgentDocumentAuthorityContext = {
|
|
121
|
+
sessionId: string;
|
|
122
|
+
attemptId: string;
|
|
123
|
+
};
|
|
93
124
|
export type DocumentInventoryStatusCounts = Record<DocumentStatus, number>;
|
|
94
125
|
export type DocumentInventorySourceKindCounts = Record<KnowledgeSourceKind, number>;
|
|
95
126
|
export type DocumentInventoryAuthorityKindCounts = Record<DocumentAuthorityKind, number>;
|
|
@@ -135,6 +166,7 @@ export type EffectiveDocumentSearchInput = Omit<DocumentSearchInput, "access"> &
|
|
|
135
166
|
initiatingSubjectId: string;
|
|
136
167
|
/** Agent retrieval additionally enforces documents.agent_access. */
|
|
137
168
|
surface: "human" | "agent";
|
|
169
|
+
agentAuthority?: AgentDocumentAuthorityContext | undefined;
|
|
138
170
|
};
|
|
139
171
|
export type ListEffectiveIndexedDocumentsInput = {
|
|
140
172
|
accountId: string;
|
|
@@ -143,18 +175,22 @@ export type ListEffectiveIndexedDocumentsInput = {
|
|
|
143
175
|
initiatingSubjectId: string;
|
|
144
176
|
checkpoint?: string | undefined;
|
|
145
177
|
limit?: number | undefined;
|
|
178
|
+
agentAuthority?: AgentDocumentAuthorityContext | undefined;
|
|
146
179
|
};
|
|
147
180
|
export type EffectiveKnowledgeBrowseInput = {
|
|
148
181
|
accountId: string;
|
|
149
182
|
workspaceId: string;
|
|
150
183
|
/** Immutable human subject accepted for the logical request/turn. */
|
|
151
184
|
initiatingSubjectId: string;
|
|
185
|
+
/** Human inspection bypasses agent_access but still uses exact subject/RLS authority. */
|
|
186
|
+
surface?: "human" | "agent" | undefined;
|
|
152
187
|
/** Omit to browse top-level documents; pass a document record id for chunks. */
|
|
153
188
|
parentId?: string | undefined;
|
|
154
189
|
topic?: string | undefined;
|
|
155
190
|
sourceKinds?: KnowledgeSourceKind[] | undefined;
|
|
156
191
|
cursor?: string | undefined;
|
|
157
192
|
limit?: number | undefined;
|
|
193
|
+
agentAuthority?: AgentDocumentAuthorityContext | undefined;
|
|
158
194
|
};
|
|
159
195
|
export type DocumentIndexHooks = {
|
|
160
196
|
beforeEmbed?: (input: {
|
|
@@ -275,6 +311,61 @@ export declare function listDocumentBasesEnsuringDefault(db: Database, input: {
|
|
|
275
311
|
accountId: string;
|
|
276
312
|
workspaceId: string;
|
|
277
313
|
}): Promise<DocumentBase[]>;
|
|
314
|
+
export declare function runDocumentDefaultCollectionBackfill(db: Database, input: RunDocumentDefaultCollectionBackfillInput): Promise<{
|
|
315
|
+
runId: string;
|
|
316
|
+
operationId: string;
|
|
317
|
+
status: "completed" | "running";
|
|
318
|
+
lastWorkspaceId: string | null;
|
|
319
|
+
processedCount: number;
|
|
320
|
+
createdCount: number;
|
|
321
|
+
adoptedCount: number;
|
|
322
|
+
completedAt: string | null;
|
|
323
|
+
}>;
|
|
324
|
+
export declare function reclassifyDocumentAuthority(db: Database, input: ReclassifyDocumentAuthorityInput): Promise<{
|
|
325
|
+
operationId: string;
|
|
326
|
+
documentId: string;
|
|
327
|
+
previousAuthority: {
|
|
328
|
+
kind: "organization" | "personal" | "workspace";
|
|
329
|
+
workspaceId: string | null;
|
|
330
|
+
subjectId: string | null;
|
|
331
|
+
authorityId: string | null;
|
|
332
|
+
};
|
|
333
|
+
authority: {
|
|
334
|
+
kind: "organization" | "personal" | "workspace";
|
|
335
|
+
workspaceId: string | null;
|
|
336
|
+
subjectId: string | null;
|
|
337
|
+
authorityId: string | null;
|
|
338
|
+
};
|
|
339
|
+
createdAt: string;
|
|
340
|
+
}>;
|
|
341
|
+
export declare function listDocumentAuthorityReclassifications(db: Database, input: {
|
|
342
|
+
accountId: string;
|
|
343
|
+
workspaceId: string;
|
|
344
|
+
documentId: string;
|
|
345
|
+
actorSubjectId: string;
|
|
346
|
+
limit?: number | undefined;
|
|
347
|
+
cursor?: string | undefined;
|
|
348
|
+
}): Promise<{
|
|
349
|
+
receipts: {
|
|
350
|
+
operationId: string;
|
|
351
|
+
documentId: string;
|
|
352
|
+
previousAuthority: {
|
|
353
|
+
kind: "organization" | "personal" | "workspace";
|
|
354
|
+
workspaceId: string | null;
|
|
355
|
+
subjectId: string | null;
|
|
356
|
+
authorityId: string | null;
|
|
357
|
+
};
|
|
358
|
+
authority: {
|
|
359
|
+
kind: "organization" | "personal" | "workspace";
|
|
360
|
+
workspaceId: string | null;
|
|
361
|
+
subjectId: string | null;
|
|
362
|
+
authorityId: string | null;
|
|
363
|
+
};
|
|
364
|
+
createdAt: string;
|
|
365
|
+
}[];
|
|
366
|
+
hasMore: boolean;
|
|
367
|
+
nextCursor: string | null;
|
|
368
|
+
}>;
|
|
278
369
|
export declare function addDocumentToBase(db: Database, input: AddDocumentRequest & {
|
|
279
370
|
accountId: string;
|
|
280
371
|
workspaceId: string;
|
|
@@ -308,6 +399,14 @@ export declare function deleteDocumentFromBase(db: Database, input: {
|
|
|
308
399
|
access?: DocumentAccessFilter | undefined;
|
|
309
400
|
}): Promise<void>;
|
|
310
401
|
export declare function listDocuments(db: Database, workspaceId: string, baseId: string, access?: DocumentAccessFilter): Promise<Document[]>;
|
|
402
|
+
/**
|
|
403
|
+
* List Documents the human can discover and manage from the requested
|
|
404
|
+
* workspace. Organization Documents are account-wide, workspace Documents are
|
|
405
|
+
* local, activated organization-user Documents are portable across the owner's
|
|
406
|
+
* same-organization workspaces, and legacy personal rows remain anchored to
|
|
407
|
+
* their ingestion workspace through documentAccessConditions.
|
|
408
|
+
*/
|
|
409
|
+
export declare function listAccessibleDocuments(db: Database, workspaceId: string, access: DocumentAccessFilter): Promise<Document[]>;
|
|
311
410
|
/**
|
|
312
411
|
* List newly ready documents in the same effective scope used by agent
|
|
313
412
|
* retrieval. The opaque checkpoint is bound to the account, requesting
|
|
@@ -327,9 +426,36 @@ export declare function decodeDocumentIndexCheckpoint(value: string, scope: {
|
|
|
327
426
|
initiatingSubjectId: string;
|
|
328
427
|
}): bigint;
|
|
329
428
|
export declare function getDocument(db: Database, workspaceId: string, documentId: string, access?: DocumentAccessFilter): Promise<Document | null>;
|
|
429
|
+
/**
|
|
430
|
+
* Resolve the immutable source file through Document authority in the requested
|
|
431
|
+
* workspace. The file remains physically owned by its ingestion workspace;
|
|
432
|
+
* callers never gain generic access to that workspace's file inventory.
|
|
433
|
+
*/
|
|
434
|
+
export declare function getDocumentOriginalFile(db: Database, input: {
|
|
435
|
+
accountId: string;
|
|
436
|
+
workspaceId: string;
|
|
437
|
+
documentId: string;
|
|
438
|
+
access: DocumentAccessFilter;
|
|
439
|
+
}): Promise<FileAsset | null>;
|
|
440
|
+
/**
|
|
441
|
+
* Internal ingestion-only read used after the worker has independently resolved
|
|
442
|
+
* and fenced the immutable document authority tuple. It deliberately does not
|
|
443
|
+
* apply provider retrieval authorization because a new Drive document must be
|
|
444
|
+
* indexed before its first ACL evidence can be attached. User, API, MCP, and
|
|
445
|
+
* agent reads must use getDocument/effective retrieval instead.
|
|
446
|
+
*/
|
|
447
|
+
export declare function getDocumentForIndexing(db: Database, workspaceId: string, documentId: string): Promise<Document | null>;
|
|
330
448
|
export declare function queueDocumentForReindex(db: Database, workspaceId: string, documentId: string, access?: DocumentAccessFilter, organizationAuthorityGranted?: boolean): Promise<Document>;
|
|
331
449
|
export declare function indexDocumentNow(db: Database, objectStorage: ObjectStorage, workspaceId: string, documentId: string, services?: DocumentServices, hooks?: DocumentIndexHooks, access?: DocumentAccessFilter): Promise<Document>;
|
|
332
450
|
export declare function searchDocuments(db: Database, input: DocumentSearchInput, services?: Pick<DocumentServices, "embedder">): Promise<DocumentSearchResult[]>;
|
|
451
|
+
export type DocumentCandidateRelevanceFloor = {
|
|
452
|
+
vectorScore: number;
|
|
453
|
+
keywordScore: number;
|
|
454
|
+
};
|
|
455
|
+
export declare function selectDocumentSearchCandidateWindow(merged: DocumentSearchResult[], limit: number, relevanceFloor?: DocumentCandidateRelevanceFloor): {
|
|
456
|
+
results: DocumentSearchResult[];
|
|
457
|
+
belowRelevanceFloor: number;
|
|
458
|
+
};
|
|
333
459
|
/**
|
|
334
460
|
* Canonical effective retrieval composition for API, SDK, and MCP surfaces.
|
|
335
461
|
* Callers supply the already-authorized immutable initiating subject; no
|
|
@@ -343,12 +469,48 @@ export declare function searchEffectiveDocuments(db: Database, input: EffectiveD
|
|
|
343
469
|
* ranking and response construction disappears rather than leaking stale data.
|
|
344
470
|
*/
|
|
345
471
|
export declare function searchEffectiveKnowledge(db: Database, input: EffectiveDocumentSearchInput, services?: Pick<DocumentServices, "embedder">): Promise<KnowledgeSearchResponse>;
|
|
472
|
+
type KnowledgeSearchCandidate = {
|
|
473
|
+
record: KnowledgeRecord;
|
|
474
|
+
semanticScore: number;
|
|
475
|
+
matchType: DocumentSearchMode;
|
|
476
|
+
vectorScore: number | null;
|
|
477
|
+
keywordScore: number | null;
|
|
478
|
+
};
|
|
479
|
+
type KnowledgeSearchSelectionInput = {
|
|
480
|
+
candidates: KnowledgeSearchCandidate[];
|
|
481
|
+
rankedCandidateCount: number;
|
|
482
|
+
requestedLimit: number;
|
|
483
|
+
alreadyBelowRelevanceFloor?: number | undefined;
|
|
484
|
+
now?: Date | undefined;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* Deterministic, content-safe final selection over already-authorized and
|
|
488
|
+
* freshly rechecked Knowledge candidates. Exported for boundary tests; callers
|
|
489
|
+
* must never use it as a substitute for the database authorization pass above.
|
|
490
|
+
*/
|
|
491
|
+
export declare function selectKnowledgeSearchResults(input: KnowledgeSearchSelectionInput): KnowledgeSearchResponse;
|
|
492
|
+
type KnowledgeBrowseEntry = {
|
|
493
|
+
record: KnowledgeRecord;
|
|
494
|
+
cursorAfter: string;
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* Bound a browse page without skipping records. Tail records omitted for the
|
|
498
|
+
* response budget remain behind the returned cursor. If one complete record is
|
|
499
|
+
* itself too large, return a deterministic discovery projection; knowledge_get
|
|
500
|
+
* remains the freshly authorized full-record path.
|
|
501
|
+
*/
|
|
502
|
+
export declare function selectKnowledgeBrowseRecords(input: {
|
|
503
|
+
entries: KnowledgeBrowseEntry[];
|
|
504
|
+
hasMoreAfterEntries: boolean;
|
|
505
|
+
}): KnowledgeBrowseResponse;
|
|
346
506
|
/** Fetch one stable Knowledge record with a fresh authorization check. */
|
|
347
507
|
export declare function getEffectiveKnowledgeRecord(db: Database, input: {
|
|
348
508
|
accountId: string;
|
|
349
509
|
workspaceId: string;
|
|
350
510
|
initiatingSubjectId: string;
|
|
511
|
+
surface?: "human" | "agent" | undefined;
|
|
351
512
|
id: string;
|
|
513
|
+
agentAuthority?: AgentDocumentAuthorityContext | undefined;
|
|
352
514
|
}): Promise<KnowledgeRecord | null>;
|
|
353
515
|
/**
|
|
354
516
|
* Browse top-level authorized documents or the chunks of one authorized
|
|
@@ -361,6 +523,7 @@ type KnowledgeBrowseCursorScope = {
|
|
|
361
523
|
workspaceId: string;
|
|
362
524
|
initiatingSubjectId: string;
|
|
363
525
|
parentId: string | null;
|
|
526
|
+
parentRevision?: string | null | undefined;
|
|
364
527
|
topic: string | null;
|
|
365
528
|
sourceKinds: readonly string[];
|
|
366
529
|
};
|
|
@@ -373,17 +536,26 @@ export declare function resolveDocumentAuthority(input: {
|
|
|
373
536
|
workspaceId: string;
|
|
374
537
|
initiatingSubjectId?: string | null | undefined;
|
|
375
538
|
}): DocumentAuthority;
|
|
539
|
+
export declare function resolveEffectiveDocumentAccess(_db: Database, input: {
|
|
540
|
+
accountId: string;
|
|
541
|
+
workspaceId: string;
|
|
542
|
+
initiatingSubjectId: string;
|
|
543
|
+
surface: "human" | "agent";
|
|
544
|
+
agentAuthority?: AgentDocumentAuthorityContext | undefined;
|
|
545
|
+
}): Promise<DocumentAccessFilter>;
|
|
376
546
|
/**
|
|
377
547
|
* Whether a single already-fetched document is readable in this workspace.
|
|
378
548
|
*
|
|
379
|
-
* Keep this compatibility predicate as strict as SQL/RLS: personal
|
|
380
|
-
* remains
|
|
381
|
-
* authority
|
|
549
|
+
* Keep this compatibility predicate as strict as SQL/RLS: legacy personal
|
|
550
|
+
* authority remains origin-workspace anchored while activated personal
|
|
551
|
+
* authority has a null workspace and follows the exact owner within the org.
|
|
382
552
|
*/
|
|
383
553
|
export declare function canViewDocument(document: Pick<DocumentAccessRecord, "authorityKind" | "authoritySubjectId"> & {
|
|
384
554
|
authorityWorkspaceId?: string | null | undefined;
|
|
385
555
|
}, viewerSubjectId: string | null | undefined, workspaceId?: string | null | undefined): boolean;
|
|
386
556
|
type DocumentAccessRecord = {
|
|
557
|
+
id: string;
|
|
558
|
+
authorityId: string | null;
|
|
387
559
|
authorityKind: string;
|
|
388
560
|
authorityWorkspaceId: string | null;
|
|
389
561
|
authoritySubjectId: string | null;
|