@promptev/context-engine 0.0.2 → 0.0.3

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.cts CHANGED
@@ -5,26 +5,13 @@ import { H as Hooks, R as RedactionPolicy, U as UsageEvent, P as ProgressEvent,
5
5
  export { D as DocumentReport, a as RedactionRule, b as RedactionRuleInit, c as applyRedaction, e as emitError, d as emitProgress, f as emitToolCall, g as emitUsage, h as graphUnits, u as unitsForFile } from './redaction-BqD_DEUQ.cjs';
6
6
  import { E as Embedder, S as StorageBackend, F as FetchImpl } from './storage-Dvpq2xAC.cjs';
7
7
  export { C as ChunkRow, a as EmbedKind, P as PostgresBackend, b as SearchScope, c as buildEmbedder } from './storage-Dvpq2xAC.cjs';
8
+ import { P as Principals, U as Unset, S as ScopeInput, K as KnowledgeComputeFn, T as Trusted } from './mcp-BKSmxayM.cjs';
9
+ export { a as KNOWLEDGE_ACTIONS, b as KNOWLEDGE_TOOL_DESCRIPTION, c as KnowledgeAction, d as Scope, e as TRUSTED, f as UNSCOPED, g as UNSET, h as callKnowledgeTool, i as createMcpApp, k as knowledgeToolDefinition, n as narrowToCeiling, r as resolvePrincipals, j as resolveScope } from './mcp-BKSmxayM.cjs';
8
10
  import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-P9pRb4Ol.cjs';
9
11
  export { c as ToolKind, d as configSchema } from './governance-P9pRb4Ol.cjs';
10
- export { createMcpApp } from './mcp.cjs';
11
12
  import 'zod';
12
13
  import 'node:http';
13
14
 
14
- /**
15
- * Sentinels distinguishing omitted arguments from real values, including null.
16
- *
17
- * UNSET: "argument omitted" vs null (e.g. updateDocument acl=null means unrestricted).
18
- * TRUSTED: trusted caller, ACL filtering disabled. Truthy on purpose so
19
- * `if (principals)` does not treat a trusted caller as anonymous.
20
- */
21
- declare const UNSET: unique symbol;
22
- type Unset = typeof UNSET;
23
- declare const TRUSTED: unique symbol;
24
- type Trusted = typeof TRUSTED;
25
- type Principals = string[] | null | typeof TRUSTED | undefined;
26
- declare function resolvePrincipals(value: Principals, method: string): string[] | null;
27
-
28
15
  type Mode$1 = "hybrid" | "graph";
29
16
  interface IngestRequest {
30
17
  content?: Buffer | null;
@@ -79,17 +66,11 @@ declare function getDocumentText(documentId: string, opts: {
79
66
  secretKey?: string | Buffer | null;
80
67
  hooks?: Hooks;
81
68
  }): Promise<string>;
82
- /**
83
- * Page through documents in scope, newest first.
84
- *
85
- * `redaction` masks `documentType` — unconstrained free text an LLM wrote
86
- * after reading the document body. `name`/`description` remain
87
- * intentionally unmasked: both are CALLER-set at ingest time, not text the
88
- * pipeline derived from the document body.
89
- */
90
69
  declare function listDocuments(opts: {
91
70
  pool: Pool;
92
71
  sourceId?: string | null;
72
+ /** OR-of-many, ONE keyset-paged query across all of them; with `sourceId`, their union. */
73
+ sourceIds?: string[] | null;
93
74
  principals?: string[] | null;
94
75
  cursor?: unknown;
95
76
  limit?: number;
@@ -315,7 +296,9 @@ interface RunSearchOpts {
315
296
  topK?: number;
316
297
  mode?: Mode;
317
298
  compressToTokens?: number | null;
318
- graphRanked?: string[] | null;
299
+ /** A list, or a promise of one: passing a promise lets the graph leg run
300
+ * BESIDE the hybrid legs instead of ahead of them. */
301
+ graphRanked?: string[] | Promise<string[] | null> | null;
319
302
  redaction?: RedactionPolicy | null;
320
303
  }
321
304
  /**
@@ -466,7 +449,13 @@ declare class ContextEngine implements ToolEngine {
466
449
  documentIds?: string[] | null;
467
450
  principals?: Principals;
468
451
  topK?: number;
469
- mode?: "hybrid" | "graph";
452
+ /**
453
+ * Omit it (or pass null) and the mode is worked out from the documents
454
+ * in scope: the graph leg runs when this deployment has a graph AND
455
+ * something in scope was ingested with `mode: "graph"`. Naming one
456
+ * forces it. The graph leg ADDS to the hybrid legs, never replaces them.
457
+ */
458
+ mode?: "hybrid" | "graph" | null;
470
459
  compressToTokens?: number | null;
471
460
  redaction?: RedactionPolicy | null;
472
461
  }): Promise<SearchResult>;
@@ -476,8 +465,25 @@ declare class ContextEngine implements ToolEngine {
476
465
  * caller can never distinguish "doesn't exist" from "exists but you
477
466
  * can't see it").
478
467
  */
468
+ /**
469
+ * How long a failed graph probe is remembered. One refused connection must
470
+ * not become one refused connection per request, and must not be permanent
471
+ * either — the database may come back.
472
+ */
473
+ private static readonly GRAPH_PROBE_BACKOFF_MS;
474
+ private graphUnreachableUntil;
475
+ /**
476
+ * Is the graph database actually up?
477
+ *
478
+ * `graph.enabled` says the deployment is CONFIGURED, not that Neo4j is
479
+ * answering. Choosing the graph leg when it is unreachable buys a connection
480
+ * timeout on every search and no extra results, so a mode-less search checks
481
+ * first and remembers a failure briefly.
482
+ */
483
+ private graphIsReachable;
479
484
  getDocument(documentId: string, opts?: {
480
485
  principals?: Principals;
486
+ redaction?: RedactionPolicy | null;
481
487
  }): Promise<Record<string, unknown>>;
482
488
  deleteDocument(documentId: string, opts?: {
483
489
  principals?: Principals;
@@ -502,17 +508,78 @@ declare class ContextEngine implements ToolEngine {
502
508
  getDocumentText(documentId: string, opts?: {
503
509
  principals?: Principals;
504
510
  }): Promise<string>;
511
+ /**
512
+ * The ONE knowledge tool, as a library call. See `knowledge-tool.ts`.
513
+ *
514
+ * The same function the MCP server serves — an application driving its own
515
+ * agent loop hands its model this one door to the corpus without speaking
516
+ * MCP at all, and cannot get a different answer, because there is one
517
+ * implementation behind both surfaces.
518
+ */
519
+ searchKnowledgeBase(args: {
520
+ action: string;
521
+ principals?: Principals;
522
+ scope: ScopeInput;
523
+ query?: string | null;
524
+ document_id?: string | null;
525
+ source_ids?: string[] | null;
526
+ document_ids?: string[] | null;
527
+ entity?: string | null;
528
+ depth?: number | null;
529
+ category?: string | null;
530
+ label?: string | null;
531
+ entity_type?: string | null;
532
+ top_k?: number | null;
533
+ mode?: string | null;
534
+ limit?: number | null;
535
+ cursor?: unknown;
536
+ redaction?: RedactionPolicy | null;
537
+ compute?: KnowledgeComputeFn | null;
538
+ map_reduce?: ((instruction: string, opts: Record<string, unknown>) => Promise<Record<string, unknown>>) | null;
539
+ start?: number | null;
540
+ end?: number | null;
541
+ max_chars?: number | null;
542
+ }): Promise<Record<string, unknown>>;
543
+ /** Read one document in order, a range of chunks at a time. */
544
+ getChunks(documentId: string, opts?: {
545
+ principals?: Principals;
546
+ start?: number | null;
547
+ end?: number | null;
548
+ redaction?: RedactionPolicy | null;
549
+ }): Promise<Record<string, unknown>>;
550
+ /**
551
+ * Several whole documents at once, each ACL-checked. An id that is absent OR
552
+ * not visible is simply missing from the result, never an error — the same
553
+ * non-disclosure `getDocument` gives, which a batch read is the classic
554
+ * place to lose.
555
+ */
556
+ getDocuments(documentIds: string[], opts?: {
557
+ principals?: Principals;
558
+ redaction?: RedactionPolicy | null;
559
+ }): Promise<Array<Record<string, unknown>>>;
560
+ /** Ask the same question of every document in scope. */
561
+ mapReduce(instruction: string, opts?: {
562
+ principals?: Principals;
563
+ sourceIds?: string[] | null;
564
+ documentIds?: string[] | null;
565
+ limit?: number | null;
566
+ maxConcurrency?: number | null;
567
+ redaction?: RedactionPolicy | null;
568
+ }): Promise<Record<string, unknown>>;
505
569
  listDocuments(opts?: {
506
570
  sourceId?: string | null;
571
+ sourceIds?: string[] | null;
507
572
  principals?: Principals;
508
573
  cursor?: unknown;
509
574
  limit?: number;
575
+ redaction?: RedactionPolicy | null;
510
576
  }): Promise<Record<string, unknown>>;
511
577
  queryStructured(question: string, opts?: {
512
578
  sourceIds?: string[] | null;
513
579
  principals?: Principals;
514
580
  docType?: string | null;
515
581
  limit?: number;
582
+ redaction?: RedactionPolicy | null;
516
583
  }): Promise<Record<string, unknown>>;
517
584
  compute(instruction: string, opts?: {
518
585
  sourceIds?: string[] | null;
@@ -866,4 +933,4 @@ declare function functionTool(fn: (...args: never[]) => unknown): CanonicalTool;
866
933
  /** Bumped by CI on every main merge; 0.0.0 = pre-first-release. */
867
934
  declare const __version__ = "0.0.0";
868
935
 
869
- export { ApprovalExpired, ApprovalNotPending, type ApprovalRecord, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, type ComputeDocument, type ComputeFrames, ContextEngine, ContextEngineConfig, DEFAULT_LEG_WEIGHT, DocumentNotFoundError, EXTRACTION_VERSION, Embedder, EngineActionError, ExtraMissingError, Extracted, ExtractionConfig, type ExtractionResult, GraphLegUnavailable, type Hit, Hooks, InProcessRunner, IngestReport, LLMClient, LLMConfig, type Principals, ProgressEvent, RedactionPolicy, RerankerConfig, type SearchResult, StorageBackend, TRUSTED, type TaskRunner, type TaskStatus, ToolConfig, type Trusted, UNSET, type Unset, UsageEvent, __version__, buildLlmClient, callLlm, compute, computeOverFrames, decryptDict, encryptDict, extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, resolvePrincipals, rrfFuse, runMigrate, runSearch, shouldRequireApproval, upsertRegistry };
936
+ export { ApprovalExpired, ApprovalNotPending, type ApprovalRecord, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, type ComputeDocument, type ComputeFrames, ContextEngine, ContextEngineConfig, DEFAULT_LEG_WEIGHT, DocumentNotFoundError, EXTRACTION_VERSION, Embedder, EngineActionError, ExtraMissingError, Extracted, ExtractionConfig, type ExtractionResult, GraphLegUnavailable, type Hit, Hooks, InProcessRunner, IngestReport, KnowledgeComputeFn, LLMClient, LLMConfig, Principals, ProgressEvent, RedactionPolicy, RerankerConfig, ScopeInput, type SearchResult, StorageBackend, type TaskRunner, type TaskStatus, ToolConfig, Trusted, Unset, UsageEvent, __version__, buildLlmClient, callLlm, compute, computeOverFrames, decryptDict, encryptDict, extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, rrfFuse, runMigrate, runSearch, shouldRequireApproval, upsertRegistry };
package/dist/index.d.ts CHANGED
@@ -5,26 +5,13 @@ import { H as Hooks, R as RedactionPolicy, U as UsageEvent, P as ProgressEvent,
5
5
  export { D as DocumentReport, a as RedactionRule, b as RedactionRuleInit, c as applyRedaction, e as emitError, d as emitProgress, f as emitToolCall, g as emitUsage, h as graphUnits, u as unitsForFile } from './redaction-BqD_DEUQ.js';
6
6
  import { E as Embedder, S as StorageBackend, F as FetchImpl } from './storage-CJrKgJeJ.js';
7
7
  export { C as ChunkRow, a as EmbedKind, P as PostgresBackend, b as SearchScope, c as buildEmbedder } from './storage-CJrKgJeJ.js';
8
+ import { P as Principals, U as Unset, S as ScopeInput, K as KnowledgeComputeFn, T as Trusted } from './mcp-BKSmxayM.js';
9
+ export { a as KNOWLEDGE_ACTIONS, b as KNOWLEDGE_TOOL_DESCRIPTION, c as KnowledgeAction, d as Scope, e as TRUSTED, f as UNSCOPED, g as UNSET, h as callKnowledgeTool, i as createMcpApp, k as knowledgeToolDefinition, n as narrowToCeiling, r as resolvePrincipals, j as resolveScope } from './mcp-BKSmxayM.js';
8
10
  import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-BLPK7NMe.js';
9
11
  export { c as ToolKind, d as configSchema } from './governance-BLPK7NMe.js';
10
- export { createMcpApp } from './mcp.js';
11
12
  import 'zod';
12
13
  import 'node:http';
13
14
 
14
- /**
15
- * Sentinels distinguishing omitted arguments from real values, including null.
16
- *
17
- * UNSET: "argument omitted" vs null (e.g. updateDocument acl=null means unrestricted).
18
- * TRUSTED: trusted caller, ACL filtering disabled. Truthy on purpose so
19
- * `if (principals)` does not treat a trusted caller as anonymous.
20
- */
21
- declare const UNSET: unique symbol;
22
- type Unset = typeof UNSET;
23
- declare const TRUSTED: unique symbol;
24
- type Trusted = typeof TRUSTED;
25
- type Principals = string[] | null | typeof TRUSTED | undefined;
26
- declare function resolvePrincipals(value: Principals, method: string): string[] | null;
27
-
28
15
  type Mode$1 = "hybrid" | "graph";
29
16
  interface IngestRequest {
30
17
  content?: Buffer | null;
@@ -79,17 +66,11 @@ declare function getDocumentText(documentId: string, opts: {
79
66
  secretKey?: string | Buffer | null;
80
67
  hooks?: Hooks;
81
68
  }): Promise<string>;
82
- /**
83
- * Page through documents in scope, newest first.
84
- *
85
- * `redaction` masks `documentType` — unconstrained free text an LLM wrote
86
- * after reading the document body. `name`/`description` remain
87
- * intentionally unmasked: both are CALLER-set at ingest time, not text the
88
- * pipeline derived from the document body.
89
- */
90
69
  declare function listDocuments(opts: {
91
70
  pool: Pool;
92
71
  sourceId?: string | null;
72
+ /** OR-of-many, ONE keyset-paged query across all of them; with `sourceId`, their union. */
73
+ sourceIds?: string[] | null;
93
74
  principals?: string[] | null;
94
75
  cursor?: unknown;
95
76
  limit?: number;
@@ -315,7 +296,9 @@ interface RunSearchOpts {
315
296
  topK?: number;
316
297
  mode?: Mode;
317
298
  compressToTokens?: number | null;
318
- graphRanked?: string[] | null;
299
+ /** A list, or a promise of one: passing a promise lets the graph leg run
300
+ * BESIDE the hybrid legs instead of ahead of them. */
301
+ graphRanked?: string[] | Promise<string[] | null> | null;
319
302
  redaction?: RedactionPolicy | null;
320
303
  }
321
304
  /**
@@ -466,7 +449,13 @@ declare class ContextEngine implements ToolEngine {
466
449
  documentIds?: string[] | null;
467
450
  principals?: Principals;
468
451
  topK?: number;
469
- mode?: "hybrid" | "graph";
452
+ /**
453
+ * Omit it (or pass null) and the mode is worked out from the documents
454
+ * in scope: the graph leg runs when this deployment has a graph AND
455
+ * something in scope was ingested with `mode: "graph"`. Naming one
456
+ * forces it. The graph leg ADDS to the hybrid legs, never replaces them.
457
+ */
458
+ mode?: "hybrid" | "graph" | null;
470
459
  compressToTokens?: number | null;
471
460
  redaction?: RedactionPolicy | null;
472
461
  }): Promise<SearchResult>;
@@ -476,8 +465,25 @@ declare class ContextEngine implements ToolEngine {
476
465
  * caller can never distinguish "doesn't exist" from "exists but you
477
466
  * can't see it").
478
467
  */
468
+ /**
469
+ * How long a failed graph probe is remembered. One refused connection must
470
+ * not become one refused connection per request, and must not be permanent
471
+ * either — the database may come back.
472
+ */
473
+ private static readonly GRAPH_PROBE_BACKOFF_MS;
474
+ private graphUnreachableUntil;
475
+ /**
476
+ * Is the graph database actually up?
477
+ *
478
+ * `graph.enabled` says the deployment is CONFIGURED, not that Neo4j is
479
+ * answering. Choosing the graph leg when it is unreachable buys a connection
480
+ * timeout on every search and no extra results, so a mode-less search checks
481
+ * first and remembers a failure briefly.
482
+ */
483
+ private graphIsReachable;
479
484
  getDocument(documentId: string, opts?: {
480
485
  principals?: Principals;
486
+ redaction?: RedactionPolicy | null;
481
487
  }): Promise<Record<string, unknown>>;
482
488
  deleteDocument(documentId: string, opts?: {
483
489
  principals?: Principals;
@@ -502,17 +508,78 @@ declare class ContextEngine implements ToolEngine {
502
508
  getDocumentText(documentId: string, opts?: {
503
509
  principals?: Principals;
504
510
  }): Promise<string>;
511
+ /**
512
+ * The ONE knowledge tool, as a library call. See `knowledge-tool.ts`.
513
+ *
514
+ * The same function the MCP server serves — an application driving its own
515
+ * agent loop hands its model this one door to the corpus without speaking
516
+ * MCP at all, and cannot get a different answer, because there is one
517
+ * implementation behind both surfaces.
518
+ */
519
+ searchKnowledgeBase(args: {
520
+ action: string;
521
+ principals?: Principals;
522
+ scope: ScopeInput;
523
+ query?: string | null;
524
+ document_id?: string | null;
525
+ source_ids?: string[] | null;
526
+ document_ids?: string[] | null;
527
+ entity?: string | null;
528
+ depth?: number | null;
529
+ category?: string | null;
530
+ label?: string | null;
531
+ entity_type?: string | null;
532
+ top_k?: number | null;
533
+ mode?: string | null;
534
+ limit?: number | null;
535
+ cursor?: unknown;
536
+ redaction?: RedactionPolicy | null;
537
+ compute?: KnowledgeComputeFn | null;
538
+ map_reduce?: ((instruction: string, opts: Record<string, unknown>) => Promise<Record<string, unknown>>) | null;
539
+ start?: number | null;
540
+ end?: number | null;
541
+ max_chars?: number | null;
542
+ }): Promise<Record<string, unknown>>;
543
+ /** Read one document in order, a range of chunks at a time. */
544
+ getChunks(documentId: string, opts?: {
545
+ principals?: Principals;
546
+ start?: number | null;
547
+ end?: number | null;
548
+ redaction?: RedactionPolicy | null;
549
+ }): Promise<Record<string, unknown>>;
550
+ /**
551
+ * Several whole documents at once, each ACL-checked. An id that is absent OR
552
+ * not visible is simply missing from the result, never an error — the same
553
+ * non-disclosure `getDocument` gives, which a batch read is the classic
554
+ * place to lose.
555
+ */
556
+ getDocuments(documentIds: string[], opts?: {
557
+ principals?: Principals;
558
+ redaction?: RedactionPolicy | null;
559
+ }): Promise<Array<Record<string, unknown>>>;
560
+ /** Ask the same question of every document in scope. */
561
+ mapReduce(instruction: string, opts?: {
562
+ principals?: Principals;
563
+ sourceIds?: string[] | null;
564
+ documentIds?: string[] | null;
565
+ limit?: number | null;
566
+ maxConcurrency?: number | null;
567
+ redaction?: RedactionPolicy | null;
568
+ }): Promise<Record<string, unknown>>;
505
569
  listDocuments(opts?: {
506
570
  sourceId?: string | null;
571
+ sourceIds?: string[] | null;
507
572
  principals?: Principals;
508
573
  cursor?: unknown;
509
574
  limit?: number;
575
+ redaction?: RedactionPolicy | null;
510
576
  }): Promise<Record<string, unknown>>;
511
577
  queryStructured(question: string, opts?: {
512
578
  sourceIds?: string[] | null;
513
579
  principals?: Principals;
514
580
  docType?: string | null;
515
581
  limit?: number;
582
+ redaction?: RedactionPolicy | null;
516
583
  }): Promise<Record<string, unknown>>;
517
584
  compute(instruction: string, opts?: {
518
585
  sourceIds?: string[] | null;
@@ -866,4 +933,4 @@ declare function functionTool(fn: (...args: never[]) => unknown): CanonicalTool;
866
933
  /** Bumped by CI on every main merge; 0.0.0 = pre-first-release. */
867
934
  declare const __version__ = "0.0.0";
868
935
 
869
- export { ApprovalExpired, ApprovalNotPending, type ApprovalRecord, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, type ComputeDocument, type ComputeFrames, ContextEngine, ContextEngineConfig, DEFAULT_LEG_WEIGHT, DocumentNotFoundError, EXTRACTION_VERSION, Embedder, EngineActionError, ExtraMissingError, Extracted, ExtractionConfig, type ExtractionResult, GraphLegUnavailable, type Hit, Hooks, InProcessRunner, IngestReport, LLMClient, LLMConfig, type Principals, ProgressEvent, RedactionPolicy, RerankerConfig, type SearchResult, StorageBackend, TRUSTED, type TaskRunner, type TaskStatus, ToolConfig, type Trusted, UNSET, type Unset, UsageEvent, __version__, buildLlmClient, callLlm, compute, computeOverFrames, decryptDict, encryptDict, extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, resolvePrincipals, rrfFuse, runMigrate, runSearch, shouldRequireApproval, upsertRegistry };
936
+ export { ApprovalExpired, ApprovalNotPending, type ApprovalRecord, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, type ComputeDocument, type ComputeFrames, ContextEngine, ContextEngineConfig, DEFAULT_LEG_WEIGHT, DocumentNotFoundError, EXTRACTION_VERSION, Embedder, EngineActionError, ExtraMissingError, Extracted, ExtractionConfig, type ExtractionResult, GraphLegUnavailable, type Hit, Hooks, InProcessRunner, IngestReport, KnowledgeComputeFn, LLMClient, LLMConfig, Principals, ProgressEvent, RedactionPolicy, RerankerConfig, ScopeInput, type SearchResult, StorageBackend, type TaskRunner, type TaskStatus, ToolConfig, Trusted, Unset, UsageEvent, __version__, buildLlmClient, callLlm, compute, computeOverFrames, decryptDict, encryptDict, extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, rrfFuse, runMigrate, runSearch, shouldRequireApproval, upsertRegistry };