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
@@ -140,6 +140,11 @@ function createAgentServer(options) {
140
140
  const body = await (0, http_js_1.readJson)(request);
141
141
  return (0, http_js_1.json)(await runs.cancel(params.runId, principal, body.reason));
142
142
  });
143
+ write('POST', '/runs/:runId/feedback', async ({ request, params, principal }) => {
144
+ const body = await (0, http_js_1.readJson)(request);
145
+ const run = await runs.addFeedback(params.runId, { ...body, source: body.source ?? principal?.userId ?? 'api' }, principal);
146
+ return (0, http_js_1.json)({ runId: run.id, feedback: run.feedback?.at(-1) }, 201);
147
+ });
143
148
  read('GET', '/runs/:runId/events', async ({ request, params, principal, url }) => {
144
149
  await runs.run(params.runId, principal);
145
150
  const header = request.headers.get('last-event-id') ?? url.searchParams.get('lastEventId');
@@ -20,6 +20,10 @@ export declare class MemoryStore implements Store {
20
20
  private readonly options;
21
21
  private readonly items;
22
22
  private readonly maxItems;
23
+ /** Whether any item was ever given a time to live; until one is, there is nothing to sweep. */
24
+ private expiring;
25
+ /** When expired items were last swept, in milliseconds. */
26
+ private sweptAt;
23
27
  private readonly now;
24
28
  constructor(options?: MemoryStoreOptions);
25
29
  /** Stores an item, keeping its original `createdAt` when it replaces one. */
@@ -42,5 +46,11 @@ export declare class MemoryStore implements Store {
42
46
  size(): number;
43
47
  private embed;
44
48
  private expired;
49
+ /**
50
+ * Drops expired items. Reads already skip them, so this only reclaims memory: it runs once any item
51
+ * has a time to live, and at most once a second, so a write stays constant-time however many items
52
+ * there are. A store that is full sweeps before it evicts, so a live item never makes way for an
53
+ * expired one.
54
+ */
45
55
  private sweep;
46
56
  }
@@ -11,6 +11,8 @@ class MemoryStore {
11
11
  options;
12
12
  items = new Map();
13
13
  maxItems;
14
+ expiring = false;
15
+ sweptAt = Number.NEGATIVE_INFINITY;
14
16
  now;
15
17
  constructor(options = {}) {
16
18
  this.options = options;
@@ -25,6 +27,8 @@ class MemoryStore {
25
27
  const timestamp = this.now().toISOString();
26
28
  const existing = this.items.get(id);
27
29
  const vector = await this.embed(value, options.index);
30
+ if (options.ttlMs !== undefined)
31
+ this.expiring = true;
28
32
  this.items.delete(id);
29
33
  this.items.set(id, {
30
34
  namespace: [...namespace],
@@ -106,6 +110,12 @@ class MemoryStore {
106
110
  return item.expiresAt !== undefined && Date.parse(item.expiresAt) <= this.now().getTime();
107
111
  }
108
112
  sweep() {
113
+ if (!this.expiring)
114
+ return;
115
+ const now = this.now().getTime();
116
+ if (now - this.sweptAt < 1_000 && this.items.size <= this.maxItems)
117
+ return;
118
+ this.sweptAt = now;
109
119
  for (const [id, item] of this.items)
110
120
  if (this.expired(item))
111
121
  this.items.delete(id);
@@ -9,7 +9,7 @@ exports.replayFetch = replayFetch;
9
9
  exports.fixtureFetch = fixtureFetch;
10
10
  exports.installFetch = installFetch;
11
11
  exports.readFixtures = readFixtures;
12
- const node_crypto_1 = require("node:crypto");
12
+ const sha256_js_1 = require("../utils/sha256.js");
13
13
  const promises_1 = require("node:fs/promises");
14
14
  const node_path_1 = __importDefault(require("node:path"));
15
15
  class FixtureMissingError extends Error {
@@ -160,7 +160,7 @@ function defaultKey(input, ignoreBodyFields = []) {
160
160
  }
161
161
  catch {
162
162
  }
163
- return (0, node_crypto_1.createHash)('sha256').update(`${input.method}\n${input.url}\n${body}`).digest('hex').slice(0, 16);
163
+ return (0, sha256_js_1.sha256Hex)(`${input.method}\n${input.url}\n${body}`).slice(0, 16);
164
164
  }
165
165
  function canonical(value) {
166
166
  if (Array.isArray(value))
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.JsonlTraceStore = exports.MemoryTraceStore = exports.assembleTree = exports.applyQuery = void 0;
7
7
  exports.closeAbandonedRuns = closeAbandonedRuns;
8
+ const ids_js_1 = require("../utils/ids.js");
8
9
  const promises_1 = require("node:fs/promises");
9
10
  const node_path_1 = __importDefault(require("node:path"));
10
11
  const query_js_1 = require("./query.js");
@@ -141,7 +142,7 @@ class JsonlTraceStore {
141
142
  catch {
142
143
  return;
143
144
  }
144
- if (Buffer.byteLength(content, 'utf8') <= this.maxBytes)
145
+ if ((0, ids_js_1.utf8Length)(content) <= this.maxBytes)
145
146
  return;
146
147
  const lines = content.split('\n').filter(Boolean);
147
148
  await (0, promises_1.writeFile)(this.file, `${lines.slice(Math.floor(lines.length / 2)).join('\n')}\n`, 'utf8');
@@ -4,8 +4,8 @@ exports.Tracer = void 0;
4
4
  exports.w3cTraceId = w3cTraceId;
5
5
  exports.w3cSpanId = w3cSpanId;
6
6
  exports.stripFields = stripFields;
7
+ const ids_js_1 = require("../utils/ids.js");
7
8
  const node_async_hooks_1 = require("node:async_hooks");
8
- const node_crypto_1 = require("node:crypto");
9
9
  class Tracer {
10
10
  options;
11
11
  context = new node_async_hooks_1.AsyncLocalStorage();
@@ -201,7 +201,7 @@ class Tracer {
201
201
  }
202
202
  exports.Tracer = Tracer;
203
203
  function id(prefix) {
204
- return `${prefix}-${(0, node_crypto_1.randomBytes)(8).toString('hex')}`;
204
+ return `${prefix}-${(0, ids_js_1.randomHex)(8)}`;
205
205
  }
206
206
  function w3cTraceId(traceId) {
207
207
  if (/^[0-9a-f]{32}$/.test(traceId))
@@ -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;
@@ -8,6 +8,7 @@ import type { OperationLifecycleLike } from './lifecycle.js';
8
8
  * is, so a different process can pick it up.
9
9
  */
10
10
  import type { CacheAdapter } from '../cache/adapters.js';
11
+ import type { Principal } from './principal.js';
11
12
  import type { Store } from './store.js';
12
13
  /** Entry sentinel. An edge from `START` names the first node. */
13
14
  export declare const START = "__start__";
@@ -243,6 +244,14 @@ export interface NodeOptions<S extends ChannelSchema = ChannelSchema> {
243
244
  * that are not.
244
245
  */
245
246
  idempotent?: boolean;
247
+ /**
248
+ * What the node does to the world, as capabilities: `payments:charge`, `network:api.stripe.com`,
249
+ * `filesystem:write`. Declared for the linter, which reports a node with effects that also
250
+ * interrupts, since the node runs again from the top when the answer comes.
251
+ */
252
+ effects?: readonly string[];
253
+ /** True when the node may call `context.interrupt()`. Declared for the linter. */
254
+ interrupts?: boolean;
246
255
  /**
247
256
  * Nodes this one may reach through `Send` or a `Command`. Declaring them keeps compile-time
248
257
  * reachability checks and diagrams exact, so a node reached only that way is not reported as
@@ -374,6 +383,8 @@ export interface NodeContext<S extends ChannelSchema> {
374
383
  readonly threadId: string;
375
384
  /** The tenant the run is for, when it has one. */
376
385
  readonly tenantId?: string;
386
+ /** Who the run is for, when it was started with a principal: the caller the server authenticated. */
387
+ readonly principal?: Readonly<Principal>;
377
388
  /** Identifies this task. Equal to `node` unless the task came from a `Send`. */
378
389
  readonly taskId: string;
379
390
  /** Input carried by a `Send`. Undefined for a node reached through an ordinary edge. */
@@ -577,6 +588,14 @@ export interface GraphRunOptions {
577
588
  * `tenantId` is refused before anything runs. A run without one carries on the thread's tenant.
578
589
  */
579
590
  tenantId?: string;
591
+ /**
592
+ * Who the run is for, such as the caller the server authenticated. Nodes read it as
593
+ * `context.principal`, and an agent hands it to every tool and middleware. Its `tenantId` is the
594
+ * run's tenant when `tenantId` is not given, and a run whose two tenants differ is refused. Its
595
+ * `userId` is recorded on every checkpoint as `metadata.userId`; the rest is never stored, so a
596
+ * resumed run carries the principal of whoever resumed it.
597
+ */
598
+ principal?: Principal;
580
599
  /** Overrides the compiled `maxConcurrency` for this run. */
581
600
  maxConcurrency?: number;
582
601
  /** Breakpoints for this run only, replacing the compiled ones. */
@@ -853,6 +872,10 @@ export interface GraphDescription {
853
872
  idempotent?: boolean;
854
873
  /** True when the node reuses results through `cache`. */
855
874
  cache?: boolean;
875
+ /** The capabilities its work uses, when it declares them. */
876
+ effects?: string[];
877
+ /** True when it declares that it may interrupt. */
878
+ interrupts?: boolean;
856
879
  /** The graph this node runs, when it is a compiled graph used through `asNode()`. */
857
880
  subgraph?: GraphDescription;
858
881
  }>;
@@ -876,6 +899,19 @@ export interface GraphDescription {
876
899
  checkpointer?: 'memory' | 'custom' | 'none';
877
900
  /** Tasks a superstep runs at once. */
878
901
  maxConcurrency?: number;
902
+ /** The tools the graph's nodes call, when it was compiled with them, as an agent is. */
903
+ tools?: GraphToolDescription[];
904
+ }
905
+ /** A tool a graph calls, as the linter reads it. */
906
+ export interface GraphToolDescription {
907
+ /** The tool's name. */
908
+ name: string;
909
+ /** Its capabilities, when it declares a fixed list. */
910
+ capabilities?: string[];
911
+ /** True when it computes its capabilities from each call's arguments. */
912
+ dynamic?: boolean;
913
+ /** How its calls are approved: an interrupt for each, a permission policy, or not at all. */
914
+ approval: 'interrupt' | 'policy' | 'none';
879
915
  }
880
916
  /**
881
917
  * Options applied when a graph is compiled: stores, breakpoints, concurrency, retries, and failure
@@ -898,6 +934,8 @@ export interface CompileOptions {
898
934
  maxConcurrency?: number;
899
935
  /** Default retry policy for every node. A node's own policy wins. */
900
936
  retry?: RetryPolicy;
937
+ /** The tools the graph's nodes call, for `describe()` and the linter. `createAgent()` fills it. */
938
+ tools?: GraphToolDescription[];
901
939
  /**
902
940
  * Defaults for every node: a retry policy, timeouts, and an `onError`. A node's own options win,
903
941
  * field by field. `retry` here is the same as `compile({ retry })`, and wins over it.
@@ -1,5 +1,7 @@
1
1
  import type { CacheTtl, ReasoningEffort } from './providers.js';
2
2
  import type { AssetInput } from './images.js';
3
+ import type { Principal } from './principal.js';
4
+ import type { Store } from './store.js';
3
5
  declare global {
4
6
  namespace NodeJS {
5
7
  /**
@@ -128,8 +130,19 @@ export interface ToolDefinition {
128
130
  description: string;
129
131
  /** JSON Schema for the arguments. */
130
132
  parameters: Record<string, unknown>;
131
- /** Runs the tool, for the agent loop and executors that call tools automatically. */
132
- execute?: (args: Record<string, unknown>) => Promise<unknown>;
133
+ /**
134
+ * Runs the tool, for the agent loop and executors that call tools automatically. An agent passes
135
+ * a `ToolContext` too: who the run is for, its thread and tenant, its signal, and its store.
136
+ */
137
+ execute?: (args: Record<string, unknown>, context?: ToolContext) => Promise<unknown>;
138
+ /**
139
+ * What the tool does to the world, as capabilities a permission policy decides on:
140
+ * `filesystem:read` or `filesystem:write` with an optional path, `network` with an optional host,
141
+ * `shell` with an optional command, `code`, or a name of the application's own such as `payments`.
142
+ * A function computes them from each call's arguments, so a policy sees the path, host, or command
143
+ * the call actually uses. Never sent to a model.
144
+ */
145
+ capabilities?: readonly string[] | ((args: Record<string, unknown>) => readonly string[]);
133
146
  /**
134
147
  * Ends a cacheable prefix after this tool. Only honored when the request sets
135
148
  * `cache.mode: 'explicit'` and the provider accepts caller-placed breakpoints.
@@ -145,6 +158,27 @@ export interface ToolDefinition {
145
158
  export type ToolChoice = 'auto' | 'none' | 'required' | {
146
159
  name: string;
147
160
  };
161
+ /**
162
+ * What a tool receives besides its arguments when an agent runs it. Every field is optional: a tool
163
+ * run outside an agent, or by an executor given nothing, sees none of them.
164
+ */
165
+ export interface ToolContext {
166
+ /** The model's id for this call. */
167
+ toolCallId?: string;
168
+ /** The thread the run belongs to. */
169
+ threadId?: string;
170
+ /** The tenant the run is for. */
171
+ tenantId?: string;
172
+ /**
173
+ * Who the run is for: the caller the server authenticated, with their roles and scopes, so a
174
+ * tool can act as that user and nobody else.
175
+ */
176
+ principal?: Readonly<Principal>;
177
+ /** Aborted when the run is cancelled or the step times out. A tool that waits should stop with it. */
178
+ signal?: AbortSignal;
179
+ /** Long-term memory. In a tenant's run, the tenant's view of it. */
180
+ store?: Store;
181
+ }
148
182
  /** What a tool returned, correlated with the call that asked for it. */
149
183
  export interface ToolCallResult {
150
184
  /** The id of the call this answers. */
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Who a request, a run, or a tool call is for.
3
+ *
4
+ * One shape everywhere: the server's authentication hook returns it, a run carries it, graph nodes
5
+ * and workflow steps read it, tools and middleware receive it, and a permission policy can decide on
6
+ * it. Its tenant scopes threads, runs, budgets, and the store.
7
+ */
8
+ export interface Principal {
9
+ /** Isolates threads, runs, and cron jobs. Requests only ever see their own tenant's resources. */
10
+ tenantId?: string;
11
+ /** Who the caller is: a token's subject, a key's owner. Recorded on what they create. */
12
+ userId?: string;
13
+ /** What the caller may do. A route that names a scope refuses a principal without it. */
14
+ scopes?: readonly string[];
15
+ /** The caller's roles, for policies and tools that decide by role rather than by scope. */
16
+ roles?: readonly string[];
17
+ /** How the caller was authenticated: `jwt`, `api-key`, `proxy`, or a name of your own. */
18
+ method?: string;
19
+ /** The verified claims or attributes the principal was built from, for anything the fields above leave out. */
20
+ claims?: Readonly<Record<string, unknown>>;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -6,15 +6,9 @@
6
6
  * graph thread, so state, interrupts, and history come from the checkpointer; and an assistant is
7
7
  * anything that can stream events for an input, which a compiled graph already does.
8
8
  */
9
- /** Who is making a request, as the server's authentication hook reports them. */
10
- export interface Principal {
11
- /** Isolates threads, runs, and cron jobs. Requests only ever see their own tenant's resources. */
12
- tenantId?: string;
13
- /** Who the caller is, recorded on what they create. */
14
- userId?: string;
15
- /** What the caller may do. A route that names a scope refuses a principal without it. */
16
- scopes?: readonly string[];
17
- }
9
+ import type { Principal } from './principal.js';
10
+ import type { RunFeedback } from './tracing.js';
11
+ export type { Principal };
18
12
  /** Where a run stands, as the server reports it. */
19
13
  export type RunStatus = 'queued' | 'running' | 'awaiting_input' | 'succeeded' | 'failed' | 'cancelled' | 'expired';
20
14
  /** What happens when a run is requested for a thread that is already running one. */
@@ -82,6 +76,11 @@ export interface RunRecord {
82
76
  worker?: string;
83
77
  /** Its latest attempt, starting at 1. */
84
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[];
85
84
  }
86
85
  /** Why a run got the revision it did. */
87
86
  export type RevisionReason = 'split' | 'thread' | 'requested';
@@ -0,0 +1,4 @@
1
+ /** Base64 text as bytes, in a buffer of their own, so typed-array views of it are aligned. */
2
+ export declare function decodeBase64(data: string): Uint8Array;
3
+ /** Bytes as base64 text. */
4
+ export declare function encodeBase64(bytes: Uint8Array): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeBase64 = decodeBase64;
4
+ exports.encodeBase64 = encodeBase64;
5
+ const host = () => globalThis.Buffer;
6
+ function decodeBase64(data) {
7
+ const buffer = host();
8
+ if (buffer)
9
+ return new Uint8Array(buffer.from(data, 'base64'));
10
+ const binary = atob(data);
11
+ const bytes = new Uint8Array(binary.length);
12
+ for (let index = 0; index < binary.length; index += 1)
13
+ bytes[index] = binary.charCodeAt(index);
14
+ return bytes;
15
+ }
16
+ function encodeBase64(bytes) {
17
+ const buffer = host();
18
+ if (buffer)
19
+ return buffer.from(bytes).toString('base64');
20
+ let binary = '';
21
+ for (let index = 0; index < bytes.length; index += 0x8000) {
22
+ binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
23
+ }
24
+ return btoa(binary);
25
+ }
@@ -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 `ig​nore` read as `ignore`.
21
+ */
22
+ export declare function normalizeForDetection(text: string): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.luhn = luhn;
4
+ exports.ibanChecksum = ibanChecksum;
5
+ exports.phoneDigits = phoneDigits;
6
+ exports.phoneNumber = phoneNumber;
7
+ exports.normalizeForDetection = normalizeForDetection;
8
+ function luhn(value) {
9
+ const digits = value.replace(/[\s-]/g, '');
10
+ if (!/^\d{13,19}$/.test(digits))
11
+ return false;
12
+ let sum = 0;
13
+ for (let index = 0; index < digits.length; index += 1) {
14
+ let digit = Number(digits[digits.length - 1 - index]);
15
+ if (index % 2 === 1) {
16
+ digit *= 2;
17
+ if (digit > 9)
18
+ digit -= 9;
19
+ }
20
+ sum += digit;
21
+ }
22
+ return sum % 10 === 0;
23
+ }
24
+ function ibanChecksum(value) {
25
+ const iban = value.replace(/ /g, '').toUpperCase();
26
+ if (!/^[A-Z]{2}\d{2}[A-Z0-9]{11,30}$/.test(iban))
27
+ return false;
28
+ const rearranged = `${iban.slice(4)}${iban.slice(0, 4)}`;
29
+ let remainder = 0;
30
+ for (const char of rearranged) {
31
+ const code = /\d/.test(char) ? char : String(char.charCodeAt(0) - 55);
32
+ for (const digit of code)
33
+ remainder = (remainder * 10 + Number(digit)) % 97;
34
+ }
35
+ return remainder === 1;
36
+ }
37
+ function phoneDigits(value) {
38
+ const digits = value.replace(/\D/g, '').length;
39
+ return digits >= 10 && digits <= 15;
40
+ }
41
+ function phoneNumber(value) {
42
+ return phoneDigits(value) && (/^\s*\+/.test(value) || /\d[\s.()-]+\d/.test(value));
43
+ }
44
+ function normalizeForDetection(text) {
45
+ return text.normalize('NFKC').replace(/[­᠎​-‏‪-‮⁠-⁤]/g, '');
46
+ }
@@ -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;
@@ -1,7 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomHex = randomHex;
3
4
  exports.generateRequestId = generateRequestId;
4
- const node_crypto_1 = require("node:crypto");
5
+ exports.utf8Length = utf8Length;
6
+ function randomHex(bytes) {
7
+ const values = globalThis.crypto.getRandomValues(new Uint8Array(bytes));
8
+ let hex = '';
9
+ for (const value of values)
10
+ hex += HEX[value];
11
+ return hex;
12
+ }
5
13
  function generateRequestId() {
6
- return `req_${(0, node_crypto_1.randomBytes)(12).toString('hex')}`;
14
+ return `req_${randomHex(12)}`;
15
+ }
16
+ function utf8Length(text) {
17
+ let length = 0;
18
+ for (let index = 0; index < text.length; index += 1) {
19
+ const code = text.charCodeAt(index);
20
+ if (code < 0x80)
21
+ length += 1;
22
+ else if (code < 0x800)
23
+ length += 2;
24
+ else if (code >= 0xd800 && code <= 0xdbff && (text.charCodeAt(index + 1) & 0xfc00) === 0xdc00) {
25
+ length += 4;
26
+ index += 1;
27
+ }
28
+ else
29
+ length += 3;
30
+ }
31
+ return length;
7
32
  }
33
+ 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;