@lanonasis/mem-intel-sdk 2.0.6 → 2.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/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [2.1.0] - 2026-04-01
11
+
12
+ ### Added
13
+
14
+ - **Context-aware intelligence query contract**:
15
+ - added optional `organizationId`, `topicId`, `memoryTypes`, and `queryScope` support to the public SDK query surface
16
+ - extended predictive recall request typing so the context-aware contract stays consistent across client, MCP server, and internal tools
17
+ - **Shared scoped server-side query resolver**:
18
+ - internal intelligence tools now resolve personal, organization, and hybrid queries through one shared helper instead of hardcoded `user_id`-only paths
19
+ - added resolver test coverage for scoped query behavior
20
+
21
+ ### Changed
22
+
23
+ - **Consumer compatibility alignment**:
24
+ - CLI intelligence commands now accept additive context flags and forward them through to the SDK contract
25
+ - dashboard memory-intelligence hook now passes optional context fields through the client layer
26
+ - **Prediction and related-memory internals**:
27
+ - updated related-memory, health, duplicate, insight, tag, pattern, and predictive helpers to honor the new scoped query contract without forcing a physical storage split
28
+
29
+ ### Fixed
30
+
31
+ - **Edge envelope compatibility for `queryMemories()`**:
32
+ - switched the SDK memory query path to the enhanced response adapter so `/intelligence/memories` can use the standard edge-function envelope without breaking the client
33
+
10
34
  ## [2.0.3] - 2026-02-25
11
35
 
12
36
  ### Added
@@ -10,6 +10,8 @@
10
10
  * enabling the SDK to anticipate what actions users might want to take.
11
11
  */
12
12
  import { z } from "zod";
13
+ export declare const BehaviorOutcomeValues: readonly ["success", "partial", "failed"];
14
+ export type BehaviorOutcome = typeof BehaviorOutcomeValues[number];
13
15
  /**
14
16
  * A single action within a behavior pattern
15
17
  */
