@aparte/svelte 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1344 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/aparteChat.d.ts +48 -0
- package/dist/stores/aparteChat.d.ts.map +1 -0
- package/dist/stores/aparteClient.d.ts +11 -0
- package/dist/stores/aparteClient.d.ts.map +1 -0
- package/dist/stores/conversationManager.d.ts +23 -0
- package/dist/stores/conversationManager.d.ts.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +63 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1344 @@
|
|
|
1
|
+
import { SvelteComponent, init, safe_not_equal, compute_slots, ensure_array_like, create_slot, detach, transition_out, transition_in, group_outros, check_outros, update_keyed_each, outro_and_destroy_block, set_custom_element_data, update_slot_base, get_all_dirty_from_scope, get_slot_changes, attr, toggle_class, insert, append, listen, element, space, binding_callbacks, empty, noop, set_style } from "svelte/internal";
|
|
2
|
+
import "svelte/internal/disclose-version";
|
|
3
|
+
import { createEventDispatcher, onMount, onDestroy, tick } from "svelte";
|
|
4
|
+
import { AparteChatHost, AparteClient, ConversationManager, AparteConfig, DEFAULT_UI_EVENTS, applyElementProps } from "@aparte/core";
|
|
5
|
+
import { writable, derived } from "svelte/store";
|
|
6
|
+
const get_footer_right_slot_changes = (dirty) => ({});
|
|
7
|
+
const get_footer_right_slot_context = (ctx) => ({});
|
|
8
|
+
const get_footer_center_slot_changes = (dirty) => ({});
|
|
9
|
+
const get_footer_center_slot_context = (ctx) => ({});
|
|
10
|
+
const get_footer_left_slot_changes = (dirty) => ({});
|
|
11
|
+
const get_footer_left_slot_context = (ctx) => ({});
|
|
12
|
+
const get_composer_slot_changes = (dirty) => ({});
|
|
13
|
+
const get_composer_slot_context = (ctx) => ({});
|
|
14
|
+
const get_above_composer_slot_changes = (dirty) => ({});
|
|
15
|
+
const get_above_composer_slot_context = (ctx) => ({});
|
|
16
|
+
function get_each_context(ctx, list, i) {
|
|
17
|
+
const child_ctx = ctx.slice();
|
|
18
|
+
child_ctx[51] = list[i];
|
|
19
|
+
return child_ctx;
|
|
20
|
+
}
|
|
21
|
+
const get_bubble_slot_changes = (dirty) => ({
|
|
22
|
+
message: dirty[0] & /*internalMessages*/
|
|
23
|
+
16
|
|
24
|
+
});
|
|
25
|
+
const get_bubble_slot_context = (ctx) => ({ message: (
|
|
26
|
+
/*m*/
|
|
27
|
+
ctx[51]
|
|
28
|
+
) });
|
|
29
|
+
const get_empty_state_slot_changes = (dirty) => ({});
|
|
30
|
+
const get_empty_state_slot_context = (ctx) => ({});
|
|
31
|
+
function create_if_block_1(ctx) {
|
|
32
|
+
let current;
|
|
33
|
+
const empty_state_slot_template = (
|
|
34
|
+
/*#slots*/
|
|
35
|
+
ctx[43]["empty-state"]
|
|
36
|
+
);
|
|
37
|
+
const empty_state_slot = create_slot(
|
|
38
|
+
empty_state_slot_template,
|
|
39
|
+
ctx,
|
|
40
|
+
/*$$scope*/
|
|
41
|
+
ctx[42],
|
|
42
|
+
get_empty_state_slot_context
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
c() {
|
|
46
|
+
if (empty_state_slot) empty_state_slot.c();
|
|
47
|
+
},
|
|
48
|
+
m(target, anchor) {
|
|
49
|
+
if (empty_state_slot) {
|
|
50
|
+
empty_state_slot.m(target, anchor);
|
|
51
|
+
}
|
|
52
|
+
current = true;
|
|
53
|
+
},
|
|
54
|
+
p(ctx2, dirty) {
|
|
55
|
+
if (empty_state_slot) {
|
|
56
|
+
if (empty_state_slot.p && (!current || dirty[1] & /*$$scope*/
|
|
57
|
+
2048)) {
|
|
58
|
+
update_slot_base(
|
|
59
|
+
empty_state_slot,
|
|
60
|
+
empty_state_slot_template,
|
|
61
|
+
ctx2,
|
|
62
|
+
/*$$scope*/
|
|
63
|
+
ctx2[42],
|
|
64
|
+
!current ? get_all_dirty_from_scope(
|
|
65
|
+
/*$$scope*/
|
|
66
|
+
ctx2[42]
|
|
67
|
+
) : get_slot_changes(
|
|
68
|
+
empty_state_slot_template,
|
|
69
|
+
/*$$scope*/
|
|
70
|
+
ctx2[42],
|
|
71
|
+
dirty,
|
|
72
|
+
get_empty_state_slot_changes
|
|
73
|
+
),
|
|
74
|
+
get_empty_state_slot_context
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
i(local) {
|
|
80
|
+
if (current) return;
|
|
81
|
+
transition_in(empty_state_slot, local);
|
|
82
|
+
current = true;
|
|
83
|
+
},
|
|
84
|
+
o(local) {
|
|
85
|
+
transition_out(empty_state_slot, local);
|
|
86
|
+
current = false;
|
|
87
|
+
},
|
|
88
|
+
d(detaching) {
|
|
89
|
+
if (empty_state_slot) empty_state_slot.d(detaching);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function fallback_block_1(ctx) {
|
|
94
|
+
let aparte_chat_bubble;
|
|
95
|
+
let aparte_chat_bubble_message_id_value;
|
|
96
|
+
let aparte_chat_bubble_data_role_value;
|
|
97
|
+
let aparte_chat_bubble_timestamp_value;
|
|
98
|
+
let aparte_chat_bubble_content_value;
|
|
99
|
+
let aparte_chat_bubble_streaming_value;
|
|
100
|
+
return {
|
|
101
|
+
c() {
|
|
102
|
+
aparte_chat_bubble = element("aparte-chat-bubble");
|
|
103
|
+
set_custom_element_data(aparte_chat_bubble, "message-id", aparte_chat_bubble_message_id_value = /*m*/
|
|
104
|
+
ctx[51].id);
|
|
105
|
+
set_custom_element_data(aparte_chat_bubble, "data-role", aparte_chat_bubble_data_role_value = /*m*/
|
|
106
|
+
ctx[51].role);
|
|
107
|
+
set_custom_element_data(aparte_chat_bubble, "timestamp", aparte_chat_bubble_timestamp_value = /*m*/
|
|
108
|
+
ctx[51].timestamp);
|
|
109
|
+
set_custom_element_data(aparte_chat_bubble, "content", aparte_chat_bubble_content_value = /*m*/
|
|
110
|
+
ctx[51].content);
|
|
111
|
+
set_custom_element_data(aparte_chat_bubble, "streaming", aparte_chat_bubble_streaming_value = /*m*/
|
|
112
|
+
ctx[51].status === "streaming" || /*m*/
|
|
113
|
+
ctx[51].status === "pending" ? "" : null);
|
|
114
|
+
},
|
|
115
|
+
m(target, anchor) {
|
|
116
|
+
insert(target, aparte_chat_bubble, anchor);
|
|
117
|
+
},
|
|
118
|
+
p(ctx2, dirty) {
|
|
119
|
+
if (dirty[0] & /*internalMessages*/
|
|
120
|
+
16 && aparte_chat_bubble_message_id_value !== (aparte_chat_bubble_message_id_value = /*m*/
|
|
121
|
+
ctx2[51].id)) {
|
|
122
|
+
set_custom_element_data(aparte_chat_bubble, "message-id", aparte_chat_bubble_message_id_value);
|
|
123
|
+
}
|
|
124
|
+
if (dirty[0] & /*internalMessages*/
|
|
125
|
+
16 && aparte_chat_bubble_data_role_value !== (aparte_chat_bubble_data_role_value = /*m*/
|
|
126
|
+
ctx2[51].role)) {
|
|
127
|
+
set_custom_element_data(aparte_chat_bubble, "data-role", aparte_chat_bubble_data_role_value);
|
|
128
|
+
}
|
|
129
|
+
if (dirty[0] & /*internalMessages*/
|
|
130
|
+
16 && aparte_chat_bubble_timestamp_value !== (aparte_chat_bubble_timestamp_value = /*m*/
|
|
131
|
+
ctx2[51].timestamp)) {
|
|
132
|
+
set_custom_element_data(aparte_chat_bubble, "timestamp", aparte_chat_bubble_timestamp_value);
|
|
133
|
+
}
|
|
134
|
+
if (dirty[0] & /*internalMessages*/
|
|
135
|
+
16 && aparte_chat_bubble_content_value !== (aparte_chat_bubble_content_value = /*m*/
|
|
136
|
+
ctx2[51].content)) {
|
|
137
|
+
set_custom_element_data(aparte_chat_bubble, "content", aparte_chat_bubble_content_value);
|
|
138
|
+
}
|
|
139
|
+
if (dirty[0] & /*internalMessages*/
|
|
140
|
+
16 && aparte_chat_bubble_streaming_value !== (aparte_chat_bubble_streaming_value = /*m*/
|
|
141
|
+
ctx2[51].status === "streaming" || /*m*/
|
|
142
|
+
ctx2[51].status === "pending" ? "" : null)) {
|
|
143
|
+
set_custom_element_data(aparte_chat_bubble, "streaming", aparte_chat_bubble_streaming_value);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
d(detaching) {
|
|
147
|
+
if (detaching) {
|
|
148
|
+
detach(aparte_chat_bubble);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function create_each_block(key_1, ctx) {
|
|
154
|
+
let first;
|
|
155
|
+
let current;
|
|
156
|
+
const bubble_slot_template = (
|
|
157
|
+
/*#slots*/
|
|
158
|
+
ctx[43].bubble
|
|
159
|
+
);
|
|
160
|
+
const bubble_slot = create_slot(
|
|
161
|
+
bubble_slot_template,
|
|
162
|
+
ctx,
|
|
163
|
+
/*$$scope*/
|
|
164
|
+
ctx[42],
|
|
165
|
+
get_bubble_slot_context
|
|
166
|
+
);
|
|
167
|
+
const bubble_slot_or_fallback = bubble_slot || fallback_block_1(ctx);
|
|
168
|
+
return {
|
|
169
|
+
key: key_1,
|
|
170
|
+
first: null,
|
|
171
|
+
c() {
|
|
172
|
+
first = empty();
|
|
173
|
+
if (bubble_slot_or_fallback) bubble_slot_or_fallback.c();
|
|
174
|
+
this.first = first;
|
|
175
|
+
},
|
|
176
|
+
m(target, anchor) {
|
|
177
|
+
insert(target, first, anchor);
|
|
178
|
+
if (bubble_slot_or_fallback) {
|
|
179
|
+
bubble_slot_or_fallback.m(target, anchor);
|
|
180
|
+
}
|
|
181
|
+
current = true;
|
|
182
|
+
},
|
|
183
|
+
p(new_ctx, dirty) {
|
|
184
|
+
ctx = new_ctx;
|
|
185
|
+
if (bubble_slot) {
|
|
186
|
+
if (bubble_slot.p && (!current || dirty[0] & /*internalMessages*/
|
|
187
|
+
16 | dirty[1] & /*$$scope*/
|
|
188
|
+
2048)) {
|
|
189
|
+
update_slot_base(
|
|
190
|
+
bubble_slot,
|
|
191
|
+
bubble_slot_template,
|
|
192
|
+
ctx,
|
|
193
|
+
/*$$scope*/
|
|
194
|
+
ctx[42],
|
|
195
|
+
!current ? get_all_dirty_from_scope(
|
|
196
|
+
/*$$scope*/
|
|
197
|
+
ctx[42]
|
|
198
|
+
) : get_slot_changes(
|
|
199
|
+
bubble_slot_template,
|
|
200
|
+
/*$$scope*/
|
|
201
|
+
ctx[42],
|
|
202
|
+
dirty,
|
|
203
|
+
get_bubble_slot_changes
|
|
204
|
+
),
|
|
205
|
+
get_bubble_slot_context
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
if (bubble_slot_or_fallback && bubble_slot_or_fallback.p && (!current || dirty[0] & /*internalMessages*/
|
|
210
|
+
16)) {
|
|
211
|
+
bubble_slot_or_fallback.p(ctx, !current ? [-1, -1] : dirty);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
i(local) {
|
|
216
|
+
if (current) return;
|
|
217
|
+
transition_in(bubble_slot_or_fallback, local);
|
|
218
|
+
current = true;
|
|
219
|
+
},
|
|
220
|
+
o(local) {
|
|
221
|
+
transition_out(bubble_slot_or_fallback, local);
|
|
222
|
+
current = false;
|
|
223
|
+
},
|
|
224
|
+
d(detaching) {
|
|
225
|
+
if (detaching) {
|
|
226
|
+
detach(first);
|
|
227
|
+
}
|
|
228
|
+
if (bubble_slot_or_fallback) bubble_slot_or_fallback.d(detaching);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function create_if_block(ctx) {
|
|
233
|
+
let div;
|
|
234
|
+
let t0;
|
|
235
|
+
let t1;
|
|
236
|
+
let current;
|
|
237
|
+
const footer_left_slot_template = (
|
|
238
|
+
/*#slots*/
|
|
239
|
+
ctx[43]["footer-left"]
|
|
240
|
+
);
|
|
241
|
+
const footer_left_slot = create_slot(
|
|
242
|
+
footer_left_slot_template,
|
|
243
|
+
ctx,
|
|
244
|
+
/*$$scope*/
|
|
245
|
+
ctx[42],
|
|
246
|
+
get_footer_left_slot_context
|
|
247
|
+
);
|
|
248
|
+
const footer_center_slot_template = (
|
|
249
|
+
/*#slots*/
|
|
250
|
+
ctx[43]["footer-center"]
|
|
251
|
+
);
|
|
252
|
+
const footer_center_slot = create_slot(
|
|
253
|
+
footer_center_slot_template,
|
|
254
|
+
ctx,
|
|
255
|
+
/*$$scope*/
|
|
256
|
+
ctx[42],
|
|
257
|
+
get_footer_center_slot_context
|
|
258
|
+
);
|
|
259
|
+
const footer_right_slot_template = (
|
|
260
|
+
/*#slots*/
|
|
261
|
+
ctx[43]["footer-right"]
|
|
262
|
+
);
|
|
263
|
+
const footer_right_slot = create_slot(
|
|
264
|
+
footer_right_slot_template,
|
|
265
|
+
ctx,
|
|
266
|
+
/*$$scope*/
|
|
267
|
+
ctx[42],
|
|
268
|
+
get_footer_right_slot_context
|
|
269
|
+
);
|
|
270
|
+
return {
|
|
271
|
+
c() {
|
|
272
|
+
div = element("div");
|
|
273
|
+
if (footer_left_slot) footer_left_slot.c();
|
|
274
|
+
t0 = space();
|
|
275
|
+
if (footer_center_slot) footer_center_slot.c();
|
|
276
|
+
t1 = space();
|
|
277
|
+
if (footer_right_slot) footer_right_slot.c();
|
|
278
|
+
attr(div, "class", "aparte-composer-footer");
|
|
279
|
+
},
|
|
280
|
+
m(target, anchor) {
|
|
281
|
+
insert(target, div, anchor);
|
|
282
|
+
if (footer_left_slot) {
|
|
283
|
+
footer_left_slot.m(div, null);
|
|
284
|
+
}
|
|
285
|
+
append(div, t0);
|
|
286
|
+
if (footer_center_slot) {
|
|
287
|
+
footer_center_slot.m(div, null);
|
|
288
|
+
}
|
|
289
|
+
append(div, t1);
|
|
290
|
+
if (footer_right_slot) {
|
|
291
|
+
footer_right_slot.m(div, null);
|
|
292
|
+
}
|
|
293
|
+
current = true;
|
|
294
|
+
},
|
|
295
|
+
p(ctx2, dirty) {
|
|
296
|
+
if (footer_left_slot) {
|
|
297
|
+
if (footer_left_slot.p && (!current || dirty[1] & /*$$scope*/
|
|
298
|
+
2048)) {
|
|
299
|
+
update_slot_base(
|
|
300
|
+
footer_left_slot,
|
|
301
|
+
footer_left_slot_template,
|
|
302
|
+
ctx2,
|
|
303
|
+
/*$$scope*/
|
|
304
|
+
ctx2[42],
|
|
305
|
+
!current ? get_all_dirty_from_scope(
|
|
306
|
+
/*$$scope*/
|
|
307
|
+
ctx2[42]
|
|
308
|
+
) : get_slot_changes(
|
|
309
|
+
footer_left_slot_template,
|
|
310
|
+
/*$$scope*/
|
|
311
|
+
ctx2[42],
|
|
312
|
+
dirty,
|
|
313
|
+
get_footer_left_slot_changes
|
|
314
|
+
),
|
|
315
|
+
get_footer_left_slot_context
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (footer_center_slot) {
|
|
320
|
+
if (footer_center_slot.p && (!current || dirty[1] & /*$$scope*/
|
|
321
|
+
2048)) {
|
|
322
|
+
update_slot_base(
|
|
323
|
+
footer_center_slot,
|
|
324
|
+
footer_center_slot_template,
|
|
325
|
+
ctx2,
|
|
326
|
+
/*$$scope*/
|
|
327
|
+
ctx2[42],
|
|
328
|
+
!current ? get_all_dirty_from_scope(
|
|
329
|
+
/*$$scope*/
|
|
330
|
+
ctx2[42]
|
|
331
|
+
) : get_slot_changes(
|
|
332
|
+
footer_center_slot_template,
|
|
333
|
+
/*$$scope*/
|
|
334
|
+
ctx2[42],
|
|
335
|
+
dirty,
|
|
336
|
+
get_footer_center_slot_changes
|
|
337
|
+
),
|
|
338
|
+
get_footer_center_slot_context
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (footer_right_slot) {
|
|
343
|
+
if (footer_right_slot.p && (!current || dirty[1] & /*$$scope*/
|
|
344
|
+
2048)) {
|
|
345
|
+
update_slot_base(
|
|
346
|
+
footer_right_slot,
|
|
347
|
+
footer_right_slot_template,
|
|
348
|
+
ctx2,
|
|
349
|
+
/*$$scope*/
|
|
350
|
+
ctx2[42],
|
|
351
|
+
!current ? get_all_dirty_from_scope(
|
|
352
|
+
/*$$scope*/
|
|
353
|
+
ctx2[42]
|
|
354
|
+
) : get_slot_changes(
|
|
355
|
+
footer_right_slot_template,
|
|
356
|
+
/*$$scope*/
|
|
357
|
+
ctx2[42],
|
|
358
|
+
dirty,
|
|
359
|
+
get_footer_right_slot_changes
|
|
360
|
+
),
|
|
361
|
+
get_footer_right_slot_context
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
i(local) {
|
|
367
|
+
if (current) return;
|
|
368
|
+
transition_in(footer_left_slot, local);
|
|
369
|
+
transition_in(footer_center_slot, local);
|
|
370
|
+
transition_in(footer_right_slot, local);
|
|
371
|
+
current = true;
|
|
372
|
+
},
|
|
373
|
+
o(local) {
|
|
374
|
+
transition_out(footer_left_slot, local);
|
|
375
|
+
transition_out(footer_center_slot, local);
|
|
376
|
+
transition_out(footer_right_slot, local);
|
|
377
|
+
current = false;
|
|
378
|
+
},
|
|
379
|
+
d(detaching) {
|
|
380
|
+
if (detaching) {
|
|
381
|
+
detach(div);
|
|
382
|
+
}
|
|
383
|
+
if (footer_left_slot) footer_left_slot.d(detaching);
|
|
384
|
+
if (footer_center_slot) footer_center_slot.d(detaching);
|
|
385
|
+
if (footer_right_slot) footer_right_slot.d(detaching);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function fallback_block(ctx) {
|
|
390
|
+
let div1;
|
|
391
|
+
let aparte_composer_attachments;
|
|
392
|
+
let t0;
|
|
393
|
+
let div0;
|
|
394
|
+
let t3;
|
|
395
|
+
let current;
|
|
396
|
+
let if_block = (
|
|
397
|
+
/*$$slots*/
|
|
398
|
+
(ctx[9]["footer-left"] || /*$$slots*/
|
|
399
|
+
ctx[9]["footer-center"] || /*$$slots*/
|
|
400
|
+
ctx[9]["footer-right"]) && create_if_block(ctx)
|
|
401
|
+
);
|
|
402
|
+
return {
|
|
403
|
+
c() {
|
|
404
|
+
div1 = element("div");
|
|
405
|
+
aparte_composer_attachments = element("aparte-composer-attachments");
|
|
406
|
+
t0 = space();
|
|
407
|
+
div0 = element("div");
|
|
408
|
+
div0.innerHTML = `<aparte-composer-add-attachment></aparte-composer-add-attachment> <aparte-composer-input></aparte-composer-input> <aparte-composer-send></aparte-composer-send>`;
|
|
409
|
+
t3 = space();
|
|
410
|
+
if (if_block) if_block.c();
|
|
411
|
+
attr(div0, "class", "aparte-composer-row");
|
|
412
|
+
attr(div1, "class", "aparte-composer-shell");
|
|
413
|
+
},
|
|
414
|
+
m(target, anchor) {
|
|
415
|
+
insert(target, div1, anchor);
|
|
416
|
+
append(div1, aparte_composer_attachments);
|
|
417
|
+
append(div1, t0);
|
|
418
|
+
append(div1, div0);
|
|
419
|
+
append(div1, t3);
|
|
420
|
+
if (if_block) if_block.m(div1, null);
|
|
421
|
+
current = true;
|
|
422
|
+
},
|
|
423
|
+
p(ctx2, dirty) {
|
|
424
|
+
if (
|
|
425
|
+
/*$$slots*/
|
|
426
|
+
ctx2[9]["footer-left"] || /*$$slots*/
|
|
427
|
+
ctx2[9]["footer-center"] || /*$$slots*/
|
|
428
|
+
ctx2[9]["footer-right"]
|
|
429
|
+
) {
|
|
430
|
+
if (if_block) {
|
|
431
|
+
if_block.p(ctx2, dirty);
|
|
432
|
+
if (dirty[0] & /*$$slots*/
|
|
433
|
+
512) {
|
|
434
|
+
transition_in(if_block, 1);
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
if_block = create_if_block(ctx2);
|
|
438
|
+
if_block.c();
|
|
439
|
+
transition_in(if_block, 1);
|
|
440
|
+
if_block.m(div1, null);
|
|
441
|
+
}
|
|
442
|
+
} else if (if_block) {
|
|
443
|
+
group_outros();
|
|
444
|
+
transition_out(if_block, 1, 1, () => {
|
|
445
|
+
if_block = null;
|
|
446
|
+
});
|
|
447
|
+
check_outros();
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
i(local) {
|
|
451
|
+
if (current) return;
|
|
452
|
+
transition_in(if_block);
|
|
453
|
+
current = true;
|
|
454
|
+
},
|
|
455
|
+
o(local) {
|
|
456
|
+
transition_out(if_block);
|
|
457
|
+
current = false;
|
|
458
|
+
},
|
|
459
|
+
d(detaching) {
|
|
460
|
+
if (detaching) {
|
|
461
|
+
detach(div1);
|
|
462
|
+
}
|
|
463
|
+
if (if_block) if_block.d();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function create_fragment$1(ctx) {
|
|
468
|
+
let div;
|
|
469
|
+
let aparte_chat_viewport;
|
|
470
|
+
let t0;
|
|
471
|
+
let each_blocks = [];
|
|
472
|
+
let each_1_lookup = /* @__PURE__ */ new Map();
|
|
473
|
+
let t1;
|
|
474
|
+
let aparte_chat_status;
|
|
475
|
+
let aparte_chat_status_visible_value;
|
|
476
|
+
let t2;
|
|
477
|
+
let t3;
|
|
478
|
+
let aparte_composer;
|
|
479
|
+
let div_data_aparte_empty_value;
|
|
480
|
+
let current;
|
|
481
|
+
let mounted;
|
|
482
|
+
let dispose;
|
|
483
|
+
let if_block = (
|
|
484
|
+
/*internalMessages*/
|
|
485
|
+
ctx[4].length === 0 && create_if_block_1(ctx)
|
|
486
|
+
);
|
|
487
|
+
let each_value = ensure_array_like(
|
|
488
|
+
/*internalMessages*/
|
|
489
|
+
ctx[4]
|
|
490
|
+
);
|
|
491
|
+
const get_key = (ctx2) => (
|
|
492
|
+
/*m*/
|
|
493
|
+
ctx2[51].id
|
|
494
|
+
);
|
|
495
|
+
for (let i = 0; i < each_value.length; i += 1) {
|
|
496
|
+
let child_ctx = get_each_context(ctx, each_value, i);
|
|
497
|
+
let key = get_key(child_ctx);
|
|
498
|
+
each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
|
|
499
|
+
}
|
|
500
|
+
const above_composer_slot_template = (
|
|
501
|
+
/*#slots*/
|
|
502
|
+
ctx[43]["above-composer"]
|
|
503
|
+
);
|
|
504
|
+
const above_composer_slot = create_slot(
|
|
505
|
+
above_composer_slot_template,
|
|
506
|
+
ctx,
|
|
507
|
+
/*$$scope*/
|
|
508
|
+
ctx[42],
|
|
509
|
+
get_above_composer_slot_context
|
|
510
|
+
);
|
|
511
|
+
const composer_slot_template = (
|
|
512
|
+
/*#slots*/
|
|
513
|
+
ctx[43].composer
|
|
514
|
+
);
|
|
515
|
+
const composer_slot = create_slot(
|
|
516
|
+
composer_slot_template,
|
|
517
|
+
ctx,
|
|
518
|
+
/*$$scope*/
|
|
519
|
+
ctx[42],
|
|
520
|
+
get_composer_slot_context
|
|
521
|
+
);
|
|
522
|
+
const composer_slot_or_fallback = composer_slot || fallback_block(ctx);
|
|
523
|
+
return {
|
|
524
|
+
c() {
|
|
525
|
+
div = element("div");
|
|
526
|
+
aparte_chat_viewport = element("aparte-chat-viewport");
|
|
527
|
+
if (if_block) if_block.c();
|
|
528
|
+
t0 = space();
|
|
529
|
+
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
530
|
+
each_blocks[i].c();
|
|
531
|
+
}
|
|
532
|
+
t1 = space();
|
|
533
|
+
aparte_chat_status = element("aparte-chat-status");
|
|
534
|
+
t2 = space();
|
|
535
|
+
if (above_composer_slot) above_composer_slot.c();
|
|
536
|
+
t3 = space();
|
|
537
|
+
aparte_composer = element("aparte-composer");
|
|
538
|
+
if (composer_slot_or_fallback) composer_slot_or_fallback.c();
|
|
539
|
+
set_custom_element_data(aparte_chat_status, "visible", aparte_chat_status_visible_value = /*typingActive*/
|
|
540
|
+
ctx[7] ? "" : null);
|
|
541
|
+
set_custom_element_data(
|
|
542
|
+
aparte_chat_status,
|
|
543
|
+
"text",
|
|
544
|
+
/*typingText*/
|
|
545
|
+
ctx[0]
|
|
546
|
+
);
|
|
547
|
+
set_custom_element_data(aparte_chat_viewport, "framework-managed", "");
|
|
548
|
+
attr(div, "class", "aparte-chat-container");
|
|
549
|
+
attr(div, "data-aparte-chat", "");
|
|
550
|
+
attr(div, "data-aparte-empty", div_data_aparte_empty_value = /*centerWhenEmpty*/
|
|
551
|
+
ctx[1] && /*internalMessages*/
|
|
552
|
+
ctx[4].length === 0 ? "" : null);
|
|
553
|
+
attr(
|
|
554
|
+
div,
|
|
555
|
+
"id",
|
|
556
|
+
/*hostId*/
|
|
557
|
+
ctx[2]
|
|
558
|
+
);
|
|
559
|
+
toggle_class(
|
|
560
|
+
div,
|
|
561
|
+
"aparte-chat-container--auto-center",
|
|
562
|
+
/*centerWhenEmpty*/
|
|
563
|
+
ctx[1]
|
|
564
|
+
);
|
|
565
|
+
},
|
|
566
|
+
m(target, anchor) {
|
|
567
|
+
insert(target, div, anchor);
|
|
568
|
+
append(div, aparte_chat_viewport);
|
|
569
|
+
if (if_block) if_block.m(aparte_chat_viewport, null);
|
|
570
|
+
append(aparte_chat_viewport, t0);
|
|
571
|
+
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
572
|
+
if (each_blocks[i]) {
|
|
573
|
+
each_blocks[i].m(aparte_chat_viewport, null);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
append(aparte_chat_viewport, t1);
|
|
577
|
+
append(aparte_chat_viewport, aparte_chat_status);
|
|
578
|
+
ctx[44](aparte_chat_viewport);
|
|
579
|
+
append(div, t2);
|
|
580
|
+
if (above_composer_slot) {
|
|
581
|
+
above_composer_slot.m(div, null);
|
|
582
|
+
}
|
|
583
|
+
append(div, t3);
|
|
584
|
+
append(div, aparte_composer);
|
|
585
|
+
if (composer_slot_or_fallback) {
|
|
586
|
+
composer_slot_or_fallback.m(aparte_composer, null);
|
|
587
|
+
}
|
|
588
|
+
ctx[45](aparte_composer);
|
|
589
|
+
ctx[46](div);
|
|
590
|
+
current = true;
|
|
591
|
+
if (!mounted) {
|
|
592
|
+
dispose = listen(
|
|
593
|
+
aparte_composer,
|
|
594
|
+
"aparte-send",
|
|
595
|
+
/*handleSend*/
|
|
596
|
+
ctx[8]
|
|
597
|
+
);
|
|
598
|
+
mounted = true;
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
p(ctx2, dirty) {
|
|
602
|
+
if (
|
|
603
|
+
/*internalMessages*/
|
|
604
|
+
ctx2[4].length === 0
|
|
605
|
+
) {
|
|
606
|
+
if (if_block) {
|
|
607
|
+
if_block.p(ctx2, dirty);
|
|
608
|
+
if (dirty[0] & /*internalMessages*/
|
|
609
|
+
16) {
|
|
610
|
+
transition_in(if_block, 1);
|
|
611
|
+
}
|
|
612
|
+
} else {
|
|
613
|
+
if_block = create_if_block_1(ctx2);
|
|
614
|
+
if_block.c();
|
|
615
|
+
transition_in(if_block, 1);
|
|
616
|
+
if_block.m(aparte_chat_viewport, t0);
|
|
617
|
+
}
|
|
618
|
+
} else if (if_block) {
|
|
619
|
+
group_outros();
|
|
620
|
+
transition_out(if_block, 1, 1, () => {
|
|
621
|
+
if_block = null;
|
|
622
|
+
});
|
|
623
|
+
check_outros();
|
|
624
|
+
}
|
|
625
|
+
if (dirty[0] & /*internalMessages*/
|
|
626
|
+
16 | dirty[1] & /*$$scope*/
|
|
627
|
+
2048) {
|
|
628
|
+
each_value = ensure_array_like(
|
|
629
|
+
/*internalMessages*/
|
|
630
|
+
ctx2[4]
|
|
631
|
+
);
|
|
632
|
+
group_outros();
|
|
633
|
+
each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, aparte_chat_viewport, outro_and_destroy_block, create_each_block, t1, get_each_context);
|
|
634
|
+
check_outros();
|
|
635
|
+
}
|
|
636
|
+
if (!current || dirty[0] & /*typingActive*/
|
|
637
|
+
128 && aparte_chat_status_visible_value !== (aparte_chat_status_visible_value = /*typingActive*/
|
|
638
|
+
ctx2[7] ? "" : null)) {
|
|
639
|
+
set_custom_element_data(aparte_chat_status, "visible", aparte_chat_status_visible_value);
|
|
640
|
+
}
|
|
641
|
+
if (!current || dirty[0] & /*typingText*/
|
|
642
|
+
1) {
|
|
643
|
+
set_custom_element_data(
|
|
644
|
+
aparte_chat_status,
|
|
645
|
+
"text",
|
|
646
|
+
/*typingText*/
|
|
647
|
+
ctx2[0]
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
if (above_composer_slot) {
|
|
651
|
+
if (above_composer_slot.p && (!current || dirty[1] & /*$$scope*/
|
|
652
|
+
2048)) {
|
|
653
|
+
update_slot_base(
|
|
654
|
+
above_composer_slot,
|
|
655
|
+
above_composer_slot_template,
|
|
656
|
+
ctx2,
|
|
657
|
+
/*$$scope*/
|
|
658
|
+
ctx2[42],
|
|
659
|
+
!current ? get_all_dirty_from_scope(
|
|
660
|
+
/*$$scope*/
|
|
661
|
+
ctx2[42]
|
|
662
|
+
) : get_slot_changes(
|
|
663
|
+
above_composer_slot_template,
|
|
664
|
+
/*$$scope*/
|
|
665
|
+
ctx2[42],
|
|
666
|
+
dirty,
|
|
667
|
+
get_above_composer_slot_changes
|
|
668
|
+
),
|
|
669
|
+
get_above_composer_slot_context
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (composer_slot) {
|
|
674
|
+
if (composer_slot.p && (!current || dirty[1] & /*$$scope*/
|
|
675
|
+
2048)) {
|
|
676
|
+
update_slot_base(
|
|
677
|
+
composer_slot,
|
|
678
|
+
composer_slot_template,
|
|
679
|
+
ctx2,
|
|
680
|
+
/*$$scope*/
|
|
681
|
+
ctx2[42],
|
|
682
|
+
!current ? get_all_dirty_from_scope(
|
|
683
|
+
/*$$scope*/
|
|
684
|
+
ctx2[42]
|
|
685
|
+
) : get_slot_changes(
|
|
686
|
+
composer_slot_template,
|
|
687
|
+
/*$$scope*/
|
|
688
|
+
ctx2[42],
|
|
689
|
+
dirty,
|
|
690
|
+
get_composer_slot_changes
|
|
691
|
+
),
|
|
692
|
+
get_composer_slot_context
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
} else {
|
|
696
|
+
if (composer_slot_or_fallback && composer_slot_or_fallback.p && (!current || dirty[0] & /*$$slots*/
|
|
697
|
+
512 | dirty[1] & /*$$scope*/
|
|
698
|
+
2048)) {
|
|
699
|
+
composer_slot_or_fallback.p(ctx2, !current ? [-1, -1] : dirty);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (!current || dirty[0] & /*centerWhenEmpty, internalMessages*/
|
|
703
|
+
18 && div_data_aparte_empty_value !== (div_data_aparte_empty_value = /*centerWhenEmpty*/
|
|
704
|
+
ctx2[1] && /*internalMessages*/
|
|
705
|
+
ctx2[4].length === 0 ? "" : null)) {
|
|
706
|
+
attr(div, "data-aparte-empty", div_data_aparte_empty_value);
|
|
707
|
+
}
|
|
708
|
+
if (!current || dirty[0] & /*hostId*/
|
|
709
|
+
4) {
|
|
710
|
+
attr(
|
|
711
|
+
div,
|
|
712
|
+
"id",
|
|
713
|
+
/*hostId*/
|
|
714
|
+
ctx2[2]
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
if (!current || dirty[0] & /*centerWhenEmpty*/
|
|
718
|
+
2) {
|
|
719
|
+
toggle_class(
|
|
720
|
+
div,
|
|
721
|
+
"aparte-chat-container--auto-center",
|
|
722
|
+
/*centerWhenEmpty*/
|
|
723
|
+
ctx2[1]
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
i(local) {
|
|
728
|
+
if (current) return;
|
|
729
|
+
transition_in(if_block);
|
|
730
|
+
for (let i = 0; i < each_value.length; i += 1) {
|
|
731
|
+
transition_in(each_blocks[i]);
|
|
732
|
+
}
|
|
733
|
+
transition_in(above_composer_slot, local);
|
|
734
|
+
transition_in(composer_slot_or_fallback, local);
|
|
735
|
+
current = true;
|
|
736
|
+
},
|
|
737
|
+
o(local) {
|
|
738
|
+
transition_out(if_block);
|
|
739
|
+
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
740
|
+
transition_out(each_blocks[i]);
|
|
741
|
+
}
|
|
742
|
+
transition_out(above_composer_slot, local);
|
|
743
|
+
transition_out(composer_slot_or_fallback, local);
|
|
744
|
+
current = false;
|
|
745
|
+
},
|
|
746
|
+
d(detaching) {
|
|
747
|
+
if (detaching) {
|
|
748
|
+
detach(div);
|
|
749
|
+
}
|
|
750
|
+
if (if_block) if_block.d();
|
|
751
|
+
for (let i = 0; i < each_blocks.length; i += 1) {
|
|
752
|
+
each_blocks[i].d();
|
|
753
|
+
}
|
|
754
|
+
ctx[44](null);
|
|
755
|
+
if (above_composer_slot) above_composer_slot.d(detaching);
|
|
756
|
+
if (composer_slot_or_fallback) composer_slot_or_fallback.d(detaching);
|
|
757
|
+
ctx[45](null);
|
|
758
|
+
ctx[46](null);
|
|
759
|
+
mounted = false;
|
|
760
|
+
dispose();
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
function toggleAttr(el, name, on, value) {
|
|
765
|
+
if (on) el.setAttribute(name, value);
|
|
766
|
+
else el.removeAttribute(name);
|
|
767
|
+
}
|
|
768
|
+
function instance$1($$self, $$props, $$invalidate) {
|
|
769
|
+
let { $$slots: slots = {}, $$scope } = $$props;
|
|
770
|
+
const $$slots = compute_slots(slots);
|
|
771
|
+
let { messages = [] } = $$props;
|
|
772
|
+
let { placeholder = "Type a message..." } = $$props;
|
|
773
|
+
let { disabled = false } = $$props;
|
|
774
|
+
let { isTyping = false } = $$props;
|
|
775
|
+
let { typingText = "Assistant is thinking..." } = $$props;
|
|
776
|
+
let { submitOnEnter = true } = $$props;
|
|
777
|
+
let { layoutTransitionMs = 0 } = $$props;
|
|
778
|
+
let { centerWhenEmpty = false } = $$props;
|
|
779
|
+
let { conversationId = null } = $$props;
|
|
780
|
+
let { config = void 0 } = $$props;
|
|
781
|
+
const dispatch = createEventDispatcher();
|
|
782
|
+
let hostId = "";
|
|
783
|
+
let rootRef;
|
|
784
|
+
let viewportRef;
|
|
785
|
+
let composerRef;
|
|
786
|
+
let internalMessages = [...messages];
|
|
787
|
+
let typingActive = isTyping;
|
|
788
|
+
let host = null;
|
|
789
|
+
let teardown = null;
|
|
790
|
+
let lastProp = messages;
|
|
791
|
+
let lastTyping = isTyping;
|
|
792
|
+
let lastConv = conversationId;
|
|
793
|
+
function handleSend(event) {
|
|
794
|
+
viewportRef?.requestSmoothScroll?.();
|
|
795
|
+
dispatch("messageSent", event.detail);
|
|
796
|
+
}
|
|
797
|
+
function handleAction(event) {
|
|
798
|
+
dispatch("action", event.detail);
|
|
799
|
+
}
|
|
800
|
+
onMount(() => {
|
|
801
|
+
$$invalidate(2, hostId = `aparte-chat-${crypto.randomUUID()}`);
|
|
802
|
+
if (rootRef) $$invalidate(5, rootRef.id = hostId, rootRef);
|
|
803
|
+
const binding = {
|
|
804
|
+
hostId,
|
|
805
|
+
host: rootRef,
|
|
806
|
+
viewport: viewportRef,
|
|
807
|
+
getMessages: () => internalMessages,
|
|
808
|
+
setMessages: (m) => {
|
|
809
|
+
$$invalidate(4, internalMessages = m);
|
|
810
|
+
},
|
|
811
|
+
onMessagesChange: (m) => dispatch("messagesChange", m),
|
|
812
|
+
onMessageAppended: (m) => dispatch("messageAppended", m),
|
|
813
|
+
onTypingChange: (t) => {
|
|
814
|
+
$$invalidate(7, typingActive = t);
|
|
815
|
+
dispatch("typingChange", t);
|
|
816
|
+
},
|
|
817
|
+
onStreamingChange: () => {
|
|
818
|
+
},
|
|
819
|
+
afterRender: (cb) => {
|
|
820
|
+
void tick().then(cb);
|
|
821
|
+
},
|
|
822
|
+
resetComposer: () => composerRef?.reset?.()
|
|
823
|
+
};
|
|
824
|
+
$$invalidate(38, host = new AparteChatHost(
|
|
825
|
+
binding,
|
|
826
|
+
{
|
|
827
|
+
layoutTransitionMs,
|
|
828
|
+
conversationId: conversationId ?? null,
|
|
829
|
+
onConversationCreated: (id) => dispatch("conversationCreated", id),
|
|
830
|
+
config
|
|
831
|
+
}
|
|
832
|
+
));
|
|
833
|
+
teardown = host.bind();
|
|
834
|
+
host.syncBubbles();
|
|
835
|
+
rootRef?.addEventListener("aparte-action", handleAction);
|
|
836
|
+
});
|
|
837
|
+
onDestroy(() => {
|
|
838
|
+
rootRef?.removeEventListener("aparte-action", handleAction);
|
|
839
|
+
teardown?.();
|
|
840
|
+
teardown = null;
|
|
841
|
+
$$invalidate(38, host = null);
|
|
842
|
+
});
|
|
843
|
+
function appendMessage(m) {
|
|
844
|
+
host?.appendMessage(m);
|
|
845
|
+
}
|
|
846
|
+
function updateMessage(id, u) {
|
|
847
|
+
host?.updateMessage(id, u);
|
|
848
|
+
}
|
|
849
|
+
function updateLastMessage(content, options) {
|
|
850
|
+
host?.updateLastMessage(content, options);
|
|
851
|
+
}
|
|
852
|
+
function addSegment(segment) {
|
|
853
|
+
host?.addSegment(segment);
|
|
854
|
+
}
|
|
855
|
+
function updateSegment(segmentId, updates) {
|
|
856
|
+
host?.updateSegment(segmentId, updates);
|
|
857
|
+
}
|
|
858
|
+
function removeSegment(segmentId) {
|
|
859
|
+
host?.removeSegment(segmentId);
|
|
860
|
+
}
|
|
861
|
+
function appendToSegment(segmentId, content) {
|
|
862
|
+
host?.appendToSegment(segmentId, content);
|
|
863
|
+
}
|
|
864
|
+
function getMessages() {
|
|
865
|
+
return host?.getMessages() ?? internalMessages;
|
|
866
|
+
}
|
|
867
|
+
function clearMessages() {
|
|
868
|
+
host?.clearMessages();
|
|
869
|
+
}
|
|
870
|
+
function addBranch(messageId) {
|
|
871
|
+
return host?.addBranch(messageId) ?? 0;
|
|
872
|
+
}
|
|
873
|
+
function addSiblingOf(existingId, message) {
|
|
874
|
+
return host?.addSiblingOf(existingId, message) ?? null;
|
|
875
|
+
}
|
|
876
|
+
function truncateFrom(messageId) {
|
|
877
|
+
host?.truncateFrom(messageId);
|
|
878
|
+
}
|
|
879
|
+
function truncateResponsesAfter(userMessageId) {
|
|
880
|
+
host?.truncateResponsesAfter(userMessageId);
|
|
881
|
+
}
|
|
882
|
+
function injectTokenStream(messageId, tokens) {
|
|
883
|
+
return host?.streamTokens(messageId, tokens) ?? Promise.resolve();
|
|
884
|
+
}
|
|
885
|
+
function stopTokenStream() {
|
|
886
|
+
host?.stopTokenStream();
|
|
887
|
+
}
|
|
888
|
+
function setConversationId(id) {
|
|
889
|
+
return host?.setConversationId(id) ?? Promise.resolve();
|
|
890
|
+
}
|
|
891
|
+
function scrollToBottom() {
|
|
892
|
+
viewportRef?.scrollToBottom?.();
|
|
893
|
+
}
|
|
894
|
+
function getViewport() {
|
|
895
|
+
return viewportRef ?? null;
|
|
896
|
+
}
|
|
897
|
+
function focusInput() {
|
|
898
|
+
composerRef?.focus?.();
|
|
899
|
+
}
|
|
900
|
+
function isStreaming() {
|
|
901
|
+
return host?.isStreaming ?? false;
|
|
902
|
+
}
|
|
903
|
+
function aparte_chat_viewport_binding($$value) {
|
|
904
|
+
binding_callbacks[$$value ? "unshift" : "push"](() => {
|
|
905
|
+
viewportRef = $$value;
|
|
906
|
+
$$invalidate(6, viewportRef);
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
function aparte_composer_binding($$value) {
|
|
910
|
+
binding_callbacks[$$value ? "unshift" : "push"](() => {
|
|
911
|
+
composerRef = $$value;
|
|
912
|
+
$$invalidate(3, composerRef);
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
function div_binding($$value) {
|
|
916
|
+
binding_callbacks[$$value ? "unshift" : "push"](() => {
|
|
917
|
+
rootRef = $$value;
|
|
918
|
+
$$invalidate(5, rootRef);
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
$$self.$$set = ($$props2) => {
|
|
922
|
+
if ("messages" in $$props2) $$invalidate(10, messages = $$props2.messages);
|
|
923
|
+
if ("placeholder" in $$props2) $$invalidate(11, placeholder = $$props2.placeholder);
|
|
924
|
+
if ("disabled" in $$props2) $$invalidate(12, disabled = $$props2.disabled);
|
|
925
|
+
if ("isTyping" in $$props2) $$invalidate(13, isTyping = $$props2.isTyping);
|
|
926
|
+
if ("typingText" in $$props2) $$invalidate(0, typingText = $$props2.typingText);
|
|
927
|
+
if ("submitOnEnter" in $$props2) $$invalidate(14, submitOnEnter = $$props2.submitOnEnter);
|
|
928
|
+
if ("layoutTransitionMs" in $$props2) $$invalidate(15, layoutTransitionMs = $$props2.layoutTransitionMs);
|
|
929
|
+
if ("centerWhenEmpty" in $$props2) $$invalidate(1, centerWhenEmpty = $$props2.centerWhenEmpty);
|
|
930
|
+
if ("conversationId" in $$props2) $$invalidate(16, conversationId = $$props2.conversationId);
|
|
931
|
+
if ("config" in $$props2) $$invalidate(17, config = $$props2.config);
|
|
932
|
+
if ("$$scope" in $$props2) $$invalidate(42, $$scope = $$props2.$$scope);
|
|
933
|
+
};
|
|
934
|
+
$$self.$$.update = () => {
|
|
935
|
+
if ($$self.$$.dirty[0] & /*messages*/
|
|
936
|
+
1024 | $$self.$$.dirty[1] & /*lastProp, host*/
|
|
937
|
+
384) {
|
|
938
|
+
if (messages !== lastProp) {
|
|
939
|
+
$$invalidate(39, lastProp = messages);
|
|
940
|
+
$$invalidate(4, internalMessages = [...messages]);
|
|
941
|
+
if (messages.length === 0) host?.clearRenderCache();
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
if ($$self.$$.dirty[0] & /*isTyping*/
|
|
945
|
+
8192 | $$self.$$.dirty[1] & /*lastTyping*/
|
|
946
|
+
512) {
|
|
947
|
+
if (isTyping !== lastTyping) {
|
|
948
|
+
$$invalidate(40, lastTyping = isTyping);
|
|
949
|
+
$$invalidate(7, typingActive = isTyping);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
if ($$self.$$.dirty[0] & /*conversationId*/
|
|
953
|
+
65536 | $$self.$$.dirty[1] & /*lastConv, host*/
|
|
954
|
+
1152) {
|
|
955
|
+
if (conversationId !== lastConv) {
|
|
956
|
+
$$invalidate(41, lastConv = conversationId);
|
|
957
|
+
void host?.setConversationId(conversationId ?? null);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
if ($$self.$$.dirty[0] & /*internalMessages*/
|
|
961
|
+
16 | $$self.$$.dirty[1] & /*host*/
|
|
962
|
+
128) {
|
|
963
|
+
if (host && internalMessages) {
|
|
964
|
+
void tick().then(() => host?.syncBubbles());
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
if ($$self.$$.dirty[0] & /*composerRef, hostId, placeholder, disabled, submitOnEnter*/
|
|
968
|
+
22540) {
|
|
969
|
+
if (composerRef) {
|
|
970
|
+
composerRef.setAttribute("target", hostId);
|
|
971
|
+
composerRef.setAttribute("placeholder", placeholder);
|
|
972
|
+
toggleAttr(composerRef, "disabled", disabled, "");
|
|
973
|
+
toggleAttr(composerRef, "submit-on-enter", !submitOnEnter, "false");
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
return [
|
|
978
|
+
typingText,
|
|
979
|
+
centerWhenEmpty,
|
|
980
|
+
hostId,
|
|
981
|
+
composerRef,
|
|
982
|
+
internalMessages,
|
|
983
|
+
rootRef,
|
|
984
|
+
viewportRef,
|
|
985
|
+
typingActive,
|
|
986
|
+
handleSend,
|
|
987
|
+
$$slots,
|
|
988
|
+
messages,
|
|
989
|
+
placeholder,
|
|
990
|
+
disabled,
|
|
991
|
+
isTyping,
|
|
992
|
+
submitOnEnter,
|
|
993
|
+
layoutTransitionMs,
|
|
994
|
+
conversationId,
|
|
995
|
+
config,
|
|
996
|
+
appendMessage,
|
|
997
|
+
updateMessage,
|
|
998
|
+
updateLastMessage,
|
|
999
|
+
addSegment,
|
|
1000
|
+
updateSegment,
|
|
1001
|
+
removeSegment,
|
|
1002
|
+
appendToSegment,
|
|
1003
|
+
getMessages,
|
|
1004
|
+
clearMessages,
|
|
1005
|
+
addBranch,
|
|
1006
|
+
addSiblingOf,
|
|
1007
|
+
truncateFrom,
|
|
1008
|
+
truncateResponsesAfter,
|
|
1009
|
+
injectTokenStream,
|
|
1010
|
+
stopTokenStream,
|
|
1011
|
+
setConversationId,
|
|
1012
|
+
scrollToBottom,
|
|
1013
|
+
getViewport,
|
|
1014
|
+
focusInput,
|
|
1015
|
+
isStreaming,
|
|
1016
|
+
host,
|
|
1017
|
+
lastProp,
|
|
1018
|
+
lastTyping,
|
|
1019
|
+
lastConv,
|
|
1020
|
+
$$scope,
|
|
1021
|
+
slots,
|
|
1022
|
+
aparte_chat_viewport_binding,
|
|
1023
|
+
aparte_composer_binding,
|
|
1024
|
+
div_binding
|
|
1025
|
+
];
|
|
1026
|
+
}
|
|
1027
|
+
class AparteChat extends SvelteComponent {
|
|
1028
|
+
constructor(options) {
|
|
1029
|
+
super();
|
|
1030
|
+
init(
|
|
1031
|
+
this,
|
|
1032
|
+
options,
|
|
1033
|
+
instance$1,
|
|
1034
|
+
create_fragment$1,
|
|
1035
|
+
safe_not_equal,
|
|
1036
|
+
{
|
|
1037
|
+
messages: 10,
|
|
1038
|
+
placeholder: 11,
|
|
1039
|
+
disabled: 12,
|
|
1040
|
+
isTyping: 13,
|
|
1041
|
+
typingText: 0,
|
|
1042
|
+
submitOnEnter: 14,
|
|
1043
|
+
layoutTransitionMs: 15,
|
|
1044
|
+
centerWhenEmpty: 1,
|
|
1045
|
+
conversationId: 16,
|
|
1046
|
+
config: 17,
|
|
1047
|
+
appendMessage: 18,
|
|
1048
|
+
updateMessage: 19,
|
|
1049
|
+
updateLastMessage: 20,
|
|
1050
|
+
addSegment: 21,
|
|
1051
|
+
updateSegment: 22,
|
|
1052
|
+
removeSegment: 23,
|
|
1053
|
+
appendToSegment: 24,
|
|
1054
|
+
getMessages: 25,
|
|
1055
|
+
clearMessages: 26,
|
|
1056
|
+
addBranch: 27,
|
|
1057
|
+
addSiblingOf: 28,
|
|
1058
|
+
truncateFrom: 29,
|
|
1059
|
+
truncateResponsesAfter: 30,
|
|
1060
|
+
injectTokenStream: 31,
|
|
1061
|
+
stopTokenStream: 32,
|
|
1062
|
+
setConversationId: 33,
|
|
1063
|
+
scrollToBottom: 34,
|
|
1064
|
+
getViewport: 35,
|
|
1065
|
+
focusInput: 36,
|
|
1066
|
+
isStreaming: 37
|
|
1067
|
+
},
|
|
1068
|
+
null,
|
|
1069
|
+
[-1, -1]
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
get appendMessage() {
|
|
1073
|
+
return this.$$.ctx[18];
|
|
1074
|
+
}
|
|
1075
|
+
get updateMessage() {
|
|
1076
|
+
return this.$$.ctx[19];
|
|
1077
|
+
}
|
|
1078
|
+
get updateLastMessage() {
|
|
1079
|
+
return this.$$.ctx[20];
|
|
1080
|
+
}
|
|
1081
|
+
get addSegment() {
|
|
1082
|
+
return this.$$.ctx[21];
|
|
1083
|
+
}
|
|
1084
|
+
get updateSegment() {
|
|
1085
|
+
return this.$$.ctx[22];
|
|
1086
|
+
}
|
|
1087
|
+
get removeSegment() {
|
|
1088
|
+
return this.$$.ctx[23];
|
|
1089
|
+
}
|
|
1090
|
+
get appendToSegment() {
|
|
1091
|
+
return this.$$.ctx[24];
|
|
1092
|
+
}
|
|
1093
|
+
get getMessages() {
|
|
1094
|
+
return this.$$.ctx[25];
|
|
1095
|
+
}
|
|
1096
|
+
get clearMessages() {
|
|
1097
|
+
return this.$$.ctx[26];
|
|
1098
|
+
}
|
|
1099
|
+
get addBranch() {
|
|
1100
|
+
return this.$$.ctx[27];
|
|
1101
|
+
}
|
|
1102
|
+
get addSiblingOf() {
|
|
1103
|
+
return this.$$.ctx[28];
|
|
1104
|
+
}
|
|
1105
|
+
get truncateFrom() {
|
|
1106
|
+
return this.$$.ctx[29];
|
|
1107
|
+
}
|
|
1108
|
+
get truncateResponsesAfter() {
|
|
1109
|
+
return this.$$.ctx[30];
|
|
1110
|
+
}
|
|
1111
|
+
get injectTokenStream() {
|
|
1112
|
+
return this.$$.ctx[31];
|
|
1113
|
+
}
|
|
1114
|
+
get stopTokenStream() {
|
|
1115
|
+
return this.$$.ctx[32];
|
|
1116
|
+
}
|
|
1117
|
+
get setConversationId() {
|
|
1118
|
+
return this.$$.ctx[33];
|
|
1119
|
+
}
|
|
1120
|
+
get scrollToBottom() {
|
|
1121
|
+
return this.$$.ctx[34];
|
|
1122
|
+
}
|
|
1123
|
+
get getViewport() {
|
|
1124
|
+
return this.$$.ctx[35];
|
|
1125
|
+
}
|
|
1126
|
+
get focusInput() {
|
|
1127
|
+
return this.$$.ctx[36];
|
|
1128
|
+
}
|
|
1129
|
+
get isStreaming() {
|
|
1130
|
+
return this.$$.ctx[37];
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
function createAparteChat(initial = []) {
|
|
1134
|
+
const messages = writable([...initial]);
|
|
1135
|
+
let comp = null;
|
|
1136
|
+
return {
|
|
1137
|
+
messages,
|
|
1138
|
+
connect: (component) => {
|
|
1139
|
+
comp = component;
|
|
1140
|
+
},
|
|
1141
|
+
onMessagesChange: (m) => messages.set(m),
|
|
1142
|
+
appendMessage: (m) => comp?.appendMessage(m),
|
|
1143
|
+
updateMessage: (id, u) => comp?.updateMessage(id, u),
|
|
1144
|
+
updateLastMessage: (c, o) => comp?.updateLastMessage(c, o),
|
|
1145
|
+
addSegment: (s) => comp?.addSegment(s),
|
|
1146
|
+
updateSegment: (id, u) => comp?.updateSegment(id, u),
|
|
1147
|
+
removeSegment: (id) => comp?.removeSegment(id),
|
|
1148
|
+
appendToSegment: (id, c) => comp?.appendToSegment(id, c),
|
|
1149
|
+
clearMessages: () => comp?.clearMessages(),
|
|
1150
|
+
addBranch: (id) => comp?.addBranch(id) ?? 0,
|
|
1151
|
+
addSiblingOf: (id, m) => comp?.addSiblingOf(id, m) ?? null,
|
|
1152
|
+
truncateFrom: (id) => comp?.truncateFrom(id),
|
|
1153
|
+
truncateResponsesAfter: (id) => comp?.truncateResponsesAfter(id),
|
|
1154
|
+
injectTokenStream: (id, tokens) => comp?.injectTokenStream(id, tokens) ?? Promise.resolve(),
|
|
1155
|
+
stopTokenStream: () => comp?.stopTokenStream(),
|
|
1156
|
+
setConversationId: (id) => comp?.setConversationId(id) ?? Promise.resolve(),
|
|
1157
|
+
isStreaming: () => comp?.isStreaming() ?? false
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function createAparteClient(options) {
|
|
1161
|
+
const client = new AparteClient(options ?? {});
|
|
1162
|
+
onMount(() => {
|
|
1163
|
+
client.start();
|
|
1164
|
+
});
|
|
1165
|
+
onDestroy(() => client.stop());
|
|
1166
|
+
return { client, abort: () => client.abort() };
|
|
1167
|
+
}
|
|
1168
|
+
function createConversationManager() {
|
|
1169
|
+
let manager = null;
|
|
1170
|
+
let unsub = null;
|
|
1171
|
+
const conversations = writable([]);
|
|
1172
|
+
const activeId = writable(null);
|
|
1173
|
+
const activeConversations = derived(
|
|
1174
|
+
conversations,
|
|
1175
|
+
($c) => $c.filter((c) => !c.archivedAt).sort((a, b) => b.updatedAt - a.updatedAt)
|
|
1176
|
+
);
|
|
1177
|
+
const archivedConversations = derived(
|
|
1178
|
+
conversations,
|
|
1179
|
+
($c) => $c.filter((c) => !!c.archivedAt).sort((a, b) => b.updatedAt - a.updatedAt)
|
|
1180
|
+
);
|
|
1181
|
+
const activeConversation = derived(
|
|
1182
|
+
[conversations, activeId],
|
|
1183
|
+
([$c, $id]) => $id ? $c.find((c) => c.id === $id) ?? null : null
|
|
1184
|
+
);
|
|
1185
|
+
onDestroy(() => unsub?.());
|
|
1186
|
+
const assert = () => {
|
|
1187
|
+
if (!manager) throw new Error("[createConversationManager] Not initialised. Call init(adapter) first.");
|
|
1188
|
+
return manager;
|
|
1189
|
+
};
|
|
1190
|
+
async function init2(adapter) {
|
|
1191
|
+
const m = new ConversationManager(adapter);
|
|
1192
|
+
manager = m;
|
|
1193
|
+
unsub = m.subscribe((convs) => {
|
|
1194
|
+
conversations.set([...convs]);
|
|
1195
|
+
activeId.set(m.activeId);
|
|
1196
|
+
});
|
|
1197
|
+
await m.init();
|
|
1198
|
+
activeId.set(m.activeId);
|
|
1199
|
+
AparteConfig.setConversationManager(m);
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
conversations,
|
|
1203
|
+
activeConversations,
|
|
1204
|
+
archivedConversations,
|
|
1205
|
+
activeId,
|
|
1206
|
+
activeConversation,
|
|
1207
|
+
init: init2,
|
|
1208
|
+
createNew: (title) => assert().createNew(title),
|
|
1209
|
+
addMessage: (convId, message) => assert().addMessage(convId, message),
|
|
1210
|
+
updateMessages: (convId, messages) => assert().updateMessages(convId, messages),
|
|
1211
|
+
delete: (id) => assert().delete(id),
|
|
1212
|
+
archive: (id) => assert().archive(id),
|
|
1213
|
+
unarchive: (id) => assert().unarchive(id)
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
function create_fragment(ctx) {
|
|
1217
|
+
let span;
|
|
1218
|
+
return {
|
|
1219
|
+
c() {
|
|
1220
|
+
span = element("span");
|
|
1221
|
+
set_style(span, "display", "contents");
|
|
1222
|
+
},
|
|
1223
|
+
m(target, anchor) {
|
|
1224
|
+
insert(target, span, anchor);
|
|
1225
|
+
ctx[9](span);
|
|
1226
|
+
},
|
|
1227
|
+
p: noop,
|
|
1228
|
+
i: noop,
|
|
1229
|
+
o: noop,
|
|
1230
|
+
d(detaching) {
|
|
1231
|
+
if (detaching) {
|
|
1232
|
+
detach(span);
|
|
1233
|
+
}
|
|
1234
|
+
ctx[9](null);
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
function instance($$self, $$props, $$invalidate) {
|
|
1239
|
+
let { name } = $$props;
|
|
1240
|
+
let { props = {} } = $$props;
|
|
1241
|
+
let { events = void 0 } = $$props;
|
|
1242
|
+
const dispatch = createEventDispatcher();
|
|
1243
|
+
let host;
|
|
1244
|
+
let el = null;
|
|
1245
|
+
let cleanups = [];
|
|
1246
|
+
function applyProps() {
|
|
1247
|
+
if (el) applyElementProps(el, props);
|
|
1248
|
+
}
|
|
1249
|
+
function create() {
|
|
1250
|
+
if (!host) return;
|
|
1251
|
+
$$invalidate(6, el = document.createElement(name));
|
|
1252
|
+
applyProps();
|
|
1253
|
+
for (const ev of events ?? DEFAULT_UI_EVENTS) {
|
|
1254
|
+
const listener = (e) => dispatch("elementEvent", e);
|
|
1255
|
+
el.addEventListener(ev, listener);
|
|
1256
|
+
cleanups.push(() => el?.removeEventListener(ev, listener));
|
|
1257
|
+
}
|
|
1258
|
+
host.appendChild(el);
|
|
1259
|
+
}
|
|
1260
|
+
function destroy() {
|
|
1261
|
+
for (const c of cleanups) c();
|
|
1262
|
+
cleanups = [];
|
|
1263
|
+
el?.remove();
|
|
1264
|
+
$$invalidate(6, el = null);
|
|
1265
|
+
}
|
|
1266
|
+
onMount(create);
|
|
1267
|
+
onDestroy(destroy);
|
|
1268
|
+
let lastName = name;
|
|
1269
|
+
let lastEvtsKey = (events ?? DEFAULT_UI_EVENTS).join("|");
|
|
1270
|
+
function getElement() {
|
|
1271
|
+
return el;
|
|
1272
|
+
}
|
|
1273
|
+
function callMethod(methodName, ...args) {
|
|
1274
|
+
const fn = el?.[methodName];
|
|
1275
|
+
return typeof fn === "function" ? fn.apply(el, args) : void 0;
|
|
1276
|
+
}
|
|
1277
|
+
function span_binding($$value) {
|
|
1278
|
+
binding_callbacks[$$value ? "unshift" : "push"](() => {
|
|
1279
|
+
host = $$value;
|
|
1280
|
+
$$invalidate(0, host);
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
$$self.$$set = ($$props2) => {
|
|
1284
|
+
if ("name" in $$props2) $$invalidate(1, name = $$props2.name);
|
|
1285
|
+
if ("props" in $$props2) $$invalidate(2, props = $$props2.props);
|
|
1286
|
+
if ("events" in $$props2) $$invalidate(3, events = $$props2.events);
|
|
1287
|
+
};
|
|
1288
|
+
$$self.$$.update = () => {
|
|
1289
|
+
if ($$self.$$.dirty & /*events, el, name, lastName, lastEvtsKey*/
|
|
1290
|
+
458) {
|
|
1291
|
+
{
|
|
1292
|
+
const evtsKey = (events ?? DEFAULT_UI_EVENTS).join("|");
|
|
1293
|
+
if (el && (name !== lastName || evtsKey !== lastEvtsKey)) {
|
|
1294
|
+
$$invalidate(7, lastName = name);
|
|
1295
|
+
$$invalidate(8, lastEvtsKey = evtsKey);
|
|
1296
|
+
destroy();
|
|
1297
|
+
create();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
if ($$self.$$.dirty & /*el, props*/
|
|
1302
|
+
68) {
|
|
1303
|
+
if (el && props) applyProps();
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
return [
|
|
1307
|
+
host,
|
|
1308
|
+
name,
|
|
1309
|
+
props,
|
|
1310
|
+
events,
|
|
1311
|
+
getElement,
|
|
1312
|
+
callMethod,
|
|
1313
|
+
el,
|
|
1314
|
+
lastName,
|
|
1315
|
+
lastEvtsKey,
|
|
1316
|
+
span_binding
|
|
1317
|
+
];
|
|
1318
|
+
}
|
|
1319
|
+
class AparteUi extends SvelteComponent {
|
|
1320
|
+
constructor(options) {
|
|
1321
|
+
super();
|
|
1322
|
+
init(this, options, instance, create_fragment, safe_not_equal, {
|
|
1323
|
+
name: 1,
|
|
1324
|
+
props: 2,
|
|
1325
|
+
events: 3,
|
|
1326
|
+
getElement: 4,
|
|
1327
|
+
callMethod: 5
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
get getElement() {
|
|
1331
|
+
return this.$$.ctx[4];
|
|
1332
|
+
}
|
|
1333
|
+
get callMethod() {
|
|
1334
|
+
return this.$$.ctx[5];
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
export {
|
|
1338
|
+
AparteChat,
|
|
1339
|
+
AparteUi,
|
|
1340
|
+
createAparteChat,
|
|
1341
|
+
createAparteClient,
|
|
1342
|
+
createConversationManager
|
|
1343
|
+
};
|
|
1344
|
+
//# sourceMappingURL=index.js.map
|