@devilsdev/rag-core 3.4.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/all.d.ts +59 -0
- package/dist/index.cjs +443 -48
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types/adapters/mastra.d.ts +6 -2
- package/dist/types/agentic/agentic-pipeline.d.ts +1 -1
- package/dist/types/agentic/iterative-retriever.d.ts +1 -1
- package/dist/types/agentic/query-planner.d.ts +1 -1
- package/dist/types/agentic/self-critique.d.ts +1 -1
- package/dist/types/ai/federation/federated-learning-coordinator.d.ts +1 -1
- package/dist/types/ai/training/model-training-orchestrator.d.ts +1 -1
- package/dist/types/chunking/chunking-engine.d.ts +1 -1
- package/dist/types/citation/citation-tracker.d.ts +1 -1
- package/dist/types/config/component-factory.d.ts +1 -0
- package/dist/types/connectors/anthropic-connector.d.ts +35 -1
- package/dist/types/connectors/base-connector.d.ts +1 -1
- package/dist/types/connectors/connector-utils.d.ts +20 -0
- package/dist/types/cost/cost-calculator.d.ts +1 -1
- package/dist/types/cost/cost-tracker.d.ts +1 -1
- package/dist/types/cost/token-budget.d.ts +1 -1
- package/dist/types/dashboard/dashboard-generator.d.ts +1 -1
- package/dist/types/dashboard/metrics-aggregator.d.ts +1 -1
- package/dist/types/debug/execution-tracer.d.ts +1 -1
- package/dist/types/debug/trace-inspector.d.ts +1 -1
- package/dist/types/dev/dev-server.d.ts +1 -1
- package/dist/types/dev/hot-reload.d.ts +1 -1
- package/dist/types/ecosystem/plugin-analytics-dashboard.d.ts +1 -1
- package/dist/types/ecosystem/plugin-certification.d.ts +1 -1
- package/dist/types/ecosystem/plugin-hub.d.ts +1 -1
- package/dist/types/enterprise/audit-logging.d.ts +1 -1
- package/dist/types/enterprise/data-governance.d.ts +1 -1
- package/dist/types/enterprise/multi-tenancy.d.ts +1 -1
- package/dist/types/enterprise/sso-integration.d.ts +1 -1
- package/dist/types/evaluate/pipeline-evaluator.d.ts +1 -1
- package/dist/types/graph/entity-extractor.d.ts +1 -1
- package/dist/types/graph/graph-retriever.d.ts +1 -1
- package/dist/types/graph/knowledge-graph.d.ts +1 -1
- package/dist/types/grounding/llm-judge.d.ts +10 -3
- package/dist/types/grounding/provider-citations.d.ts +244 -0
- package/dist/types/guardrails/detectors.d.ts +88 -0
- package/dist/types/guardrails/evaluate-detectors.d.ts +61 -0
- package/dist/types/guardrails/guardrails-pipeline.d.ts +2 -9
- package/dist/types/guardrails/post-generation-guard.d.ts +33 -3
- package/dist/types/guardrails/pre-retrieval-guard.d.ts +29 -1
- package/dist/types/guardrails/retrieval-guard.d.ts +30 -1
- package/dist/types/mcp/mcp-server.d.ts +1 -1
- package/dist/types/observability/otel.d.ts +9 -3
- package/dist/types/observability/scores.d.ts +57 -0
- package/dist/types/reranker/cascade-reranker.d.ts +1 -1
- package/dist/types/reranker/embedding-reranker.d.ts +1 -1
- package/dist/types/reranker/scoring-reranker.d.ts +1 -1
- package/dist/types/retrieval/bm25-search.d.ts +1 -1
- package/dist/types/retrieval/hybrid-retriever.d.ts +1 -1
- package/dist/types/retrieval/pinecone-retriever.d.ts +141 -0
- package/dist/types/security/jwt-validator.d.ts +1 -1
- package/dist/types/security/plugin-sandbox.d.ts +1 -1
- package/dist/types/streaming/sse-adapter.d.ts +1 -1
- package/dist/types/streaming/stream-router.d.ts +1 -1
- package/dist/types/streaming/streaming-embedder.d.ts +1 -1
- package/dist/types/streaming/websocket-adapter.d.ts +1 -1
- package/dist/types/templates/scaffold.d.ts +1 -1
- package/dist/types/testing/contract-tests.d.ts +8 -4
- package/dist/types/utils/batch-processor.d.ts +1 -1
- package/dist/types/utils/connection-pool.d.ts +1 -1
- package/dist/types/utils/optional-peer.d.ts +21 -1
- package/package.json +2 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object} result - A pipeline run result (or a stream's done
|
|
3
|
+
* chunk) with `evaluation` and/or `citations`, or a checkAnswer() result
|
|
4
|
+
* @param {object} [options]
|
|
5
|
+
* @param {boolean} [options.explanations=false] - Include explanations,
|
|
6
|
+
* which quote the answer
|
|
7
|
+
* @returns {Array<{name: string, value: number, target: 'retrieval'|'generation', label?: string, explanation?: string}>}
|
|
8
|
+
*/
|
|
9
|
+
export function evaluationScores(result: object, { explanations }?: {
|
|
10
|
+
explanations?: boolean;
|
|
11
|
+
}): Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
value: number;
|
|
14
|
+
target: "retrieval" | "generation";
|
|
15
|
+
label?: string;
|
|
16
|
+
explanation?: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* The scores of a run result or answer check as Langfuse scores: the
|
|
20
|
+
* objects `langfuse.score.create()` takes (from `@langfuse/client`), and,
|
|
21
|
+
* without a trace id, the evaluations a Langfuse experiment evaluator
|
|
22
|
+
* returns. Langfuse is not a dependency.
|
|
23
|
+
*
|
|
24
|
+
* With `telemetry` on, a run result carries its OpenTelemetry trace and span
|
|
25
|
+
* ids in `result.telemetry`; Langfuse uses the same ids when it receives the
|
|
26
|
+
* spans (LangfuseSpanProcessor), so each score is attached to the trace and
|
|
27
|
+
* to the span it judges: the retrieval for contextPrecision and
|
|
28
|
+
* contextRecall, the generation for the rest. A score whose stage had no
|
|
29
|
+
* span (a cache hit) gets the trace only: Langfuse's default span filter
|
|
30
|
+
* keeps the stage spans (they have gen_ai.* attributes) but not the run
|
|
31
|
+
* span, so an observation id for it could point at nothing.
|
|
32
|
+
*
|
|
33
|
+
* @param {object} result - A pipeline run result, a stream's done chunk, or a checkAnswer() result
|
|
34
|
+
* @param {object} [options]
|
|
35
|
+
* @param {string} [options.traceId] - Overrides `result.telemetry.traceId`
|
|
36
|
+
* @param {string} [options.observationId] - Attach every score to this observation
|
|
37
|
+
* @param {string} [options.sessionId]
|
|
38
|
+
* @param {boolean} [options.comments=false] - Add explanations as comments; they quote the answer
|
|
39
|
+
* @returns {Array<{name: string, value: number, dataType: 'NUMERIC', traceId?: string, observationId?: string, sessionId?: string, comment?: string, metadata?: {label: string}}>}
|
|
40
|
+
*/
|
|
41
|
+
export function toLangfuseScores(result: object, options?: {
|
|
42
|
+
traceId?: string;
|
|
43
|
+
observationId?: string;
|
|
44
|
+
sessionId?: string;
|
|
45
|
+
comments?: boolean;
|
|
46
|
+
}): Array<{
|
|
47
|
+
name: string;
|
|
48
|
+
value: number;
|
|
49
|
+
dataType: "NUMERIC";
|
|
50
|
+
traceId?: string;
|
|
51
|
+
observationId?: string;
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
comment?: string;
|
|
54
|
+
metadata?: {
|
|
55
|
+
label: string;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @extends EventEmitter
|
|
7
7
|
*/
|
|
8
|
-
export class CascadeReranker extends EventEmitter
|
|
8
|
+
export class CascadeReranker extends EventEmitter {
|
|
9
9
|
/**
|
|
10
10
|
* @param {object[]} [rerankers=[]] - Array of objects with .rerank() method
|
|
11
11
|
* @param {object} [options]
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @extends EventEmitter
|
|
10
10
|
*/
|
|
11
|
-
export class EmbeddingReranker extends EventEmitter
|
|
11
|
+
export class EmbeddingReranker extends EventEmitter {
|
|
12
12
|
/**
|
|
13
13
|
* @param {object} embedder - Must expose .embedQuery(text) or .embed(text)
|
|
14
14
|
* @param {object} [options]
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Keyword search with BM25 ranking. Index documents with index(), then
|
|
3
3
|
* search(query) returns them scored by term frequency and rarity.
|
|
4
4
|
*/
|
|
5
|
-
export class BM25Search extends EventEmitter
|
|
5
|
+
export class BM25Search extends EventEmitter {
|
|
6
6
|
constructor(options?: {});
|
|
7
7
|
config: {
|
|
8
8
|
k1: number;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Runs several retrievers in parallel (for example vector and BM25) and
|
|
3
3
|
* fuses their results with weighted reciprocal rank fusion.
|
|
4
4
|
*/
|
|
5
|
-
export class HybridRetriever extends EventEmitter
|
|
5
|
+
export class HybridRetriever extends EventEmitter {
|
|
6
6
|
/**
|
|
7
7
|
* @param {Array<{retriever: object, weight: number, name: string}>} retrievers
|
|
8
8
|
* @param {object} options
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retriever on a Pinecone serverless index over its REST API, with no
|
|
3
|
+
* client package. The index must exist, with a dense vector of your
|
|
4
|
+
* embedding model's dimension; use the cosine metric for the scores the
|
|
5
|
+
* other retrievers return.
|
|
6
|
+
*/
|
|
7
|
+
export class PineconeRetriever {
|
|
8
|
+
/**
|
|
9
|
+
* @param {Object} options
|
|
10
|
+
* @param {string} [options.apiKey] - Defaults to PINECONE_API_KEY
|
|
11
|
+
* @param {string} [options.index] - The index name, described on first use
|
|
12
|
+
* @param {string} [options.host] - The index host (from the console), instead of or with `index`
|
|
13
|
+
* @param {string} [options.namespace='rag_documents'] - A namespace this retriever owns
|
|
14
|
+
* @param {'auto'|'documents'|'vectors'} [options.api='auto'] - Document index (Documents API) or vector index; auto reads it from the index description
|
|
15
|
+
* @param {string} [options.vectorField] - The document index's dense_vector field (default: the schema's)
|
|
16
|
+
* @param {number} [options.freshnessTimeoutMs=30000] - How long a read waits for this retriever's writes to be indexed; 0 to not wait
|
|
17
|
+
* @param {string} [options.cacheKey] - Cache identity; change it when the index changes
|
|
18
|
+
* @param {Function} [options.fetch] - fetch implementation (defaults to the global)
|
|
19
|
+
*/
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
index?: string;
|
|
23
|
+
host?: string;
|
|
24
|
+
namespace?: string;
|
|
25
|
+
api?: "auto" | "documents" | "vectors";
|
|
26
|
+
vectorField?: string;
|
|
27
|
+
freshnessTimeoutMs?: number;
|
|
28
|
+
cacheKey?: string;
|
|
29
|
+
fetch?: Function;
|
|
30
|
+
});
|
|
31
|
+
index: string;
|
|
32
|
+
namespace: string;
|
|
33
|
+
freshnessTimeoutMs: number;
|
|
34
|
+
cacheKey: string;
|
|
35
|
+
_apiKey: string;
|
|
36
|
+
_host: string;
|
|
37
|
+
_api: "auto" | "documents" | "vectors";
|
|
38
|
+
_vectorField: string;
|
|
39
|
+
_fetch: any;
|
|
40
|
+
_resolving: any;
|
|
41
|
+
_writeLsn: number;
|
|
42
|
+
_dimension: any;
|
|
43
|
+
/**
|
|
44
|
+
* Cache identity for createRagPipeline({ cache }): none unless you set
|
|
45
|
+
* `cacheKey`, since other clients can change the index.
|
|
46
|
+
* @param {'retriever'} role
|
|
47
|
+
* @returns {string|null}
|
|
48
|
+
*/
|
|
49
|
+
getCacheKey(role: "retriever"): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* One REST call; resolves the parsed body and the response headers.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
private _call;
|
|
55
|
+
/**
|
|
56
|
+
* The index's host and kind, from its description (once): a document
|
|
57
|
+
* index's dense_vector field and dimension, or a vector index's.
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
private _resolve;
|
|
61
|
+
/** @private */
|
|
62
|
+
private _describe;
|
|
63
|
+
_indexDimension: any;
|
|
64
|
+
/** A data-plane call; records the log sequence number of writes. @private */
|
|
65
|
+
private _data;
|
|
66
|
+
/** The Documents API path for this namespace. @private */
|
|
67
|
+
private _docs;
|
|
68
|
+
/**
|
|
69
|
+
* A search, repeated until it reflects this retriever's writes (when the
|
|
70
|
+
* index reports log sequence numbers) or `freshnessTimeoutMs` passes.
|
|
71
|
+
* Resolves `[{ id, score, fields }]`.
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
private _search;
|
|
75
|
+
/** Waits until this retriever's writes are indexed (for list and size). @private */
|
|
76
|
+
private _waitForWrites;
|
|
77
|
+
/**
|
|
78
|
+
* Inserts or replaces documents.
|
|
79
|
+
* @param {Array<{ id: string, vector: number[], content?: string, metadata?: Object }>} docs
|
|
80
|
+
* @returns {Promise<void>}
|
|
81
|
+
*/
|
|
82
|
+
store(docs: Array<{
|
|
83
|
+
id: string;
|
|
84
|
+
vector: number[];
|
|
85
|
+
content?: string;
|
|
86
|
+
metadata?: any;
|
|
87
|
+
}>): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* The documents most similar to a query vector.
|
|
90
|
+
* @param {number[]|{ queryVector?: number[], topK?: number, signal?: AbortSignal }} request
|
|
91
|
+
* A vector, or an object with one (required; optional in the type to
|
|
92
|
+
* match the retriever contract)
|
|
93
|
+
* @param {number} [k=10] - Results when `request` is a vector
|
|
94
|
+
* @returns {Promise<Array<{ id: string, score: number, content: string, metadata: Object }>>}
|
|
95
|
+
*/
|
|
96
|
+
retrieve(request: number[] | {
|
|
97
|
+
queryVector?: number[];
|
|
98
|
+
topK?: number;
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
}, k?: number): Promise<Array<{
|
|
101
|
+
id: string;
|
|
102
|
+
score: number;
|
|
103
|
+
content: string;
|
|
104
|
+
metadata: any;
|
|
105
|
+
}>>;
|
|
106
|
+
/** @private */
|
|
107
|
+
private _delete;
|
|
108
|
+
/**
|
|
109
|
+
* Deletes the chunks of one source (`metadata.source`), for re-ingesting.
|
|
110
|
+
* @param {string} source
|
|
111
|
+
*/
|
|
112
|
+
removeBySource(source: string): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Deletes documents by id.
|
|
115
|
+
* @param {string[]} ids
|
|
116
|
+
*/
|
|
117
|
+
delete(ids: string[]): Promise<void>;
|
|
118
|
+
/** Deletes every document this retriever stored in its namespace. */
|
|
119
|
+
clear(): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Every document, without vectors.
|
|
122
|
+
* @param {{ limit?: number }} [options]
|
|
123
|
+
* @returns {Promise<Array<{ id: string, content: string, metadata: Object }>>}
|
|
124
|
+
*/
|
|
125
|
+
list({ limit }?: {
|
|
126
|
+
limit?: number;
|
|
127
|
+
}): Promise<Array<{
|
|
128
|
+
id: string;
|
|
129
|
+
content: string;
|
|
130
|
+
metadata: any;
|
|
131
|
+
}>>;
|
|
132
|
+
/** @returns {Promise<number>} The documents this retriever stored */
|
|
133
|
+
size(): Promise<number>;
|
|
134
|
+
/** Documents API: fetch by filter, page by page. @private */
|
|
135
|
+
private _listDocuments;
|
|
136
|
+
/** Vectors API: list ids, then fetch them. @private */
|
|
137
|
+
private _listVectors;
|
|
138
|
+
}
|
|
139
|
+
/** The record id for a document id: itself when Pinecone accepts it. */
|
|
140
|
+
export function recordId(id: any): string;
|
|
141
|
+
export const API_VERSION: "2026-07";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* adapter.on('token', (t) => console.log('sent', t));
|
|
12
12
|
* await adapter.stream(asyncTokenGenerator, res);
|
|
13
13
|
*/
|
|
14
|
-
export class SSEAdapter extends EventEmitter
|
|
14
|
+
export class SSEAdapter extends EventEmitter {
|
|
15
15
|
/**
|
|
16
16
|
* @param {Object} [options] - Configuration overrides
|
|
17
17
|
* @param {string} [options.eventName='token'] - SSE event name for token frames
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* const handler = router.createHandler(pipeline);
|
|
14
14
|
* app.post('/api/query', handler);
|
|
15
15
|
*/
|
|
16
|
-
export class StreamRouter extends EventEmitter
|
|
16
|
+
export class StreamRouter extends EventEmitter {
|
|
17
17
|
/**
|
|
18
18
|
* @param {Object} [options] - Configuration overrides
|
|
19
19
|
* @param {string} [options.defaultTransport='sse'] - Fallback transport type
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* se.on('done', (stats) => console.log('finished', stats));
|
|
17
17
|
* const all = await se.embedAll(documents);
|
|
18
18
|
*/
|
|
19
|
-
export class StreamingEmbedder extends EventEmitter
|
|
19
|
+
export class StreamingEmbedder extends EventEmitter {
|
|
20
20
|
/**
|
|
21
21
|
* @param {Object} embedder - Embedder instance with `.embed()` or `.embedQuery()`
|
|
22
22
|
* @param {Object} [options] - Override any key from {@link DEFAULT_CONFIG}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* adapter.on('done', () => console.log('stream complete'));
|
|
13
13
|
* await adapter.stream(asyncTokenGenerator, ws);
|
|
14
14
|
*/
|
|
15
|
-
export class WebSocketAdapter extends EventEmitter
|
|
15
|
+
export class WebSocketAdapter extends EventEmitter {
|
|
16
16
|
/**
|
|
17
17
|
* @param {Object} [options] - Configuration overrides
|
|
18
18
|
* @param {string} [options.messageType='token'] - Type field for token messages
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* const result = scaffolder.create('document-qa', '/path/to/my-project');
|
|
10
10
|
* console.log(result.files); // list of created files
|
|
11
11
|
*/
|
|
12
|
-
export class ProjectScaffolder extends EventEmitter
|
|
12
|
+
export class ProjectScaffolder extends EventEmitter {
|
|
13
13
|
/**
|
|
14
14
|
* @param {Object} [options={}] - Scaffolder configuration
|
|
15
15
|
* @param {boolean} [options.installDependencies=false] - Whether to auto-run npm install
|
|
@@ -11,20 +11,22 @@
|
|
|
11
11
|
* import { describe, it } from "vitest"; // or "node:test"
|
|
12
12
|
* runContractTests("llm", () => new MyLLM(), { describe, it });
|
|
13
13
|
*
|
|
14
|
-
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'} type - Plugin type
|
|
14
|
+
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'|'detector'} type - Plugin type
|
|
15
15
|
* @param {() => (object|Promise<object>)} factory - Returns a new, empty plugin for each check
|
|
16
16
|
* @param {object} [options]
|
|
17
17
|
* @param {string} [options.name] - Name of the test group (default: "<type> contract")
|
|
18
18
|
* @param {boolean} [options.registry=false] - Also require the `metadata` pluginRegistry.register() needs
|
|
19
19
|
* @param {(retriever: object, documents: object[]) => (void|Promise<void>)} [options.setup] - Retrievers: loads the test documents (default: `retriever.store(documents)`), for retrievers without store()
|
|
20
|
+
* @param {string} [options.positive] - Detectors: text the detector must flag, instead of the default sample for its kind
|
|
20
21
|
* @param {Function} [options.describe] - Your framework's describe (default: the global one)
|
|
21
22
|
* @param {Function} [options.it] - Your framework's it/test (default: the global it or test)
|
|
22
23
|
* @returns {void}
|
|
23
24
|
*/
|
|
24
|
-
export function runContractTests(type: "loader" | "embedder" | "retriever" | "reranker" | "llm", factory: () => (object | Promise<object>), options?: {
|
|
25
|
+
export function runContractTests(type: "loader" | "embedder" | "retriever" | "reranker" | "llm" | "detector", factory: () => (object | Promise<object>), options?: {
|
|
25
26
|
name?: string;
|
|
26
27
|
registry?: boolean;
|
|
27
28
|
setup?: (retriever: object, documents: object[]) => (void | Promise<void>);
|
|
29
|
+
positive?: string;
|
|
28
30
|
describe?: Function;
|
|
29
31
|
it?: Function;
|
|
30
32
|
}): void;
|
|
@@ -35,16 +37,18 @@ export function runContractTests(type: "loader" | "embedder" | "retriever" | "re
|
|
|
35
37
|
* const report = await checkContract("embedder", () => new MyEmbedder());
|
|
36
38
|
* if (!report.passed) console.log(report.results.filter((r) => !r.passed));
|
|
37
39
|
*
|
|
38
|
-
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'} type - Plugin type
|
|
40
|
+
* @param {'loader'|'embedder'|'retriever'|'reranker'|'llm'|'detector'} type - Plugin type
|
|
39
41
|
* @param {() => (object|Promise<object>)} factory - Returns a new, empty plugin for each check
|
|
40
42
|
* @param {object} [options]
|
|
41
43
|
* @param {boolean} [options.registry=false] - Also require the `metadata` pluginRegistry.register() needs
|
|
42
44
|
* @param {(retriever: object, documents: object[]) => (void|Promise<void>)} [options.setup] - Retrievers: loads the test documents (default: `retriever.store(documents)`), for retrievers without store()
|
|
45
|
+
* @param {string} [options.positive] - Detectors: text the detector must flag, instead of the default sample for its kind
|
|
43
46
|
* @returns {Promise<{ type: string, passed: boolean, results: Array<{ name: string, passed: boolean, skipped: boolean, error?: string }> }>}
|
|
44
47
|
*/
|
|
45
|
-
export function checkContract(type: "loader" | "embedder" | "retriever" | "reranker" | "llm", factory: () => (object | Promise<object>), options?: {
|
|
48
|
+
export function checkContract(type: "loader" | "embedder" | "retriever" | "reranker" | "llm" | "detector", factory: () => (object | Promise<object>), options?: {
|
|
46
49
|
registry?: boolean;
|
|
47
50
|
setup?: (retriever: object, documents: object[]) => (void | Promise<void>);
|
|
51
|
+
positive?: string;
|
|
48
52
|
}): Promise<{
|
|
49
53
|
type: string;
|
|
50
54
|
passed: boolean;
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Load an optional peer dependency. `load` must be a literal
|
|
3
3
|
* `() => require('name')`, so bundlers (esbuild, Wrangler, webpack) can see
|
|
4
4
|
* and include the package; probing with require.resolve() instead fails in
|
|
5
|
-
* bundles even when the package is there.
|
|
5
|
+
* bundles even when the package is there. A bundle of a project without the
|
|
6
|
+
* package fails to build, though, because the require isn't inside a
|
|
7
|
+
* `try`: loaders on the main entry's path use `missingPeer` with the
|
|
8
|
+
* require in their own `try` instead.
|
|
6
9
|
*
|
|
7
10
|
* Only the package itself being absent becomes a `MISSING_DEPENDENCY` error
|
|
8
11
|
* carrying `hint`; any other failure, including a module missing inside the
|
|
@@ -14,3 +17,20 @@
|
|
|
14
17
|
* @returns {any} The module
|
|
15
18
|
*/
|
|
16
19
|
export function loadOptionalPeer(name: string, load: () => any, hint: string): any;
|
|
20
|
+
/**
|
|
21
|
+
* For a loader that requires an optional peer inside its own `try`, which
|
|
22
|
+
* bundlers (esbuild, Wrangler) then include when the package is installed
|
|
23
|
+
* and leave out, without failing the build, when it isn't:
|
|
24
|
+
*
|
|
25
|
+
* try {
|
|
26
|
+
* return require('openai');
|
|
27
|
+
* } catch (error) {
|
|
28
|
+
* throw missingPeer(error, 'openai', hint);
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* @param {Error} error - What require() threw
|
|
32
|
+
* @param {string} name - The package name
|
|
33
|
+
* @param {string} hint - The error message when the package is missing
|
|
34
|
+
* @returns {Error} A `MISSING_DEPENDENCY` error carrying `hint` when the package itself is absent; otherwise `error`
|
|
35
|
+
*/
|
|
36
|
+
export function missingPeer(error: Error, name: string, hint: string): Error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devilsdev/rag-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "createRagPipeline and its building blocks: retrieval, reranking, caching, cost tracking and model routing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rag",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
|
+
"workerd": "./dist/index.cjs",
|
|
29
30
|
"require": "./dist/index.cjs",
|
|
30
31
|
"import": "./dist/index.mjs"
|
|
31
32
|
},
|