@opengeni/documents 0.7.0-canary.0 → 0.8.2-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 CHANGED
@@ -166,6 +166,7 @@ export type DocumentSearchInput = {
166
166
  limit?: number | undefined;
167
167
  mode?: DocumentSearchMode | undefined;
168
168
  sourceKinds?: KnowledgeSourceKind[] | undefined;
169
+ authorityKinds?: DocumentAuthorityKind[] | undefined;
169
170
  aclTags?: string[] | undefined;
170
171
  access?: DocumentAccessFilter | undefined;
171
172
  };
package/dist/index.js CHANGED
@@ -844,7 +844,10 @@ async function getDocumentDefaultCollectionBackfillAudit(db, input) {
844
844
  operationsHasMore,
845
845
  operationsNextCursor: operationTail ? encodeDocumentMigrationAuditCursor(
846
846
  ["backfill-operations", input.accountId, input.runId],
847
- { timestamp: operationTail.createdAt, id: operationTail.operationId }
847
+ {
848
+ timestamp: operationTail.createdAt,
849
+ id: operationTail.operationId
850
+ }
848
851
  ) : null,
849
852
  receiptsHasMore,
850
853
  receiptsNextCursor: receiptTail ? encodeDocumentMigrationAuditCursor(
@@ -931,9 +934,14 @@ function decodeDocumentMigrationAuditCursor(value, parts, requireTimestamp) {
931
934
  ) || (requireTimestamp ? typeof parsed.t !== "string" || !Number.isFinite(new Date(parsed.t).getTime()) : parsed.t !== null)) {
932
935
  throw new Error("cursor payload");
933
936
  }
934
- return { timestamp: typeof parsed.t === "string" ? parsed.t : null, id: parsed.i };
937
+ return {
938
+ timestamp: typeof parsed.t === "string" ? parsed.t : null,
939
+ id: parsed.i
940
+ };
935
941
  } catch (error) {
936
- throw new Error("invalid document migration audit cursor", { cause: error });
942
+ throw new Error("invalid document migration audit cursor", {
943
+ cause: error
944
+ });
937
945
  }
938
946
  }
939
947
  async function reclassifyDocumentAuthority(db, input) {
@@ -1035,7 +1043,9 @@ function decodeDocumentAuthorityReclassificationCursor(value, scope) {
1035
1043
  }
1036
1044
  return { createdAt: parsed.t, operationId: parsed.i };
1037
1045
  } catch (error) {
1038
- throw new Error("invalid document authority receipt cursor", { cause: error });
1046
+ throw new Error("invalid document authority receipt cursor", {
1047
+ cause: error
1048
+ });
1039
1049
  }
1040
1050
  }
