@mnmal-ai/substrate-nl 1.0.0-alpha.14 → 1.0.0-alpha.15

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
@@ -6,6 +6,9 @@ Natural-language ask surface. A deterministic parser reads a question against a
6
6
 
7
7
  - `POST /substrate/v1/nl` with `{ namespace, question, project?, type?, asOf? }` returns one of `rows`, `recall`, `clarify` or `refuse`, plus a `trail` of how it got there. Send `accept: text/event-stream` for the same as SSE events (`parsed`, `judging`, `judged`, then the outcome, then `done`), otherwise it is one JSON body.
8
8
  - `asOf` is "now" for relative dates ("yesterday", "last week") and for the year of a month-day ("on Oct 23"): an ISO-8601 date-time with an offset, such as `2026-10-02T12:00:00-05:00`. Day boundaries are in its offset. Anything else is `400 invalid_params`. Without it the server clock is used. The `parsed` event's `asOf` says which clock the question was read against.
9
+ - Aggregates: `average|avg|mean <field>`, `total|sum [of] <field>`, `min|minimum|max|maximum <field>`, each over the seed type with every filter, value and time range the question also names. The field must be a seed number field (min and max also take a date field). An unknown field, a wrong kind or a field on a walked type is dropped with a reason, and the answer is `unknown`. `highest|lowest <field>` is an aggregate only when `of` or `for` follows the field, a type is named after the field, and no type is named before the superlative ("the highest price of items"). Otherwise it orders ("items with the highest price", "items with the highest price for last week"). A recency or limit word inside a count or an aggregate ("the last sale", "the first 3 items") is dropped as a filter, so the answer is `unknown`. So is an aggregate inside a "how many" question. The outcome is `rows` with `answer: 'aggregate'`, the engine's `data`, and `aggregate: { fn, field, value }`. A store that answers no walks, or a seed under a row policy, refuses the frame: `aggregate` is then absent and `errors` says why. Unlike a count, there is no paged fallback.
10
+ - Grouping an aggregate: `by|per day|hour` buckets the type's time field (`timeField` ruling, else `createdAt`). `by|per <field>` groups by a seed enum or yes/no field, as one aggregate per value (at most 20) plus one for rows with no value. That last group is keyed `null` and is left out when its value is null. Either one gives `aggregate: { fn, field, by, groups: [{ key, value }], truncated? }`. `week`, `month` and `year` buckets, and grouping by any other field, are dropped with a reason, and the ungrouped value still answers.
11
+ - Ordering across one hop: `top|bottom [N] <type> by [pick] <field>` and `<type> with the highest|lowest <field>` may name a number field one crossRef hop away, as `<other type> <field>` ("top 10 items by supplier rating"), a `fieldPhrases` ruling, or a field name only one other type has. The seed's rows are ordered by an `_agg` over that hop, through `derive: { <name>: { value: '_agg.<name>' } }` and `orderBy: [{ $<name>: dir }]`, and each row carries the value under `_agg.<name>`. A hop out to one row reads its value. A direction word right after `by` (`lowest|smallest|least` or `highest|largest|most`) sets the direction, for a seed field too ("top 10 items by lowest price" is ascending). A hop in from many picks one value: `latest|current|most recent` after `by` picks the latest, else the phrase ruling's `pick`, else `max` for a descending order and `min` for an ascending one. Any other pick word after `by` (`cheapest`, or `latest` on a field with one value per row) drops the ordering with a reason. When the field is named as `<type> <field>` and a time range is asked, that type stays a competing reading. The evidence and the plan name it, for example `max(Item.price) per supplier`. Rows with no neighbour sort last. Two or more hops, a field on several types, an unknown field and a non-number field are dropped with a reason.
9
12
  - `GET /substrate/v1/nl/pack/<ns>` returns the namespace pack (types, fields, values, rulings) with an `etag`; send `if-none-match` for a `304`.
10
13
  - NL is read-only: a mutation-shaped question is `refuse`, never executed.
11
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/ask/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAGf,KAAK,gBAAgB,EAGtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,KAAK,KAAK,EAAqC,MAAM,mBAAmB,CAAC;AAElF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAa,MAAM,aAAa,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,cA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CAAC,OAAO,CAAC,CAgJzB"}
@@ -1254,7 +1254,14 @@ function parseQuestion(question, pack, ctx) {
1254
1254
  role: "time",
1255
1255
  detail: `${time.range.gte ?? ""} .. ${time.range.lt ?? ""}`.trim()
1256
1256
  });
1257
- const fieldOrder = claimFieldOrder(tokens, walkClaims, pack, rulings);
1257
+ const aggregate = claimAggregate(tokens, walkClaims, pack, rulings, [...mentioned.values()].map((m) => m.at[0]));
1258
+ const fieldOrder = claimFieldOrder(tokens, walkClaims, pack, rulings, mentioned);
1259
+ const fieldType = fieldOrder?.type;
1260
+ if (fieldType !== void 0 && time === null && mentioned.size > 1) {
1261
+ mentioned.delete(fieldType);
1262
+ const e = evidence.findIndex((x) => x.role === "type" && x.detail === fieldType);
1263
+ if (e >= 0) evidence.splice(e, 1);
1264
+ }
1258
1265
  const ids = [];
1259
1266
  let bareNumber = false;
