@rezzed.ai/memory 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # @rezzed.ai/memory
2
+
3
+ **CacheBash Memory SDK** — Lightweight TypeScript client for storing and recalling learned patterns via CacheBash.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @rezzed.ai/memory
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { CacheBashMemory } from "@rezzed.ai/memory";
15
+
16
+ const memory = new CacheBashMemory({
17
+ apiKey: "your-api-key",
18
+ programId: "your-program-id",
19
+ endpoint: "https://api.cachebash.dev/v1/mcp", // optional, this is the default
20
+ });
21
+
22
+ // Store a memory pattern
23
+ await memory.store({
24
+ id: "pattern-001",
25
+ domain: "workflow",
26
+ pattern: "Always validate input before processing",
27
+ confidence: 0.95,
28
+ evidence: "Prevented 3 runtime errors in production",
29
+ });
30
+
31
+ // Recall all patterns
32
+ const patterns = await memory.recall();
33
+ console.log(patterns);
34
+
35
+ // Recall patterns by domain
36
+ const workflowPatterns = await memory.recall({ domain: "workflow" });
37
+
38
+ // Search patterns
39
+ const searchResults = await memory.recall({ search: "validate" });
40
+
41
+ // Get memory health stats
42
+ 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
+ // }
52
+ ```
53
+
54
+ ## API Reference
55
+
56
+ ### `CacheBashMemory`
57
+
58
+ Main client class for memory operations.
59
+
60
+ #### Constructor
61
+
62
+ ```typescript
63
+ new CacheBashMemory(config: CacheBashMemoryConfig)
64
+ ```
65
+
66
+ **Config:**
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`)
70
+
71
+ #### Methods
72
+
73
+ ##### `store(pattern: StorePatternInput): Promise<void>`
74
+
75
+ Store or update a memory pattern. If a pattern with the same `id` exists, it will be replaced.
76
+
77
+ **Pattern fields:**
78
+ - `id` (string) — Unique pattern identifier
79
+ - `domain` (string) — Domain category (e.g., "workflow", "security", "performance")
80
+ - `pattern` (string) — The learned pattern or rule
81
+ - `confidence` (number) — Confidence score (0-1)
82
+ - `evidence` (string) — Supporting evidence or context
83
+
84
+ ##### `recall(options?: RecallOptions): Promise<MemoryPattern[]>`
85
+
86
+ Recall memory patterns with optional filters.
87
+
88
+ **Options:**
89
+ - `domain` (string, optional) — Filter by domain
90
+ - `search` (string, optional) — Text search across pattern and evidence fields
91
+
92
+ **Returns:** Array of `MemoryPattern` objects (excludes stale patterns by default)
93
+
94
+ ##### `health(): Promise<MemoryHealth>`
95
+
96
+ Get memory health statistics.
97
+
98
+ **Returns:**
99
+ - `totalPatterns` — Total pattern count
100
+ - `promotedPatterns` — Patterns promoted to permanent storage
101
+ - `stalePatterns` — Patterns marked as stale
102
+ - `domains` — List of all domains
103
+ - `avgConfidence` — Average confidence score
104
+ - `oldestPattern` — Timestamp of oldest pattern
105
+ - `newestPattern` — Timestamp of newest pattern
106
+ - `decay` — Decay configuration (TTL, max age, etc.)
107
+
108
+ ## Types
109
+
110
+ ```typescript
111
+ interface MemoryPattern {
112
+ id: string;
113
+ domain: string;
114
+ pattern: string;
115
+ confidence: number;
116
+ evidence: string;
117
+ discoveredAt: string;
118
+ lastReinforced: string;
119
+ promotedToStore: boolean;
120
+ stale: boolean;
121
+ }
122
+
123
+ interface MemoryHealth {
124
+ totalPatterns: number;
125
+ promotedPatterns: number;
126
+ stalePatterns: number;
127
+ domains: string[];
128
+ avgConfidence: number;
129
+ oldestPattern: string | null;
130
+ newestPattern: string | null;
131
+ decay: {
132
+ contextSummaryTTLDays: number;
133
+ learnedPatternMaxAge: number;
134
+ maxUnpromotedPatterns: number;
135
+ lastDecayRun: string;
136
+ };
137
+ }
138
+ ```
139
+
140
+ ## License
141
+
142
+ MIT
143
+
144
+ ## Links
145
+
146
+ - [CacheBash Documentation](https://rezzed.ai/cachebash)
147
+ - [GitHub Repository](https://github.com/rezzedai/cachebash)
148
+ - [Report Issues](https://github.com/rezzedai/cachebash/issues)
@@ -0,0 +1,107 @@
1
+ /**
2
+ * CacheBash Memory SDK Types
3
+ */
4
+ /**
5
+ * A learned pattern stored in program memory.
6
+ */
7
+ interface MemoryPattern {
8
+ id: string;
9
+ domain: string;
10
+ pattern: string;
11
+ confidence: number;
12
+ evidence: string;
13
+ discoveredAt: string;
14
+ lastReinforced: string;
15
+ promotedToStore: boolean;
16
+ stale: boolean;
17
+ }
18
+ /**
19
+ * Memory health statistics.
20
+ */
21
+ interface MemoryHealth {
22
+ totalPatterns: number;
23
+ promotedPatterns: number;
24
+ stalePatterns: number;
25
+ domains: string[];
26
+ avgConfidence: number;
27
+ oldestPattern: string | null;
28
+ newestPattern: string | null;
29
+ decay: {
30
+ contextSummaryTTLDays: number;
31
+ learnedPatternMaxAge: number;
32
+ maxUnpromotedPatterns: number;
33
+ lastDecayRun: string;
34
+ };
35
+ }
36
+ /**
37
+ * Configuration for CacheBashMemory client.
38
+ */
39
+ interface CacheBashMemoryConfig {
40
+ /**
41
+ * CacheBash API key (required).
42
+ */
43
+ apiKey: string;
44
+ /**
45
+ * MCP endpoint URL.
46
+ * @default "https://api.cachebash.dev/v1/mcp"
47
+ */
48
+ endpoint?: string;
49
+ /**
50
+ * Program ID for memory operations.
51
+ */
52
+ programId: string;
53
+ }
54
+ /**
55
+ * Options for recalling memories.
56
+ */
57
+ interface RecallOptions {
58
+ /**
59
+ * Filter by domain (optional).
60
+ */
61
+ domain?: string;
62
+ /**
63
+ * Text search query (optional).
64
+ */
65
+ search?: string;
66
+ }
67
+ /**
68
+ * Pattern to store in memory.
69
+ */
70
+ interface StorePatternInput {
71
+ id: string;
72
+ domain: string;
73
+ pattern: string;
74
+ confidence: number;
75
+ evidence: string;
76
+ }
77
+
78
+ /**
79
+ * CacheBashMemory — SDK client for memory pattern storage and recall.
80
+ */
81
+
82
+ declare class CacheBashMemory {
83
+ private readonly apiKey;
84
+ private readonly endpoint;
85
+ private readonly programId;
86
+ private requestId;
87
+ constructor(config: CacheBashMemoryConfig);
88
+ /**
89
+ * Store a memory pattern.
90
+ * If a pattern with the same ID exists, it will be replaced.
91
+ */
92
+ store(input: StorePatternInput): Promise<void>;
93
+ /**
94
+ * Recall memory patterns with optional filters.
95
+ */
96
+ recall(options?: RecallOptions): Promise<MemoryPattern[]>;
97
+ /**
98
+ * Get memory health statistics.
99
+ */
100
+ health(): Promise<MemoryHealth>;
101
+ /**
102
+ * Call an MCP tool via HTTP transport.
103
+ */
104
+ private callTool;
105
+ }
106
+
107
+ export { CacheBashMemory, type CacheBashMemoryConfig, type MemoryHealth, type MemoryPattern, type RecallOptions, type StorePatternInput };
@@ -0,0 +1,107 @@
1
+ /**
2
+ * CacheBash Memory SDK Types
3
+ */
4
+ /**
5
+ * A learned pattern stored in program memory.
6
+ */
7
+ interface MemoryPattern {
8
+ id: string;
9
+ domain: string;
10
+ pattern: string;
11
+ confidence: number;
12
+ evidence: string;
13
+ discoveredAt: string;
14
+ lastReinforced: string;
15
+ promotedToStore: boolean;
16
+ stale: boolean;
17
+ }
18
+ /**
19
+ * Memory health statistics.
20
+ */
21
+ interface MemoryHealth {
22
+ totalPatterns: number;
23
+ promotedPatterns: number;
24
+ stalePatterns: number;
25
+ domains: string[];
26
+ avgConfidence: number;
27
+ oldestPattern: string | null;
28
+ newestPattern: string | null;
29
+ decay: {
30
+ contextSummaryTTLDays: number;
31
+ learnedPatternMaxAge: number;
32
+ maxUnpromotedPatterns: number;
33
+ lastDecayRun: string;
34
+ };
35
+ }
36
+ /**
37
+ * Configuration for CacheBashMemory client.
38
+ */
39
+ interface CacheBashMemoryConfig {
40
+ /**
41
+ * CacheBash API key (required).
42
+ */
43
+ apiKey: string;
44
+ /**
45
+ * MCP endpoint URL.
46
+ * @default "https://api.cachebash.dev/v1/mcp"
47
+ */
48
+ endpoint?: string;
49
+ /**
50
+ * Program ID for memory operations.
51
+ */
52
+ programId: string;
53
+ }
54
+ /**
55
+ * Options for recalling memories.
56
+ */
57
+ interface RecallOptions {
58
+ /**
59
+ * Filter by domain (optional).
60
+ */
61
+ domain?: string;
62
+ /**
63
+ * Text search query (optional).
64
+ */
65
+ search?: string;
66
+ }
67
+ /**
68
+ * Pattern to store in memory.
69
+ */
70
+ interface StorePatternInput {
71
+ id: string;
72
+ domain: string;
73
+ pattern: string;
74
+ confidence: number;
75
+ evidence: string;
76
+ }
77
+
78
+ /**
79
+ * CacheBashMemory — SDK client for memory pattern storage and recall.
80
+ */
81
+
82
+ declare class CacheBashMemory {
83
+ private readonly apiKey;
84
+ private readonly endpoint;
85
+ private readonly programId;
86
+ private requestId;
87
+ constructor(config: CacheBashMemoryConfig);
88
+ /**
89
+ * Store a memory pattern.
90
+ * If a pattern with the same ID exists, it will be replaced.
91
+ */
92
+ store(input: StorePatternInput): Promise<void>;
93
+ /**
94
+ * Recall memory patterns with optional filters.
95
+ */
96
+ recall(options?: RecallOptions): Promise<MemoryPattern[]>;
97
+ /**
98
+ * Get memory health statistics.
99
+ */
100
+ health(): Promise<MemoryHealth>;
101
+ /**
102
+ * Call an MCP tool via HTTP transport.
103
+ */
104
+ private callTool;
105
+ }
106
+
107
+ export { CacheBashMemory, type CacheBashMemoryConfig, type MemoryHealth, type MemoryPattern, type RecallOptions, type StorePatternInput };
package/dist/index.js ADDED
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CacheBashMemory: () => CacheBashMemory
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/client.ts
28
+ var CacheBashMemory = class {
29
+ apiKey;
30
+ endpoint;
31
+ programId;
32
+ requestId = 1;
33
+ constructor(config) {
34
+ this.apiKey = config.apiKey;
35
+ this.endpoint = config.endpoint || "https://api.cachebash.dev/v1/mcp";
36
+ this.programId = config.programId;
37
+ if (!this.apiKey) {
38
+ throw new Error("CacheBashMemory: apiKey is required");
39
+ }
40
+ if (!this.programId) {
41
+ throw new Error("CacheBashMemory: programId is required");
42
+ }
43
+ }
44
+ /**
45
+ * Store a memory pattern.
46
+ * If a pattern with the same ID exists, it will be replaced.
47
+ */
48
+ async store(input) {
49
+ const now = (/* @__PURE__ */ new Date()).toISOString();
50
+ const pattern = {
51
+ ...input,
52
+ discoveredAt: now,
53
+ lastReinforced: now,
54
+ promotedToStore: false,
55
+ stale: false
56
+ };
57
+ const result = await this.callTool("store_memory", {
58
+ programId: this.programId,
59
+ pattern
60
+ });
61
+ if (!result.success) {
62
+ throw new Error(`Failed to store memory: ${result.error || "Unknown error"}`);
63
+ }
64
+ }
65
+ /**
66
+ * Recall memory patterns with optional filters.
67
+ */
68
+ async recall(options) {
69
+ const result = await this.callTool("recall_memory", {
70
+ programId: this.programId,
71
+ domain: options?.domain,
72
+ query: options?.search,
73
+ includeStale: false
74
+ });
75
+ if (!result.success) {
76
+ throw new Error(`Failed to recall memory: ${result.error || "Unknown error"}`);
77
+ }
78
+ return result.patterns || [];
79
+ }
80
+ /**
81
+ * Get memory health statistics.
82
+ */
83
+ async health() {
84
+ const result = await this.callTool("memory_health", {
85
+ programId: this.programId
86
+ });
87
+ if (!result.success) {
88
+ throw new Error(`Failed to get memory health: ${result.error || "Unknown error"}`);
89
+ }
90
+ return result.health;
91
+ }
92
+ /**
93
+ * Call an MCP tool via HTTP transport.
94
+ */
95
+ async callTool(name, args) {
96
+ const request = {
97
+ jsonrpc: "2.0",
98
+ method: "tools/call",
99
+ params: {
100
+ name,
101
+ arguments: args
102
+ },
103
+ id: this.requestId++
104
+ };
105
+ const response = await fetch(this.endpoint, {
106
+ method: "POST",
107
+ headers: {
108
+ "Content-Type": "application/json",
109
+ Authorization: `Bearer ${this.apiKey}`
110
+ },
111
+ body: JSON.stringify(request)
112
+ });
113
+ if (!response.ok) {
114
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
115
+ }
116
+ const data = await response.json();
117
+ if (data.error) {
118
+ throw new Error(`MCP error ${data.error.code}: ${data.error.message}`);
119
+ }
120
+ if (!data.result) {
121
+ throw new Error("MCP response missing result");
122
+ }
123
+ if (data.result.isError) {
124
+ const errorText = data.result.content[0]?.text || "Unknown error";
125
+ throw new Error(`MCP tool error: ${errorText}`);
126
+ }
127
+ const textContent = data.result.content[0]?.text;
128
+ if (!textContent) {
129
+ throw new Error("MCP response missing content");
130
+ }
131
+ return JSON.parse(textContent);
132
+ }
133
+ };
134
+ // Annotate the CommonJS export names for ESM import in node:
135
+ 0 && (module.exports = {
136
+ CacheBashMemory
137
+ });
138
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,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AA,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":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,111 @@
1
+ // src/client.ts
2
+ var CacheBashMemory = class {
3
+ apiKey;
4
+ endpoint;
5
+ programId;
6
+ requestId = 1;
7
+ constructor(config) {
8
+ this.apiKey = config.apiKey;
9
+ this.endpoint = config.endpoint || "https://api.cachebash.dev/v1/mcp";
10
+ this.programId = config.programId;
11
+ if (!this.apiKey) {
12
+ throw new Error("CacheBashMemory: apiKey is required");
13
+ }
14
+ if (!this.programId) {
15
+ throw new Error("CacheBashMemory: programId is required");
16
+ }
17
+ }
18
+ /**
19
+ * Store a memory pattern.
20
+ * If a pattern with the same ID exists, it will be replaced.
21
+ */
22
+ async store(input) {
23
+ const now = (/* @__PURE__ */ new Date()).toISOString();
24
+ const pattern = {
25
+ ...input,
26
+ discoveredAt: now,
27
+ lastReinforced: now,
28
+ promotedToStore: false,
29
+ stale: false
30
+ };
31
+ const result = await this.callTool("store_memory", {
32
+ programId: this.programId,
33
+ pattern
34
+ });
35
+ if (!result.success) {
36
+ throw new Error(`Failed to store memory: ${result.error || "Unknown error"}`);
37
+ }
38
+ }
39
+ /**
40
+ * Recall memory patterns with optional filters.
41
+ */
42
+ async recall(options) {
43
+ const result = await this.callTool("recall_memory", {
44
+ programId: this.programId,
45
+ domain: options?.domain,
46
+ query: options?.search,
47
+ includeStale: false
48
+ });
49
+ if (!result.success) {
50
+ throw new Error(`Failed to recall memory: ${result.error || "Unknown error"}`);
51
+ }
52
+ return result.patterns || [];
53
+ }
54
+ /**
55
+ * Get memory health statistics.
56
+ */
57
+ async health() {
58
+ const result = await this.callTool("memory_health", {
59
+ programId: this.programId
60
+ });
61
+ if (!result.success) {
62
+ throw new Error(`Failed to get memory health: ${result.error || "Unknown error"}`);
63
+ }
64
+ return result.health;
65
+ }
66
+ /**
67
+ * Call an MCP tool via HTTP transport.
68
+ */
69
+ async callTool(name, args) {
70
+ const request = {
71
+ jsonrpc: "2.0",
72
+ method: "tools/call",
73
+ params: {
74
+ name,
75
+ arguments: args
76
+ },
77
+ id: this.requestId++
78
+ };
79
+ const response = await fetch(this.endpoint, {
80
+ method: "POST",
81
+ headers: {
82
+ "Content-Type": "application/json",
83
+ Authorization: `Bearer ${this.apiKey}`
84
+ },
85
+ body: JSON.stringify(request)
86
+ });
87
+ if (!response.ok) {
88
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
89
+ }
90
+ const data = await response.json();
91
+ if (data.error) {
92
+ throw new Error(`MCP error ${data.error.code}: ${data.error.message}`);
93
+ }
94
+ if (!data.result) {
95
+ throw new Error("MCP response missing result");
96
+ }
97
+ if (data.result.isError) {
98
+ const errorText = data.result.content[0]?.text || "Unknown error";
99
+ throw new Error(`MCP tool error: ${errorText}`);
100
+ }
101
+ const textContent = data.result.content[0]?.text;
102
+ if (!textContent) {
103
+ throw new Error("MCP response missing content");
104
+ }
105
+ return JSON.parse(textContent);
106
+ }
107
+ };
108
+ export {
109
+ CacheBashMemory
110
+ };
111
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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,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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ACb;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":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@rezzed.ai/memory",
3
+ "version": "0.1.0",
4
+ "description": "CacheBash Memory SDK — Lightweight client for memory pattern storage and recall",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "tsup",
18
+ "typecheck": "tsc --noEmit"
19
+ },
20
+ "dependencies": {},
21
+ "devDependencies": {
22
+ "tsup": "^8.0.0",
23
+ "typescript": "^5.4.0",
24
+ "@types/node": "^20.0.0"
25
+ },
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ },
29
+ "files": [
30
+ "dist/"
31
+ ],
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/rezzedai/cachebash.git",
36
+ "directory": "packages/memory"
37
+ },
38
+ "homepage": "https://rezzed.ai/cachebash",
39
+ "bugs": "https://github.com/rezzedai/cachebash/issues",
40
+ "keywords": [
41
+ "cachebash",
42
+ "memory",
43
+ "mcp",
44
+ "ai",
45
+ "agents",
46
+ "patterns",
47
+ "learned-behavior"
48
+ ]
49
+ }