@lanonasis/mem-intel-sdk 1.0.0 → 1.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 +16 -0
- package/README.md +50 -21
- package/dist/core/client.d.ts +29 -8
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/index.cjs +251 -13
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +251 -13
- package/dist/core/index.js.map +1 -1
- package/dist/core/types.d.ts +36 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index-sdk.d.ts +5 -3
- package/dist/index-sdk.d.ts.map +1 -1
- package/dist/index.cjs +251 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +251 -13
- package/dist/index.js.map +1 -1
- package/dist/node/client.d.ts +2 -2
- package/dist/node/client.d.ts.map +1 -1
- package/dist/node/index.cjs +251 -13
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +251 -13
- package/dist/node/index.js.map +1 -1
- package/dist/react/context/MemoryIntelligenceProvider.d.ts +2 -2
- package/dist/react/context/MemoryIntelligenceProvider.d.ts.map +1 -1
- package/dist/react/hooks/useMemoryIntelligence.d.ts +13 -12
- package/dist/react/hooks/useMemoryIntelligence.d.ts.map +1 -1
- package/dist/react/index.cjs +254 -19
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +254 -19
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +272 -27
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +272 -27
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp-server.d.ts +1 -1
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/utils/embeddings.d.ts +1 -1
- package/dist/utils/embeddings.d.ts.map +1 -1
- package/dist/utils/formatting.d.ts +1 -1
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/http-client.d.ts +35 -0
- package/dist/utils/http-client.d.ts.map +1 -1
- package/dist/utils/index.d.ts +7 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/response-adapter.d.ts +66 -0
- package/dist/utils/response-adapter.d.ts.map +1 -0
- package/dist/vue/composables/useMemoryIntelligence.d.ts +1 -1
- package/dist/vue/composables/useMemoryIntelligence.d.ts.map +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.ts +3 -3
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* React hooks for Memory Intelligence using React Query
|
|
3
3
|
*/
|
|
4
4
|
import { UseQueryOptions, UseMutationOptions } from "@tanstack/react-query";
|
|
5
|
-
import { PatternAnalysis, TagSuggestionsResult, RelatedMemoriesResult, DuplicatesResult, InsightsResult, MemoryHealth, AnalyzePatternsParams, SuggestTagsParams, FindRelatedParams, DetectDuplicatesParams, ExtractInsightsParams, HealthCheckParams } from "../../core/types";
|
|
5
|
+
import { PatternAnalysis, TagSuggestionsResult, RelatedMemoriesResult, DuplicatesResult, InsightsResult, MemoryHealth, AnalyzePatternsParams, SuggestTagsParams, FindRelatedParams, DetectDuplicatesParams, ExtractInsightsParams, HealthCheckParams } from "../../core/types.js";
|
|
6
|
+
import type { IntelligenceResponse } from "../../core/client.js";
|
|
6
7
|
/**
|
|
7
8
|
* Get the Memory Intelligence client from context
|
|
8
9
|
*/
|
|
9
|
-
export declare function useMemoryIntelligence(): import("../../index-sdk").MemoryIntelligenceClient;
|
|
10
|
+
export declare function useMemoryIntelligence(): import("../../index-sdk.js").MemoryIntelligenceClient;
|
|
10
11
|
/**
|
|
11
12
|
* Hook for analyzing memory patterns
|
|
12
13
|
*
|
|
@@ -19,7 +20,7 @@ export declare function useMemoryIntelligence(): import("../../index-sdk").Memor
|
|
|
19
20
|
* });
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
|
-
export declare function usePatternAnalysis(params: AnalyzePatternsParams, options?: Omit<UseQueryOptions<PatternAnalysis
|
|
23
|
+
export declare function usePatternAnalysis(params: AnalyzePatternsParams, options?: Omit<UseQueryOptions<IntelligenceResponse<PatternAnalysis>>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<IntelligenceResponse<PatternAnalysis>, Error>;
|
|
23
24
|
/**
|
|
24
25
|
* Hook for getting tag suggestions
|
|
25
26
|
*
|
|
@@ -32,7 +33,7 @@ export declare function usePatternAnalysis(params: AnalyzePatternsParams, option
|
|
|
32
33
|
* });
|
|
33
34
|
* ```
|
|
34
35
|
*/
|
|
35
|
-
export declare function useTagSuggestions(params: SuggestTagsParams, options?: Omit<UseQueryOptions<TagSuggestionsResult
|
|
36
|
+
export declare function useTagSuggestions(params: SuggestTagsParams, options?: Omit<UseQueryOptions<IntelligenceResponse<TagSuggestionsResult>>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<IntelligenceResponse<TagSuggestionsResult>, Error>;
|
|
36
37
|
/**
|
|
37
38
|
* Mutation hook for getting tag suggestions (if you need manual trigger)
|
|
38
39
|
*
|
|
@@ -47,7 +48,7 @@ export declare function useTagSuggestions(params: SuggestTagsParams, options?: O
|
|
|
47
48
|
* });
|
|
48
49
|
* ```
|
|
49
50
|
*/
|
|
50
|
-
export declare function useTagSuggestionsMutation(options?: UseMutationOptions<TagSuggestionsResult
|
|
51
|
+
export declare function useTagSuggestionsMutation(options?: UseMutationOptions<IntelligenceResponse<TagSuggestionsResult>, Error, SuggestTagsParams>): import("@tanstack/react-query").UseMutationResult<IntelligenceResponse<TagSuggestionsResult>, Error, SuggestTagsParams, unknown>;
|
|
51
52
|
/**
|
|
52
53
|
* Hook for finding related memories
|
|
53
54
|
*
|
|
@@ -61,7 +62,7 @@ export declare function useTagSuggestionsMutation(options?: UseMutationOptions<T
|
|
|
61
62
|
* });
|
|
62
63
|
* ```
|
|
63
64
|
*/
|
|
64
|
-
export declare function useRelatedMemories(params: FindRelatedParams, options?: Omit<UseQueryOptions<RelatedMemoriesResult
|
|
65
|
+
export declare function useRelatedMemories(params: FindRelatedParams, options?: Omit<UseQueryOptions<IntelligenceResponse<RelatedMemoriesResult>>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<IntelligenceResponse<RelatedMemoriesResult>, Error>;
|
|
65
66
|
/**
|
|
66
67
|
* Hook for detecting duplicate memories
|
|
67
68
|
*
|
|
@@ -74,11 +75,11 @@ export declare function useRelatedMemories(params: FindRelatedParams, options?:
|
|
|
74
75
|
* });
|
|
75
76
|
* ```
|
|
76
77
|
*/
|
|
77
|
-
export declare function useDuplicateDetection(params: DetectDuplicatesParams, options?: Omit<UseQueryOptions<DuplicatesResult
|
|
78
|
+
export declare function useDuplicateDetection(params: DetectDuplicatesParams, options?: Omit<UseQueryOptions<IntelligenceResponse<DuplicatesResult>>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<IntelligenceResponse<DuplicatesResult>, Error>;
|
|
78
79
|
/**
|
|
79
80
|
* Mutation hook for duplicate detection (if you need manual trigger)
|
|
80
81
|
*/
|
|
81
|
-
export declare function useDuplicateDetectionMutation(options?: UseMutationOptions<DuplicatesResult
|
|
82
|
+
export declare function useDuplicateDetectionMutation(options?: UseMutationOptions<IntelligenceResponse<DuplicatesResult>, Error, DetectDuplicatesParams>): import("@tanstack/react-query").UseMutationResult<IntelligenceResponse<DuplicatesResult>, Error, DetectDuplicatesParams, unknown>;
|
|
82
83
|
/**
|
|
83
84
|
* Hook for extracting insights
|
|
84
85
|
*
|
|
@@ -91,11 +92,11 @@ export declare function useDuplicateDetectionMutation(options?: UseMutationOptio
|
|
|
91
92
|
* });
|
|
92
93
|
* ```
|
|
93
94
|
*/
|
|
94
|
-
export declare function useInsightExtraction(params: ExtractInsightsParams, options?: Omit<UseQueryOptions<InsightsResult
|
|
95
|
+
export declare function useInsightExtraction(params: ExtractInsightsParams, options?: Omit<UseQueryOptions<IntelligenceResponse<InsightsResult>>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<IntelligenceResponse<InsightsResult>, Error>;
|
|
95
96
|
/**
|
|
96
97
|
* Mutation hook for insight extraction (if you need manual trigger)
|
|
97
98
|
*/
|
|
98
|
-
export declare function useInsightExtractionMutation(options?: UseMutationOptions<InsightsResult
|
|
99
|
+
export declare function useInsightExtractionMutation(options?: UseMutationOptions<IntelligenceResponse<InsightsResult>, Error, ExtractInsightsParams>): import("@tanstack/react-query").UseMutationResult<IntelligenceResponse<InsightsResult>, Error, ExtractInsightsParams, unknown>;
|
|
99
100
|
/**
|
|
100
101
|
* Hook for checking memory health
|
|
101
102
|
*
|
|
@@ -107,9 +108,9 @@ export declare function useInsightExtractionMutation(options?: UseMutationOption
|
|
|
107
108
|
* });
|
|
108
109
|
* ```
|
|
109
110
|
*/
|
|
110
|
-
export declare function useHealthCheck(params: HealthCheckParams, options?: Omit<UseQueryOptions<MemoryHealth
|
|
111
|
+
export declare function useHealthCheck(params: HealthCheckParams, options?: Omit<UseQueryOptions<IntelligenceResponse<MemoryHealth>>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<IntelligenceResponse<MemoryHealth>, Error>;
|
|
111
112
|
/**
|
|
112
113
|
* Mutation hook for health check (if you need manual trigger)
|
|
113
114
|
*/
|
|
114
|
-
export declare function useHealthCheckMutation(options?: UseMutationOptions<MemoryHealth
|
|
115
|
+
export declare function useHealthCheckMutation(options?: UseMutationOptions<IntelligenceResponse<MemoryHealth>, Error, HealthCheckParams>): import("@tanstack/react-query").UseMutationResult<IntelligenceResponse<MemoryHealth>, Error, HealthCheckParams, unknown>;
|
|
115
116
|
//# sourceMappingURL=useMemoryIntelligence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMemoryIntelligence.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMemoryIntelligence.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAyB,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEnG,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,
|
|
1
|
+
{"version":3,"file":"useMemoryIntelligence.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMemoryIntelligence.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAyB,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEnG,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;GAEG;AACH,wBAAgB,qBAAqB,0DAGpC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,qBAAqB,EAC7B,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,gGAS/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,qGASpG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,CAAC,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,oIAQnG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,qBAAqB,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,sGASrG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,iGAShG;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,CAAC,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,qIAQpG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,qBAAqB,EAC7B,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,+FAS9F;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,CAAC,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,kIAQjG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,6FAS5F;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,kBAAkB,CAAC,oBAAoB,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,4HAQ3F"}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
5
|
var reactQuery = require('@tanstack/react-query');
|
|
5
6
|
var zod = require('zod');
|
|
6
7
|
|
|
@@ -50,12 +51,120 @@ var ValidationError = class extends MemoryIntelligenceError {
|
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
// src/utils/response-adapter.ts
|
|
55
|
+
function adaptEdgeFunctionResponse(httpResponse) {
|
|
56
|
+
if (httpResponse.error) {
|
|
57
|
+
return {
|
|
58
|
+
status: httpResponse.status,
|
|
59
|
+
error: httpResponse.error
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const envelope = httpResponse.data;
|
|
63
|
+
if (!envelope) {
|
|
64
|
+
return {
|
|
65
|
+
status: httpResponse.status,
|
|
66
|
+
error: {
|
|
67
|
+
message: "Empty response from server",
|
|
68
|
+
code: "EMPTY_RESPONSE"
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (!envelope.success && envelope.error) {
|
|
73
|
+
return {
|
|
74
|
+
status: httpResponse.status,
|
|
75
|
+
error: envelope.error,
|
|
76
|
+
usage: envelope.usage,
|
|
77
|
+
tier_info: envelope.tier_info
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
status: httpResponse.status,
|
|
82
|
+
data: envelope.data,
|
|
83
|
+
usage: envelope.usage,
|
|
84
|
+
tier_info: envelope.tier_info
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function isEdgeFunctionEnvelope(data) {
|
|
88
|
+
if (typeof data !== "object" || data === null) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const obj = data;
|
|
92
|
+
return "success" in obj && typeof obj.success === "boolean";
|
|
93
|
+
}
|
|
94
|
+
function adaptResponse(httpResponse) {
|
|
95
|
+
if (httpResponse.error) {
|
|
96
|
+
return {
|
|
97
|
+
status: httpResponse.status,
|
|
98
|
+
error: httpResponse.error
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const responseData = httpResponse.data;
|
|
102
|
+
if (isEdgeFunctionEnvelope(responseData)) {
|
|
103
|
+
return adaptEdgeFunctionResponse({
|
|
104
|
+
status: httpResponse.status,
|
|
105
|
+
data: responseData
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
status: httpResponse.status,
|
|
110
|
+
data: responseData
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var ResponseCache = class {
|
|
114
|
+
cache = /* @__PURE__ */ new Map();
|
|
115
|
+
ttl;
|
|
116
|
+
constructor(ttlMs = 3e5) {
|
|
117
|
+
this.ttl = ttlMs;
|
|
118
|
+
}
|
|
119
|
+
generateKey(endpoint, params) {
|
|
120
|
+
const paramStr = params ? JSON.stringify(params) : "";
|
|
121
|
+
return `${endpoint}:${paramStr}`;
|
|
122
|
+
}
|
|
123
|
+
set(endpoint, data, params) {
|
|
124
|
+
const key = this.generateKey(endpoint, params);
|
|
125
|
+
this.cache.set(key, {
|
|
126
|
+
data,
|
|
127
|
+
timestamp: Date.now(),
|
|
128
|
+
endpoint,
|
|
129
|
+
params
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
get(endpoint, params) {
|
|
133
|
+
const key = this.generateKey(endpoint, params);
|
|
134
|
+
const entry = this.cache.get(key);
|
|
135
|
+
if (!entry) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
if (Date.now() - entry.timestamp > this.ttl) {
|
|
139
|
+
this.cache.delete(key);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return entry.data;
|
|
143
|
+
}
|
|
144
|
+
clear() {
|
|
145
|
+
this.cache.clear();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Clean up expired entries
|
|
149
|
+
*/
|
|
150
|
+
cleanup() {
|
|
151
|
+
const now = Date.now();
|
|
152
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
153
|
+
if (now - entry.timestamp > this.ttl) {
|
|
154
|
+
this.cache.delete(key);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
53
160
|
// src/utils/http-client.ts
|
|
54
161
|
var HttpClient = class {
|
|
55
162
|
apiUrl;
|
|
56
163
|
apiKey;
|
|
57
164
|
timeout;
|
|
58
165
|
headers;
|
|
166
|
+
processingMode;
|
|
167
|
+
cache;
|
|
59
168
|
constructor(config) {
|
|
60
169
|
if (!config.apiKey) {
|
|
61
170
|
throw new ConfigurationError("API key is required");
|
|
@@ -68,11 +177,35 @@ var HttpClient = class {
|
|
|
68
177
|
this.apiUrl = config.apiUrl.replace(/\/$/, "");
|
|
69
178
|
this.apiKey = config.apiKey;
|
|
70
179
|
this.timeout = config.timeout || 3e4;
|
|
180
|
+
this.processingMode = config.processingMode || "api";
|
|
71
181
|
this.headers = {
|
|
72
182
|
"Content-Type": "application/json",
|
|
73
183
|
"X-API-Key": this.apiKey,
|
|
74
184
|
...config.headers
|
|
75
185
|
};
|
|
186
|
+
if (config.enableCache !== false && this.processingMode === "offline-fallback") {
|
|
187
|
+
this.cache = new ResponseCache(config.cacheTTL || 3e5);
|
|
188
|
+
} else {
|
|
189
|
+
this.cache = null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get the current processing mode
|
|
194
|
+
*/
|
|
195
|
+
getProcessingMode() {
|
|
196
|
+
return this.processingMode;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Check if cache is enabled
|
|
200
|
+
*/
|
|
201
|
+
isCacheEnabled() {
|
|
202
|
+
return this.cache !== null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Clear the response cache
|
|
206
|
+
*/
|
|
207
|
+
clearCache() {
|
|
208
|
+
this.cache?.clear();
|
|
76
209
|
}
|
|
77
210
|
async request(method, endpoint, data) {
|
|
78
211
|
const url = `${this.apiUrl}${endpoint}`;
|
|
@@ -132,6 +265,43 @@ var HttpClient = class {
|
|
|
132
265
|
};
|
|
133
266
|
}
|
|
134
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Enhanced request that handles Edge Function envelope format
|
|
270
|
+
* and supports offline-fallback caching
|
|
271
|
+
*/
|
|
272
|
+
async enhancedRequest(method, endpoint, data) {
|
|
273
|
+
const cacheKey = data ? JSON.stringify(data) : void 0;
|
|
274
|
+
const rawResponse = await this.request(method, endpoint, data);
|
|
275
|
+
if (rawResponse.error?.code === "NETWORK_ERROR" || rawResponse.error?.code === "TIMEOUT") {
|
|
276
|
+
if (this.processingMode === "offline-fallback" && this.cache) {
|
|
277
|
+
const cached = this.cache.get(endpoint, cacheKey ? JSON.parse(cacheKey) : void 0);
|
|
278
|
+
if (cached) {
|
|
279
|
+
return {
|
|
280
|
+
status: 200,
|
|
281
|
+
data: cached,
|
|
282
|
+
fromCache: true
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
status: rawResponse.status,
|
|
288
|
+
error: rawResponse.error,
|
|
289
|
+
fromCache: false
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
const adapted = adaptResponse(rawResponse);
|
|
293
|
+
if (!adapted.error && adapted.data && this.cache) {
|
|
294
|
+
this.cache.set(endpoint, adapted.data, cacheKey ? JSON.parse(cacheKey) : void 0);
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
status: adapted.status,
|
|
298
|
+
data: adapted.data,
|
|
299
|
+
error: adapted.error,
|
|
300
|
+
usage: adapted.usage,
|
|
301
|
+
tier_info: adapted.tier_info,
|
|
302
|
+
fromCache: false
|
|
303
|
+
};
|
|
304
|
+
}
|
|
135
305
|
async get(endpoint) {
|
|
136
306
|
return this.request("GET", endpoint);
|
|
137
307
|
}
|
|
@@ -147,6 +317,22 @@ var HttpClient = class {
|
|
|
147
317
|
async delete(endpoint) {
|
|
148
318
|
return this.request("DELETE", endpoint);
|
|
149
319
|
}
|
|
320
|
+
// Enhanced methods with Edge Function envelope support
|
|
321
|
+
async getEnhanced(endpoint) {
|
|
322
|
+
return this.enhancedRequest("GET", endpoint);
|
|
323
|
+
}
|
|
324
|
+
async postEnhanced(endpoint, data) {
|
|
325
|
+
return this.enhancedRequest("POST", endpoint, data);
|
|
326
|
+
}
|
|
327
|
+
async putEnhanced(endpoint, data) {
|
|
328
|
+
return this.enhancedRequest("PUT", endpoint, data);
|
|
329
|
+
}
|
|
330
|
+
async patchEnhanced(endpoint, data) {
|
|
331
|
+
return this.enhancedRequest("PATCH", endpoint, data);
|
|
332
|
+
}
|
|
333
|
+
async deleteEnhanced(endpoint) {
|
|
334
|
+
return this.enhancedRequest("DELETE", endpoint);
|
|
335
|
+
}
|
|
150
336
|
};
|
|
151
337
|
|
|
152
338
|
// src/core/client.ts
|
|
@@ -154,20 +340,43 @@ var DEFAULT_API_URL = "https://api.lanonasis.com/api/v1";
|
|
|
154
340
|
var MemoryIntelligenceClient = class {
|
|
155
341
|
httpClient;
|
|
156
342
|
defaultResponseFormat;
|
|
343
|
+
processingMode;
|
|
157
344
|
constructor(config) {
|
|
158
345
|
if (!config.apiKey) {
|
|
159
346
|
throw new ConfigurationError(
|
|
160
347
|
"Missing required configuration: apiKey is required (format: lano_xxxxxxxxxx)"
|
|
161
348
|
);
|
|
162
349
|
}
|
|
350
|
+
this.processingMode = config.processingMode || "api";
|
|
163
351
|
this.httpClient = new HttpClient({
|
|
164
352
|
apiUrl: config.apiUrl || DEFAULT_API_URL,
|
|
165
353
|
apiKey: config.apiKey,
|
|
166
354
|
timeout: config.timeout,
|
|
167
|
-
headers: config.headers
|
|
355
|
+
headers: config.headers,
|
|
356
|
+
processingMode: this.processingMode,
|
|
357
|
+
enableCache: config.enableCache,
|
|
358
|
+
cacheTTL: config.cacheTTL
|
|
168
359
|
});
|
|
169
360
|
this.defaultResponseFormat = config.responseFormat || "markdown";
|
|
170
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Get the current processing mode
|
|
364
|
+
*/
|
|
365
|
+
getProcessingMode() {
|
|
366
|
+
return this.processingMode;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Check if cache is enabled (for offline-fallback mode)
|
|
370
|
+
*/
|
|
371
|
+
isCacheEnabled() {
|
|
372
|
+
return this.httpClient.isCacheEnabled();
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Clear the response cache
|
|
376
|
+
*/
|
|
377
|
+
clearCache() {
|
|
378
|
+
this.httpClient.clearCache();
|
|
379
|
+
}
|
|
171
380
|
/**
|
|
172
381
|
* Get HTTP client for direct API access
|
|
173
382
|
*/
|
|
@@ -199,7 +408,7 @@ var MemoryIntelligenceClient = class {
|
|
|
199
408
|
* Analyze usage patterns and trends in memory collection
|
|
200
409
|
*/
|
|
201
410
|
async analyzePatterns(params) {
|
|
202
|
-
const response = await this.httpClient.
|
|
411
|
+
const response = await this.httpClient.postEnhanced(
|
|
203
412
|
"/intelligence/analyze-patterns",
|
|
204
413
|
{
|
|
205
414
|
...params,
|
|
@@ -209,13 +418,18 @@ var MemoryIntelligenceClient = class {
|
|
|
209
418
|
if (response.error) {
|
|
210
419
|
throw new DatabaseError(`Failed to analyze patterns: ${response.error.message}`);
|
|
211
420
|
}
|
|
212
|
-
return
|
|
421
|
+
return {
|
|
422
|
+
data: response.data,
|
|
423
|
+
usage: response.usage,
|
|
424
|
+
tier_info: response.tier_info,
|
|
425
|
+
fromCache: response.fromCache
|
|
426
|
+
};
|
|
213
427
|
}
|
|
214
428
|
/**
|
|
215
429
|
* Get AI-powered tag suggestions for a memory
|
|
216
430
|
*/
|
|
217
431
|
async suggestTags(params) {
|
|
218
|
-
const response = await this.httpClient.
|
|
432
|
+
const response = await this.httpClient.postEnhanced(
|
|
219
433
|
"/intelligence/suggest-tags",
|
|
220
434
|
{
|
|
221
435
|
...params,
|
|
@@ -225,13 +439,18 @@ var MemoryIntelligenceClient = class {
|
|
|
225
439
|
if (response.error) {
|
|
226
440
|
throw new DatabaseError(`Failed to suggest tags: ${response.error.message}`);
|
|
227
441
|
}
|
|
228
|
-
return
|
|
442
|
+
return {
|
|
443
|
+
data: response.data,
|
|
444
|
+
usage: response.usage,
|
|
445
|
+
tier_info: response.tier_info,
|
|
446
|
+
fromCache: response.fromCache
|
|
447
|
+
};
|
|
229
448
|
}
|
|
230
449
|
/**
|
|
231
450
|
* Find semantically related memories using vector similarity
|
|
232
451
|
*/
|
|
233
452
|
async findRelated(params) {
|
|
234
|
-
const response = await this.httpClient.
|
|
453
|
+
const response = await this.httpClient.postEnhanced(
|
|
235
454
|
"/intelligence/find-related",
|
|
236
455
|
{
|
|
237
456
|
...params,
|
|
@@ -241,13 +460,18 @@ var MemoryIntelligenceClient = class {
|
|
|
241
460
|
if (response.error) {
|
|
242
461
|
throw new DatabaseError(`Failed to find related memories: ${response.error.message}`);
|
|
243
462
|
}
|
|
244
|
-
return
|
|
463
|
+
return {
|
|
464
|
+
data: response.data,
|
|
465
|
+
usage: response.usage,
|
|
466
|
+
tier_info: response.tier_info,
|
|
467
|
+
fromCache: response.fromCache
|
|
468
|
+
};
|
|
245
469
|
}
|
|
246
470
|
/**
|
|
247
471
|
* Detect potential duplicate memories
|
|
248
472
|
*/
|
|
249
473
|
async detectDuplicates(params) {
|
|
250
|
-
const response = await this.httpClient.
|
|
474
|
+
const response = await this.httpClient.postEnhanced(
|
|
251
475
|
"/intelligence/detect-duplicates",
|
|
252
476
|
{
|
|
253
477
|
...params,
|
|
@@ -257,13 +481,18 @@ var MemoryIntelligenceClient = class {
|
|
|
257
481
|
if (response.error) {
|
|
258
482
|
throw new DatabaseError(`Failed to detect duplicates: ${response.error.message}`);
|
|
259
483
|
}
|
|
260
|
-
return
|
|
484
|
+
return {
|
|
485
|
+
data: response.data,
|
|
486
|
+
usage: response.usage,
|
|
487
|
+
tier_info: response.tier_info,
|
|
488
|
+
fromCache: response.fromCache
|
|
489
|
+
};
|
|
261
490
|
}
|
|
262
491
|
/**
|
|
263
492
|
* Extract insights and patterns from memories
|
|
264
493
|
*/
|
|
265
494
|
async extractInsights(params) {
|
|
266
|
-
const response = await this.httpClient.
|
|
495
|
+
const response = await this.httpClient.postEnhanced(
|
|
267
496
|
"/intelligence/extract-insights",
|
|
268
497
|
{
|
|
269
498
|
...params,
|
|
@@ -273,13 +502,18 @@ var MemoryIntelligenceClient = class {
|
|
|
273
502
|
if (response.error) {
|
|
274
503
|
throw new DatabaseError(`Failed to extract insights: ${response.error.message}`);
|
|
275
504
|
}
|
|
276
|
-
return
|
|
505
|
+
return {
|
|
506
|
+
data: response.data,
|
|
507
|
+
usage: response.usage,
|
|
508
|
+
tier_info: response.tier_info,
|
|
509
|
+
fromCache: response.fromCache
|
|
510
|
+
};
|
|
277
511
|
}
|
|
278
512
|
/**
|
|
279
513
|
* Check the health and organization quality of memories
|
|
280
514
|
*/
|
|
281
515
|
async healthCheck(params) {
|
|
282
|
-
const response = await this.httpClient.
|
|
516
|
+
const response = await this.httpClient.postEnhanced(
|
|
283
517
|
"/intelligence/health-check",
|
|
284
518
|
{
|
|
285
519
|
...params,
|
|
@@ -289,20 +523,21 @@ var MemoryIntelligenceClient = class {
|
|
|
289
523
|
if (response.error) {
|
|
290
524
|
throw new DatabaseError(`Failed to check health: ${response.error.message}`);
|
|
291
525
|
}
|
|
292
|
-
return
|
|
526
|
+
return {
|
|
527
|
+
data: response.data,
|
|
528
|
+
usage: response.usage,
|
|
529
|
+
tier_info: response.tier_info,
|
|
530
|
+
fromCache: response.fromCache
|
|
531
|
+
};
|
|
293
532
|
}
|
|
294
533
|
};
|
|
295
|
-
|
|
296
|
-
// src/react/context/MemoryIntelligenceProvider.tsx
|
|
297
|
-
var MemoryIntelligenceContext = React.createContext(
|
|
298
|
-
null
|
|
299
|
-
);
|
|
534
|
+
var MemoryIntelligenceContext = React.createContext(null);
|
|
300
535
|
function MemoryIntelligenceProvider({
|
|
301
536
|
config,
|
|
302
537
|
children
|
|
303
538
|
}) {
|
|
304
539
|
const [client] = React__default.default.useState(() => new MemoryIntelligenceClient(config));
|
|
305
|
-
return /* @__PURE__ */
|
|
540
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MemoryIntelligenceContext.Provider, { value: { client }, children });
|
|
306
541
|
}
|
|
307
542
|
function useMemoryIntelligenceContext() {
|
|
308
543
|
const context = React.useContext(MemoryIntelligenceContext);
|