@reverbia/sdk 1.0.0-next.20260109181949 → 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.cjs +32 -1
- package/dist/expo/index.d.mts +26 -0
- package/dist/expo/index.d.ts +26 -0
- package/dist/expo/index.mjs +32 -1
- package/dist/react/index.cjs +61 -5
- package/dist/react/index.d.mts +60 -1
- package/dist/react/index.d.ts +60 -1
- package/dist/react/index.mjs +59 -5
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -1642,6 +1642,34 @@ function useChatStorage(options) {
|
|
|
1642
1642
|
if (!content) {
|
|
1643
1643
|
return extractedSources;
|
|
1644
1644
|
}
|
|
1645
|
+
const jsonBlockRegex = /```(?:json)?\s*(\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\})\s*```/g;
|
|
1646
|
+
let jsonMatch;
|
|
1647
|
+
let foundJsonSources = false;
|
|
1648
|
+
while ((jsonMatch = jsonBlockRegex.exec(content)) !== null) {
|
|
1649
|
+
if (jsonMatch[1]) {
|
|
1650
|
+
try {
|
|
1651
|
+
const parsed = JSON.parse(jsonMatch[1]);
|
|
1652
|
+
if (Array.isArray(parsed.sources)) {
|
|
1653
|
+
foundJsonSources = true;
|
|
1654
|
+
for (const source of parsed.sources) {
|
|
1655
|
+
if (source.url && !seenUrls.has(source.url)) {
|
|
1656
|
+
seenUrls.add(source.url);
|
|
1657
|
+
extractedSources.push({
|
|
1658
|
+
title: source.title || void 0,
|
|
1659
|
+
url: source.url,
|
|
1660
|
+
// Map 'description' from JSON to 'snippet' in SearchSource type
|
|
1661
|
+
snippet: source.description || source.snippet || void 0
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
} catch {
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
if (foundJsonSources) {
|
|
1671
|
+
return extractedSources;
|
|
1672
|
+
}
|
|
1645
1673
|
const markdownLinkRegex = /\[([^\]]*)\]\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g;
|
|
1646
1674
|
const plainUrlRegex = /https?:\/\/[^\s<>\[\]()'"]+/g;
|
|
1647
1675
|
let match;
|
|
@@ -1889,12 +1917,15 @@ function useChatStorage(options) {
|
|
|
1889
1917
|
content: assistantContent,
|
|
1890
1918
|
sources
|
|
1891
1919
|
});
|
|
1920
|
+
const jsonSourcesBlockRegex = /```(?:json)?\s*\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\}\s*```/g;
|
|
1921
|
+
let cleanedContent = assistantContent.replace(jsonSourcesBlockRegex, "").trim();
|
|
1922
|
+
cleanedContent = cleanedContent.replace(/\n{3,}/g, "\n\n");
|
|
1892
1923
|
let storedAssistantMessage;
|
|
1893
1924
|
try {
|
|
1894
1925
|
storedAssistantMessage = await createMessageOp(storageCtx, {
|
|
1895
1926
|
conversationId: convId,
|
|
1896
1927
|
role: "assistant",
|
|
1897
|
-
content:
|
|
1928
|
+
content: cleanedContent,
|
|
1898
1929
|
model: responseData.model || model,
|
|
1899
1930
|
usage: convertUsageToStored(responseData.usage),
|
|
1900
1931
|
responseDuration,
|
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/expo/index.mjs
CHANGED
|
@@ -1606,6 +1606,34 @@ function useChatStorage(options) {
|
|
|
1606
1606
|
if (!content) {
|
|
1607
1607
|
return extractedSources;
|
|
1608
1608
|
}
|
|
1609
|
+
const jsonBlockRegex = /```(?:json)?\s*(\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\})\s*```/g;
|
|
1610
|
+
let jsonMatch;
|
|
1611
|
+
let foundJsonSources = false;
|
|
1612
|
+
while ((jsonMatch = jsonBlockRegex.exec(content)) !== null) {
|
|
1613
|
+
if (jsonMatch[1]) {
|
|
1614
|
+
try {
|
|
1615
|
+
const parsed = JSON.parse(jsonMatch[1]);
|
|
1616
|
+
if (Array.isArray(parsed.sources)) {
|
|
1617
|
+
foundJsonSources = true;
|
|
1618
|
+
for (const source of parsed.sources) {
|
|
1619
|
+
if (source.url && !seenUrls.has(source.url)) {
|
|
1620
|
+
seenUrls.add(source.url);
|
|
1621
|
+
extractedSources.push({
|
|
1622
|
+
title: source.title || void 0,
|
|
1623
|
+
url: source.url,
|
|
1624
|
+
// Map 'description' from JSON to 'snippet' in SearchSource type
|
|
1625
|
+
snippet: source.description || source.snippet || void 0
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
} catch {
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (foundJsonSources) {
|
|
1635
|
+
return extractedSources;
|
|
1636
|
+
}
|
|
1609
1637
|
const markdownLinkRegex = /\[([^\]]*)\]\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g;
|
|
1610
1638
|
const plainUrlRegex = /https?:\/\/[^\s<>\[\]()'"]+/g;
|
|
1611
1639
|
let match;
|
|
@@ -1853,12 +1881,15 @@ function useChatStorage(options) {
|
|
|
1853
1881
|
content: assistantContent,
|
|
1854
1882
|
sources
|
|
1855
1883
|
});
|
|
1884
|
+
const jsonSourcesBlockRegex = /```(?:json)?\s*\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\}\s*```/g;
|
|
1885
|
+
let cleanedContent = assistantContent.replace(jsonSourcesBlockRegex, "").trim();
|
|
1886
|
+
cleanedContent = cleanedContent.replace(/\n{3,}/g, "\n\n");
|
|
1856
1887
|
let storedAssistantMessage;
|
|
1857
1888
|
try {
|
|
1858
1889
|
storedAssistantMessage = await createMessageOp(storageCtx, {
|
|
1859
1890
|
conversationId: convId,
|
|
1860
1891
|
role: "assistant",
|
|
1861
|
-
content:
|
|
1892
|
+
content: cleanedContent,
|
|
1862
1893
|
model: responseData.model || model,
|
|
1863
1894
|
usage: convertUsageToStored(responseData.usage),
|
|
1864
1895
|
responseDuration,
|
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 }
|
|
@@ -2987,6 +3009,34 @@ function useChatStorage(options) {
|
|
|
2987
3009
|
if (!content) {
|
|
2988
3010
|
return extractedSources;
|
|
2989
3011
|
}
|
|
3012
|
+
const jsonBlockRegex = /```(?:json)?\s*(\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\})\s*```/g;
|
|
3013
|
+
let jsonMatch;
|
|
3014
|
+
let foundJsonSources = false;
|
|
3015
|
+
while ((jsonMatch = jsonBlockRegex.exec(content)) !== null) {
|
|
3016
|
+
if (jsonMatch[1]) {
|
|
3017
|
+
try {
|
|
3018
|
+
const parsed = JSON.parse(jsonMatch[1]);
|
|
3019
|
+
if (Array.isArray(parsed.sources)) {
|
|
3020
|
+
foundJsonSources = true;
|
|
3021
|
+
for (const source of parsed.sources) {
|
|
3022
|
+
if (source.url && !seenUrls.has(source.url)) {
|
|
3023
|
+
seenUrls.add(source.url);
|
|
3024
|
+
extractedSources.push({
|
|
3025
|
+
title: source.title || void 0,
|
|
3026
|
+
url: source.url,
|
|
3027
|
+
// Map 'description' from JSON to 'snippet' in SearchSource type
|
|
3028
|
+
snippet: source.description || source.snippet || void 0
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
} catch {
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
}
|
|
3037
|
+
if (foundJsonSources) {
|
|
3038
|
+
return extractedSources;
|
|
3039
|
+
}
|
|
2990
3040
|
const markdownLinkRegex = /\[([^\]]*)\]\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g;
|
|
2991
3041
|
const plainUrlRegex = /(?<![(\[])https?:\/\/[^\s<>\[\]()'"]+(?<![.,;:!?])/g;
|
|
2992
3042
|
let match;
|
|
@@ -3026,7 +3076,8 @@ function useChatStorage(options) {
|
|
|
3026
3076
|
[]
|
|
3027
3077
|
);
|
|
3028
3078
|
const extractAndStoreMCPImages = (0, import_react2.useCallback)(
|
|
3029
|
-
async (content, writeFile) => {
|
|
3079
|
+
async (content, writeFile, options2) => {
|
|
3080
|
+
const { replaceUrls = true } = options2 ?? {};
|
|
3030
3081
|
try {
|
|
3031
3082
|
const MCP_IMAGE_URL_PATTERN = new RegExp(
|
|
3032
3083
|
`https://${MCP_R2_DOMAIN.replace(/\./g, "\\.")}[^\\s)]*`,
|
|
@@ -3100,9 +3151,10 @@ function useChatStorage(options) {
|
|
|
3100
3151
|
id: fileId,
|
|
3101
3152
|
name: fileName,
|
|
3102
3153
|
type: mimeType,
|
|
3103
|
-
size
|
|
3154
|
+
size,
|
|
3155
|
+
sourceUrl: imageUrl
|
|
3104
3156
|
});
|
|
3105
|
-
if (imageUrl) {
|
|
3157
|
+
if (replaceUrls && imageUrl) {
|
|
3106
3158
|
replaceUrlWithPlaceholder(imageUrl, fileId);
|
|
3107
3159
|
}
|
|
3108
3160
|
} else {
|
|
@@ -3312,11 +3364,13 @@ function useChatStorage(options) {
|
|
|
3312
3364
|
content: assistantContent,
|
|
3313
3365
|
sources
|
|
3314
3366
|
}).filter((source) => !source.url?.includes(MCP_R2_DOMAIN));
|
|
3367
|
+
const jsonSourcesBlockRegex = /```(?:json)?\s*\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\}\s*```/g;
|
|
3368
|
+
let cleanedContent = assistantContent.replace(jsonSourcesBlockRegex, "").trim();
|
|
3369
|
+
cleanedContent = cleanedContent.replace(/\n{3,}/g, "\n\n");
|
|
3315
3370
|
let processedFiles = [];
|
|
3316
|
-
let cleanedContent = assistantContent;
|
|
3317
3371
|
if (writeFile) {
|
|
3318
3372
|
const result2 = await extractAndStoreMCPImages(
|
|
3319
|
-
|
|
3373
|
+
cleanedContent,
|
|
3320
3374
|
writeFile
|
|
3321
3375
|
);
|
|
3322
3376
|
processedFiles = result2.processedFiles;
|
|
@@ -9157,6 +9211,7 @@ function hasDriveCredentials() {
|
|
|
9157
9211
|
encryptData,
|
|
9158
9212
|
exportPublicKey,
|
|
9159
9213
|
extractConversationContext,
|
|
9214
|
+
findFileIdBySourceUrl,
|
|
9160
9215
|
formatMemoriesForChat,
|
|
9161
9216
|
generateCompositeKey,
|
|
9162
9217
|
generateConversationId,
|
|
@@ -9184,6 +9239,7 @@ function hasDriveCredentials() {
|
|
|
9184
9239
|
memoryStorageSchema,
|
|
9185
9240
|
refreshCalendarToken,
|
|
9186
9241
|
refreshDriveToken,
|
|
9242
|
+
replaceUrlWithMCPPlaceholder,
|
|
9187
9243
|
requestEncryptionKey,
|
|
9188
9244
|
requestKeyPair,
|
|
9189
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 }
|
|
@@ -2860,6 +2880,34 @@ function useChatStorage(options) {
|
|
|
2860
2880
|
if (!content) {
|
|
2861
2881
|
return extractedSources;
|
|
2862
2882
|
}
|
|
2883
|
+
const jsonBlockRegex = /```(?:json)?\s*(\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\})\s*```/g;
|
|
2884
|
+
let jsonMatch;
|
|
2885
|
+
let foundJsonSources = false;
|
|
2886
|
+
while ((jsonMatch = jsonBlockRegex.exec(content)) !== null) {
|
|
2887
|
+
if (jsonMatch[1]) {
|
|
2888
|
+
try {
|
|
2889
|
+
const parsed = JSON.parse(jsonMatch[1]);
|
|
2890
|
+
if (Array.isArray(parsed.sources)) {
|
|
2891
|
+
foundJsonSources = true;
|
|
2892
|
+
for (const source of parsed.sources) {
|
|
2893
|
+
if (source.url && !seenUrls.has(source.url)) {
|
|
2894
|
+
seenUrls.add(source.url);
|
|
2895
|
+
extractedSources.push({
|
|
2896
|
+
title: source.title || void 0,
|
|
2897
|
+
url: source.url,
|
|
2898
|
+
// Map 'description' from JSON to 'snippet' in SearchSource type
|
|
2899
|
+
snippet: source.description || source.snippet || void 0
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
} catch {
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
if (foundJsonSources) {
|
|
2909
|
+
return extractedSources;
|
|
2910
|
+
}
|
|
2863
2911
|
const markdownLinkRegex = /\[([^\]]*)\]\(([^()]*(?:\([^()]*\)[^()]*)*)\)/g;
|
|
2864
2912
|
const plainUrlRegex = /(?<![(\[])https?:\/\/[^\s<>\[\]()'"]+(?<![.,;:!?])/g;
|
|
2865
2913
|
let match;
|
|
@@ -2899,7 +2947,8 @@ function useChatStorage(options) {
|
|
|
2899
2947
|
[]
|
|
2900
2948
|
);
|
|
2901
2949
|
const extractAndStoreMCPImages = useCallback2(
|
|
2902
|
-
async (content, writeFile) => {
|
|
2950
|
+
async (content, writeFile, options2) => {
|
|
2951
|
+
const { replaceUrls = true } = options2 ?? {};
|
|
2903
2952
|
try {
|
|
2904
2953
|
const MCP_IMAGE_URL_PATTERN = new RegExp(
|
|
2905
2954
|
`https://${MCP_R2_DOMAIN.replace(/\./g, "\\.")}[^\\s)]*`,
|
|
@@ -2973,9 +3022,10 @@ function useChatStorage(options) {
|
|
|
2973
3022
|
id: fileId,
|
|
2974
3023
|
name: fileName,
|
|
2975
3024
|
type: mimeType,
|
|
2976
|
-
size
|
|
3025
|
+
size,
|
|
3026
|
+
sourceUrl: imageUrl
|
|
2977
3027
|
});
|
|
2978
|
-
if (imageUrl) {
|
|
3028
|
+
if (replaceUrls && imageUrl) {
|
|
2979
3029
|
replaceUrlWithPlaceholder(imageUrl, fileId);
|
|
2980
3030
|
}
|
|
2981
3031
|
} else {
|
|
@@ -3185,11 +3235,13 @@ function useChatStorage(options) {
|
|
|
3185
3235
|
content: assistantContent,
|
|
3186
3236
|
sources
|
|
3187
3237
|
}).filter((source) => !source.url?.includes(MCP_R2_DOMAIN));
|
|
3238
|
+
const jsonSourcesBlockRegex = /```(?:json)?\s*\{(?:(?!```)[^])*?"sources"(?:(?!```)[^])*?\}\s*```/g;
|
|
3239
|
+
let cleanedContent = assistantContent.replace(jsonSourcesBlockRegex, "").trim();
|
|
3240
|
+
cleanedContent = cleanedContent.replace(/\n{3,}/g, "\n\n");
|
|
3188
3241
|
let processedFiles = [];
|
|
3189
|
-
let cleanedContent = assistantContent;
|
|
3190
3242
|
if (writeFile) {
|
|
3191
3243
|
const result2 = await extractAndStoreMCPImages(
|
|
3192
|
-
|
|
3244
|
+
cleanedContent,
|
|
3193
3245
|
writeFile
|
|
3194
3246
|
);
|
|
3195
3247
|
processedFiles = result2.processedFiles;
|
|
@@ -9062,6 +9114,7 @@ export {
|
|
|
9062
9114
|
encryptData,
|
|
9063
9115
|
exportPublicKey,
|
|
9064
9116
|
extractConversationContext,
|
|
9117
|
+
findFileIdBySourceUrl,
|
|
9065
9118
|
formatMemoriesForChat,
|
|
9066
9119
|
generateCompositeKey,
|
|
9067
9120
|
generateConversationId,
|
|
@@ -9089,6 +9142,7 @@ export {
|
|
|
9089
9142
|
memoryStorageSchema,
|
|
9090
9143
|
refreshCalendarToken,
|
|
9091
9144
|
refreshDriveToken,
|
|
9145
|
+
replaceUrlWithMCPPlaceholder,
|
|
9092
9146
|
requestEncryptionKey,
|
|
9093
9147
|
requestKeyPair,
|
|
9094
9148
|
revokeCalendarToken,
|