@mnmal-ai/substrate-nl 1.0.0-alpha.16 → 1.0.0-alpha.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 +2 -2
- package/dist/ask/run.d.ts.map +1 -1
- package/dist/{bootstrap-C01XZHK8.js → bootstrap-DZv1ymCg.js} +50 -36
- package/dist/bootstrap.js +1 -1
- package/dist/index.js +1 -1
- package/dist/parse/parse.d.ts.map +1 -1
- package/dist/parse/walks.d.ts +4 -4
- package/dist/parse/walks.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@ Natural-language ask surface. A deterministic parser reads a question against a
|
|
|
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
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`
|
|
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 `
|
|
10
|
+
- Grouping an aggregate: `by|per day|hour` groups by the type's time field, truncated to the day or hour through `groupBy` and `dateTrunc` (the `timeField` ruling; without one the grouping is dropped with a reason, since `createdAt` is row metadata and cannot sit inside an expression). `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 `select: { <name>: '_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.
|
|
12
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`.
|
|
13
13
|
- NL is read-only: a mutation-shaped question is `refuse`, never executed.
|
|
14
14
|
|
package/dist/ask/run.d.ts.map
CHANGED
|
@@ -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,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAyCD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,GAAG,UAAU,EAAE,CA2B9F;
|
|
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,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAyCD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,GAAG,UAAU,EAAE,CA2B9F;AAsOD,wBAAuB,MAAM,CAC3B,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,OAAO,GACZ,cAAc,CAAC,OAAO,CAAC,CAgJzB"}
|
|
@@ -56,13 +56,13 @@ const FieldPhraseSchema = z.object({
|
|
|
56
56
|
field: z.string().min(1).optional(),
|
|
57
57
|
value: z.unknown().optional(),
|
|
58
58
|
exclude: z.record(z.string(), z.unknown()).optional(),
|
|
59
|
-
|
|
59
|
+
select: z.union([z.object({ sub: z.tuple([z.string(), z.string()]) }).strict(), z.object({ div: z.tuple([z.string(), z.string()]) }).strict()]).optional(),
|
|
60
60
|
pick: z.enum([
|
|
61
61
|
"latest",
|
|
62
62
|
"max",
|
|
63
63
|
"min"
|
|
64
64
|
]).optional()
|
|
65
|
-
}).strict().refine((v) => v.field !== void 0 || v.value === void 0 && v.exclude === void 0, { message: "value and exclude require field" }).refine((v) => v.field !== void 0 || v.
|
|
65
|
+
}).strict().refine((v) => v.field !== void 0 || v.value === void 0 && v.exclude === void 0, { message: "value and exclude require field" }).refine((v) => v.field !== void 0 || v.select !== void 0 || v.pick !== void 0, { message: "an entry needs at least one of field, select, pick" });
|
|
66
66
|
const FieldPhrasesSchema = z.record(z.string(), FieldPhraseSchema).transform((rec, ctx) => {
|
|
67
67
|
const out = {};
|
|
68
68
|
for (const [phrase, entry] of Object.entries(rec)) {
|
|
@@ -117,7 +117,7 @@ function whereFields(w, out) {
|
|
|
117
117
|
/** Why a `fieldPhrases` entry does not fit the schema, or undefined. */
|
|
118
118
|
function phraseProblem(schema, e) {
|
|
119
119
|
const types = /* @__PURE__ */ new Set();
|
|
120
|
-
const refs = [...e.field !== void 0 ? [e.field] : [], ...e.
|
|
120
|
+
const refs = [...e.field !== void 0 ? [e.field] : [], ...e.select ? Object.values(e.select)[0] ?? [] : []];
|
|
121
121
|
for (const r of refs) {
|
|
122
122
|
const dot = r.indexOf(".");
|
|
123
123
|
const type = dot < 0 ? r : r.slice(0, dot);
|
|
@@ -529,7 +529,7 @@ const PICK_WORDS = {
|
|
|
529
529
|
lowest: "min",
|
|
530
530
|
cheapest: "min"
|
|
531
531
|
};
|
|
532
|
-
const
|
|
532
|
+
const COMPUTED_WORDS = /* @__PURE__ */ new Set([
|
|
533
533
|
"margin",
|
|
534
534
|
"spread",
|
|
535
535
|
"gap"
|
|
@@ -542,7 +542,7 @@ const take = (tokens, [s, e]) => {
|
|
|
542
542
|
for (let i = s; i <= e; i++) tokens[i].used = true;
|
|
543
543
|
};
|
|
544
544
|
/**
|
|
545
|
-
* Claims field phrases, pick words, "by <
|
|
545
|
+
* Claims field phrases, pick words, "by <computed>" and comparisons. Only a
|
|
546
546
|
* namespace that declares `fieldPhrases` composes walks, so nothing changes
|
|
547
547
|
* for one that does not.
|
|
548
548
|
*/
|
|
@@ -551,7 +551,7 @@ function claimWalkParts(tokens, rulings, glue) {
|
|
|
551
551
|
phrases: [],
|
|
552
552
|
compares: [],
|
|
553
553
|
picks: [],
|
|
554
|
-
|
|
554
|
+
computed: [],
|
|
555
555
|
dropped: []
|
|
556
556
|
};
|
|
557
557
|
const table = rulings.fieldPhrases;
|
|
@@ -591,11 +591,11 @@ function claimWalkParts(tokens, rulings, glue) {
|
|
|
591
591
|
}
|
|
592
592
|
}
|
|
593
593
|
for (const p of claims.phrases) {
|
|
594
|
-
if (p.entry.
|
|
594
|
+
if (p.entry.select === void 0) continue;
|
|
595
595
|
const by = tokens[p.at[0] - 1];
|
|
596
596
|
if (by?.text === "by" && !by.used) {
|
|
597
597
|
by.used = true;
|
|
598
|
-
claims.
|
|
598
|
+
claims.computed.push(p);
|
|
599
599
|
} else claims.dropped.push({
|
|
600
600
|
span: p.span,
|
|
601
601
|
reason: `"${p.span}" is a derived value; it orders a list only as "by ${p.span}"`,
|
|
@@ -605,7 +605,7 @@ function claimWalkParts(tokens, rulings, glue) {
|
|
|
605
605
|
tokens.forEach((t, i) => {
|
|
606
606
|
const next = tokens[i + 1];
|
|
607
607
|
if (t.text !== "by" || t.used || next === void 0 || next.used) return;
|
|
608
|
-
if (!
|
|
608
|
+
if (!COMPUTED_WORDS.has(next.text)) return;
|
|
609
609
|
t.used = true;
|
|
610
610
|
next.used = true;
|
|
611
611
|
claims.dropped.push({
|
|
@@ -940,8 +940,8 @@ function compose(input) {
|
|
|
940
940
|
}
|
|
941
941
|
const params = {};
|
|
942
942
|
const plan = [];
|
|
943
|
-
for (const d of claims.
|
|
944
|
-
const spec = d.entry.
|
|
943
|
+
for (const d of claims.computed) {
|
|
944
|
+
const spec = d.entry.select;
|
|
945
945
|
if (spec === void 0) continue;
|
|
946
946
|
const [op, operands] = Object.entries(spec)[0];
|
|
947
947
|
if (!operands.every((o) => o.startsWith(`${seed}.`))) {
|
|
@@ -953,24 +953,32 @@ function compose(input) {
|
|
|
953
953
|
continue;
|
|
954
954
|
}
|
|
955
955
|
const name = d.span.replace(/[^a-z0-9]+(.)?/g, (_, ch) => (ch ?? "").toUpperCase());
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
956
|
+
if (own(pack.types, seed)?.fields !== void 0 && Object.hasOwn(own(pack.types, seed)?.fields ?? {}, name)) {
|
|
957
|
+
dropped.push({
|
|
958
|
+
span: `by ${d.span}`,
|
|
959
|
+
reason: `its name "${name}" is also a field of ${seed}`,
|
|
960
|
+
kind: "order"
|
|
961
|
+
});
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
params.select = {
|
|
965
|
+
...params.select ?? {},
|
|
966
|
+
[name]: { [op]: operands.map((o) => o.slice(seed.length + 1)) }
|
|
959
967
|
};
|
|
960
|
-
params.orderBy = [{ [
|
|
968
|
+
params.orderBy = [{ [name]: "desc" }];
|
|
961
969
|
plan.push({
|
|
962
970
|
path: [
|
|
963
|
-
"
|
|
971
|
+
"select",
|
|
964
972
|
name,
|
|
965
973
|
`ruling:${d.span}`
|
|
966
974
|
],
|
|
967
|
-
kind: "
|
|
975
|
+
kind: "select",
|
|
968
976
|
served: false
|
|
969
977
|
}, {
|
|
970
978
|
path: [
|
|
971
979
|
"orderBy",
|
|
972
980
|
"0",
|
|
973
|
-
|
|
981
|
+
name,
|
|
974
982
|
"desc (default)"
|
|
975
983
|
],
|
|
976
984
|
kind: "order",
|
|
@@ -1592,8 +1600,13 @@ function assemble(type, a) {
|
|
|
1592
1600
|
dir: a.fieldOrder.dir,
|
|
1593
1601
|
limit
|
|
1594
1602
|
};
|
|
1603
|
+
else if ("hop" in r && Object.hasOwn(fields, r.hop.name)) fieldOrder.push({
|
|
1604
|
+
span: a.fieldOrder.span,
|
|
1605
|
+
reason: `its name "${r.hop.name}" is also a field of ${type}`,
|
|
1606
|
+
kind: "order"
|
|
1607
|
+
});
|
|
1595
1608
|
else if ("hop" in r) sortBy = {
|
|
1596
|
-
field:
|
|
1609
|
+
field: r.hop.name,
|
|
1597
1610
|
hop: r.hop,
|
|
1598
1611
|
dir: a.fieldOrder.dir,
|
|
1599
1612
|
limit
|
|
@@ -1628,7 +1641,7 @@ function assemble(type, a) {
|
|
|
1628
1641
|
kind: "filter"
|
|
1629
1642
|
}] : [],
|
|
1630
1643
|
...aggClaim !== null && derived ? [{
|
|
1631
|
-
span: `by ${Object.keys(a.composed?.params.
|
|
1644
|
+
span: `by ${Object.keys(a.composed?.params.select ?? {}).join(", ")}`,
|
|
1632
1645
|
reason: "grouping by a derived value is not supported",
|
|
1633
1646
|
kind: "order"
|
|
1634
1647
|
}] : []
|
|
@@ -1787,7 +1800,7 @@ function assemble(type, a) {
|
|
|
1787
1800
|
path: ["where", ...c.path]
|
|
1788
1801
|
})),
|
|
1789
1802
|
...yields,
|
|
1790
|
-
...(a.composed?.plan ?? []).filter((c) => aggClaim === null || c.kind !== "
|
|
1803
|
+
...(a.composed?.plan ?? []).filter((c) => aggClaim === null || c.kind !== "select"),
|
|
1791
1804
|
...sortBy?.hop !== void 0 ? [{
|
|
1792
1805
|
path: [
|
|
1793
1806
|
"fields",
|
|
@@ -1818,19 +1831,19 @@ function assemble(type, a) {
|
|
|
1818
1831
|
params.limit = 1;
|
|
1819
1832
|
}
|
|
1820
1833
|
if (sortBy !== null) {
|
|
1821
|
-
if (sortBy.hop !== void 0) params.
|
|
1834
|
+
if (sortBy.hop !== void 0) params.select = { [sortBy.hop.name]: `_agg.${sortBy.hop.name}` };
|
|
1822
1835
|
params.orderBy = [{ [sortBy.field]: sortBy.dir }];
|
|
1823
1836
|
params.limit = sortBy.limit;
|
|
1824
1837
|
}
|
|
1825
1838
|
Object.assign(params, a.composed?.params ?? {});
|
|
1826
1839
|
if (a.count && a.composed?.walked === true) params.count = true;
|
|
1827
1840
|
if (aggClaim !== null) {
|
|
1828
|
-
delete params.
|
|
1841
|
+
delete params.select;
|
|
1829
1842
|
delete params.orderBy;
|
|
1830
1843
|
}
|
|
1831
1844
|
if (agg?.fn !== void 0 && agg.field !== void 0) {
|
|
1832
1845
|
params.aggregate = { value: { [agg.fn]: agg.field } };
|
|
1833
|
-
if (agg.
|
|
1846
|
+
if (agg.dateGroup !== void 0) params.groupBy = { bucket: { dateTrunc: [{ lit: agg.dateGroup.by }, agg.dateGroup.field] } };
|
|
1834
1847
|
}
|
|
1835
1848
|
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";
|
|
1836
1849
|
return {
|
|
@@ -2103,7 +2116,7 @@ function claimAggregate(tokens, walkClaims, pack, rulings, mentions) {
|
|
|
2103
2116
|
by.used = next.used = true;
|
|
2104
2117
|
claim.group = {
|
|
2105
2118
|
span: `${by.text} ${next.text}`,
|
|
2106
|
-
|
|
2119
|
+
unit: next.text
|
|
2107
2120
|
};
|
|
2108
2121
|
break;
|
|
2109
2122
|
}
|
|
@@ -2181,17 +2194,17 @@ function aggregateOn(c, type, pack, rulings) {
|
|
|
2181
2194
|
});
|
|
2182
2195
|
return out;
|
|
2183
2196
|
};
|
|
2184
|
-
if (g.
|
|
2185
|
-
if (g.
|
|
2197
|
+
if (g.unit !== void 0) {
|
|
2198
|
+
if (g.unit !== "day" && g.unit !== "hour") return drop("only day and hour groupings are supported");
|
|
2186
2199
|
const field = own(rulings.timeField, type) ?? "createdAt";
|
|
2187
|
-
out.
|
|
2200
|
+
out.dateGroup = {
|
|
2188
2201
|
field,
|
|
2189
|
-
by: g.
|
|
2202
|
+
by: g.unit
|
|
2190
2203
|
};
|
|
2191
2204
|
out.evidence.push({
|
|
2192
2205
|
span: g.span,
|
|
2193
2206
|
role: "field",
|
|
2194
|
-
detail: `bucket ${field} by ${g.
|
|
2207
|
+
detail: `bucket ${field} by ${g.unit}`
|
|
2195
2208
|
});
|
|
2196
2209
|
return out;
|
|
2197
2210
|
}
|
|
@@ -2728,7 +2741,7 @@ function executable(c, pack, paged = c.answer !== "count" && c.answer !== "aggre
|
|
|
2728
2741
|
const [key, value] = Object.entries(c.frame)[0];
|
|
2729
2742
|
const { count: _count, ...params } = value.params;
|
|
2730
2743
|
if (!paged) {
|
|
2731
|
-
const { orderBy: _o, limit: _l,
|
|
2744
|
+
const { orderBy: _o, limit: _l, select: _s, ...counted } = params;
|
|
2732
2745
|
const shaped = c.answer === "aggregate" ? counted : {
|
|
2733
2746
|
...counted,
|
|
2734
2747
|
count: true
|
|
@@ -2766,7 +2779,7 @@ const COUNT_REFUSED = /* @__PURE__ */ new Set([
|
|
|
2766
2779
|
*/
|
|
2767
2780
|
function mergePlan(parsed, engine) {
|
|
2768
2781
|
if (engine === void 0) return parsed;
|
|
2769
|
-
const kindOf = (c) => c.kind === "
|
|
2782
|
+
const kindOf = (c) => c.kind === "select" && c.path[0] === "orderBy" ? "order" : c.kind;
|
|
2770
2783
|
const prefix = (a, b) => a.length <= b.length && a.every((x, i) => x === b[i]);
|
|
2771
2784
|
const used = /* @__PURE__ */ new Set();
|
|
2772
2785
|
return [...parsed.map((p) => {
|
|
@@ -2859,16 +2872,17 @@ async function aggregate(c, frame, key, source, http, deps, dropped, handoff) {
|
|
|
2859
2872
|
value: values[i]
|
|
2860
2873
|
})).filter((g) => g.key !== null || g.value !== null) };
|
|
2861
2874
|
}
|
|
2862
|
-
const
|
|
2863
|
-
const by = group?.field ??
|
|
2875
|
+
const trunc = params.groupBy?.bucket?.dateTrunc;
|
|
2876
|
+
const by = group?.field ?? trunc?.[0].lit;
|
|
2877
|
+
const short = (k) => typeof k === "string" && trunc !== void 0 ? k.slice(0, trunc[0].lit === "day" ? 10 : 13) : k;
|
|
2864
2878
|
const rows = data?.groups;
|
|
2865
2879
|
const result = rows === void 0 ? void 0 : {
|
|
2866
2880
|
fn,
|
|
2867
2881
|
field,
|
|
2868
2882
|
...by !== void 0 ? {
|
|
2869
2883
|
by,
|
|
2870
|
-
groups: rows.map((g) => ({
|
|
2871
|
-
key: g.bucket ?? g.key,
|
|
2884
|
+
groups: rows.filter((g) => trunc === void 0 || g.bucket !== null).map((g) => ({
|
|
2885
|
+
key: short(g.bucket ?? g.key),
|
|
2872
2886
|
value: g.value
|
|
2873
2887
|
}))
|
|
2874
2888
|
} : { value: rows[0]?.value ?? null },
|
package/dist/bootstrap.js
CHANGED
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-
|
|
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-DZv1ymCg.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":"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;AAsBjE,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,SAAS;IACxB,IAAI,EAAE,MAAM,CAA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AAC;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;AAiHD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,YAAY,GAChB,WAAW,CAsXb;AAkpBD,KAAK,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC"}
|
package/dist/parse/walks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Walk composition (typed edge walks spec §6). A question that names fields
|
|
3
3
|
* of other types through `fieldPhrases` rulings, compares them, windows them
|
|
4
|
-
* in time, picks one neighbour or orders by a declared
|
|
4
|
+
* in time, picks one neighbour or orders by a declared computed value, is read as
|
|
5
5
|
* walks from the seed type over the pack's declared crossRefs.
|
|
6
6
|
*
|
|
7
7
|
* Nothing here guesses. A part with no unique shortest crossRef path, or
|
|
@@ -59,12 +59,12 @@ export interface WalkClaims {
|
|
|
59
59
|
phrases: PhraseClaim[];
|
|
60
60
|
compares: CompareClaim[];
|
|
61
61
|
picks: PickClaim[];
|
|
62
|
-
|
|
62
|
+
computed: PhraseClaim[];
|
|
63
63
|
dropped: Dropped[];
|
|
64
64
|
}
|
|
65
65
|
export declare const PICK_WORDS: Record<string, PickClaim['kind']>;
|
|
66
66
|
/**
|
|
67
|
-
* Claims field phrases, pick words, "by <
|
|
67
|
+
* Claims field phrases, pick words, "by <computed>" and comparisons. Only a
|
|
68
68
|
* namespace that declares `fieldPhrases` composes walks, so nothing changes
|
|
69
69
|
* for one that does not.
|
|
70
70
|
*/
|
|
@@ -97,7 +97,7 @@ export interface Composed {
|
|
|
97
97
|
/** Clauses for the seed's where, after its own. */
|
|
98
98
|
parts: Part[];
|
|
99
99
|
params: Record<string, unknown>;
|
|
100
|
-
/** Plan clauses outside `where` (
|
|
100
|
+
/** Plan clauses outside `where` (select, orderBy). */
|
|
101
101
|
plan: PlanClause[];
|
|
102
102
|
dropped: Dropped[];
|
|
103
103
|
/** The time window was not bound to a walk: the seed takes it as before. */
|
|
@@ -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,CAAC;IACd,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;AAiBzB,iGAAiG;AACjG,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MA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2
2
|
"name": "@mnmal-ai/substrate-nl",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.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": {
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"zod": "^4.6.
|
|
36
|
+
"zod": "^4.6.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@biomejs/biome": "2.6.4",
|
|
40
|
-
"@mnmal-ai/substrate": "1.0.0-alpha.
|
|
41
|
-
"@mnmal-ai/substrate-config": "1.0.0-alpha.
|
|
40
|
+
"@mnmal-ai/substrate": "1.0.0-alpha.18",
|
|
41
|
+
"@mnmal-ai/substrate-config": "1.0.0-alpha.18",
|
|
42
42
|
"@types/node": "^26.6.4",
|
|
43
43
|
"tsdown": "^0.23.0",
|
|
44
44
|
"typescript": "^7.0.2",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@mnmal-ai/substrate": ">=1.0.0-alpha.11 <2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=26.
|
|
51
|
+
"node": ">=26.13.1"
|
|
52
52
|
},
|
|
53
53
|
"substrate": {
|
|
54
54
|
"tier": "kernel",
|