strapi-content-embeddings 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +276 -0
  2. package/dist/_chunks/App-7LMg3lrX.mjs +1004 -0
  3. package/dist/_chunks/App-wC2qv6kC.js +1008 -0
  4. package/dist/_chunks/en-B4KWt_jN.js +4 -0
  5. package/dist/_chunks/en-Byx4XI2L.mjs +4 -0
  6. package/dist/_chunks/index-Cz9cEuvw.mjs +411 -0
  7. package/dist/_chunks/index-o-tbBpJG.js +413 -0
  8. package/dist/admin/index.js +4 -0
  9. package/dist/admin/index.mjs +5 -0
  10. package/dist/admin/src/components/Initializer.d.ts +5 -0
  11. package/dist/admin/src/components/PluginIcon.d.ts +2 -0
  12. package/dist/admin/src/components/custom/BackLink.d.ts +5 -0
  13. package/dist/admin/src/components/custom/ChatModal.d.ts +1 -0
  14. package/dist/admin/src/components/custom/EmbeddingsModal.d.ts +1 -0
  15. package/dist/admin/src/components/custom/EmbeddingsTable.d.ts +12 -0
  16. package/dist/admin/src/components/custom/EmbeddingsWidget.d.ts +1 -0
  17. package/dist/admin/src/components/custom/EmptyState.d.ts +1 -0
  18. package/dist/admin/src/components/custom/Illo.d.ts +1 -0
  19. package/dist/admin/src/components/custom/Markdown.d.ts +5 -0
  20. package/dist/admin/src/components/custom/MarkdownEditor.d.ts +9 -0
  21. package/dist/admin/src/components/custom/RobotIcon.d.ts +6 -0
  22. package/dist/admin/src/components/forms/CreateEmbeddingForm.d.ts +15 -0
  23. package/dist/admin/src/index.d.ts +12 -0
  24. package/dist/admin/src/pages/App.d.ts +2 -0
  25. package/dist/admin/src/pages/CreateEmbeddings.d.ts +1 -0
  26. package/dist/admin/src/pages/EmbeddingDetails.d.ts +1 -0
  27. package/dist/admin/src/pages/HomePage.d.ts +1 -0
  28. package/dist/admin/src/pluginId.d.ts +1 -0
  29. package/dist/admin/src/utils/api.d.ts +33 -0
  30. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  31. package/dist/server/index.js +1359 -0
  32. package/dist/server/index.mjs +1360 -0
  33. package/dist/server/src/bootstrap.d.ts +5 -0
  34. package/dist/server/src/config/index.d.ts +26 -0
  35. package/dist/server/src/content-types/embedding/index.d.ts +54 -0
  36. package/dist/server/src/content-types/index.d.ts +56 -0
  37. package/dist/server/src/controllers/controller.d.ts +12 -0
  38. package/dist/server/src/controllers/index.d.ts +18 -0
  39. package/dist/server/src/controllers/mcp.d.ts +18 -0
  40. package/dist/server/src/destroy.d.ts +5 -0
  41. package/dist/server/src/index.d.ts +154 -0
  42. package/dist/server/src/mcp/index.d.ts +6 -0
  43. package/dist/server/src/mcp/schemas/index.d.ts +65 -0
  44. package/dist/server/src/mcp/server.d.ts +8 -0
  45. package/dist/server/src/mcp/tools/create-embedding.d.ts +38 -0
  46. package/dist/server/src/mcp/tools/get-embedding.d.ts +34 -0
  47. package/dist/server/src/mcp/tools/index.d.ts +114 -0
  48. package/dist/server/src/mcp/tools/list-embeddings.d.ts +40 -0
  49. package/dist/server/src/mcp/tools/rag-query.d.ts +34 -0
  50. package/dist/server/src/mcp/tools/semantic-search.d.ts +34 -0
  51. package/dist/server/src/middlewares/index.d.ts +2 -0
  52. package/dist/server/src/plugin-manager.d.ts +45 -0
  53. package/dist/server/src/policies/index.d.ts +2 -0
  54. package/dist/server/src/register.d.ts +5 -0
  55. package/dist/server/src/routes/admin.d.ts +14 -0
  56. package/dist/server/src/routes/content-api.d.ts +15 -0
  57. package/dist/server/src/routes/index.d.ts +36 -0
  58. package/dist/server/src/services/embeddings.d.ts +45 -0
  59. package/dist/server/src/services/index.d.ts +26 -0
  60. package/dist/style.css +95 -0
  61. package/package.json +104 -0
