@graphorin/memory 0.5.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 +15 -0
- package/LICENSE +21 -0
- package/README.md +401 -0
- package/dist/conflict/index.d.ts +3 -0
- package/dist/conflict/index.js +7 -0
- package/dist/conflict/locale-packs/en.js +262 -0
- package/dist/conflict/locale-packs/en.js.map +1 -0
- package/dist/conflict/locale-packs/index.js +4 -0
- package/dist/conflict/locale-packs/types.d.ts +103 -0
- package/dist/conflict/locale-packs/types.d.ts.map +1 -0
- package/dist/conflict/locale-packs/types.js +55 -0
- package/dist/conflict/locale-packs/types.js.map +1 -0
- package/dist/conflict/pipeline.d.ts +35 -0
- package/dist/conflict/pipeline.d.ts.map +1 -0
- package/dist/conflict/pipeline.js +257 -0
- package/dist/conflict/pipeline.js.map +1 -0
- package/dist/conflict/stages/helpers.js +66 -0
- package/dist/conflict/stages/helpers.js.map +1 -0
- package/dist/conflict/stages/stage1-exact-dedup.js +21 -0
- package/dist/conflict/stages/stage1-exact-dedup.js.map +1 -0
- package/dist/conflict/stages/stage2-embedding-three-zone.js +37 -0
- package/dist/conflict/stages/stage2-embedding-three-zone.js.map +1 -0
- package/dist/conflict/stages/stage3-heuristic-regex.js +45 -0
- package/dist/conflict/stages/stage3-heuristic-regex.js.map +1 -0
- package/dist/conflict/stages/stage4-subject-predicate.js +31 -0
- package/dist/conflict/stages/stage4-subject-predicate.js.map +1 -0
- package/dist/conflict/stages/stage5-defer-to-deep.js +22 -0
- package/dist/conflict/stages/stage5-defer-to-deep.js.map +1 -0
- package/dist/conflict/types.d.ts +222 -0
- package/dist/conflict/types.d.ts.map +1 -0
- package/dist/conflict/types.js +50 -0
- package/dist/conflict/types.js.map +1 -0
- package/dist/consolidator/budget.d.ts +1 -0
- package/dist/consolidator/budget.js +214 -0
- package/dist/consolidator/budget.js.map +1 -0
- package/dist/consolidator/decay.d.ts +35 -0
- package/dist/consolidator/decay.d.ts.map +1 -0
- package/dist/consolidator/decay.js +91 -0
- package/dist/consolidator/decay.js.map +1 -0
- package/dist/consolidator/dlq.js +58 -0
- package/dist/consolidator/dlq.js.map +1 -0
- package/dist/consolidator/errors.d.ts +54 -0
- package/dist/consolidator/errors.d.ts.map +1 -0
- package/dist/consolidator/errors.js +67 -0
- package/dist/consolidator/errors.js.map +1 -0
- package/dist/consolidator/idempotency.d.ts +1 -0
- package/dist/consolidator/idempotency.js +22 -0
- package/dist/consolidator/idempotency.js.map +1 -0
- package/dist/consolidator/index.d.ts +34 -0
- package/dist/consolidator/index.d.ts.map +1 -0
- package/dist/consolidator/index.js +163 -0
- package/dist/consolidator/index.js.map +1 -0
- package/dist/consolidator/lock.d.ts +2 -0
- package/dist/consolidator/lock.js +89 -0
- package/dist/consolidator/lock.js.map +1 -0
- package/dist/consolidator/noise-filter.d.ts +2 -0
- package/dist/consolidator/noise-filter.js +173 -0
- package/dist/consolidator/noise-filter.js.map +1 -0
- package/dist/consolidator/phases/deep.d.ts +4 -0
- package/dist/consolidator/phases/deep.js +198 -0
- package/dist/consolidator/phases/deep.js.map +1 -0
- package/dist/consolidator/phases/induce.d.ts +154 -0
- package/dist/consolidator/phases/induce.d.ts.map +1 -0
- package/dist/consolidator/phases/induce.js +253 -0
- package/dist/consolidator/phases/induce.js.map +1 -0
- package/dist/consolidator/phases/light.d.ts +4 -0
- package/dist/consolidator/phases/light.js +99 -0
- package/dist/consolidator/phases/light.js.map +1 -0
- package/dist/consolidator/phases/reflect.js +287 -0
- package/dist/consolidator/phases/reflect.js.map +1 -0
- package/dist/consolidator/phases/standard.d.ts +8 -0
- package/dist/consolidator/phases/standard.js +499 -0
- package/dist/consolidator/phases/standard.js.map +1 -0
- package/dist/consolidator/reconcile.js +192 -0
- package/dist/consolidator/reconcile.js.map +1 -0
- package/dist/consolidator/runtime.d.ts +62 -0
- package/dist/consolidator/runtime.d.ts.map +1 -0
- package/dist/consolidator/runtime.js +580 -0
- package/dist/consolidator/runtime.js.map +1 -0
- package/dist/consolidator/scheduler.d.ts +111 -0
- package/dist/consolidator/scheduler.d.ts.map +1 -0
- package/dist/consolidator/scheduler.js +71 -0
- package/dist/consolidator/scheduler.js.map +1 -0
- package/dist/consolidator/triggers.d.ts +40 -0
- package/dist/consolidator/triggers.d.ts.map +1 -0
- package/dist/consolidator/triggers.js +94 -0
- package/dist/consolidator/triggers.js.map +1 -0
- package/dist/consolidator/types.d.ts +397 -0
- package/dist/consolidator/types.d.ts.map +1 -0
- package/dist/consolidator/types.js +117 -0
- package/dist/consolidator/types.js.map +1 -0
- package/dist/context-engine/annotations.d.ts +118 -0
- package/dist/context-engine/annotations.d.ts.map +1 -0
- package/dist/context-engine/annotations.js +102 -0
- package/dist/context-engine/annotations.js.map +1 -0
- package/dist/context-engine/auto-recall.d.ts +52 -0
- package/dist/context-engine/auto-recall.d.ts.map +1 -0
- package/dist/context-engine/auto-recall.js +41 -0
- package/dist/context-engine/auto-recall.js.map +1 -0
- package/dist/context-engine/compaction/clear-tool-results.d.ts +55 -0
- package/dist/context-engine/compaction/clear-tool-results.d.ts.map +1 -0
- package/dist/context-engine/compaction/clear-tool-results.js +97 -0
- package/dist/context-engine/compaction/clear-tool-results.js.map +1 -0
- package/dist/context-engine/compaction/compactor.d.ts +52 -0
- package/dist/context-engine/compaction/compactor.d.ts.map +1 -0
- package/dist/context-engine/compaction/compactor.js +196 -0
- package/dist/context-engine/compaction/compactor.js.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts +15 -0
- package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-persona-block.js +27 -0
- package/dist/context-engine/compaction/hooks/reanchor-persona-block.js.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts +18 -0
- package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js +47 -0
- package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts +15 -0
- package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-project-rules.js +32 -0
- package/dist/context-engine/compaction/hooks/reanchor-project-rules.js.map +1 -0
- package/dist/context-engine/compaction/hooks/types.d.ts +42 -0
- package/dist/context-engine/compaction/hooks/types.d.ts.map +1 -0
- package/dist/context-engine/compaction/index.d.ts +9 -0
- package/dist/context-engine/compaction/index.js +9 -0
- package/dist/context-engine/compaction/templates/summary-9-section.d.ts +84 -0
- package/dist/context-engine/compaction/templates/summary-9-section.d.ts.map +1 -0
- package/dist/context-engine/compaction/templates/summary-9-section.js +84 -0
- package/dist/context-engine/compaction/templates/summary-9-section.js.map +1 -0
- package/dist/context-engine/compaction/thresholds.d.ts +68 -0
- package/dist/context-engine/compaction/thresholds.d.ts.map +1 -0
- package/dist/context-engine/compaction/thresholds.js +63 -0
- package/dist/context-engine/compaction/thresholds.js.map +1 -0
- package/dist/context-engine/compaction/types.d.ts +202 -0
- package/dist/context-engine/compaction/types.d.ts.map +1 -0
- package/dist/context-engine/engine.d.ts +258 -0
- package/dist/context-engine/engine.d.ts.map +1 -0
- package/dist/context-engine/engine.js +424 -0
- package/dist/context-engine/engine.js.map +1 -0
- package/dist/context-engine/index.d.ts +68 -0
- package/dist/context-engine/index.d.ts.map +1 -0
- package/dist/context-engine/index.js +24 -0
- package/dist/context-engine/locale-packs/en.d.ts +14 -0
- package/dist/context-engine/locale-packs/en.d.ts.map +1 -0
- package/dist/context-engine/locale-packs/en.js +87 -0
- package/dist/context-engine/locale-packs/en.js.map +1 -0
- package/dist/context-engine/locale-packs/index.js +4 -0
- package/dist/context-engine/locale-packs/resolver.d.ts +41 -0
- package/dist/context-engine/locale-packs/resolver.d.ts.map +1 -0
- package/dist/context-engine/locale-packs/resolver.js +119 -0
- package/dist/context-engine/locale-packs/resolver.js.map +1 -0
- package/dist/context-engine/locale-packs/types.d.ts +119 -0
- package/dist/context-engine/locale-packs/types.d.ts.map +1 -0
- package/dist/context-engine/locale-packs/types.js +24 -0
- package/dist/context-engine/locale-packs/types.js.map +1 -0
- package/dist/context-engine/metadata.d.ts +40 -0
- package/dist/context-engine/metadata.d.ts.map +1 -0
- package/dist/context-engine/metadata.js +66 -0
- package/dist/context-engine/metadata.js.map +1 -0
- package/dist/context-engine/preambles/inbound-en.d.ts +20 -0
- package/dist/context-engine/preambles/inbound-en.d.ts.map +1 -0
- package/dist/context-engine/preambles/inbound-en.js +23 -0
- package/dist/context-engine/preambles/inbound-en.js.map +1 -0
- package/dist/context-engine/privacy-filter.d.ts +108 -0
- package/dist/context-engine/privacy-filter.d.ts.map +1 -0
- package/dist/context-engine/privacy-filter.js +113 -0
- package/dist/context-engine/privacy-filter.js.map +1 -0
- package/dist/context-engine/templates/base-en.d.ts +19 -0
- package/dist/context-engine/templates/base-en.d.ts.map +1 -0
- package/dist/context-engine/templates/base-en.js +22 -0
- package/dist/context-engine/templates/base-en.js.map +1 -0
- package/dist/context-engine/templates/composer.d.ts +55 -0
- package/dist/context-engine/templates/composer.d.ts.map +1 -0
- package/dist/context-engine/templates/composer.js +51 -0
- package/dist/context-engine/templates/composer.js.map +1 -0
- package/dist/context-engine/token-budget.d.ts +99 -0
- package/dist/context-engine/token-budget.d.ts.map +1 -0
- package/dist/context-engine/token-budget.js +211 -0
- package/dist/context-engine/token-budget.js.map +1 -0
- package/dist/context-engine/token-counter.d.ts +54 -0
- package/dist/context-engine/token-counter.d.ts.map +1 -0
- package/dist/context-engine/token-counter.js +81 -0
- package/dist/context-engine/token-counter.js.map +1 -0
- package/dist/errors/index.d.ts +171 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +206 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/facade.d.ts +278 -0
- package/dist/facade.d.ts.map +1 -0
- package/dist/facade.js +265 -0
- package/dist/facade.js.map +1 -0
- package/dist/graph/entity-resolver.d.ts +135 -0
- package/dist/graph/entity-resolver.d.ts.map +1 -0
- package/dist/graph/entity-resolver.js +202 -0
- package/dist/graph/entity-resolver.js.map +1 -0
- package/dist/graph/index.d.ts +1 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/contextualize.d.ts +14 -0
- package/dist/internal/contextualize.d.ts.map +1 -0
- package/dist/internal/contextualize.js +110 -0
- package/dist/internal/contextualize.js.map +1 -0
- package/dist/internal/embedder-binding.js +50 -0
- package/dist/internal/embedder-binding.js.map +1 -0
- package/dist/internal/id.js +24 -0
- package/dist/internal/id.js.map +1 -0
- package/dist/internal/injection-heuristics.js +64 -0
- package/dist/internal/injection-heuristics.js.map +1 -0
- package/dist/internal/spans.js +35 -0
- package/dist/internal/spans.js.map +1 -0
- package/dist/internal/storage-adapter.d.ts +742 -0
- package/dist/internal/storage-adapter.d.ts.map +1 -0
- package/dist/migration/embedder-migration.d.ts +124 -0
- package/dist/migration/embedder-migration.d.ts.map +1 -0
- package/dist/migration/embedder-migration.js +109 -0
- package/dist/migration/embedder-migration.js.map +1 -0
- package/dist/migration/index.d.ts +2 -0
- package/dist/migration/index.js +3 -0
- package/dist/search/explain.d.ts +74 -0
- package/dist/search/explain.d.ts.map +1 -0
- package/dist/search/explain.js +50 -0
- package/dist/search/explain.js.map +1 -0
- package/dist/search/index.d.ts +6 -0
- package/dist/search/index.js +6 -0
- package/dist/search/iterative.d.ts +223 -0
- package/dist/search/iterative.d.ts.map +1 -0
- package/dist/search/iterative.js +330 -0
- package/dist/search/iterative.js.map +1 -0
- package/dist/search/query-transform.d.ts +112 -0
- package/dist/search/query-transform.d.ts.map +1 -0
- package/dist/search/query-transform.js +184 -0
- package/dist/search/query-transform.js.map +1 -0
- package/dist/search/rrf.d.ts +95 -0
- package/dist/search/rrf.d.ts.map +1 -0
- package/dist/search/rrf.js +166 -0
- package/dist/search/rrf.js.map +1 -0
- package/dist/search/types.d.ts +50 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/tiers/episodic-memory.d.ts +142 -0
- package/dist/tiers/episodic-memory.d.ts.map +1 -0
- package/dist/tiers/episodic-memory.js +254 -0
- package/dist/tiers/episodic-memory.js.map +1 -0
- package/dist/tiers/index.d.ts +8 -0
- package/dist/tiers/index.js +9 -0
- package/dist/tiers/insight-memory.d.ts +71 -0
- package/dist/tiers/insight-memory.d.ts.map +1 -0
- package/dist/tiers/insight-memory.js +133 -0
- package/dist/tiers/insight-memory.js.map +1 -0
- package/dist/tiers/procedural-memory.d.ts +147 -0
- package/dist/tiers/procedural-memory.d.ts.map +1 -0
- package/dist/tiers/procedural-memory.js +267 -0
- package/dist/tiers/procedural-memory.js.map +1 -0
- package/dist/tiers/semantic-memory.d.ts +461 -0
- package/dist/tiers/semantic-memory.d.ts.map +1 -0
- package/dist/tiers/semantic-memory.js +631 -0
- package/dist/tiers/semantic-memory.js.map +1 -0
- package/dist/tiers/session-memory.d.ts +117 -0
- package/dist/tiers/session-memory.d.ts.map +1 -0
- package/dist/tiers/session-memory.js +163 -0
- package/dist/tiers/session-memory.js.map +1 -0
- package/dist/tiers/shared-memory.d.ts +29 -0
- package/dist/tiers/shared-memory.d.ts.map +1 -0
- package/dist/tiers/shared-memory.js +58 -0
- package/dist/tiers/shared-memory.js.map +1 -0
- package/dist/tiers/working-memory.d.ts +129 -0
- package/dist/tiers/working-memory.d.ts.map +1 -0
- package/dist/tiers/working-memory.js +229 -0
- package/dist/tiers/working-memory.js.map +1 -0
- package/dist/tools/block-tools.d.ts +98 -0
- package/dist/tools/block-tools.d.ts.map +1 -0
- package/dist/tools/block-tools.js +114 -0
- package/dist/tools/block-tools.js.map +1 -0
- package/dist/tools/fact-tools.d.ts +294 -0
- package/dist/tools/fact-tools.d.ts.map +1 -0
- package/dist/tools/fact-tools.js +293 -0
- package/dist/tools/fact-tools.js.map +1 -0
- package/dist/tools/index.d.ts +35 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +36 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/recall-tools.d.ts +209 -0
- package/dist/tools/recall-tools.d.ts.map +1 -0
- package/dist/tools/recall-tools.js +170 -0
- package/dist/tools/recall-tools.js.map +1 -0
- package/dist/tools/types.d.ts +40 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/package.json +119 -0
package/dist/facade.d.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { EmbeddingMetaRegistryLike, MemoryStoreAdapter } from "./internal/storage-adapter.js";
|
|
2
|
+
import { ConflictPipeline, ConflictPipelineOptions } from "./conflict/types.js";
|
|
3
|
+
import "./conflict/index.js";
|
|
4
|
+
import { ContextualRetrievalMode } from "./internal/contextualize.js";
|
|
5
|
+
import { EpisodicMemory } from "./tiers/episodic-memory.js";
|
|
6
|
+
import { EntityResolutionConfig } from "./graph/entity-resolver.js";
|
|
7
|
+
import { ReRanker } from "./search/types.js";
|
|
8
|
+
import { SemanticMemory } from "./tiers/semantic-memory.js";
|
|
9
|
+
import { SalienceWeights } from "./consolidator/decay.js";
|
|
10
|
+
import { ConsolidatorCeilings, ConsolidatorPhase, ConsolidatorTier, ConsolidatorTriggerSpec, OnBudgetExceed, PhaseListener } from "./consolidator/types.js";
|
|
11
|
+
import { Consolidator } from "./consolidator/runtime.js";
|
|
12
|
+
import "./consolidator/index.js";
|
|
13
|
+
import { ContextEngine, ContextEngineConfig } from "./context-engine/engine.js";
|
|
14
|
+
import { CompileOptions, CompileScope, MemoryContextBlocks } from "./context-engine/index.js";
|
|
15
|
+
import { InsightMemory } from "./tiers/insight-memory.js";
|
|
16
|
+
import { ProceduralMemory } from "./tiers/procedural-memory.js";
|
|
17
|
+
import { SessionMemory } from "./tiers/session-memory.js";
|
|
18
|
+
import { SharedMemory } from "./tiers/shared-memory.js";
|
|
19
|
+
import { BlockDefinition, WorkingMemory } from "./tiers/working-memory.js";
|
|
20
|
+
import { ScopeResolver } from "./tools/types.js";
|
|
21
|
+
import "./tools/index.js";
|
|
22
|
+
import { EmbedderProvider, MemoryMetadata, Provider, SessionScope, Tool, Tracer } from "@graphorin/core";
|
|
23
|
+
|
|
24
|
+
//#region src/facade.d.ts
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Options accepted by {@link createMemory}.
|
|
28
|
+
*
|
|
29
|
+
* @stable
|
|
30
|
+
*/
|
|
31
|
+
interface CreateMemoryOptions {
|
|
32
|
+
/** Storage adapter (default: `@graphorin/store-sqlite`'s `MemoryStore`). */
|
|
33
|
+
readonly store: MemoryStoreAdapter;
|
|
34
|
+
/** Embedder registry. The default sqlite store exposes one as `sqlite.embeddings`. */
|
|
35
|
+
readonly embeddings: EmbeddingMetaRegistryLike;
|
|
36
|
+
/** Embedder provider (default: none — vector search is disabled). */
|
|
37
|
+
readonly embedder?: EmbedderProvider;
|
|
38
|
+
/** Pre-declared working blocks (idempotent — re-defining is a no-op). */
|
|
39
|
+
readonly workingBlocks?: ReadonlyArray<BlockDefinition>;
|
|
40
|
+
/**
|
|
41
|
+
* Tracer used for every `memory.*` span. Defaults to the no-op
|
|
42
|
+
* tracer from `@graphorin/core` so unit tests do not need to wire
|
|
43
|
+
* the observability stack.
|
|
44
|
+
*/
|
|
45
|
+
readonly tracer?: Tracer;
|
|
46
|
+
/** Override the reranker used by `SemanticMemory.search`. */
|
|
47
|
+
readonly reranker?: ReRanker;
|
|
48
|
+
/**
|
|
49
|
+
* Contextual-retrieval mode for the write path (P1-3). `'late-chunk'`
|
|
50
|
+
* (default) prepends a deterministic, offline situating context
|
|
51
|
+
* (entities / timeframe / topics, derived from the fact's own
|
|
52
|
+
* structured fields) to the text that is embedded + FTS-indexed, so a
|
|
53
|
+
* terse fact stays findable; the canonical `text` is preserved. `'off'`
|
|
54
|
+
* indexes the bare text. The `'llm'` enrichment is **not** available on
|
|
55
|
+
* the hot path — it is a consolidator-only opt-in configured via
|
|
56
|
+
* `consolidator: { contextualRetrieval: 'llm' }`.
|
|
57
|
+
*/
|
|
58
|
+
readonly contextualRetrieval?: 'off' | 'late-chunk';
|
|
59
|
+
/**
|
|
60
|
+
* Query transformation for retrieval (P2-3, opt-in). When supplied,
|
|
61
|
+
* `SemanticMemory.search(..., { multiQuery })` fans the query into
|
|
62
|
+
* reworded variants (multi-query / RAG-Fusion) and `{ hyde }` adds a
|
|
63
|
+
* hypothetical-answer embedding — both via one cheap LLM call on the
|
|
64
|
+
* given provider, fused through the existing RRF reranker. Omitted (the
|
|
65
|
+
* default) ⇒ search stays **offline + single-shot** and the
|
|
66
|
+
* `multiQuery` / `hyde` search options become silent no-ops. Reserve it
|
|
67
|
+
* for retrieval-heavy recall, not every search (it adds provider
|
|
68
|
+
* latency).
|
|
69
|
+
*/
|
|
70
|
+
readonly queryTransform?: {
|
|
71
|
+
/** Cheap provider used to rewrite the query / write the HyDE passage. */
|
|
72
|
+
readonly provider: Provider;
|
|
73
|
+
/** Hard ceiling on reworded variants requested per call. Default 5. */
|
|
74
|
+
readonly maxVariants?: number;
|
|
75
|
+
/** Output-token ceiling per transform call. Default 256. */
|
|
76
|
+
readonly maxTokens?: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Relation-graph entity resolution (P2-1). When `entityResolution` is
|
|
80
|
+
* `true` **and** the storage adapter exposes a `graph` surface (the
|
|
81
|
+
* default `@graphorin/store-sqlite` does), `remember(...)` resolves a
|
|
82
|
+
* fact's subject / object to canonical entities and links them, so
|
|
83
|
+
* `search(..., { expandHops: 1 })` can traverse relationships. Omitted
|
|
84
|
+
* (the default) ⇒ facts still carry s/p/o but form no entity links and
|
|
85
|
+
* the write path stays offline + unchanged. Dedup is lexical +
|
|
86
|
+
* embedding (offline, via the configured embedder); LLM adjudication of
|
|
87
|
+
* ambiguous merges is a further opt-in that needs `provider`.
|
|
88
|
+
*/
|
|
89
|
+
readonly graph?: EntityResolutionConfig & {
|
|
90
|
+
/** Enable entity resolution + linking on write. Default `false`. */
|
|
91
|
+
readonly entityResolution?: boolean;
|
|
92
|
+
/** Provider for opt-in LLM adjudication of ambiguous merges. */
|
|
93
|
+
readonly provider?: Provider;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Agentic / iterative retrieval (P2-4, opt-in). When supplied,
|
|
97
|
+
* `SemanticMemory.searchIterative(...)` and the gated `deep_recall`
|
|
98
|
+
* tool can grade a retrieved set on the given provider and, for queries
|
|
99
|
+
* judged hard, reformulate + retrieve again (widening to one-hop graph
|
|
100
|
+
* expansion) up to `maxIterations`, abstaining instead of confabulating
|
|
101
|
+
* when memory is insufficient. Omitted (the default) ⇒ `searchIterative`
|
|
102
|
+
* stays a single difficulty-gated pass with **no provider call**, and
|
|
103
|
+
* `deep_recall` is **not** registered (the tool surface stays at the
|
|
104
|
+
* canonical eleven). Reserve it for hard multi-hop / temporal recall —
|
|
105
|
+
* it adds provider latency per pass.
|
|
106
|
+
*/
|
|
107
|
+
readonly iterativeRetrieval?: {
|
|
108
|
+
/** Cheap provider used to grade retrieved memories + reformulate. */
|
|
109
|
+
readonly provider: Provider;
|
|
110
|
+
/** Default total-pass cap (clamped to `[1, 5]`). Default 3. */
|
|
111
|
+
readonly maxIterations?: number;
|
|
112
|
+
/** Output-token ceiling per grade call. Default 256. */
|
|
113
|
+
readonly maxTokens?: number;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Opt-in workflow induction (P2-2). When set, `ProceduralMemory.induce(...)`
|
|
117
|
+
* distils a reusable, value-abstracted procedure from a successful agent
|
|
118
|
+
* trajectory and stores it **quarantined** + `provenance: 'induction'`.
|
|
119
|
+
* Omitted (the default) ⇒ `induce(...)` throws
|
|
120
|
+
* {@link ProcedureInductionNotConfiguredError} and the procedural tier
|
|
121
|
+
* stays pure offline CRUD — no provider call.
|
|
122
|
+
*/
|
|
123
|
+
readonly procedureInduction?: {
|
|
124
|
+
/** Provider used to abstract trajectory values into a procedure. */
|
|
125
|
+
readonly provider: Provider;
|
|
126
|
+
/** Output-token ceiling per induction call. Default 512. */
|
|
127
|
+
readonly maxTokens?: number;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Promotion-by-demonstrated-success for quarantined induced
|
|
131
|
+
* procedures (MCON-2 part 4). Fully offline — orthogonal to
|
|
132
|
+
* `procedureInduction` (no provider needed). When configured,
|
|
133
|
+
* `procedural.recordOutcome(scope, id, true)` increments the rule's
|
|
134
|
+
* persistent success counter and promotes it into `activate()` once
|
|
135
|
+
* `afterSuccesses` verified reuses accumulate; the injection gate
|
|
136
|
+
* still refuses flagged texts. Omitted ⇒ outcomes are counted but
|
|
137
|
+
* nothing auto-promotes.
|
|
138
|
+
*/
|
|
139
|
+
readonly procedurePromotion?: {
|
|
140
|
+
/** Successful demonstrated reuses required before promotion (≥ 1). */
|
|
141
|
+
readonly afterSuccesses: number;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Resolver that produces the live {@link SessionScope} for each
|
|
145
|
+
* memory-tool invocation. Defaults to a closure that throws — the
|
|
146
|
+
* agent runtime overrides it in Phase 12.
|
|
147
|
+
*/
|
|
148
|
+
readonly resolveScope?: ScopeResolver;
|
|
149
|
+
/**
|
|
150
|
+
* Consolidator configuration. When omitted, empty, or
|
|
151
|
+
* `enabled: false`, the facade installs the Phase 10a no-op
|
|
152
|
+
* placeholder so consumers can still type their interactions without
|
|
153
|
+
* paying the runtime cost. ANY other setting — including offline
|
|
154
|
+
* knobs like `decayCapacity` or `contextualRetrieval` — implicitly
|
|
155
|
+
* enables the production runtime (MST-4); `enabled: false` together
|
|
156
|
+
* with other settings warns once and keeps the placeholder.
|
|
157
|
+
*/
|
|
158
|
+
readonly consolidator?: {
|
|
159
|
+
readonly enabled?: boolean;
|
|
160
|
+
readonly triggers?: ReadonlyArray<ConsolidatorTriggerSpec>;
|
|
161
|
+
readonly tier?: ConsolidatorTier;
|
|
162
|
+
readonly phases?: ReadonlyArray<ConsolidatorPhase>;
|
|
163
|
+
readonly ceilings?: Partial<ConsolidatorCeilings>;
|
|
164
|
+
readonly onExceed?: OnBudgetExceed;
|
|
165
|
+
/** Provider routed to the standard phase when set (MCON-7); falls back to `provider`. */
|
|
166
|
+
readonly cheapProvider?: Provider | null;
|
|
167
|
+
/** Provider routed to the deep + reflection passes when set (MCON-7). */
|
|
168
|
+
readonly deepProvider?: Provider | null;
|
|
169
|
+
readonly cheapModel?: string | null;
|
|
170
|
+
readonly deepModel?: string | null;
|
|
171
|
+
readonly noiseFilters?: ReadonlyArray<'default' | 'minimal' | 'none'>;
|
|
172
|
+
readonly lockWaitMs?: number;
|
|
173
|
+
readonly decayTauDays?: number;
|
|
174
|
+
readonly decayArchiveThreshold?: number;
|
|
175
|
+
/** Capacity-bounded eviction target for the light phase (X-1). Default unbounded. */
|
|
176
|
+
readonly decayCapacity?: number | null;
|
|
177
|
+
/** Weights for the multi-signal salience score (X-1). */
|
|
178
|
+
readonly salienceWeights?: SalienceWeights;
|
|
179
|
+
readonly maxStandardBatchSize?: number;
|
|
180
|
+
readonly maxDeepConflictsPerRun?: number;
|
|
181
|
+
readonly dlqMaxRetries?: number;
|
|
182
|
+
readonly dlqBaseBackoffMs?: number;
|
|
183
|
+
readonly dlqMaxBackoffMs?: number;
|
|
184
|
+
/** Auto-form quarantined episodes from processed slices (P1-2). Per-tier default. */
|
|
185
|
+
readonly formEpisodes?: boolean;
|
|
186
|
+
/** Score episode importance via the consolidator LLM (P1-2). Per-tier default. */
|
|
187
|
+
readonly importanceScoring?: boolean;
|
|
188
|
+
/** Opt in to auto-promotion of injection-clean extraction facts (MCON-2). Default off. */
|
|
189
|
+
readonly autoPromoteExtraction?: boolean;
|
|
190
|
+
/** Run the deep-phase reflection pass synthesizing cited insights (P1-1). Per-tier default. */
|
|
191
|
+
readonly reflection?: boolean;
|
|
192
|
+
/** Accumulated-importance threshold at which reflection fires (P1-1). */
|
|
193
|
+
readonly importanceThreshold?: number;
|
|
194
|
+
/** Upper bound on salient questions reflection asks per pass (P1-1). */
|
|
195
|
+
readonly reflectionMaxQuestions?: number;
|
|
196
|
+
/**
|
|
197
|
+
* Contextual retrieval for standard-phase fact writes (P1-3).
|
|
198
|
+
* `'llm'` opts into one budgeted cheap-model call per write to author
|
|
199
|
+
* a situating prefix (consolidator-only); `'late-chunk'` (default)
|
|
200
|
+
* and `'off'` defer to the write-path mode. Per-tier default.
|
|
201
|
+
*/
|
|
202
|
+
readonly contextualRetrieval?: ContextualRetrievalMode;
|
|
203
|
+
readonly defaultScope?: SessionScope;
|
|
204
|
+
readonly provider?: Provider | null;
|
|
205
|
+
/** Override the wall clock — used by tests. */
|
|
206
|
+
readonly now?: () => number;
|
|
207
|
+
/** Stable id seed — used by tests. */
|
|
208
|
+
readonly randomId?: () => string;
|
|
209
|
+
/** Subscribe to phase-finished events. */
|
|
210
|
+
readonly onPhaseFinished?: PhaseListener;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Conflict pipeline configuration (Phase 10b). Default: enabled,
|
|
214
|
+
* English locale pack, thresholds `0.95 / 0.85 / 0.4`. Pass
|
|
215
|
+
* `{ mode: 'off' }` to bypass the pipeline entirely (logs a one-shot
|
|
216
|
+
* WARN per process per the spec).
|
|
217
|
+
*/
|
|
218
|
+
readonly conflictPipeline?: ConflictPipelineOptions;
|
|
219
|
+
/**
|
|
220
|
+
* Context engine configuration (Phase 10d). The engine assembles
|
|
221
|
+
* the layered six-layer system prompt; `memory.compile(scope)`
|
|
222
|
+
* delegates to it for the working blocks + rules + metadata
|
|
223
|
+
* fragments. When omitted, a default engine is created (English
|
|
224
|
+
* locale; `'full'` base mode; no auto-recall; conservative
|
|
225
|
+
* `'public-tls'` provider trust).
|
|
226
|
+
*/
|
|
227
|
+
readonly contextEngine?: ContextEngineConfig;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The facade returned by {@link createMemory}.
|
|
231
|
+
*
|
|
232
|
+
* @stable
|
|
233
|
+
*/
|
|
234
|
+
interface Memory {
|
|
235
|
+
readonly working: WorkingMemory;
|
|
236
|
+
readonly session: SessionMemory;
|
|
237
|
+
readonly episodic: EpisodicMemory;
|
|
238
|
+
readonly semantic: SemanticMemory;
|
|
239
|
+
readonly procedural: ProceduralMemory;
|
|
240
|
+
readonly shared: SharedMemory;
|
|
241
|
+
/**
|
|
242
|
+
* Read surface over reflection insights (P1-1). A no-op (returns
|
|
243
|
+
* empty) when the storage adapter does not expose the optional
|
|
244
|
+
* insight surface.
|
|
245
|
+
*/
|
|
246
|
+
readonly insights: InsightMemory;
|
|
247
|
+
readonly tools: ReadonlyArray<Tool>;
|
|
248
|
+
readonly consolidator: Consolidator;
|
|
249
|
+
/** The configured conflict pipeline. Surfaced for tests + CLI tooling. */
|
|
250
|
+
readonly conflictPipeline: ConflictPipeline;
|
|
251
|
+
/** The configured context engine (Phase 10d). */
|
|
252
|
+
readonly contextEngine: ContextEngine;
|
|
253
|
+
/** The active embedder, when configured. `null` otherwise. */
|
|
254
|
+
readonly embedder: EmbedderProvider | null;
|
|
255
|
+
/** The canonical id of the active embedder, when configured. */
|
|
256
|
+
embedderId(): string | null;
|
|
257
|
+
/**
|
|
258
|
+
* Compile a system-prompt block bundle. The bundle carries the
|
|
259
|
+
* static fragments per memory tier; the agent runtime consumes
|
|
260
|
+
* the {@link ContextEngine} surface (`memory.contextEngine`)
|
|
261
|
+
* directly for the full six-layer assembly.
|
|
262
|
+
*/
|
|
263
|
+
compile(scope: CompileScope, options?: CompileOptions): Promise<MemoryContextBlocks>;
|
|
264
|
+
/** Counter snapshot consumed by Phase 10d's metadata layer. */
|
|
265
|
+
metadata(scope: SessionScope): Promise<MemoryMetadata>;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Wire every memory subsystem in one call. Returns the typed
|
|
269
|
+
* `Memory` facade ready to be passed into `createAgent({...})`.
|
|
270
|
+
*
|
|
271
|
+
* @stable
|
|
272
|
+
*/
|
|
273
|
+
declare function createMemory(options: CreateMemoryOptions): Memory;
|
|
274
|
+
/** @internal — test seam for the one-time disabled-config warning. */
|
|
275
|
+
declare function _resetConsolidatorConfigWarningForTesting(): void;
|
|
276
|
+
//#endregion
|
|
277
|
+
export { CreateMemoryOptions, Memory, _resetConsolidatorConfigWarningForTesting, createMemory };
|
|
278
|
+
//# sourceMappingURL=facade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facade.d.ts","names":[],"sources":["../src/facade.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuEA;;;;;AAQ2B,UARV,mBAAA,CAQU;EAMP;EAEE,SAAA,KAAA,EAdJ,kBAcI;EAyBC;EAiBJ,SAAA,UAAA,EAtDI,yBAsDJ;EAIK;EAgBD,SAAA,QAAA,CAAA,EAxED,gBAwEC;EAgBA;EAuBG,SAAA,aAAA,CAAA,EA7GC,aA6GD,CA7Ge,eA6Gf,CAAA;EAYY;;;;;EAGN,SAAA,MAAA,CAAA,EAtHZ,MAsHY;EAAR;EACA,SAAA,QAAA,CAAA,EArHF,QAqHE;EAEK;;;;;;;;;;EA6DiB,SAAA,mBAAA,CAAA,EAAA,KAAA,GAAA,YAAA;EAQ7B;;;;;;;;;;;EAgBY,SAAA,cAAA,CAAA,EAAA;IAEH;IAEL,SAAA,QAAA,EAvLE,QAuLF;IASJ;IAAwB,SAAA,WAAA,CAAA,EAAA,MAAA;IAAyB;IAAR,SAAA,SAAA,CAAA,EAAA,MAAA;EAExC,CAAA;EAAuB;;;AASzC;AAuWA;;;;;;;mBAjiBmB;;;;wBAIK;;;;;;;;;;;;;;;;uBAgBD;;;;;;;;;;;;;;;;uBAgBA;;;;;;;;;;;;;;;;;;;;;;;0BAuBG;;;;;;;;;;;;wBAYF,cAAc;oBAClB;sBACE,cAAc;wBACZ,QAAQ;wBACR;;6BAEK;;4BAED;;;4BAGA;;;;;;;+BAOG;;;;;;;;;;;;;;;;;;;;;;;;mCAwBI;4BACP;wBACJ;;;;;;+BAMO;;;;;;;;8BAQD;;;;;;;;;2BASH;;;;;;;UAQV,MAAA;oBACG;oBACA;qBACC;qBACA;uBACE;mBACJ;;;;;;qBAME;kBACH,cAAc;yBACP;;6BAEI;;0BAEH;;qBAEL;;;;;;;;;iBASJ,wBAAwB,iBAAiB,QAAQ;;kBAEhD,eAAe,QAAQ;;;;;;;;iBASzB,YAAA,UAAsB,sBAAsB;;iBAuW5C,yCAAA,CAAA"}
|
package/dist/facade.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { createConflictPipeline } from "./conflict/pipeline.js";
|
|
2
|
+
import "./conflict/index.js";
|
|
3
|
+
import { createProviderWorkflowInducer } from "./consolidator/phases/induce.js";
|
|
4
|
+
import { createConsolidator } from "./consolidator/runtime.js";
|
|
5
|
+
import { createConsolidatorPlaceholder } from "./consolidator/index.js";
|
|
6
|
+
import { enLocalePack } from "./context-engine/locale-packs/en.js";
|
|
7
|
+
import "./context-engine/locale-packs/index.js";
|
|
8
|
+
import { resolveLocalePack } from "./context-engine/locale-packs/resolver.js";
|
|
9
|
+
import { gatherMemoryMetadata, renderMetadataBlock } from "./context-engine/metadata.js";
|
|
10
|
+
import { partition } from "./context-engine/privacy-filter.js";
|
|
11
|
+
import { composeLayer1 } from "./context-engine/templates/composer.js";
|
|
12
|
+
import { createContextEngine } from "./context-engine/engine.js";
|
|
13
|
+
import { EntityResolver } from "./graph/entity-resolver.js";
|
|
14
|
+
import { bindEmbedder } from "./internal/embedder-binding.js";
|
|
15
|
+
import { createProviderRetrievalGrader } from "./search/iterative.js";
|
|
16
|
+
import { createProviderQueryTransformer } from "./search/query-transform.js";
|
|
17
|
+
import { RRFReranker } from "./search/rrf.js";
|
|
18
|
+
import { EpisodicMemory } from "./tiers/episodic-memory.js";
|
|
19
|
+
import { InsightMemory } from "./tiers/insight-memory.js";
|
|
20
|
+
import { ProceduralMemory } from "./tiers/procedural-memory.js";
|
|
21
|
+
import { SemanticMemory } from "./tiers/semantic-memory.js";
|
|
22
|
+
import { SessionMemory } from "./tiers/session-memory.js";
|
|
23
|
+
import { SharedMemory } from "./tiers/shared-memory.js";
|
|
24
|
+
import { WorkingMemory } from "./tiers/working-memory.js";
|
|
25
|
+
import { buildMemoryTools } from "./tools/index.js";
|
|
26
|
+
import { NOOP_TRACER } from "@graphorin/core";
|
|
27
|
+
|
|
28
|
+
//#region src/facade.ts
|
|
29
|
+
/**
|
|
30
|
+
* Wire every memory subsystem in one call. Returns the typed
|
|
31
|
+
* `Memory` facade ready to be passed into `createAgent({...})`.
|
|
32
|
+
*
|
|
33
|
+
* @stable
|
|
34
|
+
*/
|
|
35
|
+
function createMemory(options) {
|
|
36
|
+
const tracer = options.tracer ?? NOOP_TRACER;
|
|
37
|
+
const reranker = options.reranker ?? new RRFReranker();
|
|
38
|
+
const resolveScope = options.resolveScope ?? (() => {
|
|
39
|
+
throw new TypeError("[graphorin/memory] memory tool invoked without a scope resolver. Pass `resolveScope` to createMemory({...}) — the agent runtime supplies one in Phase 12.");
|
|
40
|
+
});
|
|
41
|
+
let activeEmbedderId = null;
|
|
42
|
+
if (options.embedder !== void 0) activeEmbedderId = bindEmbedder(options.embedder, options.embeddings);
|
|
43
|
+
const embedder = options.embedder ?? null;
|
|
44
|
+
const embedderIdProvider = () => activeEmbedderId;
|
|
45
|
+
const working = new WorkingMemory({
|
|
46
|
+
store: options.store,
|
|
47
|
+
tracer
|
|
48
|
+
});
|
|
49
|
+
for (const block of options.workingBlocks ?? []) working.define(block);
|
|
50
|
+
const session = new SessionMemory({
|
|
51
|
+
store: options.store,
|
|
52
|
+
tracer
|
|
53
|
+
});
|
|
54
|
+
const episodic = new EpisodicMemory({
|
|
55
|
+
store: options.store,
|
|
56
|
+
tracer,
|
|
57
|
+
embedder,
|
|
58
|
+
embedderIdProvider
|
|
59
|
+
});
|
|
60
|
+
const conflictPipeline = createConflictPipeline(options.conflictPipeline ?? {});
|
|
61
|
+
const queryTransformer = options.queryTransform !== void 0 ? createProviderQueryTransformer(options.queryTransform.provider, {
|
|
62
|
+
...options.queryTransform.maxVariants !== void 0 ? { maxVariants: options.queryTransform.maxVariants } : {},
|
|
63
|
+
...options.queryTransform.maxTokens !== void 0 ? { maxTokens: options.queryTransform.maxTokens } : {}
|
|
64
|
+
}) : null;
|
|
65
|
+
const graphStore = options.store.graph;
|
|
66
|
+
const entityResolver = options.graph?.entityResolution === true && graphStore !== void 0 ? new EntityResolver({
|
|
67
|
+
store: graphStore,
|
|
68
|
+
embedder,
|
|
69
|
+
embedderId: embedderIdProvider,
|
|
70
|
+
...options.graph.provider !== void 0 ? { provider: options.graph.provider } : {},
|
|
71
|
+
config: {
|
|
72
|
+
...options.graph.mergeThreshold !== void 0 ? { mergeThreshold: options.graph.mergeThreshold } : {},
|
|
73
|
+
...options.graph.adjudicateThreshold !== void 0 ? { adjudicateThreshold: options.graph.adjudicateThreshold } : {},
|
|
74
|
+
...options.graph.llmAdjudication !== void 0 ? { llmAdjudication: options.graph.llmAdjudication } : {}
|
|
75
|
+
}
|
|
76
|
+
}) : null;
|
|
77
|
+
const grader = options.iterativeRetrieval !== void 0 ? createProviderRetrievalGrader(options.iterativeRetrieval.provider, { ...options.iterativeRetrieval.maxTokens !== void 0 ? { maxTokens: options.iterativeRetrieval.maxTokens } : {} }) : null;
|
|
78
|
+
const semantic = new SemanticMemory({
|
|
79
|
+
store: options.store,
|
|
80
|
+
tracer,
|
|
81
|
+
embedder,
|
|
82
|
+
embedderIdProvider,
|
|
83
|
+
reranker,
|
|
84
|
+
conflictPipeline,
|
|
85
|
+
...options.contextualRetrieval !== void 0 ? { contextualRetrieval: options.contextualRetrieval } : {},
|
|
86
|
+
...queryTransformer !== null ? { queryTransformer } : {},
|
|
87
|
+
...entityResolver !== null ? { entityResolver } : {},
|
|
88
|
+
...grader !== null ? { grader } : {},
|
|
89
|
+
...options.iterativeRetrieval?.maxIterations !== void 0 ? { iterativeMaxIterations: options.iterativeRetrieval.maxIterations } : {}
|
|
90
|
+
});
|
|
91
|
+
let consolidatorForSpend = null;
|
|
92
|
+
const inducer = options.procedureInduction !== void 0 ? createProviderWorkflowInducer(options.procedureInduction.provider, {
|
|
93
|
+
...options.procedureInduction.maxTokens !== void 0 ? { maxTokens: options.procedureInduction.maxTokens } : {},
|
|
94
|
+
onUsage: (usage) => {
|
|
95
|
+
consolidatorForSpend?.recordExternalSpend(usage.promptTokens + usage.completionTokens);
|
|
96
|
+
}
|
|
97
|
+
}) : null;
|
|
98
|
+
const procedural = new ProceduralMemory({
|
|
99
|
+
store: options.store,
|
|
100
|
+
tracer,
|
|
101
|
+
...inducer !== null ? { inducer } : {},
|
|
102
|
+
...options.procedurePromotion?.afterSuccesses !== void 0 ? { promoteAfterSuccesses: options.procedurePromotion.afterSuccesses } : {}
|
|
103
|
+
});
|
|
104
|
+
const shared = new SharedMemory({
|
|
105
|
+
store: options.store,
|
|
106
|
+
tracer
|
|
107
|
+
});
|
|
108
|
+
const insights = new InsightMemory({
|
|
109
|
+
store: options.store,
|
|
110
|
+
tracer
|
|
111
|
+
});
|
|
112
|
+
const tools = buildMemoryTools({
|
|
113
|
+
working,
|
|
114
|
+
session,
|
|
115
|
+
episodic,
|
|
116
|
+
semantic,
|
|
117
|
+
procedural,
|
|
118
|
+
shared,
|
|
119
|
+
resolveScope
|
|
120
|
+
}, { includeDeepRecall: grader !== null });
|
|
121
|
+
const consolidatorOpts = options.consolidator;
|
|
122
|
+
const consolidator = buildConsolidator(consolidatorOpts, options.store, semantic, episodic, tracer);
|
|
123
|
+
consolidatorForSpend = consolidator;
|
|
124
|
+
const contextEngineConfig = options.contextEngine ?? {};
|
|
125
|
+
const contextEngine = createContextEngine(contextEngineConfig);
|
|
126
|
+
const resolved = contextEngine.config();
|
|
127
|
+
const localePack = contextEngineConfig.locale === void 0 ? enLocalePack : typeof contextEngineConfig.locale === "string" ? contextEngineConfig.locale === enLocalePack.id ? enLocalePack : resolveLocalePack({ id: contextEngineConfig.locale }) : resolveLocalePack(contextEngineConfig.locale);
|
|
128
|
+
const privacyOptedIn = contextEngineConfig.privacy !== void 0 && (contextEngineConfig.privacy.providerAcceptsSensitivity !== void 0 || contextEngineConfig.privacy.cloudUploadConsent !== void 0 || contextEngineConfig.privacy.providerTrust !== void 0);
|
|
129
|
+
async function compile(scope, compileOptions = {}) {
|
|
130
|
+
const out = {};
|
|
131
|
+
const blocks = await options.store.working.list(scope);
|
|
132
|
+
const rules = (await options.store.procedural.list(scope)).filter((rule) => rule.status !== "quarantined");
|
|
133
|
+
const shouldFilter = privacyOptedIn || compileOptions.providerAcceptsSensitivity !== void 0;
|
|
134
|
+
let blocksKept = blocks;
|
|
135
|
+
let rulesKept = rules;
|
|
136
|
+
if (shouldFilter) {
|
|
137
|
+
const filterContext = {
|
|
138
|
+
providerTrust: resolved.providerTrust,
|
|
139
|
+
cloudUploadConsent: resolved.cloudUploadConsent,
|
|
140
|
+
defaultSensitivity: resolved.defaultSensitivity
|
|
141
|
+
};
|
|
142
|
+
if (compileOptions.providerAcceptsSensitivity !== void 0) filterContext.providerAcceptsSensitivity = compileOptions.providerAcceptsSensitivity;
|
|
143
|
+
blocksKept = partition(blocks, filterContext).kept;
|
|
144
|
+
rulesKept = partition(rules, filterContext).kept;
|
|
145
|
+
}
|
|
146
|
+
const blocksXml = renderWorkingBlocksXml(blocksKept);
|
|
147
|
+
if (blocksXml.length > 0) out.workingBlocks = blocksXml;
|
|
148
|
+
if (rulesKept.length > 0) {
|
|
149
|
+
const lines = ["<memory_rules>"];
|
|
150
|
+
for (const rule of rulesKept) lines.push(` <rule priority="${rule.priority}">${escapeXml(rule.text)}</rule>`);
|
|
151
|
+
lines.push("</memory_rules>");
|
|
152
|
+
out.rules = lines.join("\n");
|
|
153
|
+
}
|
|
154
|
+
if (compileOptions.includeMetadata !== false) out.metadata = renderMetadataBlock(await metadata(scope));
|
|
155
|
+
out.base = composeLayer1(localePack, resolved.memoryBaseMode);
|
|
156
|
+
return Object.freeze(out);
|
|
157
|
+
}
|
|
158
|
+
async function metadata(scope) {
|
|
159
|
+
return gatherMemoryMetadata(scope, {
|
|
160
|
+
store: options.store,
|
|
161
|
+
consolidator,
|
|
162
|
+
embedderId: embedderIdProvider,
|
|
163
|
+
localeId: resolved.localeId
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return Object.freeze({
|
|
167
|
+
working,
|
|
168
|
+
session,
|
|
169
|
+
episodic,
|
|
170
|
+
semantic,
|
|
171
|
+
procedural,
|
|
172
|
+
shared,
|
|
173
|
+
insights,
|
|
174
|
+
tools,
|
|
175
|
+
consolidator,
|
|
176
|
+
conflictPipeline,
|
|
177
|
+
contextEngine,
|
|
178
|
+
embedder,
|
|
179
|
+
embedderId: embedderIdProvider,
|
|
180
|
+
compile,
|
|
181
|
+
metadata
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function renderWorkingBlocksXml(blocks) {
|
|
185
|
+
if (blocks.length === 0) return "";
|
|
186
|
+
const lines = ["<memory_blocks>"];
|
|
187
|
+
for (const block of blocks) {
|
|
188
|
+
const description = block.description !== void 0 ? ` description="${escapeXml(block.description)}"` : "";
|
|
189
|
+
lines.push(` <block label="${escapeXml(block.label)}"${description}>`);
|
|
190
|
+
lines.push(` ${escapeXml(block.value)}`);
|
|
191
|
+
lines.push(" </block>");
|
|
192
|
+
}
|
|
193
|
+
lines.push("</memory_blocks>");
|
|
194
|
+
return lines.join("\n");
|
|
195
|
+
}
|
|
196
|
+
function escapeXml(value) {
|
|
197
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
198
|
+
}
|
|
199
|
+
function buildConsolidator(opts, store, semantic, episodic, tracer) {
|
|
200
|
+
if (opts === void 0) return createConsolidatorPlaceholder();
|
|
201
|
+
if (!shouldEnableConsolidator(opts)) return createConsolidatorPlaceholder({
|
|
202
|
+
...opts.triggers !== void 0 ? { triggers: opts.triggers } : {},
|
|
203
|
+
...opts.tier !== void 0 ? { tier: opts.tier } : {}
|
|
204
|
+
});
|
|
205
|
+
const consolidator = createConsolidator({
|
|
206
|
+
store,
|
|
207
|
+
semantic,
|
|
208
|
+
episodic,
|
|
209
|
+
tracer,
|
|
210
|
+
...opts.provider !== void 0 ? { provider: opts.provider } : {},
|
|
211
|
+
...opts.now !== void 0 ? { now: opts.now } : {},
|
|
212
|
+
...opts.randomId !== void 0 ? { randomId: opts.randomId } : {},
|
|
213
|
+
...opts.triggers !== void 0 ? { triggers: opts.triggers } : {},
|
|
214
|
+
...opts.tier !== void 0 ? { tier: opts.tier } : {},
|
|
215
|
+
...opts.phases !== void 0 ? { phases: opts.phases } : {},
|
|
216
|
+
...opts.ceilings !== void 0 ? { ceilings: opts.ceilings } : {},
|
|
217
|
+
...opts.onExceed !== void 0 ? { onExceed: opts.onExceed } : {},
|
|
218
|
+
...opts.cheapProvider !== void 0 ? { cheapProvider: opts.cheapProvider } : {},
|
|
219
|
+
...opts.deepProvider !== void 0 ? { deepProvider: opts.deepProvider } : {},
|
|
220
|
+
...opts.cheapModel !== void 0 ? { cheapModel: opts.cheapModel } : {},
|
|
221
|
+
...opts.deepModel !== void 0 ? { deepModel: opts.deepModel } : {},
|
|
222
|
+
...opts.noiseFilters !== void 0 ? { noiseFilters: opts.noiseFilters } : {},
|
|
223
|
+
...opts.lockWaitMs !== void 0 ? { lockWaitMs: opts.lockWaitMs } : {},
|
|
224
|
+
...opts.decayTauDays !== void 0 ? { decayTauDays: opts.decayTauDays } : {},
|
|
225
|
+
...opts.decayArchiveThreshold !== void 0 ? { decayArchiveThreshold: opts.decayArchiveThreshold } : {},
|
|
226
|
+
...opts.decayCapacity !== void 0 ? { decayCapacity: opts.decayCapacity } : {},
|
|
227
|
+
...opts.salienceWeights !== void 0 ? { salienceWeights: opts.salienceWeights } : {},
|
|
228
|
+
...opts.maxStandardBatchSize !== void 0 ? { maxStandardBatchSize: opts.maxStandardBatchSize } : {},
|
|
229
|
+
...opts.maxDeepConflictsPerRun !== void 0 ? { maxDeepConflictsPerRun: opts.maxDeepConflictsPerRun } : {},
|
|
230
|
+
...opts.dlqMaxRetries !== void 0 ? { dlqMaxRetries: opts.dlqMaxRetries } : {},
|
|
231
|
+
...opts.dlqBaseBackoffMs !== void 0 ? { dlqBaseBackoffMs: opts.dlqBaseBackoffMs } : {},
|
|
232
|
+
...opts.dlqMaxBackoffMs !== void 0 ? { dlqMaxBackoffMs: opts.dlqMaxBackoffMs } : {},
|
|
233
|
+
...opts.formEpisodes !== void 0 ? { formEpisodes: opts.formEpisodes } : {},
|
|
234
|
+
...opts.importanceScoring !== void 0 ? { importanceScoring: opts.importanceScoring } : {},
|
|
235
|
+
...opts.autoPromoteExtraction !== void 0 ? { autoPromoteExtraction: opts.autoPromoteExtraction } : {},
|
|
236
|
+
...opts.reflection !== void 0 ? { reflection: opts.reflection } : {},
|
|
237
|
+
...opts.importanceThreshold !== void 0 ? { importanceThreshold: opts.importanceThreshold } : {},
|
|
238
|
+
...opts.reflectionMaxQuestions !== void 0 ? { reflectionMaxQuestions: opts.reflectionMaxQuestions } : {},
|
|
239
|
+
...opts.contextualRetrieval !== void 0 ? { contextualRetrieval: opts.contextualRetrieval } : {},
|
|
240
|
+
...opts.defaultScope !== void 0 ? { defaultScope: opts.defaultScope } : {}
|
|
241
|
+
});
|
|
242
|
+
if (opts.onPhaseFinished !== void 0) consolidator.onPhaseFinished(opts.onPhaseFinished);
|
|
243
|
+
return consolidator;
|
|
244
|
+
}
|
|
245
|
+
let consolidatorConfigIgnoredWarned = false;
|
|
246
|
+
/** @internal — test seam for the one-time disabled-config warning. */
|
|
247
|
+
function _resetConsolidatorConfigWarningForTesting() {
|
|
248
|
+
consolidatorConfigIgnoredWarned = false;
|
|
249
|
+
}
|
|
250
|
+
function shouldEnableConsolidator(opts) {
|
|
251
|
+
const keys = Object.keys(opts).filter((k) => k !== "enabled" && opts[k] !== void 0);
|
|
252
|
+
if (opts.enabled === false) {
|
|
253
|
+
if (keys.length > 0 && !consolidatorConfigIgnoredWarned) {
|
|
254
|
+
consolidatorConfigIgnoredWarned = true;
|
|
255
|
+
process.stderr.write(`[graphorin/memory] consolidator config (${keys.join(", ")}) was supplied together with enabled: false — the settings are ignored until the consolidator is enabled.\n`);
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
if (opts.enabled === true) return true;
|
|
260
|
+
return keys.length > 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
export { _resetConsolidatorConfigWarningForTesting, createMemory };
|
|
265
|
+
//# sourceMappingURL=facade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facade.js","names":["reranker: ReRanker","resolveScope: ScopeResolver","activeEmbedderId: string | null","consolidatorForSpend: Consolidator | null","consolidator: Consolidator","contextEngine: ContextEngine","out: { -readonly [K in keyof MemoryContextBlocks]: MemoryContextBlocks[K] }","blocksKept: ReadonlyArray<(typeof blocks)[number]>","rulesKept: ReadonlyArray<(typeof rules)[number]>","filterContext: Parameters<typeof partitionBySensitivity>[1]","partitionBySensitivity"],"sources":["../src/facade.ts"],"sourcesContent":["/**\n * `createMemory()` — the facade that wires every tier sub-module (the\n * seven-tier system) + the eleven (+1 gated) memory tools + the search\n * reranker + the context engine\n * stubs + the consolidator placeholder.\n *\n * @packageDocumentation\n */\n\nimport type {\n EmbedderProvider,\n MemoryMetadata,\n Provider,\n SessionScope,\n Tool,\n Tracer,\n} from '@graphorin/core';\nimport { NOOP_TRACER } from '@graphorin/core';\nimport {\n type ConflictPipeline,\n type ConflictPipelineOptions,\n createConflictPipeline,\n} from './conflict/index.js';\nimport {\n type Consolidator,\n type ConsolidatorCeilings,\n type ConsolidatorPhase,\n type ConsolidatorTier,\n type ConsolidatorTriggerSpec,\n createConsolidator,\n createConsolidatorPlaceholder,\n createProviderWorkflowInducer,\n type OnBudgetExceed,\n type PhaseListener,\n type SalienceWeights,\n} from './consolidator/index.js';\nimport { createContextEngine } from './context-engine/engine.js';\nimport type {\n CompileOptions,\n CompileScope,\n ContextEngine,\n ContextEngineConfig,\n MemoryContextBlocks,\n} from './context-engine/index.js';\nimport { enLocalePack } from './context-engine/locale-packs/index.js';\nimport { resolveLocalePack } from './context-engine/locale-packs/resolver.js';\nimport { gatherMemoryMetadata, renderMetadataBlock } from './context-engine/metadata.js';\nimport { partition as partitionBySensitivity } from './context-engine/privacy-filter.js';\nimport { composeLayer1 } from './context-engine/templates/composer.js';\nimport { type EntityResolutionConfig, EntityResolver } from './graph/entity-resolver.js';\nimport type { ContextualRetrievalMode } from './internal/contextualize.js';\nimport { bindEmbedder } from './internal/embedder-binding.js';\nimport type { EmbeddingMetaRegistryLike, MemoryStoreAdapter } from './internal/storage-adapter.js';\nimport { createProviderRetrievalGrader } from './search/iterative.js';\nimport { createProviderQueryTransformer } from './search/query-transform.js';\nimport { RRFReranker } from './search/rrf.js';\nimport type { ReRanker } from './search/types.js';\nimport { EpisodicMemory } from './tiers/episodic-memory.js';\nimport { InsightMemory } from './tiers/insight-memory.js';\nimport { ProceduralMemory } from './tiers/procedural-memory.js';\nimport { SemanticMemory } from './tiers/semantic-memory.js';\nimport { SessionMemory } from './tiers/session-memory.js';\nimport { SharedMemory } from './tiers/shared-memory.js';\nimport { type BlockDefinition, WorkingMemory } from './tiers/working-memory.js';\nimport { buildMemoryTools, type ScopeResolver } from './tools/index.js';\n\n/**\n * Options accepted by {@link createMemory}.\n *\n * @stable\n */\nexport interface CreateMemoryOptions {\n /** Storage adapter (default: `@graphorin/store-sqlite`'s `MemoryStore`). */\n readonly store: MemoryStoreAdapter;\n /** Embedder registry. The default sqlite store exposes one as `sqlite.embeddings`. */\n readonly embeddings: EmbeddingMetaRegistryLike;\n /** Embedder provider (default: none — vector search is disabled). */\n readonly embedder?: EmbedderProvider;\n /** Pre-declared working blocks (idempotent — re-defining is a no-op). */\n readonly workingBlocks?: ReadonlyArray<BlockDefinition>;\n /**\n * Tracer used for every `memory.*` span. Defaults to the no-op\n * tracer from `@graphorin/core` so unit tests do not need to wire\n * the observability stack.\n */\n readonly tracer?: Tracer;\n /** Override the reranker used by `SemanticMemory.search`. */\n readonly reranker?: ReRanker;\n /**\n * Contextual-retrieval mode for the write path (P1-3). `'late-chunk'`\n * (default) prepends a deterministic, offline situating context\n * (entities / timeframe / topics, derived from the fact's own\n * structured fields) to the text that is embedded + FTS-indexed, so a\n * terse fact stays findable; the canonical `text` is preserved. `'off'`\n * indexes the bare text. The `'llm'` enrichment is **not** available on\n * the hot path — it is a consolidator-only opt-in configured via\n * `consolidator: { contextualRetrieval: 'llm' }`.\n */\n readonly contextualRetrieval?: 'off' | 'late-chunk';\n /**\n * Query transformation for retrieval (P2-3, opt-in). When supplied,\n * `SemanticMemory.search(..., { multiQuery })` fans the query into\n * reworded variants (multi-query / RAG-Fusion) and `{ hyde }` adds a\n * hypothetical-answer embedding — both via one cheap LLM call on the\n * given provider, fused through the existing RRF reranker. Omitted (the\n * default) ⇒ search stays **offline + single-shot** and the\n * `multiQuery` / `hyde` search options become silent no-ops. Reserve it\n * for retrieval-heavy recall, not every search (it adds provider\n * latency).\n */\n readonly queryTransform?: {\n /** Cheap provider used to rewrite the query / write the HyDE passage. */\n readonly provider: Provider;\n /** Hard ceiling on reworded variants requested per call. Default 5. */\n readonly maxVariants?: number;\n /** Output-token ceiling per transform call. Default 256. */\n readonly maxTokens?: number;\n };\n /**\n * Relation-graph entity resolution (P2-1). When `entityResolution` is\n * `true` **and** the storage adapter exposes a `graph` surface (the\n * default `@graphorin/store-sqlite` does), `remember(...)` resolves a\n * fact's subject / object to canonical entities and links them, so\n * `search(..., { expandHops: 1 })` can traverse relationships. Omitted\n * (the default) ⇒ facts still carry s/p/o but form no entity links and\n * the write path stays offline + unchanged. Dedup is lexical +\n * embedding (offline, via the configured embedder); LLM adjudication of\n * ambiguous merges is a further opt-in that needs `provider`.\n */\n readonly graph?: EntityResolutionConfig & {\n /** Enable entity resolution + linking on write. Default `false`. */\n readonly entityResolution?: boolean;\n /** Provider for opt-in LLM adjudication of ambiguous merges. */\n readonly provider?: Provider;\n };\n /**\n * Agentic / iterative retrieval (P2-4, opt-in). When supplied,\n * `SemanticMemory.searchIterative(...)` and the gated `deep_recall`\n * tool can grade a retrieved set on the given provider and, for queries\n * judged hard, reformulate + retrieve again (widening to one-hop graph\n * expansion) up to `maxIterations`, abstaining instead of confabulating\n * when memory is insufficient. Omitted (the default) ⇒ `searchIterative`\n * stays a single difficulty-gated pass with **no provider call**, and\n * `deep_recall` is **not** registered (the tool surface stays at the\n * canonical eleven). Reserve it for hard multi-hop / temporal recall —\n * it adds provider latency per pass.\n */\n readonly iterativeRetrieval?: {\n /** Cheap provider used to grade retrieved memories + reformulate. */\n readonly provider: Provider;\n /** Default total-pass cap (clamped to `[1, 5]`). Default 3. */\n readonly maxIterations?: number;\n /** Output-token ceiling per grade call. Default 256. */\n readonly maxTokens?: number;\n };\n /**\n * Opt-in workflow induction (P2-2). When set, `ProceduralMemory.induce(...)`\n * distils a reusable, value-abstracted procedure from a successful agent\n * trajectory and stores it **quarantined** + `provenance: 'induction'`.\n * Omitted (the default) ⇒ `induce(...)` throws\n * {@link ProcedureInductionNotConfiguredError} and the procedural tier\n * stays pure offline CRUD — no provider call.\n */\n readonly procedureInduction?: {\n /** Provider used to abstract trajectory values into a procedure. */\n readonly provider: Provider;\n /** Output-token ceiling per induction call. Default 512. */\n readonly maxTokens?: number;\n };\n /**\n * Promotion-by-demonstrated-success for quarantined induced\n * procedures (MCON-2 part 4). Fully offline — orthogonal to\n * `procedureInduction` (no provider needed). When configured,\n * `procedural.recordOutcome(scope, id, true)` increments the rule's\n * persistent success counter and promotes it into `activate()` once\n * `afterSuccesses` verified reuses accumulate; the injection gate\n * still refuses flagged texts. Omitted ⇒ outcomes are counted but\n * nothing auto-promotes.\n */\n readonly procedurePromotion?: {\n /** Successful demonstrated reuses required before promotion (≥ 1). */\n readonly afterSuccesses: number;\n };\n /**\n * Resolver that produces the live {@link SessionScope} for each\n * memory-tool invocation. Defaults to a closure that throws — the\n * agent runtime overrides it in Phase 12.\n */\n readonly resolveScope?: ScopeResolver;\n /**\n * Consolidator configuration. When omitted, empty, or\n * `enabled: false`, the facade installs the Phase 10a no-op\n * placeholder so consumers can still type their interactions without\n * paying the runtime cost. ANY other setting — including offline\n * knobs like `decayCapacity` or `contextualRetrieval` — implicitly\n * enables the production runtime (MST-4); `enabled: false` together\n * with other settings warns once and keeps the placeholder.\n */\n readonly consolidator?: {\n readonly enabled?: boolean;\n readonly triggers?: ReadonlyArray<ConsolidatorTriggerSpec>;\n readonly tier?: ConsolidatorTier;\n readonly phases?: ReadonlyArray<ConsolidatorPhase>;\n readonly ceilings?: Partial<ConsolidatorCeilings>;\n readonly onExceed?: OnBudgetExceed;\n /** Provider routed to the standard phase when set (MCON-7); falls back to `provider`. */\n readonly cheapProvider?: Provider | null;\n /** Provider routed to the deep + reflection passes when set (MCON-7). */\n readonly deepProvider?: Provider | null;\n readonly cheapModel?: string | null;\n readonly deepModel?: string | null;\n readonly noiseFilters?: ReadonlyArray<'default' | 'minimal' | 'none'>;\n readonly lockWaitMs?: number;\n readonly decayTauDays?: number;\n readonly decayArchiveThreshold?: number;\n /** Capacity-bounded eviction target for the light phase (X-1). Default unbounded. */\n readonly decayCapacity?: number | null;\n /** Weights for the multi-signal salience score (X-1). */\n readonly salienceWeights?: SalienceWeights;\n readonly maxStandardBatchSize?: number;\n readonly maxDeepConflictsPerRun?: number;\n readonly dlqMaxRetries?: number;\n readonly dlqBaseBackoffMs?: number;\n readonly dlqMaxBackoffMs?: number;\n /** Auto-form quarantined episodes from processed slices (P1-2). Per-tier default. */\n readonly formEpisodes?: boolean;\n /** Score episode importance via the consolidator LLM (P1-2). Per-tier default. */\n readonly importanceScoring?: boolean;\n /** Opt in to auto-promotion of injection-clean extraction facts (MCON-2). Default off. */\n readonly autoPromoteExtraction?: boolean;\n /** Run the deep-phase reflection pass synthesizing cited insights (P1-1). Per-tier default. */\n readonly reflection?: boolean;\n /** Accumulated-importance threshold at which reflection fires (P1-1). */\n readonly importanceThreshold?: number;\n /** Upper bound on salient questions reflection asks per pass (P1-1). */\n readonly reflectionMaxQuestions?: number;\n /**\n * Contextual retrieval for standard-phase fact writes (P1-3).\n * `'llm'` opts into one budgeted cheap-model call per write to author\n * a situating prefix (consolidator-only); `'late-chunk'` (default)\n * and `'off'` defer to the write-path mode. Per-tier default.\n */\n readonly contextualRetrieval?: ContextualRetrievalMode;\n readonly defaultScope?: SessionScope;\n readonly provider?: Provider | null;\n /** Override the wall clock — used by tests. */\n readonly now?: () => number;\n /** Stable id seed — used by tests. */\n readonly randomId?: () => string;\n /** Subscribe to phase-finished events. */\n readonly onPhaseFinished?: PhaseListener;\n };\n /**\n * Conflict pipeline configuration (Phase 10b). Default: enabled,\n * English locale pack, thresholds `0.95 / 0.85 / 0.4`. Pass\n * `{ mode: 'off' }` to bypass the pipeline entirely (logs a one-shot\n * WARN per process per the spec).\n */\n readonly conflictPipeline?: ConflictPipelineOptions;\n /**\n * Context engine configuration (Phase 10d). The engine assembles\n * the layered six-layer system prompt; `memory.compile(scope)`\n * delegates to it for the working blocks + rules + metadata\n * fragments. When omitted, a default engine is created (English\n * locale; `'full'` base mode; no auto-recall; conservative\n * `'public-tls'` provider trust).\n */\n readonly contextEngine?: ContextEngineConfig;\n}\n\n/**\n * The facade returned by {@link createMemory}.\n *\n * @stable\n */\nexport interface Memory {\n readonly working: WorkingMemory;\n readonly session: SessionMemory;\n readonly episodic: EpisodicMemory;\n readonly semantic: SemanticMemory;\n readonly procedural: ProceduralMemory;\n readonly shared: SharedMemory;\n /**\n * Read surface over reflection insights (P1-1). A no-op (returns\n * empty) when the storage adapter does not expose the optional\n * insight surface.\n */\n readonly insights: InsightMemory;\n readonly tools: ReadonlyArray<Tool>;\n readonly consolidator: Consolidator;\n /** The configured conflict pipeline. Surfaced for tests + CLI tooling. */\n readonly conflictPipeline: ConflictPipeline;\n /** The configured context engine (Phase 10d). */\n readonly contextEngine: ContextEngine;\n /** The active embedder, when configured. `null` otherwise. */\n readonly embedder: EmbedderProvider | null;\n /** The canonical id of the active embedder, when configured. */\n embedderId(): string | null;\n /**\n * Compile a system-prompt block bundle. The bundle carries the\n * static fragments per memory tier; the agent runtime consumes\n * the {@link ContextEngine} surface (`memory.contextEngine`)\n * directly for the full six-layer assembly.\n */\n compile(scope: CompileScope, options?: CompileOptions): Promise<MemoryContextBlocks>;\n /** Counter snapshot consumed by Phase 10d's metadata layer. */\n metadata(scope: SessionScope): Promise<MemoryMetadata>;\n}\n\n/**\n * Wire every memory subsystem in one call. Returns the typed\n * `Memory` facade ready to be passed into `createAgent({...})`.\n *\n * @stable\n */\nexport function createMemory(options: CreateMemoryOptions): Memory {\n const tracer = options.tracer ?? NOOP_TRACER;\n const reranker: ReRanker = options.reranker ?? new RRFReranker();\n const resolveScope: ScopeResolver =\n options.resolveScope ??\n (() => {\n throw new TypeError(\n '[graphorin/memory] memory tool invoked without a scope resolver. ' +\n 'Pass `resolveScope` to createMemory({...}) — the agent runtime supplies one in Phase 12.',\n );\n });\n\n let activeEmbedderId: string | null = null;\n if (options.embedder !== undefined) {\n activeEmbedderId = bindEmbedder(options.embedder, options.embeddings);\n }\n const embedder = options.embedder ?? null;\n const embedderIdProvider = (): string | null => activeEmbedderId;\n\n const working = new WorkingMemory({ store: options.store, tracer });\n for (const block of options.workingBlocks ?? []) {\n working.define(block);\n }\n const session = new SessionMemory({ store: options.store, tracer });\n const episodic = new EpisodicMemory({\n store: options.store,\n tracer,\n embedder,\n embedderIdProvider,\n });\n const conflictPipeline = createConflictPipeline(options.conflictPipeline ?? {});\n // P2-3: build the (opt-in) query transformer from the supplied provider.\n // Absent ⇒ `null` ⇒ search stays offline + single-shot.\n const queryTransformer =\n options.queryTransform !== undefined\n ? createProviderQueryTransformer(options.queryTransform.provider, {\n ...(options.queryTransform.maxVariants !== undefined\n ? { maxVariants: options.queryTransform.maxVariants }\n : {}),\n ...(options.queryTransform.maxTokens !== undefined\n ? { maxTokens: options.queryTransform.maxTokens }\n : {}),\n })\n : null;\n // P2-1: build the (opt-in) entity resolver. Requires `graph.entityResolution`\n // *and* a graph-capable adapter; absent ⇒ `null` ⇒ writes carry s/p/o but\n // form no entity links and the write path stays offline + unchanged.\n const graphStore = options.store.graph;\n const entityResolver =\n options.graph?.entityResolution === true && graphStore !== undefined\n ? new EntityResolver({\n store: graphStore,\n embedder,\n embedderId: embedderIdProvider,\n ...(options.graph.provider !== undefined ? { provider: options.graph.provider } : {}),\n config: {\n ...(options.graph.mergeThreshold !== undefined\n ? { mergeThreshold: options.graph.mergeThreshold }\n : {}),\n ...(options.graph.adjudicateThreshold !== undefined\n ? { adjudicateThreshold: options.graph.adjudicateThreshold }\n : {}),\n ...(options.graph.llmAdjudication !== undefined\n ? { llmAdjudication: options.graph.llmAdjudication }\n : {}),\n },\n })\n : null;\n // P2-4: build the (opt-in) retrieval grader. Absent ⇒ `null` ⇒\n // `searchIterative` runs a single difficulty-gated pass (no provider\n // call) and the `deep_recall` tool is not registered.\n const grader =\n options.iterativeRetrieval !== undefined\n ? createProviderRetrievalGrader(options.iterativeRetrieval.provider, {\n ...(options.iterativeRetrieval.maxTokens !== undefined\n ? { maxTokens: options.iterativeRetrieval.maxTokens }\n : {}),\n })\n : null;\n const semantic = new SemanticMemory({\n store: options.store,\n tracer,\n embedder,\n embedderIdProvider,\n reranker,\n conflictPipeline,\n ...(options.contextualRetrieval !== undefined\n ? { contextualRetrieval: options.contextualRetrieval }\n : {}),\n ...(queryTransformer !== null ? { queryTransformer } : {}),\n ...(entityResolver !== null ? { entityResolver } : {}),\n ...(grader !== null ? { grader } : {}),\n ...(options.iterativeRetrieval?.maxIterations !== undefined\n ? { iterativeMaxIterations: options.iterativeRetrieval.maxIterations }\n : {}),\n });\n // P2-2: build the (opt-in) workflow inducer. Absent ⇒ `null` ⇒\n // `ProceduralMemory.induce(...)` throws and the tier stays offline CRUD.\n // MCON-15: induction spend is recorded into the consolidator budget —\n // the consolidator is constructed AFTER the inducer, so the callback\n // routes through a slot filled below (placeholder ⇒ no-op).\n let consolidatorForSpend: Consolidator | null = null;\n const inducer =\n options.procedureInduction !== undefined\n ? createProviderWorkflowInducer(options.procedureInduction.provider, {\n ...(options.procedureInduction.maxTokens !== undefined\n ? { maxTokens: options.procedureInduction.maxTokens }\n : {}),\n onUsage: (usage) => {\n consolidatorForSpend?.recordExternalSpend(usage.promptTokens + usage.completionTokens);\n },\n })\n : null;\n const procedural = new ProceduralMemory({\n store: options.store,\n tracer,\n ...(inducer !== null ? { inducer } : {}),\n // MCON-2 part 4: opt-in promotion-by-demonstrated-success.\n ...(options.procedurePromotion?.afterSuccesses !== undefined\n ? { promoteAfterSuccesses: options.procedurePromotion.afterSuccesses }\n : {}),\n });\n const shared = new SharedMemory({ store: options.store, tracer });\n const insights = new InsightMemory({ store: options.store, tracer });\n\n const tools = buildMemoryTools(\n {\n working,\n session,\n episodic,\n semantic,\n procedural,\n shared,\n resolveScope,\n },\n // P2-4: the gated `deep_recall` tool is registered only when a grader\n // is configured — the offline default stays at exactly eleven tools.\n { includeDeepRecall: grader !== null },\n );\n\n const consolidatorOpts = options.consolidator;\n const consolidator: Consolidator = buildConsolidator(\n consolidatorOpts,\n options.store,\n semantic,\n episodic,\n tracer,\n );\n consolidatorForSpend = consolidator;\n const contextEngineConfig = options.contextEngine ?? {};\n const contextEngine: ContextEngine = createContextEngine(contextEngineConfig);\n const resolved = contextEngine.config();\n const localePack =\n contextEngineConfig.locale === undefined\n ? enLocalePack\n : typeof contextEngineConfig.locale === 'string'\n ? contextEngineConfig.locale === enLocalePack.id\n ? enLocalePack\n : resolveLocalePack({ id: contextEngineConfig.locale })\n : resolveLocalePack(contextEngineConfig.locale);\n\n // The facade's `compile(...)` is the static-fragment surface\n // consumed by callers that do not know the active provider yet\n // (the agent runtime calls `memory.contextEngine.assemble(...)`\n // with full provider context when `autoAssembleContext` is\n // enabled). The privacy filter only fires\n // when the caller explicitly passes `providerAcceptsSensitivity`\n // OR the operator opted into the engine's `privacy` block.\n const privacyOptedIn =\n contextEngineConfig.privacy !== undefined &&\n (contextEngineConfig.privacy.providerAcceptsSensitivity !== undefined ||\n contextEngineConfig.privacy.cloudUploadConsent !== undefined ||\n contextEngineConfig.privacy.providerTrust !== undefined);\n\n async function compile(\n scope: CompileScope,\n compileOptions: CompileOptions = {},\n ): Promise<MemoryContextBlocks> {\n const out: { -readonly [K in keyof MemoryContextBlocks]: MemoryContextBlocks[K] } = {};\n const blocks = await options.store.working.list(scope);\n // Quarantined (e.g. P2-2-induced) procedures are provisional and must not\n // reach the system prompt — `activate()` already excludes them, and\n // compile() (public `@stable`) must agree or a compile()-based prompt\n // builder ingests unvalidated induction procedures (MST-3).\n const rules = (await options.store.procedural.list(scope)).filter(\n (rule) => rule.status !== 'quarantined',\n );\n const shouldFilter = privacyOptedIn || compileOptions.providerAcceptsSensitivity !== undefined;\n let blocksKept: ReadonlyArray<(typeof blocks)[number]> = blocks;\n let rulesKept: ReadonlyArray<(typeof rules)[number]> = rules;\n if (shouldFilter) {\n const filterContext: Parameters<typeof partitionBySensitivity>[1] = {\n providerTrust: resolved.providerTrust,\n cloudUploadConsent: resolved.cloudUploadConsent,\n defaultSensitivity: resolved.defaultSensitivity,\n };\n if (compileOptions.providerAcceptsSensitivity !== undefined) {\n (\n filterContext as {\n providerAcceptsSensitivity?: ReadonlyArray<'public' | 'internal' | 'secret'>;\n }\n ).providerAcceptsSensitivity = compileOptions.providerAcceptsSensitivity;\n }\n blocksKept = partitionBySensitivity(blocks, filterContext).kept;\n rulesKept = partitionBySensitivity(rules, filterContext).kept;\n }\n const blocksXml = renderWorkingBlocksXml(blocksKept);\n if (blocksXml.length > 0) {\n out.workingBlocks = blocksXml;\n }\n if (rulesKept.length > 0) {\n const lines = ['<memory_rules>'];\n for (const rule of rulesKept) {\n lines.push(` <rule priority=\"${rule.priority}\">${escapeXml(rule.text)}</rule>`);\n }\n lines.push('</memory_rules>');\n out.rules = lines.join('\\n');\n }\n if (compileOptions.includeMetadata !== false) {\n const meta = await metadata(scope);\n out.metadata = renderMetadataBlock(meta);\n }\n out.base = composeLayer1(localePack, resolved.memoryBaseMode);\n return Object.freeze(out);\n }\n\n async function metadata(scope: SessionScope): Promise<MemoryMetadata> {\n return gatherMemoryMetadata(scope, {\n store: options.store,\n consolidator,\n embedderId: embedderIdProvider,\n localeId: resolved.localeId,\n });\n }\n\n return Object.freeze({\n working,\n session,\n episodic,\n semantic,\n procedural,\n shared,\n insights,\n tools,\n consolidator,\n conflictPipeline,\n contextEngine,\n embedder,\n embedderId: embedderIdProvider,\n compile,\n metadata,\n });\n}\n\nfunction renderWorkingBlocksXml(\n blocks: ReadonlyArray<{\n readonly label: string;\n readonly value: string;\n readonly description?: string;\n }>,\n): string {\n if (blocks.length === 0) return '';\n const lines = ['<memory_blocks>'];\n for (const block of blocks) {\n const description =\n block.description !== undefined ? ` description=\"${escapeXml(block.description)}\"` : '';\n lines.push(` <block label=\"${escapeXml(block.label)}\"${description}>`);\n lines.push(` ${escapeXml(block.value)}`);\n lines.push(' </block>');\n }\n lines.push('</memory_blocks>');\n return lines.join('\\n');\n}\n\nfunction escapeXml(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n}\n\nfunction buildConsolidator(\n opts: CreateMemoryOptions['consolidator'],\n store: CreateMemoryOptions['store'],\n semantic: SemanticMemory,\n episodic: EpisodicMemory,\n tracer: Tracer,\n): Consolidator {\n if (opts === undefined) {\n return createConsolidatorPlaceholder();\n }\n const enabled = shouldEnableConsolidator(opts);\n if (!enabled) {\n return createConsolidatorPlaceholder({\n ...(opts.triggers !== undefined ? { triggers: opts.triggers } : {}),\n ...(opts.tier !== undefined ? { tier: opts.tier } : {}),\n });\n }\n const consolidator = createConsolidator({\n store,\n semantic,\n episodic,\n tracer,\n ...(opts.provider !== undefined ? { provider: opts.provider } : {}),\n ...(opts.now !== undefined ? { now: opts.now } : {}),\n ...(opts.randomId !== undefined ? { randomId: opts.randomId } : {}),\n ...(opts.triggers !== undefined ? { triggers: opts.triggers } : {}),\n ...(opts.tier !== undefined ? { tier: opts.tier } : {}),\n ...(opts.phases !== undefined ? { phases: opts.phases } : {}),\n ...(opts.ceilings !== undefined ? { ceilings: opts.ceilings } : {}),\n ...(opts.onExceed !== undefined ? { onExceed: opts.onExceed } : {}),\n ...(opts.cheapProvider !== undefined ? { cheapProvider: opts.cheapProvider } : {}),\n ...(opts.deepProvider !== undefined ? { deepProvider: opts.deepProvider } : {}),\n ...(opts.cheapModel !== undefined ? { cheapModel: opts.cheapModel } : {}),\n ...(opts.deepModel !== undefined ? { deepModel: opts.deepModel } : {}),\n ...(opts.noiseFilters !== undefined ? { noiseFilters: opts.noiseFilters } : {}),\n ...(opts.lockWaitMs !== undefined ? { lockWaitMs: opts.lockWaitMs } : {}),\n ...(opts.decayTauDays !== undefined ? { decayTauDays: opts.decayTauDays } : {}),\n ...(opts.decayArchiveThreshold !== undefined\n ? { decayArchiveThreshold: opts.decayArchiveThreshold }\n : {}),\n ...(opts.decayCapacity !== undefined ? { decayCapacity: opts.decayCapacity } : {}),\n ...(opts.salienceWeights !== undefined ? { salienceWeights: opts.salienceWeights } : {}),\n ...(opts.maxStandardBatchSize !== undefined\n ? { maxStandardBatchSize: opts.maxStandardBatchSize }\n : {}),\n ...(opts.maxDeepConflictsPerRun !== undefined\n ? { maxDeepConflictsPerRun: opts.maxDeepConflictsPerRun }\n : {}),\n ...(opts.dlqMaxRetries !== undefined ? { dlqMaxRetries: opts.dlqMaxRetries } : {}),\n ...(opts.dlqBaseBackoffMs !== undefined ? { dlqBaseBackoffMs: opts.dlqBaseBackoffMs } : {}),\n ...(opts.dlqMaxBackoffMs !== undefined ? { dlqMaxBackoffMs: opts.dlqMaxBackoffMs } : {}),\n ...(opts.formEpisodes !== undefined ? { formEpisodes: opts.formEpisodes } : {}),\n ...(opts.importanceScoring !== undefined ? { importanceScoring: opts.importanceScoring } : {}),\n ...(opts.autoPromoteExtraction !== undefined\n ? { autoPromoteExtraction: opts.autoPromoteExtraction }\n : {}),\n ...(opts.reflection !== undefined ? { reflection: opts.reflection } : {}),\n ...(opts.importanceThreshold !== undefined\n ? { importanceThreshold: opts.importanceThreshold }\n : {}),\n ...(opts.reflectionMaxQuestions !== undefined\n ? { reflectionMaxQuestions: opts.reflectionMaxQuestions }\n : {}),\n ...(opts.contextualRetrieval !== undefined\n ? { contextualRetrieval: opts.contextualRetrieval }\n : {}),\n ...(opts.defaultScope !== undefined ? { defaultScope: opts.defaultScope } : {}),\n });\n if (opts.onPhaseFinished !== undefined) {\n consolidator.onPhaseFinished(opts.onPhaseFinished);\n }\n return consolidator;\n}\n\nlet consolidatorConfigIgnoredWarned = false;\n\n/** @internal — test seam for the one-time disabled-config warning. */\nexport function _resetConsolidatorConfigWarningForTesting(): void {\n consolidatorConfigIgnoredWarned = false;\n}\n\nfunction shouldEnableConsolidator(opts: NonNullable<CreateMemoryOptions['consolidator']>): boolean {\n // MST-4: ANY non-empty consolidator config implicitly enables — the old\n // allow-list silently ignored offline knobs (`decayCapacity`,\n // `formEpisodes`, `reflection`, `contextualRetrieval`, …): the caller\n // got a no-op placeholder while believing the feature was on.\n const keys = Object.keys(opts).filter(\n (k) => k !== 'enabled' && (opts as Record<string, unknown>)[k] !== undefined,\n );\n if (opts.enabled === false) {\n if (keys.length > 0 && !consolidatorConfigIgnoredWarned) {\n consolidatorConfigIgnoredWarned = true;\n process.stderr.write(\n `[graphorin/memory] consolidator config (${keys.join(', ')}) was supplied together with enabled: false — the settings are ignored until the consolidator is enabled.\\n`,\n );\n }\n return false;\n }\n if (opts.enabled === true) return true;\n return keys.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2TA,SAAgB,aAAa,SAAsC;CACjE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAMA,WAAqB,QAAQ,YAAY,IAAI,aAAa;CAChE,MAAMC,eACJ,QAAQ,uBACD;A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