wontopos 2.0.0 → 2.1.1
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/dist/wontopos.d.ts +24 -1
- package/dist/wontopos.js +33 -3
- package/package.json +1 -1
package/dist/wontopos.d.ts
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
* npm install wontopos
|
|
5
5
|
*
|
|
6
6
|
* import { Client } from "wontopos";
|
|
7
|
-
* const mem = new Client({ apiKey: "wos-..." });
|
|
7
|
+
* const mem = new Client({ apiKey: "wos-...", model: "tablet-1" });
|
|
8
8
|
* await mem.add("she prefers tea over coffee", "alice");
|
|
9
9
|
* const hits = await mem.search("what does alice drink?", "alice");
|
|
10
10
|
*
|
|
11
|
+
* The API key picks *which memory* (your account); `model` picks *which engine*
|
|
12
|
+
* reads it. All models share one memory, so you can store
|
|
13
|
+
* with one and recall with another. Set a default in the constructor, or override
|
|
14
|
+
* a single call with `mem.withModel("tablet-1").recall(...)`.
|
|
15
|
+
*
|
|
11
16
|
* Pure semantic retrieval — no keyword/BM25 matching, so it works the SAME in every
|
|
12
17
|
* language. Storing and searching call no LLM; you only pay for embeddings.
|
|
13
18
|
*/
|
|
@@ -36,19 +41,35 @@ export interface RecallResult {
|
|
|
36
41
|
};
|
|
37
42
|
[key: string]: unknown;
|
|
38
43
|
}
|
|
44
|
+
export interface ModelInfo {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
available: boolean;
|
|
48
|
+
/** "shared" — reads the common memory pool; "isolated" — its own dedicated store. */
|
|
49
|
+
memory: "shared" | "isolated";
|
|
50
|
+
}
|
|
39
51
|
export interface ClientOptions {
|
|
40
52
|
apiKey: string;
|
|
41
53
|
/** API base URL (defaults to the hosted service). */
|
|
42
54
|
baseUrl?: string;
|
|
43
55
|
/** Per-request timeout in ms (default 30000). */
|
|
44
56
|
timeoutMs?: number;
|
|
57
|
+
/** Default model for every call (sent as `X-WOS-Model`). See `listModels()`. */
|
|
58
|
+
model?: string;
|
|
45
59
|
}
|
|
46
60
|
/** Wontopos memory client. Store and recall memories, isolated per `userId`. */
|
|
47
61
|
export declare class Client {
|
|
48
62
|
private readonly base;
|
|
49
63
|
private readonly headers;
|
|
50
64
|
private readonly timeoutMs;
|
|
65
|
+
private readonly apiKey;
|
|
51
66
|
constructor(opts: ClientOptions);
|
|
67
|
+
/**
|
|
68
|
+
* A client that uses `model` (sent as `X-WOS-Model`). Use it to set the default
|
|
69
|
+
* (`new Client({ apiKey, model })`) or to override one call
|
|
70
|
+
* (`client.withModel("tablet-1").recall(...)`).
|
|
71
|
+
*/
|
|
72
|
+
withModel(model: string): Client;
|
|
52
73
|
/** Store one memory. `metadata` optional (e.g. { event_date: "2026-03-01" }). */
|
|
53
74
|
add(content: string, userId: string, metadata?: Record<string, unknown>): Promise<any>;
|
|
54
75
|
/** Store a conversation turn (user + assistant) into short-term + long-term memory. */
|
|
@@ -65,6 +86,8 @@ export declare class Client {
|
|
|
65
86
|
history(userId: string): Promise<unknown[]>;
|
|
66
87
|
/** Memory counts for a user: { total_memories, short_term_turns }. */
|
|
67
88
|
stats(userId: string): Promise<any>;
|
|
89
|
+
/** Available models: `[{ id, name, available, memory }, ...]`. Needs no API key. */
|
|
90
|
+
listModels(): Promise<ModelInfo[]>;
|
|
68
91
|
/** Delete a single memory by id. */
|
|
69
92
|
delete(userId: string, memoryId: string): Promise<any>;
|
|
70
93
|
/** Delete ALL memories for a user (GDPR erase). */
|
package/dist/wontopos.js
CHANGED
|
@@ -4,14 +4,20 @@
|
|
|
4
4
|
* npm install wontopos
|
|
5
5
|
*
|
|
6
6
|
* import { Client } from "wontopos";
|
|
7
|
-
* const mem = new Client({ apiKey: "wos-..." });
|
|
7
|
+
* const mem = new Client({ apiKey: "wos-...", model: "tablet-1" });
|
|
8
8
|
* await mem.add("she prefers tea over coffee", "alice");
|
|
9
9
|
* const hits = await mem.search("what does alice drink?", "alice");
|
|
10
10
|
*
|
|
11
|
+
* The API key picks *which memory* (your account); `model` picks *which engine*
|
|
12
|
+
* reads it. All models share one memory, so you can store
|
|
13
|
+
* with one and recall with another. Set a default in the constructor, or override
|
|
14
|
+
* a single call with `mem.withModel("tablet-1").recall(...)`.
|
|
15
|
+
*
|
|
11
16
|
* Pure semantic retrieval — no keyword/BM25 matching, so it works the SAME in every
|
|
12
17
|
* language. Storing and searching call no LLM; you only pay for embeddings.
|
|
13
18
|
*/
|
|
14
19
|
const DEFAULT_BASE_URL = "https://api.wontopos.com";
|
|
20
|
+
const DEFAULT_MODEL = "tablet-1";
|
|
15
21
|
export class WosError extends Error {
|
|
16
22
|
status;
|
|
17
23
|
constructor(status, message) {
|
|
@@ -25,12 +31,25 @@ export class Client {
|
|
|
25
31
|
base;
|
|
26
32
|
headers;
|
|
27
33
|
timeoutMs;
|
|
34
|
+
apiKey;
|
|
28
35
|
constructor(opts) {
|
|
29
36
|
if (!opts?.apiKey)
|
|
30
37
|
throw new Error("apiKey is required");
|
|
38
|
+
this.apiKey = opts.apiKey;
|
|
31
39
|
this.base = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
32
40
|
this.timeoutMs = opts.timeoutMs ?? 30_000;
|
|
41
|
+
const model = opts.model ?? DEFAULT_MODEL;
|
|
33
42
|
this.headers = { "X-API-Key": opts.apiKey, "Content-Type": "application/json" };
|
|
43
|
+
if (model)
|
|
44
|
+
this.headers["X-WOS-Model"] = model;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A client that uses `model` (sent as `X-WOS-Model`). Use it to set the default
|
|
48
|
+
* (`new Client({ apiKey, model })`) or to override one call
|
|
49
|
+
* (`client.withModel("tablet-1").recall(...)`).
|
|
50
|
+
*/
|
|
51
|
+
withModel(model) {
|
|
52
|
+
return new Client({ apiKey: this.apiKey, baseUrl: this.base, timeoutMs: this.timeoutMs, model });
|
|
34
53
|
}
|
|
35
54
|
// ----- write -----
|
|
36
55
|
/** Store one memory. `metadata` optional (e.g. { event_date: "2026-03-01" }). */
|
|
@@ -71,6 +90,15 @@ export class Client {
|
|
|
71
90
|
stats(userId) {
|
|
72
91
|
return this.post("/api/v1/memory/stats", { user_id: userId });
|
|
73
92
|
}
|
|
93
|
+
// ----- models -----
|
|
94
|
+
/** Available models: `[{ id, name, available, memory }, ...]`. Needs no API key. */
|
|
95
|
+
async listModels() {
|
|
96
|
+
const res = await fetch(`${this.base}/api/v1/models`);
|
|
97
|
+
if (!res.ok)
|
|
98
|
+
throw new WosError(res.status, await res.text());
|
|
99
|
+
const data = await res.json();
|
|
100
|
+
return (data.models ?? []);
|
|
101
|
+
}
|
|
74
102
|
// ----- delete -----
|
|
75
103
|
/** Delete a single memory by id. */
|
|
76
104
|
delete(userId, memoryId) {
|
|
@@ -94,7 +122,7 @@ export class Client {
|
|
|
94
122
|
});
|
|
95
123
|
}
|
|
96
124
|
catch (e) {
|
|
97
|
-
throw new WosError(0, `network error: ${e
|
|
125
|
+
throw new WosError(0, `network error: ${e?.message ?? e}`);
|
|
98
126
|
}
|
|
99
127
|
finally {
|
|
100
128
|
clearTimeout(timer);
|
|
@@ -116,7 +144,9 @@ export class Client {
|
|
|
116
144
|
msg = data.message;
|
|
117
145
|
}
|
|
118
146
|
}
|
|
119
|
-
catch {
|
|
147
|
+
catch {
|
|
148
|
+
/* keep raw text */
|
|
149
|
+
}
|
|
120
150
|
throw new WosError(res.status, msg);
|
|
121
151
|
}
|
|
122
152
|
return res.json();
|
package/package.json
CHANGED