@@ -17,7 +19,11 @@ export interface BehaviorAction {
17
19
  /** Tool or action identifier */
18
20
  tool: string;
19
21
  /** Parameters used with this action */
22
+ parameters?: Record<string, unknown>;
23
+ /** Legacy alias for parameters; use `parameters` for new callers */
20
24
  params?: Record<string, unknown>;
25
+ /** Outcome of the action when recorded as a workflow step */
26
+ outcome?: BehaviorOutcome;
21
27
  /** Timestamp when action occurred */
22
28
  timestamp?: string;
23
29
  /** Duration in milliseconds (if applicable) */
@@ -48,14 +54,16 @@ export interface BehaviorPattern {
48
54
  user_id: string;
49
55
  /** Natural language description of what triggered this pattern */
50
56
  trigger: string;
51
- /** Vector embedding of the trigger for semantic search (1536 dimensions for text-embedding-3-small) */
57
+ /** OpenAI-compatible trigger embedding for semantic search */
52
58
  trigger_embedding?: number[];
59
+ /** Voyage trigger embedding for semantic search */
60
+ voyage_trigger_embedding?: number[];
53
61
  /** Context when pattern was recorded */
54
62
  context: BehaviorContext;
55
63
  /** Ordered list of actions taken */
56
64
  actions: BehaviorAction[];
57
- /** Description of the final outcome/result */
58
- final_outcome: string;
65
+ /** Final outcome/result classification */
66
+ final_outcome: BehaviorOutcome;
59
67
  /** Confidence score (0-1) indicating pattern reliability */
60
68
  confidence: number;
61
69
  /** Number of times this pattern has been recalled/used */
@@ -79,8 +87,8 @@ export interface RecordBehaviorParams {
79
87
  context?: BehaviorContext;
80
88
  /** Ordered list of actions taken */
81
89
  actions: BehaviorAction[];
82
- /** Description of the final outcome */
83
- final_outcome: string;
90
+ /** Final outcome classification */
91
+ final_outcome: BehaviorOutcome;
84
92
  /** Confidence in this pattern (0-1, default: 0.7) */
85
93
  confidence?: number;
86
94
  }
@@ -91,44 +99,54 @@ export declare const RecordBehaviorParamsSchema: z.ZodObject<{
91
99
  context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
92
100
  actions: z.ZodArray<z.ZodObject<{
93
101
  tool: z.ZodString;
102
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
94
103
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
104
+ outcome: z.ZodEnum<["success", "partial", "failed"]>;
95
105
  timestamp: z.ZodOptional<z.ZodString>;
96
106
  duration_ms: z.ZodOptional<z.ZodNumber>;
97
107
  }, "strip", z.ZodTypeAny, {
98
108
  tool: string;
109
+ outcome: "success" | "partial" | "failed";
99
110
  params?: Record<string, unknown> | undefined;
111
+ parameters?: Record<string, unknown> | undefined;
100
112
  timestamp?: string | undefined;
101
113
  duration_ms?: number | undefined;
102
114
  }, {
103
115
  tool: string;
116
+ outcome: "success" | "partial" | "failed";
104
117
  params?: Record<string, unknown> | undefined;
118
+ parameters?: Record<string, unknown> | undefined;
105
119
  timestamp?: string | undefined;
106
120
  duration_ms?: number | undefined;
107
121
  }>, "many">;
108
- final_outcome: z.ZodString;
122
+ final_outcome: z.ZodEnum<["success", "partial", "failed"]>;
109
123
  confidence: z.ZodDefault<z.ZodNumber>;
110
124
  }, "strip", z.ZodTypeAny, {
111
125
  actions: {
112
126
  tool: string;
127
+ outcome: "success" | "partial" | "failed";
113
128
  params?: Record<string, unknown> | undefined;
129
+ parameters?: Record<string, unknown> | undefined;
114
130
  timestamp?: string | undefined;
115
131
  duration_ms?: number | undefined;
116
132
  }[];
117
133
  user_id: string;
118
134
  trigger: string;
119
- final_outcome: string;
135
+ final_outcome: "success" | "partial" | "failed";
120
136
  confidence: number;
121
137
  context?: Record<string, unknown> | undefined;
122
138
  }, {
123
139
  actions: {
124
140
  tool: string;
141
+ outcome: "success" | "partial" | "failed";
125
142
  params?: Record<string, unknown> | undefined;
143
+ parameters?: Record<string, unknown> | undefined;
126
144
  timestamp?: string | undefined;
127
145
  duration_ms?: number | undefined;
128
146
  }[];
129
147
  user_id: string;
130
148
  trigger: string;
131
- final_outcome: string;
149
+ final_outcome: "success" | "partial" | "failed";
132
150
  context?: Record<string, unknown> | undefined;
133
151
  confidence?: number | undefined;
134
152
  }>;
@@ -223,51 +241,71 @@ export interface SuggestActionParams {
223
241
  /** Description of current task */
224
242
  task_description: string;
225
243
  /** Steps already completed (for predicting next step) */
226
- completed_steps?: BehaviorAction[];
244
+ completed_steps?: string[];
227
245
  /** Optional additional state */
228
246
  [key: string]: unknown;
229
247
  };
230
248
  /** Maximum suggestions to return (default: 3) */
231
249
  max_suggestions?: number;
232
250
  }
233
- /** Zod schema for API validation */
234
251
  export declare const SuggestActionParamsSchema: z.ZodObject<{
235
252
  user_id: z.ZodString;
236
253
  current_state: z.ZodObject<{
237
254
  task_description: z.ZodString;
238
- completed_steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
255
+ completed_steps: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
239
256
  tool: z.ZodString;
257
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
240
258
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
241
259
  }, "strip", z.ZodTypeAny, {
242
260
  tool: string;
243
261
  params?: Record<string, unknown> | undefined;
262
+ parameters?: Record<string, unknown> | undefined;
244
263
  }, {
245
264
  tool: string;
246
265
  params?: Record<string, unknown> | undefined;
266
+ parameters?: Record<string, unknown> | undefined;
267
+ }>]>, string, string | {
268
+ tool: string;
269
+ params?: Record<string, unknown> | undefined;
270
+ parameters?: Record<string, unknown> | undefined;
247
271
  }>, "many">>;
248
272
  }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
249
273
  task_description: z.ZodString;
250
- completed_steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
274
+ completed_steps: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
251
275
  tool: z.ZodString;
276
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
252
277
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
253
278
  }, "strip", z.ZodTypeAny, {
254
279
  tool: string;
255
280
  params?: Record<string, unknown> | undefined;
281
+ parameters?: Record<string, unknown> | undefined;
256
282
  }, {
257
283
  tool: string;
258
284
  params?: Record<string, unknown> | undefined;
285
+ parameters?: Record<string, unknown> | undefined;
286
+ }>]>, string, string | {
287
+ tool: string;
288
+ params?: Record<string, unknown> | undefined;
289
+ parameters?: Record<string, unknown> | undefined;
259
290
  }>, "many">>;
260
291
  }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
261
292
  task_description: z.ZodString;
