@assistant-ui/react 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -30,7 +30,7 @@ import { create } from "zustand";
30
30
 
31
31
  // src/types/ModelConfigTypes.ts
32
32
  var mergeModelConfigs = (configSet) => {
33
- const configs = Array.from(configSet).map((c) => c()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
33
+ const configs = Array.from(configSet).map((c) => c.getModelConfig()).sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
34
34
  return configs.reduce((acc, config) => {
35
35
  if (config.system) {
36
36
  if (acc.system) {
@@ -226,7 +226,8 @@ var makeThreadActionStore = (runtimeRef) => {
226
226
  startRun: (parentId) => runtimeRef.current.startRun(parentId),
227
227
  append: (message) => runtimeRef.current.append(message),
228
228
  cancelRun: () => runtimeRef.current.cancelRun(),
229
- addToolResult: (options) => runtimeRef.current.addToolResult(options)
229
+ addToolResult: (options) => runtimeRef.current.addToolResult(options),
230
+ getRuntime: () => runtimeRef.current
230
231
  })
231
232
  );
232
233
  };
@@ -243,10 +244,7 @@ var ThreadProvider = ({
243
244
  children,
244
245
  runtime
245
246
  }) => {
246
- const runtimeRef = useRef(runtime);
247
- useInsertionEffect(() => {
248
- runtimeRef.current = runtime;
249
- });
247
+ const runtimeRef = useRef(runtime.thread);
250
248
  const [context] = useState(() => {
251
249
  const useThread = makeThreadStore(runtimeRef);
252
250
  const useThreadMessages = makeThreadMessagesStore(runtimeRef);
@@ -261,8 +259,16 @@ var ThreadProvider = ({
261
259
  useViewport
262
260
  };
263
261
  });
262
+ const thread = useSyncExternalStore(
263
+ useCallback((c) => runtime.subscribe(c), [runtime]),
264
+ () => runtime.thread,
265
+ () => runtime.thread
266
+ );
267
+ useInsertionEffect(() => {
268
+ runtimeRef.current = thread;
269
+ });
264
270
  useEffect(() => {
265
- const onRuntimeUpdate = () => {
271
+ const onThreadUpdate = () => {
266
272
  context.useThread.setState(
267
273
  Object.freeze({
268
274
  isRunning: runtimeRef.current.isRunning
@@ -271,20 +277,11 @@ var ThreadProvider = ({
271
277
  );
272
278
  context.useThreadMessages.setState(Object.freeze(runtimeRef.current.messages), true);
273
279
  };
274
- onRuntimeUpdate();
275
- return runtime.subscribe(onRuntimeUpdate);
276
- }, [context, runtime]);
277
- const subscribe = useCallback(
278
- (c) => runtime.subscribe(c),
279
- [runtime]
280
- );
281
- const RuntimeSynchronizer = useSyncExternalStore(
282
- subscribe,
283
- () => runtime.unstable_synchronizer,
284
- () => void 0
285
- );
280
+ onThreadUpdate();
281
+ return thread.subscribe(onThreadUpdate);
282
+ }, [context, thread]);
286
283
  return /* @__PURE__ */ jsxs(ThreadContext.Provider, { value: context, children: [
287
- RuntimeSynchronizer && /* @__PURE__ */ jsx(RuntimeSynchronizer, {}),
284
+ thread.unstable_synchronizer && /* @__PURE__ */ jsx(thread.unstable_synchronizer, {}),
288
285
  children
289
286
  ] });
290
287
  };
@@ -293,7 +290,8 @@ var ThreadProvider = ({
293
290
  import { create as create8 } from "zustand";
294
291
  var makeAssistantActionsStore = (runtimeRef) => create8(
295
292
  () => Object.freeze({
296
- switchToThread: () => runtimeRef.current.switchToThread(null)
293
+ switchToThread: () => runtimeRef.current.switchToThread(null),
294
+ getRuntime: () => runtimeRef.current
297
295
  })
298
296
  );
299
297
 
@@ -310,10 +308,10 @@ var AssistantProvider = ({ children, runtime }) => {
310
308
  const useAssistantActions = makeAssistantActionsStore(runtimeRef);
311
309
  return { useModelConfig, useToolUIs, useAssistantActions };
312
310
  });
313
- const getModelCOnfig = context.useModelConfig((c) => c.getModelConfig);
311
+ const getModelConfig = context.useModelConfig();
314
312
  useEffect2(() => {
315
- return runtime.registerModelConfigProvider(getModelCOnfig);
316
- }, [runtime, getModelCOnfig]);
313
+ return runtime.registerModelConfigProvider(getModelConfig);
314
+ }, [runtime, getModelConfig]);
317
315
  return /* @__PURE__ */ jsx2(AssistantContext.Provider, { value: context, children: /* @__PURE__ */ jsx2(ThreadProvider, { runtime, children }) });
318
316
  };
319
317
 
@@ -423,7 +421,9 @@ var useAssistantTool = (tool) => {
423
421
  [tool.toolName]: rest
424
422
  }
425
423
  };
426
- const unsub1 = registerModelConfigProvider(() => config);
424
+ const unsub1 = registerModelConfigProvider({
425
+ getModelConfig: () => config
426
+ });
427
427
  const unsub2 = render ? setToolUI(toolName, render) : void 0;
428
428
  return () => {
429
429
  unsub1();
@@ -473,7 +473,7 @@ var useAssistantInstructions = (instruction) => {
473
473
  const config = {
474
474
  system: instruction
475
475
  };
476
- return registerModelConfigProvider(() => config);
476
+ return registerModelConfigProvider({ getModelConfig: () => config });
477
477
  }, [registerModelConfigProvider, instruction]);
478
478
  };
479
479
 
@@ -2080,45 +2080,14 @@ var BaseAssistantRuntime = class {
2080
2080
  constructor(_thread) {
2081
2081
  this._thread = _thread;
2082
2082
  this._thread = _thread;
2083
- this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
2084
2083
  }
2085
- get capabilities() {
2086
- return this._thread.capabilities;
2087
- }
2088
- _unsubscribe;
2089
2084
  get thread() {
2090
2085
  return this._thread;
2091
2086
  }
2092
2087
  set thread(thread) {
2093
- this._unsubscribe();
2094
2088
  this._thread = thread;
2095
- this._unsubscribe = this._thread.subscribe(this.subscriptionHandler);
2096
2089
  this.subscriptionHandler();
2097
2090
  }
2098
- get messages() {
2099
- return this.thread.messages;
2100
- }
2101
- get isRunning() {
2102
- return this.thread.isRunning;
2103
- }
2104
- getBranches(messageId) {
2105
- return this.thread.getBranches(messageId);
2106
- }
2107
- switchToBranch(branchId) {
2108
- return this.thread.switchToBranch(branchId);
2109
- }
2110
- append(message) {
2111
- return this.thread.append(message);
2112
- }
2113
- startRun(parentId) {
2114
- return this.thread.startRun(parentId);
2115
- }
2116
- cancelRun() {
2117
- return this.thread.cancelRun();
2118
- }
2119
- addToolResult(options) {
2120
- return this.thread.addToolResult(options);
2121
- }
2122
2091
  _subscriptions = /* @__PURE__ */ new Set();
2123
2092
  subscribe(callback) {
2124
2093
  this._subscriptions.add(callback);
@@ -2127,32 +2096,135 @@ var BaseAssistantRuntime = class {
2127
2096
  subscriptionHandler = () => {
2128
2097
  for (const callback of this._subscriptions) callback();
2129
2098
  };
2130
- get unstable_synchronizer() {
2131
- return this.thread.unstable_synchronizer;
2132
- }
2133
2099
  };
2134
2100
 
2101
+ // src/internal.ts
2102
+ var internal_exports = {};
2103
+ __export(internal_exports, {
2104
+ BaseAssistantRuntime: () => BaseAssistantRuntime,
2105
+ MessageRepository: () => MessageRepository,
2106
+ ProxyConfigProvider: () => ProxyConfigProvider,
2107
+ TooltipIconButton: () => TooltipIconButton,
2108
+ generateId: () => generateId,
2109
+ useSmooth: () => useSmooth
2110
+ });
2111
+
2112
+ // src/ui/base/tooltip-icon-button.tsx
2113
+ import { forwardRef as forwardRef17 } from "react";
2114
+
2115
+ // src/ui/base/tooltip.tsx
2116
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2117
+
2118
+ // src/ui/utils/withDefaults.tsx
2119
+ import {
2120
+ forwardRef as forwardRef15
2121
+ } from "react";
2122
+ import classNames from "classnames";
2123
+ import { jsx as jsx25 } from "react/jsx-runtime";
2124
+ var withDefaultProps = ({
2125
+ className,
2126
+ ...defaultProps
2127
+ }) => ({ className: classNameProp, ...props }) => {
2128
+ return {
2129
+ className: classNames(className, classNameProp),
2130
+ ...defaultProps,
2131
+ ...props
2132
+ };
2133
+ };
2134
+ var withDefaults = (Component, defaultProps) => {
2135
+ const getProps = withDefaultProps(defaultProps);
2136
+ const WithDefaults = forwardRef15(
2137
+ (props, ref) => {
2138
+ const ComponentAsAny = Component;
2139
+ return /* @__PURE__ */ jsx25(ComponentAsAny, { ...getProps(props), ref });
2140
+ }
2141
+ );
2142
+ WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
2143
+ return WithDefaults;
2144
+ };
2145
+
2146
+ // src/ui/base/tooltip.tsx
2147
+ import { jsx as jsx26 } from "react/jsx-runtime";
2148
+ var Tooltip = (props) => {
2149
+ return /* @__PURE__ */ jsx26(TooltipPrimitive.Provider, { children: /* @__PURE__ */ jsx26(TooltipPrimitive.Root, { ...props }) });
2150
+ };
2151
+ Tooltip.displayName = "Tooltip";
2152
+ var TooltipTrigger = TooltipPrimitive.Trigger;
2153
+ var TooltipContent = withDefaults(TooltipPrimitive.Content, {
2154
+ sideOffset: 4,
2155
+ className: "aui-tooltip-content"
2156
+ });
2157
+ TooltipContent.displayName = "TooltipContent";
2158
+
2159
+ // src/ui/base/button.tsx
2160
+ import { cva } from "class-variance-authority";
2161
+ import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
2162
+ import { forwardRef as forwardRef16 } from "react";
2163
+ import { jsx as jsx27 } from "react/jsx-runtime";
2164
+ var buttonVariants = cva("aui-button", {
2165
+ variants: {
2166
+ variant: {
2167
+ default: "aui-button-primary",
2168
+ outline: "aui-button-outline",
2169
+ ghost: "aui-button-ghost"
2170
+ },
2171
+ size: {
2172
+ default: "aui-button-medium",
2173
+ icon: "aui-button-icon"
2174
+ }
2175
+ },
2176
+ defaultVariants: {
2177
+ variant: "default",
2178
+ size: "default"
2179
+ }
2180
+ });
2181
+ var Button = forwardRef16(
2182
+ ({ className, variant, size, ...props }, ref) => {
2183
+ return /* @__PURE__ */ jsx27(
2184
+ Primitive11.button,
2185
+ {
2186
+ className: buttonVariants({ variant, size, className }),
2187
+ ...props,
2188
+ ref
2189
+ }
2190
+ );
2191
+ }
2192
+ );
2193
+ Button.displayName = "Button";
2194
+
2195
+ // src/ui/base/tooltip-icon-button.tsx
2196
+ import { jsx as jsx28, jsxs as jsxs4 } from "react/jsx-runtime";
2197
+ var TooltipIconButton = forwardRef17(({ children, tooltip, side = "bottom", ...rest }, ref) => {
2198
+ return /* @__PURE__ */ jsxs4(Tooltip, { children: [
2199
+ /* @__PURE__ */ jsx28(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs4(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
2200
+ children,
2201
+ /* @__PURE__ */ jsx28("span", { className: "aui-sr-only", children: tooltip })
2202
+ ] }) }),
2203
+ /* @__PURE__ */ jsx28(TooltipContent, { side, children: tooltip })
2204
+ ] });
2205
+ });
2206
+ TooltipIconButton.displayName = "TooltipIconButton";
2207
+
2135
2208
  // src/runtimes/local/LocalRuntime.tsx
2136
2209
  var LocalRuntime = class extends BaseAssistantRuntime {
2137
- _configProviders;
2210
+ _proxyConfigProvider;
2138
2211
  constructor(adapter) {
2139
- const configProviders = /* @__PURE__ */ new Set();
2140
- super(new LocalThreadRuntime(configProviders, adapter));
2141
- this._configProviders = configProviders;
2212
+ const proxyConfigProvider = new ProxyConfigProvider();
2213
+ super(new LocalThreadRuntime(proxyConfigProvider, adapter));
2214
+ this._proxyConfigProvider = proxyConfigProvider;
2142
2215
  }
2143
2216
  set adapter(adapter) {
2144
2217
  this.thread.adapter = adapter;
2145
2218
  }
2146
2219
  registerModelConfigProvider(provider) {
2147
- this._configProviders.add(provider);
2148
- return () => this._configProviders.delete(provider);
2220
+ return this._proxyConfigProvider.registerModelConfigProvider(provider);
2149
2221
  }
2150
2222
  switchToThread(threadId) {
2151
2223
  if (threadId) {
2152
2224
  throw new Error("LocalRuntime does not yet support switching threads");
2153
2225
  }
2154
2226
  return this.thread = new LocalThreadRuntime(
2155
- this._configProviders,
2227
+ this._proxyConfigProvider,
2156
2228
  this.thread.adapter
2157
2229
  );
2158
2230
  }
@@ -2164,8 +2236,8 @@ var CAPABILITIES = Object.freeze({
2164
2236
  copy: true
2165
2237
  });
2166
2238
  var LocalThreadRuntime = class {
2167
- constructor(_configProviders, adapter) {
2168
- this._configProviders = _configProviders;
2239
+ constructor(configProvider, adapter) {
2240
+ this.configProvider = configProvider;
2169
2241
  this.adapter = adapter;
2170
2242
  }
2171
2243
  _subscriptions = /* @__PURE__ */ new Set();
@@ -2186,6 +2258,10 @@ var LocalThreadRuntime = class {
2186
2258
  this.notifySubscribers();
2187
2259
  }
2188
2260
  async append(message) {
2261
+ if (message.role !== "user")
2262
+ throw new Error(
2263
+ "Only appending user messages are supported in LocalRuntime. This is likely an internal bug in assistant-ui."
2264
+ );
2189
2265
  const userMessageId = generateId();
2190
2266
  const userMessage = {
2191
2267
  id: userMessageId,
@@ -2197,11 +2273,10 @@ var LocalThreadRuntime = class {
2197
2273
  await this.startRun(userMessageId);
2198
2274
  }
2199
2275
  async startRun(parentId) {
2200
- const id = generateId();
2201
2276
  this.repository.resetHead(parentId);
2202
2277
  const messages = this.repository.getMessages();
2203
2278
  const message = {
2204
- id,
2279
+ id: generateId(),
2205
2280
  role: "assistant",
2206
2281
  status: { type: "in_progress" },
2207
2282
  content: [{ type: "text", text: "" }],
@@ -2220,7 +2295,7 @@ var LocalThreadRuntime = class {
2220
2295
  const result = await this.adapter.run({
2221
2296
  messages,
2222
2297
  abortSignal: this.abortController.signal,
2223
- config: mergeModelConfigs(this._configProviders),
2298
+ config: this.configProvider.getModelConfig(),
2224
2299
  onUpdate: updateHandler
2225
2300
  });
2226
2301
  if (result !== void 0) {
@@ -2235,7 +2310,7 @@ var LocalThreadRuntime = class {
2235
2310
  } catch (e) {
2236
2311
  message.status = { type: "error", error: e };
2237
2312
  this.repository.addOrUpdateMessage(parentId, { ...message });
2238
- console.error(e);
2313
+ throw e;
2239
2314
  } finally {
2240
2315
  this.abortController = null;
2241
2316
  this.notifySubscribers();
@@ -2245,7 +2320,6 @@ var LocalThreadRuntime = class {
2245
2320
  if (!this.abortController) return;
2246
2321
  this.abortController.abort();
2247
2322
  this.abortController = null;
2248
- this.notifySubscribers();
2249
2323
  }
2250
2324
  notifySubscribers() {
2251
2325
  for (const callback of this._subscriptions) callback();
@@ -2257,7 +2331,7 @@ var LocalThreadRuntime = class {
2257
2331
  addToolResult({ messageId, toolCallId, result }) {
2258
2332
  const { parentId, message } = this.repository.getMessage(messageId);
2259
2333
  if (message.role !== "assistant")
2260
- throw new Error("Tried to add tool re^sult to non-assistant message");
2334
+ throw new Error("Tried to add tool result to non-assistant message");
2261
2335
  let found = false;
2262
2336
  const newContent = message.content.map((c) => {
2263
2337
  if (c.type !== "tool-call") return c;
@@ -2286,20 +2360,48 @@ var useLocalRuntime = (adapter) => {
2286
2360
  return runtime;
2287
2361
  };
2288
2362
 
2363
+ // src/runtimes/edge/useEdgeRuntime.ts
2364
+ import { useState as useState8 } from "react";
2365
+
2366
+ // src/runtimes/edge/converters/toCoreMessages.ts
2367
+ var toCoreMessages = (message) => {
2368
+ return message.map((message2) => {
2369
+ return {
2370
+ role: message2.role,
2371
+ content: message2.content.map((part) => {
2372
+ if (part.type === "ui") throw new Error("UI parts are not supported");
2373
+ return part;
2374
+ })
2375
+ };
2376
+ });
2377
+ };
2378
+
2379
+ // src/runtimes/edge/converters/toLanguageModelTools.ts
2380
+ import { z } from "zod";
2381
+ import zodToJsonSchema from "zod-to-json-schema";
2382
+ var toLanguageModelTools = (tools) => {
2383
+ if (!tools) return [];
2384
+ return Object.entries(tools).map(([name, tool]) => ({
2385
+ type: "function",
2386
+ name,
2387
+ ...tool.description ? { description: tool.description } : void 0,
2388
+ parameters: tool.parameters instanceof z.ZodType ? zodToJsonSchema(tool.parameters) : tool.parameters
2389
+ }));
2390
+ };
2391
+
2289
2392
  // src/runtimes/edge/streams/assistantDecoderStream.ts
2290
2393
  function assistantDecoderStream() {
2291
2394
  let currentToolCall;
2292
2395
  return new TransformStream({
2293
2396
  transform(chunk, controller) {
2294
- const [code, valueJson] = parseStreamPart(chunk);
2295
- const value = JSON.parse(valueJson);
2397
+ const [code, value] = parseStreamPart(chunk);
2296
2398
  if (currentToolCall && code !== "2" /* ToolCallArgsTextDelta */ && code !== "E" /* Error */) {
2297
2399
  controller.enqueue({
2298
2400
  type: "tool-call",
2299
2401
  toolCallType: "function",
2300
2402
  toolCallId: currentToolCall.id,
2301
2403
  toolName: currentToolCall.name,
2302
- args: JSON.parse(currentToolCall.argsText)
2404
+ args: currentToolCall.argsText
2303
2405
  });
2304
2406
  currentToolCall = void 0;
2305
2407
  }
@@ -2312,12 +2414,12 @@ function assistantDecoderStream() {
2312
2414
  break;
2313
2415
  }
2314
2416
  case "1" /* ToolCallBegin */: {
2315
- const { id, name } = JSON.parse(value);
2417
+ const { id, name } = value;
2316
2418
  currentToolCall = { id, name, argsText: "" };
2317
2419
  break;
2318
2420
  }
2319
2421
  case "2" /* ToolCallArgsTextDelta */: {
2320
- const delta = JSON.parse(value);
2422
+ const delta = value;
2321
2423
  currentToolCall.argsText += delta;
2322
2424
  controller.enqueue({
2323
2425
  type: "tool-call-delta",
@@ -2331,14 +2433,14 @@ function assistantDecoderStream() {
2331
2433
  case "F" /* Finish */: {
2332
2434
  controller.enqueue({
2333
2435
  type: "finish",
2334
- ...JSON.parse(value)
2436
+ ...value
2335
2437
  });
2336
2438
  break;
2337
2439
  }
2338
2440
  case "E" /* Error */: {
2339
2441
  controller.enqueue({
2340
2442
  type: "error",
2341
- error: JSON.parse(value)
2443
+ error: value
2342
2444
  });
2343
2445
  break;
2344
2446
  }
@@ -2355,7 +2457,7 @@ var parseStreamPart = (part) => {
2355
2457
  if (index === -1) throw new Error("Invalid stream part");
2356
2458
  return [
2357
2459
  part.slice(0, index),
2358
- part.slice(index + 1)
2460
+ JSON.parse(part.slice(index + 1))
2359
2461
  ];
2360
2462
  };
2361
2463
 
@@ -2740,7 +2842,7 @@ function runResultStream() {
2740
2842
  message,
2741
2843
  toolCallId,
2742
2844
  toolName,
2743
- parsePartialJson(currentToolCall.argsText)
2845
+ currentToolCall.argsText
2744
2846
  );
2745
2847
  controller.enqueue(message);
2746
2848
  break;
@@ -2788,7 +2890,7 @@ var appendOrUpdateText = (message, textDelta) => {
2788
2890
  content: contentParts.concat([contentPart])
2789
2891
  };
2790
2892
  };
2791
- var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
2893
+ var appendOrUpdateToolCall = (message, toolCallId, toolName, argsText) => {
2792
2894
  let contentParts = message.content;
2793
2895
  let contentPart = message.content.at(-1);
2794
2896
  if (contentPart?.type !== "tool-call" || contentPart.toolCallId !== toolCallId) {
@@ -2796,13 +2898,15 @@ var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
2796
2898
  type: "tool-call",
2797
2899
  toolCallId,
2798
2900
  toolName,
2799
- args
2901
+ argsText,
2902
+ args: parsePartialJson(argsText)
2800
2903
  };
2801
2904
  } else {
2802
2905
  contentParts = contentParts.slice(0, -1);
2803
2906
  contentPart = {
2804
2907
  ...contentPart,
2805
- args
2908
+ argsText,
2909
+ args: parsePartialJson(argsText)
2806
2910
  };
2807
2911
  }
2808
2912
  return {
@@ -2845,11 +2949,8 @@ var appendOrUpdateFinish = (message, chunk) => {
2845
2949
  };
2846
2950
  };
2847
2951
 
2848
- // src/runtimes/edge/useEdgeRuntime.ts
2849
- import { useMemo as useMemo3 } from "react";
2850
-
2851
2952
  // src/runtimes/edge/streams/toolResultStream.ts
2852
- import { z } from "zod";
2953
+ import { z as z2 } from "zod";
2853
2954
  import sjson2 from "secure-json-parse";
2854
2955
  function toolResultStream(tools) {
2855
2956
  const toolCallExecutions = /* @__PURE__ */ new Map();
@@ -2861,9 +2962,9 @@ function toolResultStream(tools) {
2861
2962
  case "tool-call": {
2862
2963
  const { toolCallId, toolCallType, toolName, args: argsText } = chunk;
2863
2964
  const tool = tools?.[toolName];
2864
- if (!tool) return;
2965
+ if (!tool || !tool.execute) return;
2865
2966
  const args = sjson2.parse(argsText);
2866
- if (tool.parameters instanceof z.ZodType) {
2967
+ if (tool.parameters instanceof z2.ZodType) {
2867
2968
  const result = tool.parameters.safeParse(args);
2868
2969
  if (!result.success) {
2869
2970
  controller.enqueue({
@@ -2915,9 +3016,7 @@ function toolResultStream(tools) {
2915
3016
  });
2916
3017
  }
2917
3018
 
2918
- // src/runtimes/edge/useEdgeRuntime.ts
2919
- import { z as z2 } from "zod";
2920
- import { zodToJsonSchema } from "zod-to-json-schema";
3019
+ // src/runtimes/edge/EdgeChatAdapter.ts
2921
3020
  function asAsyncIterable(source) {
2922
3021
  return {
2923
3022
  [Symbol.asyncIterator]: () => {
@@ -2931,28 +3030,20 @@ function asAsyncIterable(source) {
2931
3030
  }
2932
3031
  };
2933
3032
  }
2934
- var toSerializableTools = (tools) => {
2935
- if (!tools) return [];
2936
- return Object.entries(tools).map(([name, tool]) => ({
2937
- type: "function",
2938
- name,
2939
- ...tool.description ? { description: tool.description } : void 0,
2940
- parameters: tool.parameters instanceof z2.ZodType ? zodToJsonSchema(tool.parameters) : tool.parameters
2941
- }));
2942
- };
2943
- var createEdgeChatAdapter = ({
2944
- api
2945
- }) => ({
2946
- run: async ({ messages, abortSignal, config, onUpdate }) => {
2947
- const result = await fetch(api, {
3033
+ var EdgeChatAdapter = class {
3034
+ constructor(options) {
3035
+ this.options = options;
3036
+ }
3037
+ async run({ messages, abortSignal, config, onUpdate }) {
3038
+ const result = await fetch(this.options.api, {
2948
3039
  method: "POST",
2949
3040
  headers: {
2950
3041
  "Content-Type": "application/json"
2951
3042
  },
2952
3043
  body: JSON.stringify({
2953
3044
  system: config.system,
2954
- messages,
2955
- tools: toSerializableTools(
3045
+ messages: toCoreMessages(messages),
3046
+ tools: toLanguageModelTools(
2956
3047
  config.tools
2957
3048
  )
2958
3049
  }),
@@ -2967,15 +3058,251 @@ var createEdgeChatAdapter = ({
2967
3058
  throw new Error("No data received from Edge Runtime");
2968
3059
  return update;
2969
3060
  }
2970
- });
3061
+ };
3062
+
3063
+ // src/runtimes/edge/useEdgeRuntime.ts
2971
3064
  var useEdgeRuntime = (options) => {
2972
- const adapter = useMemo3(() => createEdgeChatAdapter(options), [options]);
3065
+ const [adapter] = useState8(() => new EdgeChatAdapter(options));
2973
3066
  return useLocalRuntime(adapter);
2974
3067
  };
2975
3068
 
3069
+ // src/runtimes/edge/converters/toLanguageModelMessages.ts
3070
+ var assistantMessageSplitter = () => {
3071
+ const stash = [];
3072
+ let assistantMessage = {
3073
+ role: "assistant",
3074
+ content: []
3075
+ };
3076
+ let toolMessage = {
3077
+ role: "tool",
3078
+ content: []
3079
+ };
3080
+ return {
3081
+ addTextContentPart: (part) => {
3082
+ if (toolMessage.content.length > 0) {
3083
+ stash.push(assistantMessage);
3084
+ stash.push(toolMessage);
3085
+ assistantMessage = {
3086
+ role: "assistant",
3087
+ content: []
3088
+ };
3089
+ toolMessage = {
3090
+ role: "tool",
3091
+ content: []
3092
+ };
3093
+ }
3094
+ assistantMessage.content.push(part);
3095
+ },
3096
+ addToolCallPart: (part) => {
3097
+ assistantMessage.content.push({
3098
+ type: "tool-call",
3099
+ toolCallId: part.toolCallId,
3100
+ toolName: part.toolName,
3101
+ args: part.args
3102
+ });
3103
+ if (part.result) {
3104
+ toolMessage.content.push({
3105
+ type: "tool-result",
3106
+ toolCallId: part.toolCallId,
3107
+ toolName: part.toolName,
3108
+ result: part.result
3109
+ // isError
3110
+ });
3111
+ }
3112
+ },
3113
+ getMessages: () => {
3114
+ if (toolMessage.content.length > 0) {
3115
+ return [...stash, assistantMessage, toolMessage];
3116
+ }
3117
+ return [...stash, assistantMessage];
3118
+ }
3119
+ };
3120
+ };
3121
+ function toLanguageModelMessages(message) {
3122
+ return message.flatMap((message2) => {
3123
+ const role = message2.role;
3124
+ switch (role) {
3125
+ case "system": {
3126
+ return [{ role: "system", content: message2.content[0].text }];
3127
+ }
3128
+ case "user": {
3129
+ const msg = {
3130
+ role: "user",
3131
+ content: message2.content.map(
3132
+ (part) => {
3133
+ const type = part.type;
3134
+ switch (type) {
3135
+ case "text": {
3136
+ return part;
3137
+ }
3138
+ case "image": {
3139
+ return {
3140
+ type: "image",
3141
+ image: new URL(part.image)
3142
+ };
3143
+ }
3144
+ default: {
3145
+ const unhandledType = type;
3146
+ throw new Error(
3147
+ `Unspported content part type: ${unhandledType}`
3148
+ );
3149
+ }
3150
+ }
3151
+ }
3152
+ )
3153
+ };
3154
+ return [msg];
3155
+ }
3156
+ case "assistant": {
3157
+ const splitter = assistantMessageSplitter();
3158
+ for (const part of message2.content) {
3159
+ const type = part.type;
3160
+ switch (type) {
3161
+ case "text": {
3162
+ splitter.addTextContentPart(part);
3163
+ break;
3164
+ }
3165
+ case "tool-call": {
3166
+ splitter.addToolCallPart(part);
3167
+ break;
3168
+ }
3169
+ default: {
3170
+ const unhandledType = type;
3171
+ throw new Error(`Unhandled content part type: ${unhandledType}`);
3172
+ }
3173
+ }
3174
+ }
3175
+ return splitter.getMessages();
3176
+ }
3177
+ default: {
3178
+ const unhandledRole = role;
3179
+ throw new Error(`Unknown message role: ${unhandledRole}`);
3180
+ }
3181
+ }
3182
+ });
3183
+ }
3184
+
3185
+ // src/runtimes/edge/converters/fromLanguageModelMessages.ts
3186
+ var fromLanguageModelMessages = (lm, mergeRoundtrips) => {
3187
+ const messages = [];
3188
+ for (const lmMessage of lm) {
3189
+ const role = lmMessage.role;
3190
+ switch (role) {
3191
+ case "system": {
3192
+ messages.push({
3193
+ role: "system",
3194
+ content: [
3195
+ {
3196
+ type: "text",
3197
+ text: lmMessage.content
3198
+ }
3199
+ ]
3200
+ });
3201
+ break;
3202
+ }
3203
+ case "user": {
3204
+ messages.push({
3205
+ role: "user",
3206
+ content: lmMessage.content.map((part) => {
3207
+ const type = part.type;
3208
+ switch (type) {
3209
+ case "text": {
3210
+ return {
3211
+ type: "text",
3212
+ text: part.text
3213
+ };
3214
+ }
3215
+ case "image": {
3216
+ if (part.image instanceof URL) {
3217
+ return {
3218
+ type: "image",
3219
+ image: part.image.href
3220
+ };
3221
+ }
3222
+ throw new Error("Only images with URL data are supported");
3223
+ }
3224
+ default: {
3225
+ const unhandledType = type;
3226
+ throw new Error(`Unknown content part type: ${unhandledType}`);
3227
+ }
3228
+ }
3229
+ })
3230
+ });
3231
+ break;
3232
+ }
3233
+ case "assistant": {
3234
+ const newContent = lmMessage.content.map((part) => {
3235
+ if (part.type === "tool-call") {
3236
+ return {
3237
+ type: "tool-call",
3238
+ toolCallId: part.toolCallId,
3239
+ toolName: part.toolName,
3240
+ argsText: JSON.stringify(part.args),
3241
+ args: typeof part.args === "string" ? part.args : part.args
3242
+ };
3243
+ }
3244
+ return part;
3245
+ });
3246
+ if (mergeRoundtrips) {
3247
+ const previousMessage = messages[messages.length - 1];
3248
+ if (previousMessage?.role === "assistant") {
3249
+ previousMessage.content.push(...newContent);
3250
+ break;
3251
+ }
3252
+ }
3253
+ messages.push({
3254
+ role: "assistant",
3255
+ content: newContent
3256
+ });
3257
+ break;
3258
+ }
3259
+ case "tool": {
3260
+ const previousMessage = messages[messages.length - 1];
3261
+ if (previousMessage?.role !== "assistant")
3262
+ throw new Error(
3263
+ "A tool message must be preceded by an assistant message."
3264
+ );
3265
+ for (const tool of lmMessage.content) {
3266
+ const toolCall = previousMessage.content.find(
3267
+ (c) => c.type === "tool-call" && c.toolCallId === tool.toolCallId
3268
+ );
3269
+ if (!toolCall)
3270
+ throw new Error("Received tool result for an unknown tool call.");
3271
+ if (toolCall.toolName !== tool.toolName)
3272
+ throw new Error("Tool call name mismatch.");
3273
+ toolCall.result = tool.result;
3274
+ if (tool.isError) {
3275
+ toolCall.isError = true;
3276
+ }
3277
+ }
3278
+ break;
3279
+ }
3280
+ default: {
3281
+ const unhandledRole = role;
3282
+ throw new Error(`Unknown message role: ${unhandledRole}`);
3283
+ }
3284
+ }
3285
+ }
3286
+ return messages;
3287
+ };
3288
+
3289
+ // src/runtimes/edge/converters/fromCoreMessage.ts
3290
+ var fromCoreMessages = (message) => {
3291
+ return message.map((message2) => {
3292
+ return {
3293
+ ...message2,
3294
+ id: generateId(),
3295
+ createdAt: /* @__PURE__ */ new Date(),
3296
+ ...message2.role === "assistant" ? {
3297
+ status: { type: "done" }
3298
+ } : void 0
3299
+ };
3300
+ });
3301
+ };
3302
+
2976
3303
  // src/ui/thread-config.tsx
2977
3304
  import { createContext as createContext5, useContext as useContext5 } from "react";
2978
- import { Fragment as Fragment3, jsx as jsx25 } from "react/jsx-runtime";
3305
+ import { Fragment as Fragment3, jsx as jsx29 } from "react/jsx-runtime";
2979
3306
  var ThreadConfigContext = createContext5({});
2980
3307
  var useThreadConfig = () => {
2981
3308
  return useContext5(ThreadConfigContext);
@@ -2985,119 +3312,21 @@ var ThreadConfigProvider = ({
2985
3312
  config
2986
3313
  }) => {
2987
3314
  const assistant = useAssistantContext({ optional: true });
2988
- const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ jsx25(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx25(Fragment3, { children });
3315
+ const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ jsx29(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx29(Fragment3, { children });
2989
3316
  if (!config?.runtime) return configProvider;
2990
3317
  if (assistant) {
2991
3318
  throw new Error(
2992
3319
  "You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
2993
3320
  );
2994
3321
  }
2995
- return /* @__PURE__ */ jsx25(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
3322
+ return /* @__PURE__ */ jsx29(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
2996
3323
  };
2997
3324
  ThreadConfigProvider.displayName = "ThreadConfigProvider";
2998
3325
 
2999
3326
  // src/ui/assistant-action-bar.tsx
3000
3327
  import { forwardRef as forwardRef18 } from "react";
3001
3328
  import { CheckIcon, CopyIcon, RefreshCwIcon } from "lucide-react";
3002
-
3003
- // src/ui/base/tooltip-icon-button.tsx
3004
- import { forwardRef as forwardRef17 } from "react";
3005
-
3006
- // src/ui/base/tooltip.tsx
3007
- import * as TooltipPrimitive from "@radix-ui/react-tooltip";
3008
-
3009
- // src/ui/utils/withDefaults.tsx
3010
- import {
3011
- forwardRef as forwardRef15
3012
- } from "react";
3013
- import classNames from "classnames";
3014
- import { jsx as jsx26 } from "react/jsx-runtime";
3015
- var withDefaultProps = ({
3016
- className,
3017
- ...defaultProps
3018
- }) => ({ className: classNameProp, ...props }) => {
3019
- return {
3020
- className: classNames(className, classNameProp),
3021
- ...defaultProps,
3022
- ...props
3023
- };
3024
- };
3025
- var withDefaults = (Component, defaultProps) => {
3026
- const getProps = withDefaultProps(defaultProps);
3027
- const WithDefaults = forwardRef15(
3028
- (props, ref) => {
3029
- const ComponentAsAny = Component;
3030
- return /* @__PURE__ */ jsx26(ComponentAsAny, { ...getProps(props), ref });
3031
- }
3032
- );
3033
- WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
3034
- return WithDefaults;
3035
- };
3036
-
3037
- // src/ui/base/tooltip.tsx
3038
- import { jsx as jsx27 } from "react/jsx-runtime";
3039
- var Tooltip = (props) => {
3040
- return /* @__PURE__ */ jsx27(TooltipPrimitive.Provider, { children: /* @__PURE__ */ jsx27(TooltipPrimitive.Root, { ...props }) });
3041
- };
3042
- Tooltip.displayName = "Tooltip";
3043
- var TooltipTrigger = TooltipPrimitive.Trigger;
3044
- var TooltipContent = withDefaults(TooltipPrimitive.Content, {
3045
- sideOffset: 4,
3046
- className: "aui-tooltip-content"
3047
- });
3048
- TooltipContent.displayName = "TooltipContent";
3049
-
3050
- // src/ui/base/button.tsx
3051
- import { cva } from "class-variance-authority";
3052
- import { Primitive as Primitive11 } from "@radix-ui/react-primitive";
3053
- import { forwardRef as forwardRef16 } from "react";
3054
- import { jsx as jsx28 } from "react/jsx-runtime";
3055
- var buttonVariants = cva("aui-button", {
3056
- variants: {
3057
- variant: {
3058
- default: "aui-button-primary",
3059
- outline: "aui-button-outline",
3060
- ghost: "aui-button-ghost"
3061
- },
3062
- size: {
3063
- default: "aui-button-medium",
3064
- icon: "aui-button-icon"
3065
- }
3066
- },
3067
- defaultVariants: {
3068
- variant: "default",
3069
- size: "default"
3070
- }
3071
- });
3072
- var Button = forwardRef16(
3073
- ({ className, variant, size, ...props }, ref) => {
3074
- return /* @__PURE__ */ jsx28(
3075
- Primitive11.button,
3076
- {
3077
- className: buttonVariants({ variant, size, className }),
3078
- ...props,
3079
- ref
3080
- }
3081
- );
3082
- }
3083
- );
3084
- Button.displayName = "Button";
3085
-
3086
- // src/ui/base/tooltip-icon-button.tsx
3087
- import { jsx as jsx29, jsxs as jsxs4 } from "react/jsx-runtime";
3088
- var TooltipIconButton = forwardRef17(({ children, tooltip, side = "bottom", ...rest }, ref) => {
3089
- return /* @__PURE__ */ jsxs4(Tooltip, { children: [
3090
- /* @__PURE__ */ jsx29(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxs4(Button, { variant: "ghost", size: "icon", ...rest, ref, children: [
3091
- children,
3092
- /* @__PURE__ */ jsx29("span", { className: "aui-sr-only", children: tooltip })
3093
- ] }) }),
3094
- /* @__PURE__ */ jsx29(TooltipContent, { side, children: tooltip })
3095
- ] });
3096
- });
3097
- TooltipIconButton.displayName = "TooltipIconButton";
3098
-
3099
- // src/ui/assistant-action-bar.tsx
3100
- import { jsx as jsx30, jsxs as jsxs5 } from "react/jsx-runtime";
3329
+ import { Fragment as Fragment4, jsx as jsx30, jsxs as jsxs5 } from "react/jsx-runtime";
3101
3330
  var useAllowCopy = () => {
3102
3331
  const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
3103
3332
  const { useThreadActions } = useThreadContext();
@@ -3140,10 +3369,10 @@ var AssistantActionBarCopy = forwardRef18((props, ref) => {
3140
3369
  } = useThreadConfig();
3141
3370
  const allowCopy = useAllowCopy();
3142
3371
  if (!allowCopy) return null;
3143
- return /* @__PURE__ */ jsx30(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ jsxs5(TooltipIconButton, { tooltip, ...props, ref, children: [
3372
+ return /* @__PURE__ */ jsx30(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ jsx30(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsxs5(Fragment4, { children: [
3144
3373
  /* @__PURE__ */ jsx30(message_exports.If, { copied: true, children: /* @__PURE__ */ jsx30(CheckIcon, {}) }),
3145
3374
  /* @__PURE__ */ jsx30(message_exports.If, { copied: false, children: /* @__PURE__ */ jsx30(CopyIcon, {}) })
3146
- ] }) });
3375
+ ] }) }) });
3147
3376
  });
3148
3377
  AssistantActionBarCopy.displayName = "AssistantActionBarCopy";
3149
3378
  var AssistantActionBarReload = forwardRef18((props, ref) => {
@@ -3192,7 +3421,7 @@ var BranchPickerPrevious2 = forwardRef19((props, ref) => {
3192
3421
  branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
3193
3422
  } = {}
3194
3423
  } = useThreadConfig();
3195
- return /* @__PURE__ */ jsx31(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx31(ChevronLeftIcon, {}) }) });
3424
+ return /* @__PURE__ */ jsx31(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx31(ChevronLeftIcon, {}) }) });
3196
3425
  });
3197
3426
  BranchPickerPrevious2.displayName = "BranchPickerPrevious";
3198
3427
  var BranchPickerStateWrapper = withDefaults("span", {
@@ -3210,7 +3439,7 @@ var BranchPickerNext = forwardRef19((props, ref) => {
3210
3439
  const {
3211
3440
  strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
3212
3441
  } = useThreadConfig();
3213
- return /* @__PURE__ */ jsx31(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx31(ChevronRightIcon, {}) }) });
3442
+ return /* @__PURE__ */ jsx31(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx31(ChevronRightIcon, {}) }) });
3214
3443
  });
3215
3444
  BranchPickerNext.displayName = "BranchPickerNext";
3216
3445
  var exports2 = {
@@ -3317,7 +3546,7 @@ import { ArrowDownIcon } from "lucide-react";
3317
3546
 
3318
3547
  // src/ui/composer.tsx
3319
3548
  import { forwardRef as forwardRef21 } from "react";
3320
- import { SendHorizonalIcon } from "lucide-react";
3549
+ import { SendHorizontalIcon } from "lucide-react";
3321
3550
 
3322
3551
  // src/ui/base/CircleStopIcon.tsx
3323
3552
  import { jsx as jsx35 } from "react/jsx-runtime";
@@ -3335,7 +3564,7 @@ var CircleStopIcon = () => {
3335
3564
  CircleStopIcon.displayName = "CircleStopIcon";
3336
3565
 
3337
3566
  // src/ui/composer.tsx
3338
- import { Fragment as Fragment4, jsx as jsx36, jsxs as jsxs9 } from "react/jsx-runtime";
3567
+ import { Fragment as Fragment5, jsx as jsx36, jsxs as jsxs9 } from "react/jsx-runtime";
3339
3568
  var Composer = () => {
3340
3569
  return /* @__PURE__ */ jsxs9(ComposerRoot, { children: [
3341
3570
  /* @__PURE__ */ jsx36(ComposerInput, { autoFocus: true }),
@@ -3371,7 +3600,7 @@ var useAllowCancel = () => {
3371
3600
  var ComposerAction = () => {
3372
3601
  const allowCancel = useAllowCancel();
3373
3602
  if (!allowCancel) return /* @__PURE__ */ jsx36(ComposerSend, {});
3374
- return /* @__PURE__ */ jsxs9(Fragment4, { children: [
3603
+ return /* @__PURE__ */ jsxs9(Fragment5, { children: [
3375
3604
  /* @__PURE__ */ jsx36(thread_exports.If, { running: false, children: /* @__PURE__ */ jsx36(ComposerSend, {}) }),
3376
3605
  /* @__PURE__ */ jsx36(thread_exports.If, { running: true, children: /* @__PURE__ */ jsx36(ComposerCancel, {}) })
3377
3606
  ] });
@@ -3385,7 +3614,7 @@ var ComposerSend = forwardRef21((props, ref) => {
3385
3614
  const {
3386
3615
  strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
3387
3616
  } = useThreadConfig();
3388
- return /* @__PURE__ */ jsx36(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerSendButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx36(SendHorizonalIcon, {}) }) });
3617
+ return /* @__PURE__ */ jsx36(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerSendButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx36(SendHorizontalIcon, {}) }) });
3389
3618
  });
3390
3619
  ComposerSend.displayName = "ComposerSend";
3391
3620
  var ComposerCancelButton = withDefaults(TooltipIconButton, {
@@ -3396,7 +3625,7 @@ var ComposerCancel = forwardRef21((props, ref) => {
3396
3625
  const {
3397
3626
  strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
3398
3627
  } = useThreadConfig();
3399
- return /* @__PURE__ */ jsx36(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerCancelButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx36(CircleStopIcon, {}) }) });
3628
+ return /* @__PURE__ */ jsx36(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerCancelButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx36(CircleStopIcon, {}) }) });
3400
3629
  });
3401
3630
  ComposerCancel.displayName = "ComposerCancel";
3402
3631
  var exports5 = {
@@ -3511,7 +3740,7 @@ var UserActionBarEdit = forwardRef23((props, ref) => {
3511
3740
  } = useThreadConfig();
3512
3741
  const allowEdit = useAllowEdit();
3513
3742
  if (!allowEdit) return null;
3514
- return /* @__PURE__ */ jsx38(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx38(PencilIcon, {}) }) });
3743
+ return /* @__PURE__ */ jsx38(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(PencilIcon, {}) }) });
3515
3744
  });
3516
3745
  UserActionBarEdit.displayName = "UserActionBarEdit";
3517
3746
  var exports7 = {
@@ -3589,7 +3818,7 @@ var EditComposerCancel = forwardRef25(
3589
3818
  editComposer: { cancel: { label = "Cancel" } = {} } = {}
3590
3819
  } = {}
3591
3820
  } = useThreadConfig();
3592
- return /* @__PURE__ */ jsx40(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { variant: "ghost", ...props, ref, children: label }) });
3821
+ return /* @__PURE__ */ jsx40(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { variant: "ghost", ...props, ref, children: props.children ?? label }) });
3593
3822
  }
3594
3823
  );
3595
3824
  EditComposerCancel.displayName = "EditComposerCancel";
@@ -3598,7 +3827,7 @@ var EditComposerSend = forwardRef25(
3598
3827
  const {
3599
3828
  strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
3600
3829
  } = useThreadConfig();
3601
- return /* @__PURE__ */ jsx40(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { ...props, ref, children: label }) });
3830
+ return /* @__PURE__ */ jsx40(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { ...props, ref, children: props.children ?? label }) });
3602
3831
  }
3603
3832
  );
3604
3833
  EditComposerSend.displayName = "EditComposerSend";
@@ -3666,7 +3895,10 @@ var ThreadScrollToBottom = forwardRef26((props, ref) => {
3666
3895
  thread: { scrollToBottom: { tooltip = "Scroll to bottom" } = {} } = {}
3667
3896
  } = {}
3668
3897
  } = useThreadConfig();
3669
- return /* @__PURE__ */ jsx41(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx41(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx41(ArrowDownIcon, {}) }) });
3898
+ return /* @__PURE__ */ jsx41(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsxs13(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: [
3899
+ "|",
3900
+ props.children ?? /* @__PURE__ */ jsx41(ArrowDownIcon, {})
3901
+ ] }) });
3670
3902
  });
3671
3903
  ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
3672
3904
  var exports10 = {
@@ -3679,7 +3911,7 @@ var exports10 = {
3679
3911
  var thread_default = Object.assign(Thread, exports10);
3680
3912
 
3681
3913
  // src/ui/assistant-modal.tsx
3682
- import { jsx as jsx42, jsxs as jsxs14 } from "react/jsx-runtime";
3914
+ import { Fragment as Fragment6, jsx as jsx42, jsxs as jsxs14 } from "react/jsx-runtime";
3683
3915
  var AssistantModal = (config) => {
3684
3916
  return /* @__PURE__ */ jsxs14(AssistantModalRoot, { config, children: [
3685
3917
  /* @__PURE__ */ jsx42(AssistantModalTrigger, {}),
@@ -3717,7 +3949,7 @@ var AssistantModalButton = forwardRef27(({ "data-state": state, ...rest }, ref)
3717
3949
  } = {}
3718
3950
  } = useThreadConfig();
3719
3951
  const tooltip = state === "open" ? openTooltip : closedTooltip;
3720
- return /* @__PURE__ */ jsxs14(
3952
+ return /* @__PURE__ */ jsx42(
3721
3953
  ModalButtonStyled,
3722
3954
  {
3723
3955
  side: "left",
@@ -3725,17 +3957,22 @@ var AssistantModalButton = forwardRef27(({ "data-state": state, ...rest }, ref)
3725
3957
  "data-state": state,
3726
3958
  ...rest,
3727
3959
  ref,
3728
- children: [
3729
- /* @__PURE__ */ jsx42(BotIcon, { "data-state": state, className: "aui-modal-button-closed-icon" }),
3960
+ children: rest.children ?? /* @__PURE__ */ jsxs14(Fragment6, { children: [
3961
+ /* @__PURE__ */ jsx42(
3962
+ BotIcon,
3963
+ {
3964
+ "data-state": state,
3965
+ className: "aui-modal-button-closed-icon"
3966
+ }
3967
+ ),
3730
3968
  /* @__PURE__ */ jsx42(
3731
3969
  ChevronDownIcon,
3732
3970
  {
3733
3971
  "data-state": state,
3734
3972
  className: "aui-modal-button-open-icon"
3735
3973
  }
3736
- ),
3737
- /* @__PURE__ */ jsx42("span", { className: "aui-sr-only", children: tooltip })
3738
- ]
3974
+ )
3975
+ ] })
3739
3976
  }
3740
3977
  );
3741
3978
  });
@@ -3751,16 +3988,6 @@ var exports11 = {
3751
3988
  Content: AssistantModalContent
3752
3989
  };
3753
3990
  var assistant_modal_default = Object.assign(AssistantModal, exports11);
3754
-
3755
- // src/internal.ts
3756
- var internal_exports = {};
3757
- __export(internal_exports, {
3758
- BaseAssistantRuntime: () => BaseAssistantRuntime,
3759
- MessageRepository: () => MessageRepository,
3760
- ProxyConfigProvider: () => ProxyConfigProvider,
3761
- TooltipIconButton: () => TooltipIconButton,
3762
- useSmooth: () => useSmooth
3763
- });
3764
3991
  export {
3765
3992
  actionBar_exports as ActionBarPrimitive,
3766
3993
  assistant_action_bar_default as AssistantActionBar,
@@ -3774,6 +4001,7 @@ export {
3774
4001
  composer_exports as ComposerPrimitive,
3775
4002
  content_part_default as ContentPart,
3776
4003
  contentPart_exports as ContentPartPrimitive,
4004
+ EdgeChatAdapter,
3777
4005
  edit_composer_default as EditComposer,
3778
4006
  internal_exports as INTERNAL,
3779
4007
  message_exports as MessagePrimitive,
@@ -3783,8 +4011,11 @@ export {
3783
4011
  thread_welcome_default as ThreadWelcome,
3784
4012
  user_action_bar_default as UserActionBar,
3785
4013
  user_message_default as UserMessage,
4014
+ fromCoreMessages,
4015
+ fromLanguageModelMessages,
3786
4016
  makeAssistantTool,
3787
4017
  makeAssistantToolUI,
4018
+ toLanguageModelMessages,
3788
4019
  useActionBarCopy,
3789
4020
  useActionBarEdit,
3790
4021
  useActionBarReload,