@assistant-ui/react 0.4.3 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/edge.d.mts +94 -3
- package/dist/edge.d.ts +94 -3
- package/dist/edge.js +754 -107
- package/dist/edge.js.map +1 -1
- package/dist/edge.mjs +744 -107
- package/dist/edge.mjs.map +1 -1
- package/dist/index.d.mts +79 -65
- package/dist/index.d.ts +79 -65
- package/dist/index.js +671 -381
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +670 -384
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +155 -155
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/modal.css +22 -22
- package/dist/styles/modal.css.map +1 -1
- package/dist/styles/tailwindcss/base-components.css +11 -11
- package/dist/styles/tailwindcss/modal.css +5 -5
- package/dist/styles/tailwindcss/thread.css +35 -35
- package/package.json +3 -3
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
|
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
|
-
|
275
|
-
return
|
276
|
-
}, [context,
|
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
|
-
|
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
|
311
|
+
const getModelConfig = context.useModelConfig();
|
314
312
|
useEffect2(() => {
|
315
|
-
return runtime.registerModelConfigProvider(
|
316
|
-
}, [runtime,
|
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(
|
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
|
|
@@ -1902,7 +1902,7 @@ var ThreadPrimitiveSuggestion = createActionButton(
|
|
1902
1902
|
);
|
1903
1903
|
|
1904
1904
|
// src/runtimes/local/useLocalRuntime.tsx
|
1905
|
-
import { useInsertionEffect as useInsertionEffect3, useState as
|
1905
|
+
import { useInsertionEffect as useInsertionEffect3, useState as useState8 } from "react";
|
1906
1906
|
|
1907
1907
|
// src/utils/idUtils.tsx
|
1908
1908
|
import { customAlphabet } from "nanoid/non-secure";
|
@@ -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
|
-
}
|
2085
|
-
get capabilities() {
|
2086
|
-
return this._thread.capabilities;
|
2087
2083
|
}
|
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,179 +2096,158 @@ 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
|
|
2135
|
-
// src/
|
2136
|
-
var
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
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 });
|
2153
2140
|
}
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
);
|
2158
|
-
}
|
2141
|
+
);
|
2142
|
+
WithDefaults.displayName = "withDefaults(" + (typeof Component === "string" ? Component : Component.displayName) + ")";
|
2143
|
+
return WithDefaults;
|
2159
2144
|
};
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
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"
|
2165
2156
|
});
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
}
|
2184
|
-
switchToBranch(branchId) {
|
2185
|
-
this.repository.switchToBranch(branchId);
|
2186
|
-
this.notifySubscribers();
|
2187
|
-
}
|
2188
|
-
async append(message) {
|
2189
|
-
const userMessageId = generateId();
|
2190
|
-
const userMessage = {
|
2191
|
-
id: userMessageId,
|
2192
|
-
role: "user",
|
2193
|
-
content: message.content,
|
2194
|
-
createdAt: /* @__PURE__ */ new Date()
|
2195
|
-
};
|
2196
|
-
this.repository.addOrUpdateMessage(message.parentId, userMessage);
|
2197
|
-
await this.startRun(userMessageId);
|
2198
|
-
}
|
2199
|
-
async startRun(parentId) {
|
2200
|
-
const id = generateId();
|
2201
|
-
this.repository.resetHead(parentId);
|
2202
|
-
const messages = this.repository.getMessages();
|
2203
|
-
const message = {
|
2204
|
-
id,
|
2205
|
-
role: "assistant",
|
2206
|
-
status: { type: "in_progress" },
|
2207
|
-
content: [{ type: "text", text: "" }],
|
2208
|
-
createdAt: /* @__PURE__ */ new Date()
|
2209
|
-
};
|
2210
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
2211
|
-
this.abortController?.abort();
|
2212
|
-
this.abortController = new AbortController();
|
2213
|
-
this.notifySubscribers();
|
2214
|
-
try {
|
2215
|
-
const updateHandler = ({ content }) => {
|
2216
|
-
message.content = content;
|
2217
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
2218
|
-
this.notifySubscribers();
|
2219
|
-
};
|
2220
|
-
const result = await this.adapter.run({
|
2221
|
-
messages,
|
2222
|
-
abortSignal: this.abortController.signal,
|
2223
|
-
config: mergeModelConfigs(this._configProviders),
|
2224
|
-
onUpdate: updateHandler
|
2225
|
-
});
|
2226
|
-
if (result !== void 0) {
|
2227
|
-
updateHandler(result);
|
2228
|
-
}
|
2229
|
-
if (result.status?.type === "in_progress")
|
2230
|
-
throw new Error(
|
2231
|
-
"Unexpected in_progress status returned from ChatModelAdapter"
|
2232
|
-
);
|
2233
|
-
message.status = result.status ?? { type: "done" };
|
2234
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
2235
|
-
} catch (e) {
|
2236
|
-
message.status = { type: "error", error: e };
|
2237
|
-
this.repository.addOrUpdateMessage(parentId, { ...message });
|
2238
|
-
console.error(e);
|
2239
|
-
} finally {
|
2240
|
-
this.abortController = null;
|
2241
|
-
this.notifySubscribers();
|
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"
|
2242
2174
|
}
|
2175
|
+
},
|
2176
|
+
defaultVariants: {
|
2177
|
+
variant: "default",
|
2178
|
+
size: "default"
|
2243
2179
|
}
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
return () => this._subscriptions.delete(callback);
|
2256
|
-
}
|
2257
|
-
addToolResult({ messageId, toolCallId, result }) {
|
2258
|
-
const { parentId, message } = this.repository.getMessage(messageId);
|
2259
|
-
if (message.role !== "assistant")
|
2260
|
-
throw new Error("Tried to add tool re^sult to non-assistant message");
|
2261
|
-
let found = false;
|
2262
|
-
const newContent = message.content.map((c) => {
|
2263
|
-
if (c.type !== "tool-call") return c;
|
2264
|
-
if (c.toolCallId !== toolCallId) return c;
|
2265
|
-
found = true;
|
2266
|
-
return {
|
2267
|
-
...c,
|
2268
|
-
result
|
2269
|
-
};
|
2270
|
-
});
|
2271
|
-
if (!found)
|
2272
|
-
throw new Error("Tried to add tool result to non-existing tool call");
|
2273
|
-
this.repository.addOrUpdateMessage(parentId, {
|
2274
|
-
...message,
|
2275
|
-
content: newContent
|
2276
|
-
});
|
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
|
+
);
|
2277
2191
|
}
|
2278
|
-
|
2192
|
+
);
|
2193
|
+
Button.displayName = "Button";
|
2279
2194
|
|
2280
|
-
// src/
|
2281
|
-
|
2282
|
-
|
2283
|
-
|
2284
|
-
|
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
|
+
|
2208
|
+
// src/runtimes/edge/useEdgeRuntime.ts
|
2209
|
+
import { useState as useState7 } from "react";
|
2210
|
+
|
2211
|
+
// src/runtimes/edge/converters/toCoreMessages.ts
|
2212
|
+
var toCoreMessages = (message) => {
|
2213
|
+
return message.map((message2) => {
|
2214
|
+
return {
|
2215
|
+
role: message2.role,
|
2216
|
+
content: message2.content.map((part) => {
|
2217
|
+
if (part.type === "ui") throw new Error("UI parts are not supported");
|
2218
|
+
return part;
|
2219
|
+
})
|
2220
|
+
};
|
2285
2221
|
});
|
2286
|
-
|
2222
|
+
};
|
2223
|
+
|
2224
|
+
// src/runtimes/edge/converters/toLanguageModelTools.ts
|
2225
|
+
import { z } from "zod";
|
2226
|
+
import zodToJsonSchema from "zod-to-json-schema";
|
2227
|
+
var toLanguageModelTools = (tools) => {
|
2228
|
+
if (!tools) return [];
|
2229
|
+
return Object.entries(tools).map(([name, tool]) => ({
|
2230
|
+
type: "function",
|
2231
|
+
name,
|
2232
|
+
...tool.description ? { description: tool.description } : void 0,
|
2233
|
+
parameters: tool.parameters instanceof z.ZodType ? zodToJsonSchema(tool.parameters) : tool.parameters
|
2234
|
+
}));
|
2287
2235
|
};
|
2288
2236
|
|
2289
2237
|
// src/runtimes/edge/streams/assistantDecoderStream.ts
|
2290
2238
|
function assistantDecoderStream() {
|
2239
|
+
const toolCallNames = /* @__PURE__ */ new Map();
|
2291
2240
|
let currentToolCall;
|
2292
2241
|
return new TransformStream({
|
2293
2242
|
transform(chunk, controller) {
|
2294
|
-
const [code,
|
2295
|
-
const value = JSON.parse(valueJson);
|
2243
|
+
const [code, value] = parseStreamPart(chunk);
|
2296
2244
|
if (currentToolCall && code !== "2" /* ToolCallArgsTextDelta */ && code !== "E" /* Error */) {
|
2297
2245
|
controller.enqueue({
|
2298
2246
|
type: "tool-call",
|
2299
2247
|
toolCallType: "function",
|
2300
2248
|
toolCallId: currentToolCall.id,
|
2301
2249
|
toolName: currentToolCall.name,
|
2302
|
-
args:
|
2250
|
+
args: currentToolCall.argsText
|
2303
2251
|
});
|
2304
2252
|
currentToolCall = void 0;
|
2305
2253
|
}
|
@@ -2312,12 +2260,13 @@ function assistantDecoderStream() {
|
|
2312
2260
|
break;
|
2313
2261
|
}
|
2314
2262
|
case "1" /* ToolCallBegin */: {
|
2315
|
-
const { id, name } =
|
2263
|
+
const { id, name } = value;
|
2264
|
+
toolCallNames.set(id, name);
|
2316
2265
|
currentToolCall = { id, name, argsText: "" };
|
2317
2266
|
break;
|
2318
2267
|
}
|
2319
2268
|
case "2" /* ToolCallArgsTextDelta */: {
|
2320
|
-
const delta =
|
2269
|
+
const delta = value;
|
2321
2270
|
currentToolCall.argsText += delta;
|
2322
2271
|
controller.enqueue({
|
2323
2272
|
type: "tool-call-delta",
|
@@ -2328,17 +2277,27 @@ function assistantDecoderStream() {
|
|
2328
2277
|
});
|
2329
2278
|
break;
|
2330
2279
|
}
|
2331
|
-
case "
|
2280
|
+
case "3" /* ToolCallResult */: {
|
2332
2281
|
controller.enqueue({
|
2333
|
-
type: "
|
2334
|
-
|
2282
|
+
type: "tool-result",
|
2283
|
+
toolCallType: "function",
|
2284
|
+
toolCallId: value.id,
|
2285
|
+
toolName: toolCallNames.get(value.id),
|
2286
|
+
result: value.result
|
2287
|
+
});
|
2288
|
+
break;
|
2289
|
+
}
|
2290
|
+
case "F" /* Finish */: {
|
2291
|
+
controller.enqueue({
|
2292
|
+
type: "finish",
|
2293
|
+
...value
|
2335
2294
|
});
|
2336
2295
|
break;
|
2337
2296
|
}
|
2338
2297
|
case "E" /* Error */: {
|
2339
2298
|
controller.enqueue({
|
2340
2299
|
type: "error",
|
2341
|
-
error:
|
2300
|
+
error: value
|
2342
2301
|
});
|
2343
2302
|
break;
|
2344
2303
|
}
|
@@ -2355,7 +2314,7 @@ var parseStreamPart = (part) => {
|
|
2355
2314
|
if (index === -1) throw new Error("Invalid stream part");
|
2356
2315
|
return [
|
2357
2316
|
part.slice(0, index),
|
2358
|
-
part.slice(index + 1)
|
2317
|
+
JSON.parse(part.slice(index + 1))
|
2359
2318
|
];
|
2360
2319
|
};
|
2361
2320
|
|
@@ -2714,9 +2673,9 @@ var parsePartialJson = (json) => {
|
|
2714
2673
|
};
|
2715
2674
|
|
2716
2675
|
// src/runtimes/edge/streams/runResultStream.ts
|
2717
|
-
function runResultStream() {
|
2676
|
+
function runResultStream(initialContent) {
|
2718
2677
|
let message = {
|
2719
|
-
content:
|
2678
|
+
content: initialContent
|
2720
2679
|
};
|
2721
2680
|
const currentToolCall = { toolCallId: "", argsText: "" };
|
2722
2681
|
return new TransformStream({
|
@@ -2740,7 +2699,7 @@ function runResultStream() {
|
|
2740
2699
|
message,
|
2741
2700
|
toolCallId,
|
2742
2701
|
toolName,
|
2743
|
-
|
2702
|
+
currentToolCall.argsText
|
2744
2703
|
);
|
2745
2704
|
controller.enqueue(message);
|
2746
2705
|
break;
|
@@ -2788,7 +2747,7 @@ var appendOrUpdateText = (message, textDelta) => {
|
|
2788
2747
|
content: contentParts.concat([contentPart])
|
2789
2748
|
};
|
2790
2749
|
};
|
2791
|
-
var appendOrUpdateToolCall = (message, toolCallId, toolName,
|
2750
|
+
var appendOrUpdateToolCall = (message, toolCallId, toolName, argsText) => {
|
2792
2751
|
let contentParts = message.content;
|
2793
2752
|
let contentPart = message.content.at(-1);
|
2794
2753
|
if (contentPart?.type !== "tool-call" || contentPart.toolCallId !== toolCallId) {
|
@@ -2796,13 +2755,15 @@ var appendOrUpdateToolCall = (message, toolCallId, toolName, args) => {
|
|
2796
2755
|
type: "tool-call",
|
2797
2756
|
toolCallId,
|
2798
2757
|
toolName,
|
2799
|
-
|
2758
|
+
argsText,
|
2759
|
+
args: parsePartialJson(argsText)
|
2800
2760
|
};
|
2801
2761
|
} else {
|
2802
2762
|
contentParts = contentParts.slice(0, -1);
|
2803
2763
|
contentPart = {
|
2804
2764
|
...contentPart,
|
2805
|
-
|
2765
|
+
argsText,
|
2766
|
+
args: parsePartialJson(argsText)
|
2806
2767
|
};
|
2807
2768
|
}
|
2808
2769
|
return {
|
@@ -2845,11 +2806,8 @@ var appendOrUpdateFinish = (message, chunk) => {
|
|
2845
2806
|
};
|
2846
2807
|
};
|
2847
2808
|
|
2848
|
-
// src/runtimes/edge/useEdgeRuntime.ts
|
2849
|
-
import { useMemo as useMemo3 } from "react";
|
2850
|
-
|
2851
2809
|
// src/runtimes/edge/streams/toolResultStream.ts
|
2852
|
-
import { z } from "zod";
|
2810
|
+
import { z as z2 } from "zod";
|
2853
2811
|
import sjson2 from "secure-json-parse";
|
2854
2812
|
function toolResultStream(tools) {
|
2855
2813
|
const toolCallExecutions = /* @__PURE__ */ new Map();
|
@@ -2861,9 +2819,9 @@ function toolResultStream(tools) {
|
|
2861
2819
|
case "tool-call": {
|
2862
2820
|
const { toolCallId, toolCallType, toolName, args: argsText } = chunk;
|
2863
2821
|
const tool = tools?.[toolName];
|
2864
|
-
if (!tool) return;
|
2822
|
+
if (!tool || !tool.execute) return;
|
2865
2823
|
const args = sjson2.parse(argsText);
|
2866
|
-
if (tool.parameters instanceof
|
2824
|
+
if (tool.parameters instanceof z2.ZodType) {
|
2867
2825
|
const result = tool.parameters.safeParse(args);
|
2868
2826
|
if (!result.success) {
|
2869
2827
|
controller.enqueue({
|
@@ -2900,6 +2858,7 @@ function toolResultStream(tools) {
|
|
2900
2858
|
}
|
2901
2859
|
case "text-delta":
|
2902
2860
|
case "tool-call-delta":
|
2861
|
+
case "tool-result":
|
2903
2862
|
case "finish":
|
2904
2863
|
case "error":
|
2905
2864
|
break;
|
@@ -2915,9 +2874,7 @@ function toolResultStream(tools) {
|
|
2915
2874
|
});
|
2916
2875
|
}
|
2917
2876
|
|
2918
|
-
// src/runtimes/edge/
|
2919
|
-
import { z as z2 } from "zod";
|
2920
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
2877
|
+
// src/runtimes/edge/EdgeChatAdapter.ts
|
2921
2878
|
function asAsyncIterable(source) {
|
2922
2879
|
return {
|
2923
2880
|
[Symbol.asyncIterator]: () => {
|
@@ -2931,51 +2888,479 @@ function asAsyncIterable(source) {
|
|
2931
2888
|
}
|
2932
2889
|
};
|
2933
2890
|
}
|
2934
|
-
var
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
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, {
|
2891
|
+
var EdgeChatAdapter = class {
|
2892
|
+
constructor(options) {
|
2893
|
+
this.options = options;
|
2894
|
+
}
|
2895
|
+
async roundtrip(initialContent, { messages, abortSignal, config, onUpdate }) {
|
2896
|
+
const result = await fetch(this.options.api, {
|
2948
2897
|
method: "POST",
|
2949
2898
|
headers: {
|
2950
2899
|
"Content-Type": "application/json"
|
2951
2900
|
},
|
2952
2901
|
body: JSON.stringify({
|
2953
2902
|
system: config.system,
|
2954
|
-
messages,
|
2955
|
-
tools:
|
2903
|
+
messages: toCoreMessages(messages),
|
2904
|
+
tools: toLanguageModelTools(
|
2956
2905
|
config.tools
|
2957
2906
|
)
|
2958
2907
|
}),
|
2959
2908
|
signal: abortSignal
|
2960
2909
|
});
|
2961
|
-
const stream = result.body.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(assistantDecoderStream()).pipeThrough(toolResultStream(config.tools)).pipeThrough(runResultStream());
|
2910
|
+
const stream = result.body.pipeThrough(new TextDecoderStream()).pipeThrough(chunkByLineStream()).pipeThrough(assistantDecoderStream()).pipeThrough(toolResultStream(config.tools)).pipeThrough(runResultStream(initialContent));
|
2911
|
+
let message;
|
2962
2912
|
let update;
|
2963
2913
|
for await (update of asAsyncIterable(stream)) {
|
2964
|
-
onUpdate(update);
|
2914
|
+
message = onUpdate(update);
|
2965
2915
|
}
|
2966
2916
|
if (update === void 0)
|
2967
2917
|
throw new Error("No data received from Edge Runtime");
|
2968
|
-
return update;
|
2918
|
+
return [message, update];
|
2919
|
+
}
|
2920
|
+
async run({ messages, abortSignal, config, onUpdate }) {
|
2921
|
+
let roundtripAllowance = this.options.maxToolRoundtrips ?? 1;
|
2922
|
+
let usage = {
|
2923
|
+
promptTokens: 0,
|
2924
|
+
completionTokens: 0
|
2925
|
+
};
|
2926
|
+
let result;
|
2927
|
+
let assistantMessage;
|
2928
|
+
do {
|
2929
|
+
[assistantMessage, result] = await this.roundtrip(result?.content ?? [], {
|
2930
|
+
messages: assistantMessage ? [...messages, assistantMessage] : messages,
|
2931
|
+
abortSignal,
|
2932
|
+
config,
|
2933
|
+
onUpdate
|
2934
|
+
});
|
2935
|
+
if (result.status?.type === "done") {
|
2936
|
+
usage.promptTokens += result.status.usage?.promptTokens ?? 0;
|
2937
|
+
usage.completionTokens += result.status.usage?.completionTokens ?? 0;
|
2938
|
+
}
|
2939
|
+
} while (result.status?.type === "done" && result.status.finishReason === "tool-calls" && result.content.every((c) => c.type !== "tool-call" || !!c.result) && roundtripAllowance-- > 0);
|
2940
|
+
if (result.status?.type === "done" && usage.promptTokens > 0) {
|
2941
|
+
result = {
|
2942
|
+
...result,
|
2943
|
+
status: {
|
2944
|
+
...result.status,
|
2945
|
+
usage
|
2946
|
+
}
|
2947
|
+
};
|
2948
|
+
}
|
2949
|
+
return result;
|
2950
|
+
}
|
2951
|
+
};
|
2952
|
+
|
2953
|
+
// src/runtimes/edge/useEdgeRuntime.ts
|
2954
|
+
var useEdgeRuntime = ({
|
2955
|
+
initialMessages,
|
2956
|
+
...options
|
2957
|
+
}) => {
|
2958
|
+
const [adapter] = useState7(() => new EdgeChatAdapter(options));
|
2959
|
+
return useLocalRuntime(adapter, { initialMessages });
|
2960
|
+
};
|
2961
|
+
|
2962
|
+
// src/runtimes/edge/converters/toLanguageModelMessages.ts
|
2963
|
+
var assistantMessageSplitter = () => {
|
2964
|
+
const stash = [];
|
2965
|
+
let assistantMessage = {
|
2966
|
+
role: "assistant",
|
2967
|
+
content: []
|
2968
|
+
};
|
2969
|
+
let toolMessage = {
|
2970
|
+
role: "tool",
|
2971
|
+
content: []
|
2972
|
+
};
|
2973
|
+
return {
|
2974
|
+
addTextContentPart: (part) => {
|
2975
|
+
if (toolMessage.content.length > 0) {
|
2976
|
+
stash.push(assistantMessage);
|
2977
|
+
stash.push(toolMessage);
|
2978
|
+
assistantMessage = {
|
2979
|
+
role: "assistant",
|
2980
|
+
content: []
|
2981
|
+
};
|
2982
|
+
toolMessage = {
|
2983
|
+
role: "tool",
|
2984
|
+
content: []
|
2985
|
+
};
|
2986
|
+
}
|
2987
|
+
assistantMessage.content.push(part);
|
2988
|
+
},
|
2989
|
+
addToolCallPart: (part) => {
|
2990
|
+
assistantMessage.content.push({
|
2991
|
+
type: "tool-call",
|
2992
|
+
toolCallId: part.toolCallId,
|
2993
|
+
toolName: part.toolName,
|
2994
|
+
args: part.args
|
2995
|
+
});
|
2996
|
+
if (part.result) {
|
2997
|
+
toolMessage.content.push({
|
2998
|
+
type: "tool-result",
|
2999
|
+
toolCallId: part.toolCallId,
|
3000
|
+
toolName: part.toolName,
|
3001
|
+
result: part.result
|
3002
|
+
// isError
|
3003
|
+
});
|
3004
|
+
}
|
3005
|
+
},
|
3006
|
+
getMessages: () => {
|
3007
|
+
if (toolMessage.content.length > 0) {
|
3008
|
+
return [...stash, assistantMessage, toolMessage];
|
3009
|
+
}
|
3010
|
+
return [...stash, assistantMessage];
|
3011
|
+
}
|
3012
|
+
};
|
3013
|
+
};
|
3014
|
+
function toLanguageModelMessages(message) {
|
3015
|
+
return message.flatMap((message2) => {
|
3016
|
+
const role = message2.role;
|
3017
|
+
switch (role) {
|
3018
|
+
case "system": {
|
3019
|
+
return [{ role: "system", content: message2.content[0].text }];
|
3020
|
+
}
|
3021
|
+
case "user": {
|
3022
|
+
const msg = {
|
3023
|
+
role: "user",
|
3024
|
+
content: message2.content.map(
|
3025
|
+
(part) => {
|
3026
|
+
const type = part.type;
|
3027
|
+
switch (type) {
|
3028
|
+
case "text": {
|
3029
|
+
return part;
|
3030
|
+
}
|
3031
|
+
case "image": {
|
3032
|
+
return {
|
3033
|
+
type: "image",
|
3034
|
+
image: new URL(part.image)
|
3035
|
+
};
|
3036
|
+
}
|
3037
|
+
default: {
|
3038
|
+
const unhandledType = type;
|
3039
|
+
throw new Error(
|
3040
|
+
`Unspported content part type: ${unhandledType}`
|
3041
|
+
);
|
3042
|
+
}
|
3043
|
+
}
|
3044
|
+
}
|
3045
|
+
)
|
3046
|
+
};
|
3047
|
+
return [msg];
|
3048
|
+
}
|
3049
|
+
case "assistant": {
|
3050
|
+
const splitter = assistantMessageSplitter();
|
3051
|
+
for (const part of message2.content) {
|
3052
|
+
const type = part.type;
|
3053
|
+
switch (type) {
|
3054
|
+
case "text": {
|
3055
|
+
splitter.addTextContentPart(part);
|
3056
|
+
break;
|
3057
|
+
}
|
3058
|
+
case "tool-call": {
|
3059
|
+
splitter.addToolCallPart(part);
|
3060
|
+
break;
|
3061
|
+
}
|
3062
|
+
default: {
|
3063
|
+
const unhandledType = type;
|
3064
|
+
throw new Error(`Unhandled content part type: ${unhandledType}`);
|
3065
|
+
}
|
3066
|
+
}
|
3067
|
+
}
|
3068
|
+
return splitter.getMessages();
|
3069
|
+
}
|
3070
|
+
default: {
|
3071
|
+
const unhandledRole = role;
|
3072
|
+
throw new Error(`Unknown message role: ${unhandledRole}`);
|
3073
|
+
}
|
3074
|
+
}
|
3075
|
+
});
|
3076
|
+
}
|
3077
|
+
|
3078
|
+
// src/runtimes/edge/converters/fromLanguageModelMessages.ts
|
3079
|
+
var fromLanguageModelMessages = (lm, mergeRoundtrips) => {
|
3080
|
+
const messages = [];
|
3081
|
+
for (const lmMessage of lm) {
|
3082
|
+
const role = lmMessage.role;
|
3083
|
+
switch (role) {
|
3084
|
+
case "system": {
|
3085
|
+
messages.push({
|
3086
|
+
role: "system",
|
3087
|
+
content: [
|
3088
|
+
{
|
3089
|
+
type: "text",
|
3090
|
+
text: lmMessage.content
|
3091
|
+
}
|
3092
|
+
]
|
3093
|
+
});
|
3094
|
+
break;
|
3095
|
+
}
|
3096
|
+
case "user": {
|
3097
|
+
messages.push({
|
3098
|
+
role: "user",
|
3099
|
+
content: lmMessage.content.map((part) => {
|
3100
|
+
const type = part.type;
|
3101
|
+
switch (type) {
|
3102
|
+
case "text": {
|
3103
|
+
return {
|
3104
|
+
type: "text",
|
3105
|
+
text: part.text
|
3106
|
+
};
|
3107
|
+
}
|
3108
|
+
case "image": {
|
3109
|
+
if (part.image instanceof URL) {
|
3110
|
+
return {
|
3111
|
+
type: "image",
|
3112
|
+
image: part.image.href
|
3113
|
+
};
|
3114
|
+
}
|
3115
|
+
throw new Error("Only images with URL data are supported");
|
3116
|
+
}
|
3117
|
+
default: {
|
3118
|
+
const unhandledType = type;
|
3119
|
+
throw new Error(`Unknown content part type: ${unhandledType}`);
|
3120
|
+
}
|
3121
|
+
}
|
3122
|
+
})
|
3123
|
+
});
|
3124
|
+
break;
|
3125
|
+
}
|
3126
|
+
case "assistant": {
|
3127
|
+
const newContent = lmMessage.content.map((part) => {
|
3128
|
+
if (part.type === "tool-call") {
|
3129
|
+
return {
|
3130
|
+
type: "tool-call",
|
3131
|
+
toolCallId: part.toolCallId,
|
3132
|
+
toolName: part.toolName,
|
3133
|
+
argsText: JSON.stringify(part.args),
|
3134
|
+
args: typeof part.args === "string" ? part.args : part.args
|
3135
|
+
};
|
3136
|
+
}
|
3137
|
+
return part;
|
3138
|
+
});
|
3139
|
+
if (mergeRoundtrips) {
|
3140
|
+
const previousMessage = messages[messages.length - 1];
|
3141
|
+
if (previousMessage?.role === "assistant") {
|
3142
|
+
previousMessage.content.push(...newContent);
|
3143
|
+
break;
|
3144
|
+
}
|
3145
|
+
}
|
3146
|
+
messages.push({
|
3147
|
+
role: "assistant",
|
3148
|
+
content: newContent
|
3149
|
+
});
|
3150
|
+
break;
|
3151
|
+
}
|
3152
|
+
case "tool": {
|
3153
|
+
const previousMessage = messages[messages.length - 1];
|
3154
|
+
if (previousMessage?.role !== "assistant")
|
3155
|
+
throw new Error(
|
3156
|
+
"A tool message must be preceded by an assistant message."
|
3157
|
+
);
|
3158
|
+
for (const tool of lmMessage.content) {
|
3159
|
+
const toolCall = previousMessage.content.find(
|
3160
|
+
(c) => c.type === "tool-call" && c.toolCallId === tool.toolCallId
|
3161
|
+
);
|
3162
|
+
if (!toolCall)
|
3163
|
+
throw new Error("Received tool result for an unknown tool call.");
|
3164
|
+
if (toolCall.toolName !== tool.toolName)
|
3165
|
+
throw new Error("Tool call name mismatch.");
|
3166
|
+
toolCall.result = tool.result;
|
3167
|
+
if (tool.isError) {
|
3168
|
+
toolCall.isError = true;
|
3169
|
+
}
|
3170
|
+
}
|
3171
|
+
break;
|
3172
|
+
}
|
3173
|
+
default: {
|
3174
|
+
const unhandledRole = role;
|
3175
|
+
throw new Error(`Unknown message role: ${unhandledRole}`);
|
3176
|
+
}
|
3177
|
+
}
|
3178
|
+
}
|
3179
|
+
return messages;
|
3180
|
+
};
|
3181
|
+
|
3182
|
+
// src/runtimes/edge/converters/fromCoreMessage.ts
|
3183
|
+
var fromCoreMessages = (message) => {
|
3184
|
+
return message.map((message2) => {
|
3185
|
+
return {
|
3186
|
+
id: generateId(),
|
3187
|
+
createdAt: /* @__PURE__ */ new Date(),
|
3188
|
+
...message2.role === "assistant" ? {
|
3189
|
+
status: { type: "done" }
|
3190
|
+
} : void 0,
|
3191
|
+
...message2
|
3192
|
+
};
|
3193
|
+
});
|
3194
|
+
};
|
3195
|
+
|
3196
|
+
// src/runtimes/local/LocalRuntime.tsx
|
3197
|
+
var LocalRuntime = class extends BaseAssistantRuntime {
|
3198
|
+
_proxyConfigProvider;
|
3199
|
+
constructor(adapter, options) {
|
3200
|
+
const proxyConfigProvider = new ProxyConfigProvider();
|
3201
|
+
super(new LocalThreadRuntime(proxyConfigProvider, adapter, options));
|
3202
|
+
this._proxyConfigProvider = proxyConfigProvider;
|
3203
|
+
}
|
3204
|
+
set adapter(adapter) {
|
3205
|
+
this.thread.adapter = adapter;
|
3206
|
+
}
|
3207
|
+
registerModelConfigProvider(provider) {
|
3208
|
+
return this._proxyConfigProvider.registerModelConfigProvider(provider);
|
3209
|
+
}
|
3210
|
+
switchToThread(threadId) {
|
3211
|
+
if (threadId) {
|
3212
|
+
throw new Error("LocalRuntime does not yet support switching threads");
|
3213
|
+
}
|
3214
|
+
return this.thread = new LocalThreadRuntime(
|
3215
|
+
this._proxyConfigProvider,
|
3216
|
+
this.thread.adapter
|
3217
|
+
);
|
2969
3218
|
}
|
3219
|
+
};
|
3220
|
+
var CAPABILITIES = Object.freeze({
|
3221
|
+
edit: true,
|
3222
|
+
reload: true,
|
3223
|
+
cancel: true,
|
3224
|
+
copy: true
|
2970
3225
|
});
|
2971
|
-
var
|
2972
|
-
|
2973
|
-
|
3226
|
+
var LocalThreadRuntime = class {
|
3227
|
+
constructor(configProvider, adapter, options) {
|
3228
|
+
this.configProvider = configProvider;
|
3229
|
+
this.adapter = adapter;
|
3230
|
+
if (options?.initialMessages) {
|
3231
|
+
let parentId = null;
|
3232
|
+
const messages = fromCoreMessages(options.initialMessages);
|
3233
|
+
for (const message of messages) {
|
3234
|
+
this.repository.addOrUpdateMessage(parentId, message);
|
3235
|
+
parentId = message.id;
|
3236
|
+
}
|
3237
|
+
}
|
3238
|
+
}
|
3239
|
+
_subscriptions = /* @__PURE__ */ new Set();
|
3240
|
+
abortController = null;
|
3241
|
+
repository = new MessageRepository();
|
3242
|
+
capabilities = CAPABILITIES;
|
3243
|
+
get messages() {
|
3244
|
+
return this.repository.getMessages();
|
3245
|
+
}
|
3246
|
+
get isRunning() {
|
3247
|
+
return this.abortController != null;
|
3248
|
+
}
|
3249
|
+
getBranches(messageId) {
|
3250
|
+
return this.repository.getBranches(messageId);
|
3251
|
+
}
|
3252
|
+
switchToBranch(branchId) {
|
3253
|
+
this.repository.switchToBranch(branchId);
|
3254
|
+
this.notifySubscribers();
|
3255
|
+
}
|
3256
|
+
async append(message) {
|
3257
|
+
if (message.role !== "user")
|
3258
|
+
throw new Error(
|
3259
|
+
"Only appending user messages are supported in LocalRuntime. This is likely an internal bug in assistant-ui."
|
3260
|
+
);
|
3261
|
+
const userMessageId = generateId();
|
3262
|
+
const userMessage = {
|
3263
|
+
id: userMessageId,
|
3264
|
+
role: "user",
|
3265
|
+
content: message.content,
|
3266
|
+
createdAt: /* @__PURE__ */ new Date()
|
3267
|
+
};
|
3268
|
+
this.repository.addOrUpdateMessage(message.parentId, userMessage);
|
3269
|
+
await this.startRun(userMessageId);
|
3270
|
+
}
|
3271
|
+
async startRun(parentId) {
|
3272
|
+
this.repository.resetHead(parentId);
|
3273
|
+
const messages = this.repository.getMessages();
|
3274
|
+
const message = {
|
3275
|
+
id: generateId(),
|
3276
|
+
role: "assistant",
|
3277
|
+
status: { type: "in_progress" },
|
3278
|
+
content: [{ type: "text", text: "" }],
|
3279
|
+
createdAt: /* @__PURE__ */ new Date()
|
3280
|
+
};
|
3281
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3282
|
+
this.abortController?.abort();
|
3283
|
+
this.abortController = new AbortController();
|
3284
|
+
this.notifySubscribers();
|
3285
|
+
try {
|
3286
|
+
const updateHandler = ({ content }) => {
|
3287
|
+
message.content = content;
|
3288
|
+
const newMessage = { ...message };
|
3289
|
+
this.repository.addOrUpdateMessage(parentId, newMessage);
|
3290
|
+
this.notifySubscribers();
|
3291
|
+
return newMessage;
|
3292
|
+
};
|
3293
|
+
const result = await this.adapter.run({
|
3294
|
+
messages,
|
3295
|
+
abortSignal: this.abortController.signal,
|
3296
|
+
config: this.configProvider.getModelConfig(),
|
3297
|
+
onUpdate: updateHandler
|
3298
|
+
});
|
3299
|
+
if (result !== void 0) {
|
3300
|
+
updateHandler(result);
|
3301
|
+
}
|
3302
|
+
if (result.status?.type === "in_progress")
|
3303
|
+
throw new Error(
|
3304
|
+
"Unexpected in_progress status returned from ChatModelAdapter"
|
3305
|
+
);
|
3306
|
+
message.status = result.status ?? { type: "done" };
|
3307
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3308
|
+
} catch (e) {
|
3309
|
+
message.status = { type: "error", error: e };
|
3310
|
+
this.repository.addOrUpdateMessage(parentId, { ...message });
|
3311
|
+
throw e;
|
3312
|
+
} finally {
|
3313
|
+
this.abortController = null;
|
3314
|
+
this.notifySubscribers();
|
3315
|
+
}
|
3316
|
+
}
|
3317
|
+
cancelRun() {
|
3318
|
+
if (!this.abortController) return;
|
3319
|
+
this.abortController.abort();
|
3320
|
+
this.abortController = null;
|
3321
|
+
}
|
3322
|
+
notifySubscribers() {
|
3323
|
+
for (const callback of this._subscriptions) callback();
|
3324
|
+
}
|
3325
|
+
subscribe(callback) {
|
3326
|
+
this._subscriptions.add(callback);
|
3327
|
+
return () => this._subscriptions.delete(callback);
|
3328
|
+
}
|
3329
|
+
addToolResult({ messageId, toolCallId, result }) {
|
3330
|
+
const { parentId, message } = this.repository.getMessage(messageId);
|
3331
|
+
if (message.role !== "assistant")
|
3332
|
+
throw new Error("Tried to add tool result to non-assistant message");
|
3333
|
+
let found = false;
|
3334
|
+
const newContent = message.content.map((c) => {
|
3335
|
+
if (c.type !== "tool-call") return c;
|
3336
|
+
if (c.toolCallId !== toolCallId) return c;
|
3337
|
+
found = true;
|
3338
|
+
return {
|
3339
|
+
...c,
|
3340
|
+
result
|
3341
|
+
};
|
3342
|
+
});
|
3343
|
+
if (!found)
|
3344
|
+
throw new Error("Tried to add tool result to non-existing tool call");
|
3345
|
+
this.repository.addOrUpdateMessage(parentId, {
|
3346
|
+
...message,
|
3347
|
+
content: newContent
|
3348
|
+
});
|
3349
|
+
}
|
3350
|
+
};
|
3351
|
+
|
3352
|
+
// src/runtimes/local/useLocalRuntime.tsx
|
3353
|
+
var useLocalRuntime = (adapter, options) => {
|
3354
|
+
const [runtime] = useState8(() => new LocalRuntime(adapter, options));
|
3355
|
+
useInsertionEffect3(() => {
|
3356
|
+
runtime.adapter = adapter;
|
3357
|
+
});
|
3358
|
+
return runtime;
|
2974
3359
|
};
|
2975
3360
|
|
2976
3361
|
// src/ui/thread-config.tsx
|
2977
3362
|
import { createContext as createContext5, useContext as useContext5 } from "react";
|
2978
|
-
import { Fragment as Fragment3, jsx as
|
3363
|
+
import { Fragment as Fragment3, jsx as jsx29 } from "react/jsx-runtime";
|
2979
3364
|
var ThreadConfigContext = createContext5({});
|
2980
3365
|
var useThreadConfig = () => {
|
2981
3366
|
return useContext5(ThreadConfigContext);
|
@@ -2985,119 +3370,21 @@ var ThreadConfigProvider = ({
|
|
2985
3370
|
config
|
2986
3371
|
}) => {
|
2987
3372
|
const assistant = useAssistantContext({ optional: true });
|
2988
|
-
const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */
|
3373
|
+
const configProvider = config && Object.keys(config ?? {}).length > 0 ? /* @__PURE__ */ jsx29(ThreadConfigContext.Provider, { value: config, children }) : /* @__PURE__ */ jsx29(Fragment3, { children });
|
2989
3374
|
if (!config?.runtime) return configProvider;
|
2990
3375
|
if (assistant) {
|
2991
3376
|
throw new Error(
|
2992
3377
|
"You provided a runtime to <Thread> while simulataneously using <AssistantRuntimeProvider>. This is not allowed."
|
2993
3378
|
);
|
2994
3379
|
}
|
2995
|
-
return /* @__PURE__ */
|
3380
|
+
return /* @__PURE__ */ jsx29(AssistantRuntimeProvider, { runtime: config.runtime, children: configProvider });
|
2996
3381
|
};
|
2997
3382
|
ThreadConfigProvider.displayName = "ThreadConfigProvider";
|
2998
3383
|
|
2999
3384
|
// src/ui/assistant-action-bar.tsx
|
3000
3385
|
import { forwardRef as forwardRef18 } from "react";
|
3001
3386
|
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";
|
3387
|
+
import { Fragment as Fragment4, jsx as jsx30, jsxs as jsxs5 } from "react/jsx-runtime";
|
3101
3388
|
var useAllowCopy = () => {
|
3102
3389
|
const { assistantMessage: { allowCopy = true } = {} } = useThreadConfig();
|
3103
3390
|
const { useThreadActions } = useThreadContext();
|
@@ -3140,10 +3427,10 @@ var AssistantActionBarCopy = forwardRef18((props, ref) => {
|
|
3140
3427
|
} = useThreadConfig();
|
3141
3428
|
const allowCopy = useAllowCopy();
|
3142
3429
|
if (!allowCopy) return null;
|
3143
|
-
return /* @__PURE__ */ jsx30(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */
|
3430
|
+
return /* @__PURE__ */ jsx30(actionBar_exports.Copy, { asChild: true, children: /* @__PURE__ */ jsx30(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsxs5(Fragment4, { children: [
|
3144
3431
|
/* @__PURE__ */ jsx30(message_exports.If, { copied: true, children: /* @__PURE__ */ jsx30(CheckIcon, {}) }),
|
3145
3432
|
/* @__PURE__ */ jsx30(message_exports.If, { copied: false, children: /* @__PURE__ */ jsx30(CopyIcon, {}) })
|
3146
|
-
] }) });
|
3433
|
+
] }) }) });
|
3147
3434
|
});
|
3148
3435
|
AssistantActionBarCopy.displayName = "AssistantActionBarCopy";
|
3149
3436
|
var AssistantActionBarReload = forwardRef18((props, ref) => {
|
@@ -3192,7 +3479,7 @@ var BranchPickerPrevious2 = forwardRef19((props, ref) => {
|
|
3192
3479
|
branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
|
3193
3480
|
} = {}
|
3194
3481
|
} = useThreadConfig();
|
3195
|
-
return /* @__PURE__ */ jsx31(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx31(ChevronLeftIcon, {}) }) });
|
3482
|
+
return /* @__PURE__ */ jsx31(branchPicker_exports.Previous, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx31(ChevronLeftIcon, {}) }) });
|
3196
3483
|
});
|
3197
3484
|
BranchPickerPrevious2.displayName = "BranchPickerPrevious";
|
3198
3485
|
var BranchPickerStateWrapper = withDefaults("span", {
|
@@ -3210,7 +3497,7 @@ var BranchPickerNext = forwardRef19((props, ref) => {
|
|
3210
3497
|
const {
|
3211
3498
|
strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
|
3212
3499
|
} = useThreadConfig();
|
3213
|
-
return /* @__PURE__ */ jsx31(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx31(ChevronRightIcon, {}) }) });
|
3500
|
+
return /* @__PURE__ */ jsx31(branchPicker_exports.Next, { asChild: true, children: /* @__PURE__ */ jsx31(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx31(ChevronRightIcon, {}) }) });
|
3214
3501
|
});
|
3215
3502
|
BranchPickerNext.displayName = "BranchPickerNext";
|
3216
3503
|
var exports2 = {
|
@@ -3317,7 +3604,7 @@ import { ArrowDownIcon } from "lucide-react";
|
|
3317
3604
|
|
3318
3605
|
// src/ui/composer.tsx
|
3319
3606
|
import { forwardRef as forwardRef21 } from "react";
|
3320
|
-
import {
|
3607
|
+
import { SendHorizontalIcon } from "lucide-react";
|
3321
3608
|
|
3322
3609
|
// src/ui/base/CircleStopIcon.tsx
|
3323
3610
|
import { jsx as jsx35 } from "react/jsx-runtime";
|
@@ -3335,7 +3622,7 @@ var CircleStopIcon = () => {
|
|
3335
3622
|
CircleStopIcon.displayName = "CircleStopIcon";
|
3336
3623
|
|
3337
3624
|
// src/ui/composer.tsx
|
3338
|
-
import { Fragment as
|
3625
|
+
import { Fragment as Fragment5, jsx as jsx36, jsxs as jsxs9 } from "react/jsx-runtime";
|
3339
3626
|
var Composer = () => {
|
3340
3627
|
return /* @__PURE__ */ jsxs9(ComposerRoot, { children: [
|
3341
3628
|
/* @__PURE__ */ jsx36(ComposerInput, { autoFocus: true }),
|
@@ -3371,7 +3658,7 @@ var useAllowCancel = () => {
|
|
3371
3658
|
var ComposerAction = () => {
|
3372
3659
|
const allowCancel = useAllowCancel();
|
3373
3660
|
if (!allowCancel) return /* @__PURE__ */ jsx36(ComposerSend, {});
|
3374
|
-
return /* @__PURE__ */ jsxs9(
|
3661
|
+
return /* @__PURE__ */ jsxs9(Fragment5, { children: [
|
3375
3662
|
/* @__PURE__ */ jsx36(thread_exports.If, { running: false, children: /* @__PURE__ */ jsx36(ComposerSend, {}) }),
|
3376
3663
|
/* @__PURE__ */ jsx36(thread_exports.If, { running: true, children: /* @__PURE__ */ jsx36(ComposerCancel, {}) })
|
3377
3664
|
] });
|
@@ -3385,7 +3672,7 @@ var ComposerSend = forwardRef21((props, ref) => {
|
|
3385
3672
|
const {
|
3386
3673
|
strings: { composer: { send: { tooltip = "Send" } = {} } = {} } = {}
|
3387
3674
|
} = useThreadConfig();
|
3388
|
-
return /* @__PURE__ */ jsx36(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerSendButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx36(
|
3675
|
+
return /* @__PURE__ */ jsx36(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerSendButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx36(SendHorizontalIcon, {}) }) });
|
3389
3676
|
});
|
3390
3677
|
ComposerSend.displayName = "ComposerSend";
|
3391
3678
|
var ComposerCancelButton = withDefaults(TooltipIconButton, {
|
@@ -3396,7 +3683,7 @@ var ComposerCancel = forwardRef21((props, ref) => {
|
|
3396
3683
|
const {
|
3397
3684
|
strings: { composer: { cancel: { tooltip = "Cancel" } = {} } = {} } = {}
|
3398
3685
|
} = useThreadConfig();
|
3399
|
-
return /* @__PURE__ */ jsx36(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerCancelButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx36(CircleStopIcon, {}) }) });
|
3686
|
+
return /* @__PURE__ */ jsx36(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx36(ComposerCancelButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx36(CircleStopIcon, {}) }) });
|
3400
3687
|
});
|
3401
3688
|
ComposerCancel.displayName = "ComposerCancel";
|
3402
3689
|
var exports5 = {
|
@@ -3511,7 +3798,7 @@ var UserActionBarEdit = forwardRef23((props, ref) => {
|
|
3511
3798
|
} = useThreadConfig();
|
3512
3799
|
const allowEdit = useAllowEdit();
|
3513
3800
|
if (!allowEdit) return null;
|
3514
|
-
return /* @__PURE__ */ jsx38(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx38(PencilIcon, {}) }) });
|
3801
|
+
return /* @__PURE__ */ jsx38(actionBar_exports.Edit, { asChild: true, children: /* @__PURE__ */ jsx38(TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx38(PencilIcon, {}) }) });
|
3515
3802
|
});
|
3516
3803
|
UserActionBarEdit.displayName = "UserActionBarEdit";
|
3517
3804
|
var exports7 = {
|
@@ -3589,7 +3876,7 @@ var EditComposerCancel = forwardRef25(
|
|
3589
3876
|
editComposer: { cancel: { label = "Cancel" } = {} } = {}
|
3590
3877
|
} = {}
|
3591
3878
|
} = useThreadConfig();
|
3592
|
-
return /* @__PURE__ */ jsx40(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { variant: "ghost", ...props, ref, children: label }) });
|
3879
|
+
return /* @__PURE__ */ jsx40(composer_exports.Cancel, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { variant: "ghost", ...props, ref, children: props.children ?? label }) });
|
3593
3880
|
}
|
3594
3881
|
);
|
3595
3882
|
EditComposerCancel.displayName = "EditComposerCancel";
|
@@ -3598,7 +3885,7 @@ var EditComposerSend = forwardRef25(
|
|
3598
3885
|
const {
|
3599
3886
|
strings: { editComposer: { send: { label = "Send" } = {} } = {} } = {}
|
3600
3887
|
} = useThreadConfig();
|
3601
|
-
return /* @__PURE__ */ jsx40(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { ...props, ref, children: label }) });
|
3888
|
+
return /* @__PURE__ */ jsx40(composer_exports.Send, { asChild: true, children: /* @__PURE__ */ jsx40(Button, { ...props, ref, children: props.children ?? label }) });
|
3602
3889
|
}
|
3603
3890
|
);
|
3604
3891
|
EditComposerSend.displayName = "EditComposerSend";
|
@@ -3666,7 +3953,7 @@ var ThreadScrollToBottom = forwardRef26((props, ref) => {
|
|
3666
3953
|
thread: { scrollToBottom: { tooltip = "Scroll to bottom" } = {} } = {}
|
3667
3954
|
} = {}
|
3668
3955
|
} = useThreadConfig();
|
3669
|
-
return /* @__PURE__ */ jsx41(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx41(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: /* @__PURE__ */ jsx41(ArrowDownIcon, {}) }) });
|
3956
|
+
return /* @__PURE__ */ jsx41(thread_exports.ScrollToBottom, { asChild: true, children: /* @__PURE__ */ jsx41(ThreadScrollToBottomIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ jsx41(ArrowDownIcon, {}) }) });
|
3670
3957
|
});
|
3671
3958
|
ThreadScrollToBottom.displayName = "ThreadScrollToBottom";
|
3672
3959
|
var exports10 = {
|
@@ -3679,7 +3966,7 @@ var exports10 = {
|
|
3679
3966
|
var thread_default = Object.assign(Thread, exports10);
|
3680
3967
|
|
3681
3968
|
// src/ui/assistant-modal.tsx
|
3682
|
-
import { jsx as jsx42, jsxs as jsxs14 } from "react/jsx-runtime";
|
3969
|
+
import { Fragment as Fragment6, jsx as jsx42, jsxs as jsxs14 } from "react/jsx-runtime";
|
3683
3970
|
var AssistantModal = (config) => {
|
3684
3971
|
return /* @__PURE__ */ jsxs14(AssistantModalRoot, { config, children: [
|
3685
3972
|
/* @__PURE__ */ jsx42(AssistantModalTrigger, {}),
|
@@ -3717,7 +4004,7 @@ var AssistantModalButton = forwardRef27(({ "data-state": state, ...rest }, ref)
|
|
3717
4004
|
} = {}
|
3718
4005
|
} = useThreadConfig();
|
3719
4006
|
const tooltip = state === "open" ? openTooltip : closedTooltip;
|
3720
|
-
return /* @__PURE__ */
|
4007
|
+
return /* @__PURE__ */ jsx42(
|
3721
4008
|
ModalButtonStyled,
|
3722
4009
|
{
|
3723
4010
|
side: "left",
|
@@ -3725,17 +4012,22 @@ var AssistantModalButton = forwardRef27(({ "data-state": state, ...rest }, ref)
|
|
3725
4012
|
"data-state": state,
|
3726
4013
|
...rest,
|
3727
4014
|
ref,
|
3728
|
-
children: [
|
3729
|
-
/* @__PURE__ */ jsx42(
|
4015
|
+
children: rest.children ?? /* @__PURE__ */ jsxs14(Fragment6, { children: [
|
4016
|
+
/* @__PURE__ */ jsx42(
|
4017
|
+
BotIcon,
|
4018
|
+
{
|
4019
|
+
"data-state": state,
|
4020
|
+
className: "aui-modal-button-closed-icon"
|
4021
|
+
}
|
4022
|
+
),
|
3730
4023
|
/* @__PURE__ */ jsx42(
|
3731
4024
|
ChevronDownIcon,
|
3732
4025
|
{
|
3733
4026
|
"data-state": state,
|
3734
4027
|
className: "aui-modal-button-open-icon"
|
3735
4028
|
}
|
3736
|
-
)
|
3737
|
-
|
3738
|
-
]
|
4029
|
+
)
|
4030
|
+
] })
|
3739
4031
|
}
|
3740
4032
|
);
|
3741
4033
|
});
|
@@ -3751,16 +4043,6 @@ var exports11 = {
|
|
3751
4043
|
Content: AssistantModalContent
|
3752
4044
|
};
|
3753
4045
|
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
4046
|
export {
|
3765
4047
|
actionBar_exports as ActionBarPrimitive,
|
3766
4048
|
assistant_action_bar_default as AssistantActionBar,
|
@@ -3774,6 +4056,7 @@ export {
|
|
3774
4056
|
composer_exports as ComposerPrimitive,
|
3775
4057
|
content_part_default as ContentPart,
|
3776
4058
|
contentPart_exports as ContentPartPrimitive,
|
4059
|
+
EdgeChatAdapter,
|
3777
4060
|
edit_composer_default as EditComposer,
|
3778
4061
|
internal_exports as INTERNAL,
|
3779
4062
|
message_exports as MessagePrimitive,
|
@@ -3783,8 +4066,11 @@ export {
|
|
3783
4066
|
thread_welcome_default as ThreadWelcome,
|
3784
4067
|
user_action_bar_default as UserActionBar,
|
3785
4068
|
user_message_default as UserMessage,
|
4069
|
+
fromCoreMessages,
|
4070
|
+
fromLanguageModelMessages,
|
3786
4071
|
makeAssistantTool,
|
3787
4072
|
makeAssistantToolUI,
|
4073
|
+
toLanguageModelMessages,
|
3788
4074
|
useActionBarCopy,
|
3789
4075
|
useActionBarEdit,
|
3790
4076
|
useActionBarReload,
|