262
- completed_steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
293
+ completed_steps: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
263
294
  tool: z.ZodString;
295
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
264
296
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
265
297
  }, "strip", z.ZodTypeAny, {
266
298
  tool: string;
267
299
  params?: Record<string, unknown> | undefined;
300
+ parameters?: Record<string, unknown> | undefined;
268
301
  }, {
269
302
  tool: string;
270
303
  params?: Record<string, unknown> | undefined;
304
+ parameters?: Record<string, unknown> | undefined;
305
+ }>]>, string, string | {
306
+ tool: string;
307
+ params?: Record<string, unknown> | undefined;
308
+ parameters?: Record<string, unknown> | undefined;
271
309
  }>, "many">>;
272
310
  }, z.ZodTypeAny, "passthrough">>;
273
311
  max_suggestions: z.ZodDefault<z.ZodNumber>;
@@ -275,10 +313,7 @@ export declare const SuggestActionParamsSchema: z.ZodObject<{
275
313
  user_id: string;
276
314
  current_state: {
277
315
  task_description: string;
278
- completed_steps?: {
279
- tool: string;
280
- params?: Record<string, unknown> | undefined;
281
- }[] | undefined;
316
+ completed_steps?: string[] | undefined;
282
317
  } & {
283
318
  [k: string]: unknown;
284
319
  };
@@ -287,10 +322,11 @@ export declare const SuggestActionParamsSchema: z.ZodObject<{
287
322
  user_id: string;
288
323
  current_state: {
289
324
  task_description: string;
290
- completed_steps?: {
325
+ completed_steps?: (string | {
291
326
  tool: string;
292
327
  params?: Record<string, unknown> | undefined;
293
- }[] | undefined;
328
+ parameters?: Record<string, unknown> | undefined;
329
+ })[] | undefined;
294
330
  } & {
295
331
  [k: string]: unknown;
296
332
  };
@@ -130,11 +130,11 @@ export declare class MemoryIntelligenceClient {
130
130
  * active_files: ["src/components/DataTable.tsx"]
131
131
  * },
132
132
  * actions: [
133
- * { tool: "read_file", params: { path: "src/components/DataTable.tsx" } },
134
- * { tool: "analyze_code", params: { focus: "class_components" } },
135
- * { tool: "edit_file", params: { path: "src/components/DataTable.tsx" } }
133
+ * { tool: "read_file", parameters: { path: "src/components/DataTable.tsx" }, outcome: "success" },
134
+ * { tool: "analyze_code", parameters: { focus: "class_components" }, outcome: "success" },
135
+ * { tool: "edit_file", parameters: { path: "src/components/DataTable.tsx" }, outcome: "success" }
136
136
  * ],
137
- * final_outcome: "Successfully converted class component to functional with hooks"
137
+ * final_outcome: "success"
138
138
  * });
139
139
  *