1260
1267
  tokens.forEach((t, i) => {
@@ -1502,6 +1509,7 @@ function parseQuestion(question, pack, ctx) {
1502
1509
  fieldOrder: fieldOrder ?? composed?.seedOrder ?? null,
1503
1510
  plural: mentioned.get(type)?.plural ?? false,
1504
1511
  count,
1512
+ aggregate,
1505
1513
  allProjects,
1506
1514
  historyWord,
1507
1515
  flags: flagClaims.get(type) ?? [],
@@ -1562,16 +1570,18 @@ function assemble(type, a) {
1562
1570
  }] : a.evidence;
1563
1571
  const recency = a.order ?? (seedLatest !== void 0 ? "desc" : null);
1564
1572
  const derived = a.composed?.params.orderBy !== void 0;
1573
+ const aggClaim = a.count ? null : a.aggregate;
1565
1574
  const fieldOrder = [];
1566
1575
  let sortBy = null;
1567
- if (a.fieldOrder !== null && a.count) fieldOrder.push({
1576
+ if (a.fieldOrder !== null && (a.count || aggClaim !== null)) fieldOrder.push({
1568
1577
  span: a.fieldOrder.span,
1569
- reason: "ordering does not apply to a count",
1578
+ reason: `ordering does not apply to ${a.count ? "a count" : "an aggregate"}`,
1570
1579
  kind: "filter"
1571
1580
  });
1572
- if (a.fieldOrder !== null && !a.count) {
1581
+ if (a.fieldOrder !== null && !a.count && aggClaim === null) {
1573
1582
  const r = orderField(a.fieldOrder, type, pack, rulings);
1574
1583
  const reason = "reason" in r ? r.reason : derived ? "it conflicts with the derived ordering, which is kept" : null;
1584
+ const limit = a.fieldOrder.limit ?? (a.plural ? 10 : 1);
1575
1585
  if (reason !== null) fieldOrder.push({
1576
1586
  span: a.fieldOrder.span,
1577
1587
  reason,
@@ -1580,17 +1590,24 @@ function assemble(type, a) {
1580
1590
  else if ("field" in r) sortBy = {
1581
1591
  field: r.field,
1582
1592
  dir: a.fieldOrder.dir,
1583
- limit: a.fieldOrder.limit ?? (a.plural ? 10 : 1)
1593
+ limit
1594
+ };
1595
+ else if ("hop" in r) sortBy = {
1596
+ field: `$${r.hop.name}`,
1597
+ hop: r.hop,
1598
+ dir: a.fieldOrder.dir,
1599
+ limit
1584
1600
  };
1585
1601
  }
1586
- const conflict = (derived || sortBy !== null) && recency !== null;
1587
- const order = conflict ? null : recency;
1602
+ const pickOver = (a.count || aggClaim !== null) && recency !== null;
1603
+ const conflict = !pickOver && (derived || sortBy !== null) && recency !== null;
1604
+ const order = conflict || pickOver ? null : recency;
1588
1605
  const orderSpan = evidence.find((e) => e.role === "order")?.span ?? "";
1589
- const ev = conflict ? evidence.filter((e) => e.role !== "order") : [...evidence];
1606
+ const ev = conflict || pickOver ? evidence.filter((e) => e.role !== "order") : [...evidence];
1590
1607
  if (sortBy !== null) ev.push({
1591
1608
  span: a.fieldOrder?.span ?? "",
1592
1609
  role: "order",
1593
- detail: `${sortBy.field} ${sortBy.dir}, limit ${sortBy.limit}`
1610
+ detail: `${sortBy.hop?.label ?? sortBy.field} ${sortBy.dir}, limit ${sortBy.limit}`
1594
1611
  });
1595
1612
  const dropped = [
1596
1613
  ...a.composed?.dropped ?? [],
@@ -1599,6 +1616,21 @@ function assemble(type, a) {
1599
1616
  span: orderSpan,
1600
1617
  reason: `it conflicts with the ${derived ? "derived" : "field"} ordering, which is kept`,
1601
1618
  kind: "order"
1619
+ }] : [],
1620
+ ...pickOver ? [{
1621
+ span: orderSpan,
1622
+ reason: `${a.count ? "counting" : "aggregating"} over the latest N rows is not supported`,
1623
+ kind: "filter"
1624
+ }] : [],
1625
+ ...a.count && a.aggregate !== null ? [{
1626
+ span: a.aggregate.span,
1627
+ reason: "an aggregate does not apply to a count",
1628
+ kind: "filter"
1629
+ }] : [],
1630
+ ...aggClaim !== null && derived ? [{
1631
+ span: `by ${Object.keys(a.composed?.params.derive ?? {}).join(", ")}`,
1632
+ reason: "grouping by a derived value is not supported",
1633
+ kind: "order"
1602
1634
  }] : []
1603
1635
  ];
1604
1636
  const where = [];
@@ -1656,7 +1688,14 @@ function assemble(type, a) {
1656
1688
  for (const field of usedFields) creditFieldWords(tokens, fields[field]);
1657
1689
  if (a.author !== null) where.push({ createdById: { startsWith: a.author } });
1658
1690
  const orderExclude = a.fieldOrder?.phrase?.entry.exclude;
1659
- if (sortBy !== null && orderExclude !== void 0) where.push({ NOT: orderExclude });
1691
+ if (sortBy !== null && sortBy.hop === void 0 && orderExclude !== void 0) where.push({ NOT: orderExclude });
1692
+ const agg = aggClaim === null ? null : aggregateOn(aggClaim, type, pack, rulings);
1693
+ if (agg !== null) {
1694
+ dropped.push(...agg.dropped);
1695
+ ev.push(...agg.evidence);
1696
+ if (agg.exclude !== void 0) where.push({ NOT: agg.exclude });
1697
+ if (agg.group !== void 0) usedFields.add(agg.group.field);
1698
+ }
1660
1699
  for (const flag of a.flags) {
1661
1700
  usedFields.add(flag.detail);
1662
1701
  where.push({ [flag.detail]: { eq: true } });
@@ -1717,7 +1756,7 @@ function assemble(type, a) {
1717
1756
  const closed = statusField.enum.filter((s) => CLOSED.includes(s));
1718
1757
  if (closed.length > 0) where.push({ status: { in: closed } });
1719
1758
  } else if (!historical && live !== void 0 && statusField?.enum?.includes(live) === true && !usedFields.has("status") && order === null) where.push({ status: { eq: live } });
1720
- if (!historical && fields.archived !== void 0) where.push({ archived: { eq: false } });
1759
+ if (!historical && fields.archived !== void 0 && !usedFields.has("archived")) where.push({ archived: { eq: false } });
1721
1760
  else if (historical) ev.push({
1722
1761
  span: "(history)",
1723
1762
  role: "history",
@@ -1748,28 +1787,69 @@ function assemble(type, a) {
1748
1787
  path: ["where", ...c.path]
1749
1788
  })),
1750
1789
  ...yields,
1751
- ...a.composed?.plan ?? []
1790
+ ...(a.composed?.plan ?? []).filter((c) => aggClaim === null || c.kind !== "derive"),
1791
+ ...sortBy?.hop !== void 0 ? [{
1792
+ path: [
1793
+ "fields",
1794
+ "_agg",
1795
+ sortBy.hop.name,
1796
+ sortBy.hop.label
1797
+ ],
1798
+ kind: "hop",
1799
+ served: true
1800
+ }, {
1801
+ path: [
1802
+ "orderBy",
1803
+ "0",
1804
+ sortBy.field,
1805
+ sortBy.dir
1806
+ ],
1807
+ kind: "order",
1808
+ served: false
1809
+ }] : [],
1810
+ ...agg?.group !== void 0 ? [{
1811
+ path: ["aggregate", `group:${agg.group.field} (one frame per value, and one for no value)`],
1812
+ kind: "agg",
1813
+ served: false
1814
+ }] : []
1752
1815
  ];
1753
1816
  if (order !== null) {
1754
1817
  params.orderBy = [{ [own(rulings.timeField, type) ?? "createdAt"]: order }];
1755
1818
  params.limit = 1;
1756
1819
  }
1757
1820
  if (sortBy !== null) {
1821
+ if (sortBy.hop !== void 0) params.derive = { [sortBy.hop.name]: { value: `_agg.${sortBy.hop.name}` } };
1758
1822
  params.orderBy = [{ [sortBy.field]: sortBy.dir }];
1759
1823
  params.limit = sortBy.limit;
1760
1824
  }
1761
1825
  Object.assign(params, a.composed?.params ?? {});
1762
1826
  if (a.count && a.composed?.walked === true) params.count = true;
1763
- const answer = a.askField !== null ? a.askField.group ? `group:${a.askField.field}` : `field:${a.askField.field}` : a.count ? "count" : order !== null || a.ids.length === 1 || sortBy?.limit === 1 ? "single" : "rows";
1827
+ if (aggClaim !== null) {
1828
+ delete params.derive;
1829
+ delete params.orderBy;
1830
+ }
1831
+ if (agg?.fn !== void 0 && agg.field !== void 0) {
1832
+ params.aggregate = { value: { [agg.fn]: agg.field } };
1833
+ if (agg.bucket !== void 0) params.bucket = agg.bucket;
1834
+ }
1835
+ const answer = aggClaim !== null ? "aggregate" : a.askField !== null ? a.askField.group ? `group:${a.askField.field}` : `field:${a.askField.field}` : a.count ? "count" : order !== null || a.ids.length === 1 || sortBy?.limit === 1 ? "single" : "rows";
1764
1836
  return {
1765
1837
  type,
1766
- frame: { [`${pack.namespace}/${type}`]: { params } },
1838
+ frame: { [`${pack.namespace}/${type}`]: {
1839
+ params,
1840
+ ...sortBy?.hop !== void 0 ? { fields: { _agg: { [sortBy.hop.name]: sortBy.hop.agg } } } : {}
1841
+ } },
1767
1842
  answer,
1768
1843
  evidence: ev,
1769
1844
  residual: contentWords(tokens),
1770
1845
  plan,
1771
1846
  dropped,
1772
- strict: a.count || order !== null || sortBy !== null || a.ids.length === 1 || a.composed?.strict === true
1847
+ ...agg?.fn !== void 0 && agg.field !== void 0 ? { aggregate: {
1848
+ fn: agg.fn,
1849
+ field: agg.field,
1850
+ ...agg.group !== void 0 ? { group: agg.group } : {}
1851
+ } } : {},
1852
+ strict: a.count || aggClaim !== null || order !== null || sortBy !== null || a.ids.length === 1 || a.composed?.strict === true
1773
1853
  };
1774
1854
  }
1775
1855
  /** A field named by words on one type: one of its field phrases, else its name or an alias. */
@@ -1777,72 +1857,161 @@ function fieldByWords(words, fields, rulings) {
1777
1857
  return Object.entries(fields).find(([, f]) => f.phrases.includes(words))?.[0] ?? (words.includes(" ") ? null : resolveField(words, fields, rulings));
1778
1858
  }
1779
1859
  /**
1780
- * Claims one field ordering. Field words are a field phrase claim, else the
1781
- * longest run of up to three free words naming a field on some type; after
1782
- * "by", "highest" or "lowest" an unknown single word is claimed too, so the
1783
- * reading can drop it with a reason.
1860
+ * The field named at `i`: a field phrase claim, else the longest run of up to
1861
+ * three free words naming a field on some type, else (unless `numeric`) one
1862
+ * free unknown word, so the reading can drop it with a reason.
1784
1863
  */
1785
- function claimFieldOrder(tokens, walkClaims, pack, rulings) {
1786
- const somewhere = (w, numeric) => Object.values(pack.types).some((t) => {
1787
- const name = fieldByWords(w, t.fields, rulings);
1788
- return name !== null && (!numeric || t.fields[name]?.valueType === "number");
1789
- });
1790
- const fieldAt = (i, numeric) => {
1791
- const p = walkClaims.phrases.find((x) => x.at[0] === i && x.field !== void 0 && x.entry.value === void 0);
1792
- if (p !== void 0) return {
1793
- phrase: p,
1794
- span: p.span,
1795
- end: p.at[1]
1864
+ function fieldAt(tokens, walkClaims, pack, rulings, i, numeric) {
1865
+ const p = walkClaims.phrases.find((x) => x.at[0] === i && x.field !== void 0 && x.entry.value === void 0);
1866
+ if (p !== void 0) return {
1867
+ phrase: p,
1868
+ span: p.span,
1869
+ end: p.at[1]
1870
+ };
1871
+ for (let n = 3; n >= 1; n--) {
1872
+ const slice = tokens.slice(i, i + n);
1873
+ if (slice.length < n || slice.some((t) => t.used)) continue;
1874
+ const w = slice.map((t) => t.text).join(" ");
1875
+ if (Object.values(pack.types).some((t) => {
1876
+ const name = fieldByWords(w, t.fields, rulings);
1877
+ return name !== null && (!numeric || t.fields[name]?.valueType === "number");
1878
+ })) return {
1879
+ words: w,
1880
+ span: w,
1881
+ end: i + n - 1
1882
+ };
1883
+ }
1884
+ const t = tokens[i];
1885
+ return !numeric && t !== void 0 && !t.used && !GLUE.has(t.text) && !/^\d/.test(t.text) ? {
1886
+ words: t.text,
1887
+ span: t.text,
1888
+ end: i
1889
+ } : null;
1890
+ }
1891
+ /** Marks tokens `from`..`f.end` used; a field phrase named here is not walked to. */
1892
+ function takeField(tokens, walkClaims, from, f) {
1893
+ for (let k = from; k <= f.end; k++) tokens[k].used = true;
1894
+ if (f.phrase !== void 0) walkClaims.phrases.splice(walkClaims.phrases.indexOf(f.phrase), 1);
1895
+ }
1896
+ const fieldRef = (f) => f.phrase !== void 0 ? { phrase: f.phrase } : {
1897
+ words: f.words,
1898
+ ...f.type !== void 0 ? { type: f.type } : {}
1899
+ };
1900
+ /**
1901
+ * Claims one field ordering: "top|bottom [N] … by [pick] <field>",
1902
+ * "highest|lowest <field>", "most <number field>". The field may be a
1903
+ * "<type> <field>" pair, whose type mention is then part of the field, not a
1904
+ * seed; or a field phrase on another type that a walk pick claimed.
1905
+ */
1906
+ function claimFieldOrder(tokens, walkClaims, pack, rulings, mentioned) {
1907
+ const index = buildTypeIndex(pack, rulings);
1908
+ /** "<type> <field>": a named type's phrase at `i`, then a field of that type or one free word. */
1909
+ const typed = (i) => {
1910
+ for (const e of index) {
1911
+ const n = e.phrase.split(" ").length;
1912
+ const words = tokens.slice(i, i + n);
1913
+ const type = e.types[0];
1914
+ if (e.types.length !== 1 || !mentioned.has(type) || words.length < n) continue;
1915
+ if (words.map((t) => t.text).join(" ") !== e.phrase || words.some((t) => !t.used)) continue;
1916
+ const fields = own(pack.types, type)?.fields ?? {};
1917
+ const end = i + n - 1;
1918
+ for (let m = 3; m >= 1; m--) {
1919
+ const slice = tokens.slice(end + 1, end + 1 + m);
1920
+ if (slice.length < m || slice.some((t) => t.used)) continue;
1921
+ const w = slice.map((t) => t.text).join(" ");
1922
+ if (fieldByWords(w, fields, rulings) !== null || m === 1 && !GLUE.has(w) && !/^\d/.test(w)) return {
1923
+ words: w,
1924
+ type,
1925
+ span: `${e.phrase} ${w}`,
1926
+ end: end + m
1927
+ };
1928
+ }
1929
+ return null;
1930
+ }
1931
+ return null;
1932
+ };
1933
+ const at = (i, numeric) => typed(i) ?? fieldAt(tokens, walkClaims, pack, rulings, i, numeric);
1934
+ const take = (from, f) => takeField(tokens, walkClaims, from, f);
1935
+ /** A pick word at `i` ("latest", "lowest" …), free or claimed by a walk pick; a direction word sets `dir`. */
1936
+ const pickAt = (i) => {
1937
+ const claimed = walkClaims.picks.find((k) => k.at[0] === i);
1938
+ if (claimed !== void 0) return {
1939
+ span: claimed.span,
1940
+ kind: claimed.kind,
1941
+ dir: own(DIRECTION_WORDS, claimed.span),
1942
+ next: claimed.at[1] + 1,
1943
+ claimed
1796
1944
  };
1797
- for (let n = 3; n >= 1; n--) {
1945
+ const words = [
1946
+ ...Object.keys(PICK_WORDS).filter((w) => w.includes(" ")),
1947
+ ...Object.keys(DIRECTION_WORDS),
1948
+ ...Object.keys(PICK_WORDS)
1949
+ ];
1950
+ for (const word of words) {
1951
+ const n = word.split(" ").length;
1798
1952
  const slice = tokens.slice(i, i + n);
1799
- if (slice.length < n || slice.some((t) => t.used)) continue;
1800
- const w = slice.map((t) => t.text).join(" ");
1801
- if (somewhere(w, numeric)) return {
1802
- words: w,
1803
- span: w,
1804
- end: i + n - 1
1953
+ if (slice.length === n && slice.every((t) => !t.used) && slice.map((t) => t.text).join(" ") === word) return {
1954
+ span: word,
1955
+ kind: own(PICK_WORDS, word) ?? "max",
1956
+ dir: own(DIRECTION_WORDS, word),
1957
+ next: i + n
1805
1958
  };
1806
1959
  }
1807
- const t = tokens[i];
1808
- return !numeric && t !== void 0 && !t.used && !GLUE.has(t.text) && !/^\d/.test(t.text) ? {
1809
- words: t.text,
1810
- span: t.text,
1811
- end: i
1812
- } : null;
1813
- };
1814
- const take = (from, f) => {
1815
- for (let k = from; k <= f.end; k++) tokens[k].used = true;
1816
- if (f.phrase !== void 0) walkClaims.phrases.splice(walkClaims.phrases.indexOf(f.phrase), 1);
1960
+ return null;
1817
1961
  };
1818
- const field = (f) => f.phrase !== void 0 ? { phrase: f.phrase } : { words: f.words };
1962
+ const field = fieldRef;
1819
1963
  for (let i = 0; i < tokens.length; i++) {
1820
1964
  const t = tokens[i];
1821
- if (t.used) continue;
1965
+ if (t.used) {
1966
+ const k = walkClaims.picks.find((x) => x.at[0] === i && x.at[1] === i && (x.span === "highest" || x.span === "lowest"));
1967
+ const p = k?.phrase;
1968
+ if (k === void 0 || p === void 0 || p.field === void 0 || p.entry.value !== void 0 || walkClaims.compares.some((c) => c.subject === p || c.object === p)) continue;
1969
+ walkClaims.picks.splice(walkClaims.picks.indexOf(k), 1);
1970
+ take(i, {
1971
+ phrase: p,
1972
+ span: p.span,
1973
+ end: p.at[1]
1974
+ });
1975
+ return {
1976
+ span: `${k.span} ${p.span}`,
1977
+ dir: k.kind === "max" ? "desc" : "asc",
1978
+ phrase: p
1979
+ };
1980
+ }
1822
1981
  if (t.text === "top" || t.text === "bottom") {
1823
1982
  const n = tokens[i + 1];
1824
1983
  const limit = n !== void 0 && !n.used && /^[1-9]\d*$/.test(n.text) ? n : void 0;
1825
1984
  const by = tokens.findIndex((x, j) => j > i && x.text === "by" && !x.used && !AUTHOR_VERBS.has(tokens[j - 1]?.text ?? ""));
1826
- const f = by < 0 ? null : fieldAt(by + 1, false);
1985
+ if (by < 0) continue;
1986
+ const pick = pickAt(by + 1);
1987
+ const picked = pick === null ? null : at(pick.next, false);
1988
+ const f = picked ?? at(by + 1, false);
1827
1989
  if (f === null) continue;
1828
1990
  t.used = true;
1829
1991
  if (limit !== void 0) limit.used = true;
1992
+ const withPick = picked !== null && pick !== null;
1993
+ if (withPick && pick.claimed !== void 0) walkClaims.picks.splice(walkClaims.picks.indexOf(pick.claimed), 1);
1830
1994
  take(by, f);
1831
1995
  return {
1832
1996
  span: [
1833
1997
  t.text,
1834
1998
  limit?.text,
1835
1999
  "by",
2000
+ withPick ? pick.span : void 0,
1836
2001
  f.span
1837
2002
  ].filter((x) => x !== void 0).join(" "),
1838
- dir: t.text === "top" ? "desc" : "asc",
2003
+ dir: withPick && pick.dir !== void 0 ? pick.dir : t.text === "top" ? "desc" : "asc",
1839
2004
  ...limit !== void 0 ? { limit: Number(limit.text) } : {},
2005
+ ...withPick && pick.dir === void 0 ? { pick: {
2006
+ span: pick.span,
2007
+ kind: pick.kind
2008
+ } } : {},
1840
2009
  ...field(f)
1841
2010
  };
1842
2011
  }
1843
2012
  if (t.text === "highest" || t.text === "lowest" || t.text === "most") {
1844
2013
  const numeric = t.text === "most";
1845
- const f = fieldAt(i + 1, numeric);
2014
+ const f = at(i + 1, numeric);
1846
2015
  if (f === null) continue;
1847
2016
  take(i, f);
1848
2017
  return {
@@ -1855,10 +2024,109 @@ function claimFieldOrder(tokens, walkClaims, pack, rulings) {
1855
2024
  }
1856
2025
  return null;
1857
2026
  }
1858
- /** The seed field an ordering sorts by on `type`, or why it cannot. */
1859
- function orderField(o, type, pack, rulings) {
2027
+ const AGGREGATE_WORDS = {
2028
+ average: "avg",
2029
+ avg: "avg",
2030
+ mean: "avg",
2031
+ total: "sum",
2032
+ sum: "sum",
2033
+ min: "min",
2034
+ minimum: "min",
2035
+ lowest: "min",
2036
+ max: "max",
2037
+ maximum: "max",
2038
+ highest: "max"
2039
+ };
2040
+ /** Superlatives that are an ordering (#1903) unless the field is followed by one of these. */
2041
+ const VALUE_SUPERLATIVES = /* @__PURE__ */ new Set(["highest", "lowest"]);
2042
+ const VALUE_OF = /* @__PURE__ */ new Set(["of", "for"]);
2043
+ /** A word right after "by" that sets an ordering's direction ("top 10 items by lowest price"). */
2044
+ const DIRECTION_WORDS = {
2045
+ lowest: "asc",
2046
+ smallest: "asc",
2047
+ least: "asc",
2048
+ highest: "desc",
2049
+ largest: "desc",
2050
+ most: "desc"
2051
+ };
2052
+ /** A field grouping runs one frame per value: more than this is dropped. */
2053
+ const MAX_GROUPS = 20;
2054
+ const BUCKET_WORDS = /* @__PURE__ */ new Set([
2055
+ "hour",
2056
+ "day",
2057
+ "week",
2058
+ "month",
2059
+ "year"
2060
+ ]);
2061
+ /**
2062
+ * Claims one aggregate. "highest|lowest <field>" is a value only when "of" or
2063
+ * "for" follows the field and a type is named after it, none before the
2064
+ * superlative ("the highest price of items"); otherwise it stays an ordering
2065
+ * ("items with the highest price", "… highest price for last week").
2066
+ */
2067
+ function claimAggregate(tokens, walkClaims, pack, rulings, mentions) {
2068
+ const ofFollows = (end) => VALUE_OF.has(tokens[end + 1]?.text ?? "");
2069
+ const valueAt = (start, end) => ofFollows(end) && mentions.some((m) => m > end) && !mentions.some((m) => m < start);
2070
+ for (let i = 0; i < tokens.length; i++) {
2071
+ const t = tokens[i];
2072
+ const fn = own(AGGREGATE_WORDS, t.text);
2073
+ if (fn === void 0) continue;
2074
+ let f = null;
2075
+ if (t.used) {
2076
+ const pick = walkClaims.picks.find((k) => k.at[0] === i && k.at[1] === i);
2077
+ if (pick === void 0 || pick.phrase.field === void 0 || !valueAt(i, pick.phrase.at[1])) continue;
2078
+ walkClaims.picks.splice(walkClaims.picks.indexOf(pick), 1);
2079
+ f = {
2080
+ phrase: pick.phrase,
2081
+ span: pick.phrase.span,
2082
+ end: pick.phrase.at[1]
2083
+ };
2084
+ } else {
2085
+ let j = i + 1;
2086
+ while (!(tokens[j]?.used ?? true) && (tokens[j]?.text === "of" || tokens[j]?.text === "the")) j++;
2087
+ f = fieldAt(tokens, walkClaims, pack, rulings, j, false);
2088
+ if (f === null || VALUE_SUPERLATIVES.has(t.text) && !valueAt(i, f.end)) continue;
2089
+ }
2090
+ takeField(tokens, walkClaims, i, f);
2091
+ const claim = {
2092
+ span: tokens.slice(i, f.end + 1).map((x) => x.text).join(" "),
2093
+ word: t.text,
2094
+ fn,
2095
+ field: fieldRef(f)
2096
+ };
2097
+ for (let k = 0; k < tokens.length; k++) {
2098
+ const by = tokens[k];
2099
+ if (by.used || by.text !== "by" && by.text !== "per") continue;
2100
+ if (AUTHOR_VERBS.has(tokens[k - 1]?.text ?? "")) continue;
2101
+ const next = tokens[k + 1];
2102
+ if (next !== void 0 && !next.used && BUCKET_WORDS.has(next.text)) {
2103
+ by.used = next.used = true;
2104
+ claim.group = {
2105
+ span: `${by.text} ${next.text}`,
2106
+ bucket: next.text
2107
+ };
2108
+ break;
2109
+ }
2110
+ const g = fieldAt(tokens, walkClaims, pack, rulings, k + 1, false);
2111
+ if (g === null) continue;
2112
+ takeField(tokens, walkClaims, k, g);
2113
+ claim.group = {
2114
+ span: `${by.text} ${g.span}`,
2115
+ field: fieldRef(g)
2116
+ };
2117
+ break;
2118
+ }
2119
+ return claim;
2120
+ }
2121
+ return null;
2122
+ }
2123
+ /**
2124
+ * The seed field words or a field phrase name on `type`, or why there is none:
2125
+ * `doing` names the act when the field is on another type ("ordering").
2126
+ */
2127
+ function seedField(o, type, pack, rulings, doing) {
1860
2128
  const fields = own(pack.types, type)?.fields ?? {};
1861
- const walked = { reason: "ordering across a walk is not supported" };
2129
+ const walked = { reason: `${doing} across a walk is not supported` };
1862
2130
  let name;
1863
2131
  if (o.phrase !== void 0) {
1864
2132
  if (o.phrase.type !== type) return walked;
@@ -1870,9 +2138,169 @@ function orderField(o, type, pack, rulings) {
1870
2138
  }
1871
2139
  const f = name === null ? void 0 : fields[name];
1872
2140
  if (name === null || f === void 0) return { reason: `${type} has no field "${o.span}"` };
2141
+ return {
2142
+ name,
2143
+ f
2144
+ };
2145
+ }
2146
+ /** An aggregate claim read on `type`: its function and field, or drops saying why not. */
2147
+ function aggregateOn(c, type, pack, rulings) {
2148
+ const r = seedField({
2149
+ span: c.span,
2150
+ ...c.field
2151
+ }, type, pack, rulings, "aggregating");
2152
+ const wants = c.fn === "min" || c.fn === "max" ? ["number", "date"] : ["number"];
2153
+ const reason = "reason" in r ? r.reason : (r.f.kind === "scalar" || r.f.kind === "metadata") && wants.includes(r.f.valueType ?? "") ? null : `${c.word} needs a ${wants.join(" or ")} field; ${r.name} is a ${r.f.valueType ?? r.f.kind} field`;
2154
+ if (reason !== null || "reason" in r) return {
2155
+ dropped: [{
2156
+ span: c.span,
2157
+ reason: reason ?? "",
2158
+ kind: "filter"
2159
+ }],
2160
+ evidence: []
2161
+ };
2162
+ const out = {
2163
+ fn: c.fn,
2164
+ field: r.name,
2165
+ dropped: [],
2166
+ evidence: [{
2167
+ span: c.span,
2168
+ role: "aggregate",
2169
+ detail: `${c.fn} ${r.name}`
2170
+ }]
2171
+ };
2172
+ const exclude = c.field.phrase?.entry.exclude;
2173
+ if (exclude !== void 0) out.exclude = exclude;
2174
+ const g = c.group;
2175
+ if (g === void 0) return out;
2176
+ const drop = (why) => {
2177
+ out.dropped.push({
2178
+ span: g.span,
2179
+ reason: why,
2180
+ kind: "order"
2181
+ });
2182
+ return out;
2183
+ };
2184
+ if (g.bucket !== void 0) {
2185
+ if (g.bucket !== "day" && g.bucket !== "hour") return drop("the engine buckets by day or hour only");
2186
+ const field = own(rulings.timeField, type) ?? "createdAt";
2187
+ out.bucket = {
2188
+ field,
2189
+ by: g.bucket
2190
+ };
2191
+ out.evidence.push({
2192
+ span: g.span,
2193
+ role: "field",
2194
+ detail: `bucket ${field} by ${g.bucket}`
2195
+ });
2196
+ return out;
2197
+ }
2198
+ const gr = seedField({
2199
+ span: g.span,
2200
+ ...g.field
2201
+ }, type, pack, rulings, "grouping");
2202
+ if ("reason" in gr) return drop(gr.reason);
2203
+ const values = gr.f.valueType === "boolean" ? [true, false] : gr.f.kind === "scalar" ? gr.f.enum : void 0;
2204
+ if (values === void 0) return drop(`only enum and yes/no fields group; ${gr.name} is a ${gr.f.valueType ?? gr.f.kind} field`);
2205
+ if (values.length > MAX_GROUPS) return drop(`${gr.name} has ${values.length} values; grouping runs one frame per value, at most ${MAX_GROUPS}`);
2206
+ out.group = {
2207
+ field: gr.name,
2208
+ values
2209
+ };
2210
+ out.evidence.push({
2211
+ span: g.span,
2212
+ role: "field",
2213
+ detail: `group by ${gr.name}`
2214
+ });
2215
+ return out;
2216
+ }
2217
+ /** The seed field an ordering sorts by on `type`, the value one hop away, or why neither. */
2218
+ function orderField(o, type, pack, rulings) {
2219
+ const away = fieldAway(o, type, pack, rulings);
2220
+ if (away !== null) return "reason" in away ? away : hopOrder(o, type, away, pack, rulings);
2221
+ const r = seedField(o, type, pack, rulings, "ordering");
2222
+ if ("reason" in r) return r;
2223
+ const { name, f } = r;
2224
+ if (o.pick !== void 0) return { reason: pickReason(o.pick, `${type}.${name}`, type) };
1873
2225
  if (!((f.kind === "scalar" || f.kind === "metadata") && (f.valueType === "number" || f.valueType === "date" && o.numeric !== true))) return { reason: o.numeric === true ? `"most" needs a number field; ${name} is a ${f.valueType ?? f.kind} field` : `${name} is a ${f.valueType ?? f.kind} field; only number and date fields order` };
1874
2226
  return { field: name };
1875
2227
  }
2228
+ /** Why a pick word cannot order: it is not a direction, or there is one value per seed row. */
2229
+ function pickReason(pick, field, seed) {
2230
+ return pick.kind === "latest" ? `"${pick.span}" picks one of many rows; ${field} is one value per ${seed.toLowerCase()}` : `"${pick.span}" is not an ordering direction; say lowest or highest`;
2231
+ }
2232
+ /** The field an ordering names on a type other than `seed`, null when it is the seed's (or none). */
2233
+ function fieldAway(o, seed, pack, rulings) {
2234
+ if (o.phrase !== void 0) {
2235
+ const { type, field } = o.phrase;
2236
+ return type === void 0 || field === void 0 || type === seed ? null : {
2237
+ type,
2238
+ field
2239
+ };
2240
+ }
2241
+ const words = o.words ?? "";
2242
+ if (o.type !== void 0) {
2243
+ if (o.type === seed) return null;
2244
+ const field = fieldByWords(words, own(pack.types, o.type)?.fields ?? {}, rulings);
2245
+ return field === null ? { reason: `${o.type} has no field "${words}"` } : {
2246
+ type: o.type,
2247
+ field
2248
+ };
2249
+ }
2250
+ if (fieldByWords(words, own(pack.types, seed)?.fields ?? {}, rulings) !== null) return null;
2251
+ const on = Object.entries(pack.types).filter(([t, def]) => t !== seed && fieldByWords(words, def.fields, rulings) !== null).map(([t]) => t).sort();
2252
+ if (on.length === 0) return null;
2253
+ if (on.length > 1) return { reason: `"${words}" names a field on several types: ${on.join(", ")}` };
2254
+ const type = on[0];
2255
+ return {
2256
+ type,
2257
+ field: fieldByWords(words, own(pack.types, type)?.fields ?? {}, rulings)
2258
+ };
2259
+ }
2260
+ /**
2261
+ * The `_agg` an ordering by `<type>.<field>` sorts the seed by, over the one
2262
+ * crossRef hop between them. Out to one row, its value; in from many, a pick:
2263
+ * the asked one ("latest", "lowest" …), else max for a descending order and
2264
+ * min for an ascending one.
2265
+ */
2266
+ function hopOrder(o, seed, to, pack, rulings) {
2267
+ const paths = findPaths(pack, seed, to.type);
2268
+ if (paths.length === 0) return { reason: `no crossRef path from ${seed} to ${to.type} within 3 hops` };
2269
+ if (paths.length > 1) return { reason: `several equally short paths from ${seed} to ${to.type}: ${paths.map((p) => pathLabel(pack.namespace, p)).join("; ")}` };
2270
+ const path = paths[0];
2271
+ if (path.length > 1) return { reason: `ordering across ${path.length} hops is not supported; one hop only` };
2272
+ const f = own(pack.types, to.type)?.fields[to.field];
2273
+ const qualified = `${to.type}.${to.field}`;
2274
+ if (f === void 0 || f.kind !== "scalar" && f.kind !== "metadata" || f.valueType !== "number") return { reason: `ordering across a hop needs a number field; ${qualified} is a ${f?.valueType ?? f?.kind} field` };
2275
+ const h = path[0];
2276
+ if (o.pick !== void 0 && (h.dir === "out" || o.pick.kind !== "latest")) return { reason: pickReason(o.pick, qualified, seed) };
2277
+ const cap = to.field.charAt(0).toUpperCase() + to.field.slice(1);
2278
+ const exclude = o.phrase?.entry.exclude;
2279
+ const where = exclude !== void 0 ? { where: { NOT: exclude } } : {};
2280
+ if (h.dir === "out") return { hop: {
2281
+ name: `${to.type.charAt(0).toLowerCase()}${to.type.slice(1)}${cap}`,
2282
+ agg: {
2283
+ out: h.field,
2284
+ ...where,
2285
+ max: to.field
2286
+ },
2287
+ label: `${qualified} via ${h.field}`
2288
+ } };
2289
+ const kind = o.pick?.kind ?? o.phrase?.entry.pick ?? (o.dir === "desc" ? "max" : "min");
2290
+ const by = own(rulings.timeField, to.type) ?? "createdAt";
2291
+ return { hop: {
2292
+ name: `${kind}${to.type}${cap}`,
2293
+ agg: {
2294
+ in: `${pack.namespace}/${h.owner}.${h.field}`,
2295
+ ...where,
2296
+ ...kind === "latest" ? { latest: {
2297
+ by,
2298
+ value: to.field
2299
+ } } : { [kind]: to.field }
2300
+ },
2301
+ label: `${kind}(${qualified}) per ${seed.toLowerCase()}`
2302
+ } };
2303
+ }
1876
2304
  /** A clause's field name: the field itself, case-insensitively, then the rulings' and built-in aliases. */
1877
2305
  function resolveField(raw, fields, rulings) {
1878
2306
  const lower = raw.toLowerCase();
@@ -2292,19 +2720,21 @@ async function parseWithJudge(question, pack, ctx, judge, opts = {}) {
2292
2720
  const RECALL_K = 10;
2293
2721
  /**
2294
2722
  * The frame a candidate needs to run. A count is the server's `count: true`
2295
- * over the reading's where; `paged` is the rows frame with every projectable
2296
- * field, which a count falls back to when the server cannot count.
2723
+ * over the reading's where, an aggregate its `aggregate`; `paged` is the rows
2724
+ * frame with every projectable field, which a count falls back to when the
2725
+ * server cannot count.
2297
2726
  */
2298
- function executable(c, pack, paged = c.answer !== "count") {
2727
+ function executable(c, pack, paged = c.answer !== "count" && c.answer !== "aggregate") {
2299
2728
  const [key, value] = Object.entries(c.frame)[0];
2300
2729
  const { count: _count, ...params } = value.params;
2301
2730
  if (!paged) {
2302
2731
  const { orderBy: _o, limit: _l, derive: _d, ...counted } = params;
2732
+ const shaped = c.answer === "aggregate" ? counted : {
2733
+ ...counted,
2734
+ count: true
2735
+ };
2303
2736
  return { [key]: {
2304
- params: {
2305
- ...counted,
2306
- count: true
2307
- },
2737
+ params: shaped,
2308
2738
  fields: { id: true }
2309
2739
  } };
2310
2740
  }
@@ -2312,7 +2742,10 @@ function executable(c, pack, paged = c.answer !== "count") {
2312
2742
  for (const [name, f] of Object.entries(own(pack.types, c.type)?.fields ?? {})) if (f.kind !== "metadata") fields[name] = true;
2313
2743
  return { [key]: {
2314
2744
  params,
2315
- fields
2745
+ fields: {
2746
+ ...fields,
2747
+ ...value.fields
2748
+ }
2316
2749
  } };
2317
2750
  }
2318
2751
  /**
@@ -2361,6 +2794,7 @@ async function rows(c, source, question, http, deps, handoff, leftovers = []) {
2361
2794
  };
2362
2795
  let frame = executable(c, deps.pack);
2363
2796
  const key = Object.keys(frame)[0];
2797
+ if (c.aggregate !== void 0) return aggregate(c, frame, key, source, http, deps, dropped, handoff);
2364
2798
  let env = await deps.engine.query(frame, http);
2365
2799
  const refused = (env.errors ?? []).some((e) => COUNT_REFUSED.has(e.code ?? ""));
2366
2800
  const paging = c.answer === "count" && !(key in (env.data ?? {})) && refused;
@@ -2389,6 +2823,70 @@ async function rows(c, source, question, http, deps, handoff, leftovers = []) {
2389
2823
  plan: mergePlan(c.plan, env._diagnostics?.[key]?.plan)
2390
2824
  };
2391
2825
  }
2826
+ /**
2827
+ * An aggregate answer: the engine's one frame, or, grouped by a field the
2828
+ * engine cannot group, one frame per value of it.
2829
+ */
2830
+ async function aggregate(c, frame, key, source, http, deps, dropped, handoff) {
2831
+ const { fn, field, group } = c.aggregate;
2832
+ const params = frame[key]?.params;
2833
+ const errors = [];
2834
+ let data;
2835
+ let plan;
2836
+ if (group === void 0) {
2837
+ const env = await deps.engine.query(frame, http);
2838
+ errors.push(...env.errors ?? []);
2839
+ data = env.data !== void 0 && key in env.data ? env.data[key] : void 0;
2840
+ plan = env._diagnostics?.[key]?.plan;
2841
+ } else {
2842
+ const keys = [...group.values, null];
2843
+ const values = await Promise.all(keys.map(async (v) => {
2844
+ if (isAborted(http)) return void 0;
2845
+ const one = { [group.field]: { eq: v } };
2846
+ const where = params.where === void 0 ? one : { AND: [params.where, one] };
2847
+ const env = await deps.engine.query({ [key]: {
2848
+ params: {
2849
+ ...params,
2850
+ where
2851
+ },
2852
+ fields: { id: true }
2853
+ } }, http);
2854
+ errors.push(...env.errors ?? []);
2855
+ return (env.data?.[key])?.groups?.[0]?.value;
2856
+ }));
2857
+ data = values.some((v) => v === void 0) ? void 0 : { groups: keys.map((k, i) => ({
2858
+ key: k,
2859
+ value: values[i]
2860
+ })).filter((g) => g.key !== null || g.value !== null) };
2861
+ }
2862
+ const bucket = params.bucket;
2863
+ const by = group?.field ?? bucket?.by;
2864
+ const rows = data?.groups;
2865
+ const result = rows === void 0 ? void 0 : {
2866
+ fn,
2867
+ field,
2868
+ ...by !== void 0 ? {
2869
+ by,
2870
+ groups: rows.map((g) => ({
2871
+ key: g.bucket ?? g.key,
2872
+ value: g.value
2873
+ }))
2874
+ } : { value: rows[0]?.value ?? null },
2875
+ ...data?.truncated === true ? { truncated: true } : {}
2876
+ };
2877
+ return {
2878
+ kind: "rows",
2879
+ frame,
2880
+ answer: c.answer,
2881
+ data,
2882
+ ...result !== void 0 ? { aggregate: result } : {},
2883
+ ...errors.length > 0 ? { errors } : {},
2884
+ source,
2885
+ ...handoff !== void 0 ? { handoff } : {},
2886
+ dropped,
2887
+ plan: mergePlan(c.plan, plan)
2888
+ };
2889
+ }
2392
2890
  const MAX_COUNT_PAGES = 1e3;
2393
2891
  /** The population a count candidate matches: `seen` rows from page one, then id-only pages after its cursor. */
2394
2892
  async function countRest(frame, key, seen, first, http, deps) {
package/dist/bootstrap.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as bootstrap, t as NlBootstrapConfigSchema } from "./bootstrap-DbMpquDD.js";
1
+ import { n as bootstrap, t as NlBootstrapConfigSchema } from "./bootstrap-C01XZHK8.js";
2
2
 
3
3
  export { NlBootstrapConfigSchema, bootstrap, bootstrap as default };
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-DbMpquDD.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-C01XZHK8.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 };
@@ -25,8 +25,10 @@ export interface ParseContext {
25
25
  export type Evidence = NlEvidence;
26
26
  export interface Candidate {
27
27
  type: string;
28
+ /** `fields` carries only what the reading adds to the projection: a hop ordering's `_agg`. */
28
29
  frame: Record<string, {
29
30
  params: Record<string, unknown>;
31
+ fields?: Record<string, unknown>;
30
32
  }>;
31
33
  answer: string;
32
34
  evidence: Evidence[];
@@ -41,6 +43,18 @@ export interface Candidate {
41
43
  * comparison: a dropped filter would change its answer, so it is `unknown`.
42
44
  */
43
45
  strict: boolean;
46
+ /**
47
+ * An aggregate answer: `fn` of `field`. `group` is a field grouping the
48
+ * engine cannot express, run as one aggregate per value.
49
+ */
50
+ aggregate?: {
51
+ fn: AggregateFn;
52
+ field: string;
53
+ group?: {
54
+ field: string;
55
+ values: (string | boolean)[];
56
+ };
57
+ };
44
58
  }
45
59
  export type ParseStatus = NlParseStatus;
46
60
  export interface ParseResult {
@@ -53,4 +67,6 @@ export interface ParseResult {
53
67
  reason?: string;
54
68
  }
55
69
  export declare function parseQuestion(question: string, pack: NamespacePack, ctx: ParseContext): ParseResult;
70
+ type AggregateFn = 'avg' | 'sum' | 'min' | 'max';
71
+ export {};
56
72
  //# 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,EAAa,MAAM,kBAAkB,CAAC;AAgBjE,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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CAAC;IACtB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAiHD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,YAAY,GAChB,WAAW,CAsXb;AA2oBD,KAAK,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC"}
@@ -62,6 +62,7 @@ export interface WalkClaims {
62
62
  derives: PhraseClaim[];
63
63
  dropped: Dropped[];
64
64
  }
65
+ export declare const PICK_WORDS: Record<string, PickClaim['kind']>;
65
66
  /**
66
67
  * Claims field phrases, pick words, "by <derive>" and comparisons. Only a
67
68
  * namespace that declares `fieldPhrases` composes walks, so nothing changes
@@ -1 +1 @@
1
- {"version":3,"file":"walks.d.ts","sourceRoot":"","sources":["../../src/parse/walks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAc,GAAG,UAAU,CAMhG;AAED,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,IAAI,GAAG,KAAK,CAAC;IAClB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,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nB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,4EAA4E;IAC5E,UAAU,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,MAAM,EAAE,OAAO,CAAC;IAChB,iFAAiF;IACjF,MAAM,EAAE,OAAO,CAAC;IAChB,uFAAuF;IACvF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,CAAC;CACxE;AAOD,oFAAoF;AACpF,wBAAgB,KAAK,CACnB,KAAK,EAAE,IAAI,EAAE,GACZ;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,UAAU,EAAE,CAAA;CAAE,GAAG,IAAI,CAU/D;AAWD,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,QAAQ,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAsW3E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnmal-ai/substrate-nl",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.15",
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-alpha.14",
41
- "@mnmal-ai/substrate-config": "1.0.0-alpha.14",
40
+ "@mnmal-ai/substrate": "1.0.0-alpha.15",
41
+ "@mnmal-ai/substrate-config": "1.0.0-alpha.15",
42
42
  "@types/node": "^26.6.4",
43
43
  "tsdown": "^0.23.0",
44
44
  "typescript": "^7.0.2",