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