140
140
  * if (result.data.was_duplicate) {
@@ -180,8 +180,8 @@ export declare class MemoryIntelligenceClient {
180
180
  * current_state: {
181
181
  * task_description: "Implementing user authentication with OAuth",
182
182
  * completed_steps: [
183
- * { tool: "create_file", params: { path: "src/auth/oauth.ts" } },
184
- * { tool: "read_file", params: { path: "package.json" } }
183
+ * "create src/auth/oauth.ts",
184
+ * "inspect package.json"
185
185
  * ]
186
186
  * },
187
187
  * max_suggestions: 3
@@ -240,11 +240,12 @@ var HttpClient = class {
240
240
  clearTimeout(timeoutId);
241
241
  const responseData = await response.json();
242
242
  if (!response.ok) {
243
+ const errorMessage = responseData?.message || responseData?.error?.message || (typeof responseData?.error === "string" ? responseData.error : void 0) || "Request failed";
243
244
  return {
244
245
  status: response.status,
245
246
  error: {
246
- message: responseData?.message || responseData?.error || "Request failed",
247
- code: responseData?.code
247
+ message: errorMessage,
248
+ code: responseData?.code || responseData?.error?.code
248
249
  }
249
250
  };
250
251
  }
@@ -353,6 +354,20 @@ var HttpClient = class {
353
354
 
354
355
  // src/core/client.ts
355
356
  var DEFAULT_API_URL = "https://api.lanonasis.com/api/v1";
357
+ function appendQueryContext(params, context) {
358
+ if (context.organizationId) {
359
+ params.append("organization_id", context.organizationId);
360
+ }
361
+ if (context.topicId) {
362
+ params.append("topic_id", context.topicId);
363
+ }
364
+ if (context.queryScope) {
365
+ params.append("query_scope", context.queryScope);
366
+ }
367
+ for (const memoryType of context.memoryTypes || []) {
368
+ params.append("memory_types", memoryType);
369
+ }
370
+ }
356
371
  var MemoryIntelligenceClient = class {
357
372
  httpClient;
358
373
  defaultResponseFormat;
@@ -402,7 +417,15 @@ var MemoryIntelligenceClient = class {
402
417
  * Query memories from the API
403
418
  */
404
419
  async queryMemories(userId, options = {}) {
405
- const { type, limit = 100, offset = 0 } = options;
420
+ const {
421
+ type,
422
+ limit = 100,
423
+ offset = 0,
424
+ organizationId,
425
+ topicId,
426
+ memoryTypes,
427
+ queryScope
428
+ } = options;
406
429
  const params = new URLSearchParams({
407
430
  user_id: userId,
408
431
  limit: limit.toString(),
@@ -411,7 +434,13 @@ var MemoryIntelligenceClient = class {
411
434
  if (type) {
412
435
  params.append("type", type);
413
436
  }
414
- const response = await this.httpClient.get(
437
+ appendQueryContext(params, {
438
+ organizationId,
439
+ topicId,
440
+ memoryTypes,
441
+ queryScope
442
+ });
443
+ const response = await this.httpClient.getEnhanced(
415
444
  `/intelligence/memories?${params.toString()}`
416
445
  );
417
446
  if (response.error) {
@@ -579,6 +608,9 @@ var MemoryIntelligenceClient = class {
579
608
  "/intelligence/predictive-recall",
580
609
  {
581
610
  userId: params.userId,
611
+ organizationId: params.organizationId,
612
+ topicId: params.topicId,
613
+ queryScope: params.queryScope,
582
614
  context: params.context,
583
615
  limit: params.limit || 5,
584
616
  minConfidence: params.minConfidence || 40,
@@ -635,11 +667,11 @@ var MemoryIntelligenceClient = class {
635
667
  * active_files: ["src/components/DataTable.tsx"]
636
668
  * },
637
669
  * actions: [
638
- * { tool: "read_file", params: { path: "src/components/DataTable.tsx" } },
639
- * { tool: "analyze_code", params: { focus: "class_components" } },
640
- * { tool: "edit_file", params: { path: "src/components/DataTable.tsx" } }
670
+ * { tool: "read_file", parameters: { path: "src/components/DataTable.tsx" }, outcome: "success" },
671
+ * { tool: "analyze_code", parameters: { focus: "class_components" }, outcome: "success" },
672
+ * { tool: "edit_file", parameters: { path: "src/components/DataTable.tsx" }, outcome: "success" }
641
673
  * ],
642
- * final_outcome: "Successfully converted class component to functional with hooks"
674
+ * final_outcome: "success"
643
675
  * });
644
676
  *
645
677
  * if (result.data.was_duplicate) {
@@ -648,13 +680,20 @@ var MemoryIntelligenceClient = class {
648
680
  * ```
649
681
  */
650
682
  async recordBehavior(params) {
683
+ const actions = params.actions.map((action) => ({
684
+ tool: action.tool,
685
+ ...action.parameters || action.params ? { parameters: action.parameters ?? action.params } : {},
686
+ ...action.outcome ? { outcome: action.outcome } : {},
687
+ ...action.timestamp ? { timestamp: action.timestamp } : {},
688
+ ...action.duration_ms !== void 0 ? { duration_ms: action.duration_ms } : {}
689
+ }));
651
690
  const response = await this.httpClient.postEnhanced(
652
691
  "/intelligence/behavior-record",
653
692
  {
654
693
  user_id: params.user_id,
655
694
  trigger: params.trigger,
656
695
  context: params.context || {},
657
- actions: params.actions,
696
+ actions,
658
697
  final_outcome: params.final_outcome,
659
698
  confidence: params.confidence ?? 0.7
660
699
  }
@@ -731,8 +770,8 @@ var MemoryIntelligenceClient = class {
731
770
  * current_state: {
732
771
  * task_description: "Implementing user authentication with OAuth",
733
772
  * completed_steps: [
734
- * { tool: "create_file", params: { path: "src/auth/oauth.ts" } },
735
- * { tool: "read_file", params: { path: "package.json" } }
773
+ * "create src/auth/oauth.ts",
774
+ * "inspect package.json"
736
775
  * ]
737
776
  * },
738
777
  * max_suggestions: 3
@@ -797,8 +836,17 @@ var MemoryType = zod.z.enum([
797
836
  "personal",
798
837
  "workflow"
799
838
  ]);
839
+ var QueryScope = zod.z.enum([
840
+ "personal",
841
+ "team",
842
+ "organization",
843
+ "hybrid"
844
+ ]);
800
845
  var PredictiveRecallParamsSchema = zod.z.object({
801
846
  userId: zod.z.string().uuid(),
847
+ organizationId: zod.z.string().uuid().optional(),
848
+ topicId: zod.z.string().optional(),
849
+ queryScope: QueryScope.optional(),
802
850
  context: zod.z.object({
803
851
  currentProject: zod.z.string().optional(),
804
852
  recentTopics: zod.z.array(zod.z.string()).optional(),
@@ -835,17 +883,20 @@ var DEFAULT_SCORING_CONFIG = {
835
883
  // Not too different
836
884
  }
837
885
  };
886
+ var BehaviorOutcomeValues = ["success", "partial", "failed"];
838
887
  var RecordBehaviorParamsSchema = zod.z.object({
839
888
  user_id: zod.z.string().uuid(),
840
889
  trigger: zod.z.string().min(1, "Trigger description is required"),
841
890
  context: zod.z.record(zod.z.unknown()).optional(),
842
891
  actions: zod.z.array(zod.z.object({
843
892
  tool: zod.z.string(),
893
+ parameters: zod.z.record(zod.z.unknown()).optional(),
844
894
  params: zod.z.record(zod.z.unknown()).optional(),
895
+ outcome: zod.z.enum(BehaviorOutcomeValues),
845
896
  timestamp: zod.z.string().optional(),
846
897
  duration_ms: zod.z.number().optional()
847
898
  })).min(1, "At least one action is required"),
848
- final_outcome: zod.z.string().min(1, "Final outcome is required"),
899
+ final_outcome: zod.z.enum(BehaviorOutcomeValues),
849
900
  confidence: zod.z.number().min(0).max(1).default(0.7)
850
901
  });
851
902
  var RecallBehaviorParamsSchema = zod.z.object({
@@ -856,18 +907,24 @@ var RecallBehaviorParamsSchema = zod.z.object({
856
907
  limit: zod.z.number().int().min(1).max(20).default(5),
857
908
  similarity_threshold: zod.z.number().min(0).max(1).default(0.7)
858
909
  });
910
+ var SuggestActionStepSchema = zod.z.union([
911
+ zod.z.string().min(1, "Completed step must be a non-empty string"),
912
+ zod.z.object({
913
+ tool: zod.z.string().min(1, "Legacy step objects must include tool"),
914
+ parameters: zod.z.record(zod.z.unknown()).optional(),
915
+ params: zod.z.record(zod.z.unknown()).optional()
916
+ })
917
+ ]).transform((step) => typeof step === "string" ? step : step.tool);
859
918
  var SuggestActionParamsSchema = zod.z.object({
860
919
  user_id: zod.z.string().uuid(),
861
920
  current_state: zod.z.object({
862
921
  task_description: zod.z.string().min(1, "Task description is required"),
863
- completed_steps: zod.z.array(zod.z.object({
864
- tool: zod.z.string(),
865
- params: zod.z.record(zod.z.unknown()).optional()
866
- })).optional()
922
+ completed_steps: zod.z.array(SuggestActionStepSchema).optional()
867
923
  }).passthrough(),
868
924
  max_suggestions: zod.z.number().int().min(1).max(10).default(3)
869
925
  });
870
926
 
927
+ exports.BehaviorOutcomeValues = BehaviorOutcomeValues;
871
928
  exports.ConfigurationError = ConfigurationError;
872
929
  exports.DEFAULT_SCORING_CONFIG = DEFAULT_SCORING_CONFIG;
873
930
  exports.DatabaseError = DatabaseError;
@@ -877,6 +934,7 @@ exports.MemoryIntelligenceError = MemoryIntelligenceError;
877
934
  exports.MemoryNotFoundError = MemoryNotFoundError;
878
935
  exports.MemoryType = MemoryType;
879
936
  exports.PredictiveRecallParamsSchema = PredictiveRecallParamsSchema;
937
+ exports.QueryScope = QueryScope;
880
938
  exports.RecallBehaviorParamsSchema = RecallBehaviorParamsSchema;
881
939
  exports.RecordBehaviorParamsSchema = RecordBehaviorParamsSchema;
882
940
  exports.ResponseFormat = ResponseFormat;