@smart-cloud/ai-kit-ui 1.5.13 → 1.5.15
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/LocaleDirectionProvider.d.ts +5 -0
- package/dist/index.cjs +9 -9
- package/dist/index.js +9 -9
- package/dist/locale.d.ts +13 -0
- package/package.json +35 -19
- package/eslint.config.js +0 -18
- package/src/ShadowBoundary.tsx +0 -229
- package/src/ai-chatbot/AiChatbot.tsx +0 -2307
- package/src/ai-chatbot/attachmentStorage.ts +0 -238
- package/src/ai-chatbot/index.tsx +0 -1
- package/src/ai-feature/AiFeature.tsx +0 -2334
- package/src/ai-feature/AiFeatureBorder.tsx +0 -22
- package/src/ai-feature/ProofreadDiff.tsx +0 -118
- package/src/ai-feature/index.tsx +0 -2
- package/src/ai-feature/utils.tsx +0 -20
- package/src/doc-search/DocSearch.tsx +0 -1313
- package/src/doc-search/index.tsx +0 -1
- package/src/doc-search/initialFilters.ts +0 -10
- package/src/errorHandling.ts +0 -300
- package/src/i18n/ar.ts +0 -252
- package/src/i18n/de.ts +0 -255
- package/src/i18n/en.ts +0 -267
- package/src/i18n/es.ts +0 -255
- package/src/i18n/fr.ts +0 -256
- package/src/i18n/he.ts +0 -248
- package/src/i18n/hi.ts +0 -254
- package/src/i18n/hu.ts +0 -267
- package/src/i18n/id.ts +0 -254
- package/src/i18n/index.ts +0 -47
- package/src/i18n/it.ts +0 -257
- package/src/i18n/ja.ts +0 -254
- package/src/i18n/ko.ts +0 -252
- package/src/i18n/nb.ts +0 -252
- package/src/i18n/nl.ts +0 -253
- package/src/i18n/pl.ts +0 -256
- package/src/i18n/pt.ts +0 -252
- package/src/i18n/ru.ts +0 -252
- package/src/i18n/sv.ts +0 -251
- package/src/i18n/th.ts +0 -250
- package/src/i18n/tr.ts +0 -254
- package/src/i18n/ua.ts +0 -255
- package/src/i18n/zh.ts +0 -245
- package/src/index.tsx +0 -7
- package/src/poweredBy.tsx +0 -39
- package/src/styles/ai-kit-ui.css +0 -1006
- package/src/useAiRun.ts +0 -182
- package/src/withAiKitShell.tsx +0 -363
- package/tests/ai-disclosures.test.ts +0 -97
- package/tests/doc-search-initial-filters.test.ts +0 -20
- package/tests/error-handling.test.ts +0 -123
- package/tsconfig.json +0 -32
- package/tsconfig.node.json +0 -13
- package/tsconfig.types.json +0 -13
- package/tsup.config.ts +0 -22
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
const DB_NAME = "ai-kit-chatbot-attachments";
|
|
2
|
-
const STORE_NAME = "attachments";
|
|
3
|
-
const DB_VERSION = 1;
|
|
4
|
-
|
|
5
|
-
export type StoredAttachment = {
|
|
6
|
-
id: string;
|
|
7
|
-
name: string;
|
|
8
|
-
type: string;
|
|
9
|
-
size: number;
|
|
10
|
-
blob: Blob;
|
|
11
|
-
createdAt: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type AttachmentRecord = StoredAttachment;
|
|
15
|
-
|
|
16
|
-
let dbPromise: Promise<IDBDatabase | null> | null = null;
|
|
17
|
-
|
|
18
|
-
function isBrowserEnvironment(): boolean {
|
|
19
|
-
return (
|
|
20
|
-
typeof window !== "undefined" && typeof window.indexedDB !== "undefined"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function getDatabase(): Promise<IDBDatabase | null> {
|
|
25
|
-
if (!isBrowserEnvironment()) return null;
|
|
26
|
-
|
|
27
|
-
if (!dbPromise) {
|
|
28
|
-
dbPromise = new Promise((resolve) => {
|
|
29
|
-
try {
|
|
30
|
-
const request = window.indexedDB.open(DB_NAME, DB_VERSION);
|
|
31
|
-
|
|
32
|
-
request.onerror = () => resolve(null);
|
|
33
|
-
request.onblocked = () => resolve(null);
|
|
34
|
-
request.onupgradeneeded = () => {
|
|
35
|
-
const db = request.result;
|
|
36
|
-
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
37
|
-
db.createObjectStore(STORE_NAME, { keyPath: "id" });
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
request.onsuccess = () => resolve(request.result);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.warn("[AiChatbot] IndexedDB is not available", error);
|
|
43
|
-
resolve(null);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
const db = await dbPromise;
|
|
50
|
-
return db;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.warn("[AiChatbot] Failed to open attachment store", error);
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function runTransaction<T>(
|
|
58
|
-
mode: IDBTransactionMode,
|
|
59
|
-
handler: (store: IDBObjectStore) => T,
|
|
60
|
-
): Promise<T | null> {
|
|
61
|
-
const db = await getDatabase();
|
|
62
|
-
if (!db) return null;
|
|
63
|
-
|
|
64
|
-
return new Promise<T | null>((resolve, reject) => {
|
|
65
|
-
try {
|
|
66
|
-
const tx = db.transaction(STORE_NAME, mode);
|
|
67
|
-
const store = tx.objectStore(STORE_NAME);
|
|
68
|
-
const result = handler(store);
|
|
69
|
-
tx.oncomplete = () => resolve(result);
|
|
70
|
-
tx.onerror = () => reject(tx.error);
|
|
71
|
-
tx.onabort = () => reject(tx.error);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
reject(error);
|
|
74
|
-
}
|
|
75
|
-
}).catch((error) => {
|
|
76
|
-
console.warn("[AiChatbot] Attachment store transaction failed", error);
|
|
77
|
-
return null;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function persistAttachmentBlob(
|
|
82
|
-
id: string,
|
|
83
|
-
blob: Blob,
|
|
84
|
-
meta: { name: string; type: string; size: number },
|
|
85
|
-
): Promise<string | null> {
|
|
86
|
-
// Enforce storage quota before adding new attachment
|
|
87
|
-
await enforceStorageQuota();
|
|
88
|
-
|
|
89
|
-
const record: AttachmentRecord = {
|
|
90
|
-
id,
|
|
91
|
-
blob,
|
|
92
|
-
name: meta.name,
|
|
93
|
-
type: meta.type,
|
|
94
|
-
size: meta.size,
|
|
95
|
-
createdAt: Date.now(),
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const result = await runTransaction("readwrite", (store) => {
|
|
99
|
-
store.put(record);
|
|
100
|
-
return id;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export async function loadAttachmentBlob(
|
|
107
|
-
id: string,
|
|
108
|
-
): Promise<StoredAttachment | null> {
|
|
109
|
-
const db = await getDatabase();
|
|
110
|
-
if (!db) return null;
|
|
111
|
-
|
|
112
|
-
return new Promise<StoredAttachment | null>((resolve, reject) => {
|
|
113
|
-
try {
|
|
114
|
-
const tx = db.transaction(STORE_NAME, "readonly");
|
|
115
|
-
const request = tx.objectStore(STORE_NAME).get(id);
|
|
116
|
-
request.onsuccess = () => {
|
|
117
|
-
const value = request.result as AttachmentRecord | undefined;
|
|
118
|
-
resolve(value ?? null);
|
|
119
|
-
};
|
|
120
|
-
request.onerror = () => reject(request.error);
|
|
121
|
-
tx.onabort = () => reject(tx.error);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
reject(error);
|
|
124
|
-
}
|
|
125
|
-
}).catch((error) => {
|
|
126
|
-
console.warn("[AiChatbot] Failed to load attachment", error);
|
|
127
|
-
return null;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export async function deleteAttachmentBlob(id: string): Promise<void> {
|
|
132
|
-
await runTransaction("readwrite", (store) => {
|
|
133
|
-
store.delete(id);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export async function clearAllAttachments(): Promise<void> {
|
|
138
|
-
await runTransaction("readwrite", (store) => {
|
|
139
|
-
store.clear();
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function cleanupDanglingAttachments(
|
|
144
|
-
validIds: Set<string>,
|
|
145
|
-
): Promise<void> {
|
|
146
|
-
const db = await getDatabase();
|
|
147
|
-
if (!db) return;
|
|
148
|
-
|
|
149
|
-
await new Promise<void>((resolve, reject) => {
|
|
150
|
-
try {
|
|
151
|
-
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
152
|
-
const store = tx.objectStore(STORE_NAME);
|
|
153
|
-
const request = store.getAllKeys();
|
|
154
|
-
|
|
155
|
-
request.onsuccess = () => {
|
|
156
|
-
const keys = request.result as IDBValidKey[];
|
|
157
|
-
for (const key of keys) {
|
|
158
|
-
const keyString = String(key);
|
|
159
|
-
if (!validIds.has(keyString)) {
|
|
160
|
-
store.delete(key);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
request.onerror = () => reject(request.error);
|
|
166
|
-
tx.oncomplete = () => resolve();
|
|
167
|
-
tx.onerror = () => reject(tx.error);
|
|
168
|
-
tx.onabort = () => reject(tx.error);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
reject(error);
|
|
171
|
-
}
|
|
172
|
-
}).catch((error) => {
|
|
173
|
-
console.warn("[AiChatbot] Failed to cleanup attachments", error);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Storage quota management
|
|
178
|
-
const MAX_STORAGE_BYTES = 50 * 1024 * 1024; // 50 MB limit
|
|
179
|
-
|
|
180
|
-
export async function getAllAttachments(): Promise<StoredAttachment[]> {
|
|
181
|
-
const db = await getDatabase();
|
|
182
|
-
if (!db) return [];
|
|
183
|
-
|
|
184
|
-
return new Promise<StoredAttachment[]>((resolve, reject) => {
|
|
185
|
-
try {
|
|
186
|
-
const tx = db.transaction(STORE_NAME, "readonly");
|
|
187
|
-
const request = tx.objectStore(STORE_NAME).getAll();
|
|
188
|
-
|
|
189
|
-
request.onsuccess = () => {
|
|
190
|
-
const records = (request.result || []) as AttachmentRecord[];
|
|
191
|
-
resolve(records);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
request.onerror = () => reject(request.error);
|
|
195
|
-
tx.onerror = () => reject(tx.error);
|
|
196
|
-
tx.onabort = () => reject(tx.error);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
reject(error);
|
|
199
|
-
}
|
|
200
|
-
}).catch((error) => {
|
|
201
|
-
console.warn("[AiChatbot] Failed to get all attachments", error);
|
|
202
|
-
return [];
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export async function enforceStorageQuota(): Promise<void> {
|
|
207
|
-
const attachments = await getAllAttachments();
|
|
208
|
-
if (attachments.length === 0) return;
|
|
209
|
-
|
|
210
|
-
// Sort by creation time (oldest first)
|
|
211
|
-
const sorted = attachments.sort((a, b) => a.createdAt - b.createdAt);
|
|
212
|
-
|
|
213
|
-
// Calculate total size
|
|
214
|
-
let totalSize = sorted.reduce((sum, att) => sum + att.size, 0);
|
|
215
|
-
|
|
216
|
-
// Delete oldest attachments until under quota
|
|
217
|
-
const toDelete: string[] = [];
|
|
218
|
-
let i = 0;
|
|
219
|
-
while (totalSize > MAX_STORAGE_BYTES && i < sorted.length) {
|
|
220
|
-
const attachment = sorted[i];
|
|
221
|
-
if (attachment) {
|
|
222
|
-
toDelete.push(attachment.id);
|
|
223
|
-
totalSize -= attachment.size;
|
|
224
|
-
}
|
|
225
|
-
i++;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Delete the attachments
|
|
229
|
-
for (const id of toDelete) {
|
|
230
|
-
await deleteAttachmentBlob(id);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (toDelete.length > 0) {
|
|
234
|
-
console.log(
|
|
235
|
-
`[AiChatbot] Deleted ${toDelete.length} old attachment(s) to enforce storage quota`,
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}
|
package/src/ai-chatbot/index.tsx
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { AiChatbot, DEFAULT_CHATBOT_LABELS } from "./AiChatbot";
|