@assistant-ui/react 0.15.9 → 0.15.11

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.
@@ -2,7 +2,7 @@ import { SingleThreadList } from "./SingleThreadList.js";
2
2
  import { Derived, attachTransformScopes, useClientLookup, useClientResource } from "@assistant-ui/store";
3
3
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
4
  import { DataRenderers, Tools } from "@assistant-ui/core/react";
5
- import { useEffect, useEffectEvent, useRef, useState } from "@assistant-ui/tap/react-shim";
5
+ import { useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
6
6
  import { ToolResponse } from "assistant-stream";
7
7
  import { ModelContext, Suggestions } from "@assistant-ui/core/store";
8
8
  import { resource, withKey } from "@assistant-ui/tap";
@@ -20,7 +20,6 @@ const useMessageClient = (t0) => {
20
20
  const { message, index, parentId, onEdit, onReload, queue, branches, onRespondToToolApproval, onAddToolResult, onResumeToolCall, attachmentAdapter, submittedFeedback, onSubmitFeedback, speech, onSpeak, onStopSpeaking } = t0;
21
21
  const [isCopied, setIsCopied] = useState(false);
22
22
  const [isHovering, setIsHovering] = useState(false);
23
- const [isEditing, setIsEditing] = useState(false);
24
23
  let t1;
25
24
  if ($[0] !== message || $[1] !== onAddToolResult || $[2] !== onRespondToToolApproval || $[3] !== onResumeToolCall) {
26
25
  t1 = message.content.map((part, idx) => withKey(idx, PartResource({
@@ -52,44 +51,35 @@ const useMessageClient = (t0) => {
52
51
  } else t3 = $[8];
53
52
  const attachmentClients = useClientLookup(t3);
54
53
  let t4;
55
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
54
+ if ($[9] !== onEdit) {
56
55
  t4 = () => {
57
- setIsEditing(true);
56
+ if (!onEdit) throw new Error("Runtime does not support editing.");
58
57
  };
59
- $[9] = t4;
60
- } else t4 = $[9];
58
+ $[9] = onEdit;
59
+ $[10] = t4;
60
+ } else t4 = $[10];
61
61
  const handleBeginEdit = t4;
62
62
  let t5;
63
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
64
- t5 = () => {
65
- setIsEditing(false);
66
- };
67
- $[10] = t5;
68
- } else t5 = $[10];
69
- const handleCancelEdit = t5;
70
- let t6;
71
63
  if ($[11] !== message.id || $[12] !== onEdit || $[13] !== parentId) {
72
- t6 = (msg) => {
73
- onEdit?.({
64
+ t5 = (msg) => {
65
+ if (!onEdit) throw new Error("Runtime does not support editing.");
66
+ onEdit({
74
67
  ...msg,
75
68
  parentId,
76
69
  sourceId: message.id
77
70
  });
78
- setIsEditing(false);
79
71
  };
80
72
  $[11] = message.id;
81
73
  $[12] = onEdit;
82
74
  $[13] = parentId;
83
- $[14] = t6;
84
- } else t6 = $[14];
85
- const handleSendEdit = t6;
86
- let t7;
87
- if ($[15] !== attachmentAdapter || $[16] !== handleSendEdit || $[17] !== isEditing || $[18] !== message || $[19] !== queue) {
88
- t7 = ComposerClientResource({
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({
89
81
  type: "edit",
90
- isEditing,
91
82
  canCancel: true,
92
- onCancel: handleCancelEdit,
93
83
  onBeginEdit: handleBeginEdit,
94
84
  onSend: handleSendEdit,
95
85
  message,
@@ -97,32 +87,32 @@ const useMessageClient = (t0) => {
97
87
  attachmentAdapter
98
88
  });
99
89
  $[15] = attachmentAdapter;
100
- $[16] = handleSendEdit;
101
- $[17] = isEditing;
90
+ $[16] = handleBeginEdit;
91
+ $[17] = handleSendEdit;
102
92
  $[18] = message;
103
93
  $[19] = queue;
104
- $[20] = t7;
105
- } else t7 = $[20];
106
- const composerClient = useClientResource(t7);
94
+ $[20] = t6;
95
+ } else t6 = $[20];
96
+ const composerClient = useClientResource(t6);
107
97
  let branchIds;
108
- let t8;
98
+ let t7;
109
99
  if ($[21] !== branches || $[22] !== message.id) {
110
100
  branchIds = branches?.getBranches(message.id) ?? EMPTY_BRANCH_IDS;
111
- t8 = branchIds.indexOf(message.id);
101
+ t7 = branchIds.indexOf(message.id);
112
102
  $[21] = branches;
113
103
  $[22] = message.id;
114
104
  $[23] = branchIds;
115
- $[24] = t8;
105
+ $[24] = t7;
116
106
  } else {
117
107
  branchIds = $[23];
118
- t8 = $[24];
108
+ t7 = $[24];
119
109
  }
120
- const branchIndex = t8;
110
+ const branchIndex = t7;
121
111
  const branchNumber = branchIndex === -1 ? 1 : branchIndex + 1;
122
112
  const branchCount = branchIndex === -1 ? 1 : branchIds.length;
123
- let t9;
113
+ let t8;
124
114
  if ($[25] !== message || $[26] !== submittedFeedback) {
125
- t9 = submittedFeedback && message.role === "assistant" ? {
115
+ t8 = submittedFeedback && message.role === "assistant" ? {
126
116
  ...message,
127
117
  metadata: {
128
118
  ...message.metadata,
@@ -131,20 +121,20 @@ const useMessageClient = (t0) => {
131
121
  } : message;
132
122
  $[25] = message;
133
123
  $[26] = submittedFeedback;
134
- $[27] = t9;
135
- } else t9 = $[27];
136
- const messageWithFeedback = t9;
137
- let t10;
124
+ $[27] = t8;
125
+ } else t8 = $[27];
126
+ const messageWithFeedback = t8;
127
+ let t9;
138
128
  if ($[28] !== message.attachments) {
139
- t10 = message.attachments ?? [];
129
+ t9 = message.attachments ?? [];
140
130
  $[28] = message.attachments;
141
- $[29] = t10;
142
- } else t10 = $[29];
143
- let t11;
144
- if ($[30] !== branchCount || $[31] !== branchNumber || $[32] !== composerClient.state || $[33] !== index || $[34] !== isCopied || $[35] !== isHovering || $[36] !== messageWithFeedback || $[37] !== parentId || $[38] !== partClients.state || $[39] !== speech || $[40] !== t10) {
145
- t11 = {
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 = {
146
136
  ...messageWithFeedback,
147
- attachments: t10,
137
+ attachments: t9,
148
138
  parentId,
149
139
  isLast: false,
150
140
  branchNumber,
@@ -166,34 +156,34 @@ const useMessageClient = (t0) => {
166
156
  $[37] = parentId;
167
157
  $[38] = partClients.state;
168
158
  $[39] = speech;
169
- $[40] = t10;
170
- $[41] = t11;
171
- } else t11 = $[41];
172
- const state = t11;
173
- let t12;
159
+ $[40] = t9;
160
+ $[41] = t10;
161
+ } else t10 = $[41];
162
+ const state = t10;
163
+ let t11;
174
164
  if ($[42] !== state) {
175
- t12 = () => state;
165
+ t11 = () => state;
176
166
  $[42] = state;
177
- $[43] = t12;
178
- } else t12 = $[43];
179
- let t13;
167
+ $[43] = t11;
168
+ } else t11 = $[43];
169
+ let t12;
180
170
  if ($[44] !== composerClient.methods) {
181
- t13 = () => composerClient.methods;
171
+ t12 = () => composerClient.methods;
182
172
  $[44] = composerClient.methods;
183
- $[45] = t13;
184
- } else t13 = $[45];
185
- let t14;
173
+ $[45] = t12;
174
+ } else t12 = $[45];
175
+ let t13;
186
176
  if ($[46] !== onReload) {
187
- t14 = () => {
177
+ t13 = () => {
188
178
  onReload?.();
189
179
  };
190
180
  $[46] = onReload;
191
- $[47] = t14;
192
- } else t14 = $[47];
193
- let t15;
181
+ $[47] = t13;
182
+ } else t13 = $[47];
183
+ let t14;
194
184
  if ($[48] !== branchIds || $[49] !== branchIndex || $[50] !== branches || $[51] !== message.id) {
195
- t15 = (t16) => {
196
- const { position, branchId } = t16;
185
+ t14 = (t15) => {
186
+ const { position, branchId } = t15;
197
187
  if (!branches) return;
198
188
  const target = branchId ?? (branchIndex === -1 ? void 0 : position === "previous" ? branchIds[branchIndex - 1] : position === "next" ? branchIds[branchIndex + 1] : void 0);
199
189
  if (target !== void 0 && target !== message.id) branches.switchToBranch(target);
@@ -202,64 +192,64 @@ const useMessageClient = (t0) => {
202
192
  $[49] = branchIndex;
203
193
  $[50] = branches;
204
194
  $[51] = message.id;
205
- $[52] = t15;
206
- } else t15 = $[52];
207
- let t16;
195
+ $[52] = t14;
196
+ } else t14 = $[52];
197
+ let t15;
208
198
  if ($[53] !== message) {
209
- t16 = () => getThreadMessageText(message);
199
+ t15 = () => getThreadMessageText(message);
210
200
  $[53] = message;
211
- $[54] = t16;
212
- } else t16 = $[54];
213
- let t17;
201
+ $[54] = t15;
202
+ } else t15 = $[54];
203
+ let t16;
214
204
  if ($[55] !== partClients || $[56] !== state) {
215
- t17 = (selector) => {
205
+ t16 = (selector) => {
216
206
  if ("index" in selector) return partClients.get(selector);
217
207
  const partIndex = state.parts.findIndex((p) => p.type === "tool-call" && p.toolCallId === selector.toolCallId);
218
208
  return partClients.get({ index: partIndex });
219
209
  };
220
210
  $[55] = partClients;
221
211
  $[56] = state;
222
- $[57] = t17;
223
- } else t17 = $[57];
224
- let t18;
212
+ $[57] = t16;
213
+ } else t16 = $[57];
214
+ let t17;
225
215
  if ($[58] !== attachmentClients) {
226
- t18 = (selector_0) => {
216
+ t17 = (selector_0) => {
227
217
  if ("id" in selector_0) return attachmentClients.get({ key: selector_0.id });
228
218
  return attachmentClients.get(selector_0);
229
219
  };
230
220
  $[58] = attachmentClients;
231
- $[59] = t18;
232
- } else t18 = $[59];
233
- let t19;
234
- if ($[60] !== onSpeak || $[61] !== onStopSpeaking || $[62] !== onSubmitFeedback || $[63] !== t12 || $[64] !== t13 || $[65] !== t14 || $[66] !== t15 || $[67] !== t16 || $[68] !== t17 || $[69] !== t18) {
235
- t19 = {
236
- getState: t12,
237
- composer: t13,
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,
238
228
  delete: _temp3,
239
- reload: t14,
229
+ reload: t13,
240
230
  speak: onSpeak,
241
231
  stopSpeaking: onStopSpeaking,
242
232
  submitFeedback: onSubmitFeedback,
243
- switchToBranch: t15,
244
- getCopyText: t16,
245
- part: t17,
246
- attachment: t18,
233
+ switchToBranch: t14,
234
+ getCopyText: t15,
235
+ part: t16,
236
+ attachment: t17,
247
237
  setIsCopied,
248
238
  setIsHovering
249
239
  };
250
240
  $[60] = onSpeak;
251
241
  $[61] = onStopSpeaking;
252
242
  $[62] = onSubmitFeedback;
253
- $[63] = t12;
254
- $[64] = t13;
255
- $[65] = t14;
256
- $[66] = t15;
257
- $[67] = t16;
258
- $[68] = t17;
259
- $[69] = t18;
260
- $[70] = t19;
261
- } else t19 = $[70];
262
- return t19;
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;
263
253
  };
264
254
  const MessageClient = resource(useMessageClient);
265
255
  const usePartResource = (t0) => {
@@ -398,9 +388,10 @@ const useLiveState = (initial) => {
398
388
  return t1;
399
389
  };
400
390
  const useComposerClientResource = (t0) => {
401
- const $ = c(100);
402
- const { type, isEditing, canCancel, isSendDisabled: t1, onCancel, onBeginEdit, onSend, message, queue, attachmentAdapter } = t0;
391
+ const $ = c(104);
392
+ const { type, canCancel, isSendDisabled: t1, onCancel, onBeginEdit, onSend, message, queue, attachmentAdapter } = t0;
403
393
  const isSendDisabled = t1 === void 0 ? false : t1;
394
+ const [isEditing, setIsEditing, isEditingRef] = useLiveState(type === "thread");
404
395
  const [text, setText, textRef] = useLiveState("");
405
396
  const [role, setRole, roleRef] = useLiveState("user");
406
397
  let t2;
@@ -419,12 +410,11 @@ const useComposerClientResource = (t0) => {
419
410
  let t4;
420
411
  if ($[2] !== message || $[3] !== setAttachments || $[4] !== setRole || $[5] !== setText) {
421
412
  t4 = () => {
422
- if (message) {
423
- const messageText = message.content.filter(_temp4).map(_temp5).join("\n\n");
424
- setText(messageText);
425
- setRole(message.role);
426
- setAttachments(message.attachments ?? []);
427
- }
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 ?? []);
428
418
  };
429
419
  $[2] = message;
430
420
  $[3] = setAttachments;
@@ -432,58 +422,42 @@ const useComposerClientResource = (t0) => {
432
422
  $[5] = setText;
433
423
  $[6] = t4;
434
424
  } else t4 = $[6];
435
- const updateFromMessage = useEffectEvent(t4);
425
+ const updateFromMessage = t4;
436
426
  let t5;
437
- if ($[7] !== isEditing || $[8] !== updateFromMessage) {
438
- t5 = () => {
439
- if (isEditing) updateFromMessage();
440
- };
441
- $[7] = isEditing;
442
- $[8] = updateFromMessage;
443
- $[9] = t5;
444
- } else t5 = $[9];
445
- let t6;
446
- if ($[10] !== isEditing) {
447
- t6 = [isEditing];
448
- $[10] = isEditing;
449
- $[11] = t6;
450
- } else t6 = $[11];
451
- useEffect(t5, t6);
452
- let t7;
453
- if ($[12] !== attachmentAdapter || $[13] !== attachments || $[14] !== setAttachments) {
454
- let t8;
455
- if ($[16] !== attachmentAdapter || $[17] !== setAttachments) {
456
- t8 = (attachment) => withKey(attachment.id, AttachmentResource({
427
+ if ($[7] !== attachmentAdapter || $[8] !== attachments || $[9] !== setAttachments) {
428
+ let t6;
429
+ if ($[11] !== attachmentAdapter || $[12] !== setAttachments) {
430
+ t6 = (attachment) => withKey(attachment.id, AttachmentResource({
457
431
  attachment,
458
432
  onRemove: async () => {
459
433
  await attachmentAdapter?.remove(attachment);
460
434
  setAttachments((prev) => prev.filter((a) => a.id !== attachment.id));
461
435
  }
462
436
  }));
463
- $[16] = attachmentAdapter;
464
- $[17] = setAttachments;
465
- $[18] = t8;
466
- } else t8 = $[18];
467
- t7 = attachments.map(t8);
468
- $[12] = attachmentAdapter;
469
- $[13] = attachments;
470
- $[14] = setAttachments;
471
- $[15] = t7;
472
- } else t7 = $[15];
473
- const attachmentClients = useClientLookup(t7);
474
- let t8;
475
- if ($[19] !== attachmentAdapter) {
476
- t8 = async (removed) => {
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) => {
477
451
  if (!attachmentAdapter) return;
478
452
  await Promise.all(removed.filter(_temp6).map((a_1) => attachmentAdapter.remove(a_1)));
479
453
  };
480
- $[19] = attachmentAdapter;
481
- $[20] = t8;
482
- } else t8 = $[20];
483
- const removePendingAttachments = t8;
484
- let t9;
485
- if ($[21] !== setAttachments) {
486
- t9 = (attachment_0) => {
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) => {
487
461
  setAttachments((prev_0) => {
488
462
  const idx = prev_0.findIndex((a_2) => a_2.id === attachment_0.id);
489
463
  if (idx === -1) return [...prev_0, attachment_0];
@@ -492,41 +466,41 @@ const useComposerClientResource = (t0) => {
492
466
  return next;
493
467
  });
494
468
  };
495
- $[21] = setAttachments;
496
- $[22] = t9;
497
- } else t9 = $[22];
498
- const upsertAttachment = t9;
469
+ $[16] = setAttachments;
470
+ $[17] = t7;
471
+ } else t7 = $[17];
472
+ const upsertAttachment = t7;
499
473
  const steerItems = queue?.steerItems ?? EMPTY_QUEUE_ITEMS;
500
474
  const laneItems = queue?.items ?? EMPTY_QUEUE_ITEMS;
501
- let t10;
502
- if ($[23] !== laneItems || $[24] !== steerItems) {
503
- t10 = steerItems.length === 0 ? laneItems : laneItems.length === 0 ? steerItems : [...steerItems, ...laneItems];
504
- $[23] = laneItems;
505
- $[24] = steerItems;
506
- $[25] = t10;
507
- } else t10 = $[25];
508
- const queueItems = t10;
509
- let t11;
510
- if ($[26] !== queue || $[27] !== queueItems) {
511
- let t12;
512
- if ($[29] !== queue) {
513
- t12 = (item) => withKey(item.id, QueueItemClient({
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({
514
488
  item,
515
489
  onMove: (placement) => queue?.move(item.id, placement),
516
490
  onRemove: () => queue?.remove(item.id)
517
491
  }));
518
- $[29] = queue;
519
- $[30] = t12;
520
- } else t12 = $[30];
521
- t11 = queueItems.map(t12);
522
- $[26] = queue;
523
- $[27] = queueItems;
524
- $[28] = t11;
525
- } else t11 = $[28];
526
- const queueItemClients = useClientLookup(t11);
527
- let t12;
528
- if ($[31] !== attachmentAdapter?.accept || $[32] !== attachmentClients.state || $[33] !== attachments.length || $[34] !== canCancel || $[35] !== isEditing || $[36] !== isSendDisabled || $[37] !== queueItems || $[38] !== quote || $[39] !== role || $[40] !== runConfig || $[41] !== text || $[42] !== type) {
529
- t12 = () => {
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 = () => {
530
504
  const isEmpty = !text.trim() && !attachments.length;
531
505
  return {
532
506
  text,
@@ -544,37 +518,37 @@ const useComposerClientResource = (t0) => {
544
518
  queue: queueItems
545
519
  };
546
520
  };
547
- $[31] = attachmentAdapter?.accept;
548
- $[32] = attachmentClients.state;
549
- $[33] = attachments.length;
550
- $[34] = canCancel;
551
- $[35] = isEditing;
552
- $[36] = isSendDisabled;
553
- $[37] = queueItems;
554
- $[38] = quote;
555
- $[39] = role;
556
- $[40] = runConfig;
557
- $[41] = text;
558
- $[42] = type;
559
- $[43] = t12;
560
- } else t12 = $[43];
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];
561
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];
562
549
  let t13;
563
- if ($[44] !== t12) {
564
- t13 = t12();
565
- $[44] = t12;
566
- $[45] = t13;
567
- } else t13 = $[45];
568
- const state = t13;
569
- let t14;
570
- if ($[46] !== state) {
571
- t14 = () => state;
572
- $[46] = state;
573
- $[47] = t14;
574
- } else t14 = $[47];
575
- let t15;
576
- if ($[48] !== attachmentAdapter || $[49] !== setAttachments || $[50] !== upsertAttachment) {
577
- t15 = async (fileOrAttachment) => {
550
+ if ($[43] !== attachmentAdapter || $[44] !== setAttachments || $[45] !== upsertAttachment) {
551
+ t13 = async (fileOrAttachment) => {
578
552
  if (attachmentAdapter) {
579
553
  const file = isCreateAttachment(fileOrAttachment) ? {
580
554
  name: fileOrAttachment.name,
@@ -609,35 +583,35 @@ const useComposerClientResource = (t0) => {
609
583
  setAttachments((prev_2) => [...prev_2, newAttachment_0]);
610
584
  }
611
585
  };
612
- $[48] = attachmentAdapter;
613
- $[49] = setAttachments;
614
- $[50] = upsertAttachment;
615
- $[51] = t15;
616
- } else t15 = $[51];
617
- let t16;
618
- if ($[52] !== attachmentsRef || $[53] !== removePendingAttachments || $[54] !== setAttachments) {
619
- t16 = async () => {
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 () => {
620
594
  const removed_0 = attachmentsRef.current;
621
595
  setAttachments([]);
622
596
  await removePendingAttachments(removed_0);
623
597
  };
624
- $[52] = attachmentsRef;
625
- $[53] = removePendingAttachments;
626
- $[54] = setAttachments;
627
- $[55] = t16;
628
- } else t16 = $[55];
629
- let t17;
630
- if ($[56] !== attachmentClients) {
631
- t17 = (selector) => {
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) => {
632
606
  if ("id" in selector) return attachmentClients.get({ key: selector.id });
633
607
  return attachmentClients.get(selector);
634
608
  };
635
- $[56] = attachmentClients;
636
- $[57] = t17;
637
- } else t17 = $[57];
638
- let t18;
639
- if ($[58] !== attachmentsRef || $[59] !== removePendingAttachments || $[60] !== setAttachments || $[61] !== setQuote || $[62] !== setRole || $[63] !== setRunConfig || $[64] !== setText) {
640
- t18 = async () => {
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 () => {
641
615
  const removed_1 = attachmentsRef.current;
642
616
  setText("");
643
617
  setRole("user");
@@ -646,23 +620,24 @@ const useComposerClientResource = (t0) => {
646
620
  setQuote(void 0);
647
621
  await removePendingAttachments(removed_1);
648
622
  };
649
- $[58] = attachmentsRef;
650
- $[59] = removePendingAttachments;
651
- $[60] = setAttachments;
652
- $[61] = setQuote;
653
- $[62] = setRole;
654
- $[63] = setRunConfig;
655
- $[64] = setText;
656
- $[65] = t18;
657
- } else t18 = $[65];
658
- let t19;
659
- if ($[66] !== attachmentAdapter || $[67] !== attachmentsRef || $[68] !== canCancel || $[69] !== isEditing || $[70] !== isSendDisabled || $[71] !== onSend || $[72] !== queue || $[73] !== quoteRef || $[74] !== roleRef || $[75] !== runConfigRef || $[76] !== setAttachments || $[77] !== setQuote || $[78] !== setText || $[79] !== textRef || $[80] !== type) {
660
- t19 = (opts) => {
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) => {
661
635
  const currentQuote = quoteRef.current;
662
636
  const currentText = textRef.current;
663
637
  const currentAttachments = attachmentsRef.current;
664
638
  const isEmpty_0 = !currentText.trim() && !currentAttachments.length;
665
- if (!isEditing || isEmpty_0 || isSendDisabled) return;
639
+ if (!isEditingRef.current) throw new Error("Composer is not available");
640
+ if (isEmpty_0 || isSendDisabled) return;
666
641
  setText("");
667
642
  setAttachments([]);
668
643
  setQuote(void 0);
@@ -681,9 +656,11 @@ const useComposerClientResource = (t0) => {
681
656
  startRun: opts?.startRun,
682
657
  metadata: { custom: { ...currentQuote ? { quote: currentQuote } : {} } }
683
658
  };
684
- if (queue && type === "thread") if (opts?.steer ?? canCancel) queue.steer(composedMessage);
685
- else queue.enqueue(composedMessage);
686
- else onSend?.(composedMessage);
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);
687
664
  };
688
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) => {
689
666
  setText((prev_3) => currentText && prev_3 ? currentText + "\n" + prev_3 : currentText || prev_3);
@@ -693,75 +670,95 @@ const useComposerClientResource = (t0) => {
693
670
  });
694
671
  else dispatch(currentAttachments);
695
672
  };
696
- $[66] = attachmentAdapter;
697
- $[67] = attachmentsRef;
698
- $[68] = canCancel;
699
- $[69] = isEditing;
700
- $[70] = isSendDisabled;
701
- $[71] = onSend;
702
- $[72] = queue;
703
- $[73] = quoteRef;
704
- $[74] = roleRef;
705
- $[75] = runConfigRef;
706
- $[76] = setAttachments;
707
- $[77] = setQuote;
708
- $[78] = setText;
709
- $[79] = textRef;
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;
710
699
  $[80] = type;
711
- $[81] = t19;
712
- } else t19 = $[81];
713
- let t20;
714
- if ($[82] !== onBeginEdit) {
715
- t20 = () => {
700
+ $[81] = t18;
701
+ } else t18 = $[81];
702
+ let t19;
703
+ if ($[82] !== isEditingRef || $[83] !== onBeginEdit || $[84] !== setIsEditing || $[85] !== type || $[86] !== updateFromMessage) {
704
+ t19 = () => {
716
705
  onBeginEdit?.();
706
+ if (type === "thread") return;
707
+ if (isEditingRef.current) throw new Error("Edit already in progress");
708
+ setIsEditing(true);
709
+ updateFromMessage();
717
710
  };
718
- $[82] = onBeginEdit;
719
- $[83] = t20;
720
- } else t20 = $[83];
721
- let t21;
722
- if ($[84] !== queueItemClients) {
723
- t21 = (selector_0) => {
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) => {
724
721
  if ("id" in selector_0) return queueItemClients.get({ key: selector_0.id });
725
722
  return queueItemClients.get(selector_0);
726
723
  };
727
- $[84] = queueItemClients;
728
- $[85] = t21;
729
- } else t21 = $[85];
730
- let t22;
731
- if ($[86] !== onCancel || $[87] !== setQuote || $[88] !== setRole || $[89] !== setRunConfig || $[90] !== setText || $[91] !== t14 || $[92] !== t15 || $[93] !== t16 || $[94] !== t17 || $[95] !== t18 || $[96] !== t19 || $[97] !== t20 || $[98] !== t21) {
732
- t22 = {
733
- getState: t14,
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,
734
731
  setText,
735
732
  setRole,
736
733
  setRunConfig,
737
- addAttachment: t15,
738
- clearAttachments: t16,
739
- attachment: t17,
740
- reset: t18,
741
- send: t19,
742
- cancel: onCancel,
743
- beginEdit: t20,
734
+ addAttachment: t13,
735
+ clearAttachments: t14,
736
+ attachment: t15,
737
+ reset: t16,
738
+ send: t17,
739
+ cancel: t18,
740
+ beginEdit: t19,
744
741
  startDictation: _temp7,
745
742
  stopDictation: _temp8,
746
743
  setQuote,
747
- queueItem: t21
744
+ queueItem: t20
748
745
  };
749
- $[86] = onCancel;
750
- $[87] = setQuote;
751
- $[88] = setRole;
752
- $[89] = setRunConfig;
753
- $[90] = setText;
754
- $[91] = t14;
755
- $[92] = t15;
756
- $[93] = t16;
757
- $[94] = t17;
758
- $[95] = t18;
759
- $[96] = t19;
760
- $[97] = t20;
761
- $[98] = t21;
762
- $[99] = t22;
763
- } else t22 = $[99];
764
- return t22;
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;
765
762
  };
766
763
  const ComposerClientResource = resource(useComposerClientResource);
767
764
  const createSpeechController = (notify) => {
@@ -1054,7 +1051,6 @@ const useExternalThread = (t0) => {
1054
1051
  if ($[49] !== attachmentAdapter || $[50] !== composerQueue || $[51] !== handleCancelRun || $[52] !== handleSendNew || $[53] !== isRunning || $[54] !== isSendDisabled) {
1055
1052
  t22 = ComposerClientResource({
1056
1053
  type: "thread",
1057
- isEditing: true,
1058
1054
  canCancel: isRunning,
1059
1055
  isSendDisabled,
1060
1056
  onCancel: handleCancelRun,
@@ -1310,7 +1306,7 @@ function _temp4(part) {
1310
1306
  return part.type === "text";
1311
1307
  }
1312
1308
  function _temp5(part_0) {
1313
- return "text" in part_0 ? part_0.text : "";
1309
+ return part_0.text;
1314
1310
  }
1315
1311
  function _temp6(a_0) {
1316
1312
  return a_0.status.type !== "complete";