@floegence/floe-webapp-core 0.27.2 → 0.27.4
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.
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createComponent as N } from "solid-js/web";
|
|
2
|
-
import { createMemo as x, createEffect as
|
|
3
|
-
import { createStore as
|
|
4
|
-
import { deferNonBlocking as
|
|
2
|
+
import { createMemo as x, createEffect as W, on as _, createSignal as I, useContext as O, createContext as V, batch as H } from "solid-js";
|
|
3
|
+
import { createStore as G, reconcile as S, produce as y } from "solid-js/store";
|
|
4
|
+
import { deferNonBlocking as h } from "../../utils/defer.js";
|
|
5
5
|
import { DEFAULT_VIRTUAL_LIST_CONFIG as J } from "./types.js";
|
|
6
|
-
const L =
|
|
7
|
-
function
|
|
8
|
-
const r =
|
|
6
|
+
const L = V();
|
|
7
|
+
function ue() {
|
|
8
|
+
const r = O(L);
|
|
9
9
|
if (!r)
|
|
10
10
|
throw new Error("useChatContext must be used within a ChatProvider");
|
|
11
11
|
return r;
|
|
@@ -18,16 +18,16 @@ const ge = (r) => {
|
|
|
18
18
|
maxAttachmentSize: 10485760,
|
|
19
19
|
// 10MB
|
|
20
20
|
...r.config
|
|
21
|
-
})),
|
|
21
|
+
})), d = x(() => ({
|
|
22
22
|
...J,
|
|
23
23
|
...r.config?.virtualList
|
|
24
|
-
})), [c, u] =
|
|
25
|
-
_(
|
|
24
|
+
})), [c, u] = G(r.initialMessages || []), U = /* @__PURE__ */ new Map();
|
|
25
|
+
W(_(() => r.initialMessages, (e) => {
|
|
26
26
|
e && e.length > 0 && u(S(e));
|
|
27
27
|
}, {
|
|
28
28
|
defer: !0
|
|
29
29
|
}));
|
|
30
|
-
const [w, A] = I(!1), [T, E] = I(!0), [v, b] = I(null), g = /* @__PURE__ */ new Map(), F = x(() => v() !== null),
|
|
30
|
+
const [w, A] = I(!1), [T, E] = I(!0), [v, b] = I(null), g = /* @__PURE__ */ new Map(), F = x(() => v() !== null), m = (e) => {
|
|
31
31
|
u(y((t) => {
|
|
32
32
|
t.push(e);
|
|
33
33
|
}));
|
|
@@ -62,7 +62,7 @@ const ge = (r) => {
|
|
|
62
62
|
status: "streaming",
|
|
63
63
|
timestamp: Date.now()
|
|
64
64
|
};
|
|
65
|
-
|
|
65
|
+
m(t), b(e.messageId);
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
68
|
case "block-start": {
|
|
@@ -118,7 +118,7 @@ const ge = (r) => {
|
|
|
118
118
|
streamingMessageId: v,
|
|
119
119
|
isWorking: F,
|
|
120
120
|
config: k,
|
|
121
|
-
virtualListConfig:
|
|
121
|
+
virtualListConfig: d,
|
|
122
122
|
sendMessage: async (e, t = []) => {
|
|
123
123
|
const s = {
|
|
124
124
|
id: crypto.randomUUID(),
|
|
@@ -128,24 +128,29 @@ const ge = (r) => {
|
|
|
128
128
|
timestamp: Date.now()
|
|
129
129
|
};
|
|
130
130
|
H(() => {
|
|
131
|
-
|
|
132
|
-
...
|
|
131
|
+
m(s), l(s.id, (i) => ({
|
|
132
|
+
...i,
|
|
133
133
|
status: "complete"
|
|
134
134
|
}));
|
|
135
135
|
});
|
|
136
|
+
try {
|
|
137
|
+
r.callbacks?.onWillSend?.(e, t);
|
|
138
|
+
} catch (i) {
|
|
139
|
+
console.error("onWillSend error:", i);
|
|
140
|
+
}
|
|
136
141
|
const o = r.callbacks?.onSendMessage;
|
|
137
142
|
if (!o) return;
|
|
138
143
|
const n = e, a = [...t];
|
|
139
|
-
|
|
140
|
-
Promise.resolve(o(n, a,
|
|
141
|
-
console.error("Failed to send message:",
|
|
144
|
+
h(() => {
|
|
145
|
+
Promise.resolve(o(n, a, m)).catch((i) => {
|
|
146
|
+
console.error("Failed to send message:", i);
|
|
142
147
|
});
|
|
143
148
|
});
|
|
144
149
|
},
|
|
145
150
|
loadMoreHistory: async () => {
|
|
146
151
|
if (w() || !T()) return;
|
|
147
152
|
const e = r.callbacks?.onLoadMore;
|
|
148
|
-
e && (A(!0),
|
|
153
|
+
e && (A(!0), h(() => {
|
|
149
154
|
Promise.resolve(e()).then((t) => {
|
|
150
155
|
if (t.length === 0) {
|
|
151
156
|
E(!1);
|
|
@@ -163,7 +168,7 @@ const ge = (r) => {
|
|
|
163
168
|
},
|
|
164
169
|
retryMessage: (e) => {
|
|
165
170
|
const t = r.callbacks?.onRetry;
|
|
166
|
-
t &&
|
|
171
|
+
t && h(() => {
|
|
167
172
|
try {
|
|
168
173
|
t(e);
|
|
169
174
|
} catch (s) {
|
|
@@ -171,7 +176,7 @@ const ge = (r) => {
|
|
|
171
176
|
}
|
|
172
177
|
});
|
|
173
178
|
},
|
|
174
|
-
addMessage:
|
|
179
|
+
addMessage: m,
|
|
175
180
|
updateMessage: l,
|
|
176
181
|
deleteMessage: P,
|
|
177
182
|
clearMessages: R,
|
|
@@ -213,7 +218,7 @@ const ge = (r) => {
|
|
|
213
218
|
})
|
|
214
219
|
}));
|
|
215
220
|
const o = r.callbacks?.onToolApproval;
|
|
216
|
-
o &&
|
|
221
|
+
o && h(() => {
|
|
217
222
|
Promise.resolve(o(e, t, s)).catch((n) => {
|
|
218
223
|
console.error("Failed to approve tool call:", n);
|
|
219
224
|
});
|
|
@@ -223,28 +228,28 @@ const ge = (r) => {
|
|
|
223
228
|
setMessageHeight: (e, t) => {
|
|
224
229
|
g.set(e, t);
|
|
225
230
|
},
|
|
226
|
-
getMessageHeight: (e) => g.get(e) ||
|
|
231
|
+
getMessageHeight: (e) => g.get(e) || d().defaultItemHeight,
|
|
227
232
|
toggleChecklistItem: (e, t, s) => {
|
|
228
233
|
let o = null;
|
|
229
234
|
l(e, (a) => {
|
|
230
|
-
const
|
|
235
|
+
const i = [...a.blocks], f = i[t];
|
|
231
236
|
if (f && f.type === "checklist") {
|
|
232
237
|
const q = f.items.map((p) => p.id === s ? (o = !p.checked, {
|
|
233
238
|
...p,
|
|
234
239
|
checked: o
|
|
235
240
|
}) : p);
|
|
236
|
-
|
|
241
|
+
i[t] = {
|
|
237
242
|
...f,
|
|
238
243
|
items: q
|
|
239
244
|
};
|
|
240
245
|
}
|
|
241
246
|
return {
|
|
242
247
|
...a,
|
|
243
|
-
blocks:
|
|
248
|
+
blocks: i
|
|
244
249
|
};
|
|
245
250
|
});
|
|
246
251
|
const n = r.callbacks?.onChecklistChange;
|
|
247
|
-
!n || o === null ||
|
|
252
|
+
!n || o === null || h(() => {
|
|
248
253
|
try {
|
|
249
254
|
n(e, t, s, o);
|
|
250
255
|
} catch (a) {
|
|
@@ -338,25 +343,25 @@ function K(r) {
|
|
|
338
343
|
}
|
|
339
344
|
}
|
|
340
345
|
function Q(r, k) {
|
|
341
|
-
const
|
|
346
|
+
const d = [];
|
|
342
347
|
for (const c of k)
|
|
343
|
-
c.type === "image" ?
|
|
348
|
+
c.type === "image" ? d.push({
|
|
344
349
|
type: "image",
|
|
345
350
|
src: c.url || c.preview || "",
|
|
346
351
|
alt: c.file.name
|
|
347
|
-
}) :
|
|
352
|
+
}) : d.push({
|
|
348
353
|
type: "file",
|
|
349
354
|
name: c.file.name,
|
|
350
355
|
size: c.file.size,
|
|
351
356
|
mimeType: c.file.type,
|
|
352
357
|
url: c.url
|
|
353
358
|
});
|
|
354
|
-
return r.trim() &&
|
|
359
|
+
return r.trim() && d.push({
|
|
355
360
|
type: "text",
|
|
356
361
|
content: r.trim()
|
|
357
|
-
}),
|
|
362
|
+
}), d;
|
|
358
363
|
}
|
|
359
364
|
export {
|
|
360
365
|
ge as ChatProvider,
|
|
361
|
-
|
|
366
|
+
ue as useChatContext
|
|
362
367
|
};
|
|
@@ -29,7 +29,7 @@ const ct = (u) => {
|
|
|
29
29
|
}, H = (t) => {
|
|
30
30
|
y(t.currentTarget.value), T();
|
|
31
31
|
}, B = (t) => {
|
|
32
|
-
t.key === "Enter" && !t.shiftKey && (t.preventDefault(), x());
|
|
32
|
+
t.isComposing || t.key === "Enter" && !t.shiftKey && (t.preventDefault(), x());
|
|
33
33
|
}, x = async () => {
|
|
34
34
|
if (!f()) return;
|
|
35
35
|
const t = g().trim(), o = n.attachments();
|
|
@@ -159,6 +159,7 @@ export interface ChatConfig {
|
|
|
159
159
|
maxAttachments?: number;
|
|
160
160
|
}
|
|
161
161
|
export interface ChatCallbacks {
|
|
162
|
+
onWillSend?: (content: string, attachments: Attachment[]) => void;
|
|
162
163
|
onSendMessage?: (content: string, attachments: Attachment[], addMessage: (msg: Message) => void) => Promise<void>;
|
|
163
164
|
onLoadMore?: () => Promise<Message[]>;
|
|
164
165
|
onRetry?: (messageId: string) => void;
|