korely-memory 0.1.9 → 0.1.11
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 +25 -4
- package/dist/ai-sdk.cjs +53 -3
- package/dist/ai-sdk.js +37 -3
- package/dist/chunk-6SD5RRK3.js +31 -0
- package/dist/index.cjs +410 -100
- package/dist/index.d.cts +265 -15
- package/dist/index.d.ts +265 -15
- package/dist/index.js +395 -100
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -114,6 +114,11 @@ Every method maps to one REST endpoint.
|
|
|
114
114
|
| `events(opts?)` | `GET /v1/events` | Which writes are still being extracted; `limit` up to 200. |
|
|
115
115
|
| `batch(memories)` | `POST /v1/batch` | Bulk import, for migrations. Each item takes `timestamp`, as `add()` does. |
|
|
116
116
|
| `batchStatus(jobId)` | `GET /v1/batch/:id` | Poll an import job. |
|
|
117
|
+
| `ping()` | `GET /v1/ping` | Check a key without spending anything (no scope, rate limit or quota): its `tier`, `region` and `scopes`. Both products. |
|
|
118
|
+
| `Korely.initAgent(agentCaller?, opts?)` | `POST /v1/agents/init` | Cloud only. Static, no key needed: sign up for a free hobby key (shown once, save it), then `new Korely({ apiKey: result.api_key })`. `opts` takes `baseUrl`, `region`, `timeoutMs`, `fetch`. |
|
|
119
|
+
| `deleteAccount({ confirm: true })` | `DELETE /v1/account` | Cloud only. Delete the key's account for good, every key, memory and fact; for an account `korely init --agent` made, which nobody signs in to. One with a login rejects with `ConflictError` (`account_has_login`). Without `confirm: true` nothing is sent. The Self-hosted answers 404 (405 where it serves its dashboard). |
|
|
120
|
+
| `audit(opts?)` | `GET /v1/audit` | The trail of the key's project, newest first: `user_id`, `action`, `since` / `until` (ISO text or `Date`), `limit` up to 1000. Ids, never content. Both products; needs `memories:read`, costs no quota. |
|
|
121
|
+
| `iterAudit(opts?)` | `GET /v1/audit`, every page | `for await (const e of korely.iterAudit({ user_id }))`: an export, `page_size` events per request, `until` pinned when it starts. |
|
|
117
122
|
|
|
118
123
|
## Bi-temporal facts (the moat)
|
|
119
124
|
|
|
@@ -157,21 +162,37 @@ try {
|
|
|
157
162
|
```
|
|
158
163
|
|
|
159
164
|
`AuthenticationError` (401) · `NamespaceForbiddenError` (403, e.g.
|
|
160
|
-
`agent_cap_exceeded`) · `NotFoundError` (404) · `
|
|
165
|
+
`agent_cap_exceeded`) · `NotFoundError` (404) · `ConflictError` (409, e.g.
|
|
166
|
+
`account_has_login`; `stale_write` is its subclass `StaleWriteError`) ·
|
|
161
167
|
`QuotaExceededError` (429: `retryAfter` is set for `rate_limit_exceeded`,
|
|
162
|
-
undefined for the monthly `quota_exceeded`) · `
|
|
163
|
-
|
|
168
|
+
undefined for the monthly `quota_exceeded`) · `TooManyBatchesError` (a
|
|
169
|
+
`QuotaExceededError`: `too_many_batches` from `batch()`, Cloud only, three
|
|
170
|
+
imports still running; send again when one finishes) · `APIError` (the base
|
|
171
|
+
of all of these, and everything else: 422, 503). Every `APIError` has
|
|
172
|
+
`retryAfter` when the server sent `Retry-After`: a rate limit, and the Cloud's
|
|
173
|
+
503 `writes_paused` (writes that need a model are paused until 00:00 UTC). The
|
|
174
|
+
SDK does not retry on its own.
|
|
164
175
|
|
|
165
176
|
## Configuration
|
|
166
177
|
|
|
167
178
|
```ts
|
|
168
179
|
new Korely({
|
|
169
180
|
apiKey: "kor_live_...", // or the KORELY_API_KEY env var
|
|
170
|
-
region: "eu", //
|
|
181
|
+
region: "eu", // the API, api.korely.ai: data stored in the EU
|
|
171
182
|
timeoutMs: 30000, // covers the whole request, response body included
|
|
172
183
|
});
|
|
173
184
|
```
|
|
174
185
|
|
|
186
|
+
The data is stored in the EU (Helsinki). Which model reads a memory, and
|
|
187
|
+
where, is the project's region, chosen per project in the dashboard: Europe
|
|
188
|
+
(gpt-oss-120b on Scaleway, in Paris) or Global (Gemini, by Google), the
|
|
189
|
+
default. A memory written to a Global project is read by Google's model.
|
|
190
|
+
|
|
191
|
+
In Node, `new Korely()` with no key and no `KORELY_API_KEY` reads what
|
|
192
|
+
`korely init` saved (the key and the server, in `~/.korely/config.json`, or
|
|
193
|
+
`$KORELY_CONFIG_HOME/config.json`), as the Python client does. An argument
|
|
194
|
+
comes first, then the environment, then that file.
|
|
195
|
+
|
|
175
196
|
### Your own server (korely-agent)
|
|
176
197
|
|
|
177
198
|
Point the client at your install with `baseUrl`, or with the `KORELY_BASE_URL`
|
package/dist/ai-sdk.cjs
CHANGED
|
@@ -27,6 +27,27 @@ __export(ai_sdk_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(ai_sdk_exports);
|
|
28
28
|
var import_ai = require("ai");
|
|
29
29
|
var import_korely_memory = require("korely-memory");
|
|
30
|
+
|
|
31
|
+
// src/options.ts
|
|
32
|
+
function keysOf() {
|
|
33
|
+
return (...keys) => keys;
|
|
34
|
+
}
|
|
35
|
+
function unknownOption(method, opts, known) {
|
|
36
|
+
if (opts === void 0 || opts === null) return void 0;
|
|
37
|
+
if (typeof opts !== "object" || Array.isArray(opts)) {
|
|
38
|
+
return `${method}: the options must be an object, got ${Array.isArray(opts) ? "an array" : typeof opts}.`;
|
|
39
|
+
}
|
|
40
|
+
for (const key of Object.keys(opts)) {
|
|
41
|
+
if (known.includes(key)) continue;
|
|
42
|
+
const snake = key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
43
|
+
const camel = key.replace(/_([a-z])/g, (_m, c) => c.toUpperCase());
|
|
44
|
+
const meant = known.includes(snake) ? snake : known.includes(camel) ? camel : void 0;
|
|
45
|
+
return `${method}: unknown option ${key}.` + (meant ? ` Did you mean ${meant}?` : "") + ` It takes: ${known.join(", ")}.`;
|
|
46
|
+
}
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/ai-sdk.ts
|
|
30
51
|
var QUERY_MAX = 2e3;
|
|
31
52
|
var CONTENT_MAX = 16e3;
|
|
32
53
|
var USER_MAX = 6e3;
|
|
@@ -36,7 +57,36 @@ var CONTEXT_REUSE_MS = 5 * 6e4;
|
|
|
36
57
|
var FAILURE_REUSE_MS = 3e4;
|
|
37
58
|
var DEFAULT_CONTEXT_TIMEOUT_MS = 5e3;
|
|
38
59
|
var MAX_TIMER_MS = 2 ** 31 - 1;
|
|
39
|
-
|
|
60
|
+
var TOOLS_KEYS = keysOf()(
|
|
61
|
+
"userId",
|
|
62
|
+
"agentId",
|
|
63
|
+
"runId",
|
|
64
|
+
"client",
|
|
65
|
+
"tokenBudget",
|
|
66
|
+
"includeDate",
|
|
67
|
+
"timeZone",
|
|
68
|
+
"contextTimeoutMs",
|
|
69
|
+
"onError"
|
|
70
|
+
);
|
|
71
|
+
var MEMORY_KEYS = keysOf()(
|
|
72
|
+
"userId",
|
|
73
|
+
"agentId",
|
|
74
|
+
"runId",
|
|
75
|
+
"client",
|
|
76
|
+
"tokenBudget",
|
|
77
|
+
"includeDate",
|
|
78
|
+
"timeZone",
|
|
79
|
+
"contextTimeoutMs",
|
|
80
|
+
"onError",
|
|
81
|
+
"remember",
|
|
82
|
+
"waitUntil"
|
|
83
|
+
);
|
|
84
|
+
function checkOptions(method, opts, known) {
|
|
85
|
+
const problem = unknownOption(method, opts, known);
|
|
86
|
+
if (problem) throw new import_korely_memory.KorelyError(problem);
|
|
87
|
+
}
|
|
88
|
+
function scopeOf(options, caller, known) {
|
|
89
|
+
checkOptions(caller, options, known);
|
|
40
90
|
const o = options ?? {};
|
|
41
91
|
if (typeof o.userId !== "string" || !o.userId.trim()) {
|
|
42
92
|
throw new import_korely_memory.KorelyError(
|
|
@@ -168,7 +218,7 @@ function readWithin(read, limit) {
|
|
|
168
218
|
});
|
|
169
219
|
}
|
|
170
220
|
function korelyMemoryMiddleware(options) {
|
|
171
|
-
const scope = scopeOf(options, "korelyMemoryMiddleware");
|
|
221
|
+
const scope = scopeOf(options, "korelyMemoryMiddleware", MEMORY_KEYS);
|
|
172
222
|
const remember = options.remember ?? true;
|
|
173
223
|
const report = scope.report;
|
|
174
224
|
const waitUntil = options.waitUntil;
|
|
@@ -286,7 +336,7 @@ function oneText(value, key, max) {
|
|
|
286
336
|
return { success: true, value: { [key]: clip(raw.trim(), max) } };
|
|
287
337
|
}
|
|
288
338
|
function korelyTools(options) {
|
|
289
|
-
const scope = scopeOf(options, "korelyTools");
|
|
339
|
+
const scope = scopeOf(options, "korelyTools", TOOLS_KEYS);
|
|
290
340
|
const withDate = (text) => scope.today ? `${scope.today()}
|
|
291
341
|
|
|
292
342
|
${text}` : text;
|
package/dist/ai-sdk.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
keysOf,
|
|
3
|
+
unknownOption
|
|
4
|
+
} from "./chunk-6SD5RRK3.js";
|
|
5
|
+
|
|
1
6
|
// src/ai-sdk.ts
|
|
2
7
|
import { gateway, jsonSchema, tool, wrapLanguageModel } from "ai";
|
|
3
8
|
import { Korely, KorelyError } from "korely-memory";
|
|
@@ -10,7 +15,36 @@ var CONTEXT_REUSE_MS = 5 * 6e4;
|
|
|
10
15
|
var FAILURE_REUSE_MS = 3e4;
|
|
11
16
|
var DEFAULT_CONTEXT_TIMEOUT_MS = 5e3;
|
|
12
17
|
var MAX_TIMER_MS = 2 ** 31 - 1;
|
|
13
|
-
|
|
18
|
+
var TOOLS_KEYS = keysOf()(
|
|
19
|
+
"userId",
|
|
20
|
+
"agentId",
|
|
21
|
+
"runId",
|
|
22
|
+
"client",
|
|
23
|
+
"tokenBudget",
|
|
24
|
+
"includeDate",
|
|
25
|
+
"timeZone",
|
|
26
|
+
"contextTimeoutMs",
|
|
27
|
+
"onError"
|
|
28
|
+
);
|
|
29
|
+
var MEMORY_KEYS = keysOf()(
|
|
30
|
+
"userId",
|
|
31
|
+
"agentId",
|
|
32
|
+
"runId",
|
|
33
|
+
"client",
|
|
34
|
+
"tokenBudget",
|
|
35
|
+
"includeDate",
|
|
36
|
+
"timeZone",
|
|
37
|
+
"contextTimeoutMs",
|
|
38
|
+
"onError",
|
|
39
|
+
"remember",
|
|
40
|
+
"waitUntil"
|
|
41
|
+
);
|
|
42
|
+
function checkOptions(method, opts, known) {
|
|
43
|
+
const problem = unknownOption(method, opts, known);
|
|
44
|
+
if (problem) throw new KorelyError(problem);
|
|
45
|
+
}
|
|
46
|
+
function scopeOf(options, caller, known) {
|
|
47
|
+
checkOptions(caller, options, known);
|
|
14
48
|
const o = options ?? {};
|
|
15
49
|
if (typeof o.userId !== "string" || !o.userId.trim()) {
|
|
16
50
|
throw new KorelyError(
|
|
@@ -142,7 +176,7 @@ function readWithin(read, limit) {
|
|
|
142
176
|
});
|
|
143
177
|
}
|
|
144
178
|
function korelyMemoryMiddleware(options) {
|
|
145
|
-
const scope = scopeOf(options, "korelyMemoryMiddleware");
|
|
179
|
+
const scope = scopeOf(options, "korelyMemoryMiddleware", MEMORY_KEYS);
|
|
146
180
|
const remember = options.remember ?? true;
|
|
147
181
|
const report = scope.report;
|
|
148
182
|
const waitUntil = options.waitUntil;
|
|
@@ -260,7 +294,7 @@ function oneText(value, key, max) {
|
|
|
260
294
|
return { success: true, value: { [key]: clip(raw.trim(), max) } };
|
|
261
295
|
}
|
|
262
296
|
function korelyTools(options) {
|
|
263
|
-
const scope = scopeOf(options, "korelyTools");
|
|
297
|
+
const scope = scopeOf(options, "korelyTools", TOOLS_KEYS);
|
|
264
298
|
const withDate = (text) => scope.today ? `${scope.today()}
|
|
265
299
|
|
|
266
300
|
${text}` : text;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/options.ts
|
|
9
|
+
function keysOf() {
|
|
10
|
+
return (...keys) => keys;
|
|
11
|
+
}
|
|
12
|
+
function unknownOption(method, opts, known) {
|
|
13
|
+
if (opts === void 0 || opts === null) return void 0;
|
|
14
|
+
if (typeof opts !== "object" || Array.isArray(opts)) {
|
|
15
|
+
return `${method}: the options must be an object, got ${Array.isArray(opts) ? "an array" : typeof opts}.`;
|
|
16
|
+
}
|
|
17
|
+
for (const key of Object.keys(opts)) {
|
|
18
|
+
if (known.includes(key)) continue;
|
|
19
|
+
const snake = key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
20
|
+
const camel = key.replace(/_([a-z])/g, (_m, c) => c.toUpperCase());
|
|
21
|
+
const meant = known.includes(snake) ? snake : known.includes(camel) ? camel : void 0;
|
|
22
|
+
return `${method}: unknown option ${key}.` + (meant ? ` Did you mean ${meant}?` : "") + ` It takes: ${known.join(", ")}.`;
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
__require,
|
|
29
|
+
keysOf,
|
|
30
|
+
unknownOption
|
|
31
|
+
};
|