xmem-ai 1.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/dist/index.d.ts +3 -0
- package/dist/index.js +13 -0
- package/dist/src/client.d.ts +24 -0
- package/dist/src/client.js +62 -0
- package/dist/src/error.d.ts +27 -0
- package/dist/src/error.js +58 -0
- package/dist/src/network.d.ts +5 -0
- package/dist/src/network.js +54 -0
- package/dist/src/types.d.ts +80 -0
- package/dist/src/types.js +5 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { XMemClient } from "./src/client";
|
|
2
|
+
export type { APIEnvelope, DomainResult, HealthStatus, IngestParams, IngestResult, OperationDetail, RetrieveParams, RetrieveResult, SearchParams, SearchResult, SourceRecord, WeaverSummary, } from "./src/types";
|
|
3
|
+
export { XMemSDKError, AuthenticationError, ConnectionError, NotReadyError, RateLimitError, ServerError, ValidationError, } from "./src/error";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
var client_1 = require("./src/client");
|
|
5
|
+
Object.defineProperty(exports, "XMemClient", { enumerable: true, get: function () { return client_1.XMemClient; } });
|
|
6
|
+
var error_1 = require("./src/error");
|
|
7
|
+
Object.defineProperty(exports, "XMemSDKError", { enumerable: true, get: function () { return error_1.XMemSDKError; } });
|
|
8
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return error_1.AuthenticationError; } });
|
|
9
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return error_1.ConnectionError; } });
|
|
10
|
+
Object.defineProperty(exports, "NotReadyError", { enumerable: true, get: function () { return error_1.NotReadyError; } });
|
|
11
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_1.RateLimitError; } });
|
|
12
|
+
Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return error_1.ServerError; } });
|
|
13
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return error_1.ValidationError; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XMem TypeScript client.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { XMemClient } from "@xmem/sdk";
|
|
6
|
+
*
|
|
7
|
+
* const client = new XMemClient("http://localhost:8000", "sk-...");
|
|
8
|
+
* const result = await client.ingest({ user_query: "I love hiking", user_id: "u1" });
|
|
9
|
+
* const answer = await client.retrieve({ query: "hobbies", user_id: "u1" });
|
|
10
|
+
* console.log(answer.answer);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import type { HealthStatus, IngestParams, IngestResult, RetrieveParams, RetrieveResult, SearchParams, SearchResult } from "./types";
|
|
14
|
+
export declare class XMemClient {
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
private readonly headers;
|
|
17
|
+
constructor(apiUrl?: string, apiKey?: string);
|
|
18
|
+
private req;
|
|
19
|
+
ping(): Promise<HealthStatus>;
|
|
20
|
+
isReady(): Promise<boolean>;
|
|
21
|
+
ingest(params: IngestParams): Promise<IngestResult>;
|
|
22
|
+
retrieve(params: RetrieveParams): Promise<RetrieveResult>;
|
|
23
|
+
search(params: SearchParams): Promise<SearchResult>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* XMem TypeScript client.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { XMemClient } from "@xmem/sdk";
|
|
7
|
+
*
|
|
8
|
+
* const client = new XMemClient("http://localhost:8000", "sk-...");
|
|
9
|
+
* const result = await client.ingest({ user_query: "I love hiking", user_id: "u1" });
|
|
10
|
+
* const answer = await client.retrieve({ query: "hobbies", user_id: "u1" });
|
|
11
|
+
* console.log(answer.answer);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.XMemClient = void 0;
|
|
16
|
+
const network_1 = require("./network");
|
|
17
|
+
class XMemClient {
|
|
18
|
+
constructor(apiUrl, apiKey) {
|
|
19
|
+
this.baseUrl = (apiUrl || process.env.XMEM_API_URL || "http://localhost:8000").replace(/\/$/, "");
|
|
20
|
+
const key = apiKey || process.env.XMEM_API_KEY || "";
|
|
21
|
+
this.headers = {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
...(key ? { Authorization: `Bearer ${key}` } : {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async req(method, path, body) {
|
|
27
|
+
return (0, network_1.request)(this.baseUrl, path, {
|
|
28
|
+
method,
|
|
29
|
+
headers: this.headers,
|
|
30
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// ── Health ───────────────────────────────────────────────────────
|
|
34
|
+
async ping() {
|
|
35
|
+
try {
|
|
36
|
+
const env = await this.req("GET", "/health");
|
|
37
|
+
return env.data;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { status: "unreachable", pipelines_ready: false, version: "" };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async isReady() {
|
|
44
|
+
return (await this.ping()).pipelines_ready;
|
|
45
|
+
}
|
|
46
|
+
// ── Ingest ───────────────────────────────────────────────────────
|
|
47
|
+
async ingest(params) {
|
|
48
|
+
const env = await this.req("POST", "/v1/memory/ingest", params);
|
|
49
|
+
return { ...env.data, request_id: env.request_id, elapsed_ms: env.elapsed_ms };
|
|
50
|
+
}
|
|
51
|
+
// ── Retrieve ─────────────────────────────────────────────────────
|
|
52
|
+
async retrieve(params) {
|
|
53
|
+
const env = await this.req("POST", "/v1/memory/retrieve", params);
|
|
54
|
+
return { ...env.data, request_id: env.request_id, elapsed_ms: env.elapsed_ms };
|
|
55
|
+
}
|
|
56
|
+
// ── Search ───────────────────────────────────────────────────────
|
|
57
|
+
async search(params) {
|
|
58
|
+
const env = await this.req("POST", "/v1/memory/search", params);
|
|
59
|
+
return { ...env.data, request_id: env.request_id, elapsed_ms: env.elapsed_ms };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.XMemClient = XMemClient;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy for the XMem TypeScript SDK.
|
|
3
|
+
*/
|
|
4
|
+
export declare class XMemSDKError extends Error {
|
|
5
|
+
readonly statusCode?: number;
|
|
6
|
+
readonly requestId?: string;
|
|
7
|
+
constructor(message: string, statusCode?: number, requestId?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class AuthenticationError extends XMemSDKError {
|
|
10
|
+
constructor(message: string, statusCode?: number, requestId?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class RateLimitError extends XMemSDKError {
|
|
13
|
+
readonly retryAfter?: number;
|
|
14
|
+
constructor(message: string, statusCode?: number, requestId?: string, retryAfter?: number);
|
|
15
|
+
}
|
|
16
|
+
export declare class ServerError extends XMemSDKError {
|
|
17
|
+
constructor(message: string, statusCode?: number, requestId?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class ValidationError extends XMemSDKError {
|
|
20
|
+
constructor(message: string, statusCode?: number, requestId?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class NotReadyError extends XMemSDKError {
|
|
23
|
+
constructor(message: string, statusCode?: number, requestId?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class ConnectionError extends XMemSDKError {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error hierarchy for the XMem TypeScript SDK.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConnectionError = exports.NotReadyError = exports.ValidationError = exports.ServerError = exports.RateLimitError = exports.AuthenticationError = exports.XMemSDKError = void 0;
|
|
7
|
+
class XMemSDKError extends Error {
|
|
8
|
+
constructor(message, statusCode, requestId) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "XMemSDKError";
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
this.requestId = requestId;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.XMemSDKError = XMemSDKError;
|
|
16
|
+
class AuthenticationError extends XMemSDKError {
|
|
17
|
+
constructor(message, statusCode, requestId) {
|
|
18
|
+
super(message, statusCode, requestId);
|
|
19
|
+
this.name = "AuthenticationError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.AuthenticationError = AuthenticationError;
|
|
23
|
+
class RateLimitError extends XMemSDKError {
|
|
24
|
+
constructor(message, statusCode, requestId, retryAfter) {
|
|
25
|
+
super(message, statusCode, requestId);
|
|
26
|
+
this.name = "RateLimitError";
|
|
27
|
+
this.retryAfter = retryAfter;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.RateLimitError = RateLimitError;
|
|
31
|
+
class ServerError extends XMemSDKError {
|
|
32
|
+
constructor(message, statusCode, requestId) {
|
|
33
|
+
super(message, statusCode, requestId);
|
|
34
|
+
this.name = "ServerError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ServerError = ServerError;
|
|
38
|
+
class ValidationError extends XMemSDKError {
|
|
39
|
+
constructor(message, statusCode, requestId) {
|
|
40
|
+
super(message, statusCode, requestId);
|
|
41
|
+
this.name = "ValidationError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ValidationError = ValidationError;
|
|
45
|
+
class NotReadyError extends XMemSDKError {
|
|
46
|
+
constructor(message, statusCode, requestId) {
|
|
47
|
+
super(message, statusCode, requestId);
|
|
48
|
+
this.name = "NotReadyError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NotReadyError = NotReadyError;
|
|
52
|
+
class ConnectionError extends XMemSDKError {
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "ConnectionError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ConnectionError = ConnectionError;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Internal HTTP transport for the XMem TypeScript SDK.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.request = request;
|
|
7
|
+
const error_1 = require("./error");
|
|
8
|
+
function mapError(status, body) {
|
|
9
|
+
const msg = body.error || body.detail || `HTTP ${status}`;
|
|
10
|
+
const rid = body.request_id;
|
|
11
|
+
if (status === 401 || status === 403)
|
|
12
|
+
return new error_1.AuthenticationError(msg, status, rid);
|
|
13
|
+
if (status === 422)
|
|
14
|
+
return new error_1.ValidationError(msg, status, rid);
|
|
15
|
+
if (status === 429)
|
|
16
|
+
return new error_1.RateLimitError(msg, status, rid, Number(body.retry_after ?? 60));
|
|
17
|
+
if (status === 503)
|
|
18
|
+
return new error_1.NotReadyError(msg, status, rid);
|
|
19
|
+
if (status >= 500)
|
|
20
|
+
return new error_1.ServerError(msg, status, rid);
|
|
21
|
+
return new error_1.XMemSDKError(msg, status, rid);
|
|
22
|
+
}
|
|
23
|
+
async function request(baseUrl, path, init) {
|
|
24
|
+
let response;
|
|
25
|
+
try {
|
|
26
|
+
response = await fetch(`${baseUrl}${path}`, init);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new error_1.ConnectionError(`Connection failed: ${err}`);
|
|
30
|
+
}
|
|
31
|
+
let body;
|
|
32
|
+
try {
|
|
33
|
+
body = (await response.json());
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
if (response.status >= 400) {
|
|
37
|
+
throw mapError(response.status, { error: await response.text().catch(() => "") });
|
|
38
|
+
}
|
|
39
|
+
throw new error_1.XMemSDKError(`Unparseable response (HTTP ${response.status})`);
|
|
40
|
+
}
|
|
41
|
+
if (response.status >= 400) {
|
|
42
|
+
throw mapError(response.status, body);
|
|
43
|
+
}
|
|
44
|
+
if (body.status === "error") {
|
|
45
|
+
throw mapError(response.status || 500, body);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
status: "ok",
|
|
49
|
+
data: body.data,
|
|
50
|
+
error: body.error,
|
|
51
|
+
request_id: body.request_id,
|
|
52
|
+
elapsed_ms: body.elapsed_ms,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the XMem TypeScript SDK.
|
|
3
|
+
*/
|
|
4
|
+
export interface APIEnvelope<T = Record<string, unknown>> {
|
|
5
|
+
status: "ok" | "error";
|
|
6
|
+
data?: T;
|
|
7
|
+
error?: string;
|
|
8
|
+
request_id?: string;
|
|
9
|
+
elapsed_ms?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface HealthStatus {
|
|
12
|
+
status: string;
|
|
13
|
+
pipelines_ready: boolean;
|
|
14
|
+
version: string;
|
|
15
|
+
uptime_seconds?: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IngestParams {
|
|
19
|
+
user_query: string;
|
|
20
|
+
user_id: string;
|
|
21
|
+
agent_response?: string;
|
|
22
|
+
session_datetime?: string;
|
|
23
|
+
image_url?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface OperationDetail {
|
|
26
|
+
type: string;
|
|
27
|
+
content: string;
|
|
28
|
+
reason: string;
|
|
29
|
+
}
|
|
30
|
+
export interface WeaverSummary {
|
|
31
|
+
succeeded: number;
|
|
32
|
+
skipped: number;
|
|
33
|
+
failed: number;
|
|
34
|
+
}
|
|
35
|
+
export interface DomainResult {
|
|
36
|
+
confidence: number;
|
|
37
|
+
operations: OperationDetail[];
|
|
38
|
+
weaver?: WeaverSummary;
|
|
39
|
+
}
|
|
40
|
+
export interface IngestResult {
|
|
41
|
+
model: string;
|
|
42
|
+
classification: unknown[];
|
|
43
|
+
profile?: DomainResult;
|
|
44
|
+
temporal?: DomainResult;
|
|
45
|
+
summary?: DomainResult;
|
|
46
|
+
image?: DomainResult;
|
|
47
|
+
request_id?: string;
|
|
48
|
+
elapsed_ms?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface RetrieveParams {
|
|
51
|
+
query: string;
|
|
52
|
+
user_id: string;
|
|
53
|
+
top_k?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface SourceRecord {
|
|
56
|
+
domain: string;
|
|
57
|
+
content: string;
|
|
58
|
+
score: number;
|
|
59
|
+
metadata: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
export interface RetrieveResult {
|
|
62
|
+
model: string;
|
|
63
|
+
answer: string;
|
|
64
|
+
sources: SourceRecord[];
|
|
65
|
+
confidence: number;
|
|
66
|
+
request_id?: string;
|
|
67
|
+
elapsed_ms?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface SearchParams {
|
|
70
|
+
query: string;
|
|
71
|
+
user_id: string;
|
|
72
|
+
domains?: string[];
|
|
73
|
+
top_k?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface SearchResult {
|
|
76
|
+
results: SourceRecord[];
|
|
77
|
+
total: number;
|
|
78
|
+
request_id?: string;
|
|
79
|
+
elapsed_ms?: number;
|
|
80
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xmem-ai",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"xmem",
|
|
16
|
+
"memory",
|
|
17
|
+
"long-term-memory",
|
|
18
|
+
"llm",
|
|
19
|
+
"rag",
|
|
20
|
+
"ai-agent"
|
|
21
|
+
],
|
|
22
|
+
"author": "Ishaan Gupta",
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"description": "TypeScript SDK for the XMem long-term memory API",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^25.3.1",
|
|
27
|
+
"rimraf": "^6.1.3",
|
|
28
|
+
"typescript": "^5.8.0"
|
|
29
|
+
}
|
|
30
|
+
}
|