nexus-ai-pro 2.3.0 → 2.4.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/API_STABILITY.md +186 -0
- package/CHANGELOG.md +184 -1
- package/README.md +14 -5
- package/SECURITY.md +140 -0
- package/dist/adapter-kit/contracts.d.ts +87 -0
- package/dist/adapter-kit/contracts.js +237 -0
- package/dist/adapter-kit/errors.d.ts +39 -0
- package/dist/adapter-kit/errors.js +52 -0
- package/dist/adapter-kit/index.d.ts +144 -0
- package/dist/adapter-kit/index.js +178 -0
- package/dist/adapter-kit/semver.d.ts +12 -0
- package/dist/adapter-kit/semver.js +55 -0
- package/dist/agent/middleware/pii.js +2 -33
- package/dist/core/secure-stream.js +4 -3
- package/dist/embeddings/adapters.js +2 -1
- package/dist/evals/judge.js +2 -5
- package/dist/evaluate/cache.d.ts +0 -14
- package/dist/evaluate/cache.js +0 -30
- package/dist/evaluate/file-cache.d.ts +15 -0
- package/dist/evaluate/file-cache.js +30 -0
- package/dist/evaluate/index.d.ts +2 -1
- package/dist/evaluate/index.js +2 -1
- package/dist/evaluate/review.js +2 -2
- package/dist/evaluate/run.js +2 -2
- package/dist/evaluate/version.js +3 -3
- package/dist/graph/graph.js +2 -2
- package/dist/graph/node-cache.js +3 -3
- package/dist/hallucination/rag.d.ts +4 -1
- package/dist/hallucination/rag.js +6 -1
- package/dist/images/asset-stores.js +2 -3
- package/dist/images/asset-support.js +2 -2
- package/dist/images/assets.js +1 -2
- package/dist/images/evals.js +4 -4
- package/dist/insights/proposals.js +1 -2
- package/dist/insights/regressions.d.ts +26 -2
- package/dist/insights/regressions.js +129 -3
- package/dist/loaders/git.js +8 -1
- package/dist/loaders/web.js +7 -1
- package/dist/mcp/client.d.ts +14 -0
- package/dist/mcp/client.js +59 -1
- package/dist/mcp/registry.d.ts +6 -0
- package/dist/mcp/registry.js +7 -0
- package/dist/prompts/file.js +28 -11
- package/dist/protocols/a2a.d.ts +235 -0
- package/dist/protocols/a2a.js +386 -0
- package/dist/protocols/acp.d.ts +87 -0
- package/dist/protocols/acp.js +322 -0
- package/dist/protocols/ag-ui.d.ts +120 -0
- package/dist/protocols/ag-ui.js +180 -0
- package/dist/protocols/shared.d.ts +80 -0
- package/dist/protocols/shared.js +49 -0
- package/dist/providers/anthropic.js +1 -0
- package/dist/providers/cohere.js +2 -2
- package/dist/providers/google.js +2 -11
- package/dist/providers/openai.js +1 -0
- package/dist/rag/file-ingestion.js +15 -9
- package/dist/runtime/detect.d.ts +17 -0
- package/dist/runtime/detect.js +16 -0
- package/dist/runtime/index.d.ts +19 -0
- package/dist/runtime/index.js +7 -0
- package/dist/security/injection-detector.d.ts +2 -0
- package/dist/security/injection-detector.js +7 -1
- package/dist/security/input-guard.js +5 -2
- package/dist/security/output-guard.js +8 -4
- package/dist/security/pii-detector.js +22 -6
- package/dist/security/prompt-hardening.js +6 -2
- package/dist/security/semantic-injection-classifier.d.ts +2 -1
- package/dist/security/semantic-injection-classifier.js +31 -35
- package/dist/security/upload-scanner.d.ts +8 -0
- package/dist/security/upload-scanner.js +51 -9
- package/dist/server/deployments.d.ts +63 -1
- package/dist/server/deployments.js +75 -2
- package/dist/server/runs.d.ts +9 -0
- package/dist/server/runs.js +20 -0
- package/dist/server/server.js +5 -0
- package/dist/testing/record.js +2 -2
- package/dist/tracing/stores.js +2 -1
- package/dist/tracing/tracer.js +2 -2
- package/dist/types/config.d.ts +20 -0
- package/dist/types/server.d.ts +6 -0
- package/dist/utils/base64.d.ts +4 -0
- package/dist/utils/base64.js +21 -0
- package/dist/utils/checksums.d.ts +22 -0
- package/dist/utils/checksums.js +39 -0
- package/dist/utils/ids.d.ts +8 -0
- package/dist/utils/ids.js +26 -2
- package/dist/utils/sha256.d.ts +22 -0
- package/dist/utils/sha256.js +120 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist-cjs/adapter-kit/contracts.d.ts +87 -0
- package/dist-cjs/adapter-kit/contracts.js +243 -0
- package/dist-cjs/adapter-kit/errors.d.ts +39 -0
- package/dist-cjs/adapter-kit/errors.js +57 -0
- package/dist-cjs/adapter-kit/index.d.ts +144 -0
- package/dist-cjs/adapter-kit/index.js +194 -0
- package/dist-cjs/adapter-kit/semver.d.ts +12 -0
- package/dist-cjs/adapter-kit/semver.js +59 -0
- package/dist-cjs/agent/middleware/pii.js +4 -35
- package/dist-cjs/core/secure-stream.js +4 -3
- package/dist-cjs/embeddings/adapters.js +2 -1
- package/dist-cjs/evals/judge.js +2 -5
- package/dist-cjs/evaluate/cache.d.ts +0 -14
- package/dist-cjs/evaluate/cache.js +1 -65
- package/dist-cjs/evaluate/file-cache.d.ts +15 -0
- package/dist-cjs/evaluate/file-cache.js +67 -0
- package/dist-cjs/evaluate/index.d.ts +2 -1
- package/dist-cjs/evaluate/index.js +3 -2
- package/dist-cjs/evaluate/review.js +2 -2
- package/dist-cjs/evaluate/run.js +2 -2
- package/dist-cjs/evaluate/version.js +3 -3
- package/dist-cjs/graph/graph.js +2 -2
- package/dist-cjs/graph/node-cache.js +3 -3
- package/dist-cjs/hallucination/rag.d.ts +4 -1
- package/dist-cjs/hallucination/rag.js +6 -1
- package/dist-cjs/images/asset-stores.js +2 -3
- package/dist-cjs/images/asset-support.js +2 -2
- package/dist-cjs/images/assets.js +1 -2
- package/dist-cjs/images/evals.js +4 -4
- package/dist-cjs/insights/proposals.js +1 -2
- package/dist-cjs/insights/regressions.d.ts +26 -2
- package/dist-cjs/insights/regressions.js +129 -3
- package/dist-cjs/loaders/git.js +8 -1
- package/dist-cjs/loaders/web.js +7 -1
- package/dist-cjs/mcp/client.d.ts +14 -0
- package/dist-cjs/mcp/client.js +60 -1
- package/dist-cjs/mcp/registry.d.ts +6 -0
- package/dist-cjs/mcp/registry.js +7 -0
- package/dist-cjs/prompts/file.js +28 -11
- package/dist-cjs/protocols/a2a.d.ts +235 -0
- package/dist-cjs/protocols/a2a.js +393 -0
- package/dist-cjs/protocols/acp.d.ts +87 -0
- package/dist-cjs/protocols/acp.js +326 -0
- package/dist-cjs/protocols/ag-ui.d.ts +120 -0
- package/dist-cjs/protocols/ag-ui.js +186 -0
- package/dist-cjs/protocols/shared.d.ts +80 -0
- package/dist-cjs/protocols/shared.js +59 -0
- package/dist-cjs/providers/anthropic.js +1 -0
- package/dist-cjs/providers/cohere.js +2 -2
- package/dist-cjs/providers/google.js +3 -12
- package/dist-cjs/providers/openai.js +1 -0
- package/dist-cjs/rag/file-ingestion.js +14 -8
- package/dist-cjs/runtime/detect.d.ts +17 -0
- package/dist-cjs/runtime/detect.js +19 -0
- package/dist-cjs/runtime/index.d.ts +19 -0
- package/dist-cjs/runtime/index.js +31 -0
- package/dist-cjs/security/injection-detector.d.ts +2 -0
- package/dist-cjs/security/injection-detector.js +7 -1
- package/dist-cjs/security/input-guard.js +5 -2
- package/dist-cjs/security/output-guard.js +8 -4
- package/dist-cjs/security/pii-detector.js +22 -6
- package/dist-cjs/security/prompt-hardening.js +6 -2
- package/dist-cjs/security/semantic-injection-classifier.d.ts +2 -1
- package/dist-cjs/security/semantic-injection-classifier.js +31 -35
- package/dist-cjs/security/upload-scanner.d.ts +8 -0
- package/dist-cjs/security/upload-scanner.js +53 -9
- package/dist-cjs/server/deployments.d.ts +63 -1
- package/dist-cjs/server/deployments.js +75 -2
- package/dist-cjs/server/runs.d.ts +9 -0
- package/dist-cjs/server/runs.js +20 -0
- package/dist-cjs/server/server.js +5 -0
- package/dist-cjs/testing/record.js +2 -2
- package/dist-cjs/tracing/stores.js +2 -1
- package/dist-cjs/tracing/tracer.js +2 -2
- package/dist-cjs/types/config.d.ts +20 -0
- package/dist-cjs/types/server.d.ts +6 -0
- package/dist-cjs/utils/base64.d.ts +4 -0
- package/dist-cjs/utils/base64.js +25 -0
- package/dist-cjs/utils/checksums.d.ts +22 -0
- package/dist-cjs/utils/checksums.js +46 -0
- package/dist-cjs/utils/ids.d.ts +8 -0
- package/dist-cjs/utils/ids.js +28 -2
- package/dist-cjs/utils/sha256.d.ts +22 -0
- package/dist-cjs/utils/sha256.js +125 -0
- package/dist-cjs/version.d.ts +1 -1
- package/dist-cjs/version.js +1 -1
- package/llms.txt +5 -2
- package/package.json +76 -6
package/dist/types/config.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface OpenAIProviderConfig {
|
|
|
25
25
|
apiKey: string;
|
|
26
26
|
/** API base URL. Point it at an OpenAI-compatible server to use that instead. */
|
|
27
27
|
baseUrl?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Replaces the global `fetch` for every request: a platform's bound fetch on an edge runtime, a
|
|
30
|
+
* proxy, or a stub in tests.
|
|
31
|
+
*/
|
|
32
|
+
fetch?: typeof globalThis.fetch;
|
|
28
33
|
/** OpenAI organization to bill. */
|
|
29
34
|
organization?: string;
|
|
30
35
|
/** Headers added to every request. */
|
|
@@ -59,6 +64,11 @@ export interface AnthropicProviderConfig {
|
|
|
59
64
|
apiKey: string;
|
|
60
65
|
/** API base URL. */
|
|
61
66
|
baseUrl?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Replaces the global `fetch` for every request: a platform's bound fetch on an edge runtime, a
|
|
69
|
+
* proxy, or a stub in tests.
|
|
70
|
+
*/
|
|
71
|
+
fetch?: typeof globalThis.fetch;
|
|
62
72
|
/** Name this provider registers under. */
|
|
63
73
|
providerName?: string;
|
|
64
74
|
/** Model-name prefixes this provider answers for. */
|
|
@@ -75,6 +85,11 @@ export interface GoogleProviderConfig {
|
|
|
75
85
|
apiKey: string;
|
|
76
86
|
/** API base URL. */
|
|
77
87
|
baseUrl?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Replaces the global `fetch` for every request: a platform's bound fetch on an edge runtime, a
|
|
90
|
+
* proxy, or a stub in tests.
|
|
91
|
+
*/
|
|
92
|
+
fetch?: typeof globalThis.fetch;
|
|
78
93
|
}
|
|
79
94
|
/** Configuration for a local Ollama server. */
|
|
80
95
|
export interface OllamaProviderConfig {
|
|
@@ -101,6 +116,11 @@ export interface CohereProviderConfig {
|
|
|
101
116
|
apiKey: string;
|
|
102
117
|
/** API base URL. */
|
|
103
118
|
baseUrl?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Replaces the global `fetch` for every request: a platform's bound fetch on an edge runtime, a
|
|
121
|
+
* proxy, or a stub in tests.
|
|
122
|
+
*/
|
|
123
|
+
fetch?: typeof globalThis.fetch;
|
|
104
124
|
}
|
|
105
125
|
export interface OpenRouterProviderConfig {
|
|
106
126
|
apiKey: string;
|
package/dist/types/server.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* anything that can stream events for an input, which a compiled graph already does.
|
|
8
8
|
*/
|
|
9
9
|
import type { Principal } from './principal.js';
|
|
10
|
+
import type { RunFeedback } from './tracing.js';
|
|
10
11
|
export type { Principal };
|
|
11
12
|
/** Where a run stands, as the server reports it. */
|
|
12
13
|
export type RunStatus = 'queued' | 'running' | 'awaiting_input' | 'succeeded' | 'failed' | 'cancelled' | 'expired';
|
|
@@ -75,6 +76,11 @@ export interface RunRecord {
|
|
|
75
76
|
worker?: string;
|
|
76
77
|
/** Its latest attempt, starting at 1. */
|
|
77
78
|
attempt?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Scores left on the run by people or by online evaluation, through `POST /runs/:runId/feedback`
|
|
81
|
+
* or `Deployments.evaluate()`. A canary guard compares them between revisions as its quality signal.
|
|
82
|
+
*/
|
|
83
|
+
feedback?: RunFeedback[];
|
|
78
84
|
}
|
|
79
85
|
/** Why a run got the revision it did. */
|
|
80
86
|
export type RevisionReason = 'split' | 'thread' | 'requested';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const host = () => globalThis.Buffer;
|
|
2
|
+
export function decodeBase64(data) {
|
|
3
|
+
const buffer = host();
|
|
4
|
+
if (buffer)
|
|
5
|
+
return new Uint8Array(buffer.from(data, 'base64'));
|
|
6
|
+
const binary = atob(data);
|
|
7
|
+
const bytes = new Uint8Array(binary.length);
|
|
8
|
+
for (let index = 0; index < binary.length; index += 1)
|
|
9
|
+
bytes[index] = binary.charCodeAt(index);
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
export function encodeBase64(bytes) {
|
|
13
|
+
const buffer = host();
|
|
14
|
+
if (buffer)
|
|
15
|
+
return buffer.from(bytes).toString('base64');
|
|
16
|
+
let binary = '';
|
|
17
|
+
for (let index = 0; index < bytes.length; index += 0x8000) {
|
|
18
|
+
binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
|
|
19
|
+
}
|
|
20
|
+
return btoa(binary);
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks that tell a real identifier from a number that only looks like one. Every detector of card
|
|
3
|
+
* numbers and account numbers uses them, so an order id or a millisecond timestamp is never masked as
|
|
4
|
+
* a card.
|
|
5
|
+
*/
|
|
6
|
+
/** Whether a card number passes the Luhn check, with 13 to 19 digits; spaces and dashes are ignored. */
|
|
7
|
+
export declare function luhn(value: string): boolean;
|
|
8
|
+
/** Whether an IBAN passes its mod-97 check, with 15 to 34 characters; spaces are ignored. */
|
|
9
|
+
export declare function ibanChecksum(value: string): boolean;
|
|
10
|
+
/** Whether a phone-like match has as many digits as a phone number can: 10 to 15. */
|
|
11
|
+
export declare function phoneDigits(value: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a match reads as a phone number: 10 to 15 digits, written with a leading `+` or with
|
|
14
|
+
* separators. A bare run of digits is an id or a timestamp far more often than a phone number.
|
|
15
|
+
*/
|
|
16
|
+
export declare function phoneNumber(value: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Text as a detector should read it: Unicode compatibility forms folded (full-width letters become
|
|
19
|
+
* ASCII), and the invisible characters an attacker uses to split a phrase removed, so
|
|
20
|
+
* `ignore` and `ignore` read as `ignore`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeForDetection(text: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function luhn(value) {
|
|
2
|
+
const digits = value.replace(/[\s-]/g, '');
|
|
3
|
+
if (!/^\d{13,19}$/.test(digits))
|
|
4
|
+
return false;
|
|
5
|
+
let sum = 0;
|
|
6
|
+
for (let index = 0; index < digits.length; index += 1) {
|
|
7
|
+
let digit = Number(digits[digits.length - 1 - index]);
|
|
8
|
+
if (index % 2 === 1) {
|
|
9
|
+
digit *= 2;
|
|
10
|
+
if (digit > 9)
|
|
11
|
+
digit -= 9;
|
|
12
|
+
}
|
|
13
|
+
sum += digit;
|
|
14
|
+
}
|
|
15
|
+
return sum % 10 === 0;
|
|
16
|
+
}
|
|
17
|
+
export function ibanChecksum(value) {
|
|
18
|
+
const iban = value.replace(/ /g, '').toUpperCase();
|
|
19
|
+
if (!/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(iban))
|
|
20
|
+
return false;
|
|
21
|
+
const rearranged = `${iban.slice(4)}${iban.slice(0, 4)}`;
|
|
22
|
+
let remainder = 0;
|
|
23
|
+
for (const char of rearranged) {
|
|
24
|
+
const code = /\d/.test(char) ? char : String(char.charCodeAt(0) - 55);
|
|
25
|
+
for (const digit of code)
|
|
26
|
+
remainder = (remainder * 10 + Number(digit)) % 97;
|
|
27
|
+
}
|
|
28
|
+
return remainder === 1;
|
|
29
|
+
}
|
|
30
|
+
export function phoneDigits(value) {
|
|
31
|
+
const digits = value.replace(/\D/g, '').length;
|
|
32
|
+
return digits >= 10 && digits <= 15;
|
|
33
|
+
}
|
|
34
|
+
export function phoneNumber(value) {
|
|
35
|
+
return phoneDigits(value) && (/^\s*\+/.test(value) || /\d[\s.()-]+\d/.test(value));
|
|
36
|
+
}
|
|
37
|
+
export function normalizeForDetection(text) {
|
|
38
|
+
return text.normalize('NFKC').replace(/[---]/g, '');
|
|
39
|
+
}
|
package/dist/utils/ids.d.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ids and text measures from Web Crypto and plain JavaScript, so the modules that use them run on
|
|
3
|
+
* every runtime: Node.js, Deno, Bun, edge runtimes, and browsers.
|
|
4
|
+
*/
|
|
5
|
+
/** Random bytes as lowercase hex, two characters per byte. */
|
|
6
|
+
export declare function randomHex(bytes: number): string;
|
|
1
7
|
export declare function generateRequestId(): string;
|
|
8
|
+
/** The bytes UTF-8 takes for a string, as `Buffer.byteLength()` counts them, without encoding it. */
|
|
9
|
+
export declare function utf8Length(text: string): number;
|
package/dist/utils/ids.js
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
export function randomHex(bytes) {
|
|
2
|
+
const values = globalThis.crypto.getRandomValues(new Uint8Array(bytes));
|
|
3
|
+
let hex = '';
|
|
4
|
+
for (const value of values)
|
|
5
|
+
hex += HEX[value];
|
|
6
|
+
return hex;
|
|
7
|
+
}
|
|
2
8
|
export function generateRequestId() {
|
|
3
|
-
return `req_${
|
|
9
|
+
return `req_${randomHex(12)}`;
|
|
10
|
+
}
|
|
11
|
+
export function utf8Length(text) {
|
|
12
|
+
let length = 0;
|
|
13
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
14
|
+
const code = text.charCodeAt(index);
|
|
15
|
+
if (code < 0x80)
|
|
16
|
+
length += 1;
|
|
17
|
+
else if (code < 0x800)
|
|
18
|
+
length += 2;
|
|
19
|
+
else if (code >= 0xd800 && code <= 0xdbff && (text.charCodeAt(index + 1) & 0xfc00) === 0xdc00) {
|
|
20
|
+
length += 4;
|
|
21
|
+
index += 1;
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
length += 3;
|
|
25
|
+
}
|
|
26
|
+
return length;
|
|
4
27
|
}
|
|
28
|
+
const HEX = Array.from({ length: 256 }, (_, value) => value.toString(16).padStart(2, '0'));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 that can be fed in pieces, as `createHash('sha256')` is, with the same digest. Strings are
|
|
3
|
+
* hashed as UTF-8. Synchronous, unlike Web Crypto's `digest()`, so a cache key can be computed where
|
|
4
|
+
* it is needed.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Sha256 {
|
|
7
|
+
private readonly state;
|
|
8
|
+
private readonly block;
|
|
9
|
+
private readonly words;
|
|
10
|
+
private filled;
|
|
11
|
+
private total;
|
|
12
|
+
/** Adds data: a string, as UTF-8, or bytes. */
|
|
13
|
+
update(data: string | Uint8Array): this;
|
|
14
|
+
/** The digest as lowercase hex. The hash takes no more data afterwards. */
|
|
15
|
+
digest(): string;
|
|
16
|
+
private compress;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The SHA-256 digest of a string, as UTF-8, or of bytes, as lowercase hex. Native where the runtime
|
|
20
|
+
* has it, which is ten times faster on large inputs, and the same digest everywhere else.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sha256Hex(data: string | Uint8Array): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const K = new Uint32Array([
|
|
2
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
|
|
3
|
+
0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
4
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8,
|
|
5
|
+
0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
6
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
|
|
7
|
+
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
8
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7,
|
|
9
|
+
0xc67178f2,
|
|
10
|
+
]);
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
export class Sha256 {
|
|
13
|
+
state = new Uint32Array([
|
|
14
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
15
|
+
]);
|
|
16
|
+
block = new Uint8Array(64);
|
|
17
|
+
words = new Uint32Array(64);
|
|
18
|
+
filled = 0;
|
|
19
|
+
total = 0;
|
|
20
|
+
update(data) {
|
|
21
|
+
const bytes = typeof data === 'string' ? encoder.encode(data) : data;
|
|
22
|
+
this.total += bytes.length;
|
|
23
|
+
let offset = 0;
|
|
24
|
+
if (this.filled > 0) {
|
|
25
|
+
const take = Math.min(64 - this.filled, bytes.length);
|
|
26
|
+
this.block.set(bytes.subarray(0, take), this.filled);
|
|
27
|
+
this.filled += take;
|
|
28
|
+
offset = take;
|
|
29
|
+
if (this.filled < 64)
|
|
30
|
+
return this;
|
|
31
|
+
this.compress(this.block, 0);
|
|
32
|
+
this.filled = 0;
|
|
33
|
+
}
|
|
34
|
+
for (; offset + 64 <= bytes.length; offset += 64)
|
|
35
|
+
this.compress(bytes, offset);
|
|
36
|
+
if (offset < bytes.length) {
|
|
37
|
+
this.block.set(bytes.subarray(offset), 0);
|
|
38
|
+
this.filled = bytes.length - offset;
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
digest() {
|
|
43
|
+
const bits = this.total * 8;
|
|
44
|
+
const padding = new Uint8Array(this.filled < 56 ? 64 - this.filled : 128 - this.filled);
|
|
45
|
+
padding[0] = 0x80;
|
|
46
|
+
const view = new DataView(padding.buffer);
|
|
47
|
+
view.setUint32(padding.length - 8, Math.floor(bits / 0x100000000));
|
|
48
|
+
view.setUint32(padding.length - 4, bits >>> 0);
|
|
49
|
+
const total = this.total;
|
|
50
|
+
this.update(padding);
|
|
51
|
+
this.total = total;
|
|
52
|
+
let hex = '';
|
|
53
|
+
for (const word of this.state)
|
|
54
|
+
hex += word.toString(16).padStart(8, '0');
|
|
55
|
+
return hex;
|
|
56
|
+
}
|
|
57
|
+
compress(bytes, offset) {
|
|
58
|
+
const w = this.words;
|
|
59
|
+
for (let index = 0; index < 16; index += 1) {
|
|
60
|
+
const at = offset + index * 4;
|
|
61
|
+
w[index] =
|
|
62
|
+
(bytes[at] << 24) |
|
|
63
|
+
(bytes[at + 1] << 16) |
|
|
64
|
+
(bytes[at + 2] << 8) |
|
|
65
|
+
bytes[at + 3];
|
|
66
|
+
}
|
|
67
|
+
for (let index = 16; index < 64; index += 1) {
|
|
68
|
+
const a = w[index - 15];
|
|
69
|
+
const b = w[index - 2];
|
|
70
|
+
const s0 = ((a >>> 7) | (a << 25)) ^ ((a >>> 18) | (a << 14)) ^ (a >>> 3);
|
|
71
|
+
const s1 = ((b >>> 17) | (b << 15)) ^ ((b >>> 19) | (b << 13)) ^ (b >>> 10);
|
|
72
|
+
w[index] = (w[index - 16] + s0 + w[index - 7] + s1) | 0;
|
|
73
|
+
}
|
|
74
|
+
const h = this.state;
|
|
75
|
+
let a = h[0];
|
|
76
|
+
let b = h[1];
|
|
77
|
+
let c = h[2];
|
|
78
|
+
let d = h[3];
|
|
79
|
+
let e = h[4];
|
|
80
|
+
let f = h[5];
|
|
81
|
+
let g = h[6];
|
|
82
|
+
let k = h[7];
|
|
83
|
+
for (let index = 0; index < 64; index += 1) {
|
|
84
|
+
const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
85
|
+
const choose = (e & f) ^ (~e & g);
|
|
86
|
+
const t1 = (k + s1 + choose + K[index] + w[index]) | 0;
|
|
87
|
+
const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
88
|
+
const majority = (a & b) ^ (a & c) ^ (b & c);
|
|
89
|
+
const t2 = (s0 + majority) | 0;
|
|
90
|
+
k = g;
|
|
91
|
+
g = f;
|
|
92
|
+
f = e;
|
|
93
|
+
e = (d + t1) | 0;
|
|
94
|
+
d = c;
|
|
95
|
+
c = b;
|
|
96
|
+
b = a;
|
|
97
|
+
a = (t1 + t2) | 0;
|
|
98
|
+
}
|
|
99
|
+
h[0] = h[0] + a;
|
|
100
|
+
h[1] = h[1] + b;
|
|
101
|
+
h[2] = h[2] + c;
|
|
102
|
+
h[3] = h[3] + d;
|
|
103
|
+
h[4] = h[4] + e;
|
|
104
|
+
h[5] = h[5] + f;
|
|
105
|
+
h[6] = h[6] + g;
|
|
106
|
+
h[7] = h[7] + k;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const nativeHash = (() => {
|
|
110
|
+
try {
|
|
111
|
+
const host = globalThis.process;
|
|
112
|
+
return host?.getBuiltinModule?.('crypto')?.createHash;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
export function sha256Hex(data) {
|
|
119
|
+
return nativeHash ? nativeHash('sha256').update(data).digest('hex') : new Sha256().update(data).digest();
|
|
120
|
+
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const NEXUS_VERSION = '2.
|
|
1
|
+
export const NEXUS_VERSION = '2.4.0';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract suites the adapter kit ships: what every vector store, retriever, and long-term store
|
|
3
|
+
* must do, as checks that need no test framework. Each check is named for the behavior it proves,
|
|
4
|
+
* and a capability the adapter does not declare is reported as skipped, never as a failure.
|
|
5
|
+
*/
|
|
6
|
+
import type { RagChunk } from '../hallucination/rag.js';
|
|
7
|
+
import type { EmbeddingProvider, VectorStore } from '../hallucination/retrieval.js';
|
|
8
|
+
import type { Retriever } from '../rag/retrievers.js';
|
|
9
|
+
import type { Store } from '../types/store.js';
|
|
10
|
+
/** One check of a contract suite. */
|
|
11
|
+
export interface AdapterCheck {
|
|
12
|
+
/** What was checked, as a sentence. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** Whether it held. */
|
|
15
|
+
ok: boolean;
|
|
16
|
+
/** Why it did not hold, or why it was skipped. */
|
|
17
|
+
detail?: string;
|
|
18
|
+
/** True when the adapter does not declare the capability the check needs. */
|
|
19
|
+
skipped?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** The passages every retrieval contract runs on, and that benchmarks reuse. */
|
|
22
|
+
export declare const ADAPTER_FIXTURE_PASSAGES: readonly RagChunk[];
|
|
23
|
+
/** What a vector store declares it supports, for its contract. */
|
|
24
|
+
export interface VectorStoreCapabilities {
|
|
25
|
+
/** `searchVector()` with a vector computed elsewhere. Defaults to true. */
|
|
26
|
+
searchVector?: boolean;
|
|
27
|
+
/** `minScore` drops weak matches. Defaults to true. */
|
|
28
|
+
minScore?: boolean;
|
|
29
|
+
/** Metadata filters: `exact` matches values, `typed` also tells `3` from `'3'`, `none` has no filters. Defaults to `exact`. */
|
|
30
|
+
filters?: 'none' | 'exact' | 'typed';
|
|
31
|
+
}
|
|
32
|
+
/** Options for `runVectorStoreContract()`. */
|
|
33
|
+
export interface VectorStoreContractOptions {
|
|
34
|
+
/** The embedding function the store was given, to compute a query vector for `searchVector()`. */
|
|
35
|
+
embed: EmbeddingProvider;
|
|
36
|
+
/** What the store supports. */
|
|
37
|
+
capabilities?: VectorStoreCapabilities;
|
|
38
|
+
/** Waits for writes to become searchable, for a store whose index is eventually consistent. */
|
|
39
|
+
settle?: () => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The `VectorStore` contract: ranking, `topK`, sources and metadata round-tripped, filters,
|
|
43
|
+
* `minScore`, vector search, replacement by id, deletes, and empty writes. The store should be empty
|
|
44
|
+
* when it starts.
|
|
45
|
+
*/
|
|
46
|
+
export declare function runVectorStoreContract(store: VectorStore, options: VectorStoreContractOptions): Promise<AdapterCheck[]>;
|
|
47
|
+
/** What a retriever declares it supports, for its contract. */
|
|
48
|
+
export interface RetrieverCapabilities {
|
|
49
|
+
/** It holds its own passages, with `add()` and `delete()`: a `SparseRetriever`. Defaults to whether it has them. */
|
|
50
|
+
writes?: boolean;
|
|
51
|
+
/** Metadata filters. Defaults to true. */
|
|
52
|
+
filters?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Options for `runRetrieverContract()`. */
|
|
55
|
+
export interface RetrieverContractOptions {
|
|
56
|
+
/** What the retriever supports. */
|
|
57
|
+
capabilities?: RetrieverCapabilities;
|
|
58
|
+
/**
|
|
59
|
+
* Loads the fixture passages, for a retriever that does not hold its own: into the vector store
|
|
60
|
+
* behind it, say. A retriever with `add()` is loaded through that.
|
|
61
|
+
*/
|
|
62
|
+
load?: (passages: RagChunk[]) => Promise<void>;
|
|
63
|
+
/** Waits for writes to become searchable. */
|
|
64
|
+
settle?: () => Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The `Retriever` contract, and the `SparseRetriever` contract when the retriever takes writes:
|
|
68
|
+
* an exact term found, ranking, `topK`, filters, replacement, deletes, and an empty query.
|
|
69
|
+
*/
|
|
70
|
+
export declare function runRetrieverContract(retriever: Retriever, options?: RetrieverContractOptions): Promise<AdapterCheck[]>;
|
|
71
|
+
/** What a long-term store declares it supports, for its contract. */
|
|
72
|
+
export interface StoreCapabilities {
|
|
73
|
+
/** `search()` lists a namespace prefix, newest first. Defaults to true. */
|
|
74
|
+
search?: boolean;
|
|
75
|
+
/** `search()` filters on value fields. Defaults to true. */
|
|
76
|
+
filters?: boolean;
|
|
77
|
+
/** `listNamespaces()`. Defaults to true. */
|
|
78
|
+
namespaces?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The long-term `Store` contract: values round-trip, a replaced item keeps its creation time, a
|
|
82
|
+
* missing key reads as nothing, deletes, prefix search with filters and paging, and namespace
|
|
83
|
+
* listing. The store should be empty when it starts.
|
|
84
|
+
*/
|
|
85
|
+
export declare function runStoreContract(store: Store, options?: {
|
|
86
|
+
capabilities?: StoreCapabilities;
|
|
87
|
+
}): Promise<AdapterCheck[]>;
|