@jungjaehoon/mama-core 1.7.0 → 1.8.1

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.
@@ -77,7 +77,7 @@ async function injectDecisionContext(userMessage) {
77
77
  async function performMemoryInjection(userMessage, startTime) {
78
78
  // 1. Generate query embedding
79
79
  const { generateEmbedding } = await import('./embeddings.js');
80
- const queryEmbedding = await generateEmbedding(userMessage);
80
+ const queryEmbedding = await generateEmbedding(userMessage, 'query');
81
81
  const embeddingLatency = Date.now() - startTime;
82
82
  (0, debug_logger_js_1.info)(`[MAMA] Embedding generation: ${embeddingLatency}ms`);
83
83
  // 2. Adaptive threshold (shorter queries need higher confidence)
@@ -0,0 +1,29 @@
1
+ import { type ContextRef } from '../context-compile/types.js';
2
+ export declare const STRICT_SOURCE_REF_KINDS: readonly ["memory", "raw", "entity", "case", "decision", "os_task", "agent_situation_packet", "report_slot", "context_packet", "model_run", "tool_trace", "wiki_page", "report"];
3
+ export type StrictSourceRefKind = (typeof STRICT_SOURCE_REF_KINDS)[number];
4
+ export declare const LEGACY_SOURCE_REF_KINDS: readonly ["message", "conversation", "raw_memory"];
5
+ export type LegacySourceRefKind = (typeof LEGACY_SOURCE_REF_KINDS)[number];
6
+ export type SourceRef = {
7
+ kind: Exclude<StrictSourceRefKind, 'raw'>;
8
+ id: string;
9
+ } | {
10
+ kind: 'raw';
11
+ id: string;
12
+ connector: string;
13
+ source_id?: string;
14
+ channel_id?: string | null;
15
+ } | {
16
+ kind: 'legacy';
17
+ legacy_kind: LegacySourceRefKind;
18
+ id: string;
19
+ };
20
+ export declare function fromContextRef(ref: ContextRef): SourceRef;
21
+ export declare function toContextRef(ref: SourceRef): ContextRef | null;
22
+ export declare function fromVerifyArtifact(artifact: {
23
+ type: string;
24
+ id: string;
25
+ }): SourceRef;
26
+ export declare function parseSourceRefString(value: string): SourceRef;
27
+ export declare function serializeSourceRef(ref: SourceRef): string;
28
+ export declare function assertNonEmptySourceRefs(refs: readonly SourceRef[]): void;
29
+ //# sourceMappingURL=source-ref.d.ts.map
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LEGACY_SOURCE_REF_KINDS = exports.STRICT_SOURCE_REF_KINDS = void 0;
4
+ exports.fromContextRef = fromContextRef;
5
+ exports.toContextRef = toContextRef;
6
+ exports.fromVerifyArtifact = fromVerifyArtifact;
7
+ exports.parseSourceRefString = parseSourceRefString;
8
+ exports.serializeSourceRef = serializeSourceRef;
9
+ exports.assertNonEmptySourceRefs = assertNonEmptySourceRefs;
10
+ const types_js_1 = require("../context-compile/types.js");
11
+ exports.STRICT_SOURCE_REF_KINDS = [
12
+ 'memory',
13
+ 'raw',
14
+ 'entity',
15
+ 'case',
16
+ 'decision',
17
+ 'os_task',
18
+ 'agent_situation_packet',
19
+ 'report_slot',
20
+ 'context_packet',
21
+ 'model_run',
22
+ 'tool_trace',
23
+ 'wiki_page',
24
+ 'report',
25
+ ];
26
+ exports.LEGACY_SOURCE_REF_KINDS = ['message', 'conversation', 'raw_memory'];
27
+ const STRICT_SOURCE_REF_KIND_SET = new Set(exports.STRICT_SOURCE_REF_KINDS);
28
+ const CONTEXT_REF_KIND_SET = new Set(types_js_1.CONTEXT_REF_KINDS);
29
+ const LEGACY_SOURCE_REF_KIND_SET = new Set(exports.LEGACY_SOURCE_REF_KINDS);
30
+ const VERIFY_ARTIFACT_KIND_SET = new Set([
31
+ 'decision',
32
+ 'os_task',
33
+ 'agent_situation_packet',
34
+ 'report_slot',
35
+ 'context_packet',
36
+ 'model_run',
37
+ 'tool_trace',
38
+ ]);
39
+ function requiredString(value, field) {
40
+ if (typeof value !== 'string') {
41
+ throw new Error(`Source ref ${field} must be a string`);
42
+ }
43
+ const trimmed = value.trim();
44
+ if (trimmed.length === 0) {
45
+ throw new Error(`Source ref ${field} must not be empty`);
46
+ }
47
+ return trimmed;
48
+ }
49
+ function optionalString(value, field) {
50
+ if (value === undefined) {
51
+ return undefined;
52
+ }
53
+ return requiredString(value, field);
54
+ }
55
+ function optionalNullableString(value, field) {
56
+ if (value === null) {
57
+ return null;
58
+ }
59
+ return optionalString(value, field);
60
+ }
61
+ function assertStrictSourceRefKind(kind) {
62
+ if (!STRICT_SOURCE_REF_KIND_SET.has(kind)) {
63
+ throw new Error(`Unsupported source ref kind: ${kind}`);
64
+ }
65
+ }
66
+ function assertLegacySourceRefKind(kind) {
67
+ if (!LEGACY_SOURCE_REF_KIND_SET.has(kind)) {
68
+ throw new Error(`Unsupported legacy source ref kind: ${kind}`);
69
+ }
70
+ }
71
+ function assertContextSourceRefKind(kind) {
72
+ if (kind === 'raw' || !CONTEXT_REF_KIND_SET.has(kind)) {
73
+ throw new Error(`Unsupported context source ref kind: ${kind}`);
74
+ }
75
+ }
76
+ function fromContextRef(ref) {
77
+ if (ref === null || ref === undefined) {
78
+ throw new Error('Context ref must not be null or undefined');
79
+ }
80
+ const input = ref;
81
+ const kind = requiredString(input.kind, 'kind');
82
+ if (kind === 'raw') {
83
+ const normalized = {
84
+ kind: 'raw',
85
+ id: requiredString(input.raw_id, 'raw_id'),
86
+ connector: requiredString(input.connector, 'connector'),
87
+ };
88
+ const sourceId = optionalString(input.source_id, 'source_id');
89
+ const channelId = optionalNullableString(input.channel_id, 'channel_id');
90
+ if (sourceId !== undefined) {
91
+ normalized.source_id = sourceId;
92
+ }
93
+ if (channelId !== undefined) {
94
+ normalized.channel_id = channelId;
95
+ }
96
+ return normalized;
97
+ }
98
+ assertContextSourceRefKind(kind);
99
+ return {
100
+ kind,
101
+ id: requiredString(input.id, 'id'),
102
+ };
103
+ }
104
+ function toContextRef(ref) {
105
+ if (ref === null || ref === undefined) {
106
+ return null;
107
+ }
108
+ switch (ref.kind) {
109
+ case 'memory':
110
+ case 'entity':
111
+ case 'case':
112
+ return {
113
+ kind: ref.kind,
114
+ id: requiredString(ref.id, 'id'),
115
+ };
116
+ case 'raw': {
117
+ const normalized = {
118
+ kind: 'raw',
119
+ raw_id: requiredString(ref.id, 'id'),
120
+ connector: requiredString(ref.connector, 'connector'),
121
+ };
122
+ const sourceId = optionalString(ref.source_id, 'source_id');
123
+ const channelId = optionalNullableString(ref.channel_id, 'channel_id');
124
+ if (sourceId !== undefined) {
125
+ normalized.source_id = sourceId;
126
+ }
127
+ if (channelId !== undefined) {
128
+ normalized.channel_id = channelId;
129
+ }
130
+ return normalized;
131
+ }
132
+ default:
133
+ return null;
134
+ }
135
+ }
136
+ function fromVerifyArtifact(artifact) {
137
+ if (artifact === null || artifact === undefined) {
138
+ throw new Error('Artifact must not be null or undefined');
139
+ }
140
+ const kind = requiredString(artifact.type, 'type');
141
+ if (!VERIFY_ARTIFACT_KIND_SET.has(kind)) {
142
+ throw new Error(`Unsupported verify artifact source ref kind: ${kind}`);
143
+ }
144
+ assertStrictSourceRefKind(kind);
145
+ if (kind === 'raw') {
146
+ throw new Error('Verify artifact source refs cannot use raw kind');
147
+ }
148
+ return {
149
+ kind,
150
+ id: requiredString(artifact.id, 'id'),
151
+ };
152
+ }
153
+ function parseSourceRefString(value) {
154
+ const rawValue = requiredString(value, 'value');
155
+ const parts = rawValue.split(':');
156
+ const kind = requiredString(parts[0], 'kind');
157
+ if (kind === 'raw') {
158
+ const connector = requiredString(parts[1], 'connector');
159
+ const id = requiredString(parts.slice(2).join(':'), 'id');
160
+ return { kind: 'raw', connector, id };
161
+ }
162
+ if (LEGACY_SOURCE_REF_KIND_SET.has(kind)) {
163
+ assertLegacySourceRefKind(kind);
164
+ return {
165
+ kind: 'legacy',
166
+ legacy_kind: kind,
167
+ id: requiredString(parts.slice(1).join(':'), 'id'),
168
+ };
169
+ }
170
+ assertStrictSourceRefKind(kind);
171
+ if (kind === 'raw') {
172
+ throw new Error('Raw source refs must include connector and id');
173
+ }
174
+ const sourceKind = kind;
175
+ return {
176
+ kind: sourceKind,
177
+ id: requiredString(parts.slice(1).join(':'), 'id'),
178
+ };
179
+ }
180
+ function serializeSourceRef(ref) {
181
+ if (ref === null || ref === undefined) {
182
+ throw new Error('Source ref must not be null or undefined');
183
+ }
184
+ switch (ref.kind) {
185
+ case 'raw':
186
+ return `raw:${requiredString(ref.connector, 'connector')}:${requiredString(ref.id, 'id')}`;
187
+ case 'legacy':
188
+ assertLegacySourceRefKind(ref.legacy_kind);
189
+ return `${ref.legacy_kind}:${requiredString(ref.id, 'id')}`;
190
+ default: {
191
+ assertStrictSourceRefKind(ref.kind);
192
+ return `${ref.kind}:${requiredString(ref.id, 'id')}`;
193
+ }
194
+ }
195
+ }
196
+ function assertNonEmptySourceRefs(refs) {
197
+ if (!Array.isArray(refs) || refs.length === 0) {
198
+ throw new Error('Source refs must not be empty');
199
+ }
200
+ for (const ref of refs) {
201
+ serializeSourceRef(ref);
202
+ }
203
+ }
204
+ //# sourceMappingURL=source-ref.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jungjaehoon/mama-core",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "MAMA Core - Shared modules for Memory-Augmented MCP Assistant",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -50,6 +50,7 @@
50
50
  "./agent-situation": "./dist/agent-situation/index.js",
51
51
  "./agent-graph": "./dist/agent-graph/index.js",
52
52
  "./context-compile": "./dist/context-compile/index.js",
53
+ "./provenance/source-ref": "./dist/provenance/source-ref.js",
53
54
  "./edges/types": "./dist/edges/types.js",
54
55
  "./edges/store": "./dist/edges/store.js",
55
56
  "./edges/ref-validation": "./dist/edges/ref-validation.js"