@promptev/context-engine 0.0.3 → 0.0.4
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/README.md +25 -1
- package/dist/cli.js +527 -16
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +532 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +244 -3
- package/dist/index.d.ts +244 -3
- package/dist/index.js +528 -17
- package/dist/index.js.map +1 -1
- package/dist/{mcp-BKSmxayM.d.cts → mcp-uirRbluA.d.cts} +4 -0
- package/dist/{mcp-BKSmxayM.d.ts → mcp-uirRbluA.d.ts} +4 -0
- package/dist/mcp.cjs +50 -10
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +50 -10
- package/dist/mcp.js.map +1 -1
- package/dist/skills/context-engine/SKILL.md +29 -1
- package/package.json +1 -1
- package/src/skills/context-engine/SKILL.md +29 -1
package/dist/index.d.cts
CHANGED
|
@@ -5,8 +5,8 @@ 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-
|
|
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-
|
|
8
|
+
import { P as Principals, U as Unset, S as ScopeInput, K as KnowledgeComputeFn, T as Trusted } from './mcp-uirRbluA.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-uirRbluA.cjs';
|
|
10
10
|
import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-P9pRb4Ol.cjs';
|
|
11
11
|
export { c as ToolKind, d as configSchema } from './governance-P9pRb4Ol.cjs';
|
|
12
12
|
import 'zod';
|
|
@@ -71,6 +71,13 @@ declare function listDocuments(opts: {
|
|
|
71
71
|
sourceId?: string | null;
|
|
72
72
|
/** OR-of-many, ONE keyset-paged query across all of them; with `sourceId`, their union. */
|
|
73
73
|
sourceIds?: string[] | null;
|
|
74
|
+
/**
|
|
75
|
+
* Narrows to specific documents IN SQL, not after the page is built: three
|
|
76
|
+
* named documents that happen to sit on page four would otherwise come back
|
|
77
|
+
* as an empty page rather than as themselves. An empty array means nothing
|
|
78
|
+
* is in scope and stays empty.
|
|
79
|
+
*/
|
|
80
|
+
documentIds?: string[] | null;
|
|
74
81
|
principals?: string[] | null;
|
|
75
82
|
cursor?: unknown;
|
|
76
83
|
limit?: number;
|
|
@@ -78,6 +85,167 @@ declare function listDocuments(opts: {
|
|
|
78
85
|
secretKey?: string | Buffer | null;
|
|
79
86
|
hooks?: Hooks;
|
|
80
87
|
}): Promise<Record<string, unknown>>;
|
|
88
|
+
type SpreadsheetDescription = {
|
|
89
|
+
document_id: string;
|
|
90
|
+
name: unknown;
|
|
91
|
+
source_id: unknown;
|
|
92
|
+
sheets: SheetSchema[] | null;
|
|
93
|
+
schema_unavailable?: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Sheet names, column headers and row counts for the named spreadsheets.
|
|
97
|
+
*
|
|
98
|
+
* `documentIds` comes from a listing the caller has already been shown, but
|
|
99
|
+
* the ACL and the source scope are applied AGAIN here: "we already filtered
|
|
100
|
+
* the list" is exactly how a batch read ends up reading one row it should
|
|
101
|
+
* not have. A document that is not visible, is not in scope, or is not
|
|
102
|
+
* tabular simply does not appear in the result.
|
|
103
|
+
*
|
|
104
|
+
* Reading document bodies is the cost, so it is bounded twice: the caller
|
|
105
|
+
* passes only the page it is describing, and `budget` caps the total
|
|
106
|
+
* characters of stored text this will pull. Documents past the budget are
|
|
107
|
+
* still LISTED, with `sheets: null` and a reason — a silently shortened
|
|
108
|
+
* schema would read as "that workbook has no sheets".
|
|
109
|
+
*
|
|
110
|
+
* `redaction` masks sheet names and column headers, which are derived from
|
|
111
|
+
* the document body exactly like `search`'s chunk text. The document `name`
|
|
112
|
+
* is not masked, matching `listDocuments`: it is caller-set at ingest.
|
|
113
|
+
*/
|
|
114
|
+
declare function spreadsheetSchema(opts: {
|
|
115
|
+
pool: Pool;
|
|
116
|
+
documentIds: string[];
|
|
117
|
+
sourceIds?: string[] | null;
|
|
118
|
+
principals?: string[] | null;
|
|
119
|
+
budget?: number;
|
|
120
|
+
redaction?: RedactionPolicy | null;
|
|
121
|
+
secretKey?: string | Buffer | null;
|
|
122
|
+
hooks?: Hooks;
|
|
123
|
+
}): Promise<SpreadsheetDescription[]>;
|
|
124
|
+
type DocumentStructure = Record<string, unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* What is INSIDE each of the named documents, whatever its type.
|
|
127
|
+
*
|
|
128
|
+
* Returns `{documentId: structure}`. The shape of `structure` follows the
|
|
129
|
+
* document, because the thing a model needs to know differs by type:
|
|
130
|
+
*
|
|
131
|
+
* | document | structure |
|
|
132
|
+
* |---|---|
|
|
133
|
+
* | CSV / XLSX / TSV | `sheets: [{name, columns, row_count}]` |
|
|
134
|
+
* | markdown, Word, HTML, a transcribed PDF | `sections: [...]`, `last_page` |
|
|
135
|
+
* | JSON | `keys: [...]` |
|
|
136
|
+
* | anything else | just `chunks` |
|
|
137
|
+
*
|
|
138
|
+
* `chunks` is on every one of them, and is the floor: a plain `.txt` has no
|
|
139
|
+
* headings to report, but a model still has to know whether `get_chunks` is
|
|
140
|
+
* worth calling. A document that is present but described by nothing at all
|
|
141
|
+
* reads as an empty document, which is why there is no "no structure" case.
|
|
142
|
+
*
|
|
143
|
+
* Everything but the spreadsheet columns comes from `meta_data` on the chunk
|
|
144
|
+
* rows, which the chunkers already wrote at ingest (`section_title`, `page`,
|
|
145
|
+
* `top_level_key`) — one grouped query over small rows, no document body read
|
|
146
|
+
* and no LLM. Columns are the exception: the header row is not in chunk
|
|
147
|
+
* metadata, so the tabular half still parses stored text, under the same
|
|
148
|
+
* budget (see `spreadsheetSchema`).
|
|
149
|
+
*/
|
|
150
|
+
declare function documentStructure(opts: {
|
|
151
|
+
pool: Pool;
|
|
152
|
+
documentIds: string[];
|
|
153
|
+
sourceIds?: string[] | null;
|
|
154
|
+
principals?: string[] | null;
|
|
155
|
+
budget?: number;
|
|
156
|
+
/**
|
|
157
|
+
* Cap every list at `MAX_STRUCTURE_ITEMS` and report the remainder as a
|
|
158
|
+
* count. One rule decides it, and the caller above applies it: **the cap is
|
|
159
|
+
* for the call that did NOT name its documents.** A `discover` describing a
|
|
160
|
+
* whole page has a context budget to keep; a caller that asked about one
|
|
161
|
+
* document asked for all of it, exactly like `spreadsheetSchema`.
|
|
162
|
+
*/
|
|
163
|
+
bounded?: boolean;
|
|
164
|
+
redaction?: RedactionPolicy | null;
|
|
165
|
+
secretKey?: string | Buffer | null;
|
|
166
|
+
hooks?: Hooks;
|
|
167
|
+
}): Promise<Record<string, DocumentStructure>>;
|
|
168
|
+
type DocumentTypeCount = {
|
|
169
|
+
kind: "spreadsheet" | "text";
|
|
170
|
+
type: string | null;
|
|
171
|
+
documents: number;
|
|
172
|
+
with_fields: number;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* The corpus census: `[{kind, type, documents, with_fields}]`.
|
|
176
|
+
*
|
|
177
|
+
* Keyed by TWO things, because only one of them is always known:
|
|
178
|
+
*
|
|
179
|
+
* - `kind` is derived from the mime (`isTabularMime`, the same predicate
|
|
180
|
+
* `compute` selects on), so it is known for every document ever ingested.
|
|
181
|
+
* - `type` is the document's `document_type`, which is unconstrained free
|
|
182
|
+
* text an LLM wrote during structured extraction — and extraction is
|
|
183
|
+
* opt-in (`extractStructured`, off by default). On a deployment that never
|
|
184
|
+
* enabled it, `type` is null on every row. A census keyed on `type` alone
|
|
185
|
+
* would therefore be a single null bucket, which tells a model nothing
|
|
186
|
+
* about a corpus it is about to query.
|
|
187
|
+
*
|
|
188
|
+
* `with_fields` counts documents whose `structured_data` is a non-empty
|
|
189
|
+
* object. Extraction that ran and legitimately found nothing stores `{}`, and
|
|
190
|
+
* counting that as coverage would point a model at `query_meta` for a type
|
|
191
|
+
* that has nothing to filter on.
|
|
192
|
+
*/
|
|
193
|
+
declare function documentTypes(opts: {
|
|
194
|
+
pool: Pool;
|
|
195
|
+
sourceIds?: string[] | null;
|
|
196
|
+
principals?: string[] | null;
|
|
197
|
+
documentIds?: string[] | null;
|
|
198
|
+
limit?: number;
|
|
199
|
+
redaction?: RedactionPolicy | null;
|
|
200
|
+
secretKey?: string | Buffer | null;
|
|
201
|
+
hooks?: Hooks;
|
|
202
|
+
}): Promise<DocumentTypeCount[]>;
|
|
203
|
+
type FieldDescription = {
|
|
204
|
+
field: string;
|
|
205
|
+
type: string;
|
|
206
|
+
documents: number;
|
|
207
|
+
};
|
|
208
|
+
type FieldGroup = {
|
|
209
|
+
kind: "spreadsheet" | "text";
|
|
210
|
+
type: string | null;
|
|
211
|
+
fields: FieldDescription[];
|
|
212
|
+
more_fields?: string[];
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Extracted structured field names grouped by document kind AND type.
|
|
216
|
+
*
|
|
217
|
+
* Returns `[{kind, type, fields: [{field, type, documents}], more_fields}]` —
|
|
218
|
+
* one row per group, keyed by the SAME pair `documentTypes` is keyed by. That
|
|
219
|
+
* pairing is the point: `document_type` is a label an LLM wrote, so two
|
|
220
|
+
* different kinds can share one ("invoice" for both a PDF and a CSV of
|
|
221
|
+
* invoice rows). Keyed on the label alone, their fields merge into one group
|
|
222
|
+
* and a model reads a spreadsheet's columns as a PDF's extracted fields.
|
|
223
|
+
*
|
|
224
|
+
* `more_fields` holds the NAMES the per-group detail cap left out, not a
|
|
225
|
+
* count: nothing is dropped silently, and a name is all a caller needs to
|
|
226
|
+
* reach a field through `query_meta`. It is absent when nothing was left out.
|
|
227
|
+
*
|
|
228
|
+
* Counted over the documents the CALLER can see, not over the learned field
|
|
229
|
+
* registry (`context_engine_structured_keys`), which carries no ACL: a
|
|
230
|
+
* registry-wide answer would tell an anonymous caller the field names of
|
|
231
|
+
* every restricted document in the corpus. Counting from `structured_data`
|
|
232
|
+
* also makes `documents` mean what it says — how many in-scope documents
|
|
233
|
+
* actually carry the field.
|
|
234
|
+
*
|
|
235
|
+
* The type is `inferDataType`, the same function that labelled the registry,
|
|
236
|
+
* so the vocabulary a model reads here is the one the rest of the engine
|
|
237
|
+
* uses.
|
|
238
|
+
*/
|
|
239
|
+
declare function fieldSummary(opts: {
|
|
240
|
+
pool: Pool;
|
|
241
|
+
sourceIds?: string[] | null;
|
|
242
|
+
principals?: string[] | null;
|
|
243
|
+
documentIds?: string[] | null;
|
|
244
|
+
maxFieldsPerType?: number;
|
|
245
|
+
redaction?: RedactionPolicy | null;
|
|
246
|
+
secretKey?: string | Buffer | null;
|
|
247
|
+
hooks?: Hooks;
|
|
248
|
+
}): Promise<FieldGroup[]>;
|
|
81
249
|
/**
|
|
82
250
|
* Answer a natural-language question against documents' `structuredData`.
|
|
83
251
|
*
|
|
@@ -102,6 +270,24 @@ declare function queryStructured(question: string, opts: {
|
|
|
102
270
|
secretKey?: string | Buffer | null;
|
|
103
271
|
hooks?: Hooks;
|
|
104
272
|
}): Promise<Record<string, unknown>>;
|
|
273
|
+
type SheetSchema = {
|
|
274
|
+
name: string;
|
|
275
|
+
columns: string[];
|
|
276
|
+
row_count: number;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* The schema of one stored spreadsheet: `[{name, columns, row_count}]`.
|
|
280
|
+
*
|
|
281
|
+
* Header row and row count per SHEET, not unioned across the workbook — two
|
|
282
|
+
* sheets that both have an `amount` column are two different frames to
|
|
283
|
+
* `compute`, and a union would hide which one has the column a question
|
|
284
|
+
* needs. `row_count` counts DATA rows (the header is not one of them).
|
|
285
|
+
*
|
|
286
|
+
* Needs no danfo: `discover` must stay callable on an install that never
|
|
287
|
+
* enabled code execution, which is exactly the install where a model most
|
|
288
|
+
* needs the columns before it writes a query.
|
|
289
|
+
*/
|
|
290
|
+
declare function spreadsheetSchemaFromText(text: string | null | undefined): SheetSchema[];
|
|
105
291
|
/**
|
|
106
292
|
* Compute an answer to `instruction` over in-scope spreadsheet documents.
|
|
107
293
|
*
|
|
@@ -569,11 +755,66 @@ declare class ContextEngine implements ToolEngine {
|
|
|
569
755
|
listDocuments(opts?: {
|
|
570
756
|
sourceId?: string | null;
|
|
571
757
|
sourceIds?: string[] | null;
|
|
758
|
+
documentIds?: string[] | null;
|
|
572
759
|
principals?: Principals;
|
|
573
760
|
cursor?: unknown;
|
|
574
761
|
limit?: number;
|
|
575
762
|
redaction?: RedactionPolicy | null;
|
|
576
763
|
}): Promise<Record<string, unknown>>;
|
|
764
|
+
/**
|
|
765
|
+
* Sheet names, columns and row counts for the named spreadsheets.
|
|
766
|
+
*
|
|
767
|
+
* See `actions.spreadsheetSchema`. This is the half of `discover` that lets
|
|
768
|
+
* a model write ONE `compute` call: sheet names here are the keys it will
|
|
769
|
+
* index `dfs` by, and columns are the names it will use inside the code it
|
|
770
|
+
* writes.
|
|
771
|
+
*/
|
|
772
|
+
spreadsheetSchema(opts: {
|
|
773
|
+
documentIds: string[];
|
|
774
|
+
sourceIds?: string[] | null;
|
|
775
|
+
principals?: Principals;
|
|
776
|
+
redaction?: RedactionPolicy | null;
|
|
777
|
+
}): Promise<SpreadsheetDescription[]>;
|
|
778
|
+
/**
|
|
779
|
+
* What is inside each of the named documents, whatever its type.
|
|
780
|
+
*
|
|
781
|
+
* See `actions.documentStructure`. Sheets and columns for a workbook,
|
|
782
|
+
* sections and the last page for a document with headings, top-level keys
|
|
783
|
+
* for JSON, and a chunk count for everything — so `discover` describes the
|
|
784
|
+
* whole corpus rather than only the spreadsheets in it.
|
|
785
|
+
*/
|
|
786
|
+
documentStructure(opts: {
|
|
787
|
+
documentIds: string[];
|
|
788
|
+
sourceIds?: string[] | null;
|
|
789
|
+
principals?: Principals;
|
|
790
|
+
bounded?: boolean;
|
|
791
|
+
redaction?: RedactionPolicy | null;
|
|
792
|
+
}): Promise<Record<string, DocumentStructure>>;
|
|
793
|
+
/**
|
|
794
|
+
* The corpus census — `[{kind, type, documents, with_fields}]`.
|
|
795
|
+
*
|
|
796
|
+
* See `actions.documentTypes`. `kind` comes from the mime and is always
|
|
797
|
+
* known; `type` is the LLM-written document type and exists only where
|
|
798
|
+
* structured extraction was opted into.
|
|
799
|
+
*/
|
|
800
|
+
documentTypes(opts?: {
|
|
801
|
+
sourceIds?: string[] | null;
|
|
802
|
+
principals?: Principals;
|
|
803
|
+
documentIds?: string[] | null;
|
|
804
|
+
redaction?: RedactionPolicy | null;
|
|
805
|
+
}): Promise<DocumentTypeCount[]>;
|
|
806
|
+
/**
|
|
807
|
+
* Extracted structured field names grouped by document kind and type.
|
|
808
|
+
*
|
|
809
|
+
* See `actions.fieldSummary`. One row per group, keyed by the same
|
|
810
|
+
* `(kind, type)` pair `documentTypes` uses.
|
|
811
|
+
*/
|
|
812
|
+
fieldSummary(opts?: {
|
|
813
|
+
sourceIds?: string[] | null;
|
|
814
|
+
principals?: Principals;
|
|
815
|
+
documentIds?: string[] | null;
|
|
816
|
+
redaction?: RedactionPolicy | null;
|
|
817
|
+
}): Promise<FieldGroup[]>;
|
|
577
818
|
queryStructured(question: string, opts?: {
|
|
578
819
|
sourceIds?: string[] | null;
|
|
579
820
|
principals?: Principals;
|
|
@@ -933,4 +1174,4 @@ declare function functionTool(fn: (...args: never[]) => unknown): CanonicalTool;
|
|
|
933
1174
|
/** Bumped by CI on every main merge; 0.0.0 = pre-first-release. */
|
|
934
1175
|
declare const __version__ = "0.0.0";
|
|
935
1176
|
|
|
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 };
|
|
1177
|
+
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, documentStructure, documentTypes, encryptDict, extract, extractStructuredData, fieldSummary, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, rrfFuse, runMigrate, runSearch, shouldRequireApproval, spreadsheetSchema, spreadsheetSchemaFromText, upsertRegistry };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ 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-
|
|
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-
|
|
8
|
+
import { P as Principals, U as Unset, S as ScopeInput, K as KnowledgeComputeFn, T as Trusted } from './mcp-uirRbluA.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-uirRbluA.js';
|
|
10
10
|
import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-BLPK7NMe.js';
|
|
11
11
|
export { c as ToolKind, d as configSchema } from './governance-BLPK7NMe.js';
|
|
12
12
|
import 'zod';
|
|
@@ -71,6 +71,13 @@ declare function listDocuments(opts: {
|
|
|
71
71
|
sourceId?: string | null;
|
|
72
72
|
/** OR-of-many, ONE keyset-paged query across all of them; with `sourceId`, their union. */
|
|
73
73
|
sourceIds?: string[] | null;
|
|
74
|
+
/**
|
|
75
|
+
* Narrows to specific documents IN SQL, not after the page is built: three
|
|
76
|
+
* named documents that happen to sit on page four would otherwise come back
|
|
77
|
+
* as an empty page rather than as themselves. An empty array means nothing
|
|
78
|
+
* is in scope and stays empty.
|
|
79
|
+
*/
|
|
80
|
+
documentIds?: string[] | null;
|
|
74
81
|
principals?: string[] | null;
|
|
75
82
|
cursor?: unknown;
|
|
76
83
|
limit?: number;
|
|
@@ -78,6 +85,167 @@ declare function listDocuments(opts: {
|
|
|
78
85
|
secretKey?: string | Buffer | null;
|
|
79
86
|
hooks?: Hooks;
|
|
80
87
|
}): Promise<Record<string, unknown>>;
|
|
88
|
+
type SpreadsheetDescription = {
|
|
89
|
+
document_id: string;
|
|
90
|
+
name: unknown;
|
|
91
|
+
source_id: unknown;
|
|
92
|
+
sheets: SheetSchema[] | null;
|
|
93
|
+
schema_unavailable?: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Sheet names, column headers and row counts for the named spreadsheets.
|
|
97
|
+
*
|
|
98
|
+
* `documentIds` comes from a listing the caller has already been shown, but
|
|
99
|
+
* the ACL and the source scope are applied AGAIN here: "we already filtered
|
|
100
|
+
* the list" is exactly how a batch read ends up reading one row it should
|
|
101
|
+
* not have. A document that is not visible, is not in scope, or is not
|
|
102
|
+
* tabular simply does not appear in the result.
|
|
103
|
+
*
|
|
104
|
+
* Reading document bodies is the cost, so it is bounded twice: the caller
|
|
105
|
+
* passes only the page it is describing, and `budget` caps the total
|
|
106
|
+
* characters of stored text this will pull. Documents past the budget are
|
|
107
|
+
* still LISTED, with `sheets: null` and a reason — a silently shortened
|
|
108
|
+
* schema would read as "that workbook has no sheets".
|
|
109
|
+
*
|
|
110
|
+
* `redaction` masks sheet names and column headers, which are derived from
|
|
111
|
+
* the document body exactly like `search`'s chunk text. The document `name`
|
|
112
|
+
* is not masked, matching `listDocuments`: it is caller-set at ingest.
|
|
113
|
+
*/
|
|
114
|
+
declare function spreadsheetSchema(opts: {
|
|
115
|
+
pool: Pool;
|
|
116
|
+
documentIds: string[];
|
|
117
|
+
sourceIds?: string[] | null;
|
|
118
|
+
principals?: string[] | null;
|
|
119
|
+
budget?: number;
|
|
120
|
+
redaction?: RedactionPolicy | null;
|
|
121
|
+
secretKey?: string | Buffer | null;
|
|
122
|
+
hooks?: Hooks;
|
|
123
|
+
}): Promise<SpreadsheetDescription[]>;
|
|
124
|
+
type DocumentStructure = Record<string, unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* What is INSIDE each of the named documents, whatever its type.
|
|
127
|
+
*
|
|
128
|
+
* Returns `{documentId: structure}`. The shape of `structure` follows the
|
|
129
|
+
* document, because the thing a model needs to know differs by type:
|
|
130
|
+
*
|
|
131
|
+
* | document | structure |
|
|
132
|
+
* |---|---|
|
|
133
|
+
* | CSV / XLSX / TSV | `sheets: [{name, columns, row_count}]` |
|
|
134
|
+
* | markdown, Word, HTML, a transcribed PDF | `sections: [...]`, `last_page` |
|
|
135
|
+
* | JSON | `keys: [...]` |
|
|
136
|
+
* | anything else | just `chunks` |
|
|
137
|
+
*
|
|
138
|
+
* `chunks` is on every one of them, and is the floor: a plain `.txt` has no
|
|
139
|
+
* headings to report, but a model still has to know whether `get_chunks` is
|
|
140
|
+
* worth calling. A document that is present but described by nothing at all
|
|
141
|
+
* reads as an empty document, which is why there is no "no structure" case.
|
|
142
|
+
*
|
|
143
|
+
* Everything but the spreadsheet columns comes from `meta_data` on the chunk
|
|
144
|
+
* rows, which the chunkers already wrote at ingest (`section_title`, `page`,
|
|
145
|
+
* `top_level_key`) — one grouped query over small rows, no document body read
|
|
146
|
+
* and no LLM. Columns are the exception: the header row is not in chunk
|
|
147
|
+
* metadata, so the tabular half still parses stored text, under the same
|
|
148
|
+
* budget (see `spreadsheetSchema`).
|
|
149
|
+
*/
|
|
150
|
+
declare function documentStructure(opts: {
|
|
151
|
+
pool: Pool;
|
|
152
|
+
documentIds: string[];
|
|
153
|
+
sourceIds?: string[] | null;
|
|
154
|
+
principals?: string[] | null;
|
|
155
|
+
budget?: number;
|
|
156
|
+
/**
|
|
157
|
+
* Cap every list at `MAX_STRUCTURE_ITEMS` and report the remainder as a
|
|
158
|
+
* count. One rule decides it, and the caller above applies it: **the cap is
|
|
159
|
+
* for the call that did NOT name its documents.** A `discover` describing a
|
|
160
|
+
* whole page has a context budget to keep; a caller that asked about one
|
|
161
|
+
* document asked for all of it, exactly like `spreadsheetSchema`.
|
|
162
|
+
*/
|
|
163
|
+
bounded?: boolean;
|
|
164
|
+
redaction?: RedactionPolicy | null;
|
|
165
|
+
secretKey?: string | Buffer | null;
|
|
166
|
+
hooks?: Hooks;
|
|
167
|
+
}): Promise<Record<string, DocumentStructure>>;
|
|
168
|
+
type DocumentTypeCount = {
|
|
169
|
+
kind: "spreadsheet" | "text";
|
|
170
|
+
type: string | null;
|
|
171
|
+
documents: number;
|
|
172
|
+
with_fields: number;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* The corpus census: `[{kind, type, documents, with_fields}]`.
|
|
176
|
+
*
|
|
177
|
+
* Keyed by TWO things, because only one of them is always known:
|
|
178
|
+
*
|
|
179
|
+
* - `kind` is derived from the mime (`isTabularMime`, the same predicate
|
|
180
|
+
* `compute` selects on), so it is known for every document ever ingested.
|
|
181
|
+
* - `type` is the document's `document_type`, which is unconstrained free
|
|
182
|
+
* text an LLM wrote during structured extraction — and extraction is
|
|
183
|
+
* opt-in (`extractStructured`, off by default). On a deployment that never
|
|
184
|
+
* enabled it, `type` is null on every row. A census keyed on `type` alone
|
|
185
|
+
* would therefore be a single null bucket, which tells a model nothing
|
|
186
|
+
* about a corpus it is about to query.
|
|
187
|
+
*
|
|
188
|
+
* `with_fields` counts documents whose `structured_data` is a non-empty
|
|
189
|
+
* object. Extraction that ran and legitimately found nothing stores `{}`, and
|
|
190
|
+
* counting that as coverage would point a model at `query_meta` for a type
|
|
191
|
+
* that has nothing to filter on.
|
|
192
|
+
*/
|
|
193
|
+
declare function documentTypes(opts: {
|
|
194
|
+
pool: Pool;
|
|
195
|
+
sourceIds?: string[] | null;
|
|
196
|
+
principals?: string[] | null;
|
|
197
|
+
documentIds?: string[] | null;
|
|
198
|
+
limit?: number;
|
|
199
|
+
redaction?: RedactionPolicy | null;
|
|
200
|
+
secretKey?: string | Buffer | null;
|
|
201
|
+
hooks?: Hooks;
|
|
202
|
+
}): Promise<DocumentTypeCount[]>;
|
|
203
|
+
type FieldDescription = {
|
|
204
|
+
field: string;
|
|
205
|
+
type: string;
|
|
206
|
+
documents: number;
|
|
207
|
+
};
|
|
208
|
+
type FieldGroup = {
|
|
209
|
+
kind: "spreadsheet" | "text";
|
|
210
|
+
type: string | null;
|
|
211
|
+
fields: FieldDescription[];
|
|
212
|
+
more_fields?: string[];
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Extracted structured field names grouped by document kind AND type.
|
|
216
|
+
*
|
|
217
|
+
* Returns `[{kind, type, fields: [{field, type, documents}], more_fields}]` —
|
|
218
|
+
* one row per group, keyed by the SAME pair `documentTypes` is keyed by. That
|
|
219
|
+
* pairing is the point: `document_type` is a label an LLM wrote, so two
|
|
220
|
+
* different kinds can share one ("invoice" for both a PDF and a CSV of
|
|
221
|
+
* invoice rows). Keyed on the label alone, their fields merge into one group
|
|
222
|
+
* and a model reads a spreadsheet's columns as a PDF's extracted fields.
|
|
223
|
+
*
|
|
224
|
+
* `more_fields` holds the NAMES the per-group detail cap left out, not a
|
|
225
|
+
* count: nothing is dropped silently, and a name is all a caller needs to
|
|
226
|
+
* reach a field through `query_meta`. It is absent when nothing was left out.
|
|
227
|
+
*
|
|
228
|
+
* Counted over the documents the CALLER can see, not over the learned field
|
|
229
|
+
* registry (`context_engine_structured_keys`), which carries no ACL: a
|
|
230
|
+
* registry-wide answer would tell an anonymous caller the field names of
|
|
231
|
+
* every restricted document in the corpus. Counting from `structured_data`
|
|
232
|
+
* also makes `documents` mean what it says — how many in-scope documents
|
|
233
|
+
* actually carry the field.
|
|
234
|
+
*
|
|
235
|
+
* The type is `inferDataType`, the same function that labelled the registry,
|
|
236
|
+
* so the vocabulary a model reads here is the one the rest of the engine
|
|
237
|
+
* uses.
|
|
238
|
+
*/
|
|
239
|
+
declare function fieldSummary(opts: {
|
|
240
|
+
pool: Pool;
|
|
241
|
+
sourceIds?: string[] | null;
|
|
242
|
+
principals?: string[] | null;
|
|
243
|
+
documentIds?: string[] | null;
|
|
244
|
+
maxFieldsPerType?: number;
|
|
245
|
+
redaction?: RedactionPolicy | null;
|
|
246
|
+
secretKey?: string | Buffer | null;
|
|
247
|
+
hooks?: Hooks;
|
|
248
|
+
}): Promise<FieldGroup[]>;
|
|
81
249
|
/**
|
|
82
250
|
* Answer a natural-language question against documents' `structuredData`.
|
|
83
251
|
*
|
|
@@ -102,6 +270,24 @@ declare function queryStructured(question: string, opts: {
|
|
|
102
270
|
secretKey?: string | Buffer | null;
|
|
103
271
|
hooks?: Hooks;
|
|
104
272
|
}): Promise<Record<string, unknown>>;
|
|
273
|
+
type SheetSchema = {
|
|
274
|
+
name: string;
|
|
275
|
+
columns: string[];
|
|
276
|
+
row_count: number;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* The schema of one stored spreadsheet: `[{name, columns, row_count}]`.
|
|
280
|
+
*
|
|
281
|
+
* Header row and row count per SHEET, not unioned across the workbook — two
|
|
282
|
+
* sheets that both have an `amount` column are two different frames to
|
|
283
|
+
* `compute`, and a union would hide which one has the column a question
|
|
284
|
+
* needs. `row_count` counts DATA rows (the header is not one of them).
|
|
285
|
+
*
|
|
286
|
+
* Needs no danfo: `discover` must stay callable on an install that never
|
|
287
|
+
* enabled code execution, which is exactly the install where a model most
|
|
288
|
+
* needs the columns before it writes a query.
|
|
289
|
+
*/
|
|
290
|
+
declare function spreadsheetSchemaFromText(text: string | null | undefined): SheetSchema[];
|
|
105
291
|
/**
|
|
106
292
|
* Compute an answer to `instruction` over in-scope spreadsheet documents.
|
|
107
293
|
*
|
|
@@ -569,11 +755,66 @@ declare class ContextEngine implements ToolEngine {
|
|
|
569
755
|
listDocuments(opts?: {
|
|
570
756
|
sourceId?: string | null;
|
|
571
757
|
sourceIds?: string[] | null;
|
|
758
|
+
documentIds?: string[] | null;
|
|
572
759
|
principals?: Principals;
|
|
573
760
|
cursor?: unknown;
|
|
574
761
|
limit?: number;
|
|
575
762
|
redaction?: RedactionPolicy | null;
|
|
576
763
|
}): Promise<Record<string, unknown>>;
|
|
764
|
+
/**
|
|
765
|
+
* Sheet names, columns and row counts for the named spreadsheets.
|
|
766
|
+
*
|
|
767
|
+
* See `actions.spreadsheetSchema`. This is the half of `discover` that lets
|
|
768
|
+
* a model write ONE `compute` call: sheet names here are the keys it will
|
|
769
|
+
* index `dfs` by, and columns are the names it will use inside the code it
|
|
770
|
+
* writes.
|
|
771
|
+
*/
|
|
772
|
+
spreadsheetSchema(opts: {
|
|
773
|
+
documentIds: string[];
|
|
774
|
+
sourceIds?: string[] | null;
|
|
775
|
+
principals?: Principals;
|
|
776
|
+
redaction?: RedactionPolicy | null;
|
|
777
|
+
}): Promise<SpreadsheetDescription[]>;
|
|
778
|
+
/**
|
|
779
|
+
* What is inside each of the named documents, whatever its type.
|
|
780
|
+
*
|
|
781
|
+
* See `actions.documentStructure`. Sheets and columns for a workbook,
|
|
782
|
+
* sections and the last page for a document with headings, top-level keys
|
|
783
|
+
* for JSON, and a chunk count for everything — so `discover` describes the
|
|
784
|
+
* whole corpus rather than only the spreadsheets in it.
|
|
785
|
+
*/
|
|
786
|
+
documentStructure(opts: {
|
|
787
|
+
documentIds: string[];
|
|
788
|
+
sourceIds?: string[] | null;
|
|
789
|
+
principals?: Principals;
|
|
790
|
+
bounded?: boolean;
|
|
791
|
+
redaction?: RedactionPolicy | null;
|
|
792
|
+
}): Promise<Record<string, DocumentStructure>>;
|
|
793
|
+
/**
|
|
794
|
+
* The corpus census — `[{kind, type, documents, with_fields}]`.
|
|
795
|
+
*
|
|
796
|
+
* See `actions.documentTypes`. `kind` comes from the mime and is always
|
|
797
|
+
* known; `type` is the LLM-written document type and exists only where
|
|
798
|
+
* structured extraction was opted into.
|
|
799
|
+
*/
|
|
800
|
+
documentTypes(opts?: {
|
|
801
|
+
sourceIds?: string[] | null;
|
|
802
|
+
principals?: Principals;
|
|
803
|
+
documentIds?: string[] | null;
|
|
804
|
+
redaction?: RedactionPolicy | null;
|
|
805
|
+
}): Promise<DocumentTypeCount[]>;
|
|
806
|
+
/**
|
|
807
|
+
* Extracted structured field names grouped by document kind and type.
|
|
808
|
+
*
|
|
809
|
+
* See `actions.fieldSummary`. One row per group, keyed by the same
|
|
810
|
+
* `(kind, type)` pair `documentTypes` uses.
|
|
811
|
+
*/
|
|
812
|
+
fieldSummary(opts?: {
|
|
813
|
+
sourceIds?: string[] | null;
|
|
814
|
+
principals?: Principals;
|
|
815
|
+
documentIds?: string[] | null;
|
|
816
|
+
redaction?: RedactionPolicy | null;
|
|
817
|
+
}): Promise<FieldGroup[]>;
|
|
577
818
|
queryStructured(question: string, opts?: {
|
|
578
819
|
sourceIds?: string[] | null;
|
|
579
820
|
principals?: Principals;
|
|
@@ -933,4 +1174,4 @@ declare function functionTool(fn: (...args: never[]) => unknown): CanonicalTool;
|
|
|
933
1174
|
/** Bumped by CI on every main merge; 0.0.0 = pre-first-release. */
|
|
934
1175
|
declare const __version__ = "0.0.0";
|
|
935
1176
|
|
|
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 };
|
|
1177
|
+
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, documentStructure, documentTypes, encryptDict, extract, extractStructuredData, fieldSummary, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, rrfFuse, runMigrate, runSearch, shouldRequireApproval, spreadsheetSchema, spreadsheetSchemaFromText, upsertRegistry };
|