@reverbia/sdk 1.0.0-next.20260110032702 → 1.0.0-next.20260110155148
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/index.d.mts +26 -0
- package/dist/expo/index.d.ts +26 -0
- package/dist/react/index.cjs +29 -3
- package/dist/react/index.d.mts +60 -1
- package/dist/react/index.d.ts +60 -1
- package/dist/react/index.mjs +27 -3
- package/package.json +1 -1
package/dist/expo/index.d.mts
CHANGED
|
@@ -777,12 +777,38 @@ declare function generateCompositeKey(namespace: string, key: string): string;
|
|
|
777
777
|
declare function generateUniqueKey(namespace: string, key: string, value: string): string;
|
|
778
778
|
|
|
779
779
|
type ChatRole = "user" | "assistant" | "system";
|
|
780
|
+
/**
|
|
781
|
+
* Metadata for files attached to messages.
|
|
782
|
+
*
|
|
783
|
+
* Note the distinction between `url` and `sourceUrl`:
|
|
784
|
+
* - `url`: Content URL that gets sent to the AI as part of the message (e.g., data URIs for user uploads)
|
|
785
|
+
* - `sourceUrl`: Original external URL for locally-cached files (for lookup only, never sent to AI)
|
|
786
|
+
*/
|
|
780
787
|
interface FileMetadata {
|
|
788
|
+
/** Unique identifier for the file (used as OPFS key for cached files) */
|
|
781
789
|
id: string;
|
|
790
|
+
/** Display name of the file */
|
|
782
791
|
name: string;
|
|
792
|
+
/** MIME type (e.g., "image/png") */
|
|
783
793
|
type: string;
|
|
794
|
+
/** File size in bytes */
|
|
784
795
|
size: number;
|
|
796
|
+
/**
|
|
797
|
+
* Content URL to include when sending this message to the AI.
|
|
798
|
+
* When present, this URL is added as an `image_url` content part.
|
|
799
|
+
* Typically used for user-uploaded files (data URIs) that should be sent with the message.
|
|
800
|
+
*
|
|
801
|
+
* NOT used for MCP-cached files - those use `sourceUrl` for lookup and render from OPFS.
|
|
802
|
+
*/
|
|
785
803
|
url?: string;
|
|
804
|
+
/**
|
|
805
|
+
* Original external URL for files downloaded and cached locally (e.g., from MCP R2).
|
|
806
|
+
* Used purely for URL→OPFS mapping to enable fallback when the source returns 404.
|
|
807
|
+
*
|
|
808
|
+
* This is metadata for local lookup only - it is NOT sent to the AI or rendered directly.
|
|
809
|
+
* The file content is served from OPFS using the `id` field.
|
|
810
|
+
*/
|
|
811
|
+
sourceUrl?: string;
|
|
786
812
|
}
|
|
787
813
|
interface ChatCompletionUsage {
|
|
788
814
|
promptTokens?: number;
|
package/dist/expo/index.d.ts
CHANGED
|
@@ -777,12 +777,38 @@ declare function generateCompositeKey(namespace: string, key: string): string;
|
|
|
777
777
|
declare function generateUniqueKey(namespace: string, key: string, value: string): string;
|
|
778
778
|
|
|
779
779
|
type ChatRole = "user" | "assistant" | "system";
|
|
780
|
+
/**
|
|
781
|
+
* Metadata for files attached to messages.
|
|
782
|
+
*
|
|
783
|
+
* Note the distinction between `url` and `sourceUrl`:
|
|
784
|
+
* - `url`: Content URL that gets sent to the AI as part of the message (e.g., data URIs for user uploads)
|
|
785
|
+
* - `sourceUrl`: Original external URL for locally-cached files (for lookup only, never sent to AI)
|
|
786
|
+
*/
|
|
780
787
|
interface FileMetadata {
|
|
788
|
+
/** Unique identifier for the file (used as OPFS key for cached files) */
|
|
781
789
|
id: string;
|
|
790
|
+
/** Display name of the file */
|
|
782
791
|
name: string;
|
|
792
|
+
/** MIME type (e.g., "image/png") */
|
|
783
793
|
type: string;
|
|
794
|
+
/** File size in bytes */
|
|
784
795
|
size: number;
|
|
796
|
+
/**
|
|
797
|
+
* Content URL to include when sending this message to the AI.
|
|
798
|
+
* When present, this URL is added as an `image_url` content part.
|
|
799
|
+
* Typically used for user-uploaded files (data URIs) that should be sent with the message.
|
|
800
|
+
*
|
|
801
|
+
* NOT used for MCP-cached files - those use `sourceUrl` for lookup and render from OPFS.
|
|
802
|
+
*/
|
|
785
803
|
url?: string;
|
|
804
|
+
/**
|
|
805
|
+
* Original external URL for files downloaded and cached locally (e.g., from MCP R2).
|
|
806
|
+
* Used purely for URL→OPFS mapping to enable fallback when the source returns 404.
|
|
807
|
+
*
|
|
808
|
+
* This is metadata for local lookup only - it is NOT sent to the AI or rendered directly.
|
|
809
|
+
* The file content is served from OPFS using the `id` field.
|
|
810
|
+
*/
|
|
811
|
+
sourceUrl?: string;
|
|
786
812
|
}
|
|
787
813
|
interface ChatCompletionUsage {
|
|
788
814
|
promptTokens?: number;
|
package/dist/react/index.cjs
CHANGED
|
@@ -74,6 +74,7 @@ __export(index_exports, {
|
|
|
74
74
|
encryptData: () => encryptData,
|
|
75
75
|
exportPublicKey: () => exportPublicKey,
|
|
76
76
|
extractConversationContext: () => extractConversationContext,
|
|
77
|
+
findFileIdBySourceUrl: () => findFileIdBySourceUrl,
|
|
77
78
|
formatMemoriesForChat: () => formatMemoriesForChat,
|
|
78
79
|
generateCompositeKey: () => generateCompositeKey,
|
|
79
80
|
generateConversationId: () => generateConversationId,
|
|
@@ -101,6 +102,7 @@ __export(index_exports, {
|
|
|
101
102
|
memoryStorageSchema: () => memoryStorageSchema,
|
|
102
103
|
refreshCalendarToken: () => refreshCalendarToken,
|
|
103
104
|
refreshDriveToken: () => refreshDriveToken,
|
|
105
|
+
replaceUrlWithMCPPlaceholder: () => replaceUrlWithMCPPlaceholder,
|
|
104
106
|
requestEncryptionKey: () => requestEncryptionKey,
|
|
105
107
|
requestKeyPair: () => requestKeyPair,
|
|
106
108
|
revokeCalendarToken: () => revokeCalendarToken,
|
|
@@ -2828,6 +2830,26 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2828
2830
|
}
|
|
2829
2831
|
|
|
2830
2832
|
// src/react/useChatStorage.ts
|
|
2833
|
+
function replaceUrlWithMCPPlaceholder(content, url, fileId) {
|
|
2834
|
+
const escapedUrl = url.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2835
|
+
const placeholder = `![MCP_IMAGE:${fileId}]`;
|
|
2836
|
+
let result = content;
|
|
2837
|
+
const markdownImagePattern = new RegExp(
|
|
2838
|
+
`!\\[[^\\]]*\\]\\([\\s]*${escapedUrl}[\\s]*\\)`,
|
|
2839
|
+
"g"
|
|
2840
|
+
);
|
|
2841
|
+
result = result.replace(markdownImagePattern, placeholder);
|
|
2842
|
+
result = result.replace(new RegExp(escapedUrl, "g"), placeholder);
|
|
2843
|
+
const orphanedMarkdownPattern = new RegExp(
|
|
2844
|
+
`!\\[[^\\]]*\\]\\([\\s]*\\!\\[MCP_IMAGE:${fileId}\\][\\s]*\\)`,
|
|
2845
|
+
"g"
|
|
2846
|
+
);
|
|
2847
|
+
result = result.replace(orphanedMarkdownPattern, placeholder);
|
|
2848
|
+
return result;
|
|
2849
|
+
}
|
|
2850
|
+
function findFileIdBySourceUrl(files, sourceUrl) {
|
|
2851
|
+
return files?.find((f) => f.sourceUrl === sourceUrl)?.id;
|
|
2852
|
+
}
|
|
2831
2853
|
function storedToLlmapiMessage(stored) {
|
|
2832
2854
|
const content = [
|
|
2833
2855
|
{ type: "text", text: stored.content }
|
|
@@ -3054,7 +3076,8 @@ function useChatStorage(options) {
|
|
|
3054
3076
|
[]
|
|
3055
3077
|
);
|
|
3056
3078
|
const extractAndStoreMCPImages = (0, import_react2.useCallback)(
|
|
3057
|
-
async (content, writeFile) => {
|
|
3079
|
+
async (content, writeFile, options2) => {
|
|
3080
|
+
const { replaceUrls = true } = options2 ?? {};
|
|
3058
3081
|
try {
|
|
3059
3082
|
const MCP_IMAGE_URL_PATTERN = new RegExp(
|
|
3060
3083
|
`https://${MCP_R2_DOMAIN.replace(/\./g, "\\.")}[^\\s)]*`,
|
|
@@ -3128,9 +3151,10 @@ function useChatStorage(options) {
|
|
|
3128
3151
|
id: fileId,
|
|
3129
3152
|
name: fileName,
|
|
3130
3153
|
type: mimeType,
|
|
3131
|
-
size
|
|
3154
|
+
size,
|
|
3155
|
+
sourceUrl: imageUrl
|
|
3132
3156
|
});
|
|
3133
|
-
if (imageUrl) {
|
|
3157
|
+
if (replaceUrls && imageUrl) {
|
|
3134
3158
|
replaceUrlWithPlaceholder(imageUrl, fileId);
|
|
3135
3159
|
}
|
|
3136
3160
|
} else {
|
|
@@ -9187,6 +9211,7 @@ function hasDriveCredentials() {
|
|
|
9187
9211
|
encryptData,
|
|
9188
9212
|
exportPublicKey,
|
|
9189
9213
|
extractConversationContext,
|
|
9214
|
+
findFileIdBySourceUrl,
|
|
9190
9215
|
formatMemoriesForChat,
|
|
9191
9216
|
generateCompositeKey,
|
|
9192
9217
|
generateConversationId,
|
|
@@ -9214,6 +9239,7 @@ function hasDriveCredentials() {
|
|
|
9214
9239
|
memoryStorageSchema,
|
|
9215
9240
|
refreshCalendarToken,
|
|
9216
9241
|
refreshDriveToken,
|
|
9242
|
+
replaceUrlWithMCPPlaceholder,
|
|
9217
9243
|
requestEncryptionKey,
|
|
9218
9244
|
requestKeyPair,
|
|
9219
9245
|
revokeCalendarToken,
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1423,12 +1423,38 @@ declare function generateCompositeKey(namespace: string, key: string): string;
|
|
|
1423
1423
|
declare function generateUniqueKey(namespace: string, key: string, value: string): string;
|
|
1424
1424
|
|
|
1425
1425
|
type ChatRole = "user" | "assistant" | "system";
|
|
1426
|
+
/**
|
|
1427
|
+
* Metadata for files attached to messages.
|
|
1428
|
+
*
|
|
1429
|
+
* Note the distinction between `url` and `sourceUrl`:
|
|
1430
|
+
* - `url`: Content URL that gets sent to the AI as part of the message (e.g., data URIs for user uploads)
|
|
1431
|
+
* - `sourceUrl`: Original external URL for locally-cached files (for lookup only, never sent to AI)
|
|
1432
|
+
*/
|
|
1426
1433
|
interface FileMetadata {
|
|
1434
|
+
/** Unique identifier for the file (used as OPFS key for cached files) */
|
|
1427
1435
|
id: string;
|
|
1436
|
+
/** Display name of the file */
|
|
1428
1437
|
name: string;
|
|
1438
|
+
/** MIME type (e.g., "image/png") */
|
|
1429
1439
|
type: string;
|
|
1440
|
+
/** File size in bytes */
|
|
1430
1441
|
size: number;
|
|
1442
|
+
/**
|
|
1443
|
+
* Content URL to include when sending this message to the AI.
|
|
1444
|
+
* When present, this URL is added as an `image_url` content part.
|
|
1445
|
+
* Typically used for user-uploaded files (data URIs) that should be sent with the message.
|
|
1446
|
+
*
|
|
1447
|
+
* NOT used for MCP-cached files - those use `sourceUrl` for lookup and render from OPFS.
|
|
1448
|
+
*/
|
|
1431
1449
|
url?: string;
|
|
1450
|
+
/**
|
|
1451
|
+
* Original external URL for files downloaded and cached locally (e.g., from MCP R2).
|
|
1452
|
+
* Used purely for URL→OPFS mapping to enable fallback when the source returns 404.
|
|
1453
|
+
*
|
|
1454
|
+
* This is metadata for local lookup only - it is NOT sent to the AI or rendered directly.
|
|
1455
|
+
* The file content is served from OPFS using the `id` field.
|
|
1456
|
+
*/
|
|
1457
|
+
sourceUrl?: string;
|
|
1432
1458
|
}
|
|
1433
1459
|
interface ChatCompletionUsage {
|
|
1434
1460
|
promptTokens?: number;
|
|
@@ -1744,6 +1770,39 @@ declare class Conversation extends Model {
|
|
|
1744
1770
|
isDeleted: boolean;
|
|
1745
1771
|
}
|
|
1746
1772
|
|
|
1773
|
+
/**
|
|
1774
|
+
* Replace a URL in content with an MCP_IMAGE placeholder.
|
|
1775
|
+
* This is used to swap external URLs with locally-stored file references.
|
|
1776
|
+
*
|
|
1777
|
+
* @param content - The message content containing the URL
|
|
1778
|
+
* @param url - The URL to replace
|
|
1779
|
+
* @param fileId - The OPFS file ID to reference
|
|
1780
|
+
* @returns The content with the URL replaced by ![MCP_IMAGE:fileId]
|
|
1781
|
+
*
|
|
1782
|
+
* @example
|
|
1783
|
+
* ```ts
|
|
1784
|
+
* // Replace a URL that returned 404 with local file reference
|
|
1785
|
+
* const newContent = replaceUrlWithMCPPlaceholder(
|
|
1786
|
+
* message.content,
|
|
1787
|
+
* "https://example.com/image.png",
|
|
1788
|
+
* "abc-123-def"
|
|
1789
|
+
* );
|
|
1790
|
+
* await updateMessage(message.uniqueId, { content: newContent });
|
|
1791
|
+
* ```
|
|
1792
|
+
*/
|
|
1793
|
+
declare function replaceUrlWithMCPPlaceholder(content: string, url: string, fileId: string): string;
|
|
1794
|
+
/**
|
|
1795
|
+
* Find the OPFS file ID for a given source URL from a message's files.
|
|
1796
|
+
* Used to look up local file storage when an external URL fails (e.g., 404).
|
|
1797
|
+
*
|
|
1798
|
+
* @param files - Array of FileMetadata from a stored message
|
|
1799
|
+
* @param sourceUrl - The original URL to look up
|
|
1800
|
+
* @returns The file ID if found, or undefined
|
|
1801
|
+
*/
|
|
1802
|
+
declare function findFileIdBySourceUrl(files: {
|
|
1803
|
+
id: string;
|
|
1804
|
+
sourceUrl?: string;
|
|
1805
|
+
}[] | undefined, sourceUrl: string): string | undefined;
|
|
1747
1806
|
/**
|
|
1748
1807
|
* Options for useChatStorage hook (React version)
|
|
1749
1808
|
*
|
|
@@ -3742,4 +3801,4 @@ declare function storeDriveToken(accessToken: string, expiresIn?: number, refres
|
|
|
3742
3801
|
*/
|
|
3743
3802
|
declare function hasDriveCredentials(): boolean;
|
|
3744
3803
|
|
|
3745
|
-
export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, type CreateUserPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, DEFAULT_PERSONALITY_SETTINGS, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type EmbeddedWalletSignerFn, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type PersonalitySettings, type PersonalitySliders, type PersonalityStyle, type ProfileUpdate, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, SLIDER_CONFIG, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type StoredUserPreference, UserPreference as StoredUserPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UpdateUserPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseEncryptionResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseImageGenerationResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsResult, type UseOCRResult, type UsePdfResult, type UseSearchResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearCalendarToken, clearDriveToken, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, exportPublicKey, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getAndClearCalendarPendingMessage, getAndClearCalendarReturnUrl, getAndClearDrivePendingMessage, getAndClearDriveReturnUrl, getCalendarAccessToken, getDriveAccessToken, getGoogleDriveStoredToken, getValidCalendarToken, getValidDriveToken, handleCalendarCallback, handleDriveCallback, hasCalendarCredentials, hasDriveCredentials, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, isCalendarCallback, isDriveCallback, memoryStorageSchema, refreshCalendarToken, refreshDriveToken, requestEncryptionKey, requestKeyPair, revokeCalendarToken, revokeDriveToken, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, startCalendarAuth, startDriveAuth, storeCalendarPendingMessage, storeCalendarReturnUrl, storeCalendarToken, storeDrivePendingMessage, storeDriveReturnUrl, storeDriveToken, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings, userPreferencesStorageSchema };
|
|
3804
|
+
export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, type CreateUserPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, DEFAULT_PERSONALITY_SETTINGS, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type EmbeddedWalletSignerFn, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type PersonalitySettings, type PersonalitySliders, type PersonalityStyle, type ProfileUpdate, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, SLIDER_CONFIG, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type StoredUserPreference, UserPreference as StoredUserPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UpdateUserPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseEncryptionResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseImageGenerationResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsResult, type UseOCRResult, type UsePdfResult, type UseSearchResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearCalendarToken, clearDriveToken, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, exportPublicKey, extractConversationContext, findFileIdBySourceUrl, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getAndClearCalendarPendingMessage, getAndClearCalendarReturnUrl, getAndClearDrivePendingMessage, getAndClearDriveReturnUrl, getCalendarAccessToken, getDriveAccessToken, getGoogleDriveStoredToken, getValidCalendarToken, getValidDriveToken, handleCalendarCallback, handleDriveCallback, hasCalendarCredentials, hasDriveCredentials, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, isCalendarCallback, isDriveCallback, memoryStorageSchema, refreshCalendarToken, refreshDriveToken, replaceUrlWithMCPPlaceholder, requestEncryptionKey, requestKeyPair, revokeCalendarToken, revokeDriveToken, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, startCalendarAuth, startDriveAuth, storeCalendarPendingMessage, storeCalendarReturnUrl, storeCalendarToken, storeDrivePendingMessage, storeDriveReturnUrl, storeDriveToken, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings, userPreferencesStorageSchema };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1423,12 +1423,38 @@ declare function generateCompositeKey(namespace: string, key: string): string;
|
|
|
1423
1423
|
declare function generateUniqueKey(namespace: string, key: string, value: string): string;
|
|
1424
1424
|
|
|
1425
1425
|
type ChatRole = "user" | "assistant" | "system";
|
|
1426
|
+
/**
|
|
1427
|
+
* Metadata for files attached to messages.
|
|
1428
|
+
*
|
|
1429
|
+
* Note the distinction between `url` and `sourceUrl`:
|
|
1430
|
+
* - `url`: Content URL that gets sent to the AI as part of the message (e.g., data URIs for user uploads)
|
|
1431
|
+
* - `sourceUrl`: Original external URL for locally-cached files (for lookup only, never sent to AI)
|
|
1432
|
+
*/
|
|
1426
1433
|
interface FileMetadata {
|
|
1434
|
+
/** Unique identifier for the file (used as OPFS key for cached files) */
|
|
1427
1435
|
id: string;
|
|
1436
|
+
/** Display name of the file */
|
|
1428
1437
|
name: string;
|
|
1438
|
+
/** MIME type (e.g., "image/png") */
|
|
1429
1439
|
type: string;
|
|
1440
|
+
/** File size in bytes */
|
|
1430
1441
|
size: number;
|
|
1442
|
+
/**
|
|
1443
|
+
* Content URL to include when sending this message to the AI.
|
|
1444
|
+
* When present, this URL is added as an `image_url` content part.
|
|
1445
|
+
* Typically used for user-uploaded files (data URIs) that should be sent with the message.
|
|
1446
|
+
*
|
|
1447
|
+
* NOT used for MCP-cached files - those use `sourceUrl` for lookup and render from OPFS.
|
|
1448
|
+
*/
|
|
1431
1449
|
url?: string;
|
|
1450
|
+
/**
|
|
1451
|
+
* Original external URL for files downloaded and cached locally (e.g., from MCP R2).
|
|
1452
|
+
* Used purely for URL→OPFS mapping to enable fallback when the source returns 404.
|
|
1453
|
+
*
|
|
1454
|
+
* This is metadata for local lookup only - it is NOT sent to the AI or rendered directly.
|
|
1455
|
+
* The file content is served from OPFS using the `id` field.
|
|
1456
|
+
*/
|
|
1457
|
+
sourceUrl?: string;
|
|
1432
1458
|
}
|
|
1433
1459
|
interface ChatCompletionUsage {
|
|
1434
1460
|
promptTokens?: number;
|
|
@@ -1744,6 +1770,39 @@ declare class Conversation extends Model {
|
|
|
1744
1770
|
isDeleted: boolean;
|
|
1745
1771
|
}
|
|
1746
1772
|
|
|
1773
|
+
/**
|
|
1774
|
+
* Replace a URL in content with an MCP_IMAGE placeholder.
|
|
1775
|
+
* This is used to swap external URLs with locally-stored file references.
|
|
1776
|
+
*
|
|
1777
|
+
* @param content - The message content containing the URL
|
|
1778
|
+
* @param url - The URL to replace
|
|
1779
|
+
* @param fileId - The OPFS file ID to reference
|
|
1780
|
+
* @returns The content with the URL replaced by ![MCP_IMAGE:fileId]
|
|
1781
|
+
*
|
|
1782
|
+
* @example
|
|
1783
|
+
* ```ts
|
|
1784
|
+
* // Replace a URL that returned 404 with local file reference
|
|
1785
|
+
* const newContent = replaceUrlWithMCPPlaceholder(
|
|
1786
|
+
* message.content,
|
|
1787
|
+
* "https://example.com/image.png",
|
|
1788
|
+
* "abc-123-def"
|
|
1789
|
+
* );
|
|
1790
|
+
* await updateMessage(message.uniqueId, { content: newContent });
|
|
1791
|
+
* ```
|
|
1792
|
+
*/
|
|
1793
|
+
declare function replaceUrlWithMCPPlaceholder(content: string, url: string, fileId: string): string;
|
|
1794
|
+
/**
|
|
1795
|
+
* Find the OPFS file ID for a given source URL from a message's files.
|
|
1796
|
+
* Used to look up local file storage when an external URL fails (e.g., 404).
|
|
1797
|
+
*
|
|
1798
|
+
* @param files - Array of FileMetadata from a stored message
|
|
1799
|
+
* @param sourceUrl - The original URL to look up
|
|
1800
|
+
* @returns The file ID if found, or undefined
|
|
1801
|
+
*/
|
|
1802
|
+
declare function findFileIdBySourceUrl(files: {
|
|
1803
|
+
id: string;
|
|
1804
|
+
sourceUrl?: string;
|
|
1805
|
+
}[] | undefined, sourceUrl: string): string | undefined;
|
|
1747
1806
|
/**
|
|
1748
1807
|
* Options for useChatStorage hook (React version)
|
|
1749
1808
|
*
|
|
@@ -3742,4 +3801,4 @@ declare function storeDriveToken(accessToken: string, expiresIn?: number, refres
|
|
|
3742
3801
|
*/
|
|
3743
3802
|
declare function hasDriveCredentials(): boolean;
|
|
3744
3803
|
|
|
3745
|
-
export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, type CreateUserPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, DEFAULT_PERSONALITY_SETTINGS, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type EmbeddedWalletSignerFn, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type PersonalitySettings, type PersonalitySliders, type PersonalityStyle, type ProfileUpdate, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, SLIDER_CONFIG, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type StoredUserPreference, UserPreference as StoredUserPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UpdateUserPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseEncryptionResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseImageGenerationResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsResult, type UseOCRResult, type UsePdfResult, type UseSearchResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearCalendarToken, clearDriveToken, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, exportPublicKey, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getAndClearCalendarPendingMessage, getAndClearCalendarReturnUrl, getAndClearDrivePendingMessage, getAndClearDriveReturnUrl, getCalendarAccessToken, getDriveAccessToken, getGoogleDriveStoredToken, getValidCalendarToken, getValidDriveToken, handleCalendarCallback, handleDriveCallback, hasCalendarCredentials, hasDriveCredentials, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, isCalendarCallback, isDriveCallback, memoryStorageSchema, refreshCalendarToken, refreshDriveToken, requestEncryptionKey, requestKeyPair, revokeCalendarToken, revokeDriveToken, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, startCalendarAuth, startDriveAuth, storeCalendarPendingMessage, storeCalendarReturnUrl, storeCalendarToken, storeDrivePendingMessage, storeDriveReturnUrl, storeDriveToken, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings, userPreferencesStorageSchema };
|
|
3804
|
+
export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, type CreateUserPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, DEFAULT_PERSONALITY_SETTINGS, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type EmbeddedWalletSignerFn, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type PersonalitySettings, type PersonalitySliders, type PersonalityStyle, type ProfileUpdate, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, SLIDER_CONFIG, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type StoredUserPreference, UserPreference as StoredUserPreferenceModel, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UpdateUserPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseEncryptionResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseImageGenerationResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseModelsResult, type UseOCRResult, type UsePdfResult, type UseSearchResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearAllEncryptionKeys, clearAllKeyPairs, clearCalendarToken, clearDriveToken, clearToken as clearDropboxToken, clearEncryptionKey, clearGoogleDriveToken, clearICloudAuth, clearKeyPair, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, exportPublicKey, extractConversationContext, findFileIdBySourceUrl, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getAndClearCalendarPendingMessage, getAndClearCalendarReturnUrl, getAndClearDrivePendingMessage, getAndClearDriveReturnUrl, getCalendarAccessToken, getDriveAccessToken, getGoogleDriveStoredToken, getValidCalendarToken, getValidDriveToken, handleCalendarCallback, handleDriveCallback, hasCalendarCredentials, hasDriveCredentials, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, hasKeyPair, isCalendarCallback, isDriveCallback, memoryStorageSchema, refreshCalendarToken, refreshDriveToken, replaceUrlWithMCPPlaceholder, requestEncryptionKey, requestKeyPair, revokeCalendarToken, revokeDriveToken, sdkMigrations, sdkModelClasses, sdkSchema, settingsStorageSchema, startCalendarAuth, startDriveAuth, storeCalendarPendingMessage, storeCalendarReturnUrl, storeCalendarToken, storeDrivePendingMessage, storeDriveReturnUrl, storeDriveToken, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings, userPreferencesStorageSchema };
|
package/dist/react/index.mjs
CHANGED
|
@@ -2701,6 +2701,26 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2701
2701
|
}
|
|
2702
2702
|
|
|
2703
2703
|
// src/react/useChatStorage.ts
|
|
2704
|
+
function replaceUrlWithMCPPlaceholder(content, url, fileId) {
|
|
2705
|
+
const escapedUrl = url.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2706
|
+
const placeholder = `![MCP_IMAGE:${fileId}]`;
|
|
2707
|
+
let result = content;
|
|
2708
|
+
const markdownImagePattern = new RegExp(
|
|
2709
|
+
`!\\[[^\\]]*\\]\\([\\s]*${escapedUrl}[\\s]*\\)`,
|
|
2710
|
+
"g"
|
|
2711
|
+
);
|
|
2712
|
+
result = result.replace(markdownImagePattern, placeholder);
|
|
2713
|
+
result = result.replace(new RegExp(escapedUrl, "g"), placeholder);
|
|
2714
|
+
const orphanedMarkdownPattern = new RegExp(
|
|
2715
|
+
`!\\[[^\\]]*\\]\\([\\s]*\\!\\[MCP_IMAGE:${fileId}\\][\\s]*\\)`,
|
|
2716
|
+
"g"
|
|
2717
|
+
);
|
|
2718
|
+
result = result.replace(orphanedMarkdownPattern, placeholder);
|
|
2719
|
+
return result;
|
|
2720
|
+
}
|
|
2721
|
+
function findFileIdBySourceUrl(files, sourceUrl) {
|
|
2722
|
+
return files?.find((f) => f.sourceUrl === sourceUrl)?.id;
|
|
2723
|
+
}
|
|
2704
2724
|
function storedToLlmapiMessage(stored) {
|
|
2705
2725
|
const content = [
|
|
2706
2726
|
{ type: "text", text: stored.content }
|
|
@@ -2927,7 +2947,8 @@ function useChatStorage(options) {
|
|
|
2927
2947
|
[]
|
|
2928
2948
|
);
|
|
2929
2949
|
const extractAndStoreMCPImages = useCallback2(
|
|
2930
|
-
async (content, writeFile) => {
|
|
2950
|
+
async (content, writeFile, options2) => {
|
|
2951
|
+
const { replaceUrls = true } = options2 ?? {};
|
|
2931
2952
|
try {
|
|
2932
2953
|
const MCP_IMAGE_URL_PATTERN = new RegExp(
|
|
2933
2954
|
`https://${MCP_R2_DOMAIN.replace(/\./g, "\\.")}[^\\s)]*`,
|
|
@@ -3001,9 +3022,10 @@ function useChatStorage(options) {
|
|
|
3001
3022
|
id: fileId,
|
|
3002
3023
|
name: fileName,
|
|
3003
3024
|
type: mimeType,
|
|
3004
|
-
size
|
|
3025
|
+
size,
|
|
3026
|
+
sourceUrl: imageUrl
|
|
3005
3027
|
});
|
|
3006
|
-
if (imageUrl) {
|
|
3028
|
+
if (replaceUrls && imageUrl) {
|
|
3007
3029
|
replaceUrlWithPlaceholder(imageUrl, fileId);
|
|
3008
3030
|
}
|
|
3009
3031
|
} else {
|
|
@@ -9092,6 +9114,7 @@ export {
|
|
|
9092
9114
|
encryptData,
|
|
9093
9115
|
exportPublicKey,
|
|
9094
9116
|
extractConversationContext,
|
|
9117
|
+
findFileIdBySourceUrl,
|
|
9095
9118
|
formatMemoriesForChat,
|
|
9096
9119
|
generateCompositeKey,
|
|
9097
9120
|
generateConversationId,
|
|
@@ -9119,6 +9142,7 @@ export {
|
|
|
9119
9142
|
memoryStorageSchema,
|
|
9120
9143
|
refreshCalendarToken,
|
|
9121
9144
|
refreshDriveToken,
|
|
9145
|
+
replaceUrlWithMCPPlaceholder,
|
|
9122
9146
|
requestEncryptionKey,
|
|
9123
9147
|
requestKeyPair,
|
|
9124
9148
|
revokeCalendarToken,
|