@tangleai/context 0.21.1 → 0.25.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/src/evidence.d.ts CHANGED
@@ -2,11 +2,10 @@
2
2
  * Validate structure and references, without interpreting prose or making requests.
3
3
  * Supplied artifacts are the host's allow-list; matching ids must retain their
4
4
  * admitted descriptor. Without an external list, the envelope is self-contained.
5
- * @param {any} envelope
6
- * @param {{ artifacts?: import('./schemas/evidence.js').ArtifactRecord[] }} [options]
5
+ * @param [options]
7
6
  */
8
- export function validateClaimEvidence(envelope: any, options?: {
9
- artifacts?: import("./schemas/evidence.js").ArtifactRecord[];
7
+ export declare function validateClaimEvidence(envelope: any, options?: {
8
+ artifacts?: import('./schemas/evidence.ts').ArtifactRecord[];
10
9
  }): {
11
10
  valid: boolean;
12
11
  errors: any[];
@@ -14,17 +13,13 @@ export function validateClaimEvidence(envelope: any, options?: {
14
13
  /**
15
14
  * A second guarded-document consumer: replace or patch a claim envelope using
16
15
  * host persistence and an explicit artifact admission list.
17
- * @param {{ read: () => Promise<any>, apply: (document: any, proposal: any) => any,
18
- * validateProposal: (proposal: any) => any, commit: (document: any) => Promise<any>,
19
- * artifacts: import('./schemas/evidence.js').ArtifactRecord[],
20
- * snapshot?: () => Promise<any>, restore?: (token: any) => Promise<any> }} options
21
16
  */
22
- export function createClaimRefiner(options: {
17
+ export declare function createClaimRefiner(options: {
23
18
  read: () => Promise<any>;
24
19
  apply: (document: any, proposal: any) => any;
25
20
  validateProposal: (proposal: any) => any;
26
21
  commit: (document: any) => Promise<any>;
27
- artifacts: import("./schemas/evidence.js").ArtifactRecord[];
22
+ artifacts: import('./schemas/evidence.ts').ArtifactRecord[];
28
23
  snapshot?: () => Promise<any>;
29
24
  restore?: (token: any) => Promise<any>;
30
25
  }): {
package/src/evidence.js CHANGED
@@ -1,71 +1,69 @@
1
- //@ts-check
2
1
  import { JarenValidator } from '@jarenjs/validate';
3
2
  import { checkOutcome } from '@jarenjs/core/check';
4
- import { CLAIM_EVIDENCE_SCHEMA } from './schemas/evidence.js';
3
+ import { CLAIM_EVIDENCE_SCHEMA } from "./schemas/evidence.js";
5
4
  import { createGuardedRefiner } from '@jarenjs/core/guarded';
6
5
  const check = new JarenValidator({ collectErrors: true, skipErrors: false }).compile(CLAIM_EVIDENCE_SCHEMA);
7
-
8
6
  /**
9
7
  * Validate structure and references, without interpreting prose or making requests.
10
8
  * Supplied artifacts are the host's allow-list; matching ids must retain their
11
9
  * admitted descriptor. Without an external list, the envelope is self-contained.
12
- * @param {any} envelope
13
- * @param {{ artifacts?: import('./schemas/evidence.js').ArtifactRecord[] }} [options]
10
+ * @param [options]
14
11
  */
15
12
  export function validateClaimEvidence(envelope, options = {}) {
16
- const shape = checkOutcome(check(envelope));
17
- if (!shape.valid) return shape;
18
- const errors = [];
19
- const add = (code, docPath, message) => errors.push({ code, docPath, instancePath: docPath, message });
20
- const sets = {};
21
- for (const kind of ['artifacts', 'evidence', 'claims']) {
22
- const ids = new Set();
23
- envelope[kind].forEach((record, index) => {
24
- if (ids.has(record.id)) add('EVIDENCE_DUPLICATE', `/${kind}/${index}/id`, `duplicate ${kind} id '${record.id}'`);
25
- ids.add(record.id);
13
+ const shape = checkOutcome(check(envelope));
14
+ if (!shape.valid)
15
+ return shape;
16
+ const errors = [];
17
+ const add = (code, docPath, message) => errors.push({ code, docPath, instancePath: docPath, message });
18
+ const sets = {};
19
+ for (const kind of ['artifacts', 'evidence', 'claims']) {
20
+ const ids = new Set();
21
+ envelope[kind].forEach((record, index) => {
22
+ if (ids.has(record.id))
23
+ add('EVIDENCE_DUPLICATE', `/${kind}/${index}/id`, `duplicate ${kind} id '${record.id}'`);
24
+ ids.add(record.id);
25
+ });
26
+ sets[kind] = ids;
27
+ }
28
+ if (options.artifacts) {
29
+ const admitted = new Map(options.artifacts.map((artifact) => [artifact.id, artifact]));
30
+ envelope.artifacts.forEach((artifact, i) => {
31
+ const held = admitted.get(artifact.id);
32
+ if (!held || ['kind', 'locator', 'digest'].some((field) => artifact[field] !== held[field]))
33
+ add('EVIDENCE_UNADMITTED', `/artifacts/${i}`, `artifact '${artifact.id}' is not admitted with this descriptor`);
34
+ });
35
+ }
36
+ envelope.evidence.forEach((record, i) => {
37
+ if (!sets.artifacts.has(record.artifact))
38
+ add('EVIDENCE_ARTIFACT', `/evidence/${i}/artifact`, `unknown artifact '${record.artifact}'`);
26
39
  });
27
- sets[kind] = ids;
28
- }
29
- if (options.artifacts) {
30
- const admitted = new Map(options.artifacts.map((artifact) => [artifact.id, artifact]));
31
- envelope.artifacts.forEach((artifact, i) => {
32
- const held = admitted.get(artifact.id);
33
- if (!held || ['kind', 'locator', 'digest'].some((field) => artifact[field] !== held[field]))
34
- add('EVIDENCE_UNADMITTED', `/artifacts/${i}`, `artifact '${artifact.id}' is not admitted with this descriptor`);
40
+ const visible = new Set(envelope.visibleEvidence);
41
+ envelope.visibleEvidence.forEach((id, i) => {
42
+ if (!sets.evidence.has(id))
43
+ add('EVIDENCE_REFERENCE', `/visibleEvidence/${i}`, `unknown evidence '${id}'`);
35
44
  });
36
- }
37
- envelope.evidence.forEach((record, i) => {
38
- if (!sets.artifacts.has(record.artifact))
39
- add('EVIDENCE_ARTIFACT', `/evidence/${i}/artifact`, `unknown artifact '${record.artifact}'`);
40
- });
41
- const visible = new Set(envelope.visibleEvidence);
42
- envelope.visibleEvidence.forEach((id, i) => {
43
- if (!sets.evidence.has(id)) add('EVIDENCE_REFERENCE', `/visibleEvidence/${i}`, `unknown evidence '${id}'`);
44
- });
45
- envelope.claims.forEach((claim, i) => {
46
- if (claim.critical && (claim.status === 'unresolved' || claim.evidence.length === 0))
47
- add('EVIDENCE_CRITICAL', `/claims/${i}/status`, `critical claim '${claim.id}' is unresolved`);
48
- claim.evidence.forEach((id, j) => {
49
- if (!sets.evidence.has(id)) add('EVIDENCE_REFERENCE', `/claims/${i}/evidence/${j}`, `unknown evidence '${id}'`);
50
- else if (!visible.has(id)) add('EVIDENCE_HIDDEN', `/claims/${i}/evidence/${j}`, `evidence '${id}' is outside the visible view`);
45
+ envelope.claims.forEach((claim, i) => {
46
+ if (claim.critical && (claim.status === 'unresolved' || claim.evidence.length === 0))
47
+ add('EVIDENCE_CRITICAL', `/claims/${i}/status`, `critical claim '${claim.id}' is unresolved`);
48
+ claim.evidence.forEach((id, j) => {
49
+ if (!sets.evidence.has(id))
50
+ add('EVIDENCE_REFERENCE', `/claims/${i}/evidence/${j}`, `unknown evidence '${id}'`);
51
+ else if (!visible.has(id))
52
+ add('EVIDENCE_HIDDEN', `/claims/${i}/evidence/${j}`, `evidence '${id}' is outside the visible view`);
53
+ });
51
54
  });
52
- });
53
- errors.sort((a, b) => a.docPath < b.docPath ? -1 : a.docPath > b.docPath ? 1 : a.code.localeCompare(b.code));
54
- return { valid: errors.length === 0, errors };
55
+ errors.sort((a, b) => a.docPath < b.docPath ? -1 : a.docPath > b.docPath ? 1 : a.code.localeCompare(b.code));
56
+ return { valid: errors.length === 0, errors };
55
57
  }
56
-
57
58
  /**
58
59
  * A second guarded-document consumer: replace or patch a claim envelope using
59
60
  * host persistence and an explicit artifact admission list.
60
- * @param {{ read: () => Promise<any>, apply: (document: any, proposal: any) => any,
61
- * validateProposal: (proposal: any) => any, commit: (document: any) => Promise<any>,
62
- * artifacts: import('./schemas/evidence.js').ArtifactRecord[],
63
- * snapshot?: () => Promise<any>, restore?: (token: any) => Promise<any> }} options
64
61
  */
65
62
  export function createClaimRefiner(options) {
66
- const artifacts = JSON.parse(JSON.stringify(options.artifacts));
67
- return createGuardedRefiner({ ...options,
68
- validateCandidate: (next) => validateClaimEvidence(next, { artifacts }),
69
- planCommit: (next) => next,
70
- });
63
+ const artifacts = JSON.parse(JSON.stringify(options.artifacts));
64
+ return createGuardedRefiner({
65
+ ...options,
66
+ validateCandidate: (next) => validateClaimEvidence(next, { artifacts }),
67
+ planCommit: (next) => next,
68
+ });
71
69
  }
package/src/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- export { createMemoryStorage } from "./storage/memory.js";
2
- export { RECALL_TOOL_NAME, createRecallTool, roundSlotName, indexSlotName, slotRef, slotAddress, slotAddressesIn } from "./recall.js";
3
- export { createLedger, sameIdentity, describeIdentity } from "./ledger.js";
4
- export { createEnvironment, environmentTools, chunkSlotName, chunkFamily, CHUNK_KIND } from "./environment.js";
5
- export { LEDGER_SCHEMAS, GOAL_SCHEMA, MEMORY_SCHEMA, SKILL_SCHEMA, SLOT_SCHEMA } from "./schemas/ledger.js";
6
- export { REFINEMENT_PATCH_SCHEMA, refinementPatchSchema, REFINEMENT_PATH_PATTERN, DEFAULT_MAX_OPS, MEMORY_PROPOSAL_SCHEMA, SKILL_PROPOSAL_SCHEMA, PROGRESS_PROPOSAL_SCHEMA } from "./schemas/patch.js";
7
- export { validateClaimEvidence, createClaimRefiner } from "./evidence.js";
8
- export { CLAIM_EVIDENCE_SCHEMA, ARTIFACT_SCHEMA, EVIDENCE_SCHEMA, CLAIM_SCHEMA } from "./schemas/evidence.js";
9
- export { ledgerFootprint, checkpointProgress, validateCheckpoint, goalPrompt } from "./retention.js";
1
+ /** context: public AI mechanisms over injected Jaren foundations. */
2
+ export { RECALL_TOOL_NAME, createRecallTool, roundSlotName, indexSlotName, slotRef, slotAddress, slotAddressesIn } from './recall.ts';
3
+ export { createLedger, sameIdentity, describeIdentity } from './ledger.ts';
4
+ export { createEnvironment, environmentTools, chunkSlotName, chunkFamily, CHUNK_KIND } from './environment.ts';
5
+ export { createMemoryStorage } from './storage/memory.ts';
6
+ export { LEDGER_SCHEMAS, GOAL_SCHEMA, MEMORY_SCHEMA, SKILL_SCHEMA, SLOT_SCHEMA } from './schemas/ledger.ts';
7
+ export { REFINEMENT_PATCH_SCHEMA, refinementPatchSchema, REFINEMENT_PATH_PATTERN, DEFAULT_MAX_OPS, MEMORY_PROPOSAL_SCHEMA, SKILL_PROPOSAL_SCHEMA, PROGRESS_PROPOSAL_SCHEMA } from './schemas/patch.ts';
8
+ export { validateClaimEvidence, createClaimRefiner } from './evidence.ts';
9
+ export { CLAIM_EVIDENCE_SCHEMA, ARTIFACT_SCHEMA, EVIDENCE_SCHEMA, CLAIM_SCHEMA } from './schemas/evidence.ts';
10
+ export { ledgerFootprint, checkpointProgress, validateCheckpoint, goalPrompt } from './retention.ts';
package/src/index.js CHANGED
@@ -1,11 +1,10 @@
1
- //@ts-check
2
1
  /** context: public AI mechanisms over injected Jaren foundations. */
3
- export { RECALL_TOOL_NAME, createRecallTool, roundSlotName, indexSlotName, slotRef, slotAddress, slotAddressesIn } from './recall.js';
4
- export { createLedger, sameIdentity, describeIdentity } from './ledger.js';
5
- export { createEnvironment, environmentTools, chunkSlotName, chunkFamily, CHUNK_KIND } from './environment.js';
6
- export { createMemoryStorage } from './storage/memory.js';
7
- export { LEDGER_SCHEMAS, GOAL_SCHEMA, MEMORY_SCHEMA, SKILL_SCHEMA, SLOT_SCHEMA } from './schemas/ledger.js';
8
- export { REFINEMENT_PATCH_SCHEMA, refinementPatchSchema, REFINEMENT_PATH_PATTERN, DEFAULT_MAX_OPS, MEMORY_PROPOSAL_SCHEMA, SKILL_PROPOSAL_SCHEMA, PROGRESS_PROPOSAL_SCHEMA } from './schemas/patch.js';
9
- export { validateClaimEvidence, createClaimRefiner } from './evidence.js';
10
- export { CLAIM_EVIDENCE_SCHEMA, ARTIFACT_SCHEMA, EVIDENCE_SCHEMA, CLAIM_SCHEMA } from './schemas/evidence.js';
11
- export { ledgerFootprint, checkpointProgress, validateCheckpoint, goalPrompt } from './retention.js';
2
+ export { RECALL_TOOL_NAME, createRecallTool, roundSlotName, indexSlotName, slotRef, slotAddress, slotAddressesIn } from "./recall.js";
3
+ export { createLedger, sameIdentity, describeIdentity } from "./ledger.js";
4
+ export { createEnvironment, environmentTools, chunkSlotName, chunkFamily, CHUNK_KIND } from "./environment.js";
5
+ export { createMemoryStorage } from "./storage/memory.js";
6
+ export { LEDGER_SCHEMAS, GOAL_SCHEMA, MEMORY_SCHEMA, SKILL_SCHEMA, SLOT_SCHEMA } from "./schemas/ledger.js";
7
+ export { REFINEMENT_PATCH_SCHEMA, refinementPatchSchema, REFINEMENT_PATH_PATTERN, DEFAULT_MAX_OPS, MEMORY_PROPOSAL_SCHEMA, SKILL_PROPOSAL_SCHEMA, PROGRESS_PROPOSAL_SCHEMA } from "./schemas/patch.js";
8
+ export { validateClaimEvidence, createClaimRefiner } from "./evidence.js";
9
+ export { CLAIM_EVIDENCE_SCHEMA, ARTIFACT_SCHEMA, EVIDENCE_SCHEMA, CLAIM_SCHEMA } from "./schemas/evidence.js";
10
+ export { ledgerFootprint, checkpointProgress, validateCheckpoint, goalPrompt } from "./retention.js";
package/src/ledger.d.ts CHANGED
@@ -1,3 +1,59 @@
1
+ /**
2
+ * The ledger: schema-validated, durable, addressable state that outlives
3
+ * a context window.
4
+ *
5
+ * An agent today is bounded by one transcript — everything it learned is
6
+ * gone when the tab closes, and everything it gathered is gone when the
7
+ * history budget bites. The ledger is the other half: a goal it is
8
+ * working towards, memories it has earned, skills it can reuse, and
9
+ * slots holding content too big to carry. Four kinds, one small
10
+ * interface, over an injected storage adapter.
11
+ *
12
+ * Three decisions shape the whole file:
13
+ *
14
+ * - **Storage is injected, never imported.** The adapter is four async
15
+ * methods (`get`/`set`/`delete`/`keys`); a host backs it with
16
+ * `@jarenjs/db` over OPFS, with `localStorage`, or with nothing. This
17
+ * package keeps exactly two dependencies, so it still loads in a
18
+ * static page — `createLedger()` with no arguments works, in memory.
19
+ * Optional `mutate` atomically transforms a detached record map. Ledger
20
+ * writes stage outside storage and publish with comparison against current
21
+ * state. Four-method adapters retain the explicit single-writer contract.
22
+ * - **Nothing enters without passing its schema**, compiled by
23
+ * `JarenValidator` here at construction. A rejected write answers the
24
+ * same `{ error, errors, inputSchema }` the toolbox answers with (one
25
+ * implementation, in `check.ts`) and never throws: a model that wrote
26
+ * a bad memory can read why and fix it.
27
+ * - **Every mutation is reversible.** `snapshot()` before, `rollback()`
28
+ * after — which is what will make model-proposed refinements safe to
29
+ * accept later, because a bad one can be undone without a human
30
+ * reading the diff.
31
+ *
32
+ * And one more, added when recall by meaning arrived:
33
+ *
34
+ * - **Meaning is a seam, not a dependency.** A record may carry an
35
+ * `embedding` with its identity (`embeddedBy: { model, dims }`);
36
+ * `recall({ near })` ranks by cosine similarity through an injected
37
+ * embedder — `createEmbeddingClient(...)`, `createHashEmbedder()`, or
38
+ * any host `{ embed, model, dims }` — and without one it REFUSES,
39
+ * naming the seam, exactly as a `where` predicate refuses without
40
+ * `compileQuery`. It refuses a mixture of identities rather than
41
+ * ranking the matching subset (a silent subset is a silent wrong
42
+ * answer), it reports how many records it skipped for carrying no
43
+ * vector rather than scoring them, and a write never acquires the
44
+ * seam's network dependency unless `embedOnWrite` asks for it;
45
+ * `embedMissing()` is the explicit sweep that closes the gap. Every
46
+ * dot and cosine comes from `@jarenjs/core/vector`; none is computed
47
+ * here. A storage adapter that can rank the records itself may say so
48
+ * with an optional fifth method (`rank`, see
49
+ * {@link createMemoryStorage}'s contract); the ledger then asks it
50
+ * instead of sweeping, holds it to the same identity refusal and skip
51
+ * report, and names which one ran in `via`.
52
+ *
53
+ * Its consumers today: the agent's compaction archive, the environment's
54
+ * slots, refinement's patchable state, and the website assistant's
55
+ * durable memory — all on this one implementation.
56
+ */
1
57
  /**
2
58
  * Whether two vector identities name the same space: the same model at
3
59
  * the same width. The rule the ledger applies before any arithmetic
@@ -18,15 +74,13 @@
18
74
  * produce vectors whose cosine is arithmetic without meaning, which is
19
75
  * why `dims` matching is necessary and never sufficient.
20
76
  *
21
- * @param {LedgerEmbeddedBy | undefined | null} a
22
- * @param {LedgerEmbeddedBy | undefined | null} b
23
- * @returns {boolean} whether both are identities naming one space
77
+ * @returns whether both are identities naming one space
24
78
  * @example
25
79
  * sameIdentity({ model: 'm', dims: 4 }, { model: 'm', dims: 4 }); // true
26
80
  * sameIdentity({ model: 'm', dims: 4 }, { model: 'm', dims: 8 }); // false — a re-embed, not a match
27
81
  * sameIdentity(undefined, undefined); // false — no space is not a shared space
28
82
  */
29
- export function sameIdentity(a: LedgerEmbeddedBy | undefined | null, b: LedgerEmbeddedBy | undefined | null): boolean;
83
+ export declare function sameIdentity(a: LedgerEmbeddedBy | undefined | null, b: LedgerEmbeddedBy | undefined | null): boolean;
30
84
  /**
31
85
  * An identity as a refusal names it — `"text-embedding-3-small (1536
32
86
  * dims)"`. Exported for the same reason as {@link sameIdentity}: it is
@@ -35,31 +89,12 @@ export function sameIdentity(a: LedgerEmbeddedBy | undefined | null, b: LedgerEm
35
89
  * key for collecting the DISTINCT identities a `rank` adapter owes its
36
90
  * caller.
37
91
  *
38
- * @param {LedgerEmbeddedBy} identity
39
- * @returns {string}
40
92
  */
41
- export function describeIdentity(identity: LedgerEmbeddedBy): string;
93
+ export declare function describeIdentity(identity: LedgerEmbeddedBy): string;
42
94
  /**
43
95
  * Create a ledger.
44
96
  *
45
- * @param {{ storage?: { get: (key: string) => Promise<any>,
46
- * set: (key: string, value: any) => Promise<void>,
47
- * delete: (key: string) => Promise<void>,
48
- * keys: (prefix?: string) => Promise<string[]>,
49
- * status?: () => any,
50
- * mutate?: import('./storage/transaction.js').StorageMutation,
51
- * rank?: (request: { prefix: string, vector: number[], model: string, dims: number,
52
- * limit?: number, minScore?: number }) => Promise<{ hits: { key: string, score: number }[],
53
- * skipped: number, identities: LedgerEmbeddedBy[], ranking?: LedgerRanking }> },
54
- * compileQuery?: (document: any) => (data: any) => any,
55
- * embedder?: Embedder,
56
- * embedOnWrite?: boolean,
57
- * validator?: any,
58
- * now?: () => string,
59
- * archiveLimits?: { maxItems?: number, maxBytes?: number },
60
- * goalLimits?: { maxEntries?: number, maxBytes?: number, maxChars?: number },
61
- * checkpointReducer?: (goal: any) => any,
62
- * artifacts?: import('./schemas/evidence.js').ArtifactRecord[] }} [options]
97
+ * @param [options]
63
98
  * - `storage` defaults to an in-memory adapter, so a ledger works with
64
99
  * nothing wired. Anything durable is the host's to inject. Its four
65
100
  * methods are the contract; an adapter that can rank vectors itself
@@ -84,14 +119,14 @@ export function describeIdentity(identity: LedgerEmbeddedBy): string;
84
119
  * - `now` returns an RFC 3339 timestamp (injected for deterministic
85
120
  * tests, exactly as the rest of the suite injects its environment).
86
121
  */
87
- export function createLedger(options?: {
122
+ export declare function createLedger(options?: {
88
123
  storage?: {
89
124
  get: (key: string) => Promise<any>;
90
125
  set: (key: string, value: any) => Promise<void>;
91
126
  delete: (key: string) => Promise<void>;
92
127
  keys: (prefix?: string) => Promise<string[]>;
93
128
  status?: () => any;
94
- mutate?: import("./storage/transaction.js").StorageMutation;
129
+ mutate?: import('./storage/transaction.ts').StorageMutation;
95
130
  rank?: (request: {
96
131
  prefix: string;
97
132
  vector: number[];
@@ -124,12 +159,13 @@ export function createLedger(options?: {
124
159
  maxChars?: number;
125
160
  };
126
161
  checkpointReducer?: (goal: any) => any;
127
- artifacts?: import("./schemas/evidence.js").ArtifactRecord[];
162
+ artifacts?: import('./schemas/evidence.ts').ArtifactRecord[];
128
163
  }): {
129
164
  storageStatus: () => any;
130
165
  concurrency: string;
131
166
  validate: (kind: "goal" | "memory" | "skill" | "slot", record: any) => null | {
132
167
  error: string;
168
+ code?: string;
133
169
  errors: any[];
134
170
  inputSchema: any;
135
171
  };
@@ -147,12 +183,15 @@ export function createLedger(options?: {
147
183
  at?: string;
148
184
  }) => Promise<LedgerGoal | LedgerRejection | {
149
185
  error: string;
186
+ code?: string;
150
187
  }>;
151
188
  setGoalStatus: (status: "active" | "done" | "abandoned" | "superseded") => Promise<LedgerGoal | LedgerRejection | {
152
189
  error: string;
190
+ code?: string;
153
191
  }>;
154
192
  composeGoal: () => Promise<{
155
193
  error: string;
194
+ code?: string;
156
195
  errors: any[];
157
196
  inputSchema: any;
158
197
  } | {
@@ -190,12 +229,36 @@ export function createLedger(options?: {
190
229
  getSkill: (id: string) => Promise<LedgerSkill | null>;
191
230
  listSkills: () => Promise<LedgerSkill[]>;
192
231
  deleteSkill: (id: string) => Promise<boolean>;
193
- recall: (query?: LedgerQuery) => Promise<LedgerMemory[] | LedgerRankedMemories | {
194
- error: string;
195
- }>;
196
- recallSkills: (query?: LedgerQuery) => Promise<LedgerSkill[] | LedgerRankedSkills | {
197
- error: string;
198
- }>;
232
+ recall: {
233
+ (query: LedgerQuery & {
234
+ near: string;
235
+ }): Promise<LedgerRankedMemories | {
236
+ error: string;
237
+ }>;
238
+ (query?: LedgerQuery & {
239
+ near?: undefined;
240
+ }): Promise<LedgerMemory[] | {
241
+ error: string;
242
+ }>;
243
+ (query: LedgerQuery): Promise<LedgerMemory[] | LedgerRankedMemories | {
244
+ error: string;
245
+ }>;
246
+ };
247
+ recallSkills: {
248
+ (query: LedgerQuery & {
249
+ near: string;
250
+ }): Promise<LedgerRankedSkills | {
251
+ error: string;
252
+ }>;
253
+ (query?: LedgerQuery & {
254
+ near?: undefined;
255
+ }): Promise<LedgerSkill[] | {
256
+ error: string;
257
+ }>;
258
+ (query: LedgerQuery): Promise<LedgerSkill[] | LedgerRankedSkills | {
259
+ error: string;
260
+ }>;
261
+ };
199
262
  embedMissing: (options?: {
200
263
  limit?: number;
201
264
  batch?: number;
@@ -219,7 +282,7 @@ export function createLedger(options?: {
219
282
  }>;
220
283
  listSlots: () => Promise<LedgerSlot[]>;
221
284
  deleteSlot: (name: string) => Promise<boolean>;
222
- putArchive: (entries: any, protection?: {}) => Promise<{
285
+ putArchive: (entries: any, protection?: Record<string, any>) => Promise<{
223
286
  error: string;
224
287
  code: string;
225
288
  retention?: undefined;
@@ -245,7 +308,7 @@ export function createLedger(options?: {
245
308
  report?: undefined;
246
309
  footprint?: undefined;
247
310
  } | {
248
- next: any;
311
+ next: Record<string, any>;
249
312
  report: {
250
313
  version: number;
251
314
  policy: string;
@@ -261,10 +324,11 @@ export function createLedger(options?: {
261
324
  retention?: undefined;
262
325
  } | {
263
326
  error: string;
327
+ code?: string;
264
328
  errors: any[];
265
329
  inputSchema: any;
266
330
  } | {
267
- ok: boolean;
331
+ ok: true;
268
332
  retention: {
269
333
  version: number;
270
334
  policy: string;
@@ -281,70 +345,46 @@ export function createLedger(options?: {
281
345
  snapshot: () => Promise<string>;
282
346
  rollback: (token: string) => Promise<true | {
283
347
  error: string;
348
+ code?: string;
284
349
  }>;
285
350
  transaction: (expected: any, work: (ledger: any) => Promise<any>) => Promise<any>;
286
351
  };
287
- export type LedgerGoal = import("./schemas/ledger.js").LedgerGoal;
288
- export type LedgerMemory = import("./schemas/ledger.js").LedgerMemory;
289
- export type LedgerSkill = import("./schemas/ledger.js").LedgerSkill;
290
- export type LedgerSlot = import("./schemas/ledger.js").LedgerSlot;
291
- export type LedgerRejection = import("./schemas/ledger.js").LedgerRejection;
292
- export type LedgerEmbeddingPair = import("./schemas/ledger.js").LedgerEmbeddingPair;
293
- export type LedgerEmbeddedBy = import("./schemas/ledger.js").LedgerEmbeddedBy;
294
- export type Embedder = import("@tangleai/models/embed").Embedder;
295
- /**
296
- * What `recall({ near })` answers: the memories that carry a comparable
297
- * vector, ranked by cosine similarity (descending; ties by recency, then
298
- * id), one score per memory in the same order, and the count of records
299
- * that passed the filter but carry no vector and were therefore skipped
300
- * — reported, never scored.
301
- */
352
+ export type LedgerGoal = import('./schemas/ledger.ts').LedgerGoal;
353
+ export type LedgerMemory = import('./schemas/ledger.ts').LedgerMemory;
354
+ export type LedgerSkill = import('./schemas/ledger.ts').LedgerSkill;
355
+ export type LedgerSlot = import('./schemas/ledger.ts').LedgerSlot;
356
+ export type LedgerRejection = import('./schemas/ledger.ts').LedgerRejection;
357
+ export type LedgerEmbeddingPair = import('./schemas/ledger.ts').LedgerEmbeddingPair;
358
+ export type LedgerEmbeddedBy = import('./schemas/ledger.ts').LedgerEmbeddedBy;
359
+ export type Embedder = import('@tangleai/models/embed').Embedder;
302
360
  export type LedgerRankedMemories = {
303
361
  memories: LedgerMemory[];
304
362
  scores: number[];
305
- skipped: number;
306
- /**
307
- * - which path answered: the ledger's
308
- * own read-and-rank, or the adapter's `rank` capability
309
- */
310
- via: "sweep" | "adapter";
311
- /**
312
- * - candidate selection provenance, not a quality guarantee
313
- */
363
+ skipped: number; /**
364
+ * - which path answered: the ledger's
365
+ * own read-and-rank, or the adapter's `rank` capability
366
+ */
367
+ via: "sweep" | "adapter"; /**
368
+ * - candidate selection provenance, not a quality guarantee
369
+ */
314
370
  ranking: LedgerRanking;
315
371
  };
316
- /**
317
- * What `recallSkills({ near })` answers — see {@link LedgerRankedMemories}.
318
- */
319
372
  export type LedgerRankedSkills = {
320
373
  skills: LedgerSkill[];
321
374
  scores: number[];
322
- skipped: number;
323
- /**
324
- * - see {@link LedgerRankedMemories}
325
- */
326
- via: "sweep" | "adapter";
327
- /**
328
- * - see {@link LedgerRankedMemories}
329
- */
375
+ skipped: number; /**
376
+ * - see {@link LedgerRankedMemories}
377
+ */
378
+ via: "sweep" | "adapter"; /**
379
+ * - see {@link LedgerRankedMemories}
380
+ */
330
381
  ranking: LedgerRanking;
331
382
  };
332
- /**
333
- * Optional storage rank metadata. Legacy adapters normalize to exhaustive.
334
- * Exhaustive means exact candidate selection, not that every record is returned.
335
- * Candidate count is the number returned before ledger filtering and capping.
336
- */
337
383
  export type LedgerRanking = {
338
384
  algorithm: string;
339
385
  exhaustive: boolean;
340
386
  candidateCount: number;
341
387
  };
342
- /**
343
- * The query both recalls take. `near` is the string to rank by meaning
344
- * against, and needs the embedder seam; `minScore` filters the ranked
345
- * result (cosine, in [-1, 1]); `tags` and `where` narrow the candidates
346
- * first, exactly as they do without `near`.
347
- */
348
388
  export type LedgerQuery = {
349
389
  tags?: string[];
350
390
  where?: any;