@assistant-ui/react 0.4.2 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(src_exports, {
43
43
  ComposerPrimitive: () => composer_exports,
44
44
  ContentPart: () => content_part_default,
45
45
  ContentPartPrimitive: () => contentPart_exports,
46
+ EdgeChatAdapter: () => EdgeChatAdapter,
46
47
  EditComposer: () => edit_composer_default,
47
48
  INTERNAL: () => internal_exports,
48
49
  MessagePrimitive: () => message_exports,
@@ -52,8 +53,11 @@ __export(src_exports, {
52
53
  ThreadWelcome: () => thread_welcome_default,
53
54
  UserActionBar: () => user_action_bar_default,
54
55
  UserMessage: () => user_message_default,
56
+ fromCoreMessages: () => fromCoreMessages,
57
+ fromLanguageModelMessages: () => fromLanguageModelMessages,
55
58
  makeAssistantTool: () => makeAssistantTool,
56
59
  makeAssistantToolUI: () => makeAssistantToolUI,
60
+ toLanguageModelMessages: () => toLanguageModelMessages,
57
61
  useActionBarCopy: () => useActionBarCopy,
58
62
  useActionBarEdit: () => useActionBarEdit,
59
63
  useActionBarReload: () => useActionBarReload,
@@ -113,7 +117,7 @@ var import_zustand = require("zustand");
113
117
 
114
118
  // src/types/ModelConfigTypes.ts
115
119
  var mergeModelConfigs = (configSet) => {
116
- const configs = Array.from(configSet).map((c) => c()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
120
+ const configs = Array.from(configSet).map((c) => c.getModelConfig()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
117
121
  return configs.reduce((acc, config) => {
118
122
  if (config.system) {
119
123
  if (acc.system) {
@@ -302,7 +306,8 @@ var makeThreadActionStore = (runtimeRef) => {
302
306
  startRun: (parentId) => runtimeRef.current.startRun(parentId),
303
307
  append: (message) => runtimeRef.current.append(message),
304
308
  cancelRun: () => runtimeRef.current.cancelRun(),
305
- addToolResult: (options) => runtimeRef.current.addToolResult(options)
309
+ addToolResult: (options) => runtimeRef.current.addToolResult(options),
310
+ getRuntime: () => runtimeRef.current
306
311
  })
307
312
  );
308
313
  };
@@ -319,10 +324,7 @@ var ThreadProvider = ({
319
324
  children,
320
325
  runtime
321
326
  }) => {
322
- const runtimeRef = (0, import_react3.useRef)(runtime);
323
- (0, import_react3.useInsertionEffect)(() => {
324
- runtimeRef.current = runtime;
325
- });
327
+ const runtimeRef = (0, import_react3.useRef)(runtime.thread);
326
328
  const [context] = (0, import_react3.useState)(() => {
327
329
  const useThread = makeThreadStore(runtimeRef);
328
330
  const useThreadMessages = makeThreadMessagesStore(runtimeRef);
@@ -337,8 +339,16 @@ var ThreadProvider = ({
337
339
  useViewport
338
340
  };
339
341
  });
342
+ const thread = (0, import_react3.useSyncExternalStore)(
343
+ (0, import_react3.useCallback)((c) => runtime.subscribe(c), [runtime]),
344
+ () => runtime.thread,
345
+ () => runtime.thread
346
+ );
347
+ (0, import_react3.useInsertionEffect)(() => {
348
+ runtimeRef.current = thread;
349
+ });
340
350
  (0, import_react3.useEffect)(() => {
341
- const onRuntimeUpdate = () => {
351
+ const onThreadUpdate = () => {
342
352
  context.useThread.setState(
343
353
  Object.freeze({
344
354
  isRunning: runtimeRef.current.isRunning
@@ -347,20 +357,11 @@ var ThreadProvider = ({
347
357
  );
348
358
  context.useThreadMessages.setState(Object.freeze(runtimeRef.current.messages), true);
349
359
  };
350
- onRuntimeUpdate();
351
- return runtime.subscribe(onRuntimeUpdate);
352
- }, [context, runtime]);
353
- const subscribe = (0, import_react3.useCallback)(
354
- (c) => runtime.subscribe(c),
355
- [runtime]
356
- );
357
- const RuntimeSynchronizer = (0, import_react3.useSyncExternalStore)(
358
- subscribe,
359
- () => runtime.unstable_synchronizer,
360
- () => void 0
361
- );
360
+ onThreadUpdate();
361
+ return thread.subscribe(onThreadUpdate);
362
+ }, [context, thread]);
362
363
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ThreadContext.Provider, { value: context, children: [
363
- RuntimeSynchronizer && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RuntimeSynchronizer, {}),
364
+ thread.unstable_synchronizer && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(thread.unstable_synchronizer, {}),
364
365
  children
365
366
  ] });
366
367
  };
@@ -369,7 +370,8 @@ var ThreadProvider = ({
369
370
  var import_zustand8 = require("zustand");
370
371
  var makeAssistantActionsStore = (runtimeRef) => (0, import_zustand8.create)(
371
372
  () => Object.freeze({
372
- switchToThread: () => runtimeRef.current.switchToThread(null)
373
+ switchToThread: () => runtimeRef.current.switchToThread(null),
374
+ getRuntime: () => runtimeRef.current
373
375
  })
374
376
  );
375
377
 
@@ -386,10 +388,10 @@ var AssistantProvider = ({ children, runtime }) => {
386
388
  const useAssistantActions = makeAssistantActionsStore(runtimeRef);
387
389
  return { useModelConfig, useToolUIs, useAssistantActions };
388
390
  });
389
- const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
391
+ const getModelConfig = context.useModelConfig();
390
392
  (0, import_react4.useEffect)(() => {
391
- return runtime.registerModelConfigProvider(getModelCOnfig);
392
- }, [runtime, getModelCOnfig]);
393
+ return runtime.registerModelConfigProvider(getModelConfig);
394
+ }, [runtime, getModelConfig]);
393
395
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ThreadProvider, { runtime, children }) });
394
396
  };
395
397
 
@@ -499,7 +501,9 @@ var useAssistantTool = (tool) => {
499
501
  [tool.toolName]: rest
500
502
  }
501
503
  };
502
- const unsub1 = registerModelConfigProvider(() => config);
504
+ const unsub1 = registerModelConfigProvider({
505
+ getModelConfig: () => config
506
+ });
503
507
  const unsub2 = render ? setToolUI(toolName, render) : void 0;
504
508
  return () => {
505
509
  unsub1();
@@ -549,7 +553,7 @@ var useAssistantInstructions = (instruction) => {
549
553
  const config = {
550
554
  system: instruction
551
555
  };
552
- return registerModelConfigProvider(() => config);
556
+ return registerModelConfigProvider({ getModelConfig: () => config });
553
557
  }, [registerModelConfigProvider, instruction]);
554
558
  };
555
559
 
@@ -1298,6 +1302,9 @@ var TextStreamAnimator = class {
1298
1302
  };
1299
1303
  };
1300
1304
  var useSmooth = (text, smooth = false) => {
1305
+ const { useMessage } = useMessageContext();
1306
+ const id = useMessage((m) => m.message.id);
1307
+ const idRef = (0, import_react35.useRef)(id);
1301
1308
  const [displayedText, setDisplayedText] = (0, import_react35.useState)(text);
1302
1309
  const [animatorRef] = (0, import_react35.useState)(
1303
1310
  new TextStreamAnimator(text, setDisplayedText)
@@ -1307,7 +1314,8 @@ var useSmooth = (text, smooth = false) => {
1307
1314
  animatorRef.stop();
1308
1315
  return;
1309
1316
  }
1310
- if (!text.startsWith(animatorRef.targetText)) {
1317
+ if (idRef.current !== id || !text.startsWith(animatorRef.targetText)) {
1318
+ idRef.current = id;
1311
1319
  setDisplayedText(text);
1312
1320
  animatorRef.currentText = text;
1313
1321
  animatorRef.targetText = text;
@@ -1316,7 +1324,7 @@ var useSmooth = (text, smooth = false) => {
1316
1324
  }
1317
1325
  animatorRef.targetText = text;
1318
1326
  animatorRef.start();
1319
- }, [animatorRef, smooth, text]);
1327
+ }, [animatorRef, id, smooth, text]);
1320
1328
  (0, import_react35.useEffect)(() => {
1321
1329
  return () => {
1322
1330
  animatorRef.stop();
@@ -1718,14 +1726,11 @@ var useThreadViewportAutoScroll = ({
1718
1726
  }) => {
1719
1727
  const divRef = (0, import_react46.useRef)(null);
1720
1728
  const { useViewport } = useThreadContext();
1721
- const firstRenderRef = (0, import_react46.useRef)(true);
1722
1729
  const lastScrollTop = (0, import_react46.useRef)(0);
1723
1730
  const isScrollingToBottomRef = (0, import_react46.useRef)(false);
1724
- const scrollToBottom = () => {
1731
+ const scrollToBottom = (behavior) => {
1725
1732
  const div = divRef.current;
1726
1733
  if (!div || !autoScroll) return;
1727
- const behavior = firstRenderRef.current ? "instant" : "auto";
1728
- firstRenderRef.current = false;
1729
1734
  isScrollingToBottomRef.current = true;
1730
1735
  div.scrollTo({ top: div.scrollHeight, behavior });
1731
1736
  };
@@ -1736,7 +1741,9 @@ var useThreadViewportAutoScroll = ({
1736
1741
  const newIsAtBottom = div.scrollHeight - div.scrollTop <= div.clientHeight;
1737
1742
  if (!newIsAtBottom && lastScrollTop.current < div.scrollTop) {
1738
1743
  } else {
1739
- isScrollingToBottomRef.current = newIsAtBottom;
1744
+ if (newIsAtBottom) {
1745
+ isScrollingToBottomRef.current = false;
1746
+ }
1740
1747
  if (newIsAtBottom !== isAtBottom) {
1741
1748
  useViewport.setState({
1742
1749
  isAtBottom: newIsAtBottom
@@ -1746,11 +1753,10 @@ var useThreadViewportAutoScroll = ({
1746
1753
  lastScrollTop.current = div.scrollTop;
1747
1754
  };
1748
1755
  const resizeRef = useOnResizeContent(() => {
1749
- if (!isScrollingToBottomRef.current && !useViewport.getState().isAtBottom && !firstRenderRef.current) {
1750
- handleScroll();
1751
- } else {
1752
- scrollToBottom();
1756
+ if (isScrollingToBottomRef.current || useViewport.getState().isAtBottom) {
1757
+ scrollToBottom("instant");
1753
1758
  }
1759
+ handleScroll();
1754
1760
  });
1755
1761
  const scrollRef = useManagedRef((el) => {
1756
1762
  el.addEventListener("scroll", handleScroll);
@@ -1760,7 +1766,7 @@ var useThreadViewportAutoScroll = ({
1760
1766
  });
1761
1767
  const autoScrollRef = (0, import_react_compose_refs3.useComposedRefs)(resizeRef, scrollRef, divRef);
1762
1768
  useOnScrollToBottom(() => {
1763
- scrollToBottom();
1769
+ scrollToBottom("auto");
1764
1770
  });
1765
1771
  return autoScrollRef;
1766
1772
  };
@@ -1966,7 +1972,7 @@ var ThreadPrimitiveSuggestion = createActionButton(
1966
1972
  );
1967
1973
 
1968
1974
  // src/runtimes/local/useLocalRuntime.tsx
1969
- var import_react50 = require("react");
1975
+ var import_react53 = require("react");
1970
1976
 
1971
1977
  // src/utils/idUtils.tsx
1972
1978
  var import_non_secure = require("nanoid/non-secure");
@@ -2144,45 +2150,14 @@ var BaseAssistantRuntime = class {
2144
2150
  constructor(_thread) {
2145
2151
  this._thread = _thread;
2146
2152
  this._thread = _thread;
2147
- this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
2148
2153
  }
2149
- get capabilities() {
2150
- return this._thread.capabilities;
2151
- }
2152
- _unsubscribe;
2153
2154
  get thread() {
2154
2155
  return this._thread;
2155
2156
  }
2156
2157
  set thread(thread) {
2157
- this._unsubscribe();
2158
2158
  this._thread = thread;
2159
- this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
2160
2159
  this.subscriptionHandler();
2161
2160
  }
2162
- get messages() {
2163
- return this.thread.messages;
2164
- }
2165
- get isRunning() {
2166
- return this.thread.isRunning;
2167
- }
2168
- getBranches(messageId) {
2169
- return this.thread.getBranches(messageId);
2170
- }
2171
- switchToBranch(branchId) {
2172
- return this.thread.switchToBranch(branchId);
2173
- }
2174
- append(message) {
2175
- return this.thread.append(message);
2176
- }
2177
- startRun(parentId) {
2178
- return this.thread.startRun(parentId);
2179
- }
2180
- cancelRun() {
2181
- return this.thread.cancelRun();
2182
- }
2183
- addToolResult(options) {
2184
- return this.thread.addToolResult(options);
2185
- }
2186
2161
  _subscriptions = /* @__PURE__ */ new Set();
2187
2162
  subscribe(callback) {
2188
2163
  this._subscriptions.add(callback);
@@ -2191,32 +2166,133 @@ var BaseAssistantRuntime = class {
2191
2166
  subscriptionHandler = () => {
2192
2167
  for (const callback of this._subscriptions) callback();
2193
2168
  };
2194
- get unstable_synchronizer() {
2195
- return this.thread.unstable_synchronizer;
2196
- }
2197
2169
  };
2198
2170
 
2171
+ // src/internal.ts
2172
+ var internal_exports = {};
2173
+ __export(internal_exports, {
2174
+ BaseAssistantRuntime: () => BaseAssistantRuntime,
2175
+ MessageRepository: () => MessageRepository,
2176
+ ProxyConfigProvider: () => ProxyConfigProvider,
2177
+ TooltipIconButton: () => TooltipIconButton,
2178
+ generateId: () => generateId,
2179
+ useSmooth: () => useSmooth
2180
+ });
2181
+
2182
+ // src/ui/base/tooltip-icon-button.tsx
2183
+ var import_react52 = require("react");
2184
+
2185
+ // src/ui/base/tooltip.tsx
2186
+ var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip"));
2187
+
2188
+ // src/ui/utils/withDefaults.tsx
2189
+ var import_react50 = require("react");
2190
+ var import_classnames = __toESM(require("classnames"));
2191
+ var import_jsx_runtime25 = require("react/jsx-runtime");
2192
+ var withDefaultProps = ({
2193
+ className,
2194
+ ...defaultProps
2195
+ }) => ({ className: classNameProp, ...props }) => {
2196
+ return {
2197
+ className: (0, import_classnames.default)(className, classNameProp),
2198
+ ...defaultProps,
2199
+ ...props
2200
+ };
2201
+ };
2202
+ var withDefaults = (Component, defaultProps) => {
2203
+ const getProps = withDefaultProps(defaultProps);
2204
+ const WithDefaults = (0, import_react50.forwardRef)(
2205
+ (props, ref) => {
2206
+ const ComponentAsAny = Component;
2207
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ComponentAsAny, { ...getProps(props), ref });
2208
+ }
2209
+ );
2210
+ WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
2211
+ return WithDefaults;
2212
+ };
2213
+
2214
+ // src/ui/base/tooltip.tsx
2215
+ var import_jsx_runtime26 = require("react/jsx-runtime");
2216
+ var Tooltip = (props) => {
2217
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(TooltipPrimitive.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(TooltipPrimitive.Root, { ...props }) });
2218
+ };
2219
+ Tooltip.displayName = "Tooltip";
2220
+ var TooltipTrigger = TooltipPrimitive.Trigger;
2221
+ var TooltipContent = withDefaults(TooltipPrimitive.Content, {
2222
+ sideOffset: 4,
2223
+ className: "aui-tooltip-content"
2224
+ });
2225
+ TooltipContent.displayName = "TooltipContent";
2226
+
2227
+ // src/ui/base/button.tsx
2228
+ var import_class_variance_authority = require("class-variance-authority");
2229
+ var import_react_primitive11 = require("@radix-ui/react-primitive");
2230
+ var import_react51 = require("react");
2231
+ var import_jsx_runtime27 = require("react/jsx-runtime");
2232
+ var buttonVariants = (0, import_class_variance_authority.cva)("aui-button", {
2233
+ variants: {
2234
+ variant: {
2235
+ default: "aui-button-primary",
2236
+ outline: "aui-button-outline",
2237
+ ghost: "aui-button-ghost"
2238
+ },
2239
+ size: {
2240
+ default: "aui-button-medium",
2241
+ icon: "aui-button-icon"
2242
+ }
2243
+ },
2244
+ defaultVariants: {
2245
+ variant: "default",
2246
+ size: "default"
2247
+ }
2248
+ });
2249
+ var Button = (0, import_react51.forwardRef)(
2250
+ ({ className, variant, size, ...props }, ref) => {
2251
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
2252
+ import_react_primitive11.Primitive.button,
2253
+ {
2254
+ className: buttonVariants({ variant, size, className }),
2255
+ ...props,
2256
+ ref
2257
+ }
2258
+ );
2259
+ }
2260
+ );
2261
+ Button.displayName = "Button";
2262
+
2263
+ // src/ui/base/tooltip-icon-button.tsx
2264
+ var import_jsx_runtime28 = require("react/jsx-runtime");
2265
+ var TooltipIconButton = (0, import_react52.forwardRef)(({ children, tooltip, side = "bottom", ...rest }, ref) => {
2266
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(Tooltip, { children: [
2267
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
2268
+ children,
2269
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: "aui-sr-only", children: tooltip })
2270
+ ] }) }),
2271
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(TooltipContent, { side, children: tooltip })
2272
+ ] });
2273
+ });
2274
+ TooltipIconButton.displayName = "TooltipIconButton";
2275
+
2199
2276
  // src/runtimes/local/LocalRuntime.tsx
2200
2277
  var LocalRuntime = class extends BaseAssistantRuntime {
2201
- _configProviders;
2278
+ _proxyConfigProvider;
2202
2279
  constructor(adapter) {
2203
- const configProviders = /* @__PURE__ */ new Set();
2204
- super(new LocalThreadRuntime(configProviders, adapter));
2205
- this._configProviders = configProviders;
2280
+ const proxyConfigProvider = new ProxyConfigProvider();
2281
+ super(new LocalThreadRuntime(proxyConfigProvider, adapter));
2282
+ this._proxyConfigProvider = proxyConfigProvider;
2206
2283
  }
2207
2284
  set adapter(adapter) {
2208
2285
  this.thread.adapter = adapter;
2209
2286
  }
2210
2287
  registerModelConfigProvider(provider) {
2211
- this._configProviders.add(provider);
2212
- return () => this._configProviders.delete(provider);
2288
+ return this._proxyConfigProvider.registerModelConfigProvider(provider);
2213
2289
  }
2214
2290
  switchToThread(threadId) {
2215
2291
  if (threadId) {
2216
2292
  throw new Error("LocalRuntime does not yet support switching threads");
2217
2293
  }
2218
2294
  return this.thread = new LocalThreadRuntime(
2219
- this._configProviders,
2295
+ this._proxyConfigProvider,
2220
2296
  this.thread.adapter
2221
2297
  );
2222
2298
  }
@@ -2228,8 +2304,8 @@ var CAPABILITIES = Object.freeze({
2228
2304
  copy: true
2229
2305
  });
2230
2306
  var LocalThreadRuntime = class {
2231
- constructor(_configProviders, adapter) {
2232
- this._configProviders = _configProviders;
2307
+ constructor(configProvider, adapter) {
2308
+ this.configProvider = configProvider;
2233
2309
  this.adapter = adapter;
2234
2310
  }
2235
2311
  _subscriptions = /* @__PURE__ */ new Set();
@@ -2250,6 +2326,10 @@ var LocalThreadRuntime = class {
2250
2326
  this.notifySubscribers();
2251
2327
  }
2252
2328
  async append(message) {
2329
+ if (message.role !== "user")
2330
+ throw new Error(
2331
+ "Only appending user messages are supported in LocalRuntime. This is likely an internal bug in assistant-ui."
2332
+ );
2253
2333
  const userMessageId = generateId();
2254
2334
  const userMessage = {
2255
2335
  id: userMessageId,
@@ -2261,11 +2341,10 @@ var LocalThreadRuntime = class {
2261
2341
  await this.startRun(userMessageId);
2262
2342
  }
2263
2343
  async startRun(parentId) {
2264
- const id = generateId();
2265
2344
  this.repository.resetHead(parentId);
2266
2345
  const messages = this.repository.getMessages();
2267
2346
  const message = {
2268
- id,
2347
+ id: generateId(),
2269
2348
  role: "assistant",
2270
2349
  status: { type: "in_progress" },
2271
2350
  content: [{ type: "text", text: "" }],
@@ -2284,7 +2363,7 @@ var LocalThreadRuntime = class {
2284
2363
  const result = await this.adapter.run({
2285
2364
  messages,
2286
2365
  abortSignal: this.abortController.signal,
2287
- config: mergeModelConfigs(this._configProviders),
2366
+ config: this.configProvider.getModelConfig(),
2288
2367
  onUpdate: updateHandler
2289
2368
  });
2290
2369
  if (result !== void 0) {
@@ -2299,7 +2378,7 @@ var LocalThreadRuntime = class {
2299
2378
  } catch (e) {
2300
2379
  message.status = { type: "error", error: e };
2301
2380
  this.repository.addOrUpdateMessage(parentId, { ...message });
2302
- console.error(e);
2381
+ throw e;
2303
2382
  } finally {
2304
2383
  this.abortController = null;
2305
2384
  this.notifySubscribers();
@@ -2309,7 +2388,6 @@ var LocalThreadRuntime = class {
2309
2388
  if (!this.abortController) return;
2310
2389
  this.abortController.abort();
2311
2390
  this.abortController = null;
2312
- this.notifySubscribers();
2313
2391
  }
2314
2392
  notifySubscribers() {
2315
2393
  for (const callback of this._subscriptions) callback();
@@ -2321,7 +2399,7 @@ var LocalThreadRuntime = class {
2321
2399
  addToolResult({ messageId, toolCallId, result }) {
2322
2400
  const { parentId, message } = this.repository.getMessage(messageId);
2323
2401
  if (message.role !== "assistant")
2324
- throw new Error("Tried to add tool re^sult to non-assistant message");
2402
+ throw new Error("Tried to add tool result to non-assistant message");
2325
2403
  let found = false;
2326
2404
  const newContent = message.content.map((c) => {
2327
2405
  if (c.type !== "tool-call") return c;
@@ -2343,27 +2421,55 @@ var LocalThreadRuntime = class {
2343
2421
 
2344
2422
  // src/runtimes/local/useLocalRuntime.tsx
2345
2423
  var useLocalRuntime = (adapter) => {
2346
- const [runtime] = (0, import_react50.useState)(() => new LocalRuntime(adapter));
2347
- (0, import_react50.useInsertionEffect)(() => {
2424
+ const [runtime] = (0, import_react53.useState)(() => new LocalRuntime(adapter));
2425
+ (0, import_react53.useInsertionEffect)(() => {
2348
2426
  runtime.adapter = adapter;
2349
2427
  });
2350
2428
  return runtime;
2351
2429
  };
2352
2430
 
2431
+ // src/runtimes/edge/useEdgeRuntime.ts
2432
+ var import_react54 = require("react");
2433
+
2434
+ // src/runtimes/edge/converters/toCoreMessages.ts
2435
+ var toCoreMessages = (message) => {
2436
+ return message.map((message2) => {
2437
+ return {
2438
+ role: message2.role,
2439
+ content: message2.content.map((part) => {
2440
+ if (part.type === "ui") throw new Error("UI parts are not supported");
2441
+ return part;
2442
+ })
2443
+ };
2444
+ });
2445
+ };
2446
+
2447
+ // src/runtimes/edge/converters/toLanguageModelTools.ts
2448
+ var import_zod = require("zod");
2449
+ var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
2450
+ var toLanguageModelTools = (tools) => {
2451
+ if (!tools) return [];
2452
+ return Object.entries(tools).map(([name, tool]) => ({
2453
+ type: "function",
2454
+ name,
2455
+ ...tool.description ? { description: tool.description } : void 0,
2456
+ parameters: tool.parameters instanceof import_zod.z.ZodType ? (0, import_zod_to_json_schema.default)(tool.parameters) : tool.parameters
2457
+ }));
2458
+ };
2459
+
2353
2460
  // src/runtimes/edge/streams/assistantDecoderStream.ts
2354
2461
  function assistantDecoderStream() {
2355
2462
  let currentToolCall;
2356
2463
  return new TransformStream({
2357
2464
  transform(chunk, controller) {
2358
- const [code, valueJson] = chunk.split(":");
2359
- const value = JSON.parse(valueJson);
2465
+ const [code, value] = parseStreamPart(chunk);
2360
2466
  if (currentToolCall && code !== "2" /* ToolCallArgsTextDelta */ && code !== "E" /* Error */) {
2361
2467
  controller.enqueue({
2362
2468
  type: "tool-call",
2363
2469
  toolCallType: "function",
2364
2470
  toolCallId: currentToolCall.id,
2365
2471
  toolName: currentToolCall.name,
2366
- args: JSON.parse(currentToolCall.argsText)
2472
+ args: currentToolCall.argsText
2367
2473
  });
2368
2474
  currentToolCall = void 0;
2369
2475
  }
@@ -2376,12 +2482,12 @@ function assistantDecoderStream() {
2376
2482
  break;
2377
2483
  }
2378
2484
  case "1" /* ToolCallBegin */: {
2379
- const { id, name } = JSON.parse(value);
2485
+ const { id, name } = value;
2380
2486
  currentToolCall = { id, name, argsText: "" };
2381
2487
  break;
2382
2488
  }
2383
2489
  case "2" /* ToolCallArgsTextDelta */: {
2384
- const delta = JSON.parse(value);
2490
+ const delta = value;
2385
2491
  currentToolCall.argsText += delta;
2386
2492
  controller.enqueue({
2387
2493
  type: "tool-call-delta",
@@ -2395,14 +2501,14 @@ function assistantDecoderStream() {
2395
2501
  case "F" /* Finish */: {
2396
2502
  controller.enqueue({
2397
2503
  type: "finish",
2398
- ...JSON.parse(value)
2504
+ ...value
2399
2505
  });
2400
2506
  break;
2401
2507
  }
2402
2508
  case "E" /* Error */: {
2403
2509
  controller.enqueue({
2404
2510
  type: "error",
2405
- error: JSON.parse(value)
2511
+ error: value
2406
2512
  });
2407
2513
  break;
2408
2514
  }
@@ -2414,6 +2520,14 @@ function assistantDecoderStream() {
2414
2520
  }
2415
2521
  });
2416
2522
  }
2523
+ var parseStreamPart = (part) => {
2524
+ const index = part.indexOf(":");
2525
+ if (index === -1) throw new Error("Invalid stream part");
2526
+ return [
2527
+ part.slice(0, index),
2528
+ JSON.parse(part.slice(index + 1))
2529
+ ];
2530
+ };
2417
2531
 
2418
2532
  // src/runtimes/edge/streams/chunkByLineStream.ts
2419
2533
  function chunkByLineStream() {
@@ -2796,7 +2910,7 @@ function runResultStream() {
2796
2910
  message,
2797
2911
  toolCallId,
2798
2912
  toolName,
2799
- parsePartialJson(currentToolCall.argsText)
2913
+ currentToolCall.argsText
2800
2914
  );
2801
2915
  controller.enqueue(message);
2802
2916
  break;
@@ -2844,7 +2958,7 @@ var appendOrUpdateText = (message, textDelta) => {
2844
2958
  content: contentParts.concat([contentPart])
2845
2959
  };
2846
2960
  };
2847
- var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
2961
+ var appendOrUpdateToolCall = (message, toolCallId, toolName, argsText) => {
2848
2962
  let contentParts = message.content;
2849
2963
  let contentPart = message.content.at(-1);
2850
2964
  if (contentPart?.type !== "tool-call" || contentPart.toolCallId !== toolCallId) {
@@ -2852,13 +2966,15 @@ var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
2852
2966
  type: "tool-call",
2853
2967
  toolCallId,
2854
2968
  toolName,
2855
- args
2969
+ argsText,
2970
+ args: parsePartialJson(argsText)
2856
2971
  };
2857
2972
  } else {
2858
2973
  contentParts = contentParts.slice(0, -1);
2859
2974
  contentPart = {
2860
2975
  ...contentPart,
2861
- args
2976
+ argsText,
2977
+ args: parsePartialJson(argsText)
2862
2978
  };
2863
2979
  }
2864
2980
  return {
@@ -2901,11 +3017,8 @@ var appendOrUpdateFinish = (message, chunk) => {
2901
3017
  };
2902
3018
  };
2903
3019
 
2904
- // src/runtimes/edge/useEdgeRuntime.ts
2905
- var import_react51 = require("react");
2906
-
2907
3020
  // src/runtimes/edge/streams/toolResultStream.ts
2908
- var import_zod = require("zod");
3021
+ var import_zod2 = require("zod");
2909
3022
  var import_secure_json_parse2 = __toESM(require("secure-json-parse"));
2910
3023
  function toolResultStream(tools) {
2911
3024
  const toolCallExecutions = /* @__PURE__ */ new Map();
@@ -2917,9 +3030,9 @@ function toolResultStream(tools) {
2917
3030
  case "tool-call": {
2918
3031
  const { toolCallId, toolCallType, toolName, args: argsText } = chunk;
2919
3032
  const tool = tools?.[toolName];
2920
- if (!tool) return;
3033
+ if (!tool || !tool.execute) return;
2921
3034
  const args = import_secure_json_parse2.default.parse(argsText);
2922
- if (tool.parameters instanceof import_zod.z.ZodType) {
3035
+ if (tool.parameters instanceof import_zod2.z.ZodType) {
2923
3036
  const result = tool.parameters.safeParse(args);
2924
3037
  if (!result.success) {
2925
3038
  controller.enqueue({
@@ -2971,9 +3084,7 @@ function toolResultStream(tools) {
2971
3084
  });
2972
3085
  }
2973
3086
 
2974
- // src/runtimes/edge/useEdgeRuntime.ts
2975
- var import_zod2 = require("zod");
2976
- var import_zod_to_json_schema = require("zod-to-json-schema");
3087
+ // src/runtimes/edge/EdgeChatAdapter.ts
2977
3088
  function asAsyncIterable(source) {
2978
3089
  return {
2979
3090
  [Symbol.asyncIterator]: () => {
@@ -2987,28 +3098,20 @@ function asAsyncIterable(source) {
2987
3098
  }
2988
3099
  };
2989
3100
  }
2990
- var toSerializableTools = (tools) => {
2991
- if (!tools) return [];
2992
- return Object.entries(tools).map(([name, tool]) => ({
2993
- type: "function",
2994
- name,
2995
- ...tool.description ? { description: tool.description } : void 0,
2996
- parameters: tool.parameters instanceof import_zod2.z.ZodType ? (0, import_zod_to_json_schema.zodToJsonSchema)(tool.parameters) : tool.parameters
2997
- }));
2998
- };
2999
- var createEdgeChatAdapter = ({
3000
- api
3001
- }) => ({
3002
- run: async ({ messages, abortSignal, config, onUpdate }) => {
3003
- const result = await fetch(api, {
3101
+ var EdgeChatAdapter = class {
3102
+ constructor(options) {
3103
+ this.options = options;
3104
+ }
3105
+ async run({ messages, abortSignal, config, onUpdate }) {
3106
+ const result = await fetch(this.options.api, {
3004
3107
  method: "POST",
3005
3108
  headers: {
3006
3109
  "Content-Type": "application/json"
3007
3110
  },
3008
3111
  body: JSON.stringify({
3009
3112
  system: config.system,
3010
- messages,
3011
- tools: toSerializableTools(
3113
+ messages: toCoreMessages(messages),
3114
+ tools: toLanguageModelTools(
3012
3115
  config.tools
3013
3116
  )
3014
3117
  }),
@@ -3023,134 +3126,274 @@ var createEdgeChatAdapter = ({
3023
3126
  throw new Error("No data received from Edge Runtime");
3024
3127
  return update;
3025
3128
  }
3026
- });
3129
+ };
3130
+
3131
+ // src/runtimes/edge/useEdgeRuntime.ts
3027
3132
  var useEdgeRuntime = (options) => {
3028
- const adapter = (0, import_react51.useMemo)(() => createEdgeChatAdapter(options), [options]);
3133
+ const [adapter] = (0, import_react54.useState)(() => new EdgeChatAdapter(options));
3029
3134
  return useLocalRuntime(adapter);
3030
3135
  };
3031
3136
 
3137
+ // src/runtimes/edge/converters/toLanguageModelMessages.ts
3138
+ var assistantMessageSplitter = () => {
3139
+ const stash = [];
3140
+ let assistantMessage = {
3141
+ role: "assistant",
3142
+ content: []
3143
+ };
3144
+ let toolMessage = {
3145
+ role: "tool",
3146
+ content: []
3147
+ };
3148
+ return {
3149
+ addTextContentPart: (part) => {
3150
+ if (toolMessage.content.length > 0) {
3151
+ stash.push(assistantMessage);
3152
+ stash.push(toolMessage);
3153
+ assistantMessage = {
3154
+ role: "assistant",
3155
+ content: []
3156
+ };
3157
+ toolMessage = {
3158
+ role: "tool",
3159
+ content: []
3160
+ };
3161
+ }
3162
+ assistantMessage.content.push(part);
3163
+ },
3164
+ addToolCallPart: (part) => {
3165
+ assistantMessage.content.push({
3166
+ type: "tool-call",
3167
+ toolCallId: part.toolCallId,
3168
+ toolName: part.toolName,
3169
+ args: part.args
3170
+ });
3171
+ if (part.result) {
3172
+ toolMessage.content.push({
3173
+ type: "tool-result",
3174
+ toolCallId: part.toolCallId,
3175
+ toolName: part.toolName,
3176
+ result: part.result
3177
+ // isError
3178
+ });
3179
+ }
3180
+ },
3181
+ getMessages: () => {
3182
+ if (toolMessage.content.length > 0) {
3183
+ return [...stash, assistantMessage, toolMessage];
3184
+ }
3185
+ return [...stash, assistantMessage];
3186
+ }
3187
+ };
3188
+ };
3189
+ function toLanguageModelMessages(message) {
3190
+ return message.flatMap((message2) => {
3191
+ const role = message2.role;
3192
+ switch (role) {
3193
+ case "system": {
3194
+ return [{ role: "system", content: message2.content[0].text }];
3195
+ }
3196
+ case "user": {
3197
+ const msg = {
3198
+ role: "user",
3199
+ content: message2.content.map(
3200
+ (part) => {
3201
+ const type = part.type;
3202
+ switch (type) {
3203
+ case "text": {
3204
+ return part;
3205
+ }
3206
+ case "image": {
3207
+ return {
3208
+ type: "image",
3209
+ image: new URL(part.image)
3210
+ };
3211
+ }
3212
+ default: {
3213
+ const unhandledType = type;
3214
+ throw new Error(
3215
+ `Unspported content part type: ${unhandledType}`
3216
+ );
3217
+ }
3218
+ }
3219
+ }
3220
+ )
3221
+ };
3222
+ return [msg];
3223
+ }
3224
+ case "assistant": {
3225
+ const splitter = assistantMessageSplitter();
3226
+ for (const part of message2.content) {
3227
+ const type = part.type;
3228
+ switch (type) {
3229
+ case "text": {
3230
+ splitter.addTextContentPart(part);
3231
+ break;
3232
+ }
3233
+ case "tool-call": {
3234
+ splitter.addToolCallPart(part);
3235
+ break;
3236
+ }
3237
+ default: {
3238
+ const unhandledType = type;
3239
+ throw new Error(`Unhandled content part type: ${unhandledType}`);
3240
+ }
3241
+ }
3242
+ }
3243
+ return splitter.getMessages();
3244
+ }
3245
+ default: {
3246
+ const unhandledRole = role;
3247
+ throw new Error(`Unknown message role: ${unhandledRole}`);
3248
+ }
3249
+ }
3250
+ });
3251
+ }
3252
+
3253
+ // src/runtimes/edge/converters/fromLanguageModelMessages.ts
3254
+ var fromLanguageModelMessages = (lm, mergeRoundtrips) => {
3255
+ const messages = [];
3256
+ for (const lmMessage of lm) {
3257
+ const role = lmMessage.role;
3258
+ switch (role) {
3259
+ case "system": {
3260
+ messages.push({
3261
+ role: "system",
3262
+ content: [
3263
+ {
3264
+ type: "text",
3265
+ text: lmMessage.content
3266
+ }
3267
+ ]
3268
+ });
3269
+ break;
3270
+ }
3271
+ case "user": {
3272
+ messages.push({
3273
+ role: "user",
3274
+ content: lmMessage.content.map((part) => {
3275
+ const type = part.type;
3276
+ switch (type) {
3277
+ case "text": {
3278
+ return {
3279
+ type: "text",
3280
+ text: part.text
3281
+ };
3282
+ }
3283
+ case "image": {
3284
+ if (part.image instanceof URL) {
3285
+ return {
3286
+ type: "image",
3287
+ image: part.image.href
3288
+ };
3289
+ }
3290
+ throw new Error("Only images with URL data are supported");
3291
+ }
3292
+ default: {
3293
+ const unhandledType = type;
3294
+ throw new Error(`Unknown content part type: ${unhandledType}`);
3295
+ }
3296
+ }
3297
+ })
3298
+ });
3299
+ break;
3300
+ }
3301
+ case "assistant": {
3302
+ const newContent = lmMessage.content.map((part) => {
3303
+ if (part.type === "tool-call") {
3304
+ return {
3305
+ type: "tool-call",
3306
+ toolCallId: part.toolCallId,
3307
+ toolName: part.toolName,
3308
+ argsText: JSON.stringify(part.args),
3309
+ args: typeof part.args === "string" ? part.args : part.args
3310
+ };
3311
+ }
3312
+ return part;
3313
+ });
3314
+ if (mergeRoundtrips) {
3315
+ const previousMessage = messages[messages.length - 1];
3316
+ if (previousMessage?.role === "assistant") {
3317
+ previousMessage.content.push(...newContent);
3318
+ break;
3319
+ }
3320
+ }
3321
+ messages.push({
3322
+ role: "assistant",
3323
+ content: newContent
3324
+ });
3325
+ break;
3326
+ }
3327
+ case "tool": {
3328
+ const previousMessage = messages[messages.length - 1];
3329
+ if (previousMessage?.role !== "assistant")
3330
+ throw new Error(
3331
+ "A tool message must be preceded by an assistant message."
3332
+ );
3333
+ for (const tool of lmMessage.content) {
3334
+ const toolCall = previousMessage.content.find(
3335
+ (c) => c.type === "tool-call" && c.toolCallId === tool.toolCallId
3336
+ );
3337
+ if (!toolCall)
3338
+ throw new Error("Received tool result for an unknown tool call.");
3339
+ if (toolCall.toolName !== tool.toolName)
3340
+ throw new Error("Tool call name mismatch.");
3341
+ toolCall.result = tool.result;
3342
+ if (tool.isError) {
3343
+ toolCall.isError = true;
3344
+ }
3345
+ }
3346
+ break;
3347
+ }
3348
+ default: {
3349
+ const unhandledRole = role;
3350
+ throw new Error(`Unknown message role: ${unhandledRole}`);
3351
+ }
3352
+ }
3353
+ }
3354
+ return messages;
3355
+ };
3356
+
3357
+ // src/runtimes/edge/converters/fromCoreMessage.ts
3358
+ var fromCoreMessages = (message) => {
3359
+ return message.map((message2) => {
3360
+ return {
3361
+ ...message2,
3362
+ id: generateId(),
3363
+ createdAt: /* @__PURE__ */ new Date(),
3364
+ ...message2.role === "assistant" ? {
3365
+ status: { type: "done" }
3366
+ } : void 0
3367
+ };
3368
+ });
3369
+ };
3370
+
3032
3371
  // src/ui/thread-config.tsx
3033
- var import_react52 = require("react");
3034
- var import_jsx_runtime25 = require("react/jsx-runtime");
3035
- var ThreadConfigContext = (0, import_react52.createContext)({});
3372
+ var import_react55 = require("react");
3373
+ var import_jsx_runtime29 = require("react/jsx-runtime");
3374
+ var ThreadConfigContext = (0, import_react55.createContext)({});
3036
3375
  var useThreadConfig = () => {
3037
- return (0, import_react52.useContext)(ThreadConfigContext);
3376
+ return (0, import_react55.useContext)(ThreadConfigContext);
3038
3377
  };
3039
3378
  var ThreadConfigProvider = ({
3040
3379
  children,
3041
3380
  config
3042
3381
  }) => {
3043
3382
  const assistant = useAssistantContext({ optional: true });
3044
- 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 });
3383
+ const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_jsx_runtime29.Fragment, { children });
3045
3384
  if (!config?.runtime) return configProvider;
3046
3385
  if (assistant) {
3047
3386
  throw new Error(
3048
3387
  "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
3049
3388
  );
3050
3389
  }
3051
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
3390
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
3052
3391
  };
3053
3392
  ThreadConfigProvider.displayName = "ThreadConfigProvider";
3054
3393
 
3055
3394
  // src/ui/assistant-action-bar.tsx
3056
3395
  var import_react56 = require("react");
3057
3396
  var import_lucide_react = require("lucide-react");
3058
-
3059
- // src/ui/base/tooltip-icon-button.tsx
3060
- var import_react55 = require("react");
3061
-
3062
- // src/ui/base/tooltip.tsx
3063
- var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip"));
3064
-
3065
- // src/ui/utils/withDefaults.tsx
3066
- var import_react53 = require("react");
3067
- var import_classnames = __toESM(require("classnames"));
3068
- var import_jsx_runtime26 = require("react/jsx-runtime");
3069
- var withDefaultProps = ({
3070
- className,
3071
- ...defaultProps
3072
- }) => ({ className: classNameProp, ...props }) => {
3073
- return {
3074
- className: (0, import_classnames.default)(className, classNameProp),
3075
- ...defaultProps,
3076
- ...props
3077
- };
3078
- };
3079
- var withDefaults = (Component, defaultProps) => {
3080
- const getProps = withDefaultProps(defaultProps);
3081
- const WithDefaults = (0, import_react53.forwardRef)(
3082
- (props, ref) => {
3083
- const ComponentAsAny = Component;
3084
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ComponentAsAny, { ...getProps(props), ref });
3085
- }
3086
- );
3087
- WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
3088
- return WithDefaults;
3089
- };
3090
-
3091
- // src/ui/base/tooltip.tsx
3092
- var import_jsx_runtime27 = require("react/jsx-runtime");
3093
- var Tooltip = (props) => {
3094
- return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(TooltipPrimitive.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(TooltipPrimitive.Root, { ...props }) });
3095
- };
3096
- Tooltip.displayName = "Tooltip";
3097
- var TooltipTrigger = TooltipPrimitive.Trigger;
3098
- var TooltipContent = withDefaults(TooltipPrimitive.Content, {
3099
- sideOffset: 4,
3100
- className: "aui-tooltip-content"
3101
- });
3102
- TooltipContent.displayName = "TooltipContent";
3103
-
3104
- // src/ui/base/button.tsx
3105
- var import_class_variance_authority = require("class-variance-authority");
3106
- var import_react_primitive11 = require("@radix-ui/react-primitive");
3107
- var import_react54 = require("react");
3108
- var import_jsx_runtime28 = require("react/jsx-runtime");
3109
- var buttonVariants = (0, import_class_variance_authority.cva)("aui-button", {
3110
- variants: {
3111
- variant: {
3112
- default: "aui-button-primary",
3113
- outline: "aui-button-outline",
3114
- ghost: "aui-button-ghost"
3115
- },
3116
- size: {
3117
- default: "aui-button-medium",
3118
- icon: "aui-button-icon"
3119
- }
3120
- },
3121
- defaultVariants: {
3122
- variant: "default",
3123
- size: "default"
3124
- }
3125
- });
3126
- var Button = (0, import_react54.forwardRef)(
3127
- ({ className, variant, size, ...props }, ref) => {
3128
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3129
- import_react_primitive11.Primitive.button,
3130
- {
3131
- className: buttonVariants({ variant, size, className }),
3132
- ...props,
3133
- ref
3134
- }
3135
- );
3136
- }
3137
- );
3138
- Button.displayName = "Button";
3139
-
3140
- // src/ui/base/tooltip-icon-button.tsx
3141
- var import_jsx_runtime29 = require("react/jsx-runtime");
3142
- var TooltipIconButton = (0, import_react55.forwardRef)(({ children, tooltip, side = "bottom", ...rest }, ref) => {
3143
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(Tooltip, { children: [
3144
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
3145
- children,
3146
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { className: "aui-sr-only", children: tooltip })
3147
- ] }) }),
3148
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(TooltipContent, { side, children: tooltip })
3149
- ] });
3150
- });
3151
- TooltipIconButton.displayName = "TooltipIconButton";
3152
-
3153
- // src/ui/assistant-action-bar.tsx
3154
3397
  var import_jsx_runtime30 = require("react/jsx-runtime");
3155
3398
  var useAllowCopy = () => {
3156
3399
  const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
@@ -3194,10 +3437,10 @@ var AssistantActionBarCopy = (0, import_react56.forwardRef)((props, ref) => {
3194
3437
  } = useThreadConfig();
3195
3438
  const allowCopy = useAllowCopy();
3196
3439
  if (!allowCopy) return null;
3197
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(TooltipIconButton, { tooltip, ...props, ref, children: [
3440
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
3198
3441
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(message_exports.If, { copied: true, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_lucide_react.CheckIcon, {}) }),
3199
3442
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(message_exports.If, { copied: false, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_lucide_react.CopyIcon, {}) })
3200
- ] }) });
3443
+ ] }) }) });
3201
3444
  });
3202
3445
  AssistantActionBarCopy.displayName = "AssistantActionBarCopy";
3203
3446
  var AssistantActionBarReload = (0, import_react56.forwardRef)((props, ref) => {
@@ -3246,7 +3489,7 @@ var BranchPickerPrevious2 = (0, import_react57.forwardRef)((props, ref) => {
3246
3489
  branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
3247
3490
  } = {}
3248
3491
  } = useThreadConfig();
3249
- 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, {}) }) });
3492
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_lucide_react2.ChevronLeftIcon, {}) }) });
3250
3493
  });
3251
3494
  BranchPickerPrevious2.displayName = "BranchPickerPrevious";
3252
3495
  var BranchPickerStateWrapper = withDefaults("span", {
@@ -3264,7 +3507,7 @@ var BranchPickerNext = (0, import_react57.forwardRef)((props, ref) => {
3264
3507
  const {
3265
3508
  strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
3266
3509
  } = useThreadConfig();
3267
- 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, {}) }) });
3510
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_lucide_react2.ChevronRightIcon, {}) }) });
3268
3511
  });
3269
3512
  BranchPickerNext.displayName = "BranchPickerNext";
3270
3513
  var exports3 = {
@@ -3439,7 +3682,7 @@ var ComposerSend = (0, import_react59.forwardRef)((props, ref) => {
3439
3682
  const {
3440
3683
  strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
3441
3684
  } = useThreadConfig();
3442
- 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, {}) }) });
3685
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerSendButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_lucide_react3.SendHorizontalIcon, {}) }) });
3443
3686
  });
