@anuma/sdk 3.0.0 → 3.1.1

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.
@@ -2741,6 +2741,33 @@ interface CachedServerTools {
2741
2741
  /** Checksum from the server for cache invalidation */
2742
2742
  checksum?: string;
2743
2743
  }
2744
+ /**
2745
+ * Pluggable persistence for the fetched server-tools list.
2746
+ *
2747
+ * The default backend ({@link localStorageToolsCache}) writes to browser
2748
+ * `localStorage` and is a silent no-op where `localStorage` is undefined
2749
+ * (Node, React Native). Pass a custom backend to `getServerTools` to cache
2750
+ * somewhere that survives on those platforms — e.g. an AsyncStorage/MMKV
2751
+ * adapter on RN, or an in-memory `Map` on a server. Methods may be sync or
2752
+ * async; `getServerTools` awaits them either way.
2753
+ *
2754
+ * The stored payload carries a `version`; `getServerTools` discards any entry
2755
+ * whose version does not match the current cache format, so a stale custom
2756
+ * backend can never feed an incompatible shape back into selection.
2757
+ */
2758
+ interface ToolsCacheBackend {
2759
+ /** Return the cached payload, or null when absent/unreadable. */
2760
+ get(): CachedServerTools | null | Promise<CachedServerTools | null>;
2761
+ /** Persist the payload. Implementations should swallow write failures. */
2762
+ set(value: CachedServerTools): void | Promise<void>;
2763
+ /**
2764
+ * Remove the cached payload. Optional — a read/write-only backend may omit it,
2765
+ * in which case `clearServerToolsCache` (and the version-mismatch
2766
+ * invalidation) is a no-op for that backend. The default
2767
+ * {@link localStorageToolsCache} implements it.
2768
+ */
2769
+ clear?(): void | Promise<void>;
2770
+ }
2744
2771
  /**
2745
2772
  * Options for fetching server tools
2746
2773
  */
@@ -2755,6 +2782,12 @@ interface ServerToolsOptions {
2755
2782
  getToken?: () => Promise<string | null>;
2756
2783
  /** Direct API key for server-side usage (uses X-API-Key header) */
2757
2784
  apiKey?: string;
2785
+ /**
2786
+ * Where to read/write the cached tools list. Defaults to
2787
+ * {@link localStorageToolsCache} (browser `localStorage`; no-op elsewhere).
2788
+ * Provide a backend to enable caching on Node / React Native.
2789
+ */
2790
+ cache?: ToolsCacheBackend;
2758
2791
  }
2759
2792
  /** Default cache expiration: 1 day */
2760
2793
  declare const DEFAULT_CACHE_EXPIRATION_MS: number;
