xmem-ai 1.1.0 → 2.0.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/README.md +95 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/src/client.d.ts +5 -3
- package/dist/src/client.js +22 -7
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# xmem-ai
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [XMem](https://github.com/xmem-ai/xmem) long-term memory API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install xmem-ai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
All constructor arguments are required: API base URL, API key, and username (sent on every request via the `X-XMem-Username` header).
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { XMemClient } from "xmem-ai";
|
|
17
|
+
|
|
18
|
+
const client = new XMemClient(
|
|
19
|
+
"http://localhost:8000",
|
|
20
|
+
process.env.XMEM_API_KEY!,
|
|
21
|
+
"alice",
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const ready = await client.isReady();
|
|
25
|
+
|
|
26
|
+
await client.ingest({
|
|
27
|
+
user_query: "Hello",
|
|
28
|
+
user_id: "user_42",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const answer = await client.retrieve({
|
|
32
|
+
query: "What did we talk about?",
|
|
33
|
+
user_id: "user_42",
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Error handling
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import {
|
|
41
|
+
XMemClient,
|
|
42
|
+
AuthenticationError,
|
|
43
|
+
RateLimitError,
|
|
44
|
+
} from "xmem-ai";
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
await client.ingest({ user_query: "test", user_id: "u1" });
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (e instanceof AuthenticationError) {
|
|
50
|
+
console.error(`Auth failed: ${e.message}`);
|
|
51
|
+
} else if (e instanceof RateLimitError) {
|
|
52
|
+
console.error(`Rate limited, retry after ${e.retryAfter}s`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Migrating from 1.x
|
|
58
|
+
|
|
59
|
+
Version **2.0.0** is a breaking release.
|
|
60
|
+
|
|
61
|
+
### Constructor
|
|
62
|
+
|
|
63
|
+
**Before (1.x):**
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
new XMemClient(); // defaults: localhost, no API key
|
|
67
|
+
new XMemClient(apiUrl);
|
|
68
|
+
new XMemClient(apiUrl, apiKey);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Optional arguments fell back to `process.env.XMEM_API_URL`, `process.env.XMEM_API_KEY`, and defaults.
|
|
72
|
+
|
|
73
|
+
**After (2.x):**
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
new XMemClient(apiUrl, apiKey, username);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- `apiUrl`, `apiKey`, and `username` are **required** strings.
|
|
80
|
+
- Passing `undefined`, `null`, or whitespace-only values throws **`Error`** immediately (before any network call).
|
|
81
|
+
- Username is included on **every** request as the **`X-XMem-Username`** HTTP header.
|
|
82
|
+
|
|
83
|
+
Replace previous env-only setups by reading variables yourself and passing them explicitly:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const apiUrl = process.env.XMEM_API_URL ?? "http://localhost:8000";
|
|
87
|
+
const apiKey = process.env.XMEM_API_KEY!;
|
|
88
|
+
const username = process.env.XMEM_USERNAME!;
|
|
89
|
+
|
|
90
|
+
const client = new XMemClient(apiUrl, apiKey, username);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
Apache-2.0 License
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { XMemClient } from "./src/client";
|
|
1
|
+
export { XMemClient, XMEM_USERNAME_HEADER } from "./src/client";
|
|
2
2
|
export type { APIEnvelope, CodeQueryParams, CodeQueryResult, DirectoryNode, DirectoryTreeResult, DomainResult, HealthStatus, IngestParams, IngestResult, OperationDetail, RepoListResult, RetrieveParams, RetrieveResult, SearchParams, SearchResult, SourceRecord, WeaverSummary, } from "./src/types";
|
|
3
3
|
export { XMemSDKError, AuthenticationError, ConnectionError, NotReadyError, RateLimitError, ServerError, ValidationError, } from "./src/error";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.ServerError = exports.RateLimitError = exports.NotReadyError = exports.ConnectionError = exports.AuthenticationError = exports.XMemSDKError = exports.XMemClient = void 0;
|
|
3
|
+
exports.ValidationError = exports.ServerError = exports.RateLimitError = exports.NotReadyError = exports.ConnectionError = exports.AuthenticationError = exports.XMemSDKError = exports.XMEM_USERNAME_HEADER = exports.XMemClient = void 0;
|
|
4
4
|
var client_1 = require("./src/client");
|
|
5
5
|
Object.defineProperty(exports, "XMemClient", { enumerable: true, get: function () { return client_1.XMemClient; } });
|
|
6
|
+
Object.defineProperty(exports, "XMEM_USERNAME_HEADER", { enumerable: true, get: function () { return client_1.XMEM_USERNAME_HEADER; } });
|
|
6
7
|
var error_1 = require("./src/error");
|
|
7
8
|
Object.defineProperty(exports, "XMemSDKError", { enumerable: true, get: function () { return error_1.XMemSDKError; } });
|
|
8
9
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return error_1.AuthenticationError; } });
|
package/dist/src/client.d.ts
CHANGED
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
* XMem TypeScript client.
|
|
3
3
|
*
|
|
4
4
|
* ```ts
|
|
5
|
-
* import { XMemClient } from "
|
|
5
|
+
* import { XMemClient } from "xmem-ai";
|
|
6
6
|
*
|
|
7
|
-
* const client = new XMemClient("http://localhost:8000", "sk-...");
|
|
7
|
+
* const client = new XMemClient("http://localhost:8000", "sk-...", "alice");
|
|
8
8
|
* const result = await client.ingest({ user_query: "I love hiking", user_id: "u1" });
|
|
9
9
|
* const answer = await client.retrieve({ query: "hobbies", user_id: "u1" });
|
|
10
10
|
* console.log(answer.answer);
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
import type { CodeQueryParams, CodeQueryResult, DirectoryTreeResult, HealthStatus, IngestParams, IngestResult, RepoListResult, RetrieveParams, RetrieveResult, SearchParams, SearchResult } from "./types";
|
|
14
|
+
/** HTTP header name used to send the SDK username on every request. */
|
|
15
|
+
export declare const XMEM_USERNAME_HEADER = "X-XMem-Username";
|
|
14
16
|
export declare class XMemClient {
|
|
15
17
|
private readonly baseUrl;
|
|
16
18
|
private readonly headers;
|
|
17
|
-
constructor(apiUrl
|
|
19
|
+
constructor(apiUrl: string, apiKey: string, username: string);
|
|
18
20
|
private req;
|
|
19
21
|
ping(): Promise<HealthStatus>;
|
|
20
22
|
isReady(): Promise<boolean>;
|
package/dist/src/client.js
CHANGED
|
@@ -3,24 +3,39 @@
|
|
|
3
3
|
* XMem TypeScript client.
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
|
-
* import { XMemClient } from "
|
|
6
|
+
* import { XMemClient } from "xmem-ai";
|
|
7
7
|
*
|
|
8
|
-
* const client = new XMemClient("http://localhost:8000", "sk-...");
|
|
8
|
+
* const client = new XMemClient("http://localhost:8000", "sk-...", "alice");
|
|
9
9
|
* const result = await client.ingest({ user_query: "I love hiking", user_id: "u1" });
|
|
10
10
|
* const answer = await client.retrieve({ query: "hobbies", user_id: "u1" });
|
|
11
11
|
* console.log(answer.answer);
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.XMemClient = void 0;
|
|
15
|
+
exports.XMemClient = exports.XMEM_USERNAME_HEADER = void 0;
|
|
16
16
|
const network_1 = require("./network");
|
|
17
|
+
/** HTTP header name used to send the SDK username on every request. */
|
|
18
|
+
exports.XMEM_USERNAME_HEADER = "X-XMem-Username";
|
|
19
|
+
function requireNonEmptyString(paramName, value) {
|
|
20
|
+
if (value === undefined || value === null) {
|
|
21
|
+
throw new Error(`XMemClient: ${paramName} is required`);
|
|
22
|
+
}
|
|
23
|
+
const s = String(value).trim();
|
|
24
|
+
if (!s) {
|
|
25
|
+
throw new Error(`XMemClient: ${paramName} cannot be empty`);
|
|
26
|
+
}
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
17
29
|
class XMemClient {
|
|
18
|
-
constructor(apiUrl, apiKey) {
|
|
19
|
-
|
|
20
|
-
const key = apiKey
|
|
30
|
+
constructor(apiUrl, apiKey, username) {
|
|
31
|
+
const url = requireNonEmptyString("apiUrl", apiUrl);
|
|
32
|
+
const key = requireNonEmptyString("apiKey", apiKey);
|
|
33
|
+
const user = requireNonEmptyString("username", username);
|
|
34
|
+
this.baseUrl = url.replace(/\/$/, "");
|
|
21
35
|
this.headers = {
|
|
22
36
|
"Content-Type": "application/json",
|
|
23
|
-
|
|
37
|
+
Authorization: `Bearer ${key}`,
|
|
38
|
+
[exports.XMEM_USERNAME_HEADER]: user,
|
|
24
39
|
};
|
|
25
40
|
}
|
|
26
41
|
async req(method, path, body) {
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.XMemSDKError = exports.XMemClient = void 0;
|
|
17
|
+
exports.XMemSDKError = exports.XMEM_USERNAME_HEADER = exports.XMemClient = void 0;
|
|
18
18
|
var client_1 = require("./client");
|
|
19
19
|
Object.defineProperty(exports, "XMemClient", { enumerable: true, get: function () { return client_1.XMemClient; } });
|
|
20
|
+
Object.defineProperty(exports, "XMEM_USERNAME_HEADER", { enumerable: true, get: function () { return client_1.XMEM_USERNAME_HEADER; } });
|
|
20
21
|
__exportStar(require("./types"), exports);
|
|
21
22
|
var error_1 = require("./error");
|
|
22
23
|
Object.defineProperty(exports, "XMemSDKError", { enumerable: true, get: function () { return error_1.XMemSDKError; } });
|
package/dist/src/types.d.ts
CHANGED