3444
3687
  ComposerSend.displayName = "ComposerSend";
3445
3688
  var ComposerCancelButton = withDefaults(TooltipIconButton, {
@@ -3450,7 +3693,7 @@ var ComposerCancel = (0, import_react59.forwardRef)((props, ref) => {
3450
3693
  const {
3451
3694
  strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
3452
3695
  } = useThreadConfig();
3453
- 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, {}) }) });
3696
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ComposerCancelButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(CircleStopIcon, {}) }) });
3454
3697
  });
3455
3698
  ComposerCancel.displayName = "ComposerCancel";
3456
3699
  var exports6 = {
@@ -3565,7 +3808,7 @@ var UserActionBarEdit = (0, import_react61.forwardRef)((props, ref) => {
3565
3808
  } = useThreadConfig();
3566
3809
  const allowEdit = useAllowEdit();
3567
3810
  if (!allowEdit) return null;
3568
- 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, {}) }) });
3811
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_lucide_react4.PencilIcon, {}) }) });
3569
3812
  });
3570
3813
  UserActionBarEdit.displayName = "UserActionBarEdit";
3571
3814
  var exports8 = {
@@ -3643,7 +3886,7 @@ var EditComposerCancel = (0, import_react63.forwardRef)(
3643
3886
  editComposer: { cancel: { label = "Cancel" } = {} } = {}
3644
3887
  } = {}
3645
3888
  } = useThreadConfig();