@@ -2770,14 +2803,21 @@ interface ParsedServerToolsResponse {
2770
2803
  */
2771
2804
  declare function getCachedServerTools(): CachedServerTools | null;
2772
2805
  /**
2773
- * Clear the server tools cache
2806
+ * Clear the cached server tools. Defaults to the browser-`localStorage` backend;
2807
+ * pass the SAME {@link ToolsCacheBackend} you gave `getServerTools` to invalidate
2808
+ * a custom backend (a no-op when that backend defines no `clear`). Returns the
2809
+ * backend's clear result, which may be async.
2774
2810
  */
2775
2811
  declare function clearServerToolsCache(): void;
2812
+ declare function clearServerToolsCache(cache: ToolsCacheBackend): void | Promise<void>;
2776
2813
  /**
2777
- * Get the checksum of currently cached tools.
2778
- * Returns undefined if no cache or no checksum stored.
2814
+ * Get the checksum of the currently cached tools, or undefined when there is no
2815
+ * cache / no stored checksum. Defaults to the browser-`localStorage` backend;
2816
+ * pass the SAME backend you gave `getServerTools` to read a custom backend's
2817
+ * checksum (an async backend yields a promise).
2779
2818
  */
2780
2819
  declare function getToolsChecksum(): string | undefined;
2820
+ declare function getToolsChecksum(cache: ToolsCacheBackend): string | undefined | Promise<string | undefined>;
2781
2821
  /**
2782
2822
  * Check if tools should be refreshed based on checksum comparison.
2783
2823
  * Returns true if:
@@ -2789,11 +2829,12 @@ declare function getToolsChecksum(): string | undefined;
2789
2829
  * - Checksums match
2790
2830
  */
2791
2831
  declare function shouldRefreshTools(responseChecksum: string | undefined): boolean;
2832
+ declare function shouldRefreshTools(responseChecksum: string | undefined, cache: ToolsCacheBackend | undefined): boolean | Promise<boolean>;
2792
2833
  /**
2793
2834
  * Get server tools with caching support.
2794
2835
  *
2795
2836
  * Flow:
2796
- * 1. Check localStorage cache
2837
+ * 1. Check the cache backend (localStorage by default; override via `cache`)
2797
2838
  * 2. If cache valid and not force refresh, return cached tools
2798
2839
  * 3. Otherwise, fetch from API, cache, and return
2799
2840
  * 4. On fetch failure, return cached tools if available (stale-while-error)
@@ -3085,6 +3126,11 @@ interface SelectServerToolsForPromptOptions {
3085
3126
  embeddingModel?: string;
3086
3127
  /** Cache expiration in ms for the server-tools catalog fetch. */
3087
3128
  cacheExpirationMs?: number;
3129
+ /**
3130
+ * Where to read/write the cached catalog. Defaults to browser `localStorage`
3131
+ * (a no-op on Node/RN); pass a backend to persist on those platforms.
3132
+ */
3133
+ cache?: ToolsCacheBackend;
3088
3134
  /**
3089
3135
  * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
3090
3136
  * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
@@ -5366,11 +5412,26 @@ interface EmbeddingOptions {
5366
5412
  }
5367
5413
 
5368
5414
  /**
5369
- * Memory Retrieval Embeddings
5415
+ * Embedding generation — dependency-free core.
5416
+ *
5417
+ * The raw "text → embedding" calls, split out of `embeddings.ts` so they can be
5418
+ * imported by node/React-Native-safe modules (the server-tool + client-tool
5419
+ * selection engine in `../tools`) WITHOUT pulling in the WatermelonDB-backed
5420
+ * `db/chat/operations` that `embeddings.ts` needs for its message-persistence
5421
+ * helpers (`embedMessage`, `embedAllMessages`, `chunkAndEmbed*`).
5370
5422
  *
5371
- * Functions for generating and storing embeddings for conversation messages.
5423
+ * Nothing here touches the database; the only I/O is the HTTP embeddings
5424
+ * endpoint. `embeddings.ts` re-exports these so existing importers of
5425
+ * `../memoryEngine/embeddings` (and the `../memoryEngine` barrel) keep working.
5372
5426
  */
5373
5427
 
5428
+ /**
5429
+ * Generate an embedding for text using the API
5430
+ *
5431
+ * Supports two auth methods:
5432
+ * - `apiKey`: Uses X-API-Key header (for server-side/CLI usage)
5433
+ * - `getToken`: Uses Authorization: Bearer header (for Privy identity tokens)
5434
+ */
5374
5435
  declare function generateEmbedding(text: string, options: EmbeddingOptions): Promise<number[]>;
5375
5436
  /**
5376
5437
  * Generate embeddings for multiple texts, automatically chunking large inputs.
@@ -5385,6 +5446,18 @@ declare function generateEmbedding(text: string, options: EmbeddingOptions): Pro
5385
5446
  * @returns Array of embeddings in the same order as input texts
5386
5447
  */
5387
5448
  declare function generateEmbeddings(texts: string[], options: EmbeddingOptions): Promise<number[][]>;
5449
+
5450
+ /**
5451
+ * Memory Retrieval Embeddings
5452
+ *
5453
+ * Message-level embedding + persistence helpers: find messages via the
5454
+ * WatermelonDB-backed `db/chat/operations`, embed their content, and store the
5455
+ * vectors/chunks back. The raw "text → embedding" calls live in `./generate`
5456
+ * (dependency-free so the tool-selection engine can import them without the DB
5457
+ * layer) and are re-exported here so existing importers of
5458
+ * `../memoryEngine/embeddings` and the `../memoryEngine` barrel keep working.
5459
+ */
5460
+
5388
5461
  /**
5389
5462
  * Embed a single message and store the embedding in the database
5390
5463
  *
@@ -6583,14 +6656,14 @@ declare function createChunkVectorCache(maxSize?: number): ChunkVectorCache;
6583
6656
  declare function recall(query: string, ctx: RecallContext, options?: RecallOptions): Promise<RecallResult>;
6584
6657
 
6585
6658
  /**
6586
- * Unified Recall Tool
6659
+ * Recall tool constants — deliberately dependency-free.
6587
6660
  *
6588
- * Single chat-completion tool that searches both vault facts and
6589
- * conversation chunks via `recall()`. Replaces the legacy pair of
6590
- * `memory_vault_search` (facts) + `search_memory` (chunks) — the LLM no
6591
- * longer has to route between two tools.
6661
+ * Split out of `recallTool.ts` so the tool NAME can be referenced from
6662
+ * node/React-Native-safe modules (e.g. the client-tool selector in
6663
+ * `../tools/clientToolSelection`) without dragging `recall()` and its
6664
+ * WatermelonDB-backed operations into the module graph. `recallTool.ts`
6665
+ * re-exports these to preserve their public identity.
6592
6666
  */
6593
-
6594
6667
  /** Tool name surfaced to the LLM. Exported so bench harnesses and chat
6595
6668
  * clients reference the same string — drift between prod and bench would
6596
6669
  * mask tool-routing bugs in eval. */
@@ -6598,6 +6671,16 @@ declare const RECALL_TOOL_NAME = "recall_memory";
6598
6671
  /** Maximum results the executor will return to the LLM, regardless of
6599
6672
  * the LLM-supplied `limit`. */
6600
6673
  declare const RECALL_MAX_LIMIT = 50;
6674
+
6675
+ /**
6676
+ * Unified Recall Tool
6677
+ *
6678
+ * Single chat-completion tool that searches both vault facts and
6679
+ * conversation chunks via `recall()`. Replaces the legacy pair of
6680
+ * `memory_vault_search` (facts) + `search_memory` (chunks) — the LLM no
6681
+ * longer has to route between two tools.
6682
+ */
6683
+
6601
6684
  interface RecallToolOptions {
6602
6685
  /** Lanes to search. Default: ["fact", "chunk"]. */
6603
6686
  types?: MemoryKind[];
@@ -2741,6 +2741,33 @@ interface CachedServerTools {
2741
2741
  /** Checksum from the server for cache invalidation */
2742
2742
  checksum?: string;
2743
2743
  }
2744
+ /**
2745
+ * Pluggable persistence for the fetched server-tools list.
2746
+ *
2747
+ * The default backend ({@link localStorageToolsCache}) writes to browser
2748
+ * `localStorage` and is a silent no-op where `localStorage` is undefined
2749
+ * (Node, React Native). Pass a custom backend to `getServerTools` to cache
2750
+ * somewhere that survives on those platforms — e.g. an AsyncStorage/MMKV
2751
+ * adapter on RN, or an in-memory `Map` on a server. Methods may be sync or
2752
+ * async; `getServerTools` awaits them either way.
2753
+ *
2754
+ * The stored payload carries a `version`; `getServerTools` discards any entry
2755
+ * whose version does not match the current cache format, so a stale custom
2756
+ * backend can never feed an incompatible shape back into selection.
2757
+ */
2758
+ interface ToolsCacheBackend {
2759
+ /** Return the cached payload, or null when absent/unreadable. */
2760
+ get(): CachedServerTools | null | Promise<CachedServerTools | null>;
2761
+ /** Persist the payload. Implementations should swallow write failures. */
2762
+ set(value: CachedServerTools): void | Promise<void>;
2763
+ /**
2764
+ * Remove the cached payload. Optional — a read/write-only backend may omit it,
2765
+ * in which case `clearServerToolsCache` (and the version-mismatch
2766
+ * invalidation) is a no-op for that backend. The default
2767
+ * {@link localStorageToolsCache} implements it.
2768
+ */
2769
+ clear?(): void | Promise<void>;
2770
+ }
2744
2771
  /**
2745
2772
  * Options for fetching server tools
2746
2773
  */
@@ -2755,6 +2782,12 @@ interface ServerToolsOptions {
2755
2782
  getToken?: () => Promise<string | null>;
2756
2783
  /** Direct API key for server-side usage (uses X-API-Key header) */
2757
2784
  apiKey?: string;
2785
+ /**
2786
+ * Where to read/write the cached tools list. Defaults to
2787
+ * {@link localStorageToolsCache} (browser `localStorage`; no-op elsewhere).
2788
+ * Provide a backend to enable caching on Node / React Native.
2789
+ */
2790
+ cache?: ToolsCacheBackend;
2758
2791
  }
2759
2792
  /** Default cache expiration: 1 day */
2760
2793
  declare const DEFAULT_CACHE_EXPIRATION_MS: number;
@@ -2770,14 +2803,21 @@ interface ParsedServerToolsResponse {
2770
2803
  */
2771
2804
  declare function getCachedServerTools(): CachedServerTools | null;
2772
2805
  /**
2773
- * Clear the server tools cache
2806
+ * Clear the cached server tools. Defaults to the browser-`localStorage` backend;
2807
+ * pass the SAME {@link ToolsCacheBackend} you gave `getServerTools` to invalidate
2808
+ * a custom backend (a no-op when that backend defines no `clear`). Returns the
2809
+ * backend's clear result, which may be async.
2774
2810
  */
2775
2811
  declare function clearServerToolsCache(): void;
2812
+ declare function clearServerToolsCache(cache: ToolsCacheBackend): void | Promise<void>;
2776
2813
  /**
2777
- * Get the checksum of currently cached tools.
2778
- * Returns undefined if no cache or no checksum stored.
2814
+ * Get the checksum of the currently cached tools, or undefined when there is no
2815
+ * cache / no stored checksum. Defaults to the browser-`localStorage` backend;
2816
+ * pass the SAME backend you gave `getServerTools` to read a custom backend's
2817
+ * checksum (an async backend yields a promise).
2779
2818
  */
2780
2819
  declare function getToolsChecksum(): string | undefined;
2820
+ declare function getToolsChecksum(cache: ToolsCacheBackend): string | undefined | Promise<string | undefined>;
2781
2821
  /**
2782
2822
  * Check if tools should be refreshed based on checksum comparison.
2783
2823
  * Returns true if:
@@ -2789,11 +2829,12 @@ declare function getToolsChecksum(): string | undefined;
2789
2829
  * - Checksums match
2790
2830
  */
2791
2831
  declare function shouldRefreshTools(responseChecksum: string | undefined): boolean;
2832
+ declare function shouldRefreshTools(responseChecksum: string | undefined, cache: ToolsCacheBackend | undefined): boolean | Promise<boolean>;
2792
2833
  /**
2793
2834
  * Get server tools with caching support.
2794
2835
  *
2795
2836
  * Flow:
2796
- * 1. Check localStorage cache
2837
+ * 1. Check the cache backend (localStorage by default; override via `cache`)
2797
2838
  * 2. If cache valid and not force refresh, return cached tools
2798
2839
  * 3. Otherwise, fetch from API, cache, and return
2799
2840
  * 4. On fetch failure, return cached tools if available (stale-while-error)
@@ -3085,6 +3126,11 @@ interface SelectServerToolsForPromptOptions {
3085
3126
  embeddingModel?: string;
3086
3127
  /** Cache expiration in ms for the server-tools catalog fetch. */
3087
3128
  cacheExpirationMs?: number;
3129
+ /**
3130
+ * Where to read/write the cached catalog. Defaults to browser `localStorage`
3131
+ * (a no-op on Node/RN); pass a backend to persist on those platforms.
3132
+ */
3133
+ cache?: ToolsCacheBackend;
3088
3134
  /**
3089
3135
  * Phase 3 defer-loading. When `enabled`, this helper returns the FULL catalog (skipping semantic/
3090
3136
  * static filtering) to mirror useChatStorage's responses send path, which swaps in the full catalog
@@ -5366,11 +5412,26 @@ interface EmbeddingOptions {
5366
5412
  }
5367
5413
 
5368
5414
  /**
5369
- * Memory Retrieval Embeddings
5415
+ * Embedding generation — dependency-free core.
5416
+ *
5417
+ * The raw "text → embedding" calls, split out of `embeddings.ts` so they can be
5418
+ * imported by node/React-Native-safe modules (the server-tool + client-tool
5419
+ * selection engine in `../tools`) WITHOUT pulling in the WatermelonDB-backed
5420
+ * `db/chat/operations` that `embeddings.ts` needs for its message-persistence
5421
+ * helpers (`embedMessage`, `embedAllMessages`, `chunkAndEmbed*`).
5370
5422
  *
5371
- * Functions for generating and storing embeddings for conversation messages.
5423
+ * Nothing here touches the database; the only I/O is the HTTP embeddings
5424
+ * endpoint. `embeddings.ts` re-exports these so existing importers of
5425
+ * `../memoryEngine/embeddings` (and the `../memoryEngine` barrel) keep working.
5372
5426
  */
5373
5427
 
5428
+ /**
5429
+ * Generate an embedding for text using the API
5430
+ *
5431
+ * Supports two auth methods:
5432
+ * - `apiKey`: Uses X-API-Key header (for server-side/CLI usage)
5433
+ * - `getToken`: Uses Authorization: Bearer header (for Privy identity tokens)
5434
+ */
5374
5435
  declare function generateEmbedding(text: string, options: EmbeddingOptions): Promise<number[]>;
5375
5436
  /**
5376
5437
  * Generate embeddings for multiple texts, automatically chunking large inputs.
@@ -5385,6 +5446,18 @@ declare function generateEmbedding(text: string, options: EmbeddingOptions): Pro
5385
5446
  * @returns Array of embeddings in the same order as input texts
5386
5447
  */
5387
5448
  declare function generateEmbeddings(texts: string[], options: EmbeddingOptions): Promise<number[][]>;
5449
+
5450
+ /**
5451
+ * Memory Retrieval Embeddings
5452
+ *
5453
+ * Message-level embedding + persistence helpers: find messages via the
5454
+ * WatermelonDB-backed `db/chat/operations`, embed their content, and store the
5455
+ * vectors/chunks back. The raw "text → embedding" calls live in `./generate`
5456
+ * (dependency-free so the tool-selection engine can import them without the DB
5457
+ * layer) and are re-exported here so existing importers of
5458
+ * `../memoryEngine/embeddings` and the `../memoryEngine` barrel keep working.
5459
+ */
5460
+
5388
5461
  /**
5389
5462
  * Embed a single message and store the embedding in the database
5390
5463
  *
@@ -6583,14 +6656,14 @@ declare function createChunkVectorCache(maxSize?: number): ChunkVectorCache;
6583
6656
  declare function recall(query: string, ctx: RecallContext, options?: RecallOptions): Promise<RecallResult>;
6584
6657
 
6585
6658
  /**
6586
- * Unified Recall Tool
6659
+ * Recall tool constants — deliberately dependency-free.
6587
6660
  *
6588
- * Single chat-completion tool that searches both vault facts and
6589
- * conversation chunks via `recall()`. Replaces the legacy pair of
6590
- * `memory_vault_search` (facts) + `search_memory` (chunks) — the LLM no
6591
- * longer has to route between two tools.
6661
+ * Split out of `recallTool.ts` so the tool NAME can be referenced from
6662
+ * node/React-Native-safe modules (e.g. the client-tool selector in
6663
+ * `../tools/clientToolSelection`) without dragging `recall()` and its
6664
+ * WatermelonDB-backed operations into the module graph. `recallTool.ts`
6665
+ * re-exports these to preserve their public identity.
6592
6666
  */
6593
-
6594
6667
  /** Tool name surfaced to the LLM. Exported so bench harnesses and chat
6595
6668
  * clients reference the same string — drift between prod and bench would
6596
6669
  * mask tool-routing bugs in eval. */
@@ -6598,6 +6671,16 @@ declare const RECALL_TOOL_NAME = "recall_memory";
6598
6671
  /** Maximum results the executor will return to the LLM, regardless of
6599
6672
  * the LLM-supplied `limit`. */
6600
6673
  declare const RECALL_MAX_LIMIT = 50;
6674
+
6675
+ /**
6676
+ * Unified Recall Tool
6677
+ *
6678
+ * Single chat-completion tool that searches both vault facts and
6679
+ * conversation chunks via `recall()`. Replaces the legacy pair of
6680
+ * `memory_vault_search` (facts) + `search_memory` (chunks) — the LLM no
6681
+ * longer has to route between two tools.
6682
+ */
6683
+
6601
6684
  interface RecallToolOptions {
6602
6685
  /** Lanes to search. Default: ["fact", "chunk"]. */
6603
6686
  types?: MemoryKind[];