anansi-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,84 @@
1
+ # anansi-memory
2
+
3
+ The memory layer for AI apps. Give any LLM application persistent, synthesized memory in two API calls.
4
+
5
+ ```bash
6
+ npm install anansi-memory
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```typescript
12
+ import AnansiMemory from "@anansi/memory";
13
+
14
+ const memory = new AnansiMemory({ apiKey: process.env.ANANSI_API_KEY });
15
+
16
+ // Store a conversation turn
17
+ await memory.ingest({
18
+ userId: "user_123",
19
+ content: "User is building a voice agent. Prefers TypeScript. Team of 4.",
20
+ sourceType: "conversation",
21
+ });
22
+
23
+ // Before your next LLM call — inject synthesized context into system prompt
24
+ const ctx = await memory.context({ userId: "user_123", q: "what is the user building?" });
25
+ const systemPrompt = `You are a helpful assistant.\n\n${memory.formatForPrompt(ctx)}`;
26
+ ```
27
+
28
+ ## API
29
+
30
+ ### `new AnansiMemory(options)`
31
+
32
+ | Option | Type | Description |
33
+ |---|---|---|
34
+ | `apiKey` | `string` | Your API key (`zzy_...`) |
35
+ | `baseUrl` | `string` | Override API base URL (default: `https://api.zazzy.app`) |
36
+
37
+ ### `memory.ingest(options)`
38
+
39
+ Store content in a user's memory. Returns `{ id, queued: true }`.
40
+
41
+ | Option | Type | Required | Description |
42
+ |---|---|---|---|
43
+ | `userId` | `string` | ✓ | Your internal user ID |
44
+ | `content` | `string` | ✓ | Text to remember, max 100 KB |
45
+ | `sourceType` | `string` | | `conversation`, `document`, `note`, `meeting`, `custom` |
46
+ | `sourceId` | `string` | | Idempotency key — re-ingesting the same ID is a no-op |
47
+ | `metadata` | `object` | | `title`, `author`, `timestamp`, any custom fields |
48
+
49
+ ### `memory.context(options)`
50
+
51
+ Retrieve synthesized memory for a user. Returns `{ static, dynamic, relevant }`.
52
+
53
+ | Option | Type | Required | Description |
54
+ |---|---|---|---|
55
+ | `userId` | `string` | ✓ | Your internal user ID |
56
+ | `q` | `string` | | Optional query to retrieve relevant chunks |
57
+
58
+ ### `memory.formatForPrompt(ctx)`
59
+
60
+ Format a context result into a ready-to-inject system prompt block.
61
+
62
+ ## Error handling
63
+
64
+ ```typescript
65
+ import AnansiMemory, { AnansiError } from "@anansi/memory";
66
+
67
+ try {
68
+ await memory.ingest({ userId, content });
69
+ } catch (err) {
70
+ if (err instanceof AnansiError) {
71
+ console.error(err.statusCode, err.message);
72
+ // 401 — invalid API key
73
+ // 402 — monthly quota exceeded
74
+ // 413 — content too large
75
+ // 429 — rate limit (retry after 60s)
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Links
81
+
82
+ - [Developer Portal](https://api.zazzy.app/portal)
83
+ - [API Docs](https://api.zazzy.app/docs)
84
+ - [GitHub](https://github.com/JibrilSul/zazzy)
@@ -0,0 +1,49 @@
1
+ export interface AnansiMemoryOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ export interface IngestOptions {
6
+ userId: string;
7
+ content: string;
8
+ sourceType?: "conversation" | "document" | "note" | "meeting" | "custom";
9
+ sourceId?: string;
10
+ metadata?: {
11
+ title?: string;
12
+ author?: string;
13
+ timestamp?: string;
14
+ [key: string]: unknown;
15
+ };
16
+ }
17
+ export interface IngestResult {
18
+ id: string;
19
+ queued: boolean;
20
+ }
21
+ export interface ContextOptions {
22
+ userId: string;
23
+ q?: string;
24
+ }
25
+ export interface RelevantChunk {
26
+ content: string;
27
+ similarity: number;
28
+ metadata: Record<string, unknown>;
29
+ }
30
+ export interface ContextResult {
31
+ static: string[];
32
+ dynamic: string[];
33
+ relevant: RelevantChunk[];
34
+ }
35
+ export declare class AnansiMemory {
36
+ private readonly apiKey;
37
+ private readonly baseUrl;
38
+ constructor(options: AnansiMemoryOptions);
39
+ private request;
40
+ ingest(options: IngestOptions): Promise<IngestResult>;
41
+ context(options: ContextOptions): Promise<ContextResult>;
42
+ formatForPrompt(ctx: ContextResult): string;
43
+ }
44
+ export declare class AnansiError extends Error {
45
+ readonly statusCode: number;
46
+ constructor(message: string, statusCode: number);
47
+ }
48
+ export default AnansiMemory;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,cAAc,GAAG,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,mBAAmB;YAM1B,OAAO;IA2Bf,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAUrD,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAM9D,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM;CAsB5C;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKhD;AAED,eAAe,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ // anansi-memory — The memory layer for AI apps
2
+ // Two calls: ingest content, retrieve synthesized context.
3
+ export class AnansiMemory {
4
+ constructor(options) {
5
+ if (!options.apiKey)
6
+ throw new Error("AnansiMemory: apiKey is required");
7
+ this.apiKey = options.apiKey;
8
+ this.baseUrl = (options.baseUrl ?? "https://api.zazzy.app").replace(/\/$/, "");
9
+ }
10
+ async request(method, path, body) {
11
+ const url = `${this.baseUrl}${path}`;
12
+ const res = await fetch(url, {
13
+ method,
14
+ headers: {
15
+ Authorization: `Bearer ${this.apiKey}`,
16
+ ...(body !== undefined ? { "Content-Type": "application/json" } : {}),
17
+ },
18
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
19
+ });
20
+ if (!res.ok) {
21
+ let message = `Anansi API error ${res.status}`;
22
+ try {
23
+ const err = (await res.json());
24
+ if (err.error)
25
+ message = err.error;
26
+ }
27
+ catch { }
28
+ throw new AnansiError(message, res.status);
29
+ }
30
+ return res.json();
31
+ }
32
+ async ingest(options) {
33
+ return this.request("POST", "/v1/ingest", {
34
+ userId: options.userId,
35
+ content: options.content,
36
+ sourceType: options.sourceType,
37
+ sourceId: options.sourceId,
38
+ metadata: options.metadata,
39
+ });
40
+ }
41
+ async context(options) {
42
+ const params = new URLSearchParams({ userId: options.userId });
43
+ if (options.q)
44
+ params.set("q", options.q);
45
+ return this.request("GET", `/v1/context?${params}`);
46
+ }
47
+ formatForPrompt(ctx) {
48
+ const lines = [];
49
+ if (ctx.static.length > 0) {
50
+ lines.push("## User — Stable facts");
51
+ ctx.static.forEach((f) => lines.push(`- ${f}`));
52
+ }
53
+ if (ctx.dynamic.length > 0) {
54
+ if (lines.length > 0)
55
+ lines.push("");
56
+ lines.push("## User — Current context");
57
+ ctx.dynamic.forEach((d) => lines.push(`- ${d}`));
58
+ }
59
+ if (ctx.relevant.length > 0) {
60
+ if (lines.length > 0)
61
+ lines.push("");
62
+ lines.push("## Relevant history");
63
+ ctx.relevant.forEach((r) => lines.push(`- ${r.content}`));
64
+ }
65
+ return lines.join("\n");
66
+ }
67
+ }
68
+ export class AnansiError extends Error {
69
+ constructor(message, statusCode) {
70
+ super(message);
71
+ this.name = "AnansiError";
72
+ this.statusCode = statusCode;
73
+ }
74
+ }
75
+ export default AnansiMemory;
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,2DAA2D;AA0C3D,MAAM,OAAO,YAAY;IAIvB,YAAY,OAA4B;QACtC,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACzE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,uBAAuB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjF,CAAC;IAEO,KAAK,CAAC,OAAO,CACnB,MAAsB,EACtB,IAAY,EACZ,IAAc;QAEd,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,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C,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGpC,YAAY,OAAe,EAAE,UAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,eAAe,YAAY,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "anansi-memory",
3
+ "version": "0.1.0",
4
+ "description": "The memory layer for AI apps — persistent, synthesized context for any LLM application",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc --watch",
18
+ "prepublishOnly": "tsc"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "keywords": ["memory", "llm", "ai", "rag", "context", "vector", "anansi"],
25
+ "license": "MIT",
26
+ "author": "Anansi <hello@zazzy.app>",
27
+ "homepage": "https://zazzy.app",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/JibrilSul/zazzy.git",
31
+ "directory": "packages/sdk"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org"
36
+ },
37
+ "devDependencies": {
38
+ "typescript": "^5.4.0"
39
+ }
40
+ }