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
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.McpClient = void 0;
37
+ exports.serverEnvironment = serverEnvironment;
37
38
  exports.createStdioTransport = createStdioTransport;
38
39
  exports.createHttpTransport = createHttpTransport;
39
40
  const protocol_js_1 = require("./protocol.js");
@@ -170,6 +171,64 @@ class McpClient {
170
171
  }
171
172
  }
172
173
  exports.McpClient = McpClient;
174
+ const INHERITED_ENV = new Set([
175
+ 'PATH',
176
+ 'PATHEXT',
177
+ 'HOME',
178
+ 'USER',
179
+ 'USERNAME',
180
+ 'LOGNAME',
181
+ 'SHELL',
182
+ 'TERM',
183
+ 'LANG',
184
+ 'LANGUAGE',
185
+ 'TZ',
186
+ 'TMPDIR',
187
+ 'TEMP',
188
+ 'TMP',
189
+ 'XDG_CONFIG_HOME',
190
+ 'XDG_CACHE_HOME',
191
+ 'XDG_DATA_HOME',
192
+ 'XDG_RUNTIME_DIR',
193
+ 'SYSTEMROOT',
194
+ 'SYSTEMDRIVE',
195
+ 'WINDIR',
196
+ 'COMSPEC',
197
+ 'APPDATA',
198
+ 'LOCALAPPDATA',
199
+ 'USERPROFILE',
200
+ 'HOMEDRIVE',
201
+ 'HOMEPATH',
202
+ 'PROGRAMDATA',
203
+ 'PROGRAMFILES',
204
+ 'PROGRAMFILES(X86)',
205
+ 'COMMONPROGRAMFILES',
206
+ 'PROCESSOR_ARCHITECTURE',
207
+ 'NUMBER_OF_PROCESSORS',
208
+ 'OS',
209
+ 'HTTP_PROXY',
210
+ 'HTTPS_PROXY',
211
+ 'NO_PROXY',
212
+ 'ALL_PROXY',
213
+ 'NODE_EXTRA_CA_CERTS',
214
+ 'SSL_CERT_FILE',
215
+ 'SSL_CERT_DIR',
216
+ ]);
217
+ function serverEnvironment(source, options = {}) {
218
+ if (options.inheritEnv === false)
219
+ return { ...options.env };
220
+ const named = new Set((Array.isArray(options.inheritEnv) ? options.inheritEnv : []).map((name) => name.toUpperCase()));
221
+ const inherited = {};
222
+ for (const [name, value] of Object.entries(source)) {
223
+ if (value === undefined)
224
+ continue;
225
+ const upper = name.toUpperCase();
226
+ if (options.inheritEnv === true || INHERITED_ENV.has(upper) || upper.startsWith('LC_') || named.has(upper)) {
227
+ inherited[name] = value;
228
+ }
229
+ }
230
+ return { ...inherited, ...options.env };
231
+ }
173
232
  function createStdioTransport(options) {
174
233
  let child;
175
234
  const decoder = new protocol_js_1.LineDecoder();
@@ -180,7 +239,7 @@ function createStdioTransport(options) {
180
239
  const { spawn } = await Promise.resolve().then(() => __importStar(require('node:child_process')));
181
240
  const spawned = spawn(options.command, options.args ?? [], {
182
241
  cwd: options.cwd,
183
- env: { ...process.env, ...options.env },
242
+ env: serverEnvironment(process.env, options),
184
243
  stdio: ['pipe', 'pipe', 'inherit'],
185
244
  });
186
245
  spawned.stdout.setEncoding('utf8');
@@ -15,6 +15,12 @@ export interface McpServerConfig {
15
15
  env?: Record<string, string>;
16
16
  /** Working directory for the process. */
17
17
  cwd?: string;
18
+ /**
19
+ * Which of this process's own environment variables a local server inherits, besides `env`. By
20
+ * default, only what a process needs to start, never an API key; a list adds variables by name,
21
+ * `true` passes the whole environment, and `false` nothing but `env`.
22
+ */
23
+ inheritEnv?: boolean | string[];
18
24
  /** The endpoint of a remote server, reached over HTTP. */
19
25
  url?: string;
20
26
  /** Headers sent to a remote server, such as authorization. */
@@ -97,6 +97,7 @@ class McpRegistry {
97
97
  ...(resolved.args ? { args: resolved.args } : {}),
98
98
  ...(resolved.env ? { env: resolved.env } : {}),
99
99
  ...(resolved.cwd ? { cwd: resolved.cwd } : {}),
100
+ ...(resolved.inheritEnv !== undefined ? { inheritEnv: resolved.inheritEnv } : {}),
100
101
  })
101
102
  : (0, client_js_1.createHttpTransport)({
102
103
  url: resolved.url,
@@ -202,6 +203,12 @@ function validateMcpConfig(value) {
202
203
  throw new McpRegistryError(`Server "${name}": "${field}" is a list of strings`, name);
203
204
  }
204
205
  }
206
+ const inherit = server.inheritEnv;
207
+ if (inherit !== undefined &&
208
+ typeof inherit !== 'boolean' &&
209
+ !(Array.isArray(inherit) && inherit.every((item) => typeof item === 'string'))) {
210
+ throw new McpRegistryError(`Server "${name}": "inheritEnv" is true, false, or a list of names`, name);
211
+ }
205
212
  for (const field of ['env', 'headers']) {
206
213
  const map = server[field];
207
214
  if (map !== undefined &&
@@ -0,0 +1,67 @@
1
+ import type { RagChunk } from '../hallucination/rag.js';
2
+ import type { VectorSearchResult } from '../hallucination/retrieval.js';
3
+ import type { RetrieveOptions, SparseRetriever } from '../rag/retrievers.js';
4
+ import type { MigrationResult, SchemaMigration } from '../utils/schema-migrations.js';
5
+ import { type PostgresLikeClient } from './client.js';
6
+ import type { PostgresMigrateOptions } from './migrations.js';
7
+ /** Options for `PostgresKeywordIndex`. */
8
+ export interface PostgresKeywordIndexOptions {
9
+ /** Table name, optionally schema-qualified. Defaults to `nexus_keywords`. */
10
+ table?: string;
11
+ /**
12
+ * Searches the table of a `PostgresVectorStore` instead of keeping chunks of its own. `migrate()`
13
+ * adds a generated search column and its index to that table, the store's writes keep it current,
14
+ * and `add()` and `delete()` leave writing to the store. One copy of every chunk, and keyword and
15
+ * vector search can never disagree about what exists.
16
+ */
17
+ shared?: boolean;
18
+ /** The text search configuration: `english`, `simple`, `german`, and so on. Defaults to `english`. */
19
+ language?: string;
20
+ /**
21
+ * `any` (the default) finds chunks with any of the query's terms, ranked by how many and how close,
22
+ * as keyword search for retrieval should. `all` needs every term, read as a web search query, with
23
+ * quoted phrases and `-` for exclusion.
24
+ */
25
+ match?: 'any' | 'all';
26
+ }
27
+ /**
28
+ * The versioned schema, which `migrate()` applies. Version 1 creates the table with a generated
29
+ * `tsvector` column and a GIN index, or, `shared`, adds the column and the index to a vector table.
30
+ */
31
+ export declare function keywordIndexMigrations(options?: PostgresKeywordIndexOptions): SchemaMigration[];
32
+ /**
33
+ * Keyword search in Postgres, with its full-text search: stemmed terms, a GIN index, and
34
+ * `ts_rank_cd` ranking, so only the best matches leave the database however large the table.
35
+ *
36
+ * A `SparseRetriever`, so `hybridRetriever()` fuses it with `PostgresVectorStore`. With `shared`, it
37
+ * searches the vector store's own table, and the hybrid search runs over one copy of the data. A
38
+ * metadata filter runs in SQL, with the same meaning as the vector store's.
39
+ *
40
+ * ```ts
41
+ * const vectors = new PostgresVectorStore(client, { dimensions: 1536, embed });
42
+ * const keywords = new PostgresKeywordIndex(client, { table: 'nexus_vectors', shared: true });
43
+ * await vectors.migrate();
44
+ * await keywords.migrate();
45
+ * const retriever = hybridRetriever([vectorRetriever(vectors), keywords]);
46
+ * ```
47
+ */
48
+ export declare class PostgresKeywordIndex implements SparseRetriever {
49
+ private readonly client;
50
+ private readonly options;
51
+ private readonly table;
52
+ private readonly language;
53
+ constructor(client: PostgresLikeClient, options?: PostgresKeywordIndexOptions);
54
+ /**
55
+ * Applies this index's pending migrations, recorded in `nexus_schema_migrations`, under a lock.
56
+ * Never runs implicitly. With `shared`, run the vector store's `migrate()` first.
57
+ */
58
+ migrate(options?: PostgresMigrateOptions): Promise<MigrationResult>;
59
+ /** Adds chunks, or replaces those whose id exists. With `shared`, does nothing: the vector store writes. */
60
+ add(chunks: readonly RagChunk[]): Promise<void>;
61
+ /** Removes chunks by id. With `shared`, does nothing: the vector store deletes. */
62
+ delete(ids: readonly string[]): Promise<void>;
63
+ /** The chunks that best match a query's terms, best first, scored from 0 to 1. */
64
+ retrieve(query: string, options?: RetrieveOptions): Promise<VectorSearchResult[]>;
65
+ /** Chunks held. */
66
+ size(): Promise<number>;
67
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PostgresKeywordIndex = void 0;
37
+ exports.keywordIndexMigrations = keywordIndexMigrations;
38
+ const client_js_1 = require("./client.js");
39
+ const sql_js_1 = require("./sql.js");
40
+ const DEFAULT_TABLE = 'nexus_keywords';
41
+ function languageOf(options) {
42
+ const language = options.language ?? 'english';
43
+ if (!/^[a-z_]{1,63}$/.test(language))
44
+ throw new RangeError(`"${language}" is not a text search configuration name`);
45
+ return language;
46
+ }
47
+ function keywordIndexMigrations(options = {}) {
48
+ const name = options.table ?? DEFAULT_TABLE;
49
+ const table = (0, client_js_1.quoteTable)(name);
50
+ const generated = `fts tsvector GENERATED ALWAYS AS (to_tsvector('${languageOf(options)}'::regconfig, content)) STORED`;
51
+ return [
52
+ {
53
+ component: `keywords:${name}`,
54
+ version: 1,
55
+ name: options.shared ? 'add full-text search to a vector table' : 'create the keyword table',
56
+ statements: [
57
+ options.shared
58
+ ? `ALTER TABLE ${table} ADD COLUMN IF NOT EXISTS ${generated}`
59
+ : `CREATE TABLE IF NOT EXISTS ${table} (
60
+ id text PRIMARY KEY,
61
+ content text NOT NULL,
62
+ source text,
63
+ metadata jsonb,
64
+ ${generated}
65
+ )`,
66
+ `CREATE INDEX IF NOT EXISTS ${(0, client_js_1.quoteDerived)(name, 'fts')} ON ${table} USING gin (fts)`,
67
+ ],
68
+ },
69
+ ];
70
+ }
71
+ class PostgresKeywordIndex {
72
+ client;
73
+ options;
74
+ table;
75
+ language;
76
+ constructor(client, options = {}) {
77
+ this.client = client;
78
+ this.options = options;
79
+ this.table = (0, client_js_1.quoteTable)(options.table ?? DEFAULT_TABLE);
80
+ this.language = languageOf(options);
81
+ }
82
+ async migrate(options = {}) {
83
+ const { applyPostgresMigrations } = await Promise.resolve().then(() => __importStar(require('./migrations.js')));
84
+ return applyPostgresMigrations(this.client, keywordIndexMigrations(this.options), options);
85
+ }
86
+ async add(chunks) {
87
+ if (this.options.shared || chunks.length === 0)
88
+ return;
89
+ const params = new sql_js_1.SqlParams();
90
+ const rows = chunks.map((chunk) => `(${params.add(chunk.id)}, ${params.add(chunk.content)}, ${params.add(chunk.source ?? null)}, ${params.add(chunk.metadata === undefined ? null : JSON.stringify(chunk.metadata))}::jsonb)`);
91
+ await this.client.query(`INSERT INTO ${this.table} (id, content, source, metadata) VALUES ${rows.join(', ')}
92
+ ON CONFLICT (id) DO UPDATE SET content = EXCLUDED.content, source = EXCLUDED.source, metadata = EXCLUDED.metadata`, params.values);
93
+ }
94
+ async delete(ids) {
95
+ if (this.options.shared || ids.length === 0)
96
+ return;
97
+ await this.client.query(`DELETE FROM ${this.table} WHERE id = ANY($1::text[])`, [(0, sql_js_1.textArray)(ids)]);
98
+ }
99
+ async retrieve(query, options = {}) {
100
+ options.signal?.throwIfAborted();
101
+ const params = new sql_js_1.SqlParams();
102
+ const text = params.add(query);
103
+ const language = `'${this.language}'::regconfig`;
104
+ const tsquery = this.options.match === 'all'
105
+ ? `websearch_to_tsquery(${language}, ${text})`
106
+ : `NULLIF(replace(plainto_tsquery(${language}, ${text})::text, ' & ', ' | '), '')::tsquery`;
107
+ const conditions = ['fts @@ q.query'];
108
+ if (options.filter && Object.keys(options.filter).length > 0) {
109
+ conditions.push(`metadata @> ${params.add(JSON.stringify(options.filter))}::jsonb`);
110
+ }
111
+ const limit = params.add(options.topK ?? 5);
112
+ const { rows } = await this.client.query(`SELECT id, content, source, metadata::text AS metadata, ts_rank_cd(fts, q.query, 32) AS score
113
+ FROM ${this.table}, (SELECT ${tsquery} AS query) AS q
114
+ WHERE ${conditions.join(' AND ')}
115
+ ORDER BY score DESC, id LIMIT ${limit}`, params.values);
116
+ return rows.map((row) => ({
117
+ id: row.id,
118
+ content: row.content,
119
+ ...(row.source === null ? {} : { source: row.source }),
120
+ ...(row.metadata === null ? {} : { metadata: (0, client_js_1.fromJson)(row.metadata) }),
121
+ score: Number(row.score),
122
+ }));
123
+ }
124
+ async size() {
125
+ const { rows } = await this.client.query(`SELECT count(*)::int AS count FROM ${this.table}`);
126
+ return Number(rows[0]?.count ?? 0);
127
+ }
128
+ }
129
+ exports.PostgresKeywordIndex = PostgresKeywordIndex;
@@ -44,20 +44,24 @@ class FilePromptStore {
44
44
  }
45
45
  async setLabel(label, expected) {
46
46
  const file = this.labelFile(label.name, label.label);
47
- if (expected !== undefined) {
48
- const current = await readJson(file);
49
- if (expected === null ? current !== undefined : current?.version !== expected)
50
- return false;
51
- }
52
- await writeJson(file, label);
53
- return true;
47
+ return serialized(file, async () => {
48
+ if (expected !== undefined) {
49
+ const current = await readJson(file);
50
+ if (expected === null ? current !== undefined : current?.version !== expected)
51
+ return false;
52
+ }
53
+ await writeJson(file, label);
54
+ return true;
55
+ });
54
56
  }
55
57
  async deleteLabel(name, label) {
56
58
  const file = this.labelFile(name, label);
57
- if ((await readJson(file)) === undefined)
58
- return false;
59
- await (0, promises_1.rm)(file, { force: true });
60
- return true;
59
+ return serialized(file, async () => {
60
+ if ((await readJson(file)) === undefined)
61
+ return false;
62
+ await (0, promises_1.rm)(file, { force: true });
63
+ return true;
64
+ });
61
65
  }
62
66
  async appendHistory(entry) {
63
67
  await (0, promises_1.mkdir)(this.promptDir(entry.name), { recursive: true });
@@ -116,6 +120,19 @@ async function readJson(file) {
116
120
  return undefined;
117
121
  }
118
122
  }
123
+ const labelWrites = new Map();
124
+ async function serialized(file, work) {
125
+ const key = node_path_1.default.resolve(file);
126
+ const next = (labelWrites.get(key) ?? Promise.resolve()).catch(() => undefined).then(work);
127
+ labelWrites.set(key, next);
128
+ try {
129
+ return await next;
130
+ }
131
+ finally {
132
+ if (labelWrites.get(key) === next)
133
+ labelWrites.delete(key);
134
+ }
135
+ }
119
136
  async function writeJson(file, value) {
120
137
  await (0, promises_1.mkdir)(node_path_1.default.dirname(file), { recursive: true });
121
138
  const temporary = `${file}.${process.pid}.${Date.now()}.tmp`;
@@ -0,0 +1,235 @@
1
+ import type { Message, ToolDefinition } from '../types/messages.js';
2
+ import type { Principal } from '../types/principal.js';
3
+ import { type ProtocolGraph, type ProtocolInterrupt } from './shared.js';
4
+ export type { ProtocolGraph, ProtocolInterrupt, ProtocolResult, ProtocolRunOptions } from './shared.js';
5
+ /** The protocol version this module speaks. */
6
+ export declare const A2A_PROTOCOL_VERSION = "1.0";
7
+ /** Who a message is from. */
8
+ export type A2aRole = 'ROLE_USER' | 'ROLE_AGENT';
9
+ /** Where a task stands. */
10
+ export type A2aTaskState = 'TASK_STATE_SUBMITTED' | 'TASK_STATE_WORKING' | 'TASK_STATE_INPUT_REQUIRED' | 'TASK_STATE_AUTH_REQUIRED' | 'TASK_STATE_COMPLETED' | 'TASK_STATE_FAILED' | 'TASK_STATE_CANCELED' | 'TASK_STATE_REJECTED';
11
+ /** One part of a message or an artifact: text, structured data, or a file by URL or bytes. */
12
+ export interface A2aPart {
13
+ /** Text. */
14
+ text?: string;
15
+ /** Structured data. */
16
+ data?: unknown;
17
+ /** A file, by URL. */
18
+ url?: string;
19
+ /** A file, as base64 bytes. */
20
+ raw?: string;
21
+ /** The part's media type. */
22
+ mediaType?: string;
23
+ /** A file's name. */
24
+ filename?: string;
25
+ /** Anything else. */
26
+ metadata?: Record<string, unknown>;
27
+ }
28
+ /** A message between agents. */
29
+ export interface A2aMessage {
30
+ /** Its id. */
31
+ messageId: string;
32
+ /** Who it is from. */
33
+ role: A2aRole;
34
+ /** What it says. */
35
+ parts: A2aPart[];
36
+ /** The conversation it belongs to. */
37
+ contextId?: string;
38
+ /** The task it continues, when it answers one. */
39
+ taskId?: string;
40
+ /** Anything else. */
41
+ metadata?: Record<string, unknown>;
42
+ }
43
+ /** What a task produced. */
44
+ export interface A2aArtifact {
45
+ /** Its id. */
46
+ artifactId: string;
47
+ /** Its name. */
48
+ name?: string;
49
+ /** Its content. */
50
+ parts: A2aPart[];
51
+ }
52
+ /** A unit of work an agent was asked to do. */
53
+ export interface A2aTask {
54
+ /** Its id. */
55
+ id: string;
56
+ /** The conversation it belongs to. */
57
+ contextId: string;
58
+ /** Where it stands, with the agent's latest message. */
59
+ status: {
60
+ state: A2aTaskState;
61
+ message?: A2aMessage;
62
+ timestamp?: string;
63
+ };
64
+ /** What it produced. */
65
+ artifacts?: A2aArtifact[];
66
+ /** The messages exchanged, when asked for. */
67
+ history?: A2aMessage[];
68
+ /** Anything else. */
69
+ metadata?: Record<string, unknown>;
70
+ }
71
+ /** A skill an agent card advertises. */
72
+ export interface A2aSkill {
73
+ /** Its id. */
74
+ id: string;
75
+ /** Its name. */
76
+ name: string;
77
+ /** What it does. */
78
+ description: string;
79
+ /** Labels for discovery. */
80
+ tags: string[];
81
+ /** Example requests. */
82
+ examples?: string[];
83
+ }
84
+ /** What an agent publishes about itself at `/.well-known/agent-card.json`. */
85
+ export interface A2aAgentCard {
86
+ /** Its name. */
87
+ name: string;
88
+ /** What it does. */
89
+ description: string;
90
+ /** Its version. */
91
+ version: string;
92
+ /** Who provides it. */
93
+ provider?: {
94
+ organization: string;
95
+ url?: string;
96
+ };
97
+ /** Where it is reached, and how. */
98
+ supportedInterfaces: Array<{
99
+ url: string;
100
+ protocolBinding: string;
101
+ protocolVersion: string;
102
+ }>;
103
+ /** What it supports. */
104
+ capabilities: {
105
+ streaming: boolean;
106
+ pushNotifications: boolean;
107
+ extendedAgentCard: boolean;
108
+ };
109
+ /** Media types it accepts. */
110
+ defaultInputModes: string[];
111
+ /** Media types it produces. */
112
+ defaultOutputModes: string[];
113
+ /** What it can do. */
114
+ skills: A2aSkill[];
115
+ }
116
+ /** A streamed event: a task, a status change, or a piece of an artifact. */
117
+ export type A2aStreamEvent = {
118
+ task: A2aTask;
119
+ } | {
120
+ message: A2aMessage;
121
+ } | {
122
+ statusUpdate: {
123
+ taskId: string;
124
+ contextId: string;
125
+ status: A2aTask['status'];
126
+ };
127
+ } | {
128
+ artifactUpdate: {
129
+ taskId: string;
130
+ contextId: string;
131
+ artifact: A2aArtifact;
132
+ append?: boolean;
133
+ lastChunk?: boolean;
134
+ };
135
+ };
136
+ /** A2A's error codes, beside JSON-RPC's own. */
137
+ export declare const A2A_ERRORS: {
138
+ readonly taskNotFound: -32001;
139
+ readonly taskNotCancelable: -32002;
140
+ readonly unsupportedOperation: -32004;
141
+ readonly versionNotSupported: -32009;
142
+ };
143
+ /** Raised by the client when an agent answers with a JSON-RPC error. */
144
+ export declare class A2aError extends Error {
145
+ /** The JSON-RPC error code. */
146
+ readonly code: number;
147
+ /** The error's data, when the agent sent any. */
148
+ readonly data?: unknown | undefined;
149
+ constructor(
150
+ /** The JSON-RPC error code. */
151
+ code: number, message: string,
152
+ /** The error's data, when the agent sent any. */
153
+ data?: unknown | undefined);
154
+ }
155
+ /** Options for `a2aHandler()`. */
156
+ export interface A2aServerOptions {
157
+ /** The card's content: the endpoint `url` is where this handler is mounted. */
158
+ card: Omit<A2aAgentCard, 'supportedInterfaces' | 'capabilities' | 'defaultInputModes' | 'defaultOutputModes'> & {
159
+ url: string;
160
+ defaultInputModes?: string[];
161
+ defaultOutputModes?: string[];
162
+ };
163
+ /** The graph input for a task. Defaults to `{ messages }`: the context's conversation and the new message. */
164
+ input?: (message: A2aMessage, history: Message[]) => unknown;
165
+ /**
166
+ * The answer a message gives a paused task's question. Defaults to its first data part's value,
167
+ * such as `{ approved: true }` for a tool approval, or else its text. Text answering an approval is
168
+ * read as words: yes, ok, allow, approve, or confirm allows, and anything else refuses.
169
+ */
170
+ answer?: (message: A2aMessage, interrupt: ProtocolInterrupt) => unknown;
171
+ /** Who the task is for, from the request: the place to authenticate the calling agent. */
172
+ principal?: (request: Request) => Principal | undefined | Promise<Principal | undefined>;
173
+ /** Most tasks and contexts kept in memory. Defaults to 10,000 each. */
174
+ maxTasks?: number;
175
+ }
176
+ /**
177
+ * An HTTP handler that serves a graph as an A2A agent: `GET` the card, `POST` JSON-RPC. Mount it
178
+ * at the card's `url`; it answers the well-known card path under the same origin too.
179
+ *
180
+ * ```ts
181
+ * const handler = a2aHandler(agent, {
182
+ * card: { name: 'Researcher', description: 'Answers research questions', version: '1.0.0', url: 'https://agents.example.com/a2a', skills: [] },
183
+ * });
184
+ * ```
185
+ */
186
+ export declare function a2aHandler(graph: ProtocolGraph, options: A2aServerOptions): (request: Request) => Promise<Response>;
187
+ /** Options for `a2aClient()`. */
188
+ export interface A2aClientOptions {
189
+ /** The agent: its card's URL, or its JSON-RPC endpoint, whose origin serves the card. */
190
+ url: string;
191
+ /** Replaces the global `fetch`, for authentication, a proxy, or tests. */
192
+ fetch?: typeof globalThis.fetch;
193
+ /** Headers added to every request, such as an authorization header. */
194
+ headers?: Record<string, string>;
195
+ }
196
+ /** What to send: text, and optionally data, a conversation, or the paused task it answers. */
197
+ export interface A2aSendOptions {
198
+ /** The conversation to continue. */
199
+ contextId?: string;
200
+ /** The paused task this message answers. */
201
+ taskId?: string;
202
+ /** Structured data sent beside the text, such as `{ approved: true }`. */
203
+ data?: unknown;
204
+ /** Cancels the request. */
205
+ signal?: AbortSignal;
206
+ }
207
+ /** A client for one A2A agent. */
208
+ export interface A2aClient {
209
+ /** The agent's card, fetched once. */
210
+ card(): Promise<A2aAgentCard>;
211
+ /** Sends a message and waits for the task it starts or continues. */
212
+ send(text: string, options?: A2aSendOptions): Promise<A2aTask>;
213
+ /** Sends a message and reads the task's events as they arrive. */
214
+ stream(text: string, options?: A2aSendOptions): AsyncGenerator<A2aStreamEvent>;
215
+ /** Reads a task. */
216
+ getTask(taskId: string, historyLength?: number): Promise<A2aTask>;
217
+ /** Cancels a task. */
218
+ cancel(taskId: string): Promise<A2aTask>;
219
+ }
220
+ /** A client for an A2A agent, by its card or endpoint URL. */
221
+ export declare function a2aClient(options: A2aClientOptions): A2aClient;
222
+ /** Options for `a2aTool()`. */
223
+ export interface A2aToolOptions extends A2aClientOptions {
224
+ /** The tool's name, as the model calls it. */
225
+ name: string;
226
+ /** What the remote agent does, written for the model that decides when to call it. */
227
+ description: string;
228
+ }
229
+ /**
230
+ * A remote A2A agent as a tool another agent can call. Each call is a task, and the remote agent's
231
+ * answer is the result; a remote task that needs input reports its question, which the model can
232
+ * answer by calling again with `taskId`. The tool declares the host it reaches, as
233
+ * `network:<host>`, so a permission policy grants or denies it like any other.
234
+ */
235
+ export declare function a2aTool(options: A2aToolOptions): ToolDefinition;