@mnmal-ai/substrate-nl 0.0.0-stage → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +37 -2
- package/config.schema.json +22 -0
- package/default-config.json +1 -0
- package/dist/access.d.ts +18 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/ask/encode.d.ts +11 -0
- package/dist/ask/encode.d.ts.map +1 -0
- package/dist/ask/events.d.ts +7 -0
- package/dist/ask/events.d.ts.map +1 -0
- package/dist/ask/run.d.ts +14 -0
- package/dist/ask/run.d.ts.map +1 -0
- package/dist/bootstrap-BpKUloR3.js +1821 -0
- package/dist/bootstrap.d.ts +18 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +3 -0
- package/dist/complete/complete.d.ts +19 -0
- package/dist/complete/complete.d.ts.map +1 -0
- package/dist/complete.js +157 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/judge/judge.d.ts +65 -0
- package/dist/judge/judge.d.ts.map +1 -0
- package/dist/judge/ollama.d.ts +20 -0
- package/dist/judge/ollama.d.ts.map +1 -0
- package/dist/own.d.ts +6 -0
- package/dist/own.d.ts.map +1 -0
- package/dist/pack/build.d.ts +17 -0
- package/dist/pack/build.d.ts.map +1 -0
- package/dist/pack/profile.d.ts +27 -0
- package/dist/pack/profile.d.ts.map +1 -0
- package/dist/pack/rulings.d.ts +9 -0
- package/dist/pack/rulings.d.ts.map +1 -0
- package/dist/pack/service.d.ts +28 -0
- package/dist/pack/service.d.ts.map +1 -0
- package/dist/pack/types.d.ts +21 -0
- package/dist/pack/types.d.ts.map +1 -0
- package/dist/pack/words.d.ts +7 -0
- package/dist/pack/words.d.ts.map +1 -0
- package/dist/parse/parse.d.ts +47 -0
- package/dist/parse/parse.d.ts.map +1 -0
- package/dist/parse/time.d.ts +13 -0
- package/dist/parse/time.d.ts.map +1 -0
- package/dist/plugin.d.ts +20 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/routes.d.ts +16 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/rulings/schema.d.ts +20 -0
- package/dist/rulings/schema.d.ts.map +1 -0
- package/package.json +62 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { NlEngineAccess } from './access.js';
|
|
3
|
+
export declare const NlBootstrapConfigSchema: z.ZodObject<{
|
|
4
|
+
judge: z.ZodOptional<z.ZodObject<{
|
|
5
|
+
baseUrl: z.ZodURL;
|
|
6
|
+
model: z.ZodString;
|
|
7
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
}, z.core.$strict>>;
|
|
9
|
+
rulings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<import("@mnmal-ai/substrate/sdk").NlNamespaceRulings, unknown, z.core.$ZodTypeInternals<import("@mnmal-ai/substrate/sdk").NlNamespaceRulings, unknown>>>>;
|
|
10
|
+
packTtlMs: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type NlBootstrapConfig = z.infer<typeof NlBootstrapConfigSchema>;
|
|
13
|
+
export interface NlHostDeps {
|
|
14
|
+
nlEngine: NlEngineAccess;
|
|
15
|
+
}
|
|
16
|
+
export declare const bootstrap: import("@mnmal-ai/substrate/sdk").KernelBootstrap<NlHostDeps>;
|
|
17
|
+
export default bootstrap;
|
|
18
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAalD,eAAO,MAAM,uBAAuB;;;;;;;;kBAMzB,CAAC;AAEZ,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,eAAO,MAAM,SAAS,+DAWpB,CAAC;eAGY,SAAS"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keystroke-speed completion over a served namespace pack. Pure, and imports
|
|
3
|
+
* types only, so the `@mnmal-ai/substrate-nl/complete` subpath runs in a browser
|
|
4
|
+
* or a TUI without pulling the plugin's server dependencies.
|
|
5
|
+
*/
|
|
6
|
+
import type { NamespaceRulings } from '../pack/rulings.js';
|
|
7
|
+
import type { NamespacePack } from '../pack/types.js';
|
|
8
|
+
export type CompletePack = NamespacePack & {
|
|
9
|
+
rulings?: NamespaceRulings;
|
|
10
|
+
};
|
|
11
|
+
export interface NlSuggestion {
|
|
12
|
+
replace: [start: number, end: number];
|
|
13
|
+
insert: string;
|
|
14
|
+
label: string;
|
|
15
|
+
detail?: string;
|
|
16
|
+
score: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function complete(draft: string, cursor: number, pack: CompletePack): NlSuggestion[];
|
|
19
|
+
//# sourceMappingURL=complete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../src/complete/complete.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE1E,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AA2ED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,CA2E1F"}
|
package/dist/complete.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
//#region src/complete/complete.ts
|
|
2
|
+
/** Own-key lookup: inherited names (`constructor`, `__proto__`) are not entries. Inlined so this module imports types only. */
|
|
3
|
+
const own = (rec, key) => rec !== void 0 && Object.hasOwn(rec, key) ? rec[key] : void 0;
|
|
4
|
+
const cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
5
|
+
const DSL_OPERATORS = {
|
|
6
|
+
gte: ">=",
|
|
7
|
+
lte: "<=",
|
|
8
|
+
gt: ">",
|
|
9
|
+
lt: "<",
|
|
10
|
+
between: "..",
|
|
11
|
+
neq: "!",
|
|
12
|
+
contains: "~"
|
|
13
|
+
};
|
|
14
|
+
const OPERATOR_FORM = /^[<>!~.]/;
|
|
15
|
+
const isHigh = (u) => u >= 55296 && u <= 56319;
|
|
16
|
+
const isLow = (u) => u >= 56320 && u <= 57343;
|
|
17
|
+
/** The token around `cursor`: [start, end). Whitespace-delimited; a trailing `field:` stays one token. */
|
|
18
|
+
function tokenAt(draft, cursor) {
|
|
19
|
+
let c = Number.isFinite(cursor) ? Math.max(0, Math.min(Math.trunc(cursor), draft.length)) : 0;
|
|
20
|
+
if (c > 0 && c < draft.length && isHigh(draft.charCodeAt(c - 1)) && isLow(draft.charCodeAt(c))) c--;
|
|
21
|
+
let start = c;
|
|
22
|
+
while (start > 0 && !/\s/.test(draft[start - 1])) start--;
|
|
23
|
+
let end = c;
|
|
24
|
+
while (end < draft.length && !/\s/.test(draft[end])) end++;
|
|
25
|
+
return [start, end];
|
|
26
|
+
}
|
|
27
|
+
function typeIn(words, pack) {
|
|
28
|
+
const aliases = pack.rulings?.typeAliases ?? {};
|
|
29
|
+
for (const w of words) {
|
|
30
|
+
const lw = w.toLowerCase();
|
|
31
|
+
const aliased = own(aliases, lw);
|
|
32
|
+
if (aliased !== void 0) return aliased;
|
|
33
|
+
for (const t of Object.values(pack.types)) if (t.phrases.includes(lw)) return t.name;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function rank(prefix, pool, replace) {
|
|
37
|
+
const p = prefix.toLowerCase();
|
|
38
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const x of pool) {
|
|
41
|
+
const k = x.insert.toLowerCase();
|
|
42
|
+
if (seen.has(x.insert) || k === p) continue;
|
|
43
|
+
const score = k.startsWith(p) ? 2 : p.length > 0 && k.includes(p) ? 1 : 0;
|
|
44
|
+
if (score === 0) continue;
|
|
45
|
+
seen.add(x.insert);
|
|
46
|
+
out.push({
|
|
47
|
+
replace,
|
|
48
|
+
insert: x.insert,
|
|
49
|
+
label: x.label,
|
|
50
|
+
...x.detail !== void 0 ? { detail: x.detail } : {},
|
|
51
|
+
score
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return out.sort((a, b) => b.score - a.score || a.insert.length - b.insert.length || cmp(a.insert, b.insert));
|
|
55
|
+
}
|
|
56
|
+
function complete(draft, cursor, pack) {
|
|
57
|
+
if (draft.trim() === "") return [];
|
|
58
|
+
const [start, end] = tokenAt(draft, cursor);
|
|
59
|
+
const token = draft.slice(start, end);
|
|
60
|
+
const type = typeIn(draft.slice(0, start).split(/\s+/).filter((w) => w !== ""), pack);
|
|
61
|
+
const colon = token.indexOf(":");
|
|
62
|
+
if (colon > 0 && type !== void 0) {
|
|
63
|
+
const typed = token.slice(0, colon);
|
|
64
|
+
const fieldName = own(pack.rulings?.fieldAliases, typed) ?? typed;
|
|
65
|
+
const f = own(own(pack.types, type)?.fields, fieldName);
|
|
66
|
+
if (f === void 0) return [];
|
|
67
|
+
const valueStart = start + colon + 1;
|
|
68
|
+
const pool = [
|
|
69
|
+
...(f.enum ?? []).map((v) => ({
|
|
70
|
+
insert: v,
|
|
71
|
+
label: v
|
|
72
|
+
})),
|
|
73
|
+
...Object.entries(f.aliases ?? {}).map(([alias, canon]) => ({
|
|
74
|
+
insert: alias,
|
|
75
|
+
label: `${alias} → ${canon}`
|
|
76
|
+
})),
|
|
77
|
+
...Object.entries(pack.values).filter(([, refs]) => refs.some((r) => r.type === type && r.field === fieldName)).map(([v, refs]) => ({
|
|
78
|
+
insert: refs.find((r) => r.type === type)?.value ?? v,
|
|
79
|
+
label: v
|
|
80
|
+
}))
|
|
81
|
+
];
|
|
82
|
+
const prefix = token.slice(colon + 1);
|
|
83
|
+
if (OPERATOR_FORM.test(prefix)) return [];
|
|
84
|
+
if (prefix === "") {
|
|
85
|
+
const replace = [valueStart, end];
|
|
86
|
+
const seen = /* @__PURE__ */ new Set();
|
|
87
|
+
const values = pool.filter((x) => !seen.has(x.insert) && seen.add(x.insert)).sort((a, b) => cmp(a.insert, b.insert)).map((x) => ({
|
|
88
|
+
replace,
|
|
89
|
+
insert: x.insert,
|
|
90
|
+
label: x.label,
|
|
91
|
+
score: 2
|
|
92
|
+
}));
|
|
93
|
+
const ops = f.operators.flatMap((op) => {
|
|
94
|
+
const form = own(DSL_OPERATORS, op);
|
|
95
|
+
return form === void 0 ? [] : [{
|
|
96
|
+
replace,
|
|
97
|
+
insert: form,
|
|
98
|
+
label: form,
|
|
99
|
+
detail: op,
|
|
100
|
+
score: 1
|
|
101
|
+
}];
|
|
102
|
+
});
|
|
103
|
+
return [...values, ...ops];
|
|
104
|
+
}
|
|
105
|
+
return rank(prefix, pool, [valueStart, end]);
|
|
106
|
+
}
|
|
107
|
+
if (token === "") return [];
|
|
108
|
+
const pool = [];
|
|
109
|
+
if (type === void 0) {
|
|
110
|
+
for (const t of Object.values(pack.types)) for (const ph of t.phrases) pool.push({
|
|
111
|
+
insert: ph,
|
|
112
|
+
label: ph,
|
|
113
|
+
detail: `${pack.namespace}/${t.name}`
|
|
114
|
+
});
|
|
115
|
+
for (const [alias, t] of Object.entries(pack.rulings?.typeAliases ?? {})) pool.push({
|
|
116
|
+
insert: alias,
|
|
117
|
+
label: alias,
|
|
118
|
+
detail: `${pack.namespace}/${t}`
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
for (const f of Object.values(own(pack.types, type)?.fields ?? {})) {
|
|
122
|
+
if (f.kind === "metadata") continue;
|
|
123
|
+
pool.push({
|
|
124
|
+
insert: `${f.name}:`,
|
|
125
|
+
label: f.name,
|
|
126
|
+
detail: f.operators.join(" ")
|
|
127
|
+
});
|
|
128
|
+
for (const ph of f.phrases) if (ph !== f.name) pool.push({
|
|
129
|
+
insert: `${f.name}:`,
|
|
130
|
+
label: ph,
|
|
131
|
+
detail: f.name
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
for (const [alias, canon] of Object.entries(pack.rulings?.fieldAliases ?? {})) pool.push({
|
|
135
|
+
insert: `${alias}:`,
|
|
136
|
+
label: `${alias} → ${canon}`,
|
|
137
|
+
detail: canon
|
|
138
|
+
});
|
|
139
|
+
for (const [word, preds] of Object.entries(pack.rulings?.valueAliases ?? {})) {
|
|
140
|
+
const p = preds[0];
|
|
141
|
+
if (!/\s/.test(word) && p !== void 0) pool.push({
|
|
142
|
+
insert: word,
|
|
143
|
+
label: word,
|
|
144
|
+
detail: `${p.type}.${p.field}`
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const [v, refs] of Object.entries(pack.values)) if (refs.some((r) => r.field === "project")) pool.push({
|
|
149
|
+
insert: refs[0]?.value ?? v,
|
|
150
|
+
label: refs[0]?.value ?? v,
|
|
151
|
+
detail: "project"
|
|
152
|
+
});
|
|
153
|
+
return rank(token, pool, [start, end]);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
export { complete };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type { NlEngineAccess, NlEnvelope } from './access.js';
|
|
2
|
+
export type { AskRequest, NlEvent, NlOutcome } from './ask/events.js';
|
|
3
|
+
export { runAsk } from './ask/run.js';
|
|
4
|
+
export type { NlBootstrapConfig, NlHostDeps } from './bootstrap.js';
|
|
5
|
+
export { bootstrap, NlBootstrapConfigSchema } from './bootstrap.js';
|
|
6
|
+
export type { CompletePack, NlSuggestion } from './complete/complete.js';
|
|
7
|
+
export { complete } from './complete/complete.js';
|
|
8
|
+
export type { Judge } from './judge/judge.js';
|
|
9
|
+
export { parseWithJudge } from './judge/judge.js';
|
|
10
|
+
export { OllamaJudge } from './judge/ollama.js';
|
|
11
|
+
export { buildNamespacePack } from './pack/build.js';
|
|
12
|
+
export { profileNamespace } from './pack/profile.js';
|
|
13
|
+
export type { NamespaceRulings } from './pack/rulings.js';
|
|
14
|
+
export type { ServedPack } from './pack/service.js';
|
|
15
|
+
export { PackService } from './pack/service.js';
|
|
16
|
+
export type { NamespacePack } from './pack/types.js';
|
|
17
|
+
export { parseQuestion } from './parse/parse.js';
|
|
18
|
+
export type { NlPluginConfig } from './plugin.js';
|
|
19
|
+
export { CONTRACT_VERSION, createNlPlugin } from './plugin.js';
|
|
20
|
+
export type { NlRouteDeps } from './routes.js';
|
|
21
|
+
export { askHandler, packHandler } from './routes.js';
|
|
22
|
+
export { mergeRulings, NamespaceRulingsSchema, readRulings } from './rulings/schema.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/D,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { a as askHandler, c as profileNamespace, d as mergeRulings, f as readRulings, g as parseQuestion, h as parseWithJudge, i as createNlPlugin, l as buildNamespacePack, m as runAsk, n as bootstrap, o as packHandler, p as OllamaJudge, r as CONTRACT_VERSION, s as PackService, t as NlBootstrapConfigSchema, u as NamespaceRulingsSchema } from "./bootstrap-BpKUloR3.js";
|
|
2
|
+
import { complete } from "./complete.js";
|
|
3
|
+
|
|
4
|
+
export { CONTRACT_VERSION, NamespaceRulingsSchema, NlBootstrapConfigSchema, OllamaJudge, PackService, askHandler, bootstrap, buildNamespacePack, complete, createNlPlugin, mergeRulings, packHandler, parseQuestion, parseWithJudge, profileNamespace, readRulings, runAsk };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier 1b: a constrained judge for what the parser escalates. The model never
|
|
3
|
+
* writes a frame. It picks ONE choice from options generated for this
|
|
4
|
+
* question (a candidate, a type, a word-to-field binding, recall, clarify,
|
|
5
|
+
* refuse), its output constrained to those options by a JSON schema. The
|
|
6
|
+
* choice is then applied deterministically and the parser runs again, so
|
|
7
|
+
* every frame that comes out is still the parser's, tied to the words.
|
|
8
|
+
*/
|
|
9
|
+
import type { NlJudgeAction, NlJudgeChoice, NlJudgeStep } from '@mnmal-ai/substrate/sdk';
|
|
10
|
+
import type { NamespaceRulings } from '../pack/rulings.js';
|
|
11
|
+
import type { NamespacePack } from '../pack/types.js';
|
|
12
|
+
import { type Candidate, type ParseContext, type ParseResult } from '../parse/parse.js';
|
|
13
|
+
export type JudgeAction = NlJudgeAction;
|
|
14
|
+
export type JudgeChoice = NlJudgeChoice;
|
|
15
|
+
export interface JudgePrompt {
|
|
16
|
+
system: string;
|
|
17
|
+
user: string;
|
|
18
|
+
/** JSON schema the reply must satisfy; every enum is drawn from this question. */
|
|
19
|
+
schema: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** Transport for one constrained decision. Returns the parsed JSON reply. */
|
|
22
|
+
export interface Judge {
|
|
23
|
+
decide(prompt: JudgePrompt, signal?: AbortSignal): Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
export type JudgeStep = NlJudgeStep;
|
|
26
|
+
export type JudgedResult = {
|
|
27
|
+
status: 'resolved';
|
|
28
|
+
candidate: Candidate;
|
|
29
|
+
trail: JudgeStep[];
|
|
30
|
+
} | {
|
|
31
|
+
status: 'recall';
|
|
32
|
+
query: string;
|
|
33
|
+
trail: JudgeStep[];
|
|
34
|
+
} | {
|
|
35
|
+
status: 'clarify' | 'refuse';
|
|
36
|
+
reason: string;
|
|
37
|
+
trail: JudgeStep[];
|
|
38
|
+
} | {
|
|
39
|
+
status: 'escalated';
|
|
40
|
+
result: ParseResult;
|
|
41
|
+
trail: JudgeStep[];
|
|
42
|
+
};
|
|
43
|
+
/** Build the options, the prompt and the schema for one escalated parse. */
|
|
44
|
+
export declare function buildJudgePrompt(question: string, result: ParseResult, pack: NamespacePack, rulings?: NamespaceRulings, rejected?: string[]): JudgePrompt;
|
|
45
|
+
/** Check a reply against the options it was offered. */
|
|
46
|
+
export declare function checkChoice(reply: unknown, prompt: JudgePrompt): JudgeChoice | string;
|
|
47
|
+
export interface JudgeOptions {
|
|
48
|
+
/** Judge rounds before giving up. Default 3. */
|
|
49
|
+
rounds?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Does any row of `type` match `where`? A binding is applied only when its
|
|
52
|
+
* value occurs in the data: a bound value that matches nothing is the
|
|
53
|
+
* judge reading a word as data that is not data. Omitted, bindings are
|
|
54
|
+
* checked against the schema only.
|
|
55
|
+
*/
|
|
56
|
+
exists?: (type: string, where: Record<string, unknown>) => Promise<boolean>;
|
|
57
|
+
/** Aborts the in-flight judge call. */
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Parse; while the parse is not resolved, ask the judge and apply its choice.
|
|
62
|
+
* A refused, clarified or resolved parse never reaches the model.
|
|
63
|
+
*/
|
|
64
|
+
export declare function parseWithJudge(question: string, pack: NamespacePack, ctx: ParseContext, judge: Judge, opts?: JudgeOptions): Promise<JudgedResult>;
|
|
65
|
+
//# sourceMappingURL=judge.d.ts.map
|
|
@@ -0,0 +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,EAAE,CAAA;CAAE,GAChE;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,GACvD;IAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,GACpE;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AAarE,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,aAAa,EACnB,OAAO,GAAE,gBAAqB,EAC9B,QAAQ,GAAE,MAAM,EAAO,GACtB,WAAW,CAqFb;AAED,wDAAwD;AACxD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,MAAM,CAkBrF;AAkBD,MAAM,WAAW,YAAY;IAC3B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E,uCAAuC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAmCD;;;GAGG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,EACZ,IAAI,GAAE,YAAiB,GACtB,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Judge, JudgePrompt } from './judge.js';
|
|
2
|
+
export interface OllamaJudgeConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
model: string;
|
|
5
|
+
/** Abort a call after this long. Default 60s. */
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Ollama's native chat endpoint with `format` set to the question's schema,
|
|
10
|
+
* so decoding cannot leave the offered options. Thinking off, temperature 0
|
|
11
|
+
* and a fixed seed. Sends no `num_ctx` / `keep_alive`: Ollama shares one
|
|
12
|
+
* runner per model, and differing options force a reload for every client
|
|
13
|
+
* (see substrate-embedder's README).
|
|
14
|
+
*/
|
|
15
|
+
export declare class OllamaJudge implements Judge {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(config: OllamaJudgeConfig);
|
|
18
|
+
decide(prompt: JudgePrompt, signal?: AbortSignal): Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ollama.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../src/judge/ollama.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,qBAAa,WAAY,YAAW,KAAK;;IAGvC,YAAY,MAAM,EAAE,iBAAiB,EAEpC;IAEK,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAqBxE;CACF"}
|
package/dist/own.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lookup into a plain-object record by a user-supplied key. Inherited
|
|
3
|
+
* names (`constructor`, `__proto__`, `toString`) are not entries.
|
|
4
|
+
*/
|
|
5
|
+
export declare function own<T>(rec: Record<string, T> | undefined, key: string): T | undefined;
|
|
6
|
+
//# sourceMappingURL=own.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"own.d.ts","sourceRoot":"","sources":["../src/own.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAErF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Schema } from '@mnmal-ai/substrate/sdk';
|
|
2
|
+
import type { NamespacePack, NamespaceProfile } from './types.js';
|
|
3
|
+
export interface BuildPackInput {
|
|
4
|
+
namespace: string;
|
|
5
|
+
schema: Schema;
|
|
6
|
+
/** The schema's operator table, keyed `scalar.<type>`, `crossRef`, `list`. */
|
|
7
|
+
operators: Record<string, readonly string[]>;
|
|
8
|
+
profile?: NamespaceProfile;
|
|
9
|
+
/** Safety cap: a profiled field with more distinct values is not used. Default 1000. */
|
|
10
|
+
maxDistinct?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the NL vocabulary for one namespace. Pure: the same schema, operator
|
|
14
|
+
* table and profile always give byte-identical output, with sorted keys.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildNamespacePack(input: BuildPackInput): NamespacePack;
|
|
17
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/pack/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAChE,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,CA8CvE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Schema } from '@mnmal-ai/substrate/sdk';
|
|
2
|
+
import type { NamespaceProfile } from './types.js';
|
|
3
|
+
/** One page of rows for `type`, projecting `fields`. */
|
|
4
|
+
export type ReadPage = (type: string, fields: string[], cursor?: string) => Promise<{
|
|
5
|
+
rows: Record<string, unknown>[];
|
|
6
|
+
nextCursor: string | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
export interface ProfileInput {
|
|
9
|
+
schema: Schema;
|
|
10
|
+
read: ReadPage;
|
|
11
|
+
/** Stop collecting a field past this many distinct values. Default 1000. */
|
|
12
|
+
maxDistinct?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Rows read per type. Default 10 000. The pack is built on the request
|
|
15
|
+
* path, per caller, so an unbounded read would be a full scan of every type.
|
|
16
|
+
* A field's labels that appear only past the budget are left out of its
|
|
17
|
+
* vocabulary.
|
|
18
|
+
*/
|
|
19
|
+
maxRows?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Distinct values of every indexed string field (and indexed list-of-string
|
|
23
|
+
* field) in the namespace, reading up to `maxRows` rows per type. A field that
|
|
24
|
+
* passes `maxDistinct` is marked truncated and stops growing.
|
|
25
|
+
*/
|
|
26
|
+
export declare function profileNamespace(input: ProfileInput): Promise<NamespaceProfile>;
|
|
27
|
+
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -0,0 +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,wDAAwD;AACxD,MAAM,MAAM,QAAQ,GAAG,CACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,CAAC,EAAE,MAAM,KACZ,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,CAAC;AAElF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA+CrF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator rulings for one namespace, kept as data: what the schema cannot
|
|
3
|
+
* say about how people talk about it. The pack is generated; rulings are
|
|
4
|
+
* curated, and they win over the pack where they speak.
|
|
5
|
+
*/
|
|
6
|
+
import type { NlNamespaceRulings, NlValueAlias } from '@mnmal-ai/substrate/sdk';
|
|
7
|
+
export type NamespaceRulings = NlNamespaceRulings;
|
|
8
|
+
export type ValueAlias = NlValueAlias;
|
|
9
|
+
//# sourceMappingURL=rulings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rulings.d.ts","sourceRoot":"","sources":["../../src/pack/rulings.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEhF,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { NlServedPack, SubstrateRequest } from '@mnmal-ai/substrate/sdk';
|
|
2
|
+
import type { NlEngineAccess } from '../access.js';
|
|
3
|
+
import type { NamespaceRulings } from './rulings.js';
|
|
4
|
+
export type ServedPack = NlServedPack;
|
|
5
|
+
export interface PackServiceOptions {
|
|
6
|
+
engine: NlEngineAccess;
|
|
7
|
+
rulings?: Record<string, NamespaceRulings>;
|
|
8
|
+
ttlMs?: number;
|
|
9
|
+
/** Cache capacity; least-recently-used entries are evicted. Default 256. */
|
|
10
|
+
maxEntries?: number;
|
|
11
|
+
now?: () => number;
|
|
12
|
+
log?: (line: string) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Packs are built under the CALLER's request: the profile reads distinct
|
|
16
|
+
* values through `engine.query(frame, req)`, so row policy applies and a
|
|
17
|
+
* pack can never disclose a value its caller could not read. Hence the
|
|
18
|
+
* principal is part of the cache key.
|
|
19
|
+
*/
|
|
20
|
+
export declare class PackService {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(opts: PackServiceOptions);
|
|
23
|
+
get(ns: string, req: SubstrateRequest): Promise<{
|
|
24
|
+
pack: ServedPack;
|
|
25
|
+
etag: string;
|
|
26
|
+
} | undefined>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/pack/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAU,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAKnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AAQD;;;;;GAKG;AACH,qBAAa,WAAW;;IAMtB,YAAY,IAAI,EAAE,kBAAkB,EAEnC;IAEK,GAAG,CACP,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CA4BzD;CAuCF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-namespace vocabulary the NL parser works from: every type and field
|
|
3
|
+
* a question can name, the operators each field accepts, and which concrete
|
|
4
|
+
* values belong to which field. Built deterministically from `schema`
|
|
5
|
+
* plus a profile of the data, and keyed to `schemaVersion` so it can be
|
|
6
|
+
* rebuilt when the schema moves.
|
|
7
|
+
*/
|
|
8
|
+
import type { NlNamespacePack, NlPackField, NlPackType, NlPackValueRef } from '@mnmal-ai/substrate/sdk';
|
|
9
|
+
export type NamespacePack = NlNamespacePack;
|
|
10
|
+
export type PackType = NlPackType;
|
|
11
|
+
export type PackField = NlPackField;
|
|
12
|
+
export type PackValueRef = NlPackValueRef;
|
|
13
|
+
/** Distinct values observed per (type, field). `truncated` once past the cap. */
|
|
14
|
+
export interface NamespaceProfile {
|
|
15
|
+
types: Record<string, Record<string, FieldProfile>>;
|
|
16
|
+
}
|
|
17
|
+
export interface FieldProfile {
|
|
18
|
+
values: string[];
|
|
19
|
+
truncated: boolean;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** `AgentMessage` -> ['agent', 'message']; `shortId` -> ['short', 'id']. */
|
|
2
|
+
export declare function splitWords(name: string): string[];
|
|
3
|
+
/** English plural for a lower-case noun, by suffix rule. */
|
|
4
|
+
export declare function pluralize(word: string): string;
|
|
5
|
+
/** Sorted, de-duplicated. */
|
|
6
|
+
export declare function uniqueSorted(xs: Iterable<string>): string[];
|
|
7
|
+
//# sourceMappingURL=words.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"words.d.ts","sourceRoot":"","sources":["../../src/pack/words.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOjD;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED,6BAA6B;AAC7B,wBAAgB,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAE3D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic NL -> frame parser. Recognisers claim spans of the question
|
|
3
|
+
* against a namespace pack and the namespace's rulings; assembly turns the
|
|
4
|
+
* claims into candidate frames. The same question, pack, rulings and context
|
|
5
|
+
* always give the same result, and every clause in a produced frame is tied
|
|
6
|
+
* to the words that caused it.
|
|
7
|
+
*
|
|
8
|
+
* `resolved` means one candidate and nothing left over that could change it.
|
|
9
|
+
* Anything else is for the next tier to judge: this parser never guesses.
|
|
10
|
+
*/
|
|
11
|
+
import type { NlEvidence, NlParseStatus } from '@mnmal-ai/substrate/sdk';
|
|
12
|
+
import type { NamespaceRulings } from '../pack/rulings.js';
|
|
13
|
+
import type { NamespacePack } from '../pack/types.js';
|
|
14
|
+
export interface ParseContext {
|
|
15
|
+
/** The asking project: the default scope is this project or none. */
|
|
16
|
+
project?: string;
|
|
17
|
+
/** "now" for relative dates, ISO-8601 with offset. */
|
|
18
|
+
asOf: string;
|
|
19
|
+
/** Type a bare `#N` refers to. */
|
|
20
|
+
defaultIdType?: string;
|
|
21
|
+
rulings?: NamespaceRulings;
|
|
22
|
+
/** Read the question as this type only: a judge's choice, applied deterministically. */
|
|
23
|
+
forceType?: string;
|
|
24
|
+
}
|
|
25
|
+
export type Evidence = NlEvidence;
|
|
26
|
+
export interface Candidate {
|
|
27
|
+
type: string;
|
|
28
|
+
frame: Record<string, {
|
|
29
|
+
params: Record<string, unknown>;
|
|
30
|
+
}>;
|
|
31
|
+
answer: string;
|
|
32
|
+
evidence: Evidence[];
|
|
33
|
+
/** Content words this reading leaves unexplained. */
|
|
34
|
+
residual: string[];
|
|
35
|
+
}
|
|
36
|
+
export type ParseStatus = NlParseStatus;
|
|
37
|
+
export interface ParseResult {
|
|
38
|
+
status: ParseStatus;
|
|
39
|
+
candidates: Candidate[];
|
|
40
|
+
/** What an unparsed question was understood to say, for the judge. */
|
|
41
|
+
evidence?: Evidence[];
|
|
42
|
+
/** Content words the best reading leaves unexplained. */
|
|
43
|
+
residual: string[];
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare function parseQuestion(question: string, pack: NamespacePack, ctx: ParseContext): ParseResult;
|
|
47
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,kBAAkB,CAAC;AAIjE,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,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;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;AA+GD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,YAAY,GAChB,WAAW,CAuSb"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A half-open range of instants, ISO-8601 with the asking offset. */
|
|
2
|
+
export interface DateRange {
|
|
3
|
+
gte: string;
|
|
4
|
+
lt: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The range a time phrase names, relative to `asOf` and in its offset:
|
|
8
|
+
* today, yesterday, this/last week (weeks start Monday), this/last month,
|
|
9
|
+
* rolling "past <unit>" and "last N <units>", "since <weekday>". Null when
|
|
10
|
+
* the phrase is not a time phrase.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rangeFor(phrase: string, asOf: string): DateRange | null;
|
|
13
|
+
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/parse/time.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ;AAID;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAgDvE"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mnmal-ai/substrate-nl` as a substrate plugin: NL owns no namespace, only two
|
|
3
|
+
* kernel routes. Both are read-gated: row policy keeps the data safe, and the
|
|
4
|
+
* gate keeps an anonymous caller from spending the operator's judge GPU.
|
|
5
|
+
*/
|
|
6
|
+
import type { KernelPlugin } from '@mnmal-ai/substrate/sdk';
|
|
7
|
+
import type { NlEngineAccess } from './access.js';
|
|
8
|
+
import type { Judge } from './judge/judge.js';
|
|
9
|
+
import type { NamespaceRulings } from './pack/rulings.js';
|
|
10
|
+
export interface NlPluginConfig {
|
|
11
|
+
engine: NlEngineAccess;
|
|
12
|
+
judge?: Judge;
|
|
13
|
+
judgeTimeoutMs?: number;
|
|
14
|
+
rulings?: Record<string, NamespaceRulings>;
|
|
15
|
+
packTtlMs?: number;
|
|
16
|
+
}
|
|
17
|
+
/** The routes rely on `KernelRouteClaim.capability`, which every 1.x host honours. */
|
|
18
|
+
export declare const CONTRACT_VERSION = ">=1.0.0-alpha.0 <2.0.0";
|
|
19
|
+
export declare function createNlPlugin(cfg: NlPluginConfig): KernelPlugin;
|
|
20
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAI1D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,2BAA2B,CAAC;AAEzD,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,GAAG,YAAY,CAoBhE"}
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpHandler } from '@mnmal-ai/substrate/sdk';
|
|
2
|
+
import type { NlEngineAccess } from './access.js';
|
|
3
|
+
import type { Judge } from './judge/judge.js';
|
|
4
|
+
import type { PackService } from './pack/service.js';
|
|
5
|
+
export interface NlRouteDeps {
|
|
6
|
+
engine: NlEngineAccess;
|
|
7
|
+
packs: PackService;
|
|
8
|
+
judge?: Judge;
|
|
9
|
+
judgeTimeoutMs?: number;
|
|
10
|
+
now?: () => Date;
|
|
11
|
+
/** Receives the real engine error; clients only ever see a fixed message. */
|
|
12
|
+
log?: (err: unknown) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function askHandler(deps: NlRouteDeps): HttpHandler;
|
|
15
|
+
export declare function packHandler(deps: NlRouteDeps): HttpHandler;
|
|
16
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,yBAAyB,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,6EAA6E;IAC7E,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9B;AAkBD,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAqDzD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAwB1D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rulings arrive from two places: declared by the namespace owner in
|
|
3
|
+
* `defineNamespace(..., { annotations: { nl } })`, and overridden by the
|
|
4
|
+
* operator in `substrate-nl.config.json`. Both are validated here. Bad declared
|
|
5
|
+
* rulings are dropped with a warning rather than failing the boot: one
|
|
6
|
+
* namespace's typo must not take NL down for every namespace, and must not
|
|
7
|
+
* pass silently either.
|
|
8
|
+
*/
|
|
9
|
+
import type { Schema } from '@mnmal-ai/substrate/sdk';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import type { NamespaceRulings } from '../pack/rulings.js';
|
|
12
|
+
export declare const NamespaceRulingsSchema: z.ZodType<NamespaceRulings>;
|
|
13
|
+
/** Per top-level key: records merge entry-by-entry (override wins), arrays replace. */
|
|
14
|
+
export declare function mergeRulings(declared: NamespaceRulings, override: NamespaceRulings | undefined): NamespaceRulings;
|
|
15
|
+
/** The effective rulings for one namespace's schema, plus anything that was dropped. */
|
|
16
|
+
export declare function readRulings(schema: Schema, override?: NamespaceRulings): {
|
|
17
|
+
rulings: NamespaceRulings;
|
|
18
|
+
warnings: string[];
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=schema.d.ts.map
|