strapi-content-embeddings 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/en-B4KWt_jN.js +0 -1
- package/dist/_chunks/en-Byx4XI2L.mjs +0 -1
- package/dist/admin/index.js +686 -4
- package/dist/admin/index.mjs +683 -4
- package/dist/server/index.js +293 -287
- package/dist/server/index.mjs +293 -287
- package/dist/server/src/index.d.ts +5 -0
- package/dist/server/src/mcp/schemas/index.d.ts +3 -0
- package/dist/server/src/mcp/tools/create-embedding.d.ts +3 -4
- package/dist/server/src/mcp/tools/get-embedding.d.ts +3 -3
- package/dist/server/src/mcp/tools/index.d.ts +1 -0
- package/dist/server/src/mcp/tools/list-embeddings.d.ts +3 -3
- package/dist/server/src/mcp/tools/rag-query.d.ts +3 -3
- package/dist/server/src/mcp/tools/semantic-search.d.ts +3 -3
- package/dist/server/src/services/ai-tools.d.ts +13 -0
- package/dist/server/src/services/embeddings.d.ts +2 -2
- package/dist/server/src/services/index.d.ts +5 -0
- package/dist/server/src/tools/create-embedding.d.ts +9 -0
- package/dist/server/src/tools/get-embedding.d.ts +8 -0
- package/dist/server/src/tools/index.d.ts +14 -0
- package/dist/server/src/tools/list-embeddings.d.ts +8 -0
- package/dist/server/src/tools/rag-query.d.ts +8 -0
- package/dist/server/src/tools/semantic-search.d.ts +8 -0
- package/dist/server/src/tools/types.d.ts +14 -0
- package/package.json +1 -1
- package/dist/_chunks/App-ByRBbkZn.js +0 -1600
- package/dist/_chunks/App-ByRBbkZn.js.map +0 -1
- package/dist/_chunks/App-MjsTrWRS.mjs +0 -1596
- package/dist/_chunks/App-MjsTrWRS.mjs.map +0 -1
- package/dist/_chunks/en-B4KWt_jN.js.map +0 -1
- package/dist/_chunks/en-Byx4XI2L.mjs.map +0 -1
- package/dist/_chunks/index-TWbcT-zJ.js +0 -785
- package/dist/_chunks/index-TWbcT-zJ.js.map +0 -1
- package/dist/_chunks/index-ifqYByO5.mjs +0 -783
- package/dist/_chunks/index-ifqYByO5.mjs.map +0 -1
- package/dist/admin/index.js.map +0 -1
- package/dist/admin/index.mjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.mjs.map +0 -1
|
@@ -1,1600 +0,0 @@
|
|
|
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 qs = require("qs");
|
|
10
|
-
const index = require("./index-TWbcT-zJ.js");
|
|
11
|
-
const styled = require("styled-components");
|
|
12
|
-
const ReactMarkdown = require("react-markdown");
|
|
13
|
-
const reactIntl = require("react-intl");
|
|
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: 0, 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
|
-
const SYNC_BASE = `/${index.PLUGIN_ID}`;
|
|
472
|
-
const syncApi = {
|
|
473
|
-
getStatus: async (fetchClient) => {
|
|
474
|
-
const response = await fetchClient.get(`${SYNC_BASE}/sync/status`);
|
|
475
|
-
return response.data;
|
|
476
|
-
},
|
|
477
|
-
syncFromNeon: async (fetchClient, options) => {
|
|
478
|
-
const queryString = options ? `?${qs__default.default.stringify(options)}` : "";
|
|
479
|
-
const response = await fetchClient.post(`${SYNC_BASE}/sync${queryString}`);
|
|
480
|
-
return response.data;
|
|
481
|
-
},
|
|
482
|
-
recreateAll: async (fetchClient) => {
|
|
483
|
-
const response = await fetchClient.post(`${SYNC_BASE}/recreate`);
|
|
484
|
-
return response.data;
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
function StatCard({ label, value, subtitle, variant = "default" }) {
|
|
488
|
-
const bgColors = {
|
|
489
|
-
default: "neutral100",
|
|
490
|
-
success: "success100",
|
|
491
|
-
warning: "warning100",
|
|
492
|
-
danger: "danger100"
|
|
493
|
-
};
|
|
494
|
-
const textColors = {
|
|
495
|
-
default: "neutral800",
|
|
496
|
-
success: "success700",
|
|
497
|
-
warning: "warning700",
|
|
498
|
-
danger: "danger700"
|
|
499
|
-
};
|
|
500
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
501
|
-
designSystem.Box,
|
|
502
|
-
{
|
|
503
|
-
padding: 4,
|
|
504
|
-
background: bgColors[variant],
|
|
505
|
-
hasRadius: true,
|
|
506
|
-
borderColor: "neutral200",
|
|
507
|
-
style: { textAlign: "center", minWidth: "120px" },
|
|
508
|
-
children: [
|
|
509
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { textTransform: "uppercase", fontSize: "11px" }, children: label }),
|
|
510
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", textColor: textColors[variant], fontWeight: "bold", children: value }) }),
|
|
511
|
-
subtitle && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: subtitle }) })
|
|
512
|
-
]
|
|
513
|
-
}
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
function SyncModal({ isOpen, onClose, onSyncComplete }) {
|
|
517
|
-
const fetchClient = admin.useFetchClient();
|
|
518
|
-
const [operation, setOperation] = react.useState("status");
|
|
519
|
-
const [removeOrphans, setRemoveOrphans] = react.useState(false);
|
|
520
|
-
const [dryRun, setDryRun] = react.useState(true);
|
|
521
|
-
const [isLoading, setIsLoading] = react.useState(false);
|
|
522
|
-
const [status, setStatus] = react.useState(null);
|
|
523
|
-
const [syncResult, setSyncResult] = react.useState(null);
|
|
524
|
-
const [recreateResult, setRecreateResult] = react.useState(null);
|
|
525
|
-
const [error, setError] = react.useState(null);
|
|
526
|
-
react.useEffect(() => {
|
|
527
|
-
if (isOpen) {
|
|
528
|
-
fetchStatus();
|
|
529
|
-
}
|
|
530
|
-
}, [isOpen]);
|
|
531
|
-
react.useEffect(() => {
|
|
532
|
-
if (!isOpen) {
|
|
533
|
-
setSyncResult(null);
|
|
534
|
-
setRecreateResult(null);
|
|
535
|
-
setError(null);
|
|
536
|
-
setOperation("status");
|
|
537
|
-
setDryRun(true);
|
|
538
|
-
setRemoveOrphans(false);
|
|
539
|
-
}
|
|
540
|
-
}, [isOpen]);
|
|
541
|
-
const fetchStatus = async () => {
|
|
542
|
-
setIsLoading(true);
|
|
543
|
-
setError(null);
|
|
544
|
-
try {
|
|
545
|
-
const result = await syncApi.getStatus(fetchClient);
|
|
546
|
-
setStatus(result);
|
|
547
|
-
} catch (err) {
|
|
548
|
-
setError(err.message || "Failed to fetch sync status");
|
|
549
|
-
} finally {
|
|
550
|
-
setIsLoading(false);
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
const handleExecute = async () => {
|
|
554
|
-
setIsLoading(true);
|
|
555
|
-
setError(null);
|
|
556
|
-
setSyncResult(null);
|
|
557
|
-
setRecreateResult(null);
|
|
558
|
-
try {
|
|
559
|
-
if (operation === "status") {
|
|
560
|
-
await fetchStatus();
|
|
561
|
-
} else if (operation === "sync") {
|
|
562
|
-
const result = await syncApi.syncFromNeon(fetchClient, { removeOrphans, dryRun });
|
|
563
|
-
setSyncResult(result);
|
|
564
|
-
if (!dryRun && onSyncComplete) {
|
|
565
|
-
onSyncComplete();
|
|
566
|
-
}
|
|
567
|
-
} else if (operation === "recreate") {
|
|
568
|
-
const result = await syncApi.recreateAll(fetchClient);
|
|
569
|
-
setRecreateResult(result);
|
|
570
|
-
if (onSyncComplete) {
|
|
571
|
-
onSyncComplete();
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
} catch (err) {
|
|
575
|
-
setError(err.message || "Operation failed");
|
|
576
|
-
} finally {
|
|
577
|
-
setIsLoading(false);
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
const renderStatus = () => {
|
|
581
|
-
if (!status) return null;
|
|
582
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 5, background: "neutral0", shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, children: [
|
|
583
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
|
|
584
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
|
|
585
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Database, {}),
|
|
586
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: "Sync Status" })
|
|
587
|
-
] }),
|
|
588
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { active: status.inSync, size: "S", children: status.inSync ? "In Sync" : "Out of Sync" })
|
|
589
|
-
] }),
|
|
590
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
|
|
591
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, justifyContent: "center", wrap: "wrap", children: [
|
|
592
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
593
|
-
StatCard,
|
|
594
|
-
{
|
|
595
|
-
label: "Neon DB",
|
|
596
|
-
value: status.neonCount,
|
|
597
|
-
subtitle: "embeddings"
|
|
598
|
-
}
|
|
599
|
-
),
|
|
600
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
601
|
-
StatCard,
|
|
602
|
-
{
|
|
603
|
-
label: "Strapi DB",
|
|
604
|
-
value: status.strapiCount,
|
|
605
|
-
subtitle: "embeddings"
|
|
606
|
-
}
|
|
607
|
-
)
|
|
608
|
-
] }),
|
|
609
|
-
!status.inSync && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
610
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
|
|
611
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, background: "warning100", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
|
612
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "warning700", children: "Differences Found" }),
|
|
613
|
-
status.missingInStrapi > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "warning700", children: [
|
|
614
|
-
"• ",
|
|
615
|
-
status.missingInStrapi,
|
|
616
|
-
" embeddings missing in Strapi (will be created)"
|
|
617
|
-
] }),
|
|
618
|
-
status.missingInNeon > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "danger600", children: [
|
|
619
|
-
"• ",
|
|
620
|
-
status.missingInNeon,
|
|
621
|
-
" orphaned entries in Strapi (not in Neon)"
|
|
622
|
-
] }),
|
|
623
|
-
status.contentDifferences > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "warning700", children: [
|
|
624
|
-
"• ",
|
|
625
|
-
status.contentDifferences,
|
|
626
|
-
" entries with content differences"
|
|
627
|
-
] })
|
|
628
|
-
] }) })
|
|
629
|
-
] })
|
|
630
|
-
] }) });
|
|
631
|
-
};
|
|
632
|
-
const renderSyncResult = () => {
|
|
633
|
-
if (!syncResult) return null;
|
|
634
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 5, background: syncResult.success ? "success100" : "danger100", shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, children: [
|
|
635
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
|
|
636
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: syncResult.dryRun ? "Preview Results" : "Sync Results" }),
|
|
637
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { active: syncResult.success, children: syncResult.success ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", children: [
|
|
638
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Check, { width: 12, height: 12 }),
|
|
639
|
-
"Success"
|
|
640
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, alignItems: "center", children: [
|
|
641
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Cross, { width: 12, height: 12 }),
|
|
642
|
-
"Failed"
|
|
643
|
-
] }) })
|
|
644
|
-
] }),
|
|
645
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
|
|
646
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, justifyContent: "center", wrap: "wrap", children: [
|
|
647
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
648
|
-
StatCard,
|
|
649
|
-
{
|
|
650
|
-
label: "Created",
|
|
651
|
-
value: syncResult.actions.created,
|
|
652
|
-
variant: syncResult.actions.created > 0 ? "success" : "default"
|
|
653
|
-
}
|
|
654
|
-
),
|
|
655
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
656
|
-
StatCard,
|
|
657
|
-
{
|
|
658
|
-
label: "Updated",
|
|
659
|
-
value: syncResult.actions.updated,
|
|
660
|
-
variant: syncResult.actions.updated > 0 ? "warning" : "default"
|
|
661
|
-
}
|
|
662
|
-
),
|
|
663
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
664
|
-
StatCard,
|
|
665
|
-
{
|
|
666
|
-
label: "Removed",
|
|
667
|
-
value: syncResult.actions.orphansRemoved,
|
|
668
|
-
variant: syncResult.actions.orphansRemoved > 0 ? "danger" : "default"
|
|
669
|
-
}
|
|
670
|
-
)
|
|
671
|
-
] }),
|
|
672
|
-
syncResult.errors.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 3, background: "danger100", hasRadius: true, children: [
|
|
673
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "danger700", children: "Errors" }),
|
|
674
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { paddingTop: 2, children: [
|
|
675
|
-
syncResult.errors.slice(0, 3).map((err, i) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "danger600", children: [
|
|
676
|
-
"• ",
|
|
677
|
-
err
|
|
678
|
-
] }, i)),
|
|
679
|
-
syncResult.errors.length > 3 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "danger600", fontWeight: "bold", children: [
|
|
680
|
-
"+ ",
|
|
681
|
-
syncResult.errors.length - 3,
|
|
682
|
-
" more errors"
|
|
683
|
-
] })
|
|
684
|
-
] })
|
|
685
|
-
] }),
|
|
686
|
-
syncResult.dryRun && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { variant: "default", closeLabel: "Close", children: 'This was a preview. No changes were made. Click "Apply Changes" below to execute the sync.' }) })
|
|
687
|
-
] }) });
|
|
688
|
-
};
|
|
689
|
-
const renderRecreateResult = () => {
|
|
690
|
-
if (!recreateResult) return null;
|
|
691
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 5, background: recreateResult.success ? "success100" : "danger100", shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, children: [
|
|
692
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", children: [
|
|
693
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: "Recreate Results" }),
|
|
694
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { active: recreateResult.success, children: recreateResult.success ? "Success" : "Failed" })
|
|
695
|
-
] }),
|
|
696
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, {}),
|
|
697
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, justifyContent: "center", wrap: "wrap", children: [
|
|
698
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
699
|
-
StatCard,
|
|
700
|
-
{
|
|
701
|
-
label: "Processed",
|
|
702
|
-
value: recreateResult.totalProcessed
|
|
703
|
-
}
|
|
704
|
-
),
|
|
705
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
706
|
-
StatCard,
|
|
707
|
-
{
|
|
708
|
-
label: "Created",
|
|
709
|
-
value: recreateResult.created,
|
|
710
|
-
variant: "success"
|
|
711
|
-
}
|
|
712
|
-
),
|
|
713
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
714
|
-
StatCard,
|
|
715
|
-
{
|
|
716
|
-
label: "Failed",
|
|
717
|
-
value: recreateResult.failed,
|
|
718
|
-
variant: recreateResult.failed > 0 ? "danger" : "default"
|
|
719
|
-
}
|
|
720
|
-
)
|
|
721
|
-
] }),
|
|
722
|
-
recreateResult.errors.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 3, background: "danger100", hasRadius: true, children: [
|
|
723
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "danger700", children: "Errors" }),
|
|
724
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 2, children: recreateResult.errors.slice(0, 3).map((err, i) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "danger600", children: [
|
|
725
|
-
"• ",
|
|
726
|
-
err
|
|
727
|
-
] }, i)) })
|
|
728
|
-
] })
|
|
729
|
-
] }) });
|
|
730
|
-
};
|
|
731
|
-
const getButtonLabel = () => {
|
|
732
|
-
if (operation === "status") return "Refresh Status";
|
|
733
|
-
if (operation === "sync") return dryRun ? "Preview Sync" : "Run Sync";
|
|
734
|
-
if (operation === "recreate") return "Recreate All";
|
|
735
|
-
return "Execute";
|
|
736
|
-
};
|
|
737
|
-
const handleApplyChanges = async () => {
|
|
738
|
-
setIsLoading(true);
|
|
739
|
-
setError(null);
|
|
740
|
-
setSyncResult(null);
|
|
741
|
-
try {
|
|
742
|
-
const result = await syncApi.syncFromNeon(fetchClient, { removeOrphans, dryRun: false });
|
|
743
|
-
setSyncResult(result);
|
|
744
|
-
if (onSyncComplete) {
|
|
745
|
-
onSyncComplete();
|
|
746
|
-
}
|
|
747
|
-
} catch (err) {
|
|
748
|
-
setError(err.message || "Failed to apply changes");
|
|
749
|
-
} finally {
|
|
750
|
-
setIsLoading(false);
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
const showApplyButton = syncResult?.dryRun && syncResult?.success;
|
|
754
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isOpen, onOpenChange: (open) => !open && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
|
|
755
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
|
|
756
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}),
|
|
757
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: "Database Sync" })
|
|
758
|
-
] }) }),
|
|
759
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 5, children: [
|
|
760
|
-
error && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { variant: "danger", closeLabel: "Close", onClose: () => setError(null), children: error }),
|
|
761
|
-
isLoading && !status ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 6, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading status..." }) }) : renderStatus(),
|
|
762
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 5, background: "neutral0", shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, children: [
|
|
763
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: "Select Operation" }),
|
|
764
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
765
|
-
designSystem.SingleSelect,
|
|
766
|
-
{
|
|
767
|
-
value: operation,
|
|
768
|
-
onChange: (value) => setOperation(value),
|
|
769
|
-
disabled: isLoading,
|
|
770
|
-
size: "M",
|
|
771
|
-
children: [
|
|
772
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "status", children: "Check Status" }),
|
|
773
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "sync", children: "Sync from Neon" }),
|
|
774
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "recreate", children: "Recreate All (Danger)" })
|
|
775
|
-
]
|
|
776
|
-
}
|
|
777
|
-
),
|
|
778
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: [
|
|
779
|
-
operation === "status" && "Compare Neon and Strapi databases without making changes.",
|
|
780
|
-
operation === "sync" && "Import embeddings from Neon DB to Strapi. Use this to restore missing entries.",
|
|
781
|
-
operation === "recreate" && "Delete all Neon embeddings and recreate them from Strapi data."
|
|
782
|
-
] })
|
|
783
|
-
] }) }),
|
|
784
|
-
operation === "sync" && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { padding: 5, background: "neutral0", shadow: "tableShadow", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, children: [
|
|
785
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", children: "Sync Options" }),
|
|
786
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
|
|
787
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
788
|
-
designSystem.Checkbox,
|
|
789
|
-
{
|
|
790
|
-
checked: dryRun,
|
|
791
|
-
onCheckedChange: (checked) => setDryRun(checked),
|
|
792
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", children: [
|
|
793
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: "Dry Run" }),
|
|
794
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Preview changes without applying them" })
|
|
795
|
-
] })
|
|
796
|
-
}
|
|
797
|
-
),
|
|
798
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
799
|
-
designSystem.Checkbox,
|
|
800
|
-
{
|
|
801
|
-
checked: removeOrphans,
|
|
802
|
-
onCheckedChange: (checked) => setRemoveOrphans(checked),
|
|
803
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", children: [
|
|
804
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: "Remove Orphans" }),
|
|
805
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Delete Strapi entries that don't exist in Neon" })
|
|
806
|
-
] })
|
|
807
|
-
}
|
|
808
|
-
)
|
|
809
|
-
] })
|
|
810
|
-
] }) }),
|
|
811
|
-
operation === "recreate" && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { variant: "danger", closeLabel: "Close", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
|
812
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
|
|
813
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, {}),
|
|
814
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "bold", children: "Destructive Operation" })
|
|
815
|
-
] }),
|
|
816
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", children: "This will delete ALL embeddings in Neon and recreate them from Strapi data. This operation cannot be undone. Only use if embeddings are corrupted." })
|
|
817
|
-
] }) }),
|
|
818
|
-
syncResult && renderSyncResult(),
|
|
819
|
-
recreateResult && renderRecreateResult()
|
|
820
|
-
] }) }),
|
|
821
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", width: "100%", children: [
|
|
822
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: "Cancel" }) }),
|
|
823
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
|
824
|
-
showApplyButton && /* @__PURE__ */ jsxRuntime.jsx(
|
|
825
|
-
designSystem.Button,
|
|
826
|
-
{
|
|
827
|
-
onClick: handleApplyChanges,
|
|
828
|
-
loading: isLoading,
|
|
829
|
-
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}),
|
|
830
|
-
variant: "success",
|
|
831
|
-
children: "Apply Changes"
|
|
832
|
-
}
|
|
833
|
-
),
|
|
834
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
835
|
-
designSystem.Button,
|
|
836
|
-
{
|
|
837
|
-
onClick: handleExecute,
|
|
838
|
-
loading: isLoading,
|
|
839
|
-
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}),
|
|
840
|
-
variant: operation === "recreate" ? "danger" : "secondary",
|
|
841
|
-
children: getButtonLabel()
|
|
842
|
-
}
|
|
843
|
-
)
|
|
844
|
-
] })
|
|
845
|
-
] }) })
|
|
846
|
-
] }) });
|
|
847
|
-
}
|
|
848
|
-
const PAGE_SIZE = 10;
|
|
849
|
-
function debounce(func, wait) {
|
|
850
|
-
let timeout;
|
|
851
|
-
return (...args) => {
|
|
852
|
-
clearTimeout(timeout);
|
|
853
|
-
timeout = setTimeout(() => func(...args), wait);
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
function HomePage() {
|
|
857
|
-
const { get } = admin.useFetchClient();
|
|
858
|
-
const navigate = reactRouterDom.useNavigate();
|
|
859
|
-
const [embeddings, setEmbeddings] = react.useState(null);
|
|
860
|
-
const [search, setSearch] = react.useState("");
|
|
861
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
862
|
-
const [currentPage, setCurrentPage] = react.useState(1);
|
|
863
|
-
const [isSyncModalOpen, setIsSyncModalOpen] = react.useState(false);
|
|
864
|
-
const totalPages = embeddings ? Math.ceil(embeddings.totalCount / PAGE_SIZE) : 0;
|
|
865
|
-
const buildQuery = (searchTerm, page) => qs__default.default.stringify({
|
|
866
|
-
page,
|
|
867
|
-
pageSize: PAGE_SIZE,
|
|
868
|
-
filters: searchTerm ? {
|
|
869
|
-
$or: [{ title: { $containsi: searchTerm } }, { content: { $containsi: searchTerm } }]
|
|
870
|
-
} : void 0
|
|
871
|
-
});
|
|
872
|
-
const fetchData = react.useCallback(
|
|
873
|
-
async (searchTerm, page) => {
|
|
874
|
-
setIsLoading(true);
|
|
875
|
-
try {
|
|
876
|
-
const response = await get(`/${index.PLUGIN_ID}/embeddings/find?${buildQuery(searchTerm, page)}`);
|
|
877
|
-
setEmbeddings(response.data);
|
|
878
|
-
} catch (error) {
|
|
879
|
-
console.error("Failed to fetch embeddings:", error);
|
|
880
|
-
setEmbeddings({ data: [], count: 0, totalCount: 0 });
|
|
881
|
-
} finally {
|
|
882
|
-
setIsLoading(false);
|
|
883
|
-
}
|
|
884
|
-
},
|
|
885
|
-
[get]
|
|
886
|
-
);
|
|
887
|
-
const debouncedFetch = react.useMemo(() => debounce(fetchData, 500), [fetchData]);
|
|
888
|
-
react.useEffect(() => {
|
|
889
|
-
debouncedFetch(search, currentPage);
|
|
890
|
-
}, [search, currentPage, debouncedFetch]);
|
|
891
|
-
react.useEffect(() => {
|
|
892
|
-
setCurrentPage(1);
|
|
893
|
-
}, [search]);
|
|
894
|
-
const handleSearchChange = (e) => {
|
|
895
|
-
setSearch(e.target.value);
|
|
896
|
-
};
|
|
897
|
-
const handleCreateNew = () => {
|
|
898
|
-
navigate(`/plugins/${index.PLUGIN_ID}/embeddings`);
|
|
899
|
-
};
|
|
900
|
-
const handleSyncComplete = () => {
|
|
901
|
-
fetchData(search, currentPage);
|
|
902
|
-
};
|
|
903
|
-
const headerActions = /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
|
904
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}), onClick: () => setIsSyncModalOpen(true), children: "Sync" }),
|
|
905
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), onClick: handleCreateNew, children: "Create new embedding" })
|
|
906
|
-
] });
|
|
907
|
-
if (isLoading && !embeddings) {
|
|
908
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
909
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
910
|
-
admin.Layouts.Header,
|
|
911
|
-
{
|
|
912
|
-
title: "Content Embeddings",
|
|
913
|
-
subtitle: "Manage your content embeddings",
|
|
914
|
-
primaryAction: headerActions
|
|
915
|
-
}
|
|
916
|
-
),
|
|
917
|
-
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading..." }) }) }),
|
|
918
|
-
/* @__PURE__ */ jsxRuntime.jsx(ChatModal, {}),
|
|
919
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
920
|
-
SyncModal,
|
|
921
|
-
{
|
|
922
|
-
isOpen: isSyncModalOpen,
|
|
923
|
-
onClose: () => setIsSyncModalOpen(false),
|
|
924
|
-
onSyncComplete: handleSyncComplete
|
|
925
|
-
}
|
|
926
|
-
)
|
|
927
|
-
] });
|
|
928
|
-
}
|
|
929
|
-
if (embeddings?.totalCount === 0 && !search) {
|
|
930
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
931
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
932
|
-
admin.Layouts.Header,
|
|
933
|
-
{
|
|
934
|
-
title: "Content Embeddings",
|
|
935
|
-
subtitle: "Manage your content embeddings",
|
|
936
|
-
primaryAction: headerActions
|
|
937
|
-
}
|
|
938
|
-
),
|
|
939
|
-
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(EmptyState, {}) }),
|
|
940
|
-
/* @__PURE__ */ jsxRuntime.jsx(ChatModal, {}),
|
|
941
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
942
|
-
SyncModal,
|
|
943
|
-
{
|
|
944
|
-
isOpen: isSyncModalOpen,
|
|
945
|
-
onClose: () => setIsSyncModalOpen(false),
|
|
946
|
-
onSyncComplete: handleSyncComplete
|
|
947
|
-
}
|
|
948
|
-
)
|
|
949
|
-
] });
|
|
950
|
-
}
|
|
951
|
-
const renderEmbeddingsContent = () => {
|
|
952
|
-
if (isLoading) {
|
|
953
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: "Loading..." }) });
|
|
954
|
-
}
|
|
955
|
-
if (embeddings?.data && embeddings.data.length > 0) {
|
|
956
|
-
return /* @__PURE__ */ jsxRuntime.jsx(EmbeddingsTable, { data: embeddings.data });
|
|
957
|
-
}
|
|
958
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 8, textAlign: "center", children: [
|
|
959
|
-
'No embeddings found matching "',
|
|
960
|
-
search,
|
|
961
|
-
'"'
|
|
962
|
-
] });
|
|
963
|
-
};
|
|
964
|
-
const shouldShowPagination = embeddings && embeddings.totalCount > 0 && totalPages > 1;
|
|
965
|
-
const getVisiblePages = () => {
|
|
966
|
-
const pages = [];
|
|
967
|
-
const maxVisible = 5;
|
|
968
|
-
let start = Math.max(1, currentPage - Math.floor(maxVisible / 2));
|
|
969
|
-
const end = Math.min(totalPages, start + maxVisible - 1);
|
|
970
|
-
if (end - start + 1 < maxVisible) {
|
|
971
|
-
start = Math.max(1, end - maxVisible + 1);
|
|
972
|
-
}
|
|
973
|
-
for (let i = start; i <= end; i++) {
|
|
974
|
-
pages.push(i);
|
|
975
|
-
}
|
|
976
|
-
return pages;
|
|
977
|
-
};
|
|
978
|
-
const renderPagination = () => {
|
|
979
|
-
if (!shouldShowPagination || !embeddings) {
|
|
980
|
-
return null;
|
|
981
|
-
}
|
|
982
|
-
const startItem = (currentPage - 1) * PAGE_SIZE + 1;
|
|
983
|
-
const endItem = Math.min(currentPage * PAGE_SIZE, embeddings.totalCount);
|
|
984
|
-
const visiblePages = getVisiblePages();
|
|
985
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 3, paddingTop: 6, children: [
|
|
986
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Pagination, { activePage: currentPage, pageCount: totalPages, children: [
|
|
987
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
988
|
-
designSystem.PreviousLink,
|
|
989
|
-
{
|
|
990
|
-
onClick: () => setCurrentPage((p) => Math.max(1, p - 1)),
|
|
991
|
-
disabled: currentPage === 1,
|
|
992
|
-
children: "Previous"
|
|
993
|
-
}
|
|
994
|
-
),
|
|
995
|
-
visiblePages.map((page) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
996
|
-
designSystem.PageLink,
|
|
997
|
-
{
|
|
998
|
-
number: page,
|
|
999
|
-
onClick: () => setCurrentPage(page),
|
|
1000
|
-
children: page
|
|
1001
|
-
},
|
|
1002
|
-
page
|
|
1003
|
-
)),
|
|
1004
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1005
|
-
designSystem.NextLink,
|
|
1006
|
-
{
|
|
1007
|
-
onClick: () => setCurrentPage((p) => Math.min(totalPages, p + 1)),
|
|
1008
|
-
disabled: currentPage === totalPages,
|
|
1009
|
-
children: "Next"
|
|
1010
|
-
}
|
|
1011
|
-
)
|
|
1012
|
-
] }),
|
|
1013
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
1014
|
-
"Showing ",
|
|
1015
|
-
startItem,
|
|
1016
|
-
" to ",
|
|
1017
|
-
endItem,
|
|
1018
|
-
" of ",
|
|
1019
|
-
embeddings.totalCount,
|
|
1020
|
-
" entries"
|
|
1021
|
-
] })
|
|
1022
|
-
] });
|
|
1023
|
-
};
|
|
1024
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
1025
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1026
|
-
admin.Layouts.Header,
|
|
1027
|
-
{
|
|
1028
|
-
title: "Content Embeddings",
|
|
1029
|
-
subtitle: `${embeddings?.totalCount || 0} embeddings total`,
|
|
1030
|
-
primaryAction: headerActions
|
|
1031
|
-
}
|
|
1032
|
-
),
|
|
1033
|
-
/* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
|
|
1034
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1035
|
-
designSystem.TextInput,
|
|
1036
|
-
{
|
|
1037
|
-
placeholder: "Search embeddings...",
|
|
1038
|
-
name: "search",
|
|
1039
|
-
value: search,
|
|
1040
|
-
onChange: handleSearchChange,
|
|
1041
|
-
startAction: /* @__PURE__ */ jsxRuntime.jsx(icons.Search, {})
|
|
1042
|
-
}
|
|
1043
|
-
) }),
|
|
1044
|
-
renderEmbeddingsContent(),
|
|
1045
|
-
renderPagination()
|
|
1046
|
-
] }),
|
|
1047
|
-
/* @__PURE__ */ jsxRuntime.jsx(ChatModal, {}),
|
|
1048
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1049
|
-
SyncModal,
|
|
1050
|
-
{
|
|
1051
|
-
isOpen: isSyncModalOpen,
|
|
1052
|
-
onClose: () => setIsSyncModalOpen(false),
|
|
1053
|
-
onSyncComplete: handleSyncComplete
|
|
1054
|
-
}
|
|
1055
|
-
)
|
|
1056
|
-
] });
|
|
1057
|
-
}
|
|
1058
|
-
function CreateEmbeddingsForm({
|
|
1059
|
-
onSubmit,
|
|
1060
|
-
isLoading,
|
|
1061
|
-
input,
|
|
1062
|
-
setInput,
|
|
1063
|
-
markdown,
|
|
1064
|
-
handleMarkdownChange,
|
|
1065
|
-
metadata,
|
|
1066
|
-
setMetadata,
|
|
1067
|
-
height,
|
|
1068
|
-
children
|
|
1069
|
-
}) {
|
|
1070
|
-
return /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { disabled: isLoading, style: { border: "none", padding: 0, margin: 0 }, children: [
|
|
1071
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
|
|
1072
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Title" }),
|
|
1073
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1074
|
-
designSystem.TextInput,
|
|
1075
|
-
{
|
|
1076
|
-
placeholder: "Enter a title for your embedding",
|
|
1077
|
-
name: "input",
|
|
1078
|
-
onChange: (e) => setInput(e.target.value),
|
|
1079
|
-
value: input
|
|
1080
|
-
}
|
|
1081
|
-
)
|
|
1082
|
-
] }) }),
|
|
1083
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
|
|
1084
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Content" }),
|
|
1085
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1086
|
-
index.MarkdownEditor,
|
|
1087
|
-
{
|
|
1088
|
-
content: markdown,
|
|
1089
|
-
onChange: handleMarkdownChange,
|
|
1090
|
-
height
|
|
1091
|
-
}
|
|
1092
|
-
)
|
|
1093
|
-
] }) }),
|
|
1094
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
|
|
1095
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Metadata (JSON)" }),
|
|
1096
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "Optional JSON metadata for this embedding" }),
|
|
1097
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1098
|
-
designSystem.Textarea,
|
|
1099
|
-
{
|
|
1100
|
-
placeholder: '{"category": "docs", "source": "manual"}',
|
|
1101
|
-
name: "metadata",
|
|
1102
|
-
onChange: (e) => setMetadata(e.target.value),
|
|
1103
|
-
value: metadata
|
|
1104
|
-
}
|
|
1105
|
-
)
|
|
1106
|
-
] }) }),
|
|
1107
|
-
children
|
|
1108
|
-
] }) });
|
|
1109
|
-
}
|
|
1110
|
-
function BackLink({ to }) {
|
|
1111
|
-
if (to) {
|
|
1112
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { tag: reactRouterDom.NavLink, to, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, {}), children: "Go back" });
|
|
1113
|
-
}
|
|
1114
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Link, { tag: reactRouterDom.NavLink, to: "..", relative: "path", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, {}), children: "Go back" });
|
|
1115
|
-
}
|
|
1116
|
-
const CHUNK_SIZE = 4e3;
|
|
1117
|
-
function CreateEmbeddings() {
|
|
1118
|
-
const { formatMessage } = reactIntl.useIntl();
|
|
1119
|
-
const navigate = reactRouterDom.useNavigate();
|
|
1120
|
-
const { post } = admin.useFetchClient();
|
|
1121
|
-
const [isLoading, setIsLoading] = react.useState(false);
|
|
1122
|
-
const [title, setTitle] = react.useState("");
|
|
1123
|
-
const [content, setContent] = react.useState("");
|
|
1124
|
-
const [metadata, setMetadata] = react.useState("");
|
|
1125
|
-
const [error, setError] = react.useState(null);
|
|
1126
|
-
const isValid = title.trim() && content.trim();
|
|
1127
|
-
const contentLength = content.length;
|
|
1128
|
-
const willChunk = contentLength > CHUNK_SIZE;
|
|
1129
|
-
const estimatedChunks = willChunk ? Math.ceil(contentLength / (CHUNK_SIZE - 200)) : 1;
|
|
1130
|
-
function parseMetadata() {
|
|
1131
|
-
if (!metadata.trim()) return null;
|
|
1132
|
-
try {
|
|
1133
|
-
return JSON.parse(metadata);
|
|
1134
|
-
} catch {
|
|
1135
|
-
return null;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
async function handleSubmit(e) {
|
|
1139
|
-
e.preventDefault();
|
|
1140
|
-
e.stopPropagation();
|
|
1141
|
-
if (!isValid) {
|
|
1142
|
-
setError("Please provide a title and content");
|
|
1143
|
-
return;
|
|
1144
|
-
}
|
|
1145
|
-
if (metadata.trim()) {
|
|
1146
|
-
const parsedMetadata = parseMetadata();
|
|
1147
|
-
if (parsedMetadata === null) {
|
|
1148
|
-
setError("Invalid JSON in metadata field");
|
|
1149
|
-
return;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
setIsLoading(true);
|
|
1153
|
-
setError(null);
|
|
1154
|
-
try {
|
|
1155
|
-
await post(`/${index.PLUGIN_ID}/embeddings/create-embedding`, {
|
|
1156
|
-
data: {
|
|
1157
|
-
title: title.trim(),
|
|
1158
|
-
content: content.trim(),
|
|
1159
|
-
metadata: parseMetadata()
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
navigate(`/plugins/${index.PLUGIN_ID}`);
|
|
1163
|
-
} catch (err) {
|
|
1164
|
-
console.error("Failed to create embedding:", err);
|
|
1165
|
-
setError(err.message || "Failed to create embedding. Please try again.");
|
|
1166
|
-
setIsLoading(false);
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
1170
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1171
|
-
admin.Layouts.Header,
|
|
1172
|
-
{
|
|
1173
|
-
title: formatMessage({
|
|
1174
|
-
id: "CreateEmbeddings.header.title",
|
|
1175
|
-
defaultMessage: "Create Embedding"
|
|
1176
|
-
}),
|
|
1177
|
-
subtitle: willChunk ? formatMessage(
|
|
1178
|
-
{
|
|
1179
|
-
id: "CreateEmbeddings.header.subtitle.chunked",
|
|
1180
|
-
defaultMessage: "Content: {length} characters (will create ~{chunks} embeddings)"
|
|
1181
|
-
},
|
|
1182
|
-
{ length: contentLength, chunks: estimatedChunks }
|
|
1183
|
-
) : formatMessage(
|
|
1184
|
-
{
|
|
1185
|
-
id: "CreateEmbeddings.header.subtitle",
|
|
1186
|
-
defaultMessage: "Content: {length} characters"
|
|
1187
|
-
},
|
|
1188
|
-
{ length: contentLength }
|
|
1189
|
-
),
|
|
1190
|
-
primaryAction: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1191
|
-
designSystem.Button,
|
|
1192
|
-
{
|
|
1193
|
-
type: "submit",
|
|
1194
|
-
disabled: isLoading || !isValid,
|
|
1195
|
-
loading: isLoading,
|
|
1196
|
-
onClick: (e) => {
|
|
1197
|
-
e.preventDefault();
|
|
1198
|
-
const form = document.querySelector("form");
|
|
1199
|
-
if (form) {
|
|
1200
|
-
form.dispatchEvent(
|
|
1201
|
-
new Event("submit", { cancelable: true, bubbles: true })
|
|
1202
|
-
);
|
|
1203
|
-
}
|
|
1204
|
-
},
|
|
1205
|
-
children: isLoading ? "Creating..." : "Create Embedding"
|
|
1206
|
-
}
|
|
1207
|
-
),
|
|
1208
|
-
navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
|
|
1209
|
-
}
|
|
1210
|
-
),
|
|
1211
|
-
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
1212
|
-
error && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1213
|
-
designSystem.Box,
|
|
1214
|
-
{
|
|
1215
|
-
padding: 4,
|
|
1216
|
-
marginBottom: 4,
|
|
1217
|
-
background: "danger100",
|
|
1218
|
-
borderColor: "danger600",
|
|
1219
|
-
hasRadius: true,
|
|
1220
|
-
children: error
|
|
1221
|
-
}
|
|
1222
|
-
),
|
|
1223
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1224
|
-
CreateEmbeddingsForm,
|
|
1225
|
-
{
|
|
1226
|
-
onSubmit: handleSubmit,
|
|
1227
|
-
isLoading,
|
|
1228
|
-
input: title,
|
|
1229
|
-
setInput: setTitle,
|
|
1230
|
-
markdown: content,
|
|
1231
|
-
handleMarkdownChange: setContent,
|
|
1232
|
-
metadata,
|
|
1233
|
-
setMetadata
|
|
1234
|
-
}
|
|
1235
|
-
)
|
|
1236
|
-
] }) })
|
|
1237
|
-
] });
|
|
1238
|
-
}
|
|
1239
|
-
const StyledTypography = styled__default.default(designSystem.Typography)`
|
|
1240
|
-
display: block;
|
|
1241
|
-
margin-bottom: 1rem;
|
|
1242
|
-
`;
|
|
1243
|
-
const ChunkTab = styled__default.default.div`
|
|
1244
|
-
padding: 0.5rem 1rem;
|
|
1245
|
-
cursor: pointer;
|
|
1246
|
-
border-bottom: 2px solid ${({ $isActive }) => $isActive ? "#4945ff" : "transparent"};
|
|
1247
|
-
color: ${({ $isActive }) => $isActive ? "#4945ff" : "inherit"};
|
|
1248
|
-
font-weight: ${({ $isActive }) => $isActive ? "600" : "400"};
|
|
1249
|
-
white-space: nowrap;
|
|
1250
|
-
|
|
1251
|
-
&:hover {
|
|
1252
|
-
color: #4945ff;
|
|
1253
|
-
}
|
|
1254
|
-
`;
|
|
1255
|
-
const ChunkTabsContainer = styled__default.default(designSystem.Flex)`
|
|
1256
|
-
border-bottom: 1px solid #dcdce4;
|
|
1257
|
-
overflow-x: auto;
|
|
1258
|
-
margin-bottom: 1rem;
|
|
1259
|
-
`;
|
|
1260
|
-
function Metadata({ data }) {
|
|
1261
|
-
const metadata = {
|
|
1262
|
-
id: data.documentId,
|
|
1263
|
-
title: data.title,
|
|
1264
|
-
collectionType: data.collectionType || "standalone",
|
|
1265
|
-
fieldName: data.fieldName || "content",
|
|
1266
|
-
embeddingId: data.embeddingId || "N/A",
|
|
1267
|
-
vectorDimensions: data.embedding?.length || 0
|
|
1268
|
-
};
|
|
1269
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, children: [
|
|
1270
|
-
/* @__PURE__ */ jsxRuntime.jsx(StyledTypography, { variant: "beta", children: "Metadata" }),
|
|
1271
|
-
Object.entries(metadata).map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { children: [
|
|
1272
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { children: [
|
|
1273
|
-
key,
|
|
1274
|
-
":"
|
|
1275
|
-
] }),
|
|
1276
|
-
" ",
|
|
1277
|
-
String(value)
|
|
1278
|
-
] }) }, key)),
|
|
1279
|
-
data.metadata && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginTop: 4, children: [
|
|
1280
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", children: "Custom Metadata" }),
|
|
1281
|
-
/* @__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) }) })
|
|
1282
|
-
] })
|
|
1283
|
-
] });
|
|
1284
|
-
}
|
|
1285
|
-
function ConfirmDeleteEmbedding({ onConfirm, isLoading }) {
|
|
1286
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { children: [
|
|
1287
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}), children: "Delete" }) }),
|
|
1288
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
|
1289
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: "Confirm Deletion" }),
|
|
1290
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 2, children: [
|
|
1291
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: "Are you sure you want to delete this embedding?" }),
|
|
1292
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "This action cannot be undone." })
|
|
1293
|
-
] }) }),
|
|
1294
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
|
|
1295
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: "Cancel" }) }),
|
|
1296
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Action, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1297
|
-
designSystem.Button,
|
|
1298
|
-
{
|
|
1299
|
-
variant: "danger",
|
|
1300
|
-
onClick: onConfirm,
|
|
1301
|
-
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
|
|
1302
|
-
loading: isLoading,
|
|
1303
|
-
children: isLoading ? "Deleting..." : "Delete"
|
|
1304
|
-
}
|
|
1305
|
-
) })
|
|
1306
|
-
] })
|
|
1307
|
-
] })
|
|
1308
|
-
] });
|
|
1309
|
-
}
|
|
1310
|
-
function EmbeddingDetails() {
|
|
1311
|
-
const navigate = reactRouterDom.useNavigate();
|
|
1312
|
-
const { id } = reactRouterDom.useParams();
|
|
1313
|
-
const { del, get, put } = admin.useFetchClient();
|
|
1314
|
-
const { toggleNotification } = admin.useNotification();
|
|
1315
|
-
const [data, setData] = react.useState(null);
|
|
1316
|
-
const [chunks, setChunks] = react.useState([]);
|
|
1317
|
-
const [activeChunkIndex, setActiveChunkIndex] = react.useState(0);
|
|
1318
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
1319
|
-
const [isDeleting, setIsDeleting] = react.useState(false);
|
|
1320
|
-
const [isEditing, setIsEditing] = react.useState(false);
|
|
1321
|
-
const [isSaving, setIsSaving] = react.useState(false);
|
|
1322
|
-
const [editTitle, setEditTitle] = react.useState("");
|
|
1323
|
-
const [editContent, setEditContent] = react.useState("");
|
|
1324
|
-
const [editMetadata, setEditMetadata] = react.useState("");
|
|
1325
|
-
const isChunkedDocument = chunks.length > 1;
|
|
1326
|
-
const activeChunk = isChunkedDocument ? chunks[activeChunkIndex] : data;
|
|
1327
|
-
react.useEffect(() => {
|
|
1328
|
-
async function fetchData() {
|
|
1329
|
-
if (!id) return;
|
|
1330
|
-
try {
|
|
1331
|
-
const response = await get(`/${index.PLUGIN_ID}/embeddings/find/${id}`);
|
|
1332
|
-
const embeddingData = response.data;
|
|
1333
|
-
setData(embeddingData);
|
|
1334
|
-
const chunksResponse = await get(`/${index.PLUGIN_ID}/embeddings/related-chunks/${id}`);
|
|
1335
|
-
const relatedChunks = chunksResponse.data?.data || [];
|
|
1336
|
-
if (relatedChunks.length > 1) {
|
|
1337
|
-
const sortedChunks = relatedChunks.sort((a, b) => {
|
|
1338
|
-
const aIndex = a.metadata?.chunkIndex ?? 0;
|
|
1339
|
-
const bIndex = b.metadata?.chunkIndex ?? 0;
|
|
1340
|
-
return aIndex - bIndex;
|
|
1341
|
-
});
|
|
1342
|
-
setChunks(sortedChunks);
|
|
1343
|
-
const currentIndex = sortedChunks.findIndex(
|
|
1344
|
-
(chunk) => chunk.documentId === id
|
|
1345
|
-
);
|
|
1346
|
-
if (currentIndex >= 0) {
|
|
1347
|
-
setActiveChunkIndex(currentIndex);
|
|
1348
|
-
}
|
|
1349
|
-
const firstChunk = sortedChunks[currentIndex >= 0 ? currentIndex : 0];
|
|
1350
|
-
setEditTitle(firstChunk.title || "");
|
|
1351
|
-
setEditContent(firstChunk.content || "");
|
|
1352
|
-
setEditMetadata(firstChunk.metadata ? JSON.stringify(firstChunk.metadata, null, 2) : "");
|
|
1353
|
-
} else {
|
|
1354
|
-
setChunks([embeddingData]);
|
|
1355
|
-
setEditTitle(embeddingData.title || "");
|
|
1356
|
-
setEditContent(embeddingData.content || "");
|
|
1357
|
-
setEditMetadata(embeddingData.metadata ? JSON.stringify(embeddingData.metadata, null, 2) : "");
|
|
1358
|
-
}
|
|
1359
|
-
} catch (error) {
|
|
1360
|
-
console.error("Failed to fetch embedding:", error);
|
|
1361
|
-
} finally {
|
|
1362
|
-
setIsLoading(false);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
fetchData();
|
|
1366
|
-
}, [id, get]);
|
|
1367
|
-
react.useEffect(() => {
|
|
1368
|
-
if (activeChunk && !isEditing) {
|
|
1369
|
-
setEditTitle(activeChunk.title || "");
|
|
1370
|
-
setEditContent(activeChunk.content || "");
|
|
1371
|
-
setEditMetadata(activeChunk.metadata ? JSON.stringify(activeChunk.metadata, null, 2) : "");
|
|
1372
|
-
}
|
|
1373
|
-
}, [activeChunkIndex, activeChunk, isEditing]);
|
|
1374
|
-
const handleDelete = async () => {
|
|
1375
|
-
if (!activeChunk || isDeleting) return;
|
|
1376
|
-
setIsDeleting(true);
|
|
1377
|
-
try {
|
|
1378
|
-
if (isChunkedDocument) {
|
|
1379
|
-
for (const chunk of chunks) {
|
|
1380
|
-
await del(`/${index.PLUGIN_ID}/embeddings/delete-embedding/${chunk.documentId}`);
|
|
1381
|
-
}
|
|
1382
|
-
} else {
|
|
1383
|
-
await del(`/${index.PLUGIN_ID}/embeddings/delete-embedding/${activeChunk.documentId}`);
|
|
1384
|
-
}
|
|
1385
|
-
navigate(`/plugins/${index.PLUGIN_ID}`);
|
|
1386
|
-
} catch (error) {
|
|
1387
|
-
console.error("Failed to delete embedding:", error);
|
|
1388
|
-
setIsDeleting(false);
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
const handleStartEdit = () => {
|
|
1392
|
-
if (activeChunk) {
|
|
1393
|
-
setEditTitle(activeChunk.title || "");
|
|
1394
|
-
setEditContent(activeChunk.content || "");
|
|
1395
|
-
setEditMetadata(activeChunk.metadata ? JSON.stringify(activeChunk.metadata, null, 2) : "");
|
|
1396
|
-
}
|
|
1397
|
-
setIsEditing(true);
|
|
1398
|
-
};
|
|
1399
|
-
const handleCancelEdit = () => {
|
|
1400
|
-
setIsEditing(false);
|
|
1401
|
-
if (activeChunk) {
|
|
1402
|
-
setEditTitle(activeChunk.title || "");
|
|
1403
|
-
setEditContent(activeChunk.content || "");
|
|
1404
|
-
setEditMetadata(activeChunk.metadata ? JSON.stringify(activeChunk.metadata, null, 2) : "");
|
|
1405
|
-
}
|
|
1406
|
-
};
|
|
1407
|
-
const handleSave = async () => {
|
|
1408
|
-
if (!activeChunk || isSaving) return;
|
|
1409
|
-
let parsedMetadata = null;
|
|
1410
|
-
if (editMetadata.trim()) {
|
|
1411
|
-
try {
|
|
1412
|
-
parsedMetadata = JSON.parse(editMetadata);
|
|
1413
|
-
} catch {
|
|
1414
|
-
toggleNotification({
|
|
1415
|
-
type: "warning",
|
|
1416
|
-
message: "Invalid JSON in metadata field"
|
|
1417
|
-
});
|
|
1418
|
-
return;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
setIsSaving(true);
|
|
1422
|
-
try {
|
|
1423
|
-
const response = await put(`/${index.PLUGIN_ID}/embeddings/update-embedding/${activeChunk.documentId}`, {
|
|
1424
|
-
data: {
|
|
1425
|
-
title: editTitle.trim(),
|
|
1426
|
-
content: editContent.trim(),
|
|
1427
|
-
metadata: parsedMetadata
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1430
|
-
const updatedData = response.data;
|
|
1431
|
-
if (isChunkedDocument) {
|
|
1432
|
-
const newChunks = [...chunks];
|
|
1433
|
-
newChunks[activeChunkIndex] = updatedData;
|
|
1434
|
-
setChunks(newChunks);
|
|
1435
|
-
} else {
|
|
1436
|
-
setData(updatedData);
|
|
1437
|
-
setChunks([updatedData]);
|
|
1438
|
-
}
|
|
1439
|
-
setIsEditing(false);
|
|
1440
|
-
toggleNotification({
|
|
1441
|
-
type: "success",
|
|
1442
|
-
message: "Chunk updated successfully"
|
|
1443
|
-
});
|
|
1444
|
-
} catch (error) {
|
|
1445
|
-
console.error("Failed to update embedding:", error);
|
|
1446
|
-
toggleNotification({
|
|
1447
|
-
type: "danger",
|
|
1448
|
-
message: error.message || "Failed to update embedding"
|
|
1449
|
-
});
|
|
1450
|
-
} finally {
|
|
1451
|
-
setIsSaving(false);
|
|
1452
|
-
}
|
|
1453
|
-
};
|
|
1454
|
-
const handleChunkSelect = (index2) => {
|
|
1455
|
-
if (isEditing) {
|
|
1456
|
-
const confirmed = globalThis.confirm("You have unsaved changes. Discard them?");
|
|
1457
|
-
if (!confirmed) return;
|
|
1458
|
-
setIsEditing(false);
|
|
1459
|
-
}
|
|
1460
|
-
setActiveChunkIndex(index2);
|
|
1461
|
-
};
|
|
1462
|
-
const getOriginalTitle = () => {
|
|
1463
|
-
if (isChunkedDocument && chunks[0]?.metadata) {
|
|
1464
|
-
return chunks[0].metadata.originalTitle || chunks[0].title?.replace(/\s*\[Part \d+\/\d+\]$/, "");
|
|
1465
|
-
}
|
|
1466
|
-
return data?.title || "Embedding Details";
|
|
1467
|
-
};
|
|
1468
|
-
if (isLoading) {
|
|
1469
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
1470
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1471
|
-
admin.Layouts.Header,
|
|
1472
|
-
{
|
|
1473
|
-
title: "Loading...",
|
|
1474
|
-
navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
|
|
1475
|
-
}
|
|
1476
|
-
),
|
|
1477
|
-
/* @__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..." }) }) })
|
|
1478
|
-
] });
|
|
1479
|
-
}
|
|
1480
|
-
if (!data || !activeChunk) {
|
|
1481
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
1482
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1483
|
-
admin.Layouts.Header,
|
|
1484
|
-
{
|
|
1485
|
-
title: "Embedding Not Found",
|
|
1486
|
-
navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
|
|
1487
|
-
}
|
|
1488
|
-
),
|
|
1489
|
-
/* @__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." }) }) })
|
|
1490
|
-
] });
|
|
1491
|
-
}
|
|
1492
|
-
const headerTitle = isEditing ? `Edit: ${activeChunk.title}` : isChunkedDocument ? getOriginalTitle() : data.title || "Embedding Details";
|
|
1493
|
-
const headerSubtitle = isChunkedDocument ? `Chunked Document (${chunks.length} parts)` : `Embedding ID: ${data.embeddingId || "N/A"}`;
|
|
1494
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Main, { children: [
|
|
1495
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1496
|
-
admin.Layouts.Header,
|
|
1497
|
-
{
|
|
1498
|
-
title: headerTitle,
|
|
1499
|
-
subtitle: headerSubtitle,
|
|
1500
|
-
primaryAction: isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
|
1501
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}), onClick: handleCancelEdit, children: "Cancel" }),
|
|
1502
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}), onClick: handleSave, loading: isSaving, children: isSaving ? "Saving..." : "Save Chunk" })
|
|
1503
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
|
1504
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Button, { variant: "secondary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {}), onClick: handleStartEdit, children: [
|
|
1505
|
-
"Edit ",
|
|
1506
|
-
isChunkedDocument ? "Chunk" : ""
|
|
1507
|
-
] }),
|
|
1508
|
-
/* @__PURE__ */ jsxRuntime.jsx(ConfirmDeleteEmbedding, { onConfirm: handleDelete, isLoading: isDeleting })
|
|
1509
|
-
] }),
|
|
1510
|
-
navigationAction: /* @__PURE__ */ jsxRuntime.jsx(BackLink, { to: `/plugins/${index.PLUGIN_ID}` })
|
|
1511
|
-
}
|
|
1512
|
-
),
|
|
1513
|
-
/* @__PURE__ */ jsxRuntime.jsx(admin.Layouts.Content, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 8, children: [
|
|
1514
|
-
isChunkedDocument && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { background: "neutral0", padding: 4, hasRadius: true, children: [
|
|
1515
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 3, children: [
|
|
1516
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "beta", children: "Document Chunks" }),
|
|
1517
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { children: [
|
|
1518
|
-
chunks.length,
|
|
1519
|
-
" parts"
|
|
1520
|
-
] })
|
|
1521
|
-
] }),
|
|
1522
|
-
/* @__PURE__ */ jsxRuntime.jsx(ChunkTabsContainer, { gap: 0, children: chunks.map((chunk, index2) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1523
|
-
ChunkTab,
|
|
1524
|
-
{
|
|
1525
|
-
$isActive: index2 === activeChunkIndex,
|
|
1526
|
-
onClick: () => handleChunkSelect(index2),
|
|
1527
|
-
children: [
|
|
1528
|
-
"Part ",
|
|
1529
|
-
index2 + 1,
|
|
1530
|
-
index2 === activeChunkIndex && isEditing && " (editing)"
|
|
1531
|
-
]
|
|
1532
|
-
},
|
|
1533
|
-
chunk.documentId
|
|
1534
|
-
)) })
|
|
1535
|
-
] }) }),
|
|
1536
|
-
isEditing ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 6, children: [
|
|
1537
|
-
/* @__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: [
|
|
1538
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginBottom: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
|
|
1539
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Title" }),
|
|
1540
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1541
|
-
designSystem.TextInput,
|
|
1542
|
-
{
|
|
1543
|
-
value: editTitle,
|
|
1544
|
-
onChange: (e) => setEditTitle(e.target.value)
|
|
1545
|
-
}
|
|
1546
|
-
)
|
|
1547
|
-
] }) }),
|
|
1548
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginBottom: 4, children: [
|
|
1549
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
|
|
1550
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Content" }),
|
|
1551
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "Changes to content will regenerate the embedding vector" })
|
|
1552
|
-
] }),
|
|
1553
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1554
|
-
index.MarkdownEditor,
|
|
1555
|
-
{
|
|
1556
|
-
content: editContent,
|
|
1557
|
-
onChange: setEditContent,
|
|
1558
|
-
height: 300
|
|
1559
|
-
}
|
|
1560
|
-
)
|
|
1561
|
-
] })
|
|
1562
|
-
] }) }) }),
|
|
1563
|
-
/* @__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: [
|
|
1564
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Metadata (JSON)" }),
|
|
1565
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "Optional custom metadata" }),
|
|
1566
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1567
|
-
designSystem.Textarea,
|
|
1568
|
-
{
|
|
1569
|
-
value: editMetadata,
|
|
1570
|
-
onChange: (e) => setEditMetadata(e.target.value),
|
|
1571
|
-
placeholder: '{"key": "value"}'
|
|
1572
|
-
}
|
|
1573
|
-
)
|
|
1574
|
-
] }) }) }) }) })
|
|
1575
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Root, { gap: 6, children: [
|
|
1576
|
-
/* @__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: [
|
|
1577
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "center", marginBottom: 3, children: [
|
|
1578
|
-
/* @__PURE__ */ jsxRuntime.jsx(StyledTypography, { variant: "beta", style: { margin: 0 }, children: isChunkedDocument ? `Part ${activeChunkIndex + 1} Content` : "Embedding Content" }),
|
|
1579
|
-
isChunkedDocument && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
1580
|
-
activeChunk.content?.length || 0,
|
|
1581
|
-
" characters"
|
|
1582
|
-
] })
|
|
1583
|
-
] }),
|
|
1584
|
-
activeChunk.content ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: activeChunk.content }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: "No content" })
|
|
1585
|
-
] }) }) }),
|
|
1586
|
-
/* @__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: activeChunk }) }) })
|
|
1587
|
-
] })
|
|
1588
|
-
] }) })
|
|
1589
|
-
] });
|
|
1590
|
-
}
|
|
1591
|
-
const App = () => {
|
|
1592
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(reactRouterDom.Routes, { children: [
|
|
1593
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { index: true, element: /* @__PURE__ */ jsxRuntime.jsx(HomePage, {}) }),
|
|
1594
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "*", element: /* @__PURE__ */ jsxRuntime.jsx(admin.Page.Error, {}) }),
|
|
1595
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "/embeddings", element: /* @__PURE__ */ jsxRuntime.jsx(CreateEmbeddings, {}) }),
|
|
1596
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Route, { path: "/embeddings/:id", element: /* @__PURE__ */ jsxRuntime.jsx(EmbeddingDetails, {}) })
|
|
1597
|
-
] });
|
|
1598
|
-
};
|
|
1599
|
-
exports.App = App;
|
|
1600
|
-
//# sourceMappingURL=App-ByRBbkZn.js.map
|