@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/CHANGELOG.md +40 -0
- package/README.md +24 -23
- package/package.json +4 -4
- package/src/archive.d.ts +3 -3
- package/src/archive.js +49 -44
- package/src/environment.d.ts +52 -22
- package/src/environment.js +491 -548
- package/src/evidence.d.ts +5 -10
- package/src/evidence.js +49 -51
- package/src/index.d.ts +10 -9
- package/src/index.js +9 -10
- package/src/ledger.d.ts +123 -83
- package/src/ledger.js +1039 -1185
- package/src/recall.d.ts +44 -23
- package/src/recall.js +48 -68
- package/src/retention.d.ts +7 -7
- package/src/retention.js +88 -71
- package/src/schemas/evidence.d.ts +11 -10
- package/src/schemas/evidence.js +14 -21
- package/src/schemas/ledger.d.ts +737 -430
- package/src/schemas/ledger.js +130 -243
- package/src/schemas/patch.d.ts +122 -108
- package/src/schemas/patch.js +59 -64
- package/src/storage/memory.d.ts +3 -8
- package/src/storage/memory.js +41 -43
- package/src/storage/slot.d.ts +3 -4
- package/src/storage/slot.js +104 -96
- package/src/storage/transaction.d.ts +3 -18
- package/src/storage/transaction.js +22 -34
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
|
|
6
|
-
* @param {{ artifacts?: import('./schemas/evidence.js').ArtifactRecord[] }} [options]
|
|
5
|
+
* @param [options]
|
|
7
6
|
*/
|
|
8
|
-
export function validateClaimEvidence(envelope: any, options?: {
|
|
9
|
-
artifacts?: import(
|
|
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(
|
|
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
|
|
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
|
|
13
|
-
* @param {{ artifacts?: import('./schemas/evidence.js').ArtifactRecord[] }} [options]
|
|
10
|
+
* @param [options]
|
|
14
11
|
*/
|
|
15
12
|
export function validateClaimEvidence(envelope, options = {}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
2
|
-
export { RECALL_TOOL_NAME, createRecallTool, roundSlotName, indexSlotName, slotRef, slotAddress, slotAddressesIn } from
|
|
3
|
-
export { createLedger, sameIdentity, describeIdentity } from
|
|
4
|
-
export { createEnvironment, environmentTools, chunkSlotName, chunkFamily, CHUNK_KIND } from
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
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
|
|
4
|
-
export { createLedger, sameIdentity, describeIdentity } from
|
|
5
|
-
export { createEnvironment, environmentTools, chunkSlotName, chunkFamily, CHUNK_KIND } from
|
|
6
|
-
export { createMemoryStorage } from
|
|
7
|
-
export { LEDGER_SCHEMAS, GOAL_SCHEMA, MEMORY_SCHEMA, SKILL_SCHEMA, SLOT_SCHEMA } from
|
|
8
|
-
export { REFINEMENT_PATCH_SCHEMA, refinementPatchSchema, REFINEMENT_PATH_PATTERN, DEFAULT_MAX_OPS, MEMORY_PROPOSAL_SCHEMA, SKILL_PROPOSAL_SCHEMA, PROGRESS_PROPOSAL_SCHEMA } from
|
|
9
|
-
export { validateClaimEvidence, createClaimRefiner } from
|
|
10
|
-
export { CLAIM_EVIDENCE_SCHEMA, ARTIFACT_SCHEMA, EVIDENCE_SCHEMA, CLAIM_SCHEMA } from
|
|
11
|
-
export { ledgerFootprint, checkpointProgress, validateCheckpoint, goalPrompt } from
|
|
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
|
-
* @
|
|
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
|
|
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(
|
|
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(
|
|
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:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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?:
|
|
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:
|
|
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(
|
|
288
|
-
export type LedgerMemory = import(
|
|
289
|
-
export type LedgerSkill = import(
|
|
290
|
-
export type LedgerSlot = import(
|
|
291
|
-
export type LedgerRejection = import(
|
|
292
|
-
export type LedgerEmbeddingPair = import(
|
|
293
|
-
export type LedgerEmbeddedBy = import(
|
|
294
|
-
export type Embedder = import(
|
|
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
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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;
|