@jungjaehoon/mama-core 2.4.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -239
- package/db/migrations/030-case-first-memory-substrate.sql +13 -98
- package/db/migrations/034-add-connector-event-scope-columns.sql +9 -13
- package/db/migrations/039-add-connector-event-operator-ingest-seq.sql +9 -95
- package/db/migrations/062-refresh-connector-event-sequences.sql +9 -113
- package/db/migrations/063-refresh-legacy-connector-event-updates.sql +9 -32
- package/db/migrations/067-add-connector-event-source-entity-id.sql +9 -13
- package/db/migrations/069-create-registry-nodes.sql +52 -0
- package/db/migrations/070-record-identity.sql +35 -0
- package/db/migrations/071-service-operation-origins.sql +187 -0
- package/db/migrations/072-observation-versions.sql +29 -0
- package/db/migrations/073-registry-corrections.sql +45 -0
- package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
- package/db/migrations/075-agent-judgments.sql +58 -0
- package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
- package/db/migrations/077-legacy-record-kind.sql +6 -0
- package/db/migrations/078-source-ingest-commands.sql +18 -0
- package/db/migrations/079-twin-edge-relations.sql +43 -0
- package/db/migrations/080-restore-duration-days.sql +7 -0
- package/db/migrations/081-mailbox.sql +61 -0
- package/db/migrations/082-commitments-row-id.sql +12 -0
- package/db/migrations/083-observation-is-the-evidence.sql +49 -0
- package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
- package/db/migrations/085-a-migration-has-a-source.sql +37 -0
- package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
- package/db/migrations/087-mailbox-payload.sql +5 -0
- package/db/migrations/088-native-input-journal.sql +14 -0
- package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
- package/db/migrations/090-model-run-native-inputs.sql +29 -0
- package/db/migrations/091-native-turn-results.sql +11 -0
- package/db/migrations/092-restore-decision-fts.sql +34 -0
- package/db/migrations/093-native-turn-primary-kind.sql +14 -0
- package/db/migrations/094-commitment-run-provenance.sql +9 -0
- package/db/migrations/095-model-run-native-input-identity.sql +39 -0
- package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
- package/db/migrations/097-native-input-json-validity.sql +37 -0
- package/db/migrations/098-workflow-memory-kind.sql +105 -0
- package/db/migrations/099-commitment-revision-graph.sql +2 -0
- package/dist/action-contracts.d.ts +212 -0
- package/dist/action-contracts.js +10 -0
- package/dist/api/catalog.d.ts +118 -0
- package/dist/api/catalog.js +1756 -0
- package/dist/api/dispatch.d.ts +76 -0
- package/dist/api/dispatch.js +372 -0
- package/dist/canonicalize.d.ts +2 -2
- package/dist/canonicalize.js +3 -3
- package/dist/client/client.d.ts +33 -0
- package/dist/client/client.js +123 -0
- package/dist/client/ipc.d.ts +81 -0
- package/dist/client/ipc.js +314 -0
- package/dist/db-adapter/base-adapter.d.ts +6 -66
- package/dist/db-adapter/base-adapter.js +6 -6
- package/dist/db-adapter/index.d.ts +5 -5
- package/dist/db-adapter/index.js +2 -5
- package/dist/db-adapter/node-sqlite-adapter.d.ts +85 -15
- package/dist/db-adapter/node-sqlite-adapter.js +1985 -570
- package/dist/db-manager.d.ts +53 -97
- package/dist/db-manager.js +121 -603
- package/dist/embedding/embedder.d.ts +132 -0
- package/dist/embedding/embedder.js +299 -0
- package/dist/identity/principal-repository.d.ts +2 -2
- package/dist/index.d.ts +43 -58
- package/dist/index.js +97 -145
- package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
- package/dist/knowledge/access.js +663 -0
- package/dist/knowledge/case-errors.d.ts +31 -0
- package/dist/knowledge/case-errors.js +40 -0
- package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
- package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
- package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
- package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
- package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
- package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
- package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
- package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
- package/dist/knowledge/commitment-revision-migration.d.ts +4 -0
- package/dist/knowledge/commitment-revision-migration.js +50 -0
- package/dist/knowledge/commitments.d.ts +192 -0
- package/dist/knowledge/commitments.js +386 -0
- package/dist/knowledge/decision-edges.d.ts +70 -0
- package/dist/knowledge/decision-edges.js +123 -0
- package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
- package/dist/knowledge/graph-query.js +1585 -0
- package/dist/knowledge/identity.d.ts +16 -0
- package/dist/knowledge/identity.js +22 -0
- package/dist/knowledge/index.d.ts +47 -0
- package/dist/knowledge/index.js +90 -0
- package/dist/knowledge/judgment-edge.d.ts +6 -0
- package/dist/knowledge/judgment-edge.js +22 -0
- package/dist/knowledge/judgments.d.ts +118 -0
- package/dist/knowledge/judgments.js +802 -0
- package/dist/knowledge/observations.d.ts +160 -0
- package/dist/knowledge/observations.js +449 -0
- package/dist/knowledge/question-type.d.ts +34 -0
- package/dist/knowledge/question-type.js +70 -0
- package/dist/{search → knowledge}/ranker-features.js +1 -1
- package/dist/{search → knowledge}/search-quality.d.ts +0 -1
- package/dist/knowledge/search.d.ts +38 -0
- package/dist/knowledge/search.js +91 -0
- package/dist/knowledge/source-ingest.d.ts +65 -0
- package/dist/knowledge/source-ingest.js +174 -0
- package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
- package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
- package/dist/knowledge/work-dates.d.ts +49 -0
- package/dist/knowledge/work-dates.js +120 -0
- package/dist/mama-api.d.ts +114 -778
- package/dist/mama-api.js +313 -2461
- package/dist/memory/api.d.ts +264 -24
- package/dist/memory/api.js +1633 -843
- package/dist/memory/bootstrap-builder.d.ts +2 -1
- package/dist/memory/bootstrap-builder.js +5 -5
- package/dist/memory/channel-summary-state-store.d.ts +3 -2
- package/dist/memory/channel-summary-state-store.js +53 -51
- package/dist/memory/channel-summary-store.d.ts +5 -3
- package/dist/memory/channel-summary-store.js +3 -8
- package/dist/memory/dashboard-read.d.ts +46 -0
- package/dist/memory/dashboard-read.js +94 -0
- package/dist/memory/event-store.d.ts +3 -3
- package/dist/memory/event-store.js +3 -10
- package/dist/memory/finding-store.d.ts +3 -2
- package/dist/memory/finding-store.js +2 -7
- package/dist/memory/graph-read.d.ts +52 -0
- package/dist/memory/graph-read.js +130 -0
- package/dist/memory/judgment-types.d.ts +394 -0
- package/dist/memory/judgment-types.js +16 -0
- package/dist/memory/provenance-audit.d.ts +5 -2
- package/dist/memory/provenance-audit.js +8 -14
- package/dist/memory/provenance-live.d.ts +141 -0
- package/dist/memory/provenance-live.js +409 -0
- package/dist/memory/provenance-query.d.ts +5 -4
- package/dist/memory/provenance-query.js +21 -29
- package/dist/memory/provenance-resolver.d.ts +191 -0
- package/dist/memory/provenance-resolver.js +155 -0
- package/dist/memory/provenance.d.ts +1 -11
- package/dist/memory/provenance.js +2 -33
- package/dist/memory/recall-sanitize.d.ts +55 -0
- package/dist/memory/recall-sanitize.js +144 -0
- package/dist/memory/secret-filter.d.ts +32 -0
- package/dist/memory/secret-filter.js +126 -0
- package/dist/memory/truth-store.d.ts +2 -1
- package/dist/memory/truth-store.js +1 -4
- package/dist/memory/types.d.ts +74 -24
- package/dist/memory/types.js +75 -5
- package/dist/memory/write-adapters.d.ts +98 -0
- package/dist/memory/write-adapters.js +242 -0
- package/dist/operations/owner-action-effects.d.ts +53 -0
- package/dist/operations/owner-action-effects.js +96 -0
- package/dist/provenance/source-ref.d.ts +1 -1
- package/dist/provenance/source-ref.js +0 -2
- package/dist/registry/corrections.d.ts +31 -0
- package/dist/registry/corrections.js +332 -0
- package/dist/registry/record-identity.d.ts +49 -0
- package/dist/registry/record-identity.js +133 -0
- package/dist/registry/store.d.ts +101 -0
- package/dist/registry/store.js +395 -0
- package/dist/registry/types.d.ts +28 -0
- package/dist/registry/types.js +5 -0
- package/dist/relevance-scorer.js +2 -2
- package/dist/runtime/agent-event-bus.d.ts +50 -0
- package/dist/runtime/agent-event-bus.js +101 -0
- package/dist/runtime/drivers/claude-cli-wrapper.d.ts +152 -0
- package/dist/runtime/drivers/claude-cli-wrapper.js +375 -0
- package/dist/runtime/drivers/claude-effort.d.ts +4 -0
- package/dist/runtime/drivers/claude-effort.js +16 -0
- package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
- package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
- package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
- package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
- package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
- package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
- package/dist/runtime/drivers/codex-home.d.ts +20 -0
- package/dist/runtime/drivers/codex-home.js +674 -0
- package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
- package/dist/runtime/drivers/codex-thread-registry.js +433 -0
- package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
- package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
- package/dist/runtime/drivers/persistent-cli-process.d.ts +425 -0
- package/dist/runtime/drivers/persistent-cli-process.js +1529 -0
- package/dist/runtime/drivers/types.d.ts +456 -0
- package/dist/runtime/drivers/types.js +110 -0
- package/dist/runtime/mailbox.d.ts +223 -0
- package/dist/runtime/mailbox.js +582 -0
- package/dist/runtime/model-run-store.d.ts +28 -0
- package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
- package/dist/{model-runs/types.d.ts → runtime/model-run-types.d.ts} +33 -4
- package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
- package/dist/runtime/native-effect-observer.d.ts +22 -0
- package/dist/runtime/native-effect-observer.js +103 -0
- package/dist/runtime/native-input-journal.d.ts +46 -0
- package/dist/runtime/native-input-journal.js +308 -0
- package/dist/runtime/native-prompt.d.ts +118 -0
- package/dist/runtime/native-prompt.js +496 -0
- package/dist/runtime/native-session.d.ts +10 -0
- package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
- package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
- package/dist/runtime/native-tool-trace-observer.js +65 -0
- package/dist/runtime/native-turn.d.ts +272 -0
- package/dist/runtime/native-turn.js +1041 -0
- package/dist/runtime/operations.d.ts +236 -0
- package/dist/runtime/operations.js +565 -0
- package/dist/runtime/post-tool-handler.d.ts +74 -0
- package/dist/runtime/post-tool-handler.js +137 -0
- package/dist/runtime/prompt-layers.d.ts +126 -0
- package/dist/runtime/prompt-layers.js +239 -0
- package/dist/runtime/runtime-process.d.ts +102 -0
- package/dist/runtime/runtime-process.js +206 -0
- package/dist/runtime/runtime.d.ts +278 -0
- package/dist/runtime/runtime.js +563 -0
- package/dist/runtime/session-pool.d.ts +176 -0
- package/dist/runtime/session-pool.js +369 -0
- package/dist/runtime/stimulus-payload.d.ts +5 -0
- package/dist/runtime/stimulus-payload.js +50 -0
- package/dist/runtime/subagent-bridge.d.ts +24 -0
- package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
- package/dist/runtime/text-completion.d.ts +22 -0
- package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
- package/dist/runtime/token-estimator.d.ts +25 -0
- package/dist/runtime/token-estimator.js +75 -0
- package/dist/runtime/tool-trace-store.d.ts +22 -0
- package/dist/{model-runs → runtime}/tool-trace-store.js +46 -27
- package/dist/runtime/trace-summary.d.ts +5 -0
- package/dist/runtime/trace-summary.js +74 -0
- package/dist/runtime/turn-text.d.ts +23 -0
- package/dist/runtime/turn-text.js +41 -0
- package/dist/storage/database.d.ts +67 -0
- package/dist/storage/database.js +158 -0
- package/package.json +20 -34
- package/dist/agent-graph/alias-write.d.ts +0 -3
- package/dist/agent-graph/alias-write.js +0 -234
- package/dist/agent-graph/entity-resolve.d.ts +0 -3
- package/dist/agent-graph/entity-resolve.js +0 -271
- package/dist/agent-graph/errors.d.ts +0 -4
- package/dist/agent-graph/errors.js +0 -11
- package/dist/agent-graph/graph-query.d.ts +0 -5
- package/dist/agent-graph/graph-query.js +0 -360
- package/dist/agent-graph/index.d.ts +0 -6
- package/dist/agent-situation/builder.d.ts +0 -8
- package/dist/agent-situation/builder.js +0 -239
- package/dist/agent-situation/cache-key.d.ts +0 -4
- package/dist/agent-situation/cache-key.js +0 -64
- package/dist/agent-situation/index.d.ts +0 -7
- package/dist/agent-situation/index.js +0 -28
- package/dist/agent-situation/packet-store.d.ts +0 -27
- package/dist/agent-situation/packet-store.js +0 -228
- package/dist/agent-situation/ranking-policy.d.ts +0 -18
- package/dist/agent-situation/ranking-policy.js +0 -75
- package/dist/agent-situation/source-readers.d.ts +0 -52
- package/dist/agent-situation/source-readers.js +0 -300
- package/dist/agent-situation/types.d.ts +0 -195
- package/dist/cases/wiki-page-index.d.ts +0 -37
- package/dist/cases/wiki-page-index.js +0 -201
- package/dist/config-loader.d.ts +0 -68
- package/dist/config-loader.js +0 -239
- package/dist/connectors/event-index.d.ts +0 -24
- package/dist/connectors/event-index.js +0 -245
- package/dist/connectors/raw-query.d.ts +0 -40
- package/dist/connectors/raw-query.js +0 -412
- package/dist/connectors/types.d.ts +0 -117
- package/dist/connectors/types.js +0 -3
- package/dist/context-compile/boundary-defaults.d.ts +0 -12
- package/dist/context-compile/boundary-defaults.js +0 -105
- package/dist/context-compile/channel-grant.js +0 -66
- package/dist/context-compile/compiler-policy.d.ts +0 -39
- package/dist/context-compile/compiler-policy.js +0 -147
- package/dist/context-compile/compiler.d.ts +0 -18
- package/dist/context-compile/compiler.js +0 -404
- package/dist/context-compile/index.d.ts +0 -10
- package/dist/context-compile/index.js +0 -26
- package/dist/context-compile/packet-store.d.ts +0 -8
- package/dist/context-compile/packet-store.js +0 -239
- package/dist/context-compile/ref.d.ts +0 -7
- package/dist/context-compile/ref.js +0 -102
- package/dist/context-compile/source-readers.d.ts +0 -70
- package/dist/context-compile/source-readers.js +0 -840
- package/dist/context-compile/types.d.ts +0 -155
- package/dist/context-compile/types.js +0 -11
- package/dist/context-compile/visibility.d.ts +0 -21
- package/dist/context-compile/visibility.js +0 -224
- package/dist/decision-tracker.d.ts +0 -206
- package/dist/decision-tracker.js +0 -481
- package/dist/edges/ref-validation.d.ts +0 -7
- package/dist/edges/ref-validation.js +0 -321
- package/dist/edges/store.d.ts +0 -8
- package/dist/edges/store.js +0 -129
- package/dist/embedding-client.d.ts +0 -28
- package/dist/embedding-client.js +0 -53
- package/dist/embedding-server/index.d.ts +0 -67
- package/dist/embedding-server/index.js +0 -405
- package/dist/embedding-server/mobile/auth.d.ts +0 -44
- package/dist/embedding-server/mobile/auth.js +0 -150
- package/dist/embedding-server/mobile/daemon.d.ts +0 -129
- package/dist/embedding-server/mobile/daemon.js +0 -313
- package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
- package/dist/embedding-server/mobile/output-parser.js +0 -241
- package/dist/embedding-server/mobile/session-api.d.ts +0 -57
- package/dist/embedding-server/mobile/session-api.js +0 -261
- package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
- package/dist/embedding-server/mobile/session-manager.js +0 -378
- package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
- package/dist/embedding-server/mobile/websocket-handler.js +0 -486
- package/dist/embeddings.d.ts +0 -68
- package/dist/embeddings.js +0 -244
- package/dist/entities/audit-metrics.d.ts +0 -68
- package/dist/entities/audit-metrics.js +0 -124
- package/dist/entities/candidate-generator.d.ts +0 -8
- package/dist/entities/candidate-generator.js +0 -24
- package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
- package/dist/entities/entity-linked-decision-counts.js +0 -29
- package/dist/entities/entity-list.d.ts +0 -22
- package/dist/entities/entity-list.js +0 -3
- package/dist/entities/entity-orphan-list.d.ts +0 -17
- package/dist/entities/entity-orphan-list.js +0 -3
- package/dist/entities/entity-search.d.ts +0 -20
- package/dist/entities/entity-search.js +0 -3
- package/dist/entities/errors.d.ts +0 -55
- package/dist/entities/errors.js +0 -100
- package/dist/entities/lineage-store.d.ts +0 -28
- package/dist/entities/lineage-store.js +0 -204
- package/dist/entities/normalization.d.ts +0 -14
- package/dist/entities/normalization.js +0 -63
- package/dist/entities/policy-store.d.ts +0 -8
- package/dist/entities/policy-store.js +0 -75
- package/dist/entities/policy-types.d.ts +0 -72
- package/dist/entities/policy-types.js +0 -59
- package/dist/entities/projection.d.ts +0 -8
- package/dist/entities/projection.js +0 -82
- package/dist/entities/provenance-query.d.ts +0 -32
- package/dist/entities/provenance-query.js +0 -3
- package/dist/entities/read-identity.d.ts +0 -31
- package/dist/entities/read-identity.js +0 -264
- package/dist/entities/recall-bridge.d.ts +0 -5
- package/dist/entities/recall-bridge.js +0 -171
- package/dist/entities/resolution-engine.d.ts +0 -8
- package/dist/entities/resolution-engine.js +0 -3
- package/dist/entities/rollback-preview.d.ts +0 -35
- package/dist/entities/rollback-preview.js +0 -3
- package/dist/entities/source-locator.d.ts +0 -3
- package/dist/entities/source-locator.js +0 -32
- package/dist/entities/store.d.ts +0 -69
- package/dist/entities/store.js +0 -544
- package/dist/entities/types.d.ts +0 -166
- package/dist/entities/types.js +0 -30
- package/dist/memory/extraction-prompt.d.ts +0 -4
- package/dist/memory/extraction-prompt.js +0 -89
- package/dist/memory/scope-backfill.d.ts +0 -14
- package/dist/memory/scope-backfill.js +0 -3
- package/dist/memory/scope-store.d.ts +0 -4
- package/dist/memory/scope-store.js +0 -9
- package/dist/memory-store.d.ts +0 -87
- package/dist/memory-store.js +0 -78
- package/dist/model-runs/store.d.ts +0 -13
- package/dist/model-runs/tool-trace-store.d.ts +0 -8
- package/dist/notification-manager.d.ts +0 -7
- package/dist/notification-manager.js +0 -12
- package/dist/outcome-tracker.d.ts +0 -151
- package/dist/outcome-tracker.js +0 -271
- package/dist/query-intent.d.ts +0 -23
- package/dist/query-intent.js +0 -114
- package/dist/runtime/trusted-provenance.d.ts +0 -3
- package/dist/runtime/trusted-provenance.js +0 -6
- package/dist/search/question-type.d.ts +0 -5
- package/dist/search/question-type.js +0 -41
- package/dist/test-utils.d.ts +0 -80
- package/dist/test-utils.js +0 -218
- package/dist/tier-validator.d.ts +0 -43
- package/dist/tier-validator.js +0 -159
- package/dist/time-formatter.d.ts +0 -25
- package/dist/time-formatter.js +0 -93
- /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
- /package/dist/{search → knowledge}/feedback-store.js +0 -0
- /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
- /package/dist/{search → knowledge}/search-quality.js +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding: the model, and one process-wide embedder over it.
|
|
3
|
+
*
|
|
4
|
+
* `createEmbedder` returns one embedder holding its own pipeline and cache. Two
|
|
5
|
+
* calls give two independent embedders, so a caller can run a different model
|
|
6
|
+
* without disturbing anyone else's, and a cache entry can never be served to a
|
|
7
|
+
* caller that asked a different model for it.
|
|
8
|
+
*
|
|
9
|
+
* Below that, the module-level surface the rest of the product and the plugin
|
|
10
|
+
* hooks call: `generateEmbedding`, the prefix scheme, the model facts and the
|
|
11
|
+
* cosine. That surface lived in a top-level `embeddings.ts` that did nothing
|
|
12
|
+
* but hold one embedder and re-expose it; a module that owns the model owns
|
|
13
|
+
* the way to ask it for a vector. The published `@jungjaehoon/mama-core/embeddings`
|
|
14
|
+
* subpath still points here, because it names a capability, not a file.
|
|
15
|
+
*
|
|
16
|
+
* @module embedding/embedder
|
|
17
|
+
*/
|
|
18
|
+
import { embeddingCache } from '../embedding-cache.js';
|
|
19
|
+
import { EmbeddingCache } from '../embedding-cache.js';
|
|
20
|
+
export type EmbeddingPipeline = (text: string | string[], options?: {
|
|
21
|
+
pooling?: string;
|
|
22
|
+
normalize?: boolean;
|
|
23
|
+
truncation?: boolean;
|
|
24
|
+
max_length?: number;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
data: Float32Array;
|
|
27
|
+
}>;
|
|
28
|
+
export interface EmbedderOptions {
|
|
29
|
+
modelName: string;
|
|
30
|
+
/** Vectors this model must produce. A mismatch is a failed load, not a warning. */
|
|
31
|
+
dimension: number;
|
|
32
|
+
quantized: boolean;
|
|
33
|
+
maxLength: number;
|
|
34
|
+
/**
|
|
35
|
+
* Where the model files are cached. Optional: absent leaves it to the transformers
|
|
36
|
+
* library's own convention, which is the caller's machine to decide, not this
|
|
37
|
+
* library's.
|
|
38
|
+
*/
|
|
39
|
+
cacheDir?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Cache to use. Callers that share one embedder with existing consumers pass
|
|
42
|
+
* the cache those consumers already clear and read stats from; omit it and the
|
|
43
|
+
* embedder owns a private one.
|
|
44
|
+
*/
|
|
45
|
+
cache?: EmbeddingCache;
|
|
46
|
+
}
|
|
47
|
+
export interface Embedder {
|
|
48
|
+
readonly modelName: string;
|
|
49
|
+
readonly dimension: number;
|
|
50
|
+
/** Embed one already-prefixed input. The caller owns the role prefix. */
|
|
51
|
+
embed(modelInput: string): Promise<Float32Array>;
|
|
52
|
+
/** Load the model without embedding anything, so a caller can pay that cost up front. */
|
|
53
|
+
warm(): Promise<void>;
|
|
54
|
+
cache: EmbeddingCache;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build an embedder. The model loads on first use, not here.
|
|
58
|
+
*
|
|
59
|
+
* A failed load is remembered: the second call reports the original failure
|
|
60
|
+
* instead of spending another model download on the same broken configuration.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createEmbedder(options: EmbedderOptions): Embedder;
|
|
63
|
+
/**
|
|
64
|
+
* Which model, at what width, quantized or not.
|
|
65
|
+
*
|
|
66
|
+
* These used to be read from a config file under the product's home directory, which
|
|
67
|
+
* meant the core could not produce an embedding until that product existed. They are
|
|
68
|
+
* facts about the model, not about who is asking for one, so they live with the code
|
|
69
|
+
* that loads it. A caller that wants a different model passes it.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DEFAULT_MODEL_NAME = "Xenova/multilingual-e5-large";
|
|
72
|
+
/** State where this consumer keeps its model cache. Call before the first embedding. */
|
|
73
|
+
export declare function declareEmbeddingCacheDir(dir: string): void;
|
|
74
|
+
/** Test seam: forget what was declared. */
|
|
75
|
+
export declare function clearEmbeddingCacheDir(): void;
|
|
76
|
+
export declare const DEFAULT_EMBEDDING_DIM = 1024;
|
|
77
|
+
export declare const DEFAULT_QUANTIZED = true;
|
|
78
|
+
export declare const EMBEDDING_MODEL_MAX_LENGTH = 512;
|
|
79
|
+
export declare const EMBEDDING_MAX_TOKENISH_SEGMENTS = 480;
|
|
80
|
+
export type EmbeddingRole = 'passage' | 'query';
|
|
81
|
+
export declare const EMBEDDING_PREFIX_SCHEME = "e5-prefixed-v1";
|
|
82
|
+
export declare function isForceTier3Enabled(): boolean;
|
|
83
|
+
export declare function prepareEmbeddingText(text: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Decision object for enhanced embedding generation
|
|
86
|
+
*/
|
|
87
|
+
export interface DecisionForEmbedding {
|
|
88
|
+
topic: string;
|
|
89
|
+
decision: string;
|
|
90
|
+
reasoning?: string;
|
|
91
|
+
outcome?: string;
|
|
92
|
+
confidence?: number;
|
|
93
|
+
user_involvement?: string;
|
|
94
|
+
evidence?: string | string[] | unknown;
|
|
95
|
+
alternatives?: string | string[] | unknown;
|
|
96
|
+
risks?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generate embedding vector from text
|
|
100
|
+
*
|
|
101
|
+
* Story M1.4 AC #1: Uses configurable embeddingDim from config
|
|
102
|
+
* Target: < 30ms latency
|
|
103
|
+
*
|
|
104
|
+
* @param text - Input text to embed
|
|
105
|
+
* @returns Embedding vector (dimension from config)
|
|
106
|
+
* @throws Error if text is empty or embedding fails
|
|
107
|
+
*/
|
|
108
|
+
export declare function generateEmbedding(text: string, role?: EmbeddingRole): Promise<Float32Array>;
|
|
109
|
+
/**
|
|
110
|
+
* Generate enhanced embedding with content + metadata
|
|
111
|
+
*
|
|
112
|
+
* Task 3.4: Implement enhanced embedding format
|
|
113
|
+
* Inspired by A-mem: Content + Metadata for richer semantic representation
|
|
114
|
+
*
|
|
115
|
+
* @param decision - Decision object
|
|
116
|
+
* @returns 1024-dim enhanced embedding
|
|
117
|
+
*/
|
|
118
|
+
export declare function generateEnhancedEmbedding(decision: DecisionForEmbedding, role?: EmbeddingRole): Promise<Float32Array>;
|
|
119
|
+
/**
|
|
120
|
+
* Calculate cosine similarity between two embeddings
|
|
121
|
+
*
|
|
122
|
+
* Utility for testing and validation
|
|
123
|
+
*
|
|
124
|
+
* @param embA - First embedding
|
|
125
|
+
* @param embB - Second embedding
|
|
126
|
+
* @returns Cosine similarity (0-1)
|
|
127
|
+
*/
|
|
128
|
+
export declare function cosineSimilarity(embA: Float32Array, embB: Float32Array): number;
|
|
129
|
+
export { embeddingCache };
|
|
130
|
+
export declare const EMBEDDING_DIM = 1024;
|
|
131
|
+
export declare const MODEL_NAME = "Xenova/multilingual-e5-large";
|
|
132
|
+
//# sourceMappingURL=embedder.d.ts.map
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Embedding: the model, and one process-wide embedder over it.
|
|
4
|
+
*
|
|
5
|
+
* `createEmbedder` returns one embedder holding its own pipeline and cache. Two
|
|
6
|
+
* calls give two independent embedders, so a caller can run a different model
|
|
7
|
+
* without disturbing anyone else's, and a cache entry can never be served to a
|
|
8
|
+
* caller that asked a different model for it.
|
|
9
|
+
*
|
|
10
|
+
* Below that, the module-level surface the rest of the product and the plugin
|
|
11
|
+
* hooks call: `generateEmbedding`, the prefix scheme, the model facts and the
|
|
12
|
+
* cosine. That surface lived in a top-level `embeddings.ts` that did nothing
|
|
13
|
+
* but hold one embedder and re-expose it; a module that owns the model owns
|
|
14
|
+
* the way to ask it for a vector. The published `@jungjaehoon/mama-core/embeddings`
|
|
15
|
+
* subpath still points here, because it names a capability, not a file.
|
|
16
|
+
*
|
|
17
|
+
* @module embedding/embedder
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.MODEL_NAME = exports.EMBEDDING_DIM = exports.embeddingCache = exports.EMBEDDING_PREFIX_SCHEME = exports.EMBEDDING_MAX_TOKENISH_SEGMENTS = exports.EMBEDDING_MODEL_MAX_LENGTH = exports.DEFAULT_QUANTIZED = exports.DEFAULT_EMBEDDING_DIM = exports.DEFAULT_MODEL_NAME = void 0;
|
|
21
|
+
exports.createEmbedder = createEmbedder;
|
|
22
|
+
exports.declareEmbeddingCacheDir = declareEmbeddingCacheDir;
|
|
23
|
+
exports.clearEmbeddingCacheDir = clearEmbeddingCacheDir;
|
|
24
|
+
exports.isForceTier3Enabled = isForceTier3Enabled;
|
|
25
|
+
exports.prepareEmbeddingText = prepareEmbeddingText;
|
|
26
|
+
exports.generateEmbedding = generateEmbedding;
|
|
27
|
+
exports.generateEnhancedEmbedding = generateEnhancedEmbedding;
|
|
28
|
+
exports.cosineSimilarity = cosineSimilarity;
|
|
29
|
+
const embedding_cache_js_1 = require("../embedding-cache.js");
|
|
30
|
+
Object.defineProperty(exports, "embeddingCache", { enumerable: true, get: function () { return embedding_cache_js_1.embeddingCache; } });
|
|
31
|
+
const embedding_cache_js_2 = require("../embedding-cache.js");
|
|
32
|
+
const debug_logger_js_1 = require("../debug-logger.js");
|
|
33
|
+
const progress_indicator_js_1 = require("../progress-indicator.js");
|
|
34
|
+
/**
|
|
35
|
+
* Build an embedder. The model loads on first use, not here.
|
|
36
|
+
*
|
|
37
|
+
* A failed load is remembered: the second call reports the original failure
|
|
38
|
+
* instead of spending another model download on the same broken configuration.
|
|
39
|
+
*/
|
|
40
|
+
function createEmbedder(options) {
|
|
41
|
+
const cache = options.cache ?? new embedding_cache_js_2.EmbeddingCache();
|
|
42
|
+
let pipeline = null;
|
|
43
|
+
let loadFailure = null;
|
|
44
|
+
async function load() {
|
|
45
|
+
if (pipeline) {
|
|
46
|
+
return pipeline;
|
|
47
|
+
}
|
|
48
|
+
if (loadFailure) {
|
|
49
|
+
throw loadFailure;
|
|
50
|
+
}
|
|
51
|
+
(0, progress_indicator_js_1.logLoading)(`Loading embedding model: ${options.modelName}...`);
|
|
52
|
+
const startedAt = Date.now();
|
|
53
|
+
try {
|
|
54
|
+
// Dynamic import keeps the ES-module-only package out of the CommonJS graph.
|
|
55
|
+
const { pipeline: createPipeline, env } = await import('@huggingface/transformers');
|
|
56
|
+
if (options.cacheDir) {
|
|
57
|
+
env.cacheDir = options.cacheDir;
|
|
58
|
+
(0, debug_logger_js_1.info)(`[embedder] Model cache directory: ${options.cacheDir}`);
|
|
59
|
+
}
|
|
60
|
+
pipeline = (await createPipeline('feature-extraction', options.modelName, {
|
|
61
|
+
dtype: options.quantized ? 'q8' : 'fp32',
|
|
62
|
+
}));
|
|
63
|
+
(0, progress_indicator_js_1.logComplete)(`Embedding model ready (${Date.now() - startedAt}ms, ${options.dimension}-dim, ${options.quantized ? 'q8' : 'fp32'})`);
|
|
64
|
+
return pipeline;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
loadFailure = error instanceof Error ? error : new Error(String(error));
|
|
68
|
+
throw loadFailure;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
modelName: options.modelName,
|
|
73
|
+
dimension: options.dimension,
|
|
74
|
+
cache,
|
|
75
|
+
async warm() {
|
|
76
|
+
await load();
|
|
77
|
+
},
|
|
78
|
+
async embed(modelInput) {
|
|
79
|
+
const cached = cache.get(modelInput);
|
|
80
|
+
if (cached) {
|
|
81
|
+
return cached;
|
|
82
|
+
}
|
|
83
|
+
const model = await load();
|
|
84
|
+
const output = await model(modelInput, {
|
|
85
|
+
pooling: 'mean',
|
|
86
|
+
normalize: true,
|
|
87
|
+
truncation: true,
|
|
88
|
+
max_length: options.maxLength,
|
|
89
|
+
});
|
|
90
|
+
const vector = output.data;
|
|
91
|
+
if (vector.length !== options.dimension) {
|
|
92
|
+
throw new Error(`Expected ${options.dimension}-dim, got ${vector.length}-dim`);
|
|
93
|
+
}
|
|
94
|
+
cache.set(modelInput, vector);
|
|
95
|
+
return vector;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Shared cache directory (not in node_modules)
|
|
100
|
+
/**
|
|
101
|
+
* Which model, at what width, quantized or not.
|
|
102
|
+
*
|
|
103
|
+
* These used to be read from a config file under the product's home directory, which
|
|
104
|
+
* meant the core could not produce an embedding until that product existed. They are
|
|
105
|
+
* facts about the model, not about who is asking for one, so they live with the code
|
|
106
|
+
* that loads it. A caller that wants a different model passes it.
|
|
107
|
+
*/
|
|
108
|
+
exports.DEFAULT_MODEL_NAME = 'Xenova/multilingual-e5-large';
|
|
109
|
+
/**
|
|
110
|
+
* Where the shared embedder caches its model files.
|
|
111
|
+
*
|
|
112
|
+
* The core used to compute one under the user's home directory and call it "the
|
|
113
|
+
* library's convention". It is not: `@huggingface/transformers@3.8.1` caches under its
|
|
114
|
+
* own package directory (`src/env.js:96`). So the old value was this library choosing
|
|
115
|
+
* a location on one machine, for consumers that never asked - and dropping it outright
|
|
116
|
+
* would move a 560MB model into `node_modules` and re-download it on the next run.
|
|
117
|
+
*
|
|
118
|
+
* A consumer states its own, once, before anything embeds. Nothing declared and no
|
|
119
|
+
* `HF_HOME`/`TRANSFORMERS_CACHE` set leaves the library to its own default.
|
|
120
|
+
*/
|
|
121
|
+
let declaredCacheDir;
|
|
122
|
+
/** State where this consumer keeps its model cache. Call before the first embedding. */
|
|
123
|
+
function declareEmbeddingCacheDir(dir) {
|
|
124
|
+
declaredCacheDir = dir;
|
|
125
|
+
}
|
|
126
|
+
/** Test seam: forget what was declared. */
|
|
127
|
+
function clearEmbeddingCacheDir() {
|
|
128
|
+
declaredCacheDir = undefined;
|
|
129
|
+
}
|
|
130
|
+
exports.DEFAULT_EMBEDDING_DIM = 1024;
|
|
131
|
+
exports.DEFAULT_QUANTIZED = true;
|
|
132
|
+
const TIER3_ENV_VALUES = new Set(['1', 'true', 'yes']);
|
|
133
|
+
exports.EMBEDDING_MODEL_MAX_LENGTH = 512;
|
|
134
|
+
exports.EMBEDDING_MAX_TOKENISH_SEGMENTS = 480;
|
|
135
|
+
exports.EMBEDDING_PREFIX_SCHEME = 'e5-prefixed-v1';
|
|
136
|
+
function applyRolePrefix(preparedText, role) {
|
|
137
|
+
return `${role}: ${preparedText}`;
|
|
138
|
+
}
|
|
139
|
+
const TOKENISH_SEGMENT_PATTERN = /[\p{Script=Hangul}\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]|\S+/gu;
|
|
140
|
+
// Type for pipeline function from @huggingface/transformers
|
|
141
|
+
// One process-wide embedder for callers that have not been given one of their
|
|
142
|
+
// own. `createEmbedder` owns the pipeline and its cache; this module only holds
|
|
143
|
+
// the instance and rebuilds it when the configured model changes.
|
|
144
|
+
let embedder = null;
|
|
145
|
+
function isForceTier3Enabled() {
|
|
146
|
+
return TIER3_ENV_VALUES.has(String(process.env.MAMA_FORCE_TIER_3 || '').toLowerCase());
|
|
147
|
+
}
|
|
148
|
+
function assertEmbeddingsEnabled() {
|
|
149
|
+
if (isForceTier3Enabled()) {
|
|
150
|
+
throw new Error('Embedding generation disabled because MAMA_FORCE_TIER_3=true. ' +
|
|
151
|
+
'Tier 3 test mode must use lexical/no-vector fallback instead of loading the embedding model.');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function prepareEmbeddingText(text) {
|
|
155
|
+
const trimmed = text.trim();
|
|
156
|
+
let count = 0;
|
|
157
|
+
let cutIndex = trimmed.length;
|
|
158
|
+
for (const match of trimmed.matchAll(TOKENISH_SEGMENT_PATTERN)) {
|
|
159
|
+
count++;
|
|
160
|
+
if (count > exports.EMBEDDING_MAX_TOKENISH_SEGMENTS) {
|
|
161
|
+
cutIndex = match.index ?? trimmed.length;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return cutIndex === trimmed.length ? trimmed : trimmed.slice(0, cutIndex).trimEnd();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Load embedding model (configurable)
|
|
169
|
+
*
|
|
170
|
+
* Story M1.4 AC #2: Transformers.js singleton initialization
|
|
171
|
+
* Story M1.4 AC #3: Changing model via config triggers informative log + resets caches
|
|
172
|
+
*
|
|
173
|
+
* @returns Embedding pipeline
|
|
174
|
+
*/
|
|
175
|
+
function resolveEmbedder() {
|
|
176
|
+
assertEmbeddingsEnabled();
|
|
177
|
+
const modelName = exports.DEFAULT_MODEL_NAME;
|
|
178
|
+
// Story M1.4 AC #3: a configured model change resets the pipeline and cache.
|
|
179
|
+
if (embedder && embedder.modelName !== modelName) {
|
|
180
|
+
(0, debug_logger_js_1.info)('[MAMA] Embedding model changed - resetting pipeline');
|
|
181
|
+
(0, debug_logger_js_1.info)(`[MAMA] Old model: ${embedder.modelName}`);
|
|
182
|
+
(0, debug_logger_js_1.info)(`[MAMA] New model: ${modelName}`);
|
|
183
|
+
embedding_cache_js_1.embeddingCache.clear();
|
|
184
|
+
embedder = null;
|
|
185
|
+
(0, debug_logger_js_1.info)('[MAMA] Model cache cleared');
|
|
186
|
+
}
|
|
187
|
+
if (!embedder) {
|
|
188
|
+
embedder = createEmbedder({
|
|
189
|
+
modelName,
|
|
190
|
+
dimension: exports.DEFAULT_EMBEDDING_DIM,
|
|
191
|
+
quantized: exports.DEFAULT_QUANTIZED,
|
|
192
|
+
maxLength: exports.EMBEDDING_MODEL_MAX_LENGTH,
|
|
193
|
+
// The environment a user set, else what this consumer declared, else the
|
|
194
|
+
// library's own default. The core names no directory of its own.
|
|
195
|
+
cacheDir: process.env.HF_HOME || process.env.TRANSFORMERS_CACHE || declaredCacheDir,
|
|
196
|
+
// The shared cache: consumers already clear it and read its stats.
|
|
197
|
+
cache: embedding_cache_js_1.embeddingCache,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return embedder;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Generate embedding vector from text
|
|
204
|
+
*
|
|
205
|
+
* Story M1.4 AC #1: Uses configurable embeddingDim from config
|
|
206
|
+
* Target: < 30ms latency
|
|
207
|
+
*
|
|
208
|
+
* @param text - Input text to embed
|
|
209
|
+
* @returns Embedding vector (dimension from config)
|
|
210
|
+
* @throws Error if text is empty or embedding fails
|
|
211
|
+
*/
|
|
212
|
+
async function generateEmbedding(text, role = 'passage') {
|
|
213
|
+
if (typeof text !== 'string' || text.trim().length === 0) {
|
|
214
|
+
throw new Error('Text cannot be empty');
|
|
215
|
+
}
|
|
216
|
+
assertEmbeddingsEnabled();
|
|
217
|
+
const preparedText = prepareEmbeddingText(text);
|
|
218
|
+
const modelInput = applyRolePrefix(preparedText, role); // e5 instruction prefix
|
|
219
|
+
// The embedder keys its cache on the PREFIXED input, so a passage vector can
|
|
220
|
+
// never be served to a query.
|
|
221
|
+
try {
|
|
222
|
+
return await resolveEmbedder().embed(modelInput);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
226
|
+
throw new Error(`Failed to generate embedding: ${message}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Generate enhanced embedding with content + metadata
|
|
231
|
+
*
|
|
232
|
+
* Task 3.4: Implement enhanced embedding format
|
|
233
|
+
* Inspired by A-mem: Content + Metadata for richer semantic representation
|
|
234
|
+
*
|
|
235
|
+
* @param decision - Decision object
|
|
236
|
+
* @returns 1024-dim enhanced embedding
|
|
237
|
+
*/
|
|
238
|
+
async function generateEnhancedEmbedding(decision, role = 'passage') {
|
|
239
|
+
// Construct enriched text representation with narrative fields (Story 2.2)
|
|
240
|
+
const parts = [
|
|
241
|
+
`Topic: ${decision.topic}`,
|
|
242
|
+
`Decision: ${decision.decision}`,
|
|
243
|
+
`Reasoning: ${decision.reasoning || 'N/A'}`,
|
|
244
|
+
`Outcome: ${decision.outcome || 'ONGOING'}`,
|
|
245
|
+
`Confidence: ${decision.confidence !== undefined ? decision.confidence : 0.5}`,
|
|
246
|
+
`User Involvement: ${decision.user_involvement || 'N/A'}`,
|
|
247
|
+
];
|
|
248
|
+
// Add narrative fields if present (Story 2.2: Narrative-Based Search)
|
|
249
|
+
if (decision.evidence) {
|
|
250
|
+
const evidenceText = Array.isArray(decision.evidence)
|
|
251
|
+
? decision.evidence.join('; ')
|
|
252
|
+
: typeof decision.evidence === 'string'
|
|
253
|
+
? decision.evidence
|
|
254
|
+
: JSON.stringify(decision.evidence);
|
|
255
|
+
parts.push(`Evidence: ${evidenceText}`);
|
|
256
|
+
}
|
|
257
|
+
if (decision.alternatives) {
|
|
258
|
+
const alternativesText = Array.isArray(decision.alternatives)
|
|
259
|
+
? decision.alternatives.join('; ')
|
|
260
|
+
: typeof decision.alternatives === 'string'
|
|
261
|
+
? decision.alternatives
|
|
262
|
+
: JSON.stringify(decision.alternatives);
|
|
263
|
+
parts.push(`Alternatives: ${alternativesText}`);
|
|
264
|
+
}
|
|
265
|
+
if (decision.risks) {
|
|
266
|
+
parts.push(`Risks: ${decision.risks}`);
|
|
267
|
+
}
|
|
268
|
+
const enrichedText = parts.join('\n').trim();
|
|
269
|
+
return generateEmbedding(enrichedText, role);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Calculate cosine similarity between two embeddings
|
|
273
|
+
*
|
|
274
|
+
* Utility for testing and validation
|
|
275
|
+
*
|
|
276
|
+
* @param embA - First embedding
|
|
277
|
+
* @param embB - Second embedding
|
|
278
|
+
* @returns Cosine similarity (0-1)
|
|
279
|
+
*/
|
|
280
|
+
function cosineSimilarity(embA, embB) {
|
|
281
|
+
if (embA.length !== embB.length) {
|
|
282
|
+
throw new Error('Embeddings must have same dimension');
|
|
283
|
+
}
|
|
284
|
+
let dotProduct = 0;
|
|
285
|
+
let normA = 0;
|
|
286
|
+
let normB = 0;
|
|
287
|
+
for (let i = 0; i < embA.length; i++) {
|
|
288
|
+
dotProduct += embA[i] * embB[i];
|
|
289
|
+
normA += embA[i] * embA[i];
|
|
290
|
+
normB += embB[i] * embB[i];
|
|
291
|
+
}
|
|
292
|
+
const similarity = dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
293
|
+
return similarity;
|
|
294
|
+
}
|
|
295
|
+
// Static snapshots of config values at module load time (Story M1.4)
|
|
296
|
+
exports.EMBEDDING_DIM = exports.DEFAULT_EMBEDDING_DIM;
|
|
297
|
+
exports.MODEL_NAME = exports.DEFAULT_MODEL_NAME;
|
|
298
|
+
// Expose config functions for external use
|
|
299
|
+
//# sourceMappingURL=embedder.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DatabaseAdapter
|
|
1
|
+
import type { DatabaseAdapter } from '../db-manager.js';
|
|
2
2
|
export interface PrincipalRow {
|
|
3
3
|
principalId: string;
|
|
4
4
|
kind: 'owner' | 'member';
|
|
@@ -64,5 +64,5 @@ export declare class PrincipalScopeGrantError extends Error {
|
|
|
64
64
|
readonly code: PrincipalScopeGrantErrorCode;
|
|
65
65
|
constructor(code: PrincipalScopeGrantErrorCode, message: string);
|
|
66
66
|
}
|
|
67
|
-
export declare function createPrincipalRepository(adapter: Pick<
|
|
67
|
+
export declare function createPrincipalRepository(adapter: Pick<DatabaseAdapter, 'prepare' | 'transaction'>): PrincipalRepository;
|
|
68
68
|
//# sourceMappingURL=principal-repository.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -2,83 +2,68 @@
|
|
|
2
2
|
* MAMA Core - Main exports
|
|
3
3
|
*
|
|
4
4
|
* Shared modules for Memory-Augmented MCP Assistant.
|
|
5
|
-
* Used by mcp-server, claude-code-plugin, and standalone packages.
|
|
6
5
|
*
|
|
7
6
|
* @module mama-core
|
|
8
7
|
* @version 1.0.0
|
|
9
8
|
*/
|
|
10
|
-
export { generateEmbedding, generateEnhancedEmbedding, cosineSimilarity, embeddingCache, EMBEDDING_DIM, MODEL_NAME, EMBEDDING_PREFIX_SCHEME, type EmbeddingRole, } from './
|
|
9
|
+
export { generateEmbedding, generateEnhancedEmbedding, cosineSimilarity, embeddingCache, EMBEDDING_DIM, MODEL_NAME, EMBEDDING_PREFIX_SCHEME, type EmbeddingRole, } from './embedding/embedder.js';
|
|
11
10
|
export { EmbeddingCache } from './embedding-cache.js';
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export { createAdapter, DatabaseAdapter, SQLiteAdapter, type AdapterConfig, type Statement, type VectorSearchResult, type RunResult, } from './db-adapter/index.js';
|
|
15
|
-
export { traverseDecisionChain, DB_PATH, DB_DIR, LEGACY_DB_PATH, DEFAULT_DB_PATH, } from './memory-store.js';
|
|
11
|
+
export { initDB, getDB, getAdapter, closeDB, updateDecisionOutcome, getDbPath, type DatabaseAdapter, type DatabaseInstance, type PreparedStatement, type DecisionRecord, type OutcomeData, type SemanticEdges, type SemanticEdgeItem, type DecisionInput, } from './db-manager.js';
|
|
12
|
+
export { createAdapter, SQLiteAdapter, type AdapterConfig, type Statement, type VectorSearchResult, type RunResult, } from './db-adapter/index.js';
|
|
16
13
|
import mama from './mama-api.js';
|
|
17
14
|
export { mama };
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
15
|
+
export { createMamaApi, type MamaApi } from './mama-api.js';
|
|
16
|
+
export { MEMORY_SCOPE_KINDS, MEMORY_KINDS, MEMORY_STATUSES, MEMORY_EDGE_TYPES, createEmptyRecallBundle, type MemoryScopeKind, type MemoryKind, type MemoryKindFilter, type MemoryStatus, type MemoryEdgeType, type MemoryScopeRef, type MemorySourceRef, type MemoryRecord, type MemoryWriteProvenance, type MemoryProvenanceRecord, type PublicSaveMemoryInput, type PublicIngestMemoryInput, type PublicIngestConversationInput, type MemorySearchResultHit, type MemoryEdge, type ProfileSnapshot, type RecallBundle, type ConversationMessage, type IngestConversationInput, type ExtractedMemoryUnit, type IngestConversationResult, type AuditFindingRecord, canonicalizeContextScopes, } from './memory/types.js';
|
|
17
|
+
export { saveMemory, saveJudgmentRecord, saveLegacyMemory, promoteMemoryStatus, readMemoryRecordById, readMemoryRecordsInScopes, retireMemoryRecord, recallMemory, buildProfile, ingestMemory, evolveMemory, buildMemoryBootstrap, createAuditAck, recordMemoryAudit, ingestConversation, upsertChannelSummary, getChannelSummary, type MemoryRetirementStatus, type ReadMemoryRecordsOptions, } from './memory/api.js';
|
|
18
|
+
export { createKnowledge, appendJudgment, ingestSource, JudgmentError, type Knowledge, type KnowledgeOptions, type JudgmentAccess, type SourceIngestCommand, type SourceIngestReceipt, type WorkGraphPage, type WorkGraphQuery, type WorkReference, } from './knowledge/index.js';
|
|
21
19
|
export { queryRelevantTruth } from './memory/truth-store.js';
|
|
22
20
|
export { createAuditFinding, listOpenAuditFindings } from './memory/finding-store.js';
|
|
23
21
|
export { appendMemoryEvent, insertMemoryEventInTransaction, listMemoryEventsForMemory, listRecentMemoryEvents, } from './memory/event-store.js';
|
|
24
|
-
export {
|
|
22
|
+
export { normalizeMemoryWriteProvenance, type NormalizedMemoryProvenance, } from './memory/provenance.js';
|
|
25
23
|
export { getMemoryProvenance, listMemoriesByEnvelopeHash, listMemoriesByGatewayCallId, listMemoriesByModelRunId, } from './memory/provenance-query.js';
|
|
26
|
-
export { type BackfillResult, type ConnectorEventScopeBackfillInput, } from './memory/scope-backfill.js';
|
|
27
24
|
export { getMemoryProvenanceAudit, listMemoryProvenanceAudit, type MemoryProvenanceAuditRecord, type MemoryProvenanceAuditListOptions, } from './memory/provenance-audit.js';
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export
|
|
25
|
+
export { OBSERVATION_COLUMNS, isEventVisibleNow, isMessageRefVisible, parseSourceRef, resolveMemoryProvenanceLive, toIndexedEvent, type EventRow, type LiveProvenanceOptions, } from './memory/provenance-live.js';
|
|
26
|
+
export { resolveMemoryProvenance, type IndexedEvent, type ParsedSourceRef, type ProvenanceResolution, type ProvenanceResolverDeps, type ProvenanceSubjectRecord, type RecordedSupport, type ResolutionFailure, type ResolvedEvent, type UnresolvedSupport, } from './memory/provenance-resolver.js';
|
|
27
|
+
export { sanitizeRecallBundle, sanitizeRecallText, type SafeRecallBundle, type SafeRecallMemory, } from './memory/recall-sanitize.js';
|
|
28
|
+
export { scanForSecrets, scanMemoryWriteInput, type SecretScanResult, } from './memory/secret-filter.js';
|
|
29
|
+
export { MODEL_RUN_STATUSES, type ModelRunStatus, type BeginModelRunInput, type ModelRunRecord, type AppendToolTraceInput, type AppendOperationToolTraceInput, type ToolTraceRecord, type ToolTraceScope, type ListToolTracesInput, type ToolTracePage, } from './runtime/model-run-types.js';
|
|
30
|
+
export { beginModelRun, commitModelRun, failModelRun, getModelRun, } from './runtime/model-run-store.js';
|
|
31
|
+
export { appendToolTrace, appendOperationToolTrace, listToolTracesForRun, listToolTraces, readToolTrace, } from './runtime/tool-trace-store.js';
|
|
32
|
+
export { TWIN_EDGE_SOURCES, TWIN_EDGE_TYPES, TWIN_REF_KINDS, type InsertTwinEdgeInput, type ListVisibleTwinEdgesOptions, type TwinEdgeInsert, type TwinEdgeRecord, type TwinEdgeSource, type TwinEdgeType, type TwinRef, type TwinRefKind, type TwinScopeRef, } from './knowledge/twin-edge-types.js';
|
|
33
|
+
export { getTwinEdge, insertTwinEdge, listTwinEdgesForRefs, mapTwinEdgeRow, } from './knowledge/judgments.js';
|
|
34
|
+
export { listVisibleTwinEdgesForRefs } from './knowledge/access.js';
|
|
35
|
+
export type { ActionCall, ActionContract, ActionExample, ActionFailure, ActionFailureKind, ActionResult, ActionSchemaObject, ActionSessionFacts, } from './action-contracts.js';
|
|
36
|
+
export { createCatalog, coreActionRegistrations, UnknownActionError, type ActionCatalog, type ActionContext, type ActionExec, type ActionRegistration, type MemoryReadAllowance, } from './api/catalog.js';
|
|
37
|
+
export { createDispatcher, validateInput, withCallReceipt, type ActionDispatcher, type DispatcherOptions, } from './api/dispatch.js';
|
|
38
|
+
export { createClient, type Client, type ClientCall, type ClientOptions } from './client/client.js';
|
|
39
|
+
export { startRuntime, type RuntimeHandle, type RuntimePaths, type StartRuntimeOptions, } from './runtime/runtime.js';
|
|
40
|
+
export { createActionIpcServer, encodeFrame, IpcTransportError, newRequestId, sendIpcRequest, IPC_MAX_FRAME_BYTES, type ActionIpcServer, type ActionIpcServerOptions, type IpcRequest, type IpcResponse, } from './client/ipc.js';
|
|
35
41
|
export * from './provenance/source-ref.js';
|
|
36
|
-
export * from './
|
|
37
|
-
export * from './
|
|
38
|
-
export * from './entities/types.js';
|
|
39
|
-
export * from './entities/errors.js';
|
|
40
|
-
export * from './entities/store.js';
|
|
41
|
-
export * from './entities/normalization.js';
|
|
42
|
-
export * from './entities/projection.js';
|
|
43
|
-
export * from './entities/recall-bridge.js';
|
|
44
|
-
export * from './entities/read-identity.js';
|
|
45
|
-
export * from './entities/audit-metrics.js';
|
|
46
|
-
export * from './entities/provenance-query.js';
|
|
47
|
-
export * from './entities/lineage-store.js';
|
|
48
|
-
export * from './entities/entity-search.js';
|
|
49
|
-
export * from './entities/entity-list.js';
|
|
50
|
-
export * from './entities/entity-orphan-list.js';
|
|
51
|
-
export * from './entities/rollback-preview.js';
|
|
52
|
-
export * from './entities/source-locator.js';
|
|
53
|
-
export * from './entities/policy-types.js';
|
|
54
|
-
export * from './entities/policy-store.js';
|
|
42
|
+
export * from './knowledge/case-errors.js';
|
|
43
|
+
export * from './knowledge/graph-query.js';
|
|
55
44
|
export { canonicalizeJSON, targetRefHash, CanonicalizeError, type CanonicalizeErrorCode, } from './canonicalize.js';
|
|
56
|
-
export { loadConfig, getModelName, getEmbeddingDim, getCacheDir, updateConfig, getConfigPath, DEFAULT_CONFIG, type MAMAConfig, type ConfigUpdates, } from './config-loader.js';
|
|
57
45
|
export { calculateRelevance, selectTopDecisions, formatTopNContext, type DecisionWithEmbedding, type QueryContext, type FormattedContext, type TestResult, } from './relevance-scorer.js';
|
|
58
|
-
export { learnDecision, generateDecisionId, getPreviousDecision, createEdge, createSupersedesEdge, markSuperseded, calculateCombinedConfidence, detectRefinement, parseReasoningForRelationships, createEdgesFromReasoning, updateConfidence, VALID_EDGE_TYPES, type EdgeType, type DecisionDetection, type ToolExecution, type SessionContext, type LearnDecisionResult, type ParsedRelationship, type EvidenceItem, } from './decision-tracker.js';
|
|
59
|
-
export { checkNodeVersion, checkSQLite, checkEmbeddings, checkDatabase, getTierDescription, type TierValidation, type CheckResult, type NamedCheckResult, } from './tier-validator.js';
|
|
60
46
|
export { logProgress, logComplete, logFailed, logError, logLoading, logSearching, } from './progress-indicator.js';
|
|
61
47
|
export { debug, info, warn, error, DebugLogger } from './debug-logger.js';
|
|
62
|
-
export { formatTimeAgo } from './time-formatter.js';
|
|
63
48
|
export { MAMAError, NotFoundError, ValidationError, DatabaseError, EmbeddingError, ConfigurationError, LinkError, RateLimitError, TimeoutError, ErrorCodes, wrapError, isMAMAError, type ErrorDetails, type ErrorResponse, type ErrorJSON, type ErrorCode, } from './errors.js';
|
|
64
49
|
export { formatContext, formatLegacyContext, formatRecall, formatList, formatTrustContext, ensureTokenBudget, estimateTokens, extractQuickAnswer, extractCodeExample, type DecisionForFormat, type TrustContext, type SemanticEdges as FormatterSemanticEdges, type FormatOptions, } from './decision-formatter.js';
|
|
65
|
-
export { analyzeOutcome, matchesFailureIndicators, matchesSuccessIndicators, matchesPartialIndicators, extractFailureReason, getRecentDecision, calculateDurationDays, getEvidenceImpact, markOutcome, FAILURE_INDICATORS, SUCCESS_INDICATORS, PARTIAL_INDICATORS, RECENT_WINDOW_MS, type HookContext, type OutcomeType, } from './outcome-tracker.js';
|
|
66
|
-
export { analyzeIntent, type IntentResult, type AnalyzeOptions } from './query-intent.js';
|
|
67
50
|
export { generate, isAvailable, listModels, DEFAULT_MODEL, FALLBACK_MODEL, type GenerateOptions, type DecisionAnalysisResult, type QueryIntentResult, } from './ollama-client.js';
|
|
68
|
-
export {
|
|
69
|
-
export * from './
|
|
70
|
-
export * from './
|
|
71
|
-
export * from './
|
|
72
|
-
export * from './
|
|
73
|
-
export * from './
|
|
74
|
-
export * from './connectors/event-index.js';
|
|
75
|
-
export * from './connectors/raw-query.js';
|
|
76
|
-
export * from './connectors/types.js';
|
|
51
|
+
export type { TextCompletion, TextCompletionOptions } from './runtime/text-completion.js';
|
|
52
|
+
export * from './knowledge/case-types.js';
|
|
53
|
+
export * from './knowledge/case-store.js';
|
|
54
|
+
export * from './knowledge/case-search-rollup.js';
|
|
55
|
+
export * from './knowledge/case-timeline-range.js';
|
|
56
|
+
export * from './knowledge/observations.js';
|
|
77
57
|
export * from './identity/principal-repository.js';
|
|
78
|
-
export * from './
|
|
79
|
-
export * from './
|
|
80
|
-
export * from './
|
|
81
|
-
export * from './
|
|
82
|
-
export * from './
|
|
83
|
-
export * from './
|
|
58
|
+
export * from './knowledge/question-type.js';
|
|
59
|
+
export * from './knowledge/feedback-store.js';
|
|
60
|
+
export * from './knowledge/ranker-features.js';
|
|
61
|
+
export * from './knowledge/ranker-trainer.js';
|
|
62
|
+
export * from './knowledge/ranker-rescore.js';
|
|
63
|
+
export * from './knowledge/search-quality.js';
|
|
64
|
+
export * from './registry/store.js';
|
|
65
|
+
export * from './registry/record-identity.js';
|
|
66
|
+
export * from './registry/corrections.js';
|
|
67
|
+
export * from './registry/types.js';
|
|
68
|
+
export * from './operations/owner-action-effects.js';
|
|
84
69
|
//# sourceMappingURL=index.d.ts.map
|