xmemory 2.1.0 → 2.1.2
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 +13 -11
- package/dist/client.d.ts +2 -1
- package/dist/client.js +24 -4
- package/dist/instance.js +3 -3
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ import { XmemoryClient } from "xmemory";
|
|
|
15
15
|
|
|
16
16
|
const xm = new XmemoryClient({
|
|
17
17
|
url: "https://api.xmemory.ai", // or set XMEM_API_URL env var
|
|
18
|
-
|
|
18
|
+
apiKey: "<your-api-key>", // or set XMEM_API_KEY env var
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// Write and read from an existing instance
|
|
@@ -28,11 +28,13 @@ console.log(result.reader_result);
|
|
|
28
28
|
|
|
29
29
|
## Configuration
|
|
30
30
|
|
|
31
|
-
| Parameter | Env var
|
|
32
|
-
|
|
33
|
-
| `url` | `XMEM_API_URL`
|
|
34
|
-
| `
|
|
35
|
-
| `timeoutMs` | —
|
|
31
|
+
| Parameter | Env var | Default | Description |
|
|
32
|
+
|-------------|------------------|---------------------------|-----------------------------------------|
|
|
33
|
+
| `url` | `XMEM_API_URL` | `https://api.xmemory.ai` | Base URL of the Xmemory API |
|
|
34
|
+
| `apiKey` | `XMEM_API_KEY` | `undefined` | Bearer API key for authentication |
|
|
35
|
+
| `timeoutMs` | — | `60000` | Default request timeout in milliseconds |
|
|
36
|
+
|
|
37
|
+
The legacy `token` option and `XMEM_AUTH_TOKEN` env var are still accepted for backwards compatibility but are deprecated and will be removed in a future release. Using them prints a deprecation warning. If both the new and legacy values are set, the new ones win.
|
|
36
38
|
|
|
37
39
|
## Creating a client
|
|
38
40
|
|
|
@@ -40,13 +42,13 @@ console.log(result.reader_result);
|
|
|
40
42
|
import { XmemoryClient, xmemoryInstance } from "xmemory";
|
|
41
43
|
|
|
42
44
|
// Option 1: constructor (no health check)
|
|
43
|
-
const xm1 = new XmemoryClient({
|
|
45
|
+
const xm1 = new XmemoryClient({ apiKey: "..." });
|
|
44
46
|
|
|
45
47
|
// Option 2: factory with health check
|
|
46
|
-
const xm2 = await XmemoryClient.create({
|
|
48
|
+
const xm2 = await XmemoryClient.create({ apiKey: "..." });
|
|
47
49
|
|
|
48
50
|
// Option 3: convenience function (same as Option 2)
|
|
49
|
-
const xm3 = await xmemoryInstance({
|
|
51
|
+
const xm3 = await xmemoryInstance({ apiKey: "..." });
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
## Admin operations
|
|
@@ -122,7 +124,7 @@ const result = await inst.write("Bob is a designer based in Berlin.");
|
|
|
122
124
|
console.log(result.write_id, result.trace_id);
|
|
123
125
|
```
|
|
124
126
|
|
|
125
|
-
Options: `{ extractionLogic?, diffEngine?, timeoutMs? }` — `extractionLogic` defaults to `"
|
|
127
|
+
Options: `{ extractionLogic?, diffEngine?, timeoutMs? }` — `extractionLogic` defaults to `"fast"`.
|
|
126
128
|
|
|
127
129
|
### `inst.writeAsync(text, options?)` → `AsyncWriteResult`
|
|
128
130
|
|
|
@@ -189,7 +191,7 @@ All errors throw `XmemoryAPIError`. Health check failures throw `XmemoryHealthCh
|
|
|
189
191
|
import { XmemoryClient, XmemoryAPIError, XmemoryHealthCheckError } from "xmemory";
|
|
190
192
|
|
|
191
193
|
try {
|
|
192
|
-
const xm = await XmemoryClient.create({
|
|
194
|
+
const xm = await XmemoryClient.create({ apiKey: "..." });
|
|
193
195
|
} catch (e) {
|
|
194
196
|
if (e instanceof XmemoryHealthCheckError) {
|
|
195
197
|
console.error("Server unreachable:", e.message);
|
package/dist/client.d.ts
CHANGED
|
@@ -22,9 +22,10 @@ export interface AdminNamespace {
|
|
|
22
22
|
export declare class XmemoryClient {
|
|
23
23
|
private readonly _baseUrl;
|
|
24
24
|
private readonly _timeoutMs;
|
|
25
|
-
private readonly
|
|
25
|
+
private readonly _apiKey;
|
|
26
26
|
readonly admin: AdminNamespace;
|
|
27
27
|
constructor(options?: XmemoryClientOptions);
|
|
28
|
+
private static _resolveApiKey;
|
|
28
29
|
/** Factory that performs a health check before returning the client. */
|
|
29
30
|
static create(options?: XmemoryClientOptions): Promise<XmemoryClient>;
|
|
30
31
|
/** Return an InstanceHandle scoped to the given instance ID. */
|
package/dist/client.js
CHANGED
|
@@ -5,21 +5,41 @@ import { InstanceHandle } from "./instance.js";
|
|
|
5
5
|
import { XmemoryAPIError, XmemoryHealthCheckError, buildInstanceSchema, } from "./types.js";
|
|
6
6
|
const DEFAULT_BASE_URL = "https://api.xmemory.ai";
|
|
7
7
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
8
|
+
const ORANGE = "\x1b[38;5;208m";
|
|
9
|
+
const RESET = "\x1b[0m";
|
|
10
|
+
function deprecationWarning(message) {
|
|
11
|
+
console.warn(`${ORANGE}[xmemory] DEPRECATION: ${message}${RESET}`);
|
|
12
|
+
}
|
|
8
13
|
// ---------------------------------------------------------------------------
|
|
9
14
|
// Client
|
|
10
15
|
// ---------------------------------------------------------------------------
|
|
11
16
|
export class XmemoryClient {
|
|
12
17
|
_baseUrl;
|
|
13
18
|
_timeoutMs;
|
|
14
|
-
|
|
19
|
+
_apiKey;
|
|
15
20
|
admin;
|
|
16
21
|
constructor(options = {}) {
|
|
17
22
|
const env = typeof process !== "undefined" ? process.env : undefined;
|
|
18
23
|
this._baseUrl = (options.url ?? env?.XMEM_API_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
19
|
-
this.
|
|
24
|
+
this._apiKey = XmemoryClient._resolveApiKey(options, env);
|
|
20
25
|
this._timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
21
26
|
this.admin = this._buildAdmin();
|
|
22
27
|
}
|
|
28
|
+
static _resolveApiKey(options, env) {
|
|
29
|
+
if (options.apiKey != null)
|
|
30
|
+
return options.apiKey;
|
|
31
|
+
if (options.token != null) {
|
|
32
|
+
deprecationWarning("The `token` constructor option is deprecated and will be removed soon. Use `apiKey` instead.");
|
|
33
|
+
return options.token;
|
|
34
|
+
}
|
|
35
|
+
if (env?.XMEM_API_KEY)
|
|
36
|
+
return env.XMEM_API_KEY;
|
|
37
|
+
if (env?.XMEM_AUTH_TOKEN) {
|
|
38
|
+
deprecationWarning("The `XMEM_AUTH_TOKEN` environment variable is deprecated and will be removed soon. Use `XMEM_API_KEY` instead.");
|
|
39
|
+
return env.XMEM_AUTH_TOKEN;
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
23
43
|
/** Factory that performs a health check before returning the client. */
|
|
24
44
|
static async create(options = {}) {
|
|
25
45
|
const client = new XmemoryClient(options);
|
|
@@ -64,8 +84,8 @@ export class XmemoryClient {
|
|
|
64
84
|
};
|
|
65
85
|
if (hasBody)
|
|
66
86
|
h["Content-Type"] = "application/json";
|
|
67
|
-
if (this.
|
|
68
|
-
h["Authorization"] = `Bearer ${this.
|
|
87
|
+
if (this._apiKey)
|
|
88
|
+
h["Authorization"] = `Bearer ${this._apiKey}`;
|
|
69
89
|
return h;
|
|
70
90
|
}
|
|
71
91
|
/** Core request — returns the raw API wrapper `{ids, items, errors}`. */
|
package/dist/instance.js
CHANGED
|
@@ -119,7 +119,7 @@ export class InstanceHandle {
|
|
|
119
119
|
async write(text, options) {
|
|
120
120
|
const body = {
|
|
121
121
|
text,
|
|
122
|
-
extraction_logic: options?.extractionLogic ?? "
|
|
122
|
+
extraction_logic: options?.extractionLogic ?? "fast",
|
|
123
123
|
};
|
|
124
124
|
if (options?.diffEngine != null)
|
|
125
125
|
body.diff_engine = options.diffEngine;
|
|
@@ -131,7 +131,7 @@ export class InstanceHandle {
|
|
|
131
131
|
async writeAsync(text, options) {
|
|
132
132
|
const body = {
|
|
133
133
|
text,
|
|
134
|
-
extraction_logic: options?.extractionLogic ?? "
|
|
134
|
+
extraction_logic: options?.extractionLogic ?? "fast",
|
|
135
135
|
};
|
|
136
136
|
if (options?.diffEngine != null)
|
|
137
137
|
body.diff_engine = options.diffEngine;
|
|
@@ -149,7 +149,7 @@ export class InstanceHandle {
|
|
|
149
149
|
async extract(text, options) {
|
|
150
150
|
const body = {
|
|
151
151
|
text,
|
|
152
|
-
extraction_logic: options?.extractionLogic ?? "
|
|
152
|
+
extraction_logic: options?.extractionLogic ?? "fast",
|
|
153
153
|
};
|
|
154
154
|
return this._requestOne("POST", `/instances/${this.id}/extract`, {
|
|
155
155
|
body,
|
package/dist/types.d.ts
CHANGED