3646
- 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 }) });
3889
+ 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: props.children ?? label }) });
3647
3890
  }
3648
3891
  );
3649
3892
  EditComposerCancel.displayName = "EditComposerCancel";
@@ -3652,7 +3895,7 @@ var EditComposerSend = (0, import_react63.forwardRef)(
3652
3895
  const {
3653
3896
  strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
3654
3897
  } = useThreadConfig();
3655
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Button, { ...props, ref, children: label }) });
3898
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Button, { ...props, ref, children: props.children ?? label }) });
3656
3899
  }
3657
3900
  );
3658
3901
  EditComposerSend.displayName = "EditComposerSend";
@@ -3720,7 +3963,10 @@ var ThreadScrollToBottom = (0, import_react64.forwardRef)((props, ref) => {
3720
3963
  thread: { scrollToBottom: { tooltip = "Scroll to bottom" } = {} } = {}
3721
3964
  } = {}
3722
3965
  } = useThreadConfig();
3723
- 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, {}) }) });
3966
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: [
3967
+ "|",
3968
+ props.children ?? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_lucide_react5.ArrowDownIcon, {})
3969
+ ] }) });
3724
3970
  });
3725
3971
  ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
3726
3972
  var exports11 = {
@@ -3771,7 +4017,7 @@ var AssistantModalButton = (0, import_react65.forwardRef)(({ "data-state": state
3771
4017
  } = {}
3772
4018
  } = useThreadConfig();
3773
4019
  const tooltip = state === "open" ? openTooltip : closedTooltip;
3774
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
4020
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
3775
4021
  ModalButtonStyled,
3776
4022
  {
3777
4023
  side: "left",
@@ -3779,17 +4025,22 @@ var AssistantModalButton = (0, import_react65.forwardRef)(({ "data-state": state
3779
4025
  "data-state": state,
3780
4026
  ...rest,
3781
4027
  ref,
3782
- children: [
3783
- /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_lucide_react6.BotIcon, { "data-state": state, className: "aui-modal-button-closed-icon" }),
4028
+ children: rest.children ?? /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_jsx_runtime42.Fragment, { children: [
4029
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4030
+ import_lucide_react6.BotIcon,
4031
+ {
4032
+ "data-state": state,
4033
+ className: "aui-modal-button-closed-icon"
4034
+ }
4035
+ ),
3784
4036
  /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
3785
4037
  import_lucide_react6.ChevronDownIcon,
3786
4038
  {
3787
4039
  "data-state": state,
3788
4040
  className: "aui-modal-button-open-icon"
3789
4041
  }
3790
- ),
3791
- /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: "aui-sr-only", children: tooltip })
3792
- ]
4042
+ )
4043
+ ] })
3793
4044
  }
