@anuma/sdk 3.0.0 → 3.1.0
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/expo/{chunk-IY7NNIYM.mjs → chunk-22CSPJLL.mjs} +16 -850
- package/dist/expo/index.cjs +1663 -1071
- package/dist/expo/index.d.mts +179 -10
- package/dist/expo/index.d.ts +179 -10
- package/dist/expo/index.mjs +1556 -68
- package/dist/expo/{recall-DJ5LD5WJ.mjs → recall-LICO3TJ7.mjs} +1 -1
- package/dist/index.cjs +415 -394
- package/dist/index.mjs +412 -391
- package/dist/react/{chunk-OSDVRDLI.mjs → chunk-FD5MB73N.mjs} +8 -987
- package/dist/react/index.cjs +1687 -1712
- package/dist/react/index.d.mts +103 -12
- package/dist/react/index.d.ts +103 -12
- package/dist/react/index.mjs +1209 -219
- package/dist/react/{recall-3BDCIEQF.mjs → recall-FPACUZGD.mjs} +1 -1
- package/dist/server/{chunk-QQOIC37O.mjs → chunk-RKUNGNBF.mjs} +7 -817
- package/dist/server/index.cjs +223 -941
- package/dist/server/index.d.mts +95 -12
- package/dist/server/index.d.ts +95 -12
- package/dist/server/index.mjs +182 -23
- package/dist/server/{recall-6QLUEYB7.mjs → recall-WT5HY2IA.mjs} +1 -1
- package/dist/tools/selection/chunk-4ETHWSXJ.mjs +25 -0
- package/dist/tools/selection/clientConfig-WITO4T6L.mjs +12 -0
- package/dist/tools/selection/index.cjs +1977 -0
- package/dist/tools/selection/index.d.mts +1380 -0
- package/dist/tools/selection/index.d.ts +1380 -0
- package/dist/tools/selection/index.mjs +1859 -0
- package/package.json +8 -1
package/dist/expo/index.d.mts
CHANGED
|
@@ -2786,6 +2786,13 @@ type SendMessageArgs = BaseSendMessageArgs & {
|
|
|
2786
2786
|
* This is typically extracted text from preprocessed file attachments.
|
|
2787
2787
|
*/
|
|
2788
2788
|
fileContext?: string;
|
|
2789
|
+
/**
|
|
2790
|
+
* Tool-set guidance to inject as a system message — the persona/usage prompt
|
|
2791
|
+
* for whichever tool sets activated this turn (e.g. the app-builder prompt).
|
|
2792
|
+
* Additive: composes with the other context messages, never replaces them.
|
|
2793
|
+
* Mirrors react's useChat toolGuidance channel.
|
|
2794
|
+
*/
|
|
2795
|
+
toolGuidance?: string;
|
|
2789
2796
|
/**
|
|
2790
2797
|
* Override the API type for this request only.
|
|
2791
2798
|
* Useful when different models need different APIs.
|
|
@@ -3130,6 +3137,33 @@ interface CachedServerTools {
|
|
|
3130
3137
|
/** Checksum from the server for cache invalidation */
|
|
3131
3138
|
checksum?: string;
|
|
3132
3139
|
}
|
|
3140
|
+
/**
|
|
3141
|
+
* Pluggable persistence for the fetched server-tools list.
|
|
3142
|
+
*
|
|
3143
|
+
* The default backend ({@link localStorageToolsCache}) writes to browser
|
|
3144
|
+
* `localStorage` and is a silent no-op where `localStorage` is undefined
|
|
3145
|
+
* (Node, React Native). Pass a custom backend to `getServerTools` to cache
|
|
3146
|
+
* somewhere that survives on those platforms — e.g. an AsyncStorage/MMKV
|
|
3147
|
+
* adapter on RN, or an in-memory `Map` on a server. Methods may be sync or
|
|
3148
|
+
* async; `getServerTools` awaits them either way.
|
|
3149
|
+
*
|
|
3150
|
+
* The stored payload carries a `version`; `getServerTools` discards any entry
|
|
3151
|
+
* whose version does not match the current cache format, so a stale custom
|
|
3152
|
+
* backend can never feed an incompatible shape back into selection.
|
|
3153
|
+
*/
|
|
3154
|
+
interface ToolsCacheBackend {
|
|
3155
|
+
/** Return the cached payload, or null when absent/unreadable. */
|
|
3156
|
+
get(): CachedServerTools | null | Promise<CachedServerTools | null>;
|
|
3157
|
+
/** Persist the payload. Implementations should swallow write failures. */
|
|
3158
|
+
set(value: CachedServerTools): void | Promise<void>;
|
|
3159
|
+
/**
|
|
3160
|
+
* Remove the cached payload. Optional — a read/write-only backend may omit it,
|
|
3161
|
+
* in which case `clearServerToolsCache` (and the version-mismatch
|
|
3162
|
+
* invalidation) is a no-op for that backend. The default
|
|
3163
|
+
* {@link localStorageToolsCache} implements it.
|
|
3164
|
+
*/
|
|
3165
|
+
clear?(): void | Promise<void>;
|
|
3166
|
+
}
|
|
3133
3167
|
/**
|
|
3134
3168
|
* Options for fetching server tools
|
|
3135
3169
|
*/
|
|
@@ -3144,6 +3178,12 @@ interface ServerToolsOptions {
|
|
|
3144
3178
|
getToken?: () => Promise<string | null>;
|
|
3145
3179
|
/** Direct API key for server-side usage (uses X-API-Key header) */
|
|
3146
3180
|
apiKey?: string;
|
|
3181
|
+
/**
|
|
3182
|
+
* Where to read/write the cached tools list. Defaults to
|
|
3183
|
+
* {@link localStorageToolsCache} (browser `localStorage`; no-op elsewhere).
|
|
3184
|
+
* Provide a backend to enable caching on Node / React Native.
|
|
3185
|
+
*/
|
|
3186
|
+
cache?: ToolsCacheBackend;
|
|
3147
3187
|
}
|
|
3148
3188
|
/** Default cache expiration: 1 day */
|
|
3149
3189
|
declare const DEFAULT_CACHE_EXPIRATION_MS: number;
|
|
@@ -3152,14 +3192,18 @@ declare const DEFAULT_CACHE_EXPIRATION_MS: number;
|
|
|
3152
3192
|
*/
|
|
3153
3193
|
declare function getCachedServerTools(): CachedServerTools | null;
|
|
3154
3194
|
/**
|
|
3155
|
-
* Clear the server tools
|
|
3195
|
+
* Clear the cached server tools. Defaults to the browser-`localStorage` backend;
|
|
3196
|
+
* pass the SAME {@link ToolsCacheBackend} you gave `getServerTools` to invalidate
|
|
3197
|
+
* a custom backend (a no-op when that backend defines no `clear`). Returns the
|
|
3198
|
+
* backend's clear result, which may be async.
|
|
3156
3199
|
*/
|
|
3157
3200
|
declare function clearServerToolsCache(): void;
|
|
3201
|
+
declare function clearServerToolsCache(cache: ToolsCacheBackend): void | Promise<void>;
|
|
3158
3202
|
/**
|
|
3159
3203
|
* Get server tools with caching support.
|
|
3160
3204
|
*
|
|
3161
3205
|
* Flow:
|
|
3162
|
-
* 1. Check localStorage cache
|
|
3206
|
+
* 1. Check the cache backend (localStorage by default; override via `cache`)
|
|
3163
3207
|
* 2. If cache valid and not force refresh, return cached tools
|
|
3164
3208
|
* 3. Otherwise, fetch from API, cache, and return
|
|
3165
3209
|
* 4. On fetch failure, return cached tools if available (stale-while-error)
|
|
@@ -3179,6 +3223,52 @@ interface DeferLoadingConfig {
|
|
|
3179
3223
|
/** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
|
|
3180
3224
|
hotToolNames: readonly string[];
|
|
3181
3225
|
}
|
|
3226
|
+
/**
|
|
3227
|
+
* A tool set defines a group of tools that work together. When any "anchor"
|
|
3228
|
+
* tool in the set is matched semantically (with a score at or above
|
|
3229
|
+
* `anchorMinSimilarity`), the set is activated and all of its members are
|
|
3230
|
+
* pulled into the selection.
|
|
3231
|
+
*
|
|
3232
|
+
* Two activation strategies consume this interface:
|
|
3233
|
+
* - `expandToolSetsAdditive` (used by `useChatStorage` and
|
|
3234
|
+
* `createServerToolsFilter`) keeps all original matches and adds the
|
|
3235
|
+
* set's members on top — non-set tools are never dropped.
|
|
3236
|
+
* - `applyToolSets` is exclusive: it keeps only set members plus non-set
|
|
3237
|
+
* tools that scored above `independentThreshold`.
|
|
3238
|
+
*
|
|
3239
|
+
* Pick `expandToolSetsAdditive` when you want recall over precision
|
|
3240
|
+
* (typical), and `applyToolSets` when you specifically want non-set
|
|
3241
|
+
* matches stripped on activation.
|
|
3242
|
+
*/
|
|
3243
|
+
interface ToolSet {
|
|
3244
|
+
/** Human-readable name for logging/debugging */
|
|
3245
|
+
name: string;
|
|
3246
|
+
/** All tool names in the set */
|
|
3247
|
+
members: string[];
|
|
3248
|
+
/**
|
|
3249
|
+
* Tools that trigger the set when selected. If any anchor appears in the
|
|
3250
|
+
* semantic match results with a score at or above `anchorMinSimilarity`,
|
|
3251
|
+
* all members are pulled in.
|
|
3252
|
+
*/
|
|
3253
|
+
anchors: string[];
|
|
3254
|
+
/**
|
|
3255
|
+
* Minimum similarity an anchor must reach to activate the set.
|
|
3256
|
+
* Prevents false activation on prompts where the anchor barely passes
|
|
3257
|
+
* the global minSimilarity threshold. Default: 0.60
|
|
3258
|
+
*/
|
|
3259
|
+
anchorMinSimilarity?: number;
|
|
3260
|
+
/**
|
|
3261
|
+
* System-prompt fragment to APPEND to the base prompt when this set
|
|
3262
|
+
* activates. Additive, never a replacement — it composes with the host's
|
|
3263
|
+
* persona / memory. Gated on genuine activation (anchor score ≥
|
|
3264
|
+
* `anchorMinSimilarity`, or a forced set) via {@link activatedToolSetNames} →
|
|
3265
|
+
* {@link toolSetSystemPrompts}, NOT on mere anchor presence — a borderline
|
|
3266
|
+
* anchor kept by recall-over-precision must not drag this persona in. Write
|
|
3267
|
+
* it to be self-limiting too (condition its behavior on the user actually
|
|
3268
|
+
* wanting what the set does), so a borderline activation doesn't bias the turn.
|
|
3269
|
+
*/
|
|
3270
|
+
systemPrompt?: string;
|
|
3271
|
+
}
|
|
3182
3272
|
|
|
3183
3273
|
/**
|
|
3184
3274
|
* Function type for dynamic server tools filtering based on prompt embeddings.
|
|
@@ -3541,6 +3631,13 @@ interface BaseUseChatStorageOptions {
|
|
|
3541
3631
|
* {@link DeferLoadingConfig}.
|
|
3542
3632
|
*/
|
|
3543
3633
|
deferLoading?: DeferLoadingConfig;
|
|
3634
|
+
/**
|
|
3635
|
+
* Where to read/write the cached server-tools catalog. Defaults to browser
|
|
3636
|
+
* `localStorage`, which is a silent no-op on React Native — so on RN pass an
|
|
3637
|
+
* AsyncStorage/MMKV-backed {@link ToolsCacheBackend} here or every send
|
|
3638
|
+
* refetches the whole catalog. Forwarded to `getServerTools`.
|
|
3639
|
+
*/
|
|
3640
|
+
cache?: ToolsCacheBackend;
|
|
3544
3641
|
};
|
|
3545
3642
|
/**
|
|
3546
3643
|
* Automatically generate embeddings for messages after saving.
|
|
@@ -5892,14 +5989,14 @@ declare function createChunkVectorCache(maxSize?: number): ChunkVectorCache;
|
|
|
5892
5989
|
declare function recall(query: string, ctx: RecallContext, options?: RecallOptions): Promise<RecallResult>;
|
|
5893
5990
|
|
|
5894
5991
|
/**
|
|
5895
|
-
*
|
|
5992
|
+
* Recall tool constants — deliberately dependency-free.
|
|
5896
5993
|
*
|
|
5897
|
-
*
|
|
5898
|
-
*
|
|
5899
|
-
* `
|
|
5900
|
-
*
|
|
5994
|
+
* Split out of `recallTool.ts` so the tool NAME can be referenced from
|
|
5995
|
+
* node/React-Native-safe modules (e.g. the client-tool selector in
|
|
5996
|
+
* `../tools/clientToolSelection`) without dragging `recall()` and its
|
|
5997
|
+
* WatermelonDB-backed operations into the module graph. `recallTool.ts`
|
|
5998
|
+
* re-exports these to preserve their public identity.
|
|
5901
5999
|
*/
|
|
5902
|
-
|
|
5903
6000
|
/** Tool name surfaced to the LLM. Exported so bench harnesses and chat
|
|
5904
6001
|
* clients reference the same string — drift between prod and bench would
|
|
5905
6002
|
* mask tool-routing bugs in eval. */
|
|
@@ -5907,6 +6004,16 @@ declare const RECALL_TOOL_NAME = "recall_memory";
|
|
|
5907
6004
|
/** Maximum results the executor will return to the LLM, regardless of
|
|
5908
6005
|
* the LLM-supplied `limit`. */
|
|
5909
6006
|
declare const RECALL_MAX_LIMIT = 50;
|
|
6007
|
+
|
|
6008
|
+
/**
|
|
6009
|
+
* Unified Recall Tool
|
|
6010
|
+
*
|
|
6011
|
+
* Single chat-completion tool that searches both vault facts and
|
|
6012
|
+
* conversation chunks via `recall()`. Replaces the legacy pair of
|
|
6013
|
+
* `memory_vault_search` (facts) + `search_memory` (chunks) — the LLM no
|
|
6014
|
+
* longer has to route between two tools.
|
|
6015
|
+
*/
|
|
6016
|
+
|
|
5910
6017
|
interface RecallToolOptions {
|
|
5911
6018
|
/** Lanes to search. Default: ["fact", "chunk"]. */
|
|
5912
6019
|
types?: MemoryKind[];
|
|
@@ -6210,11 +6317,26 @@ declare function chunkText(text: string, options?: ChunkingOptions): TextChunk[]
|
|
|
6210
6317
|
declare function shouldChunkMessage(content: string, chunkSize?: number): boolean;
|
|
6211
6318
|
|
|
6212
6319
|
/**
|
|
6213
|
-
*
|
|
6320
|
+
* Embedding generation — dependency-free core.
|
|
6214
6321
|
*
|
|
6215
|
-
*
|
|
6322
|
+
* The raw "text → embedding" calls, split out of `embeddings.ts` so they can be
|
|
6323
|
+
* imported by node/React-Native-safe modules (the server-tool + client-tool
|
|
6324
|
+
* selection engine in `../tools`) WITHOUT pulling in the WatermelonDB-backed
|
|
6325
|
+
* `db/chat/operations` that `embeddings.ts` needs for its message-persistence
|
|
6326
|
+
* helpers (`embedMessage`, `embedAllMessages`, `chunkAndEmbed*`).
|
|
6327
|
+
*
|
|
6328
|
+
* Nothing here touches the database; the only I/O is the HTTP embeddings
|
|
6329
|
+
* endpoint. `embeddings.ts` re-exports these so existing importers of
|
|
6330
|
+
* `../memoryEngine/embeddings` (and the `../memoryEngine` barrel) keep working.
|
|
6216
6331
|
*/
|
|
6217
6332
|
|
|
6333
|
+
/**
|
|
6334
|
+
* Generate an embedding for text using the API
|
|
6335
|
+
*
|
|
6336
|
+
* Supports two auth methods:
|
|
6337
|
+
* - `apiKey`: Uses X-API-Key header (for server-side/CLI usage)
|
|
6338
|
+
* - `getToken`: Uses Authorization: Bearer header (for Privy identity tokens)
|
|
6339
|
+
*/
|
|
6218
6340
|
declare function generateEmbedding(text: string, options: EmbeddingOptions): Promise<number[]>;
|
|
6219
6341
|
/**
|
|
6220
6342
|
* Generate embeddings for multiple texts, automatically chunking large inputs.
|
|
@@ -6229,6 +6351,18 @@ declare function generateEmbedding(text: string, options: EmbeddingOptions): Pro
|
|
|
6229
6351
|
* @returns Array of embeddings in the same order as input texts
|
|
6230
6352
|
*/
|
|
6231
6353
|
declare function generateEmbeddings(texts: string[], options: EmbeddingOptions): Promise<number[][]>;
|
|
6354
|
+
|
|
6355
|
+
/**
|
|
6356
|
+
* Memory Retrieval Embeddings
|
|
6357
|
+
*
|
|
6358
|
+
* Message-level embedding + persistence helpers: find messages via the
|
|
6359
|
+
* WatermelonDB-backed `db/chat/operations`, embed their content, and store the
|
|
6360
|
+
* vectors/chunks back. The raw "text → embedding" calls live in `./generate`
|
|
6361
|
+
* (dependency-free so the tool-selection engine can import them without the DB
|
|
6362
|
+
* layer) and are re-exported here so existing importers of
|
|
6363
|
+
* `../memoryEngine/embeddings` and the `../memoryEngine` barrel keep working.
|
|
6364
|
+
*/
|
|
6365
|
+
|
|
6232
6366
|
/**
|
|
6233
6367
|
* Embed a single message and store the embedding in the database
|
|
6234
6368
|
*
|
|
@@ -6523,6 +6657,31 @@ interface UseChatStorageOptions extends BaseUseChatStorageOptions {
|
|
|
6523
6657
|
* Auto-flush queued operations when key becomes available. @default true
|
|
6524
6658
|
*/
|
|
6525
6659
|
autoFlushOnKeyAvailable?: boolean;
|
|
6660
|
+
/**
|
|
6661
|
+
* Additional tool sets to apply on top of the built-in ones (app-generation,
|
|
6662
|
+
* slides, github). When any anchor tool in a custom set is selected by
|
|
6663
|
+
* semantic matching, all members of that set are included automatically.
|
|
6664
|
+
*
|
|
6665
|
+
* Treated as static config — set once at hook setup. Changing it across
|
|
6666
|
+
* renders does not affect in-flight `sendMessage` calls; use
|
|
6667
|
+
* `activeToolSets` for dynamic, conversation-state-driven overrides.
|
|
6668
|
+
*/
|
|
6669
|
+
extraToolSets?: ToolSet[];
|
|
6670
|
+
/**
|
|
6671
|
+
* Tool set names that should expand unconditionally for this request,
|
|
6672
|
+
* bypassing the anchor-similarity check. Use when conversation state
|
|
6673
|
+
* implies a set should be present regardless of how the prompt is phrased
|
|
6674
|
+
* — e.g., pass `["documents"]` when the conversation already contains a
|
|
6675
|
+
* generated document, so short follow-up prompts ("make the background red")
|
|
6676
|
+
* still get the full document toolkit.
|
|
6677
|
+
*
|
|
6678
|
+
* Read via a ref so updates are visible to in-flight `sendMessage` calls
|
|
6679
|
+
* without rebuilding the callback.
|
|
6680
|
+
*
|
|
6681
|
+
* Names must match a set's `name` from `BUILT_IN_TOOL_SETS` or
|
|
6682
|
+
* `extraToolSets`. Unknown names are ignored.
|
|
6683
|
+
*/
|
|
6684
|
+
activeToolSets?: string[];
|
|
6526
6685
|
/**
|
|
6527
6686
|
* Opt into resumable streaming. When `true`, `sendMessage` sends the
|
|
6528
6687
|
* resumable capability header, a stable `assistantUniqueId` is allocated for
|
|
@@ -6558,6 +6717,16 @@ interface UseChatStorageOptions extends BaseUseChatStorageOptions {
|
|
|
6558
6717
|
model?: string;
|
|
6559
6718
|
round?: number;
|
|
6560
6719
|
}) => void;
|
|
6720
|
+
/**
|
|
6721
|
+
* Observability hook fired once per send with the tools actually selected for
|
|
6722
|
+
* the turn (after server + client filtering). Never throws into the send path.
|
|
6723
|
+
* Mirrors react's onToolSelection.
|
|
6724
|
+
*/
|
|
6725
|
+
onToolSelection?: (info: {
|
|
6726
|
+
prompt: string;
|
|
6727
|
+
clientToolNames: string[];
|
|
6728
|
+
serverToolNames: string[];
|
|
6729
|
+
}) => void;
|
|
6561
6730
|
}
|
|
6562
6731
|
/**
|
|
6563
6732
|
* Arguments for sendMessage with storage (Expo version)
|
package/dist/expo/index.d.ts
CHANGED
|
@@ -2786,6 +2786,13 @@ type SendMessageArgs = BaseSendMessageArgs & {
|
|
|
2786
2786
|
* This is typically extracted text from preprocessed file attachments.
|
|
2787
2787
|
*/
|
|
2788
2788
|
fileContext?: string;
|
|
2789
|
+
/**
|
|
2790
|
+
* Tool-set guidance to inject as a system message — the persona/usage prompt
|
|
2791
|
+
* for whichever tool sets activated this turn (e.g. the app-builder prompt).
|
|
2792
|
+
* Additive: composes with the other context messages, never replaces them.
|
|
2793
|
+
* Mirrors react's useChat toolGuidance channel.
|
|
2794
|
+
*/
|
|
2795
|
+
toolGuidance?: string;
|
|
2789
2796
|
/**
|
|
2790
2797
|
* Override the API type for this request only.
|
|
2791
2798
|
* Useful when different models need different APIs.
|
|
@@ -3130,6 +3137,33 @@ interface CachedServerTools {
|
|
|
3130
3137
|
/** Checksum from the server for cache invalidation */
|
|
3131
3138
|
checksum?: string;
|
|
3132
3139
|
}
|
|
3140
|
+
/**
|
|
3141
|
+
* Pluggable persistence for the fetched server-tools list.
|
|
3142
|
+
*
|
|
3143
|
+
* The default backend ({@link localStorageToolsCache}) writes to browser
|
|
3144
|
+
* `localStorage` and is a silent no-op where `localStorage` is undefined
|
|
3145
|
+
* (Node, React Native). Pass a custom backend to `getServerTools` to cache
|
|
3146
|
+
* somewhere that survives on those platforms — e.g. an AsyncStorage/MMKV
|
|
3147
|
+
* adapter on RN, or an in-memory `Map` on a server. Methods may be sync or
|
|
3148
|
+
* async; `getServerTools` awaits them either way.
|
|
3149
|
+
*
|
|
3150
|
+
* The stored payload carries a `version`; `getServerTools` discards any entry
|
|
3151
|
+
* whose version does not match the current cache format, so a stale custom
|
|
3152
|
+
* backend can never feed an incompatible shape back into selection.
|
|
3153
|
+
*/
|
|
3154
|
+
interface ToolsCacheBackend {
|
|
3155
|
+
/** Return the cached payload, or null when absent/unreadable. */
|
|
3156
|
+
get(): CachedServerTools | null | Promise<CachedServerTools | null>;
|
|
3157
|
+
/** Persist the payload. Implementations should swallow write failures. */
|
|
3158
|
+
set(value: CachedServerTools): void | Promise<void>;
|
|
3159
|
+
/**
|
|
3160
|
+
* Remove the cached payload. Optional — a read/write-only backend may omit it,
|
|
3161
|
+
* in which case `clearServerToolsCache` (and the version-mismatch
|
|
3162
|
+
* invalidation) is a no-op for that backend. The default
|
|
3163
|
+
* {@link localStorageToolsCache} implements it.
|
|
3164
|
+
*/
|
|
3165
|
+
clear?(): void | Promise<void>;
|
|
3166
|
+
}
|
|
3133
3167
|
/**
|
|
3134
3168
|
* Options for fetching server tools
|
|
3135
3169
|
*/
|
|
@@ -3144,6 +3178,12 @@ interface ServerToolsOptions {
|
|
|
3144
3178
|
getToken?: () => Promise<string | null>;
|
|
3145
3179
|
/** Direct API key for server-side usage (uses X-API-Key header) */
|
|
3146
3180
|
apiKey?: string;
|
|
3181
|
+
/**
|
|
3182
|
+
* Where to read/write the cached tools list. Defaults to
|
|
3183
|
+
* {@link localStorageToolsCache} (browser `localStorage`; no-op elsewhere).
|
|
3184
|
+
* Provide a backend to enable caching on Node / React Native.
|
|
3185
|
+
*/
|
|
3186
|
+
cache?: ToolsCacheBackend;
|
|
3147
3187
|
}
|
|
3148
3188
|
/** Default cache expiration: 1 day */
|
|
3149
3189
|
declare const DEFAULT_CACHE_EXPIRATION_MS: number;
|
|
@@ -3152,14 +3192,18 @@ declare const DEFAULT_CACHE_EXPIRATION_MS: number;
|
|
|
3152
3192
|
*/
|
|
3153
3193
|
declare function getCachedServerTools(): CachedServerTools | null;
|
|
3154
3194
|
/**
|
|
3155
|
-
* Clear the server tools
|
|
3195
|
+
* Clear the cached server tools. Defaults to the browser-`localStorage` backend;
|
|
3196
|
+
* pass the SAME {@link ToolsCacheBackend} you gave `getServerTools` to invalidate
|
|
3197
|
+
* a custom backend (a no-op when that backend defines no `clear`). Returns the
|
|
3198
|
+
* backend's clear result, which may be async.
|
|
3156
3199
|
*/
|
|
3157
3200
|
declare function clearServerToolsCache(): void;
|
|
3201
|
+
declare function clearServerToolsCache(cache: ToolsCacheBackend): void | Promise<void>;
|
|
3158
3202
|
/**
|
|
3159
3203
|
* Get server tools with caching support.
|
|
3160
3204
|
*
|
|
3161
3205
|
* Flow:
|
|
3162
|
-
* 1. Check localStorage cache
|
|
3206
|
+
* 1. Check the cache backend (localStorage by default; override via `cache`)
|
|
3163
3207
|
* 2. If cache valid and not force refresh, return cached tools
|
|
3164
3208
|
* 3. Otherwise, fetch from API, cache, and return
|
|
3165
3209
|
* 4. On fetch failure, return cached tools if available (stale-while-error)
|
|
@@ -3179,6 +3223,52 @@ interface DeferLoadingConfig {
|
|
|
3179
3223
|
/** Server-tool names to keep non-deferred (besides the tool-search tool), in priority order. */
|
|
3180
3224
|
hotToolNames: readonly string[];
|
|
3181
3225
|
}
|
|
3226
|
+
/**
|
|
3227
|
+
* A tool set defines a group of tools that work together. When any "anchor"
|
|
3228
|
+
* tool in the set is matched semantically (with a score at or above
|
|
3229
|
+
* `anchorMinSimilarity`), the set is activated and all of its members are
|
|
3230
|
+
* pulled into the selection.
|
|
3231
|
+
*
|
|
3232
|
+
* Two activation strategies consume this interface:
|
|
3233
|
+
* - `expandToolSetsAdditive` (used by `useChatStorage` and
|
|
3234
|
+
* `createServerToolsFilter`) keeps all original matches and adds the
|
|
3235
|
+
* set's members on top — non-set tools are never dropped.
|
|
3236
|
+
* - `applyToolSets` is exclusive: it keeps only set members plus non-set
|
|
3237
|
+
* tools that scored above `independentThreshold`.
|
|
3238
|
+
*
|
|
3239
|
+
* Pick `expandToolSetsAdditive` when you want recall over precision
|
|
3240
|
+
* (typical), and `applyToolSets` when you specifically want non-set
|
|
3241
|
+
* matches stripped on activation.
|
|
3242
|
+
*/
|
|
3243
|
+
interface ToolSet {
|
|
3244
|
+
/** Human-readable name for logging/debugging */
|
|
3245
|
+
name: string;
|
|
3246
|
+
/** All tool names in the set */
|
|
3247
|
+
members: string[];
|
|
3248
|
+
/**
|
|
3249
|
+
* Tools that trigger the set when selected. If any anchor appears in the
|
|
3250
|
+
* semantic match results with a score at or above `anchorMinSimilarity`,
|
|
3251
|
+
* all members are pulled in.
|
|
3252
|
+
*/
|
|
3253
|
+
anchors: string[];
|
|
3254
|
+
/**
|
|
3255
|
+
* Minimum similarity an anchor must reach to activate the set.
|
|
3256
|
+
* Prevents false activation on prompts where the anchor barely passes
|
|
3257
|
+
* the global minSimilarity threshold. Default: 0.60
|
|
3258
|
+
*/
|
|
3259
|
+
anchorMinSimilarity?: number;
|
|
3260
|
+
/**
|
|
3261
|
+
* System-prompt fragment to APPEND to the base prompt when this set
|
|
3262
|
+
* activates. Additive, never a replacement — it composes with the host's
|
|
3263
|
+
* persona / memory. Gated on genuine activation (anchor score ≥
|
|
3264
|
+
* `anchorMinSimilarity`, or a forced set) via {@link activatedToolSetNames} →
|
|
3265
|
+
* {@link toolSetSystemPrompts}, NOT on mere anchor presence — a borderline
|
|
3266
|
+
* anchor kept by recall-over-precision must not drag this persona in. Write
|
|
3267
|
+
* it to be self-limiting too (condition its behavior on the user actually
|
|
3268
|
+
* wanting what the set does), so a borderline activation doesn't bias the turn.
|
|
3269
|
+
*/
|
|
3270
|
+
systemPrompt?: string;
|
|
3271
|
+
}
|
|
3182
3272
|
|
|
3183
3273
|
/**
|
|
3184
3274
|
* Function type for dynamic server tools filtering based on prompt embeddings.
|
|
@@ -3541,6 +3631,13 @@ interface BaseUseChatStorageOptions {
|
|
|
3541
3631
|
* {@link DeferLoadingConfig}.
|
|
3542
3632
|
*/
|
|
3543
3633
|
deferLoading?: DeferLoadingConfig;
|
|
3634
|
+
/**
|
|
3635
|
+
* Where to read/write the cached server-tools catalog. Defaults to browser
|
|
3636
|
+
* `localStorage`, which is a silent no-op on React Native — so on RN pass an
|
|
3637
|
+
* AsyncStorage/MMKV-backed {@link ToolsCacheBackend} here or every send
|
|
3638
|
+
* refetches the whole catalog. Forwarded to `getServerTools`.
|
|
3639
|
+
*/
|
|
3640
|
+
cache?: ToolsCacheBackend;
|
|
3544
3641
|
};
|
|
3545
3642
|
/**
|
|
3546
3643
|
* Automatically generate embeddings for messages after saving.
|
|
@@ -5892,14 +5989,14 @@ declare function createChunkVectorCache(maxSize?: number): ChunkVectorCache;
|
|
|
5892
5989
|
declare function recall(query: string, ctx: RecallContext, options?: RecallOptions): Promise<RecallResult>;
|
|
5893
5990
|
|
|
5894
5991
|
/**
|
|
5895
|
-
*
|
|
5992
|
+
* Recall tool constants — deliberately dependency-free.
|
|
5896
5993
|
*
|
|
5897
|
-
*
|
|
5898
|
-
*
|
|
5899
|
-
* `
|
|
5900
|
-
*
|
|
5994
|
+
* Split out of `recallTool.ts` so the tool NAME can be referenced from
|
|
5995
|
+
* node/React-Native-safe modules (e.g. the client-tool selector in
|
|
5996
|
+
* `../tools/clientToolSelection`) without dragging `recall()` and its
|
|
5997
|
+
* WatermelonDB-backed operations into the module graph. `recallTool.ts`
|
|
5998
|
+
* re-exports these to preserve their public identity.
|
|
5901
5999
|
*/
|
|
5902
|
-
|
|
5903
6000
|
/** Tool name surfaced to the LLM. Exported so bench harnesses and chat
|
|
5904
6001
|
* clients reference the same string — drift between prod and bench would
|
|
5905
6002
|
* mask tool-routing bugs in eval. */
|
|
@@ -5907,6 +6004,16 @@ declare const RECALL_TOOL_NAME = "recall_memory";
|
|
|
5907
6004
|
/** Maximum results the executor will return to the LLM, regardless of
|
|
5908
6005
|
* the LLM-supplied `limit`. */
|
|
5909
6006
|
declare const RECALL_MAX_LIMIT = 50;
|
|
6007
|
+
|
|
6008
|
+
/**
|
|
6009
|
+
* Unified Recall Tool
|
|
6010
|
+
*
|
|
6011
|
+
* Single chat-completion tool that searches both vault facts and
|
|
6012
|
+
* conversation chunks via `recall()`. Replaces the legacy pair of
|
|
6013
|
+
* `memory_vault_search` (facts) + `search_memory` (chunks) — the LLM no
|
|
6014
|
+
* longer has to route between two tools.
|
|
6015
|
+
*/
|
|
6016
|
+
|
|
5910
6017
|
interface RecallToolOptions {
|
|
5911
6018
|
/** Lanes to search. Default: ["fact", "chunk"]. */
|
|
5912
6019
|
types?: MemoryKind[];
|
|
@@ -6210,11 +6317,26 @@ declare function chunkText(text: string, options?: ChunkingOptions): TextChunk[]
|
|
|
6210
6317
|
declare function shouldChunkMessage(content: string, chunkSize?: number): boolean;
|
|
6211
6318
|
|
|
6212
6319
|
/**
|
|
6213
|
-
*
|
|
6320
|
+
* Embedding generation — dependency-free core.
|
|
6214
6321
|
*
|
|
6215
|
-
*
|
|
6322
|
+
* The raw "text → embedding" calls, split out of `embeddings.ts` so they can be
|
|
6323
|
+
* imported by node/React-Native-safe modules (the server-tool + client-tool
|
|
6324
|
+
* selection engine in `../tools`) WITHOUT pulling in the WatermelonDB-backed
|
|
6325
|
+
* `db/chat/operations` that `embeddings.ts` needs for its message-persistence
|
|
6326
|
+
* helpers (`embedMessage`, `embedAllMessages`, `chunkAndEmbed*`).
|
|
6327
|
+
*
|
|
6328
|
+
* Nothing here touches the database; the only I/O is the HTTP embeddings
|
|
6329
|
+
* endpoint. `embeddings.ts` re-exports these so existing importers of
|
|
6330
|
+
* `../memoryEngine/embeddings` (and the `../memoryEngine` barrel) keep working.
|
|
6216
6331
|
*/
|
|
6217
6332
|
|
|
6333
|
+
/**
|
|
6334
|
+
* Generate an embedding for text using the API
|
|
6335
|
+
*
|
|
6336
|
+
* Supports two auth methods:
|
|
6337
|
+
* - `apiKey`: Uses X-API-Key header (for server-side/CLI usage)
|
|
6338
|
+
* - `getToken`: Uses Authorization: Bearer header (for Privy identity tokens)
|
|
6339
|
+
*/
|
|
6218
6340
|
declare function generateEmbedding(text: string, options: EmbeddingOptions): Promise<number[]>;
|
|
6219
6341
|
/**
|
|
6220
6342
|
* Generate embeddings for multiple texts, automatically chunking large inputs.
|
|
@@ -6229,6 +6351,18 @@ declare function generateEmbedding(text: string, options: EmbeddingOptions): Pro
|
|
|
6229
6351
|
* @returns Array of embeddings in the same order as input texts
|
|
6230
6352
|
*/
|
|
6231
6353
|
declare function generateEmbeddings(texts: string[], options: EmbeddingOptions): Promise<number[][]>;
|
|
6354
|
+
|
|
6355
|
+
/**
|
|
6356
|
+
* Memory Retrieval Embeddings
|
|
6357
|
+
*
|
|
6358
|
+
* Message-level embedding + persistence helpers: find messages via the
|
|
6359
|
+
* WatermelonDB-backed `db/chat/operations`, embed their content, and store the
|
|
6360
|
+
* vectors/chunks back. The raw "text → embedding" calls live in `./generate`
|
|
6361
|
+
* (dependency-free so the tool-selection engine can import them without the DB
|
|
6362
|
+
* layer) and are re-exported here so existing importers of
|
|
6363
|
+
* `../memoryEngine/embeddings` and the `../memoryEngine` barrel keep working.
|
|
6364
|
+
*/
|
|
6365
|
+
|
|
6232
6366
|
/**
|
|
6233
6367
|
* Embed a single message and store the embedding in the database
|
|
6234
6368
|
*
|
|
@@ -6523,6 +6657,31 @@ interface UseChatStorageOptions extends BaseUseChatStorageOptions {
|
|
|
6523
6657
|
* Auto-flush queued operations when key becomes available. @default true
|
|
6524
6658
|
*/
|
|
6525
6659
|
autoFlushOnKeyAvailable?: boolean;
|
|
6660
|
+
/**
|
|
6661
|
+
* Additional tool sets to apply on top of the built-in ones (app-generation,
|
|
6662
|
+
* slides, github). When any anchor tool in a custom set is selected by
|
|
6663
|
+
* semantic matching, all members of that set are included automatically.
|
|
6664
|
+
*
|
|
6665
|
+
* Treated as static config — set once at hook setup. Changing it across
|
|
6666
|
+
* renders does not affect in-flight `sendMessage` calls; use
|
|
6667
|
+
* `activeToolSets` for dynamic, conversation-state-driven overrides.
|
|
6668
|
+
*/
|
|
6669
|
+
extraToolSets?: ToolSet[];
|
|
6670
|
+
/**
|
|
6671
|
+
* Tool set names that should expand unconditionally for this request,
|
|
6672
|
+
* bypassing the anchor-similarity check. Use when conversation state
|
|
6673
|
+
* implies a set should be present regardless of how the prompt is phrased
|
|
6674
|
+
* — e.g., pass `["documents"]` when the conversation already contains a
|
|
6675
|
+
* generated document, so short follow-up prompts ("make the background red")
|
|
6676
|
+
* still get the full document toolkit.
|
|
6677
|
+
*
|
|
6678
|
+
* Read via a ref so updates are visible to in-flight `sendMessage` calls
|
|
6679
|
+
* without rebuilding the callback.
|
|
6680
|
+
*
|
|
6681
|
+
* Names must match a set's `name` from `BUILT_IN_TOOL_SETS` or
|
|
6682
|
+
* `extraToolSets`. Unknown names are ignored.
|
|
6683
|
+
*/
|
|
6684
|
+
activeToolSets?: string[];
|
|
6526
6685
|
/**
|
|
6527
6686
|
* Opt into resumable streaming. When `true`, `sendMessage` sends the
|
|
6528
6687
|
* resumable capability header, a stable `assistantUniqueId` is allocated for
|
|
@@ -6558,6 +6717,16 @@ interface UseChatStorageOptions extends BaseUseChatStorageOptions {
|
|
|
6558
6717
|
model?: string;
|
|
6559
6718
|
round?: number;
|
|
6560
6719
|
}) => void;
|
|
6720
|
+
/**
|
|
6721
|
+
* Observability hook fired once per send with the tools actually selected for
|
|
6722
|
+
* the turn (after server + client filtering). Never throws into the send path.
|
|
6723
|
+
* Mirrors react's onToolSelection.
|
|
6724
|
+
*/
|
|
6725
|
+
onToolSelection?: (info: {
|
|
6726
|
+
prompt: string;
|
|
6727
|
+
clientToolNames: string[];
|
|
6728
|
+
serverToolNames: string[];
|
|
6729
|
+
}) => void;
|
|
6561
6730
|
}
|
|
6562
6731
|
/**
|
|
6563
6732
|
* Arguments for sendMessage with storage (Expo version)
|