@assistant-ui/react 0.3.5 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -31,14 +32,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
32
  var src_exports = {};
32
33
  __export(src_exports, {
33
34
  ActionBarPrimitive: () => actionBar_exports,
35
+ AssistantActionBar: () => assistant_action_bar_default,
36
+ AssistantMessage: () => assistant_message_default,
37
+ AssistantModal: () => assistant_modal_default,
34
38
  AssistantModalPrimitive: () => assistantModal_exports,
35
39
  AssistantRuntimeProvider: () => AssistantRuntimeProvider,
40
+ BranchPicker: () => branch_picker_default,
36
41
  BranchPickerPrimitive: () => branchPicker_exports,
42
+ Composer: () => composer_default,
37
43
  ComposerPrimitive: () => composer_exports,
44
+ ContentPart: () => content_part_default,
38
45
  ContentPartPrimitive: () => contentPart_exports,
46
+ EditComposer: () => edit_composer_default,
39
47
  INTERNAL: () => internal_exports,
40
48
  MessagePrimitive: () => message_exports,
49
+ Thread: () => thread_default,
50
+ ThreadConfigProvider: () => ThreadConfigProvider,
41
51
  ThreadPrimitive: () => thread_exports,
52
+ ThreadWelcome: () => thread_welcome_default,
53
+ UserActionBar: () => user_action_bar_default,
54
+ UserMessage: () => user_message_default,
42
55
  makeAssistantTool: () => makeAssistantTool,
43
56
  makeAssistantToolUI: () => makeAssistantToolUI,
44
57
  useActionBarCopy: () => useActionBarCopy,
@@ -61,10 +74,12 @@ __export(src_exports, {
61
74
  useContentPartDisplay: () => useContentPartDisplay,
62
75
  useContentPartImage: () => useContentPartImage,
63
76
  useContentPartText: () => useContentPartText,
77
+ useEdgeRuntime: () => useEdgeRuntime,
64
78
  useLocalRuntime: () => useLocalRuntime,
65
79
  useMessageContext: () => useMessageContext,
66
80
  useMessageIf: () => useMessageIf,
67
81
  useSwitchToNewThread: () => useSwitchToNewThread,
82
+ useThreadConfig: () => useThreadConfig,
68
83
  useThreadContext: () => useThreadContext,
69
84
  useThreadEmpty: () => useThreadEmpty,
70
85
  useThreadIf: () => useThreadIf,
@@ -84,14 +99,14 @@ var import_react = require("react");
84
99
  var AssistantContext = (0, import_react.createContext)(
85
100
  null
86
101
  );
87
- var useAssistantContext = () => {
102
+ function useAssistantContext(options) {
88
103
  const context = (0, import_react.useContext)(AssistantContext);
89
- if (!context)
104
+ if (!options?.optional && !context)
90
105
  throw new Error(
91
106
  "This component must be used within an AssistantRuntimeProvider."
92
107
  );
93
108
  return context;
94
- };
109
+ }
95
110
 
96
111
  // src/context/stores/AssistantModelConfig.ts
97
112
  var import_zustand = require("zustand");
@@ -189,14 +204,14 @@ var import_react3 = require("react");
189
204
  // src/context/react/ThreadContext.ts
190
205
  var import_react2 = require("react");
191
206
  var ThreadContext = (0, import_react2.createContext)(null);
192
- var useThreadContext = () => {
207
+ function useThreadContext(options) {
193
208
  const context = (0, import_react2.useContext)(ThreadContext);
194
- if (!context)
209
+ if (!options?.optional && !context)
195
210
  throw new Error(
196
211
  "This component must be used within an AssistantRuntimeProvider."
197
212
  );
198
213
  return context;
199
- };
214
+ }
200
215
 
201
216
  // src/context/stores/Composer.ts
202
217
  var import_zustand3 = require("zustand");
@@ -287,7 +302,7 @@ var makeThreadActionStore = (runtimeRef) => {
287
302
  startRun: (parentId) => runtimeRef.current.startRun(parentId),
288
303
  append: (message) => runtimeRef.current.append(message),
289
304
  cancelRun: () => runtimeRef.current.cancelRun(),
290
- addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
305
+ addToolResult: (options) => runtimeRef.current.addToolResult(options)
291
306
  })
292
307
  );
293
308
  };
@@ -391,19 +406,19 @@ var import_react7 = require("react");
391
406
  // src/context/react/MessageContext.ts
392
407
  var import_react6 = require("react");
393
408
  var MessageContext = (0, import_react6.createContext)(null);
394
- var useMessageContext = () => {
409
+ function useMessageContext(options) {
395
410
  const context = (0, import_react6.useContext)(MessageContext);
396
- if (!context)
411
+ if (!options?.optional && !context)
397
412
  throw new Error(
398
413
  "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
399
414
  );
400
415
  return context;
401
- };
416
+ }
402
417
 
403
418
  // src/context/react/ComposerContext.ts
404
419
  var useComposerContext = () => {
405
420
  const { useComposer } = useThreadContext();
406
- const { useEditComposer } = (0, import_react7.useContext)(MessageContext) ?? {};
421
+ const { useEditComposer } = useMessageContext({ optional: true }) ?? {};
407
422
  return (0, import_react7.useMemo)(
408
423
  () => ({
409
424
  useComposer: useEditComposer ?? useComposer,
@@ -418,14 +433,14 @@ var import_react8 = require("react");
418
433
  var ContentPartContext = (0, import_react8.createContext)(
419
434
  null
420
435
  );
421
- var useContentPartContext = () => {
436
+ function useContentPartContext(options) {
422
437
  const context = (0, import_react8.useContext)(ContentPartContext);
423
- if (!context)
438
+ if (!options?.optional && !context)
424
439
  throw new Error(
425
440
  "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
426
441
  );
427
442
  return context;
428
- };
443
+ }
429
444
 
430
445
  // src/hooks/useAppendMessage.tsx
431
446
  var import_react9 = require("react");
@@ -771,6 +786,7 @@ var useMessageIf = (props) => {
771
786
  if (props.hasBranches === true && branches.length < 2) return false;
772
787
  if (props.user && message.role !== "user") return false;
773
788
  if (props.assistant && message.role !== "assistant") return false;
789
+ if (props.system && message.role !== "system") return false;
774
790
  if (props.lastOrHover === true && !isHovering && !isLast) return false;
775
791
  if (props.copied === true && !isCopied) return false;
776
792
  if (props.copied === false && isCopied) return false;
@@ -1157,9 +1173,9 @@ var useIsHoveringRef = () => {
1157
1173
  );
1158
1174
  return useManagedRef(callbackRef);
1159
1175
  };
1160
- var MessagePrimitiveRoot = (0, import_react33.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef15) => {
1176
+ var MessagePrimitiveRoot = (0, import_react33.forwardRef)(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef28) => {
1161
1177
  const isHoveringRef = useIsHoveringRef();
1162
- const ref = (0, import_react_compose_refs.useComposedRefs)(forwardRef15, isHoveringRef);
1178
+ const ref = (0, import_react_compose_refs.useComposedRefs)(forwardRef28, isHoveringRef);
1163
1179
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_primitive3.Primitive.div, { ...rest, ref });
1164
1180
  });
1165
1181
  MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
@@ -1181,11 +1197,12 @@ var import_react38 = require("react");
1181
1197
  var import_react34 = require("react");
1182
1198
  var import_zustand9 = require("zustand");
1183
1199
  var import_jsx_runtime13 = require("react/jsx-runtime");
1200
+ var DONE_STATUS = { type: "done" };
1184
1201
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
1185
1202
  const part = message.content[partIndex];
1186
1203
  if (!part) return;
1187
- const messageStatus = message.role === "assistant" ? message.status : "done";
1188
- const status = partIndex === message.content.length - 1 ? messageStatus : "done";
1204
+ const messageStatus = message.role === "assistant" ? message.status : DONE_STATUS;
1205
+ const status = partIndex === message.content.length - 1 ? messageStatus : DONE_STATUS;
1189
1206
  const currentState = useContentPart.getState();
1190
1207
  if (currentState.part === part && currentState.status === status) return;
1191
1208
  useContentPart.setState(
@@ -1227,7 +1244,8 @@ var import_react36 = require("react");
1227
1244
  // src/utils/hooks/useSmooth.tsx
1228
1245
  var import_react35 = require("react");
1229
1246
  var TextStreamAnimator = class {
1230
- constructor(setText) {
1247
+ constructor(currentText, setText) {
1248
+ this.currentText = currentText;
1231
1249
  this.setText = setText;
1232
1250
  }
1233
1251
  animationFrameId = null;
@@ -1248,33 +1266,31 @@ var TextStreamAnimator = class {
1248
1266
  const currentTime = Date.now();
1249
1267
  const deltaTime = currentTime - this.lastUpdateTime;
1250
1268
  let timeToConsume = deltaTime;
1251
- this.setText((currentText) => {
1252
- const targetText = this.targetText;
1253
- if (currentText === targetText) {
1254
- this.animationFrameId = null;
1255
- return currentText;
1256
- }
1257
- const remainingChars = targetText.length - currentText.length;
1258
- const baseTimePerChar = Math.min(5, 250 / remainingChars);
1259
- let charsToAdd = 0;
1260
- while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
1261
- charsToAdd++;
1262
- timeToConsume -= baseTimePerChar;
1263
- }
1269
+ const remainingChars = this.targetText.length - this.currentText.length;
1270
+ const baseTimePerChar = Math.min(5, 250 / remainingChars);
1271
+ let charsToAdd = 0;
1272
+ while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
1273
+ charsToAdd++;
1274
+ timeToConsume -= baseTimePerChar;
1275
+ }
1276
+ if (charsToAdd !== remainingChars) {
1264
1277
  this.animationFrameId = requestAnimationFrame(this.animate);
1265
- if (charsToAdd === 0) {
1266
- return currentText;
1267
- }
1268
- const newText = targetText.slice(0, currentText.length + charsToAdd);
1269
- this.lastUpdateTime = currentTime - timeToConsume;
1270
- return newText;
1271
- });
1278
+ } else {
1279
+ this.animationFrameId = null;
1280
+ }
1281
+ if (charsToAdd === 0) return;
1282
+ this.currentText = this.targetText.slice(
1283
+ 0,
1284
+ this.currentText.length + charsToAdd
1285
+ );
1286
+ this.lastUpdateTime = currentTime - timeToConsume;
1287
+ this.setText(this.currentText);
1272
1288
  };
1273
1289
  };
1274
1290
  var useSmooth = (text, smooth = false) => {
1275
1291
  const [displayedText, setDisplayedText] = (0, import_react35.useState)(text);
1276
1292
  const [animatorRef] = (0, import_react35.useState)(
1277
- new TextStreamAnimator(setDisplayedText)
1293
+ new TextStreamAnimator(text, setDisplayedText)
1278
1294
  );
1279
1295
  (0, import_react35.useEffect)(() => {
1280
1296
  if (!smooth) {
@@ -1283,6 +1299,7 @@ var useSmooth = (text, smooth = false) => {
1283
1299
  }
1284
1300
  if (!text.startsWith(animatorRef.targetText)) {
1285
1301
  setDisplayedText(text);
1302
+ animatorRef.currentText = text;
1286
1303
  animatorRef.targetText = text;
1287
1304
  animatorRef.stop();
1288
1305
  return;
@@ -1332,11 +1349,9 @@ var ContentPartPrimitiveDisplay = () => {
1332
1349
  ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
1333
1350
 
1334
1351
  // src/primitives/contentPart/ContentPartInProgress.tsx
1335
- var ContentPartPrimitiveInProgress = ({
1336
- children
1337
- }) => {
1352
+ var ContentPartPrimitiveInProgress = ({ children }) => {
1338
1353
  const { useContentPart } = useContentPartContext();
1339
- const isInProgress = useContentPart((c) => c.status === "in_progress");
1354
+ const isInProgress = useContentPart((c) => c.status.type === "in_progress");
1340
1355
  return isInProgress ? children : null;
1341
1356
  };
1342
1357
  ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
@@ -1361,31 +1376,37 @@ var defaultComponents = {
1361
1376
  };
1362
1377
  var MessageContentPartComponent = ({
1363
1378
  components: {
1364
- Text = defaultComponents.Text,
1365
- Image = defaultComponents.Image,
1379
+ Text: Text2 = defaultComponents.Text,
1380
+ Image: Image2 = defaultComponents.Image,
1366
1381
  UI = defaultComponents.UI,
1367
- tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {}
1382
+ tools: { by_name = {}, Fallback: Fallback2 = defaultComponents.tools.Fallback } = {}
1368
1383
  } = {}
1369
1384
  }) => {
1370
1385
  const { useThreadActions } = useThreadContext();
1386
+ const { useMessage } = useMessageContext();
1371
1387
  const addToolResult = useThreadActions((t) => t.addToolResult);
1372
1388
  const { useContentPart } = useContentPartContext();
1373
1389
  const { part, status } = useContentPart();
1374
1390
  const type = part.type;
1375
1391
  switch (type) {
1376
1392
  case "text":
1377
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text, { part, status });
1393
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Text2, { part, status });
1378
1394
  case "image":
1379
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Image, { part, status });
1395
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Image2, { part, status });
1380
1396
  case "ui":
1381
1397
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(UI, { part, status });
1382
1398
  case "tool-call": {
1383
- const Tool = by_name[part.toolName] || Fallback;
1384
- const addResult = (result) => addToolResult(part.toolCallId, result);
1399
+ const Tool = by_name[part.toolName] || Fallback2;
1400
+ const addResult = (result) => addToolResult({
1401
+ messageId: useMessage.getState().message.id,
1402
+ toolCallId: part.toolCallId,
1403
+ result
1404
+ });
1385
1405
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Tool, { part, status, addResult });
1386
1406
  }
1387
1407
  default:
1388
- throw new Error(`Unknown content part type: ${type}`);
1408
+ const unhandledType = type;
1409
+ throw new Error(`Unknown content part type: ${unhandledType}`);
1389
1410
  }
1390
1411
  };
1391
1412
  var MessageContentPartImpl = ({
@@ -1870,29 +1891,32 @@ var MessageProvider = ({
1870
1891
 
1871
1892
  // src/primitives/thread/ThreadMessages.tsx
1872
1893
  var import_jsx_runtime24 = require("react/jsx-runtime");
1894
+ var DEFAULT_SYSTEM_MESSAGE = () => null;
1873
1895
  var getComponents = (components) => {
1874
1896
  return {
1875
1897
  EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
1876
1898
  UserMessage: components.UserMessage ?? components.Message,
1877
- AssistantMessage: components.AssistantMessage ?? components.Message
1899
+ AssistantMessage: components.AssistantMessage ?? components.Message,
1900
+ SystemMessage: components.SystemMessage ?? DEFAULT_SYSTEM_MESSAGE
1878
1901
  };
1879
1902
  };
1880
1903
  var ThreadMessageImpl = ({
1881
1904
  messageIndex,
1882
1905
  components
1883
1906
  }) => {
1884
- const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
1907
+ const { UserMessage: UserMessage2, EditComposer: EditComposer2, AssistantMessage: AssistantMessage2, SystemMessage: SystemMessage2 } = getComponents(components);
1885
1908
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessageProvider, { messageIndex, children: [
1886
1909
  /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(MessagePrimitiveIf, { user: true, children: [
1887
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(UserMessage, {}) }),
1888
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(EditComposer, {}) })
1910
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(UserMessage2, {}) }),
1911
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(EditComposer2, {}) })
1889
1912
  ] }),
1890
- /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage, {}) })
1913
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage2, {}) }),
1914
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { system: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(SystemMessage2, {}) })
1891
1915
  ] });
