@mnmal-ai/substrate-nl 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +5 -1
- package/dist/access.d.ts +5 -1
- package/dist/access.d.ts.map +1 -1
- package/dist/ask/encode.d.ts +6 -5
- package/dist/ask/encode.d.ts.map +1 -1
- package/dist/ask/run.d.ts +8 -1
- package/dist/ask/run.d.ts.map +1 -1
- package/dist/bootstrap-BPLe_YWE.js +3706 -0
- package/dist/bootstrap.js +1 -1
- package/dist/index.js +1 -1
- package/dist/judge/judge.d.ts.map +1 -1
- package/dist/parse/compare.d.ts +26 -0
- package/dist/parse/compare.d.ts.map +1 -0
- package/dist/parse/parse.d.ts +26 -1
- package/dist/parse/parse.d.ts.map +1 -1
- package/dist/parse/time.d.ts +13 -5
- package/dist/parse/time.d.ts.map +1 -1
- package/dist/parse/walks.d.ts +127 -0
- package/dist/parse/walks.d.ts.map +1 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/rulings/schema.d.ts +3 -1
- package/dist/rulings/schema.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/bootstrap-BAz6il5S.js +0 -1826
package/README.md
CHANGED
|
@@ -4,7 +4,11 @@ Natural-language ask surface. A deterministic parser reads a question against a
|
|
|
4
4
|
|
|
5
5
|
## Contract
|
|
6
6
|
|
|
7
|
-
- `POST /substrate/v1/nl` with `{ namespace, question, project?, type? }` returns one of `rows`, `recall`, `clarify` or `refuse`, plus a `trail` of how it got there. Send `accept:
|
|
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: application/vnd.substrate.frames+json` for the same as a stream of length-prefixed JSON frames, each `{ event, data }` (`parsed`, `judging`, `judged`, then the outcome, then `done`; a failure mid-stream is an `error` event). Otherwise it is one JSON body. `+pack` is refused `406 not_acceptable`.
|
|
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` 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.
|
|
8
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`.
|
|
9
13
|
- NL is read-only: a mutation-shaped question is `refuse`, never executed.
|
|
10
14
|
|
package/dist/access.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Query, Schema, SubstrateRequest } from '@mnmal-ai/substrate/sdk';
|
|
1
|
+
import type { PlanClause, Query, Schema, SubstrateRequest } from '@mnmal-ai/substrate/sdk';
|
|
2
2
|
export interface NlEnvelope {
|
|
3
3
|
data?: Record<string, unknown>;
|
|
4
4
|
errors?: unknown[];
|
|
@@ -6,6 +6,10 @@ export interface NlEnvelope {
|
|
|
6
6
|
nextCursor?: string;
|
|
7
7
|
hasMore: boolean;
|
|
8
8
|
}>;
|
|
9
|
+
/** Per frame key; `plan` marks a walk read's clauses index-served or not. */
|
|
10
|
+
_diagnostics?: Record<string, {
|
|
11
|
+
plan?: PlanClause[];
|
|
12
|
+
}>;
|
|
9
13
|
}
|
|
10
14
|
export interface NlEngineAccess {
|
|
11
15
|
/** Live namespace schemas (with annotations). */
|
package/dist/access.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3F,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACxE,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,CAAC,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,cAAc;IAC7B,iDAAiD;IACjD,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,wFAAwF;IACxF,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC;IACrE,yFAAyF;IACzF,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACjE"}
|
package/dist/ask/encode.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { NlEvent, NlOutcome } from './events.js';
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
4
|
-
/**
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
2
|
+
/** One NL event as wire bytes. */
|
|
3
|
+
export type EncodeEvent = (name: string, data: unknown) => Uint8Array;
|
|
4
|
+
/** A length-prefixed JSON frame carrying `{ event, data }`, the client's `NlWireEvent`. */
|
|
5
|
+
export declare const frameBytes: EncodeEvent;
|
|
6
|
+
export declare const FRAMES_HEADERS: Record<string, string>;
|
|
7
|
+
export declare function toEventStream(events: AsyncGenerator<NlEvent>, encode: EncodeEvent, onCancel?: () => void, onError?: (err: unknown) => void): ReadableStream<Uint8Array>;
|
|
7
8
|
export declare function toJson(events: AsyncGenerator<NlEvent>): Promise<{
|
|
8
9
|
outcome: NlOutcome | null;
|
|
9
10
|
trail: NlEvent[];
|
package/dist/ask/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/ask/encode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/ask/encode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAQtD,kCAAkC;AAClC,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,UAAU,CAAC;AAEtE,2FAA2F;AAC3F,eAAO,MAAM,UAAU,EAAE,WAAyE,CAAC;AAEnG,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIjD,CAAC;AAEF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,EAC/B,MAAM,EAAE,WAAW,EACnB,QAAQ,CAAC,EAAE,MAAM,IAAI,EACrB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,GAC/B,cAAc,CAAC,UAAU,CAAC,CAuB5B;AAED,wBAAsB,MAAM,CAC1B,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,GAC9B,OAAO,CAAC;IAAE,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CAQ1D"}
|
package/dist/ask/run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PlanClause, type SubstrateRequest } from '@mnmal-ai/substrate/sdk';
|
|
2
2
|
import type { NlEngineAccess } from '../access.js';
|
|
3
3
|
import { type Judge } from '../judge/judge.js';
|
|
4
4
|
import type { ServedPack } from '../pack/service.js';
|
|
@@ -10,5 +10,12 @@ export interface AskDeps {
|
|
|
10
10
|
judgeTimeoutMs?: number;
|
|
11
11
|
now?: () => Date;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The parser's plan with the engine's `served`/`recommend` where the engine
|
|
15
|
+
* planned the same clause (matched by path: the engine's path is a prefix of
|
|
16
|
+
* the parser's labelled one, or, for a NOT, extends it). Parser-only clauses
|
|
17
|
+
* keep their entries; engine-only clauses are appended.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mergePlan(parsed: PlanClause[], engine: PlanClause[] | undefined): PlanClause[];
|
|
13
20
|
export declare function runAsk(req: AskRequest, http: SubstrateRequest, deps: AskDeps): AsyncGenerator<NlEvent>;
|
|
14
21
|
//# sourceMappingURL=run.d.ts.map
|
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,KAAK,
|
|
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"}
|