3794
4045
  );
3795
4046
  });
@@ -3805,16 +4056,6 @@ var exports12 = {
3805
4056
  Content: AssistantModalContent
3806
4057
  };
3807
4058
  var assistant_modal_default = Object.assign(AssistantModal, exports12);
3808
-
3809
- // src/internal.ts
3810
- var internal_exports = {};
3811
- __export(internal_exports, {
3812
- BaseAssistantRuntime: () => BaseAssistantRuntime,
3813
- MessageRepository: () => MessageRepository,
3814
- ProxyConfigProvider: () => ProxyConfigProvider,
3815
- TooltipIconButton: () => TooltipIconButton,
3816
- useSmooth: () => useSmooth
3817
- });
3818
4059
  // Annotate the CommonJS export names for ESM import in node:
3819
4060
  0 && (module.exports = {
3820
4061
  ActionBarPrimitive,
@@ -3829,6 +4070,7 @@ __export(internal_exports, {
3829
4070
  ComposerPrimitive,
3830
4071
  ContentPart,
3831
4072
  ContentPartPrimitive,
4073
+ EdgeChatAdapter,
3832
4074
  EditComposer,
3833
4075
  INTERNAL,
3834
4076
  MessagePrimitive,
@@ -3838,8 +4080,11 @@ __export(internal_exports, {
3838
4080
  ThreadWelcome,
3839
4081
  UserActionBar,
3840
4082
  UserMessage,
4083
+ fromCoreMessages,
4084
+ fromLanguageModelMessages,
3841
4085
  makeAssistantTool,
3842
4086
  makeAssistantToolUI,
4087
+ toLanguageModelMessages,
3843
4088
  useActionBarCopy,
3844
4089
  useActionBarEdit,
3845
4090
  useActionBarReload,