nexus-ai-pro 2.2.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.
Files changed (298) hide show
  1. package/API_STABILITY.md +225 -0
  2. package/CHANGELOG.md +325 -1
  3. package/README.md +20 -6
  4. package/SECURITY.md +140 -0
  5. package/dist/adapter-kit/contracts.d.ts +87 -0
  6. package/dist/adapter-kit/contracts.js +237 -0
  7. package/dist/adapter-kit/errors.d.ts +39 -0
  8. package/dist/adapter-kit/errors.js +52 -0
  9. package/dist/adapter-kit/index.d.ts +144 -0
  10. package/dist/adapter-kit/index.js +178 -0
  11. package/dist/adapter-kit/semver.d.ts +12 -0
  12. package/dist/adapter-kit/semver.js +55 -0
  13. package/dist/agent/capabilities.d.ts +39 -0
  14. package/dist/agent/capabilities.js +36 -0
  15. package/dist/agent/create-agent.d.ts +61 -11
  16. package/dist/agent/create-agent.js +136 -22
  17. package/dist/agent/index.d.ts +3 -2
  18. package/dist/agent/index.js +1 -1
  19. package/dist/agent/middleware/approval.d.ts +26 -0
  20. package/dist/agent/middleware/approval.js +23 -0
  21. package/dist/agent/{middleware.d.ts → middleware/basic.d.ts} +5 -4
  22. package/dist/agent/{middleware.js → middleware/basic.js} +3 -5
  23. package/dist/agent/middleware/context-editor.d.ts +52 -0
  24. package/dist/agent/middleware/context-editor.js +66 -0
  25. package/dist/agent/middleware/filesystem.d.ts +44 -0
  26. package/dist/agent/middleware/filesystem.js +83 -0
  27. package/dist/agent/middleware/index.d.ts +19 -0
  28. package/dist/agent/middleware/index.js +9 -0
  29. package/dist/agent/middleware/limits.d.ts +42 -0
  30. package/dist/agent/middleware/limits.js +52 -0
  31. package/dist/agent/middleware/models.d.ts +48 -0
  32. package/dist/agent/middleware/models.js +44 -0
  33. package/dist/agent/middleware/pii.d.ts +67 -0
  34. package/dist/agent/middleware/pii.js +142 -0
  35. package/dist/agent/middleware/retry.d.ts +66 -0
  36. package/dist/agent/middleware/retry.js +59 -0
  37. package/dist/agent/middleware/shared.d.ts +41 -0
  38. package/dist/agent/middleware/shared.js +73 -0
  39. package/dist/agent/middleware/tool-selector.d.ts +64 -0
  40. package/dist/agent/middleware/tool-selector.js +106 -0
  41. package/dist/agent/permissions.d.ts +113 -0
  42. package/dist/agent/permissions.js +180 -0
  43. package/dist/agent/sandbox.d.ts +151 -0
  44. package/dist/agent/sandbox.js +257 -0
  45. package/dist/agent/tool.d.ts +8 -3
  46. package/dist/agent/tool.js +14 -3
  47. package/dist/core/secure-stream.js +4 -3
  48. package/dist/deep-agent/index.d.ts +109 -0
  49. package/dist/deep-agent/index.js +216 -0
  50. package/dist/embeddings/adapters.js +2 -1
  51. package/dist/evals/judge.js +2 -5
  52. package/dist/evaluate/cache.d.ts +0 -14
  53. package/dist/evaluate/cache.js +0 -30
  54. package/dist/evaluate/file-cache.d.ts +15 -0
  55. package/dist/evaluate/file-cache.js +30 -0
  56. package/dist/evaluate/index.d.ts +2 -1
  57. package/dist/evaluate/index.js +2 -1
  58. package/dist/evaluate/review.js +2 -2
  59. package/dist/evaluate/run.js +2 -2
  60. package/dist/evaluate/version.js +3 -3
  61. package/dist/graph/functional.d.ts +9 -0
  62. package/dist/graph/functional.js +20 -3
  63. package/dist/graph/graph.js +27 -6
  64. package/dist/graph/lint.d.ts +4 -1
  65. package/dist/graph/lint.js +35 -0
  66. package/dist/graph/node-cache.js +3 -3
  67. package/dist/hallucination/rag.d.ts +4 -1
  68. package/dist/hallucination/rag.js +6 -1
  69. package/dist/images/asset-stores.js +2 -3
  70. package/dist/images/asset-support.js +2 -2
  71. package/dist/images/assets.js +1 -2
  72. package/dist/images/evals.js +4 -4
  73. package/dist/insights/proposals.js +1 -2
  74. package/dist/insights/regressions.d.ts +26 -2
  75. package/dist/insights/regressions.js +129 -3
  76. package/dist/loaders/git.js +8 -1
  77. package/dist/loaders/web.js +7 -1
  78. package/dist/mcp/client.d.ts +14 -0
  79. package/dist/mcp/client.js +59 -1
  80. package/dist/mcp/registry.d.ts +6 -0
  81. package/dist/mcp/registry.js +7 -0
  82. package/dist/postgres/fulltext.d.ts +67 -0
  83. package/dist/postgres/fulltext.js +91 -0
  84. package/dist/prompts/file.js +28 -11
  85. package/dist/protocols/a2a.d.ts +235 -0
  86. package/dist/protocols/a2a.js +386 -0
  87. package/dist/protocols/acp.d.ts +87 -0
  88. package/dist/protocols/acp.js +322 -0
  89. package/dist/protocols/ag-ui.d.ts +120 -0
  90. package/dist/protocols/ag-ui.js +180 -0
  91. package/dist/protocols/shared.d.ts +80 -0
  92. package/dist/protocols/shared.js +49 -0
  93. package/dist/providers/anthropic.js +1 -0
  94. package/dist/providers/cohere.js +2 -2
  95. package/dist/providers/google.js +2 -11
  96. package/dist/providers/openai.js +1 -0
  97. package/dist/rag/elasticsearch.d.ts +71 -0
  98. package/dist/rag/elasticsearch.js +130 -0
  99. package/dist/rag/file-ingestion.js +15 -9
  100. package/dist/rag/pipeline.d.ts +140 -0
  101. package/dist/rag/pipeline.js +187 -0
  102. package/dist/rag/rerankers.d.ts +92 -0
  103. package/dist/rag/rerankers.js +97 -0
  104. package/dist/rag/retrievers.d.ts +12 -1
  105. package/dist/runtime/detect.d.ts +17 -0
  106. package/dist/runtime/detect.js +16 -0
  107. package/dist/runtime/index.d.ts +19 -0
  108. package/dist/runtime/index.js +7 -0
  109. package/dist/security/injection-detector.d.ts +2 -0
  110. package/dist/security/injection-detector.js +7 -1
  111. package/dist/security/input-guard.js +5 -2
  112. package/dist/security/output-guard.js +8 -4
  113. package/dist/security/pii-detector.js +22 -6
  114. package/dist/security/prompt-hardening.js +6 -2
  115. package/dist/security/semantic-injection-classifier.d.ts +2 -1
  116. package/dist/security/semantic-injection-classifier.js +31 -35
  117. package/dist/security/upload-scanner.d.ts +8 -0
  118. package/dist/security/upload-scanner.js +51 -9
  119. package/dist/server/assistant.d.ts +5 -1
  120. package/dist/server/assistant.js +4 -2
  121. package/dist/server/auth.d.ts +250 -0
  122. package/dist/server/auth.js +392 -0
  123. package/dist/server/deployments.d.ts +63 -1
  124. package/dist/server/deployments.js +75 -2
  125. package/dist/server/runs.d.ts +9 -0
  126. package/dist/server/runs.js +20 -0
  127. package/dist/server/server.js +5 -0
  128. package/dist/store/memory.d.ts +10 -0
  129. package/dist/store/memory.js +10 -0
  130. package/dist/testing/record.js +2 -2
  131. package/dist/tracing/stores.js +2 -1
  132. package/dist/tracing/tracer.js +2 -2
  133. package/dist/types/config.d.ts +20 -0
  134. package/dist/types/graph.d.ts +38 -0
  135. package/dist/types/messages.d.ts +36 -2
  136. package/dist/types/principal.d.ts +21 -0
  137. package/dist/types/principal.js +1 -0
  138. package/dist/types/server.d.ts +8 -9
  139. package/dist/utils/base64.d.ts +4 -0
  140. package/dist/utils/base64.js +21 -0
  141. package/dist/utils/checksums.d.ts +22 -0
  142. package/dist/utils/checksums.js +39 -0
  143. package/dist/utils/ids.d.ts +8 -0
  144. package/dist/utils/ids.js +26 -2
  145. package/dist/utils/sha256.d.ts +22 -0
  146. package/dist/utils/sha256.js +120 -0
  147. package/dist/utils/tenant.d.ts +11 -0
  148. package/dist/utils/tenant.js +14 -0
  149. package/dist/version.d.ts +1 -1
  150. package/dist/version.js +1 -1
  151. package/dist-cjs/adapter-kit/contracts.d.ts +87 -0
  152. package/dist-cjs/adapter-kit/contracts.js +243 -0
  153. package/dist-cjs/adapter-kit/errors.d.ts +39 -0
  154. package/dist-cjs/adapter-kit/errors.js +57 -0
  155. package/dist-cjs/adapter-kit/index.d.ts +144 -0
  156. package/dist-cjs/adapter-kit/index.js +194 -0
  157. package/dist-cjs/adapter-kit/semver.d.ts +12 -0
  158. package/dist-cjs/adapter-kit/semver.js +59 -0
  159. package/dist-cjs/agent/capabilities.d.ts +39 -0
  160. package/dist-cjs/agent/capabilities.js +41 -0
  161. package/dist-cjs/agent/create-agent.d.ts +61 -11
  162. package/dist-cjs/agent/create-agent.js +136 -22
  163. package/dist-cjs/agent/index.d.ts +3 -2
  164. package/dist-cjs/agent/index.js +4 -4
  165. package/dist-cjs/agent/middleware/approval.d.ts +26 -0
  166. package/dist-cjs/agent/middleware/approval.js +26 -0
  167. package/dist-cjs/agent/{middleware.d.ts → middleware/basic.d.ts} +5 -4
  168. package/dist-cjs/agent/{middleware.js → middleware/basic.js} +3 -5
  169. package/dist-cjs/agent/middleware/context-editor.d.ts +52 -0
  170. package/dist-cjs/agent/middleware/context-editor.js +70 -0
  171. package/dist-cjs/agent/middleware/filesystem.d.ts +44 -0
  172. package/dist-cjs/agent/middleware/filesystem.js +86 -0
  173. package/dist-cjs/agent/middleware/index.d.ts +19 -0
  174. package/dist-cjs/agent/middleware/index.js +28 -0
  175. package/dist-cjs/agent/middleware/limits.d.ts +42 -0
  176. package/dist-cjs/agent/middleware/limits.js +57 -0
  177. package/dist-cjs/agent/middleware/models.d.ts +48 -0
  178. package/dist-cjs/agent/middleware/models.js +48 -0
  179. package/dist-cjs/agent/middleware/pii.d.ts +67 -0
  180. package/dist-cjs/agent/middleware/pii.js +147 -0
  181. package/dist-cjs/agent/middleware/retry.d.ts +66 -0
  182. package/dist-cjs/agent/middleware/retry.js +63 -0
  183. package/dist-cjs/agent/middleware/shared.d.ts +41 -0
  184. package/dist-cjs/agent/middleware/shared.js +83 -0
  185. package/dist-cjs/agent/middleware/tool-selector.d.ts +64 -0
  186. package/dist-cjs/agent/middleware/tool-selector.js +109 -0
  187. package/dist-cjs/agent/permissions.d.ts +113 -0
  188. package/dist-cjs/agent/permissions.js +189 -0
  189. package/dist-cjs/agent/sandbox.d.ts +151 -0
  190. package/dist-cjs/agent/sandbox.js +297 -0
  191. package/dist-cjs/agent/tool.d.ts +8 -3
  192. package/dist-cjs/agent/tool.js +14 -3
  193. package/dist-cjs/core/secure-stream.js +4 -3
  194. package/dist-cjs/deep-agent/index.d.ts +109 -0
  195. package/dist-cjs/deep-agent/index.js +219 -0
  196. package/dist-cjs/embeddings/adapters.js +2 -1
  197. package/dist-cjs/evals/judge.js +2 -5
  198. package/dist-cjs/evaluate/cache.d.ts +0 -14
  199. package/dist-cjs/evaluate/cache.js +1 -65
  200. package/dist-cjs/evaluate/file-cache.d.ts +15 -0
  201. package/dist-cjs/evaluate/file-cache.js +67 -0
  202. package/dist-cjs/evaluate/index.d.ts +2 -1
  203. package/dist-cjs/evaluate/index.js +3 -2
  204. package/dist-cjs/evaluate/review.js +2 -2
  205. package/dist-cjs/evaluate/run.js +2 -2
  206. package/dist-cjs/evaluate/version.js +3 -3
  207. package/dist-cjs/graph/functional.d.ts +9 -0
  208. package/dist-cjs/graph/functional.js +20 -3
  209. package/dist-cjs/graph/graph.js +27 -6
  210. package/dist-cjs/graph/lint.d.ts +4 -1
  211. package/dist-cjs/graph/lint.js +35 -0
  212. package/dist-cjs/graph/node-cache.js +3 -3
  213. package/dist-cjs/hallucination/rag.d.ts +4 -1
  214. package/dist-cjs/hallucination/rag.js +6 -1
  215. package/dist-cjs/images/asset-stores.js +2 -3
  216. package/dist-cjs/images/asset-support.js +2 -2
  217. package/dist-cjs/images/assets.js +1 -2
  218. package/dist-cjs/images/evals.js +4 -4
  219. package/dist-cjs/insights/proposals.js +1 -2
  220. package/dist-cjs/insights/regressions.d.ts +26 -2
  221. package/dist-cjs/insights/regressions.js +129 -3
  222. package/dist-cjs/loaders/git.js +8 -1
  223. package/dist-cjs/loaders/web.js +7 -1
  224. package/dist-cjs/mcp/client.d.ts +14 -0
  225. package/dist-cjs/mcp/client.js +60 -1
  226. package/dist-cjs/mcp/registry.d.ts +6 -0
  227. package/dist-cjs/mcp/registry.js +7 -0
  228. package/dist-cjs/postgres/fulltext.d.ts +67 -0
  229. package/dist-cjs/postgres/fulltext.js +129 -0
  230. package/dist-cjs/prompts/file.js +28 -11
  231. package/dist-cjs/protocols/a2a.d.ts +235 -0
  232. package/dist-cjs/protocols/a2a.js +393 -0
  233. package/dist-cjs/protocols/acp.d.ts +87 -0
  234. package/dist-cjs/protocols/acp.js +326 -0
  235. package/dist-cjs/protocols/ag-ui.d.ts +120 -0
  236. package/dist-cjs/protocols/ag-ui.js +186 -0
  237. package/dist-cjs/protocols/shared.d.ts +80 -0
  238. package/dist-cjs/protocols/shared.js +59 -0
  239. package/dist-cjs/providers/anthropic.js +1 -0
  240. package/dist-cjs/providers/cohere.js +2 -2
  241. package/dist-cjs/providers/google.js +3 -12
  242. package/dist-cjs/providers/openai.js +1 -0
  243. package/dist-cjs/rag/elasticsearch.d.ts +71 -0
  244. package/dist-cjs/rag/elasticsearch.js +135 -0
  245. package/dist-cjs/rag/file-ingestion.js +14 -8
  246. package/dist-cjs/rag/pipeline.d.ts +140 -0
  247. package/dist-cjs/rag/pipeline.js +191 -0
  248. package/dist-cjs/rag/rerankers.d.ts +92 -0
  249. package/dist-cjs/rag/rerankers.js +107 -0
  250. package/dist-cjs/rag/retrievers.d.ts +12 -1
  251. package/dist-cjs/runtime/detect.d.ts +17 -0
  252. package/dist-cjs/runtime/detect.js +19 -0
  253. package/dist-cjs/runtime/index.d.ts +19 -0
  254. package/dist-cjs/runtime/index.js +31 -0
  255. package/dist-cjs/security/injection-detector.d.ts +2 -0
  256. package/dist-cjs/security/injection-detector.js +7 -1
  257. package/dist-cjs/security/input-guard.js +5 -2
  258. package/dist-cjs/security/output-guard.js +8 -4
  259. package/dist-cjs/security/pii-detector.js +22 -6
  260. package/dist-cjs/security/prompt-hardening.js +6 -2
  261. package/dist-cjs/security/semantic-injection-classifier.d.ts +2 -1
  262. package/dist-cjs/security/semantic-injection-classifier.js +31 -35
  263. package/dist-cjs/security/upload-scanner.d.ts +8 -0
  264. package/dist-cjs/security/upload-scanner.js +53 -9
  265. package/dist-cjs/server/assistant.d.ts +5 -1
  266. package/dist-cjs/server/assistant.js +4 -2
  267. package/dist-cjs/server/auth.d.ts +250 -0
  268. package/dist-cjs/server/auth.js +402 -0
  269. package/dist-cjs/server/deployments.d.ts +63 -1
  270. package/dist-cjs/server/deployments.js +75 -2
  271. package/dist-cjs/server/runs.d.ts +9 -0
  272. package/dist-cjs/server/runs.js +20 -0
  273. package/dist-cjs/server/server.js +5 -0
  274. package/dist-cjs/store/memory.d.ts +10 -0
  275. package/dist-cjs/store/memory.js +10 -0
  276. package/dist-cjs/testing/record.js +2 -2
  277. package/dist-cjs/tracing/stores.js +2 -1
  278. package/dist-cjs/tracing/tracer.js +2 -2
  279. package/dist-cjs/types/config.d.ts +20 -0
  280. package/dist-cjs/types/graph.d.ts +38 -0
  281. package/dist-cjs/types/messages.d.ts +36 -2
  282. package/dist-cjs/types/principal.d.ts +21 -0
  283. package/dist-cjs/types/principal.js +2 -0
  284. package/dist-cjs/types/server.d.ts +8 -9
  285. package/dist-cjs/utils/base64.d.ts +4 -0
  286. package/dist-cjs/utils/base64.js +25 -0
  287. package/dist-cjs/utils/checksums.d.ts +22 -0
  288. package/dist-cjs/utils/checksums.js +46 -0
  289. package/dist-cjs/utils/ids.d.ts +8 -0
  290. package/dist-cjs/utils/ids.js +28 -2
  291. package/dist-cjs/utils/sha256.d.ts +22 -0
  292. package/dist-cjs/utils/sha256.js +125 -0
  293. package/dist-cjs/utils/tenant.d.ts +11 -0
  294. package/dist-cjs/utils/tenant.js +15 -0
  295. package/dist-cjs/version.d.ts +1 -1
  296. package/dist-cjs/version.js +1 -1
  297. package/llms.txt +7 -3
  298. package/package.json +193 -6
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterError = void 0;
4
+ exports.classifyAdapterError = classifyAdapterError;
5
+ class AdapterError extends Error {
6
+ adapter;
7
+ operation;
8
+ code;
9
+ retryable;
10
+ status;
11
+ constructor(adapter, operation, failure, cause) {
12
+ super(`${adapter} ${operation} failed (${failure.code}): ${cause instanceof Error ? cause.message : String(cause)}`, {
13
+ cause,
14
+ });
15
+ this.adapter = adapter;
16
+ this.operation = operation;
17
+ this.name = 'AdapterError';
18
+ this.code = failure.code;
19
+ this.retryable = failure.retryable;
20
+ if (failure.status !== undefined)
21
+ this.status = failure.status;
22
+ }
23
+ }
24
+ exports.AdapterError = AdapterError;
25
+ const RETRYABLE = new Set(['RATE_LIMIT', 'TIMEOUT', 'UNAVAILABLE']);
26
+ function classifyAdapterError(error) {
27
+ const value = error;
28
+ const raw = value?.status ?? value?.statusCode ?? value?.response?.status;
29
+ const status = typeof raw === 'number' ? raw : undefined;
30
+ const code = (() => {
31
+ if (value?.name === 'AbortError')
32
+ return 'CANCELLED';
33
+ if (value?.name === 'TimeoutError' || value?.code === 'ETIMEDOUT')
34
+ return 'TIMEOUT';
35
+ if (status !== undefined) {
36
+ if (status === 401 || status === 403)
37
+ return 'AUTH';
38
+ if (status === 404)
39
+ return 'NOT_FOUND';
40
+ if (status === 408)
41
+ return 'TIMEOUT';
42
+ if (status === 409 || status === 412)
43
+ return 'CONFLICT';
44
+ if (status === 429)
45
+ return 'RATE_LIMIT';
46
+ if (status >= 500)
47
+ return 'UNAVAILABLE';
48
+ if (status >= 400)
49
+ return 'INVALID';
50
+ }
51
+ if (typeof value?.code === 'string' && /^(ECONNREFUSED|ECONNRESET|ENOTFOUND|EAI_AGAIN|EPIPE)$/.test(value.code)) {
52
+ return 'UNAVAILABLE';
53
+ }
54
+ return 'UNKNOWN';
55
+ })();
56
+ return { code, retryable: RETRYABLE.has(code), ...(status === undefined ? {} : { status }) };
57
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The adapter kit: how a package outside this repository builds an adapter — a provider, an
3
+ * embeddings backend, a vector store, a retriever, or a long-term store — and proves it works.
4
+ *
5
+ * Each `define*()` takes what the adapter is, the releases of `nexus-ai-pro` it supports, what it
6
+ * can do, and how to create it, and returns an adapter whose instances normalize every failure into
7
+ * an `AdapterError` and report every call for telemetry. Its `verify()` runs the same contract suite
8
+ * this package runs on its own adapters, skipping only what the adapter declares it cannot do, with a
9
+ * small benchmark held to the budgets it declares.
10
+ */
11
+ import type { EmbeddingProvider, VectorStore } from '../hallucination/retrieval.js';
12
+ import type { BaseProvider } from '../providers/base.js';
13
+ import type { Retriever } from '../rag/retrievers.js';
14
+ import { type EmbeddingProviderConformanceOptions } from '../testing/embedding-provider-conformance.js';
15
+ import { type ProviderConformanceOptions } from '../testing/provider-conformance.js';
16
+ import type { EmbeddingsProvider } from '../types/embeddings.js';
17
+ import type { Store } from '../types/store.js';
18
+ import { type AdapterCheck, type RetrieverCapabilities, type RetrieverContractOptions, type StoreCapabilities, type VectorStoreCapabilities } from './contracts.js';
19
+ import { type AdapterErrorClass } from './errors.js';
20
+ export { ADAPTER_FIXTURE_PASSAGES, type AdapterCheck, type RetrieverCapabilities, type RetrieverContractOptions, runRetrieverContract, runStoreContract, runVectorStoreContract, type StoreCapabilities, type VectorStoreCapabilities, type VectorStoreContractOptions, } from './contracts.js';
21
+ export { AdapterError, type AdapterErrorClass, type AdapterErrorCode, classifyAdapterError } from './errors.js';
22
+ export { parseVersion, satisfiesRange } from './semver.js';
23
+ /** The kinds of adapter the kit builds. */
24
+ export type AdapterKind = 'provider' | 'embeddings' | 'vector-store' | 'retriever' | 'store';
25
+ /** What every adapter declares about itself. */
26
+ export interface AdapterDefinition<Config, Instance, Capabilities> {
27
+ /** Its name, usually its package name, such as `@acme/nexus-milvus`. */
28
+ name: string;
29
+ /** Its own version. */
30
+ version: string;
31
+ /** The releases of `nexus-ai-pro` it works with, as a range: `>=2.4.0 <3`. */
32
+ nexus: string;
33
+ /** What it can do. The contract skips what it declares it cannot, and fails what it claims and cannot. */
34
+ capabilities: Capabilities;
35
+ /** Creates an instance from its configuration. */
36
+ create(config: Config): Instance | Promise<Instance>;
37
+ /**
38
+ * Classifies a failure from the service behind the adapter, when the kit's own reading of statuses
39
+ * and network codes is not enough. Returning nothing falls back to that reading.
40
+ */
41
+ normalizeError?(error: unknown, operation: string): AdapterErrorClass | undefined;
42
+ /** The p95 latency each operation must stay within in `verify()`'s benchmark, in milliseconds. */
43
+ budgets?: Readonly<Record<string, number>>;
44
+ }
45
+ /** One call through an adapter, for telemetry. */
46
+ export interface AdapterCallEvent {
47
+ /** The adapter. */
48
+ adapter: string;
49
+ /** Its kind. */
50
+ kind: AdapterKind;
51
+ /** The method called, such as `search`. */
52
+ operation: string;
53
+ /** How long the call took, in milliseconds. */
54
+ durationMs: number;
55
+ /** Whether it succeeded. */
56
+ ok: boolean;
57
+ /** How it failed, when it did. */
58
+ error?: AdapterErrorClass;
59
+ }
60
+ /** Options for an adapter's `create()`. */
61
+ export interface AdapterCreateOptions {
62
+ /** Receives every call: the hook a tracer, a metrics exporter, or a log subscribes with. */
63
+ onCall?: (event: AdapterCallEvent) => void;
64
+ }
65
+ /** What `verify()` measured for one operation over the contract's calls. */
66
+ export interface AdapterBenchmarkEntry {
67
+ /** Successful calls measured. */
68
+ calls: number;
69
+ /** Median latency, in milliseconds. */
70
+ p50Ms: number;
71
+ /** 95th-percentile latency, in milliseconds. */
72
+ p95Ms: number;
73
+ }
74
+ /** What `verify()` found. */
75
+ export interface AdapterReport {
76
+ /** The adapter. */
77
+ adapter: string;
78
+ /** Its version. */
79
+ version: string;
80
+ /** Its kind. */
81
+ kind: AdapterKind;
82
+ /** The `nexus-ai-pro` release it was verified against. */
83
+ nexusVersion: string;
84
+ /** Whether that release is inside the adapter's declared range. */
85
+ compatible: boolean;
86
+ /** True when it is compatible and every check that ran held. */
87
+ passed: boolean;
88
+ /** Every check, in order, with skipped ones marked. */
89
+ checks: AdapterCheck[];
90
+ /** Latency per operation over the contract's calls. */
91
+ benchmark: Record<string, AdapterBenchmarkEntry>;
92
+ }
93
+ /** An adapter built with the kit. */
94
+ export interface Adapter<Config, Instance, Capabilities, VerifyOptions> extends Readonly<Omit<AdapterDefinition<Config, Instance, Capabilities>, 'create'>> {
95
+ /** Its kind. */
96
+ readonly kind: AdapterKind;
97
+ /** Creates an instance whose every call normalizes its failures and reports itself. */
98
+ create(config: Config, options?: AdapterCreateOptions): Promise<Instance>;
99
+ /** Whether a release of `nexus-ai-pro` is inside the declared range. Defaults to the installed one. */
100
+ compatible(nexusVersion?: string): boolean;
101
+ /** Runs the contract suite for its kind against a fresh instance, with a benchmark. */
102
+ verify(config: Config, options: VerifyOptions): Promise<AdapterReport>;
103
+ }
104
+ /** What a chat provider supports, which decides the conformance cases it runs. */
105
+ export interface ProviderAdapterCapabilities {
106
+ /** `stream()`. */
107
+ streaming: boolean;
108
+ /** JSON output through `responseFormat`. */
109
+ json: boolean;
110
+ /** Tool calls. */
111
+ tools: boolean;
112
+ /** `healthCheck()`. */
113
+ health: boolean;
114
+ }
115
+ /** Options for a provider adapter's `verify()`: the model and, if you like, cases of your own. */
116
+ export type ProviderVerifyOptions = Pick<ProviderConformanceOptions, 'model' | 'fixtures'>;
117
+ /** Builds a chat-provider adapter, verified by the provider conformance suite. */
118
+ export declare function defineProviderAdapter<Config, Instance extends BaseProvider>(definition: AdapterDefinition<Config, Instance, ProviderAdapterCapabilities>): Adapter<Config, Instance, ProviderAdapterCapabilities, ProviderVerifyOptions>;
119
+ /** What an embeddings backend supports. */
120
+ export interface EmbeddingsAdapterCapabilities {
121
+ /** Stops an embedding call when its signal aborts. */
122
+ abort: boolean;
123
+ /** Returns the same vectors for the same input. */
124
+ deterministic: boolean;
125
+ }
126
+ /** Options for an embeddings adapter's `verify()`. */
127
+ export type EmbeddingsVerifyOptions = Pick<EmbeddingProviderConformanceOptions, 'model' | 'fixtures'>;
128
+ /** Builds an embeddings adapter, verified by the embeddings conformance suite. */
129
+ export declare function defineEmbeddingsAdapter<Config, Instance extends EmbeddingsProvider>(definition: AdapterDefinition<Config, Instance, EmbeddingsAdapterCapabilities>): Adapter<Config, Instance, EmbeddingsAdapterCapabilities, EmbeddingsVerifyOptions>;
130
+ /** Options for a vector-store adapter's `verify()`. */
131
+ export interface VectorStoreVerifyOptions {
132
+ /** The embedding function the store embeds with, to compute a query vector. */
133
+ embed: EmbeddingProvider;
134
+ /** Waits for writes to become searchable, for an eventually consistent index. */
135
+ settle?: () => Promise<void>;
136
+ }
137
+ /** Builds a vector-store adapter, verified by the `VectorStore` contract. */
138
+ export declare function defineVectorStoreAdapter<Config, Instance extends VectorStore>(definition: AdapterDefinition<Config, Instance, VectorStoreCapabilities>): Adapter<Config, Instance, VectorStoreCapabilities, VectorStoreVerifyOptions>;
139
+ /** Options for a retriever adapter's `verify()`. */
140
+ export type RetrieverVerifyOptions = Omit<RetrieverContractOptions, 'capabilities'>;
141
+ /** Builds a retriever adapter, verified by the `Retriever` contract, and the `SparseRetriever` one when it takes writes. */
142
+ export declare function defineRetrieverAdapter<Config, Instance extends Retriever>(definition: AdapterDefinition<Config, Instance, RetrieverCapabilities>): Adapter<Config, Instance, RetrieverCapabilities, RetrieverVerifyOptions>;
143
+ /** Builds a long-term store adapter, verified by the `Store` contract. */
144
+ export declare function defineStoreAdapter<Config, Instance extends Store>(definition: AdapterDefinition<Config, Instance, StoreCapabilities>): Adapter<Config, Instance, StoreCapabilities, Record<string, never>>;
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.satisfiesRange = exports.parseVersion = exports.classifyAdapterError = exports.AdapterError = exports.runVectorStoreContract = exports.runStoreContract = exports.runRetrieverContract = exports.ADAPTER_FIXTURE_PASSAGES = void 0;
4
+ exports.defineProviderAdapter = defineProviderAdapter;
5
+ exports.defineEmbeddingsAdapter = defineEmbeddingsAdapter;
6
+ exports.defineVectorStoreAdapter = defineVectorStoreAdapter;
7
+ exports.defineRetrieverAdapter = defineRetrieverAdapter;
8
+ exports.defineStoreAdapter = defineStoreAdapter;
9
+ const embedding_provider_conformance_js_1 = require("../testing/embedding-provider-conformance.js");
10
+ const provider_conformance_js_1 = require("../testing/provider-conformance.js");
11
+ const version_js_1 = require("../version.js");
12
+ const contracts_js_1 = require("./contracts.js");
13
+ const errors_js_1 = require("./errors.js");
14
+ const semver_js_1 = require("./semver.js");
15
+ var contracts_js_2 = require("./contracts.js");
16
+ Object.defineProperty(exports, "ADAPTER_FIXTURE_PASSAGES", { enumerable: true, get: function () { return contracts_js_2.ADAPTER_FIXTURE_PASSAGES; } });
17
+ Object.defineProperty(exports, "runRetrieverContract", { enumerable: true, get: function () { return contracts_js_2.runRetrieverContract; } });
18
+ Object.defineProperty(exports, "runStoreContract", { enumerable: true, get: function () { return contracts_js_2.runStoreContract; } });
19
+ Object.defineProperty(exports, "runVectorStoreContract", { enumerable: true, get: function () { return contracts_js_2.runVectorStoreContract; } });
20
+ var errors_js_2 = require("./errors.js");
21
+ Object.defineProperty(exports, "AdapterError", { enumerable: true, get: function () { return errors_js_2.AdapterError; } });
22
+ Object.defineProperty(exports, "classifyAdapterError", { enumerable: true, get: function () { return errors_js_2.classifyAdapterError; } });
23
+ var semver_js_2 = require("./semver.js");
24
+ Object.defineProperty(exports, "parseVersion", { enumerable: true, get: function () { return semver_js_2.parseVersion; } });
25
+ Object.defineProperty(exports, "satisfiesRange", { enumerable: true, get: function () { return semver_js_2.satisfiesRange; } });
26
+ const OPERATIONS = {
27
+ provider: ['complete', 'healthCheck'],
28
+ embeddings: ['embed'],
29
+ 'vector-store': ['add', 'search', 'searchVector', 'delete'],
30
+ retriever: ['retrieve', 'add', 'delete'],
31
+ store: ['put', 'get', 'delete', 'search', 'listNamespaces'],
32
+ };
33
+ function build(kind, definition, contract) {
34
+ for (const field of ['name', 'version', 'nexus']) {
35
+ if (typeof definition[field] !== 'string' || !definition[field])
36
+ throw new TypeError(`An adapter needs a ${field}`);
37
+ }
38
+ (0, semver_js_1.satisfiesRange)(version_js_1.NEXUS_VERSION, definition.nexus);
39
+ const create = async (config, options = {}) => instrument(kind, definition, await definition.create(config), options);
40
+ return {
41
+ kind,
42
+ name: definition.name,
43
+ version: definition.version,
44
+ nexus: definition.nexus,
45
+ capabilities: definition.capabilities,
46
+ ...(definition.normalizeError ? { normalizeError: definition.normalizeError } : {}),
47
+ ...(definition.budgets ? { budgets: definition.budgets } : {}),
48
+ create,
49
+ compatible: (nexusVersion = version_js_1.NEXUS_VERSION) => (0, semver_js_1.satisfiesRange)(nexusVersion, definition.nexus),
50
+ async verify(config, options) {
51
+ const durations = new Map();
52
+ const instance = await create(config, {
53
+ onCall: (event) => {
54
+ if (event.ok)
55
+ durations.set(event.operation, [...(durations.get(event.operation) ?? []), event.durationMs]);
56
+ },
57
+ });
58
+ const compatible = (0, semver_js_1.satisfiesRange)(version_js_1.NEXUS_VERSION, definition.nexus);
59
+ const checks = [
60
+ {
61
+ name: `declares support for nexus-ai-pro ${version_js_1.NEXUS_VERSION}`,
62
+ ok: compatible,
63
+ ...(compatible ? {} : { detail: `the declared range is ${definition.nexus}` }),
64
+ },
65
+ ...(await contract(instance, options, definition.capabilities)),
66
+ ];
67
+ const benchmark = {};
68
+ for (const [operation, values] of durations) {
69
+ const sorted = [...values].sort((a, b) => a - b);
70
+ const at = (q) => round(sorted[Math.min(sorted.length - 1, Math.ceil(q * sorted.length) - 1)] ?? 0);
71
+ benchmark[operation] = { calls: sorted.length, p50Ms: at(0.5), p95Ms: at(0.95) };
72
+ }
73
+ for (const [operation, budget] of Object.entries(definition.budgets ?? {})) {
74
+ const measured = benchmark[operation]?.p95Ms;
75
+ checks.push(measured === undefined
76
+ ? {
77
+ name: `${operation} stays within ${budget} ms at p95`,
78
+ ok: true,
79
+ skipped: true,
80
+ detail: 'not called by the contract',
81
+ }
82
+ : {
83
+ name: `${operation} stays within ${budget} ms at p95`,
84
+ ok: measured <= budget,
85
+ ...(measured <= budget ? {} : { detail: `measured ${measured} ms` }),
86
+ });
87
+ }
88
+ return {
89
+ adapter: definition.name,
90
+ version: definition.version,
91
+ kind,
92
+ nexusVersion: version_js_1.NEXUS_VERSION,
93
+ compatible,
94
+ passed: checks.every((check) => check.ok),
95
+ checks,
96
+ benchmark,
97
+ };
98
+ },
99
+ };
100
+ }
101
+ function instrument(kind, definition, instance, options) {
102
+ const operations = new Set(OPERATIONS[kind]);
103
+ return new Proxy(instance, {
104
+ get(target, property, receiver) {
105
+ const value = Reflect.get(target, property, receiver);
106
+ if (typeof property !== 'string' || !operations.has(property) || typeof value !== 'function') {
107
+ return typeof value === 'function' ? value.bind(target) : value;
108
+ }
109
+ return async (...args) => {
110
+ const started = performance.now();
111
+ try {
112
+ const result = await value.apply(target, args);
113
+ options.onCall?.({
114
+ adapter: definition.name,
115
+ kind,
116
+ operation: property,
117
+ durationMs: performance.now() - started,
118
+ ok: true,
119
+ });
120
+ return result;
121
+ }
122
+ catch (error) {
123
+ const failure = error instanceof errors_js_1.AdapterError
124
+ ? {
125
+ code: error.code,
126
+ retryable: error.retryable,
127
+ ...(error.status === undefined ? {} : { status: error.status }),
128
+ }
129
+ : (definition.normalizeError?.(error, property) ?? (0, errors_js_1.classifyAdapterError)(error));
130
+ options.onCall?.({
131
+ adapter: definition.name,
132
+ kind,
133
+ operation: property,
134
+ durationMs: performance.now() - started,
135
+ ok: false,
136
+ error: failure,
137
+ });
138
+ throw error instanceof errors_js_1.AdapterError ? error : new errors_js_1.AdapterError(definition.name, property, failure, error);
139
+ }
140
+ };
141
+ },
142
+ });
143
+ }
144
+ function defineProviderAdapter(definition) {
145
+ return build('provider', definition, async (provider, options, capabilities) => {
146
+ const results = await (0, provider_conformance_js_1.runProviderConformance)(definition.name, provider, {
147
+ ...options,
148
+ testStream: capabilities.streaming,
149
+ testJson: capabilities.json,
150
+ testTools: capabilities.tools,
151
+ testHealth: capabilities.health,
152
+ });
153
+ return results.flatMap((result) => [
154
+ {
155
+ name: `completes the ${result.caseName} case`,
156
+ ok: result.completeOk,
157
+ ...(result.completeOk ? {} : { detail: result.error ?? 'the response was not accepted' }),
158
+ },
159
+ ...(result.streamOk === undefined ? [] : [{ name: `streams the ${result.caseName} case`, ok: result.streamOk }]),
160
+ ...(result.healthOk === undefined ? [] : [{ name: 'answers its health check', ok: result.healthOk }]),
161
+ ]);
162
+ });
163
+ }
164
+ function defineEmbeddingsAdapter(definition) {
165
+ return build('embeddings', definition, async (provider, options, capabilities) => {
166
+ const results = await (0, embedding_provider_conformance_js_1.runEmbeddingProviderConformance)(definition.name, provider, {
167
+ ...options,
168
+ testAbort: capabilities.abort,
169
+ testDeterminism: capabilities.deterministic,
170
+ });
171
+ return results.flatMap((result) => [
172
+ {
173
+ name: `embeds the ${result.caseName} case`,
174
+ ok: result.ok,
175
+ ...(result.ok ? {} : { detail: result.error ?? 'not accepted' }),
176
+ },
177
+ ...(result.abortOk === undefined
178
+ ? []
179
+ : [{ name: `stops the ${result.caseName} case when aborted`, ok: result.abortOk }]),
180
+ ]);
181
+ });
182
+ }
183
+ function defineVectorStoreAdapter(definition) {
184
+ return build('vector-store', definition, (store, options, capabilities) => (0, contracts_js_1.runVectorStoreContract)(store, { ...options, capabilities }));
185
+ }
186
+ function defineRetrieverAdapter(definition) {
187
+ return build('retriever', definition, (retriever, options, capabilities) => (0, contracts_js_1.runRetrieverContract)(retriever, { ...options, capabilities }));
188
+ }
189
+ function defineStoreAdapter(definition) {
190
+ return build('store', definition, (store, _options, capabilities) => (0, contracts_js_1.runStoreContract)(store, { capabilities }));
191
+ }
192
+ function round(value) {
193
+ return Math.round(value * 100) / 100;
194
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Version ranges, as an adapter declares the releases of `nexus-ai-pro` it works with. A small,
3
+ * dependency-free subset of npm's ranges: comparators joined by spaces must all hold, alternatives
4
+ * joined by `||` need one to hold, and `>=`, `>`, `<=`, `<`, `=`, `^`, `~`, `x`, and `*` mean what
5
+ * they mean in npm.
6
+ */
7
+ type Version = [number, number, number];
8
+ /** A version as three numbers. A prerelease or build tag is ignored. `undefined` for anything else. */
9
+ export declare function parseVersion(version: string): Version | undefined;
10
+ /** Whether `version` satisfies `range`, such as `>=2.4.0 <3` or `^2.4.0 || ^3.0.0`. */
11
+ export declare function satisfiesRange(version: string, range: string): boolean;
12
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseVersion = parseVersion;
4
+ exports.satisfiesRange = satisfiesRange;
5
+ function parseVersion(version) {
6
+ const match = /^\s*v?(\d+)\.(\d+)\.(\d+)/.exec(version);
7
+ return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : undefined;
8
+ }
9
+ function satisfiesRange(version, range) {
10
+ const parsed = parseVersion(version);
11
+ if (!parsed)
12
+ return false;
13
+ return range.split('||').some((alternative) => {
14
+ const comparators = alternative.trim().split(/\s+/).filter(Boolean);
15
+ return comparators.length === 0 || comparators.every((comparator) => holds(parsed, comparator));
16
+ });
17
+ }
18
+ function holds(version, comparator) {
19
+ const match = /^(>=|<=|>|<|=|\^|~)?v?(\d+|x|X|\*)(?:\.(\d+|x|X|\*))?(?:\.(\d+|x|X|\*))?/.exec(comparator);
20
+ if (!match)
21
+ throw new RangeError(`"${comparator}" is not a version range`);
22
+ const operator = match[1] ?? '';
23
+ const parts = [match[2], match[3], match[4]];
24
+ const fixed = parts.findIndex((part) => part === undefined || /^[xX*]$/.test(part));
25
+ const known = fixed === -1 ? 3 : fixed;
26
+ const base = parts.map((part, index) => (index < known ? Number(part) : 0));
27
+ if (known === 0)
28
+ return operator === '' || operator === '=' || operator === '>=' || operator === '<=';
29
+ switch (operator) {
30
+ case '>=':
31
+ return compare(version, base) >= 0;
32
+ case '>':
33
+ return known === 3 ? compare(version, base) > 0 : compare(version, bump(base, known - 1)) >= 0;
34
+ case '<=':
35
+ return known === 3 ? compare(version, base) <= 0 : compare(version, bump(base, known - 1)) < 0;
36
+ case '<':
37
+ return compare(version, base) < 0;
38
+ case '^': {
39
+ const pinned = base[0] > 0 || known === 1 ? 0 : base[1] > 0 || known === 2 ? 1 : 2;
40
+ return compare(version, base) >= 0 && compare(version, bump(base, pinned)) < 0;
41
+ }
42
+ case '~':
43
+ return compare(version, base) >= 0 && compare(version, bump(base, known >= 2 ? 1 : 0)) < 0;
44
+ default:
45
+ return known === 3
46
+ ? compare(version, base) === 0
47
+ : compare(version, base) >= 0 && compare(version, bump(base, known - 1)) < 0;
48
+ }
49
+ }
50
+ function bump(version, part) {
51
+ return version.map((value, index) => (index < part ? value : index === part ? value + 1 : 0));
52
+ }
53
+ function compare(left, right) {
54
+ for (let index = 0; index < 3; index += 1) {
55
+ if (left[index] !== right[index])
56
+ return left[index] - right[index];
57
+ }
58
+ return 0;
59
+ }
@@ -0,0 +1,39 @@
1
+ import type { ToolDefinition } from '../types/messages.js';
2
+ /**
3
+ * Capabilities: what a tool does to the world, written as strings a policy can decide on.
4
+ *
5
+ * | Capability | Means |
6
+ * | --- | --- |
7
+ * | `filesystem:read`, `filesystem:read:<path>` | Reads files, or one path |
8
+ * | `filesystem:write`, `filesystem:write:<path>` | Writes, creates, or deletes files |
9
+ * | `network`, `network:<host or URL>` | Opens a network connection, to a host when given |
10
+ * | `shell`, `shell:<command line>` | Runs a shell command |
11
+ * | `code` | Runs code it was given, as an interpreter does |
12
+ * | `<name>`, `<name>:<detail>` | Anything the application names, such as `payments:refund` |
13
+ *
14
+ * A tool that declares `capabilities: []` does nothing to the world; one that declares none at all
15
+ * is undeclared, and a policy decides on it as such.
16
+ */
17
+ /** One capability, split into its parts. */
18
+ export interface ParsedCapability {
19
+ /** `filesystem`, `network`, `shell`, `code`, or the application's own name. */
20
+ kind: string;
21
+ /** `read` or `write`, for the filesystem. */
22
+ access?: 'read' | 'write';
23
+ /** The path, host, command, or detail, when the capability names one. */
24
+ target?: string;
25
+ }
26
+ /** Splits a capability string into its kind, access, and target. */
27
+ export declare function parseCapability(capability: string): ParsedCapability;
28
+ /**
29
+ * The capabilities one call of a tool declares: its static list, or what its function computes from
30
+ * the call's arguments. `undefined` means undeclared — no list, or a function that threw — which is
31
+ * not the same as `[]`, a tool that declares it does nothing to the world.
32
+ */
33
+ export declare function capabilitiesOf(tool: Pick<ToolDefinition, 'capabilities'> | undefined, args: Record<string, unknown>): string[] | undefined;
34
+ /**
35
+ * Whether a capability is sensitive: anything but reading files. A pure tool declares
36
+ * `capabilities: []`; whatever it does declare, a write, a command, code, the network, or an
37
+ * effect of the application's own such as `payments`, changes the world or leaves the process.
38
+ */
39
+ export declare function isSensitiveCapability(capability: string): boolean;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCapability = parseCapability;
4
+ exports.capabilitiesOf = capabilitiesOf;
5
+ exports.isSensitiveCapability = isSensitiveCapability;
6
+ function parseCapability(capability) {
7
+ const text = capability.trim();
8
+ const colon = text.indexOf(':');
9
+ const kind = (colon < 0 ? text : text.slice(0, colon)).toLowerCase();
10
+ const rest = colon < 0 ? undefined : text.slice(colon + 1);
11
+ if (kind === 'filesystem') {
12
+ if (!rest)
13
+ return { kind };
14
+ const [access, ...path] = rest.split(':');
15
+ const parsed = { kind };
16
+ if (access === 'read' || access === 'write')
17
+ parsed.access = access;
18
+ const target = parsed.access ? path.join(':') : rest;
19
+ if (target)
20
+ parsed.target = target;
21
+ return parsed;
22
+ }
23
+ return rest === undefined || rest === '' ? { kind } : { kind, target: rest };
24
+ }
25
+ function capabilitiesOf(tool, args) {
26
+ const declared = tool?.capabilities;
27
+ if (!declared)
28
+ return undefined;
29
+ if (typeof declared !== 'function')
30
+ return [...declared];
31
+ try {
32
+ return [...declared(args)];
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ }
38
+ function isSensitiveCapability(capability) {
39
+ const parsed = parseCapability(capability);
40
+ return !(parsed.kind === 'filesystem' && parsed.access === 'read');
41
+ }