@promptev/context-engine 0.0.1 → 0.0.2
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 +23 -0
- package/dist/cli.js +142 -58
- package/dist/cli.js.map +1 -1
- package/dist/{config-CdlSkKgV.d.ts → config-BODDdXJ7.d.ts} +33 -11
- package/dist/{config-CNnASw5X.d.cts → config-C5RZ00W6.d.cts} +33 -11
- package/dist/express.d.cts +3 -3
- package/dist/express.d.ts +3 -3
- package/dist/fastify.d.cts +3 -3
- package/dist/fastify.d.ts +3 -3
- package/dist/{governance-XFVgtEdV.d.ts → governance-BLPK7NMe.d.ts} +1 -1
- package/dist/{governance-D8g6Wyvb.d.cts → governance-P9pRb4Ol.d.cts} +1 -1
- package/dist/graph/index.cjs +51 -18
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +2 -2
- package/dist/graph/index.d.ts +2 -2
- package/dist/graph/index.js +51 -18
- package/dist/graph/index.js.map +1 -1
- package/dist/hono.d.cts +3 -3
- package/dist/hono.d.ts +3 -3
- package/dist/index.cjs +142 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -7
- package/dist/index.d.ts +62 -7
- package/dist/index.js +142 -58
- package/dist/index.js.map +1 -1
- package/dist/{router-Dsv3fv0R.d.cts → router-CiFwC-EN.d.cts} +1 -1
- package/dist/{router-B_DTkQgU.d.ts → router-D8gBzwLd.d.ts} +1 -1
- package/dist/skills/context-engine/SKILL.md +5 -1
- package/dist/{storage-DU1JRno5.d.cts → storage-CJrKgJeJ.d.ts} +5 -2
- package/dist/{storage-Dvt2ZxsV.d.ts → storage-Dvpq2xAC.d.cts} +5 -2
- package/package.json +1 -1
- package/src/skills/context-engine/SKILL.md +5 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Pool } from 'pg';
|
|
2
|
-
import { C as ContextEngineConfig, L as LLMConfig, E as ExtractionConfig, R as RerankerConfig } from './config-
|
|
3
|
-
export { a as ContextEngineConfigInit, b as EmbeddingConfig, F as FusionConfig, G as GraphConfig, S as StorageConfig } from './config-
|
|
2
|
+
import { C as ContextEngineConfig, L as LLMConfig, E as ExtractionConfig, R as RerankerConfig } from './config-C5RZ00W6.cjs';
|
|
3
|
+
export { a as ContextEngineConfigInit, b as EmbeddingConfig, F as FusionConfig, G as GraphConfig, S as StorageConfig } from './config-C5RZ00W6.cjs';
|
|
4
4
|
import { H as Hooks, R as RedactionPolicy, U as UsageEvent, P as ProgressEvent, I as IngestReport } from './redaction-BqD_DEUQ.cjs';
|
|
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
|
-
import { E as Embedder, S as StorageBackend, F as FetchImpl } from './storage-
|
|
7
|
-
export { C as ChunkRow, a as EmbedKind, P as PostgresBackend, b as SearchScope, c as buildEmbedder } from './storage-
|
|
8
|
-
import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-
|
|
9
|
-
export { c as ToolKind, d as configSchema } from './governance-
|
|
6
|
+
import { E as Embedder, S as StorageBackend, F as FetchImpl } from './storage-Dvpq2xAC.cjs';
|
|
7
|
+
export { C as ChunkRow, a as EmbedKind, P as PostgresBackend, b as SearchScope, c as buildEmbedder } from './storage-Dvpq2xAC.cjs';
|
|
8
|
+
import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-P9pRb4Ol.cjs';
|
|
9
|
+
export { c as ToolKind, d as configSchema } from './governance-P9pRb4Ol.cjs';
|
|
10
10
|
export { createMcpApp } from './mcp.cjs';
|
|
11
11
|
import 'zod';
|
|
12
12
|
import 'node:http';
|
|
@@ -129,6 +129,13 @@ declare function queryStructured(question: string, opts: {
|
|
|
129
129
|
* call, no sandbox run — when the flag is `false`. That flag, not the
|
|
130
130
|
* isolate, is the actual security boundary.
|
|
131
131
|
*
|
|
132
|
+
* Only the document half lives here: fetch the in-scope tabular documents
|
|
133
|
+
* and parse their stored text into `{sheet: rows[]}`. Everything after that
|
|
134
|
+
* — the guards, both redaction surfaces below, the prompt → code → sandbox
|
|
135
|
+
* path and the swept result — is `computeOverFrames`, the seam a host calls
|
|
136
|
+
* when it already holds the frames and has no document to point at; this
|
|
137
|
+
* function builds its frames from documents and delegates.
|
|
138
|
+
*
|
|
132
139
|
* `config.redaction` is applied TWICE:
|
|
133
140
|
* 1. Each document's raw `.text` is masked BEFORE it is parsed into a
|
|
134
141
|
* table, so the data the LLM-authored code runs against is built from
|
|
@@ -146,6 +153,54 @@ declare function compute(instruction: string, opts: {
|
|
|
146
153
|
modelCfg?: LLMConfig | null;
|
|
147
154
|
timeout?: number;
|
|
148
155
|
}): Promise<Record<string, unknown>>;
|
|
156
|
+
/** What `compute()` builds and `computeOverFrames` consumes: sheet name → rows. */
|
|
157
|
+
type ComputeFrames = Record<string, Record<string, unknown>[]>;
|
|
158
|
+
/** A source document behind a frame, as `compute()` reports it in `documentsUsed`. */
|
|
159
|
+
interface ComputeDocument {
|
|
160
|
+
id: string;
|
|
161
|
+
name?: string | null;
|
|
162
|
+
sourceId?: string | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Compute an answer to `instruction` over caller-supplied tables.
|
|
166
|
+
*
|
|
167
|
+
* The frame-level seam under `compute()`: everything `compute()` does AFTER
|
|
168
|
+
* it has turned its documents into `{sheet: rows[]}` lives here, so a host
|
|
169
|
+
* that already holds the frames — an uploaded workbook, a connector's
|
|
170
|
+
* sheet, a query result — can run the same prompt → code → sandbox path
|
|
171
|
+
* without first ingesting a document to point at.
|
|
172
|
+
*
|
|
173
|
+
* `frames` keys are the sheet names the caller chose; the LLM sees them and
|
|
174
|
+
* each row's columns exactly as it sees a parsed document's.
|
|
175
|
+
*
|
|
176
|
+
* The guards are `compute()`'s, in the same order and all BEFORE any LLM
|
|
177
|
+
* call: `config.enableCodeExecution` off → `EngineActionError`; no LLM
|
|
178
|
+
* (`modelCfg` or `config.llm`) → `Error`; blank instruction or empty
|
|
179
|
+
* `frames` → `EngineActionError`; `timeout` clamped to 1..300 seconds.
|
|
180
|
+
*
|
|
181
|
+
* `config.redaction` is applied at the same two surfaces as `compute()`:
|
|
182
|
+
*
|
|
183
|
+
* 1. Every string cell and every column name is masked BEFORE the prompt is
|
|
184
|
+
* built (`maskFrames`), so neither the schema summary the LLM reads nor
|
|
185
|
+
* the rows its code runs against carry a raw value. Same intended
|
|
186
|
+
* trade-off as `compute()`'s point 1 — a masked cell can change a
|
|
187
|
+
* computed result, and that is correct.
|
|
188
|
+
* 2. The returned object is swept whole through `redactValueRecursive`,
|
|
189
|
+
* `code` included — `compute()`'s point 2, deliberately blunt.
|
|
190
|
+
*
|
|
191
|
+
* `hooks`, `principals` and `documents` are how `compute()` threads its own
|
|
192
|
+
* context through; a host calling the seam directly normally leaves them at
|
|
193
|
+
* their defaults (no error hook, trusted-internal `unless` evaluation, no
|
|
194
|
+
* source documents — `documentsUsed` comes back empty).
|
|
195
|
+
*/
|
|
196
|
+
declare function computeOverFrames(frames: ComputeFrames, instruction: string, opts: {
|
|
197
|
+
config: ContextEngineConfig;
|
|
198
|
+
modelCfg?: LLMConfig | null;
|
|
199
|
+
timeout?: number;
|
|
200
|
+
hooks?: Hooks | null;
|
|
201
|
+
principals?: string[] | null;
|
|
202
|
+
documents?: ComputeDocument[] | null;
|
|
203
|
+
}): Promise<Record<string, unknown>>;
|
|
149
204
|
|
|
150
205
|
/**
|
|
151
206
|
* AES-256-GCM crypto seam. Wire format is a compatibility promise with the
|
|
@@ -811,4 +866,4 @@ declare function functionTool(fn: (...args: never[]) => unknown): CanonicalTool;
|
|
|
811
866
|
/** Bumped by CI on every main merge; 0.0.0 = pre-first-release. */
|
|
812
867
|
declare const __version__ = "0.0.0";
|
|
813
868
|
|
|
814
|
-
export { ApprovalExpired, ApprovalNotPending, type ApprovalRecord, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, 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, decryptDict, encryptDict, extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, resolvePrincipals, rrfFuse, runMigrate, runSearch, shouldRequireApproval, upsertRegistry };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Pool } from 'pg';
|
|
2
|
-
import { C as ContextEngineConfig, L as LLMConfig, E as ExtractionConfig, R as RerankerConfig } from './config-
|
|
3
|
-
export { a as ContextEngineConfigInit, b as EmbeddingConfig, F as FusionConfig, G as GraphConfig, S as StorageConfig } from './config-
|
|
2
|
+
import { C as ContextEngineConfig, L as LLMConfig, E as ExtractionConfig, R as RerankerConfig } from './config-BODDdXJ7.js';
|
|
3
|
+
export { a as ContextEngineConfigInit, b as EmbeddingConfig, F as FusionConfig, G as GraphConfig, S as StorageConfig } from './config-BODDdXJ7.js';
|
|
4
4
|
import { H as Hooks, R as RedactionPolicy, U as UsageEvent, P as ProgressEvent, I as IngestReport } from './redaction-BqD_DEUQ.js';
|
|
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
|
-
import { E as Embedder, S as StorageBackend, F as FetchImpl } from './storage-
|
|
7
|
-
export { C as ChunkRow, a as EmbedKind, P as PostgresBackend, b as SearchScope, c as buildEmbedder } from './storage-
|
|
8
|
-
import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-
|
|
9
|
-
export { c as ToolKind, d as configSchema } from './governance-
|
|
6
|
+
import { E as Embedder, S as StorageBackend, F as FetchImpl } from './storage-CJrKgJeJ.js';
|
|
7
|
+
export { C as ChunkRow, a as EmbedKind, P as PostgresBackend, b as SearchScope, c as buildEmbedder } from './storage-CJrKgJeJ.js';
|
|
8
|
+
import { T as ToolEngine, C as CanonicalTool, b as ToolHttpClient, a as ToolConfig } from './governance-BLPK7NMe.js';
|
|
9
|
+
export { c as ToolKind, d as configSchema } from './governance-BLPK7NMe.js';
|
|
10
10
|
export { createMcpApp } from './mcp.js';
|
|
11
11
|
import 'zod';
|
|
12
12
|
import 'node:http';
|
|
@@ -129,6 +129,13 @@ declare function queryStructured(question: string, opts: {
|
|
|
129
129
|
* call, no sandbox run — when the flag is `false`. That flag, not the
|
|
130
130
|
* isolate, is the actual security boundary.
|
|
131
131
|
*
|
|
132
|
+
* Only the document half lives here: fetch the in-scope tabular documents
|
|
133
|
+
* and parse their stored text into `{sheet: rows[]}`. Everything after that
|
|
134
|
+
* — the guards, both redaction surfaces below, the prompt → code → sandbox
|
|
135
|
+
* path and the swept result — is `computeOverFrames`, the seam a host calls
|
|
136
|
+
* when it already holds the frames and has no document to point at; this
|
|
137
|
+
* function builds its frames from documents and delegates.
|
|
138
|
+
*
|
|
132
139
|
* `config.redaction` is applied TWICE:
|
|
133
140
|
* 1. Each document's raw `.text` is masked BEFORE it is parsed into a
|
|
134
141
|
* table, so the data the LLM-authored code runs against is built from
|
|
@@ -146,6 +153,54 @@ declare function compute(instruction: string, opts: {
|
|
|
146
153
|
modelCfg?: LLMConfig | null;
|
|
147
154
|
timeout?: number;
|
|
148
155
|
}): Promise<Record<string, unknown>>;
|
|
156
|
+
/** What `compute()` builds and `computeOverFrames` consumes: sheet name → rows. */
|
|
157
|
+
type ComputeFrames = Record<string, Record<string, unknown>[]>;
|
|
158
|
+
/** A source document behind a frame, as `compute()` reports it in `documentsUsed`. */
|
|
159
|
+
interface ComputeDocument {
|
|
160
|
+
id: string;
|
|
161
|
+
name?: string | null;
|
|
162
|
+
sourceId?: string | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Compute an answer to `instruction` over caller-supplied tables.
|
|
166
|
+
*
|
|
167
|
+
* The frame-level seam under `compute()`: everything `compute()` does AFTER
|
|
168
|
+
* it has turned its documents into `{sheet: rows[]}` lives here, so a host
|
|
169
|
+
* that already holds the frames — an uploaded workbook, a connector's
|
|
170
|
+
* sheet, a query result — can run the same prompt → code → sandbox path
|
|
171
|
+
* without first ingesting a document to point at.
|
|
172
|
+
*
|
|
173
|
+
* `frames` keys are the sheet names the caller chose; the LLM sees them and
|
|
174
|
+
* each row's columns exactly as it sees a parsed document's.
|
|
175
|
+
*
|
|
176
|
+
* The guards are `compute()`'s, in the same order and all BEFORE any LLM
|
|
177
|
+
* call: `config.enableCodeExecution` off → `EngineActionError`; no LLM
|
|
178
|
+
* (`modelCfg` or `config.llm`) → `Error`; blank instruction or empty
|
|
179
|
+
* `frames` → `EngineActionError`; `timeout` clamped to 1..300 seconds.
|
|
180
|
+
*
|
|
181
|
+
* `config.redaction` is applied at the same two surfaces as `compute()`:
|
|
182
|
+
*
|
|
183
|
+
* 1. Every string cell and every column name is masked BEFORE the prompt is
|
|
184
|
+
* built (`maskFrames`), so neither the schema summary the LLM reads nor
|
|
185
|
+
* the rows its code runs against carry a raw value. Same intended
|
|
186
|
+
* trade-off as `compute()`'s point 1 — a masked cell can change a
|
|
187
|
+
* computed result, and that is correct.
|
|
188
|
+
* 2. The returned object is swept whole through `redactValueRecursive`,
|
|
189
|
+
* `code` included — `compute()`'s point 2, deliberately blunt.
|
|
190
|
+
*
|
|
191
|
+
* `hooks`, `principals` and `documents` are how `compute()` threads its own
|
|
192
|
+
* context through; a host calling the seam directly normally leaves them at
|
|
193
|
+
* their defaults (no error hook, trusted-internal `unless` evaluation, no
|
|
194
|
+
* source documents — `documentsUsed` comes back empty).
|
|
195
|
+
*/
|
|
196
|
+
declare function computeOverFrames(frames: ComputeFrames, instruction: string, opts: {
|
|
197
|
+
config: ContextEngineConfig;
|
|
198
|
+
modelCfg?: LLMConfig | null;
|
|
199
|
+
timeout?: number;
|
|
200
|
+
hooks?: Hooks | null;
|
|
201
|
+
principals?: string[] | null;
|
|
202
|
+
documents?: ComputeDocument[] | null;
|
|
203
|
+
}): Promise<Record<string, unknown>>;
|
|
149
204
|
|
|
150
205
|
/**
|
|
151
206
|
* AES-256-GCM crypto seam. Wire format is a compatibility promise with the
|
|
@@ -811,4 +866,4 @@ declare function functionTool(fn: (...args: never[]) => unknown): CanonicalTool;
|
|
|
811
866
|
/** Bumped by CI on every main merge; 0.0.0 = pre-first-release. */
|
|
812
867
|
declare const __version__ = "0.0.0";
|
|
813
868
|
|
|
814
|
-
export { ApprovalExpired, ApprovalNotPending, type ApprovalRecord, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, 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, decryptDict, encryptDict, extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, resolvePrincipals, rrfFuse, runMigrate, runSearch, shouldRequireApproval, upsertRegistry };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -803,6 +803,47 @@ var init_hooks = __esm({
|
|
|
803
803
|
}
|
|
804
804
|
});
|
|
805
805
|
|
|
806
|
+
// src/providers/google.ts
|
|
807
|
+
async function buildGenaiClient(cfg2, timeoutMs, purpose) {
|
|
808
|
+
const specifier = "@google/genai";
|
|
809
|
+
let mod;
|
|
810
|
+
try {
|
|
811
|
+
mod = await import(specifier);
|
|
812
|
+
} catch {
|
|
813
|
+
throw new ExtraMissingError("gemini", specifier, purpose);
|
|
814
|
+
}
|
|
815
|
+
const Ctor = mod.GoogleGenAI ?? mod.Client;
|
|
816
|
+
if (!Ctor) {
|
|
817
|
+
throw new ExtraMissingError("gemini", specifier, purpose);
|
|
818
|
+
}
|
|
819
|
+
const opts = { httpOptions: { timeout: timeoutMs } };
|
|
820
|
+
if (cfg2.provider === "vertex_ai") {
|
|
821
|
+
opts.vertexai = true;
|
|
822
|
+
if (cfg2.project || cfg2.location) {
|
|
823
|
+
if (cfg2.project) opts.project = cfg2.project;
|
|
824
|
+
if (cfg2.location) opts.location = cfg2.location;
|
|
825
|
+
} else if (cfg2.apiKey) {
|
|
826
|
+
opts.apiKey = cfg2.apiKey;
|
|
827
|
+
}
|
|
828
|
+
} else {
|
|
829
|
+
opts.apiKey = cfg2.apiKey ?? null;
|
|
830
|
+
}
|
|
831
|
+
try {
|
|
832
|
+
return new Ctor(opts);
|
|
833
|
+
} catch (err) {
|
|
834
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
835
|
+
if (!message.includes("Authentication is not set up")) throw err;
|
|
836
|
+
throw new Error(
|
|
837
|
+
`${message} Set \`project\` on the provider config, or export GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION. Credentials themselves come from Application Default Credentials.`
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
var init_google = __esm({
|
|
842
|
+
"src/providers/google.ts"() {
|
|
843
|
+
init_errors();
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
806
847
|
// src/providers/llm.ts
|
|
807
848
|
var llm_exports = {};
|
|
808
849
|
__export(llm_exports, {
|
|
@@ -838,20 +879,6 @@ function buildOpenAIChatClient(cfg2) {
|
|
|
838
879
|
maxRetries: 0
|
|
839
880
|
});
|
|
840
881
|
}
|
|
841
|
-
async function loadGeminiChatClient(apiKey) {
|
|
842
|
-
const specifier = "@google/genai";
|
|
843
|
-
let mod;
|
|
844
|
-
try {
|
|
845
|
-
mod = await import(specifier);
|
|
846
|
-
} catch {
|
|
847
|
-
throw new ExtraMissingError("gemini", specifier, "gemini llm");
|
|
848
|
-
}
|
|
849
|
-
const Ctor = mod.GoogleGenAI ?? mod.Client;
|
|
850
|
-
if (!Ctor) {
|
|
851
|
-
throw new ExtraMissingError("gemini", specifier, "gemini llm");
|
|
852
|
-
}
|
|
853
|
-
return new Ctor({ apiKey: apiKey ?? null, httpOptions: { timeout: GEMINI_CALL_TIMEOUT_MS } });
|
|
854
|
-
}
|
|
855
882
|
async function loadBedrockSdk() {
|
|
856
883
|
const specifier = "@aws-sdk/client-bedrock-runtime";
|
|
857
884
|
try {
|
|
@@ -870,7 +897,7 @@ function buildLlmClient(cfg2, opts) {
|
|
|
870
897
|
if (OPENAI_FAMILY.has(cfg2.provider)) {
|
|
871
898
|
return new LLMClient(cfg2, { client: buildOpenAIChatClient(cfg2) });
|
|
872
899
|
}
|
|
873
|
-
if (cfg2.provider
|
|
900
|
+
if (GOOGLE_FAMILY.has(cfg2.provider) || cfg2.provider === "bedrock") {
|
|
874
901
|
return new LLMClient(cfg2);
|
|
875
902
|
}
|
|
876
903
|
throw new Error(`unknown llm provider: ${JSON.stringify(cfg2.provider)}`);
|
|
@@ -887,16 +914,18 @@ async function callLlm(cfg2, opts) {
|
|
|
887
914
|
await owned.aclose();
|
|
888
915
|
}
|
|
889
916
|
}
|
|
890
|
-
var CALL_TIMEOUT_MS, TIMEOUT_MS, GEMINI_CALL_TIMEOUT_MS, ANTHROPIC_VERSION, ANTHROPIC_MAX_TOKENS, OPENAI_FAMILY, LLMClient;
|
|
917
|
+
var CALL_TIMEOUT_MS, TIMEOUT_MS, GEMINI_CALL_TIMEOUT_MS, ANTHROPIC_VERSION, ANTHROPIC_MAX_TOKENS, OPENAI_FAMILY, GOOGLE_FAMILY, LLMClient;
|
|
891
918
|
var init_llm = __esm({
|
|
892
919
|
"src/providers/llm.ts"() {
|
|
893
920
|
init_errors();
|
|
921
|
+
init_google();
|
|
894
922
|
CALL_TIMEOUT_MS = 24e4;
|
|
895
923
|
TIMEOUT_MS = CALL_TIMEOUT_MS;
|
|
896
924
|
GEMINI_CALL_TIMEOUT_MS = CALL_TIMEOUT_MS;
|
|
897
925
|
ANTHROPIC_VERSION = "2023-06-01";
|
|
898
926
|
ANTHROPIC_MAX_TOKENS = 4096;
|
|
899
927
|
OPENAI_FAMILY = /* @__PURE__ */ new Set(["openai", "azure_openai", "custom"]);
|
|
928
|
+
GOOGLE_FAMILY = /* @__PURE__ */ new Set(["gemini", "vertex_ai"]);
|
|
900
929
|
LLMClient = class {
|
|
901
930
|
cfg;
|
|
902
931
|
provider;
|
|
@@ -936,7 +965,7 @@ var init_llm = __esm({
|
|
|
936
965
|
if (OPENAI_FAMILY.has(this.provider)) {
|
|
937
966
|
return this.callOpenAI(system, user, jsonMode, images, maxTokens, temperature);
|
|
938
967
|
}
|
|
939
|
-
if (this.provider
|
|
968
|
+
if (GOOGLE_FAMILY.has(this.provider)) {
|
|
940
969
|
return this.callGemini(system, user, jsonMode, images, maxTokens, thinkingBudget, temperature);
|
|
941
970
|
}
|
|
942
971
|
if (this.provider === "bedrock") {
|
|
@@ -1019,7 +1048,11 @@ Respond with valid JSON only.`;
|
|
|
1019
1048
|
}
|
|
1020
1049
|
async callGemini(system, user, jsonMode, images, maxTokens, thinkingBudget = null, temperature = null) {
|
|
1021
1050
|
if (!this.genaiClient) {
|
|
1022
|
-
this.genaiClient = await
|
|
1051
|
+
this.genaiClient = await buildGenaiClient(
|
|
1052
|
+
this.cfg,
|
|
1053
|
+
GEMINI_CALL_TIMEOUT_MS,
|
|
1054
|
+
"gemini llm"
|
|
1055
|
+
);
|
|
1023
1056
|
}
|
|
1024
1057
|
const parts = [];
|
|
1025
1058
|
for (const img of images ?? []) {
|
|
@@ -1898,17 +1931,30 @@ var init_config = __esm({
|
|
|
1898
1931
|
"src/config.ts"() {
|
|
1899
1932
|
init_redaction();
|
|
1900
1933
|
embeddingSchema = z.object({
|
|
1901
|
-
provider: z.enum(["openai", "azure_openai", "gemini", "voyage", "cohere", "custom"]),
|
|
1934
|
+
provider: z.enum(["openai", "azure_openai", "gemini", "vertex_ai", "voyage", "cohere", "custom"]),
|
|
1902
1935
|
model: z.string(),
|
|
1903
1936
|
dim: z.number().int().positive().nullable().optional().default(null),
|
|
1904
1937
|
apiKey: z.string().nullable().optional().default(null),
|
|
1905
|
-
baseUrl: z.string().nullable().optional().default(null)
|
|
1938
|
+
baseUrl: z.string().nullable().optional().default(null),
|
|
1939
|
+
// `vertex_ai` only. Left optional on purpose: the Google SDK resolves both
|
|
1940
|
+
// from GOOGLE_CLOUD_PROJECT / GOOGLE_CLOUD_LOCATION, which is how a GCP
|
|
1941
|
+
// deployment is already wired, and requiring them here would break it.
|
|
1942
|
+
//
|
|
1943
|
+
// No `.default(null)`, unlike the fields above — these types come from
|
|
1944
|
+
// `z.infer`, so a default would make them REQUIRED on the output type and
|
|
1945
|
+
// break every hand-written `EmbeddingConfig` literal already compiled
|
|
1946
|
+
// against 0.0.1. Optional keeps the addition additive.
|
|
1947
|
+
project: z.string().nullable().optional(),
|
|
1948
|
+
location: z.string().nullable().optional()
|
|
1906
1949
|
});
|
|
1907
1950
|
llmSchema = z.object({
|
|
1908
|
-
provider: z.enum(["anthropic", "openai", "azure_openai", "gemini", "bedrock", "custom"]),
|
|
1951
|
+
provider: z.enum(["anthropic", "openai", "azure_openai", "gemini", "vertex_ai", "bedrock", "custom"]),
|
|
1909
1952
|
model: z.string(),
|
|
1910
1953
|
apiKey: z.string().nullable().optional().default(null),
|
|
1911
|
-
baseUrl: z.string().nullable().optional().default(null)
|
|
1954
|
+
baseUrl: z.string().nullable().optional().default(null),
|
|
1955
|
+
// `vertex_ai` only — see the note on embeddingSchema.
|
|
1956
|
+
project: z.string().nullable().optional(),
|
|
1957
|
+
location: z.string().nullable().optional()
|
|
1912
1958
|
});
|
|
1913
1959
|
graphSchema = z.object({
|
|
1914
1960
|
enabled: z.boolean().default(false),
|
|
@@ -7567,20 +7613,8 @@ function parseSpreadsheetText(dfd, text) {
|
|
|
7567
7613
|
return out;
|
|
7568
7614
|
}
|
|
7569
7615
|
async function compute(instruction, opts) {
|
|
7570
|
-
|
|
7571
|
-
throw new EngineActionError(
|
|
7572
|
-
"compute() executes generated code and is disabled by default; set enableCodeExecution=true only in a deployment with out-of-process/container isolation."
|
|
7573
|
-
);
|
|
7574
|
-
}
|
|
7575
|
-
const llmCfg = opts.modelCfg ?? opts.config.llm;
|
|
7576
|
-
if (llmCfg == null) {
|
|
7577
|
-
throw new Error("compute() requires an LLM: pass modelCfg= or configure ContextEngineConfig.llm");
|
|
7578
|
-
}
|
|
7579
|
-
if (!instruction?.trim()) {
|
|
7580
|
-
throw new EngineActionError("instruction must not be empty");
|
|
7581
|
-
}
|
|
7616
|
+
checkComputePreconditions(opts.config, opts.modelCfg, instruction);
|
|
7582
7617
|
const dfd = await requireDanfo();
|
|
7583
|
-
const timeout = Math.max(1, Math.min(Math.trunc(opts.timeout || DEFAULT_COMPUTE_TIMEOUT), 300));
|
|
7584
7618
|
const principals = opts.principals ?? null;
|
|
7585
7619
|
const params = [];
|
|
7586
7620
|
let where = scopeSql(opts.sourceIds ?? null, principals, params);
|
|
@@ -7650,6 +7684,69 @@ async function compute(instruction, opts) {
|
|
|
7650
7684
|
if (!Object.keys(dfs).length) {
|
|
7651
7685
|
throw new EngineActionError("in-scope documents did not parse into any usable dataframe");
|
|
7652
7686
|
}
|
|
7687
|
+
return computeOverFrames(dfs, instruction, {
|
|
7688
|
+
config: opts.config,
|
|
7689
|
+
modelCfg: opts.modelCfg,
|
|
7690
|
+
timeout: opts.timeout,
|
|
7691
|
+
hooks: opts.hooks,
|
|
7692
|
+
principals,
|
|
7693
|
+
documents
|
|
7694
|
+
});
|
|
7695
|
+
}
|
|
7696
|
+
function checkComputePreconditions(config, modelCfg, instruction) {
|
|
7697
|
+
if (!config.enableCodeExecution) {
|
|
7698
|
+
throw new EngineActionError(
|
|
7699
|
+
"compute() executes generated code and is disabled by default; set enableCodeExecution=true only in a deployment with out-of-process/container isolation."
|
|
7700
|
+
);
|
|
7701
|
+
}
|
|
7702
|
+
const llmCfg = modelCfg ?? config.llm;
|
|
7703
|
+
if (llmCfg == null) {
|
|
7704
|
+
throw new Error("compute() requires an LLM: pass modelCfg= or configure ContextEngineConfig.llm");
|
|
7705
|
+
}
|
|
7706
|
+
if (!instruction?.trim()) {
|
|
7707
|
+
throw new EngineActionError("instruction must not be empty");
|
|
7708
|
+
}
|
|
7709
|
+
return llmCfg;
|
|
7710
|
+
}
|
|
7711
|
+
function maskFrames(frames, policy, opts) {
|
|
7712
|
+
if (policy == null || policy.isEmpty()) return frames;
|
|
7713
|
+
const mask = (text) => redactValueRecursive(text, policy, opts);
|
|
7714
|
+
const masked = {};
|
|
7715
|
+
for (const [name, rows] of Object.entries(frames)) {
|
|
7716
|
+
const labels = /* @__PURE__ */ new Map();
|
|
7717
|
+
const taken = /* @__PURE__ */ new Set();
|
|
7718
|
+
for (const row of rows) {
|
|
7719
|
+
for (const column of Object.keys(row)) {
|
|
7720
|
+
if (labels.has(column)) continue;
|
|
7721
|
+
const base = mask(column);
|
|
7722
|
+
let label = base;
|
|
7723
|
+
for (let n = 2; taken.has(label); n++) label = `${base}_${n}`;
|
|
7724
|
+
taken.add(label);
|
|
7725
|
+
labels.set(column, label);
|
|
7726
|
+
}
|
|
7727
|
+
}
|
|
7728
|
+
masked[name] = rows.map(
|
|
7729
|
+
(row) => Object.fromEntries(
|
|
7730
|
+
Object.entries(row).map(([column, value]) => [
|
|
7731
|
+
labels.get(column) ?? column,
|
|
7732
|
+
typeof value === "string" ? mask(value) : value
|
|
7733
|
+
])
|
|
7734
|
+
)
|
|
7735
|
+
);
|
|
7736
|
+
}
|
|
7737
|
+
return masked;
|
|
7738
|
+
}
|
|
7739
|
+
async function computeOverFrames(frames, instruction, opts) {
|
|
7740
|
+
const llmCfg = checkComputePreconditions(opts.config, opts.modelCfg, instruction);
|
|
7741
|
+
if (!frames || !Object.keys(frames).length) {
|
|
7742
|
+
throw new EngineActionError("no tabular data to compute over");
|
|
7743
|
+
}
|
|
7744
|
+
const hooks = opts.hooks ?? {};
|
|
7745
|
+
const principals = opts.principals ?? null;
|
|
7746
|
+
const documents = [...opts.documents ?? []];
|
|
7747
|
+
const timeout = Math.max(1, Math.min(Math.trunc(opts.timeout || DEFAULT_COMPUTE_TIMEOUT), 300));
|
|
7748
|
+
const redactOpts = { principals, secretKey: opts.config.secretKey, hooks };
|
|
7749
|
+
const dfs = maskFrames(frames, opts.config.redaction, redactOpts);
|
|
7653
7750
|
const schemaLines = Object.entries(dfs).map(
|
|
7654
7751
|
([name, table]) => `- ${name}: columns=${JSON.stringify(Object.keys(table[0] ?? {}))}, rows=${table.length}`
|
|
7655
7752
|
);
|
|
@@ -7666,7 +7763,7 @@ ${schemaLines.join("\n")}`;
|
|
|
7666
7763
|
jsonMode: false
|
|
7667
7764
|
});
|
|
7668
7765
|
} catch (exc) {
|
|
7669
|
-
emitError(
|
|
7766
|
+
emitError(hooks, exc, { stage: "compute_codegen", instruction: instruction.slice(0, 200) });
|
|
7670
7767
|
throw exc;
|
|
7671
7768
|
}
|
|
7672
7769
|
const code = stripCodeFences(rawCode);
|
|
@@ -7677,12 +7774,12 @@ ${schemaLines.join("\n")}`;
|
|
|
7677
7774
|
maskedCode = redactValueRecursive(code.slice(0, 500), opts.config.redaction, {
|
|
7678
7775
|
principals,
|
|
7679
7776
|
secretKey: opts.config.secretKey,
|
|
7680
|
-
hooks
|
|
7777
|
+
hooks
|
|
7681
7778
|
});
|
|
7682
7779
|
} catch {
|
|
7683
7780
|
maskedCode = "<redaction failed: code omitted>";
|
|
7684
7781
|
}
|
|
7685
|
-
emitError(
|
|
7782
|
+
emitError(hooks, new Error(execResult.error || "compute execution failed"), {
|
|
7686
7783
|
stage: "compute_exec",
|
|
7687
7784
|
code: maskedCode
|
|
7688
7785
|
});
|
|
@@ -7703,7 +7800,7 @@ ${schemaLines.join("\n")}`;
|
|
|
7703
7800
|
return redactValueRecursive(result, opts.config.redaction, {
|
|
7704
7801
|
principals,
|
|
7705
7802
|
secretKey: opts.config.secretKey,
|
|
7706
|
-
hooks
|
|
7803
|
+
hooks
|
|
7707
7804
|
});
|
|
7708
7805
|
}
|
|
7709
7806
|
|
|
@@ -7818,10 +7915,11 @@ init_errors();
|
|
|
7818
7915
|
init_hooks();
|
|
7819
7916
|
|
|
7820
7917
|
// src/providers/embeddings.ts
|
|
7821
|
-
init_errors();
|
|
7822
7918
|
init_text();
|
|
7919
|
+
init_google();
|
|
7823
7920
|
var TIMEOUT_MS3 = 3e4;
|
|
7824
7921
|
var OPENAI_FAMILY2 = /* @__PURE__ */ new Set(["openai", "azure_openai", "custom"]);
|
|
7922
|
+
var GOOGLE_FAMILY2 = /* @__PURE__ */ new Set(["gemini", "vertex_ai"]);
|
|
7825
7923
|
function estimatedTokens(texts) {
|
|
7826
7924
|
return texts.reduce((n, t) => n + tokenCount(t), 0);
|
|
7827
7925
|
}
|
|
@@ -7893,7 +7991,7 @@ var Embedder = class {
|
|
|
7893
7991
|
/** Provider dispatch. Overridable per-instance (tests stub this). */
|
|
7894
7992
|
async rawEmbed(texts, kind = "document") {
|
|
7895
7993
|
if (OPENAI_FAMILY2.has(this.provider)) return this.embedOpenAI(texts);
|
|
7896
|
-
if (this.provider
|
|
7994
|
+
if (GOOGLE_FAMILY2.has(this.provider)) return this.embedGemini(texts);
|
|
7897
7995
|
if (this.provider === "voyage") return this.embedVoyage(texts, kind);
|
|
7898
7996
|
if (this.provider === "cohere") return this.embedCohere(texts, kind);
|
|
7899
7997
|
throw new Error(`unknown embedding provider: ${JSON.stringify(this.provider)}`);
|
|
@@ -7909,7 +8007,7 @@ var Embedder = class {
|
|
|
7909
8007
|
}
|
|
7910
8008
|
async embedGemini(texts) {
|
|
7911
8009
|
if (!this.genaiClient) {
|
|
7912
|
-
this.genaiClient = await
|
|
8010
|
+
this.genaiClient = await buildGenaiClient(this.cfg, TIMEOUT_MS3, "gemini embeddings");
|
|
7913
8011
|
}
|
|
7914
8012
|
const resp = await this.genaiClient.models.embedContent({
|
|
7915
8013
|
model: this.model,
|
|
@@ -7958,20 +8056,6 @@ var Embedder = class {
|
|
|
7958
8056
|
return this.fetchImpl;
|
|
7959
8057
|
}
|
|
7960
8058
|
};
|
|
7961
|
-
async function loadGeminiEmbedClient(apiKey) {
|
|
7962
|
-
const specifier = "@google/genai";
|
|
7963
|
-
let mod;
|
|
7964
|
-
try {
|
|
7965
|
-
mod = await import(specifier);
|
|
7966
|
-
} catch {
|
|
7967
|
-
throw new ExtraMissingError("gemini", specifier, "gemini embeddings");
|
|
7968
|
-
}
|
|
7969
|
-
const Ctor = mod.GoogleGenAI ?? mod.Client;
|
|
7970
|
-
if (!Ctor) {
|
|
7971
|
-
throw new ExtraMissingError("gemini", specifier, "gemini embeddings");
|
|
7972
|
-
}
|
|
7973
|
-
return new Ctor({ apiKey: apiKey ?? null, httpOptions: { timeout: TIMEOUT_MS3 } });
|
|
7974
|
-
}
|
|
7975
8059
|
function buildEmbedder(cfg2, opts) {
|
|
7976
8060
|
if (opts?.client || opts?.fetch || opts?.fetchImpl) {
|
|
7977
8061
|
return new Embedder(cfg2, opts);
|
|
@@ -7982,7 +8066,7 @@ function buildEmbedder(cfg2, opts) {
|
|
|
7982
8066
|
if (cfg2.provider === "voyage" || cfg2.provider === "cohere") {
|
|
7983
8067
|
return new Embedder(cfg2, { fetch: globalThis.fetch });
|
|
7984
8068
|
}
|
|
7985
|
-
if (cfg2.provider
|
|
8069
|
+
if (GOOGLE_FAMILY2.has(cfg2.provider)) {
|
|
7986
8070
|
return new Embedder(cfg2);
|
|
7987
8071
|
}
|
|
7988
8072
|
throw new Error(`unknown embedding provider: ${JSON.stringify(cfg2.provider)}`);
|
|
@@ -12949,6 +13033,6 @@ var CeleryRunner = class {
|
|
|
12949
13033
|
// src/index.ts
|
|
12950
13034
|
init_usage();
|
|
12951
13035
|
|
|
12952
|
-
export { ApprovalExpired, ApprovalNotPending, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, ContextEngine, ContextEngineConfig, DEFAULT_LEG_WEIGHT, DocumentNotFoundError, EXTRACTION_VERSION, Embedder, EngineActionError, ExtraMissingError, Extracted, GraphLegUnavailable, InProcessRunner, LLMClient, PostgresBackend, RedactionPolicy, RedactionRule, TRUSTED, ToolConfig, UNSET, __version__, applyRedaction, buildEmbedder, buildLlmClient, callLlm, compute, configSchema, createMcpApp, decryptDict, emitError, emitProgress, emitToolCall, emitUsage, encryptDict, extract2 as extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, graphUnits, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, resolvePrincipals, rrfFuse, runMigrate, runSearch, shouldRequireApproval, unitsForFile, upsertRegistry };
|
|
13036
|
+
export { ApprovalExpired, ApprovalNotPending, CeleryRunner, CodeExecutionError, CodeExecutionTimeout, ContextEngine, ContextEngineConfig, DEFAULT_LEG_WEIGHT, DocumentNotFoundError, EXTRACTION_VERSION, Embedder, EngineActionError, ExtraMissingError, Extracted, GraphLegUnavailable, InProcessRunner, LLMClient, PostgresBackend, RedactionPolicy, RedactionRule, TRUSTED, ToolConfig, UNSET, __version__, applyRedaction, buildEmbedder, buildLlmClient, callLlm, compute, computeOverFrames, configSchema, createMcpApp, decryptDict, emitError, emitProgress, emitToolCall, emitUsage, encryptDict, extract2 as extract, extractStructuredData, functionTool, getDocumentText, getSecretKey, graphUnits, listDocuments, queryStructured, redactHits, rerank, resolveApproval, resolveFields, resolvePrincipals, rrfFuse, runMigrate, runSearch, shouldRequireApproval, unitsForFile, upsertRegistry };
|
|
12953
13037
|
//# sourceMappingURL=index.js.map
|
|
12954
13038
|
//# sourceMappingURL=index.js.map
|