@world-engines/ladybug-bridge 0.1.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 +46 -0
- package/README.md +3 -0
- package/dist/index.d.ts +704 -0
- package/dist/index.js +3781 -0
- package/dist/view-access-policy.d.ts +153 -0
- package/dist/view-access-policy.js +835 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import { type Connection, type Database } from "@ladybugdb/wasm-core";
|
|
2
|
+
export { canonicalLadybugRelationId, createViewAccessPolicySubject, derivedGraphViewAccessPolicy, deriveViewAccessPolicySubjectId, deriveViewAccessPolicySubjectIdForTarget, isViewReadable, isViewWritable, resolveEdgeViewAccessMode, resolveOverlayLeafViewAccessMode, resolveViewAccessMode, sealViewAccessPolicy, validateViewAccessPolicy, viewAccessPolicyAddressForTarget, VIEW_ACCESS_POLICY_DENY_ROOT, VIEW_ACCESS_POLICY_ROOT_SUBJECT_ID, VIEW_ACCESS_POLICY_SCHEMA_VERSION, } from "./view-access-policy.js";
|
|
3
|
+
export type { AttributeOwnerKind, CanonicalWalLeafChange, EffectiveViewAccessMode, OverlayLeafAccessInput, OverlayLeafProvenance, TypedLadybugTarget, ViewAccessAttributeOwnerAddress, ViewAccessMode, ViewAccessPolicyAddress, ViewAccessPolicySnapshot, DerivedGraphViewAccessPolicy, ViewAccessPolicySubject, ViewAccessPolicySubjectKind, ViewAccessPolicyTarget, ViewAccessResolution, } from "./view-access-policy.js";
|
|
4
|
+
export type LadybugVariant = {
|
|
5
|
+
setWorkerPath?: (workerPath: string) => void;
|
|
6
|
+
init: () => Promise<void>;
|
|
7
|
+
getVersion: () => Promise<string>;
|
|
8
|
+
Database: new (databasePath?: string) => Database;
|
|
9
|
+
Connection: new (database: Database) => Connection;
|
|
10
|
+
};
|
|
11
|
+
export type EntityRow = {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
readonly props: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type RecallCandidateRecord = {
|
|
17
|
+
readonly entity: EntityRow;
|
|
18
|
+
readonly embedding: readonly number[];
|
|
19
|
+
readonly messageId: string;
|
|
20
|
+
readonly turnId: string;
|
|
21
|
+
readonly recordedRevision: number;
|
|
22
|
+
readonly writeRevision: number;
|
|
23
|
+
};
|
|
24
|
+
export type AnalyzerArmStatus = "ready" | "unavailable" | "reindex-needed" | "failed";
|
|
25
|
+
export type AnalyzerTokenProjection = Readonly<{
|
|
26
|
+
readonly original: string;
|
|
27
|
+
readonly normalized: string;
|
|
28
|
+
readonly stem: string;
|
|
29
|
+
readonly start: number;
|
|
30
|
+
readonly end: number;
|
|
31
|
+
}>;
|
|
32
|
+
export type AnalyzerRelationSignalProjection = Readonly<{
|
|
33
|
+
readonly kind: "negation" | "completion" | "modality" | "relation";
|
|
34
|
+
readonly normalized: string;
|
|
35
|
+
readonly tokenIndexes: readonly number[];
|
|
36
|
+
readonly version: string;
|
|
37
|
+
readonly canonical?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* 单个实体的版本化分析器旁路投影。规范实体属性保持不变;
|
|
41
|
+
* 该投影是实体全文检索分支唯一索引的文本。
|
|
42
|
+
*/
|
|
43
|
+
export type EntityAnalyzerProjection = Readonly<{
|
|
44
|
+
readonly contractVersion: number;
|
|
45
|
+
readonly analyzerId: string;
|
|
46
|
+
readonly analyzerVersion: string;
|
|
47
|
+
readonly lexicalStatus: Exclude<AnalyzerArmStatus, "reindex-needed">;
|
|
48
|
+
readonly relationalStatus: Exclude<AnalyzerArmStatus, "reindex-needed">;
|
|
49
|
+
readonly lexicalText: string;
|
|
50
|
+
readonly tokens: readonly AnalyzerTokenProjection[];
|
|
51
|
+
readonly relationSignals: readonly AnalyzerRelationSignalProjection[];
|
|
52
|
+
}>;
|
|
53
|
+
export type EntityAnalyzerProjectionReadback = Readonly<{
|
|
54
|
+
readonly entityId: string;
|
|
55
|
+
readonly lexicalStatus: AnalyzerArmStatus;
|
|
56
|
+
readonly relationalStatus: AnalyzerArmStatus;
|
|
57
|
+
readonly lexicalArm: Readonly<{
|
|
58
|
+
readonly status: AnalyzerArmStatus;
|
|
59
|
+
readonly analyzerVersion: string | null;
|
|
60
|
+
}>;
|
|
61
|
+
readonly relationalArm: Readonly<{
|
|
62
|
+
readonly status: AnalyzerArmStatus;
|
|
63
|
+
readonly analyzerVersion: string | null;
|
|
64
|
+
}>;
|
|
65
|
+
readonly projection: EntityAnalyzerProjection | null;
|
|
66
|
+
}>;
|
|
67
|
+
export type RelationRow = {
|
|
68
|
+
readonly src: string;
|
|
69
|
+
readonly dst: string;
|
|
70
|
+
readonly kind: string;
|
|
71
|
+
readonly props: unknown;
|
|
72
|
+
};
|
|
73
|
+
export type BulkEntityRow = {
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly kind: string;
|
|
76
|
+
readonly props: unknown;
|
|
77
|
+
readonly embedding: readonly number[] | null;
|
|
78
|
+
readonly messageId: string;
|
|
79
|
+
readonly turnId: string;
|
|
80
|
+
readonly analyzerProjection?: EntityAnalyzerProjection;
|
|
81
|
+
};
|
|
82
|
+
export type BulkRelationRow = {
|
|
83
|
+
readonly src: string;
|
|
84
|
+
readonly dst: string;
|
|
85
|
+
readonly kind: string;
|
|
86
|
+
readonly props: unknown;
|
|
87
|
+
readonly messageId: string;
|
|
88
|
+
readonly turnId: string;
|
|
89
|
+
};
|
|
90
|
+
export type RollbackResult = {
|
|
91
|
+
readonly deletedEntities: number;
|
|
92
|
+
readonly deletedRelations: number;
|
|
93
|
+
};
|
|
94
|
+
export type LadybugDiagnostics = {
|
|
95
|
+
readonly entityCount: number;
|
|
96
|
+
readonly relationCount: number;
|
|
97
|
+
readonly embeddedEntityCount: number;
|
|
98
|
+
readonly vectorIndexedEntityCount: number;
|
|
99
|
+
readonly ftsIndexedEntityCount: number;
|
|
100
|
+
readonly vectorIndexBuilt: boolean;
|
|
101
|
+
readonly ftsIndexBuilt: boolean;
|
|
102
|
+
};
|
|
103
|
+
export type TranscriptMessageRole = "user" | "assistant";
|
|
104
|
+
export type TranscriptMessageStatus = "streaming" | "done" | "failed" | "aborted" | "tombstoned";
|
|
105
|
+
export type TranscriptScope = {
|
|
106
|
+
readonly scenarioId: string;
|
|
107
|
+
readonly saveId: string;
|
|
108
|
+
readonly worldlineId: string;
|
|
109
|
+
};
|
|
110
|
+
export type TranscriptMessageRecord = TranscriptScope & {
|
|
111
|
+
readonly messageId: string;
|
|
112
|
+
readonly turnId: string;
|
|
113
|
+
readonly role: TranscriptMessageRole;
|
|
114
|
+
readonly content: string;
|
|
115
|
+
readonly status: TranscriptMessageStatus;
|
|
116
|
+
readonly createdAtMs: number;
|
|
117
|
+
readonly updatedAtMs: number;
|
|
118
|
+
/**
|
|
119
|
+
* The first committed conversation-ledger sequence for this message inside
|
|
120
|
+
* this exact scenario/save/worldline scope. Later edit/tombstone ledger
|
|
121
|
+
* events must retain this immutable identity rather than supplying their
|
|
122
|
+
* newer event sequence.
|
|
123
|
+
*/
|
|
124
|
+
readonly sourceLedgerSeq: number;
|
|
125
|
+
};
|
|
126
|
+
export type TranscriptMessageInput = Omit<TranscriptMessageRecord, keyof TranscriptScope>;
|
|
127
|
+
export type TranscriptScopedAccess = {
|
|
128
|
+
readonly scope: TranscriptScope;
|
|
129
|
+
};
|
|
130
|
+
export type TranscriptJournalIdentity = {
|
|
131
|
+
/** Save-scoped Runtime2 journal idempotency key. */
|
|
132
|
+
readonly idempotencyKey: string;
|
|
133
|
+
/** Hash of the sealed Runtime2 transaction payload. */
|
|
134
|
+
readonly payloadSha256: string;
|
|
135
|
+
/** Exact durable journal phase authorizing this transcript mutation. */
|
|
136
|
+
readonly phase: string;
|
|
137
|
+
readonly phaseRevision: number;
|
|
138
|
+
};
|
|
139
|
+
export type TranscriptPendingJournalAuthority = {
|
|
140
|
+
readonly identity: TranscriptJournalIdentity;
|
|
141
|
+
/** Digest of the exact ordered transcript records plus suffix sealed by the journal. */
|
|
142
|
+
readonly mutationPayloadSha256: string;
|
|
143
|
+
/**
|
|
144
|
+
* Exact union of pre- and post-mutation message ids sealed by the pending
|
|
145
|
+
* journal. This permits suffix removal plus replacement upserts without
|
|
146
|
+
* granting authority over unrelated rows.
|
|
147
|
+
*/
|
|
148
|
+
readonly authorizedMutationMessageIds: readonly string[];
|
|
149
|
+
/** Exact upsert cohort and immutable first-ledger identities sealed by the journal. */
|
|
150
|
+
readonly requiredUpserts: readonly Readonly<{
|
|
151
|
+
readonly messageId: string;
|
|
152
|
+
readonly sourceLedgerSeq: number;
|
|
153
|
+
}>[];
|
|
154
|
+
/** Exact suffix operation sealed by the journal, or null when none is authorized. */
|
|
155
|
+
readonly suffix: TranscriptSuffixMutationSpec | null;
|
|
156
|
+
};
|
|
157
|
+
export type TranscriptAuthorityRequest = TranscriptScopedAccess & {
|
|
158
|
+
readonly operation: "mutation" | "recall";
|
|
159
|
+
readonly journal: TranscriptJournalIdentity | null;
|
|
160
|
+
};
|
|
161
|
+
export type TranscriptReachabilitySnapshot = TranscriptScope & {
|
|
162
|
+
/** Domain-separated digest/version of the host-owned active worldline lineage. */
|
|
163
|
+
readonly lineageDigest: string;
|
|
164
|
+
/** Exact active reachable user/assistant message IDs for this scope. */
|
|
165
|
+
readonly activeReachableMessageIds: readonly string[];
|
|
166
|
+
/**
|
|
167
|
+
* Host-owned pending Runtime2 journal. Ordinary recall is rejected whenever
|
|
168
|
+
* this is non-null. Mutations require an exact identity match.
|
|
169
|
+
*/
|
|
170
|
+
readonly pendingJournal: TranscriptPendingJournalAuthority | null;
|
|
171
|
+
};
|
|
172
|
+
export type TranscriptReachabilityResolver = (request: Readonly<TranscriptAuthorityRequest>) => Promise<TranscriptReachabilitySnapshot>;
|
|
173
|
+
export type TranscriptMutationAccess = TranscriptScopedAccess & {
|
|
174
|
+
readonly journal: TranscriptJournalIdentity;
|
|
175
|
+
};
|
|
176
|
+
export type TranscriptUpsertRequest = TranscriptMutationAccess & {
|
|
177
|
+
readonly message: TranscriptMessageInput;
|
|
178
|
+
};
|
|
179
|
+
export type TranscriptUpsertBatchRequest = TranscriptMutationAccess & {
|
|
180
|
+
readonly messages: readonly TranscriptMessageInput[];
|
|
181
|
+
};
|
|
182
|
+
export type TranscriptRecallRequest = TranscriptScopedAccess & {
|
|
183
|
+
readonly query: string;
|
|
184
|
+
readonly topK: number;
|
|
185
|
+
};
|
|
186
|
+
export type TranscriptRecallHit = TranscriptMessageRecord & {
|
|
187
|
+
readonly score: number;
|
|
188
|
+
};
|
|
189
|
+
export type TranscriptSuffixMutationSpec = {
|
|
190
|
+
/** Mutates records with sourceLedgerSeq strictly greater than this pivot. */
|
|
191
|
+
readonly afterSourceLedgerSeq: number;
|
|
192
|
+
readonly mode: "tombstone" | "delete";
|
|
193
|
+
readonly updatedAtMs: number;
|
|
194
|
+
};
|
|
195
|
+
export type TranscriptSuffixMutation = TranscriptMutationAccess & TranscriptSuffixMutationSpec;
|
|
196
|
+
export type TranscriptMutationBatchRequest = TranscriptMutationAccess & {
|
|
197
|
+
readonly messages: readonly TranscriptMessageInput[];
|
|
198
|
+
readonly suffix?: TranscriptSuffixMutationSpec;
|
|
199
|
+
};
|
|
200
|
+
export type TranscriptMutationReceipt = {
|
|
201
|
+
readonly journal: TranscriptJournalIdentity;
|
|
202
|
+
readonly lineageDigest: string;
|
|
203
|
+
readonly mutationPayloadSha256: string;
|
|
204
|
+
readonly activeReachableMessageIds: readonly string[];
|
|
205
|
+
readonly upsertedMessageIds: readonly string[];
|
|
206
|
+
readonly upserts: readonly Readonly<{
|
|
207
|
+
readonly messageId: string;
|
|
208
|
+
readonly sourceLedgerSeq: number;
|
|
209
|
+
}>[];
|
|
210
|
+
readonly suffix: TranscriptSuffixMutationSpec | null;
|
|
211
|
+
readonly suffixMode: TranscriptSuffixMutationSpec["mode"] | null;
|
|
212
|
+
readonly suffixAffectedMessageIds: readonly string[];
|
|
213
|
+
readonly receiptSha256: string;
|
|
214
|
+
};
|
|
215
|
+
export type TranscriptMutationBatchResult = {
|
|
216
|
+
readonly messages: readonly TranscriptMessageRecord[];
|
|
217
|
+
readonly receipt: TranscriptMutationReceipt;
|
|
218
|
+
};
|
|
219
|
+
export type TranscriptSuffixMutationResult = {
|
|
220
|
+
readonly mode: TranscriptSuffixMutation["mode"];
|
|
221
|
+
readonly affectedMessageIds: readonly string[];
|
|
222
|
+
readonly receipt: TranscriptMutationReceipt;
|
|
223
|
+
};
|
|
224
|
+
declare const WORLD_MEMORY_HOST_AUTHORITY_TYPE: unique symbol;
|
|
225
|
+
/**
|
|
226
|
+
* Unserializable per-bridge capability held by the trusted top-window host.
|
|
227
|
+
* Author views, business graph callers and external LLMs must never receive it.
|
|
228
|
+
*/
|
|
229
|
+
export type WorldMemoryHostAuthority = Readonly<{
|
|
230
|
+
readonly [WORLD_MEMORY_HOST_AUTHORITY_TYPE]: "world-memory-host-authority";
|
|
231
|
+
}>;
|
|
232
|
+
export declare function createWorldMemoryHostAuthority(): WorldMemoryHostAuthority;
|
|
233
|
+
export type MemoryAuthorityClass = "world_fact" | "observation" | "experience" | "summary";
|
|
234
|
+
export type MemoryDerivedKind = "observation" | "experience" | "summary";
|
|
235
|
+
export type MemoryEpisode = {
|
|
236
|
+
readonly id: string;
|
|
237
|
+
readonly sourceMessageIds: readonly string[];
|
|
238
|
+
readonly turnBundleId: string;
|
|
239
|
+
readonly synopsis: string;
|
|
240
|
+
readonly embedding: readonly number[];
|
|
241
|
+
readonly sourceDigest: string;
|
|
242
|
+
readonly worldTimeFrom: number;
|
|
243
|
+
readonly worldTimeTo: number | null;
|
|
244
|
+
readonly recordedWriteSeq: number;
|
|
245
|
+
readonly reachability: string;
|
|
246
|
+
readonly model: string;
|
|
247
|
+
readonly provider: string;
|
|
248
|
+
readonly attemptId: string;
|
|
249
|
+
readonly schemaVersion: number;
|
|
250
|
+
};
|
|
251
|
+
export type MemoryClaimRoot = {
|
|
252
|
+
readonly id: string;
|
|
253
|
+
readonly subjectKind: string;
|
|
254
|
+
readonly entityId: string | null;
|
|
255
|
+
readonly attrPath: string | null;
|
|
256
|
+
readonly relationKey: string | null;
|
|
257
|
+
readonly currentClaimId: string | null;
|
|
258
|
+
readonly latestRevision: number;
|
|
259
|
+
readonly schemaVersion: number;
|
|
260
|
+
};
|
|
261
|
+
export type MemoryClaim = {
|
|
262
|
+
readonly id: string;
|
|
263
|
+
readonly rootId: string;
|
|
264
|
+
readonly authorityClass: "world_fact";
|
|
265
|
+
readonly status: string;
|
|
266
|
+
/** Strict canonical JSON, verified before persistence. */
|
|
267
|
+
readonly canonicalValue: string;
|
|
268
|
+
readonly canonicalValueSha256: string;
|
|
269
|
+
readonly confidence: number;
|
|
270
|
+
readonly recordedFromWriteSeq: number;
|
|
271
|
+
readonly recordedToWriteSeq: number | null;
|
|
272
|
+
readonly validFromWorldSeconds: number;
|
|
273
|
+
readonly validToWorldSeconds: number | null;
|
|
274
|
+
readonly sourceDigest: string;
|
|
275
|
+
readonly sourceEpisodeIds: readonly string[];
|
|
276
|
+
readonly sourceMessageIds: readonly string[];
|
|
277
|
+
readonly revision: number;
|
|
278
|
+
readonly schemaVersion: number;
|
|
279
|
+
};
|
|
280
|
+
type MemoryDerivedFields = {
|
|
281
|
+
readonly id: string;
|
|
282
|
+
readonly text: string;
|
|
283
|
+
readonly embedding: readonly number[];
|
|
284
|
+
readonly status: string;
|
|
285
|
+
readonly sourceDigest: string;
|
|
286
|
+
readonly coverageIds: readonly string[];
|
|
287
|
+
readonly summarizedThroughOpId: string | null;
|
|
288
|
+
readonly validFromWorldSeconds: number;
|
|
289
|
+
readonly validToWorldSeconds: number | null;
|
|
290
|
+
readonly recordedWriteSeq: number;
|
|
291
|
+
readonly model: string;
|
|
292
|
+
readonly provider: string;
|
|
293
|
+
readonly promptVersion: string;
|
|
294
|
+
readonly tokenizerVersion: string;
|
|
295
|
+
readonly schemaVersion: number;
|
|
296
|
+
};
|
|
297
|
+
export type MemoryDerived = Readonly<MemoryDerivedFields & ({
|
|
298
|
+
readonly derivedKind: "observation";
|
|
299
|
+
readonly authorityClass: "observation";
|
|
300
|
+
} | {
|
|
301
|
+
readonly derivedKind: "experience";
|
|
302
|
+
readonly authorityClass: "experience";
|
|
303
|
+
} | {
|
|
304
|
+
readonly derivedKind: "summary";
|
|
305
|
+
readonly authorityClass: "summary";
|
|
306
|
+
})>;
|
|
307
|
+
export type MemoryRelationKind = "WmEpisodeSupportsClaim" | "WmClaimSupersedesClaim" | "WmClaimContradictsClaim" | "WmDerivedFromEpisode" | "WmDerivedFromClaim" | "WmEpisodeMentionsEntity" | "WmDerivedMentionsEntity" | "WmClaimAboutEntity";
|
|
308
|
+
export type MemoryRelation = {
|
|
309
|
+
readonly kind: MemoryRelationKind;
|
|
310
|
+
readonly sourceId: string;
|
|
311
|
+
readonly targetId: string;
|
|
312
|
+
};
|
|
313
|
+
export type MemoryVectorSearchHit = {
|
|
314
|
+
readonly id: string;
|
|
315
|
+
readonly distance: number;
|
|
316
|
+
};
|
|
317
|
+
export type MemoryFullTextSearchHit = {
|
|
318
|
+
readonly id: string;
|
|
319
|
+
readonly score: number;
|
|
320
|
+
};
|
|
321
|
+
export type MemoryClosure = {
|
|
322
|
+
readonly episodeIds?: readonly string[];
|
|
323
|
+
readonly claimRootIds?: readonly string[];
|
|
324
|
+
readonly claimIds?: readonly string[];
|
|
325
|
+
readonly derivedIds?: readonly string[];
|
|
326
|
+
};
|
|
327
|
+
export type MemoryClosureDeleteResult = {
|
|
328
|
+
readonly deletedEpisodes: number;
|
|
329
|
+
readonly deletedClaimRoots: number;
|
|
330
|
+
readonly deletedClaims: number;
|
|
331
|
+
readonly deletedDerived: number;
|
|
332
|
+
};
|
|
333
|
+
/** Narrow capability surface used by the trusted WorldMemory host module. */
|
|
334
|
+
export type WorldMemoryHostAdapter = Readonly<{
|
|
335
|
+
upsertMemoryEpisode(row: MemoryEpisode): Promise<void>;
|
|
336
|
+
upsertMemoryClaimRoot(row: MemoryClaimRoot): Promise<void>;
|
|
337
|
+
upsertMemoryClaim(row: MemoryClaim): Promise<void>;
|
|
338
|
+
upsertMemoryDerived(row: MemoryDerived): Promise<void>;
|
|
339
|
+
upsertMemoryRelation(row: MemoryRelation): Promise<void>;
|
|
340
|
+
getClaimRoot(id: string): Promise<MemoryClaimRoot | null>;
|
|
341
|
+
getClaimsByRoot(rootId: string): Promise<MemoryClaim[]>;
|
|
342
|
+
resolveClaimsForEntities(entityIds: readonly string[]): Promise<MemoryClaim[]>;
|
|
343
|
+
vectorSearchEpisodes(query: readonly number[], topK: number, config?: QueryConfig): Promise<MemoryVectorSearchHit[]>;
|
|
344
|
+
fullTextSearchEpisodes(query: string, topK: number, config?: QueryConfig): Promise<MemoryFullTextSearchHit[]>;
|
|
345
|
+
vectorSearchDerived(query: readonly number[], topK: number, config?: QueryConfig): Promise<MemoryVectorSearchHit[]>;
|
|
346
|
+
fullTextSearchDerived(query: string, topK: number, config?: QueryConfig): Promise<MemoryFullTextSearchHit[]>;
|
|
347
|
+
deleteMemoryClosure(closure: MemoryClosure): Promise<MemoryClosureDeleteResult>;
|
|
348
|
+
snapshotWorldMemory(): Promise<WorldMemorySnapshot>;
|
|
349
|
+
captureWorldMemoryView(): Promise<WorldMemoryView>;
|
|
350
|
+
worldMemoryStateDigest(): Promise<string>;
|
|
351
|
+
stateIdentity(): Promise<Readonly<{
|
|
352
|
+
physicalStateSha256: string;
|
|
353
|
+
writeSequence: number;
|
|
354
|
+
}>>;
|
|
355
|
+
restoreWorldMemorySnapshot(snapshot: WorldMemorySnapshot): Promise<void>;
|
|
356
|
+
}>;
|
|
357
|
+
export type WorldMemorySnapshot = {
|
|
358
|
+
readonly episodes: readonly MemoryEpisode[];
|
|
359
|
+
readonly claimRoots: readonly MemoryClaimRoot[];
|
|
360
|
+
readonly claims: readonly MemoryClaim[];
|
|
361
|
+
readonly derived: readonly MemoryDerived[];
|
|
362
|
+
readonly relations: readonly MemoryRelation[];
|
|
363
|
+
readonly episodeVectorIndexBuilt: boolean;
|
|
364
|
+
readonly episodeFtsIndexBuilt: boolean;
|
|
365
|
+
readonly derivedVectorIndexBuilt: boolean;
|
|
366
|
+
readonly derivedFtsIndexBuilt: boolean;
|
|
367
|
+
};
|
|
368
|
+
export type WorldMemoryView = Readonly<{
|
|
369
|
+
readonly snapshot: WorldMemorySnapshot;
|
|
370
|
+
readonly identity: Readonly<{
|
|
371
|
+
readonly snapshotSha256: string;
|
|
372
|
+
readonly revision: number;
|
|
373
|
+
}>;
|
|
374
|
+
}>;
|
|
375
|
+
export type NeighborRow = {
|
|
376
|
+
readonly id: string;
|
|
377
|
+
readonly kind: string;
|
|
378
|
+
readonly edgeKind: string;
|
|
379
|
+
readonly depth: number;
|
|
380
|
+
};
|
|
381
|
+
export type VectorHit = {
|
|
382
|
+
readonly id: string;
|
|
383
|
+
readonly distance: number;
|
|
384
|
+
};
|
|
385
|
+
export type GraphRagSeed = {
|
|
386
|
+
readonly id: string;
|
|
387
|
+
readonly distance: number;
|
|
388
|
+
};
|
|
389
|
+
export type NodeProvenance = {
|
|
390
|
+
readonly seedId: string;
|
|
391
|
+
readonly hop: number;
|
|
392
|
+
};
|
|
393
|
+
export type GraphRagNode = {
|
|
394
|
+
readonly entity: EntityRow;
|
|
395
|
+
readonly provenance: readonly NodeProvenance[];
|
|
396
|
+
};
|
|
397
|
+
export type GraphRagResult = {
|
|
398
|
+
readonly seeds: readonly GraphRagSeed[];
|
|
399
|
+
readonly nodes: readonly GraphRagNode[];
|
|
400
|
+
readonly edges: readonly RelationRow[];
|
|
401
|
+
};
|
|
402
|
+
export declare const STRUCTURED_TRIGGER_LOCK_REASON_LOCKED_UNTIL: "locked_until";
|
|
403
|
+
export declare const STRUCTURED_TRIGGER_LOCK_REASON_ENTER_WHEN: "enter_when";
|
|
404
|
+
export type StructuredTriggerLockReason = typeof STRUCTURED_TRIGGER_LOCK_REASON_LOCKED_UNTIL | typeof STRUCTURED_TRIGGER_LOCK_REASON_ENTER_WHEN;
|
|
405
|
+
export type StructuredTriggerLock = {
|
|
406
|
+
readonly trigger_id: string;
|
|
407
|
+
readonly reason: StructuredTriggerLockReason | string;
|
|
408
|
+
};
|
|
409
|
+
export type StructuredObjectValue = {
|
|
410
|
+
readonly type: "object";
|
|
411
|
+
readonly inner_keys: readonly string[];
|
|
412
|
+
readonly expandable: boolean;
|
|
413
|
+
};
|
|
414
|
+
export type StructuredValue = StructuredObjectValue | unknown;
|
|
415
|
+
export type StructuredEntry = {
|
|
416
|
+
readonly key: string;
|
|
417
|
+
readonly value: StructuredValue;
|
|
418
|
+
readonly expandable: boolean;
|
|
419
|
+
readonly trigger_lock?: StructuredTriggerLock;
|
|
420
|
+
};
|
|
421
|
+
export type RecallStructured = {
|
|
422
|
+
readonly entities: readonly StructuredEntry[];
|
|
423
|
+
};
|
|
424
|
+
export declare function isStructuredObjectValue(v: unknown): v is StructuredObjectValue;
|
|
425
|
+
export type LadybugBridgeOptions = {
|
|
426
|
+
readonly dim: number;
|
|
427
|
+
readonly workerPath?: string;
|
|
428
|
+
/** Trusted host authority. Transcript APIs fail closed when it is absent. */
|
|
429
|
+
readonly resolveTranscriptReachability?: TranscriptReachabilityResolver;
|
|
430
|
+
/** Exact object-identity capability required to obtain the WorldMemory adapter. */
|
|
431
|
+
readonly worldMemoryHostAuthority?: WorldMemoryHostAuthority;
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Structural capability passed only to the trusted Rust/WASM runtime.
|
|
435
|
+
* It exposes the graph methods consumed by `LadybugStore`, while keeping
|
|
436
|
+
* WorldMemory raw tables behind `WorldMemoryHostAdapter`.
|
|
437
|
+
*/
|
|
438
|
+
export type LadybugWasmRuntimeAdapter = Readonly<Pick<LadybugBridge, "allEntities" | "allRelations" | "attrHistoryCheck" | "beginTransaction" | "bulkUpsertEntities" | "bulkUpsertRelations" | "close" | "commitTransaction" | "createFtsIndex" | "createVectorIndex" | "deleteEntity" | "deleteRelation" | "diagnostics" | "dropFtsIndex" | "dropVectorIndex" | "entityCount" | "findByKind" | "fullTextSearch" | "getById" | "hasEmbedding" | "hasFtsIndex" | "hasVectorIndex" | "init" | "latchClear" | "latchCommitBatch" | "latchLoad" | "latchRollback" | "neighbors" | "pruneAttrHistory" | "query" | "queryAttrHistory" | "recallAndExpand" | "recallCandidateRecord" | "relationCount" | "rollbackAfterMessage" | "rollbackAttrHistoryAfterMessage" | "rollbackTransaction" | "stateDigest" | "upsertAttrHistory" | "upsertEntity" | "upsertRelation" | "vectorSearch"> & {
|
|
439
|
+
worldMemoryStateDigest(): Promise<string>;
|
|
440
|
+
restoreWorldMemorySnapshotInTransaction(snapshot: WorldMemorySnapshot): Promise<void>;
|
|
441
|
+
}>;
|
|
442
|
+
export type IndexConfig = {
|
|
443
|
+
readonly metric?: string;
|
|
444
|
+
readonly mu?: number;
|
|
445
|
+
readonly ml?: number;
|
|
446
|
+
readonly efc?: number;
|
|
447
|
+
readonly cache_embeddings?: boolean;
|
|
448
|
+
readonly stemmer?: string;
|
|
449
|
+
readonly tokenizer?: string;
|
|
450
|
+
readonly stopwords?: string;
|
|
451
|
+
};
|
|
452
|
+
export type QueryConfig = {
|
|
453
|
+
readonly efs?: number;
|
|
454
|
+
readonly bm25_k1?: number;
|
|
455
|
+
readonly bm25_b?: number;
|
|
456
|
+
readonly conjunctive?: boolean;
|
|
457
|
+
};
|
|
458
|
+
export type NeighborsOptions = {
|
|
459
|
+
readonly entityKinds?: readonly string[];
|
|
460
|
+
readonly relationKinds?: readonly string[];
|
|
461
|
+
};
|
|
462
|
+
export declare const WM_EPISODE_VECTOR_INDEX = "WM_EPISODE_VECTOR_INDEX";
|
|
463
|
+
export declare const WM_EPISODE_FTS_INDEX = "WM_EPISODE_FTS_INDEX";
|
|
464
|
+
export declare const WM_DERIVED_VECTOR_INDEX = "WM_DERIVED_VECTOR_INDEX";
|
|
465
|
+
export declare const WM_DERIVED_FTS_INDEX = "WM_DERIVED_FTS_INDEX";
|
|
466
|
+
export declare const SNAPSHOT_PROVENANCE_MESSAGE_ID = "__initial_snapshot__";
|
|
467
|
+
export type LatchState = "open" | "closed" | "dead";
|
|
468
|
+
export type LatchSource = "deterministic" | "judge";
|
|
469
|
+
export type LeafLatchRow = {
|
|
470
|
+
readonly scenario_id: string;
|
|
471
|
+
readonly leaf_id: string;
|
|
472
|
+
readonly state: LatchState;
|
|
473
|
+
readonly first_fired_at_ms: number;
|
|
474
|
+
readonly last_evaluated_at_ms: number;
|
|
475
|
+
readonly fire_count: number;
|
|
476
|
+
readonly source: LatchSource;
|
|
477
|
+
readonly confidence: number;
|
|
478
|
+
};
|
|
479
|
+
export type AttrHistoryRow = {
|
|
480
|
+
readonly attrHistoryId: string;
|
|
481
|
+
readonly entityId: string;
|
|
482
|
+
readonly attrPath: string;
|
|
483
|
+
readonly oldValueText: string | null;
|
|
484
|
+
readonly newValueText: string;
|
|
485
|
+
readonly replacedAtMessageId: string;
|
|
486
|
+
readonly replacedAtTurnId: string;
|
|
487
|
+
readonly replacedAtWriteSeq: number;
|
|
488
|
+
readonly superseded: boolean;
|
|
489
|
+
};
|
|
490
|
+
export type AttrHistoryCheckResult = {
|
|
491
|
+
readonly superseded: boolean;
|
|
492
|
+
readonly supersededByMessageId?: string;
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* Produces the host journal's canonical digest for one ordered transcript
|
|
496
|
+
* mutation. The bridge recomputes the same digest before touching Ladybug.
|
|
497
|
+
*/
|
|
498
|
+
export declare function computeTranscriptMutationPayloadSha256(input: Pick<TranscriptMutationBatchRequest, "scope" | "messages" | "suffix">): Promise<string>;
|
|
499
|
+
export declare class LadybugBridge {
|
|
500
|
+
private readonly dim;
|
|
501
|
+
private readonly variant;
|
|
502
|
+
private db;
|
|
503
|
+
private conn;
|
|
504
|
+
private ready;
|
|
505
|
+
private vectorIndexBuilt;
|
|
506
|
+
private ftsIndexBuilt;
|
|
507
|
+
private vectorIndexedEntityCount;
|
|
508
|
+
private ftsIndexedEntityCount;
|
|
509
|
+
private memoryEpisodeVectorIndexBuilt;
|
|
510
|
+
private memoryEpisodeFtsIndexBuilt;
|
|
511
|
+
private memoryDerivedVectorIndexBuilt;
|
|
512
|
+
private memoryDerivedFtsIndexBuilt;
|
|
513
|
+
private transcriptFtsBuilt;
|
|
514
|
+
private transcriptQueue;
|
|
515
|
+
private transcriptOperationReservations;
|
|
516
|
+
private transcriptOperationActive;
|
|
517
|
+
private graphRollbackInProgress;
|
|
518
|
+
private initializing;
|
|
519
|
+
private closing;
|
|
520
|
+
private readonly transcriptReachabilityResolver;
|
|
521
|
+
private readonly worldMemoryHostAuthority;
|
|
522
|
+
private worldMemoryQueue;
|
|
523
|
+
private worldMemoryOperationReservations;
|
|
524
|
+
private worldMemoryRevision;
|
|
525
|
+
private _writeSeq;
|
|
526
|
+
private tx;
|
|
527
|
+
private assertWorldMemoryHostAuthority;
|
|
528
|
+
createWorldMemoryHostAdapter(authority: WorldMemoryHostAuthority): WorldMemoryHostAdapter;
|
|
529
|
+
createWasmRuntimeAdapter(authority: WorldMemoryHostAuthority): LadybugWasmRuntimeAdapter;
|
|
530
|
+
private nextSeq;
|
|
531
|
+
private withWorldMemoryHostLock;
|
|
532
|
+
private advanceWorldMemoryRevision;
|
|
533
|
+
private captureWorldMemoryView;
|
|
534
|
+
private worldMemorySnapshotSha256;
|
|
535
|
+
private captureStateIdentity;
|
|
536
|
+
private withTranscriptLock;
|
|
537
|
+
private withTranscriptOperationIsolation;
|
|
538
|
+
private resolveTranscriptAuthority;
|
|
539
|
+
private assertTranscriptReachabilityCoverage;
|
|
540
|
+
isInTransaction(): boolean;
|
|
541
|
+
beginTransaction(): void;
|
|
542
|
+
commitTransaction(): void;
|
|
543
|
+
rollbackTransaction(): Promise<void>;
|
|
544
|
+
withTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
545
|
+
private applyUndoOp;
|
|
546
|
+
private restoreAttrHistoryRowsDuringRollback;
|
|
547
|
+
private restoreLatchRowsDuringRollback;
|
|
548
|
+
private snapshotEntity;
|
|
549
|
+
private snapshotEntityAnalyzerProjection;
|
|
550
|
+
private snapshotRelation;
|
|
551
|
+
private recordEntityUndoBeforeWrite;
|
|
552
|
+
private recordRelationUndoBeforeWrite;
|
|
553
|
+
private recordEntityUndoBeforeDelete;
|
|
554
|
+
private recordRelationUndoBeforeDelete;
|
|
555
|
+
private recordAttrHistoryUndo;
|
|
556
|
+
private recordAllAttrHistoryUndo;
|
|
557
|
+
private recordLatchScenarioUndo;
|
|
558
|
+
private recordRollbackAfterMessageUndo;
|
|
559
|
+
constructor(options: LadybugBridgeOptions, variant?: LadybugVariant);
|
|
560
|
+
init(): Promise<void>;
|
|
561
|
+
private requireConnUnchecked;
|
|
562
|
+
private requireConn;
|
|
563
|
+
private queryDuringRollback;
|
|
564
|
+
private runDuringRollback;
|
|
565
|
+
private assertStatementCannotAddressWorldMemory;
|
|
566
|
+
private assertBusinessStatementCannotAddressWorldMemory;
|
|
567
|
+
private queryForWasmRuntime;
|
|
568
|
+
private queryInternal;
|
|
569
|
+
private runInternal;
|
|
570
|
+
query(statement: string): Promise<Record<string, unknown>[]>;
|
|
571
|
+
run(statement: string, params: Record<string, unknown>): Promise<Record<string, unknown>[]>;
|
|
572
|
+
private queryWorldMemory;
|
|
573
|
+
private runWorldMemory;
|
|
574
|
+
/**
|
|
575
|
+
* Redacted full-state CAS used by the Runtime 2 transaction barrier. Raw
|
|
576
|
+
* rows never cross the bridge; only a domain-separated digest is returned.
|
|
577
|
+
*/
|
|
578
|
+
stateDigest(): Promise<string>;
|
|
579
|
+
recallCandidateRecord(id: string): Promise<RecallCandidateRecord | null>;
|
|
580
|
+
private createSchema;
|
|
581
|
+
private createWorldMemorySchema;
|
|
582
|
+
private executeWorldMemoryQuery;
|
|
583
|
+
private ensureWorldMemoryIndexes;
|
|
584
|
+
private dropMemoryEpisodeIndexes;
|
|
585
|
+
private dropMemoryDerivedIndexes;
|
|
586
|
+
private rebuildMemoryEpisodeIndexes;
|
|
587
|
+
private rebuildMemoryDerivedIndexes;
|
|
588
|
+
private toMemoryEpisode;
|
|
589
|
+
private toMemoryClaimRoot;
|
|
590
|
+
private toMemoryClaim;
|
|
591
|
+
private toMemoryDerived;
|
|
592
|
+
private listMemoryEpisodes;
|
|
593
|
+
private listMemoryClaimRoots;
|
|
594
|
+
private memoryClaimProjection;
|
|
595
|
+
private listMemoryClaims;
|
|
596
|
+
private listMemoryDerived;
|
|
597
|
+
private listMemoryRelations;
|
|
598
|
+
private snapshotWorldMemory;
|
|
599
|
+
private recordWorldMemoryUndo;
|
|
600
|
+
private recordWorldMemoryUndoIfTransaction;
|
|
601
|
+
private normalizeMemoryEpisode;
|
|
602
|
+
private normalizeMemoryClaimRoot;
|
|
603
|
+
private normalizeMemoryClaim;
|
|
604
|
+
private normalizeMemoryDerived;
|
|
605
|
+
private normalizeMemoryRelation;
|
|
606
|
+
private normalizeWorldMemorySnapshot;
|
|
607
|
+
private executeWorldMemoryRun;
|
|
608
|
+
private writeMemoryEpisode;
|
|
609
|
+
private writeMemoryClaimRoot;
|
|
610
|
+
private writeMemoryClaim;
|
|
611
|
+
private writeMemoryDerived;
|
|
612
|
+
private writeMemoryRelation;
|
|
613
|
+
private assertWorldMemoryExternalEntityReferences;
|
|
614
|
+
private replaceWorldMemorySnapshot;
|
|
615
|
+
private restoreWorldMemorySnapshot;
|
|
616
|
+
private restoreWorldMemorySnapshotInTransaction;
|
|
617
|
+
private restoreWorldMemorySnapshotFromHost;
|
|
618
|
+
private upsertMemoryEpisode;
|
|
619
|
+
private upsertMemoryClaimRoot;
|
|
620
|
+
private upsertMemoryClaim;
|
|
621
|
+
private upsertMemoryDerived;
|
|
622
|
+
private upsertMemoryRelation;
|
|
623
|
+
private getClaimRoot;
|
|
624
|
+
private getClaimsByRoot;
|
|
625
|
+
private resolveClaimsForEntities;
|
|
626
|
+
private vectorSearchEpisodes;
|
|
627
|
+
private fullTextSearchEpisodes;
|
|
628
|
+
private vectorSearchDerived;
|
|
629
|
+
private fullTextSearchDerived;
|
|
630
|
+
private deleteMemoryClosure;
|
|
631
|
+
private transcriptPk;
|
|
632
|
+
private toTranscriptMessage;
|
|
633
|
+
private writeTranscriptRecord;
|
|
634
|
+
private readTranscriptByPk;
|
|
635
|
+
private listTranscriptScope;
|
|
636
|
+
private restoreTranscriptScope;
|
|
637
|
+
private invalidateTranscriptFtsIndex;
|
|
638
|
+
private ensureTranscriptFtsIndex;
|
|
639
|
+
upsertTranscriptMessage(request: TranscriptUpsertRequest): Promise<TranscriptMessageRecord>;
|
|
640
|
+
upsertTranscriptMessages(request: TranscriptUpsertBatchRequest): Promise<TranscriptMutationBatchResult>;
|
|
641
|
+
/**
|
|
642
|
+
* Applies the pending journal's suffix operation and replacement/upsert cohort
|
|
643
|
+
* under one bridge lock. A failure restores the exact pre-operation scope;
|
|
644
|
+
* process loss restores the last SAV-backed in-memory database checkpoint.
|
|
645
|
+
*/
|
|
646
|
+
mutateTranscriptMessagesBatch(request: TranscriptMutationBatchRequest): Promise<TranscriptMutationBatchResult>;
|
|
647
|
+
recallTranscriptMessages(request: TranscriptRecallRequest): Promise<TranscriptRecallHit[]>;
|
|
648
|
+
mutateTranscriptSuffix(input: TranscriptSuffixMutation): Promise<TranscriptSuffixMutationResult>;
|
|
649
|
+
private latchPk;
|
|
650
|
+
latchLoad(scenarioId: string): Promise<LeafLatchRow[]>;
|
|
651
|
+
latchCommitBatch(scenarioId: string, rows: ReadonlyArray<LeafLatchRow>): Promise<number>;
|
|
652
|
+
latchClear(scenarioId: string): Promise<void>;
|
|
653
|
+
latchRollback(scenarioId: string, leafIds: ReadonlyArray<string>): Promise<void>;
|
|
654
|
+
upsertAttrHistory(rows: ReadonlyArray<AttrHistoryRow>): Promise<void>;
|
|
655
|
+
queryAttrHistory(entityId: string, attrPath: string): Promise<AttrHistoryRow[]>;
|
|
656
|
+
attrHistoryCheck(entityId: string, attrPath: string, valueText: string): Promise<AttrHistoryCheckResult>;
|
|
657
|
+
pruneAttrHistory(entityId: string, attrPath: string, maxRetain?: number): Promise<number>;
|
|
658
|
+
rollbackAttrHistoryAfterMessage(messageId: string): Promise<number>;
|
|
659
|
+
attrHistoryCount(): Promise<number>;
|
|
660
|
+
private assertMaxRetain;
|
|
661
|
+
private toAttrHistory;
|
|
662
|
+
createVectorIndex(config?: IndexConfig): Promise<void>;
|
|
663
|
+
dropVectorIndex(): Promise<void>;
|
|
664
|
+
createFtsIndex(config?: IndexConfig): Promise<void>;
|
|
665
|
+
private buildVectorIndexArgs;
|
|
666
|
+
private buildFtsIndexArgs;
|
|
667
|
+
dropFtsIndex(): Promise<void>;
|
|
668
|
+
hasVectorIndex(): boolean;
|
|
669
|
+
hasFtsIndex(): boolean;
|
|
670
|
+
/**
|
|
671
|
+
* 只读运行时诊断。只返回数量与索引状态,不跨 wasm 边界暴露实体 props/embedding 明文。
|
|
672
|
+
* `vectorIndexedEntityCount` 只在本 bridge 成功完成 CREATE_VECTOR_INDEX 后计数,
|
|
673
|
+
* 因而可用于提交屏障确认 HNSW 已覆盖当前全部 embedding 行。
|
|
674
|
+
*/
|
|
675
|
+
diagnostics(): Promise<LadybugDiagnostics>;
|
|
676
|
+
upsertEntity(id: string, kind: string, props: unknown, embedding: readonly number[] | null, messageId?: string, turnId?: string, analyzerProjection?: EntityAnalyzerProjection): Promise<void>;
|
|
677
|
+
private replaceEntityAnalyzerProjection;
|
|
678
|
+
getEntityAnalyzerProjection(entityId: string): Promise<EntityAnalyzerProjectionReadback>;
|
|
679
|
+
bulkUpsertEntities(entries: ReadonlyArray<BulkEntityRow>): Promise<void>;
|
|
680
|
+
bulkUpsertRelations(entries: ReadonlyArray<BulkRelationRow>): Promise<void>;
|
|
681
|
+
upsertRelation(src: string, dst: string, kind: string, props: unknown, messageId?: string, turnId?: string): Promise<void>;
|
|
682
|
+
deleteEntity(id: string): Promise<void>;
|
|
683
|
+
rollbackAfterMessage(messageId: string): Promise<RollbackResult>;
|
|
684
|
+
deleteRelation(src: string, dst: string): Promise<void>;
|
|
685
|
+
getById(id: string): Promise<EntityRow | null>;
|
|
686
|
+
findByKind(kind: string): Promise<EntityRow[]>;
|
|
687
|
+
allEntities(): Promise<EntityRow[]>;
|
|
688
|
+
allRelations(): Promise<RelationRow[]>;
|
|
689
|
+
neighbors(id: string, depth: number, options?: NeighborsOptions): Promise<NeighborRow[]>;
|
|
690
|
+
vectorSearch(query: readonly number[], topK: number, config?: QueryConfig): Promise<VectorHit[]>;
|
|
691
|
+
fullTextSearch(query: string, topK: number, config?: QueryConfig): Promise<string[]>;
|
|
692
|
+
recallAndExpand(query: readonly number[], topK: number, depth: number, config?: QueryConfig): Promise<GraphRagResult>;
|
|
693
|
+
private buildFtsQueryArgs;
|
|
694
|
+
private recallCypher;
|
|
695
|
+
private rebuildGraphRag;
|
|
696
|
+
private toStringList;
|
|
697
|
+
private toEntity;
|
|
698
|
+
private toRelation;
|
|
699
|
+
private toNeighbor;
|
|
700
|
+
entityCount(): Promise<number>;
|
|
701
|
+
relationCount(): Promise<number>;
|
|
702
|
+
hasEmbedding(id: string): Promise<boolean>;
|
|
703
|
+
close(): Promise<void>;
|
|
704
|
+
}
|