@assistant-ui/react 0.15.7 → 0.15.9

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.
Files changed (25) hide show
  1. package/LICENSE +21 -0
  2. package/dist/client/ExternalThread.d.ts +3 -1
  3. package/dist/client/ExternalThread.d.ts.map +1 -1
  4. package/dist/client/ExternalThread.js +524 -335
  5. package/dist/client/ExternalThread.js.map +1 -1
  6. package/dist/legacy-runtime/cloud/auiV0.d.ts +1 -0
  7. package/dist/legacy-runtime/cloud/auiV0.d.ts.map +1 -1
  8. package/dist/legacy-runtime/cloud/auiV0.js +2 -1
  9. package/dist/legacy-runtime/cloud/auiV0.js.map +1 -1
  10. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
  11. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +2 -0
  12. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  13. package/dist/unstable/useLiveCompletionAdapter.js +32 -7
  14. package/dist/unstable/useLiveCompletionAdapter.js.map +1 -1
  15. package/dist/utils/useToolArgsFieldStatus.d.ts +2 -2
  16. package/package.json +13 -15
  17. package/src/client/ExternalThread.ts +172 -9
  18. package/src/legacy-runtime/cloud/auiV0.ts +8 -1
  19. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransport.spec.md +1 -0
  20. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +79 -0
  21. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +2 -0
  22. package/src/tests/external-thread-feedback.test.tsx +204 -0
  23. package/src/tests/external-thread-speech.test.tsx +328 -0
  24. package/src/unstable/useLiveCompletionAdapter.test.tsx +90 -0
  25. package/src/unstable/useLiveCompletionAdapter.ts +32 -7
@@ -16,8 +16,8 @@ const derivePartStatus = (message, partIndex, part) => {
16
16
  return toMessagePartStatus(message, partIndex, part);
17
17
  };
