nexus-ai-pro 2.0.0 → 2.2.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 (282) hide show
  1. package/API_STABILITY.md +65 -0
  2. package/CHANGELOG.md +267 -1
  3. package/MIGRATING.md +1 -1
  4. package/README.md +17 -8
  5. package/dist/agent/create-agent.d.ts +9 -1
  6. package/dist/agent/create-agent.js +40 -1
  7. package/dist/cache/memory-cache.d.ts +8 -0
  8. package/dist/cache/memory-cache.js +9 -0
  9. package/dist/cache/semantic-cache.d.ts +6 -3
  10. package/dist/cache/semantic-cache.js +5 -2
  11. package/dist/cli/args.js +3 -0
  12. package/dist/cli/db.d.ts +16 -4
  13. package/dist/cli/db.js +169 -22
  14. package/dist/cli/doctor.d.ts +17 -0
  15. package/dist/cli/doctor.js +53 -0
  16. package/dist/cli/graph.d.ts +9 -0
  17. package/dist/cli/graph.js +47 -0
  18. package/dist/cli.js +21 -2
  19. package/dist/core/lifecycle.js +11 -6
  20. package/dist/core/nexus.d.ts +12 -2
  21. package/dist/core/nexus.js +106 -23
  22. package/dist/doctor/index.d.ts +90 -0
  23. package/dist/doctor/index.js +237 -0
  24. package/dist/evals/judge.d.ts +11 -0
  25. package/dist/evals/judge.js +33 -0
  26. package/dist/evaluate/index.d.ts +1 -0
  27. package/dist/evaluate/index.js +1 -0
  28. package/dist/evaluate/provenance.d.ts +22 -0
  29. package/dist/evaluate/provenance.js +10 -0
  30. package/dist/evaluate/run.js +20 -4
  31. package/dist/graph/durability.d.ts +27 -0
  32. package/dist/graph/durability.js +66 -0
  33. package/dist/graph/errors.d.ts +30 -4
  34. package/dist/graph/errors.js +18 -2
  35. package/dist/graph/event-stream.d.ts +75 -0
  36. package/dist/graph/event-stream.js +289 -0
  37. package/dist/graph/functional.d.ts +80 -7
  38. package/dist/graph/functional.js +138 -35
  39. package/dist/graph/graph.d.ts +56 -8
  40. package/dist/graph/graph.js +331 -49
  41. package/dist/graph/index.d.ts +4 -2
  42. package/dist/graph/index.js +3 -1
  43. package/dist/graph/lint.d.ts +57 -0
  44. package/dist/graph/lint.js +141 -0
  45. package/dist/graph/run-control.d.ts +28 -0
  46. package/dist/graph/run-control.js +26 -0
  47. package/dist/images/evals.js +4 -2
  48. package/dist/operations/adapters.d.ts +52 -4
  49. package/dist/operations/adapters.js +194 -7
  50. package/dist/operations/runner.js +14 -15
  51. package/dist/operations/stats.js +8 -1
  52. package/dist/operations/store.d.ts +5 -1
  53. package/dist/operations/store.js +7 -0
  54. package/dist/ops/circuit-breaker.d.ts +52 -0
  55. package/dist/ops/circuit-breaker.js +4 -0
  56. package/dist/ops/circuit-store.d.ts +13 -2
  57. package/dist/ops/circuit-store.js +68 -0
  58. package/dist/ops/circuit-sync.d.ts +17 -0
  59. package/dist/ops/circuit-sync.js +86 -0
  60. package/dist/ops/health.d.ts +24 -0
  61. package/dist/ops/health.js +38 -10
  62. package/dist/ops/index.d.ts +1 -1
  63. package/dist/ops/index.js +1 -1
  64. package/dist/ops/rate-limit-adapters.d.ts +23 -0
  65. package/dist/ops/rate-limit-adapters.js +34 -0
  66. package/dist/ops/rate-limiter.d.ts +14 -2
  67. package/dist/ops/rate-limiter.js +31 -0
  68. package/dist/postgres/circuits.d.ts +21 -4
  69. package/dist/postgres/circuits.js +65 -4
  70. package/dist/postgres/client.d.ts +0 -2
  71. package/dist/postgres/client.js +0 -4
  72. package/dist/postgres/evaluate.d.ts +16 -4
  73. package/dist/postgres/evaluate.js +17 -5
  74. package/dist/postgres/index.d.ts +32 -11
  75. package/dist/postgres/index.js +65 -31
  76. package/dist/postgres/migrations.d.ts +60 -0
  77. package/dist/postgres/migrations.js +121 -0
  78. package/dist/postgres/operations.d.ts +14 -3
  79. package/dist/postgres/operations.js +45 -15
  80. package/dist/postgres/prompts.d.ts +11 -2
  81. package/dist/postgres/prompts.js +14 -3
  82. package/dist/postgres/rollups.d.ts +35 -0
  83. package/dist/postgres/rollups.js +129 -0
  84. package/dist/postgres/store.d.ts +11 -2
  85. package/dist/postgres/store.js +14 -3
  86. package/dist/postgres/traces.d.ts +13 -3
  87. package/dist/postgres/traces.js +25 -3
  88. package/dist/postgres/vectors.d.ts +11 -2
  89. package/dist/postgres/vectors.js +14 -3
  90. package/dist/router/auto-router.d.ts +34 -7
  91. package/dist/router/auto-router.js +201 -68
  92. package/dist/server/assistant.d.ts +44 -0
  93. package/dist/server/assistant.js +39 -0
  94. package/dist/server/errors.d.ts +12 -0
  95. package/dist/server/errors.js +7 -0
  96. package/dist/server/index.d.ts +1 -1
  97. package/dist/server/index.js +1 -1
  98. package/dist/server/runs.d.ts +28 -1
  99. package/dist/server/runs.js +110 -14
  100. package/dist/sqlite/index.d.ts +16 -3
  101. package/dist/sqlite/index.js +16 -3
  102. package/dist/sqlite/migrations.d.ts +26 -0
  103. package/dist/sqlite/migrations.js +63 -0
  104. package/dist/sqlite/operations.d.ts +14 -3
  105. package/dist/sqlite/operations.js +42 -15
  106. package/dist/sqlite/store.d.ts +9 -2
  107. package/dist/sqlite/store.js +13 -3
  108. package/dist/sqlite/vectors.d.ts +11 -2
  109. package/dist/sqlite/vectors.js +13 -2
  110. package/dist/store/tenant.d.ts +12 -0
  111. package/dist/store/tenant.js +29 -0
  112. package/dist/tenancy/index.d.ts +113 -0
  113. package/dist/tenancy/index.js +233 -0
  114. package/dist/testing/record.d.ts +42 -0
  115. package/dist/testing/record.js +57 -5
  116. package/dist/tracing/index.d.ts +3 -3
  117. package/dist/tracing/index.js +2 -2
  118. package/dist/tracing/instrument.js +30 -0
  119. package/dist/tracing/otlp.d.ts +91 -0
  120. package/dist/tracing/otlp.js +124 -0
  121. package/dist/tracing/rollups.d.ts +100 -0
  122. package/dist/tracing/rollups.js +139 -0
  123. package/dist/tracing/stores.d.ts +17 -0
  124. package/dist/tracing/stores.js +23 -0
  125. package/dist/tracing/tracer.d.ts +50 -4
  126. package/dist/tracing/tracer.js +85 -6
  127. package/dist/types/config.d.ts +33 -2
  128. package/dist/types/evaluate.d.ts +37 -0
  129. package/dist/types/graph.d.ts +354 -9
  130. package/dist/types/graph.js +3 -1
  131. package/dist/types/messages.d.ts +5 -0
  132. package/dist/types/operations.d.ts +22 -2
  133. package/dist/types/response.d.ts +20 -0
  134. package/dist/types/server.d.ts +18 -0
  135. package/dist/types/tracing.d.ts +11 -0
  136. package/dist/utils/schema-migrations.d.ts +97 -0
  137. package/dist/utils/schema-migrations.js +91 -0
  138. package/dist/utils/signals.d.ts +17 -0
  139. package/dist/utils/signals.js +26 -0
  140. package/dist/utils/tenant.d.ts +14 -0
  141. package/dist/utils/tenant.js +16 -0
  142. package/dist/version.d.ts +5 -0
  143. package/dist/version.js +1 -0
  144. package/dist-cjs/agent/create-agent.d.ts +9 -1
  145. package/dist-cjs/agent/create-agent.js +40 -1
  146. package/dist-cjs/cache/memory-cache.d.ts +8 -0
  147. package/dist-cjs/cache/memory-cache.js +9 -0
  148. package/dist-cjs/cache/semantic-cache.d.ts +6 -3
  149. package/dist-cjs/cache/semantic-cache.js +5 -2
  150. package/dist-cjs/cli/args.js +3 -0
  151. package/dist-cjs/cli/db.d.ts +16 -4
  152. package/dist-cjs/cli/db.js +200 -20
  153. package/dist-cjs/cli/doctor.d.ts +17 -0
  154. package/dist-cjs/cli/doctor.js +56 -0
  155. package/dist-cjs/cli/graph.d.ts +9 -0
  156. package/dist-cjs/cli/graph.js +50 -0
  157. package/dist-cjs/core/lifecycle.js +11 -6
  158. package/dist-cjs/core/nexus.d.ts +12 -2
  159. package/dist-cjs/core/nexus.js +106 -23
  160. package/dist-cjs/doctor/index.d.ts +90 -0
  161. package/dist-cjs/doctor/index.js +276 -0
  162. package/dist-cjs/evals/judge.d.ts +11 -0
  163. package/dist-cjs/evals/judge.js +33 -0
  164. package/dist-cjs/evaluate/index.d.ts +1 -0
  165. package/dist-cjs/evaluate/index.js +3 -1
  166. package/dist-cjs/evaluate/provenance.d.ts +22 -0
  167. package/dist-cjs/evaluate/provenance.js +14 -0
  168. package/dist-cjs/evaluate/run.js +20 -4
  169. package/dist-cjs/graph/durability.d.ts +27 -0
  170. package/dist-cjs/graph/durability.js +70 -0
  171. package/dist-cjs/graph/errors.d.ts +30 -4
  172. package/dist-cjs/graph/errors.js +20 -3
  173. package/dist-cjs/graph/event-stream.d.ts +75 -0
  174. package/dist-cjs/graph/event-stream.js +295 -0
  175. package/dist-cjs/graph/functional.d.ts +80 -7
  176. package/dist-cjs/graph/functional.js +137 -34
  177. package/dist-cjs/graph/graph.d.ts +56 -8
  178. package/dist-cjs/graph/graph.js +330 -48
  179. package/dist-cjs/graph/index.d.ts +4 -2
  180. package/dist-cjs/graph/index.js +7 -1
  181. package/dist-cjs/graph/lint.d.ts +57 -0
  182. package/dist-cjs/graph/lint.js +144 -0
  183. package/dist-cjs/graph/run-control.d.ts +28 -0
  184. package/dist-cjs/graph/run-control.js +30 -0
  185. package/dist-cjs/images/evals.js +4 -2
  186. package/dist-cjs/operations/adapters.d.ts +52 -4
  187. package/dist-cjs/operations/adapters.js +193 -6
  188. package/dist-cjs/operations/runner.js +14 -15
  189. package/dist-cjs/operations/stats.js +8 -1
  190. package/dist-cjs/operations/store.d.ts +5 -1
  191. package/dist-cjs/operations/store.js +7 -0
  192. package/dist-cjs/ops/circuit-breaker.d.ts +52 -0
  193. package/dist-cjs/ops/circuit-breaker.js +4 -0
  194. package/dist-cjs/ops/circuit-store.d.ts +13 -2
  195. package/dist-cjs/ops/circuit-store.js +68 -0
  196. package/dist-cjs/ops/circuit-sync.d.ts +17 -0
  197. package/dist-cjs/ops/circuit-sync.js +87 -0
  198. package/dist-cjs/ops/health.d.ts +24 -0
  199. package/dist-cjs/ops/health.js +38 -10
  200. package/dist-cjs/ops/index.d.ts +1 -1
  201. package/dist-cjs/ops/rate-limit-adapters.d.ts +23 -0
  202. package/dist-cjs/ops/rate-limit-adapters.js +35 -1
  203. package/dist-cjs/ops/rate-limiter.d.ts +14 -2
  204. package/dist-cjs/ops/rate-limiter.js +32 -0
  205. package/dist-cjs/postgres/circuits.d.ts +21 -4
  206. package/dist-cjs/postgres/circuits.js +98 -3
  207. package/dist-cjs/postgres/client.d.ts +0 -2
  208. package/dist-cjs/postgres/client.js +0 -5
  209. package/dist-cjs/postgres/evaluate.d.ts +16 -4
  210. package/dist-cjs/postgres/evaluate.js +50 -4
  211. package/dist-cjs/postgres/index.d.ts +32 -11
  212. package/dist-cjs/postgres/index.js +69 -20
  213. package/dist-cjs/postgres/migrations.d.ts +60 -0
  214. package/dist-cjs/postgres/migrations.js +129 -0
  215. package/dist-cjs/postgres/operations.d.ts +14 -3
  216. package/dist-cjs/postgres/operations.js +78 -14
  217. package/dist-cjs/postgres/prompts.d.ts +11 -2
  218. package/dist-cjs/postgres/prompts.js +47 -2
  219. package/dist-cjs/postgres/rollups.d.ts +35 -0
  220. package/dist-cjs/postgres/rollups.js +168 -0
  221. package/dist-cjs/postgres/store.d.ts +11 -2
  222. package/dist-cjs/postgres/store.js +47 -2
  223. package/dist-cjs/postgres/traces.d.ts +13 -3
  224. package/dist-cjs/postgres/traces.js +58 -2
  225. package/dist-cjs/postgres/vectors.d.ts +11 -2
  226. package/dist-cjs/postgres/vectors.js +47 -2
  227. package/dist-cjs/router/auto-router.d.ts +34 -7
  228. package/dist-cjs/router/auto-router.js +201 -68
  229. package/dist-cjs/server/assistant.d.ts +44 -0
  230. package/dist-cjs/server/assistant.js +39 -0
  231. package/dist-cjs/server/errors.d.ts +12 -0
  232. package/dist-cjs/server/errors.js +9 -1
  233. package/dist-cjs/server/index.d.ts +1 -1
  234. package/dist-cjs/server/index.js +2 -1
  235. package/dist-cjs/server/runs.d.ts +28 -1
  236. package/dist-cjs/server/runs.js +109 -13
  237. package/dist-cjs/sqlite/index.d.ts +16 -3
  238. package/dist-cjs/sqlite/index.js +31 -10
  239. package/dist-cjs/sqlite/migrations.d.ts +26 -0
  240. package/dist-cjs/sqlite/migrations.js +71 -0
  241. package/dist-cjs/sqlite/operations.d.ts +14 -3
  242. package/dist-cjs/sqlite/operations.js +76 -15
  243. package/dist-cjs/sqlite/store.d.ts +9 -2
  244. package/dist-cjs/sqlite/store.js +47 -3
  245. package/dist-cjs/sqlite/vectors.d.ts +11 -2
  246. package/dist-cjs/sqlite/vectors.js +47 -2
  247. package/dist-cjs/store/tenant.d.ts +12 -0
  248. package/dist-cjs/store/tenant.js +33 -0
  249. package/dist-cjs/tenancy/index.d.ts +113 -0
  250. package/dist-cjs/tenancy/index.js +250 -0
  251. package/dist-cjs/testing/record.d.ts +42 -0
  252. package/dist-cjs/testing/record.js +57 -5
  253. package/dist-cjs/tracing/index.d.ts +3 -3
  254. package/dist-cjs/tracing/index.js +4 -1
  255. package/dist-cjs/tracing/instrument.js +30 -0
  256. package/dist-cjs/tracing/otlp.d.ts +91 -0
  257. package/dist-cjs/tracing/otlp.js +129 -0
  258. package/dist-cjs/tracing/rollups.d.ts +100 -0
  259. package/dist-cjs/tracing/rollups.js +147 -0
  260. package/dist-cjs/tracing/stores.d.ts +17 -0
  261. package/dist-cjs/tracing/stores.js +24 -0
  262. package/dist-cjs/tracing/tracer.d.ts +50 -4
  263. package/dist-cjs/tracing/tracer.js +87 -6
  264. package/dist-cjs/types/config.d.ts +33 -2
  265. package/dist-cjs/types/evaluate.d.ts +37 -0
  266. package/dist-cjs/types/graph.d.ts +354 -9
  267. package/dist-cjs/types/graph.js +3 -1
  268. package/dist-cjs/types/messages.d.ts +5 -0
  269. package/dist-cjs/types/operations.d.ts +22 -2
  270. package/dist-cjs/types/response.d.ts +20 -0
  271. package/dist-cjs/types/server.d.ts +18 -0
  272. package/dist-cjs/types/tracing.d.ts +11 -0
  273. package/dist-cjs/utils/schema-migrations.d.ts +97 -0
  274. package/dist-cjs/utils/schema-migrations.js +102 -0
  275. package/dist-cjs/utils/signals.d.ts +17 -0
  276. package/dist-cjs/utils/signals.js +29 -0
  277. package/dist-cjs/utils/tenant.d.ts +14 -0
  278. package/dist-cjs/utils/tenant.js +22 -0
  279. package/dist-cjs/version.d.ts +5 -0
  280. package/dist-cjs/version.js +4 -0
  281. package/llms.txt +4 -3
  282. package/package.json +110 -2
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Versioned schema migrations, shared by the Postgres and SQLite adapters.
3
+ *
4
+ * Each adapter's tables form a component, such as `operations:nexus_operations`, with numbered
5
+ * migrations. The database records which ran, with a checksum of their statements, so an upgrade
6
+ * applies only what is new and an edited migration is refused instead of silently ignored.
7
+ */
8
+ /** One numbered schema change to one adapter's tables. */
9
+ export interface SchemaMigration {
10
+ /**
11
+ * The tables it belongs to, such as `operations:nexus_operations`. Versions count per component,
12
+ * so two operation stores on two tables migrate independently.
13
+ */
14
+ component: string;
15
+ /** Its number, from 1, in the order it applies. */
16
+ version: number;
17
+ /** What it does, in a few words. */
18
+ name: string;
19
+ /**
20
+ * Its statements, in order. Every bundled statement is idempotent (`IF NOT EXISTS`), so a migration
21
+ * interrupted between statements on a database without transactional DDL runs again safely.
22
+ */
23
+ statements: readonly string[];
24
+ }
25
+ /** A migration the database has recorded as applied. */
26
+ export interface AppliedMigration {
27
+ /** Its component. */
28
+ component: string;
29
+ /** Its version. */
30
+ version: number;
31
+ /** Its name when it ran. */
32
+ name: string;
33
+ /** The checksum of its statements when it ran. */
34
+ checksum: string;
35
+ /** ISO-8601 time it was applied. */
36
+ appliedAt: string;
37
+ }
38
+ /** Where a database stands against the migrations this code knows. */
39
+ export interface MigrationStatus {
40
+ /** Recorded migrations, oldest first. */
41
+ applied: AppliedMigration[];
42
+ /** Known migrations not yet applied, in the order `migrate()` would apply them. */
43
+ pending: SchemaMigration[];
44
+ /**
45
+ * Applied migrations whose statements have changed since: an edited migration, or adapter options,
46
+ * such as a vector width, that differ from those it ran with. `migrate()` refuses to run while any
47
+ * remain.
48
+ */
49
+ changed: Array<{
50
+ migration: SchemaMigration;
51
+ applied: AppliedMigration;
52
+ }>;
53
+ /**
54
+ * Recorded migrations this code does not know, written by a newer release. Expected while a rollout
55
+ * runs two versions side by side, since every migration only adds.
56
+ */
57
+ unknown: AppliedMigration[];
58
+ /** True when nothing is pending or changed. */
59
+ current: boolean;
60
+ }
61
+ /** What one `migrate()` call did, or with `dryRun`, would do. */
62
+ export interface MigrationResult {
63
+ /** Migrations applied, or with `dryRun`, pending. */
64
+ applied: SchemaMigration[];
65
+ /** The statements run, or with `dryRun`, that would run, in order. */
66
+ statements: string[];
67
+ /** Whether nothing was written. */
68
+ dryRun: boolean;
69
+ }
70
+ /** Raised when migrations cannot run safely: a changed migration, a bad list, or a lock held too long. */
71
+ export declare class SchemaMigrationError extends Error {
72
+ /** A stable code: `MIGRATION_CHANGED`, `MIGRATION_INVALID`, or `MIGRATION_LOCKED`. */
73
+ readonly code: 'MIGRATION_CHANGED' | 'MIGRATION_INVALID' | 'MIGRATION_LOCKED';
74
+ constructor(code: SchemaMigrationError['code'], message: string);
75
+ }
76
+ /** The default table that records applied migrations. */
77
+ export declare const MIGRATIONS_TABLE = "nexus_schema_migrations";
78
+ /**
79
+ * A checksum of a migration's statements: cyrb53, a fast 53-bit hash, as 14 hex digits.
80
+ *
81
+ * It detects a migration edited after it ran; it is not a security boundary, so it needs no crypto
82
+ * module and runs anywhere a driver does. Line endings are normalized, so a checkout on Windows
83
+ * computes the same value as one on Linux.
84
+ */
85
+ export declare function migrationChecksum(migration: Pick<SchemaMigration, 'statements'>): string;
86
+ /** @internal Refuses a list with a gap, a duplicate, or an empty migration, before anything runs. */
87
+ export declare function validateMigrations(migrations: readonly SchemaMigration[]): void;
88
+ /** @internal Compares known migrations with recorded ones. */
89
+ export declare function planMigrations(known: readonly SchemaMigration[], applied: readonly AppliedMigration[]): MigrationStatus;
90
+ /** @internal Refuses to migrate while an applied migration has changed. */
91
+ export declare function assertUnchanged(status: MigrationStatus): void;
92
+ /** @internal A SQL string literal. Values here are component names and checksums, never user input. */
93
+ export declare function sqlLiteral(value: string): string;
94
+ /** @internal */
95
+ export declare function label(migration: Pick<SchemaMigration, 'component' | 'version' | 'name'>): string;
96
+ /** @internal Waits, for lock polling. */
97
+ export declare function delay(ms: number): Promise<void>;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIGRATIONS_TABLE = exports.SchemaMigrationError = void 0;
4
+ exports.migrationChecksum = migrationChecksum;
5
+ exports.validateMigrations = validateMigrations;
6
+ exports.planMigrations = planMigrations;
7
+ exports.assertUnchanged = assertUnchanged;
8
+ exports.sqlLiteral = sqlLiteral;
9
+ exports.label = label;
10
+ exports.delay = delay;
11
+ class SchemaMigrationError extends Error {
12
+ code;
13
+ constructor(code, message) {
14
+ super(message);
15
+ this.name = 'SchemaMigrationError';
16
+ this.code = code;
17
+ }
18
+ }
19
+ exports.SchemaMigrationError = SchemaMigrationError;
20
+ exports.MIGRATIONS_TABLE = 'nexus_schema_migrations';
21
+ function migrationChecksum(migration) {
22
+ const text = migration.statements.map((statement) => statement.replace(/\r\n/g, '\n').trim()).join('\n;\n');
23
+ let h1 = 0xdeadbeef;
24
+ let h2 = 0x41c6ce57;
25
+ for (let index = 0; index < text.length; index += 1) {
26
+ const code = text.charCodeAt(index);
27
+ h1 = Math.imul(h1 ^ code, 2654435761);
28
+ h2 = Math.imul(h2 ^ code, 1597334677);
29
+ }
30
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
31
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
32
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16).padStart(14, '0');
33
+ }
34
+ function validateMigrations(migrations) {
35
+ const versions = new Map();
36
+ for (const migration of migrations) {
37
+ if (!migration.component)
38
+ throw new SchemaMigrationError('MIGRATION_INVALID', 'A migration has no component');
39
+ if (!Number.isInteger(migration.version) || migration.version < 1) {
40
+ throw new SchemaMigrationError('MIGRATION_INVALID', `${migration.component} has version ${migration.version}; versions are integers from 1`);
41
+ }
42
+ if (migration.statements.length === 0) {
43
+ throw new SchemaMigrationError('MIGRATION_INVALID', `${label(migration)} has no statements`);
44
+ }
45
+ const list = versions.get(migration.component) ?? [];
46
+ if (list.includes(migration.version)) {
47
+ throw new SchemaMigrationError('MIGRATION_INVALID', `${label(migration)} is listed twice`);
48
+ }
49
+ list.push(migration.version);
50
+ versions.set(migration.component, list);
51
+ }
52
+ for (const [component, list] of versions) {
53
+ const sorted = [...list].sort((a, b) => a - b);
54
+ sorted.forEach((version, index) => {
55
+ if (version !== index + 1) {
56
+ throw new SchemaMigrationError('MIGRATION_INVALID', `${component} skips version ${index + 1}`);
57
+ }
58
+ });
59
+ }
60
+ }
61
+ function planMigrations(known, applied) {
62
+ validateMigrations(known);
63
+ const recorded = new Map(applied.map((row) => [`${row.component}@${row.version}`, row]));
64
+ const knownKeys = new Set(known.map((migration) => `${migration.component}@${migration.version}`));
65
+ const pending = [];
66
+ const changed = [];
67
+ for (const migration of known) {
68
+ const row = recorded.get(`${migration.component}@${migration.version}`);
69
+ if (!row)
70
+ pending.push(migration);
71
+ else if (row.checksum !== migrationChecksum(migration))
72
+ changed.push({ migration, applied: row });
73
+ }
74
+ const order = new Map();
75
+ for (const migration of known)
76
+ if (!order.has(migration.component))
77
+ order.set(migration.component, order.size);
78
+ pending.sort((a, b) => order.get(a.component) - order.get(b.component) || a.version - b.version);
79
+ const sortedApplied = [...applied].sort((a, b) => a.appliedAt.localeCompare(b.appliedAt) || a.component.localeCompare(b.component) || a.version - b.version);
80
+ return {
81
+ applied: sortedApplied,
82
+ pending,
83
+ changed,
84
+ unknown: sortedApplied.filter((row) => !knownKeys.has(`${row.component}@${row.version}`)),
85
+ current: pending.length === 0 && changed.length === 0,
86
+ };
87
+ }
88
+ function assertUnchanged(status) {
89
+ if (status.changed.length === 0)
90
+ return;
91
+ const names = status.changed.map(({ migration }) => label(migration)).join(', ');
92
+ throw new SchemaMigrationError('MIGRATION_CHANGED', `${names} changed after it was applied. A migration is never edited once it runs; add a new one, or check the adapter options (a table or vector width) match those it ran with.`);
93
+ }
94
+ function sqlLiteral(value) {
95
+ return `'${value.replace(/'/g, "''")}'`;
96
+ }
97
+ function label(migration) {
98
+ return `${migration.component} v${migration.version} (${migration.name})`;
99
+ }
100
+ function delay(ms) {
101
+ return new Promise((resolve) => setTimeout(resolve, ms));
102
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A signal that aborts when any of its sources does, and can be let go of.
3
+ *
4
+ * `AbortSignal.any()` cannot be undone: in Node 22 a source signal keeps a reference for every signal
5
+ * ever composed from it, about half a kilobyte each, for as long as the source lives. A graph composes
6
+ * one per task attempt from the run's signal, so a long-lived signal shared by many runs — a server's,
7
+ * a worker's — grew without bound. A linked signal listens to its sources directly and `dispose()`
8
+ * removes the listeners, so a finished attempt keeps nothing.
9
+ */
10
+ export interface LinkedSignal {
11
+ /** Aborts, with that source's reason, when any source aborts. */
12
+ readonly signal: AbortSignal;
13
+ /** Stops listening to the sources. Safe to call more than once. */
14
+ dispose(): void;
15
+ }
16
+ /** Links the given signals; missing ones are ignored, and one signal is returned as it is. */
17
+ export declare function linkSignals(sources: ReadonlyArray<AbortSignal | undefined>): LinkedSignal;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.linkSignals = linkSignals;
4
+ const NOTHING_TO_DISPOSE = () => undefined;
5
+ function linkSignals(sources) {
6
+ const present = sources.filter((source) => source !== undefined);
7
+ if (present.length === 1)
8
+ return { signal: present[0], dispose: NOTHING_TO_DISPOSE };
9
+ const controller = new AbortController();
10
+ const aborted = present.find((source) => source.aborted);
11
+ if (aborted) {
12
+ controller.abort(aborted.reason);
13
+ return { signal: controller.signal, dispose: NOTHING_TO_DISPOSE };
14
+ }
15
+ const listeners = [];
16
+ const dispose = () => {
17
+ for (const [source, listener] of listeners.splice(0))
18
+ source.removeEventListener('abort', listener);
19
+ };
20
+ for (const source of present) {
21
+ const listener = () => {
22
+ controller.abort(source.reason);
23
+ dispose();
24
+ };
25
+ source.addEventListener('abort', listener, { once: true });
26
+ listeners.push([source, listener]);
27
+ }
28
+ return { signal: controller.signal, dispose };
29
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The tenant id rule every scope shares. An id is letters, digits, `_`, and `-`, so it can never hold
3
+ * the `/` a scoped name or key is built with: no tenant's prefix is a prefix of another's.
4
+ */
5
+ /** Refused when a tenant id is empty, too long, or holds a character a scoped key could be split on. */
6
+ export declare class TenantIdError extends RangeError {
7
+ /** Always `TENANT_ID_INVALID`. */
8
+ readonly code = "TENANT_ID_INVALID";
9
+ constructor(tenantId: unknown);
10
+ }
11
+ /** Returns a tenant id unchanged, or throws `TenantIdError` when it is not one. */
12
+ export declare function assertTenantId(tenantId: string): string;
13
+ /** @internal The prefix a tenant's names and keys carry in a shared store. */
14
+ export declare function tenantPrefix(tenantId: string): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TenantIdError = void 0;
4
+ exports.assertTenantId = assertTenantId;
5
+ exports.tenantPrefix = tenantPrefix;
6
+ class TenantIdError extends RangeError {
7
+ code = 'TENANT_ID_INVALID';
8
+ constructor(tenantId) {
9
+ super(`"${String(tenantId)}" is not a valid tenant id: use 1 to 128 letters, digits, underscores, and hyphens`);
10
+ this.name = 'TenantIdError';
11
+ }
12
+ }
13
+ exports.TenantIdError = TenantIdError;
14
+ const TENANT_ID = /^[A-Za-z0-9_-]{1,128}$/;
15
+ function assertTenantId(tenantId) {
16
+ if (typeof tenantId !== 'string' || !TENANT_ID.test(tenantId))
17
+ throw new TenantIdError(tenantId);
18
+ return tenantId;
19
+ }
20
+ function tenantPrefix(tenantId) {
21
+ return `tenant/${assertTenantId(tenantId)}/`;
22
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This package's version, recorded where provenance matters, such as on every experiment. A test
3
+ * keeps it equal to `package.json`.
4
+ */
5
+ export declare const NEXUS_VERSION = "2.2.0";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NEXUS_VERSION = void 0;
4
+ exports.NEXUS_VERSION = '2.2.0';
package/llms.txt CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  > The typed AI framework for TypeScript. One API for provider routing and failover, agent graphs and workflows that run branches in parallel and survive a restart, retrieval over any vector store, MCP, durable background operations, guardrails, cost control, images, voice, and evals — with a studio a team can share.
4
4
 
5
- Import only what you use. The root import is the client and nothing else, and every other capability has its own entry point with a size budget CI enforces; [the packaging guide](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/packaging.md) publishes what each one costs. The package has no required dependencies: a graph-only application loads 51 KB, and installs nothing but this package.
5
+ Import only what you use. The root import is the client and nothing else, and every other capability has its own entry point with a size budget CI enforces; [the packaging guide](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/packaging.md) publishes what each one costs. The package has no required dependencies: a graph-only application loads 78 KB, and installs nothing but this package.
6
6
 
7
7
  - Install with `npm install nexus-ai-pro`. It needs Node.js 22 or newer, and ships ESM and CommonJS builds with shared types. License: MIT.
8
- - It has 135 entry points. `nexus-ai-pro` itself is the client, and every other capability has its own subpath, such as `nexus-ai-pro/graph`.
8
+ - It has 143 entry points. `nexus-ai-pro` itself is the client, and every other capability has its own subpath, such as `nexus-ai-pro/graph`.
9
9
  - Nothing is a required dependency. Install only the optional peers you use: `@anthropic-ai/sdk`, `@types/node`, `ajv`, `ajv-formats`, `ollama`, `openai`, `zod`.
10
10
  - Each guide explains every export of its entry points, then lists them in a reference generated from the doc comments.
11
11
 
@@ -42,6 +42,7 @@ Import only what you use. The root import is the client and nothing else, and ev
42
42
  - [Studio](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/studio.md): A shared UI for traces, threads, approvals, experiments, prompts, deployments, costs, and health, as a separate package
43
43
  - [Agent server](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/server.md): Self-hosted HTTP server for assistants: threads, durable runs, resumable streams, cron, a worker queue, and metrics
44
44
  - [Deployments](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/deployments.md): Revisions and canaries with automatic rollback, autoscaling on Kubernetes and Helm, and per-tenant limits
45
+ - [Tenancy](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/tenancy.md): One tenant model: a tenant's view of every store, tenant graph runs, and the isolation suite
45
46
  - [Workflows](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/workflows.md): Ready-made chains and domain workflows
46
47
  - [Command line](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/cli.md): The `nexus` command
47
48
  - [Packaging and install weight](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/docs/packaging.md): Every entry point and what it costs
@@ -57,5 +58,5 @@ Import only what you use. The root import is the client and nothing else, and ev
57
58
  ## Optional
58
59
 
59
60
  - [Full documentation](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/llms-full.txt): The README and every guide in one file, for a tool that takes one document
60
- - [Roadmap](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/ROADMAP.md): Delivered work and what is planned next
61
+ - [Roadmap](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/ROADMAP.md): The releases planned next, and the gaps each one closes
61
62
  - [Contributing](https://raw.githubusercontent.com/mkhitar-abrahamyan/nexus-ai/main/CONTRIBUTING.md): Testing and the release procedure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-ai-pro",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Typed AI framework for TypeScript: provider routing and failover, durable agent graphs and workflows, retrieval over any vector store, MCP, evals, guardrails, and cost control",
5
5
  "type": "module",
6
6
  "main": "dist-cjs/index.js",
@@ -500,6 +500,16 @@
500
500
  "default": "./dist-cjs/sqlite/vectors.js"
501
501
  }
502
502
  },
503
+ "./sqlite/migrations": {
504
+ "import": {
505
+ "types": "./dist/sqlite/migrations.d.ts",
506
+ "default": "./dist/sqlite/migrations.js"
507
+ },
508
+ "require": {
509
+ "types": "./dist-cjs/sqlite/migrations.d.ts",
510
+ "default": "./dist-cjs/sqlite/migrations.js"
511
+ }
512
+ },
503
513
  "./graph/visualize": {
504
514
  "import": {
505
515
  "types": "./dist/graph/visualize.d.ts",
@@ -510,6 +520,16 @@
510
520
  "default": "./dist-cjs/graph/visualize.js"
511
521
  }
512
522
  },
523
+ "./graph/lint": {
524
+ "import": {
525
+ "types": "./dist/graph/lint.d.ts",
526
+ "default": "./dist/graph/lint.js"
527
+ },
528
+ "require": {
529
+ "types": "./dist-cjs/graph/lint.d.ts",
530
+ "default": "./dist-cjs/graph/lint.js"
531
+ }
532
+ },
513
533
  "./agent": {
514
534
  "import": {
515
535
  "types": "./dist/agent/index.d.ts",
@@ -570,6 +590,26 @@
570
590
  "default": "./dist-cjs/tracing/index.js"
571
591
  }
572
592
  },
593
+ "./tracing/otlp": {
594
+ "import": {
595
+ "types": "./dist/tracing/otlp.d.ts",
596
+ "default": "./dist/tracing/otlp.js"
597
+ },
598
+ "require": {
599
+ "types": "./dist-cjs/tracing/otlp.d.ts",
600
+ "default": "./dist-cjs/tracing/otlp.js"
601
+ }
602
+ },
603
+ "./tracing/rollups": {
604
+ "import": {
605
+ "types": "./dist/tracing/rollups.d.ts",
606
+ "default": "./dist/tracing/rollups.js"
607
+ },
608
+ "require": {
609
+ "types": "./dist-cjs/tracing/rollups.d.ts",
610
+ "default": "./dist-cjs/tracing/rollups.js"
611
+ }
612
+ },
573
613
  "./evaluate": {
574
614
  "import": {
575
615
  "types": "./dist/evaluate/index.d.ts",
@@ -650,6 +690,26 @@
650
690
  "default": "./dist-cjs/postgres/evaluate.js"
651
691
  }
652
692
  },
693
+ "./postgres/migrations": {
694
+ "import": {
695
+ "types": "./dist/postgres/migrations.d.ts",
696
+ "default": "./dist/postgres/migrations.js"
697
+ },
698
+ "require": {
699
+ "types": "./dist-cjs/postgres/migrations.d.ts",
700
+ "default": "./dist-cjs/postgres/migrations.js"
701
+ }
702
+ },
703
+ "./postgres/rollups": {
704
+ "import": {
705
+ "types": "./dist/postgres/rollups.d.ts",
706
+ "default": "./dist/postgres/rollups.js"
707
+ },
708
+ "require": {
709
+ "types": "./dist-cjs/postgres/rollups.d.ts",
710
+ "default": "./dist-cjs/postgres/rollups.js"
711
+ }
712
+ },
653
713
  "./optimizer/cost": {
654
714
  "import": {
655
715
  "types": "./dist/optimizer/cost.d.ts",
@@ -780,6 +840,26 @@
780
840
  "default": "./dist-cjs/server/tenancy.js"
781
841
  }
782
842
  },
843
+ "./tenancy": {
844
+ "import": {
845
+ "types": "./dist/tenancy/index.d.ts",
846
+ "default": "./dist/tenancy/index.js"
847
+ },
848
+ "require": {
849
+ "types": "./dist-cjs/tenancy/index.d.ts",
850
+ "default": "./dist-cjs/tenancy/index.js"
851
+ }
852
+ },
853
+ "./doctor": {
854
+ "import": {
855
+ "types": "./dist/doctor/index.d.ts",
856
+ "default": "./dist/doctor/index.js"
857
+ },
858
+ "require": {
859
+ "types": "./dist-cjs/doctor/index.d.ts",
860
+ "default": "./dist-cjs/doctor/index.js"
861
+ }
862
+ },
783
863
  "./prompts": {
784
864
  "import": {
785
865
  "types": "./dist/prompts/index.d.ts",
@@ -1408,9 +1488,10 @@
1408
1488
  "test:conformance:real": "tsx tests/conformance.real.ts",
1409
1489
  "test:vectors:live": "tsx tests/vector-stores.live.ts",
1410
1490
  "bench:graph": "node scripts/bench-graph.mjs",
1491
+ "bench:runtime": "node --expose-gc scripts/bench-runtime.mjs",
1411
1492
  "pack:dry-run": "npm pack --dry-run --cache .tmp-nexus-ai-tests/npm-cache",
1412
1493
  "check": "npm run format:check && npm run registry:check && npm run llms:check && npm run lint && npm test && npm run typecheck:tests && npm run studio:typecheck && npm run typecheck:examples && npm run typecheck:examples:browser && npm run test:coverage",
1413
- "check:release": "npm run check && npm run bench:graph && npm run pack:dry-run && npm run test:clean-install && npm run test:studio-install",
1494
+ "check:release": "npm run check && npm run bench:graph && npm run bench:runtime && npm run pack:dry-run && npm run test:clean-install && npm run test:studio-install",
1414
1495
  "prepack": "npm run build",
1415
1496
  "prepublishOnly": "npm run check:release",
1416
1497
  "build:esm": "tsc --removeComments --declaration false && tsc --emitDeclarationOnly",
@@ -1538,10 +1619,13 @@
1538
1619
  "ajv-formats": "^3.0.1",
1539
1620
  "bullmq": "^5.63.0",
1540
1621
  "express": "^5.1.0",
1622
+ "nexus-ai-pro-2-0": "npm:nexus-ai-pro@^2.0.0",
1623
+ "nexus-ai-pro-2-1": "npm:nexus-ai-pro@^2.1.0",
1541
1624
  "ollama": "^0.5.6",
1542
1625
  "openai": "^4.52.0",
1543
1626
  "tsx": "^4.16.0",
1544
1627
  "typescript": "^5.5.0",
1628
+ "wasmoon": "^1.16.0",
1545
1629
  "yaml": "^2.9.1",
1546
1630
  "zod": "^3.23.0"
1547
1631
  },
@@ -1722,6 +1806,9 @@
1722
1806
  "graph/visualize": [
1723
1807
  "dist-cjs/graph/visualize.d.ts"
1724
1808
  ],
1809
+ "graph/lint": [
1810
+ "dist-cjs/graph/lint.d.ts"
1811
+ ],
1725
1812
  "agent": [
1726
1813
  "dist-cjs/agent/index.d.ts"
1727
1814
  ],
@@ -1737,6 +1824,12 @@
1737
1824
  "tracing": [
1738
1825
  "dist-cjs/tracing/index.d.ts"
1739
1826
  ],
1827
+ "tracing/otlp": [
1828
+ "dist-cjs/tracing/otlp.d.ts"
1829
+ ],
1830
+ "tracing/rollups": [
1831
+ "dist-cjs/tracing/rollups.d.ts"
1832
+ ],
1740
1833
  "evaluate": [
1741
1834
  "dist-cjs/evaluate/index.d.ts"
1742
1835
  ],
@@ -1758,6 +1851,12 @@
1758
1851
  "postgres/evaluate": [
1759
1852
  "dist-cjs/postgres/evaluate.d.ts"
1760
1853
  ],
1854
+ "postgres/migrations": [
1855
+ "dist-cjs/postgres/migrations.d.ts"
1856
+ ],
1857
+ "postgres/rollups": [
1858
+ "dist-cjs/postgres/rollups.d.ts"
1859
+ ],
1761
1860
  "server": [
1762
1861
  "dist-cjs/server/index.d.ts"
1763
1862
  ],
@@ -1797,6 +1896,12 @@
1797
1896
  "server/tenancy": [
1798
1897
  "dist-cjs/server/tenancy.d.ts"
1799
1898
  ],
1899
+ "tenancy": [
1900
+ "dist-cjs/tenancy/index.d.ts"
1901
+ ],
1902
+ "doctor": [
1903
+ "dist-cjs/doctor/index.d.ts"
1904
+ ],
1800
1905
  "prompts": [
1801
1906
  "dist-cjs/prompts/index.d.ts"
1802
1907
  ],
@@ -1971,6 +2076,9 @@
1971
2076
  "sqlite/vectors": [
1972
2077
  "dist-cjs/sqlite/vectors.d.ts"
1973
2078
  ],
2079
+ "sqlite/migrations": [
2080
+ "dist-cjs/sqlite/migrations.d.ts"
2081
+ ],
1974
2082
  "mcp/registry": [
1975
2083
  "dist-cjs/mcp/registry.d.ts"
1976
2084
  ],