@assistant-ui/react 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __export = (target, all) => {
3
4
  for (var name in all)
@@ -15,14 +16,14 @@ import { createContext, useContext } from "react";
15
16
  var AssistantContext = createContext(
16
17
  null
17
18
  );
18
- var useAssistantContext = () => {
19
+ function useAssistantContext(options) {
19
20
  const context = useContext(AssistantContext);
20
- if (!context)
21
+ if (!options?.optional && !context)
21
22
  throw new Error(
22
23
  "This component must be used within an AssistantRuntimeProvider."
23
24
  );
24
25
  return context;
25
- };
26
+ }
26
27
 
27
28
  // src/context/stores/AssistantModelConfig.ts
28
29
  import { create } from "zustand";
@@ -127,14 +128,14 @@ import {
127
128
  // src/context/react/ThreadContext.ts
128
129
  import { createContext as createContext2, useContext as useContext2 } from "react";
129
130
  var ThreadContext = createContext2(null);
130
- var useThreadContext = () => {
131
+ function useThreadContext(options) {
131
132
  const context = useContext2(ThreadContext);
132
- if (!context)
133
+ if (!options?.optional && !context)
133
134
  throw new Error(
134
135
  "This component must be used within an AssistantRuntimeProvider."
135
136
  );
136
137
  return context;
137
- };
138
+ }
138
139
 
139
140
  // src/context/stores/Composer.ts
140
141
  import { create as create3 } from "zustand";
@@ -225,7 +226,7 @@ var makeThreadActionStore = (runtimeRef) => {
225
226
  startRun: (parentId) => runtimeRef.current.startRun(parentId),
226
227
  append: (message) => runtimeRef.current.append(message),
227
228
  cancelRun: () => runtimeRef.current.cancelRun(),
228
- addToolResult: (toolCallId, result) => runtimeRef.current.addToolResult(toolCallId, result)
229
+ addToolResult: (options) => runtimeRef.current.addToolResult(options)
229
230
  })
230
231
  );
231
232
  };
@@ -324,24 +325,24 @@ var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
324
325
  var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
325
326
 
326
327
  // src/context/react/ComposerContext.ts
327
- import { useContext as useContext4, useMemo } from "react";
328
+ import { useMemo } from "react";
328
329
 
329
330
  // src/context/react/MessageContext.ts
330
331
  import { createContext as createContext3, useContext as useContext3 } from "react";
331
332
  var MessageContext = createContext3(null);
332
- var useMessageContext = () => {
333
+ function useMessageContext(options) {
333
334
  const context = useContext3(MessageContext);
334
- if (!context)
335
+ if (!options?.optional && !context)
335
336
  throw new Error(
336
337
  "This component can only be used inside a component passed to <ThreadPrimitive.Messages components={...} />."
337
338
  );
338
339
  return context;
339
- };
340
+ }
340
341
 
341
342
  // src/context/react/ComposerContext.ts
