@promptev/context-engine 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE.md +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +112 -0
  4. package/dist/cli.js +11998 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config-Bl9U789m.d.cts +174 -0
  7. package/dist/config-Bt9bUQqU.d.ts +174 -0
  8. package/dist/embeddings-B-jZ42mk.d.cts +67 -0
  9. package/dist/embeddings-DaSdAZN3.d.ts +67 -0
  10. package/dist/express.cjs +3173 -0
  11. package/dist/express.cjs.map +1 -0
  12. package/dist/express.d.cts +24 -0
  13. package/dist/express.d.ts +24 -0
  14. package/dist/express.js +3170 -0
  15. package/dist/express.js.map +1 -0
  16. package/dist/fastify.cjs +3184 -0
  17. package/dist/fastify.cjs.map +1 -0
  18. package/dist/fastify.d.cts +16 -0
  19. package/dist/fastify.d.ts +16 -0
  20. package/dist/fastify.js +3181 -0
  21. package/dist/fastify.js.map +1 -0
  22. package/dist/governance-BDkcv4qZ.d.cts +79 -0
  23. package/dist/governance-XIScatRO.d.ts +79 -0
  24. package/dist/graph/index.cjs +1428 -0
  25. package/dist/graph/index.cjs.map +1 -0
  26. package/dist/graph/index.d.cts +104 -0
  27. package/dist/graph/index.d.ts +104 -0
  28. package/dist/graph/index.js +1413 -0
  29. package/dist/graph/index.js.map +1 -0
  30. package/dist/hono.cjs +3183 -0
  31. package/dist/hono.cjs.map +1 -0
  32. package/dist/hono.d.cts +39 -0
  33. package/dist/hono.d.ts +39 -0
  34. package/dist/hono.js +3179 -0
  35. package/dist/hono.js.map +1 -0
  36. package/dist/index.cjs +11731 -0
  37. package/dist/index.cjs.map +1 -0
  38. package/dist/index.d.cts +851 -0
  39. package/dist/index.d.ts +851 -0
  40. package/dist/index.js +11676 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/mcp.cjs +181 -0
  43. package/dist/mcp.cjs.map +1 -0
  44. package/dist/mcp.d.cts +26 -0
  45. package/dist/mcp.d.ts +26 -0
  46. package/dist/mcp.js +179 -0
  47. package/dist/mcp.js.map +1 -0
  48. package/dist/migrations/sql/0001.sql +119 -0
  49. package/dist/migrations/sql/0002_graph.sql +48 -0
  50. package/dist/migrations/sql/0003_tools.sql +61 -0
  51. package/dist/migrations/sql/0004_acl_indexes.sql +4 -0
  52. package/dist/redaction-BmDSWJ7h.d.cts +98 -0
  53. package/dist/redaction-BmDSWJ7h.d.ts +98 -0
  54. package/dist/redaction-presidio.cjs +79 -0
  55. package/dist/redaction-presidio.cjs.map +1 -0
  56. package/dist/redaction-presidio.d.cts +22 -0
  57. package/dist/redaction-presidio.d.ts +22 -0
  58. package/dist/redaction-presidio.js +73 -0
  59. package/dist/redaction-presidio.js.map +1 -0
  60. package/dist/router-CrxZ2y_Z.d.ts +82 -0
  61. package/dist/router-OPgSoYAB.d.cts +82 -0
  62. package/dist/skills/context-engine/SKILL.md +160 -0
  63. package/package.json +184 -0
  64. package/src/migrations/sql/0001.sql +119 -0
  65. package/src/migrations/sql/0002_graph.sql +48 -0
  66. package/src/migrations/sql/0003_tools.sql +61 -0
  67. package/src/migrations/sql/0004_acl_indexes.sql +4 -0
  68. package/src/skills/context-engine/SKILL.md +160 -0