18
18
  const useMessageClient = (t0) => {
19
- const $ = c(64);
20
- const { message, index, parentId, onEdit, onReload, queue, branches, onRespondToToolApproval, onAddToolResult, onResumeToolCall, attachmentAdapter } = 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
21
  const [isCopied, setIsCopied] = useState(false);
22
22
  const [isHovering, setIsHovering] = useState(false);
23
23
  const [isEditing, setIsEditing] = useState(false);
@@ -121,127 +121,145 @@ const useMessageClient = (t0) => {
121
121
  const branchNumber = branchIndex === -1 ? 1 : branchIndex + 1;
122
122
  const branchCount = branchIndex === -1 ? 1 : branchIds.length;
123
123
  let t9;
124
- if ($[25] !== message.attachments) {
125
- t9 = message.attachments ?? [];
126
- $[25] = message.attachments;
127
- $[26] = t9;
128
- } else t9 = $[26];
129
- let t10;
130
- if ($[27] !== branchCount || $[28] !== branchNumber || $[29] !== composerClient.state || $[30] !== index || $[31] !== isCopied || $[32] !== isHovering || $[33] !== message || $[34] !== parentId || $[35] !== partClients.state || $[36] !== t9) {
131
- t10 = {
124
+ if ($[25] !== message || $[26] !== submittedFeedback) {
125
+ t9 = submittedFeedback && message.role === "assistant" ? {
132
126
  ...message,
133
- attachments: t9,
127
+ metadata: {
128
+ ...message.metadata,
129
+ submittedFeedback: { type: submittedFeedback }
130
+ }
131
+ } : message;
132
+ $[25] = message;
133
+ $[26] = submittedFeedback;
134
+ $[27] = t9;
135
+ } else t9 = $[27];
136
+ const messageWithFeedback = t9;
137
+ let t10;
138
+ if ($[28] !== message.attachments) {
139
+ t10 = message.attachments ?? [];
140
+ $[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 = {
146
+ ...messageWithFeedback,
147
+ attachments: t10,
134
148
  parentId,
135
149
  isLast: false,
136
150
  branchNumber,
137
151
  branchCount,
138
- speech: void 0,
152
+ speech,
139
153
  parts: partClients.state,
140
154
  isCopied,
141
155
  isHovering,
142
156
  index,
143
157
  composer: composerClient.state
144
158
  };
145
- $[27] = branchCount;
146
- $[28] = branchNumber;
147
- $[29] = composerClient.state;
148
- $[30] = index;
149
- $[31] = isCopied;
150
- $[32] = isHovering;
151
- $[33] = message;
152
- $[34] = parentId;
153
- $[35] = partClients.state;
154
- $[36] = t9;
155
- $[37] = t10;
156
- } else t10 = $[37];
157
- const state = t10;
158
- let t11;
159
- if ($[38] !== state) {
160
- t11 = () => state;
161
- $[38] = state;
162
- $[39] = t11;
163
- } else t11 = $[39];
159
+ $[30] = branchCount;
160
+ $[31] = branchNumber;
161
+ $[32] = composerClient.state;
162
+ $[33] = index;
163
+ $[34] = isCopied;
164
+ $[35] = isHovering;
165
+ $[36] = messageWithFeedback;
166
+ $[37] = parentId;
167
+ $[38] = partClients.state;
168
+ $[39] = speech;
169
+ $[40] = t10;
170
+ $[41] = t11;
171
+ } else t11 = $[41];
172
+ const state = t11;
164
173
  let t12;
165
- if ($[40] !== composerClient.methods) {
166
- t12 = () => composerClient.methods;
167
- $[40] = composerClient.methods;
168
- $[41] = t12;
169
- } else t12 = $[41];
174
+ if ($[42] !== state) {
175
+ t12 = () => state;
176
+ $[42] = state;
177
+ $[43] = t12;
178
+ } else t12 = $[43];
170
179
  let t13;
171
- if ($[42] !== onReload) {
172
- t13 = () => {
180
+ if ($[44] !== composerClient.methods) {
181
+ t13 = () => composerClient.methods;
182
+ $[44] = composerClient.methods;
183
+ $[45] = t13;
184
+ } else t13 = $[45];
185
+ let t14;
186
+ if ($[46] !== onReload) {
187
+ t14 = () => {
173
188
  onReload?.();
174
189
  };
175
- $[42] = onReload;
176
- $[43] = t13;
177
- } else t13 = $[43];
178
- let t14;
179
- if ($[44] !== branchIds || $[45] !== branchIndex || $[46] !== branches || $[47] !== message.id) {
180
- t14 = (t15) => {
181
- const { position, branchId } = t15;
190
+ $[46] = onReload;
191
+ $[47] = t14;
192
+ } else t14 = $[47];
193
+ let t15;
194
+ if ($[48] !== branchIds || $[49] !== branchIndex || $[50] !== branches || $[51] !== message.id) {
195
+ t15 = (t16) => {
196
+ const { position, branchId } = t16;
182
197
  if (!branches) return;
183
198
  const target = branchId ?? (branchIndex === -1 ? void 0 : position === "previous" ? branchIds[branchIndex - 1] : position === "next" ? branchIds[branchIndex + 1] : void 0);
184
199
  if (target !== void 0 && target !== message.id) branches.switchToBranch(target);
185
200
  };
186
- $[44] = branchIds;
187
- $[45] = branchIndex;
188
- $[46] = branches;
189
- $[47] = message.id;
190
- $[48] = t14;
191
- } else t14 = $[48];
192
- let t15;
193
- if ($[49] !== message) {
194
- t15 = () => getThreadMessageText(message);
195
- $[49] = message;
196
- $[50] = t15;
197
- } else t15 = $[50];
201
+ $[48] = branchIds;
202
+ $[49] = branchIndex;
203
+ $[50] = branches;
204
+ $[51] = message.id;
205
+ $[52] = t15;
206
+ } else t15 = $[52];
198
207
  let t16;
199
- if ($[51] !== partClients || $[52] !== state) {
200
- t16 = (selector) => {
208
+ if ($[53] !== message) {
209
+ t16 = () => getThreadMessageText(message);
210
+ $[53] = message;
211
+ $[54] = t16;
212
+ } else t16 = $[54];
213
+ let t17;
214
+ if ($[55] !== partClients || $[56] !== state) {
215
+ t17 = (selector) => {
201
216
  if ("index" in selector) return partClients.get(selector);
202
217
  const partIndex = state.parts.findIndex((p) => p.type === "tool-call" && p.toolCallId === selector.toolCallId);
203
218
  return partClients.get({ index: partIndex });
204
219
  };
205
- $[51] = partClients;
206
- $[52] = state;
207
- $[53] = t16;
208
- } else t16 = $[53];
209
- let t17;
210
- if ($[54] !== attachmentClients) {
211
- t17 = (selector_0) => {
220
+ $[55] = partClients;
221
+ $[56] = state;
222
+ $[57] = t17;
223
+ } else t17 = $[57];
224
+ let t18;
225
+ if ($[58] !== attachmentClients) {
226
+ t18 = (selector_0) => {
212
227
  if ("id" in selector_0) return attachmentClients.get({ key: selector_0.id });
213
228
  return attachmentClients.get(selector_0);
214
229
  };
215
- $[54] = attachmentClients;
216
- $[55] = t17;
217
- } else t17 = $[55];
218
- let t18;
219
- if ($[56] !== t11 || $[57] !== t12 || $[58] !== t13 || $[59] !== t14 || $[60] !== t15 || $[61] !== t16 || $[62] !== t17) {
220
- t18 = {
221
- getState: t11,
222
- composer: t12,
230
+ $[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,
223
238
  delete: _temp3,
224
- reload: t13,
225
- speak: _temp4,
226
- stopSpeaking: _temp5,
227
- submitFeedback: _temp6,
228
- switchToBranch: t14,
229
- getCopyText: t15,
230
- part: t16,
231
- attachment: t17,
239
+ reload: t14,
240
+ speak: onSpeak,
241
+ stopSpeaking: onStopSpeaking,
242
+ submitFeedback: onSubmitFeedback,
243
+ switchToBranch: t15,
244
+ getCopyText: t16,
245
+ part: t17,
246
+ attachment: t18,
232
247
  setIsCopied,
233
248
  setIsHovering
234
249
  };
235
- $[56] = t11;
236
- $[57] = t12;
237
- $[58] = t13;
238
- $[59] = t14;
239
- $[60] = t15;
240
- $[61] = t16;
241
- $[62] = t17;
242
- $[63] = t18;
243
- } else t18 = $[63];
244
- return t18;
250
+ $[60] = onSpeak;
251
+ $[61] = onStopSpeaking;
252
+ $[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;
245
263
  };
246
264
  const MessageClient = resource(useMessageClient);
247
265
  const usePartResource = (t0) => {
@@ -402,7 +420,7 @@ const useComposerClientResource = (t0) => {
402
420
  if ($[2] !== message || $[3] !== setAttachments || $[4] !== setRole || $[5] !== setText) {
403
421
  t4 = () => {
404
422
  if (message) {
405
- const messageText = message.content.filter(_temp7).map(_temp8).join("\n\n");
423
+ const messageText = message.content.filter(_temp4).map(_temp5).join("\n\n");
406
424
  setText(messageText);
407
425
  setRole(message.role);
408
426
  setAttachments(message.attachments ?? []);
@@ -457,7 +475,7 @@ const useComposerClientResource = (t0) => {
457
475
  if ($[19] !== attachmentAdapter) {
458
476
  t8 = async (removed) => {
459
477
  if (!attachmentAdapter) return;
460
- await Promise.all(removed.filter(_temp9).map((a_1) => attachmentAdapter.remove(a_1)));
478
+ await Promise.all(removed.filter(_temp6).map((a_1) => attachmentAdapter.remove(a_1)));
461
479
  };
462
480
  $[19] = attachmentAdapter;
463
481
  $[20] = t8;
@@ -723,8 +741,8 @@ const useComposerClientResource = (t0) => {
723
741
  send: t19,
724
742
  cancel: onCancel,
725
743
  beginEdit: t20,
726
- startDictation: _temp0,
727
- stopDictation: _temp1,
744
+ startDictation: _temp7,
745
+ stopDictation: _temp8,
728
746
  setQuote,
729
747
  queueItem: t21
730
748
  };
@@ -746,6 +764,57 @@ const useComposerClientResource = (t0) => {
746
764
  return t22;
747
765
  };
748
766
  const ComposerClientResource = resource(useComposerClientResource);
767
+ const createSpeechController = (notify) => {
768
+ let session;
769
+ const clear = () => {
770
+ if (!session) return;
771
+ session.cancel();
772
+ session = void 0;
773
+ notify(void 0);
774
+ };
775
+ return {
776
+ speak: (adapter, message) => {
777
+ clear();
778
+ const utterance = adapter.speak(getThreadMessageText(message));
779
+ let unsub;
780
+ unsub = utterance.subscribe(() => {
781
+ if (utterance.status.type === "ended") {
782
+ unsub?.();
783
+ session = void 0;
784
+ notify(void 0);
785
+ } else notify({
786
+ messageId: message.id,
787
+ status: utterance.status
788
+ });
789
+ });
790
+ if (utterance.status.type === "ended") {
791
+ unsub();
792
+ notify(void 0);
793
+ return;
794
+ }
795
+ session = {
796
+ messageId: message.id,
797
+ cancel: () => {
798
+ unsub();
799
+ utterance.cancel();
800
+ }
801
+ };
802
+ notify({
803
+ messageId: message.id,
804
+ status: utterance.status
805
+ });
806
+ },
807
+ stop: () => {
808
+ if (!session) throw new Error("No message is being spoken");
809
+ clear();
810
+ },
811
+ stopMessage: (messageId) => {
812
+ if (session?.messageId !== messageId) throw new Error("Message is not being spoken");
813
+ clear();
814
+ },
815
+ dispose: clear
816
+ };
817
+ };
749
818
  const dedupeMessagesById = (messages) => {
750
819
  const seenIds = /* @__PURE__ */ new Set();
751
820
  const deduped = [];
@@ -761,8 +830,8 @@ const dedupeMessagesById = (messages) => {
761
830
  return deduped.length === messages.length ? messages : deduped.reverse();
762
831
  };
763
832
  const useExternalThread = (t0) => {
764
- const $ = c(78);
765
- const { messages: messagesProp, isRunning: t1, isLoading: t2, state: threadState, extras, isSendDisabled: t3, onNew, onEdit, onReload, onStartRun, onCancel, onResume, onAddToolResult, onResumeToolCall, onLoadExternalState, attachmentAdapter, queue, branches, onRespondToToolApproval } = t0;
833
+ const $ = c(106);
834
+ 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;
766
835
  const isRunning = t1 === void 0 ? false : t1;
767
836
  const isLoading = t2 === void 0 ? false : t2;
768
837
  const isSendDisabled = t3 === void 0 ? false : t3;
@@ -774,98 +843,216 @@ const useExternalThread = (t0) => {
774
843
  } else t4 = $[1];
775
844
  const messages = t4;
776
845
  let t5;
777
- if ($[2] !== messages || $[3] !== onReload) {
778
- t5 = (messageId) => {
779
- const messageIndex = messages.findIndex((m) => m.id === messageId);
846
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
847
+ t5 = {};
848
+ $[2] = t5;
849
+ } else t5 = $[2];
850
+ const [submittedFeedback, setSubmittedFeedback] = useState(t5);
851
+ let t6;
852
+ if ($[3] !== submittedFeedback) {
853
+ t6 = (msg) => {
854
+ const entry = submittedFeedback[msg.id];
855
+ return entry && msg.metadata.submittedFeedback?.type === entry.external ? entry.type : void 0;
856
+ };
857
+ $[3] = submittedFeedback;
858
+ $[4] = t6;
859
+ } else t6 = $[4];
860
+ const feedbackFor = t6;
861
+ let t7;
862
+ let t8;
863
+ if ($[5] !== messages) {
864
+ t7 = () => {
865
+ setSubmittedFeedback((prev) => {
866
+ const live = Object.entries(prev).filter((t9) => {
867
+ const [id, entry_0] = t9;
868
+ const msg_0 = messages.find((m) => m.id === id);
869
+ return !!msg_0 && msg_0.metadata.submittedFeedback?.type === entry_0.external;
870
+ });
871
+ return live.length === Object.keys(prev).length ? prev : Object.fromEntries(live);
872
+ });
873
+ };
874
+ t8 = [messages];
875
+ $[5] = messages;
876
+ $[6] = t7;
877
+ $[7] = t8;
878
+ } else {
879
+ t7 = $[6];
880
+ t8 = $[7];
881
+ }
882
+ useEffect(t7, t8);
883
+ let t9;
884
+ if ($[8] !== feedbackAdapter) {
885
+ t9 = (message, t10) => {
886
+ const { type } = t10;
887
+ if (!feedbackAdapter) throw new Error("Feedback adapter not configured");
888
+ feedbackAdapter.submit({
889
+ message,
890
+ type
891
+ });
892
+ if (message.role === "assistant") setSubmittedFeedback((prev_0) => ({
893
+ ...prev_0,
894
+ [message.id]: {
895
+ type,
896
+ external: message.metadata.submittedFeedback?.type
897
+ }
898
+ }));
899
+ };
900
+ $[8] = feedbackAdapter;
901
+ $[9] = t9;
902
+ } else t9 = $[9];
903
+ const handleSubmitFeedback = t9;
904
+ const [speechState, setSpeech] = useState(void 0);
905
+ let t10;
906
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
907
+ t10 = () => createSpeechController(setSpeech);
908
+ $[10] = t10;
909
+ } else t10 = $[10];
910
+ const [speechController] = useState(t10);
911
+ const hasSpeechAdapter = !!speechAdapter;
912
+ const speech = hasSpeechAdapter ? speechState : void 0;
913
+ let t11;
914
+ let t12;
915
+ if ($[11] !== hasSpeechAdapter || $[12] !== speechController) {
916
+ t11 = () => {
917
+ if (!hasSpeechAdapter) speechController.dispose();
918
+ };
919
+ t12 = [hasSpeechAdapter, speechController];
920
+ $[11] = hasSpeechAdapter;
921
+ $[12] = speechController;
922
+ $[13] = t11;
923
+ $[14] = t12;
924
+ } else {
925
+ t11 = $[13];
926
+ t12 = $[14];
927
+ }
928
+ useEffect(t11, t12);
929
+ let t13;
930
+ let t14;
931
+ if ($[15] !== speechController) {
932
+ t13 = () => () => speechController.dispose();
933
+ t14 = [speechController];
934
+ $[15] = speechController;
935
+ $[16] = t13;
936
+ $[17] = t14;
937
+ } else {
938
+ t13 = $[16];
939
+ t14 = $[17];
940
+ }
941
+ useEffect(t13, t14);
942
+ let t15;
943
+ if ($[18] !== speechAdapter || $[19] !== speechController) {
944
+ t15 = (message_0) => {
945
+ if (!speechAdapter) throw new Error("Speech adapter not configured");
946
+ speechController.speak(speechAdapter, message_0);
947
+ };
948
+ $[18] = speechAdapter;
949
+ $[19] = speechController;
950
+ $[20] = t15;
951
+ } else t15 = $[20];
952
+ const handleSpeak = t15;
953
+ let t16;
954
+ if ($[21] !== messages || $[22] !== onReload) {
955
+ t16 = (messageId) => {
956
+ const messageIndex = messages.findIndex((m_0) => m_0.id === messageId);
780
957
  if (messageIndex === -1) return;
781
958
  const parentId = messageIndex > 0 ? messages[messageIndex - 1].id : null;
782
959
  onReload?.(parentId);
783
960
  };
784
- $[2] = messages;
785
- $[3] = onReload;
786
- $[4] = t5;
787
- } else t5 = $[4];
788
- const handleReload = t5;
789
- let t6;
790
- if ($[5] !== attachmentAdapter || $[6] !== branches || $[7] !== handleReload || $[8] !== messages || $[9] !== onAddToolResult || $[10] !== onEdit || $[11] !== onRespondToToolApproval || $[12] !== onResumeToolCall || $[13] !== queue) {
791
- t6 = messages.map((msg, index) => {
961
+ $[21] = messages;
962
+ $[22] = onReload;
963
+ $[23] = t16;
964
+ } else t16 = $[23];
965
+ const handleReload = t16;
966
+ let t17;
967
+ 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) {
968
+ t17 = messages.map((msg_1, index) => {
792
969
  const props = {
793
- message: msg,
970
+ message: msg_1,
794
971
  index,
795
972
  parentId: index > 0 ? messages[index - 1].id : null,
796
- onReload: () => handleReload(msg.id),
973
+ onReload: () => handleReload(msg_1.id),
797
974
  queue,
798
975
  branches,
799
976
  onRespondToToolApproval,
800
977
  onAddToolResult,
801
978
  onResumeToolCall,
802
- attachmentAdapter
979
+ attachmentAdapter,
980
+ submittedFeedback: feedbackFor(msg_1),
981
+ onSubmitFeedback: (feedback) => handleSubmitFeedback(msg_1, feedback),
982
+ speech: speech?.messageId === msg_1.id ? speech : void 0,
983
+ onSpeak: () => handleSpeak(msg_1),
984
+ onStopSpeaking: () => speechController.stopMessage(msg_1.id)
803
985
  };
804
986
  if (onEdit) props.onEdit = onEdit;
805
- return withKey(msg.id, MessageClient(props));
987
+ return withKey(msg_1.id, MessageClient(props));
806
988
  });
807
- $[5] = attachmentAdapter;
808
- $[6] = branches;
809
- $[7] = handleReload;
810
- $[8] = messages;
811
- $[9] = onAddToolResult;
812
- $[10] = onEdit;
813
- $[11] = onRespondToToolApproval;
814
- $[12] = onResumeToolCall;
815
- $[13] = queue;
816
- $[14] = t6;
817
- } else t6 = $[14];
818
- const messageClients = useClientLookup(t6);
819
- let t7;
820
- if ($[15] !== onCancel) {
821
- t7 = () => {
989
+ $[24] = attachmentAdapter;
990
+ $[25] = branches;
991
+ $[26] = feedbackFor;
992
+ $[27] = handleReload;
993
+ $[28] = handleSpeak;
994
+ $[29] = handleSubmitFeedback;
995
+ $[30] = messages;
996
+ $[31] = onAddToolResult;
997
+ $[32] = onEdit;
998
+ $[33] = onRespondToToolApproval;
999
+ $[34] = onResumeToolCall;
1000
+ $[35] = queue;
1001
+ $[36] = speech;
1002
+ $[37] = speechController;
1003
+ $[38] = t17;
1004
+ } else t17 = $[38];
1005
+ const messageClients = useClientLookup(t17);
1006
+ let t18;
1007
+ if ($[39] !== onCancel) {
1008
+ t18 = () => {
822
1009
  onCancel?.();
823
1010
  };
824
- $[15] = onCancel;
825
- $[16] = t7;
826
- } else t7 = $[16];
827
- const handleCancelRun = t7;
828
- let t8;
829
- if ($[17] !== messages || $[18] !== onNew) {
830
- t8 = (message) => {
1011
+ $[39] = onCancel;
1012
+ $[40] = t18;
1013
+ } else t18 = $[40];
1014
+ const handleCancelRun = t18;
1015
+ let t19;
1016
+ if ($[41] !== messages || $[42] !== onNew) {
1017
+ t19 = (message_1) => {
831
1018
  onNew?.({
832
- ...message,
1019
+ ...message_1,
833
1020
  parentId: messages.at(-1)?.id ?? null
834
1021
  });
835
1022
  };
836
- $[17] = messages;
837
- $[18] = onNew;
838
- $[19] = t8;
839
- } else t8 = $[19];
840
- const handleSendNew = t8;
841
- let t9;
842
- if ($[20] !== messages) {
843
- t9 = messages.at(-1)?.id ?? null;
844
- $[20] = messages;
845
- $[21] = t9;
846
- } else t9 = $[21];
847
- const headId = t9;
848
- let t10;
849
- if ($[22] !== headId || $[23] !== queue) {
850
- t10 = queue && {
1023
+ $[41] = messages;
1024
+ $[42] = onNew;
1025
+ $[43] = t19;
1026
+ } else t19 = $[43];
1027
+ const handleSendNew = t19;
1028
+ let t20;
1029
+ if ($[44] !== messages) {
1030
+ t20 = messages.at(-1)?.id ?? null;
1031
+ $[44] = messages;
1032
+ $[45] = t20;
1033
+ } else t20 = $[45];
1034
+ const headId = t20;
1035
+ let t21;
1036
+ if ($[46] !== headId || $[47] !== queue) {
1037
+ t21 = queue && {
851
1038
  ...queue,
852
- enqueue: (message_0) => queue.enqueue({
853
- ...message_0,
854
- parentId: message_0.parentId ?? headId
1039
+ enqueue: (message_2) => queue.enqueue({
1040
+ ...message_2,
1041
+ parentId: message_2.parentId ?? headId
855
1042
  }),
856
- steer: (message_1) => queue.steer({
857
- ...message_1,
858
- parentId: message_1.parentId ?? headId
1043
+ steer: (message_3) => queue.steer({
1044
+ ...message_3,
1045
+ parentId: message_3.parentId ?? headId
859
1046
  })
860
1047
  };
861
- $[22] = headId;
862
- $[23] = queue;
863
- $[24] = t10;
864
- } else t10 = $[24];
865
- const composerQueue = t10;
866
- let t11;
867
- if ($[25] !== attachmentAdapter || $[26] !== composerQueue || $[27] !== handleCancelRun || $[28] !== handleSendNew || $[29] !== isRunning || $[30] !== isSendDisabled) {
868
- t11 = ComposerClientResource({
1048
+ $[46] = headId;
1049
+ $[47] = queue;
1050
+ $[48] = t21;
1051
+ } else t21 = $[48];
1052
+ const composerQueue = t21;
1053
+ let t22;
1054
+ if ($[49] !== attachmentAdapter || $[50] !== composerQueue || $[51] !== handleCancelRun || $[52] !== handleSendNew || $[53] !== isRunning || $[54] !== isSendDisabled) {
1055
+ t22 = ComposerClientResource({
869
1056
  type: "thread",
870
1057
  isEditing: true,
871
1058
  canCancel: isRunning,
@@ -875,39 +1062,41 @@ const useExternalThread = (t0) => {
875
1062
  queue: composerQueue,
876
1063
  attachmentAdapter
877
1064
  });
878
- $[25] = attachmentAdapter;
879
- $[26] = composerQueue;
880
- $[27] = handleCancelRun;
881
- $[28] = handleSendNew;
882
- $[29] = isRunning;
883
- $[30] = isSendDisabled;
884
- $[31] = t11;
885
- } else t11 = $[31];
886
- const composerClient = useClientResource(t11);
1065
+ $[49] = attachmentAdapter;
1066
+ $[50] = composerQueue;
1067
+ $[51] = handleCancelRun;
1068
+ $[52] = handleSendNew;
1069
+ $[53] = isRunning;
1070
+ $[54] = isSendDisabled;
1071
+ $[55] = t22;
1072
+ } else t22 = $[55];
1073
+ const composerClient = useClientResource(t22);
887
1074
  const hasQueue = !!queue;
888
1075
  const hasBranches = !!branches;
889
1076
  const hasEdit = !!onEdit;
890
1077
  const hasReload = !!onReload;
891
1078
  const hasAttachments = !!attachmentAdapter;
892
- let t12;
893
- if ($[32] !== messageClients.state) {
894
- t12 = messageClients.state.map(_temp10);
895
- $[32] = messageClients.state;
896
- $[33] = t12;
897
- } else t12 = $[33];
898
- const messageStates = t12;
899
- const t13 = messages.length === 0;
900
- let t14;
901
- if ($[34] !== hasAttachments || $[35] !== hasBranches || $[36] !== hasEdit || $[37] !== hasQueue || $[38] !== hasReload || $[39] !== isRunning) {
902
- t14 = {
1079
+ const hasFeedback = !!feedbackAdapter;
1080
+ const hasSpeech = !!speechAdapter;
1081
+ let t23;
1082
+ if ($[56] !== messageClients.state) {
1083
+ t23 = messageClients.state.map(_temp9);
1084
+ $[56] = messageClients.state;
1085
+ $[57] = t23;
1086
+ } else t23 = $[57];
1087
+ const messageStates = t23;
1088
+ const t24 = messages.length === 0;
1089
+ let t25;
1090
+ if ($[58] !== hasAttachments || $[59] !== hasBranches || $[60] !== hasEdit || $[61] !== hasFeedback || $[62] !== hasQueue || $[63] !== hasReload || $[64] !== hasSpeech || $[65] !== isRunning) {
1091
+ t25 = {
903
1092
  edit: hasEdit,
904
1093
  delete: false,
905
1094
  reload: hasReload,
906
1095
  refetchThread: false,
907
1096
  cancel: isRunning,
908
- speech: false,
1097
+ speech: hasSpeech,
909
1098
  attachments: hasAttachments,
910
- feedback: false,
1099
+ feedback: hasFeedback,
911
1100
  voice: false,
912
1101
  switchToBranch: hasBranches,
913
1102
  switchBranchDuringRun: false,
@@ -915,68 +1104,71 @@ const useExternalThread = (t0) => {
915
1104
  dictation: false,
916
1105
  queue: hasQueue
917
1106
  };
918
- $[34] = hasAttachments;
919
- $[35] = hasBranches;
920
- $[36] = hasEdit;
921
- $[37] = hasQueue;
922
- $[38] = hasReload;
923
- $[39] = isRunning;
924
- $[40] = t14;
925
- } else t14 = $[40];
926
- let t15;
927
- if ($[41] !== threadState) {
928
- t15 = threadState ?? {};
929
- $[41] = threadState;
930
- $[42] = t15;
931
- } else t15 = $[42];
932
- let t16;
933
- if ($[43] === Symbol.for("react.memo_cache_sentinel")) {
934
- t16 = [];
935
- $[43] = t16;
936
- } else t16 = $[43];
937
- let t17;
938
- if ($[44] !== composerClient.state || $[45] !== extras || $[46] !== isLoading || $[47] !== isRunning || $[48] !== messageStates || $[49] !== t13 || $[50] !== t14 || $[51] !== t15) {
939
- t17 = {
940
- isEmpty: t13,
1107
+ $[58] = hasAttachments;
1108
+ $[59] = hasBranches;
1109
+ $[60] = hasEdit;
1110
+ $[61] = hasFeedback;
1111
+ $[62] = hasQueue;
1112
+ $[63] = hasReload;
1113
+ $[64] = hasSpeech;
1114
+ $[65] = isRunning;
1115
+ $[66] = t25;
1116
+ } else t25 = $[66];
1117
+ let t26;
1118
+ if ($[67] !== threadState) {
1119
+ t26 = threadState ?? {};
1120
+ $[67] = threadState;
1121
+ $[68] = t26;
1122
+ } else t26 = $[68];
1123
+ let t27;
1124
+ if ($[69] === Symbol.for("react.memo_cache_sentinel")) {
1125
+ t27 = [];
1126
+ $[69] = t27;
1127
+ } else t27 = $[69];
1128
+ let t28;
1129
+ if ($[70] !== composerClient.state || $[71] !== extras || $[72] !== isLoading || $[73] !== isRunning || $[74] !== messageStates || $[75] !== speech || $[76] !== t24 || $[77] !== t25 || $[78] !== t26) {
1130
+ t28 = {
1131
+ isEmpty: t24,
941
1132
  isDisabled: false,
942
1133
  isLoading,
943
1134
  isRunning,
944
- capabilities: t14,
1135
+ capabilities: t25,
945
1136
  messages: messageStates,
946
- state: t15,
947
- suggestions: t16,
1137
+ state: t26,
1138
+ suggestions: t27,
948
1139
  extras,
949
- speech: void 0,
1140
+ speech,
950
1141
  voice: void 0,
951
1142
  composer: composerClient.state
952
1143
  };
953
- $[44] = composerClient.state;
954
- $[45] = extras;
955
- $[46] = isLoading;
956
- $[47] = isRunning;
957
- $[48] = messageStates;
958
- $[49] = t13;
959
- $[50] = t14;
960
- $[51] = t15;
961
- $[52] = t17;
962
- } else t17 = $[52];
963
- const state = t17;
964
- let t18;
965
- if ($[53] !== state) {
966
- t18 = () => state;
967
- $[53] = state;
968
- $[54] = t18;
969
- } else t18 = $[54];
970
- let t19;
971
- if ($[55] !== composerClient.methods) {
972
- t19 = () => composerClient.methods;
973
- $[55] = composerClient.methods;
974
- $[56] = t19;
975
- } else t19 = $[56];
976
- let t20;
977
- if ($[57] !== messages || $[58] !== onNew || $[59] !== queue) {
978
- t20 = (message_2) => {
979
- const appendMessage = typeof message_2 === "string" ? {
1144
+ $[70] = composerClient.state;
1145
+ $[71] = extras;
1146
+ $[72] = isLoading;
1147
+ $[73] = isRunning;
1148
+ $[74] = messageStates;
1149
+ $[75] = speech;
1150
+ $[76] = t24;
1151
+ $[77] = t25;
1152
+ $[78] = t26;
1153
+ $[79] = t28;
1154
+ } else t28 = $[79];
1155
+ const state = t28;
1156
+ let t29;
1157
+ if ($[80] !== state) {
1158
+ t29 = () => state;
1159
+ $[80] = state;
1160
+ $[81] = t29;
1161
+ } else t29 = $[81];
1162
+ let t30;
1163
+ if ($[82] !== composerClient.methods) {
1164
+ t30 = () => composerClient.methods;
1165
+ $[82] = composerClient.methods;
1166
+ $[83] = t30;
1167
+ } else t30 = $[83];
1168
+ let t31;
1169
+ if ($[84] !== messages || $[85] !== onNew || $[86] !== queue) {
1170
+ t31 = (message_4) => {
1171
+ const appendMessage = typeof message_4 === "string" ? {
980
1172
  createdAt: /* @__PURE__ */ new Date(),
981
1173
  parentId: messages.at(-1)?.id ?? null,
982
1174
  sourceId: null,
@@ -984,99 +1176,100 @@ const useExternalThread = (t0) => {
984
1176
  role: "user",
985
1177
  content: [{
986
1178
  type: "text",
987
- text: message_2
1179
+ text: message_4
988
1180
  }],
989
1181
  attachments: [],
990
1182
  metadata: { custom: {} }
991
1183
  } : {
992
- createdAt: message_2.createdAt ?? /* @__PURE__ */ new Date(),
993
- parentId: message_2.parentId ?? messages.at(-1)?.id ?? null,
994
- sourceId: message_2.sourceId ?? null,
995
- role: message_2.role ?? "user",
996
- content: message_2.content,
997
- attachments: message_2.attachments ?? [],
998
- metadata: message_2.metadata ?? { custom: {} },
999
- runConfig: message_2.runConfig ?? {},
1000
- startRun: message_2.startRun
1184
+ createdAt: message_4.createdAt ?? /* @__PURE__ */ new Date(),
1185
+ parentId: message_4.parentId ?? messages.at(-1)?.id ?? null,
1186
+ sourceId: message_4.sourceId ?? null,
1187
+ role: message_4.role ?? "user",
1188
+ content: message_4.content,
1189
+ attachments: message_4.attachments ?? [],
1190
+ metadata: message_4.metadata ?? { custom: {} },
1191
+ runConfig: message_4.runConfig ?? {},
1192
+ startRun: message_4.startRun
1001
1193
  };
1002
1194
  if (queue) queue.enqueue(appendMessage);
1003
1195
  else onNew?.(appendMessage);
1004
1196
  };
1005
- $[57] = messages;
1006
- $[58] = onNew;
1007
- $[59] = queue;
1008
- $[60] = t20;
1009
- } else t20 = $[60];
1010
- let t21;
1011
- if ($[61] !== onStartRun) {
1012
- t21 = () => {
1197
+ $[84] = messages;
1198
+ $[85] = onNew;
1199
+ $[86] = queue;
1200
+ $[87] = t31;
1201
+ } else t31 = $[87];
1202
+ let t32;
1203
+ if ($[88] !== onStartRun) {
1204
+ t32 = () => {
1013
1205
  onStartRun?.();
1014
1206
  };
1015
- $[61] = onStartRun;
1016
- $[62] = t21;
1017
- } else t21 = $[62];
1018
- let t22;
1019
- if ($[63] !== onResume) {
1020
- t22 = () => {
1207
+ $[88] = onStartRun;
1208
+ $[89] = t32;
1209
+ } else t32 = $[89];
1210
+ let t33;
1211
+ if ($[90] !== onResume) {
1212
+ t33 = () => {
1021
1213
  if (!onResume) throw new Error("Runtime does not support resuming runs (onResume is not set).");
1022
1214
  onResume();
1023
1215
  };
1024
- $[63] = onResume;
1025
- $[64] = t22;
1026
- } else t22 = $[64];
1027
- let t23;
1028
- if ($[65] !== onLoadExternalState) {
1029
- t23 = (state_0) => {
1216
+ $[90] = onResume;
1217
+ $[91] = t33;
1218
+ } else t33 = $[91];
1219
+ let t34;
1220
+ if ($[92] !== onLoadExternalState) {
1221
+ t34 = (state_0) => {
1030
1222
  if (!onLoadExternalState) throw new Error("Runtime does not support importing external states (onLoadExternalState is not set).");
1031
1223
  onLoadExternalState(state_0);
1032
1224
  };
1033
- $[65] = onLoadExternalState;
1034
- $[66] = t23;
1035
- } else t23 = $[66];
1036
- let t24;
1037
- if ($[67] !== messageClients) {
1038
- t24 = (selector) => {
1225
+ $[92] = onLoadExternalState;
1226
+ $[93] = t34;
1227
+ } else t34 = $[93];
1228
+ let t35;
1229
+ if ($[94] !== messageClients) {
1230
+ t35 = (selector) => {
1039
1231
  if ("id" in selector) return messageClients.get({ key: selector.id });
1040
1232
  return messageClients.get(selector);
1041
1233
  };
1042
- $[67] = messageClients;
1043
- $[68] = t24;
1044
- } else t24 = $[68];
1045
- let t25;
1046
- if ($[69] !== handleCancelRun || $[70] !== t18 || $[71] !== t19 || $[72] !== t20 || $[73] !== t21 || $[74] !== t22 || $[75] !== t23 || $[76] !== t24) {
1047
- t25 = {
1048
- getState: t18,
1049
- composer: t19,
1050
- append: t20,
1051
- deleteMessage: _temp11,
1052
- startRun: t21,
1053
- resumeRun: t22,
1234
+ $[94] = messageClients;
1235
+ $[95] = t35;
1236
+ } else t35 = $[95];
1237
+ let t36;
1238
+ if ($[96] !== handleCancelRun || $[97] !== speechController.stop || $[98] !== t29 || $[99] !== t30 || $[100] !== t31 || $[101] !== t32 || $[102] !== t33 || $[103] !== t34 || $[104] !== t35) {
1239
+ t36 = {
1240
+ getState: t29,
1241
+ composer: t30,
1242
+ append: t31,
1243
+ deleteMessage: _temp0,
1244
+ startRun: t32,
1245
+ resumeRun: t33,
1054
1246
  cancelRun: handleCancelRun,
1055
- importExternalState: t23,
1056
- getModelContext: _temp12,
1057
- export: _temp13,
1058
- import: _temp14,
1059
- reset: _temp15,
1060
- message: t24,
1061
- stopSpeaking: _temp16,
1062
- connectVoice: _temp17,
1063
- disconnectVoice: _temp18,
1064
- getVoiceVolume: _temp19,
1065
- subscribeVoiceVolume: _temp21,
1066
- muteVoice: _temp22,
1067
- unmuteVoice: _temp23
1247
+ importExternalState: t34,
1248
+ getModelContext: _temp1,
1249
+ export: _temp10,
1250
+ import: _temp11,
1251
+ reset: _temp12,
1252
+ message: t35,
1253
+ stopSpeaking: speechController.stop,
1254
+ connectVoice: _temp13,
1255
+ disconnectVoice: _temp14,
1256
+ getVoiceVolume: _temp15,
1257
+ subscribeVoiceVolume: _temp17,
1258
+ muteVoice: _temp18,
1259
+ unmuteVoice: _temp19
1068
1260
  };
1069
- $[69] = handleCancelRun;
1070
- $[70] = t18;
1071
- $[71] = t19;
1072
- $[72] = t20;
1073
- $[73] = t21;
1074
- $[74] = t22;
1075
- $[75] = t23;
1076
- $[76] = t24;
1077
- $[77] = t25;
1078
- } else t25 = $[77];
1079
- return t25;
1261
+ $[96] = handleCancelRun;
1262
+ $[97] = speechController.stop;
1263
+ $[98] = t29;
1264
+ $[99] = t30;
1265
+ $[100] = t31;
1266
+ $[101] = t32;
1267
+ $[102] = t33;
1268
+ $[103] = t34;
1269
+ $[104] = t35;
1270
+ $[105] = t36;
1271
+ } else t36 = $[105];
1272
+ return t36;
1080
1273
  };
1081
1274
  const ExternalThread = resource(useExternalThread);
1082
1275
  attachTransformScopes(useExternalThread, (scopes, parent) => {
@@ -1113,50 +1306,46 @@ function _temp2(attachment) {
1113
1306
  }));
1114
1307
  }
1115
1308
  function _temp3() {}
1116
- function _temp4() {}
1117
- function _temp5() {}
1118
- function _temp6() {}
1119
- function _temp7(part) {
1309
+ function _temp4(part) {
1120
1310
  return part.type === "text";
1121
1311
  }
1122
- function _temp8(part_0) {
1312
+ function _temp5(part_0) {
1123
1313
  return "text" in part_0 ? part_0.text : "";
1124
1314
  }
1125
- function _temp9(a_0) {
1315
+ function _temp6(a_0) {
1126
1316
  return a_0.status.type !== "complete";
1127
1317
  }
1128
- function _temp0() {}
1129
- function _temp1() {}
1130
- function _temp10(s, idx, arr) {
1318
+ function _temp7() {}
1319
+ function _temp8() {}
1320
+ function _temp9(s, idx, arr) {
1131
1321
  return {
1132
1322
  ...s,
1133
1323
  isLast: idx === arr.length - 1
1134
1324
  };
1135
1325
  }
1136
- function _temp11() {}
1137
- function _temp12() {
1326
+ function _temp0() {}
1327
+ function _temp1() {
1138
1328
  return {
1139
1329
  tools: {},
1140
1330
  config: {}
1141
1331
  };
1142
1332
  }
1143
- function _temp13() {
1333
+ function _temp10() {
1144
1334
  return { messages: [] };
1145
1335
  }
1336
+ function _temp11() {}
1337
+ function _temp12() {}
1338
+ function _temp13() {}
1146
1339
  function _temp14() {}
1147
- function _temp15() {}
1148
- function _temp16() {}
1149
- function _temp17() {}
1150
- function _temp18() {}
1151
- function _temp19() {
1340
+ function _temp15() {
1152
1341
  return 0;
1153
1342
  }
1154
- function _temp20() {}
1155
- function _temp21() {
1156
- return _temp20;
1343
+ function _temp16() {}
1344
+ function _temp17() {
1345
+ return _temp16;
1157
1346
  }
1158
- function _temp22() {}
1159
- function _temp23() {}
1347
+ function _temp18() {}
1348
+ function _temp19() {}
1160
1349
  //#endregion
1161
1350
  export { ExternalThread };
1162
1351