1892
1916
  };
1893
1917
  var ThreadMessage = (0, import_react49.memo)(
1894
1918
  ThreadMessageImpl,
1895
- (prev, next) => prev.messageIndex === next.messageIndex && prev.components.Message === next.components.Message && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
1919
+ (prev, next) => prev.messageIndex === next.messageIndex && prev.components.Message === next.components.Message && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage && prev.components.SystemMessage === next.components.SystemMessage
1896
1920
  );
1897
1921
  var ThreadPrimitiveMessagesImpl = ({
1898
1922
  components
@@ -1915,7 +1939,7 @@ var ThreadPrimitiveMessagesImpl = ({
1915
1939
  ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
1916
1940
  var ThreadPrimitiveMessages = (0, import_react49.memo)(
1917
1941
  ThreadPrimitiveMessagesImpl,
1918
- (prev, next) => prev.components?.Message === next.components?.Message && prev.components?.UserMessage === next.components?.UserMessage && prev.components?.EditComposer === next.components?.EditComposer && prev.components?.AssistantMessage === next.components?.AssistantMessage
1942
+ (prev, next) => prev.components?.Message === next.components?.Message && prev.components?.UserMessage === next.components?.UserMessage && prev.components?.EditComposer === next.components?.EditComposer && prev.components?.AssistantMessage === next.components?.AssistantMessage && prev.components?.SystemMessage === next.components?.SystemMessage
1919
1943
  );
1920
1944
 
1921
1945
  // src/primitives/thread/ThreadScrollToBottom.tsx
@@ -1930,10 +1954,10 @@ var ThreadPrimitiveSuggestion = createActionButton(
1930
1954
  useThreadSuggestion
1931
1955
  );
1932
1956
 
1933
- // src/runtime/local/useLocalRuntime.tsx
1957
+ // src/runtimes/local/useLocalRuntime.tsx
1934
1958
  var import_react50 = require("react");
1935
1959
 
1936
- // src/runtime/utils/idUtils.tsx
1960
+ // src/utils/idUtils.tsx
1937
1961
  var import_non_secure = require("nanoid/non-secure");
1938
1962
  var generateId = (0, import_non_secure.customAlphabet)(
1939
1963
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
@@ -1942,7 +1966,7 @@ var generateId = (0, import_non_secure.customAlphabet)(
1942
1966
  var optimisticPrefix = "__optimistic__";
1943
1967
  var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
1944
1968
 
1945
- // src/runtime/utils/MessageRepository.tsx
1969
+ // src/runtimes/utils/MessageRepository.tsx
1946
1970
  var findHead = (message) => {
1947
1971
  if (message.next) return findHead(message.next);
1948
1972
  return message;
@@ -2016,6 +2040,17 @@ var MessageRepository = class {
2016
2040
  this.head = newItem;
2017
2041
  }
2018
2042
  }
2043
+ getMessage(messageId) {
2044
+ const message = this.messages.get(messageId);
2045
+ if (!message)
2046
+ throw new Error(
2047
+ "MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui."
2048
+ );
2049
+ return {
2050
+ parentId: message.prev?.current.id ?? null,
2051
+ message: message.current
2052
+ };
2053
+ }
2019
2054
  appendOptimisticMessage(parentId, message) {
2020
2055
  let optimisticId;
2021
2056
  do {
@@ -2093,7 +2128,7 @@ var MessageRepository = class {
2093
2128
  }
2094
2129
  };
2095
2130
 
2096
- // src/runtime/core/BaseAssistantRuntime.tsx
2131
+ // src/runtimes/core/BaseAssistantRuntime.tsx
2097
2132
  var BaseAssistantRuntime = class {
2098
2133
  constructor(_thread) {
2099
2134
  this._thread = _thread;
@@ -2134,8 +2169,8 @@ var BaseAssistantRuntime = class {
2134
2169
  cancelRun() {
2135
2170
  return this.thread.cancelRun();
2136
2171
  }
2137
- addToolResult(toolCallId, result) {
2138
- return this.thread.addToolResult(toolCallId, result);
2172
+ addToolResult(options) {
2173
+ return this.thread.addToolResult(options);
2139
2174
  }
2140
2175
  _subscriptions = /* @__PURE__ */ new Set();
2141
2176
  subscribe(callback) {
@@ -2150,7 +2185,7 @@ var BaseAssistantRuntime = class {
2150
2185
  }
2151
2186
  };
2152
2187
 
2153
- // src/runtime/local/LocalRuntime.tsx
2188
+ // src/runtimes/local/LocalRuntime.tsx
2154
2189
  var LocalRuntime = class extends BaseAssistantRuntime {
2155
2190
  _configProviders;
2156
2191
  constructor(adapter) {
@@ -2221,7 +2256,7 @@ var LocalThreadRuntime = class {
2221
2256
  const message = {
2222
2257
  id,
2223
2258
  role: "assistant",
2224
- status: "in_progress",
2259
+ status: { type: "in_progress" },
2225
2260
  content: [{ type: "text", text: "" }],
2226
2261
  createdAt: /* @__PURE__ */ new Date()
2227
2262
  };
@@ -2241,11 +2276,17 @@ var LocalThreadRuntime = class {
2241
2276
  config: mergeModelConfigs(this._configProviders),
2242
2277
  onUpdate: updateHandler
2243
2278
  });
2244
- updateHandler(result);
2245
- message.status = "done";
2279
+ if (result !== void 0) {
2280
+ updateHandler(result);
2281
+ }
2282
+ if (result.status?.type === "in_progress")
2283
+ throw new Error(
2284
+ "Unexpected in_progress status returned from ChatModelAdapter"
2285
+ );
2286
+ message.status = result.status ?? { type: "done" };
2246
2287
  this.repository.addOrUpdateMessage(parentId, { ...message });
2247
2288
  } catch (e) {
2248
- message.status = "error";
2289
+ message.status = { type: "error", error: e };
2249
2290
  this.repository.addOrUpdateMessage(parentId, { ...message });
2250
2291
  console.error(e);
2251
2292
  } finally {
@@ -2266,12 +2307,30 @@ var LocalThreadRuntime = class {
2266
2307
  this._subscriptions.add(callback);
2267
2308
  return () => this._subscriptions.delete(callback);
2268
2309
  }
2269
- addToolResult() {
2270
- throw new Error("LocalRuntime does not yet support adding tool results");
2310
+ addToolResult({ messageId, toolCallId, result }) {
2311
+ const { parentId, message } = this.repository.getMessage(messageId);
2312
+ if (message.role !== "assistant")
2313
+ throw new Error("Tried to add tool re^sult to non-assistant message");
2314
+ let found = false;
2315
+ const newContent = message.content.map((c) => {
2316
+ if (c.type !== "tool-call") return c;
2317
+ if (c.toolCallId !== toolCallId) return c;
2318
+ found = true;
2319
+ return {
2320
+ ...c,
2321
+ result
2322
+ };
2323
+ });
2324
+ if (!found)
2325
+ throw new Error("Tried to add tool result to non-existing tool call");
2326
+ this.repository.addOrUpdateMessage(parentId, {
2327
+ ...message,
2328
+ content: newContent
2329
+ });
2271
2330
  }
2272
2331
  };
2273
2332
 
2274
- // src/runtime/local/useLocalRuntime.tsx
2333
+ // src/runtimes/local/useLocalRuntime.tsx
2275
2334
  var useLocalRuntime = (adapter) => {
2276
2335
  const [runtime] = (0, import_react50.useState)(() => new LocalRuntime(adapter));
2277
2336
  (0, import_react50.useInsertionEffect)(() => {
@@ -2280,25 +2339,1494 @@ var useLocalRuntime = (adapter) => {
2280
2339
  return runtime;
2281
2340
  };
2282
2341
 
2342
+ // src/runtimes/edge/streams/assistantDecoderStream.ts
2343
+ function assistantDecoderStream() {
2344
+ let currentToolCall;
2345
+ return new TransformStream({
2346
+ transform(chunk, controller) {
2347
+ const [code, valueJson] = chunk.split(":");
2348
+ const value = JSON.parse(valueJson);
2349
+ if (currentToolCall && code !== "2" /* ToolCallArgsTextDelta */ && code !== "E" /* Error */) {
2350
+ controller.enqueue({
2351
+ type: "tool-call",
2352
+ toolCallType: "function",
2353
+ toolCallId: currentToolCall.id,
2354
+ toolName: currentToolCall.name,
2355
+ args: JSON.parse(currentToolCall.argsText)
2356
+ });
2357
+ currentToolCall = void 0;
2358
+ }
2359
+ switch (code) {
2360
+ case "0" /* TextDelta */: {
2361
+ controller.enqueue({
2362
+ type: "text-delta",
2363
+ textDelta: value
2364
+ });
2365
+ break;
2366
+ }
2367
+ case "1" /* ToolCallBegin */: {
2368
+ const { id, name } = JSON.parse(value);
2369
+ currentToolCall = { id, name, argsText: "" };
2370
+ break;
2371
+ }
2372
+ case "2" /* ToolCallArgsTextDelta */: {
2373
+ const delta = JSON.parse(value);
2374
+ currentToolCall.argsText += delta;
2375
+ controller.enqueue({
2376
+ type: "tool-call-delta",
2377
+ toolCallType: "function",
2378
+ toolCallId: currentToolCall.id,
2379
+ toolName: currentToolCall.name,
2380
+ argsTextDelta: delta
2381
+ });
2382
+ break;
2383
+ }
2384
+ case "F" /* Finish */: {
2385
+ controller.enqueue({
2386
+ type: "finish",
2387
+ ...JSON.parse(value)
2388
+ });
2389
+ break;
2390
+ }
2391
+ case "E" /* Error */: {
2392
+ controller.enqueue({
2393
+ type: "error",
2394
+ error: JSON.parse(value)
2395
+ });
2396
+ break;
2397
+ }
2398
+ default: {
2399
+ const unhandledType = code;
2400
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
2401
+ }
2402
+ }
2403
+ }
2404
+ });
2405
+ }
2406
+
2407
+ // src/runtimes/edge/streams/chunkByLineStream.ts
2408
+ function chunkByLineStream() {
2409
+ let buffer = "";
2410
+ return new TransformStream({
2411
+ transform(chunk, controller) {
2412
+ buffer += chunk;
2413
+ const lines = buffer.split("\n");
2414
+ for (let i = 0; i < lines.length - 1; i++) {
2415
+ controller.enqueue(lines[i]);
2416
+ }
2417
+ buffer = lines[lines.length - 1];
2418
+ },
2419
+ flush(controller) {
2420
+ if (buffer) {
2421
+ controller.enqueue(buffer);
2422
+ }
2423
+ }
2424
+ });
2425
+ }
2426
+
2427
+ // src/runtimes/edge/partial-json/parse-partial-json.ts
2428
+ var import_secure_json_parse = __toESM(require("secure-json-parse"));
2429
+
2430
+ // src/runtimes/edge/partial-json/fix-json.ts
2431
+ function fixJson(input) {
2432
+ const stack = ["ROOT"];
2433
+ let lastValidIndex = -1;
2434
+ let literalStart = null;
2435
+ function processValueStart(char, i, swapState) {
2436
+ {
2437
+ switch (char) {
2438
+ case '"': {
2439
+ lastValidIndex = i;
2440
+ stack.pop();
2441
+ stack.push(swapState);
2442
+ stack.push("INSIDE_STRING");
2443
+ break;
2444
+ }
2445
+ case "f":
2446
+ case "t":
2447
+ case "n": {
2448
+ lastValidIndex = i;
2449
+ literalStart = i;
2450
+ stack.pop();
2451
+ stack.push(swapState);
2452
+ stack.push("INSIDE_LITERAL");
2453
+ break;
2454
+ }
2455
+ case "-": {
2456
+ stack.pop();
2457
+ stack.push(swapState);
2458
+ stack.push("INSIDE_NUMBER");
2459
+ break;
2460
+ }
2461
+ case "0":
2462
+ case "1":
2463
+ case "2":
2464
+ case "3":
2465
+ case "4":
2466
+ case "5":
2467
+ case "6":
2468
+ case "7":
2469
+ case "8":
2470
+ case "9": {
2471
+ lastValidIndex = i;
2472
+ stack.pop();
2473
+ stack.push(swapState);
2474
+ stack.push("INSIDE_NUMBER");
2475
+ break;
2476
+ }
2477
+ case "{": {
2478
+ lastValidIndex = i;
2479
+ stack.pop();
2480
+ stack.push(swapState);
2481
+ stack.push("INSIDE_OBJECT_START");
2482
+ break;
2483
+ }
2484
+ case "[": {
2485
+ lastValidIndex = i;
2486
+ stack.pop();
2487
+ stack.push(swapState);
2488
+ stack.push("INSIDE_ARRAY_START");
2489
+ break;
2490
+ }
2491
+ }
2492
+ }
2493
+ }
2494
+ function processAfterObjectValue(char, i) {
2495
+ switch (char) {
2496
+ case ",": {
2497
+ stack.pop();
2498
+ stack.push("INSIDE_OBJECT_AFTER_COMMA");
2499
+ break;
2500
+ }
2501
+ case "}": {
2502
+ lastValidIndex = i;
2503
+ stack.pop();
2504
+ break;
2505
+ }
2506
+ }
2507
+ }
2508
+ function processAfterArrayValue(char, i) {
2509
+ switch (char) {
2510
+ case ",": {
2511
+ stack.pop();
2512
+ stack.push("INSIDE_ARRAY_AFTER_COMMA");
2513
+ break;
2514
+ }
2515
+ case "]": {
2516
+ lastValidIndex = i;
2517
+ stack.pop();
2518
+ break;
2519
+ }
2520
+ }
2521
+ }
2522
+ for (let i = 0; i < input.length; i++) {
2523
+ const char = input[i];
2524
+ const currentState = stack[stack.length - 1];
2525
+ switch (currentState) {
2526
+ case "ROOT":
2527
+ processValueStart(char, i, "FINISH");
2528
+ break;
2529
+ case "INSIDE_OBJECT_START": {
2530
+ switch (char) {
2531
+ case '"': {
2532
+ stack.pop();
2533
+ stack.push("INSIDE_OBJECT_KEY");
2534
+ break;
2535
+ }
2536
+ case "}": {
2537
+ lastValidIndex = i;
2538
+ stack.pop();
2539
+ break;
2540
+ }
2541
+ }
2542
+ break;
2543
+ }
2544
+ case "INSIDE_OBJECT_AFTER_COMMA": {
2545
+ switch (char) {
2546
+ case '"': {
2547
+ stack.pop();
2548
+ stack.push("INSIDE_OBJECT_KEY");
2549
+ break;
2550
+ }
2551
+ }
2552
+ break;
2553
+ }
2554
+ case "INSIDE_OBJECT_KEY": {
2555
+ switch (char) {
2556
+ case '"': {
2557
+ stack.pop();
2558
+ stack.push("INSIDE_OBJECT_AFTER_KEY");
2559
+ break;
2560
+ }
2561
+ }
2562
+ break;
2563
+ }
2564
+ case "INSIDE_OBJECT_AFTER_KEY": {
2565
+ switch (char) {
2566
+ case ":": {
2567
+ stack.pop();
2568
+ stack.push("INSIDE_OBJECT_BEFORE_VALUE");
2569
+ break;
2570
+ }
2571
+ }
2572
+ break;
2573
+ }
2574
+ case "INSIDE_OBJECT_BEFORE_VALUE": {
2575
+ processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
2576
+ break;
2577
+ }
2578
+ case "INSIDE_OBJECT_AFTER_VALUE": {
2579
+ processAfterObjectValue(char, i);
2580
+ break;
2581
+ }
2582
+ case "INSIDE_STRING": {
2583
+ switch (char) {
2584
+ case '"': {
2585
+ stack.pop();
2586
+ lastValidIndex = i;
2587
+ break;
2588
+ }
2589
+ case "\\": {
2590
+ stack.push("INSIDE_STRING_ESCAPE");
2591
+ break;
2592
+ }
2593
+ default: {
2594
+ lastValidIndex = i;
2595
+ }
2596
+ }
2597
+ break;
2598
+ }
2599
+ case "INSIDE_ARRAY_START": {
2600
+ switch (char) {
2601
+ case "]": {
2602
+ lastValidIndex = i;
2603
+ stack.pop();
2604
+ break;
2605
+ }
2606
+ default: {
2607
+ lastValidIndex = i;
2608
+ processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
2609
+ break;
2610
+ }
2611
+ }
2612
+ break;
2613
+ }
2614
+ case "INSIDE_ARRAY_AFTER_VALUE": {
2615
+ switch (char) {
2616
+ case ",": {
2617
+ stack.pop();
2618
+ stack.push("INSIDE_ARRAY_AFTER_COMMA");
2619
+ break;
2620
+ }
2621
+ case "]": {
2622
+ lastValidIndex = i;
2623
+ stack.pop();
2624
+ break;
2625
+ }
2626
+ default: {
2627
+ lastValidIndex = i;
2628
+ break;
2629
+ }
2630
+ }
2631
+ break;
2632
+ }
2633
+ case "INSIDE_ARRAY_AFTER_COMMA": {
2634
+ processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
2635
+ break;
2636
+ }
2637
+ case "INSIDE_STRING_ESCAPE": {
2638
+ stack.pop();
2639
+ lastValidIndex = i;
2640
+ break;
2641
+ }
2642
+ case "INSIDE_NUMBER": {
2643
+ switch (char) {
2644
+ case "0":
2645
+ case "1":
2646
+ case "2":
2647
+ case "3":
2648
+ case "4":
2649
+ case "5":
2650
+ case "6":
2651
+ case "7":
2652
+ case "8":
2653
+ case "9": {
2654
+ lastValidIndex = i;
2655
+ break;
2656
+ }
2657
+ case "e":
2658
+ case "E":
2659
+ case "-":
2660
+ case ".": {
2661
+ break;
2662
+ }
2663
+ case ",": {
2664
+ stack.pop();
2665
+ if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
2666
+ processAfterArrayValue(char, i);
2667
+ }
2668
+ if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
2669
+ processAfterObjectValue(char, i);
2670
+ }
2671
+ break;
2672
+ }
2673
+ case "}": {
2674
+ stack.pop();
2675
+ if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
2676
+ processAfterObjectValue(char, i);
2677
+ }
2678
+ break;
2679
+ }
2680
+ case "]": {
2681
+ stack.pop();
2682
+ if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
2683
+ processAfterArrayValue(char, i);
2684
+ }
2685
+ break;
2686
+ }
2687
+ default: {
2688
+ stack.pop();
2689
+ break;
2690
+ }
2691
+ }
2692
+ break;
2693
+ }
2694
+ case "INSIDE_LITERAL": {
2695
+ const partialLiteral = input.substring(literalStart, i + 1);
2696
+ if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
2697
+ stack.pop();
2698
+ if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
2699
+ processAfterObjectValue(char, i);
2700
+ } else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
2701
+ processAfterArrayValue(char, i);
2702
+ }
2703
+ } else {
2704
+ lastValidIndex = i;
2705
+ }
2706
+ break;
2707
+ }
2708
+ }
2709
+ }
2710
+ let result = input.slice(0, lastValidIndex + 1);
2711
+ for (let i = stack.length - 1; i >= 0; i--) {
2712
+ const state = stack[i];
2713
+ switch (state) {
2714
+ case "INSIDE_STRING": {
2715
+ result += '"';
2716
+ break;
2717
+ }
2718
+ case "INSIDE_OBJECT_KEY":
2719
+ case "INSIDE_OBJECT_AFTER_KEY":
2720
+ case "INSIDE_OBJECT_AFTER_COMMA":
2721
+ case "INSIDE_OBJECT_START":
2722
+ case "INSIDE_OBJECT_BEFORE_VALUE":
2723
+ case "INSIDE_OBJECT_AFTER_VALUE": {
2724
+ result += "}";
2725
+ break;
2726
+ }
2727
+ case "INSIDE_ARRAY_START":
2728
+ case "INSIDE_ARRAY_AFTER_COMMA":
2729
+ case "INSIDE_ARRAY_AFTER_VALUE": {
2730
+ result += "]";
2731
+ break;
2732
+ }
2733
+ case "INSIDE_LITERAL": {
2734
+ const partialLiteral = input.substring(literalStart, input.length);
2735
+ if ("true".startsWith(partialLiteral)) {
2736
+ result += "true".slice(partialLiteral.length);
2737
+ } else if ("false".startsWith(partialLiteral)) {
2738
+ result += "false".slice(partialLiteral.length);
2739
+ } else if ("null".startsWith(partialLiteral)) {
2740
+ result += "null".slice(partialLiteral.length);
2741
+ }
2742
+ }
2743
+ }
2744
+ }
2745
+ return result;
2746
+ }
2747
+
2748
+ // src/runtimes/edge/partial-json/parse-partial-json.ts
2749
+ var parsePartialJson = (json) => {
2750
+ try {
2751
+ return import_secure_json_parse.default.parse(json);
2752
+ } catch {
2753
+ try {
2754
+ return import_secure_json_parse.default.parse(fixJson(json));
2755
+ } catch {
2756
+ return void 0;
2757
+ }
2758
+ }
2759
+ };
2760
+
2761
+ // src/runtimes/edge/streams/runResultStream.ts
2762
+ function runResultStream() {
2763
+ let message = {
2764
+ content: []
2765
+ };
2766
+ const currentToolCall = { toolCallId: "", argsText: "" };
2767
+ return new TransformStream({
2768
+ transform(chunk, controller) {
2769
+ const chunkType = chunk.type;
2770
+ switch (chunkType) {
2771
+ case "text-delta": {
2772
+ message = appendOrUpdateText(message, chunk.textDelta);
2773
+ controller.enqueue(message);
2774
+ break;
2775
+ }
2776
+ case "tool-call-delta": {
2777
+ const { toolCallId, toolName, argsTextDelta } = chunk;
2778
+ if (currentToolCall.toolCallId !== toolCallId) {
2779
+ currentToolCall.toolCallId = toolCallId;
2780
+ currentToolCall.argsText = argsTextDelta;
2781
+ } else {
2782
+ currentToolCall.argsText += argsTextDelta;
2783
+ }
2784
+ message = appendOrUpdateToolCall(
2785
+ message,
2786
+ toolCallId,
2787
+ toolName,
2788
+ parsePartialJson(currentToolCall.argsText)
2789
+ );
2790
+ controller.enqueue(message);
2791
+ break;
2792
+ }
2793
+ case "tool-call": {
2794
+ break;
2795
+ }
2796
+ case "tool-result": {
2797
+ message = appendOrUpdateToolResult(
2798
+ message,
2799
+ chunk.toolCallId,
2800
+ chunk.toolName,
2801
+ chunk.result
2802
+ );
2803
+ controller.enqueue(message);
2804
+ break;
2805
+ }
2806
+ case "finish": {
2807
+ message = appendOrUpdateFinish(message, chunk);
2808
+ controller.enqueue(message);
2809
+ break;
2810
+ }
2811
+ case "error": {
2812
+ throw chunk.error;
2813
+ }
2814
+ default: {
2815
+ const unhandledType = chunkType;
2816
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
2817
+ }
2818
+ }
2819
+ }
2820
+ });
2821
+ }
2822
+ var appendOrUpdateText = (message, textDelta) => {
2823
+ let contentParts = message.content;
2824
+ let contentPart = message.content.at(-1);
2825
+ if (contentPart?.type !== "text") {
2826
+ contentPart = { type: "text", text: textDelta };
2827
+ } else {
2828
+ contentParts = contentParts.slice(0, -1);
2829
+ contentPart = { type: "text", text: contentPart.text + textDelta };
2830
+ }
2831
+ return {
2832
+ ...message,
2833
+ content: contentParts.concat([contentPart])
2834
+ };
2835
+ };
2836
+ var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
2837
+ let contentParts = message.content;
2838
+ let contentPart = message.content.at(-1);
2839
+ if (contentPart?.type !== "tool-call" || contentPart.toolCallId !== toolCallId) {
2840
+ contentPart = {
2841
+ type: "tool-call",
2842
+ toolCallId,
2843
+ toolName,
2844
+ args
2845
+ };
2846
+ } else {
2847
+ contentParts = contentParts.slice(0, -1);
2848
+ contentPart = {
2849
+ ...contentPart,
2850
+ args
2851
+ };
2852
+ }
2853
+ return {
2854
+ ...message,
2855
+ content: contentParts.concat([contentPart])
2856
+ };
2857
+ };
2858
+ var appendOrUpdateToolResult = (message, toolCallId, toolName, result) => {
2859
+ let found = false;
2860
+ const newContentParts = message.content.map((part) => {
2861
+ if (part.type !== "tool-call" || part.toolCallId !== toolCallId)
2862
+ return part;
2863
+ found = true;
2864
+ if (part.toolName !== toolName)
2865
+ throw new Error(
2866
+ `Tool call ${toolCallId} found with tool name ${part.toolName}, but expected ${toolName}`
2867
+ );
2868
+ return {
2869
+ ...part,
2870
+ result
2871
+ };
2872
+ });
2873
+ if (!found)
2874
+ throw new Error(
2875
+ `Received tool result for unknown tool call "${toolName}" / "${toolCallId}". This is likely an internal bug in assistant-ui.`
2876
+ );
2877
+ return {
2878
+ ...message,
2879
+ content: newContentParts
2880
+ };
2881
+ };
2882
+ var appendOrUpdateFinish = (message, chunk) => {
2883
+ const { type, ...rest } = chunk;
2884
+ return {
2885
+ ...message,
2886
+ status: {
2887
+ type: "done",
2888
+ ...rest
2889
+ }
2890
+ };
2891
+ };
2892
+
2893
+ // src/runtimes/edge/useEdgeRuntime.ts
2894
+ var import_react51 = require("react");
2895
+
2896
+ // src/runtimes/edge/streams/toolResultStream.ts
2897
+ var import_zod = require("zod");
2898
+ var import_secure_json_parse2 = __toESM(require("secure-json-parse"));
2899
+ function toolResultStream(tools) {
2900
+ const toolCallExecutions = /* @__PURE__ */ new Map();
2901
+ return new TransformStream({
2902
+ transform(chunk, controller) {
2903
+ controller.enqueue(chunk);
2904
+ const chunkType = chunk.type;
2905
+ switch (chunkType) {
2906
+ case "tool-call": {
2907
+ const { toolCallId, toolCallType, toolName, args: argsText } = chunk;
2908
+ const tool = tools?.[toolName];
2909
+ if (!tool) return;
2910
+ const args = import_secure_json_parse2.default.parse(argsText);
2911
+ if (tool.parameters instanceof import_zod.z.ZodType) {
2912
+ const result = tool.parameters.safeParse(args);
2913
+ if (!result.success) {
2914
+ controller.enqueue({
2915
+ type: "error",
2916
+ error: new Error("Invalid tool call arguments")
2917
+ });
2918
+ return;
2919
+ } else {
2920
+ toolCallExecutions.set(
2921
+ toolCallId,
2922
+ (async () => {
2923
+ try {
2924
+ const result2 = await tool.execute(args);
2925
+ controller.enqueue({
2926
+ type: "tool-result",
2927
+ toolCallType,
2928
+ toolCallId,
2929
+ toolName,
2930
+ result: result2
2931
+ });
2932
+ } catch (error) {
2933
+ controller.enqueue({
2934
+ type: "error",
2935
+ error
2936
+ });
2937
+ } finally {
2938
+ toolCallExecutions.delete(toolCallId);
2939
+ }
2940
+ })()
2941
+ );
2942
+ }
2943
+ }
2944
+ break;
2945
+ }
2946
+ case "text-delta":
2947
+ case "tool-call-delta":
2948
+ case "finish":
2949
+ case "error":
2950
+ break;
2951
+ default: {
2952
+ const unhandledType = chunkType;
2953
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
2954
+ }
2955
+ }
2956
+ },
2957
+ async flush() {
2958
+ await Promise.all(toolCallExecutions.values());
2959
+ }
2960
+ });
2961
+ }
2962
+
2963
+ // src/runtimes/edge/useEdgeRuntime.ts
2964
+ var import_zod2 = require("zod");
2965
+ var import_zod_to_json_schema = require("zod-to-json-schema");
2966
+ function asAsyncIterable(source) {
2967
+ return {
2968
+ [Symbol.asyncIterator]: () => {
2969
+ const reader = source.getReader();
2970
+ return {
2971
+ async next() {
2972
+ const { done, value } = await reader.read();
2973
+ return done ? { done: true, value: void 0 } : { done: false, value };
2974
+ }
2975
+ };
2976
+ }
2977
+ };
2978
+ }
2979
+ var toSerializableTools = (tools) => {
2980
+ if (!tools) return [];
2981
+ return Object.entries(tools).map(([name, tool]) => ({
2982
+ type: "function",
2983
+ name,
2984
+ ...tool.description ? { description: tool.description } : void 0,
2985
+ parameters: tool.parameters instanceof import_zod2.z.ZodType ? (0, import_zod_to_json_schema.zodToJsonSchema)(tool.parameters) : tool.parameters
2986
+ }));
2987
+ };
2988
+ var createEdgeChatAdapter = ({
2989
+ api
2990
+ }) => ({
2991
+ run: async ({ messages, abortSignal, config, onUpdate }) => {
2992
+ const result = await fetch(api, {
2993
+ method: "POST",
2994
+ headers: {
2995
+ "Content-Type": "application/json"
2996
+ },
2997
+ body: JSON.stringify({
2998
+ system: config.system,
2999
+ messages,
3000
+ tools: toSerializableTools(
3001
+ config.tools
3002
+ )
3003
+ }),
3004
+ signal: abortSignal
3005
+ });
3006
+ const stream = result.body.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(assistantDecoderStream()).pipeThrough(toolResultStream(config.tools)).pipeThrough(runResultStream());
3007
+ let update;
3008
+ for await (update of asAsyncIterable(stream)) {
3009
+ onUpdate(update);
3010
+ }
3011
+ if (update === void 0)
3012
+ throw new Error("No data received from Edge Runtime");
3013
+ return update;
3014
+ }
3015
+ });
3016
+ var useEdgeRuntime = (options) => {
3017
+ const adapter = (0, import_react51.useMemo)(() => createEdgeChatAdapter(options), [options]);
3018
+ return useLocalRuntime(adapter);
3019
+ };
3020
+
3021
+ // src/ui/thread-config.tsx
3022
+ var import_react52 = require("react");
3023
+ var import_jsx_runtime25 = require("react/jsx-runtime");
3024
+ var ThreadConfigContext = (0, import_react52.createContext)({});
3025
+ var useThreadConfig = () => {
3026
+ return (0, import_react52.useContext)(ThreadConfigContext);
3027
+ };
3028
+ var ThreadConfigProvider = ({
3029
+ children,
3030
+ config
3031
+ }) => {
3032
+ const assistant = useAssistantContext({ optional: true });
3033
+ const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children });
3034
+ if (!config?.runtime) return configProvider;
3035
+ if (assistant) {
3036
+ throw new Error(
3037
+ "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
3038
+ );
3039
+ }
3040
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
3041
+ };
3042
+ ThreadConfigProvider.displayName = "ThreadConfigProvider";
3043
+
3044
+ // src/ui/assistant-action-bar.tsx
3045
+ var import_react56 = require("react");
3046
+ var import_lucide_react = require("lucide-react");
3047
+
3048
+ // src/ui/base/tooltip-icon-button.tsx
3049
+ var import_react55 = require("react");
3050
+
3051
+ // src/ui/base/tooltip.tsx
3052
+ var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip"));
3053
+
3054
+ // src/ui/utils/withDefaults.tsx
3055
+ var import_react53 = require("react");
3056
+ var import_classnames = __toESM(require("classnames"));
3057
+ var import_jsx_runtime26 = require("react/jsx-runtime");
3058
+ var withDefaultProps = ({
3059
+ className,
3060
+ ...defaultProps
3061
+ }) => ({ className: classNameProp, ...props }) => {
3062
+ return {
3063
+ className: (0, import_classnames.default)(className, classNameProp),
3064
+ ...defaultProps,
3065
+ ...props
3066
+ };
3067
+ };
3068
+ var withDefaults = (Component, defaultProps) => {
3069
+ const getProps = withDefaultProps(defaultProps);
3070
+ const WithDefaults = (0, import_react53.forwardRef)(
3071
+ (props, ref) => {
3072
+ const ComponentAsAny = Component;
3073
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ComponentAsAny, { ...getProps(props), ref });
3074
+ }
3075
+ );
3076
+ WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
3077
+ return WithDefaults;
3078
+ };
3079
+
3080
+ // src/ui/base/tooltip.tsx
3081
+ var import_jsx_runtime27 = require("react/jsx-runtime");
3082
+ var Tooltip = (props) => {
3083
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(TooltipPrimitive.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(TooltipPrimitive.Root, { ...props }) });
3084
+ };
3085
+ Tooltip.displayName = "Tooltip";
3086
+ var TooltipTrigger = TooltipPrimitive.Trigger;
3087
+ var TooltipContent = withDefaults(TooltipPrimitive.Content, {
3088
+ sideOffset: 4,
3089
+ className: "aui-tooltip-content"
3090
+ });
3091
+ TooltipContent.displayName = "TooltipContent";
3092
+
3093
+ // src/ui/base/button.tsx
3094
+ var import_class_variance_authority = require("class-variance-authority");
3095
+ var import_react_primitive11 = require("@radix-ui/react-primitive");
3096
+ var import_react54 = require("react");
3097
+ var import_jsx_runtime28 = require("react/jsx-runtime");
3098
+ var buttonVariants = (0, import_class_variance_authority.cva)("aui-button", {
3099
+ variants: {
3100
+ variant: {
3101
+ default: "aui-button-primary",
3102
+ outline: "aui-button-outline",
3103
+ ghost: "aui-button-ghost"
3104
+ },
3105
+ size: {
3106
+ default: "aui-button-medium",
3107
+ icon: "aui-button-icon"
3108
+ }
3109
+ },
3110
+ defaultVariants: {
3111
+ variant: "default",
3112
+ size: "default"
3113
+ }
3114
+ });
3115
+ var Button = (0, import_react54.forwardRef)(
3116
+ ({ className, variant, size, ...props }, ref) => {
3117
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3118
+ import_react_primitive11.Primitive.button,
3119
+ {
3120
+ className: buttonVariants({ variant, size, className }),
3121
+ ...props,
3122
+ ref
3123
+ }
3124
+ );
3125
+ }
3126
+ );
3127
+ Button.displayName = "Button";
3128
+
3129
+ // src/ui/base/tooltip-icon-button.tsx
3130
+ var import_jsx_runtime29 = require("react/jsx-runtime");
3131
+ var TooltipIconButton = (0, import_react55.forwardRef)(({ children, tooltip, side = "bottom", ...rest }, ref) => {
3132
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(Tooltip, { children: [
3133
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
3134
+ children,
3135
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "aui-sr-only", children: tooltip })
3136
+ ] }) }),
3137
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(TooltipContent, { side, children: tooltip })
3138
+ ] });
3139
+ });
3140
+ TooltipIconButton.displayName = "TooltipIconButton";
3141
+
3142
+ // src/ui/assistant-action-bar.tsx
3143
+ var import_jsx_runtime30 = require("react/jsx-runtime");
3144
+ var useAllowCopy = () => {
3145
+ const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
3146
+ const { useThreadActions } = useThreadContext();
3147
+ const copySupported = useThreadActions((t) => t.capabilities.copy);
3148
+ return copySupported && allowCopy;
3149
+ };
3150
+ var useAllowReload = () => {
3151
+ const { assistantMessage: { allowReload = true } = {} } = useThreadConfig();
3152
+ const { useThreadActions } = useThreadContext();
3153
+ const reloadSupported = useThreadActions((t) => t.capabilities.reload);
3154
+ return reloadSupported && allowReload;
3155
+ };
3156
+ var AssistantActionBar = () => {
3157
+ const allowCopy = useAllowCopy();
3158
+ const allowReload = useAllowReload();
3159
+ if (!allowCopy && !allowReload) return null;
3160
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
3161
+ AssistantActionBarRoot,
3162
+ {
3163
+ hideWhenRunning: true,
3164
+ autohide: "not-last",
3165
+ autohideFloat: "single-branch",
3166
+ children: [
3167
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(AssistantActionBarCopy, {}),
3168
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(AssistantActionBarReload, {})
3169
+ ]
3170
+ }
3171
+ );
3172
+ };
3173
+ AssistantActionBar.displayName = "AssistantActionBar";
3174
+ var AssistantActionBarRoot = withDefaults(actionBar_exports.Root, {
3175
+ className: "aui-assistant-action-bar-root"
3176
+ });
3177
+ AssistantActionBarRoot.displayName = "AssistantActionBarRoot";
3178
+ var AssistantActionBarCopy = (0, import_react56.forwardRef)((props, ref) => {
3179
+ const {
3180
+ strings: {
3181
+ assistantMessage: { reload: { tooltip = "Copy" } = {} } = {}
3182
+ } = {}
3183
+ } = useThreadConfig();
3184
+ const allowCopy = useAllowCopy();
3185
+ if (!allowCopy) return null;
3186
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(TooltipIconButton, { tooltip, ...props, ref, children: [
3187
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(message_exports.If, { copied: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_lucide_react.CheckIcon, {}) }),
3188
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(message_exports.If, { copied: false, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_lucide_react.CopyIcon, {}) })
3189
+ ] }) });
3190
+ });
3191
+ AssistantActionBarCopy.displayName = "AssistantActionBarCopy";
3192
+ var AssistantActionBarReload = (0, import_react56.forwardRef)((props, ref) => {
3193
+ const {
3194
+ strings: {
3195
+ assistantMessage: { reload: { tooltip = "Refresh" } = {} } = {}
3196
+ } = {}
3197
+ } = useThreadConfig();
3198
+ const allowReload = useAllowReload();
3199
+ if (!allowReload) return null;
3200
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(actionBar_exports.Reload, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_lucide_react.RefreshCwIcon, {}) }) });
3201
+ });
3202
+ AssistantActionBarReload.displayName = "AssistantActionBarReload";
3203
+ var exports2 = {
3204
+ Root: AssistantActionBarRoot,
3205
+ Reload: AssistantActionBarReload,
3206
+ Copy: AssistantActionBarCopy
3207
+ };
3208
+ var assistant_action_bar_default = Object.assign(
3209
+ AssistantActionBar,
3210
+ exports2
3211
+ );
3212
+
3213
+ // src/ui/assistant-message.tsx
3214
+ var import_react58 = require("react");
3215
+
3216
+ // src/ui/branch-picker.tsx
3217
+ var import_react57 = require("react");
3218
+ var import_lucide_react2 = require("lucide-react");
3219
+ var import_jsx_runtime31 = require("react/jsx-runtime");
3220
+ var BranchPicker = () => {
3221
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(BranchPickerRoot, { hideWhenSingleBranch: true, children: [
3222
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(BranchPickerPrevious2, {}),
3223
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(BranchPickerState, {}),
3224
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(BranchPickerNext, {})
3225
+ ] });
3226
+ };
3227
+ BranchPicker.displayName = "BranchPicker";
3228
+ var BranchPickerRoot = withDefaults(branchPicker_exports.Root, {
3229
+ className: "aui-branch-picker-root"
3230
+ });
3231
+ BranchPickerRoot.displayName = "BranchPickerRoot";
3232
+ var BranchPickerPrevious2 = (0, import_react57.forwardRef)((props, ref) => {
3233
+ const {
3234
+ strings: {
3235
+ branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
3236
+ } = {}
3237
+ } = useThreadConfig();
3238
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_lucide_react2.ChevronLeftIcon, {}) }) });
3239
+ });
3240
+ BranchPickerPrevious2.displayName = "BranchPickerPrevious";
3241
+ var BranchPickerStateWrapper = withDefaults("span", {
3242
+ className: "aui-branch-picker-state"
3243
+ });
3244
+ var BranchPickerState = (0, import_react57.forwardRef)((props, ref) => {
3245
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(BranchPickerStateWrapper, { ...props, ref, children: [
3246
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(branchPicker_exports.Number, {}),
3247
+ " / ",
3248
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(branchPicker_exports.Count, {})
3249
+ ] });
3250
+ });
3251
+ BranchPickerState.displayName = "BranchPickerState";
3252
+ var BranchPickerNext = (0, import_react57.forwardRef)((props, ref) => {
3253
+ const {
3254
+ strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
3255
+ } = useThreadConfig();
3256
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_lucide_react2.ChevronRightIcon, {}) }) });
3257
+ });
3258
+ BranchPickerNext.displayName = "BranchPickerNext";
3259
+ var exports3 = {
3260
+ Root: BranchPickerRoot,
3261
+ Previous: BranchPickerPrevious2,
3262
+ Next: BranchPickerNext
3263
+ };
3264
+ var branch_picker_default = Object.assign(BranchPicker, exports3);
3265
+
3266
+ // src/ui/base/avatar.tsx
3267
+ var AvatarPrimitive = __toESM(require("@radix-ui/react-avatar"));
3268
+ var import_jsx_runtime32 = require("react/jsx-runtime");
3269
+ var Avatar = ({ src, alt, fallback }) => {
3270
+ if (src == null && fallback == null) return null;
3271
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(AvatarRoot, { children: [
3272
+ src != null && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(AvatarImage, { src, alt }),
3273
+ fallback != null && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(AvatarFallback, { children: fallback })
3274
+ ] });
3275
+ };
3276
+ Avatar.displayName = "Avatar";
3277
+ var AvatarRoot = withDefaults(AvatarPrimitive.Root, {
3278
+ className: "aui-avatar-root"
3279
+ });
3280
+ AvatarRoot.displayName = "AvatarRoot";
3281
+ var AvatarImage = withDefaults(AvatarPrimitive.Image, {
3282
+ className: "aui-avatar-image"
3283
+ });
3284
+ AvatarImage.displayName = "AvatarImage";
3285
+ var AvatarFallback = withDefaults(AvatarPrimitive.Fallback, {
3286
+ className: "aui-avatar-fallback"
3287
+ });
3288
+ AvatarFallback.displayName = "AvatarFallback";
3289
+
3290
+ // src/ui/content-part.tsx
3291
+ var import_classnames2 = __toESM(require("classnames"));
3292
+ var import_jsx_runtime33 = require("react/jsx-runtime");
3293
+ var Text = ({ status }) => {
3294
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
3295
+ "p",
3296
+ {
3297
+ className: (0, import_classnames2.default)(
3298
+ "aui-text",
3299
+ status.type === "in_progress" && "aui-text-in-progress"
3300
+ ),
3301
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(contentPart_exports.Text, {})
3302
+ }
3303
+ );
3304
+ };
3305
+ var exports4 = { Text };
3306
+ var content_part_default = exports4;
3307
+
3308
+ // src/ui/assistant-message.tsx
3309
+ var import_jsx_runtime34 = require("react/jsx-runtime");
3310
+ var AssistantMessage = () => {
3311
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(AssistantMessageRoot, { children: [
3312
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AssistantMessageAvatar, {}),
3313
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AssistantMessageContent, {}),
3314
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(branch_picker_default, {}),
3315
+ /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(assistant_action_bar_default, {})
3316
+ ] });
3317
+ };
3318
+ AssistantMessage.displayName = "AssistantMessage";
3319
+ var AssistantMessageAvatar = () => {
3320
+ const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
3321
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Avatar, { ...avatar });
3322
+ };
3323
+ var AssistantMessageRoot = withDefaults(message_exports.Root, {
3324
+ className: "aui-assistant-message-root"
3325
+ });
3326
+ AssistantMessageRoot.displayName = "AssistantMessageRoot";
3327
+ var AssistantMessageContentWrapper = withDefaults("div", {
3328
+ className: "aui-assistant-message-content"
3329
+ });
3330
+ var AssistantMessageContent = (0, import_react58.forwardRef)(({ components: componentsProp, ...rest }, ref) => {
3331
+ const { assistantMessage: { components = {} } = {} } = useThreadConfig();
3332
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(AssistantMessageContentWrapper, { ...rest, ref, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3333
+ message_exports.Content,
3334
+ {
3335
+ components: {
3336
+ ...componentsProp,
3337
+ Text: componentsProp?.Text ?? components.Text ?? content_part_default.Text
3338
+ }
3339
+ }
3340
+ ) });
3341
+ });
3342
+ AssistantMessageContent.displayName = "AssistantMessageContent";
3343
+ var exports5 = {
3344
+ Root: AssistantMessageRoot,
3345
+ Avatar: AssistantMessageAvatar,
3346
+ Content: AssistantMessageContent
3347
+ };
3348
+ var assistant_message_default = Object.assign(
3349
+ AssistantMessage,
3350
+ exports5
3351
+ );
3352
+
3353
+ // src/ui/assistant-modal.tsx
3354
+ var import_react65 = require("react");
3355
+ var import_lucide_react6 = require("lucide-react");
3356
+
3357
+ // src/ui/thread.tsx
3358
+ var import_react64 = require("react");
3359
+ var import_lucide_react5 = require("lucide-react");
3360
+
3361
+ // src/ui/composer.tsx
3362
+ var import_react59 = require("react");
3363
+ var import_lucide_react3 = require("lucide-react");
3364
+
3365
+ // src/ui/base/CircleStopIcon.tsx
3366
+ var import_jsx_runtime35 = require("react/jsx-runtime");
3367
+ var CircleStopIcon = () => {
3368
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
3369
+ "svg",
3370
+ {
3371
+ xmlns: "http://www.w3.org/2000/svg",
3372
+ viewBox: "0 0 16 16",
3373
+ fill: "currentColor",
3374
+ children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" })
3375
+ }
3376
+ );
3377
+ };
3378
+ CircleStopIcon.displayName = "CircleStopIcon";
3379
+
3380
+ // src/ui/composer.tsx
3381
+ var import_jsx_runtime36 = require("react/jsx-runtime");
3382
+ var Composer = () => {
3383
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(ComposerRoot, { children: [
3384
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerInput, { autoFocus: true }),
3385
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerAction, {})
3386
+ ] });
3387
+ };
3388
+ Composer.displayName = "Composer";
3389
+ var ComposerRoot = withDefaults(composer_exports.Root, {
3390
+ className: "aui-composer-root"
3391
+ });
3392
+ ComposerRoot.displayName = "ComposerRoot";
3393
+ var ComposerInputStyled = withDefaults(composer_exports.Input, {
3394
+ rows: 1,
3395
+ autoFocus: true,
3396
+ className: "aui-composer-input"
3397
+ });
3398
+ var ComposerInput = (0, import_react59.forwardRef)(
3399
+ (props, ref) => {
3400
+ const {
3401
+ strings: {
3402
+ composer: { input: { placeholder = "Write a message..." } = {} } = {}
3403
+ } = {}
3404
+ } = useThreadConfig();
3405
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerInputStyled, { placeholder, ...props, ref });
3406
+ }
3407
+ );
3408
+ ComposerInput.displayName = "ComposerInput";
3409
+ var useAllowCancel = () => {
3410
+ const { useThreadActions } = useThreadContext();
3411
+ const cancelSupported = useThreadActions((t) => t.capabilities.cancel);
3412
+ return cancelSupported;
3413
+ };
3414
+ var ComposerAction = () => {
3415
+ const allowCancel = useAllowCancel();
3416
+ if (!allowCancel) return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerSend, {});
3417
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(import_jsx_runtime36.Fragment, { children: [
3418
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(thread_exports.If, { running: false, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerSend, {}) }),
3419
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(thread_exports.If, { running: true, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerCancel, {}) })
3420
+ ] });
3421
+ };
3422
+ ComposerAction.displayName = "ComposerAction";
3423
+ var ComposerSendButton = withDefaults(TooltipIconButton, {
3424
+ variant: "default",
3425
+ className: "aui-composer-send"
3426
+ });
3427
+ var ComposerSend = (0, import_react59.forwardRef)((props, ref) => {
3428
+ const {
3429
+ strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
3430
+ } = useThreadConfig();
3431
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerSendButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_lucide_react3.SendHorizonalIcon, {}) }) });
3432
+ });
3433
+ ComposerSend.displayName = "ComposerSend";
3434
+ var ComposerCancelButton = withDefaults(TooltipIconButton, {
3435
+ variant: "default",
3436
+ className: "aui-composer-cancel"
3437
+ });
3438
+ var ComposerCancel = (0, import_react59.forwardRef)((props, ref) => {
3439
+ const {
3440
+ strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
3441
+ } = useThreadConfig();
3442
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerCancelButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(CircleStopIcon, {}) }) });
3443
+ });
3444
+ ComposerCancel.displayName = "ComposerCancel";
3445
+ var exports6 = {
3446
+ Root: ComposerRoot,
3447
+ Input: ComposerInput,
3448
+ Action: ComposerAction,
3449
+ Send: ComposerSend,
3450
+ Cancel: ComposerCancel
3451
+ };
3452
+ var composer_default = Object.assign(Composer, exports6);
3453
+
3454
+ // src/ui/thread-welcome.tsx
3455
+ var import_react60 = require("react");
3456
+ var import_jsx_runtime37 = require("react/jsx-runtime");
3457
+ var ThreadWelcome = () => {
3458
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(ThreadWelcomeRoot, { children: [
3459
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(ThreadWelcomeCenter, { children: [
3460
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeAvatar, {}),
3461
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeMessage, {})
3462
+ ] }),
3463
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeSuggestions, {})
3464
+ ] });
3465
+ };
3466
+ ThreadWelcome.displayName = "ThreadWelcome";
3467
+ var ThreadWelcomeRootStyled = withDefaults("div", {
3468
+ className: "aui-thread-welcome-root"
3469
+ });
3470
+ var ThreadWelcomeCenter = withDefaults("div", {
3471
+ className: "aui-thread-welcome-center"
3472
+ });
3473
+ var ThreadWelcomeRoot = (0, import_react60.forwardRef)(
3474
+ (props, ref) => {
3475
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(thread_exports.Empty, { children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeRootStyled, { ...props, ref }) });
3476
+ }
3477
+ );
3478
+ ThreadWelcomeRoot.displayName = "ThreadWelcomeRoot";
3479
+ var ThreadWelcomeAvatar = () => {
3480
+ const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
3481
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Avatar, { ...avatar });
3482
+ };
3483
+ var ThreadWelcomeMessageStyled = withDefaults("p", {
3484
+ className: "aui-thread-welcome-message"
3485
+ });
3486
+ var ThreadWelcomeMessage = (0, import_react60.forwardRef)(({ message: messageProp, ...rest }, ref) => {
3487
+ const { welcome: { message = "How can I help you today?" } = {} } = useThreadConfig();
3488
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeMessageStyled, { ...rest, ref, children: messageProp ?? message });
3489
+ });
3490
+ ThreadWelcomeMessage.displayName = "ThreadWelcomeMessage";
3491
+ var ThreadWelcomeSuggestionContainer = withDefaults("div", {
3492
+ className: "aui-thread-welcome-suggestion-container"
3493
+ });
3494
+ var ThreadWelcomeSuggestionStyled = withDefaults(thread_exports.Suggestion, {
3495
+ className: "aui-thread-welcome-suggestion"
3496
+ });
3497
+ var ThreadWelcomeSuggestion = ({
3498
+ suggestion: { text, prompt }
3499
+ }) => {
3500
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3501
+ ThreadWelcomeSuggestionStyled,
3502
+ {
3503
+ prompt: prompt ?? text,
3504
+ method: "replace",
3505
+ autoSend: true,
3506
+ children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "aui-thread-welcome-suggestion-text", children: text })
3507
+ }
3508
+ );
3509
+ };
3510
+ var ThreadWelcomeSuggestions = () => {
3511
+ const { welcome: { suggestions } = {} } = useThreadConfig();
3512
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeSuggestionContainer, { children: suggestions?.map((suggestion, idx) => {
3513
+ const key = `${suggestion.prompt}-${idx}`;
3514
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ThreadWelcomeSuggestion, { suggestion }, key);
3515
+ }) });
3516
+ };
3517
+ ThreadWelcomeSuggestions.displayName = "ThreadWelcomeSuggestions";
3518
+ var exports7 = {
3519
+ Root: ThreadWelcomeRoot,
3520
+ Center: ThreadWelcomeCenter,
3521
+ Avatar: ThreadWelcomeAvatar,
3522
+ Message: ThreadWelcomeMessage,
3523
+ Suggestions: ThreadWelcomeSuggestions,
3524
+ Suggestion: ThreadWelcomeSuggestion
3525
+ };
3526
+ var thread_welcome_default = Object.assign(ThreadWelcome, exports7);
3527
+
3528
+ // src/ui/user-message.tsx
3529
+ var import_react62 = require("react");
3530
+
3531
+ // src/ui/user-action-bar.tsx
3532
+ var import_react61 = require("react");
3533
+ var import_lucide_react4 = require("lucide-react");
3534
+ var import_jsx_runtime38 = require("react/jsx-runtime");
3535
+ var useAllowEdit = () => {
3536
+ const { userMessage: { allowEdit = true } = {} } = useThreadConfig();
3537
+ const { useThreadActions } = useThreadContext();
3538
+ const editSupported = useThreadActions((t) => t.capabilities.edit);
3539
+ return editSupported && allowEdit;
3540
+ };
3541
+ var UserActionBar = () => {
3542
+ const allowEdit = useAllowEdit();
3543
+ if (!allowEdit) return null;
3544
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(UserActionBarRoot, { hideWhenRunning: true, autohide: "not-last", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(UserActionBarEdit, {}) });
3545
+ };
3546
+ UserActionBar.displayName = "UserActionBar";
3547
+ var UserActionBarRoot = withDefaults(actionBar_exports.Root, {
3548
+ className: "aui-user-action-bar-root"
3549
+ });
3550
+ UserActionBarRoot.displayName = "UserActionBarRoot";
3551
+ var UserActionBarEdit = (0, import_react61.forwardRef)((props, ref) => {
3552
+ const {
3553
+ strings: { userMessage: { edit: { tooltip = "Edit" } = {} } = {} } = {}
3554
+ } = useThreadConfig();
3555
+ const allowEdit = useAllowEdit();
3556
+ if (!allowEdit) return null;
3557
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_lucide_react4.PencilIcon, {}) }) });
3558
+ });
3559
+ UserActionBarEdit.displayName = "UserActionBarEdit";
3560
+ var exports8 = {
3561
+ Root: UserActionBarRoot,
3562
+ Edit: UserActionBarEdit
3563
+ };
3564
+ var user_action_bar_default = Object.assign(UserActionBar, exports8);
3565
+
3566
+ // src/ui/user-message.tsx
3567
+ var import_jsx_runtime39 = require("react/jsx-runtime");
3568
+ var UserMessage = () => {
3569
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(UserMessageRoot, { children: [
3570
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(user_action_bar_default, {}),
3571
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(UserMessageContent, {}),
3572
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(branch_picker_default, {})
3573
+ ] });
3574
+ };
3575
+ UserMessage.displayName = "UserMessage";
3576
+ var UserMessageRoot = withDefaults(message_exports.Root, {
3577
+ className: "aui-user-message-root"
3578
+ });
3579
+ UserMessageRoot.displayName = "UserMessageRoot";
3580
+ var UserMessageContentWrapper = withDefaults("div", {
3581
+ className: "aui-user-message-content"
3582
+ });
3583
+ var UserMessageContent = (0, import_react62.forwardRef)(
3584
+ ({ components, ...props }, ref) => {
3585
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(UserMessageContentWrapper, { ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3586
+ message_exports.Content,
3587
+ {
3588
+ components: {
3589
+ ...components,
3590
+ Text: components?.Text ?? content_part_default.Text
3591
+ }
3592
+ }
3593
+ ) });
3594
+ }
3595
+ );
3596
+ UserMessageContent.displayName = "UserMessageContent";
3597
+ var exports9 = {
3598
+ Root: UserMessageRoot,
3599
+ Content: UserMessageContent
3600
+ };
3601
+ var user_message_default = Object.assign(UserMessage, exports9);
3602
+
3603
+ // src/ui/edit-composer.tsx
3604
+ var import_react63 = require("react");
3605
+ var import_jsx_runtime40 = require("react/jsx-runtime");
3606
+ var EditComposer = () => {
3607
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(EditComposerRoot, { children: [
3608
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(EditComposerInput, {}),
3609
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(EditComposerFooter, { children: [
3610
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(EditComposerCancel, {}),
3611
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(EditComposerSend, {})
3612
+ ] })
3613
+ ] });
3614
+ };
3615
+ EditComposer.displayName = "EditComposer";
3616
+ var EditComposerRoot = withDefaults(composer_exports.Root, {
3617
+ className: "aui-edit-composer-root"
3618
+ });
3619
+ EditComposerRoot.displayName = "EditComposerRoot";
3620
+ var EditComposerInput = withDefaults(composer_exports.Input, {
3621
+ className: "aui-edit-composer-input"
3622
+ });
3623
+ EditComposerInput.displayName = "EditComposerInput";
3624
+ var EditComposerFooter = withDefaults("div", {
3625
+ className: "aui-edit-composer-footer"
3626
+ });
3627
+ EditComposerFooter.displayName = "EditComposerFooter";
3628
+ var EditComposerCancel = (0, import_react63.forwardRef)(
3629
+ (props, ref) => {
3630
+ const {
3631
+ strings: {
3632
+ editComposer: { cancel: { label = "Cancel" } = {} } = {}
3633
+ } = {}
3634
+ } = useThreadConfig();
3635
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Button, { variant: "ghost", ...props, ref, children: label }) });
3636
+ }
3637
+ );
3638
+ EditComposerCancel.displayName = "EditComposerCancel";
3639
+ var EditComposerSend = (0, import_react63.forwardRef)(
3640
+ (props, ref) => {
3641
+ const {
3642
+ strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
3643
+ } = useThreadConfig();
3644
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Button, { ...props, ref, children: label }) });
3645
+ }
3646
+ );
3647
+ EditComposerSend.displayName = "EditComposerSend";
3648
+ var exports10 = {
3649
+ Root: EditComposerRoot,
3650
+ Input: EditComposerInput,
3651
+ Footer: EditComposerFooter,
3652
+ Cancel: EditComposerCancel,
3653
+ Send: EditComposerSend
3654
+ };
3655
+ var edit_composer_default = Object.assign(EditComposer, exports10);
3656
+
3657
+ // src/ui/thread.tsx
3658
+ var import_jsx_runtime41 = require("react/jsx-runtime");
3659
+ var Thread = (config) => {
3660
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ThreadRoot, { config, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(ThreadViewport, { children: [
3661
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(thread_welcome_default, {}),
3662
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ThreadMessages, {}),
3663
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(ThreadViewportFooter, { children: [
3664
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ThreadScrollToBottom, {}),
3665
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(composer_default, {})
3666
+ ] })
3667
+ ] }) });
3668
+ };
3669
+ var ThreadRootStyled = withDefaults(thread_exports.Root, {
3670
+ className: "aui-root aui-thread-root"
3671
+ });
3672
+ var ThreadRoot = (0, import_react64.forwardRef)(
3673
+ ({ config, ...props }, ref) => {
3674
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ThreadConfigProvider, { config, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ThreadRootStyled, { ...props, ref }) });
3675
+ }
3676
+ );
3677
+ ThreadRoot.displayName = "ThreadRoot";
3678
+ var ThreadViewport = withDefaults(thread_exports.Viewport, {
3679
+ className: "aui-thread-viewport"
3680
+ });
3681
+ ThreadViewport.displayName = "ThreadViewport";
3682
+ var ThreadViewportFooter = withDefaults("div", {
3683
+ className: "aui-thread-viewport-footer"
3684
+ });
3685
+ ThreadViewportFooter.displayName = "ThreadViewportFooter";
3686
+ var SystemMessage = () => null;
3687
+ var ThreadMessages = ({ components, ...rest }) => {
3688
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3689
+ thread_exports.Messages,
3690
+ {
3691
+ components: {
3692
+ UserMessage: components?.UserMessage ?? user_message_default,
3693
+ EditComposer: components?.EditComposer ?? edit_composer_default,
3694
+ AssistantMessage: components?.AssistantMessage ?? assistant_message_default,
3695
+ SystemMessage: components?.SystemMessage ?? SystemMessage
3696
+ },
3697
+ ...rest
3698
+ }
3699
+ );
3700
+ };
3701
+ ThreadMessages.displayName = "ThreadMessages";
3702
+ var ThreadScrollToBottomIconButton = withDefaults(TooltipIconButton, {
3703
+ variant: "outline",
3704
+ className: "aui-thread-scroll-to-bottom"
3705
+ });
3706
+ var ThreadScrollToBottom = (0, import_react64.forwardRef)((props, ref) => {
3707
+ const {
3708
+ strings: {
3709
+ thread: { scrollToBottom: { tooltip = "Scroll to bottom" } = {} } = {}
3710
+ } = {}
3711
+ } = useThreadConfig();
3712
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_lucide_react5.ArrowDownIcon, {}) }) });
3713
+ });
3714
+ ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
3715
+ var exports11 = {
3716
+ Root: ThreadRoot,
3717
+ Viewport: ThreadViewport,
3718
+ Messages: ThreadMessages,
3719
+ ScrollToBottom: ThreadScrollToBottom,
3720
+ ViewportFooter: ThreadViewportFooter
3721
+ };
3722
+ var thread_default = Object.assign(Thread, exports11);
3723
+
3724
+ // src/ui/assistant-modal.tsx
3725
+ var import_jsx_runtime42 = require("react/jsx-runtime");
3726
+ var AssistantModal = (config) => {
3727
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(AssistantModalRoot, { config, children: [
3728
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(AssistantModalTrigger, {}),
3729
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(AssistantModalContent, { children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(thread_default, {}) })
3730
+ ] });
3731
+ };
3732
+ AssistantModal.displayName = "AssistantModal";
3733
+ var AssistantModalRoot = ({ config, ...props }) => {
3734
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(ThreadConfigProvider, { config, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(assistantModal_exports.Root, { ...props }) });
3735
+ };
3736
+ AssistantModalRoot.displayName = "AssistantModalRoot";
3737
+ var AssistantModalTrigger = (0, import_react65.forwardRef)((props, ref) => {
3738
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(AssistantModalAnchor, { children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(assistantModal_exports.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(AssistantModalButton, { ...props, ref }) }) });
3739
+ });
3740
+ AssistantModalTrigger.displayName = "AssistantModalTrigger";
3741
+ var AssistantModalAnchor = withDefaults(assistantModal_exports.Anchor, {
3742
+ className: "aui-root aui-modal-anchor"
3743
+ });
3744
+ AssistantModalAnchor.displayName = "AssistantModalAnchor";
3745
+ var ModalButtonStyled = withDefaults(TooltipIconButton, {
3746
+ variant: "default",
3747
+ className: "aui-modal-button"
3748
+ });
3749
+ var AssistantModalButton = (0, import_react65.forwardRef)(({ "data-state": state, ...rest }, ref) => {
3750
+ const {
3751
+ strings: {
3752
+ assistantModal: {
3753
+ open: {
3754
+ button: { tooltip: openTooltip = "Close Assistant" } = {}
3755
+ } = {},
3756
+ closed: {
3757
+ button: { tooltip: closedTooltip = "Open Assistant" } = {}
3758
+ } = {}
3759
+ } = {}
3760
+ } = {}
3761
+ } = useThreadConfig();
3762
+ const tooltip = state === "open" ? openTooltip : closedTooltip;
3763
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
3764
+ ModalButtonStyled,
3765
+ {
3766
+ side: "left",
3767
+ tooltip,
3768
+ "data-state": state,
3769
+ ...rest,
3770
+ ref,
3771
+ children: [
3772
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_lucide_react6.BotIcon, { "data-state": state, className: "aui-modal-button-closed-icon" }),
3773
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
3774
+ import_lucide_react6.ChevronDownIcon,
3775
+ {
3776
+ "data-state": state,
3777
+ className: "aui-modal-button-open-icon"
3778
+ }
3779
+ ),
3780
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: "aui-sr-only", children: tooltip })
3781
+ ]
3782
+ }
3783
+ );
3784
+ });
3785
+ AssistantModalButton.displayName = "AssistantModalButton";
3786
+ var AssistantModalContent = withDefaults(assistantModal_exports.Content, {
3787
+ className: "aui-root aui-modal-content",
3788
+ sideOffset: 16
3789
+ });
3790
+ AssistantModalContent.displayName = "AssistantModalContent";
3791
+ var exports12 = {
3792
+ Root: AssistantModalRoot,
3793
+ Trigger: AssistantModalTrigger,
3794
+ Content: AssistantModalContent
3795
+ };
3796
+ var assistant_modal_default = Object.assign(AssistantModal, exports12);
3797
+
2283
3798
  // src/internal.ts
