@hviana/sema 0.4.2 → 0.4.4
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/dist/example/demo.d.ts +1 -0
- package/dist/example/demo.js +39 -0
- package/dist/example/train_base.d.ts +87 -0
- package/dist/example/train_base.js +2252 -0
- package/dist/src/alphabet.d.ts +7 -0
- package/dist/src/alphabet.js +33 -0
- package/dist/src/alu/src/alu.d.ts +185 -0
- package/dist/src/alu/src/alu.js +440 -0
- package/dist/src/alu/src/expr.d.ts +61 -0
- package/dist/src/alu/src/expr.js +318 -0
- package/dist/src/alu/src/index.d.ts +11 -0
- package/dist/src/alu/src/index.js +19 -0
- package/dist/src/alu/src/kernel-arith.d.ts +16 -0
- package/dist/src/alu/src/kernel-arith.js +264 -0
- package/dist/src/alu/src/kernel-bits.d.ts +19 -0
- package/dist/src/alu/src/kernel-bits.js +152 -0
- package/dist/src/alu/src/kernel-logic.d.ts +4 -0
- package/dist/src/alu/src/kernel-logic.js +60 -0
- package/dist/src/alu/src/kernel-nd.d.ts +3 -0
- package/dist/src/alu/src/kernel-nd.js +208 -0
- package/dist/src/alu/src/kernel-numeric.d.ts +54 -0
- package/dist/src/alu/src/kernel-numeric.js +366 -0
- package/dist/src/alu/src/operation.d.ts +168 -0
- package/dist/src/alu/src/operation.js +189 -0
- package/dist/src/alu/src/parser.d.ts +221 -0
- package/dist/src/alu/src/parser.js +577 -0
- package/dist/src/alu/src/resonance.d.ts +55 -0
- package/dist/src/alu/src/resonance.js +126 -0
- package/dist/src/alu/src/text.d.ts +31 -0
- package/dist/src/alu/src/text.js +73 -0
- package/dist/src/alu/src/value.d.ts +109 -0
- package/dist/src/alu/src/value.js +300 -0
- package/dist/src/alu/test/alu.test.d.ts +1 -0
- package/dist/src/alu/test/alu.test.js +764 -0
- package/dist/src/bytes.d.ts +14 -0
- package/dist/src/bytes.js +59 -0
- package/dist/src/canon.d.ts +26 -0
- package/dist/src/canon.js +57 -0
- package/dist/src/config.d.ts +111 -0
- package/dist/src/config.js +91 -0
- package/dist/src/derive/src/deduction.d.ts +136 -0
- package/dist/src/derive/src/deduction.js +159 -0
- package/dist/src/derive/src/index.d.ts +8 -0
- package/dist/src/derive/src/index.js +11 -0
- package/dist/src/derive/src/priority-queue.d.ts +20 -0
- package/dist/src/derive/src/priority-queue.js +73 -0
- package/dist/src/derive/src/rewrite.d.ts +56 -0
- package/dist/src/derive/src/rewrite.js +100 -0
- package/dist/src/derive/src/trie.d.ts +90 -0
- package/dist/src/derive/src/trie.js +217 -0
- package/dist/src/derive/test/derive.test.d.ts +1 -0
- package/dist/src/derive/test/derive.test.js +122 -0
- package/dist/src/extension.d.ts +37 -0
- package/dist/src/extension.js +7 -0
- package/dist/src/geometry.d.ts +175 -0
- package/dist/src/geometry.js +823 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +19 -0
- package/dist/src/ingest-cache.d.ts +41 -0
- package/dist/src/ingest-cache.js +165 -0
- package/dist/src/meter.d.ts +176 -0
- package/dist/src/meter.js +274 -0
- package/dist/src/mind/articulation.d.ts +6 -0
- package/dist/src/mind/articulation.js +99 -0
- package/dist/src/mind/attention.d.ts +414 -0
- package/dist/src/mind/attention.js +2082 -0
- package/dist/src/mind/bridge.d.ts +39 -0
- package/dist/src/mind/bridge.js +972 -0
- package/dist/src/mind/canonical.d.ts +34 -0
- package/dist/src/mind/canonical.js +93 -0
- package/dist/src/mind/graph-search.d.ts +294 -0
- package/dist/src/mind/graph-search.js +996 -0
- package/dist/src/mind/index.d.ts +9 -0
- package/dist/src/mind/index.js +5 -0
- package/dist/src/mind/junction.d.ts +137 -0
- package/dist/src/mind/junction.js +342 -0
- package/dist/src/mind/learning.d.ts +75 -0
- package/dist/src/mind/learning.js +270 -0
- package/dist/src/mind/match.d.ts +181 -0
- package/dist/src/mind/match.js +655 -0
- package/dist/src/mind/mechanisms/alu.d.ts +4 -0
- package/dist/src/mind/mechanisms/alu.js +36 -0
- package/dist/src/mind/mechanisms/cast.d.ts +89 -0
- package/dist/src/mind/mechanisms/cast.js +784 -0
- package/dist/src/mind/mechanisms/confluence.d.ts +24 -0
- package/dist/src/mind/mechanisms/confluence.js +255 -0
- package/dist/src/mind/mechanisms/cover.d.ts +6 -0
- package/dist/src/mind/mechanisms/cover.js +227 -0
- package/dist/src/mind/mechanisms/extraction.d.ts +33 -0
- package/dist/src/mind/mechanisms/extraction.js +300 -0
- package/dist/src/mind/mechanisms/recall.d.ts +16 -0
- package/dist/src/mind/mechanisms/recall.js +364 -0
- package/dist/src/mind/mind.d.ts +337 -0
- package/dist/src/mind/mind.js +626 -0
- package/dist/src/mind/pipeline-mechanism.d.ts +172 -0
- package/dist/src/mind/pipeline-mechanism.js +465 -0
- package/dist/src/mind/pipeline.d.ts +49 -0
- package/dist/src/mind/pipeline.js +275 -0
- package/dist/src/mind/primitives.d.ts +66 -0
- package/dist/src/mind/primitives.js +306 -0
- package/dist/src/mind/rationale.d.ts +139 -0
- package/dist/src/mind/rationale.js +163 -0
- package/dist/src/mind/reasoning.d.ts +40 -0
- package/dist/src/mind/reasoning.js +280 -0
- package/dist/src/mind/recognition.d.ts +20 -0
- package/dist/src/mind/recognition.js +504 -0
- package/dist/src/mind/resonance.d.ts +23 -0
- package/dist/src/mind/resonance.js +0 -0
- package/dist/src/mind/trace.d.ts +15 -0
- package/dist/src/mind/trace.js +73 -0
- package/dist/src/mind/traverse.d.ts +126 -0
- package/dist/src/mind/traverse.js +650 -0
- package/dist/src/mind/types.d.ts +333 -0
- package/dist/src/mind/types.js +130 -0
- package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
- package/dist/src/rabitq-ivf/src/database.js +201 -0
- package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
- package/dist/src/rabitq-ivf/src/index.js +4 -0
- package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
- package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
- package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
- package/dist/src/rabitq-ivf/src/prng.js +36 -0
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
- package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
- package/dist/src/sema.d.ts +31 -0
- package/dist/src/sema.js +63 -0
- package/dist/src/store-sqlite.d.ts +184 -0
- package/dist/src/store-sqlite.js +942 -0
- package/dist/src/store.d.ts +678 -0
- package/dist/src/store.js +1703 -0
- package/dist/src/vec.d.ts +31 -0
- package/dist/src/vec.js +109 -0
- package/package.json +1 -1
- package/src/mind/bridge.ts +55 -18
- package/src/mind/mind.ts +11 -2
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { Vec } from "../vec.js";
|
|
2
|
+
import { Sema, Space } from "../sema.js";
|
|
3
|
+
import { Alphabet } from "../alphabet.js";
|
|
4
|
+
import { Grid } from "../geometry.js";
|
|
5
|
+
import { BoundedMap, type Store } from "../store.js";
|
|
6
|
+
import { type MindConfig } from "../config.js";
|
|
7
|
+
import { type Canon } from "../canon.js";
|
|
8
|
+
import { GraphSearch, type Leaf, type Site } from "./graph-search.js";
|
|
9
|
+
import type { ComputedSpan, ExtensionHost } from "../extension.js";
|
|
10
|
+
export type { ComputedSpan, ExtensionHost };
|
|
11
|
+
import { type InspectRationale, Rationale } from "./rationale.js";
|
|
12
|
+
export type { InspectRationale, RationaleItem, RationaleStep, } from "./rationale.js";
|
|
13
|
+
export type Input = string | Uint8Array | Grid | Grid[];
|
|
14
|
+
export interface Response {
|
|
15
|
+
v: Vec | null;
|
|
16
|
+
bytes: Uint8Array;
|
|
17
|
+
/** How the answer was grounded (see {@link Provenance}). `"recall-echo"`
|
|
18
|
+
* marks the last-resort fallback that returned the nearest stored form's
|
|
19
|
+
* own bytes verbatim — an echo, NOT a grounded fact. Absent when there is
|
|
20
|
+
* no answer. */
|
|
21
|
+
provenance?: import("./pipeline.js").Provenance;
|
|
22
|
+
}
|
|
23
|
+
/** Serializable state of a conversation — can be saved and restored across
|
|
24
|
+
* sessions. The Mind never interprets the bytes; it only tracks their
|
|
25
|
+
* cumulative lengths so the caller can reconstruct turn boundaries later
|
|
26
|
+
* without inspecting content. */
|
|
27
|
+
export interface ConversationState {
|
|
28
|
+
/** The accumulated context bytes — raw concatenation of every turn's
|
|
29
|
+
* bytes in order. No separator is inserted; the boundary offsets
|
|
30
|
+
* ({@link boundaries}) tell the caller where each turn ends. */
|
|
31
|
+
context: Uint8Array;
|
|
32
|
+
/** Cumulative byte length after each completed turn. Sorted, strictly
|
|
33
|
+
* increasing, each {@code < context.length}. The first turn's length
|
|
34
|
+
* is `boundaries[0]`; the second turn starts at that offset, and so
|
|
35
|
+
* on. Empty for a single-turn or new conversation. */
|
|
36
|
+
boundaries: number[];
|
|
37
|
+
/** Byte spans occupied by replies produced by this Mind. Unlike boundary
|
|
38
|
+
* parity, this remains exact when a turn receives an empty reply. Optional
|
|
39
|
+
* so states saved before the field existed remain restorable. */
|
|
40
|
+
answeredSpans?: Array<[number, number]>;
|
|
41
|
+
}
|
|
42
|
+
/** An active conversation handle. Opaque — interact through the Mind's
|
|
43
|
+
* conversation methods ({@link Mind.beginConversation},
|
|
44
|
+
* {@link Mind.respondTurn}, {@link Mind.endConversation}). */
|
|
45
|
+
export interface Conversation {
|
|
46
|
+
readonly id: number;
|
|
47
|
+
}
|
|
48
|
+
import type { AttentionRead, MindContext, Recognition } from "./types.js";
|
|
49
|
+
export type { AnchorRejectionReason, ClimbConsensusData, ConsensusAnchorTrace, ConsensusReachTrace, ConsensusRegionTrace, CrossRegionTier, JunctionVoteTrace, RegionOutcome, } from "./attention.js";
|
|
50
|
+
export type { AncestorReach, SaturationReason, SaturationStop, } from "./types.js";
|
|
51
|
+
import { type CostReport, Meter } from "../meter.js";
|
|
52
|
+
export interface MindOptions {
|
|
53
|
+
seed?: number;
|
|
54
|
+
recallQueryK?: number;
|
|
55
|
+
haloQueryK?: number;
|
|
56
|
+
normalizeEpsilon?: number;
|
|
57
|
+
cosineEpsilon?: number;
|
|
58
|
+
geometry?: Partial<import("../config.js").GeometryConfig>;
|
|
59
|
+
alphabet?: Partial<import("../config.js").AlphabetConfig>;
|
|
60
|
+
storeConfig?: Partial<import("../config.js").StoreConfig>;
|
|
61
|
+
store?: Store;
|
|
62
|
+
/** Additional grounding mechanisms (appended after the built-in defaults). */
|
|
63
|
+
mechanisms?: import("./pipeline-mechanism.js").PipelineMechanism[];
|
|
64
|
+
/** Factories that receive the {@link ExtensionHost} and return mechanisms. */
|
|
65
|
+
mechanismFactories?: ((host: import("../extension.js").ExtensionHost) => import("./pipeline-mechanism.js").PipelineMechanism)[];
|
|
66
|
+
/** Measure the computational usage of every inference call — see
|
|
67
|
+
* src/meter.ts. Off by default and free when off (one null check per
|
|
68
|
+
* store read); on, each `respond`/`respondTurn` leaves a {@link
|
|
69
|
+
* Mind.lastCost} report behind. Counters are deterministic, so two runs
|
|
70
|
+
* of the same query on the same store are diffable; the millisecond
|
|
71
|
+
* fields are not. Profiling NEVER changes an answer — but note that
|
|
72
|
+
* attaching a RATIONALE does (traced responses bypass the ctx memos,
|
|
73
|
+
* AGENTS §2.11), so profile without a trace. */
|
|
74
|
+
profile?: boolean;
|
|
75
|
+
/** Content canonicalizer applied to EVERY response (any modality) for
|
|
76
|
+
* equivalence-class resolution — see src/canon.ts. Text entry points
|
|
77
|
+
* ({@link Mind.respondText}, {@link Mind.respondTurnText}) inject the
|
|
78
|
+
* Unicode text canonicalizer automatically when this is unset; pass
|
|
79
|
+
* `false` to disable canonical resolution everywhere. */
|
|
80
|
+
canon?: Canon | false;
|
|
81
|
+
}
|
|
82
|
+
export declare class Mind implements MindContext {
|
|
83
|
+
readonly space: Space;
|
|
84
|
+
readonly alphabet: Alphabet;
|
|
85
|
+
readonly store: Store;
|
|
86
|
+
readonly cfg: MindConfig;
|
|
87
|
+
/** The lightest-derivation engine over the Sema graph. */
|
|
88
|
+
readonly search: GraphSearch;
|
|
89
|
+
/** The grounding mechanisms iterated by {@link think}. */
|
|
90
|
+
readonly mechanisms: import("./pipeline-mechanism.js").PipelineMechanism[];
|
|
91
|
+
/** The live rationale tracer for the inference currently in flight, or null. */
|
|
92
|
+
trace: Rationale | null;
|
|
93
|
+
/** The content canonicalizer for the response in flight — see
|
|
94
|
+
* {@link MindContext.canon}. Injected per response by the modality entry
|
|
95
|
+
* point; null when the response carries no equivalence. */
|
|
96
|
+
canon: Canon | null;
|
|
97
|
+
/** Per-response canonical-resolution memo — see {@link MindContext.canonMemo}. */
|
|
98
|
+
canonMemo: Map<string, number | null> | null;
|
|
99
|
+
/** The Mind-level canon option: a canonicalizer to use for EVERY response,
|
|
100
|
+
* `false` to disable canonical resolution, or null to let each entry
|
|
101
|
+
* point decide (text entry points inject {@link textCanon}). */
|
|
102
|
+
private _canonOpt;
|
|
103
|
+
/** The work accumulator for the inference call in flight — see
|
|
104
|
+
* {@link MindContext.meter}. Non-null only between beginResponse and
|
|
105
|
+
* endResponse, and only when the Mind was constructed with
|
|
106
|
+
* `{ profile: true }`. */
|
|
107
|
+
meter: Meter | null;
|
|
108
|
+
/** Whether {@link MindOptions.profile} was set. */
|
|
109
|
+
private _profile;
|
|
110
|
+
/** The computational-usage report of the LAST completed inference call, or
|
|
111
|
+
* null when profiling is off (or nothing has been asked yet). Overwritten
|
|
112
|
+
* by every `respond`/`respondTurn`; copy it if you are aggregating. See
|
|
113
|
+
* {@link import("../meter.js").CostReport} and `sumReports`/`formatReport`
|
|
114
|
+
* for battery-level aggregation. */
|
|
115
|
+
lastCost: CostReport | null;
|
|
116
|
+
/** Memo of the consensus climb — content-keyed. See {@link MindContext.climbMemo}. */
|
|
117
|
+
climbMemo: Map<string, Map<string, AttentionRead>> | null;
|
|
118
|
+
_structMemoKey: object;
|
|
119
|
+
/** Memo of recognise() — content-keyed. See {@link MindContext.recogniseMemo}. */
|
|
120
|
+
recogniseMemo: Map<string, Recognition> | null;
|
|
121
|
+
/** Memo of perceive() — content-keyed. See {@link MindContext.perceiveMemo}. */
|
|
122
|
+
perceiveMemo: Map<string, import("../sema.js").Sema> | null;
|
|
123
|
+
/** Subtree-resolution cache. See {@link MindContext._resolvedSubtrees}. */
|
|
124
|
+
_resolvedSubtrees: WeakMap<import("../sema.js").Sema, {
|
|
125
|
+
id: number;
|
|
126
|
+
len: number;
|
|
127
|
+
}> | null;
|
|
128
|
+
answeredSpans: ReadonlyArray<readonly [number, number]>;
|
|
129
|
+
currentTurnStart: number;
|
|
130
|
+
/** The perceived gist of the query currently being answered. Set by `think`
|
|
131
|
+
* before the graph search runs; `chooseNext` consults it as a gate (a null
|
|
132
|
+
* guide means no query is in flight, so structural walkers keep plain
|
|
133
|
+
* first-edge behaviour) and the reverse projection uses it for
|
|
134
|
+
* reverse-recall disambiguation via `chooseAmong`. */
|
|
135
|
+
_edgeGuide: Vec | null;
|
|
136
|
+
/** Per-response memo of {@link chooseNext} picks — ensures every mechanism
|
|
137
|
+
* of a single response follows the SAME continuation for each ambiguous
|
|
138
|
+
* context node. */
|
|
139
|
+
_edgeChoice: Map<number, number>;
|
|
140
|
+
/** Previous deposit's seen node ids for incremental change detection. */
|
|
141
|
+
_prevSeen: Set<number> | null;
|
|
142
|
+
/** Session cache of node-id → perceived gist for candidate scoring — see
|
|
143
|
+
* {@link MindContext._gistCache}. 32 MB ≈ 8K gists at D=1024; hub
|
|
144
|
+
* candidate sets (√N at most) fit comfortably and recur across queries. */
|
|
145
|
+
_gistCache: BoundedMap<number, Vec>;
|
|
146
|
+
_depositTrees: BoundedMap<string, import("./types.js").DepositCacheEntry>;
|
|
147
|
+
_depositLens: Set<number>;
|
|
148
|
+
_internIds: WeakMap<Sema, number>;
|
|
149
|
+
private _nextConvId;
|
|
150
|
+
private _conversations;
|
|
151
|
+
/** Canonical node id of a byte span. Required by GraphSearchHost & MindContext. */
|
|
152
|
+
resolve(bytes: Uint8Array): number | null;
|
|
153
|
+
recogniseSpan(bytes: Uint8Array): {
|
|
154
|
+
sites: ReadonlyArray<Site>;
|
|
155
|
+
leaves: ReadonlyArray<Leaf>;
|
|
156
|
+
splits: ReadonlySet<number>;
|
|
157
|
+
starts: ReadonlySet<number>;
|
|
158
|
+
};
|
|
159
|
+
/** Disambiguate among multiple learnt continuations of the same context node.
|
|
160
|
+
* Required by {@link GraphSearchHost} — the graph search calls this through the
|
|
161
|
+
* host interface when a recognised form has more than one outgoing edge.
|
|
162
|
+
* Delegates to the standalone {@link chooseNext} which picks the candidate
|
|
163
|
+
* with the most distributional evidence (highest `prevOf` count — the
|
|
164
|
+
* structural manifestation of its halo). When evidence is equal the
|
|
165
|
+
* first-inserted edge wins. */
|
|
166
|
+
chooseNext(node: number): number | undefined;
|
|
167
|
+
constructor(opts?: MindOptions);
|
|
168
|
+
constructor(cfg: MindConfig, store: Store, _fromStore: true);
|
|
169
|
+
/** Exposed for tests: the consensus climb over query sub-regions. */
|
|
170
|
+
climbAttention(query: Uint8Array, k: number, mode?: import("./types.js").DFMode): Promise<import("./types.js").Attention[]>;
|
|
171
|
+
/** Exposed for tests: climb the structural DAG from a node to its
|
|
172
|
+
* edge-bearing ancestor contexts. */
|
|
173
|
+
edgeAncestors(id: number, contextCount: number): import("./types.js").AncestorReach;
|
|
174
|
+
/** Exposed for tests: find the natural break point in a sorted vote list. */
|
|
175
|
+
naturalBreak(votes: number[]): number;
|
|
176
|
+
/** Perceive input into a content-defined tree. Deterministic — identical
|
|
177
|
+
* bytes always produce an identical tree. Public for ingest-cache. */
|
|
178
|
+
perceive(input: Input, leafAt?: (i: number) => number | null, lookup?: (ids: number[]) => number | null): Sema;
|
|
179
|
+
/** Open one response's transient state — the tracer, the per-response
|
|
180
|
+
* memos, the work meter. The ONE place this state is created, and it
|
|
181
|
+
* serves BOTH entry points: `respond` takes fresh per-response memos,
|
|
182
|
+
* `respondTurn` passes its conversation, whose memos persist across turns
|
|
183
|
+
* (content-keyed, so the previous turn's results are found by this turn's
|
|
184
|
+
* sub-span calls) and whose `resolvedSubtrees` makes foldTree O(suffix)
|
|
185
|
+
* instead of O(context). respondTurn used to inline its own copy of this
|
|
186
|
+
* and of {@link endResponse}; the two drifted (a memo added to one was
|
|
187
|
+
* silently absent from the other), so there is exactly one pair now. */
|
|
188
|
+
private beginResponse;
|
|
189
|
+
/** Open (or leave closed) the response's work accumulator. Separate from
|
|
190
|
+
* {@link beginResponse} because {@link respondTurn} keeps its own
|
|
191
|
+
* conversation-scoped lifecycle and must not create fresh per-response
|
|
192
|
+
* memos — but it DOES meter, through this same pair. */
|
|
193
|
+
private _beginMeter;
|
|
194
|
+
/** Close the accumulator and publish its report. Detaching from the store
|
|
195
|
+
* matters: a Mind that shares a store with another Mind must not keep
|
|
196
|
+
* charging that store's reads to a finished response. */
|
|
197
|
+
private _endMeter;
|
|
198
|
+
/** The canonicalizer a response should carry: the Mind-level option when
|
|
199
|
+
* set (or none when explicitly disabled), else the entry point's own
|
|
200
|
+
* default — text entry points pass {@link textCanon}, binary ones null. */
|
|
201
|
+
private _canonFor;
|
|
202
|
+
/** Close one response's transient state — every per-response field, incl.
|
|
203
|
+
* the edge guide/choices `think` sets mid-flight, and the meter's report.
|
|
204
|
+
*
|
|
205
|
+
* A conversation's memo MAPS were mutated in place, so `data.*` still
|
|
206
|
+
* points at them and there is nothing to save back. Clearing the Mind's
|
|
207
|
+
* references is what matters: a concurrently-started `respond()` swaps its
|
|
208
|
+
* own fresh maps into these pointers, and copying back from them here
|
|
209
|
+
* would inject a foreign response's memos into the conversation. */
|
|
210
|
+
private endResponse;
|
|
211
|
+
/** Shared response core — the one path from bytes to voiced answer.
|
|
212
|
+
* `respond` calls this directly; `respondTurn` has its own path
|
|
213
|
+
* with conversation-persistent memos and incremental perception. */
|
|
214
|
+
private _respondImpl;
|
|
215
|
+
/** The ONE path from query bytes to a voiced answer: ground (think), then
|
|
216
|
+
* re-voice in the asker's words (articulate). Both entry points run
|
|
217
|
+
* exactly this — they differ only in the LIFECYCLE around it (fresh
|
|
218
|
+
* per-response memos vs. a conversation's persistent ones) and in what
|
|
219
|
+
* they do with the answer afterwards. It must be called between
|
|
220
|
+
* {@link beginResponse} and {@link endResponse}. */
|
|
221
|
+
private _groundAndVoice;
|
|
222
|
+
respond(input: Input, inspectRationale?: InspectRationale): Promise<Response>;
|
|
223
|
+
/** Text view of {@link respond}. NUL bytes (0x00) are stripped before
|
|
224
|
+
* decoding — they are structural padding in text answers. LOSSY for a
|
|
225
|
+
* binary answer that legitimately contains NULs: use {@link respond} and
|
|
226
|
+
* read `bytes` directly for binary/grid modalities.
|
|
227
|
+
*
|
|
228
|
+
* Injects the TEXT canonicalizer (src/canon.ts) so resolution treats
|
|
229
|
+
* every character variation of the same text — case, width, whitespace —
|
|
230
|
+
* as one form, provided the store's canon index is built
|
|
231
|
+
* ({@link buildCanonIndex}). */
|
|
232
|
+
respondText(input: string, inspectRationale?: InspectRationale): Promise<string>;
|
|
233
|
+
/** Begin a new conversation, optionally restoring from a previously-saved
|
|
234
|
+
* {@link ConversationState}. The returned handle is required for
|
|
235
|
+
* {@link respondTurn} and {@link endConversation}.
|
|
236
|
+
*
|
|
237
|
+
* Conversations are independent — a Mind can manage several concurrently.
|
|
238
|
+
* Each tracks the fold pyramid (accumulated internal processing) and
|
|
239
|
+
* turn-boundary offsets; the geometry never inspects content to guess
|
|
240
|
+
* where one turn ends and the next begins. */
|
|
241
|
+
beginConversation(state?: ConversationState): Conversation;
|
|
242
|
+
/** End a conversation, releasing its internal resources (accumulated
|
|
243
|
+
* context, boundary offsets, and the fold-pyramid cache). Idempotent. */
|
|
244
|
+
endConversation(conv: Conversation): void;
|
|
245
|
+
/** The current serialisable state of an active conversation. Save this
|
|
246
|
+
* to resume the conversation later via {@link beginConversation}. */
|
|
247
|
+
conversationState(conv: Conversation): ConversationState | null;
|
|
248
|
+
/** Append a turn to a conversation's accumulated context WITHOUT
|
|
249
|
+
* responding — raw byte append plus a boundary offset, never a
|
|
250
|
+
* separator; the fold pyramid advances by O(turn).
|
|
251
|
+
*
|
|
252
|
+
* This is the primitive for turns the Mind should hear but not answer:
|
|
253
|
+
* replaying a transcript, feeding the OTHER speaker's line in a
|
|
254
|
+
* prediction harness, or restoring context piecewise. {@link
|
|
255
|
+
* respondTurn} = addTurn + think + its own reply appended the same way. */
|
|
256
|
+
addTurn(conv: Conversation, turn: Input): ConversationState;
|
|
257
|
+
/** Grow a conversation's accumulated context by one turn's bytes — raw
|
|
258
|
+
* append plus a boundary offset, pyramid advanced by O(turn), the grown
|
|
259
|
+
* context's tree seeded into the conversation's perceive memo. The ONE
|
|
260
|
+
* place a context grows ({@link addTurn} and {@link respondTurn} both
|
|
261
|
+
* come through here), so the append semantics cannot drift. */
|
|
262
|
+
private _growContext;
|
|
263
|
+
/** Process one turn of a conversation.
|
|
264
|
+
*
|
|
265
|
+
* `turn` is the raw input for the latest turn — its bytes are appended
|
|
266
|
+
* to the accumulated context directly (raw concatenation). The Mind
|
|
267
|
+
* tracks the byte offset where each turn ends; no separator is ever
|
|
268
|
+
* inserted or inspected.
|
|
269
|
+
*
|
|
270
|
+
* Returns the response AND the updated {@link ConversationState} so the
|
|
271
|
+
* caller can persist it. The conversation handle's internal state is
|
|
272
|
+
* updated in place — the returned state is a snapshot for storage.
|
|
273
|
+
*
|
|
274
|
+
* SINGLE FLIGHT: at most one respondTurn may be in flight per Mind. The
|
|
275
|
+
* conversation's memo caches are swapped into the Mind-level per-response
|
|
276
|
+
* pointers for the duration of the turn, so a concurrently-running
|
|
277
|
+
* respond()/respondTurn() on the SAME Mind would interleave state.
|
|
278
|
+
* Different Minds (or sequential awaits, as in every test) are safe. */
|
|
279
|
+
respondTurn(conv: Conversation, turn: Input, inspectRationale?: InspectRationale): Promise<{
|
|
280
|
+
response: Response;
|
|
281
|
+
state: ConversationState;
|
|
282
|
+
}>;
|
|
283
|
+
/** Text view of {@link respondTurn}. See {@link respondText} for the
|
|
284
|
+
* NUL-stripping caveat. For binary or grid turns use {@link respondTurn}
|
|
285
|
+
* directly — this is a text-only convenience, like {@link respondText}. */
|
|
286
|
+
respondTurnText(conv: Conversation, turn: string, inspectRationale?: InspectRationale): Promise<{
|
|
287
|
+
response: string;
|
|
288
|
+
state: ConversationState;
|
|
289
|
+
}>;
|
|
290
|
+
embedding(input: Input): Promise<Vec | null>;
|
|
291
|
+
/** Kinship note: the vector arm below is a miniature of recall's tier 3
|
|
292
|
+
* (resonate → reach gate → read out the nearest form's bytes) — the
|
|
293
|
+
* read-out direction of the same operation, without recall's grounding
|
|
294
|
+
* ladder. If either side's acceptance rule changes, revisit the other. */
|
|
295
|
+
express(idOrV: number | Vec): Promise<Uint8Array>;
|
|
296
|
+
/** See {@link import("./learning.js").ingest} — `onDeposit`, when given,
|
|
297
|
+
* reports each ingested item's deposited root node ids
|
|
298
|
+
* ({@link DepositReport}); purely observational. */
|
|
299
|
+
ingest(input: Input | (Input | [Input, Input])[], second?: Input, onDeposit?: (report: import("./learning.js").DepositReport) => void): Promise<(Sema & {
|
|
300
|
+
id: number;
|
|
301
|
+
}) | undefined>;
|
|
302
|
+
private extensionHost;
|
|
303
|
+
private groundedContinuation;
|
|
304
|
+
/** Re-index structurally-important nodes whose gists were evicted from the
|
|
305
|
+
* pending cache before they reached the content index. See {@link
|
|
306
|
+
* Store.repairContentIndex} for the contract; this method wires the
|
|
307
|
+
* Mind's perception into the store's repair walk.
|
|
308
|
+
*
|
|
309
|
+
* Run this after training or at checkpoints to restore recall reach for
|
|
310
|
+
* nodes that bridge experiences but were never indexed. A pure interior
|
|
311
|
+
* node (no edges, no halo) is deliberately skipped — it is scaffolding,
|
|
312
|
+
* not an experience root or bridge, and regenerating its gist would waste
|
|
313
|
+
* I/O and index space for no recall benefit.
|
|
314
|
+
*
|
|
315
|
+
* @param minParents only repair nodes with ≥ this many structural parents
|
|
316
|
+
* (default 2 — structural bridges)
|
|
317
|
+
* @returns number of nodes added to the content index */
|
|
318
|
+
repairContentIndex(minParents?: number): Promise<number>;
|
|
319
|
+
/** Build (or incrementally refresh) the store's canonical-form index: for
|
|
320
|
+
* every content-bearing node, record the hash of its CANONICAL key so
|
|
321
|
+
* resolution can find stored forms across surface variation (case, width,
|
|
322
|
+
* whitespace — whatever `canon` equates; see src/canon.ts).
|
|
323
|
+
*
|
|
324
|
+
* Incremental and idempotent: the last indexed node id is remembered in
|
|
325
|
+
* store meta (`canon.upto`), so a refresh after further training scans
|
|
326
|
+
* only the new rows. Run once after training, and again after ingests —
|
|
327
|
+
* the same operational shape as {@link repairContentIndex}.
|
|
328
|
+
*
|
|
329
|
+
* @param canon the canonicalizer to index under — MUST be the same one
|
|
330
|
+
* queries will carry (text queries carry {@link textCanon}
|
|
331
|
+
* unless the Mind was constructed with its own)
|
|
332
|
+
* @returns number of index rows added */
|
|
333
|
+
buildCanonIndex(canon?: Canon): Promise<number>;
|
|
334
|
+
save(): Promise<Uint8Array>;
|
|
335
|
+
static load(snapshot: Uint8Array, store: Store): Promise<Mind>;
|
|
336
|
+
static loadFromStore(store: Store): Promise<Mind>;
|
|
337
|
+
}
|