342
343
  var useComposerContext = () => {
343
344
  const { useComposer } = useThreadContext();
344
- const { useEditComposer } = useContext4(MessageContext) ?? {};
345
+ const { useEditComposer } = useMessageContext({ optional: true }) ?? {};
345
346
  return useMemo(
346
347
  () => ({
347
348
  useComposer: useEditComposer ?? useComposer,
@@ -352,18 +353,18 @@ var useComposerContext = () => {
352
353
  };
353
354
 
354
355
  // src/context/react/ContentPartContext.ts
355
- import { createContext as createContext4, useContext as useContext5 } from "react";
356
+ import { createContext as createContext4, useContext as useContext4 } from "react";
356
357
  var ContentPartContext = createContext4(
357
358
  null
358
359
  );
359
- var useContentPartContext = () => {
360
- const context = useContext5(ContentPartContext);
361
- if (!context)
360
+ function useContentPartContext(options) {
361
+ const context = useContext4(ContentPartContext);
362
+ if (!options?.optional && !context)
362
363
  throw new Error(
363
364
  "This component can only be used inside a component passed to <MessagePrimitive.Content components={...} >."
364
365
  );
365
366
  return context;
366
- };
367
+ }
367
368
 
368
369
  // src/hooks/useAppendMessage.tsx
369
370
  import { useCallback as useCallback2 } from "react";
@@ -529,9 +530,10 @@ var useActionBarCopy = ({
529
530
  const { setIsCopied } = useMessageUtils.getState();
530
531
  const { isEditing, value: composerValue } = useEditComposer.getState();
531
532
  const valueToCopy = isEditing ? composerValue : getMessageText(message);
532
- navigator.clipboard.writeText(valueToCopy);
533
- setIsCopied(true);
534
- setTimeout(() => setIsCopied(false), copiedDuration);
533
+ navigator.clipboard.writeText(valueToCopy).then(() => {
534
+ setIsCopied(true);
535
+ setTimeout(() => setIsCopied(false), copiedDuration);
536
+ });
535
537
  }, [useMessage, useMessageUtils, useEditComposer, copiedDuration]);
536
538
  if (!hasCopyableContent) return null;
537
539
  return callback;
@@ -708,6 +710,7 @@ var useMessageIf = (props) => {
708
710
  if (props.hasBranches === true && branches.length < 2) return false;
709
711
  if (props.user && message.role !== "user") return false;
710
712
  if (props.assistant && message.role !== "assistant") return false;
713
+ if (props.system && message.role !== "system") return false;
711
714
  if (props.lastOrHover === true && !isHovering && !isLast) return false;
712
715
  if (props.copied === true && !isCopied) return false;
713
716
  if (props.copied === false && isCopied) return false;
@@ -1097,9 +1100,9 @@ var useIsHoveringRef = () => {
1097
1100
  );
1098
1101
  return useManagedRef(callbackRef);
1099
1102
  };
1100
- var MessagePrimitiveRoot = forwardRef6(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef15) => {
1103
+ var MessagePrimitiveRoot = forwardRef6(({ onMouseEnter, onMouseLeave, ...rest }, forwardRef28) => {
1101
1104
  const isHoveringRef = useIsHoveringRef();
1102
- const ref = useComposedRefs(forwardRef15, isHoveringRef);
1105
+ const ref = useComposedRefs(forwardRef28, isHoveringRef);
1103
1106
  return /* @__PURE__ */ jsx12(Primitive3.div, { ...rest, ref });
1104
1107
  });
1105
1108
  MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
@@ -1121,11 +1124,12 @@ import { memo as memo2 } from "react";
1121
1124
  import { useEffect as useEffect7, useState as useState4 } from "react";
1122
1125
  import { create as create9 } from "zustand";
1123
1126
  import { jsx as jsx13 } from "react/jsx-runtime";
1127
+ var DONE_STATUS = { type: "done" };
1124
1128
  var syncContentPart = ({ message }, useContentPart, partIndex) => {
1125
1129
  const part = message.content[partIndex];
1126
1130
  if (!part) return;
1127
- const messageStatus = message.role === "assistant" ? message.status : "done";
1128
- const status = partIndex === message.content.length - 1 ? messageStatus : "done";
1131
+ const messageStatus = message.role === "assistant" ? message.status : DONE_STATUS;
1132
+ const status = partIndex === message.content.length - 1 ? messageStatus : DONE_STATUS;
1129
1133
  const currentState = useContentPart.getState();
1130
1134
  if (currentState.part === part && currentState.status === status) return;
1131
1135
  useContentPart.setState(
@@ -1272,11 +1276,9 @@ var ContentPartPrimitiveDisplay = () => {
1272
1276
  ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
1273
1277
 
1274
1278
  // src/primitives/contentPart/ContentPartInProgress.tsx
1275
- var ContentPartPrimitiveInProgress = ({
1276
- children
1277
- }) => {
1279
+ var ContentPartPrimitiveInProgress = ({ children }) => {
1278
1280
  const { useContentPart } = useContentPartContext();
1279
- const isInProgress = useContentPart((c) => c.status === "in_progress");
1281
+ const isInProgress = useContentPart((c) => c.status.type === "in_progress");
1280
1282
  return isInProgress ? children : null;
1281
1283
  };
1282
1284
  ContentPartPrimitiveInProgress.displayName = "ContentPartPrimitive.InProgress";
@@ -1301,31 +1303,37 @@ var defaultComponents = {
1301
1303
  };
1302
1304
  var MessageContentPartComponent = ({
1303
1305
  components: {
1304
- Text = defaultComponents.Text,
1305
- Image = defaultComponents.Image,
1306
+ Text: Text2 = defaultComponents.Text,
1307
+ Image: Image2 = defaultComponents.Image,
1306
1308
  UI = defaultComponents.UI,
1307
- tools: { by_name = {}, Fallback = defaultComponents.tools.Fallback } = {}
1309
+ tools: { by_name = {}, Fallback: Fallback2 = defaultComponents.tools.Fallback } = {}
1308
1310
  } = {}
1309
1311
  }) => {
1310
1312
  const { useThreadActions } = useThreadContext();
1313
+ const { useMessage } = useMessageContext();
1311
1314
  const addToolResult = useThreadActions((t) => t.addToolResult);
1312
1315
  const { useContentPart } = useContentPartContext();
1313
1316
  const { part, status } = useContentPart();
1314
1317
  const type = part.type;
1315
1318
  switch (type) {
1316
1319
  case "text":
1317
- return /* @__PURE__ */ jsx16(Text, { part, status });
1320
+ return /* @__PURE__ */ jsx16(Text2, { part, status });
1318
1321
  case "image":
1319
- return /* @__PURE__ */ jsx16(Image, { part, status });
1322
+ return /* @__PURE__ */ jsx16(Image2, { part, status });
1320
1323
  case "ui":
1321
1324
  return /* @__PURE__ */ jsx16(UI, { part, status });
1322
1325
  case "tool-call": {
1323
- const Tool = by_name[part.toolName] || Fallback;
1324
- const addResult = (result) => addToolResult(part.toolCallId, result);
1326
+ const Tool = by_name[part.toolName] || Fallback2;
1327
+ const addResult = (result) => addToolResult({
1328
+ messageId: useMessage.getState().message.id,
1329
+ toolCallId: part.toolCallId,
1330
+ result
1331
+ });
1325
1332
  return /* @__PURE__ */ jsx16(Tool, { part, status, addResult });
1326
1333
  }
1327
1334
  default:
1328
- throw new Error(`Unknown content part type: ${type}`);
1335
+ const unhandledType = type;
1336
+ throw new Error(`Unknown content part type: ${unhandledType}`);
1329
1337
  }
1330
1338
  };
1331
1339
  var MessageContentPartImpl = ({
@@ -1817,29 +1825,32 @@ var MessageProvider = ({
1817
1825
 
1818
1826
  // src/primitives/thread/ThreadMessages.tsx
1819
1827
  import { jsx as jsx24, jsxs as jsxs3 } from "react/jsx-runtime";
1828
+ var DEFAULT_SYSTEM_MESSAGE = () => null;
1820
1829
  var getComponents = (components) => {
1821
1830
  return {
1822
1831
  EditComposer: components.EditComposer ?? components.UserMessage ?? components.Message,
1823
1832
  UserMessage: components.UserMessage ?? components.Message,
1824
- AssistantMessage: components.AssistantMessage ?? components.Message
1833
+ AssistantMessage: components.AssistantMessage ?? components.Message,
1834
+ SystemMessage: components.SystemMessage ?? DEFAULT_SYSTEM_MESSAGE
1825
1835
  };
1826
1836
  };
1827
1837
  var ThreadMessageImpl = ({
1828
1838
  messageIndex,
1829
1839
  components
1830
1840
  }) => {
1831
- const { UserMessage, EditComposer, AssistantMessage } = getComponents(components);
1841
+ const { UserMessage: UserMessage2, EditComposer: EditComposer2, AssistantMessage: AssistantMessage2, SystemMessage: SystemMessage2 } = getComponents(components);
1832
1842
  return /* @__PURE__ */ jsxs3(MessageProvider, { messageIndex, children: [
1833
1843
  /* @__PURE__ */ jsxs3(MessagePrimitiveIf, { user: true, children: [
1834
- /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage, {}) }),
1835
- /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer, {}) })
1844
+ /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: false, children: /* @__PURE__ */ jsx24(UserMessage2, {}) }),
1845
+ /* @__PURE__ */ jsx24(ComposerPrimitiveIf, { editing: true, children: /* @__PURE__ */ jsx24(EditComposer2, {}) })
1836
1846
  ] }),
1837
- /* @__PURE__ */ jsx24(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage, {}) })
1847
+ /* @__PURE__ */ jsx24(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ jsx24(AssistantMessage2, {}) }),
1848
+ /* @__PURE__ */ jsx24(MessagePrimitiveIf, { system: true, children: /* @__PURE__ */ jsx24(SystemMessage2, {}) })
1838
1849
  ] });
1839
1850
  };
1840
1851
  var ThreadMessage = memo3(
1841
1852
  ThreadMessageImpl,
1842
- (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
1853
+ (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
1843
1854
  );
1844
1855
  var ThreadPrimitiveMessagesImpl = ({
1845
1856
  components
@@ -1862,7 +1873,7 @@ var ThreadPrimitiveMessagesImpl = ({
1862
1873
  ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
1863
1874
  var ThreadPrimitiveMessages = memo3(
1864
1875
  ThreadPrimitiveMessagesImpl,
1865
- (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
1876
+ (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
1866
1877
  );
1867
1878
 
1868
1879
  // src/primitives/thread/ThreadScrollToBottom.tsx
@@ -1877,10 +1888,10 @@ var ThreadPrimitiveSuggestion = createActionButton(
1877
1888
  useThreadSuggestion
1878
1889
  );
1879
1890
 
1880
- // src/runtime/local/useLocalRuntime.tsx
1891
+ // src/runtimes/local/useLocalRuntime.tsx
1881
1892
  import { useInsertionEffect as useInsertionEffect3, useState as useState7 } from "react";
1882
1893
 
1883
- // src/runtime/utils/idUtils.tsx
1894
+ // src/utils/idUtils.tsx
1884
1895
  import { customAlphabet } from "nanoid/non-secure";
1885
1896
  var generateId = customAlphabet(
1886
1897
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
@@ -1889,7 +1900,7 @@ var generateId = customAlphabet(
1889
1900
  var optimisticPrefix = "__optimistic__";
1890
1901
  var generateOptimisticId = () => `${optimisticPrefix}${generateId()}`;
1891
1902
 
1892
- // src/runtime/utils/MessageRepository.tsx
1903
+ // src/runtimes/utils/MessageRepository.tsx
1893
1904
  var findHead = (message) => {
1894
1905
  if (message.next) return findHead(message.next);
1895
1906
  return message;
@@ -1963,6 +1974,17 @@ var MessageRepository = class {
1963
1974
  this.head = newItem;
1964
1975
  }
1965
1976
  }
1977
+ getMessage(messageId) {
1978
+ const message = this.messages.get(messageId);
1979
+ if (!message)
1980
+ throw new Error(
1981
+ "MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui."
1982
+ );
1983
+ return {
1984
+ parentId: message.prev?.current.id ?? null,
1985
+ message: message.current
1986
+ };
1987
+ }
1966
1988
  appendOptimisticMessage(parentId, message) {
1967
1989
  let optimisticId;
1968
1990
  do {
@@ -2040,7 +2062,7 @@ var MessageRepository = class {
2040
2062
  }
2041
2063
  };
2042
2064
 
2043
- // src/runtime/core/BaseAssistantRuntime.tsx
2065
+ // src/runtimes/core/BaseAssistantRuntime.tsx
2044
2066
  var BaseAssistantRuntime = class {
2045
2067
  constructor(_thread) {
2046
2068
  this._thread = _thread;
@@ -2081,8 +2103,8 @@ var BaseAssistantRuntime = class {
2081
2103
  cancelRun() {
2082
2104
  return this.thread.cancelRun();
2083
2105
  }
2084
- addToolResult(toolCallId, result) {
2085
- return this.thread.addToolResult(toolCallId, result);
2106
+ addToolResult(options) {
2107
+ return this.thread.addToolResult(options);
2086
2108
  }
2087
2109
  _subscriptions = /* @__PURE__ */ new Set();
2088
2110
  subscribe(callback) {
@@ -2097,7 +2119,7 @@ var BaseAssistantRuntime = class {
2097
2119
  }
2098
2120
  };
2099
2121
 
2100
- // src/runtime/local/LocalRuntime.tsx
2122
+ // src/runtimes/local/LocalRuntime.tsx
2101
2123
  var LocalRuntime = class extends BaseAssistantRuntime {
2102
2124
  _configProviders;
2103
2125
  constructor(adapter) {
@@ -2168,7 +2190,7 @@ var LocalThreadRuntime = class {
2168
2190
  const message = {
2169
2191
  id,
2170
2192
  role: "assistant",
2171
- status: "in_progress",
2193
+ status: { type: "in_progress" },
2172
2194
  content: [{ type: "text", text: "" }],
2173
2195
  createdAt: /* @__PURE__ */ new Date()
2174
2196
  };
@@ -2188,11 +2210,17 @@ var LocalThreadRuntime = class {
2188
2210
  config: mergeModelConfigs(this._configProviders),
2189
2211
  onUpdate: updateHandler
2190
2212
  });
2191
- updateHandler(result);
2192
- message.status = "done";
2213
+ if (result !== void 0) {
2214
+ updateHandler(result);
2215
+ }
2216
+ if (result.status?.type === "in_progress")
2217
+ throw new Error(
2218
+ "Unexpected in_progress status returned from ChatModelAdapter"
2219
+ );
2220
+ message.status = result.status ?? { type: "done" };
2193
2221
  this.repository.addOrUpdateMessage(parentId, { ...message });
2194
2222
  } catch (e) {
2195
- message.status = "error";
2223
+ message.status = { type: "error", error: e };
2196
2224
  this.repository.addOrUpdateMessage(parentId, { ...message });
2197
2225
  console.error(e);
2198
2226
  } finally {
@@ -2213,12 +2241,30 @@ var LocalThreadRuntime = class {
2213
2241
  this._subscriptions.add(callback);
2214
2242
  return () => this._subscriptions.delete(callback);
2215
2243
  }
2216
- addToolResult() {
2217
- throw new Error("LocalRuntime does not yet support adding tool results");
2244
+ addToolResult({ messageId, toolCallId, result }) {
2245
+ const { parentId, message } = this.repository.getMessage(messageId);
2246
+ if (message.role !== "assistant")
2247
+ throw new Error("Tried to add tool re^sult to non-assistant message");
2248
+ let found = false;
2249
+ const newContent = message.content.map((c) => {
2250
+ if (c.type !== "tool-call") return c;
2251
+ if (c.toolCallId !== toolCallId) return c;
2252
+ found = true;
2253
+ return {
2254
+ ...c,
2255
+ result
2256
+ };
2257
+ });
2258
+ if (!found)
2259
+ throw new Error("Tried to add tool result to non-existing tool call");
2260
+ this.repository.addOrUpdateMessage(parentId, {
2261
+ ...message,
2262
+ content: newContent
2263
+ });
2218
2264
  }
2219
2265
  };
2220
2266
 
2221
- // src/runtime/local/useLocalRuntime.tsx
2267
+ // src/runtimes/local/useLocalRuntime.tsx
2222
2268
  var useLocalRuntime = (adapter) => {
2223
2269
  const [runtime] = useState7(() => new LocalRuntime(adapter));
2224
2270
  useInsertionEffect3(() => {
@@ -2227,24 +2273,1495 @@ var useLocalRuntime = (adapter) => {
2227
2273
  return runtime;
2228
2274
  };
2229
2275
 
2276
+ // src/runtimes/edge/streams/assistantDecoderStream.ts
2277
+ function assistantDecoderStream() {
2278
+ let currentToolCall;
2279
+ return new TransformStream({
2280
+ transform(chunk, controller) {
2281
+ const [code, valueJson] = chunk.split(":");
2282
+ const value = JSON.parse(valueJson);
2283
+ if (currentToolCall && code !== "2" /* ToolCallArgsTextDelta */ && code !== "E" /* Error */) {
2284
+ controller.enqueue({
2285
+ type: "tool-call",
2286
+ toolCallType: "function",
2287
+ toolCallId: currentToolCall.id,
2288
+ toolName: currentToolCall.name,
2289
+ args: JSON.parse(currentToolCall.argsText)
2290
+ });
2291
+ currentToolCall = void 0;
2292
+ }
2293
+ switch (code) {
2294
+ case "0" /* TextDelta */: {
2295
+ controller.enqueue({
2296
+ type: "text-delta",
2297
+ textDelta: value
2298
+ });
2299
+ break;
2300
+ }
2301
+ case "1" /* ToolCallBegin */: {
2302
+ const { id, name } = JSON.parse(value);
2303
+ currentToolCall = { id, name, argsText: "" };
2304
+ break;
2305
+ }
2306
+ case "2" /* ToolCallArgsTextDelta */: {
2307
+ const delta = JSON.parse(value);
2308
+ currentToolCall.argsText += delta;
2309
+ controller.enqueue({
2310
+ type: "tool-call-delta",
2311
+ toolCallType: "function",
2312
+ toolCallId: currentToolCall.id,
2313
+ toolName: currentToolCall.name,
2314
+ argsTextDelta: delta
2315
+ });
2316
+ break;
2317
+ }
2318
+ case "F" /* Finish */: {
2319
+ controller.enqueue({
2320
+ type: "finish",
2321
+ ...JSON.parse(value)
2322
+ });
2323
+ break;
2324
+ }
2325
+ case "E" /* Error */: {
2326
+ controller.enqueue({
2327
+ type: "error",
2328
+ error: JSON.parse(value)
2329
+ });
2330
+ break;
2331
+ }
2332
+ default: {
2333
+ const unhandledType = code;
2334
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
2335
+ }
2336
+ }
2337
+ }
2338
+ });
2339
+ }
2340
+
2341
+ // src/runtimes/edge/streams/chunkByLineStream.ts
2342
+ function chunkByLineStream() {
2343
+ let buffer = "";
2344
+ return new TransformStream({
2345
+ transform(chunk, controller) {
2346
+ buffer += chunk;
2347
+ const lines = buffer.split("\n");
2348
+ for (let i = 0; i < lines.length - 1; i++) {
2349
+ controller.enqueue(lines[i]);
2350
+ }
2351
+ buffer = lines[lines.length - 1];
2352
+ },
2353
+ flush(controller) {
2354
+ if (buffer) {
2355
+ controller.enqueue(buffer);
2356
+ }
2357
+ }
2358
+ });
2359
+ }
2360
+
2361
+ // src/runtimes/edge/partial-json/parse-partial-json.ts
2362
+ import sjson from "secure-json-parse";
2363
+
2364
+ // src/runtimes/edge/partial-json/fix-json.ts
2365
+ function fixJson(input) {
2366
+ const stack = ["ROOT"];
2367
+ let lastValidIndex = -1;
2368
+ let literalStart = null;
2369
+ function processValueStart(char, i, swapState) {
2370
+ {
2371
+ switch (char) {
2372
+ case '"': {
2373
+ lastValidIndex = i;
2374
+ stack.pop();
2375
+ stack.push(swapState);
2376
+ stack.push("INSIDE_STRING");
2377
+ break;
2378
+ }
2379
+ case "f":
2380
+ case "t":
2381
+ case "n": {
2382
+ lastValidIndex = i;
2383
+ literalStart = i;
2384
+ stack.pop();
2385
+ stack.push(swapState);
2386
+ stack.push("INSIDE_LITERAL");
2387
+ break;
2388
+ }
2389
+ case "-": {
2390
+ stack.pop();
2391
+ stack.push(swapState);
2392
+ stack.push("INSIDE_NUMBER");
2393
+ break;
2394
+ }
2395
+ case "0":
2396
+ case "1":
2397
+ case "2":
2398
+ case "3":
2399
+ case "4":
2400
+ case "5":
2401
+ case "6":
2402
+ case "7":
2403
+ case "8":
2404
+ case "9": {
2405
+ lastValidIndex = i;
2406
+ stack.pop();
2407
+ stack.push(swapState);
2408
+ stack.push("INSIDE_NUMBER");
2409
+ break;
2410
+ }
2411
+ case "{": {
2412
+ lastValidIndex = i;
2413
+ stack.pop();
2414
+ stack.push(swapState);
2415
+ stack.push("INSIDE_OBJECT_START");
2416
+ break;
2417
+ }
2418
+ case "[": {
2419
+ lastValidIndex = i;
2420
+ stack.pop();
2421
+ stack.push(swapState);
2422
+ stack.push("INSIDE_ARRAY_START");
2423
+ break;
2424
+ }
2425
+ }
2426
+ }
2427
+ }
2428
+ function processAfterObjectValue(char, i) {
2429
+ switch (char) {
2430
+ case ",": {
2431
+ stack.pop();
2432
+ stack.push("INSIDE_OBJECT_AFTER_COMMA");
2433
+ break;
2434
+ }
2435
+ case "}": {
2436
+ lastValidIndex = i;
2437
+ stack.pop();
2438
+ break;
2439
+ }
2440
+ }
2441
+ }
2442
+ function processAfterArrayValue(char, i) {
2443
+ switch (char) {
2444
+ case ",": {
2445
+ stack.pop();
2446
+ stack.push("INSIDE_ARRAY_AFTER_COMMA");
2447
+ break;
2448
+ }
2449
+ case "]": {
2450
+ lastValidIndex = i;
2451
+ stack.pop();
2452
+ break;
2453
+ }
2454
+ }
2455
+ }
2456
+ for (let i = 0; i < input.length; i++) {
2457
+ const char = input[i];
2458
+ const currentState = stack[stack.length - 1];
2459
+ switch (currentState) {
2460
+ case "ROOT":
2461
+ processValueStart(char, i, "FINISH");
2462
+ break;
2463
+ case "INSIDE_OBJECT_START": {
2464
+ switch (char) {
2465
+ case '"': {
2466
+ stack.pop();
2467
+ stack.push("INSIDE_OBJECT_KEY");
2468
+ break;
2469
+ }
2470
+ case "}": {
2471
+ lastValidIndex = i;
2472
+ stack.pop();
2473
+ break;
2474
+ }
2475
+ }
2476
+ break;
2477
+ }
2478
+ case "INSIDE_OBJECT_AFTER_COMMA": {
2479
+ switch (char) {
2480
+ case '"': {
2481
+ stack.pop();
2482
+ stack.push("INSIDE_OBJECT_KEY");
2483
+ break;
2484
+ }
2485
+ }
2486
+ break;
2487
+ }
2488
+ case "INSIDE_OBJECT_KEY": {
2489
+ switch (char) {
2490
+ case '"': {
2491
+ stack.pop();
2492
+ stack.push("INSIDE_OBJECT_AFTER_KEY");
2493
+ break;
2494
+ }
2495
+ }
2496
+ break;
2497
+ }
2498
+ case "INSIDE_OBJECT_AFTER_KEY": {
2499
+ switch (char) {
2500
+ case ":": {
2501
+ stack.pop();
2502
+ stack.push("INSIDE_OBJECT_BEFORE_VALUE");
2503
+ break;
2504
+ }
2505
+ }
2506
+ break;
2507
+ }
2508
+ case "INSIDE_OBJECT_BEFORE_VALUE": {
2509
+ processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
2510
+ break;
2511
+ }
2512
+ case "INSIDE_OBJECT_AFTER_VALUE": {
2513
+ processAfterObjectValue(char, i);
2514
+ break;
2515
+ }
2516
+ case "INSIDE_STRING": {
2517
+ switch (char) {
2518
+ case '"': {
2519
+ stack.pop();
2520
+ lastValidIndex = i;
2521
+ break;
2522
+ }
2523
+ case "\\": {
2524
+ stack.push("INSIDE_STRING_ESCAPE");
2525
+ break;
2526
+ }
2527
+ default: {
2528
+ lastValidIndex = i;
2529
+ }
2530
+ }
2531
+ break;
2532
+ }
2533
+ case "INSIDE_ARRAY_START": {
2534
+ switch (char) {
2535
+ case "]": {
2536
+ lastValidIndex = i;
2537
+ stack.pop();
2538
+ break;
2539
+ }
2540
+ default: {
2541
+ lastValidIndex = i;
2542
+ processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
2543
+ break;
2544
+ }
2545
+ }
2546
+ break;
2547
+ }
2548
+ case "INSIDE_ARRAY_AFTER_VALUE": {
2549
+ switch (char) {
2550
+ case ",": {
2551
+ stack.pop();
2552
+ stack.push("INSIDE_ARRAY_AFTER_COMMA");
2553
+ break;
2554
+ }
2555
+ case "]": {
2556
+ lastValidIndex = i;
2557
+ stack.pop();
2558
+ break;
2559
+ }
2560
+ default: {
2561
+ lastValidIndex = i;
2562
+ break;
2563
+ }
2564
+ }
2565
+ break;
2566
+ }
2567
+ case "INSIDE_ARRAY_AFTER_COMMA": {
2568
+ processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
2569
+ break;
2570
+ }
2571
+ case "INSIDE_STRING_ESCAPE": {
2572
+ stack.pop();
2573
+ lastValidIndex = i;
2574
+ break;
2575
+ }
2576
+ case "INSIDE_NUMBER": {
2577
+ switch (char) {
2578
+ case "0":
2579
+ case "1":
2580
+ case "2":
2581
+ case "3":
2582
+ case "4":
2583
+ case "5":
2584
+ case "6":
2585
+ case "7":
2586
+ case "8":
2587
+ case "9": {
2588
+ lastValidIndex = i;
2589
+ break;
2590
+ }
2591
+ case "e":
2592
+ case "E":
2593
+ case "-":
2594
+ case ".": {
2595
+ break;
2596
+ }
2597
+ case ",": {
2598
+ stack.pop();
2599
+ if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
2600
+ processAfterArrayValue(char, i);
2601
+ }
2602
+ if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
2603
+ processAfterObjectValue(char, i);
2604
+ }
2605
+ break;
2606
+ }
2607
+ case "}": {
2608
+ stack.pop();
2609
+ if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
2610
+ processAfterObjectValue(char, i);
2611
+ }
2612
+ break;
2613
+ }
2614
+ case "]": {
2615
+ stack.pop();
2616
+ if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
2617
+ processAfterArrayValue(char, i);
2618
+ }
2619
+ break;
2620
+ }
2621
+ default: {
2622
+ stack.pop();
2623
+ break;
2624
+ }
2625
+ }
2626
+ break;
2627
+ }
2628
+ case "INSIDE_LITERAL": {
2629
+ const partialLiteral = input.substring(literalStart, i + 1);
2630
+ if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
2631
+ stack.pop();
2632
+ if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
2633
+ processAfterObjectValue(char, i);
2634
+ } else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
2635
+ processAfterArrayValue(char, i);
2636
+ }
2637
+ } else {
2638
+ lastValidIndex = i;
2639
+ }
2640
+ break;
2641
+ }
2642
+ }
2643
+ }
2644
+ let result = input.slice(0, lastValidIndex + 1);
2645
+ for (let i = stack.length - 1; i >= 0; i--) {
2646
+ const state = stack[i];
2647
+ switch (state) {
2648
+ case "INSIDE_STRING": {
2649
+ result += '"';
2650
+ break;
2651
+ }
2652
+ case "INSIDE_OBJECT_KEY":
2653
+ case "INSIDE_OBJECT_AFTER_KEY":
2654
+ case "INSIDE_OBJECT_AFTER_COMMA":
2655
+ case "INSIDE_OBJECT_START":
2656
+ case "INSIDE_OBJECT_BEFORE_VALUE":
2657
+ case "INSIDE_OBJECT_AFTER_VALUE": {
2658
+ result += "}";
2659
+ break;
2660
+ }
2661
+ case "INSIDE_ARRAY_START":
2662
+ case "INSIDE_ARRAY_AFTER_COMMA":
2663
+ case "INSIDE_ARRAY_AFTER_VALUE": {
2664
+ result += "]";
2665
+ break;
2666
+ }
2667
+ case "INSIDE_LITERAL": {
2668
+ const partialLiteral = input.substring(literalStart, input.length);
2669
+ if ("true".startsWith(partialLiteral)) {
2670
+ result += "true".slice(partialLiteral.length);
2671
+ } else if ("false".startsWith(partialLiteral)) {
2672
+ result += "false".slice(partialLiteral.length);
2673
+ } else if ("null".startsWith(partialLiteral)) {
2674
+ result += "null".slice(partialLiteral.length);
2675
+ }
2676
+ }
2677
+ }
2678
+ }
2679
+ return result;
2680
+ }
2681
+
2682
+ // src/runtimes/edge/partial-json/parse-partial-json.ts
2683
+ var parsePartialJson = (json) => {
2684
+ try {
2685
+ return sjson.parse(json);
2686
+ } catch {
2687
+ try {
2688
+ return sjson.parse(fixJson(json));
2689
+ } catch {
2690
+ return void 0;
2691
+ }
2692
+ }
2693
+ };
2694
+
2695
+ // src/runtimes/edge/streams/runResultStream.ts
2696
+ function runResultStream() {
2697
+ let message = {
2698
+ content: []
2699
+ };
2700
+ const currentToolCall = { toolCallId: "", argsText: "" };
2701
+ return new TransformStream({
2702
+ transform(chunk, controller) {
2703
+ const chunkType = chunk.type;
2704
+ switch (chunkType) {
2705
+ case "text-delta": {
2706
+ message = appendOrUpdateText(message, chunk.textDelta);
2707
+ controller.enqueue(message);
2708
+ break;
2709
+ }
2710
+ case "tool-call-delta": {
2711
+ const { toolCallId, toolName, argsTextDelta } = chunk;
2712
+ if (currentToolCall.toolCallId !== toolCallId) {
2713
+ currentToolCall.toolCallId = toolCallId;
2714
+ currentToolCall.argsText = argsTextDelta;
2715
+ } else {
2716
+ currentToolCall.argsText += argsTextDelta;
2717
+ }
2718
+ message = appendOrUpdateToolCall(
2719
+ message,
2720
+ toolCallId,
2721
+ toolName,
2722
+ parsePartialJson(currentToolCall.argsText)
2723
+ );
2724
+ controller.enqueue(message);
2725
+ break;
2726
+ }
2727
+ case "tool-call": {
2728
+ break;
2729
+ }
2730
+ case "tool-result": {
2731
+ message = appendOrUpdateToolResult(
2732
+ message,
2733
+ chunk.toolCallId,
2734
+ chunk.toolName,
2735
+ chunk.result
2736
+ );
2737
+ controller.enqueue(message);
2738
+ break;
2739
+ }
2740
+ case "finish": {
2741
+ message = appendOrUpdateFinish(message, chunk);
2742
+ controller.enqueue(message);
2743
+ break;
2744
+ }
2745
+ case "error": {
2746
+ throw chunk.error;
2747
+ }
2748
+ default: {
2749
+ const unhandledType = chunkType;
2750
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
2751
+ }
2752
+ }
2753
+ }
2754
+ });
2755
+ }
2756
+ var appendOrUpdateText = (message, textDelta) => {
2757
+ let contentParts = message.content;
2758
+ let contentPart = message.content.at(-1);
2759
+ if (contentPart?.type !== "text") {
2760
+ contentPart = { type: "text", text: textDelta };
2761
+ } else {
2762
+ contentParts = contentParts.slice(0, -1);
2763
+ contentPart = { type: "text", text: contentPart.text + textDelta };
2764
+ }
2765
+ return {
2766
+ ...message,
2767
+ content: contentParts.concat([contentPart])
2768
+ };
2769
+ };
2770
+ var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
2771
+ let contentParts = message.content;
2772
+ let contentPart = message.content.at(-1);
2773
+ if (contentPart?.type !== "tool-call" || contentPart.toolCallId !== toolCallId) {
2774
+ contentPart = {
2775
+ type: "tool-call",
2776
+ toolCallId,
2777
+ toolName,
2778
+ args
2779
+ };
2780
+ } else {
2781
+ contentParts = contentParts.slice(0, -1);
2782
+ contentPart = {
2783
+ ...contentPart,
2784
+ args
2785
+ };
2786
+ }
2787
+ return {
2788
+ ...message,
2789
+ content: contentParts.concat([contentPart])
2790
+ };
2791
+ };
2792
+ var appendOrUpdateToolResult = (message, toolCallId, toolName, result) => {
2793
+ let found = false;
2794
+ const newContentParts = message.content.map((part) => {
2795
+ if (part.type !== "tool-call" || part.toolCallId !== toolCallId)
2796
+ return part;
2797
+ found = true;
2798
+ if (part.toolName !== toolName)
2799
+ throw new Error(
2800
+ `Tool call ${toolCallId} found with tool name ${part.toolName}, but expected ${toolName}`
2801
+ );
2802
+ return {
2803
+ ...part,
2804
+ result
2805
+ };
2806
+ });
2807
+ if (!found)
2808
+ throw new Error(
2809
+ `Received tool result for unknown tool call "${toolName}" / "${toolCallId}". This is likely an internal bug in assistant-ui.`
2810
+ );
2811
+ return {
2812
+ ...message,
2813
+ content: newContentParts
2814
+ };
2815
+ };
2816
+ var appendOrUpdateFinish = (message, chunk) => {
2817
+ const { type, ...rest } = chunk;
2818
+ return {
2819
+ ...message,
2820
+ status: {
2821
+ type: "done",
2822
+ ...rest
2823
+ }
2824
+ };
2825
+ };
2826
+
2827
+ // src/runtimes/edge/useEdgeRuntime.ts
2828
+ import { useMemo as useMemo3 } from "react";
2829
+
2830
+ // src/runtimes/edge/streams/toolResultStream.ts
2831
+ import { z } from "zod";
2832
+ import sjson2 from "secure-json-parse";
2833
+ function toolResultStream(tools) {
2834
+ const toolCallExecutions = /* @__PURE__ */ new Map();
2835
+ return new TransformStream({
2836
+ transform(chunk, controller) {
2837
+ controller.enqueue(chunk);
2838
+ const chunkType = chunk.type;
2839
+ switch (chunkType) {
2840
+ case "tool-call": {
2841
+ const { toolCallId, toolCallType, toolName, args: argsText } = chunk;
2842
+ const tool = tools?.[toolName];
2843
+ if (!tool) return;
2844
+ const args = sjson2.parse(argsText);
2845
+ if (tool.parameters instanceof z.ZodType) {
2846
+ const result = tool.parameters.safeParse(args);
2847
+ if (!result.success) {
2848
+ controller.enqueue({
2849
+ type: "error",
2850
+ error: new Error("Invalid tool call arguments")
2851
+ });
2852
+ return;
2853
+ } else {
2854
+ toolCallExecutions.set(
2855
+ toolCallId,
2856
+ (async () => {
2857
+ try {
2858
+ const result2 = await tool.execute(args);
2859
+ controller.enqueue({
2860
+ type: "tool-result",
2861
+ toolCallType,
2862
+ toolCallId,
2863
+ toolName,
2864
+ result: result2
2865
+ });
2866
+ } catch (error) {
2867
+ controller.enqueue({
2868
+ type: "error",
2869
+ error
2870
+ });
2871
+ } finally {
2872
+ toolCallExecutions.delete(toolCallId);
2873
+ }
2874
+ })()
2875
+ );
2876
+ }
2877
+ }
2878
+ break;
2879
+ }
2880
+ case "text-delta":
2881
+ case "tool-call-delta":
2882
+ case "finish":
2883
+ case "error":
2884
+ break;
2885
+ default: {
2886
+ const unhandledType = chunkType;
2887
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
2888
+ }
2889
+ }
2890
+ },
2891
+ async flush() {
2892
+ await Promise.all(toolCallExecutions.values());
2893
+ }
2894
+ });
2895
+ }
2896
+
2897
+ // src/runtimes/edge/useEdgeRuntime.ts
2898
+ import { z as z2 } from "zod";
2899
+ import { zodToJsonSchema } from "zod-to-json-schema";
2900
+ function asAsyncIterable(source) {
2901
+ return {
2902
+ [Symbol.asyncIterator]: () => {
2903
+ const reader = source.getReader();
2904
+ return {
2905
+ async next() {
2906
+ const { done, value } = await reader.read();
2907
+ return done ? { done: true, value: void 0 } : { done: false, value };
2908
+ }
2909
+ };
2910
+ }
2911
+ };
2912
+ }
2913
+ var toSerializableTools = (tools) => {
2914
+ if (!tools) return [];
2915
+ return Object.entries(tools).map(([name, tool]) => ({
2916
+ type: "function",
2917
+ name,
2918
+ ...tool.description ? { description: tool.description } : void 0,
2919
+ parameters: tool.parameters instanceof z2.ZodType ? zodToJsonSchema(tool.parameters) : tool.parameters
2920
+ }));
2921
+ };
2922
+ var createEdgeChatAdapter = ({
2923
+ api
2924
+ }) => ({
2925
+ run: async ({ messages, abortSignal, config, onUpdate }) => {
2926
+ const result = await fetch(api, {
2927
+ method: "POST",
2928
+ headers: {
2929
+ "Content-Type": "application/json"
2930
+ },
2931
+ body: JSON.stringify({
2932
+ system: config.system,
2933
+ messages,
2934
+ tools: toSerializableTools(
2935
+ config.tools
2936
+ )
2937
+ }),
2938
+ signal: abortSignal
2939
+ });
2940
+ const stream = result.body.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(assistantDecoderStream()).pipeThrough(toolResultStream(config.tools)).pipeThrough(runResultStream());
2941
+ let update;
2942
+ for await (update of asAsyncIterable(stream)) {
2943
+ onUpdate(update);
2944
+ }
2945
+ if (update === void 0)
2946
+ throw new Error("No data received from Edge Runtime");
2947
+ return update;
2948
+ }
2949
+ });
2950
+ var useEdgeRuntime = (options) => {
2951
+ const adapter = useMemo3(() => createEdgeChatAdapter(options), [options]);
2952
+ return useLocalRuntime(adapter);
2953
+ };
2954
+
2955
+ // src/ui/thread-config.tsx
2956
+ import { createContext as createContext5, useContext as useContext5 } from "react";
2957
+ import { Fragment as Fragment3, jsx as jsx25 } from "react/jsx-runtime";
2958
+ var ThreadConfigContext = createContext5({});
2959
+ var useThreadConfig = () => {
2960
+ return useContext5(ThreadConfigContext);
2961
+ };
2962
+ var ThreadConfigProvider = ({
2963
+ children,
2964
+ config
2965
+ }) => {
2966
+ const assistant = useAssistantContext({ optional: true });
2967
+ const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ jsx25(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx25(Fragment3, { children });
2968
+ if (!config?.runtime) return configProvider;
2969
+ if (assistant) {
2970
+ throw new Error(
2971
+ "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
2972
+ );
2973
+ }
2974
+ return /* @__PURE__ */ jsx25(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
2975
+ };
2976
+ ThreadConfigProvider.displayName = "ThreadConfigProvider";
2977
+
2978
+ // src/ui/assistant-action-bar.tsx
2979
+ import { forwardRef as forwardRef18 } from "react";
2980
+ import { CheckIcon, CopyIcon, RefreshCwIcon } from "lucide-react";
2981
+
2982
+ // src/ui/base/tooltip-icon-button.tsx
2983
+ import { forwardRef as forwardRef17 } from "react";
2984
+
2985
+ // src/ui/base/tooltip.tsx
2986
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2987
+
2988
+ // src/ui/utils/withDefaults.tsx
2989
+ import {
2990
+ forwardRef as forwardRef15
2991
+ } from "react";
2992
+ import classNames from "classnames";
2993
+ import { jsx as jsx26 } from "react/jsx-runtime";
2994
+ var withDefaultProps = ({
2995
+ className,
2996
+ ...defaultProps
2997
+ }) => ({ className: classNameProp, ...props }) => {
2998
+ return {
2999
+ className: classNames(className, classNameProp),
3000
+ ...defaultProps,
3001
+ ...props
3002
+ };
3003
+ };
3004
+ var withDefaults = (Component, defaultProps) => {
3005
+ const getProps = withDefaultProps(defaultProps);
3006
+ const WithDefaults = forwardRef15(
3007
+ (props, ref) => {
3008
+ const ComponentAsAny = Component;
3009
+ return /* @__PURE__ */ jsx26(ComponentAsAny, { ...getProps(props), ref });
3010
+ }
3011
+ );
3012
+ WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
3013
+ return WithDefaults;
3014
+ };
3015
+
3016
+ // src/ui/base/tooltip.tsx
3017
+ import { jsx as jsx27 } from "react/jsx-runtime";
3018
+ var Tooltip = (props) => {
3019
+ return /* @__PURE__ */ jsx27(TooltipPrimitive.Provider, { children: /* @__PURE__ */ jsx27(TooltipPrimitive.Root, { ...props }) });
3020
+ };
3021
+ Tooltip.displayName = "Tooltip";
3022
+ var TooltipTrigger = TooltipPrimitive.Trigger;
3023
+ var TooltipContent = withDefaults(TooltipPrimitive.Content, {
3024
+ sideOffset: 4,
3025
+ className: "aui-tooltip-content"
3026
+ });
3027
+ TooltipContent.displayName = "TooltipContent";
3028
+
3029
+ // src/ui/base/button.tsx
3030
+ import { cva } from "class-variance-authority";
3031
+ import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
3032
+ import { forwardRef as forwardRef16 } from "react";
3033
+ import { jsx as jsx28 } from "react/jsx-runtime";
3034
+ var buttonVariants = cva("aui-button", {
3035
+ variants: {
3036
+ variant: {
3037
+ default: "aui-button-primary",
3038
+ outline: "aui-button-outline",
3039
+ ghost: "aui-button-ghost"
3040
+ },
3041
+ size: {
3042
+ default: "aui-button-medium",
3043
+ icon: "aui-button-icon"
3044
+ }
3045
+ },
3046
+ defaultVariants: {
3047
+ variant: "default",
3048
+ size: "default"
3049
+ }
3050
+ });
3051
+ var Button = forwardRef16(
3052
+ ({ className, variant, size, ...props }, ref) => {
3053
+ return /* @__PURE__ */ jsx28(
3054
+ Primitive11.button,
3055
+ {
3056
+ className: buttonVariants({ variant, size, className }),
3057
+ ...props,
3058
+ ref
3059
+ }
3060
+ );
3061
+ }
3062
+ );
3063
+ Button.displayName = "Button";
3064
+
3065
+ // src/ui/base/tooltip-icon-button.tsx
3066
+ import { jsx as jsx29, jsxs as jsxs4 } from "react/jsx-runtime";
3067
+ var TooltipIconButton = forwardRef17(({ children, tooltip, side = "bottom", ...rest }, ref) => {
3068
+ return /* @__PURE__ */ jsxs4(Tooltip, { children: [
3069
+ /* @__PURE__ */ jsx29(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs4(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
3070
+ children,
3071
+ /* @__PURE__ */ jsx29("span", { className: "aui-sr-only", children: tooltip })
3072
+ ] }) }),
3073
+ /* @__PURE__ */ jsx29(TooltipContent, { side, children: tooltip })
3074
+ ] });
3075
+ });
3076
+ TooltipIconButton.displayName = "TooltipIconButton";
3077
+
3078
+ // src/ui/assistant-action-bar.tsx
3079
+ import { jsx as jsx30, jsxs as jsxs5 } from "react/jsx-runtime";
3080
+ var useAllowCopy = () => {
3081
+ const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
3082
+ const { useThreadActions } = useThreadContext();
3083
+ const copySupported = useThreadActions((t) => t.capabilities.copy);
3084
+ return copySupported && allowCopy;
3085
+ };
3086
+ var useAllowReload = () => {
3087
+ const { assistantMessage: { allowReload = true } = {} } = useThreadConfig();
3088
+ const { useThreadActions } = useThreadContext();
3089
+ const reloadSupported = useThreadActions((t) => t.capabilities.reload);
3090
+ return reloadSupported && allowReload;
3091
+ };
3092
+ var AssistantActionBar = () => {
3093
+ const allowCopy = useAllowCopy();
3094
+ const allowReload = useAllowReload();
3095
+ if (!allowCopy && !allowReload) return null;
3096
+ return /* @__PURE__ */ jsxs5(
3097
+ AssistantActionBarRoot,
3098
+ {
3099
+ hideWhenRunning: true,
3100
+ autohide: "not-last",
3101
+ autohideFloat: "single-branch",
3102
+ children: [
3103
+ /* @__PURE__ */ jsx30(AssistantActionBarCopy, {}),
3104
+ /* @__PURE__ */ jsx30(AssistantActionBarReload, {})
3105
+ ]
3106
+ }
3107
+ );
3108
+ };
3109
+ AssistantActionBar.displayName = "AssistantActionBar";
3110
+ var AssistantActionBarRoot = withDefaults(actionBar_exports.Root, {
3111
+ className: "aui-assistant-action-bar-root"
3112
+ });
3113
+ AssistantActionBarRoot.displayName = "AssistantActionBarRoot";
3114
+ var AssistantActionBarCopy = forwardRef18((props, ref) => {
3115
+ const {
3116
+ strings: {
3117
+ assistantMessage: { reload: { tooltip = "Copy" } = {} } = {}
3118
+ } = {}
3119
+ } = useThreadConfig();
3120
+ const allowCopy = useAllowCopy();
3121
+ if (!allowCopy) return null;
3122
+ return /* @__PURE__ */ jsx30(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ jsxs5(TooltipIconButton, { tooltip, ...props, ref, children: [
3123
+ /* @__PURE__ */ jsx30(message_exports.If, { copied: true, children: /* @__PURE__ */ jsx30(CheckIcon, {}) }),
3124
+ /* @__PURE__ */ jsx30(message_exports.If, { copied: false, children: /* @__PURE__ */ jsx30(CopyIcon, {}) })
3125
+ ] }) });
3126
+ });
3127
+ AssistantActionBarCopy.displayName = "AssistantActionBarCopy";
3128
+ var AssistantActionBarReload = forwardRef18((props, ref) => {
3129
+ const {
3130
+ strings: {
3131
+ assistantMessage: { reload: { tooltip = "Refresh" } = {} } = {}
3132
+ } = {}
3133
+ } = useThreadConfig();
3134
+ const allowReload = useAllowReload();
3135
+ if (!allowReload) return null;
3136
+ return /* @__PURE__ */ jsx30(actionBar_exports.Reload, { asChild: true, children: /* @__PURE__ */ jsx30(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx30(RefreshCwIcon, {}) }) });
3137
+ });
3138
+ AssistantActionBarReload.displayName = "AssistantActionBarReload";
3139
+ var exports = {
3140
+ Root: AssistantActionBarRoot,
3141
+ Reload: AssistantActionBarReload,
3142
+ Copy: AssistantActionBarCopy
3143
+ };
3144
+ var assistant_action_bar_default = Object.assign(
3145
+ AssistantActionBar,
3146
+ exports
3147
+ );
3148
+
3149
+ // src/ui/assistant-message.tsx
3150
+ import { forwardRef as forwardRef20 } from "react";
3151
+
3152
+ // src/ui/branch-picker.tsx
3153
+ import { forwardRef as forwardRef19 } from "react";
3154
+ import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
3155
+ import { jsx as jsx31, jsxs as jsxs6 } from "react/jsx-runtime";
3156
+ var BranchPicker = () => {
3157
+ return /* @__PURE__ */ jsxs6(BranchPickerRoot, { hideWhenSingleBranch: true, children: [
3158
+ /* @__PURE__ */ jsx31(BranchPickerPrevious2, {}),
3159
+ /* @__PURE__ */ jsx31(BranchPickerState, {}),
3160
+ /* @__PURE__ */ jsx31(BranchPickerNext, {})
3161
+ ] });
3162
+ };
3163
+ BranchPicker.displayName = "BranchPicker";
3164
+ var BranchPickerRoot = withDefaults(branchPicker_exports.Root, {
3165
+ className: "aui-branch-picker-root"
3166
+ });
3167
+ BranchPickerRoot.displayName = "BranchPickerRoot";
3168
+ var BranchPickerPrevious2 = forwardRef19((props, ref) => {
3169
+ const {
3170
+ strings: {
3171
+ branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
3172
+ } = {}
3173
+ } = useThreadConfig();
3174
+ return /* @__PURE__ */ jsx31(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx31(ChevronLeftIcon, {}) }) });
3175
+ });
3176
+ BranchPickerPrevious2.displayName = "BranchPickerPrevious";
3177
+ var BranchPickerStateWrapper = withDefaults("span", {
3178
+ className: "aui-branch-picker-state"
3179
+ });
3180
+ var BranchPickerState = forwardRef19((props, ref) => {
3181
+ return /* @__PURE__ */ jsxs6(BranchPickerStateWrapper, { ...props, ref, children: [
3182
+ /* @__PURE__ */ jsx31(branchPicker_exports.Number, {}),
3183
+ " / ",
3184
+ /* @__PURE__ */ jsx31(branchPicker_exports.Count, {})
3185
+ ] });
3186
+ });
3187
+ BranchPickerState.displayName = "BranchPickerState";
3188
+ var BranchPickerNext = forwardRef19((props, ref) => {
3189
+ const {
3190
+ strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
3191
+ } = useThreadConfig();
3192
+ return /* @__PURE__ */ jsx31(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx31(ChevronRightIcon, {}) }) });
3193
+ });
3194
+ BranchPickerNext.displayName = "BranchPickerNext";
3195
+ var exports2 = {
3196
+ Root: BranchPickerRoot,
3197
+ Previous: BranchPickerPrevious2,
3198
+ Next: BranchPickerNext
3199
+ };
3200
+ var branch_picker_default = Object.assign(BranchPicker, exports2);
3201
+
3202
+ // src/ui/base/avatar.tsx
3203
+ import * as AvatarPrimitive from "@radix-ui/react-avatar";
3204
+ import { jsx as jsx32, jsxs as jsxs7 } from "react/jsx-runtime";
3205
+ var Avatar = ({ src, alt, fallback }) => {
3206
+ if (src == null && fallback == null) return null;
3207
+ return /* @__PURE__ */ jsxs7(AvatarRoot, { children: [
3208
+ src != null && /* @__PURE__ */ jsx32(AvatarImage, { src, alt }),
3209
+ fallback != null && /* @__PURE__ */ jsx32(AvatarFallback, { children: fallback })
3210
+ ] });
3211
+ };
3212
+ Avatar.displayName = "Avatar";
3213
+ var AvatarRoot = withDefaults(AvatarPrimitive.Root, {
3214
+ className: "aui-avatar-root"
3215
+ });
3216
+ AvatarRoot.displayName = "AvatarRoot";
3217
+ var AvatarImage = withDefaults(AvatarPrimitive.Image, {
3218
+ className: "aui-avatar-image"
3219
+ });
3220
+ AvatarImage.displayName = "AvatarImage";
3221
+ var AvatarFallback = withDefaults(AvatarPrimitive.Fallback, {
3222
+ className: "aui-avatar-fallback"
3223
+ });
3224
+ AvatarFallback.displayName = "AvatarFallback";
3225
+
3226
+ // src/ui/content-part.tsx
3227
+ import classNames2 from "classnames";
3228
+ import { jsx as jsx33 } from "react/jsx-runtime";
3229
+ var Text = ({ status }) => {
3230
+ return /* @__PURE__ */ jsx33(
3231
+ "p",
3232
+ {
3233
+ className: classNames2(
3234
+ "aui-text",
3235
+ status.type === "in_progress" && "aui-text-in-progress"
3236
+ ),
3237
+ children: /* @__PURE__ */ jsx33(contentPart_exports.Text, {})
3238
+ }
3239
+ );
3240
+ };
3241
+ var exports3 = { Text };
3242
+ var content_part_default = exports3;
3243
+
3244
+ // src/ui/assistant-message.tsx
3245
+ import { jsx as jsx34, jsxs as jsxs8 } from "react/jsx-runtime";
3246
+ var AssistantMessage = () => {
3247
+ return /* @__PURE__ */ jsxs8(AssistantMessageRoot, { children: [
3248
+ /* @__PURE__ */ jsx34(AssistantMessageAvatar, {}),
3249
+ /* @__PURE__ */ jsx34(AssistantMessageContent, {}),
3250
+ /* @__PURE__ */ jsx34(branch_picker_default, {}),
3251
+ /* @__PURE__ */ jsx34(assistant_action_bar_default, {})
3252
+ ] });
3253
+ };
3254
+ AssistantMessage.displayName = "AssistantMessage";
3255
+ var AssistantMessageAvatar = () => {
3256
+ const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
3257
+ return /* @__PURE__ */ jsx34(Avatar, { ...avatar });
3258
+ };
3259
+ var AssistantMessageRoot = withDefaults(message_exports.Root, {
3260
+ className: "aui-assistant-message-root"
3261
+ });
3262
+ AssistantMessageRoot.displayName = "AssistantMessageRoot";
3263
+ var AssistantMessageContentWrapper = withDefaults("div", {
3264
+ className: "aui-assistant-message-content"
3265
+ });
3266
+ var AssistantMessageContent = forwardRef20(({ components: componentsProp, ...rest }, ref) => {
3267
+ const { assistantMessage: { components = {} } = {} } = useThreadConfig();
3268
+ return /* @__PURE__ */ jsx34(AssistantMessageContentWrapper, { ...rest, ref, children: /* @__PURE__ */ jsx34(
3269
+ message_exports.Content,
3270
+ {
3271
+ components: {
3272
+ ...componentsProp,
3273
+ Text: componentsProp?.Text ?? components.Text ?? content_part_default.Text
3274
+ }
3275
+ }
3276
+ ) });
3277
+ });
3278
+ AssistantMessageContent.displayName = "AssistantMessageContent";
3279
+ var exports4 = {
3280
+ Root: AssistantMessageRoot,
3281
+ Avatar: AssistantMessageAvatar,
3282
+ Content: AssistantMessageContent
3283
+ };
3284
+ var assistant_message_default = Object.assign(
3285
+ AssistantMessage,
3286
+ exports4
3287
+ );
3288
+
3289
+ // src/ui/assistant-modal.tsx
3290
+ import { forwardRef as forwardRef27 } from "react";
3291
+ import { BotIcon, ChevronDownIcon } from "lucide-react";
3292
+
3293
+ // src/ui/thread.tsx
3294
+ import { forwardRef as forwardRef26 } from "react";
3295
+ import { ArrowDownIcon } from "lucide-react";
3296
+
3297
+ // src/ui/composer.tsx
3298
+ import { forwardRef as forwardRef21 } from "react";
3299
+ import { SendHorizonalIcon } from "lucide-react";
3300
+
3301
+ // src/ui/base/CircleStopIcon.tsx
3302
+ import { jsx as jsx35 } from "react/jsx-runtime";
3303
+ var CircleStopIcon = () => {
3304
+ return /* @__PURE__ */ jsx35(
3305
+ "svg",
3306
+ {
3307
+ xmlns: "http://www.w3.org/2000/svg",
3308
+ viewBox: "0 0 16 16",
3309
+ fill: "currentColor",
3310
+ children: /* @__PURE__ */ jsx35("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" })
3311
+ }
3312
+ );
3313
+ };
3314
+ CircleStopIcon.displayName = "CircleStopIcon";
3315
+
3316
+ // src/ui/composer.tsx
3317
+ import { Fragment as Fragment4, jsx as jsx36, jsxs as jsxs9 } from "react/jsx-runtime";
3318
+ var Composer = () => {
3319
+ return /* @__PURE__ */ jsxs9(ComposerRoot, { children: [
3320
+ /* @__PURE__ */ jsx36(ComposerInput, { autoFocus: true }),
3321
+ /* @__PURE__ */ jsx36(ComposerAction, {})
3322
+ ] });
3323
+ };
3324
+ Composer.displayName = "Composer";
3325
+ var ComposerRoot = withDefaults(composer_exports.Root, {
3326
+ className: "aui-composer-root"
3327
+ });
3328
+ ComposerRoot.displayName = "ComposerRoot";
3329
+ var ComposerInputStyled = withDefaults(composer_exports.Input, {
3330
+ rows: 1,
3331
+ autoFocus: true,
3332
+ className: "aui-composer-input"
3333
+ });
3334
+ var ComposerInput = forwardRef21(
3335
+ (props, ref) => {
3336
+ const {
3337
+ strings: {
3338
+ composer: { input: { placeholder = "Write a message..." } = {} } = {}
3339
+ } = {}
3340
+ } = useThreadConfig();
3341
+ return /* @__PURE__ */ jsx36(ComposerInputStyled, { placeholder, ...props, ref });
3342
+ }
3343
+ );
3344
+ ComposerInput.displayName = "ComposerInput";
3345
+ var useAllowCancel = () => {
3346
+ const { useThreadActions } = useThreadContext();
3347
+ const cancelSupported = useThreadActions((t) => t.capabilities.cancel);
3348
+ return cancelSupported;
3349
+ };
3350
+ var ComposerAction = () => {
3351
+ const allowCancel = useAllowCancel();
3352
+ if (!allowCancel) return /* @__PURE__ */ jsx36(ComposerSend, {});
3353
+ return /* @__PURE__ */ jsxs9(Fragment4, { children: [
3354
+ /* @__PURE__ */ jsx36(thread_exports.If, { running: false, children: /* @__PURE__ */ jsx36(ComposerSend, {}) }),
3355
+ /* @__PURE__ */ jsx36(thread_exports.If, { running: true, children: /* @__PURE__ */ jsx36(ComposerCancel, {}) })
3356
+ ] });
3357
+ };
3358
+ ComposerAction.displayName = "ComposerAction";
3359
+ var ComposerSendButton = withDefaults(TooltipIconButton, {
3360
+ variant: "default",
3361
+ className: "aui-composer-send"
3362
+ });
3363
+ var ComposerSend = forwardRef21((props, ref) => {
3364
+ const {
3365
+ strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
3366
+ } = useThreadConfig();
3367
+ return /* @__PURE__ */ jsx36(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerSendButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx36(SendHorizonalIcon, {}) }) });
3368
+ });
3369
+ ComposerSend.displayName = "ComposerSend";
3370
+ var ComposerCancelButton = withDefaults(TooltipIconButton, {
3371
+ variant: "default",
3372
+ className: "aui-composer-cancel"
3373
+ });
3374
+ var ComposerCancel = forwardRef21((props, ref) => {
3375
+ const {
3376
+ strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
3377
+ } = useThreadConfig();
3378
+ return /* @__PURE__ */ jsx36(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerCancelButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx36(CircleStopIcon, {}) }) });
3379
+ });
3380
+ ComposerCancel.displayName = "ComposerCancel";
3381
+ var exports5 = {
3382
+ Root: ComposerRoot,
3383
+ Input: ComposerInput,
3384
+ Action: ComposerAction,
3385
+ Send: ComposerSend,
3386
+ Cancel: ComposerCancel
3387
+ };
3388
+ var composer_default = Object.assign(Composer, exports5);
3389
+
3390
+ // src/ui/thread-welcome.tsx
3391
+ import { forwardRef as forwardRef22 } from "react";
3392
+ import { jsx as jsx37, jsxs as jsxs10 } from "react/jsx-runtime";
3393
+ var ThreadWelcome = () => {
3394
+ return /* @__PURE__ */ jsxs10(ThreadWelcomeRoot, { children: [
3395
+ /* @__PURE__ */ jsxs10(ThreadWelcomeCenter, { children: [
3396
+ /* @__PURE__ */ jsx37(ThreadWelcomeAvatar, {}),
3397
+ /* @__PURE__ */ jsx37(ThreadWelcomeMessage, {})
3398
+ ] }),
3399
+ /* @__PURE__ */ jsx37(ThreadWelcomeSuggestions, {})
3400
+ ] });
3401
+ };
3402
+ ThreadWelcome.displayName = "ThreadWelcome";
3403
+ var ThreadWelcomeRootStyled = withDefaults("div", {
3404
+ className: "aui-thread-welcome-root"
3405
+ });
3406
+ var ThreadWelcomeCenter = withDefaults("div", {
3407
+ className: "aui-thread-welcome-center"
3408
+ });
3409
+ var ThreadWelcomeRoot = forwardRef22(
3410
+ (props, ref) => {
3411
+ return /* @__PURE__ */ jsx37(thread_exports.Empty, { children: /* @__PURE__ */ jsx37(ThreadWelcomeRootStyled, { ...props, ref }) });
3412
+ }
3413
+ );
3414
+ ThreadWelcomeRoot.displayName = "ThreadWelcomeRoot";
3415
+ var ThreadWelcomeAvatar = () => {
3416
+ const { assistantAvatar: avatar = { fallback: "A" } } = useThreadConfig();
3417
+ return /* @__PURE__ */ jsx37(Avatar, { ...avatar });
3418
+ };
3419
+ var ThreadWelcomeMessageStyled = withDefaults("p", {
3420
+ className: "aui-thread-welcome-message"
3421
+ });
3422
+ var ThreadWelcomeMessage = forwardRef22(({ message: messageProp, ...rest }, ref) => {
3423
+ const { welcome: { message = "How can I help you today?" } = {} } = useThreadConfig();
3424
+ return /* @__PURE__ */ jsx37(ThreadWelcomeMessageStyled, { ...rest, ref, children: messageProp ?? message });
3425
+ });
3426
+ ThreadWelcomeMessage.displayName = "ThreadWelcomeMessage";
3427
+ var ThreadWelcomeSuggestionContainer = withDefaults("div", {
3428
+ className: "aui-thread-welcome-suggestion-container"
3429
+ });
3430
+ var ThreadWelcomeSuggestionStyled = withDefaults(thread_exports.Suggestion, {
3431
+ className: "aui-thread-welcome-suggestion"
3432
+ });
3433
+ var ThreadWelcomeSuggestion = ({
3434
+ suggestion: { text, prompt }
3435
+ }) => {
3436
+ return /* @__PURE__ */ jsx37(
3437
+ ThreadWelcomeSuggestionStyled,
3438
+ {
3439
+ prompt: prompt ?? text,
3440
+ method: "replace",
3441
+ autoSend: true,
3442
+ children: /* @__PURE__ */ jsx37("span", { className: "aui-thread-welcome-suggestion-text", children: text })
3443
+ }
3444
+ );
3445
+ };
3446
+ var ThreadWelcomeSuggestions = () => {
3447
+ const { welcome: { suggestions } = {} } = useThreadConfig();
3448
+ return /* @__PURE__ */ jsx37(ThreadWelcomeSuggestionContainer, { children: suggestions?.map((suggestion, idx) => {
3449
+ const key = `${suggestion.prompt}-${idx}`;
3450
+ return /* @__PURE__ */ jsx37(ThreadWelcomeSuggestion, { suggestion }, key);
3451
+ }) });
3452
+ };
3453
+ ThreadWelcomeSuggestions.displayName = "ThreadWelcomeSuggestions";
3454
+ var exports6 = {
3455
+ Root: ThreadWelcomeRoot,
3456
+ Center: ThreadWelcomeCenter,
3457
+ Avatar: ThreadWelcomeAvatar,
3458
+ Message: ThreadWelcomeMessage,
3459
+ Suggestions: ThreadWelcomeSuggestions,
3460
+ Suggestion: ThreadWelcomeSuggestion
3461
+ };
3462
+ var thread_welcome_default = Object.assign(ThreadWelcome, exports6);
3463
+
3464
+ // src/ui/user-message.tsx
3465
+ import { forwardRef as forwardRef24 } from "react";
3466
+
3467
+ // src/ui/user-action-bar.tsx
3468
+ import { forwardRef as forwardRef23 } from "react";
3469
+ import { PencilIcon } from "lucide-react";
3470
+ import { jsx as jsx38 } from "react/jsx-runtime";
3471
+ var useAllowEdit = () => {
3472
+ const { userMessage: { allowEdit = true } = {} } = useThreadConfig();
3473
+ const { useThreadActions } = useThreadContext();
3474
+ const editSupported = useThreadActions((t) => t.capabilities.edit);
3475
+ return editSupported && allowEdit;
3476
+ };
3477
+ var UserActionBar = () => {
3478
+ const allowEdit = useAllowEdit();
3479
+ if (!allowEdit) return null;
3480
+ return /* @__PURE__ */ jsx38(UserActionBarRoot, { hideWhenRunning: true, autohide: "not-last", children: /* @__PURE__ */ jsx38(UserActionBarEdit, {}) });
3481
+ };
3482
+ UserActionBar.displayName = "UserActionBar";
3483
+ var UserActionBarRoot = withDefaults(actionBar_exports.Root, {
3484
+ className: "aui-user-action-bar-root"
3485
+ });
3486
+ UserActionBarRoot.displayName = "UserActionBarRoot";
3487
+ var UserActionBarEdit = forwardRef23((props, ref) => {
3488
+ const {
3489
+ strings: { userMessage: { edit: { tooltip = "Edit" } = {} } = {} } = {}
3490
+ } = useThreadConfig();
3491
+ const allowEdit = useAllowEdit();
3492
+ if (!allowEdit) return null;
3493
+ return /* @__PURE__ */ jsx38(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx38(PencilIcon, {}) }) });
3494
+ });
3495
+ UserActionBarEdit.displayName = "UserActionBarEdit";
3496
+ var exports7 = {
3497
+ Root: UserActionBarRoot,
3498
+ Edit: UserActionBarEdit
3499
+ };
3500
+ var user_action_bar_default = Object.assign(UserActionBar, exports7);
3501
+
3502
+ // src/ui/user-message.tsx
3503
+ import { jsx as jsx39, jsxs as jsxs11 } from "react/jsx-runtime";
3504
+ var UserMessage = () => {
3505
+ return /* @__PURE__ */ jsxs11(UserMessageRoot, { children: [
3506
+ /* @__PURE__ */ jsx39(user_action_bar_default, {}),
3507
+ /* @__PURE__ */ jsx39(UserMessageContent, {}),
3508
+ /* @__PURE__ */ jsx39(branch_picker_default, {})
3509
+ ] });
3510
+ };
3511
+ UserMessage.displayName = "UserMessage";
3512
+ var UserMessageRoot = withDefaults(message_exports.Root, {
3513
+ className: "aui-user-message-root"
3514
+ });
3515
+ UserMessageRoot.displayName = "UserMessageRoot";
3516
+ var UserMessageContentWrapper = withDefaults("div", {
3517
+ className: "aui-user-message-content"
3518
+ });
3519
+ var UserMessageContent = forwardRef24(
3520
+ ({ components, ...props }, ref) => {
3521
+ return /* @__PURE__ */ jsx39(UserMessageContentWrapper, { ...props, ref, children: /* @__PURE__ */ jsx39(
3522
+ message_exports.Content,
3523
+ {
3524
+ components: {
3525
+ ...components,
3526
+ Text: components?.Text ?? content_part_default.Text
3527
+ }
3528
+ }
3529
+ ) });
3530
+ }
3531
+ );
3532
+ UserMessageContent.displayName = "UserMessageContent";
3533
+ var exports8 = {
3534
+ Root: UserMessageRoot,
3535
+ Content: UserMessageContent
3536
+ };
3537
+ var user_message_default = Object.assign(UserMessage, exports8);
3538
+
3539
+ // src/ui/edit-composer.tsx
3540
+ import { forwardRef as forwardRef25 } from "react";
3541
+ import { jsx as jsx40, jsxs as jsxs12 } from "react/jsx-runtime";
3542
+ var EditComposer = () => {
3543
+ return /* @__PURE__ */ jsxs12(EditComposerRoot, { children: [
3544
+ /* @__PURE__ */ jsx40(EditComposerInput, {}),
3545
+ /* @__PURE__ */ jsxs12(EditComposerFooter, { children: [
3546
+ /* @__PURE__ */ jsx40(EditComposerCancel, {}),
3547
+ /* @__PURE__ */ jsx40(EditComposerSend, {})
3548
+ ] })
3549
+ ] });
3550
+ };
3551
+ EditComposer.displayName = "EditComposer";
3552
+ var EditComposerRoot = withDefaults(composer_exports.Root, {
3553
+ className: "aui-edit-composer-root"
3554
+ });
3555
+ EditComposerRoot.displayName = "EditComposerRoot";
3556
+ var EditComposerInput = withDefaults(composer_exports.Input, {
3557
+ className: "aui-edit-composer-input"
3558
+ });
3559
+ EditComposerInput.displayName = "EditComposerInput";
3560
+ var EditComposerFooter = withDefaults("div", {
3561
+ className: "aui-edit-composer-footer"
3562
+ });
3563
+ EditComposerFooter.displayName = "EditComposerFooter";
3564
+ var EditComposerCancel = forwardRef25(
3565
+ (props, ref) => {
3566
+ const {
3567
+ strings: {
3568
+ editComposer: { cancel: { label = "Cancel" } = {} } = {}
3569
+ } = {}
3570
+ } = useThreadConfig();
3571
+ return /* @__PURE__ */ jsx40(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { variant: "ghost", ...props, ref, children: label }) });
3572
+ }
3573
+ );
3574
+ EditComposerCancel.displayName = "EditComposerCancel";
3575
+ var EditComposerSend = forwardRef25(
3576
+ (props, ref) => {
3577
+ const {
3578
+ strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
3579
+ } = useThreadConfig();
3580
+ return /* @__PURE__ */ jsx40(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { ...props, ref, children: label }) });
3581
+ }
3582
+ );
3583
+ EditComposerSend.displayName = "EditComposerSend";
3584
+ var exports9 = {
3585
+ Root: EditComposerRoot,
3586
+ Input: EditComposerInput,
3587
+ Footer: EditComposerFooter,
3588
+ Cancel: EditComposerCancel,
3589
+ Send: EditComposerSend
3590
+ };
3591
+ var edit_composer_default = Object.assign(EditComposer, exports9);
3592
+
3593
+ // src/ui/thread.tsx
3594
+ import { jsx as jsx41, jsxs as jsxs13 } from "react/jsx-runtime";
3595
+ var Thread = (config) => {
3596
+ return /* @__PURE__ */ jsx41(ThreadRoot, { config, children: /* @__PURE__ */ jsxs13(ThreadViewport, { children: [
3597
+ /* @__PURE__ */ jsx41(thread_welcome_default, {}),
3598
+ /* @__PURE__ */ jsx41(ThreadMessages, {}),
3599
+ /* @__PURE__ */ jsxs13(ThreadViewportFooter, { children: [
3600
+ /* @__PURE__ */ jsx41(ThreadScrollToBottom, {}),
3601
+ /* @__PURE__ */ jsx41(composer_default, {})
3602
+ ] })
3603
+ ] }) });
3604
+ };
3605
+ var ThreadRootStyled = withDefaults(thread_exports.Root, {
3606
+ className: "aui-root aui-thread-root"
3607
+ });
3608
+ var ThreadRoot = forwardRef26(
3609
+ ({ config, ...props }, ref) => {
3610
+ return /* @__PURE__ */ jsx41(ThreadConfigProvider, { config, children: /* @__PURE__ */ jsx41(ThreadRootStyled, { ...props, ref }) });
3611
+ }
3612
+ );
3613
+ ThreadRoot.displayName = "ThreadRoot";
3614
+ var ThreadViewport = withDefaults(thread_exports.Viewport, {
3615
+ className: "aui-thread-viewport"
3616
+ });
3617
+ ThreadViewport.displayName = "ThreadViewport";
3618
+ var ThreadViewportFooter = withDefaults("div", {
3619
+ className: "aui-thread-viewport-footer"
3620
+ });
3621
+ ThreadViewportFooter.displayName = "ThreadViewportFooter";
3622
+ var SystemMessage = () => null;
3623
+ var ThreadMessages = ({ components, ...rest }) => {
3624
+ return /* @__PURE__ */ jsx41(
3625
+ thread_exports.Messages,
3626
+ {
3627
+ components: {
3628
+ UserMessage: components?.UserMessage ?? user_message_default,
3629
+ EditComposer: components?.EditComposer ?? edit_composer_default,
3630
+ AssistantMessage: components?.AssistantMessage ?? assistant_message_default,
3631
+ SystemMessage: components?.SystemMessage ?? SystemMessage
3632
+ },
3633
+ ...rest
3634
+ }
3635
+ );
3636
+ };
3637
+ ThreadMessages.displayName = "ThreadMessages";
3638
+ var ThreadScrollToBottomIconButton = withDefaults(TooltipIconButton, {
3639
+ variant: "outline",
3640
+ className: "aui-thread-scroll-to-bottom"
3641
+ });
3642
+ var ThreadScrollToBottom = forwardRef26((props, ref) => {
3643
+ const {
3644
+ strings: {
3645
+ thread: { scrollToBottom: { tooltip = "Scroll to bottom" } = {} } = {}
3646
+ } = {}
3647
+ } = useThreadConfig();
3648
+ return /* @__PURE__ */ jsx41(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx41(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx41(ArrowDownIcon, {}) }) });
3649
+ });
3650
+ ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
3651
+ var exports10 = {
3652
+ Root: ThreadRoot,
3653
+ Viewport: ThreadViewport,
3654
+ Messages: ThreadMessages,
3655
+ ScrollToBottom: ThreadScrollToBottom,
3656
+ ViewportFooter: ThreadViewportFooter
3657
+ };
3658
+ var thread_default = Object.assign(Thread, exports10);
3659
+
3660
+ // src/ui/assistant-modal.tsx
3661
+ import { jsx as jsx42, jsxs as jsxs14 } from "react/jsx-runtime";
3662
+ var AssistantModal = (config) => {
3663
+ return /* @__PURE__ */ jsxs14(AssistantModalRoot, { config, children: [
3664
+ /* @__PURE__ */ jsx42(AssistantModalTrigger, {}),
3665
+ /* @__PURE__ */ jsx42(AssistantModalContent, { children: /* @__PURE__ */ jsx42(thread_default, {}) })
3666
+ ] });
3667
+ };
3668
+ AssistantModal.displayName = "AssistantModal";
3669
+ var AssistantModalRoot = ({ config, ...props }) => {
3670
+ return /* @__PURE__ */ jsx42(ThreadConfigProvider, { config, children: /* @__PURE__ */ jsx42(assistantModal_exports.Root, { ...props }) });
3671
+ };
3672
+ AssistantModalRoot.displayName = "AssistantModalRoot";
3673
+ var AssistantModalTrigger = forwardRef27((props, ref) => {
3674
+ return /* @__PURE__ */ jsx42(AssistantModalAnchor, { children: /* @__PURE__ */ jsx42(assistantModal_exports.Trigger, { asChild: true, children: /* @__PURE__ */ jsx42(AssistantModalButton, { ...props, ref }) }) });
3675
+ });
3676
+ AssistantModalTrigger.displayName = "AssistantModalTrigger";
3677
+ var AssistantModalAnchor = withDefaults(assistantModal_exports.Anchor, {
3678
+ className: "aui-root aui-modal-anchor"
3679
+ });
3680
+ AssistantModalAnchor.displayName = "AssistantModalAnchor";
3681
+ var ModalButtonStyled = withDefaults(TooltipIconButton, {
3682
+ variant: "default",
3683
+ className: "aui-modal-button"
3684
+ });
3685
+ var AssistantModalButton = forwardRef27(({ "data-state": state, ...rest }, ref) => {
3686
+ const {
3687
+ strings: {
3688
+ assistantModal: {
3689
+ open: {
3690
+ button: { tooltip: openTooltip = "Close Assistant" } = {}
3691
+ } = {},
3692
+ closed: {
3693
+ button: { tooltip: closedTooltip = "Open Assistant" } = {}
3694
+ } = {}
3695
+ } = {}
3696
+ } = {}
3697
+ } = useThreadConfig();
3698
+ const tooltip = state === "open" ? openTooltip : closedTooltip;
3699
+ return /* @__PURE__ */ jsxs14(
3700
+ ModalButtonStyled,
3701
+ {
3702
+ side: "left",
3703
+ tooltip,
3704
+ "data-state": state,
3705
+ ...rest,
3706
+ ref,
3707
+ children: [
3708
+ /* @__PURE__ */ jsx42(BotIcon, { "data-state": state, className: "aui-modal-button-closed-icon" }),
3709
+ /* @__PURE__ */ jsx42(
3710
+ ChevronDownIcon,
3711
+ {
3712
+ "data-state": state,
3713
+ className: "aui-modal-button-open-icon"
3714
+ }
3715
+ ),
3716
+ /* @__PURE__ */ jsx42("span", { className: "aui-sr-only", children: tooltip })
3717
+ ]
3718
+ }
3719
+ );
3720
+ });
3721
+ AssistantModalButton.displayName = "AssistantModalButton";
3722
+ var AssistantModalContent = withDefaults(assistantModal_exports.Content, {
3723
+ className: "aui-root aui-modal-content",
3724
+ sideOffset: 16
3725
+ });
3726
+ AssistantModalContent.displayName = "AssistantModalContent";
3727
+ var exports11 = {
3728
+ Root: AssistantModalRoot,
3729
+ Trigger: AssistantModalTrigger,
3730
+ Content: AssistantModalContent
3731
+ };
3732
+ var assistant_modal_default = Object.assign(AssistantModal, exports11);
3733
+
2230
3734
  // src/internal.ts
