@smart-cloud/ai-kit-ui 1.5.14 → 1.5.16

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.
Files changed (55) hide show
  1. package/dist/LocaleDirectionProvider.d.ts +5 -0
  2. package/dist/ai-feature/AiFeature.d.ts +1 -0
  3. package/dist/index.cjs +9 -9
  4. package/dist/index.js +9 -9
  5. package/dist/locale.d.ts +13 -0
  6. package/package.json +35 -19
  7. package/eslint.config.js +0 -18
  8. package/src/ShadowBoundary.tsx +0 -229
  9. package/src/ai-chatbot/AiChatbot.tsx +0 -2325
  10. package/src/ai-chatbot/attachmentStorage.ts +0 -238
  11. package/src/ai-chatbot/index.tsx +0 -1
  12. package/src/ai-feature/AiFeature.tsx +0 -2334
  13. package/src/ai-feature/AiFeatureBorder.tsx +0 -22
  14. package/src/ai-feature/ProofreadDiff.tsx +0 -118
  15. package/src/ai-feature/index.tsx +0 -2
  16. package/src/ai-feature/utils.tsx +0 -20
  17. package/src/doc-search/DocSearch.tsx +0 -1313
  18. package/src/doc-search/index.tsx +0 -1
  19. package/src/doc-search/initialFilters.ts +0 -10
  20. package/src/errorHandling.ts +0 -305
  21. package/src/i18n/ar.ts +0 -254
  22. package/src/i18n/de.ts +0 -257
  23. package/src/i18n/en.ts +0 -269
  24. package/src/i18n/es.ts +0 -257
  25. package/src/i18n/fr.ts +0 -258
  26. package/src/i18n/he.ts +0 -250
  27. package/src/i18n/hi.ts +0 -256
  28. package/src/i18n/hu.ts +0 -269
  29. package/src/i18n/id.ts +0 -256
  30. package/src/i18n/index.ts +0 -47
  31. package/src/i18n/it.ts +0 -259
  32. package/src/i18n/ja.ts +0 -256
  33. package/src/i18n/ko.ts +0 -254
  34. package/src/i18n/nb.ts +0 -254
  35. package/src/i18n/nl.ts +0 -255
  36. package/src/i18n/pl.ts +0 -258
  37. package/src/i18n/pt.ts +0 -254
  38. package/src/i18n/ru.ts +0 -254
  39. package/src/i18n/sv.ts +0 -253
  40. package/src/i18n/th.ts +0 -252
  41. package/src/i18n/tr.ts +0 -256
  42. package/src/i18n/ua.ts +0 -257
  43. package/src/i18n/zh.ts +0 -247
  44. package/src/index.tsx +0 -7
  45. package/src/poweredBy.tsx +0 -39
  46. package/src/styles/ai-kit-ui.css +0 -1006
  47. package/src/useAiRun.ts +0 -182
  48. package/src/withAiKitShell.tsx +0 -363
  49. package/tests/ai-disclosures.test.ts +0 -126
  50. package/tests/doc-search-initial-filters.test.ts +0 -20
  51. package/tests/error-handling.test.ts +0 -140
  52. package/tsconfig.json +0 -32
  53. package/tsconfig.node.json +0 -13
  54. package/tsconfig.types.json +0 -13
  55. 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
- }
@@ -1 +0,0 @@
1
- export { AiChatbot, DEFAULT_CHATBOT_LABELS } from "./AiChatbot";