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