@@ -0,0 +1,61 @@
1
+ -- 0003_tools — tools, approvals, calls, oauth pending
2
+
3
+ CREATE TABLE context_engine_tools (
4
+ id UUID PRIMARY KEY,
5
+ name TEXT NOT NULL,
6
+ kind TEXT NOT NULL,
7
+ description TEXT NOT NULL DEFAULT '',
8
+ source_id TEXT,
9
+ acl TEXT[],
10
+ config_encrypted TEXT,
11
+ requires_approval BOOLEAN NOT NULL DEFAULT false,
12
+ approval_policy JSONB NOT NULL DEFAULT '{}'::jsonb,
13
+ enabled BOOLEAN NOT NULL DEFAULT true,
14
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
15
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
16
+ );
17
+ CREATE INDEX ix_context_engine_tools_source_id ON context_engine_tools (source_id);
18
+
19
+ CREATE TABLE context_engine_tool_approvals (
20
+ id UUID PRIMARY KEY,
21
+ tool_name TEXT NOT NULL,
22
+ tool_args_frozen JSONB NOT NULL DEFAULT '{}'::jsonb,
23
+ source_id TEXT,
24
+ principals JSONB,
25
+ status TEXT NOT NULL DEFAULT 'pending',
26
+ approver TEXT,
27
+ approver_meta JSONB,
28
+ expires_at TIMESTAMPTZ,
29
+ resolved_at TIMESTAMPTZ,
30
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
31
+ );
32
+ CREATE INDEX ix_context_engine_tool_approvals_status ON context_engine_tool_approvals (status);
33
+
34
+ CREATE TABLE context_engine_tool_calls (
35
+ id UUID PRIMARY KEY,
36
+ tool_id UUID REFERENCES context_engine_tools(id) ON DELETE SET NULL,
37
+ tool_name TEXT NOT NULL,
38
+ kind TEXT NOT NULL,
39
+ actor_type TEXT,
40
+ actor_id TEXT,
41
+ source TEXT,
42
+ input_args JSONB NOT NULL DEFAULT '{}'::jsonb,
43
+ output_result JSONB,
44
+ output_truncated BOOLEAN NOT NULL DEFAULT false,
45
+ success BOOLEAN,
46
+ error_message TEXT,
47
+ duration_ms INTEGER,
48
+ units INTEGER,
49
+ approval_id UUID REFERENCES context_engine_tool_approvals(id) ON DELETE SET NULL,
50
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
51
+ );
52
+ CREATE INDEX ix_context_engine_tool_calls_tool_id ON context_engine_tool_calls (tool_id);
53
+ CREATE INDEX ix_context_engine_tool_calls_created_at ON context_engine_tool_calls (created_at);
54
+
55
+ CREATE TABLE context_engine_oauth_pending (
56
+ state TEXT PRIMARY KEY,
57
+ data JSONB NOT NULL,
58
+ expires_at TIMESTAMPTZ NOT NULL,
59
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
60
+ );
61
+ CREATE INDEX ix_context_engine_oauth_pending_expires_at ON context_engine_oauth_pending (expires_at);
@@ -0,0 +1,4 @@
1
+ -- 0004_acl_indexes
2
+
3
+ CREATE INDEX ix_context_engine_chunks_acl_gin ON context_engine_chunks USING gin (acl);
4
+ CREATE INDEX ix_context_engine_documents_acl_gin ON context_engine_documents USING gin (acl);
@@ -0,0 +1,98 @@
1
+ type UsageKind = "ingest" | "search" | "tool";
2
+ interface UsageEvent {
3
+ kind: UsageKind;
4
+ units: number;
5
+ detail?: Record<string, unknown>;
6
+ providerTokens?: Record<string, number>;
7
+ }
8
+ interface DocumentReport {
9
+ documentId: string;
10
+ name: string;
11
+ status: string;
12
+ pages: number | null;
13
+ chunks: number;
14
+ units: number;
15
+ graphUnits: number;
16
+ providerTokens: Record<string, number>;
17
+ error: string | null;
18
+ redactionFailed: string[];
19
+ }
20
+ interface IngestReport {
21
+ documents: DocumentReport[];
22
+ totals: {
23
+ files: number;
24
+ failed: number;
25
+ units: number;
26
+ graphUnits: number;
27
+ [key: string]: number;
28
+ };
29
+ }
30
+ declare function unitsForFile(mime: string, opts: {
31
+ pages: number | null;
32
+ slides: number | null;
33
+ sizeBytes: number;
34
+ }): number;
35
+ declare function graphUnits(chunkCount: number, primaryCommunityCount: number): number;
36
+
37
+ interface Hooks {
38
+ onUsage?: ((event: UsageEvent) => void) | null;
39
+ onError?: ((exc: unknown, ctx: Record<string, unknown>) => void) | null;
40
+ onToolCall?: ((event: Record<string, unknown>) => void) | null;
41
+ }
42
+ declare function emitUsage(hooks: Hooks | null | undefined, event: UsageEvent): void;
43
+ declare function emitError(hooks: Hooks | null | undefined, exc: unknown, ctx: Record<string, unknown>): void;
44
+ declare function emitToolCall(hooks: Hooks | null | undefined, event: Record<string, unknown>): void;
45
+
46
+ type Span = [number, number];
47
+ type DetectorFn = (text: string) => Span[];
48
+ type RedactionAction = "mask" | "hash" | "remove";
49
+ type ApplyAt = "ingest" | "output" | "both";
50
+ type RedactionPhase = "ingest" | "output";
51
+ interface RedactionRuleInit {
52
+ name: string;
53
+ detector?: string | null;
54
+ pattern?: string | null;
55
+ field?: string | null;
56
+ action?: RedactionAction;
57
+ placeholder?: string | null;
58
+ applyAt?: ApplyAt;
59
+ unless?: string[];
60
+ }
61
+ declare class RedactionRule {
62
+ name: string;
63
+ detector: string | null;
64
+ pattern: string | null;
65
+ field: string | null;
66
+ action: RedactionAction;
67
+ placeholder: string | null;
68
+ applyAt: ApplyAt;
69
+ unless: string[];
70
+ private compiled;
71
+ constructor(init: RedactionRuleInit);
72
+ private validate;
73
+ patternRe(): RegExp | null;
74
+ effectivePlaceholder(): string;
75
+ }
76
+ interface RedactionPolicyInit {
77
+ rules?: RedactionRule[] | RedactionRuleInit[];
78
+ customDetectors?: Record<string, DetectorFn>;
79
+ }
80
+ declare class RedactionPolicy {
81
+ rules: RedactionRule[];
82
+ customDetectors: Record<string, DetectorFn>;
83
+ constructor(init?: RedactionPolicyInit);
84
+ isEmpty(): boolean;
85
+ }
86
+ interface RedactionNote {
87
+ rules_fired?: string[];
88
+ spans?: number;
89
+ rules_failed?: string[];
90
+ }
91
+ declare function applyRedaction(text: string, policy: RedactionPolicy, opts: {
92
+ phase: RedactionPhase;
93
+ principals?: readonly string[] | null;
94
+ secretKey?: string | Buffer | null;
95
+ hooks?: Hooks | null;
96
+ }): [string, RedactionNote];
97
+
98
+ export { type DocumentReport as D, type Hooks as H, type IngestReport as I, RedactionPolicy as R, type UsageEvent as U, RedactionRule as a, type RedactionRuleInit as b, applyRedaction as c, emitToolCall as d, emitError as e, emitUsage as f, graphUnits as g, type DetectorFn as h, unitsForFile as u };
@@ -0,0 +1,98 @@
1
+ type UsageKind = "ingest" | "search" | "tool";
2
+ interface UsageEvent {
3
+ kind: UsageKind;
4
+ units: number;
5
+ detail?: Record<string, unknown>;
6
+ providerTokens?: Record<string, number>;
7
+ }
8
+ interface DocumentReport {
9
+ documentId: string;
10
+ name: string;
11
+ status: string;
12
+ pages: number | null;
13
+ chunks: number;
14
+ units: number;
15
+ graphUnits: number;
16
+ providerTokens: Record<string, number>;
17
+ error: string | null;
18
+ redactionFailed: string[];
19
+ }
20
+ interface IngestReport {
21
+ documents: DocumentReport[];
22
+ totals: {
23
+ files: number;
24
+ failed: number;
25
+ units: number;
26
+ graphUnits: number;
27
+ [key: string]: number;
28
+ };
29
+ }
30
+ declare function unitsForFile(mime: string, opts: {
31
+ pages: number | null;
32
+ slides: number | null;
33
+ sizeBytes: number;
34
+ }): number;
35
+ declare function graphUnits(chunkCount: number, primaryCommunityCount: number): number;
36
+
37
+ interface Hooks {
38
+ onUsage?: ((event: UsageEvent) => void) | null;
39
+ onError?: ((exc: unknown, ctx: Record<string, unknown>) => void) | null;
40
+ onToolCall?: ((event: Record<string, unknown>) => void) | null;
41
+ }
42
+ declare function emitUsage(hooks: Hooks | null | undefined, event: UsageEvent): void;
43
+ declare function emitError(hooks: Hooks | null | undefined, exc: unknown, ctx: Record<string, unknown>): void;
44
+ declare function emitToolCall(hooks: Hooks | null | undefined, event: Record<string, unknown>): void;
45
+
46
+ type Span = [number, number];
47
+ type DetectorFn = (text: string) => Span[];
48
+ type RedactionAction = "mask" | "hash" | "remove";
49
+ type ApplyAt = "ingest" | "output" | "both";
50
+ type RedactionPhase = "ingest" | "output";
51
+ interface RedactionRuleInit {
52
+ name: string;
53
+ detector?: string | null;
54
+ pattern?: string | null;
55
+ field?: string | null;
56
+ action?: RedactionAction;
57
+ placeholder?: string | null;
58
+ applyAt?: ApplyAt;
59
+ unless?: string[];
60
+ }
61
+ declare class RedactionRule {
62
+ name: string;
63
+ detector: string | null;
64
+ pattern: string | null;
65
+ field: string | null;
66
+ action: RedactionAction;
67
+ placeholder: string | null;
68
+ applyAt: ApplyAt;
69
+ unless: string[];
70
+ private compiled;
71
+ constructor(init: RedactionRuleInit);
72
+ private validate;
73
+ patternRe(): RegExp | null;
74
+ effectivePlaceholder(): string;
75
+ }
76
+ interface RedactionPolicyInit {
77
+ rules?: RedactionRule[] | RedactionRuleInit[];
78
+ customDetectors?: Record<string, DetectorFn>;
79
+ }
80
+ declare class RedactionPolicy {
81
+ rules: RedactionRule[];
82
+ customDetectors: Record<string, DetectorFn>;
83
+ constructor(init?: RedactionPolicyInit);
84
+ isEmpty(): boolean;
85
+ }
86
+ interface RedactionNote {
87
+ rules_fired?: string[];
88
+ spans?: number;
89
+ rules_failed?: string[];
90
+ }
91
+ declare function applyRedaction(text: string, policy: RedactionPolicy, opts: {
92
+ phase: RedactionPhase;
93
+ principals?: readonly string[] | null;
94
+ secretKey?: string | Buffer | null;
95
+ hooks?: Hooks | null;
96
+ }): [string, RedactionNote];
97
+
98
+ export { type DocumentReport as D, type Hooks as H, type IngestReport as I, RedactionPolicy as R, type UsageEvent as U, RedactionRule as a, type RedactionRuleInit as b, applyRedaction as c, emitToolCall as d, emitError as e, emitUsage as f, graphUnits as g, type DetectorFn as h, unitsForFile as u };
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+
5
+ // src/redaction-presidio.ts
6
+
7
+ // src/errors.ts
8
+ var ExtraMissingError = class extends Error {
9
+ constructor(extra, pkg, what) {
10
+ super(`${what} requires the '${pkg}' package (optional extra: ${extra}): npm install ${pkg}`);
11
+ this.name = "ExtraMissingError";
12
+ }
13
+ };
14
+
15
+ // src/redaction-presidio.ts
16
+ var DEFAULT_SCORE_THRESHOLD = 0.5;
17
+ function analyzerUrl() {
18
+ const url = process.env.CE_PRESIDIO_URL || process.env.PRESIDIO_URL;
19
+ if (!url) {
20
+ throw new ExtraMissingError(
21
+ "presidio",
22
+ "CE_PRESIDIO_URL",
23
+ "Presidio detectors (set CE_PRESIDIO_URL to a Presidio Analyzer HTTP endpoint)"
24
+ );
25
+ }
26
+ return url.replace(/\/$/, "");
27
+ }
28
+ function analyzeSync(text, entity, opts) {
29
+ if (!text) return [];
30
+ const base = analyzerUrl();
31
+ try {
32
+ const raw = child_process.execFileSync(
33
+ "curl",
34
+ [
35
+ "-sS",
36
+ "-X",
37
+ "POST",
38
+ `${base}/analyze`,
39
+ "-H",
40
+ "Content-Type: application/json",
41
+ "--max-time",
42
+ "10",
43
+ "-d",
44
+ JSON.stringify({ text, language: opts.language, entities: [entity] })
45
+ ],
46
+ { encoding: "utf8", timeout: 12e3 }
47
+ );
48
+ const results = JSON.parse(raw);
49
+ const spans = [];
50
+ for (const r of results) {
51
+ if ((r.score ?? 1) < opts.scoreThreshold) continue;
52
+ spans.push([Number(r.start), Number(r.end)]);
53
+ }
54
+ return spans.sort((a, b) => a[0] - b[0]);
55
+ } catch {
56
+ return [];
57
+ }
58
+ }
59
+ function presidioDetector(entity, opts = {}) {
60
+ const language = opts.language ?? "en";
61
+ const scoreThreshold = opts.scoreThreshold ?? DEFAULT_SCORE_THRESHOLD;
62
+ const fn = (text) => analyzeSync(text, entity, { language, scoreThreshold });
63
+ Object.defineProperty(fn, "name", { value: `presidio_${entity.toLowerCase()}` });
64
+ return fn;
65
+ }
66
+ function presidioDetectors(entities, opts = {}) {
67
+ analyzerUrl();
68
+ const out = {};
69
+ for (const entity of entities) out[entity] = presidioDetector(entity, opts);
70
+ return out;
71
+ }
72
+
73
+ exports.DEFAULT_SCORE_THRESHOLD = DEFAULT_SCORE_THRESHOLD;
74
+ exports.presidioDetector = presidioDetector;
75
+ exports.presidioDetectors = presidioDetectors;
76
+ exports.presidio_detector = presidioDetector;
77
+ exports.presidio_detectors = presidioDetectors;
78
+ //# sourceMappingURL=redaction-presidio.cjs.map
79
+ //# sourceMappingURL=redaction-presidio.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/redaction-presidio.ts"],"names":["execFileSync"],"mappings":"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","file":"redaction-presidio.cjs","sourcesContent":["/** Action-surface errors — user-facing / data-dependent failures (not found, ACL, bad input).\n * Config/programming errors stay as TypeError / RangeError / Error.\n */\nexport class EngineActionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"EngineActionError\";\n }\n}\n\n/** Missing vs forbidden document: identical message so callers cannot distinguish. */\nexport class DocumentNotFoundError extends Error {\n constructor(documentId: string) {\n super(`document not found: ${documentId}`);\n this.name = \"DocumentNotFoundError\";\n }\n}\n\nexport class GraphLegUnavailable extends Error {\n constructor(message = \"graph ranked list was not supplied\") {\n super(message);\n this.name = \"GraphLegUnavailable\";\n }\n}\n\nexport class ApprovalNotPending extends Error {\n constructor(message = \"approval is not pending\") {\n super(message);\n this.name = \"ApprovalNotPending\";\n }\n}\n\nexport class ApprovalExpired extends Error {\n constructor(message = \"approval has expired\") {\n super(message);\n this.name = \"ApprovalExpired\";\n }\n}\n\nexport class CodeExecutionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CodeExecutionError\";\n }\n}\n\nexport class CodeExecutionTimeout extends Error {\n constructor(message = \"code execution timed out\") {\n super(message);\n this.name = \"CodeExecutionTimeout\";\n }\n}\n\nexport class ExtraMissingError extends Error {\n constructor(extra: string, pkg: string, what: string) {\n super(`${what} requires the '${pkg}' package (optional extra: ${extra}): npm install ${pkg}`);\n this.name = \"ExtraMissingError\";\n }\n}\n","import { execFileSync } from \"node:child_process\";\nimport { ExtraMissingError } from \"./errors.js\";\nimport type { DetectorFn, Span } from \"./redaction.js\";\n\n/**\n * Microsoft Presidio has no JavaScript port. This adapter talks to a\n * Presidio Analyzer HTTP service (`CE_PRESIDIO_URL`) rather than embedding\n * spaCy. Detectors match the Python `customDetectors` shape: `(text) => Span[]`.\n *\n * The Analyzer API is async over HTTP; the sync detector uses a blocking\n * `curl` POST so `applyRedaction` can stay synchronous. Analyzer failures\n * fail-open (return no spans), matching built-in detector policy.\n */\nexport const DEFAULT_SCORE_THRESHOLD = 0.5;\n\nfunction analyzerUrl(): string {\n const url = process.env.CE_PRESIDIO_URL || process.env.PRESIDIO_URL;\n if (!url) {\n throw new ExtraMissingError(\n \"presidio\",\n \"CE_PRESIDIO_URL\",\n \"Presidio detectors (set CE_PRESIDIO_URL to a Presidio Analyzer HTTP endpoint)\",\n );\n }\n return url.replace(/\\/$/, \"\");\n}\n\nfunction analyzeSync(\n text: string,\n entity: string,\n opts: { language: string; scoreThreshold: number },\n): Span[] {\n if (!text) return [];\n const base = analyzerUrl();\n try {\n const raw = execFileSync(\n \"curl\",\n [\n \"-sS\",\n \"-X\",\n \"POST\",\n `${base}/analyze`,\n \"-H\",\n \"Content-Type: application/json\",\n \"--max-time\",\n \"10\",\n \"-d\",\n JSON.stringify({ text, language: opts.language, entities: [entity] }),\n ],\n { encoding: \"utf8\", timeout: 12_000 },\n );\n const results = JSON.parse(raw) as Array<{ start: number; end: number; score?: number }>;\n const spans: Span[] = [];\n for (const r of results) {\n if ((r.score ?? 1) < opts.scoreThreshold) continue;\n spans.push([Number(r.start), Number(r.end)]);\n }\n return spans.sort((a, b) => a[0] - b[0]);\n } catch {\n return [];\n }\n}\n\nexport function presidioDetector(\n entity: string,\n opts: { language?: string; scoreThreshold?: number } = {},\n): DetectorFn {\n const language = opts.language ?? \"en\";\n const scoreThreshold = opts.scoreThreshold ?? DEFAULT_SCORE_THRESHOLD;\n const fn: DetectorFn = (text: string) => analyzeSync(text, entity, { language, scoreThreshold });\n Object.defineProperty(fn, \"name\", { value: `presidio_${entity.toLowerCase()}` });\n return fn;\n}\n\nexport function presidioDetectors(\n entities: string[],\n opts: { language?: string; scoreThreshold?: number } = {},\n): Record<string, DetectorFn> {\n analyzerUrl();\n const out: Record<string, DetectorFn> = {};\n for (const entity of entities) out[entity] = presidioDetector(entity, opts);\n return out;\n}\n\nexport { presidioDetector as presidio_detector, presidioDetectors as presidio_detectors };\n"]}
@@ -0,0 +1,22 @@
1
+ import { h as DetectorFn } from './redaction-BmDSWJ7h.cjs';
2
+
3
+ /**
4
+ * Microsoft Presidio has no JavaScript port. This adapter talks to a
5
+ * Presidio Analyzer HTTP service (`CE_PRESIDIO_URL`) rather than embedding
6
+ * spaCy. Detectors match the Python `customDetectors` shape: `(text) => Span[]`.
7
+ *
8
+ * The Analyzer API is async over HTTP; the sync detector uses a blocking
9
+ * `curl` POST so `applyRedaction` can stay synchronous. Analyzer failures
10
+ * fail-open (return no spans), matching built-in detector policy.
11
+ */
12
+ declare const DEFAULT_SCORE_THRESHOLD = 0.5;
13
+ declare function presidioDetector(entity: string, opts?: {
14
+ language?: string;
15
+ scoreThreshold?: number;
16
+ }): DetectorFn;
17
+ declare function presidioDetectors(entities: string[], opts?: {
18
+ language?: string;
19
+ scoreThreshold?: number;
20
+ }): Record<string, DetectorFn>;
21
+
22
+ export { DEFAULT_SCORE_THRESHOLD, presidioDetector, presidioDetectors, presidioDetector as presidio_detector, presidioDetectors as presidio_detectors };
@@ -0,0 +1,22 @@
1
+ import { h as DetectorFn } from './redaction-BmDSWJ7h.js';
2
+
3
+ /**
4
+ * Microsoft Presidio has no JavaScript port. This adapter talks to a
5
+ * Presidio Analyzer HTTP service (`CE_PRESIDIO_URL`) rather than embedding
6
+ * spaCy. Detectors match the Python `customDetectors` shape: `(text) => Span[]`.
7
+ *
8
+ * The Analyzer API is async over HTTP; the sync detector uses a blocking
9
+ * `curl` POST so `applyRedaction` can stay synchronous. Analyzer failures
10
+ * fail-open (return no spans), matching built-in detector policy.
11
+ */
12
+ declare const DEFAULT_SCORE_THRESHOLD = 0.5;
13
+ declare function presidioDetector(entity: string, opts?: {
14
+ language?: string;
15
+ scoreThreshold?: number;
16
+ }): DetectorFn;
17
+ declare function presidioDetectors(entities: string[], opts?: {
18
+ language?: string;
19
+ scoreThreshold?: number;
20
+ }): Record<string, DetectorFn>;
21
+
22
+ export { DEFAULT_SCORE_THRESHOLD, presidioDetector, presidioDetectors, presidioDetector as presidio_detector, presidioDetectors as presidio_detectors };
@@ -0,0 +1,73 @@
1
+ import { execFileSync } from 'child_process';
2
+
3
+ // src/redaction-presidio.ts
4
+
5
+ // src/errors.ts
6
+ var ExtraMissingError = class extends Error {
7
+ constructor(extra, pkg, what) {
8
+ super(`${what} requires the '${pkg}' package (optional extra: ${extra}): npm install ${pkg}`);
9
+ this.name = "ExtraMissingError";
10
+ }
11
+ };
12
+
13
+ // src/redaction-presidio.ts
14
+ var DEFAULT_SCORE_THRESHOLD = 0.5;
15
+ function analyzerUrl() {
16
+ const url = process.env.CE_PRESIDIO_URL || process.env.PRESIDIO_URL;
17
+ if (!url) {
18
+ throw new ExtraMissingError(
19
+ "presidio",
20
+ "CE_PRESIDIO_URL",
21
+ "Presidio detectors (set CE_PRESIDIO_URL to a Presidio Analyzer HTTP endpoint)"
22
+ );
23
+ }
24
+ return url.replace(/\/$/, "");
25
+ }
26
+ function analyzeSync(text, entity, opts) {
27
+ if (!text) return [];
28
+ const base = analyzerUrl();
29
+ try {
30
+ const raw = execFileSync(
31
+ "curl",
32
+ [
33
+ "-sS",
34
+ "-X",
35
+ "POST",
36
+ `${base}/analyze`,
37
+ "-H",
38
+ "Content-Type: application/json",
39
+ "--max-time",
40
+ "10",
41
+ "-d",
42
+ JSON.stringify({ text, language: opts.language, entities: [entity] })
43
+ ],
44
+ { encoding: "utf8", timeout: 12e3 }
45
+ );
46
+ const results = JSON.parse(raw);
47
+ const spans = [];
48
+ for (const r of results) {
49
+ if ((r.score ?? 1) < opts.scoreThreshold) continue;
50
+ spans.push([Number(r.start), Number(r.end)]);
51
+ }
52
+ return spans.sort((a, b) => a[0] - b[0]);
53
+ } catch {
54
+ return [];
55
+ }
56
+ }
57
+ function presidioDetector(entity, opts = {}) {
58
+ const language = opts.language ?? "en";
59
+ const scoreThreshold = opts.scoreThreshold ?? DEFAULT_SCORE_THRESHOLD;
60
+ const fn = (text) => analyzeSync(text, entity, { language, scoreThreshold });
61
+ Object.defineProperty(fn, "name", { value: `presidio_${entity.toLowerCase()}` });
62
+ return fn;
63
+ }
64
+ function presidioDetectors(entities, opts = {}) {
65
+ analyzerUrl();
66
+ const out = {};
67
+ for (const entity of entities) out[entity] = presidioDetector(entity, opts);
68
+ return out;
69
+ }
70
+
71
+ export { DEFAULT_SCORE_THRESHOLD, presidioDetector, presidioDetectors, presidioDetector as presidio_detector, presidioDetectors as presidio_detectors };
72
+ //# sourceMappingURL=redaction-presidio.js.map
73
+ //# sourceMappingURL=redaction-presidio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/redaction-presidio.ts"],"names":[],"mappings":";;;;;AAqDO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAC3C,WAAA,CAAY,KAAA,EAAe,GAAA,EAAa,IAAA,EAAc;AACpD,IAAA,KAAA,CAAM,CAAA,EAAG,IAAI,CAAA,eAAA,EAAkB,GAAG,8BAA8B,KAAK,CAAA,eAAA,EAAkB,GAAG,CAAA,CAAE,CAAA;AAC5F,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AAAA,EACd;AACF,CAAA;;;AC7CO,IAAM,uBAAA,GAA0B;AAEvC,SAAS,WAAA,GAAsB;AAC7B,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,CAAI,eAAA,IAAmB,QAAQ,GAAA,CAAI,YAAA;AACvD,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,iBAAA;AAAA,MACR,UAAA;AAAA,MACA,iBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAC9B;AAEA,SAAS,WAAA,CACP,IAAA,EACA,MAAA,EACA,IAAA,EACQ;AACR,EAAA,IAAI,CAAC,IAAA,EAAM,OAAO,EAAC;AACnB,EAAA,MAAM,OAAO,WAAA,EAAY;AACzB,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,YAAA;AAAA,MACV,MAAA;AAAA,MACA;AAAA,QACE,KAAA;AAAA,QACA,IAAA;AAAA,QACA,MAAA;AAAA,QACA,GAAG,IAAI,CAAA,QAAA,CAAA;AAAA,QACP,IAAA;AAAA,QACA,gCAAA;AAAA,QACA,YAAA;AAAA,QACA,IAAA;AAAA,QACA,IAAA;AAAA,QACA,IAAA,CAAK,SAAA,CAAU,EAAE,IAAA,EAAM,QAAA,EAAU,IAAA,CAAK,QAAA,EAAU,QAAA,EAAU,CAAC,MAAM,CAAA,EAAG;AAAA,OACtE;AAAA,MACA,EAAE,QAAA,EAAU,MAAA,EAAQ,OAAA,EAAS,IAAA;AAAO,KACtC;AACA,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC9B,IAAA,MAAM,QAAgB,EAAC;AACvB,IAAA,KAAA,MAAW,KAAK,OAAA,EAAS;AACvB,MAAA,IAAA,CAAK,CAAA,CAAE,KAAA,IAAS,CAAA,IAAK,IAAA,CAAK,cAAA,EAAgB;AAC1C,MAAA,KAAA,CAAM,IAAA,CAAK,CAAC,MAAA,CAAO,CAAA,CAAE,KAAK,GAAG,MAAA,CAAO,CAAA,CAAE,GAAG,CAAC,CAAC,CAAA;AAAA,IAC7C;AACA,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,EAAE,CAAC,CAAA,GAAI,CAAA,CAAE,CAAC,CAAC,CAAA;AAAA,EACzC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAC;AAAA,EACV;AACF;AAEO,SAAS,gBAAA,CACd,MAAA,EACA,IAAA,GAAuD,EAAC,EAC5C;AACZ,EAAA,MAAM,QAAA,GAAW,KAAK,QAAA,IAAY,IAAA;AAClC,EAAA,MAAM,cAAA,GAAiB,KAAK,cAAA,IAAkB,uBAAA;AAC9C,EAAA,MAAM,EAAA,GAAiB,CAAC,IAAA,KAAiB,WAAA,CAAY,MAAM,MAAA,EAAQ,EAAE,QAAA,EAAU,cAAA,EAAgB,CAAA;AAC/F,EAAA,MAAA,CAAO,cAAA,CAAe,EAAA,EAAI,MAAA,EAAQ,EAAE,KAAA,EAAO,YAAY,MAAA,CAAO,WAAA,EAAa,CAAA,CAAA,EAAI,CAAA;AAC/E,EAAA,OAAO,EAAA;AACT;AAEO,SAAS,iBAAA,CACd,QAAA,EACA,IAAA,GAAuD,EAAC,EAC5B;AAC5B,EAAA,WAAA,EAAY;AACZ,EAAA,MAAM,MAAkC,EAAC;AACzC,EAAA,KAAA,MAAW,UAAU,QAAA,EAAU,GAAA,CAAI,MAAM,CAAA,GAAI,gBAAA,CAAiB,QAAQ,IAAI,CAAA;AAC1E,EAAA,OAAO,GAAA;AACT","file":"redaction-presidio.js","sourcesContent":["/** Action-surface errors — user-facing / data-dependent failures (not found, ACL, bad input).\n * Config/programming errors stay as TypeError / RangeError / Error.\n */\nexport class EngineActionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"EngineActionError\";\n }\n}\n\n/** Missing vs forbidden document: identical message so callers cannot distinguish. */\nexport class DocumentNotFoundError extends Error {\n constructor(documentId: string) {\n super(`document not found: ${documentId}`);\n this.name = \"DocumentNotFoundError\";\n }\n}\n\nexport class GraphLegUnavailable extends Error {\n constructor(message = \"graph ranked list was not supplied\") {\n super(message);\n this.name = \"GraphLegUnavailable\";\n }\n}\n\nexport class ApprovalNotPending extends Error {\n constructor(message = \"approval is not pending\") {\n super(message);\n this.name = \"ApprovalNotPending\";\n }\n}\n\nexport class ApprovalExpired extends Error {\n constructor(message = \"approval has expired\") {\n super(message);\n this.name = \"ApprovalExpired\";\n }\n}\n\nexport class CodeExecutionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CodeExecutionError\";\n }\n}\n\nexport class CodeExecutionTimeout extends Error {\n constructor(message = \"code execution timed out\") {\n super(message);\n this.name = \"CodeExecutionTimeout\";\n }\n}\n\nexport class ExtraMissingError extends Error {\n constructor(extra: string, pkg: string, what: string) {\n super(`${what} requires the '${pkg}' package (optional extra: ${extra}): npm install ${pkg}`);\n this.name = \"ExtraMissingError\";\n }\n}\n","import { execFileSync } from \"node:child_process\";\nimport { ExtraMissingError } from \"./errors.js\";\nimport type { DetectorFn, Span } from \"./redaction.js\";\n\n/**\n * Microsoft Presidio has no JavaScript port. This adapter talks to a\n * Presidio Analyzer HTTP service (`CE_PRESIDIO_URL`) rather than embedding\n * spaCy. Detectors match the Python `customDetectors` shape: `(text) => Span[]`.\n *\n * The Analyzer API is async over HTTP; the sync detector uses a blocking\n * `curl` POST so `applyRedaction` can stay synchronous. Analyzer failures\n * fail-open (return no spans), matching built-in detector policy.\n */\nexport const DEFAULT_SCORE_THRESHOLD = 0.5;\n\nfunction analyzerUrl(): string {\n const url = process.env.CE_PRESIDIO_URL || process.env.PRESIDIO_URL;\n if (!url) {\n throw new ExtraMissingError(\n \"presidio\",\n \"CE_PRESIDIO_URL\",\n \"Presidio detectors (set CE_PRESIDIO_URL to a Presidio Analyzer HTTP endpoint)\",\n );\n }\n return url.replace(/\\/$/, \"\");\n}\n\nfunction analyzeSync(\n text: string,\n entity: string,\n opts: { language: string; scoreThreshold: number },\n): Span[] {\n if (!text) return [];\n const base = analyzerUrl();\n try {\n const raw = execFileSync(\n \"curl\",\n [\n \"-sS\",\n \"-X\",\n \"POST\",\n `${base}/analyze`,\n \"-H\",\n \"Content-Type: application/json\",\n \"--max-time\",\n \"10\",\n \"-d\",\n JSON.stringify({ text, language: opts.language, entities: [entity] }),\n ],\n { encoding: \"utf8\", timeout: 12_000 },\n );\n const results = JSON.parse(raw) as Array<{ start: number; end: number; score?: number }>;\n const spans: Span[] = [];\n for (const r of results) {\n if ((r.score ?? 1) < opts.scoreThreshold) continue;\n spans.push([Number(r.start), Number(r.end)]);\n }\n return spans.sort((a, b) => a[0] - b[0]);\n } catch {\n return [];\n }\n}\n\nexport function presidioDetector(\n entity: string,\n opts: { language?: string; scoreThreshold?: number } = {},\n): DetectorFn {\n const language = opts.language ?? \"en\";\n const scoreThreshold = opts.scoreThreshold ?? DEFAULT_SCORE_THRESHOLD;\n const fn: DetectorFn = (text: string) => analyzeSync(text, entity, { language, scoreThreshold });\n Object.defineProperty(fn, \"name\", { value: `presidio_${entity.toLowerCase()}` });\n return fn;\n}\n\nexport function presidioDetectors(\n entities: string[],\n opts: { language?: string; scoreThreshold?: number } = {},\n): Record<string, DetectorFn> {\n analyzerUrl();\n const out: Record<string, DetectorFn> = {};\n for (const entity of entities) out[entity] = presidioDetector(entity, opts);\n return out;\n}\n\nexport { presidioDetector as presidio_detector, presidioDetectors as presidio_detectors };\n"]}
@@ -0,0 +1,82 @@
1
+ import { T as ToolEngine, a as ToolConfig } from './governance-XIScatRO.js';
2
+
3
+ type ContextEngineLike = {
4
+ ingest: (args: Record<string, unknown>) => Promise<unknown>;
5
+ search: (query: string, opts?: Record<string, unknown>) => Promise<{
6
+ hits?: unknown[];
7
+ usage?: unknown;
8
+ }>;
9
+ listDocuments: (opts: Record<string, unknown>) => Promise<unknown>;
10
+ getDocument: (id: string, opts?: Record<string, unknown>) => Promise<unknown>;
11
+ deleteDocument: (id: string, opts?: Record<string, unknown>) => Promise<unknown>;
12
+ updateDocument: (id: string, opts?: Record<string, unknown>) => Promise<unknown>;
13
+ stats: (sourceId?: string | null) => Promise<unknown>;
14
+ };
15
+ declare function handleIngestJson(engine: ContextEngineLike, payload: unknown, principals: unknown): Promise<unknown>;
16
+
17
+ interface PendingStore {
18
+ put(state: string, data: Record<string, unknown>, ttlSeconds?: number): void | Promise<void>;
19
+ pop(state: string): Record<string, unknown> | null | Promise<Record<string, unknown> | null>;
20
+ }
21
+
22
+ type ToolsHandlerEngine = ToolEngine & {
23
+ registerTool?: (tc: ToolConfig) => Promise<string>;
24
+ updateTool?: (id: string, opts: Record<string, unknown>) => Promise<ToolConfig>;
25
+ deleteTool?: (id: string, opts?: Record<string, unknown>) => Promise<void>;
26
+ testTool?: (tc: ToolConfig) => Promise<Record<string, unknown>>;
27
+ executeTool?: (callName: string, args: Record<string, unknown> | null, opts?: Record<string, unknown>) => Promise<Record<string, unknown>>;
28
+ hooks?: ToolEngine["hooks"];
29
+ };
30
+ declare function createToolsHandlers(engine: ToolsHandlerEngine, opts?: {
31
+ redirectBaseUrl?: string;
32
+ pendingStore?: PendingStore | null;
33
+ }): {
34
+ createTool(body: unknown, principals: unknown): Promise<Record<string, unknown>>;
35
+ listToolsAdmin(query: {
36
+ source_id?: string | null;
37
+ }, principals: unknown): Promise<Record<string, unknown>>;
38
+ getTool(toolId: string, principals: unknown): Promise<Record<string, unknown>>;
39
+ updateToolRoute(toolId: string, body: Record<string, unknown>, principals: unknown): Promise<Record<string, unknown>>;
40
+ deleteToolRoute(toolId: string, principals: unknown): Promise<Record<string, unknown>>;
41
+ testToolRoute(body: unknown): Promise<Record<string, unknown>>;
42
+ toolSchemaRoute(kind: string): Record<string, unknown>;
43
+ executeToolRoute(body: {
44
+ call_name?: string;
45
+ args?: Record<string, unknown> | null;
46
+ source_id?: string | null;
47
+ }, principals: unknown): Promise<Record<string, unknown>>;
48
+ mcpConnectAndList(body: {
49
+ server_name: string;
50
+ url: string;
51
+ token?: string | null;
52
+ headers?: Record<string, string> | null;
53
+ include_resources?: boolean;
54
+ }): Promise<Record<string, unknown>>;
55
+ mcpOauthStart(body: {
56
+ server_url: string;
57
+ tool_id?: string | null;
58
+ client_id?: string | null;
59
+ client_secret?: string | null;
60
+ scopes?: string | null;
61
+ }): Promise<Record<string, unknown>>;
62
+ mcpOauthCallback(query: {
63
+ code?: string | null;
64
+ state?: string | null;
65
+ error?: string | null;
66
+ error_description?: string | null;
67
+ }): Promise<{
68
+ html: string;
69
+ contentType: string;
70
+ }>;
71
+ listApprovalsRoute(query: {
72
+ status?: string | null;
73
+ source_id?: string | null;
74
+ }, principals: unknown): Promise<Record<string, unknown>>;
75
+ resolveApprovalRoute(approvalId: string, body: {
76
+ decision: "approved" | "rejected";
77
+ approver: string;
78
+ meta?: Record<string, unknown> | null;
79
+ }, principals: unknown): Promise<Record<string, unknown>>;
80
+ };
81
+
82
+ export { createToolsHandlers as c, handleIngestJson as h };
@@ -0,0 +1,82 @@
1
+ import { T as ToolEngine, a as ToolConfig } from './governance-BDkcv4qZ.cjs';
2
+
3
+ type ContextEngineLike = {
4
+ ingest: (args: Record<string, unknown>) => Promise<unknown>;
5
+ search: (query: string, opts?: Record<string, unknown>) => Promise<{
6
+ hits?: unknown[];
7
+ usage?: unknown;
8
+ }>;
9
+ listDocuments: (opts: Record<string, unknown>) => Promise<unknown>;
10
+ getDocument: (id: string, opts?: Record<string, unknown>) => Promise<unknown>;
11
+ deleteDocument: (id: string, opts?: Record<string, unknown>) => Promise<unknown>;
12
+ updateDocument: (id: string, opts?: Record<string, unknown>) => Promise<unknown>;
13
+ stats: (sourceId?: string | null) => Promise<unknown>;
14
+ };
15
+ declare function handleIngestJson(engine: ContextEngineLike, payload: unknown, principals: unknown): Promise<unknown>;
16
+
17
+ interface PendingStore {
18
+ put(state: string, data: Record<string, unknown>, ttlSeconds?: number): void | Promise<void>;
19
+ pop(state: string): Record<string, unknown> | null | Promise<Record<string, unknown> | null>;
20
+ }
21
+
22
+ type ToolsHandlerEngine = ToolEngine & {
23
+ registerTool?: (tc: ToolConfig) => Promise<string>;
24
+ updateTool?: (id: string, opts: Record<string, unknown>) => Promise<ToolConfig>;
25
+ deleteTool?: (id: string, opts?: Record<string, unknown>) => Promise<void>;
26
+ testTool?: (tc: ToolConfig) => Promise<Record<string, unknown>>;
27
+ executeTool?: (callName: string, args: Record<string, unknown> | null, opts?: Record<string, unknown>) => Promise<Record<string, unknown>>;
28
+ hooks?: ToolEngine["hooks"];
29
+ };
30
+ declare function createToolsHandlers(engine: ToolsHandlerEngine, opts?: {
31
+ redirectBaseUrl?: string;
32
+ pendingStore?: PendingStore | null;
33
+ }): {
34
+ createTool(body: unknown, principals: unknown): Promise<Record<string, unknown>>;
35
+ listToolsAdmin(query: {
36
+ source_id?: string | null;
37
+ }, principals: unknown): Promise<Record<string, unknown>>;
38
+ getTool(toolId: string, principals: unknown): Promise<Record<string, unknown>>;
39
+ updateToolRoute(toolId: string, body: Record<string, unknown>, principals: unknown): Promise<Record<string, unknown>>;
40
+ deleteToolRoute(toolId: string, principals: unknown): Promise<Record<string, unknown>>;
41
+ testToolRoute(body: unknown): Promise<Record<string, unknown>>;
42
+ toolSchemaRoute(kind: string): Record<string, unknown>;
43
+ executeToolRoute(body: {
44
+ call_name?: string;
45
+ args?: Record<string, unknown> | null;
46
+ source_id?: string | null;
47
+ }, principals: unknown): Promise<Record<string, unknown>>;
48
+ mcpConnectAndList(body: {
49
+ server_name: string;
50
+ url: string;
51
+ token?: string | null;
52
+ headers?: Record<string, string> | null;
53
+ include_resources?: boolean;
54
+ }): Promise<Record<string, unknown>>;
55
+ mcpOauthStart(body: {
56
+ server_url: string;
57
+ tool_id?: string | null;
58
+ client_id?: string | null;
59
+ client_secret?: string | null;
60
+ scopes?: string | null;
61
+ }): Promise<Record<string, unknown>>;
62
+ mcpOauthCallback(query: {
63
+ code?: string | null;
64
+ state?: string | null;
65
+ error?: string | null;
66
+ error_description?: string | null;
67
+ }): Promise<{
68
+ html: string;
69
+ contentType: string;
70
+ }>;
71
+ listApprovalsRoute(query: {
72
+ status?: string | null;
73
+ source_id?: string | null;
74
+ }, principals: unknown): Promise<Record<string, unknown>>;
75
+ resolveApprovalRoute(approvalId: string, body: {
76
+ decision: "approved" | "rejected";
77
+ approver: string;
78
+ meta?: Record<string, unknown> | null;
79
+ }, principals: unknown): Promise<Record<string, unknown>>;
80
+ };
81
+
82
+ export { createToolsHandlers as c, handleIngestJson as h };