@@ -0,0 +1,1008 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const admin = require("@strapi/strapi/admin");
5
+ const reactRouterDom = require("react-router-dom");
6
+ const react = require("react");
7
+ const designSystem = require("@strapi/design-system");
8
+ const icons = require("@strapi/icons");
9
+ const reactIntl = require("react-intl");
10
+ const qs = require("qs");
11
+ const index = require("./index-o-tbBpJG.js");
12
+ const styled = require("styled-components");
13
+ const ReactMarkdown = require("react-markdown");
14
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
15
+ const qs__default = /* @__PURE__ */ _interopDefault(qs);
16
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
17
+ const ReactMarkdown__default = /* @__PURE__ */ _interopDefault(ReactMarkdown);
18
+ const Illo = () => /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "159", height: "88", viewBox: "0 0 159 88", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
19
+ /* @__PURE__ */ jsxRuntime.jsx(
20
+ "path",
21
+ {
22
+ fillRule: "evenodd",
23
+ clipRule: "evenodd",
24
+ d: "M134.933 17.417C137.768 17.417 140.067 19.7153 140.067 22.5503C140.067 25.3854 137.768 27.6837 134.933 27.6837H105.6C108.435 27.6837 110.733 29.9819 110.733 32.817C110.733 35.6521 108.435 37.9503 105.6 37.9503H121.733C124.568 37.9503 126.867 40.2486 126.867 43.0837C126.867 45.9187 124.568 48.217 121.733 48.217H114.272C110.698 48.217 107.8 50.5153 107.8 53.3503C107.8 55.2404 109.267 56.9515 112.2 58.4837C115.035 58.4837 117.333 60.7819 117.333 63.617C117.333 66.4521 115.035 68.7503 112.2 68.7503H51.3333C48.4982 68.7503 46.2 66.4521 46.2 63.617C46.2 60.7819 48.4982 58.4837 51.3333 58.4837H22.7333C19.8982 58.4837 17.6 56.1854 17.6 53.3503C17.6 50.5153 19.8982 48.217 22.7333 48.217H52.0666C54.9017 48.217 57.2 45.9187 57.2 43.0837C57.2 40.2486 54.9017 37.9503 52.0666 37.9503H33.7333C30.8982 37.9503 28.6 35.6521 28.6 32.817C28.6 29.9819 30.8982 27.6837 33.7333 27.6837H63.0666C60.2316 27.6837 57.9333 25.3854 57.9333 22.5503C57.9333 19.7153 60.2316 17.417 63.0666 17.417H134.933ZM134.933 37.9503C137.768 37.9503 140.067 40.2486 140.067 43.0837C140.067 45.9187 137.768 48.217 134.933 48.217C132.098 48.217 129.8 45.9187 129.8 43.0837C129.8 40.2486 132.098 37.9503 134.933 37.9503Z",
25
+ fill: "#DBDBFA"
26
+ }
27
+ ),
28
+ /* @__PURE__ */ jsxRuntime.jsx(
29
+ "path",
30
+ {
31
+ fillRule: "evenodd",
32
+ clipRule: "evenodd",
33
+ d: "M95.826 16.6834L102.647 66.4348L103.26 71.4261C103.458 73.034 102.314 74.4976 100.706 74.695L57.7621 79.9679C56.1542 80.1653 54.6906 79.0219 54.4932 77.4139L47.8816 23.5671C47.7829 22.7631 48.3546 22.0313 49.1586 21.9326C49.1637 21.932 49.1688 21.9313 49.1739 21.9307L52.7367 21.5311L95.826 16.6834ZM55.6176 21.208L58.9814 20.8306Z",
34
+ fill: "white"
35
+ }
36
+ ),
37
+ /* @__PURE__ */ jsxRuntime.jsx(
38
+ "path",
39
+ {
40
+ d: "M55.6176 21.208L58.9814 20.8306M95.826 16.6834L102.647 66.4348L103.26 71.4261C103.458 73.034 102.314 74.4976 100.706 74.695L57.7621 79.9679C56.1542 80.1653 54.6906 79.0219 54.4932 77.4139L47.8816 23.5671C47.7829 22.7631 48.3546 22.0313 49.1586 21.9326C49.1637 21.932 49.1688 21.9313 49.1739 21.9307L52.7367 21.5311L95.826 16.6834Z",
41
+ stroke: "#7E7BF6",
42
+ strokeWidth: "2.5"
43
+ }
44
+ ),
45
+ /* @__PURE__ */ jsxRuntime.jsx(
46
+ "path",
47
+ {
48
+ fillRule: "evenodd",
49
+ clipRule: "evenodd",
50
+ d: "M93.9695 19.8144L100.144 64.9025L100.699 69.4258C100.878 70.8831 99.8559 72.2077 98.416 72.3845L59.9585 77.1065C58.5185 77.2833 57.2062 76.2453 57.0272 74.7881L51.0506 26.112C50.9519 25.308 51.5236 24.5762 52.3276 24.4775L57.0851 23.8934",
51
+ fill: "#F0F0FF"
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsxRuntime.jsx(
55
+ "path",
56
+ {
57
+ fillRule: "evenodd",
58
+ clipRule: "evenodd",
59
+ d: "M97.701 7.33301H64.2927C63.7358 7.33301 63.2316 7.55873 62.8667 7.92368C62.5017 8.28862 62.276 8.79279 62.276 9.34967V65.083C62.276 65.6399 62.5017 66.1441 62.8667 66.509C63.2316 66.874 63.7358 67.0997 64.2927 67.0997H107.559C108.116 67.0997 108.62 66.874 108.985 66.509C109.35 66.1441 109.576 65.6399 109.576 65.083V19.202C109.576 18.6669 109.363 18.1537 108.985 17.7755L99.1265 7.92324C98.7484 7.54531 98.2356 7.33301 97.701 7.33301Z",
60
+ fill: "white",
61
+ stroke: "#7F7CFA",
62
+ strokeWidth: "2.5"
63
+ }
64
+ ),
65
+ /* @__PURE__ */ jsxRuntime.jsx(
66
+ "path",
67
+ {
68
+ d: "M98.026 8.17871V16.6833C98.026 17.8983 99.011 18.8833 100.226 18.8833H106.044",
69
+ stroke: "#807EFA",
70
+ strokeWidth: "2.5",
71
+ strokeLinecap: "round",
72
+ strokeLinejoin: "round"
73
+ }
74
+ ),
75
+ /* @__PURE__ */ jsxRuntime.jsx(
76
+ "path",
77
+ {
78
+ d: "M70.1594 56.2838H89.2261M70.1594 18.8838H89.2261H70.1594ZM70.1594 27.6838H101.693H70.1594ZM70.1594 37.2171H101.693H70.1594ZM70.1594 46.7505H101.693H70.1594Z",
79
+ stroke: "#817FFA",
80
+ strokeWidth: "2.5",
81
+ strokeLinecap: "round",
82
+ strokeLinejoin: "round"
83
+ }
84
+ )
85
+ ] });
86
+ function EmptyState() {
87
+ return /* @__PURE__ */ jsxRuntime.jsx(
88
+ designSystem.EmptyStateLayout,
89
+ {
90
+ icon: /* @__PURE__ */ jsxRuntime.jsx(Illo, {}),
91
+ content: "Let's create our first embedding...",
92
+ action: /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Link, { to: `/plugins/${index.PLUGIN_ID}/embeddings`, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), children: "Create new embedding" }) })
93
+ }
94
+ );
95
+ }
96
+ const StyledTr = styled__default.default(designSystem.Tr)`
97
+ cursor: pointer;
98
+ &:hover {
99
+ background-color: #f0f0ff;
100
+ }
101
+ `;
102
+ function EmbeddingsTable({ data }) {
103
+ const navigate = reactRouterDom.useNavigate();
104
+ const handleRowClick = (documentId) => {
105
+ navigate(`/plugins/${index.PLUGIN_ID}/embeddings/${documentId}`);
106
+ };
107
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, background: "neutral100", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Table, { colCount: 5, rowCount: data.length + 1, children: [
108
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Thead, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tr, { children: [
109
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "ID" }) }),
110
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Title" }) }),
111
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Content" }) }),
112
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Embed ID" }) }),
113
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: "Actions" }) })
114
+ ] }) }),
115
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: data?.map((entry) => /* @__PURE__ */ jsxRuntime.jsxs(
116
+ StyledTr,
117
+ {
118
+ onClick: () => handleRowClick(entry.documentId),
119
+ children: [
120
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { textColor: "neutral800", children: [
121
+ entry.documentId.slice(0, 8),
122
+ "..."
123
+ ] }) }),
124
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { textColor: "neutral800", children: [
125
+ entry.title?.slice(0, 30),
126
+ entry.title?.length > 30 ? "..." : ""
127
+ ] }) }),
128
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { textColor: "neutral800", children: [
129
+ entry.content?.slice(0, 30),
130
+ entry.content && entry.content.length > 30 ? "..." : ""
131
+ ] }) }),
132
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { textColor: "neutral800", children: [
133
+ entry.embeddingId?.slice(0, 8),
134
+ entry.embeddingId && entry.embeddingId.length > 8 ? "..." : ""
135
+ ] }) }),
136
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(
137
+ designSystem.IconButton,
138
+ {
139
+ withTooltip: false,
140
+ label: "View details",
141
+ onClick: (e) => {
142
+ e.stopPropagation();
143
+ handleRowClick(entry.documentId);
144
+ },
145
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowRight, {})
146
+ }
147
+ ) }) })
148
+ ]
149
+ },
150
+ entry.documentId
151
+ )) })
152
+ ] }) });
153
+ }
154
+ const MarkdownWrapper = styled__default.default.div`
155
+ /* Headers */
156
+ h1 {
157
+ font-size: 2.25rem;
158
+ font-weight: 700;
159
+ margin-bottom: 1rem;
160
+ color: #272728;
161
+ }
162
+
163
+ h2 {
164
+ font-size: 1.75rem;
165
+ font-weight: 700;
166
+ margin-bottom: 1rem;
167
+ color: #272728;
168
+ }
169
+
170
+ h3 {
171
+ font-size: 1.5rem;
172
+ font-weight: 700;
173
+ margin-bottom: 1rem;
174
+ color: #272728;
175
+ }
176
+
177
+ h4 {
178
+ font-size: 1.25rem;
179
+ font-weight: 700;
180
+ margin-bottom: 1rem;
181
+ color: #272728;
182
+ }
183
+
184
+ h5 {
185
+ font-size: 1.125rem;
186
+ font-weight: 700;
187
+ margin-bottom: 1rem;
188
+ color: #272728;
189
+ }
190
+
191
+ h6 {
192
+ font-size: 1rem;
193
+ font-weight: 700;
194
+ margin-bottom: 1rem;
195
+ color: #9d4edd;
196
+ }
197
+
198
+ /* Horizontal rules */
199
+ hr {
200
+ border-color: #d1d5db;
201
+ margin-top: 2rem;
202
+ margin-bottom: 2rem;
203
+ }
204
+
205
+ a {
206
+ color: #4945ff;
207
+ text-decoration: underline;
208
+ }
209
+
210
+ /* Paragraphs */
211
+ p {
212
+ margin-bottom: 1rem;
213
+ line-height: 1.5rem;
214
+ color: #39393a;
215
+ }
216
+
217
+ /* Emphasis */
218
+ strong {
219
+ font-weight: 700;
220
+ }
221
+
222
+ em {
223
+ font-style: italic;
224
+ }
225
+
226
+ del {
227
+ text-decoration: line-through;
228
+ }
229
+
230
+ /* Blockquotes */
231
+ blockquote {
232
+ border-left-width: 1px;
233
+ border-color: #9ca3af;
234
+ padding-left: 1rem;
235
+ padding-top: 0.5rem;
236
+ padding-bottom: 0.5rem;
237
+ margin-bottom: 1rem;
238
+ }
239
+
240
+ /* Lists */
241
+ ul {
242
+ list-style-type: disc;
243
+ padding-left: 1rem;
244
+ margin-bottom: 1rem;
245
+ }
246
+
247
+ ol {
248
+ list-style-type: decimal;
249
+ padding-left: 1rem;
250
+ margin-bottom: 1rem;
251
+ }
252
+
253
+ li {
254
+ margin-bottom: 0.5rem;
255
+ }
256
+
257
+ li > ul {
258
+ list-style-type: disc;
259
+ padding-left: 1rem;
260
+ margin-bottom: 0.5rem;
261
+ }
262
+
263
+ li > ol {
264
+ list-style-type: decimal;
265
+ padding-left: 1rem;
266
+ margin-bottom: 0.5rem;
267
+ }
268
+
269
+ /* Code blocks */
270
+ pre {
271
+ font-family: monospace;
272
+ background-color: #1f2937;
273
+ color: #f9fafb;
274
+ border-radius: 0.375rem;
275
+ padding: 1rem;
276
+ margin-top: 1.5rem;
277
+ margin-bottom: 1.5rem;
278
+ line-height: 1.5rem;
279
+ overflow: auto;
280
+ }
281
+
282
+ code {
283
+ font-family: monospace;
284
+ background-color: #1f2937;
285
+ color: #f9fafb;
286
+ border-radius: 0.375rem;
287
+ padding-left: 0.5rem;
288
+ padding-right: 0.5rem;
289
+ padding-top: 0.25rem;
290
+ padding-bottom: 0.25rem;
291
+ }
292
+
293
+ /* Tables */
294
+ table {
295
+ width: 100%;
296
+ border-collapse: collapse;
297
+ border-color: #d1d5db;
298
+ margin-top: 1.5rem;
299
+ margin-bottom: 1.5rem;
300
+ }
301
+
302
+ th {
303
+ background-color: #1f2937;
304
+ text-align: left;
305
+ padding-top: 0.5rem;
306
+ padding-bottom: 0.5rem;
307
+ padding-left: 1rem;
308
+ padding-right: 1rem;
309
+ font-weight: 600;
310
+ border-bottom-width: 1px;
311
+ border-color: #d1d5db;
312
+ }
313
+
314
+ td {
315
+ padding-top: 0.5rem;
316
+ padding-bottom: 0.5rem;
317
+ padding-left: 1rem;
318
+ padding-right: 1rem;
319
+ border-bottom-width: 1px;
320
+ border-color: #d1d5db;
321
+ }
322
+
323
+ /* Images */
324
+ img {
325
+ width: 100%;
326
+ object-fit: cover;
327
+ border-radius: 0.75rem;
328
+ margin-top: 1.5rem;
329
+ margin-bottom: 1.5rem;
330
+ }
331
+ `;
332
+ function Markdown({ children }) {
333
+ return /* @__PURE__ */ jsxRuntime.jsx(MarkdownWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(ReactMarkdown__default.default, { children }) });
334
+ }
335
+ const StyledButton = styled__default.default(designSystem.Button)`
336
+ position: fixed;
337
+ bottom: 1.5rem;
338
+ right: 1.5rem;
339
+ height: 3.5rem;
340
+ width: 3.5rem;
341
+ border-radius: 50%;
342
+ display: flex;
343
+ align-items: center;
344
+ justify-content: center;
345
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
346
+ 0 2px 4px -1px rgba(0, 0, 0, 0.06);
347
+ z-index: 100;
348
+
349
+ svg {
350
+ height: 1.75rem;
351
+ width: 1.75rem;
352
+ }
353
+ `;
354
+ const ResponseContainer = styled__default.default.div`
355
+ border: solid 1px #e3e9f3;
356
+ border-radius: 4px;
357
+ padding: 1rem;
358
+ color: #32324d;
359
+ font-weight: 400;
360
+ font-size: 0.875rem;
361
+ display: block;
362
+ width: 100%;
363
+ max-height: 400px;
364
+ background: inherit;
365
+ overflow-y: auto;
366
+ scroll-behavior: smooth;
367
+ `;
368
+ function AccordionDetails({ title, content, children }) {
369
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, background: "primary100", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Root, { size: "S", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: "acc-1", children: [
370
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { children: title }) }),
371
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 3, children: [
372
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: content }),
373
+ children && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, children })
374
+ ] }) })
375
+ ] }) }) });
376
+ }
377
+ function ShowResponse({ data, onNavigate }) {
378
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: data.map((item, index2) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginBottom: 4, children: [
379
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: item.text }) }),
380
+ item.sourceDocuments?.length > 0 && item.sourceDocuments.map((doc, docIndex) => /* @__PURE__ */ jsxRuntime.jsx(
381
+ AccordionDetails,
382
+ {
383
+ title: "Original Source Document",
384
+ content: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: doc.pageContent }),
385
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
386
+ designSystem.Link,
387
+ {
388
+ onClick: () => onNavigate(doc.metadata.id),
389
+ style: { cursor: "pointer" },
390
+ children: [
391
+ "View Source for ",
392
+ doc.metadata.title
393
+ ]
394
+ }
395
+ )
396
+ },
397
+ docIndex
398
+ ))
399
+ ] }, index2)) });
400
+ }
401
+ function ChatModal() {
402
+ const { get } = admin.useFetchClient();
403
+ const containerRef = react.useRef(null);
404
+ const navigate = reactRouterDom.useNavigate();
405
+ const [isVisible, setIsVisible] = react.useState(false);
406
+ const [isLoading, setIsLoading] = react.useState(false);
407
+ const [inputValue, setInputValue] = react.useState("");
408
+ const [data, setData] = react.useState([]);
409
+ react.useEffect(() => {
410
+ if (containerRef.current) {
411
+ containerRef.current.scrollTop = containerRef.current.scrollHeight;
412
+ }
413
+ }, [data]);
414
+ function handleNavigate(id) {
415
+ setIsVisible(false);
416
+ navigate(`/plugins/${index.PLUGIN_ID}/embeddings/${id}`);
417
+ }
418
+ async function handleQueryEmbeddings(e) {
419
+ e.preventDefault();
420
+ if (!inputValue.trim() || isLoading) return;
421
+ setIsLoading(true);
422
+ try {
423
+ const response = await get(
424
+ `/${index.PLUGIN_ID}/embeddings/embeddings-query?${qs__default.default.stringify({
425
+ query: inputValue
426
+ })}`
427
+ );
428
+ if (response.data && !response.data.error) {
429
+ setData((prev) => [...prev, response.data]);
430
+ }
431
+ setInputValue("");
432
+ } catch (error) {
433
+ console.error("Query failed:", error);
434
+ } finally {
435
+ setIsLoading(false);
436
+ }
437
+ }
438
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
439
+ /* @__PURE__ */ jsxRuntime.jsx(StyledButton, { onClick: () => setIsVisible(true), "aria-label": "Open chat", children: /* @__PURE__ */ jsxRuntime.jsx(index.RobotIcon, { height: 28, width: 28 }) }),
440
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isVisible, onOpenChange: setIsVisible, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
441
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: "Chat With Your Data" }) }),
442
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Body, { children: [
443
+ data.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsx(ResponseContainer, { ref: containerRef, children: /* @__PURE__ */ jsxRuntime.jsx(ShowResponse, { data, onNavigate: handleNavigate }) }) }),
444
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: handleQueryEmbeddings, children: /* @__PURE__ */ jsxRuntime.jsx(
445
+ designSystem.TextInput,
446
+ {
447
+ placeholder: "Enter your question",
448
+ type: "text",
449
+ "aria-label": "Question",
450
+ name: "question",
451
+ onChange: (e) => setInputValue(e.target.value),
452
+ value: inputValue
453
+ }
454
+ ) }) })
455
+ ] }),
456
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
457
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: "Cancel" }) }),
458
+ /* @__PURE__ */ jsxRuntime.jsx(
459
+ designSystem.Button,
460
+ {
461
+ onClick: handleQueryEmbeddings,
462
+ disabled: !inputValue.trim() || isLoading,
463
+ loading: isLoading,
464
+ children: isLoading ? "Sending..." : "Send"
465
+ }
466
+ )
467
+ ] })
468
+ ] }) })
469
+ ] });
470
+ }
471
+ function debounce(func, wait) {
472
+ let timeout;
473
+ return (...args) => {
474
+ clearTimeout(timeout);
475
+ timeout = setTimeout(() => func(...args), wait);
476
+ };
477
+ }
478
+ function HomePage() {
479
+ const { formatMessage } = reactIntl.useIntl();
480
+ const { get } = admin.useFetchClient();
481
+ const navigate = reactRouterDom.useNavigate();
482
+ const [embeddings, setEmbeddings] = react.useState(null);
483
+ const [search, setSearch] = react.useState("");
484
+ const [isLoading, setIsLoading] = react.useState(true);
485
+ const buildQuery = (searchTerm) => qs__default.default.stringify({
486
+ filters: searchTerm ? {
487
+ $or: [
488
+ { title: { $containsi: searchTerm } },
489
+ { content: { $containsi: searchTerm } }
490
+ ]
491
+ } : void 0
492
+ });
493
+ const fetchData = react.useCallback(
494
+ async (searchTerm) => {
495
+ setIsLoading(true);
496
+ try {
497
+ const response = await get(
498
+ `/${index.PLUGIN_ID}/embeddings/find?${buildQuery(searchTerm)}`
499
+ );
500
+ setEmbeddings(response.data);
501
+ } catch (error) {
502
+ console.error("Failed to fetch embeddings:", error);
503
+ setEmbeddings({ data: [], count: 0, totalCount: 0 });
504
+ } finally {
505
+ setIsLoading(false);
506
+ }
507
+ },
508
+ [get]
509
+ );
510
+ const debouncedFetch = react.useMemo(
511
+ () => debounce(fetchData, 500),
512
+ [fetchData]
513
+ );
514
+ react.useEffect(() => {
515
+ debouncedFetch(search);
516
+ }, [search, debouncedFetch]);
517
+ const handleSearchChange = (e) => {
518
+ setSearch(e.target.value);
519
+ };
520
+ const handleCreateNew = () => {
521
+ navigate(`/plugins/${index.PLUGIN_ID}/embeddings`);
522
+ };
523
+ if (isLoading && !embeddings) {
524
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
525
+ /* @__PURE__ */ jsxRuntime.jsx(
526
+ admin.Layouts.Header,
527
+ {
528
+ title: formatMessage({
529
+ id: "HomePage.header.title",
530
+ defaultMessage: "Content Embeddings"
531
+ }),
532
+ subtitle: formatMessage({
533
+ id: "HomePage.header.subtitle",
534
+ defaultMessage: "Manage your content embeddings"
535
+ })
536
+ }
537
+ ),
538
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading..." }) }) }),
539
+ /* @__PURE__ */ jsxRuntime.jsx(ChatModal, {})
540
+ ] });
541
+ }
542
+ if (embeddings?.totalCount === 0 && !search) {
543
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
544
+ /* @__PURE__ */ jsxRuntime.jsx(
545
+ admin.Layouts.Header,
546
+ {
547
+ title: formatMessage({
548
+ id: "HomePage.header.title",
549
+ defaultMessage: "Content Embeddings"
550
+ }),
551
+ subtitle: formatMessage({
552
+ id: "HomePage.header.subtitle",
553
+ defaultMessage: "Manage your content embeddings"
554
+ })
555
+ }
556
+ ),
557
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(EmptyState, {}) }),
558
+ /* @__PURE__ */ jsxRuntime.jsx(ChatModal, {})
559
+ ] });
560
+ }
561
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
562
+ /* @__PURE__ */ jsxRuntime.jsx(
563
+ admin.Layouts.Header,
564
+ {
565
+ title: formatMessage({
566
+ id: "HomePage.header.title",
567
+ defaultMessage: "Content Embeddings"
568
+ }),
569
+ subtitle: `${embeddings?.count || 0} results found`,
570
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), onClick: handleCreateNew, children: "Create new embedding" })
571
+ }
572
+ ),
573
+ /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
574
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
575
+ designSystem.TextInput,
576
+ {
577
+ placeholder: "Search embeddings...",
578
+ name: "search",
579
+ value: search,
580
+ onChange: handleSearchChange,
581
+ startAction: /* @__PURE__ */ jsxRuntime.jsx(icons.Search, {})
582
+ }
583
+ ) }),
584
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading..." }) }) : embeddings?.data && embeddings.data.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(EmbeddingsTable, { data: embeddings.data }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 8, textAlign: "center", children: [
585
+ 'No embeddings found matching "',
586
+ search,
587
+ '"'
588
+ ] })
589
+ ] }),
590
+ /* @__PURE__ */ jsxRuntime.jsx(ChatModal, {})
591
+ ] });
592
+ }
593
+ function CreateEmbeddingsForm({
594
+ onSubmit,
595
+ isLoading,
596
+ input,
597
+ setInput,
598
+ markdown,
599
+ handleMarkdownChange,
600
+ metadata,
601
+ setMetadata,
602
+ height,
603
+ children
604
+ }) {
605
+ return /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { disabled: isLoading, style: { border: "none", padding: 0, margin: 0 }, children: [
606
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
607
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Title" }),
608
+ /* @__PURE__ */ jsxRuntime.jsx(
609
+ designSystem.TextInput,
610
+ {
611
+ placeholder: "Enter a title for your embedding",
612
+ name: "input",
613
+ onChange: (e) => setInput(e.target.value),
614
+ value: input
615
+ }
616
+ )
617
+ ] }) }),
618
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
619
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Content" }),
620
+ /* @__PURE__ */ jsxRuntime.jsx(
621
+ index.MarkdownEditor,
622
+ {
623
+ content: markdown,
624
+ onChange: handleMarkdownChange,
625
+ height
626
+ }
627
+ )
628
+ ] }) }),
629
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
630
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Metadata (JSON)" }),
631
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "Optional JSON metadata for this embedding" }),
632
+ /* @__PURE__ */ jsxRuntime.jsx(
633
+ designSystem.Textarea,
634
+ {
635
+ placeholder: '{"category": "docs", "source": "manual"}',
636
+ name: "metadata",
637
+ onChange: (e) => setMetadata(e.target.value),
638
+ value: metadata
639
+ }
640
+ )
641
+ ] }) }),
642
+ children
643
+ ] }) });
644
+ }
645
+ function BackLink({ to }) {
646
+ if (to) {
647
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { tag: reactRouterDom.NavLink, to, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, {}), children: "Go back" });
648
+ }
649
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { tag: reactRouterDom.NavLink, to: "..", relative: "path", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, {}), children: "Go back" });
650
+ }
651
+ const MAX_CONTENT_LENGTH = 4e3;
652
+ function CreateEmbeddings() {
653
+ const { formatMessage } = reactIntl.useIntl();
654
+ const navigate = reactRouterDom.useNavigate();
655
+ const { post } = admin.useFetchClient();
656
+ const [isLoading, setIsLoading] = react.useState(false);
657
+ const [title, setTitle] = react.useState("");
658
+ const [content, setContent] = react.useState("");
659
+ const [metadata, setMetadata] = react.useState("");
660
+ const [error, setError] = react.useState(null);
661
+ const isValid = title.trim() && content.trim() && content.length <= MAX_CONTENT_LENGTH;
662
+ const contentLength = content.length;
663
+ function parseMetadata() {
664
+ if (!metadata.trim()) return null;
665
+ try {
666
+ return JSON.parse(metadata);
667
+ } catch {
668
+ return null;
669
+ }
670
+ }
671
+ async function handleSubmit(e) {
672
+ e.preventDefault();
673
+ e.stopPropagation();
674
+ if (!isValid) {
675
+ setError("Please provide a title and content (max 4000 characters)");
676
+ return;
677
+ }
678
+ if (metadata.trim()) {
679
+ const parsedMetadata = parseMetadata();
680
+ if (parsedMetadata === null) {
681
+ setError("Invalid JSON in metadata field");
682
+ return;
683
+ }
684
+ }
685
+ setIsLoading(true);
686
+ setError(null);
687
+ try {
688
+ await post(`/${index.PLUGIN_ID}/embeddings/create-embedding`, {
689
+ data: {
690
+ title: title.trim(),
691
+ content: content.trim(),
692
+ metadata: parseMetadata()
693
+ }
694
+ });
695
+ navigate(`/plugins/${index.PLUGIN_ID}`);
696
+ } catch (err) {
697
+ console.error("Failed to create embedding:", err);
698
+ setError(err.message || "Failed to create embedding. Please try again.");
699
+ setIsLoading(false);
700
+ }
701
+ }
702
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
703
+ /* @__PURE__ */ jsxRuntime.jsx(
704
+ admin.Layouts.Header,
705
+ {
706
+ title: formatMessage({
707
+ id: "CreateEmbeddings.header.title",
708
+ defaultMessage: "Create Embedding"
709
+ }),
710
+ subtitle: formatMessage(
711
+ {
712
+ id: "CreateEmbeddings.header.subtitle",
713
+ defaultMessage: "Content: {length}/{max} characters"
714
+ },
715
+ { length: contentLength, max: MAX_CONTENT_LENGTH }
716
+ ),
717
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(
718
+ designSystem.Button,
719
+ {
720
+ type: "submit",
721
+ disabled: isLoading || !isValid,
722
+ loading: isLoading,
723
+ onClick: (e) => {
724
+ e.preventDefault();
725
+ const form = document.querySelector("form");
726
+ if (form) {
727
+ form.dispatchEvent(
728
+ new Event("submit", { cancelable: true, bubbles: true })
729
+ );
730
+ }
731
+ },
732
+ children: isLoading ? "Creating..." : "Create Embedding"
733
+ }
734
+ ),
735
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
736
+ }
737
+ ),
738
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
739
+ error && /* @__PURE__ */ jsxRuntime.jsx(
740
+ designSystem.Box,
741
+ {
742
+ padding: 4,
743
+ marginBottom: 4,
744
+ background: "danger100",
745
+ borderColor: "danger600",
746
+ hasRadius: true,
747
+ children: error
748
+ }
749
+ ),
750
+ /* @__PURE__ */ jsxRuntime.jsx(
751
+ CreateEmbeddingsForm,
752
+ {
753
+ onSubmit: handleSubmit,
754
+ isLoading,
755
+ input: title,
756
+ setInput: setTitle,
757
+ markdown: content,
758
+ handleMarkdownChange: setContent,
759
+ metadata,
760
+ setMetadata
761
+ }
762
+ )
763
+ ] }) })
764
+ ] });
765
+ }
766
+ const StyledTypography = styled__default.default(designSystem.Typography)`
767
+ display: block;
768
+ margin-bottom: 1rem;
769
+ `;
770
+ function Metadata({ data }) {
771
+ const metadata = {
772
+ id: data.documentId,
773
+ title: data.title,
774
+ collectionType: data.collectionType || "standalone",
775
+ fieldName: data.fieldName || "content",
776
+ embeddingId: data.embeddingId || "N/A",
777
+ vectorDimensions: data.embedding?.length || 0
778
+ };
779
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, children: [
780
+ /* @__PURE__ */ jsxRuntime.jsx(StyledTypography, { variant: "beta", children: "Metadata" }),
781
+ Object.entries(metadata).map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { children: [
782
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { children: [
783
+ key,
784
+ ":"
785
+ ] }),
786
+ " ",
787
+ String(value)
788
+ ] }) }, key)),
789
+ data.metadata && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginTop: 4, children: [
790
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Custom Metadata" }),
791
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 2, background: "neutral100", hasRadius: true, marginTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx("pre", { style: { fontSize: "12px", margin: 0, whiteSpace: "pre-wrap" }, children: JSON.stringify(data.metadata, null, 2) }) })
792
+ ] })
793
+ ] });
794
+ }
795
+ function ConfirmDeleteEmbedding({ onConfirm, isLoading }) {
796
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { children: [
797
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}), children: "Delete" }) }),
798
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
799
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: "Confirm Deletion" }),
800
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 2, children: [
801
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: "Are you sure you want to delete this embedding?" }),
802
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "This action cannot be undone." })
803
+ ] }) }),
804
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
805
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: "Cancel" }) }),
806
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Action, { children: /* @__PURE__ */ jsxRuntime.jsx(
807
+ designSystem.Button,
808
+ {
809
+ variant: "danger",
810
+ onClick: onConfirm,
811
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
812
+ loading: isLoading,
813
+ children: isLoading ? "Deleting..." : "Delete"
814
+ }
815
+ ) })
816
+ ] })
817
+ ] })
818
+ ] });
819
+ }
820
+ function EmbeddingDetails() {
821
+ const navigate = reactRouterDom.useNavigate();
822
+ const { id } = reactRouterDom.useParams();
823
+ const { del, get, put } = admin.useFetchClient();
824
+ const { toggleNotification } = admin.useNotification();
825
+ const [data, setData] = react.useState(null);
826
+ const [isLoading, setIsLoading] = react.useState(true);
827
+ const [isDeleting, setIsDeleting] = react.useState(false);
828
+ const [isEditing, setIsEditing] = react.useState(false);
829
+ const [isSaving, setIsSaving] = react.useState(false);
830
+ const [editTitle, setEditTitle] = react.useState("");
831
+ const [editContent, setEditContent] = react.useState("");
832
+ const [editMetadata, setEditMetadata] = react.useState("");
833
+ react.useEffect(() => {
834
+ async function fetchData() {
835
+ if (!id) return;
836
+ try {
837
+ const response = await get(`/${index.PLUGIN_ID}/embeddings/find/${id}`);
838
+ const embeddingData = response.data;
839
+ setData(embeddingData);
840
+ setEditTitle(embeddingData.title || "");
841
+ setEditContent(embeddingData.content || "");
842
+ setEditMetadata(embeddingData.metadata ? JSON.stringify(embeddingData.metadata, null, 2) : "");
843
+ } catch (error) {
844
+ console.error("Failed to fetch embedding:", error);
845
+ } finally {
846
+ setIsLoading(false);
847
+ }
848
+ }
849
+ fetchData();
850
+ }, [id, get]);
851
+ const handleDelete = async () => {
852
+ if (!id || isDeleting) return;
853
+ setIsDeleting(true);
854
+ try {
855
+ await del(`/${index.PLUGIN_ID}/embeddings/delete-embedding/${id}`);
856
+ navigate(`/plugins/${index.PLUGIN_ID}`);
857
+ } catch (error) {
858
+ console.error("Failed to delete embedding:", error);
859
+ setIsDeleting(false);
860
+ }
861
+ };
862
+ const handleStartEdit = () => {
863
+ if (data) {
864
+ setEditTitle(data.title || "");
865
+ setEditContent(data.content || "");
866
+ setEditMetadata(data.metadata ? JSON.stringify(data.metadata, null, 2) : "");
867
+ }
868
+ setIsEditing(true);
869
+ };
870
+ const handleCancelEdit = () => {
871
+ setIsEditing(false);
872
+ };
873
+ const handleSave = async () => {
874
+ if (!id || isSaving) return;
875
+ let parsedMetadata = null;
876
+ if (editMetadata.trim()) {
877
+ try {
878
+ parsedMetadata = JSON.parse(editMetadata);
879
+ } catch {
880
+ toggleNotification({
881
+ type: "warning",
882
+ message: "Invalid JSON in metadata field"
883
+ });
884
+ return;
885
+ }
886
+ }
887
+ setIsSaving(true);
888
+ try {
889
+ const response = await put(`/${index.PLUGIN_ID}/embeddings/update-embedding/${id}`, {
890
+ data: {
891
+ title: editTitle.trim(),
892
+ content: editContent.trim(),
893
+ metadata: parsedMetadata
894
+ }
895
+ });
896
+ setData(response.data);
897
+ setIsEditing(false);
898
+ toggleNotification({
899
+ type: "success",
900
+ message: "Embedding updated successfully"
901
+ });
902
+ } catch (error) {
903
+ console.error("Failed to update embedding:", error);
904
+ toggleNotification({
905
+ type: "danger",
906
+ message: error.message || "Failed to update embedding"
907
+ });
908
+ } finally {
909
+ setIsSaving(false);
910
+ }
911
+ };
912
+ if (isLoading) {
913
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
914
+ /* @__PURE__ */ jsxRuntime.jsx(
915
+ admin.Layouts.Header,
916
+ {
917
+ title: "Loading...",
918
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
919
+ }
920
+ ),
921
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading embedding details..." }) }) })
922
+ ] });
923
+ }
924
+ if (!data) {
925
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
926
+ /* @__PURE__ */ jsxRuntime.jsx(
927
+ admin.Layouts.Header,
928
+ {
929
+ title: "Embedding Not Found",
930
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
931
+ }
932
+ ),
933
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, textAlign: "center", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: "The requested embedding could not be found." }) }) })
934
+ ] });
935
+ }
936
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
937
+ /* @__PURE__ */ jsxRuntime.jsx(
938
+ admin.Layouts.Header,
939
+ {
940
+ title: isEditing ? "Edit Embedding" : data.title || "Embedding Details",
941
+ subtitle: `Embedding ID: ${data.embeddingId || "N/A"}`,
942
+ primaryAction: isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
943
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}), onClick: handleCancelEdit, children: "Cancel" }),
944
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}), onClick: handleSave, loading: isSaving, children: isSaving ? "Saving..." : "Save" })
945
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
946
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}), onClick: handleStartEdit, children: "Edit" }),
947
+ /* @__PURE__ */ jsxRuntime.jsx(ConfirmDeleteEmbedding, { onConfirm: handleDelete, isLoading: isDeleting })
948
+ ] }),
949
+ navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
950
+ }
951
+ ),
952
+ /* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, children: isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 6, children: [
953
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 8, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", padding: 1, hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, children: [
954
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
955
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Title" }),
956
+ /* @__PURE__ */ jsxRuntime.jsx(
957
+ designSystem.TextInput,
958
+ {
959
+ value: editTitle,
960
+ onChange: (e) => setEditTitle(e.target.value)
961
+ }
962
+ )
963
+ ] }) }),
964
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginBottom: 4, children: [
965
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
966
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Content" }),
967
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "Changes to content will regenerate the embedding vector" })
968
+ ] }),
969
+ /* @__PURE__ */ jsxRuntime.jsx(
970
+ index.MarkdownEditor,
971
+ {
972
+ content: editContent,
973
+ onChange: setEditContent,
974
+ height: 300
975
+ }
976
+ )
977
+ ] })
978
+ ] }) }) }),
979
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", padding: 1, hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
980
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Metadata (JSON)" }),
981
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "Optional custom metadata" }),
982
+ /* @__PURE__ */ jsxRuntime.jsx(
983
+ designSystem.Textarea,
984
+ {
985
+ value: editMetadata,
986
+ onChange: (e) => setEditMetadata(e.target.value),
987
+ placeholder: '{"key": "value"}'
988
+ }
989
+ )
990
+ ] }) }) }) }) })
991
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 6, children: [
992
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 8, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", padding: 1, hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, children: [
993
+ /* @__PURE__ */ jsxRuntime.jsx(StyledTypography, { variant: "beta", children: "Embedding Content" }),
994
+ data.content ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: data.content }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: "No content" })
995
+ ] }) }) }),
996
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { col: 4, s: 12, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral100", padding: 1, hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(Metadata, { data }) }) })
997
+ ] }) }) })
998
+ ] });
999
+ }
1000
+ const App = () => {
1001
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [
1002
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { index: true, element: /* @__PURE__ */ jsxRuntime.jsx(HomePage, {}) }),
1003
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "*", element: /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {}) }),
1004
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "/embeddings", element: /* @__PURE__ */ jsxRuntime.jsx(CreateEmbeddings, {}) }),
1005
+ /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "/embeddings/:id", element: /* @__PURE__ */ jsxRuntime.jsx(EmbeddingDetails, {}) })
1006
+ ] });
1007
+ };
1008
+ exports.App = App;