2284
3799
  var internal_exports = {};
2285
3800
  __export(internal_exports, {
2286
3801
  BaseAssistantRuntime: () => BaseAssistantRuntime,
2287
3802
  MessageRepository: () => MessageRepository,
2288
3803
  ProxyConfigProvider: () => ProxyConfigProvider,
3804
+ TooltipIconButton: () => TooltipIconButton,
2289
3805
  useSmooth: () => useSmooth
2290
3806
  });
2291
3807
  // Annotate the CommonJS export names for ESM import in node:
2292
3808
  0 && (module.exports = {
2293
3809
  ActionBarPrimitive,
3810
+ AssistantActionBar,
3811
+ AssistantMessage,
3812
+ AssistantModal,
2294
3813
  AssistantModalPrimitive,
2295
3814
  AssistantRuntimeProvider,
3815
+ BranchPicker,
2296
3816
  BranchPickerPrimitive,
3817
+ Composer,
2297
3818
  ComposerPrimitive,
3819
+ ContentPart,
2298
3820
  ContentPartPrimitive,
3821
+ EditComposer,
2299
3822
  INTERNAL,
2300
3823
  MessagePrimitive,
3824
+ Thread,
3825
+ ThreadConfigProvider,
2301
3826
  ThreadPrimitive,
3827
+ ThreadWelcome,
3828
+ UserActionBar,
3829
+ UserMessage,
2302
3830
  makeAssistantTool,
2303
3831
  makeAssistantToolUI,
2304
3832
  useActionBarCopy,
@@ -2321,10 +3849,12 @@ __export(internal_exports, {
2321
3849
  useContentPartDisplay,
2322
3850
  useContentPartImage,
2323
3851
  useContentPartText,
3852
+ useEdgeRuntime,
2324
3853
  useLocalRuntime,
2325
3854
  useMessageContext,
2326
3855
  useMessageIf,
2327
3856
  useSwitchToNewThread,
3857
+ useThreadConfig,
2328
3858
  useThreadContext,
2329
3859
  useThreadEmpty,
2330
3860
  useThreadIf,