@rezzed.ai/memory 0.1.0 → 0.2.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 +196 -87
- package/dist/index.d.cts +53 -11
- package/dist/index.d.ts +53 -11
- package/dist/index.js +93 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @rezzed.ai/memory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight TypeScript client for storing and recalling learned patterns via CacheBash.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @rezzed.ai/memory
|
|
@@ -16,10 +16,8 @@ import { CacheBashMemory } from "@rezzed.ai/memory";
|
|
|
16
16
|
const memory = new CacheBashMemory({
|
|
17
17
|
apiKey: "your-api-key",
|
|
18
18
|
programId: "your-program-id",
|
|
19
|
-
endpoint: "https://api.cachebash.dev/v1/mcp", // optional, this is the default
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
// Store a memory pattern
|
|
23
21
|
await memory.store({
|
|
24
22
|
id: "pattern-001",
|
|
25
23
|
domain: "workflow",
|
|
@@ -28,121 +26,232 @@ await memory.store({
|
|
|
28
26
|
evidence: "Prevented 3 runtime errors in production",
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const patterns = await memory.recall({ domain: "workflow" });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Reference
|
|
33
|
+
|
|
34
|
+
### Constructor
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
new CacheBashMemory(config: CacheBashMemoryConfig)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Parameter | Type | Required | Description |
|
|
41
|
+
| ----------- | --------------- | -------- | ------------------------------------------------ |
|
|
42
|
+
| `apiKey` | `string` | Yes | Your CacheBash API key |
|
|
43
|
+
| `programId` | `string` | Yes | Program ID for memory isolation |
|
|
44
|
+
| `transport` | `"rest" \| "mcp"` | No | Transport mode (default: `"rest"`) |
|
|
45
|
+
| `endpoint` | `string` | No | Custom API endpoint URL |
|
|
46
|
+
|
|
47
|
+
### `store(input: StorePatternInput): Promise<void>`
|
|
48
|
+
|
|
49
|
+
Store or update a memory pattern. If a pattern with the same `id` exists, it will be replaced.
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
```typescript
|
|
52
|
+
await memory.store({
|
|
53
|
+
id: "p-001",
|
|
54
|
+
domain: "security",
|
|
55
|
+
pattern: "Rate-limit all public endpoints",
|
|
56
|
+
confidence: 0.92,
|
|
57
|
+
evidence: "Blocked 3 brute-force attempts",
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**StorePatternInput fields:**
|
|
62
|
+
|
|
63
|
+
| Field | Type | Description |
|
|
64
|
+
| ------------ | -------- | -------------------------------------- |
|
|
65
|
+
| `id` | `string` | Unique pattern identifier |
|
|
66
|
+
| `domain` | `string` | Domain category (e.g. "security") |
|
|
67
|
+
| `pattern` | `string` | The learned pattern or rule |
|
|
68
|
+
| `confidence` | `number` | Confidence score (0-1) |
|
|
69
|
+
| `evidence` | `string` | Supporting evidence or context |
|
|
70
|
+
|
|
71
|
+
### `recall(options?: RecallOptions): Promise<MemoryPattern[]>`
|
|
72
|
+
|
|
73
|
+
Recall memory patterns with optional filters. Excludes stale patterns by default.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const all = await memory.recall();
|
|
77
|
+
const security = await memory.recall({ domain: "security" });
|
|
78
|
+
const search = await memory.recall({ search: "rate-limit" });
|
|
79
|
+
const withStale = await memory.recall({ includeStale: true });
|
|
80
|
+
```
|
|
37
81
|
|
|
38
|
-
|
|
39
|
-
const searchResults = await memory.recall({ search: "validate" });
|
|
82
|
+
**RecallOptions:**
|
|
40
83
|
|
|
41
|
-
|
|
84
|
+
| Field | Type | Description |
|
|
85
|
+
| -------------- | --------- | ----------------------------------- |
|
|
86
|
+
| `domain` | `string` | Filter by domain |
|
|
87
|
+
| `search` | `string` | Text search across pattern/evidence |
|
|
88
|
+
| `includeStale` | `boolean` | Include stale patterns (default: false) |
|
|
89
|
+
|
|
90
|
+
**Returns:** `MemoryPattern[]`
|
|
91
|
+
|
|
92
|
+
### `health(): Promise<MemoryHealth>`
|
|
93
|
+
|
|
94
|
+
Get memory health statistics.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
42
97
|
const health = await memory.health();
|
|
43
|
-
console.log(health);
|
|
44
|
-
// {
|
|
45
|
-
// totalPatterns: 42,
|
|
46
|
-
// promotedPatterns: 5,
|
|
47
|
-
// stalePatterns: 2,
|
|
48
|
-
// domains: ["workflow", "security", "performance"],
|
|
49
|
-
// avgConfidence: 0.87,
|
|
50
|
-
// ...
|
|
51
|
-
// }
|
|
98
|
+
console.log(health.totalPatterns, health.activePatterns);
|
|
52
99
|
```
|
|
53
100
|
|
|
54
|
-
|
|
101
|
+
**Returns:**
|
|
55
102
|
|
|
56
|
-
|
|
103
|
+
| Field | Type | Description |
|
|
104
|
+
| ------------------ | ---------- | ------------------------------------ |
|
|
105
|
+
| `totalPatterns` | `number` | Total pattern count |
|
|
106
|
+
| `activePatterns` | `number` | Non-stale patterns |
|
|
107
|
+
| `promotedPatterns` | `number` | Patterns promoted to permanent store |
|
|
108
|
+
| `stalePatterns` | `number` | Patterns marked as stale |
|
|
109
|
+
| `domains` | `string[]` | All domain names |
|
|
110
|
+
| `lastUpdatedAt` | `string \| null` | Last update timestamp |
|
|
111
|
+
| `lastUpdatedBy` | `string \| null` | Last updating program |
|
|
112
|
+
| `decay` | `object` | Decay configuration |
|
|
57
113
|
|
|
58
|
-
|
|
114
|
+
### `delete(patternId: string): Promise<void>`
|
|
59
115
|
|
|
60
|
-
|
|
116
|
+
Delete a memory pattern by ID.
|
|
61
117
|
|
|
62
118
|
```typescript
|
|
63
|
-
|
|
119
|
+
await memory.delete("p-001");
|
|
64
120
|
```
|
|
65
121
|
|
|
66
|
-
|
|
67
|
-
- `apiKey` (string, required) — Your CacheBash API key
|
|
68
|
-
- `programId` (string, required) — Program ID for memory isolation
|
|
69
|
-
- `endpoint` (string, optional) — MCP endpoint URL (default: `https://api.cachebash.dev/v1/mcp`)
|
|
122
|
+
### `reinforce(patternId: string, options?: ReinforceOptions): Promise<void>`
|
|
70
123
|
|
|
71
|
-
|
|
124
|
+
Reinforce an existing pattern. Bumps `lastReinforced` timestamp and optionally updates confidence or evidence.
|
|
72
125
|
|
|
73
|
-
|
|
126
|
+
```typescript
|
|
127
|
+
await memory.reinforce("p-001", {
|
|
128
|
+
confidence: 0.97,
|
|
129
|
+
evidence: "Confirmed again in latest deploy",
|
|
130
|
+
});
|
|
131
|
+
```
|
|
74
132
|
|
|
75
|
-
|
|
133
|
+
**ReinforceOptions:**
|
|
76
134
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
- `confidence` (number) — Confidence score (0-1)
|
|
82
|
-
- `evidence` (string) — Supporting evidence or context
|
|
135
|
+
| Field | Type | Description |
|
|
136
|
+
| ------------ | -------- | ----------------------------- |
|
|
137
|
+
| `confidence` | `number` | Updated confidence score |
|
|
138
|
+
| `evidence` | `string` | Updated evidence text |
|
|
83
139
|
|
|
84
|
-
|
|
140
|
+
## Configuration
|
|
85
141
|
|
|
86
|
-
|
|
142
|
+
### Transport Modes
|
|
87
143
|
|
|
88
|
-
**
|
|
89
|
-
- `domain` (string, optional) — Filter by domain
|
|
90
|
-
- `search` (string, optional) — Text search across pattern and evidence fields
|
|
144
|
+
**REST (default):** Simple HTTP transport. Endpoint defaults to `https://api.cachebash.dev`.
|
|
91
145
|
|
|
92
|
-
|
|
146
|
+
```typescript
|
|
147
|
+
const memory = new CacheBashMemory({
|
|
148
|
+
apiKey: "your-key",
|
|
149
|
+
programId: "your-program",
|
|
150
|
+
transport: "rest",
|
|
151
|
+
});
|
|
152
|
+
```
|
|
93
153
|
|
|
94
|
-
|
|
154
|
+
**MCP:** JSON-RPC over MCP transport. Endpoint defaults to `https://api.cachebash.dev/v1/mcp`.
|
|
95
155
|
|
|
96
|
-
|
|
156
|
+
```typescript
|
|
157
|
+
const memory = new CacheBashMemory({
|
|
158
|
+
apiKey: "your-key",
|
|
159
|
+
programId: "your-program",
|
|
160
|
+
transport: "mcp",
|
|
161
|
+
});
|
|
162
|
+
```
|
|
97
163
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
|
|
164
|
+
### Custom Endpoint
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const memory = new CacheBashMemory({
|
|
168
|
+
apiKey: "your-key",
|
|
169
|
+
programId: "your-program",
|
|
170
|
+
endpoint: "https://your-custom-endpoint.example.com",
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Error Handling
|
|
175
|
+
|
|
176
|
+
All methods throw standard `Error` objects on failure. Errors fall into three categories:
|
|
177
|
+
|
|
178
|
+
**HTTP errors** — The API returned a non-2xx status code. The error message includes the status code.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
try {
|
|
182
|
+
await memory.store(pattern);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
// "HTTP 401: Unauthorized"
|
|
185
|
+
// "HTTP 403: Forbidden"
|
|
186
|
+
// "HTTP 404: Not Found"
|
|
187
|
+
// "HTTP 500: Internal Server Error"
|
|
188
|
+
}
|
|
189
|
+
```
|
|
107
190
|
|
|
108
|
-
|
|
191
|
+
**API errors** — The API returned a 200 response with `success: false`.
|
|
109
192
|
|
|
110
193
|
```typescript
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
confidence: number;
|
|
116
|
-
evidence: string;
|
|
117
|
-
discoveredAt: string;
|
|
118
|
-
lastReinforced: string;
|
|
119
|
-
promotedToStore: boolean;
|
|
120
|
-
stale: boolean;
|
|
194
|
+
try {
|
|
195
|
+
await memory.store(pattern);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
// "API error: <message from server>"
|
|
121
198
|
}
|
|
199
|
+
```
|
|
122
200
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
decay: {
|
|
132
|
-
contextSummaryTTLDays: number;
|
|
133
|
-
learnedPatternMaxAge: number;
|
|
134
|
-
maxUnpromotedPatterns: number;
|
|
135
|
-
lastDecayRun: string;
|
|
136
|
-
};
|
|
201
|
+
**Network errors** — The fetch call itself failed (DNS resolution, timeout, connection refused).
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
try {
|
|
205
|
+
await memory.store(pattern);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
// "fetch failed: network timeout"
|
|
208
|
+
// "TypeError: Failed to fetch"
|
|
137
209
|
}
|
|
138
210
|
```
|
|
139
211
|
|
|
140
|
-
##
|
|
212
|
+
## Examples
|
|
141
213
|
|
|
142
|
-
|
|
214
|
+
See the [`examples/`](./examples/) directory for runnable scripts:
|
|
215
|
+
|
|
216
|
+
- [`basic-usage.ts`](./examples/basic-usage.ts) — Store, recall, reinforce, and delete patterns
|
|
217
|
+
|
|
218
|
+
Run an example:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
CACHEBASH_API_KEY=your-key npx tsx packages/memory/examples/basic-usage.ts
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Running Tests
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
cd packages/memory
|
|
228
|
+
npm test
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Or with watch mode:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
npm run test:watch
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Integration Tests
|
|
238
|
+
|
|
239
|
+
Run against the live API:
|
|
143
240
|
|
|
144
|
-
|
|
241
|
+
```bash
|
|
242
|
+
CACHEBASH_API_KEY=your-key npm run test:integration
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Integration tests are skipped automatically when no API key is set.
|
|
145
246
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
247
|
+
## Benchmarks
|
|
248
|
+
|
|
249
|
+
Measure API latency:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
CACHEBASH_API_KEY=your-key npm run benchmark
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
package/dist/index.d.cts
CHANGED
|
@@ -20,19 +20,24 @@ interface MemoryPattern {
|
|
|
20
20
|
*/
|
|
21
21
|
interface MemoryHealth {
|
|
22
22
|
totalPatterns: number;
|
|
23
|
+
activePatterns: number;
|
|
23
24
|
promotedPatterns: number;
|
|
24
25
|
stalePatterns: number;
|
|
25
26
|
domains: string[];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
newestPattern: string | null;
|
|
27
|
+
lastUpdatedAt: string | null;
|
|
28
|
+
lastUpdatedBy: string | null;
|
|
29
29
|
decay: {
|
|
30
|
-
contextSummaryTTLDays: number;
|
|
31
|
-
learnedPatternMaxAge: number;
|
|
32
30
|
maxUnpromotedPatterns: number;
|
|
33
|
-
|
|
31
|
+
learnedPatternMaxAge: number;
|
|
32
|
+
lastDecayRun: string | null;
|
|
34
33
|
};
|
|
35
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Transport mode for the SDK client.
|
|
37
|
+
* - "mcp": JSON-RPC over MCP transport (default)
|
|
38
|
+
* - "rest": RESTful HTTP transport (simpler, no session management)
|
|
39
|
+
*/
|
|
40
|
+
type TransportMode = "mcp" | "rest";
|
|
36
41
|
/**
|
|
37
42
|
* Configuration for CacheBashMemory client.
|
|
38
43
|
*/
|
|
@@ -42,14 +47,20 @@ interface CacheBashMemoryConfig {
|
|
|
42
47
|
*/
|
|
43
48
|
apiKey: string;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
50
|
+
* Base API endpoint URL.
|
|
51
|
+
* For MCP transport: defaults to "https://api.cachebash.dev/v1/mcp"
|
|
52
|
+
* For REST transport: defaults to "https://api.cachebash.dev"
|
|
47
53
|
*/
|
|
48
54
|
endpoint?: string;
|
|
49
55
|
/**
|
|
50
56
|
* Program ID for memory operations.
|
|
51
57
|
*/
|
|
52
58
|
programId: string;
|
|
59
|
+
/**
|
|
60
|
+
* Transport mode.
|
|
61
|
+
* @default "rest"
|
|
62
|
+
*/
|
|
63
|
+
transport?: TransportMode;
|
|
53
64
|
}
|
|
54
65
|
/**
|
|
55
66
|
* Options for recalling memories.
|
|
@@ -63,6 +74,10 @@ interface RecallOptions {
|
|
|
63
74
|
* Text search query (optional).
|
|
64
75
|
*/
|
|
65
76
|
search?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Include stale patterns (optional).
|
|
79
|
+
*/
|
|
80
|
+
includeStale?: boolean;
|
|
66
81
|
}
|
|
67
82
|
/**
|
|
68
83
|
* Pattern to store in memory.
|
|
@@ -74,15 +89,30 @@ interface StorePatternInput {
|
|
|
74
89
|
confidence: number;
|
|
75
90
|
evidence: string;
|
|
76
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for reinforcing a memory pattern.
|
|
94
|
+
*/
|
|
95
|
+
interface ReinforceOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Updated confidence score (optional).
|
|
98
|
+
*/
|
|
99
|
+
confidence?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Updated evidence text (optional).
|
|
102
|
+
*/
|
|
103
|
+
evidence?: string;
|
|
104
|
+
}
|
|
77
105
|
|
|
78
106
|
/**
|
|
79
107
|
* CacheBashMemory — SDK client for memory pattern storage and recall.
|
|
108
|
+
* Supports both MCP (JSON-RPC) and REST transports.
|
|
80
109
|
*/
|
|
81
110
|
|
|
82
111
|
declare class CacheBashMemory {
|
|
83
112
|
private readonly apiKey;
|
|
84
113
|
private readonly endpoint;
|
|
85
114
|
private readonly programId;
|
|
115
|
+
private readonly transport;
|
|
86
116
|
private requestId;
|
|
87
117
|
constructor(config: CacheBashMemoryConfig);
|
|
88
118
|
/**
|
|
@@ -99,9 +129,21 @@ declare class CacheBashMemory {
|
|
|
99
129
|
*/
|
|
100
130
|
health(): Promise<MemoryHealth>;
|
|
101
131
|
/**
|
|
102
|
-
*
|
|
132
|
+
* Delete a memory pattern by ID.
|
|
133
|
+
*/
|
|
134
|
+
delete(patternId: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Reinforce an existing pattern — bumps lastReinforced, optionally updates confidence/evidence.
|
|
137
|
+
*/
|
|
138
|
+
reinforce(patternId: string, options?: ReinforceOptions): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Call a tool via REST transport.
|
|
141
|
+
*/
|
|
142
|
+
private restCall;
|
|
143
|
+
/**
|
|
144
|
+
* Call an MCP tool via JSON-RPC transport.
|
|
103
145
|
*/
|
|
104
|
-
private
|
|
146
|
+
private mcpCall;
|
|
105
147
|
}
|
|
106
148
|
|
|
107
|
-
export { CacheBashMemory, type CacheBashMemoryConfig, type MemoryHealth, type MemoryPattern, type RecallOptions, type StorePatternInput };
|
|
149
|
+
export { CacheBashMemory, type CacheBashMemoryConfig, type MemoryHealth, type MemoryPattern, type RecallOptions, type ReinforceOptions, type StorePatternInput, type TransportMode };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,19 +20,24 @@ interface MemoryPattern {
|
|
|
20
20
|
*/
|
|
21
21
|
interface MemoryHealth {
|
|
22
22
|
totalPatterns: number;
|
|
23
|
+
activePatterns: number;
|
|
23
24
|
promotedPatterns: number;
|
|
24
25
|
stalePatterns: number;
|
|
25
26
|
domains: string[];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
newestPattern: string | null;
|
|
27
|
+
lastUpdatedAt: string | null;
|
|
28
|
+
lastUpdatedBy: string | null;
|
|
29
29
|
decay: {
|
|
30
|
-
contextSummaryTTLDays: number;
|
|
31
|
-
learnedPatternMaxAge: number;
|
|
32
30
|
maxUnpromotedPatterns: number;
|
|
33
|
-
|
|
31
|
+
learnedPatternMaxAge: number;
|
|
32
|
+
lastDecayRun: string | null;
|
|
34
33
|
};
|
|
35
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Transport mode for the SDK client.
|
|
37
|
+
* - "mcp": JSON-RPC over MCP transport (default)
|
|
38
|
+
* - "rest": RESTful HTTP transport (simpler, no session management)
|
|
39
|
+
*/
|
|
40
|
+
type TransportMode = "mcp" | "rest";
|
|
36
41
|
/**
|
|
37
42
|
* Configuration for CacheBashMemory client.
|
|
38
43
|
*/
|
|
@@ -42,14 +47,20 @@ interface CacheBashMemoryConfig {
|
|
|
42
47
|
*/
|
|
43
48
|
apiKey: string;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
50
|
+
* Base API endpoint URL.
|
|
51
|
+
* For MCP transport: defaults to "https://api.cachebash.dev/v1/mcp"
|
|
52
|
+
* For REST transport: defaults to "https://api.cachebash.dev"
|
|
47
53
|
*/
|
|
48
54
|
endpoint?: string;
|
|
49
55
|
/**
|
|
50
56
|
* Program ID for memory operations.
|
|
51
57
|
*/
|
|
52
58
|
programId: string;
|
|
59
|
+
/**
|
|
60
|
+
* Transport mode.
|
|
61
|
+
* @default "rest"
|
|
62
|
+
*/
|
|
63
|
+
transport?: TransportMode;
|
|
53
64
|
}
|
|
54
65
|
/**
|
|
55
66
|
* Options for recalling memories.
|
|
@@ -63,6 +74,10 @@ interface RecallOptions {
|
|
|
63
74
|
* Text search query (optional).
|
|
64
75
|
*/
|
|
65
76
|
search?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Include stale patterns (optional).
|
|
79
|
+
*/
|
|
80
|
+
includeStale?: boolean;
|
|
66
81
|
}
|
|
67
82
|
/**
|
|
68
83
|
* Pattern to store in memory.
|
|
@@ -74,15 +89,30 @@ interface StorePatternInput {
|
|
|
74
89
|
confidence: number;
|
|
75
90
|
evidence: string;
|
|
76
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for reinforcing a memory pattern.
|
|
94
|
+
*/
|
|
95
|
+
interface ReinforceOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Updated confidence score (optional).
|
|
98
|
+
*/
|
|
99
|
+
confidence?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Updated evidence text (optional).
|
|
102
|
+
*/
|
|
103
|
+
evidence?: string;
|
|
104
|
+
}
|
|
77
105
|
|
|
78
106
|
/**
|
|
79
107
|
* CacheBashMemory — SDK client for memory pattern storage and recall.
|
|
108
|
+
* Supports both MCP (JSON-RPC) and REST transports.
|
|
80
109
|
*/
|
|
81
110
|
|
|
82
111
|
declare class CacheBashMemory {
|
|
83
112
|
private readonly apiKey;
|
|
84
113
|
private readonly endpoint;
|
|
85
114
|
private readonly programId;
|
|
115
|
+
private readonly transport;
|
|
86
116
|
private requestId;
|
|
87
117
|
constructor(config: CacheBashMemoryConfig);
|
|
88
118
|
/**
|
|
@@ -99,9 +129,21 @@ declare class CacheBashMemory {
|
|
|
99
129
|
*/
|
|
100
130
|
health(): Promise<MemoryHealth>;
|
|
101
131
|
/**
|
|
102
|
-
*
|
|
132
|
+
* Delete a memory pattern by ID.
|
|
133
|
+
*/
|
|
134
|
+
delete(patternId: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Reinforce an existing pattern — bumps lastReinforced, optionally updates confidence/evidence.
|
|
137
|
+
*/
|
|
138
|
+
reinforce(patternId: string, options?: ReinforceOptions): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Call a tool via REST transport.
|
|
141
|
+
*/
|
|
142
|
+
private restCall;
|
|
143
|
+
/**
|
|
144
|
+
* Call an MCP tool via JSON-RPC transport.
|
|
103
145
|
*/
|
|
104
|
-
private
|
|
146
|
+
private mcpCall;
|
|
105
147
|
}
|
|
106
148
|
|
|
107
|
-
export { CacheBashMemory, type CacheBashMemoryConfig, type MemoryHealth, type MemoryPattern, type RecallOptions, type StorePatternInput };
|
|
149
|
+
export { CacheBashMemory, type CacheBashMemoryConfig, type MemoryHealth, type MemoryPattern, type RecallOptions, type ReinforceOptions, type StorePatternInput, type TransportMode };
|
package/dist/index.js
CHANGED
|
@@ -29,17 +29,23 @@ var CacheBashMemory = class {
|
|
|
29
29
|
apiKey;
|
|
30
30
|
endpoint;
|
|
31
31
|
programId;
|
|
32
|
+
transport;
|
|
32
33
|
requestId = 1;
|
|
33
34
|
constructor(config) {
|
|
34
35
|
this.apiKey = config.apiKey;
|
|
35
|
-
this.endpoint = config.endpoint || "https://api.cachebash.dev/v1/mcp";
|
|
36
36
|
this.programId = config.programId;
|
|
37
|
+
this.transport = config.transport || "rest";
|
|
37
38
|
if (!this.apiKey) {
|
|
38
39
|
throw new Error("CacheBashMemory: apiKey is required");
|
|
39
40
|
}
|
|
40
41
|
if (!this.programId) {
|
|
41
42
|
throw new Error("CacheBashMemory: programId is required");
|
|
42
43
|
}
|
|
44
|
+
if (config.endpoint) {
|
|
45
|
+
this.endpoint = config.endpoint;
|
|
46
|
+
} else {
|
|
47
|
+
this.endpoint = this.transport === "mcp" ? "https://api.cachebash.dev/v1/mcp" : "https://api.cachebash.dev";
|
|
48
|
+
}
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* Store a memory pattern.
|
|
@@ -54,26 +60,31 @@ var CacheBashMemory = class {
|
|
|
54
60
|
promotedToStore: false,
|
|
55
61
|
stale: false
|
|
56
62
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!result.success) {
|
|
62
|
-
throw new Error(`Failed to store memory: ${result.error || "Unknown error"}`);
|
|
63
|
+
if (this.transport === "rest") {
|
|
64
|
+
await this.restCall("POST", `/v1/memory/${this.programId}/patterns`, { pattern });
|
|
65
|
+
} else {
|
|
66
|
+
await this.mcpCall("store_memory", { programId: this.programId, pattern });
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
/**
|
|
66
70
|
* Recall memory patterns with optional filters.
|
|
67
71
|
*/
|
|
68
72
|
async recall(options) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
let result;
|
|
74
|
+
if (this.transport === "rest") {
|
|
75
|
+
const params = new URLSearchParams();
|
|
76
|
+
if (options?.domain) params.set("domain", options.domain);
|
|
77
|
+
if (options?.search) params.set("query", options.search);
|
|
78
|
+
if (options?.includeStale) params.set("includeStale", "true");
|
|
79
|
+
const qs = params.toString();
|
|
80
|
+
result = await this.restCall("GET", `/v1/memory/${this.programId}/patterns${qs ? `?${qs}` : ""}`);
|
|
81
|
+
} else {
|
|
82
|
+
result = await this.mcpCall("recall_memory", {
|
|
83
|
+
programId: this.programId,
|
|
84
|
+
domain: options?.domain,
|
|
85
|
+
query: options?.search,
|
|
86
|
+
includeStale: options?.includeStale || false
|
|
87
|
+
});
|
|
77
88
|
}
|
|
78
89
|
return result.patterns || [];
|
|
79
90
|
}
|
|
@@ -81,25 +92,76 @@ var CacheBashMemory = class {
|
|
|
81
92
|
* Get memory health statistics.
|
|
82
93
|
*/
|
|
83
94
|
async health() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
let result;
|
|
96
|
+
if (this.transport === "rest") {
|
|
97
|
+
result = await this.restCall("GET", `/v1/memory/${this.programId}/health`);
|
|
98
|
+
} else {
|
|
99
|
+
result = await this.mcpCall("memory_health", { programId: this.programId });
|
|
89
100
|
}
|
|
90
101
|
return result.health;
|
|
91
102
|
}
|
|
92
103
|
/**
|
|
93
|
-
*
|
|
104
|
+
* Delete a memory pattern by ID.
|
|
105
|
+
*/
|
|
106
|
+
async delete(patternId) {
|
|
107
|
+
if (this.transport === "rest") {
|
|
108
|
+
await this.restCall("DELETE", `/v1/memory/${this.programId}/patterns/${patternId}`);
|
|
109
|
+
} else {
|
|
110
|
+
await this.mcpCall("delete_memory", { programId: this.programId, patternId });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reinforce an existing pattern — bumps lastReinforced, optionally updates confidence/evidence.
|
|
115
|
+
*/
|
|
116
|
+
async reinforce(patternId, options) {
|
|
117
|
+
if (this.transport === "rest") {
|
|
118
|
+
await this.restCall("PATCH", `/v1/memory/${this.programId}/patterns/${patternId}/reinforce`, {
|
|
119
|
+
confidence: options?.confidence,
|
|
120
|
+
evidence: options?.evidence
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
await this.mcpCall("reinforce_memory", {
|
|
124
|
+
programId: this.programId,
|
|
125
|
+
patternId,
|
|
126
|
+
confidence: options?.confidence,
|
|
127
|
+
evidence: options?.evidence
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Call a tool via REST transport.
|
|
133
|
+
*/
|
|
134
|
+
async restCall(method, path, body) {
|
|
135
|
+
const url = `${this.endpoint}${path}`;
|
|
136
|
+
const options = {
|
|
137
|
+
method,
|
|
138
|
+
headers: {
|
|
139
|
+
"Content-Type": "application/json",
|
|
140
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
if (body && method !== "GET") {
|
|
144
|
+
options.body = JSON.stringify(body);
|
|
145
|
+
}
|
|
146
|
+
const response = await fetch(url, options);
|
|
147
|
+
if (!response.ok) {
|
|
148
|
+
const text = await response.text();
|
|
149
|
+
throw new Error(`HTTP ${response.status}: ${text}`);
|
|
150
|
+
}
|
|
151
|
+
const data = await response.json();
|
|
152
|
+
if (!data.success) {
|
|
153
|
+
throw new Error(`API error: ${data.error?.message || "Unknown error"}`);
|
|
154
|
+
}
|
|
155
|
+
return data.data;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Call an MCP tool via JSON-RPC transport.
|
|
94
159
|
*/
|
|
95
|
-
async
|
|
160
|
+
async mcpCall(name, args) {
|
|
96
161
|
const request = {
|
|
97
162
|
jsonrpc: "2.0",
|
|
98
163
|
method: "tools/call",
|
|
99
|
-
params: {
|
|
100
|
-
name,
|
|
101
|
-
arguments: args
|
|
102
|
-
},
|
|
164
|
+
params: { name, arguments: args },
|
|
103
165
|
id: this.requestId++
|
|
104
166
|
};
|
|
105
167
|
const response = await fetch(this.endpoint, {
|
|
@@ -128,7 +190,11 @@ var CacheBashMemory = class {
|
|
|
128
190
|
if (!textContent) {
|
|
129
191
|
throw new Error("MCP response missing content");
|
|
130
192
|
}
|
|
131
|
-
|
|
193
|
+
const parsed = JSON.parse(textContent);
|
|
194
|
+
if (!parsed.success) {
|
|
195
|
+
throw new Error(`Tool error: ${parsed.error || "Unknown error"}`);
|
|
196
|
+
}
|
|
197
|
+
return parsed;
|
|
132
198
|
}
|
|
133
199
|
};
|
|
134
200
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["/**\n * @rezzed.ai/memory — CacheBash Memory SDK\n */\n\nexport { CacheBashMemory } from \"./client.js\";\nexport type {\n CacheBashMemoryConfig,\n MemoryPattern,\n MemoryHealth,\n RecallOptions,\n StorePatternInput,\n} from \"./types.js\";\n","/**\n * CacheBashMemory — SDK client for memory pattern storage and recall.\n */\n\nimport type {\n CacheBashMemoryConfig,\n MemoryPattern,\n MemoryHealth,\n RecallOptions,\n StorePatternInput,\n} from \"./types.js\";\n\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: Record<string, unknown>;\n };\n id: number;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n result?: {\n content: Array<{ type: string; text: string }>;\n isError?: boolean;\n };\n error?: {\n code: number;\n message: string;\n };\n id: number;\n}\n\nexport class CacheBashMemory {\n private readonly apiKey: string;\n private readonly endpoint: string;\n private readonly programId: string;\n private requestId = 1;\n\n constructor(config: CacheBashMemoryConfig) {\n this.apiKey = config.apiKey;\n this.endpoint = config.endpoint || \"https://api.cachebash.dev/v1/mcp\";\n this.programId = config.programId;\n\n if (!this.apiKey) {\n throw new Error(\"CacheBashMemory: apiKey is required\");\n }\n if (!this.programId) {\n throw new Error(\"CacheBashMemory: programId is required\");\n }\n }\n\n /**\n * Store a memory pattern.\n * If a pattern with the same ID exists, it will be replaced.\n */\n async store(input: StorePatternInput): Promise<void> {\n const now = new Date().toISOString();\n const pattern: MemoryPattern = {\n ...input,\n discoveredAt: now,\n lastReinforced: now,\n promotedToStore: false,\n stale: false,\n };\n\n const result = await this.callTool(\"store_memory\", {\n programId: this.programId,\n pattern,\n });\n\n if (!result.success) {\n throw new Error(`Failed to store memory: ${result.error || \"Unknown error\"}`);\n }\n }\n\n /**\n * Recall memory patterns with optional filters.\n */\n async recall(options?: RecallOptions): Promise<MemoryPattern[]> {\n const result = await this.callTool(\"recall_memory\", {\n programId: this.programId,\n domain: options?.domain,\n query: options?.search,\n includeStale: false,\n });\n\n if (!result.success) {\n throw new Error(`Failed to recall memory: ${result.error || \"Unknown error\"}`);\n }\n\n return result.patterns || [];\n }\n\n /**\n * Get memory health statistics.\n */\n async health(): Promise<MemoryHealth> {\n const result = await this.callTool(\"memory_health\", {\n programId: this.programId,\n });\n\n if (!result.success) {\n throw new Error(`Failed to get memory health: ${result.error || \"Unknown error\"}`);\n }\n\n return result.health;\n }\n\n /**\n * Call an MCP tool via HTTP transport.\n */\n private async callTool(name: string, args: Record<string, unknown>): Promise<any> {\n const request: MCPRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(request),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n const data: MCPResponse = await response.json();\n\n if (data.error) {\n throw new Error(`MCP error ${data.error.code}: ${data.error.message}`);\n }\n\n if (!data.result) {\n throw new Error(\"MCP response missing result\");\n }\n\n if (data.result.isError) {\n const errorText = data.result.content[0]?.text || \"Unknown error\";\n throw new Error(`MCP tool error: ${errorText}`);\n }\n\n // Parse the text content as JSON\n const textContent = data.result.content[0]?.text;\n if (!textContent) {\n throw new Error(\"MCP response missing content\");\n }\n\n return JSON.parse(textContent);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmCO,IAAM,kBAAN,MAAsB;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAY;AAAA,EAEpB,YAAY,QAA+B;AACzC,SAAK,SAAS,OAAO;AACrB,SAAK,WAAW,OAAO,YAAY;AACnC,SAAK,YAAY,OAAO;AAExB,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,MAAM,OAAyC;AACnD,UAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,UAAM,UAAyB;AAAA,MAC7B,GAAG;AAAA,MACH,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,OAAO;AAAA,IACT;AAEA,UAAM,SAAS,MAAM,KAAK,SAAS,gBAAgB;AAAA,MACjD,WAAW,KAAK;AAAA,MAChB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,OAAO,SAAS;AACnB,YAAM,IA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KAAK,OAAO;AACd,YAAM,IAAI,MAAM,aAAa,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,OAAO,EAAE;AAAA,IACvE;AAEA,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AAEA,QAAI,KAAK,OAAO,SAAS;AACvB,YAAM,YAAY,KAAK,OAAO,QAAQ,CAAC,GAAG,QAAQ;AAClD,YAAM,IAAI,MAAM,mBAAmB,SAAS,EAAE;AAAA,IAChD;AAGA,UAAM,cAAc,KAAK,OAAO,QAAQ,CAAC,GAAG;AAC5C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,8BAA8B;AAAA,IAChD;AAEA,WAAO,KAAK,MAAM,WAAW;AAAA,EAC/B;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["/**\n * @rezzed.ai/memory — CacheBash Memory SDK\n */\n\nexport { CacheBashMemory } from \"./client.js\";\nexport type {\n CacheBashMemoryConfig,\n MemoryPattern,\n MemoryHealth,\n RecallOptions,\n StorePatternInput,\n ReinforceOptions,\n TransportMode,\n} from \"./types.js\";\n","/**\n * CacheBashMemory — SDK client for memory pattern storage and recall.\n * Supports both MCP (JSON-RPC) and REST transports.\n */\n\nimport type {\n CacheBashMemoryConfig,\n MemoryPattern,\n MemoryHealth,\n RecallOptions,\n StorePatternInput,\n ReinforceOptions,\n TransportMode,\n} from \"./types.js\";\n\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: Record<string, unknown>;\n };\n id: number;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n result?: {\n content: Array<{ type: string; text: string }>;\n isError?: boolean;\n };\n error?: {\n code: number;\n message: string;\n };\n id: number;\n}\n\ninterface RESTResponse {\n success: boolean;\n data?: any;\n error?: { code: string; message: string };\n}\n\nexport class CacheBashMemory {\n private readonly apiKey: string;\n private readonly endpoint: string;\n private readonly programId: string;\n private readonly transport: TransportMode;\n private requestId = 1;\n\n constructor(config: CacheBashMemoryConfig) {\n this.apiKey = config.apiKey;\n this.programId = config.programId;\n this.transport = config.transport || \"rest\";\n\n if (!this.apiKey) {\n throw new Error(\"CacheBashMemory: apiKey is required\");\n }\n if (!this.programId) {\n throw new Error(\"CacheBashMemory: programId is required\");\n }\n\n if (config.endpoint) {\n this.endpoint = config.endpoint;\n } else {\n this.endpoint = this.transport === \"mcp\"\n ? \"https://api.cachebash.dev/v1/mcp\"\n : \"https://api.cachebash.dev\";\n }\n }\n\n /**\n * Store a memory pattern.\n * If a pattern with the same ID exists, it will be replaced.\n */\n async store(input: StorePatternInput): Promise<void> {\n const now = new Date().toISOString();\n const pattern: MemoryPattern = {\n ...input,\n discoveredAt: now,\n lastReinforced: now,\n promotedToStore: false,\n stale: false,\n };\n\n if (this.transport === \"rest\") {\n await this.restCall(\"POST\", `/v1/memory/${this.programId}/patterns`, { pattern });\n } else {\n await this.mcpCall(\"store_memory\", { programId: this.programId, pattern });\n }\n }\n\n /**\n * Recall memory patterns with optional filters.\n */\n async recall(options?: RecallOptions): Promise<MemoryPattern[]> {\n let result: any;\n\n if (this.transport === \"rest\") {\n const params = new URLSearchParams();\n if (options?.domain) params.set(\"domain\", options.domain);\n if (options?.search) params.set(\"query\", options.search);\n if (options?.includeStale) params.set(\"includeStale\", \"true\");\n const qs = params.toString();\n result = await this.restCall(\"GET\", `/v1/memory/${this.programId}/patterns${qs ? `?${qs}` : \"\"}`);\n } else {\n result = await this.mcpCall(\"recall_memory\", {\n programId: this.programId,\n domain: options?.domain,\n query: options?.search,\n includeStale: options?.includeStale || false,\n });\n }\n\n return result.patterns || [];\n }\n\n /**\n * Get memory health statistics.\n */\n async health(): Promise<MemoryHealth> {\n let result: any;\n\n if (this.transport === \"rest\") {\n result = await this.restCall(\"GET\", `/v1/memory/${this.programId}/health`);\n } else {\n result = await this.mcpCall(\"memory_health\", { programId: this.programId });\n }\n\n return result.health;\n }\n\n /**\n * Delete a memory pattern by ID.\n */\n async delete(patternId: string): Promise<void> {\n if (this.transport === \"rest\") {\n await this.restCall(\"DELETE\", `/v1/memory/${this.programId}/patterns/${patternId}`);\n } else {\n await this.mcpCall(\"delete_memory\", { programId: this.programId, patternId });\n }\n }\n\n /**\n * Reinforce an existing pattern — bumps lastReinforced, optionally updates confidence/evidence.\n */\n async reinforce(patternId: string, options?: ReinforceOptions): Promise<void> {\n if (this.transport === \"rest\") {\n await this.restCall(\"PATCH\", `/v1/memory/${this.programId}/patterns/${patternId}/reinforce`, {\n confidence: options?.confidence,\n evidence: options?.evidence,\n });\n } else {\n await this.mcpCall(\"reinforce_memory\", {\n programId: this.programId,\n patternId,\n confidence: options?.confidence,\n evidence: options?.evidence,\n });\n }\n }\n\n /**\n * Call a tool via REST transport.\n */\n private async restCall(method: string, path: string, body?: Record<string, unknown>): Promise<any> {\n const url = `${this.endpoint}${path}`;\n const options: RequestInit = {\n method,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n };\n\n if (body && method !== \"GET\") {\n options.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, options);\n\n if (!response.ok) {\n const text = await response.text();\n throw new Error(`HTTP ${response.status}: ${text}`);\n }\n\n const data: RESTResponse = await response.json();\n\n if (!data.success) {\n throw new Error(`API error: ${data.error?.message || \"Unknown error\"}`);\n }\n\n return data.data;\n }\n\n /**\n * Call an MCP tool via JSON-RPC transport.\n */\n private async mcpCall(name: string, args: Record<string, unknown>): Promise<any> {\n const request: MCPRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: { name, arguments: args },\n id: this.requestId++,\n };\n\n const response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(request),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n const data: MCPResponse = await response.json();\n\n if (data.error) {\n throw new Error(`MCP error ${data.error.code}: ${data.error.message}`);\n }\n\n if (!data.result) {\n throw new Error(\"MCP response missing result\");\n }\n\n if (data.result.isError) {\n const errorText = data.result.content[0]?.text || \"Unknown error\";\n throw new Error(`MCP tool error: ${errorText}`);\n }\n\n const textContent = data.result.content[0]?.text;\n if (!textContent) {\n throw new Error(\"MCP response missing content\");\n }\n\n const parsed = JSON.parse(textContent);\n if (!parsed.success) {\n throw new Error(`Tool error: ${parsed.error || \"Unknown error\"}`);\n }\n\n return parsed;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4CO,IAAM,kBAAN,MAAsB;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAY;AAAA,EAEpB,YAAY,QAA+B;AACzC,SAAK,SAAS,OAAO;AACrB,SAAK,YAAY,OAAO;AACxB,SAAK,YAAY,OAAO,aAAa;AAErC,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAEA,QAAI,OAAO,UAAU;AACnB,WAAK,WAAW,OAAO;AAAA,IACzB,OAAO;AACL,WAAK,WAAW,KAAK,cAAc,QAC/B,qCACA;AAAA,IACN;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,MAAM,OAAyC;AACnD,UAAM,OAAM,oBAAI,KAAK,GAAE,YAAY;AACnC,UAAM,UAAyB;AAAA,MAC7B,GAAG;AAAA,MACH,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,OAAO;AAAA,IACT;AAEA,QAAI,KAAK,cAAc,QAAQ;AAC7B,YAAM,KAAK,SAAS,QAAQ,cAAc,KAAK,SAAS,aAAa,EAAE,QAAQ,CAAC;AAAA,IAClF,OAA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config) {
|
|
8
9
|
this.apiKey = config.apiKey;
|
|
9
|
-
this.endpoint = config.endpoint || "https://api.cachebash.dev/v1/mcp";
|
|
10
10
|
this.programId = config.programId;
|
|
11
|
+
this.transport = config.transport || "rest";
|
|
11
12
|
if (!this.apiKey) {
|
|
12
13
|
throw new Error("CacheBashMemory: apiKey is required");
|
|
13
14
|
}
|
|
14
15
|
if (!this.programId) {
|
|
15
16
|
throw new Error("CacheBashMemory: programId is required");
|
|
16
17
|
}
|
|
18
|
+
if (config.endpoint) {
|
|
19
|
+
this.endpoint = config.endpoint;
|
|
20
|
+
} else {
|
|
21
|
+
this.endpoint = this.transport === "mcp" ? "https://api.cachebash.dev/v1/mcp" : "https://api.cachebash.dev";
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
19
25
|
* Store a memory pattern.
|
|
@@ -28,26 +34,31 @@ var CacheBashMemory = class {
|
|
|
28
34
|
promotedToStore: false,
|
|
29
35
|
stale: false
|
|
30
36
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!result.success) {
|
|
36
|
-
throw new Error(`Failed to store memory: ${result.error || "Unknown error"}`);
|
|
37
|
+
if (this.transport === "rest") {
|
|
38
|
+
await this.restCall("POST", `/v1/memory/${this.programId}/patterns`, { pattern });
|
|
39
|
+
} else {
|
|
40
|
+
await this.mcpCall("store_memory", { programId: this.programId, pattern });
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
44
|
* Recall memory patterns with optional filters.
|
|
41
45
|
*/
|
|
42
46
|
async recall(options) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
let result;
|
|
48
|
+
if (this.transport === "rest") {
|
|
49
|
+
const params = new URLSearchParams();
|
|
50
|
+
if (options?.domain) params.set("domain", options.domain);
|
|
51
|
+
if (options?.search) params.set("query", options.search);
|
|
52
|
+
if (options?.includeStale) params.set("includeStale", "true");
|
|
53
|
+
const qs = params.toString();
|
|
54
|
+
result = await this.restCall("GET", `/v1/memory/${this.programId}/patterns${qs ? `?${qs}` : ""}`);
|
|
55
|
+
} else {
|
|
56
|
+
result = await this.mcpCall("recall_memory", {
|
|
57
|
+
programId: this.programId,
|
|
58
|
+
domain: options?.domain,
|
|
59
|
+
query: options?.search,
|
|
60
|
+
includeStale: options?.includeStale || false
|
|
61
|
+
});
|
|
51
62
|
}
|
|
52
63
|
return result.patterns || [];
|
|
53
64
|
}
|
|
@@ -55,25 +66,76 @@ var CacheBashMemory = class {
|
|
|
55
66
|
* Get memory health statistics.
|
|
56
67
|
*/
|
|
57
68
|
async health() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
let result;
|
|
70
|
+
if (this.transport === "rest") {
|
|
71
|
+
result = await this.restCall("GET", `/v1/memory/${this.programId}/health`);
|
|
72
|
+
} else {
|
|
73
|
+
result = await this.mcpCall("memory_health", { programId: this.programId });
|
|
63
74
|
}
|
|
64
75
|
return result.health;
|
|
65
76
|
}
|
|
66
77
|
/**
|
|
67
|
-
*
|
|
78
|
+
* Delete a memory pattern by ID.
|
|
79
|
+
*/
|
|
80
|
+
async delete(patternId) {
|
|
81
|
+
if (this.transport === "rest") {
|
|
82
|
+
await this.restCall("DELETE", `/v1/memory/${this.programId}/patterns/${patternId}`);
|
|
83
|
+
} else {
|
|
84
|
+
await this.mcpCall("delete_memory", { programId: this.programId, patternId });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Reinforce an existing pattern — bumps lastReinforced, optionally updates confidence/evidence.
|
|
89
|
+
*/
|
|
90
|
+
async reinforce(patternId, options) {
|
|
91
|
+
if (this.transport === "rest") {
|
|
92
|
+
await this.restCall("PATCH", `/v1/memory/${this.programId}/patterns/${patternId}/reinforce`, {
|
|
93
|
+
confidence: options?.confidence,
|
|
94
|
+
evidence: options?.evidence
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
await this.mcpCall("reinforce_memory", {
|
|
98
|
+
programId: this.programId,
|
|
99
|
+
patternId,
|
|
100
|
+
confidence: options?.confidence,
|
|
101
|
+
evidence: options?.evidence
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Call a tool via REST transport.
|
|
107
|
+
*/
|
|
108
|
+
async restCall(method, path, body) {
|
|
109
|
+
const url = `${this.endpoint}${path}`;
|
|
110
|
+
const options = {
|
|
111
|
+
method,
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
if (body && method !== "GET") {
|
|
118
|
+
options.body = JSON.stringify(body);
|
|
119
|
+
}
|
|
120
|
+
const response = await fetch(url, options);
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
const text = await response.text();
|
|
123
|
+
throw new Error(`HTTP ${response.status}: ${text}`);
|
|
124
|
+
}
|
|
125
|
+
const data = await response.json();
|
|
126
|
+
if (!data.success) {
|
|
127
|
+
throw new Error(`API error: ${data.error?.message || "Unknown error"}`);
|
|
128
|
+
}
|
|
129
|
+
return data.data;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Call an MCP tool via JSON-RPC transport.
|
|
68
133
|
*/
|
|
69
|
-
async
|
|
134
|
+
async mcpCall(name, args) {
|
|
70
135
|
const request = {
|
|
71
136
|
jsonrpc: "2.0",
|
|
72
137
|
method: "tools/call",
|
|
73
|
-
params: {
|
|
74
|
-
name,
|
|
75
|
-
arguments: args
|
|
76
|
-
},
|
|
138
|
+
params: { name, arguments: args },
|
|
77
139
|
id: this.requestId++
|
|
78
140
|
};
|
|
79
141
|
const response = await fetch(this.endpoint, {
|
|
@@ -102,7 +164,11 @@ var CacheBashMemory = class {
|
|
|
102
164
|
if (!textContent) {
|
|
103
165
|
throw new Error("MCP response missing content");
|
|
104
166
|
}
|
|
105
|
-
|
|
167
|
+
const parsed = JSON.parse(textContent);
|
|
168
|
+
if (!parsed.success) {
|
|
169
|
+
throw new Error(`Tool error: ${parsed.error || "Unknown error"}`);
|
|
170
|
+
}
|
|
171
|
+
return parsed;
|
|
106
172
|
}
|
|
107
173
|
};
|
|
108
174
|
export {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * CacheBashMemory — SDK client for memory pattern storage and recall.\n */\n\nimport type {\n CacheBashMemoryConfig,\n MemoryPattern,\n MemoryHealth,\n RecallOptions,\n StorePatternInput,\n} from \"./types.js\";\n\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: Record<string, unknown>;\n };\n id: number;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n result?: {\n content: Array<{ type: string; text: string }>;\n isError?: boolean;\n };\n error?: {\n code: number;\n message: string;\n };\n id: number;\n}\n\nexport class CacheBashMemory {\n private readonly apiKey: string;\n private readonly endpoint: string;\n private readonly programId: string;\n private requestId = 1;\n\n constructor(config: CacheBashMemoryConfig) {\n this.apiKey = config.apiKey;\n this.endpoint = config.endpoint || \"https://api.cachebash.dev/v1/mcp\";\n this.programId = config.programId;\n\n if (!this.apiKey) {\n throw new Error(\"CacheBashMemory: apiKey is required\");\n }\n if (!this.programId) {\n throw new Error(\"CacheBashMemory: programId is required\");\n }\n }\n\n /**\n * Store a memory pattern.\n * If a pattern with the same ID exists, it will be replaced.\n */\n async store(input: StorePatternInput): Promise<void> {\n const now = new Date().toISOString();\n const pattern: MemoryPattern = {\n ...input,\n discoveredAt: now,\n lastReinforced: now,\n promotedToStore: false,\n stale: false,\n };\n\n const result = await this.callTool(\"store_memory\", {\n programId: this.programId,\n pattern,\n });\n\n if (!result.success) {\n throw new Error(`Failed to store memory: ${result.error || \"Unknown error\"}`);\n }\n }\n\n /**\n * Recall memory patterns with optional filters.\n */\n async recall(options?: RecallOptions): Promise<MemoryPattern[]> {\n const result = await this.callTool(\"recall_memory\", {\n programId: this.programId,\n domain: options?.domain,\n query: options?.search,\n includeStale: false,\n });\n\n if (!result.success) {\n throw new Error(`Failed to recall memory: ${result.error || \"Unknown error\"}`);\n }\n\n return result.patterns || [];\n }\n\n /**\n * Get memory health statistics.\n */\n async health(): Promise<MemoryHealth> {\n const result = await this.callTool(\"memory_health\", {\n programId: this.programId,\n });\n\n if (!result.success) {\n throw new Error(`Failed to get memory health: ${result.error || \"Unknown error\"}`);\n }\n\n return result.health;\n }\n\n /**\n * Call an MCP tool via HTTP transport.\n */\n private async callTool(name: string, args: Record<string, unknown>): Promise<any> {\n const request: MCPRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name,\n arguments: args,\n },\n id: this.requestId++,\n };\n\n const response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(request),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n const data: MCPResponse = await response.json();\n\n if (data.error) {\n throw new Error(`MCP error ${data.error.code}: ${data.error.message}`);\n }\n\n if (!data.result) {\n throw new Error(\"MCP response missing result\");\n }\n\n if (data.result.isError) {\n const errorText = data.result.content[0]?.text || \"Unknown error\";\n throw new Error(`MCP tool error: ${errorText}`);\n }\n\n // Parse the text content as JSON\n const textContent = data.result.content[0]?.text;\n if (!textContent) {\n throw new Error(\"MCP response missing content\");\n }\n\n return JSON.parse(textContent);\n }\n}\n"],"mappings":";AAmCO,IAAM,kBAAN,MAAsB;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAY;AAAA,EAEpB,YAAY,QAA+B;AACzC,SAAK,SAAS,OAAO;AACrB,SAAK,WAAW,OAAO,Y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AA;AAAA;AAAA,EAKA,MAAc,SAAS,MAAc,MAA6C;AAChF,UAAM,UAAsB;AAAA,MAC1B,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ;AAAA,QACN;AAAA,QACA,WAAW;AAAA,MACb;AAAA,MACA,IAAI,KAAK;AAAA,IACX;AAEA,UAAM,WAAW,MAAM,MAAM,KAAK,UAAU;AAAA,MAC1C,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe,UAAU,KAAK,MAAM;AAAA,MACtC;AAAA,MACA,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,QAAQ,SAAS,MAAM,KAAK,SAAS,UAAU,EAAE;AAAA,IACnE;AAEA,UAAM,OAAoB,MAAM,SAAS,KAAK;AAE9C,QAAI,KAAK,OAAO;AACd,YAAM,IAAI,MAAM,aAAa,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,OAAO,EAAE;AAAA,IACvE;AAEA,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AAEA,QAAI,KAAK,OAAO,SAAS;AACvB,YAAM,YAAY,KAAK,OAAO,QAAQ,CAAC,GAAG,QAAQ;AAClD,YAAM,IAAI,MAAM,mBAAmB,SAAS,EAAE;AAAA,IAChD;AAGA,UAAM,cAAc,KAAK,OAAO,QAAQ,CAAC,GAAG;AAC5C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,8BAA8B;AAAA,IAChD;AAEA,WAAO,KAAK,MAAM,WAAW;AAAA,EAC/B;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * CacheBashMemory — SDK client for memory pattern storage and recall.\n * Supports both MCP (JSON-RPC) and REST transports.\n */\n\nimport type {\n CacheBashMemoryConfig,\n MemoryPattern,\n MemoryHealth,\n RecallOptions,\n StorePatternInput,\n ReinforceOptions,\n TransportMode,\n} from \"./types.js\";\n\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: Record<string, unknown>;\n };\n id: number;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n result?: {\n content: Array<{ type: string; text: string }>;\n isError?: boolean;\n };\n error?: {\n code: number;\n message: string;\n };\n id: number;\n}\n\ninterface RESTResponse {\n success: boolean;\n data?: any;\n error?: { code: string; message: string };\n}\n\nexport class CacheBashMemory {\n private readonly apiKey: string;\n private readonly endpoint: string;\n private readonly programId: string;\n private readonly transport: TransportMode;\n private requestId = 1;\n\n constructor(config: CacheBashMemoryConfig) {\n this.apiKey = config.apiKey;\n this.programId = config.programId;\n this.transport = config.transport || \"rest\";\n\n if (!this.apiKey) {\n throw new Error(\"CacheBashMemory: apiKey is required\");\n }\n if (!this.programId) {\n throw new Error(\"CacheBashMemory: programId is required\");\n }\n\n if (config.endpoint) {\n this.endpoint = config.endpoint;\n } else {\n this.endpoint = this.transport === \"mcp\"\n ? \"https://api.cachebash.dev/v1/mcp\"\n : \"https://api.cachebash.dev\";\n }\n }\n\n /**\n * Store a memory pattern.\n * If a pattern with the same ID exists, it will be replaced.\n */\n async store(input: StorePatternInput): Promise<void> {\n const now = new Date().toISOString();\n const pattern: MemoryPattern = {\n ...input,\n discoveredAt: now,\n lastReinforced: now,\n promotedToStore: false,\n stale: false,\n };\n\n if (this.transport === \"rest\") {\n await this.restCall(\"POST\", `/v1/memory/${this.programId}/patterns`, { pattern });\n } else {\n await this.mcpCall(\"store_memory\", { programId: this.programId, pattern });\n }\n }\n\n /**\n * Recall memory patterns with optional filters.\n */\n async recall(options?: RecallOptions): Promise<MemoryPattern[]> {\n let result: any;\n\n if (this.transport === \"rest\") {\n const params = new URLSearchParams();\n if (options?.domain) params.set(\"domain\", options.domain);\n if (options?.search) params.set(\"query\", options.search);\n if (options?.includeStale) params.set(\"includeStale\", \"true\");\n const qs = params.toString();\n result = await this.restCall(\"GET\", `/v1/memory/${this.programId}/patterns${qs ? `?${qs}` : \"\"}`);\n } else {\n result = await this.mcpCall(\"recall_memory\", {\n programId: this.programId,\n domain: options?.domain,\n query: options?.search,\n includeStale: options?.includeStale || false,\n });\n }\n\n return result.patterns || [];\n }\n\n /**\n * Get memory health statistics.\n */\n async health(): Promise<MemoryHealth> {\n let result: any;\n\n if (this.transport === \"rest\") {\n result = await this.restCall(\"GET\", `/v1/memory/${this.programId}/health`);\n } else {\n result = await this.mcpCall(\"memory_health\", { programId: this.programId });\n }\n\n return result.health;\n }\n\n /**\n * Delete a memory pattern by ID.\n */\n async delete(patternId: string): Promise<void> {\n if (this.transport === \"rest\") {\n await this.restCall(\"DELETE\", `/v1/memory/${this.programId}/patterns/${patternId}`);\n } else {\n await this.mcpCall(\"delete_memory\", { programId: this.programId, patternId });\n }\n }\n\n /**\n * Reinforce an existing pattern — bumps lastReinforced, optionally updates confidence/evidence.\n */\n async reinforce(patternId: string, options?: ReinforceOptions): Promise<void> {\n if (this.transport === \"rest\") {\n await this.restCall(\"PATCH\", `/v1/memory/${this.programId}/patterns/${patternId}/reinforce`, {\n confidence: options?.confidence,\n evidence: options?.evidence,\n });\n } else {\n await this.mcpCall(\"reinforce_memory\", {\n programId: this.programId,\n patternId,\n confidence: options?.confidence,\n evidence: options?.evidence,\n });\n }\n }\n\n /**\n * Call a tool via REST transport.\n */\n private async restCall(method: string, path: string, body?: Record<string, unknown>): Promise<any> {\n const url = `${this.endpoint}${path}`;\n const options: RequestInit = {\n method,\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n };\n\n if (body && method !== \"GET\") {\n options.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, options);\n\n if (!response.ok) {\n const text = await response.text();\n throw new Error(`HTTP ${response.status}: ${text}`);\n }\n\n const data: RESTResponse = await response.json();\n\n if (!data.success) {\n throw new Error(`API error: ${data.error?.message || \"Unknown error\"}`);\n }\n\n return data.data;\n }\n\n /**\n * Call an MCP tool via JSON-RPC transport.\n */\n private async mcpCall(name: string, args: Record<string, unknown>): Promise<any> {\n const request: MCPRequest = {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: { name, arguments: args },\n id: this.requestId++,\n };\n\n const response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(request),\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n const data: MCPResponse = await response.json();\n\n if (data.error) {\n throw new Error(`MCP error ${data.error.code}: ${data.error.message}`);\n }\n\n if (!data.result) {\n throw new Error(\"MCP response missing result\");\n }\n\n if (data.result.isError) {\n const errorText = data.result.content[0]?.text || \"Unknown error\";\n throw new Error(`MCP tool error: ${errorText}`);\n }\n\n const textContent = data.result.content[0]?.text;\n if (!textContent) {\n throw new Error(\"MCP response missing content\");\n }\n\n const parsed = JSON.parse(textContent);\n if (!parsed.success) {\n throw new Error(`Tool error: ${parsed.error || \"Unknown error\"}`);\n }\n\n return parsed;\n }\n}\n"],"mappings":";AA4CO,IAAM,kBAAN,MAAsB;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAY;AAAA,EAEpB,YAAY,QAA+B;AACzC,SAAK,SAAS,OAAO;AACrB,SAAK,YAAY,OAAO;AACxB,SAAK,YAAY,OAAO,aAAa;AAErC,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AACA,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAEA,QAAI,OAAO,UAAU;AACnB,WAAK,WAAW,OAAO;AAAA,IACzB,OAAO;AACL,WAAK,WAAW,KAAK,cAAc,QAC/B,qCACA;AAAA,IACN;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,M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W;AACrC,QAAI,CAAC,OAAO,SAAS;AACnB,YAAM,IAAI,MAAM,eAAe,OAAO,SAAS,eAAe,EAAE;AAAA,IAClE;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rezzed.ai/memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CacheBash Memory SDK — Lightweight client for memory pattern storage and recall",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,19 +15,25 @@
|
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsup",
|
|
18
|
-
"typecheck": "tsc --noEmit"
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
21
|
+
"test:integration": "vitest run src/__tests__/integration.test.ts",
|
|
22
|
+
"benchmark": "tsx benchmarks/latency.ts"
|
|
19
23
|
},
|
|
20
24
|
"dependencies": {},
|
|
21
25
|
"devDependencies": {
|
|
22
26
|
"tsup": "^8.0.0",
|
|
23
27
|
"typescript": "^5.4.0",
|
|
24
|
-
"@types/node": "^20.0.0"
|
|
28
|
+
"@types/node": "^20.0.0",
|
|
29
|
+
"vitest": "^3.0.0"
|
|
25
30
|
},
|
|
26
31
|
"engines": {
|
|
27
32
|
"node": ">=18.0.0"
|
|
28
33
|
},
|
|
29
34
|
"files": [
|
|
30
|
-
"dist/"
|
|
35
|
+
"dist/",
|
|
36
|
+
"README.md"
|
|
31
37
|
],
|
|
32
38
|
"license": "MIT",
|
|
33
39
|
"repository": {
|