@jfvilas/kwirth-plugin-chapete 0.1.1 → 0.1.3
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/front.js +75 -47
- package/package.json +2 -2
package/front.js
CHANGED
|
@@ -66,20 +66,20 @@
|
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
// kwirth-globals:@kwirthmagnify/kwirth-common-front
|
|
70
|
-
var
|
|
71
|
-
"kwirth-globals:@kwirthmagnify/kwirth-common-front
|
|
72
|
-
var _m = window.__kwirth__.
|
|
69
|
+
// kwirth-globals:@kwirthmagnify/kwirth-common-ai/front
|
|
70
|
+
var require_front = __commonJS({
|
|
71
|
+
"kwirth-globals:@kwirthmagnify/kwirth-common-ai/front"(exports, module) {
|
|
72
|
+
var _m = window.__kwirth__.kwirthCommonAiFront;
|
|
73
73
|
var _d = _m != null && "default" in Object(_m) ? _m.default : _m;
|
|
74
74
|
if (typeof _d !== "function" && _d != null && typeof _d.default !== "undefined") _d = _d.default;
|
|
75
75
|
module.exports = Object.assign({}, typeof _m === "object" && _m !== null ? _m : {}, { default: _d, __esModule: true });
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
// kwirth-globals:@kwirthmagnify/kwirth-common-
|
|
80
|
-
var
|
|
81
|
-
"kwirth-globals:@kwirthmagnify/kwirth-common-
|
|
82
|
-
var _m = window.__kwirth__.
|
|
79
|
+
// kwirth-globals:@kwirthmagnify/kwirth-common-front/icons
|
|
80
|
+
var require_icons = __commonJS({
|
|
81
|
+
"kwirth-globals:@kwirthmagnify/kwirth-common-front/icons"(exports, module) {
|
|
82
|
+
var _m = window.__kwirth__.MUI.icons;
|
|
83
83
|
var _d = _m != null && "default" in Object(_m) ? _m.default : _m;
|
|
84
84
|
if (typeof _d !== "function" && _d != null && typeof _d.default !== "undefined") _d = _d.default;
|
|
85
85
|
module.exports = Object.assign({}, typeof _m === "object" && _m !== null ? _m : {}, { default: _d, __esModule: true });
|
|
@@ -91,9 +91,8 @@
|
|
|
91
91
|
var import_kwirth_common2 = __toESM(require_kwirth_common(), 1);
|
|
92
92
|
|
|
93
93
|
// src/front/ChapeteSetup.tsx
|
|
94
|
-
var
|
|
95
|
-
var
|
|
96
|
-
var import_icons = __toESM(require_icons(), 1);
|
|
94
|
+
var import_react2 = __toESM(require_react(), 1);
|
|
95
|
+
var import_material2 = __toESM(require_material(), 1);
|
|
97
96
|
var import_front = __toESM(require_front(), 1);
|
|
98
97
|
|
|
99
98
|
// src/front/ChapeteConfig.ts
|
|
@@ -106,18 +105,33 @@
|
|
|
106
105
|
}
|
|
107
106
|
};
|
|
108
107
|
|
|
108
|
+
// src/front/icons.tsx
|
|
109
|
+
var import_react = __toESM(require_react(), 1);
|
|
110
|
+
var import_material = __toESM(require_material(), 1);
|
|
111
|
+
var ChapeteThought = (props) => /* @__PURE__ */ import_react.default.createElement(import_material.SvgIcon, { ...props, viewBox: "0 0 24 24" }, /* @__PURE__ */ import_react.default.createElement(
|
|
112
|
+
"path",
|
|
113
|
+
{
|
|
114
|
+
d: "M6 14A3 3 0 0 1 5.2 8.2A3.6 3.6 0 0 1 11.6 5.6A3.5 3.5 0 0 1 18.2 7.6A3.05 3.05 0 0 1 17.6 13.6A12 12 0 0 1 6 14Z",
|
|
115
|
+
fill: "none",
|
|
116
|
+
stroke: "currentColor",
|
|
117
|
+
strokeWidth: 2,
|
|
118
|
+
strokeLinecap: "round",
|
|
119
|
+
strokeLinejoin: "round"
|
|
120
|
+
}
|
|
121
|
+
), /* @__PURE__ */ import_react.default.createElement("circle", { cx: "18.6", cy: "17.4", r: "1.6", fill: "currentColor" }), /* @__PURE__ */ import_react.default.createElement("circle", { cx: "21.3", cy: "20.7", r: "1.05", fill: "currentColor" }));
|
|
122
|
+
|
|
109
123
|
// src/front/ChapeteSetup.tsx
|
|
110
|
-
var ChapeteIcon = /* @__PURE__ */
|
|
124
|
+
var ChapeteIcon = /* @__PURE__ */ import_react2.default.createElement(ChapeteThought, null);
|
|
111
125
|
var ChapeteSetup = (props) => {
|
|
112
126
|
const instanceConfig = props.setupConfig?.channelInstanceConfig || new ChapeteInstanceConfig();
|
|
113
127
|
const config = props.setupConfig?.channelConfig || new ChapeteConfig();
|
|
114
|
-
const [llms, setLlms] = (0,
|
|
115
|
-
const [loading, setLoading] = (0,
|
|
116
|
-
const [loadError, setLoadError] = (0,
|
|
117
|
-
const [llmId, setLlmId] = (0,
|
|
118
|
-
const [temperature, setTemperature] = (0,
|
|
119
|
-
const defaultRef = (0,
|
|
120
|
-
(0,
|
|
128
|
+
const [llms, setLlms] = (0, import_react2.useState)([]);
|
|
129
|
+
const [loading, setLoading] = (0, import_react2.useState)(true);
|
|
130
|
+
const [loadError, setLoadError] = (0, import_react2.useState)("");
|
|
131
|
+
const [llmId, setLlmId] = (0, import_react2.useState)(instanceConfig.llmId);
|
|
132
|
+
const [temperature, setTemperature] = (0, import_react2.useState)(instanceConfig.temperature);
|
|
133
|
+
const defaultRef = (0, import_react2.useRef)(null);
|
|
134
|
+
(0, import_react2.useEffect)(() => {
|
|
121
135
|
const load = async () => {
|
|
122
136
|
try {
|
|
123
137
|
const response = await fetch(`${props.channelObject.clusterUrl}/core/aiconfig/llms`, {
|
|
@@ -166,8 +180,8 @@
|
|
|
166
180
|
channelInstanceConfig: void 0
|
|
167
181
|
}, false, false);
|
|
168
182
|
};
|
|
169
|
-
return /* @__PURE__ */
|
|
170
|
-
|
|
183
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_material2.Dialog, { open: true, maxWidth: false, sx: { "& .MuiDialog-paper": { width: "34vw", maxWidth: "34vw", height: "38vh", maxHeight: "38vh" } } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.DialogTitle, null, "Configure Chapete channel"), /* @__PURE__ */ import_react2.default.createElement(import_material2.DialogContent, { sx: { display: "flex", flexDirection: "column", overflow: "hidden" } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "column", spacing: 2, sx: { m: 1, flex: 1, minHeight: 0 } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { variant: "body2", color: loadError || noLlms ? "warning.main" : "text.secondary" }, statusText()), /* @__PURE__ */ import_react2.default.createElement(import_front.LlmSelector, { llms, value: llmId, onChange: selectLlm, label: "LLM" }), /* @__PURE__ */ import_react2.default.createElement(
|
|
184
|
+
import_material2.TextField,
|
|
171
185
|
{
|
|
172
186
|
value: temperature,
|
|
173
187
|
onChange: (e) => setTemperature(+e.target.value),
|
|
@@ -180,12 +194,12 @@
|
|
|
180
194
|
helperText: invalidTemperature() ? "From 0 to 2" : "Lower is more precise, higher is more creative",
|
|
181
195
|
fullWidth: true
|
|
182
196
|
}
|
|
183
|
-
))), /* @__PURE__ */
|
|
197
|
+
))), /* @__PURE__ */ import_react2.default.createElement(import_material2.DialogActions, null, /* @__PURE__ */ import_react2.default.createElement(import_material2.FormControlLabel, { control: /* @__PURE__ */ import_react2.default.createElement(import_material2.Checkbox, { slotProps: { input: { ref: defaultRef } } }), label: "Set as default", sx: { width: "100%", ml: "8px" } }), /* @__PURE__ */ import_react2.default.createElement(import_material2.Button, { variant: "outlined", onClick: ok, disabled: llmId === "" || invalidTemperature() }, "OK"), /* @__PURE__ */ import_react2.default.createElement(import_material2.Button, { variant: "outlined", onClick: cancel }, "CANCEL")));
|
|
184
198
|
};
|
|
185
199
|
|
|
186
200
|
// src/front/ChapeteTabContent.tsx
|
|
187
|
-
var
|
|
188
|
-
var
|
|
201
|
+
var import_react4 = __toESM(require_react(), 1);
|
|
202
|
+
var import_material4 = __toESM(require_material(), 1);
|
|
189
203
|
var import_kwirth_common = __toESM(require_kwirth_common(), 1);
|
|
190
204
|
var import_kwirth_common_front = __toESM(require_kwirth_common_front(), 1);
|
|
191
205
|
var import_icons2 = __toESM(require_icons(), 1);
|
|
@@ -228,16 +242,16 @@
|
|
|
228
242
|
};
|
|
229
243
|
|
|
230
244
|
// src/front/ChapeteSystemDialog.tsx
|
|
231
|
-
var
|
|
232
|
-
var
|
|
245
|
+
var import_react3 = __toESM(require_react(), 1);
|
|
246
|
+
var import_material3 = __toESM(require_material(), 1);
|
|
233
247
|
var ChapeteSystemDialog = (props) => {
|
|
234
|
-
const [system, setSystem] = (0,
|
|
248
|
+
const [system, setSystem] = (0, import_react3.useState)(props.system);
|
|
235
249
|
const save = () => {
|
|
236
250
|
props.onSave(system);
|
|
237
251
|
props.onClose();
|
|
238
252
|
};
|
|
239
|
-
return /* @__PURE__ */
|
|
240
|
-
|
|
253
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_material3.Dialog, { open: true, maxWidth: false, sx: { "& .MuiDialog-paper": { width: "44vw", maxWidth: "44vw", height: "52vh", maxHeight: "52vh" } } }, /* @__PURE__ */ import_react3.default.createElement(import_material3.DialogTitle, null, "Chapete system prompt"), /* @__PURE__ */ import_react3.default.createElement(import_material3.DialogContent, { sx: { display: "flex", flexDirection: "column", overflow: "hidden" } }, /* @__PURE__ */ import_react3.default.createElement(import_material3.Stack, { direction: "column", spacing: 2, sx: { m: 1, flex: 1, minHeight: 0 } }, /* @__PURE__ */ import_react3.default.createElement(import_material3.Typography, { variant: "body2", color: "text.secondary" }, "What the model is told before every conversation. It is shared by everyone using this channel, and it applies from the next question on. Leave it empty to use the default one."), /* @__PURE__ */ import_react3.default.createElement(
|
|
254
|
+
import_material3.TextField,
|
|
241
255
|
{
|
|
242
256
|
value: system,
|
|
243
257
|
onChange: (e) => setSystem(e.target.value),
|
|
@@ -248,20 +262,20 @@
|
|
|
248
262
|
fullWidth: true,
|
|
249
263
|
sx: { flex: 1, minHeight: 0, "& .MuiInputBase-root": { height: "100%", alignItems: "flex-start", overflow: "auto" } }
|
|
250
264
|
}
|
|
251
|
-
))), /* @__PURE__ */
|
|
265
|
+
))), /* @__PURE__ */ import_react3.default.createElement(import_material3.DialogActions, null, /* @__PURE__ */ import_react3.default.createElement(import_material3.Button, { variant: "outlined", onClick: save }, "SAVE"), /* @__PURE__ */ import_react3.default.createElement(import_material3.Button, { variant: "outlined", onClick: props.onClose }, "CANCEL")));
|
|
252
266
|
};
|
|
253
267
|
|
|
254
268
|
// src/front/ChapeteTabContent.tsx
|
|
255
269
|
var ChapeteTabContent = (props) => {
|
|
256
270
|
const data = props.channelObject.data;
|
|
257
271
|
const instanceConfig = props.channelObject.instanceConfig;
|
|
258
|
-
const [, forceRender] = (0,
|
|
259
|
-
const [systemOpen, setSystemOpen] = (0,
|
|
260
|
-
const containerRef = (0,
|
|
261
|
-
const [containerHeight, setContainerHeight] = (0,
|
|
262
|
-
const bottomRef = (0,
|
|
272
|
+
const [, forceRender] = (0, import_react4.useState)(0);
|
|
273
|
+
const [systemOpen, setSystemOpen] = (0, import_react4.useState)(false);
|
|
274
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
275
|
+
const [containerHeight, setContainerHeight] = (0, import_react4.useState)(0);
|
|
276
|
+
const bottomRef = (0, import_react4.useRef)(null);
|
|
263
277
|
const refresh = () => forceRender((n) => n + 1);
|
|
264
|
-
(0,
|
|
278
|
+
(0, import_react4.useEffect)(() => {
|
|
265
279
|
const observer = new ResizeObserver(() => {
|
|
266
280
|
if (!containerRef.current) return;
|
|
267
281
|
setContainerHeight(window.innerHeight - containerRef.current.getBoundingClientRect().top);
|
|
@@ -269,7 +283,13 @@
|
|
|
269
283
|
observer.observe(document.body);
|
|
270
284
|
return () => observer.disconnect();
|
|
271
285
|
}, [containerRef.current]);
|
|
272
|
-
(0,
|
|
286
|
+
const [notStartedTop, setNotStartedTop] = (0, import_react4.useState)(0);
|
|
287
|
+
(0, import_react4.useEffect)(() => {
|
|
288
|
+
if (data.started || !containerRef.current) return;
|
|
289
|
+
const top = containerRef.current.getBoundingClientRect().top;
|
|
290
|
+
if (top !== notStartedTop) setNotStartedTop(top);
|
|
291
|
+
});
|
|
292
|
+
(0, import_react4.useEffect)(() => {
|
|
273
293
|
bottomRef.current?.scrollIntoView({ block: "end" });
|
|
274
294
|
}, [data.entries.length, data.entries[data.entries.length - 1]?.pendingId]);
|
|
275
295
|
const thinking = isThinking(data.entries);
|
|
@@ -318,24 +338,32 @@
|
|
|
318
338
|
};
|
|
319
339
|
const bubble = (entry, index) => {
|
|
320
340
|
const user = entry.role === "user" /* USER */;
|
|
321
|
-
return /* @__PURE__ */
|
|
322
|
-
|
|
341
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { key: index, direction: "row", justifyContent: user ? "flex-end" : "flex-start", sx: { mb: 1.5 } }, /* @__PURE__ */ import_react4.default.createElement(
|
|
342
|
+
import_material4.Paper,
|
|
323
343
|
{
|
|
324
344
|
variant: "outlined",
|
|
325
345
|
"data-testid": user ? "chapete-user" : "chapete-assistant",
|
|
326
346
|
sx: { maxWidth: "80%", px: 1.5, py: 1, bgcolor: user ? "action.hover" : "background.paper", borderColor: entry.error ? "error.main" : void 0 }
|
|
327
347
|
},
|
|
328
|
-
user && /* @__PURE__ */
|
|
329
|
-
!user && entry.pendingId !== void 0 && /* @__PURE__ */
|
|
330
|
-
!user && entry.pendingId === void 0 && entry.error && /* @__PURE__ */
|
|
331
|
-
!user && entry.pendingId === void 0 && !entry.error && /* @__PURE__ */
|
|
348
|
+
user && /* @__PURE__ */ import_react4.default.createElement(import_material4.Typography, { variant: "body2", sx: { whiteSpace: "pre-wrap", wordBreak: "break-word" } }, entry.content),
|
|
349
|
+
!user && entry.pendingId !== void 0 && /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { direction: "row", spacing: 1, alignItems: "center" }, /* @__PURE__ */ import_react4.default.createElement(import_material4.CircularProgress, { size: 14 }), /* @__PURE__ */ import_react4.default.createElement(import_material4.Typography, { variant: "body2", color: "text.secondary", sx: { fontStyle: "italic" } }, "Thinking...")),
|
|
350
|
+
!user && entry.pendingId === void 0 && entry.error && /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { direction: "row", spacing: 1, alignItems: "flex-start" }, /* @__PURE__ */ import_react4.default.createElement(import_icons2.Warning, { fontSize: "small", color: "error" }), /* @__PURE__ */ import_react4.default.createElement(import_material4.Typography, { variant: "body2", color: "error", sx: { whiteSpace: "pre-wrap", wordBreak: "break-word" } }, entry.usageLimit ? `Usage limit reached. ${entry.content}` : entry.content)),
|
|
351
|
+
!user && entry.pendingId === void 0 && !entry.error && /* @__PURE__ */ import_react4.default.createElement(import_material4.Box, null, /* @__PURE__ */ import_react4.default.createElement(import_kwirth_common_front.MarkdownViewer, { content: entry.content }), /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { direction: "row", justifyContent: "flex-end" }, /* @__PURE__ */ import_react4.default.createElement(import_material4.Tooltip, { title: "Copy answer" }, /* @__PURE__ */ import_react4.default.createElement(import_material4.IconButton, { size: "small", "aria-label": "Copy answer", onClick: () => copy(entry.content) }, /* @__PURE__ */ import_react4.default.createElement(import_icons2.ContentCopy, { fontSize: "small" })))))
|
|
332
352
|
));
|
|
333
353
|
};
|
|
334
354
|
if (!data.started) {
|
|
335
|
-
return /* @__PURE__ */
|
|
355
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { ref: containerRef, alignItems: "center", justifyContent: "center", sx: { flex: 1, width: "100%", minHeight: `calc(100vh - ${notStartedTop}px - 8px)`, px: 4 } }, /* @__PURE__ */ import_react4.default.createElement(
|
|
356
|
+
import_kwirth_common_front.ChannelNotStarted,
|
|
357
|
+
{
|
|
358
|
+
icon: /* @__PURE__ */ import_react4.default.createElement(ChapeteThought, { color: "primary" }),
|
|
359
|
+
name: "Chapete",
|
|
360
|
+
hint: "Chapete not started. Start the channel to pick an LLM and start chatting.",
|
|
361
|
+
channelObject: props.channelObject
|
|
362
|
+
}
|
|
363
|
+
));
|
|
336
364
|
}
|
|
337
|
-
return /* @__PURE__ */
|
|
338
|
-
|
|
365
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_material4.Box, { ref: containerRef, sx: { display: "flex", flexDirection: "column", width: "100%", height: `${containerHeight}px`, p: 1, boxSizing: "border-box" } }, /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { direction: "row", alignItems: "center", spacing: 1, sx: { px: 1, pb: 1 } }, /* @__PURE__ */ import_react4.default.createElement(import_material4.Chip, { label: `LLM: ${instanceConfig?.llmId || "(none)"}`, size: "small", variant: "outlined" }), /* @__PURE__ */ import_react4.default.createElement(import_material4.Chip, { label: `Temperature: ${instanceConfig?.temperature ?? "-"}`, size: "small", variant: "outlined" }), /* @__PURE__ */ import_react4.default.createElement(import_material4.Box, { sx: { flex: 1 } }), /* @__PURE__ */ import_react4.default.createElement(import_material4.Tooltip, { title: "Start a new conversation" }, /* @__PURE__ */ import_react4.default.createElement("span", null, /* @__PURE__ */ import_react4.default.createElement(import_material4.IconButton, { size: "small", "aria-label": "New chat", onClick: newChat, disabled: data.entries.length === 0 || thinking }, /* @__PURE__ */ import_react4.default.createElement(import_icons2.Add, { fontSize: "small" })))), /* @__PURE__ */ import_react4.default.createElement(import_material4.Tooltip, { title: "System prompt of the channel" }, /* @__PURE__ */ import_react4.default.createElement(import_material4.IconButton, { size: "small", "aria-label": "System prompt", onClick: () => setSystemOpen(true) }, /* @__PURE__ */ import_react4.default.createElement(import_icons2.Settings, { fontSize: "small" })))), /* @__PURE__ */ import_react4.default.createElement(import_material4.Box, { sx: { flex: 1, minHeight: 0, overflowY: "auto", px: 1 } }, data.entries.length === 0 && /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { alignItems: "center", justifyContent: "center", sx: { height: "100%" } }, /* @__PURE__ */ import_react4.default.createElement(import_material4.Typography, { variant: "body2", color: "text.secondary" }, "Ask anything. Enter sends, Shift+Enter adds a new line.")), data.entries.map((entry, index) => bubble(entry, index)), data.signals.map((s, index) => /* @__PURE__ */ import_react4.default.createElement(import_material4.Typography, { key: `s${index}`, variant: "caption", color: "text.secondary", component: "div" }, "*** ", s, " ***")), /* @__PURE__ */ import_react4.default.createElement("div", { ref: bottomRef })), /* @__PURE__ */ import_react4.default.createElement(import_material4.Stack, { direction: "row", spacing: 1, alignItems: "flex-end", sx: { pt: 1 } }, /* @__PURE__ */ import_react4.default.createElement(
|
|
366
|
+
import_material4.TextField,
|
|
339
367
|
{
|
|
340
368
|
value: data.draft,
|
|
341
369
|
onChange: (e) => {
|
|
@@ -351,7 +379,7 @@
|
|
|
351
379
|
disabled: thinking,
|
|
352
380
|
slotProps: { htmlInput: { "aria-label": "Message" } }
|
|
353
381
|
}
|
|
354
|
-
), /* @__PURE__ */
|
|
382
|
+
), /* @__PURE__ */ import_react4.default.createElement(import_material4.Button, { variant: "contained", startIcon: /* @__PURE__ */ import_react4.default.createElement(import_icons2.Send, null), onClick: send, disabled: !canSend() }, "SEND")), systemOpen && /* @__PURE__ */ import_react4.default.createElement(ChapeteSystemDialog, { system: data.system, onSave: saveSystem, onClose: () => setSystemOpen(false) }));
|
|
355
383
|
};
|
|
356
384
|
|
|
357
385
|
// src/front/ChapeteChannel.tsx
|
package/package.json
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"name": "@jfvilas/kwirth-plugin-chapete",
|
|
4
4
|
"displayName": "Chapete",
|
|
5
5
|
"extensionType": "plugin",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.3",
|
|
7
7
|
"description": "Chat with an LLM from Kwirth, using the LLMs configured in the core",
|
|
8
|
-
"icon": "
|
|
8
|
+
"icon": "<svg viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 14A3 3 0 0 1 5.2 8.2A3.6 3.6 0 0 1 11.6 5.6A3.5 3.5 0 0 1 18.2 7.6A3.05 3.05 0 0 1 17.6 13.6A12 12 0 0 1 6 14Z'/><circle cx='18.6' cy='17.4' r='1.6' fill='currentColor' stroke='none'/><circle cx='21.3' cy='20.7' r='1.05' fill='currentColor' stroke='none'/></svg>",
|
|
9
9
|
"website": "https://kwirthmagnify.dev",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|