@assistant-ui/react 0.15.12 → 0.15.13

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,1348 +0,0 @@
1
- import { SingleThreadList } from "./SingleThreadList.js";
2
- import { Derived, attachTransformScopes, useClientLookup, useClientResource } from "@assistant-ui/store";
3
- import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
- import { DataRenderers, Tools } from "@assistant-ui/core/react";
5
- import { useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
6
- import { ToolResponse } from "assistant-stream";
7
- import { ModelContext, Suggestions } from "@assistant-ui/core/store";
8
- import { resource, withKey } from "@assistant-ui/tap";
9
- import { fileMatchesAccept, getThreadMessageText, isCreateAttachment, resolveToolApprovalResponse, toMessagePartStatus } from "@assistant-ui/core/internal";
10
- //#region src/client/ExternalThread.ts
11
- const EMPTY_QUEUE_ITEMS = [];
12
- const EMPTY_BRANCH_IDS = [];
13
- const COMPLETE_STATUS = Object.freeze({ type: "complete" });
14
- const derivePartStatus = (message, partIndex, part) => {
15
- if (!message.status) return COMPLETE_STATUS;
16
- return toMessagePartStatus(message, partIndex, part);
17
- };
18
- const useMessageClient = (t0) => {
19
- const $ = c(71);
20
- const { message, index, parentId, onEdit, onReload, queue, branches, onRespondToToolApproval, onAddToolResult, onResumeToolCall, attachmentAdapter, submittedFeedback, onSubmitFeedback, speech, onSpeak, onStopSpeaking } = t0;
21
- const [isCopied, setIsCopied] = useState(false);
22
- const [isHovering, setIsHovering] = useState(false);
23
- let t1;
24
- if ($[0] !== message || $[1] !== onAddToolResult || $[2] !== onRespondToToolApproval || $[3] !== onResumeToolCall) {
25
- t1 = message.content.map((part, idx) => withKey(idx, PartResource({
26
- part,
27
- status: derivePartStatus(message, idx, part),
28
- messageId: message.id,
29
- onRespondToToolApproval,
30
- onAddToolResult,
31
- onResumeToolCall
32
- })));
33
- $[0] = message;
34
- $[1] = onAddToolResult;
35
- $[2] = onRespondToToolApproval;
36
- $[3] = onResumeToolCall;
37
- $[4] = t1;
38
- } else t1 = $[4];
39
- const partClients = useClientLookup(t1);
40
- let t2;
41
- if ($[5] !== message.attachments) {
42
- t2 = message.attachments ?? [];
43
- $[5] = message.attachments;
44
- $[6] = t2;
45
- } else t2 = $[6];
46
- let t3;
47
- if ($[7] !== t2) {
48
- t3 = t2.map(_temp2);
49
- $[7] = t2;
50
- $[8] = t3;
51
- } else t3 = $[8];
52
- const attachmentClients = useClientLookup(t3);
53
- let t4;
54
- if ($[9] !== onEdit) {
55
- t4 = () => {
56
- if (!onEdit) throw new Error("Runtime does not support editing.");
57
- };
58
- $[9] = onEdit;
59
- $[10] = t4;
60
- } else t4 = $[10];
61
- const handleBeginEdit = t4;
62
- let t5;
63
- if ($[11] !== message.id || $[12] !== onEdit || $[13] !== parentId) {
64
- t5 = (msg) => {
65
- if (!onEdit) throw new Error("Runtime does not support editing.");
66
- onEdit({
67
- ...msg,
68
- parentId,
69
- sourceId: message.id
70
- });
71
- };
72
- $[11] = message.id;
73
- $[12] = onEdit;
74
- $[13] = parentId;
75
- $[14] = t5;
76
- } else t5 = $[14];
77
- const handleSendEdit = t5;
78
- let t6;
79
- if ($[15] !== attachmentAdapter || $[16] !== handleBeginEdit || $[17] !== handleSendEdit || $[18] !== message || $[19] !== queue) {
80
- t6 = ComposerClientResource({
81
- type: "edit",
82
- canCancel: true,
83
- onBeginEdit: handleBeginEdit,
84
- onSend: handleSendEdit,
85
- message,
86
- queue,
87
- attachmentAdapter
88
- });
89
- $[15] = attachmentAdapter;
90
- $[16] = handleBeginEdit;
91
- $[17] = handleSendEdit;
92
- $[18] = message;
93
- $[19] = queue;
94
- $[20] = t6;
95
- } else t6 = $[20];
96
- const composerClient = useClientResource(t6);
97
- let branchIds;
98
- let t7;
99
- if ($[21] !== branches || $[22] !== message.id) {
100
- branchIds = branches?.getBranches(message.id) ?? EMPTY_BRANCH_IDS;
101
- t7 = branchIds.indexOf(message.id);
102
- $[21] = branches;
103
- $[22] = message.id;
104
- $[23] = branchIds;
105
- $[24] = t7;
106
- } else {
107
- branchIds = $[23];
108
- t7 = $[24];
109
- }
110
- const branchIndex = t7;
111
- const branchNumber = branchIndex === -1 ? 1 : branchIndex + 1;
112
- const branchCount = branchIndex === -1 ? 1 : branchIds.length;
113
- let t8;
114
- if ($[25] !== message || $[26] !== submittedFeedback) {
115
- t8 = submittedFeedback && message.role === "assistant" ? {
116
- ...message,
117
- metadata: {
118
- ...message.metadata,
119
- submittedFeedback: { type: submittedFeedback }
120
- }
121
- } : message;
122
- $[25] = message;
123
- $[26] = submittedFeedback;
124
- $[27] = t8;
125
- } else t8 = $[27];
126
- const messageWithFeedback = t8;
127
- let t9;
128
- if ($[28] !== message.attachments) {
129
- t9 = message.attachments ?? [];
130
- $[28] = message.attachments;
131
- $[29] = t9;
132
- } else t9 = $[29];
133
- let t10;
134
- if ($[30] !== branchCount || $[31] !== branchNumber || $[32] !== composerClient.state || $[33] !== index || $[34] !== isCopied || $[35] !== isHovering || $[36] !== messageWithFeedback || $[37] !== parentId || $[38] !== partClients.state || $[39] !== speech || $[40] !== t9) {
135
- t10 = {
136
- ...messageWithFeedback,
137
- attachments: t9,
138
- parentId,
139
- isLast: false,
140
- branchNumber,
141
- branchCount,
142
- speech,
143
- parts: partClients.state,
144
- isCopied,
145
- isHovering,
146
- index,
147
- composer: composerClient.state
148
- };
149
- $[30] = branchCount;
150
- $[31] = branchNumber;
151
- $[32] = composerClient.state;
152
- $[33] = index;
153
- $[34] = isCopied;
154
- $[35] = isHovering;
155
- $[36] = messageWithFeedback;
156
- $[37] = parentId;
157
- $[38] = partClients.state;
158
- $[39] = speech;
159
- $[40] = t9;
160
- $[41] = t10;
161
- } else t10 = $[41];
162
- const state = t10;
163
- let t11;
164
- if ($[42] !== state) {
165
- t11 = () => state;
166
- $[42] = state;
167
- $[43] = t11;
168
- } else t11 = $[43];
169
- let t12;
170
- if ($[44] !== composerClient.methods) {
171
- t12 = () => composerClient.methods;
172
- $[44] = composerClient.methods;
173
- $[45] = t12;
174
- } else t12 = $[45];
175
- let t13;
176
- if ($[46] !== onReload) {
177
- t13 = () => {
178
- onReload?.();
179
- };
180
- $[46] = onReload;
181
- $[47] = t13;
182
- } else t13 = $[47];
183
- let t14;
184
- if ($[48] !== branchIds || $[49] !== branchIndex || $[50] !== branches || $[51] !== message.id) {
185
- t14 = (t15) => {
186
- const { position, branchId } = t15;
187
- if (!branches) return;
188
- const target = branchId ?? (branchIndex === -1 ? void 0 : position === "previous" ? branchIds[branchIndex - 1] : position === "next" ? branchIds[branchIndex + 1] : void 0);
189
- if (target !== void 0 && target !== message.id) branches.switchToBranch(target);
190
- };
191
- $[48] = branchIds;
192
- $[49] = branchIndex;
193
- $[50] = branches;
194
- $[51] = message.id;
195
- $[52] = t14;
196
- } else t14 = $[52];
197
- let t15;
198
- if ($[53] !== message) {
199
- t15 = () => getThreadMessageText(message);
200
- $[53] = message;
201
- $[54] = t15;
202
- } else t15 = $[54];
203
- let t16;
204
- if ($[55] !== partClients || $[56] !== state) {
205
- t16 = (selector) => {
206
- if ("index" in selector) return partClients.get(selector);
207
- const partIndex = state.parts.findIndex((p) => p.type === "tool-call" && p.toolCallId === selector.toolCallId);
208
- return partClients.get({ index: partIndex });
209
- };
210
- $[55] = partClients;
211
- $[56] = state;
212
- $[57] = t16;
213
- } else t16 = $[57];
214
- let t17;
215
- if ($[58] !== attachmentClients) {
216
- t17 = (selector_0) => {
217
- if ("id" in selector_0) return attachmentClients.get({ key: selector_0.id });
218
- return attachmentClients.get(selector_0);
219
- };
220
- $[58] = attachmentClients;
221
- $[59] = t17;
222
- } else t17 = $[59];
223
- let t18;
224
- if ($[60] !== onSpeak || $[61] !== onStopSpeaking || $[62] !== onSubmitFeedback || $[63] !== t11 || $[64] !== t12 || $[65] !== t13 || $[66] !== t14 || $[67] !== t15 || $[68] !== t16 || $[69] !== t17) {
225
- t18 = {
226
- getState: t11,
227
- composer: t12,
228
- delete: _temp3,
229
- reload: t13,
230
- speak: onSpeak,
231
- stopSpeaking: onStopSpeaking,
232
- submitFeedback: onSubmitFeedback,
233
- switchToBranch: t14,
234
- getCopyText: t15,
235
- part: t16,
236
- attachment: t17,
237
- setIsCopied,
238
- setIsHovering
239
- };
240
- $[60] = onSpeak;
241
- $[61] = onStopSpeaking;
242
- $[62] = onSubmitFeedback;
243
- $[63] = t11;
244
- $[64] = t12;
245
- $[65] = t13;
246
- $[66] = t14;
247
- $[67] = t15;
248
- $[68] = t16;
249
- $[69] = t17;
250
- $[70] = t18;
251
- } else t18 = $[70];
252
- return t18;
253
- };
254
- const MessageClient = resource(useMessageClient);
255
- const usePartResource = (t0) => {
256
- const $ = c(20);
257
- const { part, status, messageId, onRespondToToolApproval, onAddToolResult, onResumeToolCall } = t0;
258
- const t1 = status;
259
- let t2;
260
- if ($[0] !== part || $[1] !== t1) {
261
- t2 = {
262
- ...part,
263
- status: t1
264
- };
265
- $[0] = part;
266
- $[1] = t1;
267
- $[2] = t2;
268
- } else t2 = $[2];
269
- const state = t2;
270
- let t3;
271
- if ($[3] !== state) {
272
- t3 = () => state;
273
- $[3] = state;
274
- $[4] = t3;
275
- } else t3 = $[4];
276
- let t4;
277
- if ($[5] !== messageId || $[6] !== onAddToolResult || $[7] !== part) {
278
- t4 = (result) => {
279
- if (!onAddToolResult) throw new Error("Runtime does not support tool results (onAddToolResult is not set).");
280
- if (part.type !== "tool-call") throw new Error("Tried to add tool result on non-tool message part");
281
- const response = ToolResponse.toResponse(result);
282
- onAddToolResult({
283
- messageId,
284
- toolName: part.toolName,
285
- toolCallId: part.toolCallId,
286
- result: response.result,
287
- isError: response.isError,
288
- ...response.artifact !== void 0 && { artifact: response.artifact },
289
- ...response.modelContent !== void 0 && { modelContent: response.modelContent }
290
- });
291
- };
292
- $[5] = messageId;
293
- $[6] = onAddToolResult;
294
- $[7] = part;
295
- $[8] = t4;
296
- } else t4 = $[8];
297
- let t5;
298
- if ($[9] !== onResumeToolCall || $[10] !== part) {
299
- t5 = (payload) => {
300
- if (!onResumeToolCall) throw new Error("Runtime does not support resuming tool calls (onResumeToolCall is not set).");
301
- if (part.type !== "tool-call") throw new Error("Tried to resume tool call on non-tool message part");
302
- onResumeToolCall({
303
- toolCallId: part.toolCallId,
304
- payload
305
- });
306
- };
307
- $[9] = onResumeToolCall;
308
- $[10] = part;
309
- $[11] = t5;
310
- } else t5 = $[11];
311
- let t6;
312
- if ($[12] !== onRespondToToolApproval || $[13] !== part) {
313
- t6 = (response_0) => {
314
- if (!onRespondToToolApproval) throw new Error("Runtime does not support tool approvals.");
315
- if (part.type !== "tool-call") throw new Error("Tried to respond to tool approval on non-tool message part");
316
- if (!part.approval || part.approval.approved !== void 0 || part.approval.resolution !== void 0) throw new Error("Tool call has no pending approval");
317
- onRespondToToolApproval(resolveToolApprovalResponse(part.approval, response_0));
318
- };
319
- $[12] = onRespondToToolApproval;
320
- $[13] = part;
321
- $[14] = t6;
322
- } else t6 = $[14];
323
- let t7;
324
- if ($[15] !== t3 || $[16] !== t4 || $[17] !== t5 || $[18] !== t6) {
325
- t7 = {
326
- getState: t3,
327
- addToolResult: t4,
328
- resumeToolCall: t5,
329
- respondToToolApproval: t6
330
- };
331
- $[15] = t3;
332
- $[16] = t4;
333
- $[17] = t5;
334
- $[18] = t6;
335
- $[19] = t7;
336
- } else t7 = $[19];
337
- return t7;
338
- };
339
- const PartResource = resource(usePartResource);
340
- const useAttachmentResource = ({ attachment, onRemove }) => {
341
- return {
342
- getState: () => attachment,
343
- remove: async () => {
344
- await onRemove?.();
345
- }
346
- };
347
- };
348
- const AttachmentResource = resource(useAttachmentResource);
349
- const useQueueItemClient = ({ item, onMove, onRemove }) => {
350
- return {
351
- getState: () => item,
352
- steer: () => onMove({
353
- lane: "steer",
354
- insertAfter: null
355
- }),
356
- move: onMove,
357
- remove: onRemove
358
- };
359
- };
360
- const QueueItemClient = resource(useQueueItemClient);
361
- const drainAdapterAdd = async (result, upsert) => {
362
- if (Symbol.asyncIterator in result) for await (const attachment of result) upsert(attachment);
363
- else upsert(await result);
364
- };
365
- const useLiveState = (initial) => {
366
- const $ = c(3);
367
- const [state, setState] = useState(initial);
368
- const ref = useRef(state);
369
- let t0;
370
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
371
- t0 = (next) => {
372
- ref.current = typeof next === "function" ? next(ref.current) : next;
373
- setState(ref.current);
374
- };
375
- $[0] = t0;
376
- } else t0 = $[0];
377
- const set = t0;
378
- let t1;
379
- if ($[1] !== state) {
380
- t1 = [
381
- state,
382
- set,
383
- ref
384
- ];
385
- $[1] = state;
386
- $[2] = t1;
387
- } else t1 = $[2];
388
- return t1;
389
- };
390
- const useComposerClientResource = (t0) => {
391
- const $ = c(104);
392
- const { type, canCancel, isSendDisabled: t1, onCancel, onBeginEdit, onSend, message, queue, attachmentAdapter } = t0;
393
- const isSendDisabled = t1 === void 0 ? false : t1;
394
- const [isEditing, setIsEditing, isEditingRef] = useLiveState(type === "thread");
395
- const [text, setText, textRef] = useLiveState("");
396
- const [role, setRole, roleRef] = useLiveState("user");
397
- let t2;
398
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
399
- t2 = {};
400
- $[0] = t2;
401
- } else t2 = $[0];
402
- const [runConfig, setRunConfig, runConfigRef] = useLiveState(t2);
403
- let t3;
404
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
405
- t3 = [];
406
- $[1] = t3;
407
- } else t3 = $[1];
408
- const [attachments, setAttachments, attachmentsRef] = useLiveState(t3);
409
- const [quote, setQuote, quoteRef] = useLiveState(void 0);
410
- let t4;
411
- if ($[2] !== message || $[3] !== setAttachments || $[4] !== setRole || $[5] !== setText) {
412
- t4 = () => {
413
- if (!message) return;
414
- const messageText = message.content.filter(_temp4).map(_temp5).join("\n\n");
415
- setText(messageText);
416
- setRole(message.role);
417
- setAttachments(message.attachments ?? []);
418
- };
419
- $[2] = message;
420
- $[3] = setAttachments;
421
- $[4] = setRole;
422
- $[5] = setText;
423
- $[6] = t4;
424
- } else t4 = $[6];
425
- const updateFromMessage = t4;
426
- let t5;
427
- if ($[7] !== attachmentAdapter || $[8] !== attachments || $[9] !== setAttachments) {
428
- let t6;
429
- if ($[11] !== attachmentAdapter || $[12] !== setAttachments) {
430
- t6 = (attachment) => withKey(attachment.id, AttachmentResource({
431
- attachment,
432
- onRemove: async () => {
433
- await attachmentAdapter?.remove(attachment);
434
- setAttachments((prev) => prev.filter((a) => a.id !== attachment.id));
435
- }
436
- }));
437
- $[11] = attachmentAdapter;
438
- $[12] = setAttachments;
439
- $[13] = t6;
440
- } else t6 = $[13];
441
- t5 = attachments.map(t6);
442
- $[7] = attachmentAdapter;
443
- $[8] = attachments;
444
- $[9] = setAttachments;
445
- $[10] = t5;
446
- } else t5 = $[10];
447
- const attachmentClients = useClientLookup(t5);
448
- let t6;
449
- if ($[14] !== attachmentAdapter) {
450
- t6 = async (removed) => {
451
- if (!attachmentAdapter) return;
452
- await Promise.all(removed.filter(_temp6).map((a_1) => attachmentAdapter.remove(a_1)));
453
- };
454
- $[14] = attachmentAdapter;
455
- $[15] = t6;
456
- } else t6 = $[15];
457
- const removePendingAttachments = t6;
458
- let t7;
459
- if ($[16] !== setAttachments) {
460
- t7 = (attachment_0) => {
461
- setAttachments((prev_0) => {
462
- const idx = prev_0.findIndex((a_2) => a_2.id === attachment_0.id);
463
- if (idx === -1) return [...prev_0, attachment_0];
464
- const next = [...prev_0];
465
- next[idx] = attachment_0;
466
- return next;
467
- });
468
- };
469
- $[16] = setAttachments;
470
- $[17] = t7;
471
- } else t7 = $[17];
472
- const upsertAttachment = t7;
473
- const steerItems = queue?.steerItems ?? EMPTY_QUEUE_ITEMS;
474
- const laneItems = queue?.items ?? EMPTY_QUEUE_ITEMS;
475
- let t8;
476
- if ($[18] !== laneItems || $[19] !== steerItems) {
477
- t8 = steerItems.length === 0 ? laneItems : laneItems.length === 0 ? steerItems : [...steerItems, ...laneItems];
478
- $[18] = laneItems;
479
- $[19] = steerItems;
480
- $[20] = t8;
481
- } else t8 = $[20];
482
- const queueItems = t8;
483
- let t9;
484
- if ($[21] !== queue || $[22] !== queueItems) {
485
- let t10;
486
- if ($[24] !== queue) {
487
- t10 = (item) => withKey(item.id, QueueItemClient({
488
- item,
489
- onMove: (placement) => queue?.move(item.id, placement),
490
- onRemove: () => queue?.remove(item.id)
491
- }));
492
- $[24] = queue;
493
- $[25] = t10;
494
- } else t10 = $[25];
495
- t9 = queueItems.map(t10);
496
- $[21] = queue;
497
- $[22] = queueItems;
498
- $[23] = t9;
499
- } else t9 = $[23];
500
- const queueItemClients = useClientLookup(t9);
501
- let t10;
502
- if ($[26] !== attachmentAdapter?.accept || $[27] !== attachmentClients.state || $[28] !== attachments.length || $[29] !== canCancel || $[30] !== isEditing || $[31] !== isSendDisabled || $[32] !== queueItems || $[33] !== quote || $[34] !== role || $[35] !== runConfig || $[36] !== text || $[37] !== type) {
503
- t10 = () => {
504
- const isEmpty = !text.trim() && !attachments.length;
505
- return {
506
- text,
507
- role,
508
- attachments: attachmentClients.state,
509
- runConfig,
510
- isEditing,
511
- canCancel,
512
- canSend: isEditing && !isEmpty && !isSendDisabled,
513
- attachmentAccept: attachmentAdapter?.accept ?? "*",
514
- isEmpty,
515
- type,
516
- dictation: void 0,
517
- quote,
518
- queue: queueItems
519
- };
520
- };
521
- $[26] = attachmentAdapter?.accept;
522
- $[27] = attachmentClients.state;
523
- $[28] = attachments.length;
524
- $[29] = canCancel;
525
- $[30] = isEditing;
526
- $[31] = isSendDisabled;
527
- $[32] = queueItems;
528
- $[33] = quote;
529
- $[34] = role;
530
- $[35] = runConfig;
531
- $[36] = text;
532
- $[37] = type;
533
- $[38] = t10;
534
- } else t10 = $[38];
535
- attachmentAdapter?.accept;
536
- let t11;
537
- if ($[39] !== t10) {
538
- t11 = t10();
539
- $[39] = t10;
540
- $[40] = t11;
541
- } else t11 = $[40];
542
- const state = t11;
543
- let t12;
544
- if ($[41] !== state) {
545
- t12 = () => state;
546
- $[41] = state;
547
- $[42] = t12;
548
- } else t12 = $[42];
549
- let t13;
550
- if ($[43] !== attachmentAdapter || $[44] !== setAttachments || $[45] !== upsertAttachment) {
551
- t13 = async (fileOrAttachment) => {
552
- if (attachmentAdapter) {
553
- const file = isCreateAttachment(fileOrAttachment) ? {
554
- name: fileOrAttachment.name,
555
- type: fileOrAttachment.contentType ?? ""
556
- } : {
557
- name: fileOrAttachment.name,
558
- type: fileOrAttachment.type
559
- };
560
- if (!fileMatchesAccept(file, attachmentAdapter.accept)) throw new Error(`File type ${file.type || "unknown"} is not accepted. Accepted types: ${attachmentAdapter.accept}`);
561
- }
562
- if (!isCreateAttachment(fileOrAttachment) && attachmentAdapter) await drainAdapterAdd(attachmentAdapter.add({ file: fileOrAttachment }), upsertAttachment);
563
- else if (!isCreateAttachment(fileOrAttachment)) {
564
- const newAttachment = {
565
- id: Math.random().toString(36).substring(7),
566
- type: "file",
567
- name: fileOrAttachment.name,
568
- contentType: fileOrAttachment.type,
569
- file: fileOrAttachment,
570
- status: { type: "complete" },
571
- content: []
572
- };
573
- setAttachments((prev_1) => [...prev_1, newAttachment]);
574
- } else {
575
- const newAttachment_0 = {
576
- id: fileOrAttachment.id ?? Math.random().toString(36).substring(7),
577
- type: fileOrAttachment.type ?? "document",
578
- name: fileOrAttachment.name,
579
- contentType: fileOrAttachment.contentType,
580
- content: fileOrAttachment.content,
581
- status: { type: "complete" }
582
- };
583
- setAttachments((prev_2) => [...prev_2, newAttachment_0]);
584
- }
585
- };
586
- $[43] = attachmentAdapter;
587
- $[44] = setAttachments;
588
- $[45] = upsertAttachment;
589
- $[46] = t13;
590
- } else t13 = $[46];
591
- let t14;
592
- if ($[47] !== attachmentsRef || $[48] !== removePendingAttachments || $[49] !== setAttachments) {
593
- t14 = async () => {
594
- const removed_0 = attachmentsRef.current;
595
- setAttachments([]);
596
- await removePendingAttachments(removed_0);
597
- };
598
- $[47] = attachmentsRef;
599
- $[48] = removePendingAttachments;
600
- $[49] = setAttachments;
601
- $[50] = t14;
602
- } else t14 = $[50];
603
- let t15;
604
- if ($[51] !== attachmentClients) {
605
- t15 = (selector) => {
606
- if ("id" in selector) return attachmentClients.get({ key: selector.id });
607
- return attachmentClients.get(selector);
608
- };
609
- $[51] = attachmentClients;
610
- $[52] = t15;
611
- } else t15 = $[52];
612
- let t16;
613
- if ($[53] !== attachmentsRef || $[54] !== removePendingAttachments || $[55] !== setAttachments || $[56] !== setQuote || $[57] !== setRole || $[58] !== setRunConfig || $[59] !== setText) {
614
- t16 = async () => {
615
- const removed_1 = attachmentsRef.current;
616
- setText("");
617
- setRole("user");
618
- setRunConfig({});
619
- setAttachments([]);
620
- setQuote(void 0);
621
- await removePendingAttachments(removed_1);
622
- };
623
- $[53] = attachmentsRef;
624
- $[54] = removePendingAttachments;
625
- $[55] = setAttachments;
626
- $[56] = setQuote;
627
- $[57] = setRole;
628
- $[58] = setRunConfig;
629
- $[59] = setText;
630
- $[60] = t16;
631
- } else t16 = $[60];
632
- let t17;
633
- if ($[61] !== attachmentAdapter || $[62] !== attachmentsRef || $[63] !== canCancel || $[64] !== isEditingRef || $[65] !== isSendDisabled || $[66] !== onSend || $[67] !== queue || $[68] !== quoteRef || $[69] !== roleRef || $[70] !== runConfigRef || $[71] !== setAttachments || $[72] !== setIsEditing || $[73] !== setQuote || $[74] !== setText || $[75] !== textRef || $[76] !== type) {
634
- t17 = (opts) => {
635
- const currentQuote = quoteRef.current;
636
- const currentText = textRef.current;
637
- const currentAttachments = attachmentsRef.current;
638
- const isEmpty_0 = !currentText.trim() && !currentAttachments.length;
639
- if (!isEditingRef.current) throw new Error("Composer is not available");
640
- if (isEmpty_0 || isSendDisabled) return;
641
- setText("");
642
- setAttachments([]);
643
- setQuote(void 0);
644
- const dispatch = (sendAttachments) => {
645
- const composedMessage = {
646
- role: roleRef.current,
647
- content: currentText ? [{
648
- type: "text",
649
- text: currentText
650
- }] : [],
651
- attachments: sendAttachments,
652
- createdAt: /* @__PURE__ */ new Date(),
653
- parentId: null,
654
- sourceId: null,
655
- runConfig: runConfigRef.current,
656
- startRun: opts?.startRun,
657
- metadata: { custom: { ...currentQuote ? { quote: currentQuote } : {} } }
658
- };
659
- if (queue && type === "thread") {
660
- if (opts?.steer ?? canCancel) queue.steer(composedMessage);
661
- else queue.enqueue(composedMessage);
662
- } else onSend?.(composedMessage);
663
- if (type === "edit") setIsEditing(false);
664
- };
665
- if (attachmentAdapter && currentAttachments.length > 0) Promise.all(currentAttachments.map((attachment_1) => attachment_1.status.type === "complete" ? attachment_1 : attachmentAdapter.send(attachment_1))).then(dispatch, (error) => {
666
- setText((prev_3) => currentText && prev_3 ? currentText + "\n" + prev_3 : currentText || prev_3);
667
- setQuote((prev_4) => prev_4 ?? currentQuote);
668
- setAttachments((prev_5) => [...currentAttachments, ...prev_5]);
669
- console.error("Failed to send attachments", error);
670
- });
671
- else dispatch(currentAttachments);
672
- };
673
- $[61] = attachmentAdapter;
674
- $[62] = attachmentsRef;
675
- $[63] = canCancel;
676
- $[64] = isEditingRef;
677
- $[65] = isSendDisabled;
678
- $[66] = onSend;
679
- $[67] = queue;
680
- $[68] = quoteRef;
681
- $[69] = roleRef;
682
- $[70] = runConfigRef;
683
- $[71] = setAttachments;
684
- $[72] = setIsEditing;
685
- $[73] = setQuote;
686
- $[74] = setText;
687
- $[75] = textRef;
688
- $[76] = type;
689
- $[77] = t17;
690
- } else t17 = $[77];
691
- let t18;
692
- if ($[78] !== onCancel || $[79] !== setIsEditing || $[80] !== type) {
693
- t18 = () => {
694
- onCancel?.();
695
- if (type === "edit") setIsEditing(false);
696
- };
697
- $[78] = onCancel;
698
- $[79] = setIsEditing;
699
- $[80] = type;
700
- $[81] = t18;
701
- } else t18 = $[81];
702
- let t19;
703
- if ($[82] !== isEditingRef || $[83] !== onBeginEdit || $[84] !== setIsEditing || $[85] !== type || $[86] !== updateFromMessage) {
704
- t19 = () => {
705
- onBeginEdit?.();
706
- if (type === "thread") return;
707
- if (isEditingRef.current) throw new Error("Edit already in progress");
708
- setIsEditing(true);
709
- updateFromMessage();
710
- };
711
- $[82] = isEditingRef;
712
- $[83] = onBeginEdit;
713
- $[84] = setIsEditing;
714
- $[85] = type;
715
- $[86] = updateFromMessage;
716
- $[87] = t19;
717
- } else t19 = $[87];
718
- let t20;
719
- if ($[88] !== queueItemClients) {
720
- t20 = (selector_0) => {
721
- if ("id" in selector_0) return queueItemClients.get({ key: selector_0.id });
722
- return queueItemClients.get(selector_0);
723
- };
724
- $[88] = queueItemClients;
725
- $[89] = t20;
726
- } else t20 = $[89];
727
- let t21;
728
- if ($[90] !== setQuote || $[91] !== setRole || $[92] !== setRunConfig || $[93] !== setText || $[94] !== t12 || $[95] !== t13 || $[96] !== t14 || $[97] !== t15 || $[98] !== t16 || $[99] !== t17 || $[100] !== t18 || $[101] !== t19 || $[102] !== t20) {
729
- t21 = {
730
- getState: t12,
731
- setText,
732
- setRole,
733
- setRunConfig,
734
- addAttachment: t13,
735
- clearAttachments: t14,
736
- attachment: t15,
737
- reset: t16,
738
- send: t17,
739
- cancel: t18,
740
- beginEdit: t19,
741
- startDictation: _temp7,
742
- stopDictation: _temp8,
743
- setQuote,
744
- queueItem: t20
745
- };
746
- $[90] = setQuote;
747
- $[91] = setRole;
748
- $[92] = setRunConfig;
749
- $[93] = setText;
750
- $[94] = t12;
751
- $[95] = t13;
752
- $[96] = t14;
753
- $[97] = t15;
754
- $[98] = t16;
755
- $[99] = t17;
756
- $[100] = t18;
757
- $[101] = t19;
758
- $[102] = t20;
759
- $[103] = t21;
760
- } else t21 = $[103];
761
- return t21;
762
- };
763
- const ComposerClientResource = resource(useComposerClientResource);
764
- const createSpeechController = (notify) => {
765
- let session;
766
- const clear = () => {
767
- if (!session) return;
768
- session.cancel();
769
- session = void 0;
770
- notify(void 0);
771
- };
772
- return {
773
- speak: (adapter, message) => {
774
- clear();
775
- const utterance = adapter.speak(getThreadMessageText(message));
776
- let unsub;
777
- unsub = utterance.subscribe(() => {
778
- if (utterance.status.type === "ended") {
779
- unsub?.();
780
- session = void 0;
781
- notify(void 0);
782
- } else notify({
783
- messageId: message.id,
784
- status: utterance.status
785
- });
786
- });
787
- if (utterance.status.type === "ended") {
788
- unsub();
789
- notify(void 0);
790
- return;
791
- }
792
- session = {
793
- messageId: message.id,
794
- cancel: () => {
795
- unsub();
796
- utterance.cancel();
797
- }
798
- };
799
- notify({
800
- messageId: message.id,
801
- status: utterance.status
802
- });
803
- },
804
- stop: () => {
805
- if (!session) throw new Error("No message is being spoken");
806
- clear();
807
- },
808
- stopMessage: (messageId) => {
809
- if (session?.messageId !== messageId) throw new Error("Message is not being spoken");
810
- clear();
811
- },
812
- dispose: clear
813
- };
814
- };
815
- const dedupeMessagesById = (messages) => {
816
- const seenIds = /* @__PURE__ */ new Set();
817
- const deduped = [];
818
- for (let i = messages.length - 1; i >= 0; i--) {
819
- const message = messages[i];
820
- if (seenIds.has(message.id)) {
821
- console.warn(`ExternalThread: duplicate message id "${message.id}" in the provided messages array; keeping the last occurrence.`);
822
- continue;
823
- }
824
- seenIds.add(message.id);
825
- deduped.push(message);
826
- }
827
- return deduped.length === messages.length ? messages : deduped.reverse();
828
- };
829
- const useExternalThread = (t0) => {
830
- const $ = c(106);
831
- const { messages: messagesProp, isRunning: t1, isLoading: t2, state: threadState, extras, isSendDisabled: t3, onNew, onEdit, onReload, onStartRun, onCancel, onResume, onAddToolResult, onResumeToolCall, onLoadExternalState, attachmentAdapter, feedbackAdapter, speechAdapter, queue, branches, onRespondToToolApproval } = t0;
832
- const isRunning = t1 === void 0 ? false : t1;
833
- const isLoading = t2 === void 0 ? false : t2;
834
- const isSendDisabled = t3 === void 0 ? false : t3;
835
- let t4;
836
- if ($[0] !== messagesProp) {
837
- t4 = dedupeMessagesById(messagesProp);
838
- $[0] = messagesProp;
839
- $[1] = t4;
840
- } else t4 = $[1];
841
- const messages = t4;
842
- let t5;
843
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
844
- t5 = {};
845
- $[2] = t5;
846
- } else t5 = $[2];
847
- const [submittedFeedback, setSubmittedFeedback] = useState(t5);
848
- let t6;
849
- if ($[3] !== submittedFeedback) {
850
- t6 = (msg) => {
851
- const entry = submittedFeedback[msg.id];
852
- return entry && msg.metadata.submittedFeedback?.type === entry.external ? entry.type : void 0;
853
- };
854
- $[3] = submittedFeedback;
855
- $[4] = t6;
856
- } else t6 = $[4];
857
- const feedbackFor = t6;
858
- let t7;
859
- let t8;
860
- if ($[5] !== messages) {
861
- t7 = () => {
862
- setSubmittedFeedback((prev) => {
863
- const live = Object.entries(prev).filter((t9) => {
864
- const [id, entry_0] = t9;
865
- const msg_0 = messages.find((m) => m.id === id);
866
- return !!msg_0 && msg_0.metadata.submittedFeedback?.type === entry_0.external;
867
- });
868
- return live.length === Object.keys(prev).length ? prev : Object.fromEntries(live);
869
- });
870
- };
871
- t8 = [messages];
872
- $[5] = messages;
873
- $[6] = t7;
874
- $[7] = t8;
875
- } else {
876
- t7 = $[6];
877
- t8 = $[7];
878
- }
879
- useEffect(t7, t8);
880
- let t9;
881
- if ($[8] !== feedbackAdapter) {
882
- t9 = (message, t10) => {
883
- const { type } = t10;
884
- if (!feedbackAdapter) throw new Error("Feedback adapter not configured");
885
- feedbackAdapter.submit({
886
- message,
887
- type
888
- });
889
- if (message.role === "assistant") setSubmittedFeedback((prev_0) => ({
890
- ...prev_0,
891
- [message.id]: {
892
- type,
893
- external: message.metadata.submittedFeedback?.type
894
- }
895
- }));
896
- };
897
- $[8] = feedbackAdapter;
898
- $[9] = t9;
899
- } else t9 = $[9];
900
- const handleSubmitFeedback = t9;
901
- const [speechState, setSpeech] = useState(void 0);
902
- let t10;
903
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
904
- t10 = () => createSpeechController(setSpeech);
905
- $[10] = t10;
906
- } else t10 = $[10];
907
- const [speechController] = useState(t10);
908
- const hasSpeechAdapter = !!speechAdapter;
909
- const speech = hasSpeechAdapter ? speechState : void 0;
910
- let t11;
911
- let t12;
912
- if ($[11] !== hasSpeechAdapter || $[12] !== speechController) {
913
- t11 = () => {
914
- if (!hasSpeechAdapter) speechController.dispose();
915
- };
916
- t12 = [hasSpeechAdapter, speechController];
917
- $[11] = hasSpeechAdapter;
918
- $[12] = speechController;
919
- $[13] = t11;
920
- $[14] = t12;
921
- } else {
922
- t11 = $[13];
923
- t12 = $[14];
924
- }
925
- useEffect(t11, t12);
926
- let t13;
927
- let t14;
928
- if ($[15] !== speechController) {
929
- t13 = () => () => speechController.dispose();
930
- t14 = [speechController];
931
- $[15] = speechController;
932
- $[16] = t13;
933
- $[17] = t14;
934
- } else {
935
- t13 = $[16];
936
- t14 = $[17];
937
- }
938
- useEffect(t13, t14);
939
- let t15;
940
- if ($[18] !== speechAdapter || $[19] !== speechController) {
941
- t15 = (message_0) => {
942
- if (!speechAdapter) throw new Error("Speech adapter not configured");
943
- speechController.speak(speechAdapter, message_0);
944
- };
945
- $[18] = speechAdapter;
946
- $[19] = speechController;
947
- $[20] = t15;
948
- } else t15 = $[20];
949
- const handleSpeak = t15;
950
- let t16;
951
- if ($[21] !== messages || $[22] !== onReload) {
952
- t16 = (messageId) => {
953
- const messageIndex = messages.findIndex((m_0) => m_0.id === messageId);
954
- if (messageIndex === -1) return;
955
- const parentId = messageIndex > 0 ? messages[messageIndex - 1].id : null;
956
- onReload?.(parentId);
957
- };
958
- $[21] = messages;
959
- $[22] = onReload;
960
- $[23] = t16;
961
- } else t16 = $[23];
962
- const handleReload = t16;
963
- let t17;
964
- if ($[24] !== attachmentAdapter || $[25] !== branches || $[26] !== feedbackFor || $[27] !== handleReload || $[28] !== handleSpeak || $[29] !== handleSubmitFeedback || $[30] !== messages || $[31] !== onAddToolResult || $[32] !== onEdit || $[33] !== onRespondToToolApproval || $[34] !== onResumeToolCall || $[35] !== queue || $[36] !== speech || $[37] !== speechController) {
965
- t17 = messages.map((msg_1, index) => {
966
- const props = {
967
- message: msg_1,
968
- index,
969
- parentId: index > 0 ? messages[index - 1].id : null,
970
- onReload: () => handleReload(msg_1.id),
971
- queue,
972
- branches,
973
- onRespondToToolApproval,
974
- onAddToolResult,
975
- onResumeToolCall,
976
- attachmentAdapter,
977
- submittedFeedback: feedbackFor(msg_1),
978
- onSubmitFeedback: (feedback) => handleSubmitFeedback(msg_1, feedback),
979
- speech: speech?.messageId === msg_1.id ? speech : void 0,
980
- onSpeak: () => handleSpeak(msg_1),
981
- onStopSpeaking: () => speechController.stopMessage(msg_1.id)
982
- };
983
- if (onEdit) props.onEdit = onEdit;
984
- return withKey(msg_1.id, MessageClient(props));
985
- });
986
- $[24] = attachmentAdapter;
987
- $[25] = branches;
988
- $[26] = feedbackFor;
989
- $[27] = handleReload;
990
- $[28] = handleSpeak;
991
- $[29] = handleSubmitFeedback;
992
- $[30] = messages;
993
- $[31] = onAddToolResult;
994
- $[32] = onEdit;
995
- $[33] = onRespondToToolApproval;
996
- $[34] = onResumeToolCall;
997
- $[35] = queue;
998
- $[36] = speech;
999
- $[37] = speechController;
1000
- $[38] = t17;
1001
- } else t17 = $[38];
1002
- const messageClients = useClientLookup(t17);
1003
- let t18;
1004
- if ($[39] !== onCancel) {
1005
- t18 = () => {
1006
- onCancel?.();
1007
- };
1008
- $[39] = onCancel;
1009
- $[40] = t18;
1010
- } else t18 = $[40];
1011
- const handleCancelRun = t18;
1012
- let t19;
1013
- if ($[41] !== messages || $[42] !== onNew) {
1014
- t19 = (message_1) => {
1015
- onNew?.({
1016
- ...message_1,
1017
- parentId: messages.at(-1)?.id ?? null
1018
- });
1019
- };
1020
- $[41] = messages;
1021
- $[42] = onNew;
1022
- $[43] = t19;
1023
- } else t19 = $[43];
1024
- const handleSendNew = t19;
1025
- let t20;
1026
- if ($[44] !== messages) {
1027
- t20 = messages.at(-1)?.id ?? null;
1028
- $[44] = messages;
1029
- $[45] = t20;
1030
- } else t20 = $[45];
1031
- const headId = t20;
1032
- let t21;
1033
- if ($[46] !== headId || $[47] !== queue) {
1034
- t21 = queue && {
1035
- ...queue,
1036
- enqueue: (message_2) => queue.enqueue({
1037
- ...message_2,
1038
- parentId: message_2.parentId ?? headId
1039
- }),
1040
- steer: (message_3) => queue.steer({
1041
- ...message_3,
1042
- parentId: message_3.parentId ?? headId
1043
- })
1044
- };
1045
- $[46] = headId;
1046
- $[47] = queue;
1047
- $[48] = t21;
1048
- } else t21 = $[48];
1049
- const composerQueue = t21;
1050
- let t22;
1051
- if ($[49] !== attachmentAdapter || $[50] !== composerQueue || $[51] !== handleCancelRun || $[52] !== handleSendNew || $[53] !== isRunning || $[54] !== isSendDisabled) {
1052
- t22 = ComposerClientResource({
1053
- type: "thread",
1054
- canCancel: isRunning,
1055
- isSendDisabled,
1056
- onCancel: handleCancelRun,
1057
- onSend: handleSendNew,
1058
- queue: composerQueue,
1059
- attachmentAdapter
1060
- });
1061
- $[49] = attachmentAdapter;
1062
- $[50] = composerQueue;
1063
- $[51] = handleCancelRun;
1064
- $[52] = handleSendNew;
1065
- $[53] = isRunning;
1066
- $[54] = isSendDisabled;
1067
- $[55] = t22;
1068
- } else t22 = $[55];
1069
- const composerClient = useClientResource(t22);
1070
- const hasQueue = !!queue;
1071
- const hasBranches = !!branches;
1072
- const hasEdit = !!onEdit;
1073
- const hasReload = !!onReload;
1074
- const hasAttachments = !!attachmentAdapter;
1075
- const hasFeedback = !!feedbackAdapter;
1076
- const hasSpeech = !!speechAdapter;
1077
- let t23;
1078
- if ($[56] !== messageClients.state) {
1079
- t23 = messageClients.state.map(_temp9);
1080
- $[56] = messageClients.state;
1081
- $[57] = t23;
1082
- } else t23 = $[57];
1083
- const messageStates = t23;
1084
- const t24 = messages.length === 0;
1085
- let t25;
1086
- if ($[58] !== hasAttachments || $[59] !== hasBranches || $[60] !== hasEdit || $[61] !== hasFeedback || $[62] !== hasQueue || $[63] !== hasReload || $[64] !== hasSpeech || $[65] !== isRunning) {
1087
- t25 = {
1088
- edit: hasEdit,
1089
- delete: false,
1090
- reload: hasReload,
1091
- refetchThread: false,
1092
- cancel: isRunning,
1093
- speech: hasSpeech,
1094
- attachments: hasAttachments,
1095
- feedback: hasFeedback,
1096
- voice: false,
1097
- switchToBranch: hasBranches,
1098
- switchBranchDuringRun: false,
1099
- unstable_copy: false,
1100
- dictation: false,
1101
- queue: hasQueue
1102
- };
1103
- $[58] = hasAttachments;
1104
- $[59] = hasBranches;
1105
- $[60] = hasEdit;
1106
- $[61] = hasFeedback;
1107
- $[62] = hasQueue;
1108
- $[63] = hasReload;
1109
- $[64] = hasSpeech;
1110
- $[65] = isRunning;
1111
- $[66] = t25;
1112
- } else t25 = $[66];
1113
- let t26;
1114
- if ($[67] !== threadState) {
1115
- t26 = threadState ?? {};
1116
- $[67] = threadState;
1117
- $[68] = t26;
1118
- } else t26 = $[68];
1119
- let t27;
1120
- if ($[69] === Symbol.for("react.memo_cache_sentinel")) {
1121
- t27 = [];
1122
- $[69] = t27;
1123
- } else t27 = $[69];
1124
- let t28;
1125
- if ($[70] !== composerClient.state || $[71] !== extras || $[72] !== isLoading || $[73] !== isRunning || $[74] !== messageStates || $[75] !== speech || $[76] !== t24 || $[77] !== t25 || $[78] !== t26) {
1126
- t28 = {
1127
- isEmpty: t24,
1128
- isDisabled: false,
1129
- isLoading,
1130
- isRunning,
1131
- capabilities: t25,
1132
- messages: messageStates,
1133
- state: t26,
1134
- suggestions: t27,
1135
- extras,
1136
- speech,
1137
- voice: void 0,
1138
- composer: composerClient.state
1139
- };
1140
- $[70] = composerClient.state;
1141
- $[71] = extras;
1142
- $[72] = isLoading;
1143
- $[73] = isRunning;
1144
- $[74] = messageStates;
1145
- $[75] = speech;
1146
- $[76] = t24;
1147
- $[77] = t25;
1148
- $[78] = t26;
1149
- $[79] = t28;
1150
- } else t28 = $[79];
1151
- const state = t28;
1152
- let t29;
1153
- if ($[80] !== state) {
1154
- t29 = () => state;
1155
- $[80] = state;
1156
- $[81] = t29;
1157
- } else t29 = $[81];
1158
- let t30;
1159
- if ($[82] !== composerClient.methods) {
1160
- t30 = () => composerClient.methods;
1161
- $[82] = composerClient.methods;
1162
- $[83] = t30;
1163
- } else t30 = $[83];
1164
- let t31;
1165
- if ($[84] !== messages || $[85] !== onNew || $[86] !== queue) {
1166
- t31 = (message_4) => {
1167
- const appendMessage = typeof message_4 === "string" ? {
1168
- createdAt: /* @__PURE__ */ new Date(),
1169
- parentId: messages.at(-1)?.id ?? null,
1170
- sourceId: null,
1171
- runConfig: {},
1172
- role: "user",
1173
- content: [{
1174
- type: "text",
1175
- text: message_4
1176
- }],
1177
- attachments: [],
1178
- metadata: { custom: {} }
1179
- } : {
1180
- createdAt: message_4.createdAt ?? /* @__PURE__ */ new Date(),
1181
- parentId: message_4.parentId ?? messages.at(-1)?.id ?? null,
1182
- sourceId: message_4.sourceId ?? null,
1183
- role: message_4.role ?? "user",
1184
- content: message_4.content,
1185
- attachments: message_4.attachments ?? [],
1186
- metadata: message_4.metadata ?? { custom: {} },
1187
- runConfig: message_4.runConfig ?? {},
1188
- startRun: message_4.startRun
1189
- };
1190
- if (queue) queue.enqueue(appendMessage);
1191
- else onNew?.(appendMessage);
1192
- };
1193
- $[84] = messages;
1194
- $[85] = onNew;
1195
- $[86] = queue;
1196
- $[87] = t31;
1197
- } else t31 = $[87];
1198
- let t32;
1199
- if ($[88] !== onStartRun) {
1200
- t32 = () => {
1201
- onStartRun?.();
1202
- };
1203
- $[88] = onStartRun;
1204
- $[89] = t32;
1205
- } else t32 = $[89];
1206
- let t33;
1207
- if ($[90] !== onResume) {
1208
- t33 = () => {
1209
- if (!onResume) throw new Error("Runtime does not support resuming runs (onResume is not set).");
1210
- onResume();
1211
- };
1212
- $[90] = onResume;
1213
- $[91] = t33;
1214
- } else t33 = $[91];
1215
- let t34;
1216
- if ($[92] !== onLoadExternalState) {
1217
- t34 = (state_0) => {
1218
- if (!onLoadExternalState) throw new Error("Runtime does not support importing external states (onLoadExternalState is not set).");
1219
- onLoadExternalState(state_0);
1220
- };
1221
- $[92] = onLoadExternalState;
1222
- $[93] = t34;
1223
- } else t34 = $[93];
1224
- let t35;
1225
- if ($[94] !== messageClients) {
1226
- t35 = (selector) => {
1227
- if ("id" in selector) return messageClients.get({ key: selector.id });
1228
- return messageClients.get(selector);
1229
- };
1230
- $[94] = messageClients;
1231
- $[95] = t35;
1232
- } else t35 = $[95];
1233
- let t36;
1234
- if ($[96] !== handleCancelRun || $[97] !== speechController.stop || $[98] !== t29 || $[99] !== t30 || $[100] !== t31 || $[101] !== t32 || $[102] !== t33 || $[103] !== t34 || $[104] !== t35) {
1235
- t36 = {
1236
- getState: t29,
1237
- composer: t30,
1238
- append: t31,
1239
- deleteMessage: _temp0,
1240
- startRun: t32,
1241
- resumeRun: t33,
1242
- cancelRun: handleCancelRun,
1243
- importExternalState: t34,
1244
- getModelContext: _temp1,
1245
- export: _temp10,
1246
- import: _temp11,
1247
- reset: _temp12,
1248
- message: t35,
1249
- stopSpeaking: speechController.stop,
1250
- connectVoice: _temp13,
1251
- disconnectVoice: _temp14,
1252
- getVoiceVolume: _temp15,
1253
- subscribeVoiceVolume: _temp17,
1254
- muteVoice: _temp18,
1255
- unmuteVoice: _temp19
1256
- };
1257
- $[96] = handleCancelRun;
1258
- $[97] = speechController.stop;
1259
- $[98] = t29;
1260
- $[99] = t30;
1261
- $[100] = t31;
1262
- $[101] = t32;
1263
- $[102] = t33;
1264
- $[103] = t34;
1265
- $[104] = t35;
1266
- $[105] = t36;
1267
- } else t36 = $[105];
1268
- return t36;
1269
- };
1270
- const ExternalThread = resource(useExternalThread);
1271
- attachTransformScopes(useExternalThread, (scopes, parent) => {
1272
- if (!scopes.threads && parent.threads.source === null) {
1273
- const threadElement = scopes.thread;
1274
- scopes.threads = SingleThreadList({ thread: threadElement });
1275
- delete scopes.thread;
1276
- scopes.thread = Derived({
1277
- source: "threads",
1278
- query: { type: "main" },
1279
- get: (aui) => aui.threads.thread("main")
1280
- });
1281
- }
1282
- if (!scopes.threadListItem && parent.threadListItem.source === null) scopes.threadListItem = Derived({
1283
- source: "threads",
1284
- query: { type: "main" },
1285
- get: (aui) => aui.threads.item("main")
1286
- });
1287
- scopes.composer ??= Derived({
1288
- source: "thread",
1289
- query: {},
1290
- get: (aui) => aui.thread.composer()
1291
- });
1292
- if (!scopes.modelContext && parent.modelContext.source === null) scopes.modelContext = ModelContext();
1293
- if (!scopes.tools && parent.tools.source === null) scopes.tools = Tools({});
1294
- if (!scopes.dataRenderers && parent.dataRenderers.source === null) scopes.dataRenderers = DataRenderers();
1295
- if (!scopes.suggestions && parent.suggestions.source === null) scopes.suggestions = Suggestions();
1296
- });
1297
- function _temp() {}
1298
- function _temp2(attachment) {
1299
- return withKey(attachment.id, AttachmentResource({
1300
- attachment,
1301
- onRemove: _temp
1302
- }));
1303
- }
1304
- function _temp3() {}
1305
- function _temp4(part) {
1306
- return part.type === "text";
1307
- }
1308
- function _temp5(part_0) {
1309
- return part_0.text;
1310
- }
1311
- function _temp6(a_0) {
1312
- return a_0.status.type !== "complete";
1313
- }
1314
- function _temp7() {}
1315
- function _temp8() {}
1316
- function _temp9(s, idx, arr) {
1317
- return {
1318
- ...s,
1319
- isLast: idx === arr.length - 1
1320
- };
1321
- }
1322
- function _temp0() {}
1323
- function _temp1() {
1324
- return {
1325
- tools: {},
1326
- config: {}
1327
- };
1328
- }
1329
- function _temp10() {
1330
- return { messages: [] };
1331
- }
1332
- function _temp11() {}
1333
- function _temp12() {}
1334
- function _temp13() {}
1335
- function _temp14() {}
1336
- function _temp15() {
1337
- return 0;
1338
- }
1339
- function _temp16() {}
1340
- function _temp17() {
1341
- return _temp16;
1342
- }
1343
- function _temp18() {}
1344
- function _temp19() {}
1345
- //#endregion
1346
- export { ExternalThread };
1347
-
1348
- //# sourceMappingURL=ExternalThread.js.map