@avantf/dsh-mem 0.7.0 → 0.8.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/README.md +4 -0
- package/lib/client.js +548 -1195
- package/lib/dsh-build.json +1 -0
- package/lib/engine/graph-recall/in-memory.d.ts +93 -0
- package/lib/engine/graph-recall/index.d.ts +22 -0
- package/lib/engine/graph-recall/traverse.d.ts +119 -0
- package/lib/engine/graph-recall/types.d.ts +188 -0
- package/lib/engine/mem/config/config_files.d.ts +1 -1
- package/lib/engine/mem/config/loader.d.ts +2 -3
- package/lib/engine/mem/config/paths.d.ts +2 -13
- package/lib/engine/mem/db/dao/contradictions.d.ts +4 -22
- package/lib/engine/mem/db/dao/entities.d.ts +80 -7
- package/lib/engine/mem/db/dao/fact_sources.d.ts +3 -13
- package/lib/engine/mem/db/dao/facts.d.ts +311 -56
- package/lib/engine/mem/db/dao/triples.d.ts +1 -26
- package/lib/engine/mem/db/graph.d.ts +249 -0
- package/lib/engine/mem/db/journal_notes.d.ts +35 -0
- package/lib/engine/mem/db/migrations.d.ts +9 -0
- package/lib/engine/mem/db/port.d.ts +22 -3
- package/lib/engine/mem/db/schema.d.ts +119 -0
- package/lib/engine/mem/db/tokenizer.d.ts +9 -0
- package/lib/engine/mem/dbdrivers/fake/driver.d.ts +75 -0
- package/lib/engine/mem/dbdrivers/fake/index.d.ts +7 -0
- package/lib/engine/mem/dbdrivers/fake/surface.d.ts +34 -0
- package/lib/engine/mem/dbdrivers/fake/transport.d.ts +61 -0
- package/lib/engine/mem/dbdrivers/sqlite/connection.d.ts +14 -0
- package/lib/engine/mem/dbdrivers/sqlite/contradictions.d.ts +35 -0
- package/lib/engine/mem/dbdrivers/sqlite/dao/index.d.ts +16 -0
- package/lib/engine/mem/dbdrivers/sqlite/driver.d.ts +54 -0
- package/lib/engine/mem/dbdrivers/sqlite/facts.d.ts +117 -0
- package/lib/engine/mem/dbdrivers/sqlite/index.d.ts +6 -0
- package/lib/engine/mem/dbdrivers/sqlite/migrations.d.ts +15 -0
- package/lib/engine/mem/dbdrivers/sqlite/relations.d.ts +62 -0
- package/lib/engine/mem/dbdrivers/sqlite/search.d.ts +56 -0
- package/lib/engine/mem/dbdrivers/sqlite/sources.d.ts +37 -0
- package/lib/engine/mem/defaults.d.ts +3 -4
- package/lib/engine/mem/dispatch.d.ts +7 -32
- package/lib/engine/mem/entities/extract.d.ts +44 -47
- package/lib/engine/mem/eval/derived_runner.d.ts +6 -1
- package/lib/engine/mem/eval/relation_gold.d.ts +251 -0
- package/lib/engine/mem/eval/write_metrics.d.ts +1 -1
- package/lib/engine/mem/facts_io.d.ts +50 -10
- package/lib/engine/mem/index.d.ts +6 -2
- package/lib/engine/mem/interfaces/capabilities.d.ts +30 -0
- package/lib/engine/mem/interfaces/common.d.ts +11 -0
- package/lib/engine/mem/interfaces/errors.d.ts +65 -0
- package/lib/engine/mem/interfaces/index.d.ts +18 -0
- package/lib/engine/mem/interfaces/migrations.d.ts +21 -0
- package/lib/engine/mem/interfaces/repositories.d.ts +471 -0
- package/lib/engine/mem/interfaces/search_index.d.ts +113 -0
- package/lib/engine/mem/interfaces/storage_backend.d.ts +84 -0
- package/lib/engine/mem/interfaces/storage_driver.d.ts +43 -0
- package/lib/engine/mem/interfaces/version.d.ts +34 -0
- package/lib/engine/mem/lifecycle/contradiction.d.ts +2 -2
- package/lib/engine/mem/modelBootstrap.d.ts +1 -1
- package/lib/engine/mem/relations/confidence.d.ts +39 -0
- package/lib/engine/mem/relations/extract.d.ts +128 -0
- package/lib/engine/mem/relations/index.d.ts +32 -0
- package/lib/engine/mem/relations/name-quality.d.ts +78 -0
- package/lib/engine/mem/relations/normalize.d.ts +275 -0
- package/lib/engine/mem/relations/patterns.d.ts +67 -0
- package/lib/engine/mem/relations/statement.d.ts +88 -0
- package/lib/engine/mem/relations/types.d.ts +79 -0
- package/lib/engine/mem/runtime.d.ts +61 -88
- package/lib/engine/mem/storage/create.d.ts +42 -0
- package/lib/engine/mem/storage/errors.d.ts +65 -0
- package/lib/engine/mem/storage/index.d.ts +15 -0
- package/lib/engine/mem/storage/ports.d.ts +472 -0
- package/lib/engine/mem/storage/registry.d.ts +37 -0
- package/lib/engine/mem/storage/sqlite.d.ts +28 -0
- package/lib/engine/mem/store/common.d.ts +1 -1
- package/lib/engine/mem/store/entity_leg.d.ts +59 -2
- package/lib/engine/mem/store/entity_sweep.d.ts +4 -3
- package/lib/engine/mem/store/explicit_relations.d.ts +52 -0
- package/lib/engine/mem/store/facts_restore.d.ts +10 -2
- package/lib/engine/mem/store/floors.d.ts +4 -1
- package/lib/engine/mem/store/graph_reader.d.ts +146 -0
- package/lib/engine/mem/store/hybrid.d.ts +50 -13
- package/lib/engine/mem/store/kinds.d.ts +47 -0
- package/lib/engine/mem/store/legs.d.ts +24 -29
- package/lib/engine/mem/store/lexical.d.ts +36 -45
- package/lib/engine/mem/store/memory.d.ts +471 -83
- package/lib/engine/mem/store/recall_policy.d.ts +49 -0
- package/lib/engine/mem/store/relation_backfill.d.ts +210 -0
- package/lib/engine/mem/store/relation_planner.d.ts +191 -0
- package/lib/engine/mem/store/secret_guard.d.ts +0 -1
- package/lib/engine/mem/store/self_query.d.ts +4 -2
- package/lib/engine/mem/store/time_filter.d.ts +121 -0
- package/lib/engine/mem/store/titles.d.ts +52 -0
- package/lib/engine/mem/store/vector_repair.d.ts +44 -54
- package/lib/engine/mem-contract/config.d.ts +44 -38
- package/lib/engine/mem-contract/text.d.ts +1 -1
- package/lib/engine/mem-contract/tools.d.ts +145 -132
- package/lib/engine/mem-contract/types.d.ts +364 -288
- package/lib/index.js +12048 -11337
- package/lib/interface-version.json +1 -1
- package/lib/types/client/index.d.ts +2 -2
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/paging.d.ts +3 -12
- package/lib/types/client/paging.d.ts.map +1 -1
- package/lib/types/client/summarize.d.ts.map +1 -1
- package/lib/types/envinit-bootstrap.d.ts +1 -1
- package/lib/types/envinit.d.ts +2 -6
- package/lib/types/envinit.d.ts.map +1 -1
- package/lib/types/hints.d.ts +28 -24
- package/lib/types/hints.d.ts.map +1 -1
- package/lib/types/index.d.ts +21 -40
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/inject.d.ts +3 -2
- package/lib/types/inject.d.ts.map +1 -1
- package/lib/types/interface_gate.d.ts +1 -1
- package/lib/types/prompt.d.ts +17 -41
- package/lib/types/prompt.d.ts.map +1 -1
- package/lib/types/provision.d.ts +3 -0
- package/lib/types/provision.d.ts.map +1 -1
- package/lib/types/remote.d.ts +14 -7
- package/lib/types/remote.d.ts.map +1 -1
- package/lib/types/tool_schema.d.ts +4 -0
- package/lib/types/tool_schema.d.ts.map +1 -1
- package/lib/types/vectorMigration.d.ts +5 -7
- package/lib/types/vectorMigration.d.ts.map +1 -1
- package/package.json +15 -14
- package/lib/engine/mem/config/domains.d.ts +0 -20
- package/lib/engine/mem/db/dao/chunks.d.ts +0 -231
- package/lib/engine/mem/db/dao/documents.d.ts +0 -51
- package/lib/engine/mem/db/hash.d.ts +0 -2
- package/lib/engine/mem/db/knowledge.d.ts +0 -17
- package/lib/engine/mem/eval/index.d.ts +0 -4
- package/lib/engine/mem/git.d.ts +0 -73
- package/lib/engine/mem/router.d.ts +0 -51
- package/lib/engine/mem/store/doc_files.d.ts +0 -125
- package/lib/engine/mem/store/document_text.d.ts +0 -47
- package/lib/engine/mem/store/ingest_guard.d.ts +0 -25
- package/lib/engine/mem/store/knowledge.d.ts +0 -598
- package/lib/engine/mem/store/source_picker.d.ts +0 -43
- package/lib/engine/mem-retrieval/adapters/local_reranker.d.ts +0 -52
- package/lib/engine/mem-retrieval/adapters/none_reranker.d.ts +0 -10
- package/lib/engine/mem-retrieval/rerank.d.ts +0 -13
- package/lib/types/client/domains.d.ts +0 -53
- package/lib/types/client/domains.d.ts.map +0 -1
- package/lib/types/client/ingest.d.ts +0 -24
- package/lib/types/client/ingest.d.ts.map +0 -1
- package/lib/types/open.d.ts +0 -77
- package/lib/types/open.d.ts.map +0 -1
- package/lib/types/reconcile.d.ts +0 -64
- package/lib/types/reconcile.d.ts.map +0 -1
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import type { AdminRequest,
|
|
1
|
+
import type { AdminRequest, RecallRequest, RememberRequest, VectorsFixReport } from '../mem-contract/index.js';
|
|
2
2
|
import { type AvantfLogger, type StatsSummary } from '../mem-contract/index.js';
|
|
3
3
|
import { type SemanticBackend } from '../mem-retrieval/index.js';
|
|
4
4
|
import { type LoadedConfig } from './config/loader.js';
|
|
5
5
|
import { type Db } from './db/conn.js';
|
|
6
|
-
import { type RelevanceHit } from './store/lexical.js';
|
|
7
6
|
import { MemoryStore } from './store/memory.js';
|
|
8
|
-
import { KnowledgeStore } from './store/knowledge.js';
|
|
9
7
|
import { type FactsExportCodec, type ImportReport, type MergeReport } from './facts_io.js';
|
|
10
8
|
import type { RestoreReport } from './store/facts_restore.js';
|
|
9
|
+
/**
|
|
10
|
+
* The write rules a MODEL-FACING boundary adds on top of the contract (JOURNAL_TITLE_SEARCH §2.3).
|
|
11
|
+
*
|
|
12
|
+
* There is exactly one today: "a journal add must carry a title" cannot be expressed in zod's
|
|
13
|
+
* discriminated union without wrapping a branch in `superRefine`, which would break the JSON-Schema /
|
|
14
|
+
* DSH-parameter derivation (both read the branch's `.shape`). So it is enforced at the tool handler
|
|
15
|
+
* (`runToolSpec` → `dispatchToolKey`) and passed down as a store rule. It is deliberately NOT a
|
|
16
|
+
* store-wide invariant: old journals, old exports, the CLI and scripts all write untitled facts.
|
|
17
|
+
*/
|
|
18
|
+
export interface RememberWriteRules {
|
|
19
|
+
requireJournalTitle?: boolean;
|
|
20
|
+
}
|
|
11
21
|
export interface RuntimeOptions {
|
|
12
22
|
dataHome?: string;
|
|
13
23
|
memoryDbPath?: string;
|
|
@@ -106,15 +116,12 @@ export type AdminRestoreSnapshotReport = RestoreReport & {
|
|
|
106
116
|
codec: FactsExportCodec;
|
|
107
117
|
};
|
|
108
118
|
/**
|
|
109
|
-
* The payload of the
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* Grouping them is a CLAIM — that `probe`, `chain` and `reason` all answer like `search` — so it is
|
|
113
|
-
* proven rather than assumed: a type-level check asserts that each store method's result equals this
|
|
114
|
-
* one, and a divergence fails there instead of the grouped overload quietly lying about it. (Only
|
|
115
|
-
* `probe` holds by construction, because it calls `memory.search`.)
|
|
119
|
+
* The payload of `mem_recall.search`: the two-stage result (an exact page or a fuzzy shortlist).
|
|
120
|
+
* Named from the store method that produces it, so a change there cannot leave this alias lying.
|
|
116
121
|
*/
|
|
117
|
-
export type RecallHitsResult = StoreResult<MemoryStore, '
|
|
122
|
+
export type RecallHitsResult = StoreResult<MemoryStore, 'searchMemory'>;
|
|
123
|
+
/** The payload of `mem_recall.titles`: an exact page or a fuzzy shortlist of title candidates. */
|
|
124
|
+
export type RecallTitlesResult = StoreResult<MemoryStore, 'titles'>;
|
|
118
125
|
/**
|
|
119
126
|
* `remember` dispatches to five store operations whose RESULTS differ: `add`/`update` return the
|
|
120
127
|
* written fact, `remove` a flag, the feedback actions the new counter (or `null`). One plain
|
|
@@ -125,37 +132,30 @@ export type RecallHitsResult = StoreResult<MemoryStore, 'search'>;
|
|
|
125
132
|
export type RememberDispatch = {
|
|
126
133
|
(req: Extract<RememberRequest, {
|
|
127
134
|
action: 'add';
|
|
128
|
-
}
|
|
135
|
+
}>, rules?: RememberWriteRules): Promise<StoreResult<MemoryStore, 'add'>>;
|
|
129
136
|
(req: Extract<RememberRequest, {
|
|
130
137
|
action: 'update';
|
|
131
|
-
}
|
|
138
|
+
}>, rules?: RememberWriteRules): Promise<StoreResult<MemoryStore, 'update'>>;
|
|
132
139
|
(req: Extract<RememberRequest, {
|
|
133
140
|
action: 'remove';
|
|
134
141
|
}>): Promise<StoreResult<MemoryStore, 'remove'>>;
|
|
135
142
|
(req: Extract<RememberRequest, {
|
|
136
143
|
action: 'helpful' | 'unhelpful';
|
|
137
144
|
}>): Promise<StoreResult<MemoryStore, 'helpful'>>;
|
|
138
|
-
(req: RememberRequest): Promise<unknown>;
|
|
145
|
+
(req: RememberRequest, rules?: RememberWriteRules): Promise<unknown>;
|
|
139
146
|
};
|
|
140
147
|
/**
|
|
141
|
-
* Same per-action idea as {@link RememberDispatch}
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* assumed.
|
|
148
|
+
* Same per-action idea as {@link RememberDispatch}, over the TWO public recall actions
|
|
149
|
+
* (docs/RECALL_INTERFACE.md §1): a content search answers hits (exact page or fuzzy shortlist), a
|
|
150
|
+
* title search answers candidates. Two different payload shapes, so two overloads.
|
|
145
151
|
*/
|
|
146
152
|
export type RecallDispatch = {
|
|
147
153
|
(req: Extract<RecallRequest, {
|
|
148
|
-
action: 'search'
|
|
154
|
+
action: 'search';
|
|
149
155
|
}>): Promise<RecallHitsResult>;
|
|
150
156
|
(req: Extract<RecallRequest, {
|
|
151
|
-
action: '
|
|
152
|
-
}>): Promise<
|
|
153
|
-
(req: Extract<RecallRequest, {
|
|
154
|
-
action: 'related';
|
|
155
|
-
}>): Promise<StoreResult<MemoryStore, 'related'>>;
|
|
156
|
-
(req: Extract<RecallRequest, {
|
|
157
|
-
action: 'contradict';
|
|
158
|
-
}>): Promise<StoreResult<MemoryStore, 'listContradictions'>>;
|
|
157
|
+
action: 'titles';
|
|
158
|
+
}>): Promise<RecallTitlesResult>;
|
|
159
159
|
(req: RecallRequest): Promise<unknown>;
|
|
160
160
|
};
|
|
161
161
|
/**
|
|
@@ -167,46 +167,49 @@ export type RecallDispatch = {
|
|
|
167
167
|
export type AdminDispatch = {
|
|
168
168
|
(req: Extract<AdminRequest, {
|
|
169
169
|
action: 'stats';
|
|
170
|
-
}>): AdminStatsResult
|
|
170
|
+
}>): Promise<AdminStatsResult>;
|
|
171
171
|
(req: Extract<AdminRequest, {
|
|
172
172
|
action: 'list';
|
|
173
|
-
}>): StoreResult<MemoryStore, 'list'
|
|
173
|
+
}>): Promise<StoreResult<MemoryStore, 'list'>>;
|
|
174
174
|
(req: Extract<AdminRequest, {
|
|
175
175
|
action: 'detail';
|
|
176
|
-
}>): StoreResult<MemoryStore, 'get'> | DispatchError
|
|
176
|
+
}>): Promise<StoreResult<MemoryStore, 'get'> | DispatchError>;
|
|
177
177
|
(req: Extract<AdminRequest, {
|
|
178
178
|
action: 'archive';
|
|
179
|
-
}>): StoreResult<MemoryStore, 'archive'
|
|
179
|
+
}>): Promise<StoreResult<MemoryStore, 'archive'>>;
|
|
180
180
|
(req: Extract<AdminRequest, {
|
|
181
181
|
action: 'restore';
|
|
182
|
-
}>): StoreResult<MemoryStore, 'restore'
|
|
182
|
+
}>): Promise<StoreResult<MemoryStore, 'restore'>>;
|
|
183
183
|
(req: Extract<AdminRequest, {
|
|
184
184
|
action: 'pin';
|
|
185
|
-
}>): StoreResult<MemoryStore, 'pin'
|
|
185
|
+
}>): Promise<StoreResult<MemoryStore, 'pin'>>;
|
|
186
186
|
(req: Extract<AdminRequest, {
|
|
187
187
|
action: 'unpin';
|
|
188
|
-
}>): StoreResult<MemoryStore, 'unpin'
|
|
188
|
+
}>): Promise<StoreResult<MemoryStore, 'unpin'>>;
|
|
189
189
|
(req: Extract<AdminRequest, {
|
|
190
190
|
action: 'trust_diagnose';
|
|
191
|
-
}>): StoreResult<MemoryStore, 'trustDiagnose'
|
|
191
|
+
}>): Promise<StoreResult<MemoryStore, 'trustDiagnose'>>;
|
|
192
192
|
(req: Extract<AdminRequest, {
|
|
193
193
|
action: 'vectors_diagnose';
|
|
194
|
-
}>): StoreResult<MemoryStore, 'vectorsDiagnose'
|
|
194
|
+
}>): Promise<StoreResult<MemoryStore, 'vectorsDiagnose'>>;
|
|
195
195
|
(req: Extract<AdminRequest, {
|
|
196
196
|
action: 'vectors_fix';
|
|
197
197
|
}>): Promise<VectorsFixReport>;
|
|
198
198
|
(req: Extract<AdminRequest, {
|
|
199
199
|
action: 'contradict_check';
|
|
200
|
-
}>): StoreResult<MemoryStore, 'checkContradictions'
|
|
200
|
+
}>): Promise<StoreResult<MemoryStore, 'checkContradictions'>>;
|
|
201
|
+
(req: Extract<AdminRequest, {
|
|
202
|
+
action: 'contradictions';
|
|
203
|
+
}>): Promise<StoreResult<MemoryStore, 'listContradictions'>>;
|
|
201
204
|
(req: Extract<AdminRequest, {
|
|
202
205
|
action: 'contradict_resolve';
|
|
203
|
-
}>): StoreResult<MemoryStore, 'resolveContradiction'
|
|
206
|
+
}>): Promise<StoreResult<MemoryStore, 'resolveContradiction'>>;
|
|
204
207
|
(req: Extract<AdminRequest, {
|
|
205
208
|
action: 'maintenance';
|
|
206
|
-
}>): StoreResult<MemoryStore, 'maintenance'
|
|
209
|
+
}>): Promise<StoreResult<MemoryStore, 'maintenance'>>;
|
|
207
210
|
(req: Extract<AdminRequest, {
|
|
208
211
|
action: 'export';
|
|
209
|
-
}>): AdminExportReport
|
|
212
|
+
}>): Promise<AdminExportReport>;
|
|
210
213
|
/** Content-detected: a SQLite source answers with the db report, an export document with the JSON one. */
|
|
211
214
|
(req: Extract<AdminRequest, {
|
|
212
215
|
action: 'import';
|
|
@@ -219,68 +222,38 @@ export type AdminDispatch = {
|
|
|
219
222
|
}>): Promise<AdminRestoreSnapshotReport>;
|
|
220
223
|
(req: AdminRequest): unknown;
|
|
221
224
|
};
|
|
222
|
-
/**
|
|
223
|
-
* `kb_manage`: ingest/import report a batch, list/detail the corpus, remove a flag, reindex a
|
|
224
|
-
* plan. Members are pinned to the store methods that produce them (`ReturnType<…>`) so the
|
|
225
|
-
* shapes cannot drift into "whatever the caller assumed".
|
|
226
|
-
*
|
|
227
|
-
* `ingest`/`import` may instead answer with a {@link KbConflictReport}: this face is the UI/CLI
|
|
228
|
-
* REPLACE mode, where an unconfirmed collision writes nothing and comes back as a structured
|
|
229
|
-
* list. The add-only face (`kbAdd`) never returns one — it refuses.
|
|
230
|
-
*/
|
|
231
|
-
export type KbDispatch = {
|
|
232
|
-
(req: Extract<KbRequest, {
|
|
233
|
-
action: 'ingest';
|
|
234
|
-
}>): Promise<StoreResult<KnowledgeStore, 'ingest'> | KbConflictReport | DispatchError>;
|
|
235
|
-
(req: Extract<KbRequest, {
|
|
236
|
-
action: 'import';
|
|
237
|
-
}>): Promise<StoreResult<KnowledgeStore, 'importPaths'> | KbConflictReport>;
|
|
238
|
-
(req: Extract<KbRequest, {
|
|
239
|
-
action: 'list';
|
|
240
|
-
}>): Promise<StoreResult<KnowledgeStore, 'list'>>;
|
|
241
|
-
(req: Extract<KbRequest, {
|
|
242
|
-
action: 'detail';
|
|
243
|
-
}>): Promise<StoreResult<KnowledgeStore, 'detail'>>;
|
|
244
|
-
(req: Extract<KbRequest, {
|
|
245
|
-
action: 'remove';
|
|
246
|
-
}>): Promise<StoreResult<KnowledgeStore, 'remove'>>;
|
|
247
|
-
(req: Extract<KbRequest, {
|
|
248
|
-
action: 'reindex';
|
|
249
|
-
}>): Promise<StoreResult<KnowledgeStore, 'reindex'>>;
|
|
250
|
-
(req: KbRequest): Promise<unknown>;
|
|
251
|
-
};
|
|
252
225
|
export interface AvantfRuntime {
|
|
253
226
|
config: LoadedConfig;
|
|
254
227
|
db: Db;
|
|
255
228
|
memory: MemoryStore;
|
|
256
|
-
knowledge: KnowledgeStore;
|
|
257
229
|
/** Logger every startup/lifecycle line goes through. */
|
|
258
230
|
logger: AvantfLogger;
|
|
259
231
|
remember: RememberDispatch;
|
|
260
232
|
recall: RecallDispatch;
|
|
261
233
|
admin: AdminDispatch;
|
|
262
|
-
kb: KbDispatch;
|
|
263
234
|
/**
|
|
264
|
-
* The
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
*
|
|
272
|
-
* relevant to `text`? A boolean (`store/lexical.ts`) because the one tool the hint names
|
|
273
|
-
* (`kb_query`) retrieves from both stores, so "which one matched" changes no downstream decision.
|
|
274
|
-
* Synchronous on purpose — the caller renders it into a prompt provider that cannot await
|
|
275
|
-
* (DESIGN §12).
|
|
235
|
+
* The conditional hint's decision (DESIGN §12): would a memory retrieval return at least one hit
|
|
236
|
+
* for `text`? Implemented as `MemoryStore.search({ query: text, limit: 1, probe: true })` and
|
|
237
|
+
* answering `hits.length > 0` — there is no second threshold, no lexical short-circuit and no
|
|
238
|
+
* self-query special case here: retrieval already augments the query with its own rewrite.
|
|
239
|
+
*
|
|
240
|
+
* READ-ONLY is a contract: this runs on the user-message path and must never reinforce a fact,
|
|
241
|
+
* record retrieval/usage stats, warm/download a model, or mutate the vstore/DB. Never throws — a
|
|
242
|
+
* missing hint is harmless while a throwing `agent/pre-step` listener takes the step down.
|
|
276
243
|
*/
|
|
277
|
-
|
|
244
|
+
wouldFind(text: string): Promise<boolean>;
|
|
278
245
|
/**
|
|
279
246
|
* True once {@link shutdown} has run: the databases are closed and no background pass may start.
|
|
280
247
|
* A gated startup job checks this (as well as the plugin's fiber) before touching the stores.
|
|
281
248
|
*/
|
|
282
249
|
readonly closed: boolean;
|
|
283
|
-
shutdown(): void
|
|
250
|
+
shutdown(): Promise<void>;
|
|
284
251
|
}
|
|
285
|
-
/**
|
|
286
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Build the runtime: load config, open memory DB, construct the stores, run their open-time pass.
|
|
254
|
+
*
|
|
255
|
+
* ASYNC since DB-2: the store's startup pass (clock repair, lifecycle tick, vector-index reload) now
|
|
256
|
+
* awaits repository reads, so it cannot run inside a constructor. Making the open await it keeps the
|
|
257
|
+
* ordering every caller depends on — by the time `buildRuntime` resolves, the store is started.
|
|
258
|
+
*/
|
|
259
|
+
export declare function buildRuntime(opts?: RuntimeOptions): Promise<AvantfRuntime>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The storage composition root (DB-1; registry-based from DB-2/DB-3).
|
|
3
|
+
*
|
|
4
|
+
* One decision, made once: which driver serves this process. The configured name is resolved through
|
|
5
|
+
* the REGISTRY, so adding a storage is adding a driver package — never a new branch here
|
|
6
|
+
* (docs/DB_DRIVER_LAYOUT.md §一 rule "不要新增其他固定 backend 分支"). An unknown name fails
|
|
7
|
+
* explicitly and creates nothing; there is no silent SQLite fallback.
|
|
8
|
+
*
|
|
9
|
+
* The builtin drivers are imported below for their REGISTRATION side effect: this file is the
|
|
10
|
+
* factory, so the factory is where the builtins must be available, no matter which module graph the
|
|
11
|
+
* host loaded. `fake` is a builtin on purpose (DB-4, docs/DB_DRIVER_LAYOUT.md §五): it exists so the
|
|
12
|
+
* config switch and the async boundary can be exercised end to end without a second storage engine,
|
|
13
|
+
* which is why selecting it needs no import at the call site.
|
|
14
|
+
*
|
|
15
|
+
* @module storage/create
|
|
16
|
+
*/
|
|
17
|
+
import type { StorageConfig } from '../../mem-contract/index.js';
|
|
18
|
+
import type { StorageBackend } from '../interfaces/storage_backend.js';
|
|
19
|
+
import '../dbdrivers/sqlite/index.js';
|
|
20
|
+
import '../dbdrivers/fake/index.js';
|
|
21
|
+
/** Raised when `storage.backend` (or `storage.driver`) names a driver this host does not have. */
|
|
22
|
+
export declare class UnknownStorageBackendError extends Error {
|
|
23
|
+
readonly backend: string;
|
|
24
|
+
constructor(backend: string);
|
|
25
|
+
}
|
|
26
|
+
export interface CreateStorageBackendOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The configured contradiction threshold (`lifecycle.contradiction_threshold`), passed to the
|
|
29
|
+
* driver for its detector construction.
|
|
30
|
+
*/
|
|
31
|
+
readonly contradictionThreshold?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Open the selected driver.
|
|
35
|
+
*
|
|
36
|
+
* ASYNC because every driver's `open` is (DB-2): the SQLite driver resolves immediately, a remote one
|
|
37
|
+
* connects. Callers await it, so the host has one opening path.
|
|
38
|
+
*
|
|
39
|
+
* @throws {UnknownStorageBackendError} when the configured name has no registered driver.
|
|
40
|
+
* @throws {UnsupportedStorageContractError} when the driver's contract major is not supported.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createStorageBackend(config: StorageConfig, options?: CreateStorageBackendOptions): Promise<StorageBackend>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The storage error boundary (DB-3).
|
|
3
|
+
*
|
|
4
|
+
* SQLite reports failures as a driver error object with a numeric `errcode`; PostgreSQL has SQLSTATE,
|
|
5
|
+
* an HTTP backend has status codes, and none of those belong above the port. The store has exactly
|
|
6
|
+
* three things it can usefully do with a failed read/write: retry (the backend is temporarily
|
|
7
|
+
* unavailable), report a conflict (a uniqueness/constraint rule refused the write), or fail (anything
|
|
8
|
+
* else). This module names those three, and `db/sqlite.ts` — the one place that sees a driver error —
|
|
9
|
+
* maps into them.
|
|
10
|
+
*
|
|
11
|
+
* WHAT THIS IS NOT: a replacement for the domain refusals. `TITLE_IMMUTABLE`, `RELATIONS_NEED_NOTE`
|
|
12
|
+
* and the other `Error`s the store throws are decisions about the caller's request, not backend
|
|
13
|
+
* failures; they stay plain and unchanged. Only errors that come out of the database layer are
|
|
14
|
+
* classified here.
|
|
15
|
+
*
|
|
16
|
+
* The messages are preserved verbatim (the classification is metadata), so every existing caller and
|
|
17
|
+
* test that asserts on a driver message keeps working.
|
|
18
|
+
*
|
|
19
|
+
* @module storage/errors
|
|
20
|
+
*/
|
|
21
|
+
/** What a caller can do about a failed storage operation. */
|
|
22
|
+
export type StorageFailureKind = 'unavailable' | 'constraint' | 'corrupt' | 'unknown';
|
|
23
|
+
/** A database-layer failure, classified so the boundary does not leak a driver's error shape. */
|
|
24
|
+
export declare class StorageError extends Error {
|
|
25
|
+
readonly kind: StorageFailureKind;
|
|
26
|
+
constructor(message: string, kind: StorageFailureKind, options?: {
|
|
27
|
+
code?: string | number;
|
|
28
|
+
cause?: unknown;
|
|
29
|
+
});
|
|
30
|
+
/** The driver's own code, kept for a log line — never branched on above the adapter. */
|
|
31
|
+
readonly code?: string | number;
|
|
32
|
+
/** Whether the same call may succeed if repeated later (a lock timeout, a restarting server). */
|
|
33
|
+
get retryable(): boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The backend is temporarily unable to serve (SQLite: `SQLITE_BUSY`/`SQLITE_LOCKED`). */
|
|
36
|
+
export declare class StorageUnavailableError extends StorageError {
|
|
37
|
+
constructor(message: string, options?: {
|
|
38
|
+
code?: string | number;
|
|
39
|
+
cause?: unknown;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** The backend refused the write because of one of its integrity rules. */
|
|
43
|
+
export declare class StorageConstraintError extends StorageError {
|
|
44
|
+
constructor(message: string, options?: {
|
|
45
|
+
code?: string | number;
|
|
46
|
+
cause?: unknown;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** The stored data cannot be read (SQLite: `SQLITE_CORRUPT`/`SQLITE_NOTADB`). */
|
|
50
|
+
export declare class StorageCorruptError extends StorageError {
|
|
51
|
+
constructor(message: string, options?: {
|
|
52
|
+
code?: string | number;
|
|
53
|
+
cause?: unknown;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** Whether a caught value is already one of ours (a second mapping must not wrap it again). */
|
|
57
|
+
export declare function isStorageError(error: unknown): error is StorageError;
|
|
58
|
+
/**
|
|
59
|
+
* Classify a driver failure into the storage vocabulary.
|
|
60
|
+
*
|
|
61
|
+
* Takes `unknown` because that is what a `catch` binds; anything already classified is returned
|
|
62
|
+
* untouched (mapping is idempotent), and a non-error value becomes a generic `StorageError` carrying
|
|
63
|
+
* its string form, so callers never have to re-check.
|
|
64
|
+
*/
|
|
65
|
+
export declare function mapStorageError(error: unknown): StorageError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The storage boundary's public entry point (DB-1; registry factory since DB-2/DB-3).
|
|
3
|
+
*
|
|
4
|
+
* It re-exports the HAL CONTRACT (`interfaces/`) for the store and for external drivers, and the
|
|
5
|
+
* registry/factory that select a driver. It deliberately re-exports NO driver implementation: a
|
|
6
|
+
* caller that wants the SQLite backend imports `dbdrivers/sqlite` explicitly (turning a hidden
|
|
7
|
+
* dependency into a visible one), while `createStorageBackend` serves everyone else through the
|
|
8
|
+
* registry.
|
|
9
|
+
*
|
|
10
|
+
* @module storage
|
|
11
|
+
*/
|
|
12
|
+
export * from '../interfaces/index.js';
|
|
13
|
+
export type { StorageConfig } from '../../mem-contract/index.js';
|
|
14
|
+
export { assertSupportedDriver, lookupStorageDriver, registerStorageDriver, storageDriverNames, UnsupportedStorageContractError, } from './registry.js';
|
|
15
|
+
export { createStorageBackend, UnknownStorageBackendError, type CreateStorageBackendOptions } from './create.js';
|