2231
3735
  var internal_exports = {};
2232
3736
  __export(internal_exports, {
2233
3737
  BaseAssistantRuntime: () => BaseAssistantRuntime,
2234
3738
  MessageRepository: () => MessageRepository,
2235
3739
  ProxyConfigProvider: () => ProxyConfigProvider,
3740
+ TooltipIconButton: () => TooltipIconButton,
2236
3741
  useSmooth: () => useSmooth
2237
3742
  });
2238
3743
  export {
2239
3744
  actionBar_exports as ActionBarPrimitive,
3745
+ assistant_action_bar_default as AssistantActionBar,
3746
+ assistant_message_default as AssistantMessage,
3747
+ assistant_modal_default as AssistantModal,
2240
3748
  assistantModal_exports as AssistantModalPrimitive,
2241
3749
  AssistantRuntimeProvider,
3750
+ branch_picker_default as BranchPicker,
2242
3751
  branchPicker_exports as BranchPickerPrimitive,
3752
+ composer_default as Composer,
2243
3753
  composer_exports as ComposerPrimitive,
3754
+ content_part_default as ContentPart,
2244
3755
  contentPart_exports as ContentPartPrimitive,
3756
+ edit_composer_default as EditComposer,
2245
3757
  internal_exports as INTERNAL,
2246
3758
  message_exports as MessagePrimitive,
3759
+ thread_default as Thread,
3760
+ ThreadConfigProvider,
2247
3761
  thread_exports as ThreadPrimitive,
3762
+ thread_welcome_default as ThreadWelcome,
3763
+ user_action_bar_default as UserActionBar,
3764
+ user_message_default as UserMessage,
2248
3765
  makeAssistantTool,
2249
3766
  makeAssistantToolUI,
2250
3767
  useActionBarCopy,
@@ -2267,10 +3784,12 @@ export {
2267
3784
  useContentPartDisplay,
2268
3785
  useContentPartImage,
2269
3786
  useContentPartText,
3787
+ useEdgeRuntime,
2270
3788
  useLocalRuntime,
2271
3789
  useMessageContext,
2272
3790
  useMessageIf,
2273
3791
  useSwitchToNewThread,
3792
+ useThreadConfig,
2274
3793
  useThreadContext,
2275
3794
  useThreadEmpty,
2276
3795
  useThreadIf,