korely-memory 0.1.8 → 0.1.10
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 +14 -3
- package/dist/index.cjs +302 -89
- package/dist/index.d.cts +242 -14
- package/dist/index.d.ts +242 -14
- package/dist/index.js +300 -89
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -265,6 +265,80 @@ interface AgentDeleteReceipt {
|
|
|
265
265
|
*/
|
|
266
266
|
slot_freed?: boolean;
|
|
267
267
|
}
|
|
268
|
+
/** What `ping()` answers: the key works. */
|
|
269
|
+
interface PingResponse {
|
|
270
|
+
/** Always true: a key that does not authenticate is an AuthenticationError instead. */
|
|
271
|
+
ok: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* The plan of the key: hobby, developer, team or scale. On the Self-hosted
|
|
274
|
+
* every key says "hobby", and it limits nothing there.
|
|
275
|
+
*/
|
|
276
|
+
tier: string;
|
|
277
|
+
/**
|
|
278
|
+
* Where the key's data is stored and processed, as the server declares it
|
|
279
|
+
* ("eu-hel1" on the Cloud; on the Self-hosted, what its operator set).
|
|
280
|
+
*/
|
|
281
|
+
region: string;
|
|
282
|
+
/** What the key may do, e.g. "memories:read". */
|
|
283
|
+
scopes: string[];
|
|
284
|
+
}
|
|
285
|
+
/** What `Korely.initAgent()` answers: a new hobby key and what it buys. */
|
|
286
|
+
interface AgentInitResult {
|
|
287
|
+
/** The key, shown this once and never again: save it. */
|
|
288
|
+
api_key: string;
|
|
289
|
+
tier: string;
|
|
290
|
+
region: string;
|
|
291
|
+
scopes: string[];
|
|
292
|
+
/** The hobby allowance: writes_per_month, queries_per_month, agents, the monthly AI budget. */
|
|
293
|
+
quotas: Record<string, unknown>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* What `deleteAccount()` removed. `deleted` is true: the account and every key
|
|
297
|
+
* of it are gone, the one this client holds included.
|
|
298
|
+
*/
|
|
299
|
+
interface AccountDeleteReceipt {
|
|
300
|
+
deleted: boolean;
|
|
301
|
+
/** Rows removed per kind (memories, facts, keys...), only the kinds that had any. */
|
|
302
|
+
removed: Record<string, number>;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Who acted, in an audit event. An open string, not a closed set: one client
|
|
306
|
+
* reads two products whose lists differ, and a server may add a value.
|
|
307
|
+
* "dashboard" is the Cloud's only, "manage" the Self-hosted's only.
|
|
308
|
+
*/
|
|
309
|
+
type AuditActor = "rest" | "mcp" | "dashboard" | "manage" | "worker" | string;
|
|
310
|
+
/**
|
|
311
|
+
* What happened, in an audit event. An open string for the same reason as
|
|
312
|
+
* AuditActor; "tenant_create" is the Self-hosted's only.
|
|
313
|
+
*/
|
|
314
|
+
type AuditAction = "read" | "write" | "fact_write" | "fact_invalidate" | "erase" | "key_create" | "key_revoke" | "tenant_create" | string;
|
|
315
|
+
/** For a read: what the call returned, by public id, at most 100 of each kind. Ids only, never content. */
|
|
316
|
+
interface AuditRead {
|
|
317
|
+
memories: string[];
|
|
318
|
+
facts: string[];
|
|
319
|
+
}
|
|
320
|
+
/** One event of the trail `audit()` reads (the API's `AuditRow`). */
|
|
321
|
+
interface AuditEvent {
|
|
322
|
+
/** When it happened, ISO 8601. */
|
|
323
|
+
ts: string;
|
|
324
|
+
actor: AuditActor;
|
|
325
|
+
action: AuditAction;
|
|
326
|
+
result: "ok" | "denied" | "error";
|
|
327
|
+
/** The end user the event touched. */
|
|
328
|
+
user_id?: string | null;
|
|
329
|
+
/** The memory or fact acted on, by public id. */
|
|
330
|
+
target_id?: string | null;
|
|
331
|
+
/** Counts and labels, never content. */
|
|
332
|
+
meta?: Record<string, unknown> | null;
|
|
333
|
+
ip?: string | null;
|
|
334
|
+
/** On a read, what it returned; with `as_of` on getFacts() it rebuilds what an agent knew when it decided. */
|
|
335
|
+
read?: AuditRead | null;
|
|
336
|
+
}
|
|
337
|
+
/** Iterable page of the audit trail, newest first. `total` counts the matches across every page. */
|
|
338
|
+
interface AuditPage extends Iterable<AuditEvent> {
|
|
339
|
+
events: AuditEvent[];
|
|
340
|
+
total: number;
|
|
341
|
+
}
|
|
268
342
|
interface AddOptions {
|
|
269
343
|
agent_id?: string;
|
|
270
344
|
user_id?: string;
|
|
@@ -317,6 +391,26 @@ interface EventsOptions {
|
|
|
317
391
|
/** Default 50, up to 200. */
|
|
318
392
|
limit?: number;
|
|
319
393
|
}
|
|
394
|
+
interface AuditOptions {
|
|
395
|
+
/**
|
|
396
|
+
* Only the events that touched this end user. An empty string is refused
|
|
397
|
+
* before sending: the server reads it as no filter.
|
|
398
|
+
*/
|
|
399
|
+
user_id?: string;
|
|
400
|
+
/** Only this kind of event. An unknown action answers an empty page; an empty string is refused. */
|
|
401
|
+
action?: AuditAction;
|
|
402
|
+
/** Events at or after it: ISO 8601 text, or a Date (sent as UTC). */
|
|
403
|
+
since?: string | Date;
|
|
404
|
+
/** Events at or before it: ISO 8601 text, or a Date (sent as UTC). */
|
|
405
|
+
until?: string | Date;
|
|
406
|
+
/** Default 100, 1 to 1000. */
|
|
407
|
+
limit?: number;
|
|
408
|
+
offset?: number;
|
|
409
|
+
}
|
|
410
|
+
interface IterAuditOptions extends Omit<AuditOptions, "limit"> {
|
|
411
|
+
/** Events per request. Default 1000, the most the API gives. */
|
|
412
|
+
page_size?: number;
|
|
413
|
+
}
|
|
320
414
|
interface GetFactsOptions {
|
|
321
415
|
subject?: string;
|
|
322
416
|
/** Matches the subject OR object side. */
|
|
@@ -370,7 +464,7 @@ interface ForgetReceipt {
|
|
|
370
464
|
|
|
371
465
|
/** Must equal `version` in package.json (a test checks). It goes out in the
|
|
372
466
|
* X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
|
|
373
|
-
declare const VERSION = "0.1.
|
|
467
|
+
declare const VERSION = "0.1.10";
|
|
374
468
|
interface KorelyOptions {
|
|
375
469
|
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
376
470
|
apiKey?: string;
|
|
@@ -383,14 +477,97 @@ interface KorelyOptions {
|
|
|
383
477
|
/** Inject a fetch implementation (mainly for testing / older runtimes). */
|
|
384
478
|
fetch?: typeof fetch;
|
|
385
479
|
}
|
|
480
|
+
/** Where and how `Korely.initAgent()` signs up: the client options a call
|
|
481
|
+
* without a key can use. */
|
|
482
|
+
type InitAgentOptions = Pick<KorelyOptions, "region" | "baseUrl" | "timeoutMs" | "fetch">;
|
|
386
483
|
declare class Korely {
|
|
387
484
|
readonly apiKey: string;
|
|
388
485
|
readonly baseUrl: string;
|
|
389
486
|
readonly timeoutMs: number;
|
|
390
487
|
private readonly fetchImpl;
|
|
391
488
|
constructor(opts?: KorelyOptions);
|
|
489
|
+
/**
|
|
490
|
+
* POST /v1/agents/init, with no key: sign up for a free hobby key.
|
|
491
|
+
*
|
|
492
|
+
* The one call that runs without a key, because it is how one is obtained,
|
|
493
|
+
* so it is static: `await Korely.initAgent("my-app")`, then
|
|
494
|
+
* `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
|
|
495
|
+
* label of who signed up, kept for your reference. The answer carries the
|
|
496
|
+
* key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
|
|
497
|
+
* The account it creates has no login: the key is the account, and
|
|
498
|
+
* `deleteAccount({ confirm: true })` closes it.
|
|
499
|
+
*
|
|
500
|
+
* Cloud only. The server is `baseUrl`, else KORELY_BASE_URL, else the
|
|
501
|
+
* region's. Refusals: 403 `signup_disabled` (NamespaceForbiddenError) when
|
|
502
|
+
* self-signup is closed; 429 `signup_rate_limited` (QuotaExceededError, with
|
|
503
|
+
* `retryAfter`) past the new accounts a network may open in a day. The
|
|
504
|
+
* Self-hosted has no such route and answers 404, or 405 where it serves its
|
|
505
|
+
* dashboard: its keys come from its own dashboard.
|
|
506
|
+
*/
|
|
507
|
+
static initAgent(agentCaller?: string, opts?: InitAgentOptions): Promise<AgentInitResult>;
|
|
392
508
|
private request;
|
|
393
|
-
|
|
509
|
+
/**
|
|
510
|
+
* GET /v1/ping: does this key work, and what may it do? Both products answer
|
|
511
|
+
* it, with the same shape.
|
|
512
|
+
*
|
|
513
|
+
* The cheapest authenticated call there is: no scope, no rate limit, no
|
|
514
|
+
* quota, so it is how to check a key that was just minted or rotated without
|
|
515
|
+
* spending anything. `users()` was the usual stand-in, and it needs
|
|
516
|
+
* `memories:read` and counts as a query.
|
|
517
|
+
*/
|
|
518
|
+
ping(): Promise<PingResponse>;
|
|
519
|
+
/**
|
|
520
|
+
* DELETE /v1/account?confirm=true: delete the account of this key for good,
|
|
521
|
+
* with every key, project, memory, fact and webhook of it; the key stops
|
|
522
|
+
* working. Cloud only, for an account made by `Korely.initAgent()` or
|
|
523
|
+
* `korely init --agent`, which nobody signs in to: the key is the account,
|
|
524
|
+
* and this is how it is closed (GDPR Art. 17).
|
|
525
|
+
*
|
|
526
|
+
* `{ confirm: true }` is required, and checked here, before anything is
|
|
527
|
+
* sent: without it, a KorelyError whose `code` is `confirmation_required`,
|
|
528
|
+
* the code the server gives the same refusal.
|
|
529
|
+
*
|
|
530
|
+
* An account with a Korely login rejects with 409 `account_has_login`
|
|
531
|
+
* (ConflictError): a key that ended up in a log must not be able to delete
|
|
532
|
+
* it, so it is closed from the app (Settings, Account). The Self-hosted has
|
|
533
|
+
* no such route and answers 404 (NotFoundError), or 405 where it serves its
|
|
534
|
+
* dashboard. No audit event survives: the trail is part of what goes.
|
|
535
|
+
*/
|
|
536
|
+
deleteAccount(opts?: {
|
|
537
|
+
confirm?: boolean;
|
|
538
|
+
}): Promise<AccountDeleteReceipt>;
|
|
539
|
+
/**
|
|
540
|
+
* GET /v1/audit: what this key's project did, and what its agents read,
|
|
541
|
+
* newest first (`ts` descending, then the event's id, so paging with
|
|
542
|
+
* `offset` is stable). Both products; the key needs `memories:read`.
|
|
543
|
+
*
|
|
544
|
+
* `user_id` keeps the events that touched one end user, the shape of an
|
|
545
|
+
* access or erasure request; `action` one kind ("read", "write", "erase"...;
|
|
546
|
+
* an unknown one answers an empty page); `since` and `until` bound `ts`,
|
|
547
|
+
* both inclusive, as ISO 8601 text or a Date. `limit` is 1 to 1000. To read
|
|
548
|
+
* everything, use `iterAudit()`. The page is iterable.
|
|
549
|
+
*
|
|
550
|
+
* Reading the trail counts against no quota and is not itself written to
|
|
551
|
+
* it; it does count against the rate limit. Scoped to the key's account and
|
|
552
|
+
* project, like every read.
|
|
553
|
+
*/
|
|
554
|
+
audit(opts?: AuditOptions): Promise<AuditPage>;
|
|
555
|
+
/**
|
|
556
|
+
* Every event `audit()` would page through, for an export:
|
|
557
|
+
* `for await (const e of korely.iterAudit({ user_id }))`. The same filters,
|
|
558
|
+
* `page_size` events per request (1000, the most the API gives),
|
|
559
|
+
* `offset += page.length` until `total`.
|
|
560
|
+
*
|
|
561
|
+
* Without `until` the walk pins it to the newest event of its first page.
|
|
562
|
+
* The trail grows while it is read, newest first, and every new event pushed
|
|
563
|
+
* the rest one place down: the next page began with events already returned.
|
|
564
|
+
* The pin makes the export the trail as it stood when it started.
|
|
565
|
+
*
|
|
566
|
+
* A rate limit rejects mid-way, as any call does, and the SDK does not
|
|
567
|
+
* retry. To resume, call again with the same `until` (pin it yourself:
|
|
568
|
+
* `until: new Date()`) and `offset` the number of events already read.
|
|
569
|
+
*/
|
|
570
|
+
iterAudit(opts?: IterAuditOptions): AsyncGenerator<AuditEvent, void, undefined>;
|
|
394
571
|
/**
|
|
395
572
|
* POST /v1/memories: store a memory; resolves to it with extracted facts.
|
|
396
573
|
* `content` is a string, or a list of chat messages (role/content), joined
|
|
@@ -562,6 +739,12 @@ declare class Korely {
|
|
|
562
739
|
* `code === "invalid_request"`) whose message names the item, e.g.
|
|
563
740
|
* `memories[3].timestamp`. Any key not listed above is refused the same
|
|
564
741
|
* way. Servers older than 2026-09-28 refuse `timestamp` itself.
|
|
742
|
+
*
|
|
743
|
+
* On the Cloud a batch is also refused, before anything is stored, with a
|
|
744
|
+
* 429: `quota_exceeded` (QuotaExceededError) when its memories do not fit in
|
|
745
|
+
* what is left of the month, batches already queued included, and
|
|
746
|
+
* `too_many_batches` (TooManyBatchesError) while three batches are still
|
|
747
|
+
* being imported. The Self-hosted meters nothing and refuses neither.
|
|
565
748
|
*/
|
|
566
749
|
batch(memories: Array<BatchMemory | Record<string, unknown>>): Promise<BatchJob>;
|
|
567
750
|
/** GET /v1/batch/:id: poll an import job. */
|
|
@@ -602,39 +785,84 @@ declare class KorelyError extends Error {
|
|
|
602
785
|
* public docs teach, `err instanceof APIError` and branch on `err.code`, let a
|
|
603
786
|
* 401, a 404 or a 429 through.
|
|
604
787
|
*/
|
|
788
|
+
interface APIErrorOptions extends KorelyErrorOptions {
|
|
789
|
+
retryAfter?: number;
|
|
790
|
+
}
|
|
605
791
|
declare class APIError extends KorelyError {
|
|
606
|
-
|
|
792
|
+
/**
|
|
793
|
+
* The server's Retry-After header in whole seconds, rounded up; undefined
|
|
794
|
+
* when it sent none. Two answers carry it: a rate limit (429
|
|
795
|
+
* `rate_limit_exceeded`) and the pause of the writes that need a model (503
|
|
796
|
+
* `writes_paused`, Cloud only), which lasts until 00:00 UTC.
|
|
797
|
+
*
|
|
798
|
+
* On every status since 2026-10-06. Only QuotaExceededError kept it, so the
|
|
799
|
+
* 503 `writes_paused` lost the one number that says when to come back.
|
|
800
|
+
*/
|
|
801
|
+
readonly retryAfter?: number;
|
|
802
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
607
803
|
}
|
|
608
804
|
/** 401: missing, malformed, or revoked API key. */
|
|
609
805
|
declare class AuthenticationError extends APIError {
|
|
610
|
-
constructor(message?: string, opts?:
|
|
806
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
611
807
|
}
|
|
612
808
|
/**
|
|
613
809
|
* 403: the key lacks a required scope, or the write would open an agent
|
|
614
810
|
* namespace past the plan's cap (`code === "agent_cap_exceeded"`).
|
|
615
811
|
*/
|
|
616
812
|
declare class NamespaceForbiddenError extends APIError {
|
|
617
|
-
constructor(message?: string, opts?:
|
|
813
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
618
814
|
}
|
|
619
815
|
/** 404: memory or fact id does not exist, or was forgotten. */
|
|
620
816
|
declare class NotFoundError extends APIError {
|
|
621
|
-
constructor(message?: string, opts?:
|
|
817
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
622
818
|
}
|
|
623
|
-
/**
|
|
624
|
-
|
|
625
|
-
|
|
819
|
+
/**
|
|
820
|
+
* 409: the request conflicts with what the server holds. `code` names the
|
|
821
|
+
* conflict: `stale_write` (update() with an expected_updated_at older than the
|
|
822
|
+
* record, thrown as the subclass StaleWriteError), `account_has_login`
|
|
823
|
+
* (`deleteAccount()` with the key of an account somebody signs in to, Cloud
|
|
824
|
+
* only) or `conflict` (the Self-hosted's code for a 409 that names no other).
|
|
825
|
+
*
|
|
826
|
+
* Until 2026-10-06 every 409 was a StaleWriteError, so a refusal that has
|
|
827
|
+
* nothing to do with an update read as a lost write, and code written to
|
|
828
|
+
* re-read the record and retry a stale write retried a refusal that never
|
|
829
|
+
* changes.
|
|
830
|
+
*/
|
|
831
|
+
declare class ConflictError extends APIError {
|
|
832
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* 409 `stale_write`: update() with an expected_updated_at older than the
|
|
836
|
+
* record. A ConflictError, so `instanceof ConflictError` is true for it too.
|
|
837
|
+
*/
|
|
838
|
+
declare class StaleWriteError extends ConflictError {
|
|
839
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
626
840
|
}
|
|
627
841
|
/**
|
|
628
842
|
* 429. `code === "rate_limit_exceeded"`: too many requests in a minute, hour
|
|
629
843
|
* or day, and `retryAfter` holds the seconds the server asked to wait.
|
|
630
844
|
* `code === "quota_exceeded"`: the monthly quota is used up, there is nothing
|
|
631
845
|
* to wait for this month, and `retryAfter` is undefined.
|
|
846
|
+
* `code === "too_many_batches"`: thrown as the subclass TooManyBatchesError.
|
|
847
|
+
* `retryAfter` comes from APIError, which every error the server answers with
|
|
848
|
+
* carries.
|
|
632
849
|
*/
|
|
633
850
|
declare class QuotaExceededError extends APIError {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
851
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* 429 `too_many_batches` (Cloud only): three `batch()` imports of the account
|
|
855
|
+
* are still running, and the Cloud takes no fourth until one of them
|
|
856
|
+
* finishes. Nothing was stored. Wait for a job to finish (`batchStatus()`) and
|
|
857
|
+
* send the batch again. There is no Retry-After, because the wait is a job and
|
|
858
|
+
* not a clock, so `retryAfter` is undefined.
|
|
859
|
+
*
|
|
860
|
+
* Its own class since 2026-10-06. It was a plain QuotaExceededError with no
|
|
861
|
+
* `retryAfter`, exactly what a monthly `quota_exceeded` looks like, and the
|
|
862
|
+
* docs tell you to stop on that one, while this one clears in minutes.
|
|
863
|
+
*/
|
|
864
|
+
declare class TooManyBatchesError extends QuotaExceededError {
|
|
865
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
638
866
|
}
|
|
639
867
|
|
|
640
|
-
export { APIError, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentScope, type AgentsPage, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, type Context, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
|
|
868
|
+
export { APIError, type AccountDeleteReceipt, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentInitResult, type AgentScope, type AgentsPage, type AuditAction, type AuditActor, type AuditEvent, type AuditOptions, type AuditPage, type AuditRead, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, ConflictError, type Context, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, type InitAgentOptions, type IterAuditOptions, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type PingResponse, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, TooManyBatchesError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
|
package/dist/index.d.ts
CHANGED
|
@@ -265,6 +265,80 @@ interface AgentDeleteReceipt {
|
|
|
265
265
|
*/
|
|
266
266
|
slot_freed?: boolean;
|
|
267
267
|
}
|
|
268
|
+
/** What `ping()` answers: the key works. */
|
|
269
|
+
interface PingResponse {
|
|
270
|
+
/** Always true: a key that does not authenticate is an AuthenticationError instead. */
|
|
271
|
+
ok: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* The plan of the key: hobby, developer, team or scale. On the Self-hosted
|
|
274
|
+
* every key says "hobby", and it limits nothing there.
|
|
275
|
+
*/
|
|
276
|
+
tier: string;
|
|
277
|
+
/**
|
|
278
|
+
* Where the key's data is stored and processed, as the server declares it
|
|
279
|
+
* ("eu-hel1" on the Cloud; on the Self-hosted, what its operator set).
|
|
280
|
+
*/
|
|
281
|
+
region: string;
|
|
282
|
+
/** What the key may do, e.g. "memories:read". */
|
|
283
|
+
scopes: string[];
|
|
284
|
+
}
|
|
285
|
+
/** What `Korely.initAgent()` answers: a new hobby key and what it buys. */
|
|
286
|
+
interface AgentInitResult {
|
|
287
|
+
/** The key, shown this once and never again: save it. */
|
|
288
|
+
api_key: string;
|
|
289
|
+
tier: string;
|
|
290
|
+
region: string;
|
|
291
|
+
scopes: string[];
|
|
292
|
+
/** The hobby allowance: writes_per_month, queries_per_month, agents, the monthly AI budget. */
|
|
293
|
+
quotas: Record<string, unknown>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* What `deleteAccount()` removed. `deleted` is true: the account and every key
|
|
297
|
+
* of it are gone, the one this client holds included.
|
|
298
|
+
*/
|
|
299
|
+
interface AccountDeleteReceipt {
|
|
300
|
+
deleted: boolean;
|
|
301
|
+
/** Rows removed per kind (memories, facts, keys...), only the kinds that had any. */
|
|
302
|
+
removed: Record<string, number>;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Who acted, in an audit event. An open string, not a closed set: one client
|
|
306
|
+
* reads two products whose lists differ, and a server may add a value.
|
|
307
|
+
* "dashboard" is the Cloud's only, "manage" the Self-hosted's only.
|
|
308
|
+
*/
|
|
309
|
+
type AuditActor = "rest" | "mcp" | "dashboard" | "manage" | "worker" | string;
|
|
310
|
+
/**
|
|
311
|
+
* What happened, in an audit event. An open string for the same reason as
|
|
312
|
+
* AuditActor; "tenant_create" is the Self-hosted's only.
|
|
313
|
+
*/
|
|
314
|
+
type AuditAction = "read" | "write" | "fact_write" | "fact_invalidate" | "erase" | "key_create" | "key_revoke" | "tenant_create" | string;
|
|
315
|
+
/** For a read: what the call returned, by public id, at most 100 of each kind. Ids only, never content. */
|
|
316
|
+
interface AuditRead {
|
|
317
|
+
memories: string[];
|
|
318
|
+
facts: string[];
|
|
319
|
+
}
|
|
320
|
+
/** One event of the trail `audit()` reads (the API's `AuditRow`). */
|
|
321
|
+
interface AuditEvent {
|
|
322
|
+
/** When it happened, ISO 8601. */
|
|
323
|
+
ts: string;
|
|
324
|
+
actor: AuditActor;
|
|
325
|
+
action: AuditAction;
|
|
326
|
+
result: "ok" | "denied" | "error";
|
|
327
|
+
/** The end user the event touched. */
|
|
328
|
+
user_id?: string | null;
|
|
329
|
+
/** The memory or fact acted on, by public id. */
|
|
330
|
+
target_id?: string | null;
|
|
331
|
+
/** Counts and labels, never content. */
|
|
332
|
+
meta?: Record<string, unknown> | null;
|
|
333
|
+
ip?: string | null;
|
|
334
|
+
/** On a read, what it returned; with `as_of` on getFacts() it rebuilds what an agent knew when it decided. */
|
|
335
|
+
read?: AuditRead | null;
|
|
336
|
+
}
|
|
337
|
+
/** Iterable page of the audit trail, newest first. `total` counts the matches across every page. */
|
|
338
|
+
interface AuditPage extends Iterable<AuditEvent> {
|
|
339
|
+
events: AuditEvent[];
|
|
340
|
+
total: number;
|
|
341
|
+
}
|
|
268
342
|
interface AddOptions {
|
|
269
343
|
agent_id?: string;
|
|
270
344
|
user_id?: string;
|
|
@@ -317,6 +391,26 @@ interface EventsOptions {
|
|
|
317
391
|
/** Default 50, up to 200. */
|
|
318
392
|
limit?: number;
|
|
319
393
|
}
|
|
394
|
+
interface AuditOptions {
|
|
395
|
+
/**
|
|
396
|
+
* Only the events that touched this end user. An empty string is refused
|
|
397
|
+
* before sending: the server reads it as no filter.
|
|
398
|
+
*/
|
|
399
|
+
user_id?: string;
|
|
400
|
+
/** Only this kind of event. An unknown action answers an empty page; an empty string is refused. */
|
|
401
|
+
action?: AuditAction;
|
|
402
|
+
/** Events at or after it: ISO 8601 text, or a Date (sent as UTC). */
|
|
403
|
+
since?: string | Date;
|
|
404
|
+
/** Events at or before it: ISO 8601 text, or a Date (sent as UTC). */
|
|
405
|
+
until?: string | Date;
|
|
406
|
+
/** Default 100, 1 to 1000. */
|
|
407
|
+
limit?: number;
|
|
408
|
+
offset?: number;
|
|
409
|
+
}
|
|
410
|
+
interface IterAuditOptions extends Omit<AuditOptions, "limit"> {
|
|
411
|
+
/** Events per request. Default 1000, the most the API gives. */
|
|
412
|
+
page_size?: number;
|
|
413
|
+
}
|
|
320
414
|
interface GetFactsOptions {
|
|
321
415
|
subject?: string;
|
|
322
416
|
/** Matches the subject OR object side. */
|
|
@@ -370,7 +464,7 @@ interface ForgetReceipt {
|
|
|
370
464
|
|
|
371
465
|
/** Must equal `version` in package.json (a test checks). It goes out in the
|
|
372
466
|
* X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
|
|
373
|
-
declare const VERSION = "0.1.
|
|
467
|
+
declare const VERSION = "0.1.10";
|
|
374
468
|
interface KorelyOptions {
|
|
375
469
|
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
376
470
|
apiKey?: string;
|
|
@@ -383,14 +477,97 @@ interface KorelyOptions {
|
|
|
383
477
|
/** Inject a fetch implementation (mainly for testing / older runtimes). */
|
|
384
478
|
fetch?: typeof fetch;
|
|
385
479
|
}
|
|
480
|
+
/** Where and how `Korely.initAgent()` signs up: the client options a call
|
|
481
|
+
* without a key can use. */
|
|
482
|
+
type InitAgentOptions = Pick<KorelyOptions, "region" | "baseUrl" | "timeoutMs" | "fetch">;
|
|
386
483
|
declare class Korely {
|
|
387
484
|
readonly apiKey: string;
|
|
388
485
|
readonly baseUrl: string;
|
|
389
486
|
readonly timeoutMs: number;
|
|
390
487
|
private readonly fetchImpl;
|
|
391
488
|
constructor(opts?: KorelyOptions);
|
|
489
|
+
/**
|
|
490
|
+
* POST /v1/agents/init, with no key: sign up for a free hobby key.
|
|
491
|
+
*
|
|
492
|
+
* The one call that runs without a key, because it is how one is obtained,
|
|
493
|
+
* so it is static: `await Korely.initAgent("my-app")`, then
|
|
494
|
+
* `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
|
|
495
|
+
* label of who signed up, kept for your reference. The answer carries the
|
|
496
|
+
* key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
|
|
497
|
+
* The account it creates has no login: the key is the account, and
|
|
498
|
+
* `deleteAccount({ confirm: true })` closes it.
|
|
499
|
+
*
|
|
500
|
+
* Cloud only. The server is `baseUrl`, else KORELY_BASE_URL, else the
|
|
501
|
+
* region's. Refusals: 403 `signup_disabled` (NamespaceForbiddenError) when
|
|
502
|
+
* self-signup is closed; 429 `signup_rate_limited` (QuotaExceededError, with
|
|
503
|
+
* `retryAfter`) past the new accounts a network may open in a day. The
|
|
504
|
+
* Self-hosted has no such route and answers 404, or 405 where it serves its
|
|
505
|
+
* dashboard: its keys come from its own dashboard.
|
|
506
|
+
*/
|
|
507
|
+
static initAgent(agentCaller?: string, opts?: InitAgentOptions): Promise<AgentInitResult>;
|
|
392
508
|
private request;
|
|
393
|
-
|
|
509
|
+
/**
|
|
510
|
+
* GET /v1/ping: does this key work, and what may it do? Both products answer
|
|
511
|
+
* it, with the same shape.
|
|
512
|
+
*
|
|
513
|
+
* The cheapest authenticated call there is: no scope, no rate limit, no
|
|
514
|
+
* quota, so it is how to check a key that was just minted or rotated without
|
|
515
|
+
* spending anything. `users()` was the usual stand-in, and it needs
|
|
516
|
+
* `memories:read` and counts as a query.
|
|
517
|
+
*/
|
|
518
|
+
ping(): Promise<PingResponse>;
|
|
519
|
+
/**
|
|
520
|
+
* DELETE /v1/account?confirm=true: delete the account of this key for good,
|
|
521
|
+
* with every key, project, memory, fact and webhook of it; the key stops
|
|
522
|
+
* working. Cloud only, for an account made by `Korely.initAgent()` or
|
|
523
|
+
* `korely init --agent`, which nobody signs in to: the key is the account,
|
|
524
|
+
* and this is how it is closed (GDPR Art. 17).
|
|
525
|
+
*
|
|
526
|
+
* `{ confirm: true }` is required, and checked here, before anything is
|
|
527
|
+
* sent: without it, a KorelyError whose `code` is `confirmation_required`,
|
|
528
|
+
* the code the server gives the same refusal.
|
|
529
|
+
*
|
|
530
|
+
* An account with a Korely login rejects with 409 `account_has_login`
|
|
531
|
+
* (ConflictError): a key that ended up in a log must not be able to delete
|
|
532
|
+
* it, so it is closed from the app (Settings, Account). The Self-hosted has
|
|
533
|
+
* no such route and answers 404 (NotFoundError), or 405 where it serves its
|
|
534
|
+
* dashboard. No audit event survives: the trail is part of what goes.
|
|
535
|
+
*/
|
|
536
|
+
deleteAccount(opts?: {
|
|
537
|
+
confirm?: boolean;
|
|
538
|
+
}): Promise<AccountDeleteReceipt>;
|
|
539
|
+
/**
|
|
540
|
+
* GET /v1/audit: what this key's project did, and what its agents read,
|
|
541
|
+
* newest first (`ts` descending, then the event's id, so paging with
|
|
542
|
+
* `offset` is stable). Both products; the key needs `memories:read`.
|
|
543
|
+
*
|
|
544
|
+
* `user_id` keeps the events that touched one end user, the shape of an
|
|
545
|
+
* access or erasure request; `action` one kind ("read", "write", "erase"...;
|
|
546
|
+
* an unknown one answers an empty page); `since` and `until` bound `ts`,
|
|
547
|
+
* both inclusive, as ISO 8601 text or a Date. `limit` is 1 to 1000. To read
|
|
548
|
+
* everything, use `iterAudit()`. The page is iterable.
|
|
549
|
+
*
|
|
550
|
+
* Reading the trail counts against no quota and is not itself written to
|
|
551
|
+
* it; it does count against the rate limit. Scoped to the key's account and
|
|
552
|
+
* project, like every read.
|
|
553
|
+
*/
|
|
554
|
+
audit(opts?: AuditOptions): Promise<AuditPage>;
|
|
555
|
+
/**
|
|
556
|
+
* Every event `audit()` would page through, for an export:
|
|
557
|
+
* `for await (const e of korely.iterAudit({ user_id }))`. The same filters,
|
|
558
|
+
* `page_size` events per request (1000, the most the API gives),
|
|
559
|
+
* `offset += page.length` until `total`.
|
|
560
|
+
*
|
|
561
|
+
* Without `until` the walk pins it to the newest event of its first page.
|
|
562
|
+
* The trail grows while it is read, newest first, and every new event pushed
|
|
563
|
+
* the rest one place down: the next page began with events already returned.
|
|
564
|
+
* The pin makes the export the trail as it stood when it started.
|
|
565
|
+
*
|
|
566
|
+
* A rate limit rejects mid-way, as any call does, and the SDK does not
|
|
567
|
+
* retry. To resume, call again with the same `until` (pin it yourself:
|
|
568
|
+
* `until: new Date()`) and `offset` the number of events already read.
|
|
569
|
+
*/
|
|
570
|
+
iterAudit(opts?: IterAuditOptions): AsyncGenerator<AuditEvent, void, undefined>;
|
|
394
571
|
/**
|
|
395
572
|
* POST /v1/memories: store a memory; resolves to it with extracted facts.
|
|
396
573
|
* `content` is a string, or a list of chat messages (role/content), joined
|
|
@@ -562,6 +739,12 @@ declare class Korely {
|
|
|
562
739
|
* `code === "invalid_request"`) whose message names the item, e.g.
|
|
563
740
|
* `memories[3].timestamp`. Any key not listed above is refused the same
|
|
564
741
|
* way. Servers older than 2026-09-28 refuse `timestamp` itself.
|
|
742
|
+
*
|
|
743
|
+
* On the Cloud a batch is also refused, before anything is stored, with a
|
|
744
|
+
* 429: `quota_exceeded` (QuotaExceededError) when its memories do not fit in
|
|
745
|
+
* what is left of the month, batches already queued included, and
|
|
746
|
+
* `too_many_batches` (TooManyBatchesError) while three batches are still
|
|
747
|
+
* being imported. The Self-hosted meters nothing and refuses neither.
|
|
565
748
|
*/
|
|
566
749
|
batch(memories: Array<BatchMemory | Record<string, unknown>>): Promise<BatchJob>;
|
|
567
750
|
/** GET /v1/batch/:id: poll an import job. */
|
|
@@ -602,39 +785,84 @@ declare class KorelyError extends Error {
|
|
|
602
785
|
* public docs teach, `err instanceof APIError` and branch on `err.code`, let a
|
|
603
786
|
* 401, a 404 or a 429 through.
|
|
604
787
|
*/
|
|
788
|
+
interface APIErrorOptions extends KorelyErrorOptions {
|
|
789
|
+
retryAfter?: number;
|
|
790
|
+
}
|
|
605
791
|
declare class APIError extends KorelyError {
|
|
606
|
-
|
|
792
|
+
/**
|
|
793
|
+
* The server's Retry-After header in whole seconds, rounded up; undefined
|
|
794
|
+
* when it sent none. Two answers carry it: a rate limit (429
|
|
795
|
+
* `rate_limit_exceeded`) and the pause of the writes that need a model (503
|
|
796
|
+
* `writes_paused`, Cloud only), which lasts until 00:00 UTC.
|
|
797
|
+
*
|
|
798
|
+
* On every status since 2026-10-06. Only QuotaExceededError kept it, so the
|
|
799
|
+
* 503 `writes_paused` lost the one number that says when to come back.
|
|
800
|
+
*/
|
|
801
|
+
readonly retryAfter?: number;
|
|
802
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
607
803
|
}
|
|
608
804
|
/** 401: missing, malformed, or revoked API key. */
|
|
609
805
|
declare class AuthenticationError extends APIError {
|
|
610
|
-
constructor(message?: string, opts?:
|
|
806
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
611
807
|
}
|
|
612
808
|
/**
|
|
613
809
|
* 403: the key lacks a required scope, or the write would open an agent
|
|
614
810
|
* namespace past the plan's cap (`code === "agent_cap_exceeded"`).
|
|
615
811
|
*/
|
|
616
812
|
declare class NamespaceForbiddenError extends APIError {
|
|
617
|
-
constructor(message?: string, opts?:
|
|
813
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
618
814
|
}
|
|
619
815
|
/** 404: memory or fact id does not exist, or was forgotten. */
|
|
620
816
|
declare class NotFoundError extends APIError {
|
|
621
|
-
constructor(message?: string, opts?:
|
|
817
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
622
818
|
}
|
|
623
|
-
/**
|
|
624
|
-
|
|
625
|
-
|
|
819
|
+
/**
|
|
820
|
+
* 409: the request conflicts with what the server holds. `code` names the
|
|
821
|
+
* conflict: `stale_write` (update() with an expected_updated_at older than the
|
|
822
|
+
* record, thrown as the subclass StaleWriteError), `account_has_login`
|
|
823
|
+
* (`deleteAccount()` with the key of an account somebody signs in to, Cloud
|
|
824
|
+
* only) or `conflict` (the Self-hosted's code for a 409 that names no other).
|
|
825
|
+
*
|
|
826
|
+
* Until 2026-10-06 every 409 was a StaleWriteError, so a refusal that has
|
|
827
|
+
* nothing to do with an update read as a lost write, and code written to
|
|
828
|
+
* re-read the record and retry a stale write retried a refusal that never
|
|
829
|
+
* changes.
|
|
830
|
+
*/
|
|
831
|
+
declare class ConflictError extends APIError {
|
|
832
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* 409 `stale_write`: update() with an expected_updated_at older than the
|
|
836
|
+
* record. A ConflictError, so `instanceof ConflictError` is true for it too.
|
|
837
|
+
*/
|
|
838
|
+
declare class StaleWriteError extends ConflictError {
|
|
839
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
626
840
|
}
|
|
627
841
|
/**
|
|
628
842
|
* 429. `code === "rate_limit_exceeded"`: too many requests in a minute, hour
|
|
629
843
|
* or day, and `retryAfter` holds the seconds the server asked to wait.
|
|
630
844
|
* `code === "quota_exceeded"`: the monthly quota is used up, there is nothing
|
|
631
845
|
* to wait for this month, and `retryAfter` is undefined.
|
|
846
|
+
* `code === "too_many_batches"`: thrown as the subclass TooManyBatchesError.
|
|
847
|
+
* `retryAfter` comes from APIError, which every error the server answers with
|
|
848
|
+
* carries.
|
|
632
849
|
*/
|
|
633
850
|
declare class QuotaExceededError extends APIError {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
851
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* 429 `too_many_batches` (Cloud only): three `batch()` imports of the account
|
|
855
|
+
* are still running, and the Cloud takes no fourth until one of them
|
|
856
|
+
* finishes. Nothing was stored. Wait for a job to finish (`batchStatus()`) and
|
|
857
|
+
* send the batch again. There is no Retry-After, because the wait is a job and
|
|
858
|
+
* not a clock, so `retryAfter` is undefined.
|
|
859
|
+
*
|
|
860
|
+
* Its own class since 2026-10-06. It was a plain QuotaExceededError with no
|
|
861
|
+
* `retryAfter`, exactly what a monthly `quota_exceeded` looks like, and the
|
|
862
|
+
* docs tell you to stop on that one, while this one clears in minutes.
|
|
863
|
+
*/
|
|
864
|
+
declare class TooManyBatchesError extends QuotaExceededError {
|
|
865
|
+
constructor(message?: string, opts?: APIErrorOptions);
|
|
638
866
|
}
|
|
639
867
|
|
|
640
|
-
export { APIError, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentScope, type AgentsPage, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, type Context, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
|
|
868
|
+
export { APIError, type AccountDeleteReceipt, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentInitResult, type AgentScope, type AgentsPage, type AuditAction, type AuditActor, type AuditEvent, type AuditOptions, type AuditPage, type AuditRead, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, ConflictError, type Context, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, type InitAgentOptions, type IterAuditOptions, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type PingResponse, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, TooManyBatchesError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
|