wontopos 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wontopos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Wontopos — long-term memory for AI agents
2
+
3
+ ```bash
4
+ npm install wontopos
5
+ ```
6
+
7
+ ```ts
8
+ import { Client } from "wontopos";
9
+
10
+ const mem = new Client({ apiKey: "wos-..." });
11
+ await mem.add("she prefers tea over coffee", "alice");
12
+
13
+ // one call → short-term + long-term + context, ready for your LLM prompt
14
+ const ctx = await mem.recall("what does alice drink?", "alice");
15
+ ```
16
+
17
+ ## Why
18
+
19
+ - **Pure semantic retrieval** — no keyword/BM25. Identical recall in every language (한국어 · 日本語 · 中文 · English).
20
+ - **No LLM in the loop** — `store` / `search` / `recall` never call a language model. You pay embeddings, not generation.
21
+ - **Bounded retrieval** — `recall()` returns a small, fixed-size slice (~1,200 tokens) regardless of how much you've stored.
22
+
23
+ ## Methods
24
+
25
+ `add` · `addTurn` · `addBulk` · `update` · `search` · `recall` · `history` · `stats` · `delete` · `deleteAll`
26
+
27
+ All methods take `{ userId }`. Memories are isolated per user, then per account.
28
+
29
+ ## Errors
30
+
31
+ ```ts
32
+ import { Client, WosError } from "wontopos";
33
+
34
+ try {
35
+ await mem.search("...", "alice");
36
+ } catch (e) {
37
+ if (e instanceof WosError) {
38
+ if (e.status === 401) console.error("API key invalid or revoked");
39
+ else if (e.status === 429) console.error("Rate limited");
40
+ else console.error(e.status, e.message);
41
+ }
42
+ }
43
+ ```
44
+
45
+ ## Self-host
46
+
47
+ ```ts
48
+ const mem = new Client({ apiKey: "...", baseUrl: "https://wos.your-host.com" });
49
+ ```
50
+
51
+ ## Links
52
+
53
+ - Homepage: <https://wontopos.com>
54
+ - API reference: <https://wontopos.com/why> (Developers tab)
55
+ - Repo: <https://github.com/Irina1920/Wos_API>
56
+
57
+ License: MIT.
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Wontopos — long-term memory for AI, in three lines.
3
+ *
4
+ * npm install wontopos
5
+ *
6
+ * import { Client } from "wontopos";
7
+ * const mem = new Client({ apiKey: "wos-..." });
8
+ * await mem.add("she prefers tea over coffee", "alice");
9
+ * const hits = await mem.search("what does alice drink?", "alice");
10
+ *
11
+ * Pure semantic retrieval — no keyword/BM25 matching, so it works the SAME in every
12
+ * language. Storing and searching call no LLM; you only pay for embeddings.
13
+ */
14
+ export declare class WosError extends Error {
15
+ readonly status: number;
16
+ constructor(status: number, message: string);
17
+ }
18
+ export interface Memory {
19
+ id?: string;
20
+ content?: string;
21
+ score?: number;
22
+ [key: string]: unknown;
23
+ }
24
+ export interface RecallResult {
25
+ short_term: {
26
+ turns: unknown[];
27
+ count: number;
28
+ };
29
+ long_term: {
30
+ memories: Memory[];
31
+ count: number;
32
+ };
33
+ context: {
34
+ around_top_memory: unknown[];
35
+ count: number;
36
+ };
37
+ [key: string]: unknown;
38
+ }
39
+ export interface ClientOptions {
40
+ apiKey: string;
41
+ /** API base URL (defaults to the hosted service). */
42
+ baseUrl?: string;
43
+ /** Per-request timeout in ms (default 30000). */
44
+ timeoutMs?: number;
45
+ }
46
+ /** Wontopos memory client. Store and recall memories, isolated per `userId`. */
47
+ export declare class Client {
48
+ private readonly base;
49
+ private readonly headers;
50
+ private readonly timeoutMs;
51
+ constructor(opts: ClientOptions);
52
+ /** Store one memory. `metadata` optional (e.g. { event_date: "2026-03-01" }). */
53
+ add(content: string, userId: string, metadata?: Record<string, unknown>): Promise<any>;
54
+ /** Store a conversation turn (user + assistant) into short-term + long-term memory. */
55
+ addTurn(userId: string, userMsg: string, assistantMsg: string): Promise<any>;
56
+ /** Bulk-ingest a large blob of text (chunked + embedded server-side). For backfilling. */
57
+ addBulk(content: string, userId: string, category?: string, timestamp?: string): Promise<any>;
58
+ /** Supersede an old memory with new content (a fact that changed). */
59
+ update(userId: string, oldMemoryId: string, newContent: string): Promise<any>;
60
+ /** Semantic search over a user's memories. Returns memories, most relevant first. */
61
+ search(query: string, userId: string, limit?: number, opts?: Record<string, unknown>): Promise<Memory[]>;
62
+ /** One-call LLM context: short-term turns + long-term matches + surrounding context. */
63
+ recall(query: string, userId: string): Promise<RecallResult>;
64
+ /** Recent conversation turns (short-term memory). */
65
+ history(userId: string): Promise<unknown[]>;
66
+ /** Memory counts for a user: { total_memories, short_term_turns }. */
67
+ stats(userId: string): Promise<any>;
68
+ /** Delete a single memory by id. */
69
+ delete(userId: string, memoryId: string): Promise<any>;
70
+ /** Delete ALL memories for a user (GDPR erase). */
71
+ deleteAll(userId: string): Promise<any>;
72
+ private post;
73
+ }
74
+ /** Back-compat alias: older code used `WME`. */
75
+ export declare const WME: typeof Client;
76
+ export default Client;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Wontopos — long-term memory for AI, in three lines.
3
+ *
4
+ * npm install wontopos
5
+ *
6
+ * import { Client } from "wontopos";
7
+ * const mem = new Client({ apiKey: "wos-..." });
8
+ * await mem.add("she prefers tea over coffee", "alice");
9
+ * const hits = await mem.search("what does alice drink?", "alice");
10
+ *
11
+ * Pure semantic retrieval — no keyword/BM25 matching, so it works the SAME in every
12
+ * language. Storing and searching call no LLM; you only pay for embeddings.
13
+ */
14
+ const DEFAULT_BASE_URL = "https://api.wontopos.com";
15
+ export class WosError extends Error {
16
+ status;
17
+ constructor(status, message) {
18
+ super(`[${status}] ${message}`);
19
+ this.name = "WosError";
20
+ this.status = status;
21
+ }
22
+ }
23
+ /** Wontopos memory client. Store and recall memories, isolated per `userId`. */
24
+ export class Client {
25
+ base;
26
+ headers;
27
+ timeoutMs;
28
+ constructor(opts) {
29
+ if (!opts?.apiKey)
30
+ throw new Error("apiKey is required");
31
+ this.base = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
32
+ this.timeoutMs = opts.timeoutMs ?? 30_000;
33
+ this.headers = { "X-API-Key": opts.apiKey, "Content-Type": "application/json" };
34
+ }
35
+ // ----- write -----
36
+ /** Store one memory. `metadata` optional (e.g. { event_date: "2026-03-01" }). */
37
+ add(content, userId, metadata = {}) {
38
+ return this.post("/api/v1/memory/store", { user_id: userId, content, metadata });
39
+ }
40
+ /** Store a conversation turn (user + assistant) into short-term + long-term memory. */
41
+ addTurn(userId, userMsg, assistantMsg) {
42
+ return this.post("/api/v1/memory/store-turn", { user_id: userId, user_msg: userMsg, assistant_msg: assistantMsg });
43
+ }
44
+ /** Bulk-ingest a large blob of text (chunked + embedded server-side). For backfilling. */
45
+ addBulk(content, userId, category = "general", timestamp) {
46
+ const body = { user_id: userId, content, category };
47
+ if (timestamp)
48
+ body.timestamp = timestamp;
49
+ return this.post("/api/v1/memory/bulk-store", body);
50
+ }
51
+ /** Supersede an old memory with new content (a fact that changed). */
52
+ update(userId, oldMemoryId, newContent) {
53
+ return this.post("/api/v1/memory/supersede", { user_id: userId, old_memory_id: oldMemoryId, new_content: newContent });
54
+ }
55
+ // ----- read -----
56
+ /** Semantic search over a user's memories. Returns memories, most relevant first. */
57
+ async search(query, userId, limit = 10, opts = {}) {
58
+ const r = await this.post("/api/v1/memory/search", { user_id: userId, query, max_results: limit, ...opts });
59
+ return (r.memories ?? []);
60
+ }
61
+ /** One-call LLM context: short-term turns + long-term matches + surrounding context. */
62
+ recall(query, userId) {
63
+ return this.post("/api/v1/memory/recall", { user_id: userId, query });
64
+ }
65
+ /** Recent conversation turns (short-term memory). */
66
+ async history(userId) {
67
+ const r = await this.post("/api/v1/memory/history", { user_id: userId });
68
+ return (r.turns ?? []);
69
+ }
70
+ /** Memory counts for a user: { total_memories, short_term_turns }. */
71
+ stats(userId) {
72
+ return this.post("/api/v1/memory/stats", { user_id: userId });
73
+ }
74
+ // ----- delete -----
75
+ /** Delete a single memory by id. */
76
+ delete(userId, memoryId) {
77
+ return this.post("/api/v1/memory/forget", { user_id: userId, memory_id: memoryId });
78
+ }
79
+ /** Delete ALL memories for a user (GDPR erase). */
80
+ deleteAll(userId) {
81
+ return this.post("/api/v1/memory/forget", { user_id: userId });
82
+ }
83
+ // ----- internal -----
84
+ async post(path, body) {
85
+ const ctrl = new AbortController();
86
+ const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
87
+ let res;
88
+ try {
89
+ res = await fetch(`${this.base}${path}`, {
90
+ method: "POST",
91
+ headers: this.headers,
92
+ body: JSON.stringify(body),
93
+ signal: ctrl.signal,
94
+ });
95
+ }
96
+ catch (e) {
97
+ throw new WosError(0, `network error: ${e.message}`);
98
+ }
99
+ finally {
100
+ clearTimeout(timer);
101
+ }
102
+ if (!res.ok) {
103
+ // Server returns either Anthropic-style envelope
104
+ // {"type":"error","error":{"type":...,"message":...,"request_id":...}}
105
+ // or simple {"error":"reason"}. Fall back to raw text.
106
+ let msg = await res.text();
107
+ try {
108
+ const data = JSON.parse(msg);
109
+ if (data && typeof data === "object") {
110
+ const err = data.error;
111
+ if (err && typeof err === "object")
112
+ msg = err.message ?? err.type ?? msg;
113
+ else if (typeof err === "string")
114
+ msg = err;
115
+ else if (typeof data.message === "string")
116
+ msg = data.message;
117
+ }
118
+ }
119
+ catch { /* keep raw text */ }
120
+ throw new WosError(res.status, msg);
121
+ }
122
+ return res.json();
123
+ }
124
+ }
125
+ /** Back-compat alias: older code used `WME`. */
126
+ export const WME = Client;
127
+ export default Client;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "wontopos",
3
+ "version": "2.0.0",
4
+ "description": "Wontopos — long-term memory for AI agents. Pure semantic retrieval, identical recall in every language, ~100× lower LLM bill.",
5
+ "keywords": [
6
+ "memory",
7
+ "ai",
8
+ "agent",
9
+ "llm",
10
+ "vector",
11
+ "embedding",
12
+ "semantic",
13
+ "rag",
14
+ "context"
15
+ ],
16
+ "homepage": "https://wontopos.com",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Irina1920/Wos_API.git",
20
+ "directory": "sdk/typescript"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/Irina1920/Wos_API/issues"
24
+ },
25
+ "license": "MIT",
26
+ "author": "Wontopos",
27
+ "type": "module",
28
+ "main": "./dist/wontopos.js",
29
+ "module": "./dist/wontopos.js",
30
+ "types": "./dist/wontopos.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/wontopos.d.ts",
34
+ "import": "./dist/wontopos.js",
35
+ "default": "./dist/wontopos.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "engines": {
44
+ "node": ">=18"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "prepublishOnly": "npm run build"
49
+ },
50
+ "devDependencies": {
51
+ "typescript": "^5.4.0"
52
+ }
53
+ }