@mnmal-ai/substrate-nl 1.0.0-beta.17 → 1.0.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,7 +38,7 @@ A **kernel-tier plugin**, installed separately: `pnpm add @mnmal-ai/substrate-nl
38
38
  }
39
39
  ```
40
40
 
41
- - `judge` optional: an [Ollama](https://ollama.com) server and model for the constrained judge (`timeoutMs` defaults to 20000). Absent means parser-only: every escalation is an honest hand-off. A slow or down judge hands off within `timeoutMs`. A hand-off with words the parser could not read answers `unknown` and runs nothing.
41
+ - `judge` optional: an [Ollama](https://ollama.com) server and model for the constrained judge (`timeoutMs` defaults to 20000). Absent means parser-only: every escalation is an honest hand-off. A slow or down judge hands off within `timeoutMs`. A hand-off with words the parser could not read answers `unknown` and runs nothing. When the judge picks a reading, the words that reading left over are reported in `dropped` as `judge: noise`. The pick is refused, and the answer is `unknown`, when a leftover word has a digit, is an aggregate or unit word ("average", "daily"), is a word of one of the type's field names or phrases ("priority todos"), or sits right before the time expression ("todos due in 2026"); "happened" and "occurred" are exempt from the last.
42
42
  - `rulings` optional; per-namespace overrides merged over rulings the namespace declares.
43
43
  - `packTtlMs` how long a served pack is reused (default 300000).
44
44
  - `inFlightPerCaller` asks one caller may have running at once (default 4). One more is answered 429 `too_many_in_flight` with `retry-after`. Sessions that share a key count as one caller.
@@ -2326,6 +2326,10 @@ const UNIT_ADJECTIVES = {
2326
2326
  annual: "year",
2327
2327
  annually: "year"
2328
2328
  };
2329
+ /** Whether `word` asks for an aggregate or names a grouping unit ("average", "daily"). */
2330
+ function shapesAnswer(word) {
2331
+ return own(AGGREGATE_WORDS, word) !== void 0 || own(UNIT_ADJECTIVES, word) !== void 0;
2332
+ }
2329
2333
  /** Whether the token just before or after token `k` is an aggregate word, claimed or not. */
2330
2334
  function besideAggregate(tokens, k) {
2331
2335
  return [k - 1, k + 1].some((j) => own(AGGREGATE_WORDS, tokens[j]?.text ?? "") !== void 0);
@@ -2965,6 +2969,28 @@ function withBinding(rulings, choice) {
2965
2969
  }
2966
2970
  };
2967
2971
  }
2972
+ /** Verbs that say only that something took place, so they choose no date field. */
2973
+ const OCCURRED = /* @__PURE__ */ new Set([
2974
+ "happen",
2975
+ "happened",
2976
+ "happening",
2977
+ "occurred"
2978
+ ]);
2979
+ /**
2980
+ * Why a leftover word of a picked reading cannot be noise, or null. An aggregate
2981
+ * or unit word asks for a different answer, a word of one of the type's fields
2982
+ * names a filter or a column, and a word right before the time expression says
2983
+ * which date the window is on ("due in 2026"), unless it is one of OCCURRED.
2984
+ */
2985
+ function notNoise(word, question, chosen, pack) {
2986
+ const parts = word.split(" ");
2987
+ if (parts.some(shapesAnswer)) return "asks for an aggregate or a grouping";
2988
+ const fields = Object.values(own(pack.types, chosen.type)?.fields ?? {});
2989
+ const fieldWords = new Set(fields.flatMap((f) => [...splitWords(f.name), ...f.phrases.flatMap((p) => p.split(" "))]));
2990
+ if (parts.some((w) => fieldWords.has(w))) return `names a ${chosen.type} field`;
2991
+ const q = question.toLowerCase();
2992
+ return !OCCURRED.has(word) && chosen.evidence.some((e) => e.role === "time" && q.includes(`${word} ${e.span.toLowerCase()}`)) ? "says which date is meant" : null;
2993
+ }
2968
2994
  /** Why a binding cannot be applied, or null when it grounds. */
2969
2995
  async function verifyBinding(choice, earlier, pack, opts) {
2970
2996
  const [type, field] = choice.field.split(".");
@@ -3048,6 +3074,20 @@ async function parseWithJudge(question, pack, ctx, judge, opts = {}) {
3048
3074
  trail
3049
3075
  };
3050
3076
  }
3077
+ const meant = chosen.residual.map((w) => [w, notNoise(w, question, chosen, pack)]).filter(([, why]) => why !== null);
3078
+ if (meant.length > 0) {
3079
+ const reason = `not noise: ${meant.map(([w, why]) => `"${w}" ${why}`).join("; ")}`;
3080
+ return {
3081
+ status: "escalated",
3082
+ result: {
3083
+ status: "partial",
3084
+ candidates: [chosen],
3085
+ residual: chosen.residual,
3086
+ reason
3087
+ },
3088
+ trail
3089
+ };
3090
+ }
3051
3091
  return {
3052
3092
  status: "resolved",
3053
3093
  candidate: chosen,
@@ -3606,22 +3646,25 @@ function buildNamespacePack(input) {
3606
3646
  const def = declared[name];
3607
3647
  const field = packField(name, def, operators);
3608
3648
  fields[name] = field;
3649
+ const observed = profile?.types[typeName]?.[name];
3650
+ const counted = (value) => observed?.counts === void 0 ? {} : { count: own(observed.counts, value) ?? 0 };
3609
3651
  for (const value of field.enum ?? []) refs.push({
3610
3652
  type: typeName,
3611
3653
  field: name,
3612
- value
3654
+ value,
3655
+ ...counted(value)
3613
3656
  });
3614
3657
  for (const alias of Object.keys(field.aliases ?? {})) refs.push({
3615
3658
  type: typeName,
3616
3659
  field: name,
3617
3660
  value: alias
3618
3661
  });
3619
- const observed = profile?.types[typeName]?.[name];
3620
3662
  if (observed !== void 0 && field.indexed && isStringy(def) && !observed.truncated && observed.values.length <= maxDistinct && areLabels(observed.values)) {
3621
3663
  for (const value of observed.values) refs.push({
3622
3664
  type: typeName,
3623
3665
  field: name,
3624
- value
3666
+ value,
3667
+ ...counted(value)
3625
3668
  });
3626
3669
  field.distinct = observed.values.length;
3627
3670
  }
@@ -3732,7 +3775,8 @@ function sortKeys(obj) {
3732
3775
  /**
3733
3776
  * Distinct values of every indexed string field (and indexed list-of-string
3734
3777
  * field) in the namespace, reading up to `maxRows` rows per type. A field that
3735
- * passes `maxDistinct` is marked truncated and stops growing.
3778
+ * passes `maxDistinct` is marked truncated and stops growing. A field carries
3779
+ * per-value row counts only when every row of its type was read.
3736
3780
  */
3737
3781
  async function profileNamespace(input) {
3738
3782
  const maxDistinct = input.maxDistinct ?? 1e3;
@@ -3742,7 +3786,7 @@ async function profileNamespace(input) {
3742
3786
  const declared = input.schema.types[typeName]?.fields ?? {};
3743
3787
  const fields = Object.keys(declared).filter((f) => profiled(declared[f]));
3744
3788
  if (fields.length === 0) continue;
3745
- const seen = new Map(fields.map((f) => [f, /* @__PURE__ */ new Set()]));
3789
+ const seen = new Map(fields.map((f) => [f, /* @__PURE__ */ new Map()]));
3746
3790
  const truncated = /* @__PURE__ */ new Set();
3747
3791
  let cursor;
3748
3792
  let rowsRead = 0;
@@ -3752,11 +3796,11 @@ async function profileNamespace(input) {
3752
3796
  for (const row of page.rows) for (const f of fields) {
3753
3797
  if (truncated.has(f)) continue;
3754
3798
  const raw = row[f];
3755
- const values = Array.isArray(raw) ? raw : [raw];
3799
+ const values = Array.isArray(raw) ? new Set(raw) : [raw];
3756
3800
  const set = seen.get(f);
3757
3801
  for (const v of values) {
3758
3802
  if (typeof v !== "string" || v.length === 0) continue;
3759
- set.add(v);
3803
+ set.set(v, (set.get(v) ?? 0) + 1);
3760
3804
  if (set.size > maxDistinct) {
3761
3805
  truncated.add(f);
3762
3806
  break;
@@ -3767,12 +3811,14 @@ async function profileNamespace(input) {
3767
3811
  } while (cursor !== void 0 && truncated.size < fields.length && rowsRead < maxRows);
3768
3812
  const out = {};
3769
3813
  for (const f of [...fields].sort()) {
3770
- const values = [...seen.get(f)].sort();
3814
+ const counted = seen.get(f);
3815
+ const values = [...counted.keys()].sort();
3771
3816
  const isTruncated = truncated.has(f);
3772
3817
  if (values.length === 0 && !isTruncated) continue;
3773
3818
  out[f] = {
3774
3819
  values: isTruncated ? values.slice(0, maxDistinct) : values,
3775
- truncated: isTruncated
3820
+ truncated: isTruncated,
3821
+ ...cursor === void 0 && !isTruncated ? { counts: Object.fromEntries(counted) } : {}
3776
3822
  };
3777
3823
  }
3778
3824
  types[typeName] = out;
package/dist/bootstrap.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as bootstrap, t as NlBootstrapConfigSchema } from "./bootstrap-LrRqIyiw.js";
1
+ import { n as bootstrap, t as NlBootstrapConfigSchema } from "./bootstrap-BcnHBZg0.js";
2
2
 
3
3
  export { NlBootstrapConfigSchema, bootstrap, bootstrap as default };
@@ -1 +1 @@
1
- {"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../src/complete/complete.ts"],"names":[],"mappings":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1F"}
package/dist/complete.js CHANGED
@@ -65,10 +65,15 @@ function complete(draft, cursor, pack) {
65
65
  const f = own(own(pack.types, type)?.fields, fieldName);
66
66
  if (f === void 0) return [];
67
67
  const valueStart = start + colon + 1;
68
+ const rows = (value) => {
69
+ const n = own(pack.values, value.trim().toLowerCase())?.find((r) => r.type === type && r.field === fieldName)?.count;
70
+ return n === void 0 ? {} : { detail: n === 1 ? "1 row" : `${n} rows` };
71
+ };
68
72
  const pool = [
69
73
  ...(f.enum ?? []).map((v) => ({
70
74
  insert: v,
71
- label: v
75
+ label: v,
76
+ ...rows(v)
72
77
  })),
73
78
  ...Object.entries(f.aliases ?? {}).map(([alias, canon]) => ({
74
79
  insert: alias,
@@ -76,7 +81,8 @@ function complete(draft, cursor, pack) {
76
81
  })),
77
82
  ...Object.entries(pack.values).filter(([, refs]) => refs.some((r) => r.type === type && r.field === fieldName)).map(([v, refs]) => ({
78
83
  insert: refs.find((r) => r.type === type)?.value ?? v,
79
- label: v
84
+ label: v,
85
+ ...rows(v)
80
86
  }))
81
87
  ];
82
88
  const prefix = token.slice(colon + 1);
@@ -88,6 +94,7 @@ function complete(draft, cursor, pack) {
88
94
  replace,
89
95
  insert: x.insert,
90
96
  label: x.label,
97
+ ...x.detail !== void 0 ? { detail: x.detail } : {},
91
98
  score: 2
92
99
  }));
93
100
  const ops = f.operators.flatMap((op) => {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as askHandler, c as profileNamespace, d as runAsk, f as parseWithJudge, g as readRulings, h as mergeRulings, i as createNlPlugin, l as buildNamespacePack, m as NamespaceRulingsSchema, n as bootstrap, o as packHandler, p as parseQuestion, r as CONTRACT_VERSION, s as PackService, t as NlBootstrapConfigSchema, u as OllamaJudge } from "./bootstrap-LrRqIyiw.js";
1
+ import { a as askHandler, c as profileNamespace, d as runAsk, f as parseWithJudge, g as readRulings, h as mergeRulings, i as createNlPlugin, l as buildNamespacePack, m as NamespaceRulingsSchema, n as bootstrap, o as packHandler, p as parseQuestion, r as CONTRACT_VERSION, s as PackService, t as NlBootstrapConfigSchema, u as OllamaJudge } from "./bootstrap-BcnHBZg0.js";
2
2
  import { complete } from "./complete.js";
3
3
 
4
4
  export { CONTRACT_VERSION, NamespaceRulingsSchema, NlBootstrapConfigSchema, OllamaJudge, PackService, askHandler, bootstrap, buildNamespacePack, complete, createNlPlugin, mergeRulings, packHandler, parseQuestion, parseWithJudge, profileNamespace, readRulings, runAsk };
@@ -1 +1 @@
1
- {"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../../src/judge/judge.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEzF,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,6EAA6E;AAC7E,MAAM,WAAW,KAAK;IACpB,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrE;AAED,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC;AAEpC,MAAM,MAAM,YAAY,GACpB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,SAAS,E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O,CAAC,EAAE,gBAAgB,CAAC;IAC3B,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAsBD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,aAAa,CA8CvE"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/pack/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAsBD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,GAAG,aAAa,CAkDvE"}
@@ -21,7 +21,8 @@ export interface ProfileInput {
21
21
  /**
22
22
  * Distinct values of every indexed string field (and indexed list-of-string
23
23
  * field) in the namespace, reading up to `maxRows` rows per type. A field that
24
- * passes `maxDistinct` is marked truncated and stops growing.
24
+ * passes `maxDistinct` is marked truncated and stops growing. A field carries
25
+ * per-value row counts only when every row of its type was read.
25
26
  */
26
27
  export declare function profileNamespace(input: ProfileInput): Promise<NamespaceProfile>;
27
28
  //# sourceMappingURL=profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/pack/profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEjE,wD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G;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqDrF"}
@@ -17,5 +17,7 @@ export interface NamespaceProfile {
17
17
  export interface FieldProfile {
18
18
  values: string[];
19
19
  truncated: boolean;
20
+ /** Rows holding each value. Absent when the type was not read to its end. */
21
+ counts?: Record<string, number>;
20
22
  }
21
23
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pack/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC;AAClC,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC;AACpC,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC;AAE1C,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pack/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC;AAClC,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC;AACpC,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC;AAE1C,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC"}
@@ -71,5 +71,7 @@ type AggregateFn = 'avg' | 'sum' | 'min' | 'max';
71
71
  declare const TIME_UNITS: readonly ['hour', 'day', 'week', 'month', 'year'];
72
72
  /** The units a date group can truncate to. */
73
73
  export type TimeUnit = (typeof TIME_UNITS)[number];
74
+ /** Whether `word` asks for an aggregate or names a grouping unit ("average", "daily"). */
75
+ export declare function shapesAnswer(word: string): boolean;
74
76
  export {};
75
77
  //# sourceMappingURL=parse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9F,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,kBAAkB,CAAC;AAsB3E,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC;AAElC,MAAM,WAAW,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ACnB,yFAAyF;IACzF,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE;QACV,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC;QAC1B,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAA;SAAE,CAAC;KACzD,CAAC;CACH;AAED,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;IACtB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAqHD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,YAAY,GAChB,WAAW,CAgcb;AAivBD,KAAK,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AA4BjD,QAAA,MAAM,UAAU,YAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAU,CAAC;AACrE,8CAA8C;AAC9C,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAYnD,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnmal-ai/substrate-nl",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "Natural-language questions for Substrate — a deterministic parser with an optional constrained judge, served at POST /substrate/v1/nl and GET /substrate/v1/nl/pack/:ns, plus browser-safe completion.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@biomejs/biome": "2.6.4",
40
- "@mnmal-ai/substrate": "1.0.0-beta.17",
41
- "@mnmal-ai/substrate-config": "1.0.0-beta.17",
40
+ "@mnmal-ai/substrate": "1.0.0-beta.18",
41
+ "@mnmal-ai/substrate-config": "1.0.0-beta.18",
42
42
  "@types/node": "^26.6.4",
43
43
  "postgres": "4.1.1",
44
44
  "tsdown": "^0.23.0",