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