1041
1051
  async function addDocumentToBase(db, input) {
@@ -1576,7 +1586,11 @@ async function curateDroppedDocument(db, services, document, parsed, file) {
1576
1586
  return updated2 ?? document;
1577
1587
  }
1578
1588
  const bases = await listDocumentBases(db, document.workspaceId);
1579
- const candidates = bases.filter((base) => base.id !== document.baseId).map((base) => ({ id: base.id, name: base.name, description: base.description }));
1589
+ const candidates = bases.filter((base) => base.id !== document.baseId).map((base) => ({
1590
+ id: base.id,
1591
+ name: base.name,
1592
+ description: base.description
1593
+ }));
1580
1594
  const input = {
1581
1595
  text: parsed.text.slice(0, DOCUMENT_CURATION_MAX_INPUT_CHARS),
1582
1596
  filename: file.filename,
@@ -1715,6 +1729,7 @@ async function searchEffectiveDocuments(db, input, services = createDocumentServ
1715
1729
  limit: input.limit,
1716
1730
  mode: input.mode,
1717
1731
  sourceKinds: input.sourceKinds,
1732
+ authorityKinds: input.authorityKinds,
1718
1733
  aclTags: input.aclTags,
1719
1734
  // Construct the lower-level access filter here instead of spreading the
1720
1735
  // caller input, so an untyped/legacy access override is always ignored.
@@ -1744,6 +1759,7 @@ async function searchEffectiveKnowledge(db, input, services = createDocumentServ
1744
1759
  ...input.baseIds ? { baseIds: input.baseIds } : {},
1745
1760
  ...input.mode ? { mode: input.mode } : {},
1746
1761
  ...input.sourceKinds ? { sourceKinds: input.sourceKinds } : {},
1762
+ ...input.authorityKinds ? { authorityKinds: input.authorityKinds } : {},
1747
1763
  ...input.aclTags ? { aclTags: input.aclTags } : {},
1748
1764
  access
1749
1765
  },
@@ -1782,6 +1798,7 @@ async function searchEffectiveKnowledge(db, input, services = createDocumentServ
1782
1798
  ranked.map((result) => result.chunkId)
1783
1799
  ),
1784
1800
  eq(schema.documents.status, "ready"),
1801
+ ...input.authorityKinds?.length ? [inArray(schema.documents.authorityKind, input.authorityKinds)] : [],
1785
1802
  ...documentAccessConditions(input.workspaceId, access)
1786
1803
  )
1787
1804
  )
@@ -2182,7 +2199,10 @@ async function browseEffectiveKnowledge(db, input) {
2182
2199
  access,
2183
2200
  async (scopedDb) => {
2184
2201
  if (parent) {
2185
- const [authorizedParent] = await scopedDb.select({ id: schema.documents.id, indexSequence: schema.documents.indexSequence }).from(schema.documents).where(
2202
+ const [authorizedParent] = await scopedDb.select({
2203
+ id: schema.documents.id,
2204
+ indexSequence: schema.documents.indexSequence
2205
+ }).from(schema.documents).where(
2186
2206
  and(
2187
2207
  eq(schema.documents.accountId, input.accountId),
2188
2208
  eq(schema.documents.id, parent.id),
@@ -2191,7 +2211,10 @@ async function browseEffectiveKnowledge(db, input) {
2191
2211
  )
2192
2212
  ).limit(1);
2193
2213
  if (!authorizedParent) {
2194
- return selectKnowledgeBrowseRecords({ entries: [], hasMoreAfterEntries: false });
2214
+ return selectKnowledgeBrowseRecords({
2215
+ entries: [],
2216
+ hasMoreAfterEntries: false
2217
+ });
2195
2218
  }
2196
2219
  if (authorizedParent.indexSequence === null) {
2197
2220
  throw new Error("ready knowledge document is missing its index revision");
@@ -2279,7 +2302,11 @@ function encodeKnowledgeBrowseCursor(scope, position) {
2279
2302
  if (position < 0n) throw new Error("knowledge browse cursor position is invalid");
2280
2303
  const version = knowledgeBrowseCursorVersion(scope);
2281
2304
  return Buffer.from(
2282
- JSON.stringify({ v: version, s: knowledgeBrowseCursorScope(scope), q: position.toString() }),
2305
+ JSON.stringify({
2306
+ v: version,
2307
+ s: knowledgeBrowseCursorScope(scope),
2308
+ q: position.toString()
2309
+ }),
2283
2310
  "utf8"
2284
2311
  ).toString("base64url");
2285
2312
  }
@@ -2326,7 +2353,10 @@ function parseKnowledgeRecordId(value) {
2326
2353
  value
2327
2354
  );
2328
2355
  if (!match) throw new Error("invalid knowledge record id");
2329
- return { kind: match[1], id: match[2].toLowerCase() };
2356
+ return {
2357
+ kind: match[1],
2358
+ id: match[2].toLowerCase()
2359
+ };
2330
2360
  }
2331
2361
  function knowledgeDocumentRecord(document, citation = null, firstChunkId = null) {
2332
2362
  if (!document.indexedAt) throw new Error(`Ready document is missing indexed_at: ${document.id}`);
@@ -2743,6 +2773,9 @@ function documentSearchConditions(input, embeddingModel) {
2743
2773
  if (input.sourceKinds?.length) {
2744
2774
  conditions.push(inArray(schema.documents.sourceKind, input.sourceKinds));
2745
2775
  }
2776
+ if (input.authorityKinds?.length) {
2777
+ conditions.push(inArray(schema.documents.authorityKind, input.authorityKinds));
2778
+ }
2746
2779
  const aclTags = cleanStringArray(input.aclTags);
2747
2780
  if (aclTags.length > 0) {
2748
2781
  conditions.push(sql`${schema.documents.aclTags} @> ${JSON.stringify(aclTags)}::jsonb`);